diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mod_exp.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c index 3ba8dcf2df..6b323408c8 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.33 2023/03/29 07:46:40 tb Exp $ */ | 1 | /* $OpenBSD: bn_mod_exp.c,v 1.34 2023/03/29 10:36:14 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> |
| @@ -16,8 +16,9 @@ | |||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <err.h> | 19 | #include <err.h> |
| 20 | #include <stdio.h> | ||
| 21 | #include <string.h> | ||
| 21 | 22 | ||
| 22 | #include <openssl/bn.h> | 23 | #include <openssl/bn.h> |
| 23 | #include <openssl/err.h> | 24 | #include <openssl/err.h> |
| @@ -71,15 +72,29 @@ static const struct mod_exp_test { | |||
| 71 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) | 72 | #define N_MOD_EXP_FN (sizeof(mod_exp_fn) / sizeof(mod_exp_fn[0])) |
| 72 | 73 | ||
| 73 | static void | 74 | static void |
| 74 | print_failure(const BIGNUM *got, const BIGNUM *a, const char *name) | 75 | bn_print(const char *name, const BIGNUM *bn) |
| 75 | { | 76 | { |
| 76 | fprintf(stderr, "%s test failed for a = ", name); | 77 | size_t len; |
| 77 | BN_print_fp(stderr, a); | 78 | int pad = 0; |
| 78 | fprintf(stderr, "\nwant 0, got "); | 79 | |
| 79 | BN_print_fp(stderr, got); | 80 | len = strlen(name); |
| 81 | if (len < 7) | ||
| 82 | pad = 6 - len; | ||
| 83 | |||
| 84 | fprintf(stderr, "%s: %*s", name, pad, ""); | ||
| 85 | BN_print_fp(stderr, bn); | ||
| 80 | fprintf(stderr, "\n"); | 86 | fprintf(stderr, "\n"); |
| 81 | } | 87 | } |
| 82 | 88 | ||
| 89 | static void | ||
| 90 | print_zero_test_failure(const BIGNUM *got, const BIGNUM *a, const char *name) | ||
| 91 | { | ||
| 92 | fprintf(stderr, "%s() zero test failed:\n", name); | ||
| 93 | |||
| 94 | bn_print("a", a); | ||
| 95 | bn_print("got", got); | ||
| 96 | } | ||
| 97 | |||
| 83 | static int | 98 | static int |
| 84 | bn_mod_exp_zero_test(const struct mod_exp_test *test, BN_CTX *ctx, int use_random) | 99 | bn_mod_exp_zero_test(const struct mod_exp_test *test, BN_CTX *ctx, int use_random) |
| 85 | { | 100 | { |
| @@ -119,7 +134,7 @@ bn_mod_exp_zero_test(const struct mod_exp_test *test, BN_CTX *ctx, int use_rando | |||
| 119 | } | 134 | } |
| 120 | 135 | ||
| 121 | if (!BN_is_zero(got)) { | 136 | if (!BN_is_zero(got)) { |
| 122 | print_failure(got, a, test->name); | 137 | print_zero_test_failure(got, a, test->name); |
| 123 | goto err; | 138 | goto err; |
| 124 | } | 139 | } |
| 125 | 140 | ||
| @@ -156,7 +171,7 @@ bn_mod_exp_zero_word_test(BN_CTX *ctx) | |||
| 156 | } | 171 | } |
| 157 | 172 | ||
| 158 | if (!BN_is_zero(got)) { | 173 | if (!BN_is_zero(got)) { |
| 159 | print_failure(got, one, name); | 174 | print_zero_test_failure(got, one, name); |
| 160 | goto err; | 175 | goto err; |
| 161 | } | 176 | } |
| 162 | 177 | ||
| @@ -289,29 +304,22 @@ static void | |||
| 289 | dump_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *b, const BIGNUM *q, | 304 | dump_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *b, const BIGNUM *q, |
| 290 | const BIGNUM *m, const BIGNUM *want, const BIGNUM *got, const char *name) | 305 | const BIGNUM *m, const BIGNUM *want, const BIGNUM *got, const char *name) |
| 291 | { | 306 | { |
| 292 | printf("BN_mod_exp_simple() and %s() disagree", name); | 307 | fprintf(stderr, "BN_mod_exp_simple() and %s() disagree:\n", name); |
| 293 | 308 | ||
| 294 | printf("\nwant: "); | 309 | bn_print("want", want); |
| 295 | BN_print_fp(stdout, want); | 310 | bn_print("got", got); |
| 296 | printf("\ngot: "); | ||
| 297 | BN_print_fp(stdout, got); | ||
| 298 | 311 | ||
| 299 | printf("\na: "); | 312 | bn_print("a", a); |
| 300 | BN_print_fp(stdout, a); | 313 | bn_print("p", p); |
| 301 | printf("\np: "); | ||
| 302 | BN_print_fp(stdout, p); | ||
| 303 | 314 | ||
| 304 | if (b != NULL) { | 315 | if (b != NULL) { |
| 305 | printf("\nb: "); | 316 | bn_print("b", b); |
| 306 | BN_print_fp(stdout, b); | 317 | bn_print("q", q); |
| 307 | printf("\nq: "); | ||
| 308 | BN_print_fp(stdout, q); | ||
| 309 | } | 318 | } |
| 310 | 319 | ||
| 311 | printf("\nm: "); | 320 | bn_print("m", m); |
| 312 | BN_print_fp(stdout, m); | ||
| 313 | 321 | ||
| 314 | printf("\n\n"); | 322 | fprintf(stderr, "\n"); |
| 315 | } | 323 | } |
| 316 | 324 | ||
| 317 | static int | 325 | static int |
