Add functions EC_POINT_mul and EC_GROUP_precompute.
The latter does nothing for now, but its existence means that applications can request precomputation when appropriate.
This commit is contained in:
@@ -77,8 +77,8 @@
|
||||
* scalar*generator
|
||||
* is included in the addition if scalar != NULL
|
||||
*/
|
||||
int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, BIGNUM *scalar,
|
||||
size_t num, EC_POINT *points[], BIGNUM *scalars[], BN_CTX *ctx)
|
||||
int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
|
||||
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
|
||||
{
|
||||
BN_CTX *new_ctx = NULL;
|
||||
EC_POINT *generator = NULL;
|
||||
@@ -228,7 +228,7 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, BIGNUM *scalar,
|
||||
{
|
||||
if (wbits[i] == 0)
|
||||
{
|
||||
BIGNUM *s;
|
||||
const BIGNUM *s;
|
||||
|
||||
s = i < num ? scalars[i] : scalar;
|
||||
|
||||
@@ -295,3 +295,59 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, BIGNUM *scalar,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
|
||||
{
|
||||
const EC_POINT *points[1];
|
||||
const BIGNUM *scalars[1];
|
||||
|
||||
points[0] = point;
|
||||
scalars[0] = p_scalar;
|
||||
|
||||
return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
|
||||
}
|
||||
|
||||
|
||||
int EC_GROUP_precompute(EC_GROUP *group, BN_CTX *ctx)
|
||||
{
|
||||
const EC_POINT *generator;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
BIGNUM *order;
|
||||
int ret = 0;
|
||||
|
||||
generator = EC_GROUP_get0_generator(group);
|
||||
if (generator == NULL)
|
||||
{
|
||||
ECerr(EC_F_EC_GROUP_PRECOMPUTE, EC_R_UNDEFINED_GENERATOR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx == NULL)
|
||||
{
|
||||
ctx = new_ctx = BN_CTX_new();
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
order = BN_CTX_get(ctx);
|
||||
if (order == NULL) goto err;
|
||||
|
||||
if (!EC_GROUP_get_order(group, order, ctx)) return 0;
|
||||
if (BN_is_zero(order))
|
||||
{
|
||||
ECerr(EC_F_EC_GROUP_PRECOMPUTE, EC_R_UNKNOWN_ORDER);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
if (new_ctx != NULL)
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user