Commit 61a54890 authored by Niels Möller's avatar Niels Möller

Do some more tests in ecc-redc-test.

parent 8b83e812
2014-09-22 Niels Möller <nisse@lysator.liu.se> 2014-09-22 Niels Möller <nisse@lysator.liu.se>
* testsuite/ecc-redc-test.c (test_main): Relaxed tests for which
tests to run.
* testsuite/ecc-modinv-test.c (test_modulo): New function, same * testsuite/ecc-modinv-test.c (test_modulo): New function, same
organization as in ecc-mod-test.c below. organization as in ecc-mod-test.c below.
......
...@@ -57,9 +57,6 @@ test_main (void) ...@@ -57,9 +57,6 @@ test_main (void)
{ {
const struct ecc_curve *ecc = ecc_curves[i]; const struct ecc_curve *ecc = ecc_curves[i];
unsigned j; unsigned j;
if (ecc->p.reduce == ecc->p.mod)
continue;
ASSERT (ecc->p.redc_size != 0);
for (j = 0; j < COUNT; j++) for (j = 0; j < COUNT; j++)
{ {
...@@ -72,38 +69,43 @@ test_main (void) ...@@ -72,38 +69,43 @@ test_main (void)
ref_redc (ref, a, ecc->p.m, ecc->p.size); ref_redc (ref, a, ecc->p.m, ecc->p.size);
mpn_copyi (m, a, 2*ecc->p.size); if (ecc->p.reduce != ecc->p.mod)
ecc->p.reduce (&ecc->p, m);
if (mpn_cmp (m, ecc->p.m, ecc->p.size) >= 0)
mpn_sub_n (m, m, ecc->p.m, ecc->p.size);
if (mpn_cmp (m, ref, ecc->p.size))
{ {
fprintf (stderr, "ecc->reduce failed: bit_size = %u\n", mpn_copyi (m, a, 2*ecc->p.size);
ecc->p.bit_size); ecc->p.reduce (&ecc->p, m);
gmp_fprintf (stderr, "a = %Nx\n", a, 2*ecc->p.size); if (mpn_cmp (m, ecc->p.m, ecc->p.size) >= 0)
gmp_fprintf (stderr, "m = %Nx (bad)\n", m, ecc->p.size); mpn_sub_n (m, m, ecc->p.m, ecc->p.size);
gmp_fprintf (stderr, "ref = %Nx\n", ref, ecc->p.size);
abort (); if (mpn_cmp (m, ref, ecc->p.size))
{
fprintf (stderr, "ecc->p.reduce failed: bit_size = %u\n",
ecc->p.bit_size);
gmp_fprintf (stderr, "a = %Nx\n", a, 2*ecc->p.size);
gmp_fprintf (stderr, "m = %Nx (bad)\n", m, ecc->p.size);
gmp_fprintf (stderr, "ref = %Nx\n", ref, ecc->p.size);
abort ();
}
} }
if (ecc->p.redc_size != 0)
mpn_copyi (m, a, 2*ecc->p.size); {
if (ecc->p.m[0] == 1) mpn_copyi (m, a, 2*ecc->p.size);
ecc_pm1_redc (&ecc->p, m); if (ecc->p.m[0] == 1)
else ecc_pm1_redc (&ecc->p, m);
ecc_pp1_redc (&ecc->p, m); else
ecc_pp1_redc (&ecc->p, m);
if (mpn_cmp (m, ecc->p.m, ecc->p.size) >= 0)
mpn_sub_n (m, m, ecc->p.m, ecc->p.size); if (mpn_cmp (m, ecc->p.m, ecc->p.size) >= 0)
mpn_sub_n (m, m, ecc->p.m, ecc->p.size);
if (mpn_cmp (m, ref, ecc->p.size))
{ if (mpn_cmp (m, ref, ecc->p.size))
fprintf (stderr, "ecc_p%c1_redc failed: bit_size = %u\n", {
(ecc->p.m[0] == 1) ? 'm' : 'p', ecc->p.bit_size); fprintf (stderr, "ecc_p%c1_redc failed: bit_size = %u\n",
gmp_fprintf (stderr, "a = %Nx\n", a, 2*ecc->p.size); (ecc->p.m[0] == 1) ? 'm' : 'p', ecc->p.bit_size);
gmp_fprintf (stderr, "m = %Nx (bad)\n", m, ecc->p.size); gmp_fprintf (stderr, "a = %Nx\n", a, 2*ecc->p.size);
gmp_fprintf (stderr, "ref = %Nx\n", ref, ecc->p.size); gmp_fprintf (stderr, "m = %Nx (bad)\n", m, ecc->p.size);
abort (); gmp_fprintf (stderr, "ref = %Nx\n", ref, ecc->p.size);
abort ();
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment