Full name: Advanced Encryption Standard (AES) round structure.
Definition
The AES round structure is the sequence of steps by which AES (Advanced Encryption Standard) encrypts one 16-byte block. AES is the block cipher §15.3, a keyed invertible map on blocks, that NIST standardized in FIPS 197 (2001). It holds the block as a 4-by-4 array §14.5 of bytes, the state, and transforms the state in rounds. A full round applies four steps: SubBytes, ShiftRows, MixColumns and AddRoundKey; the last round omits MixColumns. Keys of 128, 192 or 256 bits give 10, 12 or 14 rounds; the block is always 128 bits.
The idea
AES must turn 16 bytes into 16 bytes so that every output bit depends on every key bit and every input bit in a complicated way, and yet a key holder can undo the transformation exactly. No single simple step achieves this: a step simple enough to analyze and invert is too regular to be secure on its own. AES therefore combines a few simple, invertible steps into a round and repeats the round.
Claude Shannon named the two jobs in 1949. Confusion makes the relation between key and ciphertext complicated. In AES the SubBytes step provides it. SubBytes is the only nonlinear step, meaning the only step whose output bits are not XOR (exclusive or) combinations of its input bits and key bits. Diffusion spreads the influence of each input byte over many output bytes; ShiftRows and MixColumns provide it. AddRoundKey brings in the key. After two rounds, every byte of the state depends on all 16 input bytes. Further rounds add a safety margin: the published attacks that are far faster than trying every key work only against versions of AES with fewer rounds.
Changing the key length changes how many rounds run and how the round keys are made. The block, the state and the four steps stay the same.
How it works
Notation. Bytes are written in hexadecimal, for example 57. AES treats each byte as an element of the finite field §19.1.2 , the Galois field with 256 elements. In this field, addition is XOR. Multiplication multiplies the two bytes as polynomials whose coefficients are their bits, with coefficient arithmetic done by XOR, and keeps the remainder after division by . Every nonzero byte has a multiplicative inverse. Multiplying by 02 is the easy case: shift the byte left by one bit, and if a 1 bit fell off the top, XOR the result with 1b. Multiplying by 03 means multiplying by 02 and then taking the XOR of the result and the original byte.
The state. The 16 input bytes are written into the state column by column: bytes 0 to 3 fill column 0 from top to bottom, bytes 4 to 7 fill column 1, and so on. Row and column of the state, each numbered from 0 to 3, hold input byte . The output is read out in the same order.
The four steps.
SubBytesreplaces each of the 16 bytes by its entry in the S-box, a fixed public table of 256 entries. The entry for a byte is the multiplicative inverse of in , with 0 mapped to 0, followed by a fixed affine transformation: a fixed mixing of the 8 bits, then XOR with63. The S-box is invertible.ShiftRowsrotates row of the state to the left by positions: row 0 stays, row 1 moves by one byte, row 2 by two, row 3 by three. It sends the four bytes of each column to four different columns.MixColumnsreplaces each column by the product of a fixed 4-by-4 matrix and the column, computed in . A change in any one byte of a column changes all four bytes of that column.AddRoundKeyXORs the state with a 16-byte round key.
The order. Let be the number of rounds: 10, 12 or 14.
The key expansion, also called the key schedule, turns the key into round keys of 16 bytes each.
AddRoundKeywith round key 0.Rounds 1 to :
SubBytes,ShiftRows,MixColumns, thenAddRoundKeywith that round’s key.The final round :
SubBytes,ShiftRows, thenAddRoundKeywith round key .
Decryption applies the inverse steps in reverse order, with the round keys in reverse order. Each step can be undone: XOR with the same round key undoes AddRoundKey, the inverse table undoes the S-box, rotating right undoes ShiftRows, and the inverse matrix undoes MixColumns.
Why the final round omits MixColumns. MixColumns is linear: for any states and , . Taking , where is the inverse step, gives for any state . A MixColumns placed just before the last AddRoundKey could therefore be moved past the key addition, changing only the round key, and would then be a fixed public step applied to the ciphertext. An attacker could undo that step without the key, so it would add no security. Leaving it out also makes the decryption algorithm §14.1 resemble the encryption algorithm in structure.
Worked example
This example follows the first column of the state through round 1 of the AES-128 example in Appendix C.1 of FIPS 197, where AES-128 means AES with a 128-bit key. In hexadecimal, the key and the plaintext are
=
000102030405060708090a0b0c0d0e0f
=00112233445566778899aabbccddeeff
Initial AddRoundKey. Round key 0 is the key itself. Column 0 holds the plaintext bytes 00 11 22 33, and the matching key bytes are 00 01 02 03. Byte by byte: ; , since in binary ; ; . The other columns are treated the same way, and the whole state, read column by column, is now
00102030405060708090a0b0c0d0e0f0
SubBytes. The S-box gives 00 63, 10 ca, 20 b7 and 30 04. The whole state becomes
63cab7040953d051cd60e0e7ba70e18c
ShiftRows. Read by rows, that state is: row 0 63 09 cd ba, row 1 ca 53 60 70, row 2 b7 d0 e0 e1, row 3 04 51 e7 8c. Rotating row 1 left by one position gives 53 60 70 ca, row 2 by two gives e0 e1 b7 d0, and row 3 by three gives 8c 04 51 e7. The new column 0 is the first byte of each row: 63 53 e0 8c. Its four bytes come from four different columns of the previous state.
MixColumns. The products needed are: , since 01100011 shifted left is 11000110 and no 1 bit fell off; ; ; ; , since 11100000 shifted left is 11000000 (c0) with a 1 bit fallen off, and ; ; , since 10001100 shifted left is 00011000 (18) with a 1 bit fallen off; . The matrix rows are (02, 03, 01, 01), (01, 02, 03, 01), (01, 01, 02, 03) and (03, 01, 01, 02), so the new column is:
: , , ;
: , then , then ;
: , then , then ;
: , then , then .
AddRoundKey with round key 1. The key expansion makes the first word of round key 1 from the last key word 0c 0d 0e 0f. Rotate it to 0d 0e 0f 0c, apply the S-box to each byte to get d7 ab 76 fe, XOR the round constant 01 00 00 00 to get d6 ab 76 fe, and XOR the first key word 00 01 02 03 to get d6 aa 74 fd. Then , , and . Column 0 after round 1 is 89 d8 10 e8, as printed in FIPS 197.
All rounds, three key lengths. Encrypt the same plaintext under three keys: the 128-bit key above, the 192-bit key whose 24 bytes are 00, 01, and so on up to 17, and the 256-bit key whose 32 bytes are 00 up to 1f. They take 10, 12 and 14 rounds and give these ciphertexts, printed in Appendix C of FIPS 197:
128-bit key:
69c4e0d86a7b0430d8cdb78070b4c55a
192-bit key:dda97ca4864cdfe06eaf70a0ec0d7191
256-bit key:8ea2b7ca516745bfeafc49904b496089
All three ciphertexts are 16 bytes long. The round keys occupy , and bytes, and the 256-bit version does times the round work of the 128-bit version.
Stated precisely
Let be the key length in 32-bit words (4, 6 or 8) and the number of rounds. FIPS 197 fixes , which gives 10, 12 or 14. The key expansion produces words of 4 bytes each, and round key is the four words joined in order. Writing for the state, encryption is
Key expansion. The first words are the key. For , , where Here moves the first byte of a word to the end, applies the S-box to each of the four bytes, and the round constant is the word whose first byte is computed in (01, 02, 04, 08, 10, 20, 40, 80, 1b, 36) and whose other three bytes are 0. The middle case is used only with 256-bit keys.
The steps. SubBytes computes for each byte , where is the inverse of in , with taken as 0, and is a fixed invertible 8-by-8 matrix of bits. ShiftRows moves the byte in row , column to row , column . MixColumns maps each column to with additions and multiplications in modulo . AddRoundKey computes .
What the design proves. AES has no proof of security. Its designers, Joan Daemen and Vincent Rijmen, who submitted it under the name Rijndael, proved a narrower fact about one family of attacks [520]. In differential cryptanalysis an attacker follows how a difference between two plaintexts propagates through the rounds. A path of differences through the rounds is called a trail, and an S-box is active in a trail when its input difference is nonzero. Every trail over four rounds of AES has at least 25 active S-boxes, and the S-box turns a given nonzero input difference into a given output difference with probability at most . Every four-round trail therefore has probability at most .
Exhaustive key search tries every key: , or of them. The best published attack on the full cipher, the biclique attack of 2011 [366], needs about operations for a 128-bit key, a gain of only a factor of about 4.
Limits and common mistakes
The key length changes neither the block length nor anything that depends on it. Every AES variant has 128-bit blocks, so the data that a mode may process under one key before block repeats become likely, about blocks by the birthday bound §5.6, is the same for all three key lengths. Nonce §5.18 lengths and tag lengths are set by the mode, not by the key length.
A 256-bit key does not make a whole system 256-bit secure. A 128-bit tag, a short random nonce, or a key derived from a guessable secret sets the real limit.
The key schedules of AES-192 and AES-256 allow related-key attacks (Biryukov and Khovratovich, 2009 [367]): attacks that need encryptions under several keys whose relations the attacker chooses. A protocol that uses independently generated keys never gives an attacker such related keys; a design that makes keys by changing a few bits of one key would.
Versions with fewer rounds are not AES. Attacks far faster than exhaustive key search are published only for versions with fewer rounds, and they do not carry over to the full cipher.
An implementation can leak what the mathematics hides. Fast software often merges SubBytes, ShiftRows and MixColumns into lookups in tables indexed by secret bytes. The processor’s memory cache then reveals through timing which entries were read, and so reveals key bytes. Use dedicated processor instructions for AES or a constant-time implementation §5.36, code whose timing and memory accesses do not depend on secret data.
The state is filled column by column. An implementation that fills it row by row computes a different function; the test vectors in Appendix C of FIPS 197 catch such mistakes.
AES encrypts one block. Messages need a mode of operation, and the mode’s rules on nonces and on authentication §1.6 apply whatever the key length.
Questions answered
What changes when the AES key length changes?
When the key length of AES (Advanced Encryption Standard) changes, two things change: the number of rounds and the key expansion. Keys of 128, 192 or 256 bits give 10, 12 or 14 rounds. The key expansion, which turns the key into one 16-byte round key per round plus one more, reads 4, 6 or 8 four-byte words of key and produces 176, 208 or 240 bytes of round keys. For 256-bit keys the expansion also applies the S-box, the fixed byte-substitution table, to the previous word when computing words 12, 20, 28 and so on (counting the words from 0), the positions that are 4 more than a multiple of 8. Two consequences follow. Exhaustive key search must try about , or keys, and encryption costs about 1.2 or 1.4 times as much with 192-bit or 256-bit keys as with 128-bit keys.
Nothing else changes. For every key length the block is 128 bits (16 bytes), and the state, the S-box, the four round steps and the ciphertext length stay the same. The mode of operation’s requirements on nonces and on the amount of data per key stay the same as well.
Related entries: Block cipher (§15.3), Authenticated encryption (AEAD) (§5.16), Constant-time cryptographic implementation (§5.36), Pseudorandom permutation (PRP) (§15.2), Finite field and modular inverse (§19.1.2). Further reading: [47, 65, 366, 367, 520].