Commit c9879bcb authored by Niels Möller's avatar Niels Möller

Deleted duplicate function point_zero_p. Support n == 0 in test_ecc_mul_h instead.

parent 615bdd0c
2014-09-17 Niels Möller <nisse@lysator.liu.se>
* testsuite/testutils.c (ecc_curves): Include curve25519 in list.
(test_ecc_mul_a): Include reference points for curve25519 (with
Edwards coordinates). Allow n == 0 and n == 1, comparing to zero
and the generator, respectively.
* testsuite/ecc-add-test.c (point_zero_p): Deleted function.
(test_main): Replace calls to point_zero_p by calls to
test_ecc_mul_h with n == 0.
* testsuite/ecc-dup-test.c: Likewise.
* testsuite/ecc-modinv-test.c (mpn_zero_p): Moved function, to...
* testsuite/testutils.c (mpn_zero_p): New location. Also make
non-static.
* testsuite/testutils.c (ecc_curves): Include curve25519 in list.
(test_ecc_mul_a): Include reference points for curve25519 (with
Edwards coordinates). Allow n == 1, and compare to the generator.
* testsuite/ecdsa-keygen-test.c (ecc_valid_p): Add special case
for curve25519.
......
#include "testutils.h"
/* For curve25519 (or other edwards curves) only. */
static int
point_zero_p (const struct ecc_curve *ecc, const mp_limb_t *p)
{
mp_limb_t *d;
int ret;
mp_size_t i;
/* Zero point has Y = Z (mod p), or y = Y/Z = 1, which also implies
x == 0. */
d = xalloc_limbs (ecc->size);
ecc_modp_sub (ecc, d, p + ecc->size, p + 2*ecc->size);
while (mpn_cmp (d, ecc->p, ecc->size) >= 0)
mpn_sub_n (d, d, ecc->p, ecc->size);
for (i = 0, ret = 1; i < ecc->size; i++)
if (d[i])
{
ret = 0;
break;
}
free (d);
return ret;
}
void
test_main (void)
{
......@@ -50,12 +24,10 @@ test_main (void)
ecc_a_to_j (ecc, g, ecc->g);
ecc_add_ehh (ecc, p, z, z, scratch);
if (!point_zero_p (ecc, p))
die ("dup of zero point failed.\n");
test_ecc_mul_h (i, 0, p);
ecc_add_eh (ecc, p, z, z, scratch);
if (!point_zero_p (ecc, p))
die ("dup of zero point failed.\n");
test_ecc_mul_h (i, 0, p);
ecc_add_ehh (ecc, p, g, p, scratch);
test_ecc_mul_h (i, 1, p);
......
#include "testutils.h"
/* For curve25519 (or other edwards curves) only. */
static int
point_zero_p (const struct ecc_curve *ecc, const mp_limb_t *p)
{
mp_limb_t *d;
int ret;
mp_size_t i;
/* Zero point has Y = Z (mod p), or y = Y/Z = 1, which also implies
x == 0. */
d = xalloc_limbs (ecc->size);
ecc_modp_sub (ecc, d, p + ecc->size, p + 2*ecc->size);
while (mpn_cmp (d, ecc->p, ecc->size) >= 0)
mpn_sub_n (d, d, ecc->p, ecc->size);
for (i = 0, ret = 1; i < ecc->size; i++)
if (d[i])
{
ret = 0;
break;
}
free (d);
return ret;
}
void
test_main (void)
{
......@@ -48,8 +22,7 @@ test_main (void)
ecc_a_to_j (ecc, g, ecc->g);
ecc_dup_eh (ecc, p, z, scratch);
if (!point_zero_p (ecc, p))
die ("dup of zero point failed.\n");
test_ecc_mul_h (i, 0, p);
ecc_dup_eh (ecc, p, g, scratch);
test_ecc_mul_h (i, 2, p);
......
......@@ -1387,8 +1387,26 @@ test_ecc_mul_a (unsigned curve, unsigned n, const mp_limb_t *p)
}
};
assert (curve < 6);
assert (n >= 1 && n <= 4);
if (n == 1)
assert (n <= 4);
if (n == 0)
{
/* Makes sense for curve25519 only */
const struct ecc_curve *ecc = ecc_curves[curve];
assert (ecc->bit_size == 255);
if (!mpn_zero_p (p, ecc->size)
|| mpn_cmp (p + ecc->size, ecc->unit, ecc->size) != 0)
{
fprintf (stderr, "Incorrect point (expected (0, 1))!\n"
"got: x = ");
write_mpn (stderr, 16, p, ecc->size);
fprintf (stderr, "\n"
" y = ");
write_mpn (stderr, 16, p + ecc->size, ecc->size);
fprintf (stderr, "\n");
abort();
}
}
else if (n == 1)
{
const struct ecc_curve *ecc = ecc_curves[curve];
if (mpn_cmp (p, ecc->g, 2*ecc->size) != 0)
......
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