summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-03-26 20:13:26 +0000
committertb <>2023-03-26 20:13:26 +0000
commitf453f28fde75de8eb526e8edb64db1eab703e1ce (patch)
treea007603694f04280004341dea8255faed79e94f1 /src
parent8f3213695d21f184044158c617b8718951a19797 (diff)
downloadopenbsd-f453f28fde75de8eb526e8edb64db1eab703e1ce.tar.gz
openbsd-f453f28fde75de8eb526e8edb64db1eab703e1ce.tar.bz2
openbsd-f453f28fde75de8eb526e8edb64db1eab703e1ce.zip
Test negative modulus as well.
Lower the number of rounds. These tests are expensive.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/bn/bn_mod_exp.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c
index f4a6274af2..c16959c945 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.23 2023/03/26 20:09:14 tb Exp $ */ 1/* $OpenBSD: bn_mod_exp.c,v 1.24 2023/03/26 20:13:26 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>
@@ -24,8 +24,8 @@
24 24
25#include "bn_local.h" 25#include "bn_local.h"
26 26
27#define N_MOD_EXP_TESTS 400 27#define N_MOD_EXP_TESTS 100
28#define N_MOD_EXP2_TESTS 100 28#define N_MOD_EXP2_TESTS 50
29 29
30#define INIT_MOD_EXP_FN(f) { .name = #f, .mod_exp_fn = (f), } 30#define INIT_MOD_EXP_FN(f) { .name = #f, .mod_exp_fn = (f), }
31#define INIT_MOD_EXP_MONT_FN(f) { .name = #f, .mod_exp_mont_fn = (f), } 31#define INIT_MOD_EXP_MONT_FN(f) { .name = #f, .mod_exp_mont_fn = (f), }
@@ -404,9 +404,10 @@ bn_mod_exp_test(int reduce, BIGNUM *want, BIGNUM *a, BIGNUM *p, BIGNUM *m,
404 if (!generate_test_triple(reduce, a, p, m, ctx)) 404 if (!generate_test_triple(reduce, a, p, m, ctx))
405 errx(1, "generate_test_triple"); 405 errx(1, "generate_test_triple");
406 406
407 for (i = 0; i < 4; i++) { 407 for (i = 0; i < 8; i++) {
408 BN_set_negative(a, i & 1); 408 BN_set_negative(a, i & 1);
409 BN_set_negative(p, (i >> 1) & 1); 409 BN_set_negative(p, (i >> 1) & 1);
410 BN_set_negative(m, (i >> 2) & 1);
410 411
411 if ((BN_mod_exp_simple(want, a, p, m, ctx)) <= 0) 412 if ((BN_mod_exp_simple(want, a, p, m, ctx)) <= 0)
412 errx(1, "BN_mod_exp_simple"); 413 errx(1, "BN_mod_exp_simple");
@@ -521,11 +522,12 @@ bn_mod_exp2_test(int reduce, BIGNUM *want, BIGNUM *got, BIGNUM *a1, BIGNUM *p1,
521 if (!generate_test_quintuple(reduce, a1, p1, a2, p2, m, ctx)) 522 if (!generate_test_quintuple(reduce, a1, p1, a2, p2, m, ctx))
522 errx(1, "generate_test_quintuple"); 523 errx(1, "generate_test_quintuple");
523 524
524 for (i = 0; i < 16; i++) { 525 for (i = 0; i < 32; i++) {
525 BN_set_negative(a1, i & 1); 526 BN_set_negative(a1, i & 1);
526 BN_set_negative(p1, (i >> 1) & 1); 527 BN_set_negative(p1, (i >> 1) & 1);
527 BN_set_negative(a2, (i >> 2) & 1); 528 BN_set_negative(a2, (i >> 2) & 1);
528 BN_set_negative(p2, (i >> 3) & 1); 529 BN_set_negative(p2, (i >> 3) & 1);
530 BN_set_negative(m, (i >> 4) & 1);
529 531
530 if (!bn_mod_exp2_simple(want, a1, p1, a2, p2, m, ctx)) 532 if (!bn_mod_exp2_simple(want, a1, p1, a2, p2, m, ctx))
531 errx(1, "BN_mod_exp_simple"); 533 errx(1, "BN_mod_exp_simple");