Skip to content
Snippets Groups Projects
Commit 5d39ab92 authored by Niels Möller's avatar Niels Möller
Browse files

Enable ecc-mod-test, also with mini-gmp.

parent 3cce56be
Branches
Tags
No related merge requests found
2014-10-03 Niels Möller <nisse@lysator.liu.se> 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 * testsuite/testutils.c (mpn_out_str): New function, needed to
replace uses of gmp_fprintf. replace uses of gmp_fprintf.
......
#include "testutils.h" #include "testutils.h"
#if NETTLE_USE_MINI_GMP
void
test_main (void)
{
SKIP();
}
#else /* ! NETTLE_USE_MINI_GMP */
static void static void
ref_mod (mp_limb_t *rp, const mp_limb_t *ap, const mp_limb_t *mp, mp_size_t mn) 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]; mpz_t r, a, m;
mpn_tdiv_qr (q, rp, 0, ap, 2*mn, mp, mn); 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) #define MAX_ECC_SIZE (1 + 521 / GMP_NUMB_BITS)
...@@ -51,9 +47,14 @@ test_modulo (gmp_randstate_t rands, const char *name, ...@@ -51,9 +47,14 @@ test_modulo (gmp_randstate_t rands, const char *name,
{ {
fprintf (stderr, "m->mod %s failed: bit_size = %u\n", fprintf (stderr, "m->mod %s failed: bit_size = %u\n",
name, m->bit_size); name, m->bit_size);
gmp_fprintf (stderr, "a = %Nx\n", a, 2*m->size);
gmp_fprintf (stderr, "t = %Nx (bad)\n", t, m->size); fprintf (stderr, "a = ");
gmp_fprintf (stderr, "ref = %Nx\n", ref, m->size); 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 (); abort ();
} }
...@@ -68,9 +69,13 @@ test_modulo (gmp_randstate_t rands, const char *name, ...@@ -68,9 +69,13 @@ test_modulo (gmp_randstate_t rands, const char *name,
{ {
fprintf (stderr, "ecc_mod %s failed: bit_size = %u\n", fprintf (stderr, "ecc_mod %s failed: bit_size = %u\n",
name, m->bit_size); name, m->bit_size);
gmp_fprintf (stderr, "a = %Nx\n", a, 2*m->size); fprintf (stderr, "a = ");
gmp_fprintf (stderr, "t = %Nx (bad)\n", t, m->size); mpn_out_str (stderr, 16, a, 2*m->size);
gmp_fprintf (stderr, "ref = %Nx\n", ref, 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 (); abort ();
} }
} }
...@@ -93,4 +98,3 @@ test_main (void) ...@@ -93,4 +98,3 @@ test_main (void)
} }
gmp_randclear (rands); gmp_randclear (rands);
} }
#endif /* ! NETTLE_USE_MINI_GMP */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment