logo

Database

Rust Insecure Ec Curve

Description

This detector identifies the use of insecure (weak) elliptic curve (EC) cryptography in Rust code. Specifically, it flags code that generates EC keys using deprecated or cryptographically weak curves (e.g., curves with insufficient security strength like secp112r1, secp128r1, etc.), which can make cryptographic operations vulnerable to attacks. Using weak EC curves undermines the security guarantees of asymmetric cryptography, potentially exposing sensitive data or enabling forgery attacks.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    • Scan Rust source files for imports from specific cryptographic crates (defined in `_TYPE_CRATES`) that provide elliptic curve functionality, collecting the locally used names/aliases of those imported crate identifiers.

    • For each candidate code location in the file, check whether it represents a key generation call (`_is_weak_key_generation`) that references one of the imported cryptographic crate names and specifies a weak or insecure elliptic curve parameter — a curve name or constant known to provide insufficient security strength.

    • A vulnerability is reported when a key generation function call is found that both originates from a tracked insecure-curve crate and uses a weak curve identifier, indicating that cryptographic keys are being generated with an inadequate elliptic curve.

Vulnerable code example

use p224::ecdh::EphemeralSecret;
use p224::ecdsa;
use p224::ecdsa::SigningKey;
use rand_core::OsRng;

pub fn new_token_signer() -> SigningKey {
    // UNSAFE: P-224 is below the 128-bit security level (too weak)
    SigningKey::random(&mut OsRng)...

✅ Secure code example

use p256::ecdh::EphemeralSecret;
use p256::ecdsa;
use p256::ecdsa::SigningKey;
use rand_core::OsRng;

pub fn new_token_signer() -> SigningKey {
    // SAFE: P-256 meets the 128-bit security level
    SigningKey::random(&mut OsRng)...