Course contentsShow
← Security
Lesson 99 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

CTR Mode Nonce Reuse Attacks

Understand the catastrophic consequences of reusing a nonce in CTR mode and keystream recovery attacks.

CTR Mode Nonce Reuse Attacks

What you'll learn: Why reusing the same nonce in CTR mode completely breaks encryption and allows attackers to recover your keystream.

The Catastrophic Mistake

Remember that CTR mode turns a block cipher into a stream cipher by encrypting a counter value (nonce + counter) to produce a keystream, which is XORed with your plaintext. The entire security of CTR mode relies on never generating the same keystream twice.

If you reuse the same nonce with the same key, you regenerate the exact same keystream. Here's why that's catastrophic:

Message 1: C₁ = P₁ ⊕ Keystream
Message 2: C₂ = P₂ ⊕ Keystream (same keystream!)

An attacker who captures both ciphertexts can XOR them together:

C₁ ⊕ C₂ = (P₁ ⊕ Keystream) ⊕ (P₂ ⊕ Keystream) = P₁ ⊕ P₂

The keystream cancels out! Now the attacker has the XOR of two plaintexts, and with known-plaintext techniques or language analysis, they can often recover both messages entirely.

Real-World Impact

This isn't theoretical—nonce reuse has broken real systems. If an attacker knows even part of one plaintext (like HTTP headers), they can directly recover the corresponding keystream bytes and decrypt other messages.

Analogy: It's like using the same one-time pad twice. The "one-time" part is crucial—reuse it, and you've created a two-time pad that's completely broken.

Prevention

Each encryption operation must use a unique nonce. Common strategies: random generation (if nonce is long enough), or monotonic counters that never repeat.

Key Takeaway: Nonce reuse in CTR mode is catastrophic—it eliminates encryption security by allowing keystream recovery through simple XOR operations on captured ciphertexts. Uniqueness is non-negotiable.