Skip to content

fix(crypto): prevent nonce reuse vulnerability in AEAD encryption#2

Merged
aWN4Y25pa2EK merged 1 commit into
mainfrom
fix/nonce-reuse-prevention
Jan 21, 2026
Merged

fix(crypto): prevent nonce reuse vulnerability in AEAD encryption#2
aWN4Y25pa2EK merged 1 commit into
mainfrom
fix/nonce-reuse-prevention

Conversation

@aWN4Y25pa2EK
Copy link
Copy Markdown
Member

Summary

Fixes a critical security vulnerability where counter-based nonces reset to 0 on process restart, causing nonce reuse with the same key. For ChaCha20-Poly1305, nonce reuse enables key recovery attacks.

Changes

  • SecurityContext now uses fully random 96-bit nonces from CSPRNG
  • Deterministic nonces restricted to #[cfg(test)] builds only
  • frame.rs encode_with_aead() uses secure random nonces
  • Added nonce generation security documentation (Section 7.8.4)
  • Added tests for nonce uniqueness and entropy

Security Analysis

Before: Counter started at 0 on every process restart → same nonces reused with same key → catastrophic AEAD failure

After: Random 96-bit nonces → birthday bound at 2^48 messages → collision probability ~2^-49 at 16M messages (negligible for M2M sessions)

Testing

  • 241+ tests passing
  • Clippy clean
  • New tests verify nonce uniqueness and entropy

SECURITY: Counter-based nonces reset to 0 on process restart, which
causes nonce reuse with the same key - a catastrophic failure for
ChaCha20-Poly1305 that enables key recovery attacks.

Changes:
- SecurityContext now uses fully random 96-bit nonces from CSPRNG
- Deterministic nonces restricted to #[cfg(test)] builds only
- frame.rs encode_with_aead() now uses secure random nonces
- Added comprehensive nonce generation docs (Section 7.8.4)
- Added tests for nonce uniqueness and entropy

The random nonce approach has birthday bound at 2^48 messages, which
is negligible risk for typical M2M sessions (<2^-49 collision prob
at 16M messages).
@aWN4Y25pa2EK aWN4Y25pa2EK merged commit 4993855 into main Jan 21, 2026
3 checks passed
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.

1 participant