logo

Database

Rust Insecure Cipher Algorithm

Description

This vulnerability detector identifies the use of broken symmetric ciphers and insecure cipher modes in Rust applications. Algorithms such as DES, Triple DES and RC4, as well as the ECB mode of operation, no longer provide the confidentiality they are relied upon for: DES and RC4 are breakable with modern computing power, and ECB leaks plaintext patterns because identical blocks always encrypt to identical ciphertext. Data protected with them can be recovered or forged by an attacker who captures the ciphertext.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    Scans Rust source files that import a cryptography crate exposing weak ciphers ('des', 'rc4', 'ecb') or the 'openssl' bindings

    Identifies constructor calls such as new() and new_from_slice() on the broken cipher types Des, TdesEde2, TdesEde3, TdesEee2, TdesEee3 and Rc4, and on the ECB mode wrappers Encryptor and Decryptor

    Resolves each call to the crate the type really comes from, honoring an explicit crate qualifier at the call site and falling back to the file's imports, so identically named types from safe crates such as cbc::Encryptor are not reported

    For the openssl bindings, flags Cipher factory calls that select a broken algorithm or the ECB mode, such as des_cbc(), rc4() and aes_256_ecb()

    Reports a vulnerability for each cipher instantiation that resolves to a broken algorithm or an insecure mode of operation

Vulnerable code example

use des::{Des, KeyInit};
use openssl::symm::Cipher;

fn build_des_cipher(key: &[u8]) -> Des {
    // VULNERABLE: DES has a 56-bit key and is broken by brute force
    Des::new(key.into())
}
...

✅ Secure code example

use aes::Aes256;
use cbc::Encryptor;
use cipher::KeyIvInit;
use openssl::symm::Cipher;

fn build_aes_cipher(key: &[u8], iv: &[u8]) -> Encryptor<Aes256> {
    // SECURE: AES-256 in CBC mode instead of DES
    Encryptor::<Aes256>::new(key.into(), iv.into())...