@@ -76,7 +76,7 @@ typedef uint8_t state_t[4][4];
76
76
// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
77
77
// The numbers below can be computed dynamically trading ROM for RAM -
78
78
// This can be useful in (embedded) bootloader applications, where ROM is often limited.
79
- static const uint8_t sbox [256 ] = {
79
+ static const uint8_t sbox [256 ] PROGMEM = {
80
80
//0 1 2 3 4 5 6 7 8 9 A B C D E F
81
81
0x63 , 0x7c , 0x77 , 0x7b , 0xf2 , 0x6b , 0x6f , 0xc5 , 0x30 , 0x01 , 0x67 , 0x2b , 0xfe , 0xd7 , 0xab , 0x76 ,
82
82
0xca , 0x82 , 0xc9 , 0x7d , 0xfa , 0x59 , 0x47 , 0xf0 , 0xad , 0xd4 , 0xa2 , 0xaf , 0x9c , 0xa4 , 0x72 , 0xc0 ,
@@ -96,7 +96,7 @@ static const uint8_t sbox[256] = {
96
96
0x8c , 0xa1 , 0x89 , 0x0d , 0xbf , 0xe6 , 0x42 , 0x68 , 0x41 , 0x99 , 0x2d , 0x0f , 0xb0 , 0x54 , 0xbb , 0x16 };
97
97
98
98
#if (defined(CBC ) && CBC == 1 ) || (defined(ECB ) && ECB == 1 )
99
- static const uint8_t rsbox [256 ] = {
99
+ static const uint8_t rsbox [256 ] PROGMEM = {
100
100
0x52 , 0x09 , 0x6a , 0xd5 , 0x30 , 0x36 , 0xa5 , 0x38 , 0xbf , 0x40 , 0xa3 , 0x9e , 0x81 , 0xf3 , 0xd7 , 0xfb ,
101
101
0x7c , 0xe3 , 0x39 , 0x82 , 0x9b , 0x2f , 0xff , 0x87 , 0x34 , 0x8e , 0x43 , 0x44 , 0xc4 , 0xde , 0xe9 , 0xcb ,
102
102
0x54 , 0x7b , 0x94 , 0x32 , 0xa6 , 0xc2 , 0x23 , 0x3d , 0xee , 0x4c , 0x95 , 0x0b , 0x42 , 0xfa , 0xc3 , 0x4e ,
@@ -117,7 +117,7 @@ static const uint8_t rsbox[256] = {
117
117
118
118
// The round constant word array, Rcon[i], contains the values given by
119
119
// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
120
- static const uint8_t Rcon [11 ] = {
120
+ static const uint8_t Rcon [11 ] PROGMEM = {
121
121
0x8d , 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 , 0x1b , 0x36 };
122
122
123
123
/*
@@ -137,10 +137,10 @@ static const uint8_t Rcon[11] = {
137
137
/*
138
138
static uint8_t getSBoxValue(uint8_t num)
139
139
{
140
- return sbox[ num] ;
140
+ return pgm_read_byte( sbox + ( num)) ;
141
141
}
142
142
*/
143
- #define getSBoxValue (num ) (sbox[ (num)] )
143
+ #define getSBoxValue (num ) (pgm_read_byte( sbox + (num)) )
144
144
145
145
// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states.
146
146
static void KeyExpansion (uint8_t * RoundKey , const uint8_t * Key )
@@ -194,7 +194,7 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
194
194
tempa [3 ] = getSBoxValue (tempa [3 ]);
195
195
}
196
196
197
- tempa [0 ] = tempa [0 ] ^ Rcon [ i /Nk ] ;
197
+ tempa [0 ] = tempa [0 ] ^ ( pgm_read_byte ( Rcon + ( i /Nk ))) ;
198
198
}
199
199
#if defined(AES256 ) && (AES256 == 1 )
200
200
if (i % Nk == 4 )
@@ -339,10 +339,10 @@ static uint8_t Multiply(uint8_t x, uint8_t y)
339
339
/*
340
340
static uint8_t getSBoxInvert(uint8_t num)
341
341
{
342
- return rsbox[ num] ;
342
+ return pgm_read_byte( rsbox + ( num)) ;
343
343
}
344
344
*/
345
- #define getSBoxInvert (num ) (rsbox[ (num)] )
345
+ #define getSBoxInvert (num ) (pgm_read_byte( rsbox + (num)) )
346
346
347
347
// MixColumns function mixes the columns of the state matrix.
348
348
// The method used to multiply may be difficult to understand for the inexperienced.
0 commit comments