Support Base Implementation + SIMD implementation on Solaris (PR #461)

pull/471/head
Jeffrey Walton 2017-08-24 19:17:21 -04:00
parent b57f7f0ae0
commit 5c6a32ba0f
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
6 changed files with 160 additions and 127 deletions

View File

@ -165,28 +165,22 @@ ifeq ($(IS_X86)$(IS_X32)$(IS_CYGWIN)$(IS_MINGW)$(SUN_COMPILER),00000)
endif endif
# .intel_syntax wasn't supported until GNU assembler 2.10 # .intel_syntax wasn't supported until GNU assembler 2.10
# No DISABLE_NATIVE_ARCH with CRYPTOPP_DISABLE_ASM for now
# See http://github.com/weidai11/cryptopp/issues/395
ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10) ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
DISABLE_NATIVE_ARCH := 1
else else
ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10) ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3 CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
DISABLE_NATIVE_ARCH := 1
else else
ifeq ($(HAVE_GAS)$(GAS218_OR_LATER),10) ifeq ($(HAVE_GAS)$(GAS218_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4 CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
DISABLE_NATIVE_ARCH := 1
else else
ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10) ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
DISABLE_NATIVE_ARCH := 1
else else
ifeq ($(HAVE_GAS)$(GAS223_OR_LATER),10) ifeq ($(HAVE_GAS)$(GAS223_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SHA CXXFLAGS += -DCRYPTOPP_DISABLE_SHA
DISABLE_NATIVE_ARCH := 1
endif # -DCRYPTOPP_DISABLE_SHA endif # -DCRYPTOPP_DISABLE_SHA
endif # -DCRYPTOPP_DISABLE_AESNI endif # -DCRYPTOPP_DISABLE_AESNI
endif # -DCRYPTOPP_DISABLE_SSE4 endif # -DCRYPTOPP_DISABLE_SSE4
@ -225,6 +219,30 @@ endif # -DCRYPTOPP_DISABLE_AESNI
endif # -DCRYPTOPP_DISABLE_SSE4 endif # -DCRYPTOPP_DISABLE_SSE4
endif # -DCRYPTOPP_DISABLE_SSSE3 endif # -DCRYPTOPP_DISABLE_SSSE3
# Begin SunCC
ifeq ($(SUN_COMPILER),1)
COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=ssse3 -xdumpmacros /dev/null 2>&1 | $(EGREP) -i -c "illegal value ignored")
ifeq ($(COUNT),0)
SSSE3_FLAG = -xarch=ssse3 -D__SSSE3__=1
ARIA_FLAG = -xarch=ssse3 -D__SSSE3__=1
endif
COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=sse4_2 -xdumpmacros /dev/null 2>&1 | $(EGREP) -i -c "illegal value ignored")
ifeq ($(COUNT),0)
BLAKE2_FLAG = -xarch=sse4_2 -D__SSE4_2__=1
CRC_FLAG = -xarch=sse4_2 -D__SSE4_2__=1
endif
COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=aes -xdumpmacros /dev/null 2>&1 | $(EGREP) -i -c "illegal value ignored")
ifeq ($(COUNT),0)
GCM_FLAG = -xarch=aes -D__PCLMUL__=1
AES_FLAG = -xarch=aes -D__AES__=1
endif
COUNT := $(shell $(CXX) $(CXXFLAGS) -E -xarch=sha -xdumpmacros /dev/null 2>&1 | $(EGREP) -i -c "illegal value ignored")
ifeq ($(COUNT),0)
SHA_FLAG = -xarch=sha -D__SHA__=1
endif
endif
# End SunCC
ifneq ($(INTEL_COMPILER),0) ifneq ($(INTEL_COMPILER),0)
CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180 CXXFLAGS += -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180
ifeq ($(ICC111_OR_LATER),0) ifeq ($(ICC111_OR_LATER),0)
@ -369,9 +387,6 @@ CXXFLAGS += -m64
else ifeq ($(IS_64),0) else ifeq ($(IS_64),0)
CXXFLAGS += -m32 CXXFLAGS += -m32
endif endif
ifneq ($(SUNCC_513_OR_LATER),0)
CXXFLAGS += -native
endif
# Add for non-i386 # Add for non-i386
ifneq ($(IS_X86),1) ifneq ($(IS_X86),1)
CXXFLAGS += -KPIC CXXFLAGS += -KPIC
@ -406,8 +421,12 @@ endif # No ASM
# Native build testing. Issue 'make native'. # Native build testing. Issue 'make native'.
ifeq ($(findstring native,$(MAKECMDGOALS)),native) ifeq ($(findstring native,$(MAKECMDGOALS)),native)
ifeq ($(findstring -march=native,$(CXXFLAGS)),) ifeq ($(findstring -march=native,$(CXXFLAGS)),)
ifeq ($(IS_SUN)$(SUN_COMPILER),11)
CXXFLAGS += -native
else
CXXFLAGS += -march=native CXXFLAGS += -march=native
endif # CXXFLAGS endif # CXXFLAGS
endif # Sun
endif # Native endif # Native
# Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'. # Undefined Behavior Sanitizer (UBsan) testing. Issue 'make ubsan'.

View File

@ -475,7 +475,8 @@ NAMESPACE_END
#endif #endif
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SSSE3) #if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SSSE3)
# if defined(__SSSE3__) || (_MSC_VER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40300) # if defined(__SSSE3__) || (_MSC_VER >= 1500) || (CRYPTOPP_GCC_VERSION >= 40300) || \
(__SUNPRO_CC >= 0x5110)
#define CRYPTOPP_SSSE3_AVAILABLE 1 #define CRYPTOPP_SSSE3_AVAILABLE 1
# endif # endif
#endif #endif
@ -485,34 +486,37 @@ NAMESPACE_END
// SunCC could generate SSE4 at 12.1, but the intrinsics are missing until 12.4. // SunCC could generate SSE4 at 12.1, but the intrinsics are missing until 12.4.
#if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \ #if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
(defined(__SSE4_1__) || (CRYPTOPP_MSC_VERSION >= 1500) || \ (defined(__SSE4_1__) || (CRYPTOPP_MSC_VERSION >= 1500) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || \ (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || (__SUNPRO_CC >= 0x5110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000)) (CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000))
#define CRYPTOPP_SSE41_AVAILABLE 1 #define CRYPTOPP_SSE41_AVAILABLE 1
#endif #endif
#if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \ #if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
(defined(__SSE4_2__) || (CRYPTOPP_MSC_VERSION >= 1500) || \ (defined(__SSE4_2__) || (CRYPTOPP_MSC_VERSION >= 1500) || (__SUNPRO_CC >= 0x5110) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || \ (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000)) (CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000))
#define CRYPTOPP_SSE42_AVAILABLE 1 #define CRYPTOPP_SSE42_AVAILABLE 1
#endif #endif
// Requires Sun Studio 12.3 (SunCC 0x5120)
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_CLMUL) && \ #if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_CLMUL) && \
(defined(__PCLMUL__) || (_MSC_FULL_VER >= 150030729) || \ (defined(__PCLMUL__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \ (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300)) (CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
#define CRYPTOPP_CLMUL_AVAILABLE 1 #define CRYPTOPP_CLMUL_AVAILABLE 1
#endif #endif
// Requires Sun Studio 12.3 (SunCC 0x5120)
#if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \ #if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
(defined(__AES__) || (_MSC_FULL_VER >= 150030729) || \ (defined(__AES__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \ (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300)) (CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
#define CRYPTOPP_AESNI_AVAILABLE 1 #define CRYPTOPP_AESNI_AVAILABLE 1
#endif #endif
// Guessing at SHA for SunCC
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SHA) && \ #if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SHA) && \
(defined(__SHA__) || (CRYPTOPP_MSC_VERSION >= 1900) || \ (defined(__SHA__) || (CRYPTOPP_MSC_VERSION >= 1900) || (__SUNPRO_CC >= 0x5150) || \
(CRYPTOPP_GCC_VERSION >= 40900) || (__INTEL_COMPILER >= 1300) || \ (CRYPTOPP_GCC_VERSION >= 40900) || (__INTEL_COMPILER >= 1300) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30400) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50100)) (CRYPTOPP_LLVM_CLANG_VERSION >= 30400) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50100))
#define CRYPTOPP_SHANI_AVAILABLE 1 #define CRYPTOPP_SHANI_AVAILABLE 1

View File

@ -19,6 +19,12 @@
# undef CRYPTOPP_SSE2_ASM_AVAILABLE # undef CRYPTOPP_SSE2_ASM_AVAILABLE
#endif #endif
// SunCC 12.3 and 12.4 crash in GCM_Reduce_CLMUL
// http://github.com/weidai11/cryptopp/issues/226
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5130)
# undef CRYPTOPP_CLMUL_AVAILABLE
#endif
// Clang and GCC hoops... // Clang and GCC hoops...
#if !(defined(__ARM_FEATURE_CRYPTO) || defined(_MSC_VER)) #if !(defined(__ARM_FEATURE_CRYPTO) || defined(_MSC_VER))
# undef CRYPTOPP_ARM_PMULL_AVAILABLE # undef CRYPTOPP_ARM_PMULL_AVAILABLE

10
gcm.cpp
View File

@ -21,11 +21,11 @@
# undef CRYPTOPP_SSE2_ASM_AVAILABLE # undef CRYPTOPP_SSE2_ASM_AVAILABLE
#endif #endif
// SunCC 5.13 and below crash with AES-NI/CLMUL and C++{03|11}. Disable one or the other. // SunCC 12.3 and 12.4 crash in GCM_Reduce_CLMUL
// Also see http://github.com/weidai11/cryptopp/issues/226 // http://github.com/weidai11/cryptopp/issues/226
// #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x513) #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5130)
// # undef CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE # undef CRYPTOPP_CLMUL_AVAILABLE
// #endif #endif
#include "gcm.h" #include "gcm.h"
#include "cpu.h" #include "cpu.h"

View File

@ -52,8 +52,10 @@
// Hack for SunCC, http://github.com/weidai11/cryptopp/issues/224 // Hack for SunCC, http://github.com/weidai11/cryptopp/issues/224
#if (__SUNPRO_CC >= 0x5130) #if (__SUNPRO_CC >= 0x5130)
# define MAYBE_CONST # define MAYBE_CONST
# define MAYBE_UNCONST_CAST(T, x) const_cast<MAYBE_CONST T>(x)
#else #else
# define MAYBE_CONST const # define MAYBE_CONST const
# define MAYBE_UNCONST_CAST(T, x) (x)
#endif #endif
// Clang __m128i casts, http://bugs.llvm.org/show_bug.cgi?id=20670 // Clang __m128i casts, http://bugs.llvm.org/show_bug.cgi?id=20670
@ -627,18 +629,27 @@ inline size_t Rijndael_AdvancedProcessBlocks_AESNI(F1 func1, F4 func4,
return length; return length;
} }
size_t Rijndael_Enc_AdvancedProcessBlocks_AESNI(MAYBE_CONST word32 *subKeys, size_t rounds, size_t Rijndael_Enc_AdvancedProcessBlocks_AESNI(const word32 *subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags)
{ {
// SunCC workaround
MAYBE_CONST word32* sk = MAYBE_UNCONST_CAST(word32*, subKeys);
MAYBE_CONST byte* ib = MAYBE_UNCONST_CAST(byte*, inBlocks);
MAYBE_CONST byte* xb = MAYBE_UNCONST_CAST(byte*, xorBlocks);
return Rijndael_AdvancedProcessBlocks_AESNI(AESNI_Enc_Block, AESNI_Enc_4_Blocks, return Rijndael_AdvancedProcessBlocks_AESNI(AESNI_Enc_Block, AESNI_Enc_4_Blocks,
subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags); sk, rounds, ib, xb, outBlocks, length, flags);
} }
size_t Rijndael_Dec_AdvancedProcessBlocks_AESNI(MAYBE_CONST word32 *subKeys, size_t rounds, size_t Rijndael_Dec_AdvancedProcessBlocks_AESNI(const word32 *subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags)
{ {
MAYBE_CONST word32* sk = MAYBE_UNCONST_CAST(word32*, subKeys);
MAYBE_CONST byte* ib = MAYBE_UNCONST_CAST(byte*, inBlocks);
MAYBE_CONST byte* xb = MAYBE_UNCONST_CAST(byte*, xorBlocks);
return Rijndael_AdvancedProcessBlocks_AESNI(AESNI_Dec_Block, AESNI_Dec_4_Blocks, return Rijndael_AdvancedProcessBlocks_AESNI(AESNI_Dec_Block, AESNI_Dec_4_Blocks,
subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags); sk, rounds, ib, xb, outBlocks, length, flags);
} }
void Rijndael_UncheckedSetKey_SSE4_AESNI(const byte *userKey, size_t keyLen, word32 *rk) void Rijndael_UncheckedSetKey_SSE4_AESNI(const byte *userKey, size_t keyLen, word32 *rk)

View File

@ -90,13 +90,6 @@ NAMESPACE_BEGIN(CryptoPP)
# define CRYPTOPP_ALLOW_RIJNDAEL_UNALIGNED_DATA_ACCESS 1 # define CRYPTOPP_ALLOW_RIJNDAEL_UNALIGNED_DATA_ACCESS 1
#endif #endif
// Hack for SunCC, http://github.com/weidai11/cryptopp/issues/224
#if (__SUNPRO_CC >= 0x5130)
# define MAYBE_CONST
#else
# define MAYBE_CONST const
#endif
// Clang __m128i casts // Clang __m128i casts
#define M128I_CAST(x) ((__m128i *)(void *)(x)) #define M128I_CAST(x) ((__m128i *)(void *)(x))
#define CONST_M128I_CAST(x) ((const __m128i *)(const void *)(x)) #define CONST_M128I_CAST(x) ((const __m128i *)(const void *)(x))