]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Enable ecc-mod-test, also with mini-gmp.
authorNiels Möller <nisse@lysator.liu.se>
Fri, 3 Oct 2014 14:37:33 +0000 (16:37 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Fri, 3 Oct 2014 14:37:33 +0000 (16:37 +0200)
ChangeLog
testsuite/ecc-mod-test.c

index 6dae1704cab01ec0fe5662466475884fa7d14f5a..44cf8557acc6d4b5f19706edb7d47d93b25d7bbc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2014-10-03  Niels Möller  <nisse@lysator.liu.se>
 
+       * testsuite/ecc-mod-test.c [NETTLE_USE_MINI_GMP]: Enable test.
+       (ref_mod): Use mpz_mod and mpz_limbs_copy, instead of mpn_tdiv_qr.
+       (test_modulo): Replace gmp_fprintf calls by plain fprintf and
+       mpn_out_str.
+
        * testsuite/testutils.c (mpn_out_str): New function, needed to
        replace uses of gmp_fprintf.
 
index 660fe857efcdb24d2cea23aec0dd92ca433a3c85..3001d8e2be91bd90776b726f96afc493b9ea7d55 100644 (file)
@@ -1,18 +1,14 @@
 #include "testutils.h"
 
-#if NETTLE_USE_MINI_GMP
-void
-test_main (void)
-{
-  SKIP();
-}
-#else /* ! NETTLE_USE_MINI_GMP */
-
 static void
 ref_mod (mp_limb_t *rp, const mp_limb_t *ap, const mp_limb_t *mp, mp_size_t mn)
 {
-  mp_limb_t q[mn + 1];
-  mpn_tdiv_qr (q, rp, 0, ap, 2*mn, mp, mn);
+  mpz_t r, a, m;
+  mpz_init (r);
+  mpz_mod (r, mpz_roinit_n (a, ap, 2*mn), mpz_roinit_n (m, mp, mn));
+  mpz_limbs_copy (rp, r, mn);
+
+  mpz_clear (r);
 }
 
 #define MAX_ECC_SIZE (1 + 521 / GMP_NUMB_BITS)
@@ -51,9 +47,14 @@ test_modulo (gmp_randstate_t rands, const char *name,
        {
          fprintf (stderr, "m->mod %s failed: bit_size = %u\n",
                   name, m->bit_size);
-         gmp_fprintf (stderr, "a   = %Nx\n", a, 2*m->size);
-         gmp_fprintf (stderr, "t   = %Nx (bad)\n", t, m->size);
-         gmp_fprintf (stderr, "ref = %Nx\n", ref, m->size);
+
+         fprintf (stderr, "a   = ");
+         mpn_out_str (stderr, 16, a, 2*m->size);
+         fprintf (stderr, "\nt   = ");
+         mpn_out_str (stderr, 16, t, m->size);
+         fprintf (stderr, " (bad)\nref = ");
+         mpn_out_str (stderr, 16, ref, m->size);
+         fprintf (stderr, "\n");
          abort ();
        }
 
@@ -68,9 +69,13 @@ test_modulo (gmp_randstate_t rands, const char *name,
            {
              fprintf (stderr, "ecc_mod %s failed: bit_size = %u\n",
                       name, m->bit_size);
-             gmp_fprintf (stderr, "a   = %Nx\n", a, 2*m->size);
-             gmp_fprintf (stderr, "t   = %Nx (bad)\n", t, m->size);
-             gmp_fprintf (stderr, "ref = %Nx\n", ref, m->size);
+             fprintf (stderr, "a   = ");
+             mpn_out_str (stderr, 16, a, 2*m->size);
+             fprintf (stderr, "\nt   = ");
+             mpn_out_str (stderr, 16, t, m->size);
+             fprintf (stderr, " (bad)\nref = ");
+             mpn_out_str (stderr, 16, ref, m->size);
+             fprintf (stderr, "\n");
              abort ();
            }
        }
@@ -93,4 +98,3 @@ test_main (void)
     }
   gmp_randclear (rands);
 }
-#endif /* ! NETTLE_USE_MINI_GMP */