summaryrefslogtreecommitdiffstats
path: root/crypto/ec
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2015-05-01 03:37:06 +0200
committerRich Salz <rsalz@openssl.org>2015-05-01 03:37:06 +0200
commit23a1d5e97cd543d2b8e1b01dbf0f619b2e5ce540 (patch)
tree2d9372864fc2b34939d21b3706768ec225c9548f /crypto/ec
parentFix buffer overrun in RSA signing (diff)
downloadopenssl-23a1d5e97cd543d2b8e1b01dbf0f619b2e5ce540.tar.xz
openssl-23a1d5e97cd543d2b8e1b01dbf0f619b2e5ce540.zip
free NULL cleanup 7
This gets BN_.*free: BN_BLINDING_free BN_CTX_free BN_FLG_FREE BN_GENCB_free BN_MONT_CTX_free BN_RECP_CTX_free BN_clear_free BN_free BUF_MEM_free Also fix a call to DSA_SIG_free to ccgost engine and remove some #ifdef'd dead code in engines/e_ubsec. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/ec')
-rw-r--r--crypto/ec/ec2_mult.c3
-rw-r--r--crypto/ec/ec2_oct.c12
-rw-r--r--crypto/ec/ec2_smpl.c33
-rw-r--r--crypto/ec/ec_ameth.c9
-rw-r--r--crypto/ec/ec_asn1.c44
-rw-r--r--crypto/ec/ec_check.c3
-rw-r--r--crypto/ec/ec_curve.c21
-rw-r--r--crypto/ec/ec_key.c20
-rw-r--r--crypto/ec/ec_lib.c36
-rw-r--r--crypto/ec/ec_mult.c6
-rw-r--r--crypto/ec/eck_prn.c21
-rw-r--r--crypto/ec/ecp_mont.c60
-rw-r--r--crypto/ec/ecp_nist.c9
-rw-r--r--crypto/ec/ecp_nistp224.c9
-rw-r--r--crypto/ec/ecp_nistp256.c9
-rw-r--r--crypto/ec/ecp_nistp521.c9
-rw-r--r--crypto/ec/ecp_nistz256.c6
-rw-r--r--crypto/ec/ecp_oct.c12
-rw-r--r--crypto/ec/ecp_smpl.c45
19 files changed, 125 insertions, 242 deletions
diff --git a/crypto/ec/ec2_mult.c b/crypto/ec/ec2_mult.c
index 635c0a55f1..2049dc57f8 100644
--- a/crypto/ec/ec2_mult.c
+++ b/crypto/ec/ec2_mult.c
@@ -439,8 +439,7 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r,
err:
EC_POINT_free(p);
EC_POINT_free(acc);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
diff --git a/crypto/ec/ec2_oct.c b/crypto/ec/ec2_oct.c
index 614c371f86..821c371009 100644
--- a/crypto/ec/ec2_oct.c
+++ b/crypto/ec/ec2_oct.c
@@ -160,8 +160,7 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -278,15 +277,13 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
err:
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return 0;
}
@@ -396,8 +393,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
#endif
diff --git a/crypto/ec/ec2_smpl.c b/crypto/ec/ec2_smpl.c
index c1fb63d94d..d6a41a46bf 100644
--- a/crypto/ec/ec2_smpl.c
+++ b/crypto/ec/ec2_smpl.c
@@ -135,12 +135,9 @@ int ec_GF2m_simple_group_init(EC_GROUP *group)
group->b = BN_new();
if (!group->field || !group->a || !group->b) {
- if (group->field)
- BN_free(group->field);
- if (group->a)
- BN_free(group->a);
- if (group->b)
- BN_free(group->b);
+ BN_free(group->field);
+ BN_free(group->a);
+ BN_free(group->b);
return 0;
}
return 1;
@@ -318,8 +315,7 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -331,12 +327,9 @@ int ec_GF2m_simple_point_init(EC_POINT *point)
point->Z = BN_new();
if (!point->X || !point->Y || !point->Z) {
- if (point->X)
- BN_free(point->X);
- if (point->Y)
- BN_free(point->Y);
- if (point->Z)
- BN_free(point->Z);
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
return 0;
}
return 1;
@@ -569,8 +562,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -663,8 +655,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -716,8 +707,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -758,8 +748,7 @@ int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c
index 6b34be38d7..0554c209e5 100644
--- a/crypto/ec/ec_ameth.c
+++ b/crypto/ec/ec_ameth.c
@@ -500,12 +500,9 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
err:
if (!ret)
ECerr(EC_F_DO_EC_KEY_PRINT, reason);
- if (pub_key)
- BN_free(pub_key);
- if (order)
- BN_free(order);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_free(pub_key);
+ BN_free(order);
+ BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return (ret);
diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c
index 36dcb969c4..5976a2fba3 100644
--- a/crypto/ec/ec_asn1.c
+++ b/crypto/ec/ec_asn1.c
@@ -421,8 +421,8 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
ok = 1;
- err:if (tmp)
- BN_free(tmp);
+ err:
+ BN_free(tmp);
return (ok);
}
@@ -524,21 +524,19 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
ok = 1;
- err:if (buffer_1)
+ err:
+ if (buffer_1)
OPENSSL_free(buffer_1);
if (buffer_2)
OPENSSL_free(buffer_2);
- if (tmp_1)
- BN_free(tmp_1);
- if (tmp_2)
- BN_free(tmp_2);
+ BN_free(tmp_1);
+ BN_free(tmp_2);
return (ok);
}
static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
ECPARAMETERS *param)
{
- int ok = 0;
size_t len = 0;
ECPARAMETERS *ret = NULL;
BIGNUM *tmp = NULL;
@@ -624,18 +622,15 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
}
}
- ok = 1;
+ return ret;
- err:if (!ok) {
- if (ret && !param)
- ECPARAMETERS_free(ret);
- ret = NULL;
- }
- if (tmp)
- BN_free(tmp);
+ err:
+ if (!param)
+ ECPARAMETERS_free(ret);
+ BN_free(tmp);
if (buffer)
OPENSSL_free(buffer);
- return (ret);
+ return NULL;
}
ECPKPARAMETERS *ec_asn1_group2pkparameters(const EC_GROUP *group,
@@ -891,10 +886,8 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
/* extract the cofactor (optional) */
if (params->cofactor == NULL) {
- if (b) {
- BN_free(b);
- b = NULL;
- }
+ BN_free(b);
+ b = NULL;
} else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
@@ -913,12 +906,9 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
ret = NULL;
}
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
EC_POINT_free(point);
return (ret);
}
diff --git a/crypto/ec/ec_check.c b/crypto/ec/ec_check.c
index 422ca87cc6..1d44ad2283 100644
--- a/crypto/ec/ec_check.c
+++ b/crypto/ec/ec_check.c
@@ -112,8 +112,7 @@ int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
EC_POINT_free(point);
return ret;
}
diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c
index d79637d9e5..8bba3bcb83 100644
--- a/crypto/ec/ec_curve.c
+++ b/crypto/ec/ec_curve.c
@@ -3115,20 +3115,13 @@ static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)
group = NULL;
}
EC_POINT_free(P);
- if (ctx)
- BN_CTX_free(ctx);
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
- if (order)
- BN_free(order);
- if (x)
- BN_free(x);
- if (y)
- BN_free(y);
+ BN_CTX_free(ctx);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
+ BN_free(order);
+ BN_free(x);
+ BN_free(y);
return group;
}
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index dbd91d6f69..4c588e83aa 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -122,8 +122,7 @@ void EC_KEY_free(EC_KEY *r)
EC_GROUP_free(r->group);
EC_POINT_free(r->pub_key);
- if (r->priv_key != NULL)
- BN_clear_free(r->priv_key);
+ BN_clear_free(r->priv_key);
EC_EX_DATA_free_all_data(&r->method_data);
@@ -266,14 +265,12 @@ int EC_KEY_generate_key(EC_KEY *eckey)
ok = 1;
err:
- if (order)
- BN_free(order);
+ BN_free(order);
if (eckey->pub_key == NULL)
EC_POINT_free(pub_key);
- if (priv_key != NULL && eckey->priv_key == NULL)
+ if (eckey->priv_key != priv_key)
BN_free(priv_key);
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return (ok);
}
@@ -339,8 +336,7 @@ int EC_KEY_check_key(const EC_KEY *eckey)
}
ok = 1;
err:
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
EC_POINT_free(point);
return (ok);
}
@@ -413,8 +409,7 @@ int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
ok = 1;
err:
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
EC_POINT_free(point);
return ok;
@@ -439,8 +434,7 @@ const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
{
- if (key->priv_key)
- BN_clear_free(key->priv_key);
+ BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
return (key->priv_key == NULL) ? 0 : 1;
}
diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c
index b2a5d79710..1f51f74aa9 100644
--- a/crypto/ec/ec_lib.c
+++ b/crypto/ec/ec_lib.c
@@ -117,10 +117,8 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
return ret;
err:
- if (ret->order)
- BN_free(ret->order);
- if (ret->cofactor)
- BN_free(ret->cofactor);
+ BN_free(ret->order);
+ BN_free(ret->cofactor);
OPENSSL_free(ret);
return NULL;
}
@@ -135,8 +133,7 @@ void EC_GROUP_free(EC_GROUP *group)
EC_EX_DATA_free_all_data(&group->extra_data);
- if (group->mont_data)
- BN_MONT_CTX_free(group->mont_data);
+ BN_MONT_CTX_free(group->mont_data);
EC_POINT_free(group->generator);
BN_free(group->order);
@@ -160,8 +157,7 @@ void EC_GROUP_clear_free(EC_GROUP *group)
EC_EX_DATA_clear_free_all_data(&group->extra_data);
- if (group->mont_data)
- BN_MONT_CTX_free(group->mont_data);
+ BN_MONT_CTX_free(group->mont_data);
EC_POINT_clear_free(group->generator);
BN_clear_free(group->order);
@@ -208,10 +204,8 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
return 0;
} else {
/* src->generator == NULL */
- if (dest->mont_data != NULL) {
- BN_MONT_CTX_free(dest->mont_data);
- dest->mont_data = NULL;
- }
+ BN_MONT_CTX_free(dest->mont_data);
+ dest->mont_data = NULL;
}
if (src->generator != NULL) {
@@ -507,8 +501,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
b3 = BN_CTX_get(ctx);
if (!b3) {
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return -1;
}
@@ -535,8 +528,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
!EC_GROUP_get_cofactor(a, a2, ctx) ||
!EC_GROUP_get_cofactor(b, b2, ctx)) {
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return -1;
}
if (BN_cmp(a1, b1) || BN_cmp(a2, b2))
@@ -544,8 +536,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
}
BN_CTX_end(ctx);
- if (ctx_new)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx_new);
return r;
}
@@ -1093,10 +1084,8 @@ int ec_precompute_mont_data(EC_GROUP *group)
BN_CTX *ctx = BN_CTX_new();
int ret = 0;
- if (group->mont_data) {
- BN_MONT_CTX_free(group->mont_data);
- group->mont_data = NULL;
- }
+ BN_MONT_CTX_free(group->mont_data);
+ group->mont_data = NULL;
if (ctx == NULL)
goto err;
@@ -1115,7 +1104,6 @@ int ec_precompute_mont_data(EC_GROUP *group)
err:
- if (ctx)
- BN_CTX_free(ctx);
+ BN_CTX_free(ctx);
return ret;
}
diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c
index 6dabfc8d99..b4723fb5d5 100644
--- a/crypto/ec/ec_mult.c
+++ b/crypto/ec/ec_mult.c
@@ -553,8 +553,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
EC_POINT_free(tmp);
if (wsize != NULL)
OPENSSL_free(wsize);
@@ -746,8 +745,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (pre_comp)
ec_pre_comp_free(pre_comp);
if (points) {
diff --git a/crypto/ec/eck_prn.c b/crypto/ec/eck_prn.c
index e1f5b69c76..6eb529138a 100644
--- a/crypto/ec/eck_prn.c
+++ b/crypto/ec/eck_prn.c
@@ -318,20 +318,13 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
err:
if (!ret)
ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
- if (gen)
- BN_free(gen);
- if (order)
- BN_free(order);
- if (cofactor)
- BN_free(cofactor);
- if (ctx)
- BN_CTX_free(ctx);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
+ BN_free(gen);
+ BN_free(order);
+ BN_free(cofactor);
+ BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return (ret);
diff --git a/crypto/ec/ecp_mont.c b/crypto/ec/ecp_mont.c
index bc9fd4759c..af914aa597 100644
--- a/crypto/ec/ecp_mont.c
+++ b/crypto/ec/ecp_mont.c
@@ -122,40 +122,28 @@ int ec_GFp_mont_group_init(EC_GROUP *group)
void ec_GFp_mont_group_finish(EC_GROUP *group)
{
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_free(group->field_data2);
+ group->field_data2 = NULL;
ec_GFp_simple_group_finish(group);
}
void ec_GFp_mont_group_clear_finish(EC_GROUP *group)
{
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_clear_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_clear_free(group->field_data2);
+ group->field_data2 = NULL;
ec_GFp_simple_group_clear_finish(group);
}
int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
- if (dest->field_data1 != NULL) {
- BN_MONT_CTX_free(dest->field_data1);
- dest->field_data1 = NULL;
- }
- if (dest->field_data2 != NULL) {
- BN_clear_free(dest->field_data2);
- dest->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(dest->field_data1);
+ dest->field_data1 = NULL;
+ BN_clear_free(dest->field_data2);
+ dest->field_data2 = NULL;
if (!ec_GFp_simple_group_copy(dest, src))
return 0;
@@ -176,10 +164,8 @@ int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
return 1;
err:
- if (dest->field_data1 != NULL) {
- BN_MONT_CTX_free(dest->field_data1);
- dest->field_data1 = NULL;
- }
+ BN_MONT_CTX_free(dest->field_data1);
+ dest->field_data1 = NULL;
return 0;
}
@@ -191,14 +177,10 @@ int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p,
BIGNUM *one = NULL;
int ret = 0;
- if (group->field_data1 != NULL) {
- BN_MONT_CTX_free(group->field_data1);
- group->field_data1 = NULL;
- }
- if (group->field_data2 != NULL) {
- BN_free(group->field_data2);
- group->field_data2 = NULL;
- }
+ BN_MONT_CTX_free(group->field_data1);
+ group->field_data1 = NULL;
+ BN_free(group->field_data2);
+ group->field_data2 = NULL;
if (ctx == NULL) {
ctx = new_ctx = BN_CTX_new();
@@ -234,10 +216,8 @@ int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p,
}
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
- if (mont != NULL)
- BN_MONT_CTX_free(mont);
+ BN_CTX_free(new_ctx);
+ BN_MONT_CTX_free(mont);
return ret;
}
diff --git a/crypto/ec/ecp_nist.c b/crypto/ec/ecp_nist.c
index 814051985c..2efb69e8e6 100644
--- a/crypto/ec/ecp_nist.c
+++ b/crypto/ec/ecp_nist.c
@@ -150,8 +150,7 @@ int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -176,8 +175,7 @@ int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
ret = 1;
err:
- if (ctx_new)
- BN_CTX_free(ctx_new);
+ BN_CTX_free(ctx_new);
return ret;
}
@@ -202,7 +200,6 @@ int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
ret = 1;
err:
- if (ctx_new)
- BN_CTX_free(ctx_new);
+ BN_CTX_free(ctx_new);
return ret;
}
diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c
index a5e76f41b9..fdcf450331 100644
--- a/crypto/ec/ecp_nistp224.c
+++ b/crypto/ec/ecp_nistp224.c
@@ -1291,8 +1291,7 @@ int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p,
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -1573,8 +1572,7 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
@@ -1709,8 +1707,7 @@ int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp224_pre_comp_free(pre);
return ret;
}
diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c
index 6fce22eb61..d03bf15d8c 100644
--- a/crypto/ec/ecp_nistp256.c
+++ b/crypto/ec/ecp_nistp256.c
@@ -1906,8 +1906,7 @@ int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p,
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -2193,8 +2192,7 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
@@ -2339,8 +2337,7 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp256_pre_comp_free(pre);
return ret;
}
diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c
index 8657a8ff05..1069214f6b 100644
--- a/crypto/ec/ecp_nistp521.c
+++ b/crypto/ec/ecp_nistp521.c
@@ -1735,8 +1735,7 @@ int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p,
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -2021,8 +2020,7 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (secrets != NULL)
OPENSSL_free(secrets);
if (pre_comp != NULL)
@@ -2137,8 +2135,7 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
nistp521_pre_comp_free(pre);
return ret;
}
diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c
index 417c29a682..ae1fcddc10 100644
--- a/crypto/ec/ecp_nistz256.c
+++ b/crypto/ec/ecp_nistz256.c
@@ -1121,10 +1121,8 @@ __owur static int ecp_nistz256_set_from_affine(EC_POINT *out, const EC_GROUP *gr
ret = EC_POINT_set_affine_coordinates_GFp(group, out, x, y, ctx);
- if (x)
- BN_free(x);
- if (y)
- BN_free(y);
+ BN_free(x);
+ BN_free(y);
return ret;
}
diff --git a/crypto/ec/ecp_oct.c b/crypto/ec/ecp_oct.c
index be309cd80a..a68b559bc0 100644
--- a/crypto/ec/ecp_oct.c
+++ b/crypto/ec/ecp_oct.c
@@ -202,8 +202,7 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -312,15 +311,13 @@ size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
err:
if (used_ctx)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return 0;
}
@@ -422,7 +419,6 @@ int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c
index 2d42d34f51..df7314a73a 100644
--- a/crypto/ec/ecp_smpl.c
+++ b/crypto/ec/ecp_smpl.c
@@ -225,8 +225,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -271,8 +270,7 @@ int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
ret = 1;
err:
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -350,8 +348,7 @@ int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -363,12 +360,9 @@ int ec_GFp_simple_point_init(EC_POINT *point)
point->Z_is_one = 0;
if (!point->X || !point->Y || !point->Z) {
- if (point->X)
- BN_free(point->X);
- if (point->Y)
- BN_free(point->Y);
- if (point->Z)
- BN_free(point->Z);
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
return 0;
}
return 1;
@@ -466,8 +460,7 @@ int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -516,8 +509,7 @@ int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
ret = 1;
err:
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -649,8 +641,7 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -836,8 +827,7 @@ int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
end:
if (ctx) /* otherwise we already called BN_CTX_end */
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -979,8 +969,7 @@ int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -1097,8 +1086,7 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -1206,8 +1194,7 @@ int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
end:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -1246,8 +1233,7 @@ int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -1398,8 +1384,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
if (prod_Z != NULL) {
for (i = 0; i < num; i++) {
if (prod_Z[i] == NULL)