]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
curve25519 support for ecc_point_mul, ecc_point_mul_g, and ecdh-test.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 25 Aug 2014 19:22:40 +0000 (21:22 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 25 Aug 2014 19:23:20 +0000 (21:23 +0200)
ChangeLog
ecc-point-mul-g.c
ecc-point-mul.c
testsuite/ecdh-test.c

index 551bd23658cccaf25e529fadc19135171b40ab9a..1b0f67df9041294ae6b06057b738d124ae81ee34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2014-08-25  Niels Möller  <nisse@lysator.liu.se>
 
+       * testsuite/ecdh-test.c (set_point): Check return value of
+       ecc_point_set.
+       (test_main): Enable curve25519 test.
+
+       * ecc-point-mul-g.c (ecc_point_mul_g): Use ecc->mul_g and
+       ecc->h_to_a function pointers.
+       * ecc-point-mul.c (ecc_point_mul): Use the ecc->mul and
+       ecc->h_to_a function pointers.
+
        * ecc-internal.h (ecc_mul_g_func, ecc_mul_func, ecc_h_to_a_func):
        New typedefs.
        (struct ecc_curve): New function pointers mul, mul_g, h_to_a, and
index 8186bf2c9746453161f2d0460c44b7ff657ea071..bb9a2d760f48174ccb7903b2b1c967bc532773dc 100644 (file)
@@ -45,13 +45,14 @@ void
 ecc_point_mul_g (struct ecc_point *r, const struct ecc_scalar *n)
 {
   TMP_DECL(scratch, mp_limb_t, 3*ECC_MAX_SIZE + ECC_MUL_G_ITCH (ECC_MAX_SIZE));
-  mp_limb_t size = r->ecc->size;
-  mp_size_t itch = 3*size + ECC_MUL_G_ITCH (size);
+  const struct ecc_curve *ecc = r->ecc;
+  mp_limb_t size = ecc->size;
+  mp_size_t itch = 3*size + ecc->mul_g_itch;
 
-  assert (r->ecc == n->ecc);
+  assert (n->ecc == ecc);
 
   TMP_ALLOC (scratch, itch);
 
-  ecc_mul_g (r->ecc, scratch, n->p, scratch + 3*size);
-  ecc_j_to_a (r->ecc, 1, r->p, scratch, scratch + 3*size);
+  ecc->mul_g (ecc, scratch, n->p, scratch + 3*size);
+  ecc->h_to_a (ecc, 1, r->p, scratch, scratch + 3*size);
 }
index 09d4f642108b47a8032ce3f292ffd93c897bb543..2080b60815bcadeb1d91e615c91dd03f3e32b87a 100644 (file)
@@ -44,14 +44,15 @@ void
 ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
               const struct ecc_point *p)
 {
-  mp_limb_t size = p->ecc->size;
-  mp_size_t itch = 3*size + ECC_MUL_A_ITCH (size);
+  const struct ecc_curve *ecc = r->ecc;
+  mp_limb_t size = ecc->size;
+  mp_size_t itch = 3*size + ecc->mul_itch;
   mp_limb_t *scratch = gmp_alloc_limbs (itch);
 
-  assert (n->ecc == p->ecc);
-  assert (r->ecc == p->ecc);
+  assert (n->ecc == ecc);
+  assert (p->ecc == ecc);
 
-  ecc_mul_a (p->ecc, scratch, n->p, p->p, scratch + 3*size);
-  ecc_j_to_a (r->ecc, 1, r->p, scratch, scratch + 3*size);
+  ecc->mul (ecc, scratch, n->p, p->p, scratch + 3*size);
+  ecc->h_to_a (ecc, 1, r->p, scratch, scratch + 3*size);
   gmp_free_limbs (scratch, itch);
 }
index 76102130a7d6f9b083d9a3ec118425d7da3e3b69..14f013993895eeb5ff9b2635869c5137ecc8709c 100644 (file)
@@ -38,7 +38,9 @@ set_point (struct ecc_point *p,
   mpz_t X, Y;
   mpz_init_set_str (X, x, 0);
   mpz_init_set_str (Y, y, 0);
-  ecc_point_set (p, X, Y);
+  if (!ecc_point_set (p, X, Y))
+    die ("Test point not on curve!\n");
+
   mpz_clear (X);
   mpz_clear (Y);
 }
@@ -185,7 +187,7 @@ test_main(void)
           "4488572162727491199625798812850846214916160870437505769058530973184916706326908828109446998319674522651965593412129100088877891410841200092694907512496020182",
           "2126311732129869456512627735193938710331935978955001830871465201548004444073866677974896970734635601049909886616595755762740651165670628002084824920216966370",
           "4803556648772727869384704240411011976585308117802975396033423138930126997561438092192867119930177133880625991019440171972612468402200399449807843995563872782");
-#if 0
+
   /* NOTE: This isn't quite the standard way to do curve25519
      diffie-hellman, but it tests that the ecc_point interface works
      also with curve25519. FIXME: Which it doesn't yet do. */
@@ -198,5 +200,4 @@ test_main(void)
           "45040108202870901856797106334440548809561721639881101469282515918034252408802",
           "12684624775789228333626692483521764247362476074160626230698999100180553618972",
           "22635121008463339848034566659860493350277619617839914078958064757823336329514");
-#endif
 }