aboutsummaryrefslogtreecommitdiff
path: root/crypto/aes.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2023-06-02 15:23:18 -0700
committerRichard Henderson <richard.henderson@linaro.org>2023-07-08 07:30:17 +0100
commit15ff15982a13ddf3e03b38ff46277ed90c1f36f9 (patch)
treea03aaf8383de24d52bfc7928c83e55981a80fab2 /crypto/aes.c
parent7c58cb972e851c2e96ad5abd98b9c00b3f1c8a95 (diff)
downloadqemu-15ff15982a13ddf3e03b38ff46277ed90c1f36f9.zip
qemu-15ff15982a13ddf3e03b38ff46277ed90c1f36f9.tar.gz
qemu-15ff15982a13ddf3e03b38ff46277ed90c1f36f9.tar.bz2
crypto: Add aesdec_ISB_ISR_IMC_AK
Add a primitive for InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey. Acked-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'crypto/aes.c')
-rw-r--r--crypto/aes.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/crypto/aes.c b/crypto/aes.c
index a193d98..c2546ef 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -1484,6 +1484,64 @@ void aesdec_ISB_ISR_AK_genrev(AESState *r, const AESState *s, const AESState *k)
aesdec_ISB_ISR_AK_swap(r, s, k, true);
}
+/*
+ * Perform InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey.
+ */
+static inline void
+aesdec_ISB_ISR_IMC_AK_swap(AESState *r, const AESState *st,
+ const AESState *rk, bool swap)
+{
+ int swap_b = swap * 0xf;
+ int swap_w = swap * 0x3;
+ bool be = HOST_BIG_ENDIAN ^ swap;
+ uint32_t w0, w1, w2, w3;
+
+ w0 = (AES_Td0[st->b[swap_b ^ AES_ISH(0x0)]] ^
+ AES_Td1[st->b[swap_b ^ AES_ISH(0x1)]] ^
+ AES_Td2[st->b[swap_b ^ AES_ISH(0x2)]] ^
+ AES_Td3[st->b[swap_b ^ AES_ISH(0x3)]]);
+
+ w1 = (AES_Td0[st->b[swap_b ^ AES_ISH(0x4)]] ^
+ AES_Td1[st->b[swap_b ^ AES_ISH(0x5)]] ^
+ AES_Td2[st->b[swap_b ^ AES_ISH(0x6)]] ^
+ AES_Td3[st->b[swap_b ^ AES_ISH(0x7)]]);
+
+ w2 = (AES_Td0[st->b[swap_b ^ AES_ISH(0x8)]] ^
+ AES_Td1[st->b[swap_b ^ AES_ISH(0x9)]] ^
+ AES_Td2[st->b[swap_b ^ AES_ISH(0xA)]] ^
+ AES_Td3[st->b[swap_b ^ AES_ISH(0xB)]]);
+
+ w3 = (AES_Td0[st->b[swap_b ^ AES_ISH(0xC)]] ^
+ AES_Td1[st->b[swap_b ^ AES_ISH(0xD)]] ^
+ AES_Td2[st->b[swap_b ^ AES_ISH(0xE)]] ^
+ AES_Td3[st->b[swap_b ^ AES_ISH(0xF)]]);
+
+ /* Note that AES_TdX is encoded for big-endian. */
+ if (!be) {
+ w0 = bswap32(w0);
+ w1 = bswap32(w1);
+ w2 = bswap32(w2);
+ w3 = bswap32(w3);
+ }
+
+ r->w[swap_w ^ 0] = rk->w[swap_w ^ 0] ^ w0;
+ r->w[swap_w ^ 1] = rk->w[swap_w ^ 1] ^ w1;
+ r->w[swap_w ^ 2] = rk->w[swap_w ^ 2] ^ w2;
+ r->w[swap_w ^ 3] = rk->w[swap_w ^ 3] ^ w3;
+}
+
+void aesdec_ISB_ISR_IMC_AK_gen(AESState *r, const AESState *st,
+ const AESState *rk)
+{
+ aesdec_ISB_ISR_IMC_AK_swap(r, st, rk, false);
+}
+
+void aesdec_ISB_ISR_IMC_AK_genrev(AESState *r, const AESState *st,
+ const AESState *rk)
+{
+ aesdec_ISB_ISR_IMC_AK_swap(r, st, rk, true);
+}
+
/**
* Expand the cipher key into the encryption key schedule.
*/