summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-03-26 22:09:08 +0000
committertb <>2023-03-26 22:09:08 +0000
commitab2482a4c9e9dcffdb1a9b030e21418f871c2a5d (patch)
tree4e9ad263da287237e2d7b47608c924714b267025
parentf453f28fde75de8eb526e8edb64db1eab703e1ce (diff)
downloadopenbsd-ab2482a4c9e9dcffdb1a9b030e21418f871c2a5d.tar.gz
openbsd-ab2482a4c9e9dcffdb1a9b030e21418f871c2a5d.tar.bz2
openbsd-ab2482a4c9e9dcffdb1a9b030e21418f871c2a5d.zip
Fold the small BN_mod_exp2_mont() crash test into bn_mod_exp.c
-rw-r--r--src/regress/lib/libcrypto/bn/bn_mod_exp.c27
-rw-r--r--src/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c23
2 files changed, 27 insertions, 23 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
index c16959c945..10647ad3dd 100644
--- a/src/regress/lib/libcrypto/bn/bn_mod_exp.c
+++ b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mod_exp.c,v 1.24 2023/03/26 20:13:26 tb Exp $ */ 1/* $OpenBSD: bn_mod_exp.c,v 1.25 2023/03/26 22:09:08 tb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2022,2023 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2022,2023 Theo Buehler <tb@openbsd.org>
@@ -589,6 +589,30 @@ run_bn_mod_exp2_tests(void)
589 return failed; 589 return failed;
590} 590}
591 591
592/*
593 * Small test for a crash reported by Guido Vranken, fixed in bn_exp2.c r1.13.
594 * https://github.com/openssl/openssl/issues/17648
595 */
596
597static int
598test_bn_mod_exp2_mont_crash(void)
599{
600 BIGNUM *m;
601 int failed = 0;
602
603 if ((m = BN_new()) == NULL)
604 errx(1, "BN_new");
605
606 if (BN_mod_exp2_mont(NULL, NULL, NULL, NULL, NULL, m, NULL, NULL)) {
607 fprintf(stderr, "BN_mod_exp2_mont succeeded\n");
608 failed |= 1;
609 }
610
611 BN_free(m);
612
613 return failed;
614}
615
592int 616int
593main(void) 617main(void)
594{ 618{
@@ -597,6 +621,7 @@ main(void)
597 failed |= run_bn_mod_exp_zero_tests(); 621 failed |= run_bn_mod_exp_zero_tests();
598 failed |= run_bn_mod_exp_tests(); 622 failed |= run_bn_mod_exp_tests();
599 failed |= run_bn_mod_exp2_tests(); 623 failed |= run_bn_mod_exp2_tests();
624 failed |= test_bn_mod_exp2_mont_crash();
600 625
601 return failed; 626 return failed;
602} 627}
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c b/src/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c
index aa1cd0e0cc..e529d3d4fa 100644
--- a/src/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c
+++ b/src/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mod_exp2_mont.c,v 1.2 2022/12/17 23:41:29 tb Exp $ */ 1/* $OpenBSD: bn_mod_exp2_mont.c,v 1.3 2023/03/26 22:09:08 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -15,29 +15,8 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <err.h>
19
20#include <openssl/bn.h>
21
22/*
23 * Small test for a crash reported by Guido Vranken, fixed in bn_exp2.c r1.13.
24 * https://github.com/openssl/openssl/issues/17648
25 */
26
27int 18int
28main(void) 19main(void)
29{ 20{
30 BIGNUM *m;
31
32 if ((m = BN_new()) == NULL)
33 errx(1, "BN_new");
34
35 BN_zero(m);
36
37 if (BN_mod_exp2_mont(NULL, NULL, NULL, NULL, NULL, m, NULL, NULL))
38 errx(1, "BN_mod_exp2_mont succeeded");
39
40 BN_free(m);
41
42 return 0; 21 return 0;
43} 22}