Limit the execution time of RSA public key check
authorTomas Mraz <tomas@openssl.org>
Fri, 22 Dec 2023 15:25:56 +0000 (16:25 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 15 Jan 2024 09:58:05 +0000 (10:58 +0100)
commit18c02492138d1eb8b6548cb26e7b625fb2414a2a
treea25e4f66a2ae78a697926a1c2e7d69e5e88e3696
parent11f7b60b6ff4d2186f83fbe05f3ffbdebaa8572b
Limit the execution time of RSA public key check

Fixes CVE-2023-6237

If a large and incorrect RSA public key is checked with
EVP_PKEY_public_check() the computation could take very long time
due to no limit being applied to the RSA public key size and
unnecessarily high number of Miller-Rabin algorithm rounds
used for non-primality check of the modulus.

Now the keys larger than 16384 bits (OPENSSL_RSA_MAX_MODULUS_BITS)
will fail the check with RSA_R_MODULUS_TOO_LARGE error reason.
Also the number of Miller-Rabin rounds was set to 5.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23243)

(cherry picked from commit e09fc1d746a4fd15bb5c3d7bbbab950aadd005db)
crypto/rsa/rsa_sp800_56b_check.c
test/recipes/91-test_pkey_check.t
test/recipes/91-test_pkey_check_data/rsapub_17k.pem [new file with mode: 0644]