aes.c: use uint8_t for local x, y, z in aes_gen_tables to save RAM

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
Yanray Wang 2023-06-26 18:16:01 +08:00
parent 5c86b1775a
commit fe944ce2d8

View File

@ -364,7 +364,8 @@ static int aes_init_done = 0;
static void aes_gen_tables(void) static void aes_gen_tables(void)
{ {
int i, x, y, z; int i;
uint8_t x, y, z;
uint8_t pow[256]; uint8_t pow[256];
uint8_t log[256]; uint8_t log[256];
@ -372,17 +373,17 @@ static void aes_gen_tables(void)
* compute pow and log tables over GF(2^8) * compute pow and log tables over GF(2^8)
*/ */
for (i = 0, x = 1; i < 256; i++) { for (i = 0, x = 1; i < 256; i++) {
pow[i] = (uint8_t) x; pow[i] = x;
log[x] = (uint8_t) i; log[x] = (uint8_t) i;
x = MBEDTLS_BYTE_0(x ^ XTIME(x)); x ^= XTIME(x);
} }
/* /*
* calculate the round constants * calculate the round constants
*/ */
for (i = 0, x = 1; i < 10; i++) { for (i = 0, x = 1; i < 10; i++) {
RCON[i] = (uint32_t) x; RCON[i] = x;
x = MBEDTLS_BYTE_0(XTIME(x)); x = XTIME(x);
} }
/* /*
@ -394,13 +395,13 @@ static void aes_gen_tables(void)
for (i = 1; i < 256; i++) { for (i = 1; i < 256; i++) {
x = pow[255 - log[i]]; x = pow[255 - log[i]];
y = x; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); y = x; y = (y << 1) | (y >> 7);
x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); x ^= y; y = (y << 1) | (y >> 7);
x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); x ^= y; y = (y << 1) | (y >> 7);
x ^= y; y = MBEDTLS_BYTE_0((y << 1) | (y >> 7)); x ^= y; y = (y << 1) | (y >> 7);
x ^= y ^ 0x63; x ^= y ^ 0x63;
FSb[i] = (unsigned char) x; FSb[i] = x;
RSb[x] = (unsigned char) i; RSb[x] = (unsigned char) i;
} }
@ -409,8 +410,8 @@ static void aes_gen_tables(void)
*/ */
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
x = FSb[i]; x = FSb[i];
y = MBEDTLS_BYTE_0(XTIME(x)); y = XTIME(x);
z = MBEDTLS_BYTE_0(y ^ x); z = y ^ x;
FT0[i] = ((uint32_t) y) ^ FT0[i] = ((uint32_t) y) ^
((uint32_t) x << 8) ^ ((uint32_t) x << 8) ^