summaryrefslogtreecommitdiff
path: root/src/regress
diff options
context:
space:
mode:
authorbcook <>2016-07-05 02:54:35 +0000
committerbcook <>2016-07-05 02:54:35 +0000
commit893dbf4e24a37a4ac3cf521b4c386df31e6edf21 (patch)
tree90c31bd2681496537a3d217c0819f837c5e8d8b4 /src/regress
parent25f89b1a60c16a8a6f6b2258cfebc4c8db737315 (diff)
downloadopenbsd-893dbf4e24a37a4ac3cf521b4c386df31e6edf21.tar.gz
openbsd-893dbf4e24a37a4ac3cf521b4c386df31e6edf21.tar.bz2
openbsd-893dbf4e24a37a4ac3cf521b4c386df31e6edf21.zip
On systems where we do not have BN_ULLONG defined (most 64-bit systems),
BN_mod_word() can return incorrect results if the supplied modulus is too big, so we need to fall back to BN_div_word. Now that BN_mod_word may fail, handle errors properly update the man page. Thanks to Brian Smith for pointing out these fixes from BoringSSL: https://boringssl.googlesource.com/boringssl/+/67cb49d045f04973ddba0f92fe8a8ad483c7da89 https://boringssl.googlesource.com/boringssl/+/44bedc348d9491e63c7ed1438db100a4b8a830be ok beck@
Diffstat (limited to 'src/regress')
-rw-r--r--src/regress/lib/libcrypto/bn/general/bntest.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/bn/general/bntest.c b/src/regress/lib/libcrypto/bn/general/bntest.c
index c6bd788b54..1d541778e3 100644
--- a/src/regress/lib/libcrypto/bn/general/bntest.c
+++ b/src/regress/lib/libcrypto/bn/general/bntest.c
@@ -514,7 +514,7 @@ int
514test_div_word(BIO *bp) 514test_div_word(BIO *bp)
515{ 515{
516 BIGNUM a, b; 516 BIGNUM a, b;
517 BN_ULONG r, s; 517 BN_ULONG r, rmod, s;
518 int i; 518 int i;
519 int rc = 1; 519 int rc = 1;
520 520
@@ -523,14 +523,34 @@ test_div_word(BIO *bp)
523 523
524 for (i = 0; i < num0; i++) { 524 for (i = 0; i < num0; i++) {
525 do { 525 do {
526 BN_bntest_rand(&a, 512, -1, 0); 526 if (!BN_bntest_rand(&a, 512, -1, 0) ||
527 BN_bntest_rand(&b, BN_BITS2, -1, 0); 527 !BN_bntest_rand(&b, BN_BITS2, -1, 0)) {
528 rc = 0;
529 break;
530 }
528 s = b.d[0]; 531 s = b.d[0];
529 } while (!s); 532 } while (!s);
530 533
531 BN_copy(&b, &a); 534 if (!BN_copy(&b, &a)) {
535 rc = 0;
536 break;
537 }
538
539 s = b.d[0];
540 rmod = BN_mod_word(&b, s);
532 r = BN_div_word(&b, s); 541 r = BN_div_word(&b, s);
533 542
543 if (r == (BN_ULONG)-1 || rmod == (BN_ULONG)-1) {
544 rc = 0;
545 break;
546 }
547
548 if (rmod != r) {
549 fprintf(stderr, "Mod (word) test failed!\n");
550 rc = 0;
551 break;
552 }
553
534 if (bp != NULL) { 554 if (bp != NULL) {
535 if (!results) { 555 if (!results) {
536 BN_print(bp, &a); 556 BN_print(bp, &a);