Rust Hardcoded Aead Nonce
Description
This vulnerability detector identifies hardcoded AEAD (Authenticated Encryption with Associated Data) nonces in Rust code that uses OpenSSL. Using hardcoded nonces in AEAD encryption is a critical security flaw that completely breaks the security guarantees of the encryption scheme, making encrypted data vulnerable to various attacks including plaintext recovery.
Detection Strategy
• Scans Rust source code files that import the OpenSSL crate
• Identifies function calls to AEAD encryption methods (such as encrypt, decrypt, or cipher operations)
• Examines the cipher argument to verify it's configured for AEAD mode encryption
• Checks the IV (Initialization Vector) or nonce argument to determine if it contains hardcoded values
• Reports a vulnerability when both conditions are met: the cipher is in AEAD mode and the nonce/IV parameter uses a hardcoded value instead of a randomly generated one
Vulnerable code example
use openssl::symm::{encrypt_aead, Cipher};
fn encrypt_data(key: &[u8], plaintext: &[u8], aad: &[u8], tag: &mut [u8]) -> Vec<u8> {
// VULNERABLE: hardcoded nonce reused on every encryption
encrypt_aead(Cipher::aes_256_gcm(), key, Some(b"000000000000"), aad, plaintext, tag).unwrap()
}
fn encrypt_with_variable(key: &[u8], plaintext: &[u8], aad: &[u8], tag: &mut [u8]) -> Vec<u8> {...✅ Secure code example
use openssl::symm::{encrypt_aead, Cipher};
use rand::{rngs::OsRng, RngCore};
fn encrypt_data(key: &[u8], plaintext: &[u8], aad: &[u8], tag: &mut [u8]) -> Vec<u8> {
let mut nonce = [0u8; 12];
OsRng.fill_bytes(&mut nonce);
// SAFE: nonce is randomly generated for each encryption call
encrypt_aead(Cipher::aes_256_gcm(), key, Some(&nonce), aad, plaintext, tag).unwrap()...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.