[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 32/37] crypto: Implement aesdec_IMC with AES_imc_rot
From: |
Richard Henderson |
Subject: |
[PATCH v3 32/37] crypto: Implement aesdec_IMC with AES_imc_rot |
Date: |
Tue, 20 Jun 2023 13:07:53 +0200 |
This method uses one uint32_t * 256 table instead of 4,
which means its data cache overhead is less.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
crypto/aes.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/crypto/aes.c b/crypto/aes.c
index 9795ae8614..307c27947c 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -1411,39 +1411,39 @@ aesdec_IMC_swap(AESState *r, const AESState *st, bool
swap)
bool be = HOST_BIG_ENDIAN ^ swap;
uint32_t t;
- /* Note that AES_imc is encoded for big-endian. */
- t = (AES_imc[st->b[swap_b ^ 0x0]][0] ^
- AES_imc[st->b[swap_b ^ 0x1]][1] ^
- AES_imc[st->b[swap_b ^ 0x2]][2] ^
- AES_imc[st->b[swap_b ^ 0x3]][3]);
- if (!be) {
+ /* Note that AES_imc_rot is encoded for little-endian. */
+ t = ( AES_imc_rot[st->b[swap_b ^ 0x0]] ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x1]], 8) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x2]], 16) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x3]], 24));
+ if (be) {
t = bswap32(t);
}
r->w[swap_w ^ 0] = t;
- t = (AES_imc[st->b[swap_b ^ 0x4]][0] ^
- AES_imc[st->b[swap_b ^ 0x5]][1] ^
- AES_imc[st->b[swap_b ^ 0x6]][2] ^
- AES_imc[st->b[swap_b ^ 0x7]][3]);
- if (!be) {
+ t = ( AES_imc_rot[st->b[swap_b ^ 0x4]] ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x5]], 8) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x6]], 16) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x7]], 24));
+ if (be) {
t = bswap32(t);
}
r->w[swap_w ^ 1] = t;
- t = (AES_imc[st->b[swap_b ^ 0x8]][0] ^
- AES_imc[st->b[swap_b ^ 0x9]][1] ^
- AES_imc[st->b[swap_b ^ 0xA]][2] ^
- AES_imc[st->b[swap_b ^ 0xB]][3]);
- if (!be) {
+ t = ( AES_imc_rot[st->b[swap_b ^ 0x8]] ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0x9]], 8) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0xA]], 16) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0xB]], 24));
+ if (be) {
t = bswap32(t);
}
r->w[swap_w ^ 2] = t;
- t = (AES_imc[st->b[swap_b ^ 0xC]][0] ^
- AES_imc[st->b[swap_b ^ 0xD]][1] ^
- AES_imc[st->b[swap_b ^ 0xE]][2] ^
- AES_imc[st->b[swap_b ^ 0xF]][3]);
- if (!be) {
+ t = ( AES_imc_rot[st->b[swap_b ^ 0xC]] ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0xD]], 8) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0xE]], 16) ^
+ rol32(AES_imc_rot[st->b[swap_b ^ 0xF]], 24));
+ if (be) {
t = bswap32(t);
}
r->w[swap_w ^ 3] = t;
--
2.34.1
- [PATCH v3 19/37] target/i386: Use aesdec_IMC, (continued)
- [PATCH v3 19/37] target/i386: Use aesdec_IMC, Richard Henderson, 2023/06/20
- [PATCH v3 17/37] target/arm: Use aesenc_MC, Richard Henderson, 2023/06/20
- [PATCH v3 21/37] target/riscv: Use aesdec_IMC, Richard Henderson, 2023/06/20
- [PATCH v3 20/37] target/arm: Use aesdec_IMC, Richard Henderson, 2023/06/20
- [PATCH v3 22/37] crypto: Add aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 24/37] target/ppc: Use aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 23/37] target/i386: Use aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 25/37] target/riscv: Use aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 28/37] target/riscv: Use aesdec_ISB_ISR_IMC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 32/37] crypto: Implement aesdec_IMC with AES_imc_rot,
Richard Henderson <=
- [PATCH v3 27/37] target/i386: Use aesdec_ISB_ISR_IMC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 26/37] crypto: Add aesdec_ISB_ISR_IMC_AK, Richard Henderson, 2023/06/20
- [PATCH v3 29/37] crypto: Add aesdec_ISB_ISR_AK_IMC, Richard Henderson, 2023/06/20
- [PATCH v3 31/37] crypto: Remove AES_shifts, AES_ishifts, Richard Henderson, 2023/06/20
- [PATCH v3 33/37] crypto: Remove AES_imc, Richard Henderson, 2023/06/20