From a11985e6e464043268427d34ada6b55aed76f688 Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 4 Sep 2016 13:47:39 +0200 Subject: [PATCH 1/6] Update seckey.h See https://github.com/weidai11/cryptopp/issues/252 --- seckey.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/seckey.h b/seckey.h index a08eedee..3afc3b9d 100644 --- a/seckey.h +++ b/seckey.h @@ -194,12 +194,9 @@ public: //! \details keylength is provided in bytes, not bits. static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) { -#if MIN_KEYLENGTH > 0 if (keylength < (size_t)MIN_KEYLENGTH) return MIN_KEYLENGTH; - else -#endif - if (keylength > (size_t)MAX_KEYLENGTH) + else if (keylength > (size_t)MAX_KEYLENGTH) return (size_t)MAX_KEYLENGTH; else { From 262d125fb2bb0718896dc792305dcee2424cd02a Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 4 Sep 2016 14:10:43 +0200 Subject: [PATCH 2/6] Update seckey.h InvalidRounds expects a std::string, so it can be constructed in-place and the `__BORLANDC__` define can be removed. --- seckey.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/seckey.h b/seckey.h index 3afc3b9d..8a801306 100644 --- a/seckey.h +++ b/seckey.h @@ -80,16 +80,16 @@ protected: //! \throws InvalidRounds if the number of rounds are invalid inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg) { -#if defined(__BORLANDC__) - if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); -#elif (M==INT_MAX) // Coverity and result_independent_of_operands - if (rounds < MIN_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : "VariableRounds", rounds); -#else - if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : "VariableRounds", rounds); -#endif + if (M == INT_MAX) // Coverity and result_independent_of_operands + { + if (rounds < MIN_ROUNDS) + throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); + } + else + { + if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) + throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); + } } //! \brief Validates the number of rounds for an algorithm From cc1fe049cdfb235e03f80d794399ecef9879bb92 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 4 Sep 2016 12:22:48 -0400 Subject: [PATCH 3/6] Added test for "rotate immediate" code generation using SHA --- cryptest.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/cryptest.sh b/cryptest.sh index 09209dfe..c6a613cf 100755 --- a/cryptest.sh +++ b/cryptest.sh @@ -1060,6 +1060,51 @@ echo "Start time: $TEST_BEGIN" | tee -a "$TEST_RESULTS" # X86 code generation tests if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; then + ############################################ + # X86 rotate immediate code generation + + X86_ROTATE_IMM=1 + if [[ ("$X86_ROTATE_IMM" -ne "0") ]]; then + echo + echo "************************************" | tee -a "$TEST_RESULTS" + echo "Testing: X86 rotate immediate code generation" | tee -a "$TEST_RESULTS" + echo + + OBJFILE=sha.o; rm -f "$OBJFILE" 2>/dev/null + CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS" + + DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null) + + X86_SSE2=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c sse2) + X86_SHA256_HASH_BLOCKS=$(echo -n "$DISASS_TEXT" | "$EGREP" -c 'X86_SHA256_HashBlocks') + if [[ ("$X86_SHA256_HASH_BLOCKS" -ne "0") ]]; then + COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(rol.*0x|ror.*0x)') + if [[ ("$COUNT" -le "600") ]]; then + FAILED=1 + echo "ERROR: failed to generate rotate immediate instruction (X86_SHA256_HashBlocks)" | tee -a "$TEST_RESULTS" + fi + else + COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(rol.*0x|ror.*0x)') + if [[ ("$COUNT" -le "1000") ]]; then + FAILED=1 + echo "ERROR: failed to generate rotate immediate instruction" | tee -a "$TEST_RESULTS" + fi + fi + + if [[ ("$X86_SSE2" -ne "0" && "$X86_SHA256_HASH_BLOCKS" -eq "0") ]]; then + echo "ERROR: failed to use X86_SHA256_HashBlocks" | tee -a "$TEST_RESULTS" + if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then + echo "This could be due to Clang and lack of expected support for Intel assembly syntax in some versions of the compiler" + fi + fi + + if [[ ("$FAILED" -eq "0" && "$X86_SHA256_HASH_BLOCKS" -ne "0") ]]; then + echo "Verified rotate immediate machine instructions (X86_SHA256_HashBlocks)" | tee -a "$TEST_RESULTS" + elif [[ ("$FAILED" -eq "0") ]]; then + echo "Verified rotate immediate machine instructions" | tee -a "$TEST_RESULTS" + fi + fi + ############################################ # Test AES-NI code generation @@ -1113,7 +1158,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; t echo "ERROR: failed to generate aeskeygenassist instruction" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified aesenc, aesenclast, aesdec, aesdeclast, aesimc, aeskeygenassist machine instructions" | tee -a "$TEST_RESULTS" else if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then @@ -1151,7 +1196,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; t echo "ERROR: failed to generate pclmullqlq instruction" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified pclmullqhq and pclmullqlq machine instructions" | tee -a "$TEST_RESULTS" else if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then @@ -1194,7 +1239,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; t fi fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified rdrand and rdseed machine instructions" | tee -a "$TEST_RESULTS" else if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then @@ -1232,7 +1277,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; t echo "ERROR: failed to generate crc32b instruction" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified crc32l and crc32b machine instructions" | tee -a "$TEST_RESULTS" else if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then @@ -1294,7 +1339,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0")) ] echo "ERROR: failed to generate expected vector xor instructions" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified vector load, store, add, xor machine instructions" | tee -a "$TEST_RESULTS" fi fi @@ -1328,7 +1373,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0")) ] echo "ERROR: failed to generate pmull2 instruction" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified pmull and pmull2 machine instructions" | tee -a "$TEST_RESULTS" fi fi @@ -1374,7 +1419,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0")) ] echo "ERROR: failed to generate crc32w instruction" | tee -a "$TEST_RESULTS" fi - if [[ ("$FAILED" -eq "0") ]];then + if [[ ("$FAILED" -eq "0") ]]; then echo "Verified crc32cb, crc32cw, crc32b and crc32w machine instructions" | tee -a "$TEST_RESULTS" fi fi From 741d205592133d25b64446e07f02c11c9e325f98 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 4 Sep 2016 13:22:37 -0400 Subject: [PATCH 4/6] Removed Clang version information from message since its not affected by the version --- cryptest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptest.sh b/cryptest.sh index c6a613cf..e3970a1d 100755 --- a/cryptest.sh +++ b/cryptest.sh @@ -1093,7 +1093,7 @@ if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; t if [[ ("$X86_SSE2" -ne "0" && "$X86_SHA256_HASH_BLOCKS" -eq "0") ]]; then echo "ERROR: failed to use X86_SHA256_HashBlocks" | tee -a "$TEST_RESULTS" - if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then + if [[ ("$CLANG_COMPILER" -ne "0") ]]; then echo "This could be due to Clang and lack of expected support for Intel assembly syntax in some versions of the compiler" fi fi From 60911fe235917b9c8505583598a427ff5f1a4b38 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 4 Sep 2016 16:25:11 -0400 Subject: [PATCH 5/6] Add X86 ADX feature flag detection for adcx/adox --- cryptest.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cryptest.sh b/cryptest.sh index e3970a1d..9626bc67 100755 --- a/cryptest.sh +++ b/cryptest.sh @@ -922,6 +922,7 @@ if [[ (("$IS_X86" -ne "0" || "$IS_X64" -ne "0") && ("$CLANG_COMPILER" -ne "0" && if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mavx2"); fi if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mbmi"); fi if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mbmi2"); fi + if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "adx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-madx"); fi fi # Sun Studio 12.1 (and above) compilers consume GCC inline assembly. However, the compiler does not declare @@ -941,6 +942,7 @@ if [[ ("$IS_X86" -ne "0" || "$IS_X64" -ne "0") && ("$IS_SOLARIS" -ne "0") && ("$ if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__AVX2__"); fi if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__BMI__"); fi if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__BMI2__"); fi + if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "adx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__ADX__"); fi fi # Please, someone put an end to the madness of determining Features, FPU, ABI, hard floats and soft floats... From 6df846ffec9fb0c0c0aeece686876072ccedafd0 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 5 Sep 2016 00:27:17 -0400 Subject: [PATCH 6/6] Add header for C++{03|11|14|17} testing Added after testing revealed Clang 3.6 claimed to support C++14, but it failed to compile a program that included . Also see http://bugs.launchpad.net/ubuntu/+bug/1620181 --- adhoc.cpp.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/adhoc.cpp.proto b/adhoc.cpp.proto index fce6878c..f150126f 100644 --- a/adhoc.cpp.proto +++ b/adhoc.cpp.proto @@ -1,5 +1,6 @@ #include "config.h" #include +#include #if CRYPTOPP_MSC_VERSION # pragma warning(disable: 4100 4189 4996)