diff options
author | jsing <> | 2023-03-15 04:26:23 +0000 |
---|---|---|
committer | jsing <> | 2023-03-15 04:26:23 +0000 |
commit | 68d4a79dbefd9905bddd67b25a805bbe5ee1c220 (patch) | |
tree | 296cfff8b086d854ab4ed27e07995ad9234355d4 /src | |
parent | 16ade7a3fa0598ba43237cd3bd3acb9e3f8b5ec3 (diff) | |
download | openbsd-68d4a79dbefd9905bddd67b25a805bbe5ee1c220.tar.gz openbsd-68d4a79dbefd9905bddd67b25a805bbe5ee1c220.tar.bz2 openbsd-68d4a79dbefd9905bddd67b25a805bbe5ee1c220.zip |
Include tests with negative values in BN_mod_exp* regress.
This currently fails.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mod_exp.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c index aca2ee68fd..a2dc2a4e36 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.11 2022/12/08 07:18:47 tb Exp $ */ | 1 | /* $OpenBSD: bn_mod_exp.c,v 1.12 2023/03/15 04:26:23 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -89,6 +89,15 @@ static const struct mod_exp_test { | |||
89 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) | 89 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) |
90 | 90 | ||
91 | static int | 91 | static int |
92 | rand_neg(void) | ||
93 | { | ||
94 | static unsigned int neg = 0; | ||
95 | static int sign[8] = { 0, 0, 0, 1, 1, 0, 1, 1 }; | ||
96 | |||
97 | return (sign[(neg++) % 8]); | ||
98 | } | ||
99 | |||
100 | static int | ||
92 | test_mod_exp(const BIGNUM *result_simple, const BIGNUM *a, const BIGNUM *b, | 101 | test_mod_exp(const BIGNUM *result_simple, const BIGNUM *a, const BIGNUM *b, |
93 | const BIGNUM *m, BN_CTX *ctx, const struct mod_exp_test *test) | 102 | const BIGNUM *m, BN_CTX *ctx, const struct mod_exp_test *test) |
94 | { | 103 | { |
@@ -161,15 +170,19 @@ main(int argc, char *argv[]) | |||
161 | if ((result_simple = BN_CTX_get(ctx)) == NULL) | 170 | if ((result_simple = BN_CTX_get(ctx)) == NULL) |
162 | goto err; | 171 | goto err; |
163 | 172 | ||
164 | for (i = 0; i < 200; i++) { | 173 | for (i = 0; i < 1000; i++) { |
165 | c = arc4random() % BN_BITS - BN_BITS2; | 174 | c = arc4random() % BN_BITS - BN_BITS2; |
166 | if (!BN_rand(a, NUM_BITS + c, 0, 0)) | 175 | if (!BN_rand(a, NUM_BITS + c, 0, 0)) |
167 | goto err; | 176 | goto err; |
168 | 177 | ||
178 | BN_set_negative(a, rand_neg()); | ||
179 | |||
169 | c = arc4random() % BN_BITS - BN_BITS2; | 180 | c = arc4random() % BN_BITS - BN_BITS2; |
170 | if (!BN_rand(b, NUM_BITS + c, 0, 0)) | 181 | if (!BN_rand(b, NUM_BITS + c, 0, 0)) |
171 | goto err; | 182 | goto err; |
172 | 183 | ||
184 | BN_set_negative(b, rand_neg()); | ||
185 | |||
173 | c = arc4random() % BN_BITS - BN_BITS2; | 186 | c = arc4random() % BN_BITS - BN_BITS2; |
174 | if (!BN_rand(m, NUM_BITS + c, 0, 1)) | 187 | if (!BN_rand(m, NUM_BITS + c, 0, 1)) |
175 | goto err; | 188 | goto err; |