Commit 308c1089 authored by Niels Möller's avatar Niels Möller

Deleted unused INITIAL argument for ecc_mul_a.

parent b9f98cb7
2014-08-23 Niels Möller <nisse@lysator.liu.se> 2014-08-23 Niels Möller <nisse@lysator.liu.se>
* ecc-mul-a.c (ecc_mul_a): Deleted INITIAL argument, all callers,
except the tests, pass 1. Updated all callers.
(table_init): Likewise deleted INITIAL.
* ecc.h (ecc_mul_a): Updated prototype.
* testsuite/ecc-mul-a-test.c (test_main): Deleted tests for
ecc_mul_a with INITIAL == 0.
* ecc-internal.h (struct ecc_curve): Reordered struct, moved * ecc-internal.h (struct ecc_curve): Reordered struct, moved
function pointers before pointers to bignum constants. function pointers before pointers to bignum constants.
......
...@@ -114,7 +114,7 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc, ...@@ -114,7 +114,7 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc,
ecc_modq_mul (ecc, u2, rp, sinv); ecc_modq_mul (ecc, u2, rp, sinv);
/* Total storage: 5*ecc->size + ECC_MUL_A_ITCH (ecc->size) */ /* Total storage: 5*ecc->size + ECC_MUL_A_ITCH (ecc->size) */
ecc_mul_a (ecc, 1, P2, u2, pp, u2 + ecc->size); ecc_mul_a (ecc, P2, u2, pp, u2 + ecc->size);
/* u1 = h / s, P1 = u1 * G */ /* u1 = h / s, P1 = u1 * G */
ecc_hash (ecc, hp, length, digest); ecc_hash (ecc, hp, length, digest);
......
...@@ -55,7 +55,7 @@ ecc_mul_a_itch (const struct ecc_curve *ecc) ...@@ -55,7 +55,7 @@ ecc_mul_a_itch (const struct ecc_curve *ecc)
#if ECC_MUL_A_WBITS == 0 #if ECC_MUL_A_WBITS == 0
void void
ecc_mul_a (const struct ecc_curve *ecc, ecc_mul_a (const struct ecc_curve *ecc,
int initial, mp_limb_t *r, mp_limb_t *r,
const mp_limb_t *np, const mp_limb_t *p, const mp_limb_t *np, const mp_limb_t *p,
mp_limb_t *scratch) mp_limb_t *scratch)
{ {
...@@ -67,7 +67,7 @@ ecc_mul_a (const struct ecc_curve *ecc, ...@@ -67,7 +67,7 @@ ecc_mul_a (const struct ecc_curve *ecc,
unsigned i; unsigned i;
ecc_a_to_j (ecc, initial, pj, p); ecc_a_to_j (ecc, 1, pj, p);
mpn_zero (r, 3*ecc->size); mpn_zero (r, 3*ecc->size);
for (i = ecc->size, is_zero = 1; i-- > 0; ) for (i = ecc->size, is_zero = 1; i-- > 0; )
...@@ -104,14 +104,14 @@ ecc_mul_a (const struct ecc_curve *ecc, ...@@ -104,14 +104,14 @@ ecc_mul_a (const struct ecc_curve *ecc,
static void static void
table_init (const struct ecc_curve *ecc, table_init (const struct ecc_curve *ecc,
mp_limb_t *table, unsigned bits, mp_limb_t *table, unsigned bits,
int initial, const mp_limb_t *p, const mp_limb_t *p,
mp_limb_t *scratch) mp_limb_t *scratch)
{ {
unsigned size = 1 << bits; unsigned size = 1 << bits;
unsigned j; unsigned j;
mpn_zero (TABLE(0), 3*ecc->size); mpn_zero (TABLE(0), 3*ecc->size);
ecc_a_to_j (ecc, initial, TABLE(1), p); ecc_a_to_j (ecc, 1, TABLE(1), p);
for (j = 2; j < size; j += 2) for (j = 2; j < size; j += 2)
{ {
...@@ -122,7 +122,7 @@ table_init (const struct ecc_curve *ecc, ...@@ -122,7 +122,7 @@ table_init (const struct ecc_curve *ecc,
void void
ecc_mul_a (const struct ecc_curve *ecc, ecc_mul_a (const struct ecc_curve *ecc,
int initial, mp_limb_t *r, mp_limb_t *r,
const mp_limb_t *np, const mp_limb_t *p, const mp_limb_t *np, const mp_limb_t *p,
mp_limb_t *scratch) mp_limb_t *scratch)
{ {
...@@ -140,7 +140,7 @@ ecc_mul_a (const struct ecc_curve *ecc, ...@@ -140,7 +140,7 @@ ecc_mul_a (const struct ecc_curve *ecc,
unsigned shift = bit_index % GMP_NUMB_BITS; unsigned shift = bit_index % GMP_NUMB_BITS;
mp_limb_t w, bits; mp_limb_t w, bits;
table_init (ecc, table, ECC_MUL_A_WBITS, initial, p, scratch_out); table_init (ecc, table, ECC_MUL_A_WBITS, p, scratch_out);
w = np[limb_index]; w = np[limb_index];
bits = w >> shift; bits = w >> shift;
......
...@@ -51,7 +51,7 @@ ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n, ...@@ -51,7 +51,7 @@ ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
assert (n->ecc == p->ecc); assert (n->ecc == p->ecc);
assert (r->ecc == p->ecc); assert (r->ecc == p->ecc);
ecc_mul_a (p->ecc, 1, scratch, n->p, p->p, scratch + 3*size); ecc_mul_a (p->ecc, scratch, n->p, p->p, scratch + 3*size);
ecc_j_to_a (r->ecc, 1, r->p, scratch, scratch + 3*size); ecc_j_to_a (r->ecc, 1, r->p, scratch, scratch + 3*size);
gmp_free_limbs (scratch, itch); gmp_free_limbs (scratch, itch);
} }
...@@ -285,15 +285,13 @@ ecc_mul_g (const struct ecc_curve *ecc, mp_limb_t *r, ...@@ -285,15 +285,13 @@ ecc_mul_g (const struct ecc_curve *ecc, mp_limb_t *r,
const mp_limb_t *np, mp_limb_t *scratch); const mp_limb_t *np, mp_limb_t *scratch);
/* Computes N * P. The scalar N is the same as for ecc_mul_g. P is a /* Computes N * P. The scalar N is the same as for ecc_mul_g. P is a
non-zero point on the curve, in affine coordinates. Pass a non-zero non-zero point on the curve, in affine coordinates. Output R is a
INITIAL if the point coordinates have not previously been converted non-zero point, in Jacobian coordinates. */
to Montgomery representation. Output R is a non-zero point, in
Jacobian coordinates. */
mp_size_t mp_size_t
ecc_mul_a_itch (const struct ecc_curve *ecc); ecc_mul_a_itch (const struct ecc_curve *ecc);
void void
ecc_mul_a (const struct ecc_curve *ecc, ecc_mul_a (const struct ecc_curve *ecc,
int initial, mp_limb_t *r, mp_limb_t *r,
const mp_limb_t *np, const mp_limb_t *p, const mp_limb_t *np, const mp_limb_t *p,
mp_limb_t *scratch); mp_limb_t *scratch);
......
...@@ -234,7 +234,7 @@ static void ...@@ -234,7 +234,7 @@ static void
bench_mul_a (void *p) bench_mul_a (void *p)
{ {
struct ecc_ctx *ctx = (struct ecc_ctx *) p; struct ecc_ctx *ctx = (struct ecc_ctx *) p;
ecc_mul_a (ctx->ecc, 1, ctx->rp, ctx->ap, ctx->bp, ctx->tp); ecc_mul_a (ctx->ecc, ctx->rp, ctx->ap, ctx->bp, ctx->tp);
} }
static void static void
......
...@@ -31,34 +31,21 @@ test_main (void) ...@@ -31,34 +31,21 @@ test_main (void)
mpn_zero (n, size); mpn_zero (n, size);
n[0] = 1; n[0] = 1;
ecc_mul_a (ecc, 1, p, n, ecc->g, scratch); ecc_mul_a (ecc, p, n, ecc->g, scratch);
ecc_j_to_a (ecc, 1, p, p, scratch); ecc_j_to_a (ecc, 1, p, p, scratch);
if (mpn_cmp (p, ecc->g, 2*size != 0)) if (mpn_cmp (p, ecc->g, 2*size != 0))
die ("curve %d: ecc_mul_a with n = 1 failed.\n", ecc->bit_size); die ("curve %d: ecc_mul_a with n = 1 failed.\n", ecc->bit_size);
if (ecc->use_redc)
{
ecc_mul_a (ecc, 0, p, n, ecc->redc_g, scratch);
ecc_j_to_a (ecc, 1, p, p, scratch);
if (mpn_cmp (p, ecc->g, 2*size != 0))
die ("curve %d: ecc_mul_a with n = 1 and redc failed.\n", ecc->bit_size);
}
for (n[0] = 2; n[0] <= 4; n[0]++) for (n[0] = 2; n[0] <= 4; n[0]++)
{ {
ecc_mul_a (ecc, 1, p, n, ecc->g, scratch); ecc_mul_a (ecc, p, n, ecc->g, scratch);
test_ecc_mul_j (i, n[0], p); test_ecc_mul_j (i, n[0], p);
if (ecc->use_redc)
{
ecc_mul_a (ecc, 0, p, n, ecc->redc_g, scratch);
test_ecc_mul_j (i, n[0], p);
}
} }
/* (order - 1) * g = - g */ /* (order - 1) * g = - g */
mpn_sub_1 (n, ecc->q, size, 1); mpn_sub_1 (n, ecc->q, size, 1);
ecc_mul_a (ecc, 1, p, n, ecc->g, scratch); ecc_mul_a (ecc, p, n, ecc->g, scratch);
ecc_j_to_a (ecc, 1, p, p, scratch); ecc_j_to_a (ecc, 1, p, p, scratch);
mpn_sub_n (p + size, ecc->p, p + size, size); mpn_sub_n (p + size, ecc->p, p + size, size);
if (mpn_cmp (p, ecc->g, 2*size) != 0) if (mpn_cmp (p, ecc->g, 2*size) != 0)
...@@ -80,7 +67,7 @@ test_main (void) ...@@ -80,7 +67,7 @@ test_main (void)
mpz_limbs_copy (n, r, size); mpz_limbs_copy (n, r, size);
n[size - 1] %= ecc->q[size - 1]; n[size - 1] %= ecc->q[size - 1];
ecc_mul_a (ecc, 1, p, n, ecc->g, scratch); ecc_mul_a (ecc, p, n, ecc->g, scratch);
ecc_j_to_a (ecc, 1, p, p, scratch); ecc_j_to_a (ecc, 1, p, p, scratch);
ecc_mul_g (ecc, q, n, scratch); ecc_mul_g (ecc, q, n, scratch);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment