diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_test.c | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_test.c b/src/regress/lib/libcrypto/bn/bn_test.c index 4cefc27ab7..ce26a42c96 100644 --- a/src/regress/lib/libcrypto/bn/bn_test.c +++ b/src/regress/lib/libcrypto/bn/bn_test.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_test.c,v 1.10 2023/04/07 22:29:33 tb Exp $ */ | 1 | /* $OpenBSD: bn_test.c,v 1.11 2023/04/07 22:30:31 tb 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 | * |
@@ -424,9 +424,8 @@ test_sub(BIO *bp) | |||
424 | if (i < num1) { | 424 | if (i < num1) { |
425 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | 425 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); |
426 | CHECK_GOTO(bn_copy(b, a)); | 426 | CHECK_GOTO(bn_copy(b, a)); |
427 | if (BN_set_bit(a, i) == 0) { | 427 | if (BN_set_bit(a, i) == 0) |
428 | goto err; | 428 | goto err; |
429 | } | ||
430 | CHECK_GOTO(BN_add_word(b, i)); | 429 | CHECK_GOTO(BN_add_word(b, i)); |
431 | } else { | 430 | } else { |
432 | CHECK_GOTO(BN_bntest_rand(b, 400 + i - num1, 0, 0)); | 431 | CHECK_GOTO(BN_bntest_rand(b, 400 + i - num1, 0, 0)); |
@@ -571,22 +570,19 @@ test_div_word(BIO *bp) | |||
571 | for (i = 0; i < num0; i++) { | 570 | for (i = 0; i < num0; i++) { |
572 | do { | 571 | do { |
573 | if (!BN_bntest_rand(a, 512, -1, 0) || | 572 | if (!BN_bntest_rand(a, 512, -1, 0) || |
574 | !BN_bntest_rand(b, BN_BITS2, -1, 0)) { | 573 | !BN_bntest_rand(b, BN_BITS2, -1, 0)) |
575 | goto err; | 574 | goto err; |
576 | } | ||
577 | s = BN_get_word(b); | 575 | s = BN_get_word(b); |
578 | } while (!s); | 576 | } while (!s); |
579 | 577 | ||
580 | if (!bn_copy(b, a)) { | 578 | if (!bn_copy(b, a)) |
581 | goto err; | 579 | goto err; |
582 | } | ||
583 | 580 | ||
584 | rmod = BN_mod_word(b, s); | 581 | rmod = BN_mod_word(b, s); |
585 | r = BN_div_word(b, s); | 582 | r = BN_div_word(b, s); |
586 | 583 | ||
587 | if (r == (BN_ULONG)-1 || rmod == (BN_ULONG)-1) { | 584 | if (r == (BN_ULONG)-1 || rmod == (BN_ULONG)-1) |
588 | goto err; | 585 | goto err; |
589 | } | ||
590 | 586 | ||
591 | if (rmod != r) { | 587 | if (rmod != r) { |
592 | fprintf(stderr, "Mod (word) test failed!\n"); | 588 | fprintf(stderr, "Mod (word) test failed!\n"); |
@@ -1143,9 +1139,8 @@ test_mod_exp(BIO *bp, BN_CTX *ctx) | |||
1143 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | 1139 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); |
1144 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | 1140 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); |
1145 | 1141 | ||
1146 | if (!BN_mod_exp(d, a, b, c, ctx)) { | 1142 | if (!BN_mod_exp(d, a, b, c, ctx)) |
1147 | goto err; | 1143 | goto err; |
1148 | } | ||
1149 | 1144 | ||
1150 | if (bp != NULL) { | 1145 | if (bp != NULL) { |
1151 | if (!results) { | 1146 | if (!results) { |
@@ -1173,9 +1168,8 @@ test_mod_exp(BIO *bp, BN_CTX *ctx) | |||
1173 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | 1168 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); |
1174 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | 1169 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); |
1175 | 1170 | ||
1176 | if (!BN_mod_exp_ct(d, a, b, c, ctx)) { | 1171 | if (!BN_mod_exp_ct(d, a, b, c, ctx)) |
1177 | goto err; | 1172 | goto err; |
1178 | } | ||
1179 | 1173 | ||
1180 | if (bp != NULL) { | 1174 | if (bp != NULL) { |
1181 | if (!results) { | 1175 | if (!results) { |
@@ -1203,9 +1197,8 @@ test_mod_exp(BIO *bp, BN_CTX *ctx) | |||
1203 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | 1197 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); |
1204 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | 1198 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); |
1205 | 1199 | ||
1206 | if (!BN_mod_exp_nonct(d, a, b, c, ctx)) { | 1200 | if (!BN_mod_exp_nonct(d, a, b, c, ctx)) |
1207 | goto err; | 1201 | goto err; |
1208 | } | ||
1209 | 1202 | ||
1210 | if (bp != NULL) { | 1203 | if (bp != NULL) { |
1211 | if (!results) { | 1204 | if (!results) { |
@@ -1280,9 +1273,8 @@ test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx) | |||
1280 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | 1273 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); |
1281 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | 1274 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); |
1282 | 1275 | ||
1283 | if (!BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) { | 1276 | if (!BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) |
1284 | goto err; | 1277 | goto err; |
1285 | } | ||
1286 | 1278 | ||
1287 | if (bp != NULL) { | 1279 | if (bp != NULL) { |
1288 | if (!results) { | 1280 | if (!results) { |
@@ -1352,9 +1344,8 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) | |||
1352 | /* Zero exponent */ | 1344 | /* Zero exponent */ |
1353 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | 1345 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); |
1354 | CHECK_GOTO(BN_zero(p)); | 1346 | CHECK_GOTO(BN_zero(p)); |
1355 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) { | 1347 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) |
1356 | goto err; | 1348 | goto err; |
1357 | } | ||
1358 | if (!BN_is_one(d)) { | 1349 | if (!BN_is_one(d)) { |
1359 | fprintf(stderr, "Modular exponentiation test failed!\n"); | 1350 | fprintf(stderr, "Modular exponentiation test failed!\n"); |
1360 | goto err; | 1351 | goto err; |
@@ -1435,9 +1426,8 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) | |||
1435 | /* Zero input */ | 1426 | /* Zero input */ |
1436 | CHECK_GOTO(BN_bntest_rand(p, 1024, 0, 0)); | 1427 | CHECK_GOTO(BN_bntest_rand(p, 1024, 0, 0)); |
1437 | CHECK_GOTO(BN_zero(a)); | 1428 | CHECK_GOTO(BN_zero(a)); |
1438 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) { | 1429 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) |
1439 | goto err; | 1430 | goto err; |
1440 | } | ||
1441 | if (!BN_is_zero(d)) { | 1431 | if (!BN_is_zero(d)) { |
1442 | fprintf(stderr, "Modular exponentiation test failed!\n"); | 1432 | fprintf(stderr, "Modular exponentiation test failed!\n"); |
1443 | goto err; | 1433 | goto err; |
@@ -1449,27 +1439,22 @@ test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) | |||
1449 | */ | 1439 | */ |
1450 | CHECK_GOTO(BN_one(a)); | 1440 | CHECK_GOTO(BN_one(a)); |
1451 | CHECK_GOTO(BN_MONT_CTX_set(mont, m, ctx)); | 1441 | CHECK_GOTO(BN_MONT_CTX_set(mont, m, ctx)); |
1452 | if (!BN_from_montgomery(e, a, mont, ctx)) { | 1442 | if (!BN_from_montgomery(e, a, mont, ctx)) |
1453 | goto err; | 1443 | goto err; |
1454 | } | 1444 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) |
1455 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) { | ||
1456 | goto err; | 1445 | goto err; |
1457 | } | 1446 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) |
1458 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) { | ||
1459 | goto err; | 1447 | goto err; |
1460 | } | ||
1461 | if (BN_cmp(a, d) != 0) { | 1448 | if (BN_cmp(a, d) != 0) { |
1462 | fprintf(stderr, "Modular exponentiation test failed!\n"); | 1449 | fprintf(stderr, "Modular exponentiation test failed!\n"); |
1463 | goto err; | 1450 | goto err; |
1464 | } | 1451 | } |
1465 | /* Finally, some regular test vectors. */ | 1452 | /* Finally, some regular test vectors. */ |
1466 | CHECK_GOTO(BN_bntest_rand(e, 1024, 0, 0)); | 1453 | CHECK_GOTO(BN_bntest_rand(e, 1024, 0, 0)); |
1467 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) { | 1454 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) |
1468 | goto err; | 1455 | goto err; |
1469 | } | 1456 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) |
1470 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) { | ||
1471 | goto err; | 1457 | goto err; |
1472 | } | ||
1473 | if (BN_cmp(a, d) != 0) { | 1458 | if (BN_cmp(a, d) != 0) { |
1474 | fprintf(stderr, "Modular exponentiation test failed!\n"); | 1459 | fprintf(stderr, "Modular exponentiation test failed!\n"); |
1475 | goto err; | 1460 | goto err; |
@@ -1513,9 +1498,8 @@ test_exp(BIO *bp, BN_CTX *ctx) | |||
1513 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | 1498 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); |
1514 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | 1499 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); |
1515 | 1500 | ||
1516 | if (BN_exp(d, a, b, ctx) <= 0) { | 1501 | if (BN_exp(d, a, b, ctx) <= 0) |
1517 | goto err; | 1502 | goto err; |
1518 | } | ||
1519 | 1503 | ||
1520 | if (bp != NULL) { | 1504 | if (bp != NULL) { |
1521 | if (!results) { | 1505 | if (!results) { |