From: tb Date: Sun, 26 Mar 2023 22:09:08 +0000 (+0000) Subject: Fold the small BN_mod_exp2_mont() crash test into bn_mod_exp.c X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=39f402e92221fdfc42e85bcb4e1248964bcb0467;p=openbsd Fold the small BN_mod_exp2_mont() crash test into bn_mod_exp.c --- diff --git a/regress/lib/libcrypto/bn/bn_mod_exp.c b/regress/lib/libcrypto/bn/bn_mod_exp.c index c16959c9458..10647ad3dd2 100644 --- a/regress/lib/libcrypto/bn/bn_mod_exp.c +++ b/regress/lib/libcrypto/bn/bn_mod_exp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mod_exp.c,v 1.24 2023/03/26 20:13:26 tb Exp $ */ +/* $OpenBSD: bn_mod_exp.c,v 1.25 2023/03/26 22:09:08 tb Exp $ */ /* * Copyright (c) 2022,2023 Theo Buehler @@ -589,6 +589,30 @@ run_bn_mod_exp2_tests(void) return failed; } +/* + * Small test for a crash reported by Guido Vranken, fixed in bn_exp2.c r1.13. + * https://github.com/openssl/openssl/issues/17648 + */ + +static int +test_bn_mod_exp2_mont_crash(void) +{ + BIGNUM *m; + int failed = 0; + + if ((m = BN_new()) == NULL) + errx(1, "BN_new"); + + if (BN_mod_exp2_mont(NULL, NULL, NULL, NULL, NULL, m, NULL, NULL)) { + fprintf(stderr, "BN_mod_exp2_mont succeeded\n"); + failed |= 1; + } + + BN_free(m); + + return failed; +} + int main(void) { @@ -597,6 +621,7 @@ main(void) failed |= run_bn_mod_exp_zero_tests(); failed |= run_bn_mod_exp_tests(); failed |= run_bn_mod_exp2_tests(); + failed |= test_bn_mod_exp2_mont_crash(); return failed; } diff --git a/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c b/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c index aa1cd0e0cc0..e529d3d4fa7 100644 --- a/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c +++ b/regress/lib/libcrypto/bn/bn_mod_exp2_mont.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mod_exp2_mont.c,v 1.2 2022/12/17 23:41:29 tb Exp $ */ +/* $OpenBSD: bn_mod_exp2_mont.c,v 1.3 2023/03/26 22:09:08 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler * @@ -15,29 +15,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - -#include - -/* - * Small test for a crash reported by Guido Vranken, fixed in bn_exp2.c r1.13. - * https://github.com/openssl/openssl/issues/17648 - */ - int main(void) { - BIGNUM *m; - - if ((m = BN_new()) == NULL) - errx(1, "BN_new"); - - BN_zero(m); - - if (BN_mod_exp2_mont(NULL, NULL, NULL, NULL, NULL, m, NULL, NULL)) - errx(1, "BN_mod_exp2_mont succeeded"); - - BN_free(m); - return 0; }