[email protected] (Niels Möller) writes:
> I think it would be nice if the new function pointers could be used to
> reduce duplication in this test as well as ecc-dup-test.c.
See below patch (generated with -b, to ignore the indentation
change).
To be applied on top of your patch, does it look ok?
Regards,
/Niels
diff --git a/testsuite/ecc-add-test.c b/testsuite/ecc-add-test.c
index 8e88a76..05a0562 100644
--- a/testsuite/ecc-add-test.c
+++ b/testsuite/ecc-add-test.c
@@ -15,18 +15,19 @@ test_main (void)
mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
mp_limb_t *scratch = xalloc_limbs (ECC_ADD_JJJ_ITCH(ecc->p.size));
+ ecc_a_to_j (ecc, g, ecc->g);
+
if (ecc->p.bit_size == 255)
{
mp_limb_t *z = xalloc_limbs (ecc_size_j (ecc));
+
+ ASSERT (ecc->add_hh == ecc_add_eh);
+ ASSERT (ecc->add_hhh == ecc_add_ehh);
+
/* Zero point has x = 0, y = 1, z = 1 */
mpn_zero (z, 3*ecc->p.size);
z[ecc->p.size] = z[2*ecc->p.size] = 1;
- assert (ecc->add_hh == ecc_add_eh);
- assert (ecc->add_hhh == ecc_add_ehh);
-
- ecc_a_to_j (ecc, g, ecc->g);
-
ecc->add_hhh (ecc, p, z, z, scratch);
test_ecc_mul_h (i, 0, p);
@@ -45,29 +46,13 @@ test_main (void)
ecc->add_hh (ecc, g2, g, g, scratch);
test_ecc_mul_h (i, 2, g2);
- ecc->add_hhh (ecc, g3, g, g2, scratch);
- test_ecc_mul_h (i, 3, g3);
-
- ecc->add_hh (ecc, g3, g2, g, scratch);
- test_ecc_mul_h (i, 3, g3);
-
- ecc->add_hhh (ecc, p, g, g3, scratch);
- test_ecc_mul_h (i, 4, p);
-
- ecc->add_hh (ecc, p, g3, g, scratch);
- test_ecc_mul_h (i, 4, p);
-
- ecc->add_hhh (ecc, p, g2, g2, scratch);
- test_ecc_mul_h (i, 4, p);
-
free (z);
}
else
{
- assert (ecc->add_hhh == ecc_add_jjj);
- assert (ecc->dup == ecc_dup_jj);
-
- ecc_a_to_j (ecc, g, ecc->g);
+ ASSERT (ecc->add_hhh == ecc_add_jjj);
+ ASSERT (ecc->dup == ecc_dup_jj);
+ }
ecc->dup (ecc, g2, g, scratch);
test_ecc_mul_h (i, 2, g2);
@@ -86,7 +71,7 @@ test_main (void)
ecc->dup (ecc, p, g2, scratch);
test_ecc_mul_h (i, 4, p);
- }
+
free (g);
free (g2);
free (g3);
diff --git a/testsuite/ecc-dup-test.c b/testsuite/ecc-dup-test.c
index f987b16..784b8cc 100644
--- a/testsuite/ecc-dup-test.c
+++ b/testsuite/ecc-dup-test.c
@@ -12,35 +12,32 @@ test_main (void)
mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
mp_limb_t *scratch = xalloc_limbs (ECC_DUP_EH_ITCH(ecc->p.size));;
+ ecc_a_to_j (ecc, g, ecc->g);
+
if (ecc->p.bit_size == 255)
{
mp_limb_t *z = xalloc_limbs (ecc_size_j (ecc));
+
+ ASSERT (ecc->dup == ecc_dup_eh);
+
/* Zero point has x = 0, y = 1, z = 1 */
mpn_zero (z, 3*ecc->p.size);
z[ecc->p.size] = z[2*ecc->p.size] = 1;
- ecc_a_to_j (ecc, g, ecc->g);
-
ecc->dup (ecc, p, z, scratch);
test_ecc_mul_h (i, 0, p);
- ecc->dup (ecc, p, g, scratch);
- test_ecc_mul_h (i, 2, p);
-
- ecc->dup (ecc, p, p, scratch);
- test_ecc_mul_h (i, 4, p);
free (z);
}
else
- {
- ecc_a_to_j (ecc, g, ecc->g);
+ ASSERT (ecc->dup == ecc_dup_jj);
ecc->dup (ecc, p, g, scratch);
test_ecc_mul_h (i, 2, p);
ecc->dup (ecc, p, p, scratch);
test_ecc_mul_h (i, 4, p);
- }
+
free (p);
free (g);
free (scratch);
--
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs