From 29162246508301815c361a892951521637ac65cb Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 19 Apr 2013 15:59:30 +0200 Subject: [PATCH] Use curve25519_donna_c64 instead of curve25519_ref if supported. --- .gitignore | 2 ++ configure.ac | 2 ++ src/libsodium/Makefile.am | 3 +++ .../curve25519/ref/base_curve25519_ref.c | 4 +++ .../curve25519/ref/smult_curve25519_ref.c | 4 +++ ...19.h => crypto_scalarmult_curve25519.h.in} | 26 ++++++++++++++++--- 6 files changed, 37 insertions(+), 4 deletions(-) rename src/libsodium/include/sodium/{crypto_scalarmult_curve25519.h => crypto_scalarmult_curve25519.h.in} (55%) diff --git a/.gitignore b/.gitignore index 8d70115f..9b8bc8eb 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ src/curvecp/curvecpmakekey src/curvecp/curvecpmessage src/curvecp/curvecpprintkey src/curvecp/curvecpserver +src/libsodium/include/sodium/crypto_scalarmult_curve25519.h src/libsodium/include/sodium/version.h stamp-* test/default/*.res @@ -81,3 +82,4 @@ test/default/stream2 test/default/stream3 test/default/stream4 testing + diff --git a/configure.ac b/configure.ac index a3639d5c..d1f796d3 100644 --- a/configure.ac +++ b/configure.ac @@ -165,6 +165,7 @@ return sizeof(x) / CHAR_BIT != 16U [AC_MSG_RESULT(yes) AC_DEFINE([HAVE_TI_MODE], [1], [gcc TI mode is available])], [AC_MSG_RESULT(no)]) +AC_SUBST(HAVE_TI_MODE) dnl Checks for functions and headers @@ -246,6 +247,7 @@ AC_CONFIG_FILES([Makefile src/libsodium/Makefile src/libsodium/include/Makefile src/libsodium/include/sodium/version.h + src/libsodium/include/sodium/crypto_scalarmult_curve25519.h test/default/Makefile test/Makefile ]) diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 7b64a762..41353fb8 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -17,6 +17,9 @@ libsodium_la_SOURCES = \ crypto_generichash/blake2/ref/blake2b-ref.c \ crypto_generichash/blake2/ref/blake2s-ref.c \ crypto_generichash/blake2/ref/generichash_blake2b.c \ + crypto_scalarmult/curve25519/donna_c64/api.h \ + crypto_scalarmult/curve25519/donna_c64/base_curve25519_donna_c64.c \ + crypto_scalarmult/curve25519/donna_c64/smult_curve25519_donna_c64.c \ crypto_scalarmult/curve25519/ref/api.h \ crypto_scalarmult/curve25519/ref/base_curve25519_ref.c \ crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c \ diff --git a/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c b/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c index b83e4c25..6f58df2e 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c +++ b/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c @@ -7,6 +7,8 @@ Derived from public domain code by D. J. Bernstein. #include "api.h" +#ifndef HAVE_TI_MODE + const unsigned char base[32] = {9}; int crypto_scalarmult_base(unsigned char *q, @@ -14,3 +16,5 @@ int crypto_scalarmult_base(unsigned char *q, { return crypto_scalarmult(q,n,base); } + +#endif diff --git a/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c b/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c index e4e9669a..1c82d682 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c +++ b/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c @@ -7,6 +7,8 @@ Derived from public domain code by D. J. Bernstein. #include "api.h" +#ifndef HAVE_TI_MODE + static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32]) { unsigned int j; @@ -263,3 +265,5 @@ int crypto_scalarmult(unsigned char *q, for (i = 0;i < 32;++i) q[i] = work[64 + i]; return 0; } + +#endif diff --git a/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h b/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h.in similarity index 55% rename from src/libsodium/include/sodium/crypto_scalarmult_curve25519.h rename to src/libsodium/include/sodium/crypto_scalarmult_curve25519.h.in index 9b9bd091..4cfa74bd 100644 --- a/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +++ b/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h.in @@ -1,18 +1,36 @@ #ifndef crypto_scalarmult_curve25519_H #define crypto_scalarmult_curve25519_H +#if @HAVE_TI_MODE@-1 == 0 +# define SODIUM_HAVE_TI_MODE +#endif + #define crypto_scalarmult_curve25519_BYTES 32 #define crypto_scalarmult_curve25519_SCALARBYTES 32 + #ifdef __cplusplus extern "C" { #endif + +#ifndef SODIUM_HAVE_TI_MODE + +extern int crypto_scalarmult_curve25519_donna_c64(unsigned char *,const unsigned char *,const unsigned char *); +extern int crypto_scalarmult_curve25519_donna_c64_base(unsigned char *,const unsigned char *); +#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_donna_c64 +#define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_donna_c64_base + +#else + extern int crypto_scalarmult_curve25519_ref(unsigned char *,const unsigned char *,const unsigned char *); extern int crypto_scalarmult_curve25519_ref_base(unsigned char *,const unsigned char *); -#ifdef __cplusplus -} -#endif - #define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_ref #define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_ref_base +#endif + +#ifdef __cplusplus +} +#endif + + #endif