logo

Database

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.

Weakness:

395 - Insecure generation of random numbers - Static IV

Category: Functionality Abuse

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],...