Chapter IV
Symmetric encryption
One shared key locks and unlocks. It encrypts almost every byte you send, and it fails in very specific ways.
Block and stream ciphers
A block cipher scrambles fixed-size blocks under a key. A stream cipher XORs the message with a keystream.
One key works both ways: whoever can encrypt can decrypt. A block cipher needs a mode, below, for anything longer than a block. A stream cipher is a one-time pad whose pad is computed instead of delivered.
From DES to AES
DES’s 56-bit key fell to brute force in 1998. AES encrypts 128-bit blocks with 128, 192 or 256-bit keys and is still unbroken.
DES (1977) had a 56-bit key: in 1998, the EFF’s Deep Crack found one in 56 hours.
AES (2001) loops four steps over a 4 × 4 grid of bytes: 10, 12 or 14 rounds by key size. They do Shannon’s two jobs: confusion hides the key, diffusion spreads each byte over the block.
ECB and the penguin
Encrypting each block on its own leaks patterns: equal plaintext blocks give equal ciphertext blocks.
Electronic Codebook mode encrypts each block on its own, the obvious way.
Each square is one 16-byte block. The ciphertext has 4 distinct blocks out of 256, one per color of the original: the outline survives.
Encrypted with real AES-128. Shades show the first byte of each ciphertext block.
CBC and CTR
CBC mixes each block with the previous ciphertext, starting from a random IV. CTR encrypts a counter to make a keystream.
CBC, drawn above, needs a random IV and pads the last block (PKCS#7: n bytes of value n, attacked in chapter VIII). CTR encrypts nonce ‖ counter (‖ is concatenation) into a keystream: no padding, but the same keystream for the same key and nonce.
- Intercepted c
- 5f6afe960396320a58aadd61d3b66b4ce0fdc8baca9e2c67a585808269cfff816d
- Intercepted c′
- 5867fe960998216f39bdb278d9ba0543fbe6d3bcca903e13d495ece77eac82fd0d
Then message m′ begins THE SAF
Both were encrypted with the same key and the same nonce. The key never appears here: c ⊕ c′ ⊕ your guess is all it takes. Guess a few more words.
Encryption is not integrity
Without a MAC, flipping a bit of the ciphertext flips a chosen bit of the plaintext, and nobody notices.
CTR hides the message but does not protect it: flip a ciphertext bit and the same plaintext bit flips, with no error. CBC is malleable too: the flip garbles its block and flips the same bit in the next.
31 and “9” is 39, so 08 turns one into the other: Mallory needs to know what the byte says, never the key.Authenticated encryption
AES-GCM and ChaCha20-Poly1305 encrypt and authenticate in one call. The one rule: never reuse a nonce under the same key.
AES-GCM is CTR plus a 16-byte tag; ChaCha20-Poly1305 suits chips without AES instructions. Associated data, a header or a user ID, travels in the clear but is bound to the message.
In one breath
- Block and stream ciphers. A block cipher scrambles fixed-size blocks under a key. A stream cipher XORs the message with a keystream.
- From DES to AES. DES’s 56-bit key fell to brute force in 1998. AES encrypts 128-bit blocks with 128, 192 or 256-bit keys and is still unbroken.
- ECB and the penguin. Encrypting each block on its own leaks patterns: equal plaintext blocks give equal ciphertext blocks.
- CBC and CTR. CBC mixes each block with the previous ciphertext, starting from a random IV. CTR encrypts a counter to make a keystream.
- Encryption is not integrity. Without a MAC, flipping a bit of the ciphertext flips a chosen bit of the plaintext, and nobody notices.
- Authenticated encryption. AES-GCM and ChaCha20-Poly1305 encrypt and authenticate in one call. The one rule: never reuse a nonce under the same key.