diff options
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa_ameth.c | 9 | ||||
-rw-r--r-- | crypto/dsa/dsa_gen.c | 37 | ||||
-rw-r--r-- | crypto/dsa/dsa_key.c | 13 | ||||
-rw-r--r-- | crypto/dsa/dsa_lib.c | 21 | ||||
-rw-r--r-- | crypto/dsa/dsa_ossl.c | 32 | ||||
-rw-r--r-- | crypto/dsa/dsa_pmeth.c | 6 |
6 files changed, 41 insertions, 77 deletions
diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index 76fc2ce8c6..e26ca848dc 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -366,20 +366,17 @@ static int 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/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 3506bc3dd1..1827de8d0b 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -326,12 +326,9 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, 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,12 +343,10 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, if (seed_out) memcpy(seed_out, seed, qsize); } - if (ctx) { + if (ctx) BN_CTX_end(ctx); - BN_CTX_free(ctx); - } - if (mont != NULL) - BN_MONT_CTX_free(mont); + BN_CTX_free(ctx); + BN_MONT_CTX_free(mont); return ok; } @@ -631,17 +626,14 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, err: if (ok == 1) { if (p != ret->p) { - if (ret->p) - BN_free(ret->p); + BN_free(ret->p); ret->p = BN_dup(p); } if (q != ret->q) { - if (ret->q) - BN_free(ret->q); + BN_free(ret->q); ret->q = BN_dup(q); } - if (ret->g) - BN_free(ret->g); + BN_free(ret->g); ret->g = BN_dup(g); if (ret->p == NULL || ret->q == NULL || ret->g == NULL) { ok = -1; @@ -656,12 +648,10 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, OPENSSL_free(seed); if (seed_out != seed_tmp) OPENSSL_free(seed_tmp); - if (ctx) { + if (ctx) BN_CTX_end(ctx); - BN_CTX_free(ctx); - } - if (mont != NULL) - BN_MONT_CTX_free(mont); + BN_CTX_free(ctx); + BN_MONT_CTX_free(mont); EVP_MD_CTX_cleanup(&mctx); return ok; } @@ -696,8 +686,7 @@ int dsa_paramgen_check_g(DSA *dsa) rv = 0; err: BN_CTX_end(ctx); - if (mont) - BN_MONT_CTX_free(mont); + BN_MONT_CTX_free(mont); BN_CTX_free(ctx); return rv; diff --git a/crypto/dsa/dsa_key.c b/crypto/dsa/dsa_key.c index 1c05b0f80d..ff01deca4a 100644 --- a/crypto/dsa/dsa_key.c +++ b/crypto/dsa/dsa_key.c @@ -111,12 +111,10 @@ static int dsa_builtin_keygen(DSA *dsa) prk = priv_key; if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) { - if (local_prk != NULL) - BN_free(local_prk); + BN_free(local_prk); goto err; } - if (local_prk != NULL) - BN_free(local_prk); + BN_free(local_prk); } dsa->priv_key = priv_key; @@ -124,11 +122,10 @@ static int dsa_builtin_keygen(DSA *dsa) ok = 1; err: - if ((pub_key != NULL) && (dsa->pub_key == NULL)) + if (pub_key != dsa->pub_key) BN_free(pub_key); - if ((priv_key != NULL) && (dsa->priv_key == NULL)) + if (priv_key != dsa->priv_key) BN_free(priv_key); - if (ctx != NULL) - BN_CTX_free(ctx); + BN_CTX_free(ctx); return (ok); } diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index 5cf1824897..aec1b3639c 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -202,20 +202,13 @@ void 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); OPENSSL_free(r); } diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index 325eac479b..cd63211c86 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -214,12 +214,10 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) 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); } @@ -313,21 +311,18 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, 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) + if (ctx != ctx_in) BN_CTX_free(ctx); BN_clear_free(k); BN_clear_free(kq); @@ -422,14 +417,10 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, err: if (ret < 0) DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); - if (ctx != NULL) - BN_CTX_free(ctx); - if (u1) - BN_free(u1); - if (u2) - BN_free(u2); - if (t1) - BN_free(t1); + BN_CTX_free(ctx); + BN_free(u1); + BN_free(u2); + BN_free(t1); return (ret); } @@ -441,7 +432,6 @@ static int 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/crypto/dsa/dsa_pmeth.c b/crypto/dsa/dsa_pmeth.c index 6a47047031..c119209ab2 100644 --- a/crypto/dsa/dsa_pmeth.c +++ b/crypto/dsa/dsa_pmeth.c @@ -253,14 +253,12 @@ static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) pcb = NULL; dsa = DSA_new(); if (!dsa) { - if (pcb) - BN_GENCB_free(pcb); + BN_GENCB_free(pcb); return 0; } ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd, NULL, 0, NULL, NULL, NULL, pcb); - if (pcb) - BN_GENCB_free(pcb); + BN_GENCB_free(pcb); if (ret) EVP_PKEY_assign_DSA(pkey, dsa); else |