diff options
author | tb <> | 2023-03-29 07:46:40 +0000 |
---|---|---|
committer | tb <> | 2023-03-29 07:46:40 +0000 |
commit | f5a4ecc25fb1895f10744eabc0beb5a21384c987 (patch) | |
tree | 14287299e52fd8903f2c161295e3d9d32806fc8d /src | |
parent | e0c3aeb2d411ba02c94654c665c33921392d7f1c (diff) | |
download | openbsd-f5a4ecc25fb1895f10744eabc0beb5a21384c987.tar.gz openbsd-f5a4ecc25fb1895f10744eabc0beb5a21384c987.tar.bz2 openbsd-f5a4ecc25fb1895f10744eabc0beb5a21384c987.zip |
Dedup print functions on test failure
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mod_exp.c | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_exp.c b/src/regress/lib/libcrypto/bn/bn_mod_exp.c index 804cdd26d4..3ba8dcf2df 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.32 2023/03/29 07:38:16 tb Exp $ */ | 1 | /* $OpenBSD: bn_mod_exp.c,v 1.33 2023/03/29 07:46:40 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> |
@@ -286,8 +286,8 @@ generate_test_triple(int reduce, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx) | |||
286 | } | 286 | } |
287 | 287 | ||
288 | static void | 288 | static void |
289 | dump_exp_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | 289 | dump_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *b, const BIGNUM *q, |
290 | const BIGNUM *want, const BIGNUM *got, const char *name) | 290 | const BIGNUM *m, const BIGNUM *want, const BIGNUM *got, const char *name) |
291 | { | 291 | { |
292 | printf("BN_mod_exp_simple() and %s() disagree", name); | 292 | printf("BN_mod_exp_simple() and %s() disagree", name); |
293 | 293 | ||
@@ -300,8 +300,17 @@ dump_exp_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | |||
300 | BN_print_fp(stdout, a); | 300 | BN_print_fp(stdout, a); |
301 | printf("\np: "); | 301 | printf("\np: "); |
302 | BN_print_fp(stdout, p); | 302 | BN_print_fp(stdout, p); |
303 | |||
304 | if (b != NULL) { | ||
305 | printf("\nb: "); | ||
306 | BN_print_fp(stdout, b); | ||
307 | printf("\nq: "); | ||
308 | BN_print_fp(stdout, q); | ||
309 | } | ||
310 | |||
303 | printf("\nm: "); | 311 | printf("\nm: "); |
304 | BN_print_fp(stdout, m); | 312 | BN_print_fp(stdout, m); |
313 | |||
305 | printf("\n\n"); | 314 | printf("\n\n"); |
306 | } | 315 | } |
307 | 316 | ||
@@ -327,7 +336,7 @@ test_mod_exp(const BIGNUM *want, const BIGNUM *a, const BIGNUM *p, | |||
327 | errx(1, "%s() failed", test->name); | 336 | errx(1, "%s() failed", test->name); |
328 | 337 | ||
329 | if (BN_cmp(want, got) != 0) { | 338 | if (BN_cmp(want, got) != 0) { |
330 | dump_exp_results(a, p, m, want, got, test->name); | 339 | dump_results(a, p, NULL, NULL, m, want, got, test->name); |
331 | goto err; | 340 | goto err; |
332 | } | 341 | } |
333 | 342 | ||
@@ -405,30 +414,6 @@ test_bn_mod_exp(void) | |||
405 | return failed; | 414 | return failed; |
406 | } | 415 | } |
407 | 416 | ||
408 | static void | ||
409 | dump_exp2_results(const BIGNUM *a, const BIGNUM *p, const BIGNUM *b, | ||
410 | const BIGNUM *q, const BIGNUM *m, const BIGNUM *want, const BIGNUM *got) | ||
411 | { | ||
412 | printf("BN_mod_exp_simple() and BN_mod_exp2_mont() disagree"); | ||
413 | |||
414 | printf("\nwant: "); | ||
415 | BN_print_fp(stdout, want); | ||
416 | printf("\ngot: "); | ||
417 | BN_print_fp(stdout, got); | ||
418 | |||
419 | printf("\na: "); | ||
420 | BN_print_fp(stdout, a); | ||
421 | printf("\np: "); | ||
422 | BN_print_fp(stdout, p); | ||
423 | printf("\nb: "); | ||
424 | BN_print_fp(stdout, b); | ||
425 | printf("\nq: "); | ||
426 | BN_print_fp(stdout, q); | ||
427 | printf("\nm: "); | ||
428 | BN_print_fp(stdout, m); | ||
429 | printf("\n\n"); | ||
430 | } | ||
431 | |||
432 | static int | 417 | static int |
433 | bn_mod_exp2_simple(BIGNUM *out, const BIGNUM *a, const BIGNUM *p, | 418 | bn_mod_exp2_simple(BIGNUM *out, const BIGNUM *a, const BIGNUM *p, |
434 | const BIGNUM *b, const BIGNUM *q, const BIGNUM *m, BN_CTX *ctx) | 419 | const BIGNUM *b, const BIGNUM *q, const BIGNUM *m, BN_CTX *ctx) |
@@ -481,7 +466,7 @@ bn_mod_exp2_test(int reduce, BIGNUM *want, BIGNUM *got, BIGNUM *a, BIGNUM *p, | |||
481 | errx(1, "BN_mod_exp2_mont"); | 466 | errx(1, "BN_mod_exp2_mont"); |
482 | 467 | ||
483 | if (BN_cmp(want, got) != 0) { | 468 | if (BN_cmp(want, got) != 0) { |
484 | dump_exp2_results(a, p, b, q, m, want, got); | 469 | dump_results(a, p, b, q, m, want, got, "BN_mod_exp2_mont"); |
485 | failed |= 1; | 470 | failed |= 1; |
486 | } | 471 | } |
487 | } | 472 | } |