fix(crypto): prevent nonce reuse vulnerability in AEAD encryption#2
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SecurityContextnow uses fully random 96-bit nonces from CSPRNG#[cfg(test)]builds onlyframe.rsencode_with_aead()uses secure random noncesSecurity 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