summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-06-22 09:33:40 +1000
committerPauli <pauli@openssl.org>2023-07-01 21:18:25 +1000
commit99b7beafd212144fc3c77a6c09fc48f06f245c29 (patch)
tree1edf7d68e907691b7d6c51efb77fee07259bfb5c
parent1353736b3e6f33a9f6e47f837c5de05cc0dd3647 (diff)
ecx: update to structure based atomics
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/21260)
-rw-r--r--crypto/ec/ecx_backend.c11
-rw-r--r--crypto/ec/ecx_key.c18
-rw-r--r--include/crypto/ecx.h1
3 files changed, 11 insertions, 19 deletions
diff --git a/crypto/ec/ecx_backend.c b/crypto/ec/ecx_backend.c
index 7a43274d51..0107a612a8 100644
--- a/crypto/ec/ecx_backend.c
+++ b/crypto/ec/ecx_backend.c
@@ -113,17 +113,13 @@ ECX_KEY *ossl_ecx_key_dup(const ECX_KEY *key, int selection)
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 = key->haspubkey;
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);
@@ -146,6 +142,7 @@ ECX_KEY *ossl_ecx_key_dup(const ECX_KEY *key, int selection)
return ret;
err:
+ CRYPTO_FREE_REF(&ret->references);
ossl_ecx_key_free(ret);
return NULL;
}
diff --git a/crypto/ec/ecx_key.c b/crypto/ec/ecx_key.c
index 548e49091d..36276ce98e 100644
--- a/crypto/ec/ecx_key.c
+++ b/crypto/ec/ecx_key.c
@@ -42,24 +42,20 @@ ECX_KEY *ossl_ecx_key_new(OSSL_LIB_CTX *libctx, ECX_KEY_TYPE type, int haspubkey
break;
}
ret->type = type;
- ret->references = 1;
+
+ if (!CRYPTO_NEW_REF(&ret->references, 1))
+ goto err;
if (propq != NULL) {
ret->propq = OPENSSL_strdup(propq);
if (ret->propq == NULL)
goto err;
}
-
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
- goto err;
- }
return ret;
err:
if (ret != NULL) {
OPENSSL_free(ret->propq);
- CRYPTO_THREAD_lock_free(ret->lock);
+ CRYPTO_FREE_REF(&ret->references);
}
OPENSSL_free(ret);
return NULL;
@@ -72,7 +68,7 @@ void ossl_ecx_key_free(ECX_KEY *key)
if (key == NULL)
return;
- CRYPTO_DOWN_REF(&key->references, &i, key->lock);
+ CRYPTO_DOWN_REF(&key->references, &i);
REF_PRINT_COUNT("ECX_KEY", key);
if (i > 0)
return;
@@ -80,7 +76,7 @@ void ossl_ecx_key_free(ECX_KEY *key)
OPENSSL_free(key->propq);
OPENSSL_secure_clear_free(key->privkey, key->keylen);
- CRYPTO_THREAD_lock_free(key->lock);
+ CRYPTO_FREE_REF(&key->references);
OPENSSL_free(key);
}
@@ -93,7 +89,7 @@ int ossl_ecx_key_up_ref(ECX_KEY *key)
{
int i;
- if (CRYPTO_UP_REF(&key->references, &i, key->lock) <= 0)
+ if (CRYPTO_UP_REF(&key->references, &i) <= 0)
return 0;
REF_PRINT_COUNT("ECX_KEY", key);
diff --git a/include/crypto/ecx.h b/include/crypto/ecx.h
index 5ae38d7c9c..5f100ef16c 100644
--- a/include/crypto/ecx.h
+++ b/include/crypto/ecx.h
@@ -72,7 +72,6 @@ struct ecx_key_st {
size_t keylen;
ECX_KEY_TYPE type;
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
size_t ossl_ecx_key_length(ECX_KEY_TYPE type);