diff options
author | tb <> | 2023-04-11 10:10:52 +0000 |
---|---|---|
committer | tb <> | 2023-04-11 10:10:52 +0000 |
commit | 5b1044fc984f0e6179eb4d3337c40abbf3d98c92 (patch) | |
tree | d1cda596f000697748a306b55808d3d0d1e179af | |
parent | 2389f1d8a42806b852cf81082f3eb70ecbfdd8ae (diff) | |
download | openbsd-5b1044fc984f0e6179eb4d3337c40abbf3d98c92.tar.gz openbsd-5b1044fc984f0e6179eb4d3337c40abbf3d98c92.tar.bz2 openbsd-5b1044fc984f0e6179eb4d3337c40abbf3d98c92.zip |
bn_mod_sqrt: remove no longer necessary complications due to the
non-deterministic nature of the old implementation.
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mod_sqrt.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/regress/lib/libcrypto/bn/bn_mod_sqrt.c b/src/regress/lib/libcrypto/bn/bn_mod_sqrt.c index a8a624f85b..7ab7905136 100644 --- a/src/regress/lib/libcrypto/bn/bn_mod_sqrt.c +++ b/src/regress/lib/libcrypto/bn/bn_mod_sqrt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_mod_sqrt.c,v 1.9 2023/04/06 12:01:45 tb Exp $ */ | 1 | /* $OpenBSD: bn_mod_sqrt.c,v 1.10 2023/04/11 10:10:52 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> |
@@ -2833,7 +2833,7 @@ const size_t N_TESTS = sizeof(mod_sqrt_test_data) / sizeof(*mod_sqrt_test_data); | |||
2833 | static int | 2833 | static int |
2834 | mod_sqrt_test(struct mod_sqrt_test *test, BN_CTX *ctx) | 2834 | mod_sqrt_test(struct mod_sqrt_test *test, BN_CTX *ctx) |
2835 | { | 2835 | { |
2836 | BIGNUM *a, *p, *want, *got, *diff, *sum; | 2836 | BIGNUM *a, *p, *want, *got, *diff; |
2837 | int failed = 1; | 2837 | int failed = 1; |
2838 | 2838 | ||
2839 | BN_CTX_start(ctx); | 2839 | BN_CTX_start(ctx); |
@@ -2848,8 +2848,6 @@ mod_sqrt_test(struct mod_sqrt_test *test, BN_CTX *ctx) | |||
2848 | errx(1, "got = BN_CTX_get()"); | 2848 | errx(1, "got = BN_CTX_get()"); |
2849 | if ((diff = BN_CTX_get(ctx)) == NULL) | 2849 | if ((diff = BN_CTX_get(ctx)) == NULL) |
2850 | errx(1, "diff = BN_CTX_get()"); | 2850 | errx(1, "diff = BN_CTX_get()"); |
2851 | if ((sum = BN_CTX_get(ctx)) == NULL) | ||
2852 | errx(1, "sum = BN_CTX_get()"); | ||
2853 | 2851 | ||
2854 | if (!BN_hex2bn(&a, test->a)) | 2852 | if (!BN_hex2bn(&a, test->a)) |
2855 | errx(1, "BN_hex2bn(%s)", test->a); | 2853 | errx(1, "BN_hex2bn(%s)", test->a); |
@@ -2868,11 +2866,8 @@ mod_sqrt_test(struct mod_sqrt_test *test, BN_CTX *ctx) | |||
2868 | errx(1, "BN_hex2bn(%s)", test->sqrt); | 2866 | errx(1, "BN_hex2bn(%s)", test->sqrt); |
2869 | if (!BN_mod_sub(diff, want, got, p, ctx)) | 2867 | if (!BN_mod_sub(diff, want, got, p, ctx)) |
2870 | errx(1, "BN_mod_sub() failed\n"); | 2868 | errx(1, "BN_mod_sub() failed\n"); |
2871 | if (!BN_mod_add(sum, want, got, p, ctx)) | ||
2872 | errx(1, "BN_mod_add() failed\n"); | ||
2873 | 2869 | ||
2874 | /* XXX - Remove sum once we return the canonical square root. */ | 2870 | if (!BN_is_zero(diff)) { |
2875 | if (!BN_is_zero(diff) && !BN_is_zero(sum)) { | ||
2876 | fprintf(stderr, "a: %s\n", test->a); | 2871 | fprintf(stderr, "a: %s\n", test->a); |
2877 | fprintf(stderr, "p: %s\n", test->p); | 2872 | fprintf(stderr, "p: %s\n", test->p); |
2878 | fprintf(stderr, "want: %s\n", test->sqrt); | 2873 | fprintf(stderr, "want: %s\n", test->sqrt); |
@@ -4439,7 +4434,7 @@ static int | |||
4439 | bn_mod_sqrt_p_is_1_mod_8_test(const struct p_is_1_mod_8_tests *test, | 4434 | bn_mod_sqrt_p_is_1_mod_8_test(const struct p_is_1_mod_8_tests *test, |
4440 | BN_CTX *ctx) | 4435 | BN_CTX *ctx) |
4441 | { | 4436 | { |
4442 | BIGNUM *a, *p, *want, *got, *diff, *sum; | 4437 | BIGNUM *a, *p, *want, *got, *diff; |
4443 | const char *const *sqrts = test->sqrt; | 4438 | const char *const *sqrts = test->sqrt; |
4444 | int i; | 4439 | int i; |
4445 | int failed = 0; | 4440 | int failed = 0; |
@@ -4456,8 +4451,6 @@ bn_mod_sqrt_p_is_1_mod_8_test(const struct p_is_1_mod_8_tests *test, | |||
4456 | errx(1, "got = BN_CTX_get()"); | 4451 | errx(1, "got = BN_CTX_get()"); |
4457 | if ((diff = BN_CTX_get(ctx)) == NULL) | 4452 | if ((diff = BN_CTX_get(ctx)) == NULL) |
4458 | errx(1, "diff = BN_CTX_get()"); | 4453 | errx(1, "diff = BN_CTX_get()"); |
4459 | if ((sum = BN_CTX_get(ctx)) == NULL) | ||
4460 | errx(1, "sum = BN_CTX_get()"); | ||
4461 | 4454 | ||
4462 | if (!BN_hex2bn(&p, test->p)) | 4455 | if (!BN_hex2bn(&p, test->p)) |
4463 | errx(1, "BN_hex2bn"); | 4456 | errx(1, "BN_hex2bn"); |
@@ -4488,11 +4481,8 @@ bn_mod_sqrt_p_is_1_mod_8_test(const struct p_is_1_mod_8_tests *test, | |||
4488 | 4481 | ||
4489 | if (!BN_mod_sub(diff, want, got, p, ctx)) | 4482 | if (!BN_mod_sub(diff, want, got, p, ctx)) |
4490 | errx(1, "BN_mod_sub() failed\n"); | 4483 | errx(1, "BN_mod_sub() failed\n"); |
4491 | if (!BN_mod_add(sum, want, got, p, ctx)) | ||
4492 | errx(1, "BN_mod_add() failed\n"); | ||
4493 | 4484 | ||
4494 | /* XXX - Remove sum once we return the canonical square root. */ | 4485 | if (!BN_is_zero(diff)) { |
4495 | if (!BN_is_zero(diff) && !BN_is_zero(sum)) { | ||
4496 | fprintf(stderr, "a: %d\n", i); | 4486 | fprintf(stderr, "a: %d\n", i); |
4497 | fprintf(stderr, "p: %s\n", test->p); | 4487 | fprintf(stderr, "p: %s\n", test->p); |
4498 | fprintf(stderr, "want: %s\n", sqrts[i]); | 4488 | fprintf(stderr, "want: %s\n", sqrts[i]); |