summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_bpsw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_bpsw.c')
-rw-r--r--src/lib/libcrypto/bn/bn_bpsw.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/lib/libcrypto/bn/bn_bpsw.c b/src/lib/libcrypto/bn/bn_bpsw.c
index 82a4e87146..14f2800ad3 100644
--- a/src/lib/libcrypto/bn/bn_bpsw.c
+++ b/src/lib/libcrypto/bn/bn_bpsw.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_bpsw.c,v 1.10 2023/05/10 21:05:24 tb Exp $ */ 1/* $OpenBSD: bn_bpsw.c,v 1.11 2023/08/03 18:53:55 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Martin Grenouilloux <martin.grenouilloux@lse.epita.fr> 3 * Copyright (c) 2022 Martin Grenouilloux <martin.grenouilloux@lse.epita.fr>
4 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -385,7 +385,7 @@ bn_miller_rabin(int *is_pseudoprime, const BIGNUM *n, BN_CTX *ctx,
385 size_t rounds) 385 size_t rounds)
386{ 386{
387 BN_MONT_CTX *mctx = NULL; 387 BN_MONT_CTX *mctx = NULL;
388 BIGNUM *base, *k, *n_minus_one, *three; 388 BIGNUM *base, *k, *n_minus_one;
389 size_t i; 389 size_t i;
390 int s; 390 int s;
391 int ret = 0; 391 int ret = 0;
@@ -398,8 +398,6 @@ bn_miller_rabin(int *is_pseudoprime, const BIGNUM *n, BN_CTX *ctx,
398 goto err; 398 goto err;
399 if ((n_minus_one = BN_CTX_get(ctx)) == NULL) 399 if ((n_minus_one = BN_CTX_get(ctx)) == NULL)
400 goto err; 400 goto err;
401 if ((three = BN_CTX_get(ctx)) == NULL)
402 goto err;
403 401
404 if (BN_is_word(n, 2) || BN_is_word(n, 3)) { 402 if (BN_is_word(n, 2) || BN_is_word(n, 3)) {
405 *is_pseudoprime = 1; 403 *is_pseudoprime = 1;
@@ -451,11 +449,8 @@ bn_miller_rabin(int *is_pseudoprime, const BIGNUM *n, BN_CTX *ctx,
451 * risk of false positives in BPSW. 449 * risk of false positives in BPSW.
452 */ 450 */
453 451
454 if (!BN_set_word(three, 3))
455 goto err;
456
457 for (i = 0; i < rounds; i++) { 452 for (i = 0; i < rounds; i++) {
458 if (!bn_rand_interval(base, three, n_minus_one)) 453 if (!bn_rand_interval(base, 3, n_minus_one))
459 goto err; 454 goto err;
460 455
461 if (!bn_fermat(is_pseudoprime, n, n_minus_one, k, s, base, ctx, 456 if (!bn_fermat(is_pseudoprime, n, n_minus_one, k, s, base, ctx,