From b3e27d14aaa0130b90739addb84d733f654e96bd Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 5 Mar 2017 23:44:51 +0100 Subject: [PATCH] Move 64-bit emulation to a dedicated private header file --- .../msvc/vs2010/libsodium/libsodium.vcxproj | 2 +- .../libsodium/libsodium.vcxproj.filters | 6 +-- .../msvc/vs2012/libsodium/libsodium.vcxproj | 2 +- .../libsodium/libsodium.vcxproj.filters | 6 +-- .../msvc/vs2013/libsodium/libsodium.vcxproj | 2 +- .../libsodium/libsodium.vcxproj.filters | 6 +-- .../msvc/vs2015/libsodium/libsodium.vcxproj | 2 +- .../libsodium/libsodium.vcxproj.filters | 6 +-- libsodium.vcxproj | 2 +- libsodium.vcxproj.filters | 6 +-- src/libsodium/Makefile.am | 1 + .../aes256gcm/aesni/aead_aes256gcm_aesni.c | 1 + .../blake2b/ref/blake2b-compress-avx2.c | 1 + .../blake2b/ref/blake2b-compress-sse41.c | 1 + .../blake2b/ref/blake2b-compress-ssse3.c | 1 + .../poly1305/sse2/poly1305_sse2.c | 1 + .../argon2/argon2-fill-block-ssse3.c | 1 + .../crypto_pwhash/argon2/blamka-round-ssse3.h | 1 + .../sse/pwhash_scryptsalsa208sha256_sse.c | 1 + .../chacha20/dolbeau/chacha20_dolbeau-avx2.c | 1 + .../chacha20/dolbeau/chacha20_dolbeau-ssse3.c | 1 + .../salsa20/xmm6int/salsa20_xmm6int-avx2.c | 1 + .../salsa20/xmm6int/salsa20_xmm6int-sse2.c | 1 + src/libsodium/include/sodium/private/common.h | 39 --------------- .../include/sodium/private/sse2_64_32.h | 49 +++++++++++++++++++ 25 files changed, 82 insertions(+), 59 deletions(-) create mode 100644 src/libsodium/include/sodium/private/sse2_64_32.h diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj b/builds/msvc/vs2010/libsodium/libsodium.vcxproj index d161bc20..f4f9a0a9 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj @@ -302,10 +302,10 @@ - + diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters index dfc0aba1..63b37dd9 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters @@ -692,9 +692,6 @@ include\sodium - - include\sodium - include\sodium\private @@ -704,6 +701,9 @@ include\sodium\private + + include\sodium\private + diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj b/builds/msvc/vs2012/libsodium/libsodium.vcxproj index 3f75c276..172ae2f4 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj @@ -302,10 +302,10 @@ - + diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters index dfc0aba1..63b37dd9 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters @@ -692,9 +692,6 @@ include\sodium - - include\sodium - include\sodium\private @@ -704,6 +701,9 @@ include\sodium\private + + include\sodium\private + diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj b/builds/msvc/vs2013/libsodium/libsodium.vcxproj index 18a10d48..45b3701e 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj @@ -302,10 +302,10 @@ - + diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters index dfc0aba1..63b37dd9 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters @@ -692,9 +692,6 @@ include\sodium - - include\sodium - include\sodium\private @@ -704,6 +701,9 @@ include\sodium\private + + include\sodium\private + diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj b/builds/msvc/vs2015/libsodium/libsodium.vcxproj index fe7bd093..d038ee7d 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj @@ -302,10 +302,10 @@ - + diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters index dfc0aba1..63b37dd9 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters @@ -692,9 +692,6 @@ include\sodium - - include\sodium - include\sodium\private @@ -704,6 +701,9 @@ include\sodium\private + + include\sodium\private + diff --git a/libsodium.vcxproj b/libsodium.vcxproj index 1aa5d6b6..845df9d2 100644 --- a/libsodium.vcxproj +++ b/libsodium.vcxproj @@ -540,10 +540,10 @@ - + diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters index 10e1df2a..fcfaa2db 100644 --- a/libsodium.vcxproj.filters +++ b/libsodium.vcxproj.filters @@ -686,9 +686,6 @@ Header Files - - Header Files - Header Files @@ -698,5 +695,8 @@ Header Files + + Header Files + diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 30c18a24..87d2ed2c 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -89,6 +89,7 @@ libsodium_la_SOURCES = \ include/sodium/private/common.h \ include/sodium/private/curve25519_ref10.h \ include/sodium/private/mutex.h \ + include/sodium/private/sse2_64_32.h \ randombytes/randombytes.c \ sodium/core.c \ sodium/runtime.c \ diff --git a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c index e3ad7c06..d21f3173 100644 --- a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +++ b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -13,6 +13,7 @@ #include "crypto_aead_aes256gcm.h" #include "export.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "randombytes.h" #include "runtime.h" #include "utils.h" diff --git a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c index d57ef7b8..50a21a81 100644 --- a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c +++ b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c @@ -8,6 +8,7 @@ #include "blake2.h" #include "private/common.h" +#include "private/sse2_64_32.h" #if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H) diff --git a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c index 535d925e..8daf06ee 100644 --- a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c +++ b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c @@ -7,6 +7,7 @@ #include "blake2.h" #include "private/common.h" +#include "private/sse2_64_32.h" #if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && \ defined(HAVE_SMMINTRIN_H) diff --git a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c index 14f5eb67..1dd2f4c2 100644 --- a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c +++ b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c @@ -4,6 +4,7 @@ #include "blake2.h" #include "private/common.h" +#include "private/sse2_64_32.h" #if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) diff --git a/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c b/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c index 41796d78..f39242de 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c @@ -6,6 +6,7 @@ #include "crypto_verify_16.h" #include "poly1305_sse2.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "utils.h" #if defined(HAVE_TI_MODE) && defined(HAVE_EMMINTRIN_H) diff --git a/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c b/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c index b72f8263..c9098f71 100644 --- a/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +++ b/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c @@ -18,6 +18,7 @@ #include "argon2-core.h" #include "argon2.h" #include "private/common.h" +#include "private/sse2_64_32.h" #if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) diff --git a/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h b/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h index b9e8f94b..98a47b93 100644 --- a/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h +++ b/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h @@ -2,6 +2,7 @@ #define blamka_round_ssse3_H #include "private/common.h" +#include "private/sse2_64_32.h" #define r16 \ (_mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9)) diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 309546ef..0eb802e4 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -35,6 +35,7 @@ #include #include "private/common.h" +#include "private/sse2_64_32.h" #ifdef HAVE_EMMINTRIN_H diff --git a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c index 5ab2b9b3..c8cdff37 100644 --- a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +++ b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c @@ -5,6 +5,7 @@ #include "crypto_stream_chacha20.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "utils.h" #if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ diff --git a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c index a9e728c5..06895932 100644 --- a/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +++ b/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c @@ -5,6 +5,7 @@ #include "crypto_stream_chacha20.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "utils.h" #if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) diff --git a/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c b/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c index 1378c516..18d4773e 100644 --- a/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c +++ b/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c @@ -5,6 +5,7 @@ #include "crypto_stream_salsa20.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "utils.h" #if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ diff --git a/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c b/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c index e27b591a..d8e53a65 100644 --- a/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c +++ b/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c @@ -5,6 +5,7 @@ #include "crypto_stream_salsa20.h" #include "private/common.h" +#include "private/sse2_64_32.h" #include "utils.h" #ifdef HAVE_EMMINTRIN_H diff --git a/src/libsodium/include/sodium/private/common.h b/src/libsodium/include/sodium/private/common.h index b3a8f0ba..5e27e574 100644 --- a/src/libsodium/include/sodium/private/common.h +++ b/src/libsodium/include/sodium/private/common.h @@ -214,43 +214,4 @@ store32_be(uint8_t dst[4], uint32_t w) # include #endif -#if defined(HAVE_EMMINTRIN_H) && \ - !(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || \ - defined(_M_X64) || defined(_M_AMD64)) - -# include - -# ifndef _mm_set_epi64x -# define _mm_set_epi64x(Q0, Q1) sodium__mm_set_epi64x((Q0), (Q1)) -static inline __m128i -sodium__mm_set_epi64x(int64_t q1, int64_t q0) -{ - union { int64_t as64; int32_t as32[2]; } x0, x1; - x0.as64 = q0; x1.as64 = q1; - return _mm_set_epi32(x1.as32[1], x1.as32[0], x0.as32[1], x0.as32[0]); -} -# endif - -# ifndef _mm_set1_epi64x -# define _mm_set1_epi64x(Q) sodium__mm_set1_epi64x(Q) -static inline __m128i -sodium__mm_set1_epi64x(int64_t q) -{ - return _mm_set_epi64x(q, q); -} -# endif - -# ifndef _mm_cvtsi64_si128 -# define _mm_cvtsi64_si128(Q) sodium__mm_cvtsi64_si128(Q) -static inline __m128i -sodium__mm_cvtsi64_si128(int64_t q) -{ - union { int64_t as64; int32_t as32[2]; } x; - x.as64 = q; - return _mm_setr_epi32(x.as32[0], x.as32[1], 0, 0); -} -# endif - -#endif - #endif diff --git a/src/libsodium/include/sodium/private/sse2_64_32.h b/src/libsodium/include/sodium/private/sse2_64_32.h new file mode 100644 index 00000000..6ca346f5 --- /dev/null +++ b/src/libsodium/include/sodium/private/sse2_64_32.h @@ -0,0 +1,49 @@ +#ifndef sse2_64_32_H +#define sse2_64_32_H 1 + +#include "common.h" + +#ifdef HAVE_INTRIN_H +# include +#endif + +#if defined(HAVE_EMMINTRIN_H) && \ + !(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || \ + defined(_M_X64) || defined(_M_AMD64)) + +# include + +# ifndef _mm_set_epi64x +# define _mm_set_epi64x(Q0, Q1) sodium__mm_set_epi64x((Q0), (Q1)) +static inline __m128i +sodium__mm_set_epi64x(int64_t q1, int64_t q0) +{ + union { int64_t as64; int32_t as32[2]; } x0, x1; + x0.as64 = q0; x1.as64 = q1; + return _mm_set_epi32(x1.as32[1], x1.as32[0], x0.as32[1], x0.as32[0]); +} +# endif + +# ifndef _mm_set1_epi64x +# define _mm_set1_epi64x(Q) sodium__mm_set1_epi64x(Q) +static inline __m128i +sodium__mm_set1_epi64x(int64_t q) +{ + return _mm_set_epi64x(q, q); +} +# endif + +# ifndef _mm_cvtsi64_si128 +# define _mm_cvtsi64_si128(Q) sodium__mm_cvtsi64_si128(Q) +static inline __m128i +sodium__mm_cvtsi64_si128(int64_t q) +{ + union { int64_t as64; int32_t as32[2]; } x; + x.as64 = q; + return _mm_setr_epi32(x.as32[0], x.as32[1], 0, 0); +} +# endif + +#endif + +#endif