summaryrefslogtreecommitdiffstats
path: root/crypto/ec
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-06-22 09:32:45 +1000
committerPauli <pauli@openssl.org>2023-07-01 21:18:25 +1000
commit1353736b3e6f33a9f6e47f837c5de05cc0dd3647 (patch)
tree686c7d45b4981bcc882c8ca856ae35bfc441be77 /crypto/ec
parent420ad86a0e35ddbd65dae7e9458e36223af5f140 (diff)
ec: 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/ec')
-rw-r--r--crypto/ec/ec_key.c6
-rw-r--r--crypto/ec/ec_kmeth.c7
-rw-r--r--crypto/ec/ec_local.h1
-rw-r--r--crypto/ec/ec_mult.c12
-rw-r--r--crypto/ec/ecp_nistp224.c12
-rw-r--r--crypto/ec/ecp_nistp256.c13
-rw-r--r--crypto/ec/ecp_nistp521.c13
-rw-r--r--crypto/ec/ecp_nistz256.c12
8 files changed, 25 insertions, 51 deletions
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 58b283dd8c..e428b45d4a 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -75,7 +75,7 @@ void EC_KEY_free(EC_KEY *r)
if (r == NULL)
return;
- CRYPTO_DOWN_REF(&r->references, &i, r->lock);
+ CRYPTO_DOWN_REF(&r->references, &i);
REF_PRINT_COUNT("EC_KEY", r);
if (i > 0)
return;
@@ -94,7 +94,7 @@ void EC_KEY_free(EC_KEY *r)
#ifndef FIPS_MODULE
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);
#endif
- CRYPTO_THREAD_lock_free(r->lock);
+ CRYPTO_FREE_REF(&r->references);
EC_GROUP_free(r->group);
EC_POINT_free(r->pub_key);
BN_clear_free(r->priv_key);
@@ -194,7 +194,7 @@ int EC_KEY_up_ref(EC_KEY *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("EC_KEY", r);
diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c
index eca531d2b3..ec68ab154e 100644
--- a/crypto/ec/ec_kmeth.c
+++ b/crypto/ec/ec_kmeth.c
@@ -93,12 +93,8 @@ EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
goto err;
}
- ret->references = 1;
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1))
goto err;
- }
ret->meth = EC_KEY_get_default_method();
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
@@ -137,6 +133,7 @@ EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq,
return ret;
err:
+ CRYPTO_FREE_REF(&ret->references);
EC_KEY_free(ret);
return NULL;
}
diff --git a/crypto/ec/ec_local.h b/crypto/ec/ec_local.h
index 4786f687a4..92d2b6f570 100644
--- a/crypto/ec/ec_local.h
+++ b/crypto/ec/ec_local.h
@@ -298,7 +298,6 @@ struct ec_key_st {
#ifndef FIPS_MODULE
CRYPTO_EX_DATA ex_data;
#endif
- CRYPTO_RWLOCK *lock;
OSSL_LIB_CTX *libctx;
char *propq;
diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c
index a913c1e786..2317fc0ab5 100644
--- a/crypto/ec/ec_mult.c
+++ b/crypto/ec/ec_mult.c
@@ -45,7 +45,6 @@ struct ec_pre_comp_st {
* objects followed by a NULL */
size_t num; /* numblocks * 2^(w-1) */
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group)
@@ -62,11 +61,8 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group)
ret->group = group;
ret->blocksize = 8; /* default */
ret->w = 4; /* default */
- ret->references = 1;
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
OPENSSL_free(ret);
return NULL;
}
@@ -77,7 +73,7 @@ EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre)
{
int i;
if (pre != NULL)
- CRYPTO_UP_REF(&pre->references, &i, pre->lock);
+ CRYPTO_UP_REF(&pre->references, &i);
return pre;
}
@@ -88,7 +84,7 @@ void EC_ec_pre_comp_free(EC_PRE_COMP *pre)
if (pre == NULL)
return;
- CRYPTO_DOWN_REF(&pre->references, &i, pre->lock);
+ CRYPTO_DOWN_REF(&pre->references, &i);
REF_PRINT_COUNT("EC_ec", pre);
if (i > 0)
return;
@@ -101,7 +97,7 @@ void EC_ec_pre_comp_free(EC_PRE_COMP *pre)
EC_POINT_free(*pts);
OPENSSL_free(pre->points);
}
- CRYPTO_THREAD_lock_free(pre->lock);
+ CRYPTO_FREE_REF(&pre->references);
OPENSSL_free(pre);
}
diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c
index 6c9f9095b6..6c55724689 100644
--- a/crypto/ec/ecp_nistp224.c
+++ b/crypto/ec/ecp_nistp224.c
@@ -238,7 +238,6 @@ static const felem gmul[2][16][3] = {
struct nistp224_pre_comp_st {
felem g_pre_comp[2][16][3];
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp224_method(void)
@@ -1241,11 +1240,8 @@ static NISTP224_PRE_COMP *nistp224_pre_comp_new(void)
if (ret == NULL)
return ret;
- ret->references = 1;
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
OPENSSL_free(ret);
return NULL;
}
@@ -1256,7 +1252,7 @@ NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *p)
{
int i;
if (p != NULL)
- CRYPTO_UP_REF(&p->references, &i, p->lock);
+ CRYPTO_UP_REF(&p->references, &i);
return p;
}
@@ -1267,13 +1263,13 @@ void EC_nistp224_pre_comp_free(NISTP224_PRE_COMP *p)
if (p == NULL)
return;
- CRYPTO_DOWN_REF(&p->references, &i, p->lock);
+ CRYPTO_DOWN_REF(&p->references, &i);
REF_PRINT_COUNT("EC_nistp224", p);
if (i > 0)
return;
REF_ASSERT_ISNT(i < 0);
- CRYPTO_THREAD_lock_free(p->lock);
+ CRYPTO_FREE_REF(&p->references);
OPENSSL_free(p);
}
diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c
index 10b0fee7ec..b20107a5fa 100644
--- a/crypto/ec/ecp_nistp256.c
+++ b/crypto/ec/ecp_nistp256.c
@@ -1773,7 +1773,6 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
struct nistp256_pre_comp_st {
smallfelem g_pre_comp[2][16][3];
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp256_method(void)
@@ -1852,11 +1851,7 @@ static NISTP256_PRE_COMP *nistp256_pre_comp_new(void)
if (ret == NULL)
return ret;
- ret->references = 1;
-
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
OPENSSL_free(ret);
return NULL;
}
@@ -1867,7 +1862,7 @@ NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *p)
{
int i;
if (p != NULL)
- CRYPTO_UP_REF(&p->references, &i, p->lock);
+ CRYPTO_UP_REF(&p->references, &i);
return p;
}
@@ -1878,13 +1873,13 @@ void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *pre)
if (pre == NULL)
return;
- CRYPTO_DOWN_REF(&pre->references, &i, pre->lock);
+ CRYPTO_DOWN_REF(&pre->references, &i);
REF_PRINT_COUNT("EC_nistp256", pre);
if (i > 0)
return;
REF_ASSERT_ISNT(i < 0);
- CRYPTO_THREAD_lock_free(pre->lock);
+ CRYPTO_FREE_REF(&pre->references);
OPENSSL_free(pre);
}
diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c
index 388ccd06cf..97815cac1f 100644
--- a/crypto/ec/ecp_nistp521.c
+++ b/crypto/ec/ecp_nistp521.c
@@ -1665,7 +1665,6 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
struct nistp521_pre_comp_st {
felem g_pre_comp[16][3];
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp521_method(void)
@@ -1744,11 +1743,7 @@ static NISTP521_PRE_COMP *nistp521_pre_comp_new(void)
if (ret == NULL)
return ret;
- ret->references = 1;
-
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
OPENSSL_free(ret);
return NULL;
}
@@ -1759,7 +1754,7 @@ NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *p)
{
int i;
if (p != NULL)
- CRYPTO_UP_REF(&p->references, &i, p->lock);
+ CRYPTO_UP_REF(&p->references, &i);
return p;
}
@@ -1770,13 +1765,13 @@ void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *p)
if (p == NULL)
return;
- CRYPTO_DOWN_REF(&p->references, &i, p->lock);
+ CRYPTO_DOWN_REF(&p->references, &i);
REF_PRINT_COUNT("EC_nistp521", p);
if (i > 0)
return;
REF_ASSERT_ISNT(i < 0);
- CRYPTO_THREAD_lock_free(p->lock);
+ CRYPTO_FREE_REF(&p->references);
OPENSSL_free(p);
}
diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c
index bbf9deec4d..44d9054a17 100644
--- a/crypto/ec/ecp_nistz256.c
+++ b/crypto/ec/ecp_nistz256.c
@@ -75,7 +75,6 @@ struct nistz256_pre_comp_st {
PRECOMP256_ROW *precomp;
void *precomp_storage;
CRYPTO_REF_COUNT references;
- CRYPTO_RWLOCK *lock;
};
/* Functions implemented in assembly */
@@ -1223,11 +1222,8 @@ static NISTZ256_PRE_COMP *ecp_nistz256_pre_comp_new(const EC_GROUP *group)
ret->group = group;
ret->w = 6; /* default */
- ret->references = 1;
- ret->lock = CRYPTO_THREAD_lock_new();
- if (ret->lock == NULL) {
- ERR_raise(ERR_LIB_EC, ERR_R_CRYPTO_LIB);
+ if (!CRYPTO_NEW_REF(&ret->references, 1)) {
OPENSSL_free(ret);
return NULL;
}
@@ -1238,7 +1234,7 @@ NISTZ256_PRE_COMP *EC_nistz256_pre_comp_dup(NISTZ256_PRE_COMP *p)
{
int i;
if (p != NULL)
- CRYPTO_UP_REF(&p->references, &i, p->lock);
+ CRYPTO_UP_REF(&p->references, &i);
return p;
}
@@ -1249,14 +1245,14 @@ void EC_nistz256_pre_comp_free(NISTZ256_PRE_COMP *pre)
if (pre == NULL)
return;
- CRYPTO_DOWN_REF(&pre->references, &i, pre->lock);
+ CRYPTO_DOWN_REF(&pre->references, &i);
REF_PRINT_COUNT("EC_nistz256", pre);
if (i > 0)
return;
REF_ASSERT_ISNT(i < 0);
OPENSSL_free(pre->precomp_storage);
- CRYPTO_THREAD_lock_free(pre->lock);
+ CRYPTO_FREE_REF(&pre->references);
OPENSSL_free(pre);
}