]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
ecc-modinv-test.c: Allow invert function to return a non-canonical representation.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 15 Oct 2020 20:43:16 +0000 (22:43 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Tue, 10 Nov 2020 20:58:03 +0000 (21:58 +0100)
ChangeLog
testsuite/ecc-modinv-test.c

index fc8f9fc76648b555743e6552ff41b91e5a2a8681..9e6b0162001a66738ea9fd83e3ca58d822588868 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-10-15  Niels Möller  <nisse@lysator.liu.se>
+
+       * testsuite/ecc-modinv-test.c (test_modulo): Allow invert function
+       to return a non-canonical representation.
+
 2020-11-08  Niels Möller  <nisse@lysator.liu.se>
 
        Merge refactoring of ecc modulo and reduce functions.
index e991485ac24883f6045bd83051497416d38deaa3..9ba284faffbb45263e5b76d84acf8167784dae48 100644 (file)
@@ -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 ();
        }