From: Pauli Date: Wed, 21 Jun 2023 23:43:01 +0000 (+1000) Subject: prov(legacy): update to structure based atomics X-Git-Tag: openssl-3.2.0-alpha1~545 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7599d17d9385a7fd7489b81dfe560d319931f125;p=thirdparty%2Fopenssl.git prov(legacy): update to structure based atomics Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21260) --- diff --git a/providers/implementations/include/prov/kdfexchange.h b/providers/implementations/include/prov/kdfexchange.h index bfedd3afd36..8d95a99438d 100644 --- a/providers/implementations/include/prov/kdfexchange.h +++ b/providers/implementations/include/prov/kdfexchange.h @@ -14,7 +14,6 @@ struct kdf_data_st { OSSL_LIB_CTX *libctx; CRYPTO_REF_COUNT refcnt; - CRYPTO_RWLOCK *lock; }; typedef struct kdf_data_st KDF_DATA; diff --git a/providers/implementations/include/prov/macsignature.h b/providers/implementations/include/prov/macsignature.h index 9bfaaf9b6e6..45a50c36f25 100644 --- a/providers/implementations/include/prov/macsignature.h +++ b/providers/implementations/include/prov/macsignature.h @@ -13,7 +13,6 @@ #include "prov/provider_util.h" struct mac_key_st { - CRYPTO_RWLOCK *lock; OSSL_LIB_CTX *libctx; CRYPTO_REF_COUNT refcnt; unsigned char *priv_key; diff --git a/providers/implementations/keymgmt/kdf_legacy_kmgmt.c b/providers/implementations/keymgmt/kdf_legacy_kmgmt.c index 40885ee0190..a2303f2e193 100644 --- a/providers/implementations/keymgmt/kdf_legacy_kmgmt.c +++ b/providers/implementations/keymgmt/kdf_legacy_kmgmt.c @@ -37,13 +37,11 @@ KDF_DATA *ossl_kdf_data_new(void *provctx) if (kdfdata == NULL) return NULL; - kdfdata->lock = CRYPTO_THREAD_lock_new(); - if (kdfdata->lock == NULL) { + if (!CRYPTO_NEW_REF(&kdfdata->refcnt, 1)) { OPENSSL_free(kdfdata); return NULL; } kdfdata->libctx = PROV_LIBCTX_OF(provctx); - kdfdata->refcnt = 1; return kdfdata; } @@ -55,11 +53,11 @@ void ossl_kdf_data_free(KDF_DATA *kdfdata) if (kdfdata == NULL) return; - CRYPTO_DOWN_REF(&kdfdata->refcnt, &ref, kdfdata->lock); + CRYPTO_DOWN_REF(&kdfdata->refcnt, &ref); if (ref > 0) return; - CRYPTO_THREAD_lock_free(kdfdata->lock); + CRYPTO_FREE_REF(&kdfdata->refcnt); OPENSSL_free(kdfdata); } @@ -77,7 +75,7 @@ int ossl_kdf_data_up_ref(KDF_DATA *kdfdata) if (!ossl_prov_is_running()) return 0; - CRYPTO_UP_REF(&kdfdata->refcnt, &ref, kdfdata->lock); + CRYPTO_UP_REF(&kdfdata->refcnt, &ref); return 1; } diff --git a/providers/implementations/keymgmt/mac_legacy_kmgmt.c b/providers/implementations/keymgmt/mac_legacy_kmgmt.c index 114d9e9fe97..babeba748da 100644 --- a/providers/implementations/keymgmt/mac_legacy_kmgmt.c +++ b/providers/implementations/keymgmt/mac_legacy_kmgmt.c @@ -72,13 +72,11 @@ MAC_KEY *ossl_mac_key_new(OSSL_LIB_CTX *libctx, int cmac) if (mackey == NULL) return NULL; - mackey->lock = CRYPTO_THREAD_lock_new(); - if (mackey->lock == NULL) { + if (!CRYPTO_NEW_REF(&mackey->refcnt, 1)) { OPENSSL_free(mackey); return NULL; } mackey->libctx = libctx; - mackey->refcnt = 1; mackey->cmac = cmac; return mackey; @@ -91,14 +89,14 @@ void ossl_mac_key_free(MAC_KEY *mackey) if (mackey == NULL) return; - CRYPTO_DOWN_REF(&mackey->refcnt, &ref, mackey->lock); + CRYPTO_DOWN_REF(&mackey->refcnt, &ref); if (ref > 0) return; OPENSSL_secure_clear_free(mackey->priv_key, mackey->priv_key_len); OPENSSL_free(mackey->properties); ossl_prov_cipher_reset(&mackey->cipher); - CRYPTO_THREAD_lock_free(mackey->lock); + CRYPTO_FREE_REF(&mackey->refcnt); OPENSSL_free(mackey); } @@ -116,7 +114,7 @@ int ossl_mac_key_up_ref(MAC_KEY *mackey) if (!ossl_prov_is_running()) return 0; - CRYPTO_UP_REF(&mackey->refcnt, &ref, mackey->lock); + CRYPTO_UP_REF(&mackey->refcnt, &ref); return 1; }