From b57f7f0ae01b0b076fbec13b63ce78ac3cc87b78 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 24 Aug 2017 07:26:14 -0400 Subject: [PATCH] Rollup CMake fixes for OpenBSD, MinGW (Issues 380, 466-468, PR #469) Rollup CMake fixes for OpenBSD (Issues 467-468) Rollup CMake fixes for MinGW (Issues 466) Add CRYPTOPP_ENABLE_ARCH (Issue 380) --- CMakeLists.txt | 110 +++++++++++++++++++++++++++++++++++++------------ GNUmakefile | 4 +- Readme.txt | 18 ++++---- 3 files changed, 94 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa26069c..f12a597e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,9 @@ cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) project(cryptopp) # Make RelWithDebInfo the default (it does e.g. add '-O2 -g -DNDEBUG' for GNU) -# If not in multi-configuration environments, no explicit build type or CXX +# If not in multi-configuration environments, no explicit build type or CXX # flags are set by the user and if we are the root CMakeLists.txt file. -if (NOT CMAKE_CONFIGURATION_TYPES AND +if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_NO_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS AND @@ -46,6 +46,7 @@ option(DISABLE_SSSE3 "Disable SSSE3" OFF) option(DISABLE_SSE4 "Disable SSE4" OFF) option(DISABLE_AESNI "Disable AES-NI" OFF) option(DISABLE_SHA "Disable SHA" OFF) +option(CRYPTOPP_NATIVE_ARCH "Enable native architecture" OFF) set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory") #============================================================================ @@ -94,6 +95,8 @@ if(NOT CRYPTOPP_DATA_DIR STREQUAL "") add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}") endif() +# CRYPTOPP_NATIVE_ARCH is set below once we know what it means to be "native" + ############################################################################### # Begin JW hack @@ -103,6 +106,11 @@ endif() set(SHELL_CMD sh -c) set(GREP_CMD egrep -i -c) +execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" + COMMAND ${GREP_CMD} "amd64" + OUTPUT_VARIABLE CRYPTOPP_AMD64 + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x86_64" OUTPUT_VARIABLE CRYPTOPP_X86_64 @@ -113,6 +121,18 @@ execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" OUTPUT_VARIABLE CRYPTOPP_I386 OUTPUT_STRIP_TRAILING_WHITESPACE) +# http://github.com/weidai11/cryptopp/issues/466 +execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" + COMMAND ${GREP_CMD} "mingw32" + OUTPUT_VARIABLE CRYPTOPP_MINGW32 + OUTPUT_STRIP_TRAILING_WHITESPACE) + +# http://github.com/weidai11/cryptopp/issues/466 +execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" + COMMAND ${GREP_CMD} "w64-mingw32" + OUTPUT_VARIABLE CRYPTOPP_MINGW64 + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" COMMAND ${GREP_CMD} "x32" OUTPUT_VARIABLE CRYPTOPP_X32 @@ -144,11 +164,21 @@ execute_process(COMMAND ${SHELL_CMD} "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" OUTPUT_VARIABLE CRYPTOPP_ARM7L OUTPUT_STRIP_TRAILING_WHITESPACE) -# arm7l is another 32-bit hard float machine. RPI-3 is arm7l on 64-bit hardware -if ("${CRYPTOPP_ARM}" STREQUAL "1") - set(CRYPTOPP_ARMHF "1") +# Fixup? +if ("${CRYPTOPP_MINGW64}" STREQUAL "1") + unset(CRYPTOPP_MINGW32) endif() -if ("${CRYPTOPP_ARM7L}" STREQUAL "1") + +# MinGW32 +if ("${CRYPTOPP_MINGW32}" STREQUAL "1") + set(CRYPTOPP_I386 "1") +endif() +# OpenBSD and MinGW64 +if ("${CRYPTOPP_X86_64}" STREQUAL "1" OR "${CRYPTOPP_MINGW64}" STREQUAL "1") + set(CRYPTOPP_AMD64 "1") +endif() +# arm7l is another 32-bit hard float machine. RPI-3 is arm7l on 64-bit hardware +if ("${CRYPTOPP_ARM}" STREQUAL "1" OR "${CRYPTOPP_ARM7L}" STREQUAL "1") set(CRYPTOPP_ARMHF "1") endif() @@ -191,6 +221,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OUTPUT_VARIABLE GAS217_OR_LATER) if (GAS217_OR_LATER EQUAL 0) add_definitions(-DCRYPTOPP_DISABLE_SSSE3) + set(DISABLE_SSSE3 1) endif() # OpenBSD and CentOS 5 needed this one due to ARIA and BLAKE2 @@ -199,6 +230,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OUTPUT_VARIABLE GAS218_OR_LATER) if (GAS218_OR_LATER EQUAL 0) add_definitions(-DCRYPTOPP_DISABLE_SSE4) + set(DISABLE_SSE4 1) endif() execute_process(COMMAND echo ${GAS_STRING} @@ -206,6 +238,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OUTPUT_VARIABLE GAS219_OR_LATER) if (GAS219_OR_LATER EQUAL 0) add_definitions(-DCRYPTOPP_DISABLE_AESNI) + set(DISABLE_AESNI 1) endif() # Ubuntu 10 and Ubuntu 12 needed this one @@ -214,6 +247,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") OUTPUT_VARIABLE GAS223_OR_LATER) if (GAS223_OR_LATER EQUAL 0) add_definitions(-DCRYPTOPP_DISABLE_SHA) + set(DISABLE_SHA 1) endif() endif() endif() @@ -257,7 +291,7 @@ if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_P endif() endif() -# Solaris specific +# Solaris specific if ((NOT CRYPTOPP_CROSS_COMPILE) AND "${UNAME_SYSTEM}" STREQUAL "SunOS") # SunCC needs -native @@ -367,37 +401,53 @@ endif() # New as of Pull Request 461, http://github.com/weidai11/cryptopp/pull/461. if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) - if (("${CRYPTOPP_X86_64}" STREQUAL "1") OR ("${CRYPTOPP_I386}" STREQUAL "1") OR ("${CRYPTOPP_X32}" STREQUAL "1")) + if (("${CRYPTOPP_AMD64}" STREQUAL "1") OR ("${CRYPTOPP_I386}" STREQUAL "1") OR ("${CRYPTOPP_X32}" STREQUAL "1")) CHECK_CXX_COMPILER_FLAG("-mssse3" CRYPTOPP_IA32_SSSE3) CHECK_CXX_COMPILER_FLAG("-msse4.2" CRYPTOPP_IA32_SSE4) CHECK_CXX_COMPILER_FLAG("-mssse3 -mpclmul" CRYPTOPP_IA32_CLMUL) CHECK_CXX_COMPILER_FLAG("-msse4.1 -maes" CRYPTOPP_IA32_AES) CHECK_CXX_COMPILER_FLAG("-msse4.2 -msha" CRYPTOPP_IA32_SHA) + CHECK_CXX_COMPILER_FLAG("-march=native" CRYPTOPP_IA32_NATIVE) - if ("${CRYPTOPP_IA32_SSSE3}" STREQUAL "1") + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND "${CRYPTOPP_IA32_NATIVE}" STREQUAL "1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + elseif(CRYPTOPP_NATIVE_ARCH) + message(WARNING "CRYPTOPP_NATIVE_ARCH enabled, but failed to detect native architecture") + endif() + + if ("${CRYPTOPP_IA32_SSSE3}" STREQUAL "1" AND NOT DISABLE_SSSE3) set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3") + if ("${CRYPTOPP_IA32_SSE4}" STREQUAL "1" AND NOT DISABLE_SSE4) + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") + set_source_files_properties(crc-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") + if ("${CRYPTOPP_IA32_CLMUL}" STREQUAL "1" AND NOT DISABLE_AES) + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3 -mpclmul") + endif() + if ("${CRYPTOPP_IA32_AES}" STREQUAL "1" AND NOT DISABLE_AES) + set_source_files_properties(rijndael-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1 -maes") + endif() + if ("${CRYPTOPP_IA32_SHA}" STREQUAL "1" AND NOT DISABLE_SHA) + set_source_files_properties(sha-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha") + set_source_files_properties(shacal2-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha") + endif() + endif() endif() - if ("${CRYPTOPP_IA32_SSE4}" STREQUAL "1") - set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") - set_source_files_properties(crc-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") - endif() - if ("${CRYPTOPP_IA32_CLMUL}" STREQUAL "1") - set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3 -mpclmul") - endif() - if ("${CRYPTOPP_IA32_AES}" STREQUAL "1") - set_source_files_properties(rijndael-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1 -maes") - endif() - if ("${CRYPTOPP_IA32_SHA}" STREQUAL "1") - set_source_files_properties(sha-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha") - set_source_files_properties(shacal2-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha") - endif() - + elseif (("${CRYPTOPP_AARCH32}" STREQUAL "1") OR ("${CRYPTOPP_AARCH64}" STREQUAL "1") OR ("${CRYPTOPP_ARMV8}" STREQUAL "1")) CHECK_CXX_COMPILER_FLAG("-march=armv8-a" CRYPTOPP_ARMV8A_ASIMD) CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crc" CRYPTOPP_ARMV8A_CRC) CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crypto" CRYPTOPP_ARMV8A_CRYPTO) + CHECK_CXX_COMPILER_FLAG("-march=armv8-a" CRYPTOPP_ARMV8A_NATIVE) + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND "${CRYPTOPP_ARMV8A_NATIVE}" STREQUAL "1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a") + elseif(CRYPTOPP_NATIVE_ARCH) + message(WARNING "CRYPTOPP_NATIVE_ARCH enabled, but failed to detect native architecture") + endif() if ("${CRYPTOPP_ARMV8A_ASIMD}" STREQUAL "1") set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") @@ -419,6 +469,15 @@ if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" CHECK_CXX_COMPILER_FLAG("-march=armv7-a -mfloat-abi=hard -mfpu=neon" CRYPTOPP_ARMV7A_HARD) CHECK_CXX_COMPILER_FLAG("-march=armv7-a -mfloat-abi=softfp -mfpu=neon" CRYPTOPP_ARMV7A_SOFTFP) + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND "${CRYPTOPP_ARMV7A_HARD}" STREQUAL "1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfloat-abi=hard -mfpu=neon") + elseif (CRYPTOPP_NATIVE_ARCH AND "${CRYPTOPP_ARMV7A_SOFTFP}" STREQUAL "1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon") + elseif(CRYPTOPP_NATIVE_ARCH) + message(WARNING "CRYPTOPP_NATIVE_ARCH enabled, but failed to detect native architecture") + endif() + if ("${CRYPTOPP_ARMV7A_HARD}" STREQUAL "1") # Need to set floating point ABI to something, like "hard" of "softfp". Most Linux use hard floats ("hard"). set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") @@ -499,9 +558,6 @@ if (BUILD_SHARED) add_dependencies(dynamic cryptopp-shared) endif() -add_custom_target(distclean) -add_dependencies(distclean clean) - #============================================================================ # Third-party libraries #============================================================================ diff --git a/GNUmakefile b/GNUmakefile index 1e7e9f78..1fe2fe46 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -795,11 +795,11 @@ endif .PHONY: trim trim: ifneq ($(IS_DARWIN),0) - sed -i '' -e's/[[:space:]]*$$//' *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross + sed -i '' -e's/[[:space:]]*$$//' *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross sed -i '' -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.* make convert else - sed -i -e's/[[:space:]]*$$//' *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross + sed -i -e's/[[:space:]]*$$//' *.txt *.sh .*.yml *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross sed -i -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.* make convert endif diff --git a/Readme.txt b/Readme.txt index d5e0dd7b..48831558 100644 --- a/Readme.txt +++ b/Readme.txt @@ -24,12 +24,12 @@ Currently the library contains the following algorithms: message authentication codes VMAC, HMAC, GMAC, CMAC, CBC-MAC, DMAC, Two-Track-MAC, BLAKE2s, BLAKE2b - BLAKE2s, BLAKE2b, Keccack (F1600) SHA-1, SHA-2 + BLAKE2s, BLAKE2b, Keccack (F1600) SHA-1, SHA-2 hash functions (SHA-224, SHA-256, SHA-384, and SHA-512), SHA-3, Tiger, WHIRLPOOL, RIPEMD-128, RIPEMD-256, RIPEMD-160, RIPEMD-320 - RSA, DSA, Determinsitic DSA, ElGamal, + RSA, DSA, Determinsitic DSA, ElGamal, public-key cryptography Nyberg-Rueppel (NR), Rabin-Williams (RW), LUC, LUCELG, EC-based German Digital Signature (ECGDSA), DLIES (variants of DHAES), ESIGN @@ -223,7 +223,7 @@ The source code and its planned changes are available at the following locations source code via Apache's subversion until about July 2015. At that time, SourceForge had infrastructure problems and a cutover to GutHub was performed. * The Roadmap on the wiki provides the general direction the library is heading. - It includes planned features and releases, and even some wishlist items. + It includes planned features and releases, and even some wishlist items. Contributions of all types are welcomed. Contributions include the following. @@ -231,7 +231,7 @@ Contributions of all types are welcomed. Contributions include the following. * Features and enhancements * Test scripts and test cases * Branch and release testing - * Documentation and updates + * Documentation and updates If you think you have found a bug in the library, then you should discuss it on the Users mailing list. Discussing it will help bring the issue to the attention of folks @@ -615,18 +615,18 @@ documentation is one of the highest returns on investment. 5.6.5 - maintenance release, recompile of programs recommended - expanded community input and support - * 25 unique contributors as of this release + * 25 unique contributors as of this release - fixed CVE-2016-7420 (Issue 277, document NDEBUG for production/release) - fixed CVE-2016-7544 (Issue 302, avoid _malloca and _freea) - shipped library in recommended state - * backwards compatibility achieved with + * backwards compatibility achieved with - Visual Studio project file cleanup * improved X86 and X64 MSBuild support - * added ARM-based MSBuild awareness + * added ARM-based MSBuild awareness - improved Testing and QA * expanded platforms and compilers * expanded Coverity into OS X and Windows platforms - * added Windows test scripts using Strawberry Perl - - ported to MSVC 2015 SP3, Xcode 7.3, Sun Studio 12.5, GCC 7.0, MacPorts GCC 7.0, Clang 3.8, Intel C++ 17.00 + * added Windows test scripts using Strawberry Perl + - ported to MSVC 2015 SP3, Xcode 7.3, Sun Studio 12.5, GCC 7.0, MacPorts GCC 7.0, Clang 3.8, Intel C++ 17.00 Written by Wei Dai and the Crypto++ Project