提交 edea42c6 编写于 作者: P Paul Yang 提交者: Bernd Edlinger

Change to check last return value of BN_CTX_get

To make it consistent in the code base
Reviewed-by: NMatt Caswell <matt@openssl.org>
Reviewed-by: NBernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/3749)
上级 9e1d5e8d
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -191,14 +191,11 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, ...@@ -191,14 +191,11 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
} }
BN_CTX_start(ctx); BN_CTX_start(ctx);
res = (dv == NULL) ? BN_CTX_get(ctx) : dv;
tmp = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx);
snum = BN_CTX_get(ctx); snum = BN_CTX_get(ctx);
sdiv = BN_CTX_get(ctx); sdiv = BN_CTX_get(ctx);
if (dv == NULL) if (sdiv == NULL)
res = BN_CTX_get(ctx);
else
res = dv;
if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)
goto err; goto err;
/* First we normalise the numbers */ /* First we normalise the numbers */
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -50,10 +50,7 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ...@@ -50,10 +50,7 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
} }
BN_CTX_start(ctx); BN_CTX_start(ctx);
if ((r == a) || (r == p)) rr = ((r == a) || (r == p)) ? BN_CTX_get(ctx) : r;
rr = BN_CTX_get(ctx);
else
rr = r;
v = BN_CTX_get(ctx); v = BN_CTX_get(ctx);
if (rr == NULL || v == NULL) if (rr == NULL || v == NULL)
goto err; goto err;
...@@ -85,7 +82,7 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ...@@ -85,7 +82,7 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
err: err:
BN_CTX_end(ctx); BN_CTX_end(ctx);
bn_check_top(r); bn_check_top(r);
return (ret); return ret;
} }
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
...@@ -189,7 +186,7 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, ...@@ -189,7 +186,7 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
BN_CTX_start(ctx); BN_CTX_start(ctx);
aa = BN_CTX_get(ctx); aa = BN_CTX_get(ctx);
val[0] = BN_CTX_get(ctx); val[0] = BN_CTX_get(ctx);
if (!aa || !val[0]) if (val[0] == NULL)
goto err; goto err;
BN_RECP_CTX_init(&recp); BN_RECP_CTX_init(&recp);
...@@ -330,7 +327,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, ...@@ -330,7 +327,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
d = BN_CTX_get(ctx); d = BN_CTX_get(ctx);
r = BN_CTX_get(ctx); r = BN_CTX_get(ctx);
val[0] = BN_CTX_get(ctx); val[0] = BN_CTX_get(ctx);
if (!d || !r || !val[0]) if (val[0] == NULL)
goto err; goto err;
/* /*
...@@ -1095,7 +1092,7 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, ...@@ -1095,7 +1092,7 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
int b, bits, ret = 0; int b, bits, ret = 0;
int r_is_one; int r_is_one;
BN_ULONG w, next_w; BN_ULONG w, next_w;
BIGNUM *d, *r, *t; BIGNUM *r, *t;
BIGNUM *swap_tmp; BIGNUM *swap_tmp;
#define BN_MOD_MUL_WORD(r, w, m) \ #define BN_MOD_MUL_WORD(r, w, m) \
(BN_mul_word(r, (w)) && \ (BN_mul_word(r, (w)) && \
...@@ -1148,10 +1145,9 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, ...@@ -1148,10 +1145,9 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
} }
BN_CTX_start(ctx); BN_CTX_start(ctx);
d = BN_CTX_get(ctx);
r = BN_CTX_get(ctx); r = BN_CTX_get(ctx);
t = BN_CTX_get(ctx); t = BN_CTX_get(ctx);
if (d == NULL || r == NULL || t == NULL) if (t == NULL)
goto err; goto err;
if (in_mont != NULL) if (in_mont != NULL)
...@@ -1266,7 +1262,7 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, ...@@ -1266,7 +1262,7 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
BN_CTX_start(ctx); BN_CTX_start(ctx);
d = BN_CTX_get(ctx); d = BN_CTX_get(ctx);
val[0] = BN_CTX_get(ctx); val[0] = BN_CTX_get(ctx);
if (!d || !val[0]) if (val[0] == NULL)
goto err; goto err;
if (!BN_nnmod(val[0], a, m, ctx)) if (!BN_nnmod(val[0], a, m, ctx))
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -50,7 +50,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1, ...@@ -50,7 +50,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
r = BN_CTX_get(ctx); r = BN_CTX_get(ctx);
val1[0] = BN_CTX_get(ctx); val1[0] = BN_CTX_get(ctx);
val2[0] = BN_CTX_get(ctx); val2[0] = BN_CTX_get(ctx);
if (!d || !r || !val1[0] || !val2[0]) if (val2[0] == NULL)
goto err; goto err;
if (in_mont != NULL) if (in_mont != NULL)
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -23,7 +23,7 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx) ...@@ -23,7 +23,7 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
BN_CTX_start(ctx); BN_CTX_start(ctx);
a = BN_CTX_get(ctx); a = BN_CTX_get(ctx);
b = BN_CTX_get(ctx); b = BN_CTX_get(ctx);
if (a == NULL || b == NULL) if (b == NULL)
goto err; goto err;
if (BN_copy(a, in_a) == NULL) if (BN_copy(a, in_a) == NULL)
......
/* /*
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2002-2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
...@@ -557,13 +557,11 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ...@@ -557,13 +557,11 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
BN_CTX_start(ctx); BN_CTX_start(ctx);
if ((b = BN_CTX_get(ctx)) == NULL) b = BN_CTX_get(ctx);
goto err; c = BN_CTX_get(ctx);
if ((c = BN_CTX_get(ctx)) == NULL) u = BN_CTX_get(ctx);
goto err; v = BN_CTX_get(ctx);
if ((u = BN_CTX_get(ctx)) == NULL) if (v == NULL)
goto err;
if ((v = BN_CTX_get(ctx)) == NULL)
goto err; goto err;
if (!BN_GF2m_mod(u, a, p)) if (!BN_GF2m_mod(u, a, p))
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -180,7 +180,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont, ...@@ -180,7 +180,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
BN_CTX_start(ctx); BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx); t1 = BN_CTX_get(ctx);
t2 = BN_CTX_get(ctx); t2 = BN_CTX_get(ctx);
if (t1 == NULL || t2 == NULL) if (t2 == NULL)
goto err; goto err;
if (!BN_copy(t1, a)) if (!BN_copy(t1, a))
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -87,17 +87,11 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, ...@@ -87,17 +87,11 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
BIGNUM *a, *b, *d, *r; BIGNUM *a, *b, *d, *r;
BN_CTX_start(ctx); BN_CTX_start(ctx);
d = (dv != NULL) ? dv : BN_CTX_get(ctx);
r = (rem != NULL) ? rem : BN_CTX_get(ctx);
a = BN_CTX_get(ctx); a = BN_CTX_get(ctx);
b = BN_CTX_get(ctx); b = BN_CTX_get(ctx);
if (dv != NULL) if (b == NULL)
d = dv;
else
d = BN_CTX_get(ctx);
if (rem != NULL)
r = rem;
else
r = BN_CTX_get(ctx);
if (a == NULL || b == NULL || d == NULL || r == NULL)
goto err; goto err;
if (BN_ucmp(m, &(recp->N)) < 0) { if (BN_ucmp(m, &(recp->N)) < 0) {
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -32,7 +32,7 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) ...@@ -32,7 +32,7 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
BN_CTX_start(ctx); BN_CTX_start(ctx);
rr = (a != r) ? r : BN_CTX_get(ctx); rr = (a != r) ? r : BN_CTX_get(ctx);
tmp = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx);
if (!rr || !tmp) if (rr == NULL || tmp == NULL)
goto err; goto err;
max = 2 * al; /* Non-zero (from above) */ max = 2 * al; /* Non-zero (from above) */
......
/* /*
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2011-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -62,10 +62,10 @@ int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, ...@@ -62,10 +62,10 @@ int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (!p1) if (p1 == NULL)
p1 = BN_CTX_get(ctx); p1 = BN_CTX_get(ctx);
if (!p2) if (p2 == NULL)
p2 = BN_CTX_get(ctx); p2 = BN_CTX_get(ctx);
t = BN_CTX_get(ctx); t = BN_CTX_get(ctx);
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -75,8 +75,6 @@ int DH_check(const DH *dh, int *ret) ...@@ -75,8 +75,6 @@ int DH_check(const DH *dh, int *ret)
goto err; goto err;
BN_CTX_start(ctx); BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx); t1 = BN_CTX_get(ctx);
if (t1 == NULL)
goto err;
t2 = BN_CTX_get(ctx); t2 = BN_CTX_get(ctx);
if (t2 == NULL) if (t2 == NULL)
goto err; goto err;
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -68,7 +68,7 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator, ...@@ -68,7 +68,7 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
BN_CTX_start(ctx); BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx); t1 = BN_CTX_get(ctx);
t2 = BN_CTX_get(ctx); t2 = BN_CTX_get(ctx);
if (t1 == NULL || t2 == NULL) if (t2 == NULL)
goto err; goto err;
/* Make sure 'ret' has the necessary elements */ /* Make sure 'ret' has the necessary elements */
......
/* /*
* Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2010-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -1285,9 +1285,10 @@ int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, ...@@ -1285,9 +1285,10 @@ int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((curve_p = BN_CTX_get(ctx)) == NULL) || curve_p = BN_CTX_get(ctx);
((curve_a = BN_CTX_get(ctx)) == NULL) || curve_a = BN_CTX_get(ctx);
((curve_b = BN_CTX_get(ctx)) == NULL)) curve_b = BN_CTX_get(ctx);
if (curve_b == NULL)
goto err; goto err;
BN_bin2bn(nistp224_curve_params[0], sizeof(felem_bytearray), curve_p); BN_bin2bn(nistp224_curve_params[0], sizeof(felem_bytearray), curve_p);
BN_bin2bn(nistp224_curve_params[1], sizeof(felem_bytearray), curve_a); BN_bin2bn(nistp224_curve_params[1], sizeof(felem_bytearray), curve_a);
...@@ -1417,10 +1418,11 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r, ...@@ -1417,10 +1418,11 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || x = BN_CTX_get(ctx);
((y = BN_CTX_get(ctx)) == NULL) || y = BN_CTX_get(ctx);
((z = BN_CTX_get(ctx)) == NULL) || z = BN_CTX_get(ctx);
((tmp_scalar = BN_CTX_get(ctx)) == NULL)) tmp_scalar = BN_CTX_get(ctx);
if (tmp_scalar == NULL)
goto err; goto err;
if (scalar != NULL) { if (scalar != NULL) {
...@@ -1600,7 +1602,9 @@ int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx) ...@@ -1600,7 +1602,9 @@ int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || ((y = BN_CTX_get(ctx)) == NULL)) x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
if (y == NULL)
goto err; goto err;
/* get the generator */ /* get the generator */
if (group->generator == NULL) if (group->generator == NULL)
......
...@@ -1901,9 +1901,10 @@ int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, ...@@ -1901,9 +1901,10 @@ int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((curve_p = BN_CTX_get(ctx)) == NULL) || curve_p = BN_CTX_get(ctx);
((curve_a = BN_CTX_get(ctx)) == NULL) || curve_a = BN_CTX_get(ctx);
((curve_b = BN_CTX_get(ctx)) == NULL)) curve_b = BN_CTX_get(ctx);
if (curve_b == NULL)
goto err; goto err;
BN_bin2bn(nistp256_curve_params[0], sizeof(felem_bytearray), curve_p); BN_bin2bn(nistp256_curve_params[0], sizeof(felem_bytearray), curve_p);
BN_bin2bn(nistp256_curve_params[1], sizeof(felem_bytearray), curve_a); BN_bin2bn(nistp256_curve_params[1], sizeof(felem_bytearray), curve_a);
...@@ -2034,10 +2035,11 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r, ...@@ -2034,10 +2035,11 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || x = BN_CTX_get(ctx);
((y = BN_CTX_get(ctx)) == NULL) || y = BN_CTX_get(ctx);
((z = BN_CTX_get(ctx)) == NULL) || z = BN_CTX_get(ctx);
((tmp_scalar = BN_CTX_get(ctx)) == NULL)) tmp_scalar = BN_CTX_get(ctx);
if (tmp_scalar == NULL)
goto err; goto err;
if (scalar != NULL) { if (scalar != NULL) {
...@@ -2224,7 +2226,9 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx) ...@@ -2224,7 +2226,9 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || ((y = BN_CTX_get(ctx)) == NULL)) x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
if (y == NULL)
goto err; goto err;
/* get the generator */ /* get the generator */
if (group->generator == NULL) if (group->generator == NULL)
......
...@@ -1724,9 +1724,10 @@ int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, ...@@ -1724,9 +1724,10 @@ int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((curve_p = BN_CTX_get(ctx)) == NULL) || curve_p = BN_CTX_get(ctx);
((curve_a = BN_CTX_get(ctx)) == NULL) || curve_a = BN_CTX_get(ctx);
((curve_b = BN_CTX_get(ctx)) == NULL)) curve_b = BN_CTX_get(ctx);
if (curve_b == NULL)
goto err; goto err;
BN_bin2bn(nistp521_curve_params[0], sizeof(felem_bytearray), curve_p); BN_bin2bn(nistp521_curve_params[0], sizeof(felem_bytearray), curve_p);
BN_bin2bn(nistp521_curve_params[1], sizeof(felem_bytearray), curve_a); BN_bin2bn(nistp521_curve_params[1], sizeof(felem_bytearray), curve_a);
...@@ -1856,10 +1857,11 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r, ...@@ -1856,10 +1857,11 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || x = BN_CTX_get(ctx);
((y = BN_CTX_get(ctx)) == NULL) || y = BN_CTX_get(ctx);
((z = BN_CTX_get(ctx)) == NULL) || z = BN_CTX_get(ctx);
((tmp_scalar = BN_CTX_get(ctx)) == NULL)) tmp_scalar = BN_CTX_get(ctx);
if (tmp_scalar == NULL)
goto err; goto err;
if (scalar != NULL) { if (scalar != NULL) {
...@@ -2043,7 +2045,9 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx) ...@@ -2043,7 +2045,9 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
if ((ctx = new_ctx = BN_CTX_new()) == NULL) if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0; return 0;
BN_CTX_start(ctx); BN_CTX_start(ctx);
if (((x = BN_CTX_get(ctx)) == NULL) || ((y = BN_CTX_get(ctx)) == NULL)) x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
if (y == NULL)
goto err; goto err;
/* get the generator */ /* get the generator */
if (group->generator == NULL) if (group->generator == NULL)
......
/* /*
* Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
...@@ -1213,7 +1213,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, ...@@ -1213,7 +1213,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
BN_CTX_start(ctx); BN_CTX_start(ctx);
tmp = BN_CTX_get(ctx); tmp = BN_CTX_get(ctx);
tmp_Z = BN_CTX_get(ctx); tmp_Z = BN_CTX_get(ctx);
if (tmp == NULL || tmp_Z == NULL) if (tmp_Z == NULL)
goto err; goto err;
prod_Z = OPENSSL_malloc(num * sizeof prod_Z[0]); prod_Z = OPENSSL_malloc(num * sizeof prod_Z[0]);
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -96,7 +96,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, ...@@ -96,7 +96,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx); ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n); num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num); buf = OPENSSL_malloc(num);
if (f == NULL || ret == NULL || buf == NULL) { if (ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE); RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
...@@ -257,7 +257,7 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, ...@@ -257,7 +257,7 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx); ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n); num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num); buf = OPENSSL_malloc(num);
if (f == NULL || ret == NULL || buf == NULL) { if (ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE); RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
...@@ -392,7 +392,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, ...@@ -392,7 +392,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx); ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n); num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num); buf = OPENSSL_malloc(num);
if (f == NULL || ret == NULL || buf == NULL) { if (ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE); RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
...@@ -534,7 +534,7 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, ...@@ -534,7 +534,7 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx); ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n); num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num); buf = OPENSSL_malloc(num);
if (f == NULL || ret == NULL || buf == NULL) { if (ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE); RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册