Professional Documents
Culture Documents
Adam Berent
1.0 Preface
The following document provides a detailed and easy to understand explanation of the implementation of the AES (RIJNDAEL) encryption algorithm. The purpose of this paper is to give developers with little or no knowledge of cryptography the ability to implement AES.
2.0 Terminology
There are terms that are frequently used throughout this paper that need to be clarified. Block: AES is a block cipher. This means that the number of bytes that it encrypts is fixed. AES can currently encrypt blocks of 16 bytes at a time; no other block sizes are presently a part of the AES standard. If the bytes being encrypted are larger than the specified block then AES is executed concurrently. This also means that AES has to encrypt a minimum of 16 bytes. If the plain text is smaller than 16 bytes then it must be padded. Simply said the block is a reference to the bytes that are processed by the algorithm. State: Defines the current condition (state) of the block. That is the block of bytes that are currently being worked on. The state starts off being equal to the block, however it changes as each round of the algorithms executes. Plainly said this is the block in progress. XOR Refers to the bitwise operator Exclusive Or. XOR operates on the individual bits in a byte in the following way: 0 1 1 0 XOR XOR XOR XOR 0 0 1 1 = = = = 0 1 0 1
For example the Hex digits D4 XOR FF XOR = 11010100 11111111 00101011 (Hex 2B)
Another interesting property of the XOR operator is that it is reversible. So Hex 2B XOR FF = D4 Most programming languages have the XOR operator built in. Programming Language C C++ C# Java Visual Basic XOR Operator ^ ^ ^ ^ XOR
HEX:
Defines a notation of numbers in base 16. This simply means that; the highest number that can be represented in a single digit is 15, rather than the usual 9 in the decimal (base 10) system. Hex to Decimal table: 0 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 1 1 17 33 49 65 81 97 113 129 145 161 177 193 209 225 241 2 2 18 34 50 66 82 98 114 130 146 162 178 194 210 226 242 3 3 19 35 51 67 83 99 115 131 147 163 179 195 211 227 243 4 4 20 36 52 68 84 100 116 132 148 164 180 196 212 228 244 5 5 21 37 53 69 85 101 117 133 149 165 181 197 213 229 245 6 6 22 38 54 70 86 102 118 134 150 166 182 198 214 230 246 7 7 23 39 55 71 87 103 119 135 151 167 183 199 215 231 247 8 8 24 40 56 72 88 104 120 136 152 168 184 200 216 232 248 9 9 25 41 57 73 89 105 121 137 153 169 185 201 217 233 249 A 10 26 42 58 74 90 106 122 138 154 170 186 202 218 234 250 B 11 27 43 59 75 91 107 123 139 155 171 187 203 219 235 251 C 12 28 44 60 76 92 108 124 140 156 172 188 204 220 236 252 D 13 29 45 61 77 93 109 125 141 157 173 189 205 221 237 253 E 14 30 46 62 78 94 110 126 142 158 174 190 206 222 238 254 F 15 31 47 63 79 95 111 127 143 159 175 191 207 223 239 255
0 1 2 3 4 5 6 7 8 9 A B C D E F
For example using the above table HEX D4 = DEC 212 All of the tables and examples in this paper are written in HEX. The reason for this is that a single digit of Hex represents exactly 4 bits. This means that a single byte can always be represented by 2 HEX digits. This also makes it very useful in creating lookup tables where each HEX digit can represent a table index.
AES as well as most encryption algorithms is reversible. This means that almost the same steps are performed to complete both encryption and decryption in reverse order. The AES algorithm operates on bytes, which makes it simpler to implement and explain. This key is expanded into individual sub keys, a sub keys for each operation round. This process is called KEY EXPANSION, which is described at the end of this document. As mentioned before AES is an iterated block cipher. All that means is that the same operations are performed many times on a fixed number of bytes. These operations can easily be broken down to the following functions: ADD ROUND KEY BYTE SUB SHIFT ROW MIX COLUMN
An iteration of the above steps is called a round. The amount of rounds of the algorithm depends on the key size. Key Size (bytes) 16 24 32 Block Size (bytes) 16 16 16
Rounds 10 12 14
The only exception being that in the last round the Mix Column step is not performed, to make the algorithm reversible during decryption.
4.1 Encryption
AES encryption cipher using a 16 byte key. Round 0 1 2 3 4 5 6 7 8 9 Function Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Key(State) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Shift Row(Byte Sub(State)))
AES encryption cipher using a 24 byte key. Round 0 1 2 3 4 5 6 7 8 9 10 11 Function Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Key(State) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Shift Row(Byte Sub(State)))
AES encryption cipher using a 32 byte key. Round 0 1 2 3 4 5 6 7 8 Function Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Add Round Key(State) Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift Key(Mix Column(Shift
9 10 11 12 13
Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Mix Column(Shift Row(Byte Sub(State)))) Key(Shift Row(Byte Sub(State)))
4.2 Decryption
AES decryption cipher using a 16 byte key. Round 0 1 2 3 4 5 6 7 8 9 Function Add Round Key(State) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Add Round Key(Byte Sub(Shift Row(State)))
AES decryption cipher using a 24 byte key. Round 0 1 2 3 4 5 6 7 8 9 10 11 Function Add Round Key(State) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Add Round Key(Byte Sub(Shift Row(State)))
AES decryption cipher using a 32 byte key. Round 0 1 2 3 4 5 6 7 8 9 10 11 12 13 Function Add Round Key(State) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Mix Column(Add Round Key(Byte Sub(Shift Row(State)))) Add Round Key(Byte Sub(Shift Row(State)))
1
XOR
2
XOR
3
XOR
4
XOR
5
XOR
6
XOR
7
XOR
8
XOR
9
XOR
10
XOR
11
XOR
12
XOR
13
XOR
14
XOR
15
XOR
16
XOR
Exp Key
10
11
12
13
14
15
16
1
XOR
2
XOR
3
XOR
4
XOR
5
XOR
6
XOR
7
XOR
8
XOR
9
XOR
10
XOR
11
XOR
12
XOR
13
XOR
14
XOR
15
XOR
16
XOR
Exp Key
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
And so on for each round of execution. The method for deriving the expanded key is described in section 6.0
During decryption each value in the state is replaced with the corresponding inverse of the SBOX 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 52 7C 54 08 72 6C 90 D0 3A 96 47 FC 1F 60 A0 17 1 09 E3 7B 2E F8 70 D8 2C 91 AC F1 56 DD 51 E0 2B 2 6A 39 94 A1 F6 48 AB 1E 11 74 1A 3E A8 7F 3B 04 3 D5 82 32 66 64 50 00 8F 41 22 71 4B 33 A9 4D 7E 4 30 9B A6 28 86 FD 8C CA 4F E7 1D C6 88 19 AE BA 5 36 2F C2 D9 68 ED BC 3F 67 AD 29 D2 07 B5 2A 77 6 A5 FF 23 24 98 B9 D3 0F DC 35 C5 79 C7 4A F5 D6 7 38 87 3D B2 16 DA 0A 02 EA 85 89 20 31 0D B0 26 8 BF 34 EE 76 D4 5E F7 C1 97 E2 6F 9A B1 2D C8 E1 9 40 8E 4C 5B A4 15 E4 AF F2 F9 B7 DB 12 E5 EB 69 A A3 43 95 A2 5C 46 58 BD CF 37 62 C0 10 7A BB 14 B 9E 44 0B 49 CC 57 05 03 CE E8 0E FE 59 9F 3C 63 C 81 C4 42 6D 5D A7 B8 01 F0 1C AA 78 27 93 83 55 D F3 DE FA 8B 65 8D B3 13 B4 75 18 CD 80 C9 53 21 E D7 E9 C3 D1 B6 9D 45 8A E6 DF BE 5A EC 9C 99 0C F FB CB 4E 25 92 84 06 6B 73 6E 1B F4 5F EF 61 7D
Each row is then moved over (shifted) 1, 2 or 3 spaces over to the right, depending on the row of the state. First row is never shifted Row1 Row2 Row3 Roe4 0 1 2 3
The following table shows how the individual bytes are first arranged in the table and then moved over (shifted). Blocks 16 bytes long: From 1 2 5 9 13 6 10 14 To 1 5 9 13 6 10 14 2
3 4
7 11 15 8 12 16
11 15 16 4
3 7 8 12
During decryption the same process is reversed and all rows are shifted to the left: From 1 2 3 4 5 9 13 6 10 14 7 11 15 8 12 16 To 1 5 9 13 14 2 6 10 11 15 3 7 8 12 16 4
The first result byte is calculated by multiplying 4 values of the state column against 4 values of the first row of the matrix. The result of each multiplication is then XORed to produce 1 Byte. b1 = (b1 * 2) XOR (b2*3) XOR (b3*1) XOR (b4*1) The second result byte is calculated by multiplying the same 4 values of the state column against 4 values of the second row of the matrix. The result of each multiplication is then XORed to produce 1 Byte. b2 = (b1 * 1) XOR (b2*2) XOR (b3*3) XOR (b4*1) The third result byte is calculated by multiplying the same 4 values of the state column against 4 values of the third row of the matrix. The result of each multiplication is then XORed to produce 1 Byte. b3 = (b1 * 1) XOR (b2*1) XOR (b3*2) XOR (b4*3) The fourth result byte is calculated by multiplying the same 4 values of the state column against 4 values of the fourth row of the matrix. The result of each multiplication is then XORed to produce 1 Byte.
b4 = (b1 * 3) XOR (b2*1) XOR (b3*1) XOR (b4*2) This procedure is repeated again with the next column of the state, until there are no more state columns. Putting it all together: The first column will include state bytes 1-4 and will be multiplied against the matrix in the following manner: b1 b2 b3 b4 = = = = (b1 (b1 (b1 (b1 * * * * 2) 1) 1) 3) XOR XOR XOR XOR (b2*3) (b2*2) (b2*1) (b2*1) XOR XOR XOR XOR (b3*1) (b3*3) (b3*2) (b3*1) XOR XOR XOR XOR (b4*1) (b4*1) (b4*3) (b4*2)
(b1= specifies the first byte of the state) The second column will be multiplied against the second row of the matrix in the following manner. b5 b6 b7 b8 = = = = (b5 (b5 (b5 (b5 * * * * 2) 1) 1) 3) XOR XOR XOR XOR (b6*3) (b6*2) (b6*1) (b6*1) XOR XOR XOR XOR (b7*1) (b7*3) (b7*2) (b7*1) XOR XOR XOR XOR (b8*1) (b8*1) (b8*3) (b8*2)
L Table 0 1 2 3 4 5 6 7 8 0 64 7D 65 96 66 7E 2B AF 1 00 04 C2 2F 8F DD 6E 79 58 2 19 E0 1D 8A DB FD 48 0A A8 3 01 0E B5 05 BD 30 C3 15 50 4 32 34 F9 21 36 BF A3 9B F4 5 02 8D B9 0F D0 06 B6 9F EA 6 1A 81 27 E1 CE 8B 1E 5E D6 7 C6 EF 6A 24 94 62 42 CA 74 8 4B 4C 4D 12 13 B3 3A 4E 4F 9 C7 71 E4 F0 5C 25 6B D4 AE A 1B 08 A6 82 D2 E2 28 AC E9 B 68 C8 72 45 F1 98 54 E5 D5 C 33 F8 9A 35 40 22 FA F3 E7 D EE 69 C9 93 46 88 85 73 E6 E DF 1C 09 DA 83 91 3D A7 AD F 03 C1 78 8E 38 10 BA 57 E8
9 A B C D E F
2C 7F CC 97 53 44 67
D7 0C BB B2 39 11 4A
75 F6 3E 87 84 92 ED
7A 6F 5A 90 3C D9 DE
EB 17 FB 61 41 23 C5
16 C4 60 BE A2 20 31
0B 49 B1 DC 6D 2E FE
F5 EC 86 FC 47 89 18
59 D8 3B BC 14 B4 0D
CB 43 52 95 2A 7C 63
5F 1F A1 CF 9E B8 8C
B0 2D 6C CD 5D 26 80
9C A4 AA 37 56 77 C0
A9 76 55 3F F2 99 F7
51 7B 29 5B D3 E3 70
A0 B7 9D D1 AB A5 07
The result of the multiplication is simply the result of a lookup of the L table, followed by the addition of the results, followed by a lookup to the E table. The addition is a regular mathematical addition represented by +, not a bitwise AND. All numbers being multiplied using the Mix Column function converted to HEX will form a maximum of 2 digit Hex number. We use the first digit in the number on the vertical index and the second number on the horizontal index. If the value being multiplied is composed of only one digit we use 0 on the vertical index. For example if the two Hex values being multiplied are AF * 8 we first lookup L (AF) index which returns B7 and then lookup L (08) which returns 4B. Once the L table lookup is complete we can then simply add the numbers together. The only trick being that if the addition result is greater then FF we subtract FF from the addition result. For example AF+B7= 166. Because 166 > FF, we perform: 166-FF which gives us 67. The last step is to look up the addition result on the E table. Again we take the first digit to look up the vertical index and the second digit to look up the horizontal index. For example E(67)=F0 There fore the result of multiplying AF * 8 over a Galois Field is F0 Two last exceptions are that: Any number multiplied by one is equal to its self and does not need to go through the above procedure. For example: FF * 1 = FF Any number multiplied by zero equals zero
Other then the change to the matrix table the function performs the same steps as during encryption.
Output(1)
= = = = = = = = = = = =
(D4 * 1) XOR (BF*2) XOR (5D*3) XOR (30*1) D4 XOR E(L(BF)+L(02)) XOR E(L(5D)+L(03)) XOR 30 D4 XOR E(9D+19) XOR E(88+01) XOR 30 D4 XOR E(B6) XOR E(89) XOR 30 D4 XOR 65 XOR E7 XOR 30 66 (D4 * 1) XOR (BF*1) XOR (5D*2) XOR (30*3) D4 XOR BF XOR E(L(5D)+L(02)) XOR E(L(30)+L(03)) D4 XOR BF XOR E(88+19) XOR E(65+01) D4 XOR BF XOR E(A1) XOR E(66) D4 XOR BF XOR BA XOR 50 81
Output(2)
Output(3)
= (D4 * 3) XOR (BF*1) XOR (5D*1) XOR (30*2) = E(L(D4)+L(3)) XOR BF XOR 5D XOR E(L(30)+L(02)) = E(41+01) XOR BF XOR 5D XOR E(65+19) = E(42) XOR BF XOR 5D XOR E(7E) = 67 XOR BF XOR 5D XOR 60 = E5
Output(1)
Output(2)
Output(3)
10
16 * (number of rounds + 1). The 16 in the above function is actually the size of the block in bytes. This provides key material for every byte in the block during every round +1 Key Size (bytes) 16 24 32 Block Size (bytes) 16 16 16 Expanded Key (bytes) 176 208 240
Since the key size is much smaller than the size of the sub keys, the key is actually stretched out to provide enough key space for the algorithm. The key expansion routine executes a maximum of 4 consecutive functions. These functions are: ROT WORD SUB WORD RCON EK K An iteration of the above steps is called a round. The amount of rounds of the key expansion algorithm depends on the key size. Key Size (bytes) 16 24 32 Block Size (bytes) 16 16 16 Expansion Algorithm Rounds 44 52 60 Expanded Bytes / Round 4 4 4 Rounds Key Copy 4 6 8 Rounds Key Expansion 40 46 52 Expanded Key (bytes) 176 208 240
The first bytes of the expanded key are always equal to the key. If the key is 16 bytes long the first 16 bytes of the expanded key will be the same as the original key. If the key size is 32 bytes then the first 32 bytes of the expanded key will be the same as the original key. Each round adds 4 bytes to the Expanded Key. With the exception of the first rounds each round also takes the previous rounds 4 bytes as input operates and returns 4 bytes. One more important note is that not all of the 4 functions are always called in each round. The algorithm only calls all 4 of the functions every: 4 Rounds for a 16 byte Key 6 Rounds for a 24 byte Key 8 Rounds for a 32 byte Key The rest of the rounds only a K function result is XORed with the result of the EK function. There is an exception of this rule where if the key is 32 bytes long an additional call to the Sub Word function is called every 8 rounds starting on the 13th round.
This does a circular shift on 4 bytes similar to the Shift Row Function.
1,2,3,4 to 2,3,4,1
11
Sub Word (4 bytes) This step applies the S-box value substitution as described in Bytes Sub function to each of the 4 bytes in the argument. Rcon((Round/(KeySize/4))-1) This function returns a 4 byte value based on the following table Rcon(0) Rcon(1) Rcon(2) Rcon(3) Rcon(4) Rcon(5) Rcon(6) Rcon(7) Rcon(8) Rcon(9) Rcon(10) Rcon(11) Rcon(12) Rcon(13) Rcon(14) = = = = = = = = = = = = = = = 01000000 02000000 04000000 08000000 10000000 20000000 40000000 80000000 1B000000 36000000 6C000000 D8000000 AB000000 4D000000 9A000000
For example for a 16 byte key Rcon is first called in the 4th round (4/(16/4))-1=0 In this case Rcon will return 01000000 For a 24 byte key Rcon is first called in the 6th round (6/(24/4))-1=0 In this case Rcon will also return 01000000 EK(Offset) EK function returns 4 bytes of the Expanded Key after the specified offset. For example if offset is 0 then EK will return bytes 0,1,2,3 of the Expanded Key K(Offset) K function returns 4 bytes of the Key after the specified offset. For example if offset is 0 then K will return bytes 0,1,2,3 of the Expanded Key
12
Notice that most numbers that change in following tables match the current round number. This makes implementation in code much easier as these numbers can easily be replaced with loop variables. 16 byte Key Expansion Each round (except rounds 0, 1, 2 and 3) will take the result of the previous round and produce a 4 byte result for the current round. Notice the first 4 rounds simply copy the total of 16 bytes of the key Round 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 Expanded Key Bytes
0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97 101 105 109 113 117 121 125 129 133 137 141 145 149 153 157 161 165 169 173 2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 67 71 75 79 83 87 91 95 99 103 107 111 115 119 123 127 131 135 139 143 147 151 155 159 163 167 171 175
Function
K(0) K(4) K(8) K(12) Sub Word(Rot Word(EK((4-1)*4))) XOR Rcon((4/4)-1) XOR EK((4-4)*4) EK((5-1)*4)XOR EK((5-4)*4) EK((6-1)*4)XOR EK((6-4)*4) EK((7-1)*4)XOR EK((7-4)*4) Sub Word(Rot Word(EK((8-4)*4))) XOR Rcon((8/4)-1) XOR EK((8-4)*4) EK((8-1)*4)XOR EK((9-4)*4) EK((10-1)*4)XOR EK((10-4)*4) EK((11-1)*4)XOR EK((11-4)*4) Sub Word(Rot Word(EK((12-4)*4))) XOR Rcon((12/4)-1) XOR EK((12-4)*4) EK((13-1)*4)XOR EK((13-4)*4) EK((14-1)*4)XOR EK((14-4)*4) EK((15-1)*4)XOR EK((15-4)*4) Sub Word(Rot Word(EK((16-4)*4))) XOR Rcon((16/4)-1) XOR EK((16-4)*4) EK((17-1)*4)XOR EK((17-4)*4) EK((18-1)*4)XOR EK((18-4)*4) EK((19-1)*4)XOR EK((19-4)*4) Sub Word(Rot Word(EK((20-4)*4))) XOR Rcon((20/4)-1) XOR EK((20-4)*4) EK((21-1)*4)XOR EK((21-4)*4) EK((22-1)*4)XOR EK((22-4)*4) EK((23-1)*4)XOR EK((23-4)*4) Sub Word(Rot Word(EK((24-4)*4))) XOR Rcon((24/4)-1) XOR EK((24-4)*4) EK((25-1)*4)XOR EK((25-4)*4) EK((26-1)*4)XOR EK((26-4)*4) EK((27-1)*4)XOR EK((27-4)*4) Sub Word(Rot Word(EK((28-4)*4))) XOR Rcon((28/4)-1) XOR EK((28-4)*4) EK((29-1)*4)XOR EK((29-4)*4) EK((30-1)*4)XOR EK((30-4)*4) EK((31-1)*4)XOR EK((31-4)*4) Sub Word(Rot Word(EK((32-4)*4))) XOR Rcon((32/4)-1) XOR EK((32-4)*4) EK((33-1)*4)XOR EK((33-4)*4) EK((34-1)*4)XOR EK((34-4)*4) EK((35-1)*4)XOR EK((35-4)*4) Sub Word(Rot Word(EK((36-4)*4))) XOR Rcon((36/4)-1) XOR EK((36-4)*4) EK((37-1)*4)XOR EK((37-4)*4) EK((38-1)*4)XOR EK((38-4)*4) EK((39-1)*4)XOR EK((39-4)*4) Sub Word(Rot Word(EK((40-4)*4))) XOR Rcon((40/4)-1) XOR EK((40-4)*4) EK((41-1)*4)XOR EK((41-4)*4) EK((42-1)*4)XOR EK((42-4)*4) EK((43-1)*4)XOR EK((43-4)*4)
24 byte Key Expansion Each round (except rounds 0, 1, 2, 3, 4 and 5) will take the result of the previous round and produce a 4 byte result for the current round. Notice the first 6 rounds simply copy the total of 24 bytes of the key.
13
Round 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
Function
K(0) K(4) K(8) K(12) K(16) K(20) Sub Word(Rot Word(EK((6-1)*4))) XOR Rcon((6/6)-1) XOR EK((6-6)*4) EK((7-1)*4)XOR EK((7-6)*4) EK((8-1)*4)XOR EK((8-6)*4) EK((9-1)*4)XOR EK((9-6)*4) EK((10-1)*4)XOR EK((10-6)*4) EK((11-1)*4)XOR EK((11-6)*4) Sub Word(Rot Word(EK((12-1)*4))) XOR Rcon((12/6)-1) XOR EK((12-6)*4) EK((13-1)*4)XOR EK((13-6)*4) EK((14-1)*4)XOR EK((14-6)*4) EK((15-1)*4)XOR EK((15-6)*4) EK((16-1)*4)XOR EK((16-6)*4) EK((17-1)*4)XOR EK((17-6)*4) Sub Word(Rot Word(EK((18-1)*4))) XOR Rcon((18/6)-1) XOR EK((18-6)*4) EK((19-1)*4)XOR EK((19-6)*4) EK((20-1)*4)XOR EK((20-6)*4) EK((21-1)*4)XOR EK((21-6)*4) EK((22-1)*4)XOR EK((22-6)*4) EK((23-1)*4)XOR EK((23-6)*4) Sub Word(Rot Word(EK((24-1)*4))) XOR Rcon((24/6)-1) XOR EK((24-6)*4) EK((25-1)*4)XOR EK((25-6)*4) EK((26-1)*4)XOR EK((26-6)*4) EK((27-1)*4)XOR EK((27-6)*4) EK((28-1)*4)XOR EK((28-6)*4) EK((29-1)*4)XOR EK((29-6)*4) Sub Word(Rot Word(EK((30-1)*4))) XOR Rcon((30/6)-1) XOR EK((30-6)*4) EK((31-1)*4)XOR EK((31-6)*4) EK((32-1)*4)XOR EK((32-6)*4) EK((33-1)*4)XOR EK((33-6)*4) EK((34-1)*4)XOR EK((34-6)*4) EK((35-1)*4)XOR EK((35-6)*4) Sub Word(Rot Word(EK((36-1)*4))) XOR Rcon((36/6)-1) XOR EK((36-6)*4) EK((37-1)*4)XOR EK((37-6)*4) EK((38-1)*4)XOR EK((38-6)*4) EK((39-1)*4)XOR EK((39-6)*4) EK((40-1)*4)XOR EK((40-6)*4) EK((41-1)*4)XOR EK((41-6)*4) Sub Word(Rot Word(EK((42-1)*4))) XOR Rcon((42/6)-1) XOR EK((42-6)*4) EK((43-1)*4)XOR EK((43-6)*4) EK((44-1)*4)XOR EK((44-6)*4) EK((45-1)*4)XOR EK((45-6)*4) EK((46-1)*4)XOR EK((46-6)*4) EK((47-1)*4)XOR EK((47-6)*4) Sub Word(Rot Word(EK((48-1)*4))) XOR Rcon((48/6)-1) XOR EK((48-6)*4) EK((49-1)*4)XOR EK((49-6)*4) EK((50-1)*4)XOR EK((50-6)*4) EK((51-1)*4)XOR EK((51-6)*4)
32 byte Key Expansion Each round (except rounds 0, 1, 2, 3, 4, 5, 6 and 7) will take the result of the previous round and produce a 4 byte result for the current round. Notice the first 8 rounds simply copy the total of 32 bytes of the key.
14
Roun d 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
Function
K(0) K(4) K(8) K(12) K(16) K(20) K(24) K(28) Sub Word(Rot Word(EK((8-1)*4))) XOR Rcon((8/8)-1) XOR EK((8-8)*4) EK((9-1)*4)XOR EK((9-8)*4) EK((10-1)*4)XOR EK((10-8)*4) EK((11-1)*4)XOR EK((11-8)*4) Sub Word(EK((12-1)*4))XOR EK((12-8)*4) EK((13-1)*4)XOR EK((13-8)*4) EK((14-1)*4)XOR EK((14-8)*4) EK((15-1)*4)XOR EK((15-8)*4) Sub Word(Rot Word(EK((16-1)*4))) XOR Rcon((16/8)-1) XOR EK((16-8)*4) EK((17-1)*4)XOR EK((17-8)*4) EK((18-1)*4)XOR EK((18-8)*4) EK((19-1)*4)XOR EK((19-8)*4) Sub Word(EK((20-1)*4))XOR EK((20-8)*4) EK((21-1)*4)XOR EK((21-8)*4) EK((22-1)*4)XOR EK((22-8)*4) EK((23-1)*4)XOR EK((23-8)*4) Sub Word(Rot Word(EK((24-1)*4))) XOR Rcon((24/8)-1) XOR EK((24-8)*4) EK((25-1)*4)XOR EK((25-8)*4) EK((26-1)*4)XOR EK((26-8)*4) EK((27-1)*4)XOR EK((27-8)*4) Sub Word(EK((28-1)*4))XOR EK((28-8)*4) EK((29-1)*4)XOR EK((29-8)*4) EK((30-1)*4)XOR EK((30-8)*4) EK((31-1)*4)XOR EK((31-8)*4) Sub Word(Rot Word(EK((32-1)*4))) XOR Rcon((32/8)-1) XOR EK((32-8)*4) EK((33-1)*4)XOR EK((33-8)*4) EK((34-1)*4)XOR EK((34-8)*4) EK((35-1)*4)XOR EK((35-8)*4) Sub Word(EK((36-1)*4))XOR EK((36-8)*4) EK((37-1)*4)XOR EK((37-8)*4) EK((38-1)*4)XOR EK((38-8)*4) EK((39-1)*4)XOR EK((39-8)*4) Sub Word(Rot Word(EK((40-1)*4))) XOR Rcon((40/8)-1) XOR EK((40-8)*4) EK((41-1)*4)XOR EK((41-8)*4) EK((42-1)*4)XOR EK((42-8)*4) EK((43-1)*4)XOR EK((43-8)*4) Sub Word(EK((44-1)*4))XOR EK((44-8)*4) EK((45-1)*4)XOR EK((45-8)*4) EK((46-1)*4)XOR EK((46-8)*4) EK((47-1)*4)XOR EK((47-8)*4) Sub Word(Rot Word(EK((48-1)*4))) XOR Rcon((48/8)-1) XOR EK((48-8)*4) EK((49-1)*4)XOR EK((49-8)*4) EK((50-1)*4)XOR EK((50-8)*4) EK((51-1)*4)XOR EK((51-8)*4) Sub Word(EK((52-1)*4))XOR EK((52-8)*4) EK((53-1)*4)XOR EK((53-8)*4) EK((54-1)*4)XOR EK((54-8)*4) EK((55-1)*4)XOR EK((55-8)*4) Sub Word(Rot Word(EK((56-1)*4))) XOR Rcon((56/8)-1) XOR EK((56-8)*4) EK((57-1)*4)XOR EK((57-8)*4) EK((58-1)*4)XOR EK((58-8)*4)
15
59
EK((59-1)*4)XOR EK((59-8)*4)
7.0 Conclusion
The above document provides you with only the basic information needed to implement the AES encryption algorithm. The mathematics and design reasons behind AES were purposely left out. For more information on these topics I suggest you visit the Rijndael Home Page at: http://www.esat.kuleuven.ac.be/~rijmen/rijndael/ This document was written by Adam Berent and can be distributed without copyright as long as proper credit is given. If you would like to contact me feel free to do so at aberent@abisoft.net or visit www.abisoft.net.
8.0 References
FIPS 197, "Advanced Encryption Standard" Advanced Encryption Standard (AES) http://www.ratchkov.com/vpn/aes/aes.html RIJNDAEL http://www.cs.mcgill.ca/~kaleigh/computers/crypto_rijndael.html The Laws of Cryptography http://www.cs.utsa.edu/~wagner/laws/
16