Inadequate encryption strength due to insufficient key size
ID |
dart.cryptography.insufficient_key_size |
Severity |
high |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Cryptography |
Language |
Dart |
Description
A cryptographic key is generated below modern minimum sizes (RSA / DH < 2048 bits, AES < 128 bits, EC curves with order < 256 bits). Smaller keys are factorable or brute-forceable with present-day compute.
Rationale
Recommended minimums (NIST SP 800-57, OWASP, ENISA, BSI all agree):
-
RSA and Diffie-Hellman: 2048 bits minimum, 3072+ for long-lived secrets. 1024-bit factoring is feasible on academic clusters; 768-bit has been done publicly (TWIRL / Logjam) and dropped to a few months on nation-state hardware.
-
Symmetric (AES, ChaCha20): 128 bits minimum, 256 bits recommended for forward-secret-required contexts.
-
Elliptic curves: order >= 256 bits — P-256, Curve25519, secp256k1, secp384r1. P-192 and lower are out.
Static analysis catches the literal-integer form most often. Dynamic attacker scenarios for an undersized key range from passive plaintext recovery (offline factoring of a stored ciphertext / signature) to outright forgery of authentication tokens.
The following code illustrates a vulnerable pattern detected by this rule:
class SmallKeys {
void pcRsaWeak() {
// VULNERABLE: Inadequate encryption strength due to insufficient key size
final p1 = RSAKeyGeneratorParameters(BigInt.from(65537), 1024, 64);
// VULNERABLE: Inadequate encryption strength due to insufficient key size
final p2 = RSAKeyGeneratorParameters(BigInt.from(65537), 512, 64);
// VULNERABLE: Inadequate encryption strength due to insufficient key size
final p3 = RSAKeyGeneratorParameters(BigInt.from(65537), 1536, 64);
print('$p1 $p2 $p3');
}
}
Remediation
Use the recommended minimums above. Both package:pointycastle and
package:cryptography accept these sizes via named-argument or factory
constructors.
// Vulnerable
RSAKeyGeneratorParameters(BigInt.from(65537), 1024, 64);
Encrypter(RSA(... encoding: RSAEncoding.PKCS1));
Key.fromLength(8); // 64-bit AES key
// Fixed
RSAKeyGeneratorParameters(BigInt.from(65537), 3072, 64);
// Or the modern AEAD alternative:
final aead = AesGcm.with256bits();
References
-
OWASP Top 10 2025 - A04 : Cryptographic Failures.
-
NIST SP 800-57 Pt.1 r5 — Recommendation for Key Management — the canonical source on key-size minimums
-
BlueKrypt — Cryptographic Key Length Recommendations — Side-by-side comparison of NIST / ANSSI / ECRYPT / BSI key-size tables
-
SafeCurves — choosing safe curves for elliptic-curve cryptography — Curves with adequate order and resistance to known attacks