diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mod_exp.c | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c index 38e77f3ad9..0d3767b07e 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.28 2023/03/29 06:32:53 tb Exp $ */ | 1 | /* $OpenBSD: bn_mod_exp.c,v 1.29 2023/03/29 06:50:51 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> |
| @@ -48,13 +48,13 @@ bn_mod_exp2_mont_second(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | |||
| 48 | return BN_mod_exp2_mont(r, one, one, a, p, m, ctx, mctx); | 48 | return BN_mod_exp2_mont(r, one, one, a, p, m, ctx, mctx); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | static const struct mod_exp_zero_test { | 51 | static const struct mod_exp_test { |
| 52 | const char *name; | 52 | const char *name; |
| 53 | int (*mod_exp_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, | 53 | int (*mod_exp_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, |
| 54 | const BIGNUM *, BN_CTX *); | 54 | const BIGNUM *, BN_CTX *); |
| 55 | int (*mod_exp_mont_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, | 55 | int (*mod_exp_mont_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, |
| 56 | const BIGNUM *, BN_CTX *, BN_MONT_CTX *); | 56 | const BIGNUM *, BN_CTX *, BN_MONT_CTX *); |
| 57 | } mod_exp_zero_test_data[] = { | 57 | } mod_exp_fn[] = { |
| 58 | INIT_MOD_EXP_FN(BN_mod_exp), | 58 | INIT_MOD_EXP_FN(BN_mod_exp), |
| 59 | INIT_MOD_EXP_FN(BN_mod_exp_ct), | 59 | INIT_MOD_EXP_FN(BN_mod_exp_ct), |
| 60 | INIT_MOD_EXP_FN(BN_mod_exp_nonct), | 60 | INIT_MOD_EXP_FN(BN_mod_exp_nonct), |
| @@ -68,8 +68,7 @@ static const struct mod_exp_zero_test { | |||
| 68 | INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_second), | 68 | INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_second), |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | #define N_MOD_EXP_ZERO_TESTS \ | 71 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) |
| 72 | (sizeof(mod_exp_zero_test_data) / sizeof(mod_exp_zero_test_data[0])) | ||
| 73 | 72 | ||
| 74 | static void | 73 | static void |
| 75 | print_failure(const BIGNUM *got, const BIGNUM *a, const char *name) | 74 | print_failure(const BIGNUM *got, const BIGNUM *a, const char *name) |
| @@ -82,8 +81,7 @@ print_failure(const BIGNUM *got, const BIGNUM *a, const char *name) | |||
| 82 | } | 81 | } |
| 83 | 82 | ||
| 84 | static int | 83 | static int |
| 85 | bn_mod_exp_zero_test(const struct mod_exp_zero_test *test, BN_CTX *ctx, | 84 | bn_mod_exp_zero_test(const struct mod_exp_test *test, BN_CTX *ctx, int use_random) |
| 86 | int use_random) | ||
| 87 | { | 85 | { |
| 88 | const BIGNUM *one; | 86 | const BIGNUM *one; |
| 89 | BIGNUM *a, *p, *got; | 87 | BIGNUM *a, *p, *got; |
| @@ -182,14 +180,12 @@ run_bn_mod_exp_zero_tests(void) | |||
| 182 | errx(1, "BN_CTX_new"); | 180 | errx(1, "BN_CTX_new"); |
| 183 | 181 | ||
| 184 | use_random = 1; | 182 | use_random = 1; |
| 185 | for (i = 0; i < N_MOD_EXP_ZERO_TESTS; i++) | 183 | for (i = 0; i < N_MOD_EXP_FN; i++) |
| 186 | failed |= bn_mod_exp_zero_test(&mod_exp_zero_test_data[i], ctx, | 184 | failed |= bn_mod_exp_zero_test(&mod_exp_fn[i], ctx, use_random); |
| 187 | use_random); | ||
| 188 | 185 | ||
| 189 | use_random = 0; | 186 | use_random = 0; |
| 190 | for (i = 0; i < N_MOD_EXP_ZERO_TESTS; i++) | 187 | for (i = 0; i < N_MOD_EXP_FN; i++) |
| 191 | failed |= bn_mod_exp_zero_test(&mod_exp_zero_test_data[i], ctx, | 188 | failed |= bn_mod_exp_zero_test(&mod_exp_fn[i], ctx, use_random); |
| 192 | use_random); | ||
| 193 | 189 | ||
| 194 | failed |= bn_mod_exp_zero_word_test(ctx); | 190 | failed |= bn_mod_exp_zero_word_test(ctx); |
| 195 | 191 | ||
| @@ -198,27 +194,6 @@ run_bn_mod_exp_zero_tests(void) | |||
| 198 | return failed; | 194 | return failed; |
| 199 | } | 195 | } |
| 200 | 196 | ||
| 201 | static const struct mod_exp_test { | ||
| 202 | const char *name; | ||
| 203 | int (*mod_exp_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, | ||
| 204 | const BIGNUM *, BN_CTX *); | ||
| 205 | int (*mod_exp_mont_fn)(BIGNUM *, const BIGNUM *, const BIGNUM *, | ||
| 206 | const BIGNUM *, BN_CTX *, BN_MONT_CTX *); | ||
| 207 | } mod_exp_fn[] = { | ||
| 208 | INIT_MOD_EXP_FN(BN_mod_exp), | ||
| 209 | INIT_MOD_EXP_FN(BN_mod_exp_ct), | ||
| 210 | INIT_MOD_EXP_FN(BN_mod_exp_nonct), | ||
| 211 | INIT_MOD_EXP_FN(BN_mod_exp_recp), | ||
| 212 | INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont), | ||
| 213 | INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_ct), | ||
| 214 | INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_consttime), | ||
| 215 | INIT_MOD_EXP_MONT_FN(BN_mod_exp_mont_nonct), | ||
| 216 | INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_first), | ||
| 217 | INIT_MOD_EXP_MONT_FN(bn_mod_exp2_mont_second), | ||
| 218 | }; | ||
| 219 | |||
| 220 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) | ||
| 221 | |||
| 222 | static int | 197 | static int |
| 223 | generate_bn(BIGNUM *bn, int avg_bits, int deviate, int force_odd) | 198 | generate_bn(BIGNUM *bn, int avg_bits, int deviate, int force_odd) |
| 224 | { | 199 | { |
