Description
A key that is too short for its algorithm reduces the work needed to recover it.
Potential impact
Depending on the key’s purpose, a compromise can expose encrypted credentials, allow data or signatures to be forged, or grant unauthorized access.
Remediation
Choose 128, 192 or 256 bits for AES and at least 2048 bits for RSA. For ECC, start at 224 bits. For new systems, choose P-256 or a curve with at least the same 128-bit security strength.
Examples
RSA key generation
Before
# Noncompliant RSA key generation with pycryptodome
from Crypto.PublicKey import RSA
key = RSA.generate(1024) # Insufficient key size
After
# Compliant RSA key generation with pycryptodome
from Crypto.PublicKey import RSA
key = RSA.generate(3072) # Use at least 2048 bits
Explanation
RSA.generate(3072) generates a new 3072-bit RSA key.
DSA key generation
These excerpts compare key sizes in legacy DSA code. FIPS 186-5 permits DSA only to verify signatures generated before the standard was implemented. Choose a different algorithm for new signatures.
Before
# Noncompliant DSA key generation with pycryptodome
from Crypto.PublicKey import DSA
key = DSA.generate(1024) # Insufficient key size
After
# DSA key-size comparison with pycryptodome
from Crypto.PublicKey import DSA
key = DSA.generate(3072) # Use at least 2048 bits
Explanation
The two calls differ only in the DSA key size, 1024 or 3072 bits.
ECC key generation
Before
# Noncompliant ECC key generation with pycryptodome
from Crypto.PublicKey import ECC
key = ECC.generate(curve="secp192r1") # Insufficient key size
After
# Compliant ECC key generation with pycryptodome
from Crypto.PublicKey import ECC
key = ECC.generate(curve="P-256") # Use NIST P-256 for 128-bit security strength
Explanation
The example replaces secp192r1 with P-256, which provides 128-bit security strength. Ed25519 is a signature algorithm.