Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/crypto/ec
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@chromium.org>2015-04-22 22:08:19 +0300
committerAdam Langley <agl@google.com>2015-05-05 02:08:22 +0300
commitcfaf7ff9bf877239f17c805af6a3d7daae48e0a2 (patch)
tree873c4b8f54c1ba44b94e0c4ff13fd0d4ab516e5d /crypto/ec
parent22ccc2d8f1e0a3d19b98324d502322db8d89624f (diff)
Remove unnecessary NULL checks, part 2.
Stuff in crypto/ec. Change-Id: I3bd238c365c4766ed8abc6f835a107478b43b159 Reviewed-on: https://boringssl-review.googlesource.com/4515 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/ec')
-rw-r--r--crypto/ec/ec.c40
-rw-r--r--crypto/ec/ec_asn1.c30
-rw-r--r--crypto/ec/ec_key.c60
-rw-r--r--crypto/ec/ec_montgomery.c66
-rw-r--r--crypto/ec/oct.c16
-rw-r--r--crypto/ec/p256-64.c24
-rw-r--r--crypto/ec/simple.c48
-rw-r--r--crypto/ec/wnaf.c42
8 files changed, 88 insertions, 238 deletions
diff --git a/crypto/ec/ec.c b/crypto/ec/ec.c
index ab65ffb0..10220cbc 100644
--- a/crypto/ec/ec.c
+++ b/crypto/ec/ec.c
@@ -364,30 +364,14 @@ err:
EC_GROUP_free(group);
group = NULL;
}
- if (P) {
- 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);
- }
+ EC_POINT_free(P);
+ BN_CTX_free(ctx);
+ BN_free(p);
+ BN_free(a);
+ BN_free(b);
+ BN_free(order);
+ BN_free(x);
+ BN_free(y);
return group;
}
@@ -424,9 +408,7 @@ void EC_GROUP_free(EC_GROUP *group) {
ec_pre_comp_free(group->pre_comp);
- if (group->generator != NULL) {
- EC_POINT_free(group->generator);
- }
+ EC_POINT_free(group->generator);
BN_free(&group->order);
BN_free(&group->cofactor);
@@ -497,9 +479,7 @@ EC_GROUP *EC_GROUP_dup(const EC_GROUP *a) {
err:
if (!ok) {
- if (t) {
- EC_GROUP_free(t);
- }
+ EC_GROUP_free(t);
return NULL;
} else {
return t;
diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c
index c32ae131..ff3dca6d 100644
--- a/crypto/ec/ec_asn1.c
+++ b/crypto/ec/ec_asn1.c
@@ -172,9 +172,7 @@ ECPKPARAMETERS *ec_asn1_group2pkparameters(const EC_GROUP *group,
return NULL;
}
} else {
- if (ret->value.named_curve) {
- ASN1_OBJECT_free(ret->value.named_curve);
- }
+ ASN1_OBJECT_free(ret->value.named_curve);
}
/* use the ASN.1 OID to describe the the elliptic curve parameters. */
@@ -257,10 +255,8 @@ static EC_GROUP *d2i_ECPKParameters(EC_GROUP **groupp, const uint8_t **inp,
return NULL;
}
- if (groupp && *groupp) {
- EC_GROUP_free(*groupp);
- }
if (groupp) {
+ EC_GROUP_free(*groupp);
*groupp = group;
}
@@ -307,9 +303,7 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
}
if (priv_key->parameters) {
- if (ret->group) {
- EC_GROUP_free(ret->group);
- }
+ EC_GROUP_free(ret->group);
ret->group = ec_asn1_pkparameters2group(priv_key->parameters);
}
@@ -333,9 +327,7 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
goto err;
}
- if (ret->pub_key) {
- EC_POINT_free(ret->pub_key);
- }
+ EC_POINT_free(ret->pub_key);
ret->pub_key = EC_POINT_new(ret->group);
if (ret->pub_key == NULL) {
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_EC_LIB);
@@ -377,15 +369,13 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
err:
if (!ok) {
- if (ret && (a == NULL || *a != ret)) {
+ if (a == NULL || *a != ret) {
EC_KEY_free(ret);
}
ret = NULL;
}
- if (priv_key) {
- EC_PRIVATEKEY_free(priv_key);
- }
+ EC_PRIVATEKEY_free(priv_key);
return ret;
}
@@ -478,12 +468,8 @@ int i2d_ECPrivateKey(const EC_KEY *key, uint8_t **outp) {
ok = 1;
err:
- if (buffer) {
- OPENSSL_free(buffer);
- }
- if (priv_key) {
- EC_PRIVATEKEY_free(priv_key);
- }
+ OPENSSL_free(buffer);
+ EC_PRIVATEKEY_free(priv_key);
return (ok ? ret : 0);
}
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 0f4e666b..bbf5fee8 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -153,15 +153,9 @@ void EC_KEY_free(EC_KEY *r) {
METHOD_unref(r->ecdsa_meth);
}
- if (r->group != NULL) {
- EC_GROUP_free(r->group);
- }
- if (r->pub_key != NULL) {
- EC_POINT_free(r->pub_key);
- }
- if (r->priv_key != NULL) {
- BN_clear_free(r->priv_key);
- }
+ EC_GROUP_free(r->group);
+ EC_POINT_free(r->pub_key);
+ BN_clear_free(r->priv_key);
CRYPTO_free_ex_data(&g_ex_data_class, r, &r->ex_data);
@@ -177,9 +171,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) {
/* Copy the parameters. */
if (src->group) {
/* TODO(fork): duplicating the group seems wasteful. */
- if (dest->group) {
- EC_GROUP_free(dest->group);
- }
+ EC_GROUP_free(dest->group);
dest->group = EC_GROUP_dup(src->group);
if (dest->group == NULL) {
return NULL;
@@ -188,9 +180,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) {
/* Copy the public key. */
if (src->pub_key && src->group) {
- if (dest->pub_key) {
- EC_POINT_free(dest->pub_key);
- }
+ EC_POINT_free(dest->pub_key);
dest->pub_key = EC_POINT_dup(src->pub_key, src->group);
if (dest->pub_key == NULL) {
return NULL;
@@ -248,9 +238,7 @@ int EC_KEY_is_opaque(const EC_KEY *key) {
const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key) { return key->group; }
int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group) {
- if (key->group != NULL) {
- EC_GROUP_free(key->group);
- }
+ EC_GROUP_free(key->group);
/* TODO(fork): duplicating the group seems wasteful but see
* |EC_KEY_set_conv_form|. */
key->group = EC_GROUP_dup(group);
@@ -262,9 +250,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;
}
@@ -274,9 +260,7 @@ const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key) {
}
int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key) {
- if (key->pub_key != NULL) {
- EC_POINT_free(key->pub_key);
- }
+ EC_POINT_free(key->pub_key);
key->pub_key = EC_POINT_dup(pub_key, key->group);
return (key->pub_key == NULL) ? 0 : 1;
}
@@ -367,12 +351,8 @@ int EC_KEY_check_key(const EC_KEY *eckey) {
ok = 1;
err:
- if (ctx != NULL) {
- BN_CTX_free(ctx);
- }
- if (point != NULL) {
- EC_POINT_free(point);
- }
+ BN_CTX_free(ctx);
+ EC_POINT_free(point);
return ok;
}
@@ -423,12 +403,8 @@ int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
ok = 1;
err:
- if (ctx) {
- BN_CTX_free(ctx);
- }
- if (point) {
- EC_POINT_free(point);
- }
+ BN_CTX_free(ctx);
+ EC_POINT_free(point);
return ok;
}
@@ -489,18 +465,14 @@ int EC_KEY_generate_key(EC_KEY *eckey) {
ok = 1;
err:
- if (order) {
- BN_free(order);
- }
- if (pub_key != NULL && eckey->pub_key == NULL) {
+ 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 == NULL) {
BN_free(priv_key);
}
- if (ctx != NULL) {
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return ok;
}
diff --git a/crypto/ec/ec_montgomery.c b/crypto/ec/ec_montgomery.c
index f152b13f..74dbc6ce 100644
--- a/crypto/ec/ec_montgomery.c
+++ b/crypto/ec/ec_montgomery.c
@@ -127,38 +127,26 @@ int ec_GFp_mont_group_init(EC_GROUP *group) {
}
void ec_GFp_mont_group_finish(EC_GROUP *group) {
- if (group->mont != NULL) {
- BN_MONT_CTX_free(group->mont);
- group->mont = NULL;
- }
- if (group->one != NULL) {
- BN_free(group->one);
- group->one = NULL;
- }
+ BN_MONT_CTX_free(group->mont);
+ group->mont = NULL;
+ BN_free(group->one);
+ group->one = NULL;
ec_GFp_simple_group_finish(group);
}
void ec_GFp_mont_group_clear_finish(EC_GROUP *group) {
- if (group->mont != NULL) {
- BN_MONT_CTX_free(group->mont);
- group->mont = NULL;
- }
- if (group->one != NULL) {
- BN_clear_free(group->one);
- group->one = NULL;
- }
+ BN_MONT_CTX_free(group->mont);
+ group->mont = NULL;
+ BN_clear_free(group->one);
+ group->one = NULL;
ec_GFp_simple_group_clear_finish(group);
}
int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) {
- if (dest->mont != NULL) {
- BN_MONT_CTX_free(dest->mont);
- dest->mont = NULL;
- }
- if (dest->one != NULL) {
- BN_clear_free(dest->one);
- dest->one = NULL;
- }
+ BN_MONT_CTX_free(dest->mont);
+ dest->mont = NULL;
+ BN_clear_free(dest->one);
+ dest->one = NULL;
if (!ec_GFp_simple_group_copy(dest, src)) {
return 0;
@@ -183,10 +171,8 @@ int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src) {
return 1;
err:
- if (dest->mont != NULL) {
- BN_MONT_CTX_free(dest->mont);
- dest->mont = NULL;
- }
+ BN_MONT_CTX_free(dest->mont);
+ dest->mont = NULL;
return 0;
}
@@ -197,14 +183,10 @@ int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p,
BIGNUM *one = NULL;
int ret = 0;
- if (group->mont != NULL) {
- BN_MONT_CTX_free(group->mont);
- group->mont = NULL;
- }
- if (group->one != NULL) {
- BN_free(group->one);
- group->one = NULL;
- }
+ BN_MONT_CTX_free(group->mont);
+ group->mont = NULL;
+ BN_free(group->one);
+ group->one = NULL;
if (ctx == NULL) {
ctx = new_ctx = BN_CTX_new();
@@ -241,15 +223,9 @@ 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);
- }
- if (one != NULL) {
- BN_free(one);
- }
+ BN_CTX_free(new_ctx);
+ BN_MONT_CTX_free(mont);
+ BN_free(one);
return ret;
}
diff --git a/crypto/ec/oct.c b/crypto/ec/oct.c
index 1cb7c2f0..816a42f5 100644
--- a/crypto/ec/oct.c
+++ b/crypto/ec/oct.c
@@ -164,18 +164,14 @@ static size_t ec_GFp_simple_point2oct(const EC_GROUP *group,
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;
}
@@ -275,9 +271,7 @@ static 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;
}
@@ -456,9 +450,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;
}
diff --git a/crypto/ec/p256-64.c b/crypto/ec/p256-64.c
index a1d278e1..8f824dec 100644
--- a/crypto/ec/p256-64.c
+++ b/crypto/ec/p256-64.c
@@ -1647,9 +1647,7 @@ int ec_GFp_nistp256_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;
}
@@ -1899,21 +1897,11 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
err:
BN_CTX_end(ctx);
- if (generator != NULL) {
- EC_POINT_free(generator);
- }
- if (new_ctx != NULL) {
- BN_CTX_free(new_ctx);
- }
- if (secrets != NULL) {
- OPENSSL_free(secrets);
- }
- if (pre_comp != NULL) {
- OPENSSL_free(pre_comp);
- }
- if (tmp_smallfelems != NULL) {
- OPENSSL_free(tmp_smallfelems);
- }
+ EC_POINT_free(generator);
+ BN_CTX_free(new_ctx);
+ OPENSSL_free(secrets);
+ OPENSSL_free(pre_comp);
+ OPENSSL_free(tmp_smallfelems);
return ret;
}
diff --git a/crypto/ec/simple.c b/crypto/ec/simple.c
index 24781195..69fd2e43 100644
--- a/crypto/ec/simple.c
+++ b/crypto/ec/simple.c
@@ -226,9 +226,7 @@ int ec_GFp_simple_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;
}
@@ -268,9 +266,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;
}
@@ -345,9 +341,7 @@ err:
if (ctx != NULL) {
BN_CTX_end(ctx);
}
- if (new_ctx != NULL) {
- BN_CTX_free(new_ctx);
- }
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -446,9 +440,7 @@ int ec_GFp_simple_set_Jprojective_coordinates_GFp(
ret = 1;
err:
- if (new_ctx != NULL) {
- BN_CTX_free(new_ctx);
- }
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -491,9 +483,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;
}
@@ -612,9 +602,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;
}
@@ -805,9 +793,7 @@ end:
/* 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;
}
@@ -934,9 +920,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;
}
@@ -1053,9 +1037,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;
}
@@ -1168,9 +1150,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;
}
@@ -1211,9 +1191,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;
}
@@ -1358,9 +1336,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) {
diff --git a/crypto/ec/wnaf.c b/crypto/ec/wnaf.c
index 0beee2f9..d87a7d97 100644
--- a/crypto/ec/wnaf.c
+++ b/crypto/ec/wnaf.c
@@ -631,18 +631,10 @@ 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);
- }
- if (tmp != NULL) {
- EC_POINT_free(tmp);
- }
- if (wsize != NULL) {
- OPENSSL_free(wsize);
- }
- if (wNAF_len != NULL) {
- OPENSSL_free(wNAF_len);
- }
+ BN_CTX_free(new_ctx);
+ EC_POINT_free(tmp);
+ OPENSSL_free(wsize);
+ OPENSSL_free(wNAF_len);
if (wNAF != NULL) {
signed char **w;
@@ -659,9 +651,7 @@ err:
OPENSSL_free(val);
}
- if (val_sub != NULL) {
- OPENSSL_free(val_sub);
- }
+ OPENSSL_free(val_sub);
return ret;
}
@@ -699,10 +689,8 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) {
int ret = 0;
/* if there is an old EC_PRE_COMP object, throw it away */
- if (group->pre_comp) {
- ec_pre_comp_free(group->pre_comp);
- group->pre_comp = NULL;
- }
+ ec_pre_comp_free(group->pre_comp);
+ group->pre_comp = NULL;
generator = EC_GROUP_get0_generator(group);
if (generator == NULL) {
@@ -841,12 +829,8 @@ err:
if (ctx != NULL) {
BN_CTX_end(ctx);
}
- if (new_ctx != NULL) {
- BN_CTX_free(new_ctx);
- }
- if (pre_comp) {
- ec_pre_comp_free(pre_comp);
- }
+ BN_CTX_free(new_ctx);
+ ec_pre_comp_free(pre_comp);
if (points) {
EC_POINT **p;
@@ -855,12 +839,8 @@ err:
}
OPENSSL_free(points);
}
- if (tmp_point) {
- EC_POINT_free(tmp_point);
- }
- if (base) {
- EC_POINT_free(base);
- }
+ EC_POINT_free(tmp_point);
+ EC_POINT_free(base);
return ret;
}