logo

Database

Rust Key Derived Iv Nonce

Description

This detector identifies cryptographic implementations that improperly derive initialization vectors (IVs) or nonces from the encryption key. Using key-derived IVs/nonces is a critical vulnerability because it creates predictable patterns that can be exploited by attackers to break the encryption, potentially exposing sensitive data.

Weakness:

395 - Insecure generation of random numbers - Static IV

Category: Functionality Abuse

Detection Strategy

    • The detector activates when Rust code imports the OpenSSL cryptographic library

    • It examines function calls to identify encryption operations that derive initialization vectors or nonces from the encryption key

    • A vulnerability is reported when the code uses key-derived values for IVs or nonces instead of using random or counter-based values

    • The detection focuses on cryptographic function calls where the IV/nonce parameter is computed or derived from the same key used for encryption

Vulnerable code example

use openssl::symm::{encrypt, Cipher};
use openssl::rand::rand_bytes;

fn encrypt_data(data: &[u8]) -> Vec<u8> {
    let mut key = [0u8; 16];
    rand_bytes(&mut key).unwrap();
    
    // VULNERABLE: IV reuses the same bytes as the key...

✅ Secure code example

use openssl::symm::{encrypt, Cipher};
use openssl::rand::rand_bytes;

fn encrypt_data(data: &[u8]) -> Vec<u8> {
    let mut key = [0u8; 16];
    rand_bytes(&mut key).unwrap();
    
    let mut iv = [0u8; 16];...