summaryrefslogtreecommitdiffstats
path: root/crypto/evp/evp_rand.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-06-22 09:48:49 +1000
committerPauli <pauli@openssl.org>2023-07-01 21:18:25 +1000
commit6be83ac172aac93b49ae0b847fd5ac9de6ab3ff5 (patch)
tree87100def56be88bd30b7ad3d74ab9959c9258d7a /crypto/evp/evp_rand.c
parenta903a132a4256d34f20cb2f7636247b41fd85965 (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)
Diffstat (limited to 'crypto/evp/evp_rand.c')
-rw-r--r--crypto/evp/evp_rand.c25
1 files changed, 10 insertions, 15 deletions
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);
}