diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/bn/bn_prime.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c index 02780d32e6..b1aba663df 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.13 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: bn_prime.c,v 1.14 2015/10/21 19:02:22 miod 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 | * |
@@ -112,6 +112,8 @@ | |||
112 | #include <stdio.h> | 112 | #include <stdio.h> |
113 | #include <time.h> | 113 | #include <time.h> |
114 | 114 | ||
115 | #include <openssl/err.h> | ||
116 | |||
115 | #include "bn_lcl.h" | 117 | #include "bn_lcl.h" |
116 | 118 | ||
117 | /* NB: these functions have been "upgraded", the deprecated versions (which are | 119 | /* NB: these functions have been "upgraded", the deprecated versions (which are |
@@ -164,7 +166,16 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, | |||
164 | int found = 0; | 166 | int found = 0; |
165 | int i, j, c1 = 0; | 167 | int i, j, c1 = 0; |
166 | BN_CTX *ctx; | 168 | BN_CTX *ctx; |
167 | int checks = BN_prime_checks_for_size(bits); | 169 | int checks; |
170 | |||
171 | if (bits < 2 || (bits == 2 && safe)) { | ||
172 | /* | ||
173 | * There are no prime numbers smaller than 2, and the smallest | ||
174 | * safe prime (7) spans three bits. | ||
175 | */ | ||
176 | BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL); | ||
177 | return 0; | ||
178 | } | ||
168 | 179 | ||
169 | ctx = BN_CTX_new(); | 180 | ctx = BN_CTX_new(); |
170 | if (ctx == NULL) | 181 | if (ctx == NULL) |
@@ -172,6 +183,9 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, | |||
172 | BN_CTX_start(ctx); | 183 | BN_CTX_start(ctx); |
173 | if ((t = BN_CTX_get(ctx)) == NULL) | 184 | if ((t = BN_CTX_get(ctx)) == NULL) |
174 | goto err; | 185 | goto err; |
186 | |||
187 | checks = BN_prime_checks_for_size(bits); | ||
188 | |||
175 | loop: | 189 | loop: |
176 | /* make a random number and set the top and bottom bits */ | 190 | /* make a random number and set the top and bottom bits */ |
177 | if (add == NULL) { | 191 | if (add == NULL) { |