From fe944ce2d883c8c178ee978ec3dd75c5b65a6a6d Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Mon, 26 Jun 2023 18:16:01 +0800 Subject: [PATCH] aes.c: use uint8_t for local x, y, z in aes_gen_tables to save RAM Signed-off-by: Yanray Wang --- library/aes.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/library/aes.c b/library/aes.c index a90735aa0..240702f82 100644 --- a/library/aes.c +++ b/library/aes.c @@ -364,7 +364,8 @@ static int aes_init_done = 0; static void aes_gen_tables(void) { - int i, x, y, z; + int i; + uint8_t x, y, z; uint8_t pow[256]; uint8_t log[256]; @@ -372,17 +373,17 @@ static void aes_gen_tables(void) * compute pow and log tables over GF(2^8) */ for (i = 0, x = 1; i < 256; i++) { - pow[i] = (uint8_t) x; + pow[i] = x; log[x] = (uint8_t) i; - x = MBEDTLS_BYTE_0(x ^ XTIME(x)); + x ^= XTIME(x); } /* * calculate the round constants */ for (i = 0, x = 1; i < 10; i++) { - RCON[i] = (uint32_t) x; - x = MBEDTLS_BYTE_0(XTIME(x)); + RCON[i] = x; + x = XTIME(x); } /* @@ -394,13 +395,13 @@ static void aes_gen_tables(void) for (i = 1; i < 256; i++) { x = pow[255 - log[i]]; - y = x; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); - x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); - x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); - x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); + y = x; y = (y << 1) | (y >> 7); + x ^= y; y = (y << 1) | (y >> 7); + x ^= y; y = (y << 1) | (y >> 7); + x ^= y; y = (y << 1) | (y >> 7); x ^= y ^ 0x63; - FSb[i] = (unsigned char) x; + FSb[i] = x; RSb[x] = (unsigned char) i; } @@ -409,8 +410,8 @@ static void aes_gen_tables(void) */ for (i = 0; i < 256; i++) { x = FSb[i]; - y = MBEDTLS_BYTE_0(XTIME(x)); - z = MBEDTLS_BYTE_0(y ^ x); + y = XTIME(x); + z = y ^ x; FT0[i] = ((uint32_t) y) ^ ((uint32_t) x << 8) ^