From: Niels Möller Date: Fri, 3 Oct 2014 14:37:33 +0000 (+0200) Subject: Enable ecc-mod-test, also with mini-gmp. X-Git-Tag: nettle_3.1rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d39ab92f07d7a30617ce6bae13bb4ceca1e9003;p=thirdparty%2Fnettle.git Enable ecc-mod-test, also with mini-gmp. --- diff --git a/ChangeLog b/ChangeLog index 6dae1704..44cf8557 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2014-10-03 Niels Möller + * 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. diff --git a/testsuite/ecc-mod-test.c b/testsuite/ecc-mod-test.c index 660fe857..3001d8e2 100644 --- a/testsuite/ecc-mod-test.c +++ b/testsuite/ecc-mod-test.c @@ -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 */