From 7599d17d9385a7fd7489b81dfe560d319931f125 Mon Sep 17 00:00:00 2001 From: Pauli Date: Thu, 22 Jun 2023 09:43:01 +1000 Subject: prov(legacy): update to structure based atomics Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21260) --- providers/implementations/include/prov/kdfexchange.h | 1 - providers/implementations/include/prov/macsignature.h | 1 - providers/implementations/keymgmt/kdf_legacy_kmgmt.c | 10 ++++------ providers/implementations/keymgmt/mac_legacy_kmgmt.c | 10 ++++------ 4 files changed, 8 insertions(+), 14 deletions(-) (limited to 'providers') diff --git a/providers/implementations/include/prov/kdfexchange.h b/providers/implementations/include/prov/kdfexchange.h index bfedd3afd3..8d95a99438 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 9bfaaf9b6e..45a50c36f2 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 40885ee019..a2303f2e19 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 114d9e9fe9..babeba748d 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; } -- cgit v1.2.3