For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/rust-security/avoid-rc4.md. A documentation index is available at /llms.txt.

Avoid using the insecure RC4 stream cipher

This product is not supported for your selected Datadog site. ().

Metadata

ID: rust-security/avoid-rc4

Language: Rust

Severity: Warning

Category: Security

CWE: 327

Related CWEs:

Description

RC4 has well-known statistical biases in its keystream and has been broken in real-world protocols including WEP and TLS. It must not be used for any security-sensitive operation. Use AES-256-GCM (via the aes-gcm crate) or another modern authenticated encryption algorithm instead.

Learn More

Non-Compliant Code Examples

use rc4;
use rc4::Rc4;
use rc4::{Rc4, KeyInit};
use openssl::symm::Cipher;

fn invalid() {
    let key = [0u8; 16];

    // RustCrypto `rc4` crate
    let _ = rc4::Rc4::new_from_slice(&key);

    // openssl/boring `Cipher::rc4()` builder
    let _ = Cipher::rc4();
    let _ = openssl::symm::Cipher::rc4();
}

Compliant Code Examples

use aes_gcm::{Aes256Gcm, KeyInit};

fn ok() {
    // Safe: AES-256-GCM instead of RC4
    let key = [0u8; 32];
    let _ = Aes256Gcm::new(&key.into());
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security