diff options
| author | miod <> | 2014-07-12 16:03:37 +0000 |
|---|---|---|
| committer | miod <> | 2014-07-12 16:03:37 +0000 |
| commit | 1ae7466a2fdd60df6484d8d132d70a044fd58c92 (patch) | |
| tree | b756e0522f06b8c8ef257885370d0ada8f818fa8 /src/lib/libcrypto/ec/ec_key.c | |
| parent | 3c4c98fca81949fb441815860d40ad66626df65d (diff) | |
| download | openbsd-1ae7466a2fdd60df6484d8d132d70a044fd58c92.tar.gz openbsd-1ae7466a2fdd60df6484d8d132d70a044fd58c92.tar.bz2 openbsd-1ae7466a2fdd60df6484d8d132d70a044fd58c92.zip | |
if (x) FOO_free(x) -> FOO_free(x).
Improves readability, keeps the code smaller so that it is warmer in your
cache.
review & ok deraadt@
Diffstat (limited to 'src/lib/libcrypto/ec/ec_key.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index 7067a949da..1154c4dbf5 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_key.c,v 1.8 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
| 4 | */ | 4 | */ |
| @@ -116,12 +116,9 @@ EC_KEY_free(EC_KEY * r) | |||
| 116 | if (i > 0) | 116 | if (i > 0) |
| 117 | return; | 117 | return; |
| 118 | 118 | ||
| 119 | if (r->group != NULL) | 119 | EC_GROUP_free(r->group); |
| 120 | EC_GROUP_free(r->group); | 120 | EC_POINT_free(r->pub_key); |
| 121 | if (r->pub_key != NULL) | 121 | BN_clear_free(r->priv_key); |
| 122 | EC_POINT_free(r->pub_key); | ||
| 123 | if (r->priv_key != NULL) | ||
| 124 | BN_clear_free(r->priv_key); | ||
| 125 | 122 | ||
| 126 | EC_EX_DATA_free_all_data(&r->method_data); | 123 | EC_EX_DATA_free_all_data(&r->method_data); |
| 127 | 124 | ||
| @@ -143,8 +140,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src) | |||
| 143 | if (src->group) { | 140 | if (src->group) { |
| 144 | const EC_METHOD *meth = EC_GROUP_method_of(src->group); | 141 | const EC_METHOD *meth = EC_GROUP_method_of(src->group); |
| 145 | /* clear the old group */ | 142 | /* clear the old group */ |
| 146 | if (dest->group) | 143 | EC_GROUP_free(dest->group); |
| 147 | EC_GROUP_free(dest->group); | ||
| 148 | dest->group = EC_GROUP_new(meth); | 144 | dest->group = EC_GROUP_new(meth); |
| 149 | if (dest->group == NULL) | 145 | if (dest->group == NULL) |
| 150 | return NULL; | 146 | return NULL; |
| @@ -153,8 +149,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src) | |||
| 153 | } | 149 | } |
| 154 | /* copy the public key */ | 150 | /* copy the public key */ |
| 155 | if (src->pub_key && src->group) { | 151 | if (src->pub_key && src->group) { |
| 156 | if (dest->pub_key) | 152 | EC_POINT_free(dest->pub_key); |
| 157 | EC_POINT_free(dest->pub_key); | ||
| 158 | dest->pub_key = EC_POINT_new(src->group); | 153 | dest->pub_key = EC_POINT_new(src->group); |
| 159 | if (dest->pub_key == NULL) | 154 | if (dest->pub_key == NULL) |
| 160 | return NULL; | 155 | return NULL; |
| @@ -261,14 +256,12 @@ EC_KEY_generate_key(EC_KEY * eckey) | |||
| 261 | ok = 1; | 256 | ok = 1; |
| 262 | 257 | ||
| 263 | err: | 258 | err: |
| 264 | if (order) | 259 | BN_free(order); |
| 265 | BN_free(order); | ||
| 266 | if (pub_key != NULL && eckey->pub_key == NULL) | 260 | if (pub_key != NULL && eckey->pub_key == NULL) |
| 267 | EC_POINT_free(pub_key); | 261 | EC_POINT_free(pub_key); |
| 268 | if (priv_key != NULL && eckey->priv_key == NULL) | 262 | if (priv_key != NULL && eckey->priv_key == NULL) |
| 269 | BN_free(priv_key); | 263 | BN_free(priv_key); |
| 270 | if (ctx != NULL) | 264 | BN_CTX_free(ctx); |
| 271 | BN_CTX_free(ctx); | ||
| 272 | return (ok); | 265 | return (ok); |
| 273 | } | 266 | } |
| 274 | 267 | ||
| @@ -334,10 +327,8 @@ EC_KEY_check_key(const EC_KEY * eckey) | |||
| 334 | } | 327 | } |
| 335 | ok = 1; | 328 | ok = 1; |
| 336 | err: | 329 | err: |
| 337 | if (ctx != NULL) | 330 | BN_CTX_free(ctx); |
| 338 | BN_CTX_free(ctx); | 331 | EC_POINT_free(point); |
| 339 | if (point != NULL) | ||
| 340 | EC_POINT_free(point); | ||
| 341 | return (ok); | 332 | return (ok); |
| 342 | } | 333 | } |
| 343 | 334 | ||
| @@ -406,10 +397,8 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y) | |||
| 406 | ok = 1; | 397 | ok = 1; |
| 407 | 398 | ||
| 408 | err: | 399 | err: |
| 409 | if (ctx) | 400 | BN_CTX_free(ctx); |
| 410 | BN_CTX_free(ctx); | 401 | EC_POINT_free(point); |
| 411 | if (point) | ||
| 412 | EC_POINT_free(point); | ||
| 413 | return ok; | 402 | return ok; |
| 414 | 403 | ||
| 415 | } | 404 | } |
| @@ -423,8 +412,7 @@ EC_KEY_get0_group(const EC_KEY * key) | |||
| 423 | int | 412 | int |
| 424 | EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group) | 413 | EC_KEY_set_group(EC_KEY * key, const EC_GROUP * group) |
| 425 | { | 414 | { |
| 426 | if (key->group != NULL) | 415 | EC_GROUP_free(key->group); |
| 427 | EC_GROUP_free(key->group); | ||
| 428 | key->group = EC_GROUP_dup(group); | 416 | key->group = EC_GROUP_dup(group); |
| 429 | return (key->group == NULL) ? 0 : 1; | 417 | return (key->group == NULL) ? 0 : 1; |
| 430 | } | 418 | } |
| @@ -438,8 +426,7 @@ EC_KEY_get0_private_key(const EC_KEY * key) | |||
| 438 | int | 426 | int |
| 439 | EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key) | 427 | EC_KEY_set_private_key(EC_KEY * key, const BIGNUM * priv_key) |
| 440 | { | 428 | { |
| 441 | if (key->priv_key) | 429 | BN_clear_free(key->priv_key); |
| 442 | BN_clear_free(key->priv_key); | ||
| 443 | key->priv_key = BN_dup(priv_key); | 430 | key->priv_key = BN_dup(priv_key); |
| 444 | return (key->priv_key == NULL) ? 0 : 1; | 431 | return (key->priv_key == NULL) ? 0 : 1; |
| 445 | } | 432 | } |
| @@ -453,8 +440,7 @@ EC_KEY_get0_public_key(const EC_KEY * key) | |||
| 453 | int | 440 | int |
| 454 | EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key) | 441 | EC_KEY_set_public_key(EC_KEY * key, const EC_POINT * pub_key) |
| 455 | { | 442 | { |
| 456 | if (key->pub_key != NULL) | 443 | EC_POINT_free(key->pub_key); |
| 457 | EC_POINT_free(key->pub_key); | ||
| 458 | key->pub_key = EC_POINT_dup(pub_key, key->group); | 444 | key->pub_key = EC_POINT_dup(pub_key, key->group); |
| 459 | return (key->pub_key == NULL) ? 0 : 1; | 445 | return (key->pub_key == NULL) ? 0 : 1; |
| 460 | } | 446 | } |
