diff --git a/ChangeLog b/ChangeLog index ea613b72eb80dd8fa99db628d4b43e9362114314..01f6cab744b61cd5bd35f008bc9fd723fa480679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,18 @@ 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. diff --git a/testsuite/ecc-add-test.c b/testsuite/ecc-add-test.c index f17ea23ed48d19f748866e377d034a18f254b92a..0fccb71c823b4e554146ee118e55c7609d736874 100644 --- a/testsuite/ecc-add-test.c +++ b/testsuite/ecc-add-test.c @@ -1,31 +1,5 @@ #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); diff --git a/testsuite/ecc-dup-test.c b/testsuite/ecc-dup-test.c index 4f426f8beec2cf56e2b4eba2859cce0dccafbedb..82c31e75cf7dbdd0b4aef360259dd8e1188c54b8 100644 --- a/testsuite/ecc-dup-test.c +++ b/testsuite/ecc-dup-test.c @@ -1,31 +1,5 @@ #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); diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 71d64f018feae3acc7c9111eaf2798a749336f69..c6778e36305e80ea1f3bfa4269a1c39bcea6c2aa 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -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)