diff options
author | doug <> | 2015-04-29 00:11:12 +0000 |
---|---|---|
committer | doug <> | 2015-04-29 00:11:12 +0000 |
commit | 843c114d1987e49ba9785f455dad7c1709177bb2 (patch) | |
tree | 1bd273d1ec23b03522e575d3b072de7f0789a8b1 /src | |
parent | 9e874579a3d35b6a89acefa2792ff97236256dc2 (diff) | |
download | openbsd-843c114d1987e49ba9785f455dad7c1709177bb2.tar.gz openbsd-843c114d1987e49ba9785f455dad7c1709177bb2.tar.bz2 openbsd-843c114d1987e49ba9785f455dad7c1709177bb2.zip |
Add missing BN_CTX_end() calls.
After calling BN_CTX_start(), there must be a BN_CTX_end() before
returning. There were missing BN_CTX_end() calls in error paths. One diff
chunk was simply removing redundant code related to this.
ok deraadt@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_gf2m.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_recp.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_x931p.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_gf2m.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_recp.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_x931p.c | 16 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ec/ec_lib.c | 10 |
8 files changed, 36 insertions, 36 deletions
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c index e84729bdad..e1537d5379 100644 --- a/src/lib/libcrypto/bn/bn_gf2m.c +++ b/src/lib/libcrypto/bn/bn_gf2m.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gf2m.c,v 1.18 2015/02/10 09:50:12 miod Exp $ */ | 1 | /* $OpenBSD: bn_gf2m.c,v 1.19 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -576,7 +576,7 @@ BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
576 | bn_check_top(a); | 576 | bn_check_top(a); |
577 | BN_CTX_start(ctx); | 577 | BN_CTX_start(ctx); |
578 | if ((s = BN_CTX_get(ctx)) == NULL) | 578 | if ((s = BN_CTX_get(ctx)) == NULL) |
579 | return 0; | 579 | goto err; |
580 | if (!bn_wexpand(s, 2 * a->top)) | 580 | if (!bn_wexpand(s, 2 * a->top)) |
581 | goto err; | 581 | goto err; |
582 | 582 | ||
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c index 7b31fe0adf..b0bd0aa4df 100644 --- a/src/lib/libcrypto/bn/bn_recp.c +++ b/src/lib/libcrypto/bn/bn_recp.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_recp.c,v 1.12 2015/03/21 08:05:20 doug Exp $ */ | 1 | /* $OpenBSD: bn_recp.c,v 1.13 2015/04/29 00:11:12 doug 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 | * |
@@ -161,8 +161,10 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, | |||
161 | 161 | ||
162 | if (BN_ucmp(m, &(recp->N)) < 0) { | 162 | if (BN_ucmp(m, &(recp->N)) < 0) { |
163 | BN_zero(d); | 163 | BN_zero(d); |
164 | if (!BN_copy(r, m)) | 164 | if (!BN_copy(r, m)) { |
165 | BN_CTX_end(ctx); | ||
165 | return 0; | 166 | return 0; |
167 | } | ||
166 | BN_CTX_end(ctx); | 168 | BN_CTX_end(ctx); |
167 | return (1); | 169 | return (1); |
168 | } | 170 | } |
diff --git a/src/lib/libcrypto/bn/bn_x931p.c b/src/lib/libcrypto/bn/bn_x931p.c index 13abd5923c..1948bc8e71 100644 --- a/src/lib/libcrypto/bn/bn_x931p.c +++ b/src/lib/libcrypto/bn/bn_x931p.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_x931p.c,v 1.7 2015/02/14 15:07:54 jsing Exp $ */ | 1 | /* $OpenBSD: bn_x931p.c,v 1.8 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -202,6 +202,7 @@ BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | |||
202 | { | 202 | { |
203 | BIGNUM *t; | 203 | BIGNUM *t; |
204 | int i; | 204 | int i; |
205 | int ret = 0; | ||
205 | 206 | ||
206 | /* Number of bits for each prime is of the form | 207 | /* Number of bits for each prime is of the form |
207 | * 512+128s for s = 0, 1, ... | 208 | * 512+128s for s = 0, 1, ... |
@@ -218,23 +219,24 @@ BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | |||
218 | 219 | ||
219 | BN_CTX_start(ctx); | 220 | BN_CTX_start(ctx); |
220 | if ((t = BN_CTX_get(ctx)) == NULL) | 221 | if ((t = BN_CTX_get(ctx)) == NULL) |
221 | return 0; | 222 | goto err; |
222 | 223 | ||
223 | for (i = 0; i < 1000; i++) { | 224 | for (i = 0; i < 1000; i++) { |
224 | if (!BN_rand(Xq, nbits, 1, 0)) | 225 | if (!BN_rand(Xq, nbits, 1, 0)) |
225 | return 0; | 226 | goto err; |
226 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ | 227 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ |
227 | BN_sub(t, Xp, Xq); | 228 | BN_sub(t, Xp, Xq); |
228 | if (BN_num_bits(t) > (nbits - 100)) | 229 | if (BN_num_bits(t) > (nbits - 100)) |
229 | break; | 230 | break; |
230 | } | 231 | } |
231 | 232 | ||
232 | BN_CTX_end(ctx); | ||
233 | |||
234 | if (i < 1000) | 233 | if (i < 1000) |
235 | return 1; | 234 | ret = 1; |
236 | 235 | ||
237 | return 0; | 236 | err: |
237 | BN_CTX_end(ctx); | ||
238 | |||
239 | return ret; | ||
238 | } | 240 | } |
239 | 241 | ||
240 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 | 242 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 |
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 8cf0f2241e..d36c2c2e6e 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.16 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.17 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -531,12 +531,8 @@ EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx) | |||
531 | if (!EC_GROUP_get_order(a, a1, ctx) || | 531 | if (!EC_GROUP_get_order(a, a1, ctx) || |
532 | !EC_GROUP_get_order(b, b1, ctx) || | 532 | !EC_GROUP_get_order(b, b1, ctx) || |
533 | !EC_GROUP_get_cofactor(a, a2, ctx) || | 533 | !EC_GROUP_get_cofactor(a, a2, ctx) || |
534 | !EC_GROUP_get_cofactor(b, b2, ctx)) { | 534 | !EC_GROUP_get_cofactor(b, b2, ctx)) |
535 | BN_CTX_end(ctx); | 535 | goto err; |
536 | if (ctx_new) | ||
537 | BN_CTX_free(ctx); | ||
538 | return -1; | ||
539 | } | ||
540 | if (BN_cmp(a1, b1) || BN_cmp(a2, b2)) | 536 | if (BN_cmp(a1, b1) || BN_cmp(a2, b2)) |
541 | r = 1; | 537 | r = 1; |
542 | } | 538 | } |
diff --git a/src/lib/libssl/src/crypto/bn/bn_gf2m.c b/src/lib/libssl/src/crypto/bn/bn_gf2m.c index e84729bdad..e1537d5379 100644 --- a/src/lib/libssl/src/crypto/bn/bn_gf2m.c +++ b/src/lib/libssl/src/crypto/bn/bn_gf2m.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gf2m.c,v 1.18 2015/02/10 09:50:12 miod Exp $ */ | 1 | /* $OpenBSD: bn_gf2m.c,v 1.19 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -576,7 +576,7 @@ BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
576 | bn_check_top(a); | 576 | bn_check_top(a); |
577 | BN_CTX_start(ctx); | 577 | BN_CTX_start(ctx); |
578 | if ((s = BN_CTX_get(ctx)) == NULL) | 578 | if ((s = BN_CTX_get(ctx)) == NULL) |
579 | return 0; | 579 | goto err; |
580 | if (!bn_wexpand(s, 2 * a->top)) | 580 | if (!bn_wexpand(s, 2 * a->top)) |
581 | goto err; | 581 | goto err; |
582 | 582 | ||
diff --git a/src/lib/libssl/src/crypto/bn/bn_recp.c b/src/lib/libssl/src/crypto/bn/bn_recp.c index 7b31fe0adf..b0bd0aa4df 100644 --- a/src/lib/libssl/src/crypto/bn/bn_recp.c +++ b/src/lib/libssl/src/crypto/bn/bn_recp.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_recp.c,v 1.12 2015/03/21 08:05:20 doug Exp $ */ | 1 | /* $OpenBSD: bn_recp.c,v 1.13 2015/04/29 00:11:12 doug 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 | * |
@@ -161,8 +161,10 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp, | |||
161 | 161 | ||
162 | if (BN_ucmp(m, &(recp->N)) < 0) { | 162 | if (BN_ucmp(m, &(recp->N)) < 0) { |
163 | BN_zero(d); | 163 | BN_zero(d); |
164 | if (!BN_copy(r, m)) | 164 | if (!BN_copy(r, m)) { |
165 | BN_CTX_end(ctx); | ||
165 | return 0; | 166 | return 0; |
167 | } | ||
166 | BN_CTX_end(ctx); | 168 | BN_CTX_end(ctx); |
167 | return (1); | 169 | return (1); |
168 | } | 170 | } |
diff --git a/src/lib/libssl/src/crypto/bn/bn_x931p.c b/src/lib/libssl/src/crypto/bn/bn_x931p.c index 13abd5923c..1948bc8e71 100644 --- a/src/lib/libssl/src/crypto/bn/bn_x931p.c +++ b/src/lib/libssl/src/crypto/bn/bn_x931p.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_x931p.c,v 1.7 2015/02/14 15:07:54 jsing Exp $ */ | 1 | /* $OpenBSD: bn_x931p.c,v 1.8 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2005. | 3 | * project 2005. |
4 | */ | 4 | */ |
@@ -202,6 +202,7 @@ BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | |||
202 | { | 202 | { |
203 | BIGNUM *t; | 203 | BIGNUM *t; |
204 | int i; | 204 | int i; |
205 | int ret = 0; | ||
205 | 206 | ||
206 | /* Number of bits for each prime is of the form | 207 | /* Number of bits for each prime is of the form |
207 | * 512+128s for s = 0, 1, ... | 208 | * 512+128s for s = 0, 1, ... |
@@ -218,23 +219,24 @@ BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | |||
218 | 219 | ||
219 | BN_CTX_start(ctx); | 220 | BN_CTX_start(ctx); |
220 | if ((t = BN_CTX_get(ctx)) == NULL) | 221 | if ((t = BN_CTX_get(ctx)) == NULL) |
221 | return 0; | 222 | goto err; |
222 | 223 | ||
223 | for (i = 0; i < 1000; i++) { | 224 | for (i = 0; i < 1000; i++) { |
224 | if (!BN_rand(Xq, nbits, 1, 0)) | 225 | if (!BN_rand(Xq, nbits, 1, 0)) |
225 | return 0; | 226 | goto err; |
226 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ | 227 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ |
227 | BN_sub(t, Xp, Xq); | 228 | BN_sub(t, Xp, Xq); |
228 | if (BN_num_bits(t) > (nbits - 100)) | 229 | if (BN_num_bits(t) > (nbits - 100)) |
229 | break; | 230 | break; |
230 | } | 231 | } |
231 | 232 | ||
232 | BN_CTX_end(ctx); | ||
233 | |||
234 | if (i < 1000) | 233 | if (i < 1000) |
235 | return 1; | 234 | ret = 1; |
236 | 235 | ||
237 | return 0; | 236 | err: |
237 | BN_CTX_end(ctx); | ||
238 | |||
239 | return ret; | ||
238 | } | 240 | } |
239 | 241 | ||
240 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 | 242 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 |
diff --git a/src/lib/libssl/src/crypto/ec/ec_lib.c b/src/lib/libssl/src/crypto/ec/ec_lib.c index 8cf0f2241e..d36c2c2e6e 100644 --- a/src/lib/libssl/src/crypto/ec/ec_lib.c +++ b/src/lib/libssl/src/crypto/ec/ec_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_lib.c,v 1.16 2015/02/09 15:49:22 jsing Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.17 2015/04/29 00:11:12 doug Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -531,12 +531,8 @@ EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx) | |||
531 | if (!EC_GROUP_get_order(a, a1, ctx) || | 531 | if (!EC_GROUP_get_order(a, a1, ctx) || |
532 | !EC_GROUP_get_order(b, b1, ctx) || | 532 | !EC_GROUP_get_order(b, b1, ctx) || |
533 | !EC_GROUP_get_cofactor(a, a2, ctx) || | 533 | !EC_GROUP_get_cofactor(a, a2, ctx) || |
534 | !EC_GROUP_get_cofactor(b, b2, ctx)) { | 534 | !EC_GROUP_get_cofactor(b, b2, ctx)) |
535 | BN_CTX_end(ctx); | 535 | goto err; |
536 | if (ctx_new) | ||
537 | BN_CTX_free(ctx); | ||
538 | return -1; | ||
539 | } | ||
540 | if (BN_cmp(a1, b1) || BN_cmp(a2, b2)) | 536 | if (BN_cmp(a1, b1) || BN_cmp(a2, b2)) |
541 | r = 1; | 537 | r = 1; |
542 | } | 538 | } |