Merge pull request #7840 from yanrayw/7381_aes_gen_table

AES: use uint8_t for array of pow and log to save RAM usage
This commit is contained in:
Tom Cosgrove 2023-07-04 08:34:12 +01:00 committed by GitHub
commit 9b20c6fcc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -391,25 +391,26 @@ static int aes_init_done = 0;
static void aes_gen_tables(void)
{
int i, x, y, z;
int pow[256];
int log[256];
int i;
uint8_t x, y, z;
uint8_t pow[256];
uint8_t log[256];
/*
* compute pow and log tables over GF(2^8)
*/
for (i = 0, x = 1; i < 256; i++) {
pow[i] = x;
log[x] = i;
x = MBEDTLS_BYTE_0(x ^ XTIME(x));
log[x] = (uint8_t) i;
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);
}
/*
@ -421,13 +422,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;
}
@ -436,8 +437,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) ^