Insecure Random IV Generation

Detects initialization vectors generated using non-cryptographic random functions, compromising cipher security.

zakirkun f0ae36a 2 files · 2.3 KB Updated

File contents

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)

zakirkun/ice-tea/tree/main/skills/crypto/insecure-random-iv commit f0ae36a680

Frequently asked questions

npx skillmds@latest add zakirkun/insecure-random-iv-generation