summaryrefslogtreecommitdiffstats
path: root/crypto/ec/ecp_nistp256.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ec/ecp_nistp256.c')
-rw-r--r--crypto/ec/ecp_nistp256.c70
1 files changed, 16 insertions, 54 deletions
diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c
index 48ed2c452e..26c1693778 100644
--- a/crypto/ec/ecp_nistp256.c
+++ b/crypto/ec/ecp_nistp256.c
@@ -1756,10 +1756,10 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
}
/* Precomputation for the group generator. */
-typedef struct {
+struct nistp256_pre_comp_st {
smallfelem g_pre_comp[2][16][3];
int references;
-} NISTP256_PRE_COMP;
+};
const EC_METHOD *EC_GFp_nistp256_method(void)
{
@@ -1826,46 +1826,21 @@ static NISTP256_PRE_COMP *nistp256_pre_comp_new()
return ret;
}
-static void *nistp256_pre_comp_dup(void *src_)
+NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *p)
{
- NISTP256_PRE_COMP *src = src_;
-
- /* no need to actually copy, these objects never change! */
- CRYPTO_add(&src->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
-
- return src_;
+ if (p != NULL)
+ CRYPTO_add(&p->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
+ return p;
}
-static void nistp256_pre_comp_free(void *pre_)
+void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *pre)
{
- int i;
- NISTP256_PRE_COMP *pre = pre_;
-
- if (!pre)
- return;
-
- i = CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP);
- if (i > 0)
+ if (pre == NULL
+ || CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
return;
-
OPENSSL_free(pre);
}
-static void nistp256_pre_comp_clear_free(void *pre_)
-{
- int i;
- NISTP256_PRE_COMP *pre = pre_;
-
- if (!pre)
- return;
-
- i = CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP);
- if (i > 0)
- return;
-
- OPENSSL_clear_free(pre, sizeof(*pre));
-}
-
/******************************************************************************/
/*
* OPENSSL EC_METHOD FUNCTIONS
@@ -2031,10 +2006,7 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
goto err;
if (scalar != NULL) {
- pre = EC_EX_DATA_get_data(group->extra_data,
- nistp256_pre_comp_dup,
- nistp256_pre_comp_free,
- nistp256_pre_comp_clear_free);
+ pre = group->pre_comp.nistp256;
if (pre)
/* we have precomputation, try to use it */
g_pre_comp = (const smallfelem(*)[16][3])pre->g_pre_comp;
@@ -2212,9 +2184,7 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
felem x_tmp, y_tmp, z_tmp;
/* throw away old precomputation */
- EC_EX_DATA_free_data(&group->extra_data, nistp256_pre_comp_dup,
- nistp256_pre_comp_free,
- nistp256_pre_comp_clear_free);
+ EC_nistp256_pre_comp_free(group->pre_comp.nistp256);
if (ctx == NULL)
if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0;
@@ -2326,29 +2296,21 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
}
make_points_affine(31, &(pre->g_pre_comp[0][1]), tmp_smallfelems);
- if (!EC_EX_DATA_set_data(&group->extra_data, pre, nistp256_pre_comp_dup,
- nistp256_pre_comp_free,
- nistp256_pre_comp_clear_free))
- goto err;
- ret = 1;
+ SETPRECOMP(group, nistp256, pre);
pre = NULL;
+ ret = 1;
+
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
BN_CTX_free(new_ctx);
- nistp256_pre_comp_free(pre);
+ EC_nistp256_pre_comp_free(pre);
return ret;
}
int ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group)
{
- if (EC_EX_DATA_get_data(group->extra_data, nistp256_pre_comp_dup,
- nistp256_pre_comp_free,
- nistp256_pre_comp_clear_free)
- != NULL)
- return 1;
- else
- return 0;
+ return HAVEPRECOMP(group, nistp256);
}
#else
static void *dummy = &dummy;