Use EVP_PKEY_dup instead of manually incrementing the refcount.
Reference counting should be internal to the type, otherwise callers need to know which lock to use. Change-Id: If4d805876a321ef6dece115c805e605584ff311e Reviewed-on: https://boringssl-review.googlesource.com/1414 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
bf681a40d6
commit
e6e15fc3a1
@ -119,8 +119,7 @@ static EVP_PKEY_CTX *evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) {
|
||||
ret->operation = EVP_PKEY_OP_UNDEFINED;
|
||||
|
||||
if (pkey) {
|
||||
ret->pkey = pkey;
|
||||
CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
ret->pkey = EVP_PKEY_dup(pkey);
|
||||
}
|
||||
|
||||
if (pmeth->init) {
|
||||
@ -176,14 +175,12 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx) {
|
||||
rctx->operation = pctx->operation;
|
||||
|
||||
if (pctx->pkey) {
|
||||
CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
rctx->pkey = EVP_PKEY_dup(pctx->pkey);
|
||||
}
|
||||
rctx->pkey = pctx->pkey;
|
||||
|
||||
if (pctx->peerkey) {
|
||||
CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
rctx->peerkey = EVP_PKEY_dup(pctx->peerkey);
|
||||
}
|
||||
rctx->peerkey = pctx->peerkey;
|
||||
|
||||
if (pctx->pmeth->copy(rctx, pctx) > 0) {
|
||||
return rctx;
|
||||
@ -437,7 +434,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CRYPTO_add(&peer->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
EVP_PKEY_dup(peer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
|
||||
|
||||
if (key->pkey != NULL)
|
||||
{
|
||||
CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
return key->pkey;
|
||||
return EVP_PKEY_dup(key->pkey);
|
||||
}
|
||||
|
||||
if (key->public_key == NULL) goto error;
|
||||
@ -178,9 +177,8 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
|
||||
key->pkey = ret;
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
|
||||
}
|
||||
CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
|
||||
|
||||
return ret;
|
||||
return EVP_PKEY_dup(ret);
|
||||
|
||||
error:
|
||||
if (ret != NULL)
|
||||
|
@ -226,9 +226,8 @@ static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
|
||||
|
||||
if (c->pkeys[i].privatekey != NULL)
|
||||
EVP_PKEY_free(c->pkeys[i].privatekey);
|
||||
CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
|
||||
c->pkeys[i].privatekey=pkey;
|
||||
c->key= &(c->pkeys[i]);
|
||||
c->pkeys[i].privatekey = EVP_PKEY_dup(pkey);
|
||||
c->key = &(c->pkeys[i]);
|
||||
|
||||
c->valid=0;
|
||||
return(1);
|
||||
|
Loading…
Reference in New Issue
Block a user