Skip to content

FIX: replace clock-seeded PRNG with SecureRandom for IV generation#27

Merged
Jens-G merged 2 commits into
masterfrom
fix/secure-random-iv
May 7, 2026
Merged

FIX: replace clock-seeded PRNG with SecureRandom for IV generation#27
Jens-G merged 2 commits into
masterfrom
fix/secure-random-iv

Conversation

@Jens-G

@Jens-G Jens-G commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • IVMode now generates IVs via SecureRandom instead of seeding from Date.now(), eliminating the predictable-IV vulnerability
  • Adds a regression test to CBCModeTest that asserts two consecutive auto-generated IVs are distinct

Closes #7

Test plan

  • haxe tests.hxml — new test_auto_iv_is_unique passes, all 1280 assertions green

🤖 Generated with Claude Code

Jens-G and others added 2 commits May 7, 2026 17:50
The Random PRNG was seeded from Date.now() at construction, making
auto-generated IVs predictable. IVMode.getIV4e() now uses
SecureRandom.getSecureRandomBytes() directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
OpenSSL 3.x generates BEGIN PRIVATE KEY (PKCS#8) by default.
The method now tries PKCS#1 first, then unwraps the PKCS#8 SEQUENCE
{ version, AlgorithmIdentifier, OCTET STRING { RSAPrivateKey } }.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jens-G Jens-G marked this pull request as draft May 7, 2026 15:54
@Jens-G Jens-G marked this pull request as ready for review May 7, 2026 15:54
@Jens-G Jens-G force-pushed the fix/secure-random-iv branch 2 times, most recently from a2dae36 to b8b285f Compare May 7, 2026 16:00
@Jens-G Jens-G merged commit d22a7bf into master May 7, 2026
10 checks passed
@Jens-G Jens-G deleted the fix/secure-random-iv branch May 7, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using PRNG to generate an IV is not a good idea

1 participant