[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/35] crypto: Add aesdec_ISB_ISR
From: |
Richard Henderson |
Subject: |
[PATCH 10/35] crypto: Add aesdec_ISB_ISR |
Date: |
Fri, 2 Jun 2023 19:34:01 -0700 |
Add a primitive for InvSubBytes + InvShiftRows.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
host/include/generic/host/aes-round.h | 3 ++
include/crypto/aes-round.h | 18 +++++++++++
crypto/aes.c | 46 +++++++++++++++++++++++++++
3 files changed, 67 insertions(+)
diff --git a/host/include/generic/host/aes-round.h
b/host/include/generic/host/aes-round.h
index 598242c603..cb4fed61fe 100644
--- a/host/include/generic/host/aes-round.h
+++ b/host/include/generic/host/aes-round.h
@@ -12,4 +12,7 @@
void aesenc_SB_SR_accel(AESState *, const AESState *, bool)
QEMU_ERROR("unsupported accel");
+void aesdec_ISB_ISR_accel(AESState *, const AESState *, bool)
+ QEMU_ERROR("unsupported accel");
+
#endif
diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h
index 784e1daee6..ff1914bd63 100644
--- a/include/crypto/aes-round.h
+++ b/include/crypto/aes-round.h
@@ -38,4 +38,22 @@ static inline void aesenc_SB_SR(AESState *r, const AESState
*st, bool be)
}
}
+/*
+ * Perform InvSubBytes + InvShiftRows.
+ */
+
+void aesdec_ISB_ISR_gen(AESState *ret, const AESState *st);
+void aesdec_ISB_ISR_genrev(AESState *ret, const AESState *st);
+
+static inline void aesdec_ISB_ISR(AESState *r, const AESState *st, bool be)
+{
+ if (HAVE_AES_ACCEL) {
+ aesdec_ISB_ISR_accel(r, st, be);
+ } else if (HOST_BIG_ENDIAN == be) {
+ aesdec_ISB_ISR_gen(r, st);
+ } else {
+ aesdec_ISB_ISR_genrev(r, st);
+ }
+}
+
#endif /* CRYPTO_AES_ROUND_H */
diff --git a/crypto/aes.c b/crypto/aes.c
index 708838315a..937377647f 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -1298,6 +1298,52 @@ void aesenc_SB_SR_genrev(AESState *r, const AESState *st)
aesenc_SB_SR_swap(r, st, true);
}
+/* Perform InvSubBytes + InvShiftRows. */
+static inline void
+aesdec_ISB_ISR_swap(AESState *r, const AESState *st, bool swap)
+{
+ const int swap_b = swap ? 15 : 0;
+ uint8_t t;
+
+ /* These four indexes are not swizzled. */
+ r->b[swap_b ^ 0x0] = AES_isbox[st->b[swap_b ^ AES_ISH_0]];
+ r->b[swap_b ^ 0x4] = AES_isbox[st->b[swap_b ^ AES_ISH_4]];
+ r->b[swap_b ^ 0x8] = AES_isbox[st->b[swap_b ^ AES_ISH_8]];
+ r->b[swap_b ^ 0xc] = AES_isbox[st->b[swap_b ^ AES_ISH_C]];
+
+ /* Otherwise, break cycles. */
+
+ t = AES_isbox[st->b[swap_b ^ AES_ISH_5]];
+ r->b[swap_b ^ 0x1] = AES_isbox[st->b[swap_b ^ AES_ISH_1]];
+ r->b[swap_b ^ 0xd] = AES_isbox[st->b[swap_b ^ AES_ISH_D]];
+ r->b[swap_b ^ 0x9] = AES_isbox[st->b[swap_b ^ AES_ISH_9]];
+ r->b[swap_b ^ 0x5] = t;
+
+ t = AES_isbox[st->b[swap_b ^ AES_ISH_A]];
+ r->b[swap_b ^ 0x2] = AES_isbox[st->b[swap_b ^ AES_ISH_2]];
+ r->b[swap_b ^ 0xa] = t;
+
+ t = AES_isbox[st->b[swap_b ^ AES_ISH_E]];
+ r->b[swap_b ^ 0x6] = AES_isbox[st->b[swap_b ^ AES_ISH_6]];
+ r->b[swap_b ^ 0xe] = t;
+
+ t = AES_isbox[st->b[swap_b ^ AES_ISH_F]];
+ r->b[swap_b ^ 0x3] = AES_isbox[st->b[swap_b ^ AES_ISH_3]];
+ r->b[swap_b ^ 0x7] = AES_isbox[st->b[swap_b ^ AES_ISH_7]];
+ r->b[swap_b ^ 0xb] = AES_isbox[st->b[swap_b ^ AES_ISH_B]];
+ r->b[swap_b ^ 0xf] = t;
+}
+
+void aesdec_ISB_ISR_gen(AESState *r, const AESState *st)
+{
+ aesdec_ISB_ISR_swap(r, st, false);
+}
+
+void aesdec_ISB_ISR_genrev(AESState *r, const AESState *st)
+{
+ aesdec_ISB_ISR_swap(r, st, true);
+}
+
/**
* Expand the cipher key into the encryption key schedule.
*/
--
2.34.1
- Re: [PATCH 03/35] crypto/aes: Add constants for ShiftRows, InvShiftRows, (continued)
- [PATCH 04/35] crypto: Add aesenc_SB_SR, Richard Henderson, 2023/06/02
- [PATCH 07/35] target/arm: Use aesenc_SB_SR, Richard Henderson, 2023/06/02
- [PATCH 08/35] target/ppc: Use aesenc_SB_SR, Richard Henderson, 2023/06/02
- [PATCH 06/35] target/arm: Demultiplex AESE and AESMC, Richard Henderson, 2023/06/02
- [PATCH 13/35] target/ppc: Use aesdec_ISB_ISR, Richard Henderson, 2023/06/02
- [PATCH 09/35] target/riscv: Use aesenc_SB_SR, Richard Henderson, 2023/06/02
- [PATCH 10/35] crypto: Add aesdec_ISB_ISR,
Richard Henderson <=
- [PATCH 05/35] target/i386: Use aesenc_SB_SR, Richard Henderson, 2023/06/02
- [PATCH 11/35] target/i386: Use aesdec_ISB_ISR, Richard Henderson, 2023/06/02
- [PATCH 14/35] target/riscv: Use aesdec_ISB_ISR, Richard Henderson, 2023/06/02
- [PATCH 15/35] crypto: Add aesenc_MC, Richard Henderson, 2023/06/02
- [PATCH 16/35] target/arm: Use aesenc_MC, Richard Henderson, 2023/06/02
- [PATCH 12/35] target/arm: Use aesdec_ISB_ISR, Richard Henderson, 2023/06/02
- [PATCH 18/35] target/i386: Use aesdec_IMC, Richard Henderson, 2023/06/02
- [PATCH 21/35] crypto: Add aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/02
- [PATCH 23/35] target/ppc: Use aesenc_SB_SR_MC_AK, Richard Henderson, 2023/06/02
- [PATCH 27/35] target/riscv: Use aesdec_ISB_ISR_IMC_AK, Richard Henderson, 2023/06/02