diff options
author | Pauli <pauli@openssl.org> | 2023-06-22 09:48:49 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-07-01 21:18:25 +1000 |
commit | 6be83ac172aac93b49ae0b847fd5ac9de6ab3ff5 (patch) | |
tree | 87100def56be88bd30b7ad3d74ab9959c9258d7a | |
parent | a903a132a4256d34f20cb2f7636247b41fd85965 (diff) |
evp: 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/evp/asymcipher.c | 11 | ||||
-rw-r--r-- | crypto/evp/cmeth_lib.c | 4 | ||||
-rw-r--r-- | crypto/evp/digest.c | 14 | ||||
-rw-r--r-- | crypto/evp/evp_enc.c | 16 | ||||
-rw-r--r-- | crypto/evp/evp_lib.c | 6 | ||||
-rw-r--r-- | crypto/evp/evp_local.h | 5 | ||||
-rw-r--r-- | crypto/evp/evp_rand.c | 25 | ||||
-rw-r--r-- | crypto/evp/exchange.c | 11 | ||||
-rw-r--r-- | crypto/evp/kdf_meth.c | 9 | ||||
-rw-r--r-- | crypto/evp/kem.c | 11 | ||||
-rw-r--r-- | crypto/evp/keymgmt_meth.c | 12 | ||||
-rw-r--r-- | crypto/evp/mac_meth.c | 11 | ||||
-rw-r--r-- | crypto/evp/p_lib.c | 10 | ||||
-rw-r--r-- | crypto/evp/signature.c | 12 | ||||
-rw-r--r-- | include/crypto/evp.h | 4 |
15 files changed, 62 insertions, 99 deletions
diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index ca2a8ebdf2..c431d78a40 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -324,15 +324,12 @@ static EVP_ASYM_CIPHER *evp_asym_cipher_new(OSSL_PROVIDER *prov) if (cipher == NULL) return NULL; - cipher->lock = CRYPTO_THREAD_lock_new(); - if (cipher->lock == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); + if (!CRYPTO_NEW_REF(&cipher->refcnt, 1)) { OPENSSL_free(cipher); return NULL; } cipher->prov = prov; ossl_provider_up_ref(prov); - cipher->refcnt = 1; return cipher; } @@ -460,12 +457,12 @@ void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher) if (cipher == NULL) return; - CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock); + CRYPTO_DOWN_REF(&cipher->refcnt, &i); if (i > 0) return; OPENSSL_free(cipher->type_name); ossl_provider_free(cipher->prov); - CRYPTO_THREAD_lock_free(cipher->lock); + CRYPTO_FREE_REF(&cipher->refcnt); OPENSSL_free(cipher); } @@ -473,7 +470,7 @@ int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher) { int ref = 0; - CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock); + CRYPTO_UP_REF(&cipher->refcnt, &ref); return 1; } diff --git a/crypto/evp/cmeth_lib.c b/crypto/evp/cmeth_lib.c index a806ec5f9e..ab0d246585 100644 --- a/crypto/evp/cmeth_lib.c +++ b/crypto/evp/cmeth_lib.c @@ -46,10 +46,10 @@ EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher) if ((to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size, cipher->key_len)) != NULL) { - CRYPTO_RWLOCK *lock = to->lock; + CRYPTO_REF_COUNT refcnt = to->refcnt; memcpy(to, cipher, sizeof(*to)); - to->lock = lock; + to->refcnt = refcnt; to->origin = EVP_ORIG_METH; } return to; diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 286f5bdc63..9a0d1b5b08 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -901,13 +901,9 @@ EVP_MD *evp_md_new(void) { EVP_MD *md = OPENSSL_zalloc(sizeof(*md)); - if (md != NULL) { - md->lock = CRYPTO_THREAD_lock_new(); - if (md->lock == NULL) { - OPENSSL_free(md); - return NULL; - } - md->refcnt = 1; + if (md != NULL && !CRYPTO_NEW_REF(&md->refcnt, 1)) { + OPENSSL_free(md); + return NULL; } return md; } @@ -1120,7 +1116,7 @@ int EVP_MD_up_ref(EVP_MD *md) int ref = 0; if (md->origin == EVP_ORIG_DYNAMIC) - CRYPTO_UP_REF(&md->refcnt, &ref, md->lock); + CRYPTO_UP_REF(&md->refcnt, &ref); return 1; } @@ -1131,7 +1127,7 @@ void EVP_MD_free(EVP_MD *md) if (md == NULL || md->origin != EVP_ORIG_DYNAMIC) return; - CRYPTO_DOWN_REF(&md->refcnt, &i, md->lock); + CRYPTO_DOWN_REF(&md->refcnt, &i); if (i > 0) return; evp_md_free_int(md); diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 3187ba35c9..6b6d65163f 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1483,13 +1483,9 @@ EVP_CIPHER *evp_cipher_new(void) { EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER)); - if (cipher != NULL) { - cipher->lock = CRYPTO_THREAD_lock_new(); - if (cipher->lock == NULL) { - OPENSSL_free(cipher); - return NULL; - } - cipher->refcnt = 1; + if (cipher != NULL && !CRYPTO_NEW_REF(&cipher->refcnt, 1)) { + OPENSSL_free(cipher); + return NULL; } return cipher; } @@ -1689,7 +1685,7 @@ int EVP_CIPHER_up_ref(EVP_CIPHER *cipher) int ref = 0; if (cipher->origin == EVP_ORIG_DYNAMIC) - CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock); + CRYPTO_UP_REF(&cipher->refcnt, &ref); return 1; } @@ -1697,7 +1693,7 @@ void evp_cipher_free_int(EVP_CIPHER *cipher) { OPENSSL_free(cipher->type_name); ossl_provider_free(cipher->prov); - CRYPTO_THREAD_lock_free(cipher->lock); + CRYPTO_FREE_REF(&cipher->refcnt); OPENSSL_free(cipher); } @@ -1708,7 +1704,7 @@ void EVP_CIPHER_free(EVP_CIPHER *cipher) if (cipher == NULL || cipher->origin != EVP_ORIG_DYNAMIC) return; - CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock); + CRYPTO_DOWN_REF(&cipher->refcnt, &i); if (i > 0) return; evp_cipher_free_int(cipher); diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index 91f72aa930..bc263b6430 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -852,10 +852,10 @@ EVP_MD *EVP_MD_meth_dup(const EVP_MD *md) return NULL; if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) != NULL) { - CRYPTO_RWLOCK *lock = to->lock; + CRYPTO_REF_COUNT refcnt = to->refcnt; memcpy(to, md, sizeof(*to)); - to->lock = lock; + to->refcnt = refcnt; to->origin = EVP_ORIG_METH; } return to; @@ -865,7 +865,7 @@ void evp_md_free_int(EVP_MD *md) { OPENSSL_free(md->type_name); ossl_provider_free(md->prov); - CRYPTO_THREAD_lock_free(md->lock); + CRYPTO_FREE_REF(&md->refcnt); OPENSSL_free(md); } diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index 759045e5a0..e3a1d7d53c 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -99,7 +99,6 @@ struct evp_keymgmt_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; /* Constructor(s), destructor, information */ OSSL_FUNC_keymgmt_new_fn *new; @@ -141,7 +140,6 @@ struct evp_keyexch_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_keyexch_newctx_fn *newctx; OSSL_FUNC_keyexch_init_fn *init; @@ -161,7 +159,6 @@ struct evp_signature_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_signature_newctx_fn *newctx; OSSL_FUNC_signature_sign_init_fn *sign_init; @@ -196,7 +193,6 @@ struct evp_asym_cipher_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_asym_cipher_newctx_fn *newctx; OSSL_FUNC_asym_cipher_encrypt_init_fn *encrypt_init; @@ -217,7 +213,6 @@ struct evp_kem_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_kem_newctx_fn *newctx; OSSL_FUNC_kem_encapsulate_init_fn *encapsulate_init; diff --git a/crypto/evp/evp_rand.c b/crypto/evp/evp_rand.c index ed7f213bd8..e8dfd32ff7 100644 --- a/crypto/evp/evp_rand.c +++ b/crypto/evp/evp_rand.c @@ -27,7 +27,6 @@ struct evp_rand_st { char *type_name; const char *description; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *refcnt_lock; const OSSL_DISPATCH *dispatch; OSSL_FUNC_rand_newctx_fn *newctx; @@ -55,7 +54,7 @@ static int evp_rand_up_ref(void *vrand) int ref = 0; if (rand != NULL) - return CRYPTO_UP_REF(&rand->refcnt, &ref, rand->refcnt_lock); + return CRYPTO_UP_REF(&rand->refcnt, &ref); return 1; } @@ -66,12 +65,12 @@ static void evp_rand_free(void *vrand) if (rand == NULL) return; - CRYPTO_DOWN_REF(&rand->refcnt, &ref, rand->refcnt_lock); + CRYPTO_DOWN_REF(&rand->refcnt, &ref); if (ref > 0) return; OPENSSL_free(rand->type_name); ossl_provider_free(rand->prov); - CRYPTO_THREAD_lock_free(rand->refcnt_lock); + CRYPTO_FREE_REF(&rand->refcnt); OPENSSL_free(rand); } @@ -79,12 +78,10 @@ static void *evp_rand_new(void) { EVP_RAND *rand = OPENSSL_zalloc(sizeof(*rand)); - if (rand == NULL - || (rand->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL) { + if (rand == NULL || !CRYPTO_NEW_REF(&rand->refcnt, 1)) { OPENSSL_free(rand); return NULL; } - rand->refcnt = 1; return rand; } @@ -324,7 +321,7 @@ int EVP_RAND_CTX_up_ref(EVP_RAND_CTX *ctx) { int ref = 0; - return CRYPTO_UP_REF(&ctx->refcnt, &ref, ctx->refcnt_lock); + return CRYPTO_UP_REF(&ctx->refcnt, &ref); } EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent) @@ -341,15 +338,14 @@ EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent) ctx = OPENSSL_zalloc(sizeof(*ctx)); if (ctx == NULL) return NULL; - if ((ctx->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL) { + if (!CRYPTO_NEW_REF(&ctx->refcnt, 1)) { OPENSSL_free(ctx); - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); return NULL; } if (parent != NULL) { if (!EVP_RAND_CTX_up_ref(parent)) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); - CRYPTO_THREAD_lock_free(ctx->refcnt_lock); + CRYPTO_FREE_REF(&ctx->refcnt); OPENSSL_free(ctx); return NULL; } @@ -361,14 +357,13 @@ EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent) || !EVP_RAND_up_ref(rand)) { ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB); rand->freectx(ctx->algctx); - CRYPTO_THREAD_lock_free(ctx->refcnt_lock); + CRYPTO_FREE_REF(&ctx->refcnt); OPENSSL_free(ctx); EVP_RAND_CTX_free(parent); return NULL; } ctx->meth = rand; ctx->parent = parent; - ctx->refcnt = 1; return ctx; } @@ -380,14 +375,14 @@ void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx) if (ctx == NULL) return; - CRYPTO_DOWN_REF(&ctx->refcnt, &ref, ctx->refcnt_lock); + CRYPTO_DOWN_REF(&ctx->refcnt, &ref); if (ref > 0) return; parent = ctx->parent; ctx->meth->freectx(ctx->algctx); ctx->algctx = NULL; EVP_RAND_free(ctx->meth); - CRYPTO_THREAD_lock_free(ctx->refcnt_lock); + CRYPTO_FREE_REF(&ctx->refcnt); OPENSSL_free(ctx); EVP_RAND_CTX_free(parent); } diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index a9311b2792..195c32cfc9 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -25,15 +25,12 @@ static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov) if (exchange == NULL) return NULL; - exchange->lock = CRYPTO_THREAD_lock_new(); - if (exchange->lock == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); + if (!CRYPTO_NEW_REF(&exchange->refcnt, 1)) { OPENSSL_free(exchange); return NULL; } exchange->prov = prov; ossl_provider_up_ref(prov); - exchange->refcnt = 1; return exchange; } @@ -148,12 +145,12 @@ void EVP_KEYEXCH_free(EVP_KEYEXCH *exchange) if (exchange == NULL) return; - CRYPTO_DOWN_REF(&exchange->refcnt, &i, exchange->lock); + CRYPTO_DOWN_REF(&exchange->refcnt, &i); if (i > 0) return; OPENSSL_free(exchange->type_name); ossl_provider_free(exchange->prov); - CRYPTO_THREAD_lock_free(exchange->lock); + CRYPTO_FREE_REF(&exchange->refcnt); OPENSSL_free(exchange); } @@ -161,7 +158,7 @@ int EVP_KEYEXCH_up_ref(EVP_KEYEXCH *exchange) { int ref = 0; - CRYPTO_UP_REF(&exchange->refcnt, &ref, exchange->lock); + CRYPTO_UP_REF(&exchange->refcnt, &ref); return 1; } diff --git a/crypto/evp/kdf_meth.c b/crypto/evp/kdf_meth.c index b383cc6cdd..c043598d07 100644 --- a/crypto/evp/kdf_meth.c +++ b/crypto/evp/kdf_meth.c @@ -22,7 +22,7 @@ static int evp_kdf_up_ref(void *vkdf) EVP_KDF *kdf = (EVP_KDF *)vkdf; int ref = 0; - CRYPTO_UP_REF(&kdf->refcnt, &ref, kdf->lock); + CRYPTO_UP_REF(&kdf->refcnt, &ref); return 1; } @@ -34,12 +34,12 @@ static void evp_kdf_free(void *vkdf) if (kdf == NULL) return; - CRYPTO_DOWN_REF(&kdf->refcnt, &ref, kdf->lock); + CRYPTO_DOWN_REF(&kdf->refcnt, &ref); if (ref > 0) return; OPENSSL_free(kdf->type_name); ossl_provider_free(kdf->prov); - CRYPTO_THREAD_lock_free(kdf->lock); + CRYPTO_FREE_REF(&kdf->refcnt); OPENSSL_free(kdf); } @@ -48,11 +48,10 @@ static void *evp_kdf_new(void) EVP_KDF *kdf = NULL; if ((kdf = OPENSSL_zalloc(sizeof(*kdf))) == NULL - || (kdf->lock = CRYPTO_THREAD_lock_new()) == NULL) { + || !CRYPTO_NEW_REF(&kdf->refcnt, 1)) { OPENSSL_free(kdf); return NULL; } - kdf->refcnt = 1; return kdf; } diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c index 499978fc55..5491cabd4e 100644 --- a/crypto/evp/kem.c +++ b/crypto/evp/kem.c @@ -278,15 +278,12 @@ static EVP_KEM *evp_kem_new(OSSL_PROVIDER *prov) if (kem == NULL) return NULL; - kem->lock = CRYPTO_THREAD_lock_new(); - if (kem->lock == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); + if (!CRYPTO_NEW_REF(&kem->refcnt, 1)) { OPENSSL_free(kem); return NULL; } kem->prov = prov; ossl_provider_up_ref(prov); - kem->refcnt = 1; return kem; } @@ -428,12 +425,12 @@ void EVP_KEM_free(EVP_KEM *kem) if (kem == NULL) return; - CRYPTO_DOWN_REF(&kem->refcnt, &i, kem->lock); + CRYPTO_DOWN_REF(&kem->refcnt, &i); if (i > 0) return; OPENSSL_free(kem->type_name); ossl_provider_free(kem->prov); - CRYPTO_THREAD_lock_free(kem->lock); + CRYPTO_FREE_REF(&kem->refcnt); OPENSSL_free(kem); } @@ -441,7 +438,7 @@ int EVP_KEM_up_ref(EVP_KEM *kem) { int ref = 0; - CRYPTO_UP_REF(&kem->refcnt, &ref, kem->lock); + CRYPTO_UP_REF(&kem->refcnt, &ref); return 1; } diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index e7ec8ddc47..0f767eaddb 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -23,14 +23,10 @@ static void *keymgmt_new(void) if ((keymgmt = OPENSSL_zalloc(sizeof(*keymgmt))) == NULL) return NULL; - if ((keymgmt->lock = CRYPTO_THREAD_lock_new()) == NULL) { + if (!CRYPTO_NEW_REF(&keymgmt->refcnt, 1)) { EVP_KEYMGMT_free(keymgmt); - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); return NULL; } - - keymgmt->refcnt = 1; - return keymgmt; } @@ -249,7 +245,7 @@ int EVP_KEYMGMT_up_ref(EVP_KEYMGMT *keymgmt) { int ref = 0; - CRYPTO_UP_REF(&keymgmt->refcnt, &ref, keymgmt->lock); + CRYPTO_UP_REF(&keymgmt->refcnt, &ref); return 1; } @@ -260,12 +256,12 @@ void EVP_KEYMGMT_free(EVP_KEYMGMT *keymgmt) if (keymgmt == NULL) return; - CRYPTO_DOWN_REF(&keymgmt->refcnt, &ref, keymgmt->lock); + CRYPTO_DOWN_REF(&keymgmt->refcnt, &ref); if (ref > 0) return; OPENSSL_free(keymgmt->type_name); ossl_provider_free(keymgmt->prov); - CRYPTO_THREAD_lock_free(keymgmt->lock); + CRYPTO_FREE_REF(&keymgmt->refcnt); OPENSSL_free(keymgmt); } diff --git a/crypto/evp/mac_meth.c b/crypto/evp/mac_meth.c index e133548269..a146c4afba 100644 --- a/crypto/evp/mac_meth.c +++ b/crypto/evp/mac_meth.c @@ -21,7 +21,7 @@ static int evp_mac_up_ref(void *vmac) EVP_MAC *mac = vmac; int ref = 0; - CRYPTO_UP_REF(&mac->refcnt, &ref, mac->lock); + CRYPTO_UP_REF(&mac->refcnt, &ref); return 1; } @@ -33,12 +33,12 @@ static void evp_mac_free(void *vmac) if (mac == NULL) return; - CRYPTO_DOWN_REF(&mac->refcnt, &ref, mac->lock); + CRYPTO_DOWN_REF(&mac->refcnt, &ref); if (ref > 0) return; OPENSSL_free(mac->type_name); ossl_provider_free(mac->prov); - CRYPTO_THREAD_lock_free(mac->lock); + CRYPTO_FREE_REF(&mac->refcnt); OPENSSL_free(mac); } @@ -47,13 +47,10 @@ static void *evp_mac_new(void) EVP_MAC *mac = NULL; if ((mac = OPENSSL_zalloc(sizeof(*mac))) == NULL - || (mac->lock = CRYPTO_THREAD_lock_new()) == NULL) { + || !CRYPTO_NEW_REF(&mac->refcnt, 1)) { evp_mac_free(mac); return NULL; } - - mac->refcnt = 1; - return mac; } diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index b26b606505..c3e1ec9627 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -1448,7 +1448,9 @@ EVP_PKEY *EVP_PKEY_new(void) ret->type = EVP_PKEY_NONE; ret->save_type = EVP_PKEY_NONE; - ret->references = 1; + + if (!CRYPTO_NEW_REF(&ret->references, 1)) + goto err; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { @@ -1466,6 +1468,7 @@ EVP_PKEY *EVP_PKEY_new(void) return ret; err: + CRYPTO_FREE_REF(&ret->references); CRYPTO_THREAD_lock_free(ret->lock); OPENSSL_free(ret); return NULL; @@ -1655,7 +1658,7 @@ int EVP_PKEY_up_ref(EVP_PKEY *pkey) { int i; - if (CRYPTO_UP_REF(&pkey->references, &i, pkey->lock) <= 0) + if (CRYPTO_UP_REF(&pkey->references, &i) <= 0) return 0; REF_PRINT_COUNT("EVP_PKEY", pkey); @@ -1778,7 +1781,7 @@ void EVP_PKEY_free(EVP_PKEY *x) if (x == NULL) return; - CRYPTO_DOWN_REF(&x->references, &i, x->lock); + CRYPTO_DOWN_REF(&x->references, &i); REF_PRINT_COUNT("EVP_PKEY", x); if (i > 0) return; @@ -1788,6 +1791,7 @@ void EVP_PKEY_free(EVP_PKEY *x) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, x, &x->ex_data); #endif CRYPTO_THREAD_lock_free(x->lock); + CRYPTO_FREE_REF(&x->references); #ifndef FIPS_MODULE sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); #endif diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index f035a422ca..0596a2b337 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -25,15 +25,13 @@ static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov) if (signature == NULL) return NULL; - signature->lock = CRYPTO_THREAD_lock_new(); - if (signature->lock == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_CRYPTO_LIB); + if (!CRYPTO_NEW_REF(&signature->refcnt, 1)) { OPENSSL_free(signature); return NULL; } + signature->prov = prov; ossl_provider_up_ref(prov); - signature->refcnt = 1; return signature; } @@ -281,12 +279,12 @@ void EVP_SIGNATURE_free(EVP_SIGNATURE *signature) if (signature == NULL) return; - CRYPTO_DOWN_REF(&signature->refcnt, &i, signature->lock); + CRYPTO_DOWN_REF(&signature->refcnt, &i); if (i > 0) return; OPENSSL_free(signature->type_name); ossl_provider_free(signature->prov); - CRYPTO_THREAD_lock_free(signature->lock); + CRYPTO_FREE_REF(&signature->refcnt); OPENSSL_free(signature); } @@ -294,7 +292,7 @@ int EVP_SIGNATURE_up_ref(EVP_SIGNATURE *signature) { int ref = 0; - CRYPTO_UP_REF(&signature->refcnt, &ref, signature->lock); + CRYPTO_UP_REF(&signature->refcnt, &ref); return 1; } diff --git a/include/crypto/evp.h b/include/crypto/evp.h index 30c5aa2b1d..76ccacfd8d 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -204,7 +204,6 @@ struct evp_mac_st { const char *description; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_mac_newctx_fn *newctx; OSSL_FUNC_mac_dupctx_fn *dupctx; @@ -226,7 +225,6 @@ struct evp_kdf_st { char *type_name; const char *description; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_kdf_newctx_fn *newctx; OSSL_FUNC_kdf_dupctx_fn *dupctx; @@ -271,7 +269,6 @@ struct evp_md_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_digest_newctx_fn *newctx; OSSL_FUNC_digest_init_fn *dinit; OSSL_FUNC_digest_update_fn *dupdate; @@ -327,7 +324,6 @@ struct evp_cipher_st { const char *description; OSSL_PROVIDER *prov; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; OSSL_FUNC_cipher_newctx_fn *newctx; OSSL_FUNC_cipher_encrypt_init_fn *einit; OSSL_FUNC_cipher_decrypt_init_fn *dinit; |