Skip to main content

Inadequate Encryption Strength Using Weak Keys in M2Crypto Moduleโ€‹

PY510
inadequate_encryption_strength
CWE-326
โš ๏ธ Warning or โ›”๏ธ Error
๐Ÿ”’ Professional Plan

Using weak key sizes for cryptographic algorithms like RSA and DSA can compromise the security of your encryption and digital signatures. Here's a brief overview of the risks associated with weak key sizes for these algorithms:

RSA (Rivest-Shamir-Adleman): RSA is widely used for both encryption and digital signatures. Weak key sizes in RSA can be vulnerable to factorization attacks, such as the famous RSA-129 challenge, which was factored in 1994 after 17 years of effort. Using small key sizes makes it easier for attackers to factor the modulus and recover the private key.

It's generally recommended to use RSA key sizes of 2048 bits or more for security in the present day, with 3072 bits or higher being increasingly preferred for long-term security.

DSA (Digital Signature Algorithm): DSA is used for digital signatures and relies on the discrete logarithm problem. Using weak key sizes in DSA can make it susceptible to attacks that involve solving the discrete logarithm problem, like the GNFS (General Number Field Sieve) algorithm.

For DSA, key sizes of 2048 bits or more are recommended for modern security. Note that DSA is not as commonly used as RSA or ECC for new applications, and ECDSA (Elliptic Curve Digital Signature Algorithm) is often preferred due to its efficiency and strong security properties.

EC (Elliptic Curve): Elliptic Curve cryptography provides strong security with relatively small key sizes compared to RSA and DSA. However, even in the case of EC, using weak curve parameters or small key sizes can expose you to vulnerabilities. The strength of an EC key depends on the curve's properties and the size of the prime used.

Recommended EC key sizes depend on the curve you select, but for modern applications, curves like NIST P-256 (secp256r1) with a 256-bit key size are considered secure. Larger curves, like NIST P-384 or P-521, can provide even higher security margins.

Exampleโ€‹

from M2Crypto import RSA


new_key = RSA.gen_key(1024, 65537)

Remediationโ€‹

Its recommended to increase the key size to at least 2048 for DSA and RSA algorithms.

from M2Crypto import RSA


new_key = RSA.gen_key(2048, 65537)

False Positivesโ€‹

In the case of a false positive the rule can be suppressed. Simply add a trailing or preceding comment line with either the rule ID (PY510) or rule category name (inadequate_encryption_strength).

Fix Iconfix
from M2Crypto import RSA


# suppress: PY510
new_key = RSA.gen_key(1024, 65537)

See alsoโ€‹