Skip to main content
Be Bitwise

Block Ciphers & AES

Symmetric Encryption · Networking & Cryptography track

6 min read

In this module

Encrypting in Chunks

A block cipher encrypts data in fixed-size chunks. The reigning champion is AES (Advanced Encryption Standard), which works on 128-bit (16-byte) blocks.

Unlike a plain XOR cipher, AES throws the data through a stack of transformations across multiple rounds to thoroughly stir the key into the plaintext. By the time AES is done, an attacker would need infeasible amounts of computation to peel the key or plaintext back out.

AES at a High Level

AES emerged from a public competition NIST (the U.S. National Institute of Standards and Technology) ran from 1997 to 2001, hunting a replacement for the aging DES. The winning entry — originally called Rijndael — came from Belgian cryptographers Vincent Rijmen and Joan Daemen.

AES parameters:

  • Block size: Always 128 bits (16 bytes)
  • Key sizes: 128, 192, or 256 bits
  • Rounds: 10 (AES-128), 12 (AES-192), or 14 (AES-256)

Inside a Round

Each AES round applies four operations to a 4x4 grid of bytes called the state (the very last round skips MixColumns):

1. SubBytes (Substitution): Each byte gets swapped for a corresponding byte from a fixed lookup table — the S-box. This injects non-linearity. Without it, the whole cipher would collapse into a system of linear equations that an attacker could solve over coffee.

2. ShiftRows (Permutation): The rows of the state grid rotate cyclically. Row 0 stays put, row 1 shifts left by 1, row 2 by 2, row 3 by 3. The columns end up scrambled across each other.

3. MixColumns (Mixing): Each column is multiplied by a fixed matrix in a finite field (GF(2^8)). The bytes within a column get blended, spreading the influence of any single byte across all four.

4. AddRoundKey (Key Mixing): The round key (derived from the main key by a process called key expansion) is XORed into the state. This is the step that actually folds the secret key into the data.

Decryption runs the inverse of each step (InvSubBytes, InvShiftRows, InvMixColumns, AddRoundKey, which is its own inverse) with the round keys in reverse order.

Key Concept

AES achieves security through confusion (SubBytes makes the relationship between key and ciphertext complex) and diffusion (ShiftRows and MixColumns spread the influence of each plaintext bit across the entire block). Two rounds are enough for every output bit to depend on every input bit; the remaining rounds bury the statistical patterns that attacks feed on.

Watch the four steps act on a real block. The defaults are the worked example from FIPS 197, so you can check each state against the standard.

Step 1 of 41: input

The 16 input bytes fill the grid column by column: bytes 0–3 are column 0, and so on.

State
328831e0
435a3137
f6309807
a88da234

Why So Many Rounds?

After a single round, there are still mathematical fingerprints linking plaintext and ciphertext. Each extra round smudges them further. By round 10 (AES-128), the connection between input and output is scrambled hard enough that no known mathematical attack beats brute force.

The round count simply grows with the key. The standard sets it at the key length in 32-bit words plus six, so a 256-bit key gets 14 rounds and enough mixing for the extra key material to spread through the state. (Related-key attacks on AES-256's key schedule, published in 2009, are a separate and later finding. None of them is anywhere near practical against real use.)

AES Performance

AES was designed from day one to run fast in both hardware and software. Modern CPUs ship with dedicated AES-NI instructions that hammer through encryption at over 1 GB/s on a single core. That hardware support is half the reason AES is the default choice for almost all symmetric encryption today.

text
// With AES-NI hardware, a single instruction handles one round
AESENC xmm1, xmm2 // one AES round in ~1 clock cycle

Without hardware support, AES can still be implemented in software using lookup tables — but that opens the door to cache-timing side channels, which we'll dig into in the applied crypto module.

DES: The Predecessor

Before AES, the standard was DES (Data Encryption Standard), adopted in 1977. DES used 56-bit keys and 64-bit blocks. By the late 1990s, those 56 bits could be brute-forced in days on specialised hardware — the EFF's "Deep Crack" machine famously did it in 1998 in 56 hours, for under a quarter of a million dollars, and with distributed.net's help in under a day in 1999. Triple-DES (3DES) ran DES three times with different keys for 112-bit effective key strength, but it was a slog.

AES was designed as DES's successor: bigger blocks, longer keys, and far better performance. DES is now obsolete for any serious purpose.

The Key Expansion

AES derives a separate round key for each round from the original key through a process called key expansion (or the key schedule). Each round burns its own slice of key material, even though only one original key exists.

The key schedule reuses the same S-box as the cipher and XORs in round constants. The details get hairy, but the goal is simple: pump out enough independent-looking key material for every round from a single short key.

Block Cipher as a Building Block

AES by itself encrypts exactly one 128-bit block. Real messages are almost always longer than 16 bytes. Encrypting a full message means picking a mode of operation that defines how to apply the block cipher across multiple blocks. The choice of mode shapes security in dramatic ways, as the next lesson's famous ECB penguin will demonstrate.

Why AES Has Endured

AES emerged from an open, international competition that beat fifteen candidate algorithms against each other for four years. The transparency was unprecedented for a government-endorsed cipher, and that scrutiny is what earned the global cryptographic community's trust. Over twenty years later, no practical attack against AES has surfaced. The best known theoretical attacks shave AES-256 from 2^256 to roughly 2^254 operations — mathematically cute, practically meaningless. Layered on top of AES-NI hardware acceleration in modern CPUs, AES remains the dominant symmetric cipher, and it'll likely hold that throne for decades.