curve25519 is an elliptic curve, developed by Dan Bernstein, for fast Diffie-Hellman key agreement. DJB's original implementation was written in a language of his own devising called qhasm. The original qhasm source isn't available, only the x86 32-bit assembly output.
This project provides performant, portable 32-bit & 64-bit implementations. All implementations are of course constant time in regard to secret data.
Compilers versions are gcc 4.6.3, icc 13.1.1, clang 3.4-1~exp1.
Counts are in thousands of cycles.
Note that SSE2 performance may be less impressive on AMD & older CPUs with slower SSE ops!
E5200 @ 2.5ghz, march=core2
E3-1270 @ 3.4ghz, march=corei7-avx
No configuration is needed.
gcc curve25519.c -m32 -O3 -c
gcc curve25519.c -m64 -O3 -c
gcc curve25519.c -m32 -O3 -c -DCURVE25519_SSE2 -msse2 gcc curve25519.c -m64 -O3 -c -DCURVE25519_SSE2
clang, icc, and msvc are also supported
Define CURVE25519_SUFFIX to append a suffix to public functions, e.g.
-DCURVE25519_SUFFIX=_sse2 to create curve25519_donna_sse2 and
To use the code, link against
To generate a private/secret key, generate 32 cryptographically random bytes:
curve25519_key sk; randombytes(sk, sizeof(curve25519_key));
Manual clamping is not needed, and it is actually not possible to use unclamped keys due to the code taking advantage of the clamped bits internally.
To generate the public key from the private/secret key:
curve25519_key pk; curve25519_donna_basepoint(pk, sk);
To generate a shared key with your private/secret key and someone elses public key:
curve25519_key shared; curve25519_donna(shared, mysk, yourpk);
shared with a cryptographic hash before using, or e.g. pass
HSalsa20/HChacha as NaCl does.
Fuzzing against a reference implemenation is now available. See fuzz/README.
curve25519.c and linking with
test.c will run basic sanity tests and benchmark curve25519_donna.
Public Domain, or MIT