From 513363802494622952043bef026da68c9ceef64d Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 11 Dec 2013 19:45:11 -0800 Subject: [PATCH] Make crypto_stream_salsa20.h architecture-independent. Move implementation-specific functions to compat.c --- .gitignore | 1 - configure.ac | 1 - msvc-scripts/process.bat | 2 - src/libsodium/include/Makefile.am | 2 +- ...m_salsa20.h.in => crypto_stream_salsa20.h} | 14 ------ src/libsodium/sodium/compat.c | 43 +++++++++++++++++++ 6 files changed, 44 insertions(+), 19 deletions(-) rename src/libsodium/include/sodium/{crypto_stream_salsa20.h.in => crypto_stream_salsa20.h} (72%) diff --git a/.gitignore b/.gitignore index 64e2d1c3..2dec01a2 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,6 @@ src/curvecp/curvecpprintkey src/curvecp/curvecpserver src/libsodium/*.def src/libsodium/include/sodium/crypto_scalarmult_curve25519.h -src/libsodium/include/sodium/crypto_stream_salsa20.h src/libsodium/include/sodium/version.h stamp-* test/default/*.res diff --git a/configure.ac b/configure.ac index b0244aa2..f9d57d8c 100644 --- a/configure.ac +++ b/configure.ac @@ -398,7 +398,6 @@ AC_CONFIG_FILES([Makefile src/libsodium/include/Makefile src/libsodium/include/sodium/version.h src/libsodium/include/sodium/crypto_scalarmult_curve25519.h - src/libsodium/include/sodium/crypto_stream_salsa20.h test/default/Makefile test/Makefile ]) diff --git a/msvc-scripts/process.bat b/msvc-scripts/process.bat index 6db0c3df..0f3381e6 100755 --- a/msvc-scripts/process.bat +++ b/msvc-scripts/process.bat @@ -1,7 +1,5 @@ cscript msvc-scripts/rep.vbs //Nologo s/@HAVE_TI_MODE_V@/0/ < src\libsodium\include\sodium\crypto_scalarmult_curve25519.h.in > src\libsodium\include\sodium\crypto_scalarmult_curve25519.h -cscript msvc-scripts/rep.vbs //Nologo s/@HAVE_AMD64_ASM_V@/0/ < src\libsodium\include\sodium\crypto_stream_salsa20.h.in > src\libsodium\include\sodium\crypto_stream_salsa20.h - cscript msvc-scripts/rep.vbs //Nologo s/@VERSION@/0.4.5/ < src\libsodium\include\sodium\version.h.in > tmp cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MAJOR@/4/ < tmp > tmp2 cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MINOR@/4/ < tmp2 > src\libsodium\include\sodium\version.h diff --git a/src/libsodium/include/Makefile.am b/src/libsodium/include/Makefile.am index dbbc9da5..5c5bee14 100644 --- a/src/libsodium/include/Makefile.am +++ b/src/libsodium/include/Makefile.am @@ -33,6 +33,7 @@ SODIUM_EXPORT = \ sodium/crypto_stream.h \ sodium/crypto_stream_aes128ctr.h \ sodium/crypto_stream_aes256estream.h \ + sodium/crypto_stream_salsa20.h \ sodium/crypto_stream_salsa2012.h \ sodium/crypto_stream_salsa208.h \ sodium/crypto_stream_xsalsa20.h \ @@ -52,7 +53,6 @@ SODIUM_EXPORT = \ EXTRA_SRC = $(SODIUM_EXPORT) \ sodium/crypto_scalarmult_curve25519.h.in \ - sodium/crypto_stream_salsa20.h.in \ sodium/version.h.in nobase_include_HEADERS = $(SODIUM_EXPORT) diff --git a/src/libsodium/include/sodium/crypto_stream_salsa20.h.in b/src/libsodium/include/sodium/crypto_stream_salsa20.h similarity index 72% rename from src/libsodium/include/sodium/crypto_stream_salsa20.h.in rename to src/libsodium/include/sodium/crypto_stream_salsa20.h index b55e0ef3..5e807a38 100644 --- a/src/libsodium/include/sodium/crypto_stream_salsa20.h.in +++ b/src/libsodium/include/sodium/crypto_stream_salsa20.h @@ -9,12 +9,6 @@ * the crypto_box functions. */ -#if @HAVE_AMD64_ASM_V@ -# ifndef SODIUM_HAVE_AMD64_ASM -# define SODIUM_HAVE_AMD64_ASM -# endif -#endif - #include #include "export.h" @@ -39,14 +33,6 @@ int crypto_stream_salsa20(unsigned char *,unsigned long long,const unsigned char SODIUM_EXPORT int crypto_stream_salsa20_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *); -#ifdef SODIUM_HAVE_AMD64_ASM -# define crypto_stream_salsa20_amd64_xmm6 crypto_stream_salsa20 -# define crypto_stream_salsa20_amd64_xmm6_xor crypto_stream_salsa20_xor -#else -# define crypto_stream_salsa20_ref crypto_stream_salsa20 -# define crypto_stream_salsa20_ref_xor crypto_stream_salsa20_xor -#endif - #ifdef __cplusplus } #endif diff --git a/src/libsodium/sodium/compat.c b/src/libsodium/sodium/compat.c index a2067744..44e8dd07 100644 --- a/src/libsodium/sodium/compat.c +++ b/src/libsodium/sodium/compat.c @@ -8,6 +8,7 @@ #include "crypto_scalarmult_curve25519.h" #include "crypto_secretbox_xsalsa20poly1305.h" #include "crypto_sign_ed25519.h" +#include "crypto_stream_salsa20.h" #include "crypto_stream_xsalsa20.h" #include "crypto_verify_16.h" #include "crypto_verify_32.h" @@ -243,6 +244,48 @@ crypto_onetimeauth_poly1305_ref(unsigned char *out, return crypto_onetimeauth_poly1305(out, in, inlen, k); } +#undef crypto_stream_salsa20_amd64_xmm6 +SODIUM_EXPORT int +crypto_stream_salsa20_amd64_xmm6(unsigned char *c, + unsigned long long clen, + const unsigned char *n, + const unsigned char *k) +{ + return crypto_stream_salsa20(c, clen, n, k); +} + +#undef crypto_stream_salsa20_ref +SODIUM_EXPORT int +crypto_stream_salsa20_ref(unsigned char *c, + unsigned long long clen, + const unsigned char *n, + const unsigned char *k) +{ + return crypto_stream_salsa20(c, clen, n, k); +} + +#undef crypto_stream_salsa20_amd64_xmm6_xor +SODIUM_EXPORT int +crypto_stream_salsa20_amd64_xmm6_xor(unsigned char *c, + const unsigned char *m, + unsigned long long mlen, + const unsigned char *n, + const unsigned char *k) +{ + return crypto_stream_salsa20_xor(c, m, mlen, n, k); +} + +#undef crypto_stream_salsa20_ref_xor +SODIUM_EXPORT int +crypto_stream_salsa20_ref_xor(unsigned char *c, + const unsigned char *m, + unsigned long long mlen, + const unsigned char *n, + const unsigned char *k) +{ + return crypto_stream_salsa20_xor(c, m, mlen, n, k); +} + #ifdef __cplusplus } #endif