summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_prime.c
diff options
context:
space:
mode:
authorjsing <>2015-02-09 15:49:22 +0000
committerjsing <>2015-02-09 15:49:22 +0000
commit16f790d01f7a6fc6c94e2a033a67b80c8ec5291c (patch)
treed924c624d5eb949a9e7e395dc99d92616e911ce9 /src/lib/libcrypto/bn/bn_prime.c
parent42f7780549de5b7b5e3e7943cfef87e0e41970fc (diff)
downloadopenbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.gz
openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.bz2
openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.zip
BN_CTX_get() can fail - consistently check its return value.
There are currently cases where the return from each call is checked, the return from only the last call is checked and cases where it is not checked at all (including code in bn, ec and engine). Checking the last return value is valid as once the function fails it will continue to return NULL. However, in order to be consistent check each call with the same idiom. This makes it easy to verify. Note there are still a handful of cases that do not follow the idiom - these will be handled separately. ok beck@ doug@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_prime.c')
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index e5cd315e47..02780d32e6 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.12 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: bn_prime.c,v 1.13 2015/02/09 15:49:22 jsing 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 *
@@ -170,8 +170,7 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
170 if (ctx == NULL) 170 if (ctx == NULL)
171 goto err; 171 goto err;
172 BN_CTX_start(ctx); 172 BN_CTX_start(ctx);
173 t = BN_CTX_get(ctx); 173 if ((t = BN_CTX_get(ctx)) == NULL)
174 if (!t)
175 goto err; 174 goto err;
176loop: 175loop:
177 /* make a random number and set the top and bottom bits */ 176 /* make a random number and set the top and bottom bits */
@@ -287,10 +286,11 @@ BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
287 A = t; 286 A = t;
288 } else 287 } else
289 A = a; 288 A = a;
290 A1 = BN_CTX_get(ctx); 289 if ((A1 = BN_CTX_get(ctx)) == NULL)
291 A1_odd = BN_CTX_get(ctx); 290 goto err;
292 check = BN_CTX_get(ctx); 291 if ((A1_odd = BN_CTX_get(ctx)) == NULL)
293 if (check == NULL) 292 goto err;
293 if ((check = BN_CTX_get(ctx)) == NULL)
294 goto err; 294 goto err;
295 295
296 /* compute A1 := A - 1 */ 296 /* compute A1 := A - 1 */
@@ -461,10 +461,11 @@ probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
461 461
462 bits--; 462 bits--;
463 BN_CTX_start(ctx); 463 BN_CTX_start(ctx);
464 t1 = BN_CTX_get(ctx); 464 if ((t1 = BN_CTX_get(ctx)) == NULL)
465 q = BN_CTX_get(ctx); 465 goto err;
466 qadd = BN_CTX_get(ctx); 466 if ((q = BN_CTX_get(ctx)) == NULL)
467 if (qadd == NULL) 467 goto err;
468 if ((qadd = BN_CTX_get(ctx)) == NULL)
468 goto err; 469 goto err;
469 470
470 if (!BN_rshift1(qadd, padd)) 471 if (!BN_rshift1(qadd, padd))