summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2014-08-25 21:22:40 +0200
committerNiels Möller <nisse@lysator.liu.se>2014-08-25 21:23:20 +0200
commitcc86df70d98be60a5a299d22a37623a61b5ed0b0 (patch)
treee49fb80c8b1ad74098fd909fbb9ddb0f9afd817c
parenta45118aa18568472d7fb7a614b8ea5721f89d1ef (diff)
downloadnettle-cc86df70d98be60a5a299d22a37623a61b5ed0b0.tar.gz
curve25519 support for ecc_point_mul, ecc_point_mul_g, and ecdh-test.
-rw-r--r--ChangeLog9
-rw-r--r--ecc-point-mul-g.c11
-rw-r--r--ecc-point-mul.c13
-rw-r--r--testsuite/ecdh-test.c7
4 files changed, 26 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 551bd236..1b0f67df 100644
--- 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
diff --git a/ecc-point-mul-g.c b/ecc-point-mul-g.c
index 8186bf2c..bb9a2d76 100644
--- a/ecc-point-mul-g.c
+++ b/ecc-point-mul-g.c
@@ -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);
}
diff --git a/ecc-point-mul.c b/ecc-point-mul.c
index 09d4f642..2080b608 100644
--- a/ecc-point-mul.c
+++ b/ecc-point-mul.c
@@ -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);
}
diff --git a/testsuite/ecdh-test.c b/testsuite/ecdh-test.c
index 76102130..14f01399 100644
--- a/testsuite/ecdh-test.c
+++ b/testsuite/ecdh-test.c
@@ -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
}