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.
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)...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' pentesting team, fill out this contact form.