aes.c: provide finer guard for RSb
Variable RSb is only used for either computing reverse tables in aes_gen_tables or AES-decryption function. This commit provides more guards for when RSb is defined and used. Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
parent
422a77f716
commit
427424768a
1 changed files with 12 additions and 3 deletions
|
@ -391,9 +391,14 @@ static uint32_t FT3[256];
|
||||||
/*
|
/*
|
||||||
* Reverse S-box & tables
|
* Reverse S-box & tables
|
||||||
*/
|
*/
|
||||||
#if !defined(MBEDTLS_AES_SETKEY_ENC_ALT) || !defined(MBEDTLS_AES_DECRYPT_ALT)
|
|
||||||
|
#if !defined(MBEDTLS_AES_SETKEY_ENC_ALT) && !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||||
static unsigned char RSb[256];
|
static unsigned char RSb[256];
|
||||||
#endif /* !MBEDTLS_AES_SETKEY_ENC_ALT || !MBEDTLS_AES_DECRYPT_ALT */
|
#else /* !MBEDTLS_AES_SETKEY_ENC_ALT && !MBEDTLS_AES_SETKEY_DEC_ALT */
|
||||||
|
#if !defined(MBEDTLS_AES_DECRYPT_ALT)
|
||||||
|
static unsigned char RSb[256];
|
||||||
|
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
|
||||||
|
#endif /* !MBEDTLS_AES_SETKEY_ENC_ALT && !MBEDTLS_AES_SETKEY_DEC_ALT */
|
||||||
|
|
||||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||||
static uint32_t RT0[256];
|
static uint32_t RT0[256];
|
||||||
|
@ -447,7 +452,9 @@ static void aes_gen_tables(void)
|
||||||
* generate the forward and reverse S-boxes
|
* generate the forward and reverse S-boxes
|
||||||
*/
|
*/
|
||||||
FSb[0x00] = 0x63;
|
FSb[0x00] = 0x63;
|
||||||
|
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||||
RSb[0x63] = 0x00;
|
RSb[0x63] = 0x00;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 1; i < 256; i++) {
|
for (i = 1; i < 256; i++) {
|
||||||
x = pow[255 - log[i]];
|
x = pow[255 - log[i]];
|
||||||
|
@ -459,7 +466,9 @@ static void aes_gen_tables(void)
|
||||||
x ^= y ^ 0x63;
|
x ^= y ^ 0x63;
|
||||||
|
|
||||||
FSb[i] = x;
|
FSb[i] = x;
|
||||||
|
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||||
RSb[x] = (unsigned char) i;
|
RSb[x] = (unsigned char) i;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -481,9 +490,9 @@ static void aes_gen_tables(void)
|
||||||
FT3[i] = ROTL8(FT2[i]);
|
FT3[i] = ROTL8(FT2[i]);
|
||||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||||
x = RSb[i];
|
x = RSb[i];
|
||||||
|
|
||||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
|
||||||
RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
|
RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
|
||||||
((uint32_t) MUL(0x09, x) << 8) ^
|
((uint32_t) MUL(0x09, x) << 8) ^
|
||||||
((uint32_t) MUL(0x0D, x) << 16) ^
|
((uint32_t) MUL(0x0D, x) << 16) ^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue