A step-by-step rebuild of the lecture's AES section. Students compute SubBytes, ShiftRows, a MixColumns column and the key schedule's g function by hand on the FIPS-197 example, watch one flipped bit spread through two rounds, and see why removing any one step breaks the cipher, before covering decryption and how AES fails in practice.
Subject: Computer Security · 74 slides · code lesson
Open the interactive version of this deck
Title
Crypto Lecture 5
SubBytes, ShiftRows, MixColumns, AddRoundKey and the key schedule, computed by hand on the standard's own example
Section
Why a new standard, and the whole cipher on one page
Objectives
This lesson opens AES the way the lecture opened MD5: one box at a time, with real bytes from the standard's worked example, so that every number on the slides is one you could reproduce with a pencil.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes
Warm-up
The last part of the lecture took DES apart. Before meeting its replacement, pull the key facts back out of memory.
Discussion prompt
How long is a DES key, how many keys does that give, and why was that a problem by the late 1990s?
Hint: Count the key bits, then think about what hardware could do by 1998.
Answer:
A DES key is 56 bits, so there are 2 to the power 56 keys, about 7.2 times 10 to the 16. That sounded like a lot in 1977. In 1998 the EFF built a machine, Deep Crack, that searched the key space in about 56 hours.
Nothing was wrong with the Feistel design itself; the key was simply too short to survive cheaper hardware. A replacement needed a much longer key and a larger block, and it needed to earn trust in public, which is how AES was chosen.
Concept
In 1997 NIST asked the world for a replacement for DES. Fifteen candidate designs were submitted and attacked in public for three years. The winner, Rijndael by the Belgian cryptographers Joan Daemen and Vincent Rijmen, became the Advanced Encryption Standard in 2001.
| DES | AES | |
|---|---|---|
| standard since | 1977 | 2001, after an open competition with 15 candidates |
| designed by | IBM, with changes by the NSA | Daemen and Rijmen, as Rijndael |
| block size (bits encrypted at once) | 64 bits | 128 bits |
| key size | 56 bits | 128, 192 or 256 bits |
| rounds | 16 | 10, 12 or 14 |
The process matters as much as the design. Nobody had to trust the winner on faith: every candidate's internals were public, and the best cryptanalysts in the world spent years trying to break them. From here on we use AES-128, the version with a 128-bit key and ten rounds.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes
Estimation
DES has 2 to the power 56 keys. AES-128 has 2 to the power 128.
Predict first
How many times more AES-128 keys are there than DES keys?
Correct: About 4.7 times 10 to the 21 times as many
Why: Dividing the counts gives 2 to the power 128 minus 56, which is 2 to the 72, about 4.7 times 10 to the 21. If Deep Crack's 56 hours were sped up a billion times, searching AES-128 would still take on the order of 30 billion years. Adding bits multiplies the work; it does not add to it.
Concept
AES treats the 16 plaintext bytes as a 4 by 4 grid called the state. It XORs the key into the state once, then runs ten rounds. Every round applies the same four steps, and every round uses its own round key, made from the original key by the key schedule.
Figure (svg): The AES pipeline: plaintext, XOR with K0, then a round of SubBytes, ShiftRows, MixColumns and AddRoundKey repeated ten times, with a key schedule producing K0 to K10 on the side, then ciphertext
| step | what it does | uses the key? |
|---|---|---|
| SubBytes | replaces each byte using one fixed table | no |
| ShiftRows | rotates row r left by r places | no |
| MixColumns | mixes the four bytes of each column (skipped in round 10) | no |
| AddRoundKey | XORs in the round key Kr | yes, the only step that does |
Each numbered box gets its own slides next. Keep this map in view: whenever a detail feels lost, ask which box it belongs to and what that box is for.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-map
Ranking
Use the map. Order the operations from the plaintext to the end of round 1.
Put in order
Why: The key goes in once before any round, then every round runs SubBytes, ShiftRows, MixColumns, AddRoundKey in that order. Rounds 2 to 9 repeat the same four steps with K2 to K9, and round 10 drops MixColumns.
Matching
Each step looks simple on its own. Match each one to the job it does for the cipher as a whole; the second half of the lesson shows why each job is needed.
Match the pairs
Why: SubBytes provides non-linearity, ShiftRows and MixColumns together provide diffusion (a change anywhere spreads everywhere), and AddRoundKey is what makes the result depend on the key. Remove any one and a different property is lost.
Section
Real bytes from the FIPS-197 example
Concept
Our running example is the one printed in the standard itself: plaintext 00 11 22 ... ff and key 00 01 02 ... 0f. AES writes the 16 bytes into the 4 by 4 grid column by column: the first four bytes fill column 0, the next four fill column 1, and so on.
Figure (svg): Three 4 by 4 grids: the plaintext 00 to ff filled column by column, XOR the key grid 00 to 0f, equals the state 00 10 20 ... f0; one byte is worked in bits, 11 xor 01 = 10
Before round 1, every byte of the grid is XORed with the key byte in the same position. This first round key, K0, is simply the key itself. With this key and plaintext the result is especially tidy: 00 10 20 30 down column 0, then 40 50 60 70, and so on.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-state
Fill the middle
Column 1 of the plaintext grid is 44 55 66 77 and column 1 of the key grid is 04 05 06 07. Write each result in lowercase hex.
Fill in the blanks
44 xor 04 = 40
55 xor 05 = 50
66 xor 06 = 60
77 xor 07 = 70
Why: XOR works bit by bit with no carries. 55 is 0101 0101 and 05 is 0000 0101, so the low four bits cancel and leave 0101 0000 = 50. The same happens for 66 xor 06 = 60 and 77 xor 07 = 70: in this example each key byte exactly cancels the low hex digit of its plaintext byte.
Concept
SubBytes replaces each byte of the state with its entry in one fixed 256-entry table, the AES S-box. It is the same idea as the DES S-boxes, but with 8 bits in and 8 bits out. The first hex digit of the byte picks the row of the table and the second picks the column.
Figure (svg): Before and after grids for SubBytes; the byte 10 is looked up at row 1, column 0 of the S-box, giving ca
| byte | S-box row, column | result |
|---|---|---|
| 00 | row 0, column 0 | 63 |
| 10 | row 1, column 0 | ca |
| 20 | row 2, column 0 | b7 |
| 30 | row 3, column 0 | 04 |
Three facts matter. Every byte is replaced on its own, with the same table. The table is one-to-one, so the step can be undone, which AES needs because it has no Feistel structure. And it is the only non-linear step in the whole cipher: the table follows no simple algebraic rule, so the S-box of an XOR is not the XOR of the S-boxes.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-sub
Faded example
Column 0 of the AES S-box, read down rows 4 to 7, holds 09, 53, d0, 51. Our state's column 1 is 40 50 60 70, so each byte uses column 0 of the table. The first lookup is done.
Fill in the blanks
S[40] = 09
S[50] = 53
S[60] = d0
S[70] = 51
Why: For 50 the first digit 5 picks row 5 and the second digit 0 picks column 0, which holds 53; likewise S[60] = d0 and S[70] = 51. After SubBytes the whole state is 63 ca b7 04 | 09 53 d0 51 | cd 60 e0 e7 | ba 70 e1 8c, which matches the standard.
Two truths and a lie
Each statement is about the S-box used by SubBytes.
Eliminate the wrong options
Which statement is the myth?
Survives elimination: m
Why: The S-box is printed in the standard for everyone to read; Kerckhoffs's principle says the only secret is the key. SubBytes contributes non-linearity, not secrecy. Its table was chosen so that no simple equation relates inputs and outputs.
Concept
ShiftRows rotates each row of the state to the left. Row 0 stays where it is, row 1 moves one place, row 2 two places and row 3 three places. Bytes that fall off the left edge come back on the right.
Figure (svg): Before and after grids for ShiftRows; row 0 unchanged, rows 1 to 3 rotated left by 1, 2 and 3 places, with wrapped bytes in red
Who decides the amounts? The standard does. Row r always moves r places, for every key and every round; no key is involved. On its own this step looks like it achieves nothing, since every byte keeps its value. Its purpose shows up on the MixColumns slides: after ShiftRows, the four bytes in each column came from four different columns.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-shift
Fill the middle
After SubBytes, row 2 of the state reads b7 d0 e0 e1 and row 3 reads 04 51 e7 8c (left to right). Shift row 2 left by two places and row 3 left by three.
Fill in the blanks
row 2: b7 d0 e0 e1 -> e0 e1 b7 d0
row 3: 04 51 e7 8c -> 8c 04 51 e7
Why: Shifting left by two moves the first two bytes, b7 d0, to the end, giving e0 e1 b7 d0. Shifting left by three is the same as shifting right by one, so the last byte 8c comes to the front: 8c 04 51 e7. Together with rows 0 and 1, the new columns read 63 53 e0 8c, 09 60 e1 04, cd 70 b7 51 and ba ca d0 e7.
Prediction
After ShiftRows, column 0 holds 63 53 e0 8c.
Predict first
From how many different columns of the state before ShiftRows did these four bytes come?
Correct: Four: one from each column
Why: 63 stayed in column 0 (row 0 does not move), 53 came from column 1, e0 from column 2 and 8c from column 3. Every column after ShiftRows gathers one byte from each old column, which is exactly what MixColumns needs in order to spread information across the whole state.
Concept
MixColumns turns the four bytes of a column into four new bytes, each one a mix of all four old ones. Ordinary arithmetic would overflow a byte, so AES uses byte arithmetic that always stays inside 8 bits. Only three tools are needed: add, double and triple.
| tool | rule | example |
|---|---|---|
| add | XOR, bit by bit, no carries | 63 + 53 = 0110 0011 xor 0101 0011 = 0011 0000 = 30 |
| double | shift the bits left by one | 2*63: 0110 0011 becomes 1100 0110 = c6 |
| double, with overflow | if a 1 falls off the left, drop it and XOR 1b | 2*e0: 1100 0000 xor 0001 1011 = 1101 1011 = db |
| triple | double, then XOR the byte itself | 353 = 253 xor 53 = a6 xor 53 = f5 |
Why XOR 1b after an overflow? The bit that fell off stands for a value one byte cannot hold, and the standard folds it back in by XORing the fixed byte 1b. This keeps every product inside one byte and, just as importantly, keeps the arithmetic reversible, so MixColumns can be undone.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-bytes
Faded example
Double and triple some bytes. 53 is 0101 0011 and e0 is 1110 0000. The first line is done.
Fill in the blanks
2*63 = c6
2*53 = a6 # shift left, no overflow
353 = f5 # 253 xor 53
2*e0 = db # shift left, a 1 falls off: xor 1b
Why: Shifting 0101 0011 left gives 1010 0110 = a6, with no bit falling off. Tripling is a6 xor 53 = 1111 0101 = f5. Shifting e0 = 1110 0000 left gives 1100 0000 with a 1 falling off the top, so XOR 1b: 1100 0000 xor 0001 1011 = 1101 1011 = db.
Edge cases
Suppose doubling simply threw away the bit that falls off, without XORing 1b.
Discussion prompt
Doubling 80 and doubling 00 would then both give 00. Why is that a disaster for MixColumns, and what does XORing 1b fix?
Hint: Can two different inputs be sent to the same output?
Answer:
If two different bytes double to the same result, doubling is no longer one-to-one, and information is destroyed. MixColumns built on it could send two different columns to the same output, and then decryption could not tell which one was meant.
XORing 1b makes doubling a permutation of the 256 byte values: 80 doubles to 1b, not 00. Byte arithmetic with this rule is a finite field with 256 elements, where every non-zero byte can be divided by, which is what lets the inverse MixColumns exist.
Worked example
After ShiftRows, column 0 is 63 53 e0 8c. Each new byte is one row of a fixed matrix times this column: multiply each old byte by 1, 2 or 3 using the byte tools, then XOR the four products.
Row 0 is 02 03 01 01
Why: 263 xor 353 xor e0 xor 8c = c6 xor f5 xor e0 xor 8c = 5f
Row 1 is 01 02 03 01
Why: 63 xor 253 xor 3e0 xor 8c = 63 xor a6 xor 3b xor 8c = 72
Row 2 is 01 01 02 03
Why: 63 xor 53 xor 2e0 xor 38c = 63 xor 53 xor db xor 8f = 64
Row 3 is 03 01 01 02
Why: 363 xor 53 xor e0 xor 28c = a5 xor 53 xor e0 xor 03 = 15
Verify: compare with the standard
Why: The new column 0 is 5f 72 64 15, exactly the first four bytes of the state after MixColumns printed in FIPS-197 appendix C.1.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-mix
Picture it
Lay the computation out as a matrix times a column. Each input byte has its own colour, and each output byte uses all four colours.
Figure (svg): The fixed matrix with rows 02 03 01 01, 01 02 03 01, 01 01 02 03, 03 01 01 02, times column 63 53 e0 8c, equals 5f 72 64 15, with the four XOR sums written beside each output byte
The other three columns are mixed the same way, with the same matrix. ShiftRows spreads bytes across columns and MixColumns mixes each column, so after two rounds every output byte depends on every input byte.
Faded example
Column 1 after ShiftRows is 09 60 e1 04. Useful products: 209 = 12, 360 = a0, 260 = c0, 3e1 = 38. Row 0 is done for you.
Fill in the blanks
row 0: 209 xor 360 xor e1 xor 04 = 12 xor a0 xor e1 xor 04 = 57
row 1: 09 xor 260 xor 3e1 xor 04 = 09 xor c0 xor 38 xor 04 = f5
Why: Row 1 of the matrix is 01 02 03 01, so the products are 09, 260 = c0, 3e1 = 38 and 04. XOR them in any order: 09 xor c0 = c9, c9 xor 38 = f1, f1 xor 04 = f5. The full new column 1 is 57 f5 bc 92, matching the standard.
Concept
AddRoundKey XORs every byte of the state with the byte in the same position of this round's key. In round 1 that is K1, which the key schedule will produce in Part 3.
Figure (svg): The state after MixColumns XOR round key K1 equals the state after round 1; one byte worked in bits, 5f xor d6 = 89
It is the only step in a round that uses the key, which is why every round needs a different round key. And because XOR undoes itself, decryption removes a round key simply by XORing the same key again.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-ark
Fill the middle
Column 0 after MixColumns is 5f 72 64 15 and the first word of K1 is d6 aa 74 fd. The first byte is done.
Fill in the blanks
5f xor d6 = 89
72 xor aa = d8
64 xor 74 = 10
15 xor fd = e8
Why: 72 = 0111 0010 and aa = 1010 1010 give 1101 1000 = d8. 64 = 0110 0100 and 74 = 0111 0100 give 0001 0000 = 10. 15 = 0001 0101 and fd = 1111 1101 give 1110 1000 = e8. Column 0 of the state after round 1 is 89 d8 10 e8, as the standard prints.
Pattern
Everything in Part 2, as a procedure you can run by hand or recognise in code.
Three of the four steps are fixed public operations. Only the XORs with round keys depend on the secret, which is why the key schedule, next, matters so much.
Check
Solve it on paper before you click.
Check your understanding
In one round of AES, which steps depend on the key?
Answer: A
Why: SubBytes, ShiftRows and MixColumns are fixed by the standard and identical for every key. The secret enters a round only through AddRoundKey, as the XOR with the round key Kr.
Section
One 16-byte key becomes eleven round keys
Concept
The key is written into a 4 by 4 grid column by column, exactly like the message. One column of the key, 4 bytes, is called a word: w0 = 00 01 02 03, w1 = 04 05 06 07, w2 = 08 09 0a 0b, w3 = 0c 0d 0e 0f. Those four words are K0.
The key schedule keeps making one new word at a time until it has 44 words. Every four consecutive words form one round key.
| round key | words | used in |
|---|---|---|
| K0 | w0 to w3, the key itself | the XOR before round 1 |
| K1 | w4 to w7 | AddRoundKey in round 1 |
| K2 | w8 to w11 | AddRoundKey in round 2 |
| ... | ... | ... |
| K10 | w40 to w43 | AddRoundKey in round 10 |
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-keys
Estimation
Eleven round keys of 16 bytes each, made from one 16-byte key.
Predict first
How many bytes of round-key material does one AES-128 encryption use, and how many of them are actually secret information?
Correct: 176 bytes in total, but only 16 bytes of secret information
Why: 44 words of 4 bytes is 176 bytes. But every word is computed from the 16-byte key by public rules, so there are still only 2 to the power 128 possibilities in total. The schedule stretches the key; it cannot add secrecy that was not there.
Concept
Arrange the 44 words in rows of four, one row per round key. Then the rule of the key schedule is a picture: every new word is the word directly above it XOR the word just to its left.
Figure (svg): Rows of four words for K0, K1 and K2 with arrows from the word above and the word to the left; the first word of each row receives the last word of the row above through g
The first word of a row has nothing to its left, so it uses the last word of the row above, sent first through a scrambling function called g. In index form: w[i] = w[i-4] xor w[i-1], except that when i is a multiple of 4, w[i-1] is replaced by g(w[i-1]).
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-keys-picture
Fill the middle
w4 = d6aa74fd is given (it needs g, which comes next). The other three words of K1 use only XOR: each is the word above XOR the word to its left.
Fill in the blanks
w5 = w1 xor w4 = 04050607 xor d6aa74fd = d2af72fa
w6 = w2 xor w5 = 08090a0b xor d2af72fa = daa678f1
w7 = w3 xor w6 = 0c0d0e0f xor daa678f1 = d6ab76fe
Why: XOR byte by byte: 04 xor d6 = d2, 05 xor aa = af, 06 xor 74 = 72, 07 xor fd = fa, so w5 = d2af72fa. Then w6 = daa678f1 and w7 = d6ab76fe. Together K1 = d6aa74fd d2af72fa daa678f1 d6ab76fe, the round key printed in the standard.
Worked example
g takes one word and returns a scrambled word, reusing the S-box from SubBytes. Here it is on w3 = 0c 0d 0e 0f, the last word of K0, producing the first word of K1.
Figure (svg): The g pipeline: w3 = 0c 0d 0e 0f, rotate to 0d 0e 0f 0c, S-box to d7 ab 76 fe, XOR Rcon 01 00 00 00 to d6 ab 76 fe; then w0 xor g(w3) = d6 aa 74 fd
1. Rotate
Why: Move the first byte to the end: 0c 0d 0e 0f becomes 0d 0e 0f 0c.
2. S-box
Why: Replace each byte with its S-box entry: S[0d] = d7, S[0e] = ab, S[0f] = 76, S[0c] = fe, giving d7 ab 76 fe.
3. XOR the round constant
Why: Rcon for K1 is 01 00 00 00, so only the first byte changes: d7 xor 01 = d6. g(w3) = d6 ab 76 fe.
4. The usual XOR
Why: w4 = w0 xor g(w3) = 00010203 xor d6ab76fe = d6aa74fd.
Verify: compare with the standard
Why: d6aa74fd is the first word of K1 in FIPS-197, and the same value used in AddRoundKey for round 1.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-g-how
Faded example
w7 = d6 ab 76 fe. Its rotated bytes run through the S-box as S[ab] = 62, S[76] = 38, S[fe] = bb, S[d6] = f6. K2 uses round constant 02 00 00 00.
Fill in the blanks
rotate: d6 ab 76 fe -> ab 76 fe d6
S-box: -> 62 38 bb f6
xor Rcon: 62 xor 02 = 60
g(w7) = 60 38 bb f6
Why: Rotating moves d6 to the end: ab 76 fe d6. The S-box gives 62 38 bb f6. Only the first byte meets the round constant: 62 xor 02 = 60, so g(w7) = 60 38 bb f6. Then w8 = w4 xor g(w7) = d6aa74fd xor 6038bbf6 = b692cf0b, the first word of K2.
Concept
The round constant Rcon is one byte followed by 00 00 00, so it only ever changes the first byte of g. Each round key K1 to K10 has its own byte, and the bytes come from one simple rule: start at 01 and double each time, with the same 1b overflow rule as MixColumns.
| round key | g input after rotate and S-box | Rcon byte | first byte of g |
|---|---|---|---|
| K1, from g(w3) | d7 ab 76 fe | 01 | d7 xor 01 = d6 |
| K2, from g(w7) | 62 38 bb f6 | 02 | 62 xor 02 = 60 |
| K8, from g(w31) | d3 ba f7 2f | 80 | d3 xor 80 = 53 |
| K9, from g(w35) | 08 da b5 e4 | 1b | 08 xor 1b = 13 |
The sequence is 01, 02, 04, 08, 10, 20, 40, 80, then 1b, then 36. Doubling 80 = 1000 0000 pushes the top bit out, so instead of 00 we XOR 1b, exactly as in MixColumns; doubling 1b then gives 36.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-rcon
Fill the middle
Start at 01 and double, one byte per round key. Doubling a byte whose top bit is 1 drops that bit and XORs 1b.
Fill in the blanks
K1 01, K2 02, K3 04, K4 08, K5 10, K6 20, K7 40, K8 80, K9 1b, K10 36
Why: 80 is 1000 0000. Shifting left pushes the 1 out and leaves 0000 0000, so we XOR 1b and get 1b. Doubling 1b = 0001 1011 gives 0011 0110 = 36, with no overflow. These are the ten round constants listed in the standard.
Socratic
Suppose we drop g and build every word with XOR alone. Alice happens to pick the all-zero key.
Discussion prompt
What would her round keys be, and what would AddRoundKey then do? Then predict what changes if g has rotate and S-box but no round constant.
Hint: What is zero XOR zero?
Answer:
With XOR alone, zero XOR zero is zero, so every round key is zero and AddRoundKey does nothing at all. More generally, every round key word would be a fixed XOR combination of the four key words, a pattern anyone can write down.
| key schedule | K1 | K2 |
|---|---|---|
| XOR only | 00000000 00000000 00000000 00000000 | 00000000 00000000 00000000 00000000 |
| XOR, rotate, S-box | 63636363 63636363 63636363 63636363 | 98989898 fbfbfbfb 98989898 fbfbfbfb |
| full g, with Rcon | 62636363 62636363 62636363 62636363 | 9b9898c9 f9fbfbaa 9b9898c9 f9fbfbaa |
With rotate and S-box, 00 becomes 63, but every byte of each word stays identical because the key's bytes were identical: the key's symmetry survives. The round constant touches only the first byte, turning 63 into 62, and from K2 on the pattern is broken. The S-box brings non-linearity; Rcon makes every round different.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-g-why
Discrimination
Each piece of g fixes a different weakness. Sort each claim to the piece it describes.
Sort into buckets
Which piece of g is responsible?
Concept
Running the schedule to the end for the key 000102...0f gives these round keys, exactly as printed in the standard's appendix.
| key | words | bytes | Rcon | used in |
|---|---|---|---|---|
| K0 | w0-w3 | 00010203 04050607 08090a0b 0c0d0e0f | - | before round 1 |
| K1 | w4-w7 | d6aa74fd d2af72fa daa678f1 d6ab76fe | 01 | round 1 |
| K2 | w8-w11 | b692cf0b 643dbdf1 be9bc500 6830b3fe | 02 | round 2 |
| K3 | w12-w15 | b6ff744e d2c2c9bf 6c590cbf 0469bf41 | 04 | round 3 |
| K4 | w16-w19 | 47f7f7bc 95353e03 f96c32bc fd058dfd | 08 | round 4 |
| K5 | w20-w23 | 3caaa3e8 a99f9deb 50f3af57 adf622aa | 10 | round 5 |
| K6 | w24-w27 | 5e390f7d f7a69296 a7553dc1 0aa31f6b | 20 | round 6 |
| K7 | w28-w31 | 14f9701a e35fe28c 440adf4d 4ea9c026 | 40 | round 7 |
| K8 | w32-w35 | 47438735 a41c65b9 e016baf4 aebf7ad2 | 80 | round 8 |
| K9 | w36-w39 | 549932d1 f0855768 1093ed9c be2c974e | 1b | round 9 |
| K10 | w40-w43 | 13111d7f e3944a17 f307a78b 4d2b30c5 | 36 | round 10 |
Every round key follows from the one before it by public rules. That cuts both ways, as the next slide asks.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-keys-all
Counterexample
A designer argues: an attacker who learns only K10, the last round key, still knows nothing useful, because the real key is K0.
Discussion prompt
Is that right? Use the rule w[i] = w[i-4] xor w[i-1] to decide.
Hint: Can you solve the rule for w[i-4]?
Answer:
No. The rule can be run backwards: w[i-4] = w[i] xor w[i-1], with g applied where the forward rule used it. Starting from the four words of K10, you can recover K9, then K8, and so on down to K0, which is the key itself.
So in AES-128, knowing any single round key is the same as knowing the key. This is why side channels that leak the last round key, for example through power or timing measurements of the final round, are treated as complete key recovery. The defence lies in the implementation, not the schedule.
Section
Ten rounds, and what they do to a single flipped bit
Concept
Here is the complete encryption of our example. Round 1 is shown step by step, and every earlier slide used one piece of it. Rounds 2 to 9 repeat the same four steps with the next round key, and round 10 skips MixColumns.
plaintext 00112233445566778899aabbccddeeff
xor K0 00102030405060708090a0b0c0d0e0f0
r1 SubBytes 63cab7040953d051cd60e0e7ba70e18c
r1 ShiftRows 6353e08c0960e104cd70b751bacad0e7
r1 MixColumns 5f72641557f5bc92f7be3b291db9f91a
r1 xor K1 89d810e8855ace682d1843d8cb128fe4
r2 end 4915598f55e5d7a0daca94fa1f0a63f7
r3 end fa636a2825b339c940668a3157244d17
r4 end 247240236966b3fa6ed2753288425b6c
r5 end c81677bc9b7ac93b25027992b0261996
r6 end c62fe109f75eedc3cc79395d84f9cf5d
r7 end d1876c0f79c4300ab45594add66ff41f
r8 end fde3bad205e5d0d73547964ef1fe37f1
r9 end bd6e7c3df2b5779e0b61216e8b10b689
r10 (no Mix) 69c4e0d86a7b0430d8cdb78070b4c55a # the ciphertext| line | what produced it | checked against |
|---|---|---|
| xor K0 | the key itself, before any round | the figure on the state slide |
| r1 SubBytes to r1 xor K1 | the four steps you computed by hand | the worked examples and exercises |
| r2 end to r9 end | nine more rounds with K2 to K9 | FIPS-197 appendix C.1 |
| r10 | SubBytes, ShiftRows, xor K10, no MixColumns | openssl enc -aes-128-ecb gives the same 32 hex digits |
Every value was produced by a short reference implementation written for this deck and agrees with the standard's appendix and with OpenSSL. Writing such an implementation, about 60 lines of Python, is an excellent way to make each box concrete.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-trace
Prediction
The last round runs SubBytes, ShiftRows and AddRoundKey, but no MixColumns.
Predict first
Why does dropping MixColumns from the final round cost no security?
Correct: A final MixColumns after the last key would be a public step anyone could undo, so it adds nothing
Why: MixColumns is fixed and public. If it came after the last key XOR, anyone could simply apply the inverse to the ciphertext. Mixing only protects anything when a secret key is added after it, so the designers removed it from the last round, which also makes decryption line up neatly with encryption.
Concept
Encrypt our plaintext twice with the same key, the second time with its lowest bit flipped, so 00 becomes 01. At each stage, XOR the two states: red bytes are where the states differ.
Figure (svg): Five difference grids: start with 1 differing bit, 5 bits after SubBytes, 17 bits in one column after MixColumns, 16 bits in four columns after round 2 ShiftRows, 64 bits in all 16 bytes after round 2 MixColumns
| stage | difference | bits that differ |
|---|---|---|
| start | 01 in byte 0 | 1 |
| round 1 SubBytes | 1f in byte 0 | 5 |
| round 1 MixColumns | 3e 1f 1f 21 in column 0 | 17 |
| round 2 ShiftRows | four bytes, now in four different columns | 16 |
| round 2 MixColumns | all 16 bytes differ | 64 |
SubBytes turns one flipped bit into five inside the same byte. MixColumns spreads that byte to its whole column: the differences are 21f, 1f, 1f and 31f, using the byte tools. ShiftRows sends those four bytes into four different columns, and the next MixColumns fills the grid. Two rounds give full diffusion.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-avalanche
Prediction
The difference grids skipped every AddRoundKey.
Predict first
Why can the AddRoundKey steps be left out when tracking the difference between two encryptions under the same key?
Correct: Because XORing the same round key into both states leaves their XOR unchanged
Why: If the states are A and B, then (A xor K) xor (B xor K) = A xor B, because K cancels. AddRoundKey hides the states themselves, but it never changes how two states under the same key differ. The spreading of a difference comes entirely from the other three steps.
Picture it
The lecture repeated the experiment with a random key, a random plaintext and one random bit flipped, ten thousand times, counting how many of the 128 ciphertext bits changed. We reran it 3,000 times with our reference AES and recorded the count after every round.
Figure (svg): Average number of differing bits after each round with one-standard-deviation bars: about 16 after round 1, about 64 from round 2 on, with the spread settling to about 5.7 from round 3
Round 1 changes about 16 bits, one column's worth. Round 2 already averages 64 but with a wider spread, about 8.2, because the bits are not yet independent. From round 3 on, every round looks the same: an average of 64 with a standard deviation of about 5.7, which is exactly what 128 fair coin tosses would give. Ten rounds is a wide safety margin over the two that diffusion needs.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-avalanche-count
Estimation
For 128 fair coins the average number of heads is 64 and the standard deviation is the square root of 128 times one quarter, which is the square root of 32, about 5.66.
Predict first
One run flips a plaintext bit and sees 71 ciphertext bits change. What should you conclude?
Correct: Nothing: 71 is about 1.2 standard deviations above 64, well within normal variation
Why: 71 minus 64 is 7, and 7 divided by 5.66 is about 1.24. Roughly a fifth of runs land at least that far above or below the mean. Exactly 64 every time would actually be the suspicious result, since real coin tosses vary. In our 3,000 runs the round-10 counts ranged from 44 to 90.
Section
Every step has exactly one job
Prediction
Each of the four steps looks simple. Imagine removing one of them from all ten rounds, keeping everything else.
Predict first
Which removals leave AES secure?
Correct: None: every single removal breaks AES, each in a different way
Why: Without SubBytes AES becomes linear. Without ShiftRows it splits into four 32-bit ciphers. Without MixColumns it splits into sixteen 1-byte ciphers. Without AddRoundKey it has no key at all. The next slides take each case in turn and name the property that is lost.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-remove
Concept
Suppose SubBytes is removed. What is left in each round is ShiftRows and MixColumns, call them L, followed by a key XOR. Both of those steps are linear: applying L to an XOR gives the XOR of the separate results, L(x xor k) = L(x) xor L(k).
That one property lets every key XOR be pushed past every L to the end of the cipher. The whole encryption collapses to a public scrambling of the plaintext, followed by one constant that depends only on the key.
| what it is | depends on the key? | |
|---|---|---|
| L | ShiftRows and MixColumns of all ten rounds, composed | no, it is public |
| c_K | all eleven round keys, pushed through to the end and combined | yes, but it is one fixed 16-byte value |
| E(P) | L(P) xor c_K | only through that single constant |
A cipher of the form public function XOR constant is a disguised one-time pad that reuses its pad for every message. SubBytes is exactly what prevents this, because the S-box of an XOR is not the XOR of the S-boxes. That is what the lecture means by calling it the only non-linear step.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-sub-attack
Anomaly
Here is real output from AES with SubBytes removed. The same two messages are encrypted under two completely different keys, and the two ciphertexts of each pair are XORed.
# AES with SubBytes removed; P0 = "meet me at noon!", P1 = "attack at dawn!!"
key 000102...0f C0 xor C1 = 562ff5622065925679fa82f449ccb6ad
key 2b7e15...3c C0 xor C1 = 562ff5622065925679fa82f449ccb6ad| observation | what it means |
|---|---|
| the two XORs are identical | the key constant c_K cancels, so C0 xor C1 depends only on the plaintexts |
| C0 xor C1 is L applied to P0 xor P1 | L is public, so the relation between the two plaintexts is exposed |
| it happens for every pair of messages | worse than a reused one-time pad, which leaks only when a key is reused |
Predict first
Which earlier failure does this resemble most closely?
Correct: The reused one-time pad, where C1 xor C2 = P1 xor P2
Why: With a reused pad, XORing two ciphertexts cancels the key and leaves the XOR of the plaintexts. AES without SubBytes behaves the same way after a public, undoable scrambling, and it does so for every pair of messages ever encrypted under the key.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-sub
Concept
MixColumns mixes inside a column, and SubBytes and AddRoundKey work byte by byte. So without ShiftRows, nothing ever moves a byte into a different column. A change in column 0 spreads through column 0 in round 1 and stays there for all ten rounds.
Figure (svg): Three ciphertext grids for a one-bit plaintext change: without ShiftRows only column 0 changes; without MixColumns only byte 0 changes; with full AES every byte changes
AES then splits into four separate ciphers, each on a 32-bit column. A 32-bit block is far too small: it has only about 4.3 billion possible inputs, so the complete input-output table of each column could be collected and stored. That is the opposite of what a 128-bit block is for.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-shift
Estimation
Without ShiftRows each column is an independent 32-bit cipher. A complete table lists the output for every possible input.
Predict first
There are 2 to the power 32 possible inputs, and one 16-byte AES block carries one input for each of the four columns at once. Roughly how much ciphertext is a full table?
Correct: About 64 gigabytes
Why: 2 to the power 32 blocks of 16 bytes is 2 to the power 36 bytes, which is 64 GiB: a single ordinary disk. Compare that with the 2 to the power 128 work that full AES demands. Splitting a big block into small independent pieces destroys the security the block size was supposed to provide.
Concept
Without MixColumns no step ever combines two bytes. SubBytes and AddRoundKey act on one byte at a time, and ShiftRows only moves bytes around. So every output byte depends on exactly one input byte, through all ten rounds.
| variant | a one-bit change reaches | AES splits into |
|---|---|---|
| full AES | all 16 bytes after two rounds | one 128-bit cipher |
| no ShiftRows | the 4 bytes of one column | four 32-bit ciphers |
| no MixColumns | 1 byte | sixteen 8-bit ciphers |
A cipher on one byte has only 256 possible inputs, so its whole table is tiny: 256 blocks, about 4 kilobytes, would cover every position at once. In the figure on the previous slide only byte 0 of the ciphertext changed, because byte 0 sits in row 0, which ShiftRows never moves.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-mix
Concept
The cleanest failure. The key schedule still runs, but nothing uses its output, because AddRoundKey is the only step where round keys enter.
# AES with AddRoundKey removed, plaintext 00112233...ff
key 000102...0f C = 8c34c7e2358383edd3da9b3d23cca3b3
key 2b7e15...3c C = 8c34c7e2358383edd3da9b3d23cca3b3
flip one bit C' = ecff072a6f4d848a928f8c62a4a88602| observation | what it means |
|---|---|
| two different keys, the same ciphertext | the output does not depend on the key |
| one flipped bit changes all 16 bytes | the avalanche is still perfect |
| every step left is public and invertible | anyone can run the inverse steps and read every message |
Notice the second row. The scrambling is as thorough as ever, yet there is no secrecy whatsoever. Scrambling is not encryption: a cipher is secure only because its output depends on a secret, and here nothing does.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-ark
Matching
Summarise the four experiments. Match each removed step to what goes wrong.
Match the pairs
Why: Each step has one job: SubBytes for non-linearity, ShiftRows to carry bytes between columns, MixColumns to combine the bytes of a column, and AddRoundKey to make everything depend on the key. Remove any one and a different kind of structure appears.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-remove
Trap
A tempting test: flip input bits, check that about half the output bits change, and declare the cipher strong.
| variant | avalanche | secure? |
|---|---|---|
| full AES | perfect | yes |
| no AddRoundKey | perfect | no: there is no key at all |
| no SubBytes | spreads across the block | no: it is linear |
Random-looking output is necessary but nowhere near sufficient.
Security is about what someone without the key can work out, not about how scrambled the output looks. The checks that matter are structural: is there a non-linear step, does every part of the block affect every other part, and does the output depend on the key everywhere?
This is also why nobody should design their own cipher. AES earned trust from years of public cryptanalysis looking for exactly these hidden structures, not from passing a randomness test.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-no-ark
Explain it
The lecture ends this part with a take-home challenge: a Python AES that can skip any one of the four steps, with one variant per challenge. Before touching any code, the reasoning is what counts.
Discussion prompt
For each variant, explain to a partner in two sentences: which property of AES is lost, and what an outsider could observe about ciphertexts that they could not observe with full AES?
Hint: Look back at what each step's job was on the matching slide.
Answer:
| variant | property lost | what an outsider can observe |
|---|---|---|
| no SubBytes | non-linearity | C0 xor C1 is the same under every key |
| no ShiftRows | movement between columns | a change never leaves its column |
| no MixColumns | mixing within a column | a change never leaves its byte |
| no AddRoundKey | any dependence on the key | the same plaintext gives the same ciphertext under every key |
If you can fill in this table without looking, you understand why each step is in AES. The design lesson generalises to any block cipher: it needs a non-linear layer, a diffusion layer that reaches the whole block, and a key mixed in every round.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-challenge
Section
Undo every box, and where the real failures are
Concept
Decryption starts from the ciphertext and undoes each box in reverse order, using the round keys from K10 down to K0. XOR with a round key undoes itself. The other three steps each need a real inverse step.
Figure (svg): Two columns: encryption top down from plaintext through XOR K0, the round steps and XOR K10 to ciphertext; decryption bottom up through XOR K10, InvShiftRows, InvSubBytes, XOR Kr, InvMixColumns and finally XOR K0
| encryption step | its inverse |
|---|---|
| SubBytes | InvSubBytes: look up the inverse S-box |
| ShiftRows | InvShiftRows: rotate row r right by r |
| MixColumns | InvMixColumns: multiply by the matrix with rows 0e 0b 0d 09; it turns 5f 72 64 15 back into 63 53 e0 8c |
| AddRoundKey | the same XOR with the same round key |
Unlike DES, where the Feistel structure only ever recomputes the round function F, AES has to invert every step. That is why each step was chosen to be one-to-one, and why the S-box and the MixColumns arithmetic had to be reversible.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-dec
Ranking
Decryption begins at the ciphertext and works back through round 10, then into round 9. Order the first five operations.
Put in order
Why: Round 10 ended with XOR K10, after ShiftRows, after SubBytes, so those are undone first in reverse order. Round 9 ended with MixColumns then XOR K9, so the next undo is XOR K9 followed by InvMixColumns. InvShiftRows and InvSubBytes may swap with each other, since one moves bytes and the other changes them in place, but the standard's order is the one shown.
Check
Solve it on paper before you click.
Check your understanding
DES decryption never inverts its round function F, but AES decryption must invert SubBytes and MixColumns. Why?
Answer: A
Why: A Feistel round XORs F of one half into the other half, so running it again with the same key cancels it, whatever F is. AES rounds apply SubBytes, ShiftRows and MixColumns to the entire state, so decryption needs a true inverse of each, which is why every step was designed to be one-to-one.
Concept
Twenty-five years after standardisation, AES is both everywhere and unbroken. Its practical failures come from how it is implemented and used, not from the mathematics.
$ openssl speed -evp aes-128-gcm -bytes 16384
AES-128-GCM 5387100.16k # on the lecturer's laptop: about 5.4 GB per second, one core| question | answer today |
|---|---|
| how fast? | since about 2010, CPUs have AES instructions that run a whole round in one instruction; gigabytes per second per core |
| best attack on the maths? | about 2 to the power 126 work for AES-128 instead of 2 to the power 128 (biclique attack, 2011): unbroken in practice |
| how is it really broken? | software AES using lookup tables can leak the key through cache timing (2005); hardware AES instructions avoid this |
| quantum computers? | Grover's algorithm needs about 2 to the power 64 steps for AES-128, so AES-256 keeps a comfortable margin |
The lesson for practitioners: use the hardware-accelerated AES in your platform's standard library, never a hand-written one, and spend your attention on the mode of operation and on key management, where real systems actually fail.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-aes-practice
Sorting
Sort each item by whether it is a realistic way AES-based systems fail today.
Sort into buckets
Realistic failure, or not a practical concern?
Real world
AES runs many times a second on almost every device you own.
Discussion prompt
Name three places AES protects your data today, and for each one say what the key is shared between.
Hint: Think about your browser, your router and your laptop's disk.
Answer:
HTTPS: TLS sessions are usually encrypted with AES-GCM, using a session key your browser and the server agree on during the handshake. Wi-Fi: WPA2 and WPA3 encrypt each frame with AES, keyed from the network password and a handshake. Disk encryption: BitLocker, FileVault and LUKS encrypt the disk with AES under a key unlocked by your password or hardware chip.
Notice the pattern: AES itself is never the hard part. Each system's security depends on how the key is agreed and protected, and on the mode used to encrypt data longer than one block.
Concept
The original lecture pauses here for two course announcements. They are specific to that class, but the practices behind them apply to any course.
account set-up — students had to send a code-hosting account name for the course platform before the first graded round, with no late days; set up course accounts as soon as they are requested
two standing channels — an anonymous feedback poll for pace and clarity, and a discussion board for questions during and after class
If something in this lesson did not land, the equivalent move is the same: say so early, anonymously if you prefer, and bring questions to whatever discussion space your course uses.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-wanted
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-channels
Concept
The whole cipher on one page again, now with the job of each step, which is what the removal experiments showed.
Figure (svg): The AES pipeline: plaintext, XOR K0, ten rounds of SubBytes, ShiftRows, MixColumns and AddRoundKey with round 10 skipping MixColumns, and the key schedule supplying K0 to K10
| step | its job | without it |
|---|---|---|
| SubBytes | the only non-linear step | AES is linear |
| ShiftRows | moves bytes between columns | four 32-bit ciphers |
| MixColumns | mixes the 4 bytes of a column (not in round 10) | sixteen 1-byte ciphers |
| AddRoundKey | the only place the key enters | no secret at all |
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-recap-aes
Check
Solve it on paper before you click.
Check your understanding
Which list is the correct order of operations in round 10 of AES-128?
Answer: B
Why: Round 10 is a normal round without MixColumns: SubBytes, ShiftRows, then AddRoundKey with K10. A MixColumns after the last key would be a public step anyone could undo.
Concept
One rule, applied forty times, turns the 16-byte key into 44 words, 176 bytes, the eleven round keys.
| round key | words | for the key 000102...0f |
|---|---|---|
| K0 | w0-w3 | 00010203 04050607 08090a0b 0c0d0e0f |
| K1 | w4-w7 | d6aa74fd d2af72fa daa678f1 d6ab76fe |
| K2 | w8-w11 | b692cf0b 643dbdf1 be9bc500 6830b3fe |
| K10 | w40-w43 | 13111d7f e3944a17 f307a78b 4d2b30c5 |
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-recap-keys
Socratic
AES encrypts exactly one 16-byte block: 16 bytes in, 16 bytes out. A 1 MB file is 65,536 blocks, and a web page, a photo or an email is also far more than one block.
Discussion prompt
How would you encrypt a message longer than one block with AES? Propose a method, then think about what could go wrong with it.
Hint: What happens to two identical 16-byte chunks of the message?
Answer:
The obvious idea is to cut the message into 16-byte blocks and encrypt each one separately with the same key. But then identical plaintext blocks give identical ciphertext blocks, and patterns in the data show straight through the encryption.
The way a one-block cipher is used over a long message is called the mode of operation, and with it comes padding for the last partial block. The next lecture part shows that the mode and its initialisation vector break long before the cipher does: that is where most real failures live.
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-recap-bridge
Connect it up
Close the slides and rebuild the whole cipher.
Draw it
Draw the AES-128 pipeline from plaintext to ciphertext. Label the XOR with K0, the four steps of a round with one phrase each for its job, the missing step in round 10, and the key schedule with the rule for making a new word and the three moves of g. Then mark which boxes use the key.
Check against the recap slides. If you could not say what g does or why round 10 drops MixColumns, revisit Part 3 or the start of Part 4.
Exit ticket
One question to check the central idea of the lesson.
Predict first
A designer proposes a faster AES that drops SubBytes but keeps the other three steps and all ten rounds. What is the strongest objection?
Correct: Without the only non-linear step the cipher becomes linear, so ciphertext XORs reveal plaintext XORs under any key
Why: With SubBytes gone, all the round keys can be pushed to the end, leaving a public linear map XOR one key-dependent constant. The XOR of two ciphertexts then depends only on the XOR of the plaintexts, the same leak as a reused one-time pad. The key schedule would still use the S-box internally, but that does not save the cipher.
Recap
You have taken AES apart one box at a time with the standard's own numbers.
| idea | one line |
|---|---|
| state | 4 by 4 grid of bytes, filled column by column |
| round | SubBytes, ShiftRows, MixColumns (not in round 10), AddRoundKey |
| key schedule | w[i] = w[i-4] xor w[i-1], with g every fourth word |
| diffusion | two rounds spread one bit to all 128 |
| next | a mode of operation, to encrypt more than one block |
Security I, Lecture 2: Cryptography, symmetric ciphers (AES) slide s-recap-aes
Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.