Enforce a sane key size when generating an RSA key #7556
Labels
component-crypto
Crypto primitives and low-level interfaces
enhancement
size-xs
Estimated task size: extra small (a few hours at most)
When generating an RSA key with
mbedtls_rsa_gen_key
, the minimum key size is 128 bits. This is clearly not enforced for security, just to avoid edge cases with small numbers during the generation process.The PSA API does not enforce a minimum. There's no pk API for key generation.
This creates a risk of misuse: if you accidentally specify a key size in bytes (because that's the intended size of the signature or ciphertext) rather than bits, then a reasonable wish for a 2048-bit = 256-byte key becomes a request for an insanely small 256-bit key — but still large enough for a PKCS#1v1.5 encryption of a 16-byte payload, so you might not notice in functional testing.
We should enforce a minimum key size in
mbedtls_rsa_gen_key
that's not outright insecure. What should the threshold be?Should we make any change to 2.28 LTS? It's a security improvement, but not a critical one (since the library itself isn't broken: this is only about a risk of accidental misuse).
Note that I do not propose to introduce any minimum when using a key. You will still be able to verify or even re-create RSA-321 signatures (but not generate new keys).
Task description
mbedtls_rsa_gen_key
andpsa_generate_key
(before driver dispatch).mbedtls_rsa_gen_key
and viapsa_generate_key
. Test at leastmin - 2
(min - 1
would not be conclusive because we require the size to be a multiple of 2) andmin - 128
(in case the code changes to enforce more divisibility for the size).The text was updated successfully, but these errors were encountered: