diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2014-07-12 16:03:38 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2014-07-12 16:03:38 +0000 |
commit | 803c8dd8383f2beecc51eeb93a0d74de48fde813 (patch) | |
tree | 7f45d2fc5e781e1974149986eb31d41236a274ec /lib/libcrypto/dsa | |
parent | 5ea82a759638e52c9147469bf1c240afd43f265c (diff) |
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 'lib/libcrypto/dsa')
-rw-r--r-- | lib/libcrypto/dsa/dsa.h | 4 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_ameth.c | 18 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_gen.c | 14 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_key.c | 5 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_lib.c | 26 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_ossl.c | 23 | ||||
-rw-r--r-- | lib/libcrypto/dsa/dsa_sign.c | 8 |
7 files changed, 36 insertions, 62 deletions
diff --git a/lib/libcrypto/dsa/dsa.h b/lib/libcrypto/dsa/dsa.h index c1264ac325f..bd7b26070d9 100644 --- a/lib/libcrypto/dsa/dsa.h +++ b/lib/libcrypto/dsa/dsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa.h,v 1.17 2014/06/12 15:49:28 deraadt Exp $ */ +/* $OpenBSD: dsa.h,v 1.18 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -206,7 +206,7 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *); DSA * DSA_new(void); DSA * DSA_new_method(ENGINE *engine); -void DSA_free (DSA *r); +void DSA_free(DSA *r); /* "up" the DSA object's reference count */ int DSA_up_ref(DSA *r); int DSA_size(const DSA *); diff --git a/lib/libcrypto/dsa/dsa_ameth.c b/lib/libcrypto/dsa/dsa_ameth.c index 73c58ec94c9..7da4ac5695a 100644 --- a/lib/libcrypto/dsa/dsa_ameth.c +++ b/lib/libcrypto/dsa/dsa_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_ameth.c,v 1.12 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_ameth.c,v 1.13 2014/07/12 16:03:37 miod Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -125,8 +125,7 @@ dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) err: if (public_key) ASN1_INTEGER_free(public_key); - if (dsa) - DSA_free(dsa); + DSA_free(dsa); return 0; } @@ -264,7 +263,7 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) } EVP_PKEY_assign_DSA(pkey, dsa); - BN_CTX_free (ctx); + BN_CTX_free(ctx); if (ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); else @@ -275,7 +274,7 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) decerr: DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR); dsaerr: - BN_CTX_free (ctx); + BN_CTX_free(ctx); if (privkey) ASN1_INTEGER_free(privkey); sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); @@ -358,20 +357,17 @@ dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) if ((a = BN_dup(from->pkey.dsa->p)) == NULL) return 0; - if (to->pkey.dsa->p != NULL) - BN_free(to->pkey.dsa->p); + BN_free(to->pkey.dsa->p); to->pkey.dsa->p = a; if ((a = BN_dup(from->pkey.dsa->q)) == NULL) return 0; - if (to->pkey.dsa->q != NULL) - BN_free(to->pkey.dsa->q); + BN_free(to->pkey.dsa->q); to->pkey.dsa->q = a; if ((a = BN_dup(from->pkey.dsa->g)) == NULL) return 0; - if (to->pkey.dsa->g != NULL) - BN_free(to->pkey.dsa->g); + BN_free(to->pkey.dsa->g); to->pkey.dsa->g = a; return 1; } diff --git a/lib/libcrypto/dsa/dsa_gen.c b/lib/libcrypto/dsa/dsa_gen.c index d41e7562e10..a3d07b901a6 100644 --- a/lib/libcrypto/dsa/dsa_gen.c +++ b/lib/libcrypto/dsa/dsa_gen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_gen.c,v 1.15 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_gen.c,v 1.16 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -322,12 +322,9 @@ end: ok = 1; err: if (ok) { - if (ret->p) - BN_free(ret->p); - if (ret->q) - BN_free(ret->q); - if (ret->g) - BN_free(ret->g); + BN_free(ret->p); + BN_free(ret->q); + BN_free(ret->g); ret->p = BN_dup(p); ret->q = BN_dup(q); ret->g = BN_dup(g); @@ -346,8 +343,7 @@ err: BN_CTX_end(ctx); BN_CTX_free(ctx); } - if (mont != NULL) - BN_MONT_CTX_free(mont); + BN_MONT_CTX_free(mont); return ok; } #endif diff --git a/lib/libcrypto/dsa/dsa_key.c b/lib/libcrypto/dsa/dsa_key.c index 4573ecbccea..4dc28dbb90c 100644 --- a/lib/libcrypto/dsa/dsa_key.c +++ b/lib/libcrypto/dsa/dsa_key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_key.c,v 1.18 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_key.c,v 1.19 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -128,8 +128,7 @@ err: BN_free(pub_key); if (priv_key != NULL && dsa->priv_key == NULL) BN_free(priv_key); - if (ctx != NULL) - BN_CTX_free(ctx); + BN_CTX_free(ctx); return ok; } #endif diff --git a/lib/libcrypto/dsa/dsa_lib.c b/lib/libcrypto/dsa/dsa_lib.c index 97307134cd5..1cfd6ce6b83 100644 --- a/lib/libcrypto/dsa/dsa_lib.c +++ b/lib/libcrypto/dsa/dsa_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_lib.c,v 1.20 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_lib.c,v 1.21 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -201,20 +201,13 @@ DSA_free(DSA *r) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); - if (r->p != NULL) - BN_clear_free(r->p); - if (r->q != NULL) - BN_clear_free(r->q); - if (r->g != NULL) - BN_clear_free(r->g); - if (r->pub_key != NULL) - BN_clear_free(r->pub_key); - if (r->priv_key != NULL) - BN_clear_free(r->priv_key); - if (r->kinv != NULL) - BN_clear_free(r->kinv); - if (r->r != NULL) - BN_clear_free(r->r); + BN_clear_free(r->p); + BN_clear_free(r->q); + BN_clear_free(r->g); + BN_clear_free(r->pub_key); + BN_clear_free(r->priv_key); + BN_clear_free(r->kinv); + BN_clear_free(r->r); free(r); } @@ -305,8 +298,7 @@ DSA_dup_DH(const DSA *r) return ret; err: - if (ret != NULL) - DH_free(ret); + DH_free(ret); return NULL; } #endif diff --git a/lib/libcrypto/dsa/dsa_ossl.c b/lib/libcrypto/dsa/dsa_ossl.c index 5bff836c500..e3728530634 100644 --- a/lib/libcrypto/dsa/dsa_ossl.c +++ b/lib/libcrypto/dsa/dsa_ossl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_ossl.c,v 1.20 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_ossl.c,v 1.21 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -212,12 +212,10 @@ err: BN_free(r); BN_free(s); } - if (ctx != NULL) - BN_CTX_free(ctx); + BN_CTX_free(ctx); BN_clear_free(&m); BN_clear_free(&xr); - if (kinv != NULL) /* dsa->kinv is NULL now if we used it */ - BN_clear_free(kinv); + BN_clear_free(kinv); return ret; } @@ -295,19 +293,16 @@ dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) if ((kinv = BN_mod_inverse(NULL, &k, dsa->q, ctx)) == NULL) goto err; - if (*kinvp != NULL) - BN_clear_free(*kinvp); + BN_clear_free(*kinvp); *kinvp = kinv; kinv = NULL; - if (*rp != NULL) - BN_clear_free(*rp); + BN_clear_free(*rp); *rp = r; ret = 1; err: if (!ret) { DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB); - if (r != NULL) - BN_clear_free(r); + BN_clear_free(r); } if (ctx_in == NULL) BN_CTX_free(ctx); @@ -406,8 +401,7 @@ err: there is no error in BN. Test should be ret == -1 (Ben) */ if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); - if (ctx != NULL) - BN_CTX_free(ctx); + BN_CTX_free(ctx); BN_free(&u1); BN_free(&u2); BN_free(&t1); @@ -424,8 +418,7 @@ dsa_init(DSA *dsa) static int dsa_finish(DSA *dsa) { - if (dsa->method_mont_p) - BN_MONT_CTX_free(dsa->method_mont_p); + BN_MONT_CTX_free(dsa->method_mont_p); return 1; } diff --git a/lib/libcrypto/dsa/dsa_sign.c b/lib/libcrypto/dsa/dsa_sign.c index efeb35477c4..80e002c4a7a 100644 --- a/lib/libcrypto/dsa/dsa_sign.c +++ b/lib/libcrypto/dsa/dsa_sign.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_sign.c,v 1.17 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: dsa_sign.c,v 1.18 2014/07/12 16:03:37 miod Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -91,10 +91,8 @@ void DSA_SIG_free(DSA_SIG *sig) { if (sig) { - if (sig->r) - BN_free(sig->r); - if (sig->s) - BN_free(sig->s); + BN_free(sig->r); + BN_free(sig->s); free(sig); } } |