RSA keys shorter than 2,048 bits can be factored with modern hardware and cloud-scale compute, exposing encrypted data and signatures to recovery or forgery. NIST SP 800-57 recommends a minimum of 2,048 bits, with 3,072 or 4,096 bits preferred for data with long-term secrecy requirements. The min-length argument can be raised above the 2,048-bit default to enforce a stricter threshold. Values below 2,048 are clamped to the NIST minimum.
usersa::RsaPrivateKey;useopenssl::rsa::Rsa;userand::rngs::OsRng;fnok()-> Result<(),Box<dynstd::error::Error>>{letmutrng=OsRng;// `rsa` crate at the minimum
let_=RsaPrivateKey::new(&mutrng,2048)?;// Digit separator and type suffix — both >= 2048
let_=RsaPrivateKey::new(&mutrng,2_048)?;let_=RsaPrivateKey::new(&mutrng,4096usize)?;// Fully qualified path
let_=rsa::RsaPrivateKey::new(&mutrng,2048)?;// new_with_exp with sufficient bits
letexp=rsa::BoxedUint::from(65537u64);let_=rsa::RsaPrivateKey::new_with_exp(&mutrng,2048,exp)?;// `openssl` crate at or above the minimum
let_=Rsa::generate(2048)?;let_=openssl::rsa::Rsa::generate(4096)?;Ok(())}
Seamless integrations. Try Datadog Code Security
Datadog Code Security
Try this rule and analyze your code with Datadog Code Security
How to use this rule
1
2
rulesets:- rust-security # Rules to enforce Rust security.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Security scans to your CI pipelines