aboutsummaryrefslogtreecommitdiff
path: root/test/rsa_mp_test.c
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2025-05-07 21:18:24 +0000
committerEnji Cooper <ngie@FreeBSD.org>2025-05-07 22:37:22 +0000
commit29536654cc41bf41b92dc836c47496dc6fe0b00c (patch)
tree368a3c5b14e610bb5f6b71657f61a41e373eaf97 /test/rsa_mp_test.c
parent1c34280346af8284acdc0eae39496811d37df25d (diff)
Diffstat (limited to 'test/rsa_mp_test.c')
-rw-r--r--test/rsa_mp_test.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/rsa_mp_test.c b/test/rsa_mp_test.c
index 5405df342422..cc9e282b1409 100644
--- a/test/rsa_mp_test.c
+++ b/test/rsa_mp_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2017 BaishanCloud. All rights reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
@@ -289,8 +289,41 @@ err:
return ret;
}
+static int test_rsa_mp_gen_bad_input(void)
+{
+ int ret = 0;
+ RSA *rsa = NULL;
+ BIGNUM *ebn = NULL;
+
+ if (!TEST_ptr(rsa = RSA_new()))
+ goto err;
+
+ if (!TEST_ptr(ebn = BN_new()))
+ goto err;
+ if (!TEST_true(BN_set_word(ebn, 65537)))
+ goto err;
+
+ /* Test that a NULL exponent fails and does not segfault */
+ if (!TEST_int_eq(RSA_generate_multi_prime_key(rsa, 1024, 2, NULL, NULL), 0))
+ goto err;
+
+ /* Test invalid bitsize fails */
+ if (!TEST_int_eq(RSA_generate_multi_prime_key(rsa, 500, 2, ebn, NULL), 0))
+ goto err;
+
+ /* Test invalid prime count fails */
+ if (!TEST_int_eq(RSA_generate_multi_prime_key(rsa, 1024, 1, ebn, NULL), 0))
+ goto err;
+ ret = 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);
return 1;
}