Rust Predictable Iv Nonce Source
Description
This detector identifies predictable initialization vectors (IVs) or nonces used in AEAD encryption operations in Rust code. Using predictable IVs/nonces in cryptographic operations severely compromises security by potentially allowing attackers to recover plaintext or perform cryptographic attacks.
Detection Strategy
• Scans Rust source code files that import the OpenSSL crate
• Identifies function calls to AEAD encryption methods
• Analyzes the cipher argument to confirm it uses AEAD (Authenticated Encryption with Associated Data) encryption
• Examines the IV/nonce argument to determine if it uses a predictable source rather than cryptographically secure random generation
• Reports a vulnerability when both conditions are met: AEAD cipher is used AND the IV/nonce is generated predictably
Vulnerable code example
use openssl::symm::{encrypt_aead, Cipher};
use std::time::{SystemTime, UNIX_EPOCH};
fn encrypt_with_predictable_nonce(
key: &[u8],
plaintext: &[u8],
aad: &[u8],
tag: &mut [u8],...✅ Secure code example
use openssl::symm::{encrypt_aead, Cipher};
use rand::{rngs::OsRng, RngCore};
fn encrypt_with_predictable_nonce(
key: &[u8],
plaintext: &[u8],
aad: &[u8],
tag: &mut [u8],...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.