Skip to content
CryptoVault

Chapter IV

Symmetric encryption

One shared key locks and unlocks. It encrypts almost every byte you send, and it fails in very specific ways.

  1. IV.1Block and stream ciphers
  2. IV.2From DES to AES
  3. IV.3ECB and the penguin
  4. IV.4CBC and CTR
  5. IV.5Encryption is not integrity
  6. IV.6Authenticated encryption

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.

Block cipher: 16 bytes in, 16 outblock inAttack␣at␣dawn!!AES-128block out22ae9f09cbeb2929b503273c79a4620bStream cipher: any length, byte by byte+nonceChaCha20keystream224f51f3401bd9e12fde276fb863⊕ messageAttack␣at␣dawn= ciphertext633b25922370f9805bfe430ecf0d
A block cipher stirs a whole block at once. A stream cipher touches each byte alone, so any length works.

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.

key length, bitstime to try every keyDES569.5 daysAES-1281281.2 × 1020 yearsAES-1921922.3 × 1039 yearsAES-2562564.2 × 1058 years
At Deep Crack’s 88 billion keys a second, every extra bit doubles the search.

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.

plaintext00112233445566778899aabbccddeeff⊕ key004080c0105090d02060a0e03070b0f06309cdbaca536070b7d0e0e10451e78c6309cdba536070cae0e1b7d08c0451e75f57f71d72f5beb964bc3bf91592291aSubBytesconfusionShiftRowsdiffusionMixColumnsdiffusionAddRoundKey× 10 roundsciphertext69c4e0d86a7b0430d8cdb78070b4c55a
FIPS 197’s example, round 1. Follow the heavy cells: one byte, then its whole column. The last of the 10 rounds skips MixColumns.
AES is unbroken: the best attack saves about two bits. DES died of its key length, not its design.

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.

ECBYELLOW SUBMARINEAES761ab98c7086c509…YELLOW SUBMARINEAES761ab98c7086c509…=equal blocks showCBCIV8ce82eef…YELLOW SUBMARINEAES6e702691542c1531…YELLOW SUBMARINEAES51004b137f89a1eb…
Same key, same two blocks. ECB repeats itself; CBC feeds each ciphertext block into the next.
Try it: encrypt a penguin

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.

PitfallAdobe’s 2013 leak: 153 million accounts, passwords encrypted with 3DES-ECB under one key. Equal passwords had equal ciphertexts, next to plaintext hints.

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.

nonce ‖ counterAESkeystream0c2fbbb65ad9672a19fefd35mMEET␣AT␣NOONc = m ⊕ keystream416afee27a98330a57b1b27bm′RUN,␣WE␣KNOWc′ = m′ ⊕ keystream5e7af59a7a8e220a52b0b262Eve’s c ⊕ c′1f100b780016110005010019= m ⊕ m′, the keystream is gone
Same key and nonce, so the same keystream: XOR the two ciphertexts and it cancels, leaving the two messages mixed.
Try it: read a message you cannot decrypt
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.

PitfallA CBC IV must be unpredictable, not merely unique: TLS 1.0 reused the previous record’s last ciphertext block, and BEAST (2011) stole cookies with it.

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.

PAY␣100the order⊕ keystream5c6ee2966be957on the wire⊕00000000080000Mallory’s mask=5c6ee29663e957the bank receives⊕ keystreamPAY␣900the bank reads
“1” is 31 and “9” is 39, so 08 turns one into the other: Mallory needs to know what the byte says, never the key.
Encryption gives confidentiality, not integrity. Mallory can edit what she cannot read.

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.

keyKnoncecafebabe…associated datato: account 42plaintextPAY 100 EURseal: AES-256-GCMciphertextdae2f9069b4a7f3b035e0ftag, 16 bytes30410e9c…as sent9b → 9aMallory, byte 5openK, nonce, associated dataopenK, nonce, associated dataPAY 100 EURrejected, nothing out
The tag covers the ciphertext and the associated data: change one bit of either and nothing is decrypted.
A repeated nonce leaks m ⊕ m′, as in CTR, and lets Mallory forge tags. With random 96-bit nonces, stop at 232 messages per key.

In one breath

  1. Block and stream ciphers. A block cipher scrambles fixed-size blocks under a key. A stream cipher XORs the message with a keystream.
  2. 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.
  3. ECB and the penguin. Encrypting each block on its own leaks patterns: equal plaintext blocks give equal ciphertext blocks.
  4. CBC and CTR. CBC mixes each block with the previous ciphertext, starting from a random IV. CTR encrypts a counter to make a keystream.
  5. Encryption is not integrity. Without a MAC, flipping a bit of the ciphertext flips a chosen bit of the plaintext, and nobody notices.
  6. Authenticated encryption. AES-GCM and ChaCha20-Poly1305 encrypt and authenticate in one call. The one rule: never reuse a nonce under the same key.