summaryrefslogtreecommitdiffstats
path: root/crypto/ec/ecp_nistp521.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2016-01-05 13:06:03 -0500
committerRich Salz <rsalz@openssl.org>2016-01-13 14:32:59 -0500
commit3aef36ffef89849348049296892327e6fdf9d705 (patch)
treea8a89aedef46029fcd855e4d9ad1d19c279b8483 /crypto/ec/ecp_nistp521.c
parent8ffcca65861520fb95e4603b2cb80b3028e56baa (diff)
Add CRYPTO_EX_DATA; remove EC_EXTRA_DATA
Add CRYPTO_EX_DATA add EndC_KEY_[gs]et_method, From Roumen Petrov. Had to add various exdata calls to init/copy/free the exdata. Had to remove const from some EC functions because exdata isn't const-correct. :( Also remove EC_EXTRA_DATA and use a union to hold the possible pre-computed values and an enum to tell which value is in the union. (Rich Salz) Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
Diffstat (limited to 'crypto/ec/ecp_nistp521.c')
-rw-r--r--crypto/ec/ecp_nistp521.c69
1 files changed, 15 insertions, 54 deletions
diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c
index dd5b19b581..97744b273e 100644
--- a/crypto/ec/ecp_nistp521.c
+++ b/crypto/ec/ecp_nistp521.c
@@ -1585,10 +1585,10 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
}
/* Precomputation for the group generator. */
-typedef struct {
+struct nistp512_pre_comp_st {
felem g_pre_comp[16][3];
int references;
-} NISTP521_PRE_COMP;
+};
const EC_METHOD *EC_GFp_nistp521_method(void)
{
@@ -1654,44 +1654,19 @@ static NISTP521_PRE_COMP *nistp521_pre_comp_new()
return ret;
}
-static void *nistp521_pre_comp_dup(void *src_)
+NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *p)
{
- NISTP521_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 nistp521_pre_comp_free(void *pre_)
+void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *p)
{
- int i;
- NISTP521_PRE_COMP *pre = pre_;
-
- if (!pre)
+ if (p == NULL
+ || CRYPTO_add(&p->references, -1, CRYPTO_LOCK_EC_PRE_COMP) > 0)
return;
-
- i = CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP);
- if (i > 0)
- return;
-
- OPENSSL_free(pre);
-}
-
-static void nistp521_pre_comp_clear_free(void *pre_)
-{
- int i;
- NISTP521_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_free(p);
}
/******************************************************************************/
@@ -1858,10 +1833,7 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
goto err;
if (scalar != NULL) {
- pre = EC_EX_DATA_get_data(group->extra_data,
- nistp521_pre_comp_dup,
- nistp521_pre_comp_free,
- nistp521_pre_comp_clear_free);
+ pre = group->pre_comp.nistp521;
if (pre)
/* we have precomputation, try to use it */
g_pre_comp = &pre->g_pre_comp[0];
@@ -2036,9 +2008,7 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
felem tmp_felems[16];
/* throw away old precomputation */
- EC_EX_DATA_free_data(&group->extra_data, nistp521_pre_comp_dup,
- nistp521_pre_comp_free,
- nistp521_pre_comp_clear_free);
+ EC_nistp521_pre_comp_free(group->pre_comp.nistp521);
if (ctx == NULL)
if ((ctx = new_ctx = BN_CTX_new()) == NULL)
return 0;
@@ -2121,29 +2091,20 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
}
make_points_affine(15, &(pre->g_pre_comp[1]), tmp_felems);
- if (!EC_EX_DATA_set_data(&group->extra_data, pre, nistp521_pre_comp_dup,
- nistp521_pre_comp_free,
- nistp521_pre_comp_clear_free))
- goto err;
+ SETPRECOMP(group, nistp521, pre);
ret = 1;
pre = NULL;
err:
BN_CTX_end(ctx);
EC_POINT_free(generator);
BN_CTX_free(new_ctx);
- nistp521_pre_comp_free(pre);
+ EC_nistp521_pre_comp_free(pre);
return ret;
}
int ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group)
{
- if (EC_EX_DATA_get_data(group->extra_data, nistp521_pre_comp_dup,
- nistp521_pre_comp_free,
- nistp521_pre_comp_clear_free)
- != NULL)
- return 1;
- else
- return 0;
+ return HAVEPRECOMP(group, nistp512);
}
#else