Deterministic IVs and Predictability Attacks
What you'll learn: Why using predictable or deterministic initialization vectors (IVs) can completely undermine encryption security, especially in CBC mode.
The Core Problem
An IV should introduce randomness into encryption, ensuring that encrypting the same plaintext twice produces different ciphertexts. When IVs become deterministic (predictable or reused in a pattern), attackers can exploit this weakness.
In CBC mode, the first plaintext block is XORed with the IV before encryption. If an attacker can predict what the next IV will be, they can craft chosen plaintexts that reveal information about encrypted data.
The Attack Scenario
Imagine you're encrypting messages with CBC mode, but your IV is generated by simply incrementing a counter: IV₁ = 1, IV₂ = 2, IV₃ = 3...
An attacker who observes ciphertext knows what the next IV will be. They can:
- Predict
IV_next = n+1 - Submit a carefully crafted plaintext for encryption
- Compare the resulting ciphertext with a target ciphertext
- Extract information about the encrypted plaintext, sometimes even recovering entire blocks
Analogy: It's like sealing letters in envelopes, but always using the same decorative pattern on each envelope. An observer can track patterns, correlate messages, and identify when you're sending similar content—defeating the purpose of sealing them at all.
Why This Matters
Deterministic IVs violate a fundamental security requirement: encrypting identical plaintexts must produce different ciphertexts. Predictability gives attackers an oracle—a way to test hypotheses about encrypted data without breaking the cipher itself.
Key Takeaway: IVs must be unpredictable to attackers—typically generated using cryptographically secure random number generators. Counters, timestamps, or sequential values are never safe as IVs in CBC mode, even if they don't repeat.