Commit b0a599bd9d for openssl.org
commit b0a599bd9d194909768205dc910d048a5099ab3e
Author: ndossche <niels.dossche@ugent.be>
Date: Tue Sep 22 19:44:12 2026 +0200
Add an mfail test for rsa_multiprime_keygen()
Sampled rather than exhaustive because a single key generation performs a
few thousand allocations.
Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Fri Oct 2 08:02:55 2026
Merged-from: https://github.com/openssl/openssl/pull/32739
diff --git a/test/rsa_mp_test.c b/test/rsa_mp_test.c
index 81fa7d23cc..f3daf20f5d 100644
--- a/test/rsa_mp_test.c
+++ b/test/rsa_mp_test.c
@@ -313,9 +313,38 @@ err:
return ret;
}
+static int test_rsa_mp_gen_mfail(void)
+{
+ int ret = 0;
+ RSA *rsa = NULL;
+ BIGNUM *ebn = NULL;
+
+ /* Setting up is not under injection, only the generation itself is. */
+ if (!TEST_ptr(rsa = RSA_new()))
+ goto err;
+ if (!TEST_ptr(ebn = BN_new()))
+ goto err;
+ if (!TEST_true(BN_set_word(ebn, RSA_F4)))
+ goto err;
+
+ MFAIL_start();
+ ret = RSA_generate_multi_prime_key(rsa, 1024, NUM_EXTRA_PRIMES + 2, ebn, NULL);
+ MFAIL_end();
+
+ /* If the generation was successful, the key must be usable. */
+ if (ret > 0)
+ ret = TEST_true(RSA_check_key_ex(rsa, NULL)) ? 1 : -1;
+
+err:
+ BN_free(ebn);
+ RSA_free(rsa);
+ return ret;
+}
+
int setup_tests(void)
{
ADD_TEST(test_rsa_mp_gen_bad_input);
ADD_ALL_TESTS(test_rsa_mp, 2);
+ ADD_MFAIL_SAMPLED_TEST(test_rsa_mp_gen_mfail, 64);
return 1;
}