diff --git a/configure.ac b/configure.ac index c2427d5b..d94f7bdb 100644 --- a/configure.ac +++ b/configure.ac @@ -211,9 +211,6 @@ AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"]) AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"]) AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"]) -AC_MSG_CHECKING([Checking if we can compile for westmere]) -AX_CHECK_COMPILE_FLAG([-march=westmere $CFLAGS], [CFLAGS="-march=westmere $CFLAGS"]) - AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings]) AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"]) @@ -301,6 +298,23 @@ AS_IF([test "x$EMSCRIPTEN" = "x"],[ [AC_MSG_RESULT(yes) AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])], [AC_MSG_RESULT(no)]) + + AC_MSG_CHECKING(for AESNI instructions set and PCLMULQDQ) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#pragma GCC target("aes") +#pragma GCC target("pclmul") +#ifndef __AES__ +# define __AES__ +#endif +#ifndef __PCLMUL__ +# define __PCLMUL__ +#endif +#include +]], [[ __m128i x = _mm_aesimc_si128(_mm_setzero_si128()); + __m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);]])], + [AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_WMMINTRIN_H], [1], [aesni is available])], + [AC_MSG_RESULT(no)]) ]) AC_CHECK_HEADERS([sys/mman.h]) 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 4643b0ba..e17c78c0 100644 --- a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +++ b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -3,6 +3,23 @@ * AES256-GCM, based on original code by Romain Dolbeau */ +#pragma GCC target("sse") +#pragma GCC target("sse2") +#pragma GCC target("ssse3") +#pragma GCC target("sse4.1") +#pragma GCC target("aes") +#pragma GCC target("pclmul") + +#ifndef __SSE4_1__ +# define __SSE4_1__ +#endif +#ifndef __AES__ +# define __AES__ +#endif +#ifndef __PCLMUL__ +# define __PCLMUL__ +#endif + #include #include #include diff --git a/src/libsodium/include/sodium/runtime.h b/src/libsodium/include/sodium/runtime.h index 50226ae1..3bdc4dcd 100644 --- a/src/libsodium/include/sodium/runtime.h +++ b/src/libsodium/include/sodium/runtime.h @@ -20,6 +20,12 @@ int sodium_runtime_has_sse2(void); SODIUM_EXPORT int sodium_runtime_has_sse3(void); +SODIUM_EXPORT +int sodium_runtime_has_pclmul(void); + +SODIUM_EXPORT +int sodium_runtime_has_aesni(void); + #ifdef __cplusplus } #endif diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index 93b07932..2cf915c8 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -10,12 +10,16 @@ typedef struct CPUFeatures_ { int has_neon; int has_sse2; int has_sse3; + int has_pclmul; + int has_aesni; } CPUFeatures; static CPUFeatures _cpu_features; -#define CPUID_SSE2 0x04000000 -#define CPUIDECX_SSE3 0x00000001 +#define CPUID_SSE2 0x04000000 +#define CPUIDECX_SSE3 0x00000001 +#define CPUIDECX_PCLMUL 0x00000002 +#define CPUIDECX_AESNI 0x02000000 static int _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) @@ -104,6 +108,14 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features) cpu_features->has_sse3 = ((cpu_info[2] & CPUIDECX_SSE3) != 0x0); #endif +#ifndef HAVE_WMMINTRIN_H + cpu_features->has_pclmul = 0; + cpu_features->has_aesni = 0; +#else + cpu_features->has_pclmul = ((cpu_info[2] & CPUIDECX_PCLMUL) != 0x0); + cpu_features->has_aesni = ((cpu_info[2] & CPUIDECX_AESNI) != 0x0); +#endif + return 0; } @@ -133,3 +145,13 @@ int sodium_runtime_has_sse3(void) { return _cpu_features.has_sse3; } + +int +sodium_runtime_has_pclmul(void) { + return _cpu_features.has_pclmul; +} + +int +sodium_runtime_has_aesni(void) { + return _cpu_features.has_aesni; +}