# Insecure Random IV Generation

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

- Skill: `zakirkun/insecure-random-iv-generation` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add zakirkun/insecure-random-iv-generation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/zakirkun/insecure-random-iv-generation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: zakirkun (https://skillmd.com/u/zakirkun)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/zakirkun/insecure-random-iv-generation

---


# 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)`

