From 97937cfcd8b5a011dd54e74eb2cc3cc26a533b10 Mon Sep 17 00:00:00 2001 From: Pauli Date: Thu, 22 Jun 2023 09:35:12 +1000 Subject: [PATCH] rsa: update to structure based atomics Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21260) --- crypto/rsa/rsa_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index fa3561c33f..c591b8941d 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -79,7 +79,6 @@ static RSA *rsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx) if (ret == NULL) return NULL; - ret->references = 1; ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { ERR_raise(ERR_LIB_RSA, ERR_R_CRYPTO_LIB); @@ -87,6 +86,9 @@ static RSA *rsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx) return NULL; } + if (!CRYPTO_NEW_REF(&ret->references, 1)) + goto err; + ret->libctx = libctx; ret->meth = RSA_get_default_method(); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) @@ -135,7 +137,7 @@ void RSA_free(RSA *r) if (r == NULL) return; - CRYPTO_DOWN_REF(&r->references, &i, r->lock); + CRYPTO_DOWN_REF(&r->references, &i); REF_PRINT_COUNT("RSA", r); if (i > 0) return; @@ -152,6 +154,7 @@ void RSA_free(RSA *r) #endif CRYPTO_THREAD_lock_free(r->lock); + CRYPTO_FREE_REF(&r->references); BN_free(r->n); BN_free(r->e); @@ -179,7 +182,7 @@ int RSA_up_ref(RSA *r) { int i; - if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0) + if (CRYPTO_UP_REF(&r->references, &i) <= 0) return 0; REF_PRINT_COUNT("RSA", r);