4. AES
The world's most widely used cipher
In 1997, NIST announced a public competition to replace DES. After three years of analysis by cryptographers worldwide, the winner was Rijndael, designed by Belgian cryptographers Joan Daemen and Vincent Rijmen. It became the Advanced Encryption Standard (AES) in 2001 and has dominated symmetric encryption ever since.
AES is not a Feistel network — it's a substitution-permutation network (SPN) that transforms the entire block at once in each round, rather than splitting it in half.
AES at a Glance
| Property | Value |
|---|---|
| Block size | 128 bits (16 bytes) — always |
| Key sizes | 128, 192, or 256 bits |
| Rounds | 10 (AES-128), 12 (AES-192), or 14 (AES-256) |
| Structure | Substitution-Permutation Network (SPN) |
| Design principle | Wide Trail Strategy — provable resistance to linear/differential attacks |
The State Matrix
AES treats each 16-byte block as a 4×4 matrix of bytes, called the state. Every operation works on this matrix.
16 bytes arranged as a 4×4 state
Input bytes: b₀ b₁ b₂ b₃ b₄ b₅ b₆ b₇ b₈ b₉ b₁₀ b₁₁ b₁₂ b₁₃ b₁₄ b₁₅
State matrix (column-major order):
┌─────┬─────┬─────┬─────┐
│ b₀ │ b₄ │ b₈ │ b₁₂ │
│ b₁ │ b₅ │ b₉ │ b₁₃ │
│ b₂ │ b₆ │ b₁₀ │ b₁₄ │
│ b₃ │ b₇ │ b₁₁ │ b₁₅ │
└─────┴─────┴─────┴─────┘
The Four Round Operations
Each AES round applies four operations to the state, in this order:
-
SubBytes — Substitution
Replace each byte with a corresponding byte from a fixed 256-entry lookup table (the S-box). This is the nonlinear step — it provides confusion. The AES S-box is based on computing the multiplicative inverse in GF(28), followed by an affine transformation.
-
ShiftRows — Row rotation
Cyclically shift each row of the state: row 0 stays, row 1 shifts left by 1, row 2 by 2, row 3 by 3. This mixes data across columns, providing diffusion.
-
MixColumns — Column mixing
Multiply each column by a fixed polynomial matrix in GF(28). This mixes bytes within each column, spreading the influence of each byte to all four bytes in its column. Skipped in the final round.
-
AddRoundKey — Key mixing
XOR the state with the round key (derived from the main key via the key schedule). This is where the secret key enters the computation.
Visual overview of one AES round
┌─────────┐ ┌──────────┐ ┌───────────┐ ┌────────────┐
│SubBytes │ → │ShiftRows │ → │MixColumns │ → │AddRoundKey │
│(S-box │ │(rotate │ │(matrix │ │(XOR with │
│ lookup) │ │ rows) │ │ multiply) │ │ round key) │
└─────────┘ └──────────┘ └───────────┘ └────────────┘
Confusion Diffusion Diffusion Key mixing
ShiftRows Visualized
Before and after ShiftRows
Before: After:
┌────┬────┬────┬────┐ ┌────┬────┬────┬────┐
│ a₀ │ a₁ │ a₂ │ a₃ │ │ a₀ │ a₁ │ a₂ │ a₃ │ ← no shift
│ b₀ │ b₁ │ b₂ │ b₃ │ │ b₁ │ b₂ │ b₃ │ b₀ │ ← shift 1
│ c₀ │ c₁ │ c₂ │ c₃ │ │ c₂ │ c₃ │ c₀ │ c₁ │ ← shift 2
│ d₀ │ d₁ │ d₂ │ d₃ │ │ d₃ │ d₀ │ d₁ │ d₂ │ ← shift 3
└────┴────┴────┴────┘ └────┴────┴────┴────┘
After ShiftRows, each column contains bytes from four different original columns. Combined with MixColumns, this ensures that after just two rounds, every output byte depends on every input byte.
The AES S-Box
The S-box is a fixed lookup table that maps each byte (0x00–0xFF) to another byte. Unlike DES's S-boxes (which were designed in secret by the NSA), the AES S-box has a clean mathematical definition:
- Compute the multiplicative inverse of the byte in GF(28) (with 0 mapping to 0)
- Apply a fixed affine (linear + constant) transformation over GF(2)
This construction was chosen because the inverse function in GF(28) has the highest possible nonlinearity — it's maximally resistant to linear and differential cryptanalysis.
A few S-box values
Input → Output
0x00 → 0x63
0x01 → 0x7C
0x10 → 0xCA
0x53 → 0xED
0xFF → 0x16
The full table has 256 entries — small enough to fit in CPU cache.
The Key Schedule
AES needs a different round key for each round (plus one initial key addition). The
key schedule expands the cipher key into rounds + 1
round keys:
| Key size | Rounds | Round keys needed | Expanded key size |
|---|---|---|---|
| 128 bits | 10 | 11 | 176 bytes |
| 192 bits | 12 | 13 | 208 bytes |
| 256 bits | 14 | 15 | 240 bytes |
The expansion uses the S-box and XOR with round constants to ensure each round key is highly dependent on the original key while being different from every other round key.
The Full AES-128 Pipeline
Initial: AddRoundKey(state, roundKey[0])
Round 1: SubBytes → ShiftRows → MixColumns → AddRoundKey(roundKey[1])
Round 2: SubBytes → ShiftRows → MixColumns → AddRoundKey(roundKey[2])
...
Round 9: SubBytes → ShiftRows → MixColumns → AddRoundKey(roundKey[9])
Round 10: SubBytes → ShiftRows → AddRoundKey(roundKey[10])
↑ no MixColumns in final round
Why AES Is Secure
No Practical Attack Exists
After 25+ years of public scrutiny by the world's best cryptanalysts, no practical attack on full AES has been found. The best known attack on AES-128 requires 2126.1 operations — barely better than brute force (2128). AES-256 has a theoretical attack at 2254.4, but this is astronomically beyond any feasible computation.
Key design decisions that make AES strong:
- Wide trail strategy — the designers proved a minimum number of active S-boxes across rounds, guaranteeing resistance to linear and differential attacks
- Algebraic structure — operations in GF(28) are well-understood, leaving no room for hidden weaknesses
- Full diffusion in 2 rounds — after 2 rounds, every output bit depends on every input bit
- Conservative round count — 10-14 rounds is well above the minimum needed for security
AES in Hardware
AES is so important that Intel and AMD added dedicated instructions (AES-NI)
directly to their CPUs. A single AESENC instruction performs one complete
AES round in hardware.
Performance with AES-NI
Without AES-NI: ~300 MB/s (software implementation)
With AES-NI: ~5 GB/s (hardware acceleration)
That's fast enough to encrypt every byte flowing through
a 40 Gbps network link in real time.
Real-World Usage
| System | How it uses AES |
|---|---|
| TLS / HTTPS | AES-128-GCM or AES-256-GCM for all web traffic |
| Wi-Fi (WPA2/3) | AES-CCMP for all encrypted frames |
| Full disk encryption | BitLocker, FileVault, LUKS all default to AES-256 |
| SSH | AES-256-CTR or AES-256-GCM for session encryption |
| Signal / WhatsApp | AES-256-CBC for message encryption |
| US Government | AES-256 approved for TOP SECRET classification |
Try It Yourself — AES-128 Round Stepper
Enter a 128-bit plaintext and key (32 hex characters each). Step through every sub-operation across all 10 rounds: SubBytes, ShiftRows, MixColumns, and AddRoundKey. Changed cells are highlighted.
S-Box Explorer
The AES S-box maps each input byte to an output byte. Enter a hex value to look it up, or browse the full 16×16 table below. Row = high nibble, column = low nibble.
Avalanche Effect — AES Edition
Flip a single bit in the plaintext and compare the internal state after each round. AES achieves full diffusion (~64/128 bits different) within just 2 rounds.
Key Takeaways
- AES is a substitution-permutation network: SubBytes, ShiftRows, MixColumns, AddRoundKey
- 128-bit blocks, 128/192/256-bit keys, 10/12/14 rounds
- The S-box provides nonlinearity (confusion); ShiftRows + MixColumns provide diffusion
- Full diffusion in just 2 rounds — every output byte depends on every input byte
- No practical attack found in 25+ years; hardware acceleration makes it extremely fast
- AES is the symmetric cipher — it's everywhere
AES encrypts one 16-byte block at a time. But real messages are longer than 16 bytes. How do you chain blocks together securely? The answer — and the many ways to get it wrong — is the subject of block cipher modes.