crypto: Implement aesdec_IMC with AES_imc_rot

This method uses one uint32_t * 256 table instead of 4,
which means its data cache overhead is less.

Acked-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2023-06-03 01:26:20 +00:00
parent 66d940e9e7
commit c10c559bdf

View File

@ -1377,39 +1377,39 @@ aesdec_IMC_swap(AESState *r, const AESState *st, bool swap)
bool be = HOST_BIG_ENDIAN ^ swap; bool be = HOST_BIG_ENDIAN ^ swap;
uint32_t t; uint32_t t;
/* Note that AES_imc is encoded for big-endian. */ /* Note that AES_imc_rot is encoded for little-endian. */
t = (AES_imc[st->b[swap_b ^ 0x0]][0] ^ t = ( AES_imc_rot[st->b[swap_b ^ 0x0]] ^
AES_imc[st->b[swap_b ^ 0x1]][1] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0x1]], 8) ^
AES_imc[st->b[swap_b ^ 0x2]][2] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0x2]], 16) ^
AES_imc[st->b[swap_b ^ 0x3]][3]); rol32(AES_imc_rot[st->b[swap_b ^ 0x3]], 24));
if (!be) { if (be) {
t = bswap32(t); t = bswap32(t);
} }
r->w[swap_w ^ 0] = t; r->w[swap_w ^ 0] = t;
t = (AES_imc[st->b[swap_b ^ 0x4]][0] ^ t = ( AES_imc_rot[st->b[swap_b ^ 0x4]] ^
AES_imc[st->b[swap_b ^ 0x5]][1] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0x5]], 8) ^
AES_imc[st->b[swap_b ^ 0x6]][2] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0x6]], 16) ^
AES_imc[st->b[swap_b ^ 0x7]][3]); rol32(AES_imc_rot[st->b[swap_b ^ 0x7]], 24));
if (!be) { if (be) {
t = bswap32(t); t = bswap32(t);
} }
r->w[swap_w ^ 1] = t; r->w[swap_w ^ 1] = t;
t = (AES_imc[st->b[swap_b ^ 0x8]][0] ^ t = ( AES_imc_rot[st->b[swap_b ^ 0x8]] ^
AES_imc[st->b[swap_b ^ 0x9]][1] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0x9]], 8) ^
AES_imc[st->b[swap_b ^ 0xA]][2] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0xA]], 16) ^
AES_imc[st->b[swap_b ^ 0xB]][3]); rol32(AES_imc_rot[st->b[swap_b ^ 0xB]], 24));
if (!be) { if (be) {
t = bswap32(t); t = bswap32(t);
} }
r->w[swap_w ^ 2] = t; r->w[swap_w ^ 2] = t;
t = (AES_imc[st->b[swap_b ^ 0xC]][0] ^ t = ( AES_imc_rot[st->b[swap_b ^ 0xC]] ^
AES_imc[st->b[swap_b ^ 0xD]][1] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0xD]], 8) ^
AES_imc[st->b[swap_b ^ 0xE]][2] ^ rol32(AES_imc_rot[st->b[swap_b ^ 0xE]], 16) ^
AES_imc[st->b[swap_b ^ 0xF]][3]); rol32(AES_imc_rot[st->b[swap_b ^ 0xF]], 24));
if (!be) { if (be) {
t = bswap32(t); t = bswap32(t);
} }
r->w[swap_w ^ 3] = t; r->w[swap_w ^ 3] = t;