diff --git a/aes-internal.h b/aes-internal.h index 081f8864c983aac8ddfde8ace5857b692e2107b9..79d34e44e500099c110afad66937382965020d4b 100644 --- a/aes-internal.h +++ b/aes-internal.h @@ -28,6 +28,11 @@ #include "aes.h" +/* Define to use only small tables. */ +#ifndef AES_SMALL +# define AES_SMALL 1 +#endif + /* Macros */ #define ROTBYTE(x) (((x) >> 8) | (((x) & 0xff) << 24)) #define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff)) @@ -37,13 +42,20 @@ ((box)[(((x) >> 24) & 0xff)] << 24)) /* Don't pollute global namespace too much */ -#define dtbl _aes_dtbl +#if AES_SMALL +# define dtbl _aes_dtbl_small +# define _AES_TABLE_SIZE 1 +#else +# define dtbl _aes_dtbl +# define _AES_TABLE_SIZE 4 +#endif + #define itbl _aes_itbl #define sbox _aes_sbox #define isbox _aes_isbox /* Internal tables */ -extern const uint32_t dtbl[4][0x100]; +extern const uint32_t dtbl[_AES_TABLE_SIZE][0x100]; extern const uint32_t itbl[]; extern const uint8_t sbox[0x100]; extern const uint8_t isbox[0x100]; diff --git a/aes-tables.c b/aes-tables.c index 27b1f96403afd06e3562c5f69ff058594947f8b9..1029c5606ba9800d9d4c4ae246ca189e17991c83 100644 --- a/aes-tables.c +++ b/aes-tables.c @@ -39,7 +39,7 @@ * consistent with the row numbering. */ const uint32_t -dtbl[4][0x100] = +dtbl[_AES_TABLE_SIZE][0x100] = { { 0xa56363c6,0x847c7cf8,0x997777ee,0x8d7b7bf6, @@ -106,7 +106,9 @@ dtbl[4][0x100] = 0xdabfbf65,0x31e6e6d7,0xc6424284,0xb86868d0, 0xc3414182,0xb0999929,0x772d2d5a,0x110f0f1e, 0xcbb0b07b,0xfc5454a8,0xd6bbbb6d,0x3a16162c, - },{ + }, +#if !AES_SMALL + { 0x6363c6a5,0x7c7cf884,0x7777ee99,0x7b7bf68d, 0xf2f2ff0d,0x6b6bd6bd,0x6f6fdeb1,0xc5c59154, 0x30306050,0x01010203,0x6767cea9,0x2b2b567d, @@ -302,6 +304,7 @@ dtbl[4][0x100] = 0x82c34141,0x29b09999,0x5a772d2d,0x1e110f0f, 0x7bcbb0b0,0xa8fc5454,0x6dd6bbbb,0x2c3a1616, }, +#endif /* !AES_SMALL */ }; /* These tables combine both the S-boxes and the mixcolumn