From: Niels Möller Date: Thu, 15 Oct 2020 20:43:16 +0000 (+0200) Subject: ecc-modinv-test.c: Allow invert function to return a non-canonical representation. X-Git-Tag: nettle_3.7rc1~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e615cd1d3e60c197ee008f365d75017aa49bd2d;p=thirdparty%2Fnettle.git ecc-modinv-test.c: Allow invert function to return a non-canonical representation. --- diff --git a/ChangeLog b/ChangeLog index fc8f9fc7..9e6b0162 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-10-15 Niels Möller + + * testsuite/ecc-modinv-test.c (test_modulo): Allow invert function + to return a non-canonical representation. + 2020-11-08 Niels Möller Merge refactoring of ecc modulo and reduce functions. diff --git a/testsuite/ecc-modinv-test.c b/testsuite/ecc-modinv-test.c index e991485a..9ba284fa 100644 --- a/testsuite/ecc-modinv-test.c +++ b/testsuite/ecc-modinv-test.c @@ -44,6 +44,13 @@ zero_p (const struct ecc_modulo *m, const mp_limb_t *xp) || mpn_cmp (xp, m->m, m->size) == 0; } +static int +mod_eq_p (const struct ecc_modulo *m, const mp_limb_t *a, const mp_limb_t *b, + mp_limb_t *scratch) { + ecc_mod_sub (m, scratch, a, b); + return zero_p (m, scratch); +} + #define MAX_ECC_SIZE (1 + 521 / GMP_NUMB_BITS) #define COUNT 500 @@ -114,8 +121,7 @@ test_modulo (gmp_randstate_t rands, const char *name, continue; } m->invert (m, ai, a, scratch); - /* FIXME: Allow non-canonical representation, ai > m */ - if (mpn_cmp (ref, ai, m->size)) + if (!mod_eq_p (m, ai, ref, scratch)) { fprintf (stderr, "%s->invert failed (test %u, bit size %u):\n", name, j, m->bit_size); @@ -127,6 +133,7 @@ test_modulo (gmp_randstate_t rands, const char *name, mpn_out_str (stderr, 16, ai, m->size); fprintf (stderr, " (bad)\nr = "); mpn_out_str (stderr, 16, ref, m->size); + printf ("\n"); abort (); }