diff options
| author | tb <> | 2022-07-19 16:19:19 +0000 |
|---|---|---|
| committer | tb <> | 2022-07-19 16:19:19 +0000 |
| commit | 4a1f63cad5fa65cd18bc4210bda6874a5a94f3d5 (patch) | |
| tree | fba18e323ebb95f143e2638c9c1c6138c06e5a11 /src | |
| parent | d29e337a0bb15ee7036e52754e42c2b3136a1c4d (diff) | |
| download | openbsd-4a1f63cad5fa65cd18bc4210bda6874a5a94f3d5.tar.gz openbsd-4a1f63cad5fa65cd18bc4210bda6874a5a94f3d5.tar.bz2 openbsd-4a1f63cad5fa65cd18bc4210bda6874a5a94f3d5.zip | |
Avoid unnecessary loops in BN_generate_prime_ex()
Since there is nothing randomized in bn_is_prime_bpsw(), the concept
of rounds makes no sense. Apply a minimal change for now that avoids
expensive loops that won't change the outcome in case we found a
probable prime.
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_prime.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c index 0b1d672fcf..e9a7335861 100644 --- a/src/lib/libcrypto/bn/bn_prime.c +++ b/src/lib/libcrypto/bn/bn_prime.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_prime.c,v 1.21 2022/07/13 06:38:02 tb Exp $ */ | 1 | /* $OpenBSD: bn_prime.c,v 1.22 2022/07/19 16:19:19 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 | * |
| @@ -116,6 +116,8 @@ | |||
| 116 | 116 | ||
| 117 | #include "bn_lcl.h" | 117 | #include "bn_lcl.h" |
| 118 | 118 | ||
| 119 | #define LIBRESSL_HAS_BPSW | ||
| 120 | |||
| 119 | /* NB: these functions have been "upgraded", the deprecated versions (which are | 121 | /* NB: these functions have been "upgraded", the deprecated versions (which are |
| 120 | * compatibility wrappers using these functions) are in bn_depr.c. | 122 | * compatibility wrappers using these functions) are in bn_depr.c. |
| 121 | * - Geoff | 123 | * - Geoff |
| @@ -166,7 +168,7 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, | |||
| 166 | int found = 0; | 168 | int found = 0; |
| 167 | int i, j, c1 = 0; | 169 | int i, j, c1 = 0; |
| 168 | BN_CTX *ctx; | 170 | BN_CTX *ctx; |
| 169 | int checks; | 171 | int checks = 1; |
| 170 | 172 | ||
| 171 | if (bits < 2 || (bits == 2 && safe)) { | 173 | if (bits < 2 || (bits == 2 && safe)) { |
| 172 | /* | 174 | /* |
| @@ -184,7 +186,9 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, | |||
| 184 | if ((t = BN_CTX_get(ctx)) == NULL) | 186 | if ((t = BN_CTX_get(ctx)) == NULL) |
| 185 | goto err; | 187 | goto err; |
| 186 | 188 | ||
| 189 | #ifndef LIBRESSL_HAS_BPSW | ||
| 187 | checks = BN_prime_checks_for_size(bits); | 190 | checks = BN_prime_checks_for_size(bits); |
| 191 | #endif | ||
| 188 | 192 | ||
| 189 | loop: | 193 | loop: |
| 190 | /* make a random number and set the top and bottom bits */ | 194 | /* make a random number and set the top and bottom bits */ |
| @@ -255,8 +259,6 @@ BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_GENCB *cb) | |||
| 255 | return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb); | 259 | return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb); |
| 256 | } | 260 | } |
| 257 | 261 | ||
| 258 | #define LIBRESSL_HAS_BPSW | ||
| 259 | |||
| 260 | int | 262 | int |
| 261 | BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, | 263 | BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, |
| 262 | int do_trial_division, BN_GENCB *cb) | 264 | int do_trial_division, BN_GENCB *cb) |
