if (r == NULL)
return;
- i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC);
+ CRYPTO_atomic_add(&r->references, -1, &i, r->lock);
REF_PRINT_COUNT("EC_KEY", r);
if (i > 0)
return;
r->group->meth->keyfinish(r);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);
+ CRYPTO_THREAD_lock_free(r->lock);
EC_GROUP_free(r->group);
EC_POINT_free(r->pub_key);
BN_clear_free(r->priv_key);
if (ret == NULL)
return NULL;
+
if (EC_KEY_copy(ret, ec_key) == NULL) {
EC_KEY_free(ret);
return NULL;
int EC_KEY_up_ref(EC_KEY *r)
{
- int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
+ int i;
+
+ if (CRYPTO_atomic_add(&r->references, 1, &i, r->lock) <= 0)
+ return 0;
REF_PRINT_COUNT("EC_KEY", r);
REF_ASSERT_ISNT(i < 2);
if (ret == NULL) {
ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);
- return (NULL);
+ return NULL;
}
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {
OPENSSL_free(ret);
return NULL;
}
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data);
+ OPENSSL_free(ret);
+ return NULL;
+ }
+
ret->meth = EC_KEY_get_default_method();
#ifndef OPENSSL_NO_ENGINE
if (engine != NULL) {
if (!ENGINE_init(engine)) {
ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data);
OPENSSL_free(ret);
return NULL;
}
if (ret->meth == NULL) {
ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data);
OPENSSL_free(ret);
return NULL;
}
ret->version = 1;
ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
ret->references = 1;
+
if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
EC_KEY_free(ret);
return NULL;
int references;
int flags;
CRYPTO_EX_DATA ex_data;
+ CRYPTO_RWLOCK *lock;
} /* EC_KEY */ ;
struct ec_point_st {
#include <string.h>
#include <openssl/err.h>
+#include "internal/cryptlib.h"
#include "internal/bn_int.h"
#include "ec_lcl.h"
* objects followed by a NULL */
size_t num; /* numblocks * 2^(w-1) */
int references;
+ CRYPTO_RWLOCK *lock;
};
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group)
ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
return ret;
}
+
ret->group = group;
ret->blocksize = 8; /* default */
ret->w = 4; /* default */
ret->references = 1;
+
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
return ret;
}
EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *pre)
{
+ int i;
if (pre != NULL)
- CRYPTO_add(&pre->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ CRYPTO_atomic_add(&pre->references, 1, &i, pre->lock);
return pre;
}
void EC_ec_pre_comp_free(EC_PRE_COMP *pre)
{
- if (pre == NULL
- || CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
+ int i;
+
+ if (pre == NULL)
+ return;
+
+ CRYPTO_atomic_add(&pre->references, -1, &i, pre->lock);
+ REF_PRINT_COUNT("EC_ec", pre);
+ if (i > 0)
return;
+ REF_ASSERT_ISNT(i < 0);
if (pre->points != NULL) {
EC_POINT **pts;
EC_POINT_free(*pts);
OPENSSL_free(pre->points);
}
+ CRYPTO_THREAD_lock_free(pre->lock);
OPENSSL_free(pre);
}
struct nistp224_pre_comp_st {
felem g_pre_comp[2][16][3];
int references;
+ CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp224_method(void)
ECerr(EC_F_NISTP224_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
return ret;
}
+
ret->references = 1;
+
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_NISTP224_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
return ret;
}
NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *p)
{
+ int i;
if (p != NULL)
- CRYPTO_add(&p->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ CRYPTO_atomic_add(&p->references, 1, &i, p->lock);
return p;
}
void EC_nistp224_pre_comp_free(NISTP224_PRE_COMP *p)
{
- if (p == NULL
- || CRYPTO_add(&p->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
+ int i;
+
+ if (p == NULL)
+ return;
+
+ CRYPTO_atomic_add(&p->references, -1, &i, p->lock);
+ REF_PRINT_COUNT("EC_nistp224", x);
+ if (i > 0)
return;
+ REF_ASSERT_ISNT(i < 0);
+
+ CRYPTO_THREAD_lock_free(p->lock);
OPENSSL_free(p);
}
struct nistp256_pre_comp_st {
smallfelem g_pre_comp[2][16][3];
int references;
+ CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp256_method(void)
}
ret->references = 1;
+
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_NISTP256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
return ret;
}
NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *p)
{
+ int i;
if (p != NULL)
- CRYPTO_add(&p->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ CRYPTO_atomic_add(&p->references, 1, &i, p->lock);
return p;
}
void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *pre)
{
- if (pre == NULL
- || CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
+ int i;
+
+ if (pre == NULL)
return;
+
+ CRYPTO_atomic_add(&pre->references, -1, &i, pre->lock);
+ REF_PRINT_COUNT("EC_nistp256", x);
+ if (i > 0)
+ return;
+ REF_ASSERT_ISNT(i < 0);
+
+ CRYPTO_THREAD_lock_free(pre->lock);
OPENSSL_free(pre);
}
struct nistp521_pre_comp_st {
felem g_pre_comp[16][3];
int references;
+ CRYPTO_RWLOCK *lock;
};
const EC_METHOD *EC_GFp_nistp521_method(void)
ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
return ret;
}
+
ret->references = 1;
+
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
return ret;
}
NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *p)
{
+ int i;
if (p != NULL)
- CRYPTO_add(&p->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ CRYPTO_atomic_add(&p->references, 1, &i, p->lock);
return p;
}
void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *p)
{
- if (p == NULL
- || CRYPTO_add(&p->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
+ int i;
+
+ if (p == NULL)
+ return;
+
+ CRYPTO_atomic_add(&p->references, -1, &i, p->lock);
+ REF_PRINT_COUNT("EC_nistp521", x);
+ if (i > 0)
return;
+ REF_ASSERT_ISNT(i < 0);
+
+ CRYPTO_THREAD_lock_free(p->lock);
OPENSSL_free(p);
}
PRECOMP256_ROW *precomp;
void *precomp_storage;
int references;
+ CRYPTO_RWLOCK *lock;
};
/* Functions implemented in assembly */
ret->group = group;
ret->w = 6; /* default */
ret->references = 1;
+
+ ret->lock = CRYPTO_THREAD_lock_new();
+ if (ret->lock == NULL) {
+ ECerr(EC_F_ECP_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(ret);
+ return NULL;
+ }
return ret;
}
NISTZ256_PRE_COMP *EC_nistz256_pre_comp_dup(NISTZ256_PRE_COMP *p)
{
+ int i;
if (p != NULL)
- CRYPTO_add(&p->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ CRYPTO_atomic_add(&p->references, 1, &i, p->lock);
return p;
}
void EC_nistz256_pre_comp_free(NISTZ256_PRE_COMP *pre)
{
- if (pre == NULL
- || CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
+ int i;
+
+ if (pre == NULL)
return;
+
+ CRYPTO_atomic_add(&pre->references, -1, &i, pre->lock);
+ REF_PRINT_COUNT("EC_nistz256", x);
+ if (i > 0)
+ return;
+ REF_ASSERT_ISNT(i < 0);
+
OPENSSL_free(pre->precomp_storage);
+ CRYPTO_THREAD_lock_free(pre->lock);
OPENSSL_free(pre);
}
# define CRYPTO_LOCK_ENGINE 30
# define CRYPTO_LOCK_UI 31
# define CRYPTO_LOCK_ECDSA 32
-# define CRYPTO_LOCK_EC 33
# define CRYPTO_LOCK_ECDH 34
# define CRYPTO_LOCK_BN 35
-# define CRYPTO_LOCK_EC_PRE_COMP 36
# define CRYPTO_LOCK_STORE 37
# define CRYPTO_LOCK_COMP 38
# define CRYPTO_LOCK_FIPS 39