Commit 8bd75960 authored by Niels Möller's avatar Niels Möller
Browse files

Adapt test case to use curve25519_base.

parent 28b7678e
2014-08-06 Niels Möller <>
* testsuite/curve25519-dh-test.c (test_g): Use curve25519_base.
(test_main): Use little-endian inputs for test_g.
* curve25519-base.c (curve25519_base): New file, new function.
Analogous to NaCl's crypto_scalarmult_base.
* curve25519.h: New file.
......@@ -31,6 +31,8 @@
#include "testutils.h"
#include "curve25519.h"
int curve25519_sqrt (const struct ecc_curve *ecc,
mp_limb_t *rp, const mp_limb_t *ap)
......@@ -160,39 +162,21 @@ curve_25519 (const struct ecc_curve *ecc,
static void
test_g (const char *sz, const char *pz)
test_g (const uint8_t *s, const uint8_t *r)
mpz_t S, R, X;
const struct ecc_curve *ecc = &nettle_curve25519;
mpz_init (S);
mpz_init (R);
mpz_init (X);
mpz_set_str (S, sz, 16);
mpz_set_str (R, pz, 16);
ASSERT (mpz_size (S) == ecc->size);
curve_25519 (ecc, mpz_limbs_write (X, ecc->size),
mpz_limbs_read (S), NULL);
mpz_limbs_finish (X, ecc->size);
if (mpz_cmp (X, R) != 0)
uint8_t p[CURVE25519_SIZE];
curve25519_base (p, s);
if (!MEMEQ (CURVE25519_SIZE, p, r))
fprintf (stderr, "curve25519 failure:\ns = ");
mpz_out_str (stderr, 16, S);
fprintf (stderr, "\nX = ");
mpz_out_str (stderr, 16, X);
fprintf (stderr, " (bad)\nR = ");
mpz_out_str (stderr, 16, R);
fprintf (stderr, " (expected)\n");
printf ("curve25519_base failure:\ns = ");
print_hex (CURVE25519_SIZE, s);
printf ("\np = ");
print_hex (CURVE25519_SIZE, p);
printf (" (bad)\nr = ");
print_hex (CURVE25519_SIZE, r);
printf (" (expected)\n");
abort ();
mpz_clear (S);
mpz_clear (R);
mpz_clear (X);
static void
......@@ -240,19 +224,17 @@ test_a (const char *bz, const char *sz, const char *pz)
test_main (void)
/* From draft-josefsson-tls-curve25519-05. Different endianness for
the P values, though. */
test_g ("6A2CB91DA5FB77B12A99C0EB872F4CDF"
test_g ("6BE088FF278B2F1CFDB6182629B13B6F"
/* From draft-turner-thecurve25519function-00 (same also in
draft-josefsson-tls-curve25519-05, but the latter uses different
endianness). */
test_g (H("77076d0a7318a57d3c16c17251b26645"
test_g (H("5dab087e624a8a4b79e17f8b83800ee6"
test_a ("4F2B886F147EFCAD4D67785BC843833F"
Supports Markdown
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