Skip to content

Commit

Permalink
rsa: update to structure based atomics
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #21260)
  • Loading branch information
paulidale committed Jul 1, 2023
1 parent 8752694 commit 97937cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crypto/rsa/rsa_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ 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);
OPENSSL_free(ret);
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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 97937cf

Please sign in to comment.