summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2022-07-19 16:19:19 +0000
committertb <>2022-07-19 16:19:19 +0000
commita08917f0b598c424668ec68318b26d410fcf8990 (patch)
treefba18e323ebb95f143e2638c9c1c6138c06e5a11 /src/lib
parentf8770fbab0106066dcf0c03c9742ba98cda1785f (diff)
downloadopenbsd-a08917f0b598c424668ec68318b26d410fcf8990.tar.gz
openbsd-a08917f0b598c424668ec68318b26d410fcf8990.tar.bz2
openbsd-a08917f0b598c424668ec68318b26d410fcf8990.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/lib')
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c10
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
189loop: 193loop:
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
260int 262int
261BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, 263BN_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)