]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Reduce duplication in ecc-add-test.
authorNiels Möller <nisse@lysator.liu.se>
Sat, 23 Sep 2017 08:54:50 +0000 (10:54 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 23 Sep 2017 08:54:50 +0000 (10:54 +0200)
* testsuite/ecc-add-test.c (test_main): Reduce test duplication.
Use ecc->add_hhh_itch.

ChangeLog
testsuite/ecc-add-test.c

index 2b6d05e4ac040c21d41d9721fee0b26216007730..123860194c1c11c7a6535a7174553c9a3add6fae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-23  Niels Möller  <nisse@lysator.liu.se>
+
+       * testsuite/ecc-add-test.c (test_main): Reduce test duplication.
+       Use ecc->add_hhh_itch.
+
 2017-09-23  Daiki Ueno  <dueno@redhat.com>
 
        * ecc-internal.h (ecc_dup_func): New typedef.
index 8e88a76b631d087a8d5cfb593a6f0fd67b8aa8b5..ad2bd29230eeb0a5d858f68df9efd0a945ff7aac 100644 (file)
@@ -13,20 +13,24 @@ test_main (void)
       mp_limb_t *g2 = xalloc_limbs (ecc_size_j (ecc));
       mp_limb_t *g3 = xalloc_limbs (ecc_size_j (ecc));
       mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
-      mp_limb_t *scratch = xalloc_limbs (ECC_ADD_JJJ_ITCH(ecc->p.size));
+      mp_limb_t *scratch = xalloc_limbs (ecc->add_hhh_itch);
+
+      ASSERT (ecc->dup_itch <= ecc->add_hhh_itch);
+
+      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);
+         ASSERT (ecc->add_hh_itch <= ecc->add_hhh_itch);
+
          /* 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,48 +49,32 @@ 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);
+         ASSERT (ecc->add_hhh == ecc_add_jjj);
+         ASSERT (ecc->dup == ecc_dup_jj);
+       }
 
-         ecc_a_to_j (ecc, g, ecc->g);
+      ecc->dup (ecc, g2, g, scratch);
+      test_ecc_mul_h (i, 2, g2);
 
-         ecc->dup (ecc, g2, 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_hhh (ecc, g3, g, g2, scratch);
-         test_ecc_mul_h (i, 3, g3);
+      ecc->add_hhh (ecc, g3, g2, g, scratch);
+      test_ecc_mul_h (i, 3, g3);
 
-         ecc->add_hhh (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_hhh (ecc, p, g, g3, scratch);
-         test_ecc_mul_h (i, 4, p);
+      ecc->add_hhh (ecc, p, g3, g, scratch);
+      test_ecc_mul_h (i, 4, p);
 
-         ecc->add_hhh (ecc, p, g3, g, scratch);
-         test_ecc_mul_h (i, 4, p);
+      ecc->dup (ecc, p, g2, scratch);
+      test_ecc_mul_h (i, 4, p);
 
-         ecc->dup (ecc, p, g2, scratch);
-         test_ecc_mul_h (i, 4, p);
-       }
       free (g);
       free (g2);
       free (g3);