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-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09fbcec3d2f8d7daa484d0881d9b00210abd4375;p=thirdparty%2Fnettle.git ecc-modinv-test.c: Allow invert function to return a non-canonical representation. --- diff --git a/ChangeLog b/ChangeLog index 983078a6..d9822d1c 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-10-14 Niels Möller * ecc-mod-arith.c (ecc_mod_pow_2k, ecc_mod_pow_2k_mul): Moved diff --git a/testsuite/ecc-modinv-test.c b/testsuite/ecc-modinv-test.c index e991485a..1e54ef40 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 (); }