Insecure Random IV Generation
Overview
Even when an IV is generated dynamically (not hardcoded), using a non-cryptographic PRNG makes it predictable:
Math.random()in JavaScript (not cryptographic)random.random()in Python (Mersenne Twister, seeded predictably)rand()in C (LCG, predictable)
A predictable IV defeats the purpose of encryption for modes that rely on IV uniqueness.
Remediation
Use OS-provided cryptographic random for IV generation:
- Python:
os.urandom(16) - Node.js:
crypto.randomBytes(16) - Go:
io.ReadFull(rand.Reader, iv) - Java:
new SecureRandom().nextBytes(iv)