aboutsummaryrefslogtreecommitdiff
path: root/crypto/ec/ecx_backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ec/ecx_backend.c')
-rw-r--r--crypto/ec/ecx_backend.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/crypto/ec/ecx_backend.c b/crypto/ec/ecx_backend.c
index e42767d6bf0f..d21c037841ae 100644
--- a/crypto/ec/ecx_backend.c
+++ b/crypto/ec/ecx_backend.c
@@ -110,22 +110,16 @@ ECX_KEY *ossl_ecx_key_dup(const ECX_KEY *key, int selection)
{
ECX_KEY *ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
-
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- OPENSSL_free(ret);
- return NULL;
- }
ret->libctx = key->libctx;
ret->haspubkey = 0;
ret->keylen = key->keylen;
ret->type = key->type;
- ret->references = 1;
+
+ if (!CRYPTO_NEW_REF(&ret->references, 1))
+ goto err;
if (key->propq != NULL) {
ret->propq = OPENSSL_strdup(key->propq);
@@ -141,16 +135,18 @@ ECX_KEY *ossl_ecx_key_dup(const ECX_KEY *key, int selection)
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0
&& key->privkey != NULL) {
- if (ossl_ecx_key_allocate_privkey(ret) == NULL)
+ if (ossl_ecx_key_allocate_privkey(ret) == NULL) {
+ ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
goto err;
+ }
memcpy(ret->privkey, key->privkey, ret->keylen);
}
return ret;
err:
+ CRYPTO_FREE_REF(&ret->references);
ossl_ecx_key_free(ret);
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
return NULL;
}
@@ -189,7 +185,7 @@ ECX_KEY *ossl_ecx_key_op(const X509_ALGOR *palg,
key = ossl_ecx_key_new(libctx, KEYNID2TYPE(id), 1, propq);
if (key == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
return 0;
}
pubkey = key->pubkey;
@@ -199,7 +195,7 @@ ECX_KEY *ossl_ecx_key_op(const X509_ALGOR *palg,
} else {
privkey = ossl_ecx_key_allocate_privkey(key);
if (privkey == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
goto err;
}
if (op == KEY_OP_KEYGEN) {