}
r = 1;
mac_end:
- if (mac_ctx)
- EVP_PKEY_CTX_free(mac_ctx);
+ EVP_PKEY_CTX_free(mac_ctx);
if (r == 0)
goto end;
}
ret = 0;
end:
- if (pkey)
- EVP_PKEY_free(pkey);
- if (ctx)
- EVP_PKEY_CTX_free(ctx);
+ EVP_PKEY_free(pkey);
+ EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
if (pass)
err:
BIO_puts(err, "Error initializing context\n");
ERR_print_errors(err);
- if (ctx)
- EVP_PKEY_CTX_free(ctx);
- if (pkey)
- EVP_PKEY_free(pkey);
+ EVP_PKEY_CTX_free(ctx);
+ EVP_PKEY_free(pkey);
return 0;
}
err:
BIO_printf(err, "Error initializing %s context\n", algname);
ERR_print_errors(err);
- if (ctx)
- EVP_PKEY_CTX_free(ctx);
+ EVP_PKEY_CTX_free(ctx);
return 0;
}
CRYPTO_push_info("process -export_cert: freeing");
# endif
- if (key)
- EVP_PKEY_free(key);
+ EVP_PKEY_free(key);
if (certs)
sk_X509_pop_free(certs, X509_free);
if (ucert)
BIO_write(out, buf_out, buf_outlen);
end:
- if (ctx)
- EVP_PKEY_CTX_free(ctx);
+ EVP_PKEY_CTX_free(ctx);
BIO_free(in);
BIO_free_all(out);
if (buf_in)
if (pkey == NULL) {
pkey = X509_REQ_get_pubkey(req);
- tmp = 1;
if (pkey == NULL)
goto end;
+ tmp = 1;
}
i = X509_REQ_verify(req, pkey);
BIO_free(in);
BIO_free_all(out);
EVP_PKEY_free(pkey);
- if (genctx)
- EVP_PKEY_CTX_free(genctx);
+ EVP_PKEY_CTX_free(genctx);
if (pkeyopts)
sk_OPENSSL_STRING_free(pkeyopts);
if (sigopts)
while (exc) {
if (exc->cert)
X509_free(exc->cert);
- if (exc->key)
- EVP_PKEY_free(exc->key);
+ EVP_PKEY_free(exc->key);
if (exc->chain)
sk_X509_pop_free(exc->chain, X509_free);
curr = exc;
X509_free(cert);
if (crls)
sk_X509_CRL_pop_free(crls, X509_CRL_free);
- if (key)
- EVP_PKEY_free(key);
+ EVP_PKEY_free(key);
if (chain)
sk_X509_pop_free(chain, X509_free);
if (pass)
sk_X509_CRL_pop_free(crls, X509_CRL_free);
if (s_dcert)
X509_free(s_dcert);
- if (s_key)
- EVP_PKEY_free(s_key);
- if (s_dkey)
- EVP_PKEY_free(s_dkey);
+ EVP_PKEY_free(s_key);
+ EVP_PKEY_free(s_dkey);
if (s_chain)
sk_X509_pop_free(s_chain, X509_free);
if (s_dchain)
SSL_CTX_free(ctx2);
if (s_cert2)
X509_free(s_cert2);
- if (s_key2)
- EVP_PKEY_free(s_key2);
+ EVP_PKEY_free(s_key2);
BIO_free(serverinfo_in);
# ifndef OPENSSL_NO_NEXTPROTONEG
if (next_proto.data)
(*a) = ret;
return (ret);
err:
- if ((ret != NULL) && ((a == NULL) || (*a != ret)))
+ if (a == NULL || *a != ret)
EVP_PKEY_free(ret);
return (NULL);
}
(*a) = ret;
return (ret);
err:
- if ((ret != NULL) && ((a == NULL) || (*a != ret)))
+ if (a == NULL || *a != ret)
EVP_PKEY_free(ret);
return (NULL);
}
if (x->enc_algor != NULL)
X509_ALGOR_free(x->enc_algor);
ASN1_OCTET_STRING_free(x->enc_pkey);
- if (x->dec_pkey != NULL)
- EVP_PKEY_free(x->dec_pkey);
+ EVP_PKEY_free(x->dec_pkey);
if ((x->key_data != NULL) && (x->key_free))
OPENSSL_free(x->key_data);
OPENSSL_free(x);
return ret;
error:
- if (ret != NULL)
- EVP_PKEY_free(ret);
+ EVP_PKEY_free(ret);
return (NULL);
}
{
if (operation == ASN1_OP_FREE_POST) {
CMS_SignerInfo *si = (CMS_SignerInfo *)*pval;
- if (si->pkey)
- EVP_PKEY_free(si->pkey);
+ EVP_PKEY_free(si->pkey);
if (si->signer)
X509_free(si->signer);
if (si->pctx)
{
CMS_RecipientEncryptedKey *rek = (CMS_RecipientEncryptedKey *)*pval;
if (operation == ASN1_OP_FREE_POST) {
- if (rek->pkey)
- EVP_PKEY_free(rek->pkey);
+ EVP_PKEY_free(rek->pkey);
}
return 1;
}
EVP_CIPHER_CTX_set_flags(&kari->ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
kari->pctx = NULL;
} else if (operation == ASN1_OP_FREE_POST) {
- if (kari->pctx)
- EVP_PKEY_CTX_free(kari->pctx);
+ EVP_PKEY_CTX_free(kari->pctx);
EVP_CIPHER_CTX_cleanup(&kari->ctx);
}
return 1;
CMS_RecipientInfo *ri = (CMS_RecipientInfo *)*pval;
if (ri->type == CMS_RECIPINFO_TRANS) {
CMS_KeyTransRecipientInfo *ktri = ri->d.ktri;
- if (ktri->pkey)
- EVP_PKEY_free(ktri->pkey);
+ EVP_PKEY_free(ktri->pkey);
if (ktri->recip)
X509_free(ktri->recip);
- if (ktri->pctx)
- EVP_PKEY_CTX_free(ktri->pctx);
+ EVP_PKEY_CTX_free(ktri->pctx);
} else if (ri->type == CMS_RECIPINFO_KEK) {
CMS_KEKRecipientInfo *kekri = ri->d.kekri;
if (kekri->key) {
err:
if (ri)
M_ASN1_free_of(ri, CMS_RecipientInfo);
- if (pk)
- EVP_PKEY_free(pk);
+ EVP_PKEY_free(pk);
return NULL;
}
ec->keylen = eklen;
err:
- if (ktri->pctx) {
- EVP_PKEY_CTX_free(ktri->pctx);
- ktri->pctx = NULL;
- }
+ EVP_PKEY_CTX_free(ktri->pctx);
+ ktri->pctx = NULL;
if (!ret && ek)
OPENSSL_free(ek);
kari->pctx = pctx;
return 1;
err:
- if (pctx)
- EVP_PKEY_CTX_free(pctx);
+ EVP_PKEY_CTX_free(pctx);
return 0;
}
kari->pctx = pctx;
rv = 1;
err:
- if (!rv && pctx)
+ if (!rv)
EVP_PKEY_CTX_free(pctx);
- if (ekey)
- EVP_PKEY_free(ekey);
+ EVP_PKEY_free(ekey);
return rv;
}
{
if (signer) {
CRYPTO_add(&signer->references, 1, CRYPTO_LOCK_X509);
- if (si->pkey)
- EVP_PKEY_free(si->pkey);
+ EVP_PKEY_free(si->pkey);
si->pkey = X509_get_pubkey(signer);
}
if (si->signer)
err:
EVP_MD_CTX_cleanup(&mctx);
- if (pctx)
- EVP_PKEY_CTX_free(pctx);
+ EVP_PKEY_CTX_free(pctx);
return r;
}
}
err:
- if (pkctx)
- EVP_PKEY_CTX_free(pkctx);
+ EVP_PKEY_CTX_free(pkctx);
EVP_MD_CTX_cleanup(&mctx);
return r;
err:
if (public_key)
ASN1_INTEGER_free(public_key);
- if (pkpeer)
- EVP_PKEY_free(pkpeer);
+ EVP_PKEY_free(pkpeer);
DH_free(dhpeer);
return rv;
}
X509_ALGOR_get0(&aoid, NULL, NULL, talg);
/* Is everything uninitialised? */
if (aoid == OBJ_nid2obj(NID_undef)) {
- ASN1_INTEGER *pubk;
- pubk = BN_to_ASN1_INTEGER(pkey->pkey.dh->pub_key, NULL);
+ ASN1_INTEGER *pubk = BN_to_ASN1_INTEGER(pkey->pkey.dh->pub_key, NULL);
if (!pubk)
goto err;
/* Set the key */
rv = 1;
err:
EC_KEY_free(ecpeer);
- if (pkpeer)
- EVP_PKEY_free(pkpeer);
+ EVP_PKEY_free(pkpeer);
return rv;
}
OPENSSL_cleanse(ctx->md_data, ctx->digest->ctx_size);
OPENSSL_free(ctx->md_data);
}
- if (ctx->pctx)
- EVP_PKEY_CTX_free(ctx->pctx);
+ EVP_PKEY_CTX_free(ctx->pctx);
#ifndef OPENSSL_NO_ENGINE
if (ctx->engine)
/*
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
{
- if (ctx) {
- EVP_CIPHER_CTX_cleanup(ctx);
+ EVP_CIPHER_CTX_cleanup(ctx);
+ if (ctx)
OPENSSL_free(ctx);
- }
}
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
{
+ if (!c)
+ return 0;
if (c->cipher != NULL) {
if (c->cipher->cleanup && !c->cipher->cleanup(c))
return 0;
pkey = NULL;
out:
- if (pkey) {
- EVP_PKEY_free(pkey);
- }
+ EVP_PKEY_free(pkey);
RSA_free(rsa);
return ret;
EVP_MD_CTX_cleanup(&md_ctx);
EVP_MD_CTX_cleanup(&md_ctx_verify);
- if (pkey) {
- EVP_PKEY_free(pkey);
- }
+ EVP_PKEY_free(pkey);
if (sig) {
OPENSSL_free(sig);
}
}
EVP_MD_CTX_cleanup(&md_ctx);
- if (pkey) {
- EVP_PKEY_free(pkey);
- }
+ EVP_PKEY_free(pkey);
return ret;
}
ERR_print_errors_fp(stderr);
}
- if (pkey != NULL) {
- EVP_PKEY_free(pkey);
- }
+ EVP_PKEY_free(pkey);
return ret;
}
PKCS8_PRIV_KEY_INFO_free(p8inf);
}
- if (pkey != NULL) {
- EVP_PKEY_free(pkey);
- }
+ EVP_PKEY_free(pkey);
return ret;
}
EVP_MD_CTX_destroy(mctx);
if (mac)
OPENSSL_free(mac);
- if (genctx)
- EVP_PKEY_CTX_free(genctx);
- if (key)
- EVP_PKEY_free(key);
+ EVP_PKEY_CTX_free(genctx);
+ EVP_PKEY_free(key);
t->err = err;
return 1;
}
OPENSSL_free(kdata->input);
if (kdata->output)
OPENSSL_free(kdata->output);
- if (kdata->ctx)
- EVP_PKEY_CTX_free(kdata->ctx);
+ EVP_PKEY_CTX_free(kdata->ctx);
}
static int pkey_test_parse(struct evp_test *t,
static void EVP_PKEY_free_it(EVP_PKEY *x)
{
+ /* internal function; x is never NULL */
if (x->ameth && x->ameth->pkey_free) {
x->ameth->pkey_free(x);
x->pkey.ptr = NULL;
return -1;
}
- if (ctx->peerkey)
- EVP_PKEY_free(ctx->peerkey);
+ EVP_PKEY_free(ctx->peerkey);
ctx->peerkey = peer;
ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0)
goto merr;
merr:
- if (mac_ctx)
- EVP_PKEY_CTX_free(mac_ctx);
+ EVP_PKEY_CTX_free(mac_ctx);
return mac_key;
}
return;
if (ctx->pmeth && ctx->pmeth->cleanup)
ctx->pmeth->cleanup(ctx);
- if (ctx->pkey)
- EVP_PKEY_free(ctx->pkey);
- if (ctx->peerkey)
- EVP_PKEY_free(ctx->peerkey);
+ EVP_PKEY_free(ctx->pkey);
+ EVP_PKEY_free(ctx->peerkey);
#ifndef OPENSSL_NO_ENGINE
if (ctx->engine)
/*
if (!ret)
return NULL;
if (x) {
- if (*x)
- EVP_PKEY_free(*x);
+ EVP_PKEY_free(*x);
*x = ret;
}
return ret;
goto p8err;
ret = EVP_PKCS82PKEY(p8inf);
if (x) {
- if (*x)
- EVP_PKEY_free((EVP_PKEY *)*x);
+ EVP_PKEY_free((EVP_PKEY *)*x);
*x = ret;
}
PKCS8_PRIV_KEY_INFO_free(p8inf);
goto p8err;
ret = EVP_PKCS82PKEY(p8inf);
if (x) {
- if (*x)
- EVP_PKEY_free((EVP_PKEY *)*x);
+ EVP_PKEY_free((EVP_PKEY *)*x);
*x = ret;
}
PKCS8_PRIV_KEY_INFO_free(p8inf);
goto err;
}
if (x) {
- if (*x)
- EVP_PKEY_free((EVP_PKEY *)*x);
+ EVP_PKEY_free((EVP_PKEY *)*x);
*x = ret;
}
}
memerr:
PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE);
DSA_free(dsa);
- if (ret)
- EVP_PKEY_free(ret);
+ EVP_PKEY_free(ret);
if (ctx)
BN_CTX_free(ctx);
return NULL;
memerr:
PEMerr(PEM_F_B2I_RSA, ERR_R_MALLOC_FAILURE);
RSA_free(rsa);
- if (ret)
- EVP_PKEY_free(ret);
+ EVP_PKEY_free(ret);
return NULL;
}
err:
- if (pkey && *pkey)
+ if (pkey)
EVP_PKEY_free(*pkey);
if (cert && *cert)
X509_free(*cert);
ret = 1;
err:
- if (pkey)
- EVP_PKEY_free(pkey);
- if (pctx)
- EVP_PKEY_CTX_free(pctx);
+ EVP_PKEY_free(pkey);
+ EVP_PKEY_CTX_free(pctx);
if (ek)
OPENSSL_free(ek);
return ret;
*peklen = eklen;
err:
- if (pctx)
- EVP_PKEY_CTX_free(pctx);
+ EVP_PKEY_CTX_free(pctx);
if (!ret && ek)
OPENSSL_free(ek);
PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, PKCS7_R_SIGNATURE_FAILURE);
ret = -1;
goto err;
- } else
- ret = 1;
+ }
+ ret = 1;
err:
EVP_MD_CTX_cleanup(&mdc_tmp);
return (ret);
return 1;
err:
- if (pkey)
- EVP_PKEY_free(pkey);
+ EVP_PKEY_free(pkey);
return 0;
}
int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key)
{
- if (ctx->signer_key)
- EVP_PKEY_free(ctx->signer_key);
+ EVP_PKEY_free(ctx->signer_key);
ctx->signer_key = key;
CRYPTO_add(&ctx->signer_key->references, +1, CRYPTO_LOCK_EVP_PKEY);
case -2:
X509err(X509_F_X509_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE);
}
- if (xk)
- EVP_PKEY_free(xk);
+ EVP_PKEY_free(xk);
if (ret > 0)
return 1;
return 0;
/* Final check: root CA signature */
rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);
end:
- if (pk)
- EVP_PKEY_free(pk);
+ EVP_PKEY_free(pk);
if (rv != X509_V_OK) {
/* Invalid signature or LOS errors are for previous cert */
if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM
}
if (!EVP_PKEY_missing_parameters(ktmp))
break;
- else {
- EVP_PKEY_free(ktmp);
- ktmp = NULL;
- }
+ EVP_PKEY_free(ktmp);
+ ktmp = NULL;
}
if (ktmp == NULL) {
X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,
CMS_ContentInfo_free(cms);
if (rcert)
X509_free(rcert);
- if (rkey)
- EVP_PKEY_free(rkey);
+ EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);
CMS_ContentInfo_free(cms);
if (rcert)
X509_free(rcert);
- if (rkey)
- EVP_PKEY_free(rkey);
+ EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);
CMS_ContentInfo_free(cms);
if (scert)
X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ EVP_PKEY_free(skey);
BIO_free(in);
BIO_free(out);
if (scert)
X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ EVP_PKEY_free(skey);
if (scert2)
X509_free(scert2);
- if (skey)
- EVP_PKEY_free(skey2);
+ EVP_PKEY_free(skey2);
BIO_free(in);
BIO_free(out);
PKCS7_free(p7);
if (rcert)
X509_free(rcert);
- if (rkey)
- EVP_PKEY_free(rkey);
+ EVP_PKEY_free(rkey);
BIO_free(in);
BIO_free(out);
PKCS7_free(p7);
if (scert)
X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ EVP_PKEY_free(skey);
BIO_free(in);
BIO_free(out);
if (scert)
X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ EVP_PKEY_free(skey);
if (scert2)
X509_free(scert2);
- if (skey)
- EVP_PKEY_free(skey2);
+ EVP_PKEY_free(skey2);
BIO_free(in);
BIO_free(out);
EVP_PKEY_CTX_dup() duplicates the context B<ctx>.
EVP_PKEY_CTX_free() frees up the context B<ctx>.
+If B<ctx> is NULL, nothing is done.
=head1 NOTES
structure which is used by OpenSSL to store private keys.
EVP_PKEY_free() frees up the private key B<key>.
+If B<key> is NULL, nothing is done.
=head1 NOTES
}
ASN1_OBJECT_free(gkt->key_agreement_info->cipher);
gkt->key_agreement_info->cipher = OBJ_nid2obj(param->nid);
- if (key_is_ephemeral && sec_key)
+ if (key_is_ephemeral)
EVP_PKEY_free(sec_key);
if (!key_is_ephemeral) {
/* Set control "public key from client certificate used" */
GOST_KEY_TRANSPORT_free(gkt);
return ret;
err:
- if (key_is_ephemeral && sec_key)
+ if (key_is_ephemeral)
EVP_PKEY_free(sec_key);
GOST_KEY_TRANSPORT_free(gkt);
return -1;
ret = 1;
err:
- if (eph_key)
- EVP_PKEY_free(eph_key);
+ EVP_PKEY_free(eph_key);
if (gkt)
GOST_KEY_TRANSPORT_free(gkt);
return ret;
return res;
err:
- if (res)
- EVP_PKEY_free(res);
+ EVP_PKEY_free(res);
return NULL;
}
EVP_PKEY_CTX_free(pkey_ctx);
if (ret)
return ret;
- else
- goto err;
+ goto err;
} else {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, SSL_R_UNKNOWN_CIPHER_TYPE);
X509_free(cpk->x509);
cpk->x509 = NULL;
}
- if (cpk->privatekey) {
- EVP_PKEY_free(cpk->privatekey);
- cpk->privatekey = NULL;
- }
+ EVP_PKEY_free(cpk->privatekey);
+ cpk->privatekey = NULL;
if (cpk->chain) {
sk_X509_pop_free(cpk->chain, X509_free);
cpk->chain = NULL;