diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index adc6908a..743ebf04 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(googletest) add_subdirectory(scrypt) add_subdirectory(spdlog) +add_subdirectory(cryptopp) diff --git a/vendor/README b/vendor/README index 3c01716d..311a42ad 100644 --- a/vendor/README +++ b/vendor/README @@ -4,3 +4,5 @@ scrypt: http://www.tarsnap.com/scrypt.html googletest: https://github.com/google/googletest/tree/release-1.8.0 - changed: added NOLINT comment as workaround for clang-tidy warning https://github.com/google/googletest/issues/853 spdlog: https://github.com/gabime/spdlog/tree/v0.16.3/include/spdlog +cryptopp: https://github.com/weidai11/cryptopp/tree/CRYPTOPP_7_0_0 + - changed: added CMakeLists.txt and cryptopp-config.cmake from https://github.com/noloader/cryptopp-cmake/tree/7f3b3540740b365bed673936852d70795c0104f3 diff --git a/vendor/cryptopp/CMakeLists.txt b/vendor/cryptopp/CMakeLists.txt new file mode 100644 index 00000000..415dea68 --- /dev/null +++ b/vendor/cryptopp/CMakeLists.txt @@ -0,0 +1,4 @@ +# Don't build cryptopp test cases +set(BUILD_TESTING OFF) + +add_subdirectory(cryptopp) diff --git a/vendor/cryptopp/cryptopp/.appveyor.yml b/vendor/cryptopp/cryptopp/.appveyor.yml new file mode 100644 index 00000000..a297717e --- /dev/null +++ b/vendor/cryptopp/cryptopp/.appveyor.yml @@ -0,0 +1,54 @@ +# Appveyor's documentation is at https://www.appveyor.com/docs/build-phase/, +# and a sample configuration file is at https://www.appveyor.com/docs/appveyor-yml/. +# I have to admit its a bit complex and I don't fully understand it. + +version: 1.0.{build} +clone_depth: 3 +skip_tags: true + +configuration: + +- Debug +- Release + +platform: + +- Win32 +- x64 + +image: + +- Visual Studio 2017 +- Visual Studio 2015 +- Visual Studio 2013 + +environment: + + matrix: + + - BUILD_MODE: MSBuild + +# Disable build through solution file +build: off + +# Build through commands in script below +test_script: + +- ps: >- + + msbuild /t:Build /p:platform="$env:platform" /p:configuration="$env:configuration" cryptlib.vcxproj + + msbuild /t:Build /p:platform="$env:platform" /p:configuration="$env:configuration" cryptest.vcxproj + + msbuild /t:CopyCryptestToRoot cryptest.vcxproj + + .\cryptest.exe v + + .\cryptest.exe tv all + +notifications: + - provider: Email + to: + - cryptopp-build@googlegroups.com + on_build_success: true + on_build_failure: true diff --git a/vendor/cryptopp/cryptopp/.gitattributes b/vendor/cryptopp/cryptopp/.gitattributes new file mode 100644 index 00000000..50ca329f --- /dev/null +++ b/vendor/cryptopp/cryptopp/.gitattributes @@ -0,0 +1 @@ +*.sh eol=lf diff --git a/vendor/cryptopp/cryptopp/.github/issue_template.md b/vendor/cryptopp/cryptopp/.github/issue_template.md new file mode 100644 index 00000000..ed98eabe --- /dev/null +++ b/vendor/cryptopp/cryptopp/.github/issue_template.md @@ -0,0 +1,15 @@ +### Crypto++ Issue Report + +Thanks for taking the time to report an issue. Reporting issues helps us improve stability and reliability for all users, so it is a valuable contribution. + +Please do not ask questions in the bug tracker. Please ask questions on the Crypto++ Users List at http://groups.google.com/forum/#!forum/cryptopp-users. + +There is a wiki page with information on filing useful bug reports. If you have some time please visit http://www.cryptopp.com/wiki/Bug_Report on the wiki. The executive summary is: + +* State the operating system and version (Ubutnu 17 x86_64, Windows 7 Professional x64, etc) +* State the version of the Crypto++ library (Crypto++ 5.6.5, Master, etc) +* State how you built the library (Makefile, Cmake, distro, etc) +* Show a typical command line (the output of the compiler for cryptlib.cpp) +* Show the link command (the output of the linker for libcryptopp.so or cryptest.exe) +* Show the exact error message you are receiving (copy and paste it); or +* Clearly state the undesired behavior (and state the expected behavior) diff --git a/vendor/cryptopp/cryptopp/.gitignore b/vendor/cryptopp/cryptopp/.gitignore new file mode 100644 index 00000000..15d93060 --- /dev/null +++ b/vendor/cryptopp/cryptopp/.gitignore @@ -0,0 +1,271 @@ +#################### +## Crypto++ specific +#################### +adhoc.cpp +adhoc.cpp.copied +libcryptopp.a +libcryptopp.so +libcryptopp.dylib +cryptest.exe +cryptopp-test.cxx +cryptopp-test.exe +cryptopp-test.s +cryptopp.mac.done +GNUmakefile.deps + +############## +## Patch files +############## +*.diff +*.patch + +################# +## GNU/GCC +################# + +## Ignore GNU/GCC artifacts +a.out + +## Ignore GCC temproary files. It appears Fedora +## changed a behavior somewhere along the lines + +*.o + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## https://msdn.microsoft.com/en-us/library/hx0cxhaw.aspx + +# User-specific files +*.suo +*.user +*.sdf + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ +[Ll]ibs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.o +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc +*.exe +*.a + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml +*.publishproj + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +############# +# Mac crap +############# + +.DS_Store + +############# +## Python +############# + +*.py[cod] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +################# +## C++Builder +################# + +## Ignore C++Builder temporary files and build results. +## http://docwiki.embarcadero.com/RADStudio/en/File_Extensions_of_Files_Generated_by_RAD_Studio + +# Static library file +*.lib + +# User-specific project options +*.local + +# Dependency file +*.d diff --git a/vendor/cryptopp/cryptopp/.travis.yml b/vendor/cryptopp/cryptopp/.travis.yml new file mode 100644 index 00000000..cc5fc8af --- /dev/null +++ b/vendor/cryptopp/cryptopp/.travis.yml @@ -0,0 +1,149 @@ +language: cpp + +os: + - linux + - osx + +dist: trusty +sudo: required + +# OS X only supports one image. Use the latest. +osx_image: xcode9.1 + +git: + depth: 3 + +compiler: + - clang + - gcc + +env: + global: + - BUILD_JOBS=2 + - ANDROID_HOME=$HOME/android/sdk + - ANDROID_NDK=$HOME/android/sdk/ndk-bundle + - ANDROID_SDK_ROOT=$ANDROID_HOME + - ANDROID_NDK_ROOT=$ANDROID_NDK + + matrix: + - BUILD_MODE="all" + - BUILD_MODE="native" + - BUILD_MODE="no-asm" + - BUILD_MODE="debug" + - BUILD_MODE="asan" + - BUILD_MODE="ubsan" + +matrix: + + exclude: + # Skip GCC on OS X entirely + - os: osx + compiler: gcc + # Skip UBsan due to GCC 4.8 + - os: linux + compiler: gcc + env: BUILD_MODE="ubsan" + # Skip UBsan due to Clang 3.4 + - os: osx + compiler: clang + env: BUILD_MODE="ubsan" + + include: + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=armeabi + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=armeabi-v7a + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=armv7a-neon + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=aarch64 + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=mipsel + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=mipsel64 + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=x86 + - os: linux + env: + - BUILD_MODE=android + - PLATFORM=x86_64 + - os: osx + env: + - BUILD_MODE=ios + - PLATFORM=iPhoneOS + - os: osx + env: + - BUILD_MODE=ios + - PLATFORM=WatchOS + - os: osx + env: + - BUILD_MODE=ios + - PLATFORM=AppleTVOS + - os: osx + env: + - BUILD_MODE=ios + - PLATFORM=iPhoneSimulator + + allow_failures: + - os: osx + env: + - BUILD_MODE=ios + - PLATFORM=WatchOS + +before_install: + - | + if [[ "$BUILD_MODE" == "android" ]]; then + TestScripts/install-android.sh + fi + +script: + - | + if [[ "$BUILD_MODE" == "ios" ]]; then + cp ./TestScripts/setenv-ios.sh . + TestScripts/cryptest-ios.sh + elif [[ "$BUILD_MODE" == "android" ]]; then + cp ./TestScripts/setenv-android.sh . + TestScripts/cryptest-android.sh + elif [[ "$BUILD_MODE" == "debug" ]]; then + CXXFLAGS="-DDEBUG -g2 -O1" make -j "$BUILD_JOBS" + ./cryptest.exe v + ./cryptest.exe tv all + else + make "$BUILD_MODE" -j "$BUILD_JOBS" + ./cryptest.exe v + ./cryptest.exe tv all + fi + +# whitelist branches to avoid testing feature branches twice +branches: + only: + - master + +addons: + sonarcloud: false + + coverity_scan: + project: + name: "cryptopp" + build_command: "make -j 2" + +notifications: + email: + recipients: + - cryptopp-build@googlegroups.com + on_success: always # default: change + on_failure: always # default: always diff --git a/vendor/cryptopp/cryptopp/3way.cpp b/vendor/cryptopp/cryptopp/3way.cpp new file mode 100644 index 00000000..bd610536 --- /dev/null +++ b/vendor/cryptopp/cryptopp/3way.cpp @@ -0,0 +1,143 @@ +// 3way.cpp - modifed by Wei Dai from Joan Daemen's 3way.c +// The original code and all modifications are in the public domain. + +#include "pch.h" +#include "3way.h" +#include "misc.h" + +NAMESPACE_BEGIN(CryptoPP) + +#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) +void ThreeWay_TestInstantiations() +{ + ThreeWay::Encryption x1; + ThreeWay::Decryption x2; +} +#endif + +namespace +{ + const word32 START_E = 0x0b0b; // round constant of first encryption round + const word32 START_D = 0xb1b1; // round constant of first decryption round +} + +static inline word32 reverseBits(word32 a) +{ + a = ((a & 0xAAAAAAAA) >> 1) | ((a & 0x55555555) << 1); + a = ((a & 0xCCCCCCCC) >> 2) | ((a & 0x33333333) << 2); + return ((a & 0xF0F0F0F0) >> 4) | ((a & 0x0F0F0F0F) << 4); +} + +#define mu(a0, a1, a2) \ +{ \ + a1 = reverseBits(a1); \ + word32 t = reverseBits(a0); \ + a0 = reverseBits(a2); \ + a2 = t; \ +} + +#define pi_gamma_pi(a0, a1, a2) \ +{ \ + word32 b0, b2; \ + b2 = rotlConstant<1>(a2); \ + b0 = rotlConstant<22>(a0); \ + a0 = rotlConstant<1>(b0 ^ (a1|(~b2))); \ + a2 = rotlConstant<22>(b2 ^ (b0|(~a1))); \ + a1 ^= (b2|(~b0)); \ +} + +// thanks to Paulo Barreto for this optimized theta() +#define theta(a0, a1, a2) \ +{ \ + word32 b0, b1, c; \ + c = a0 ^ a1 ^ a2; \ + c = rotlConstant<16>(c) ^ rotlConstant<8>(c); \ + b0 = (a0 << 24) ^ (a2 >> 8) ^ (a1 << 8) ^ (a0 >> 24); \ + b1 = (a1 << 24) ^ (a0 >> 8) ^ (a2 << 8) ^ (a1 >> 24); \ + a0 ^= c ^ b0; \ + a1 ^= c ^ b1; \ + a2 ^= c ^ (b0 >> 16) ^ (b1 << 16); \ +} + +#define rho(a0, a1, a2) \ +{ \ + theta(a0, a1, a2); \ + pi_gamma_pi(a0, a1, a2); \ +} + +void ThreeWay::Base::UncheckedSetKey(const byte *uk, unsigned int length, const NameValuePairs ¶ms) +{ + AssertValidKeyLength(length); + + m_rounds = GetRoundsAndThrowIfInvalid(params, this); + + for (unsigned int i=0; i<3; i++) + m_k[i] = (word32)uk[4*i+3] | ((word32)uk[4*i+2]<<8) | ((word32)uk[4*i+1]<<16) | ((word32)uk[4*i]<<24); + + if (!IsForwardTransformation()) + { + theta(m_k[0], m_k[1], m_k[2]); + mu(m_k[0], m_k[1], m_k[2]); + m_k[0] = ByteReverse(m_k[0]); + m_k[1] = ByteReverse(m_k[1]); + m_k[2] = ByteReverse(m_k[2]); + } +} + +void ThreeWay::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const +{ + typedef BlockGetAndPut Block; + + word32 a0, a1, a2; + Block::Get(inBlock)(a0)(a1)(a2); + + word32 rc = START_E; + + for(unsigned i=0; i Block; + + word32 a0, a1, a2; + Block::Get(inBlock)(a0)(a1)(a2); + + word32 rc = START_D; + + mu(a0, a1, a2); + for(unsigned i=0; i, public FixedKeyLength<12>, public VariableRounds<11> +{ + CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "3-Way";} +}; + +/// \brief ThreeWay block cipher +/// \sa 3-Way +class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation +{ + /// \brief Class specific implementation and overrides used to operate the cipher. + /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions + class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl + { + public: + void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); + + protected: + unsigned int m_rounds; + FixedSizeSecBlock m_k; + }; + + /// \brief Class specific methods used to operate the cipher in the forward direction. + /// \details Implementations and overrides in \p Enc apply to \p ENCRYPTION. + class CRYPTOPP_NO_VTABLE Enc : public Base + { + public: + void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; + }; + + /// \brief Class specific methods used to operate the cipher in the reverse direction. + /// \details Implementations and overrides in \p Dec apply to \p DECRYPTION. + class CRYPTOPP_NO_VTABLE Dec : public Base + { + public: + void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; + }; + +public: + typedef BlockCipherFinal Encryption; + typedef BlockCipherFinal Decryption; +}; + +typedef ThreeWay::Encryption ThreeWayEncryption; +typedef ThreeWay::Decryption ThreeWayDecryption; + +NAMESPACE_END + +#endif diff --git a/vendor/cryptopp/cryptopp/CMakeLists.txt b/vendor/cryptopp/cryptopp/CMakeLists.txt new file mode 100644 index 00000000..39dc2fc6 --- /dev/null +++ b/vendor/cryptopp/cryptopp/CMakeLists.txt @@ -0,0 +1,844 @@ +# Please ensure your changes or patch meets minimum requirements. +# The minimum requirements are 2.8.5. They roughly equate to Ubuntu 12.04 LTS +# Please do not check in something for 2.8.12 or 3.5.0. To test your changes, +# please set up a Ubuntu 12.04 LTS system. Then, manually install Cmake 2.8.5 +# from http://cmake.org/Wiki/CMake_Released_Versions. +# TODO: Decide if this still applies. + +MESSAGE( STATUS +"*************************************************************************\n\ +The Crypto++ library does not officially support CMake. CMake support is a\n\ +community effort, and the library works with the folks using CMake to help\n\ +improve it. If you find an issue then please fix it or report it at\n\ +https://github.com/noloader/cryptopp-cmake.\n\ +-- *************************************************************************" +) + +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 +# flags are set by the user and if we are the root CMakeLists.txt file. +if (NOT CMAKE_CONFIGURATION_TYPES AND + NOT CMAKE_NO_BUILD_TYPE AND + NOT CMAKE_BUILD_TYPE AND + NOT CMAKE_CXX_FLAGS AND + CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif () + +set(cryptopp_VERSION_MAJOR 7) +set(cryptopp_VERSION_MINOR 0) +set(cryptopp_VERSION_PATCH 0) + +include(GNUInstallDirs) +include(CheckCXXCompilerFlag) + +#============================================================================ +# Settable options +#============================================================================ + +option(BUILD_STATIC "Build static library" ON) +option(BUILD_SHARED "Build shared library" ON) +option(BUILD_TESTING "Build library tests" ON) +option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF) +option(USE_INTERMEDIATE_OBJECTS_TARGET "Use a common intermediate objects target for the static and shared library targets" ON) + +if (CMAKE_VERSION VERSION_LESS 2.8.8 AND USE_INTERMEDIATE_OBJECTS_TARGET) + message(STATUS "Forcing USE_INTERMEDIATE_OBJECTS_TARGET to OFF - requires CMake >= 2.8.8") + set(USE_INTERMEDIATE_OBJECTS_TARGET OFF CACHE BOOL "Use a common intermediate objects target for the static and shared library targets" FORCE) +endif () + +# These are IA-32 options. TODO: Add ARM A-32, Aarch64 and Power8 options. +option(DISABLE_ASM "Disable ASM" OFF) +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") + +#============================================================================ +# Internal compiler options +#============================================================================ + +# Stop hiding the damn output... +# set(CMAKE_VERBOSE_MAKEFILE on) + +# Always 1 ahead in Master. Also see http://groups.google.com/forum/#!topic/cryptopp-users/SFhqLDTQPG4 +set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH}) + +# Don't use RPATH's. The resulting binary could fail a security audit. +if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) + set(CMAKE_MACOSX_RPATH 0) +endif () + +if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180) +endif () + +# Also see http://github.com/weidai11/cryptopp/issues/395 +if (DISABLE_ASM) + add_definitions(-DCRYPTOPP_DISABLE_ASM) +endif () +if (DISABLE_SSSE3) + add_definitions(-DCRYPTOPP_DISABLE_SSSE3) +endif () +if (DISABLE_SSE4) + add_definitions(-DCRYPTOPP_DISABLE_SSE4) +endif () +if (DISABLE_AESNI) + add_definitions(-DCRYPTOPP_DISABLE_AESNI) +endif () +if (DISABLE_SHA) + add_definitions(-DCRYPTOPP_DISABLE_SHA) +endif () +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" + +############################################################################### + +# Try to find a Posix compatible grep and sed. Solaris, Digital Unix, +# Tru64, HP-UX and a few others need tweaking + +if (${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") + set(GREP_CMD /usr/xpg4/bin/grep) + set(SED_CMD /usr/xpg4/bin/sed) +else() + set(GREP_CMD grep) + set(SED_CMD sed) +endif () + +############################################################################### + +function(CheckCompilerOption opt var) + + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + + # CMake does not provide a generic shell/terminal mechanism + # and Microsoft environments don't know what 'sh' is. + set(${var} 0 PARENT_SCOPE) + + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + + message(STATUS "Performing Test ${var}") + execute_process( + COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${opt} -E -xdumpmacros /dev/null 2>&1" + COMMAND ${GREP_CMD} -i -c -E "illegal value ignored" + RESULT_VARIABLE COMMAND_RESULT + OUTPUT_VARIABLE COMMAND_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # No dereference below. Thanks for the warning, CMake (not!). + if (COMMAND_RESULT AND NOT COMMAND_OUTPUT) + set(${var} 1 PARENT_SCOPE) + message(STATUS "Performing Test ${var} - Success") + else () + set(${var} 0 PARENT_SCOPE) + message(STATUS "Performing Test ${var} - Failed") + endif () + + else () + + CHECK_CXX_COMPILER_FLAG(${opt} ${var}) + + endif () + +endfunction(CheckCompilerOption) + +############################################################################### + +function(DumpMachine output pattern) + + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + + # CMake does not provide a generic shell/terminal mechanism + # and Microsoft environments don't know what 'sh' is. + set(${output} 0 PARENT_SCOPE) + + else () + + execute_process( + COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" + COMMAND ${GREP_CMD} -i -c -E "${pattern}" + OUTPUT_VARIABLE ${output} + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(${output} "${${output}}" PARENT_SCOPE) + + endif() + +endfunction(DumpMachine) + +# Thansk to Anonimal for MinGW; see http://github.com/weidai11/cryptopp/issues/466 +DumpMachine(CRYPTOPP_AMD64 "amd64|x86_64") +DumpMachine(CRYPTOPP_I386 "i.86") +DumpMachine(CRYPTOPP_MINGW32 "\\") +DumpMachine(CRYPTOPP_MINGW64 "w64-mingw32|mingw64") +DumpMachine(CRYPTOPP_X32 "x32") +DumpMachine(CRYPTOPP_AARCH32 "Aarch32") +DumpMachine(CRYPTOPP_AARCH64 "Aarch64") +DumpMachine(CRYPTOPP_ARMHF "armhf|arm7l|eabihf") +DumpMachine(CRYPTOPP_ARM "\\") + +############################################################################### + +# Test SunCC for a string like 'CC: Sun C++ 5.13 SunOS_i386' +if (NOT CRYPTOPP_SOLARIS) + execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1" + COMMAND ${GREP_CMD} -i -c "SunOS" + OUTPUT_VARIABLE CRYPTOPP_SOLARIS + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif () + +# Test GCC for a string like 'i386-pc-solaris2.11' +if (NOT CRYPTOPP_SOLARIS) + execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1" + COMMAND ${GREP_CMD} -i -c "Solaris" + OUTPUT_VARIABLE CRYPTOPP_SOLARIS + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif () + +# DumpMachine SunCC style +if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + + # SunCC is 32-bit, but it builds both 32 and 64 bit. Use + execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1" + COMMAND ${GREP_CMD} -i -c "Sparc" + OUTPUT_VARIABLE CRYPTOPP_SPARC + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1" + COMMAND ${GREP_CMD} -i -c -E "i386|i86" + OUTPUT_VARIABLE CRYPTOPP_I386 + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND isainfo -k + COMMAND ${GREP_CMD} -i -c "i386" + OUTPUT_VARIABLE KERNEL_I386 + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND isainfo -k + COMMAND ${GREP_CMD} -i -c "amd64" + OUTPUT_VARIABLE KERNEL_AMD64 + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND isainfo -k + COMMAND ${GREP_CMD} -i -c "Sparc" + OUTPUT_VARIABLE KERNEL_SPARC + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND isainfo -k + COMMAND ${GREP_CMD} -i -c -E "UltraSarc|Sparc64|SparcV9" + OUTPUT_VARIABLE KERNEL_SPARC64 + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Build for 32-bit on 64-bit kernels unless Native Arch is + # specified. Note that this is a policy provided by Sun. + if (CRYPTOPP_NATIVE_ARCH AND KERNEL_I386) + unset(CRYPTOPP_AMD64) + set(CRYPTOPP_I386 1) + elseif (CRYPTOPP_NATIVE_ARCH AND KERNEL_AMD64) + unset(CRYPTOPP_I386) + set(CRYPTOPP_AMD64 1) + elseif (CRYPTOPP_NATIVE_ARCH AND KERNEL_SPARC) + unset(KERNEL_SPARC64) + set(KERNEL_SPARC 1) + elseif (CRYPTOPP_NATIVE_ARCH AND KERNEL_SPARC64) + unset(KERNEL_SPARC) + set(KERNEL_SPARC64 1) + endif () +endif () + +############################################################################### + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + + execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} --version 2>&1" + COMMAND ${GREP_CMD} -i -c "macports" + OUTPUT_VARIABLE MACPORTS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (MACPORTS EQUAL 0) + # Get GAS version, add defs + set as appropriate + set(GAS_CMD sh -c "${CMAKE_CXX_COMPILER} -xc -c /dev/null -Wa,-v -o/dev/null 2>&1") + + execute_process(COMMAND ${GAS_CMD} + OUTPUT_VARIABLE GAS_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(FIND ${GAS_STRING} "GNU assembler" GAS_OUTPUT) + + if (NOT GAS_OUTPUT EQUAL -1) + #.intel_syntax wasn't supported until GNU assembler 2.10 + + # TODO(unassigned): string() REGEX was not cooperating at time of writing. Re-implement as needed. + execute_process(COMMAND echo ${GAS_STRING} + COMMAND ${GREP_CMD} -i -c -E "GNU.[Aa]ssembler.*(2\\.[1-9][0-9]|[3-9])" + OUTPUT_VARIABLE GAS210_OR_LATER) + if (GAS210_OR_LATER EQUAL 0) + add_definitions(-DCRYPTOPP_DISABLE_ASM) + set(DISABLE_ASM 1) + endif () + + execute_process(COMMAND echo ${GAS_STRING} + COMMAND ${GREP_CMD} -i -c -E "GNU.[Aa]ssembler.*(2\\.1[7-9]|2\\.[2-9]|[3-9])" + 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 + execute_process(COMMAND echo ${GAS_STRING} + COMMAND ${GREP_CMD} -i -c -E "GNU.[Aa]ssembler.*(2\\.1[8-9]|2\\.[2-9]|[3-9])" + 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} + COMMAND ${GREP_CMD} -i -c -E "GNU.[Aa]ssembler.*(2\\.19|2\\.[2-9]|[3-9])" + 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 + execute_process(COMMAND echo ${GAS_STRING} + COMMAND ${GREP_CMD} -i -c -E "GNU.[Aa]ssembler.*(2\\.2[3-9]|2\\.[3-9]|[3-9])" + OUTPUT_VARIABLE GAS223_OR_LATER) + if (GAS223_OR_LATER EQUAL 0) + add_definitions(-DCRYPTOPP_DISABLE_SHA) + set(DISABLE_SHA 1) + endif () + endif () + endif () +endif () + +# TODO: what about ICC and LLVM on Windows? +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if (CMAKE_SYSTEM_VERSION MATCHES "10\\.0.*") + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" ) + endif () + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" ) +endif () + +# Enable PIC for all target machines except 32-bit i386 due to register pressures. +if (NOT CRYPTOPP_I386) + SET(CMAKE_POSITION_INDEPENDENT_CODE 1) +endif () + +# Solaris specific +if (CRYPTOPP_SOLARIS) + + # Determine 32-bit vs 64-bit + if (CRYPTOPP_AMD64 OR CRYPTOPP_SPARC64) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") + else () + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") + endif () + + # SunCC needs -template=no%extdef + if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -template=no%extdef") + endif () + + # GCC needs to enable use of '/' + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,--divide") + endif () + +endif () + +# Link is driven through the compiler, but CXXFLAGS are not used. Also see +# http://public.kitware.com/pipermail/cmake/2003-June/003967.html +if (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)) + SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_FLAGS}") +endif () + +#============================================================================ +# Sources & headers +#============================================================================ + +# Library headers +file(GLOB cryptopp_HEADERS *.h) +# Remove headers used to build test suite +list(REMOVE_ITEM cryptopp_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/bench.h + ${CMAKE_CURRENT_SOURCE_DIR}/validate.h + ) + +# Test sources. You can use the GNUmakefile to generate the list: `make sources`. +file(GLOB cryptopp_SOURCES_TEST test.cpp bench1.cpp bench2.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp adhoc.cpp datatest.cpp regtest1.cpp regtest2.cpp regtest3.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp) + +# Library sources. You can use the GNUmakefile to generate the list: `make sources`. +# Makefile sorted them at http://github.com/weidai11/cryptopp/pull/426. +file(GLOB cryptopp_SOURCES *.cpp) +list(SORT cryptopp_SOURCES) +list(REMOVE_ITEM cryptopp_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/integer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/simple.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cryptlib_bds.cpp + ${cryptopp_SOURCES_TEST} + ) +set(cryptopp_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/integer.cpp + ${cryptopp_SOURCES} + ) + +if (MINGW OR WIN32) + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp) +endif () + +if (MSVC AND NOT DISABLE_ASM) + if (${CMAKE_GENERATOR} MATCHES ".*ARM") + message(STATUS "Disabling ASM because ARM is specified as target platform.") + else () + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm) + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm) + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") + else () + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh") + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh") + set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh") + endif () + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm) + enable_language(ASM_MASM) + endif () +endif () + +#============================================================================ +# Architecture flags +#============================================================================ + +# TODO: Android, AIX, IBM xlC, iOS and a few other profiles are missing. + +# New as of Pull Request 461, http://github.com/weidai11/cryptopp/pull/461. +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + + if (CRYPTOPP_AMD64 OR CRYPTOPP_I386 OR CRYPTOPP_X32) + + CheckCompilerOption("-msse2" CRYPTOPP_IA32_SSE2) + CheckCompilerOption("-mssse3" CRYPTOPP_IA32_SSSE3) + CheckCompilerOption("-msse4.1" CRYPTOPP_IA32_SSE41) + CheckCompilerOption("-msse4.2" CRYPTOPP_IA32_SSE42) + CheckCompilerOption("-mssse3 -mpclmul" CRYPTOPP_IA32_CLMUL) + CheckCompilerOption("-msse4.1 -maes" CRYPTOPP_IA32_AES) + CheckCompilerOption("-msse4.2 -msha" CRYPTOPP_IA32_SHA) + CheckCompilerOption("-march=native" CRYPTOPP_IA32_NATIVE) + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_IA32_NATIVE) + 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_SSE2 AND NOT DISABLE_ASM) + set_source_files_properties(sse-simd.cpp PROPERTIES COMPILE_FLAGS "-msse2") + endif () + if (CRYPTOPP_IA32_SSSE3 AND NOT DISABLE_SSSE3) + set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3") + if (CRYPTOPP_IA32_SSE41 AND NOT DISABLE_SSE4) + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1") + endif () + if (CRYPTOPP_IA32_SSE42 AND NOT DISABLE_SSE4) + set_source_files_properties(crc-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2") + if (CRYPTOPP_IA32_CLMUL AND NOT DISABLE_AES) + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3 -mpclmul") + endif () + if (CRYPTOPP_IA32_AES AND NOT DISABLE_AES) + set_source_files_properties(rijndael-simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1 -maes") + endif () + if (CRYPTOPP_IA32_SHA 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 () + + elseif (CRYPTOPP_AARCH32 OR CRYPTOPP_AARCH64) + + CheckCompilerOption("-march=armv8-a" CRYPTOPP_ARMV8A_BASE) + CheckCompilerOption("-march=armv8-a+crc" CRYPTOPP_ARMV8A_CRC) + CheckCompilerOption("-march=armv8-a+crypto" CRYPTOPP_ARMV8A_CRYPTO) + CheckCompilerOption("-march=armv8-a" CRYPTOPP_ARMV8A_NATIVE) + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_ARMV8A_NATIVE) + 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_BASE) + set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") + set_source_files_properties(neon-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a") + endif () + if (CRYPTOPP_ARMV8A_CRC) + set_source_files_properties(crc-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crc") + endif () + if (CRYPTOPP_ARMV8A_CRYPTO) + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto") + set_source_files_properties(rijndael-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto") + set_source_files_properties(sha-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto") + set_source_files_properties(shacal2-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto") + endif () + + elseif (CRYPTOPP_ARM OR CRYPTOPP_ARMHF) + + CheckCompilerOption("-march=armv7-a -mfpu=neon" CRYPTOPP_ARMV7A_NEON) + CheckCompilerOption("-march=armv7-a -mfloat-abi=hard" CRYPTOPP_ARMV7A_HARD) + CheckCompilerOption("-march=armv7-a -mfloat-abi=softfp" CRYPTOPP_ARMV7A_SOFTFP) + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_ARMV7A_HARD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfloat-abi=hard -mfpu=neon") + elseif (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_ARMV7A_SOFTFP) + 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 AND CRYPTOPP_ARMV7A_NEON) + # 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") + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") + set_source_files_properties(neon-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=hard -mfpu=neon") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=hard -mfpu=neon") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=hard -mfpu=neon") + elseif (CRYPTOPP_ARMV7A_SOFTFP AND CRYPTOPP_ARMV7A_NEON) + # 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=softfp -mfpu=neon") + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") + set_source_files_properties(neon-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=softfp -mfpu=neon") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=softfp -mfpu=neon") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-mfloat-abi=softfp -mfpu=neon") + endif () + endif () +endif () + +# New as of Pull Request 461, http://github.com/weidai11/cryptopp/pull/461. +if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + + if (CRYPTOPP_AMD64 OR CRYPTOPP_I386 OR CRYPTOPP_X32) + + CheckCompilerOption("-xarch=sse2" CRYPTOPP_IA32_SSE2) + CheckCompilerOption("-xarch=ssse3" CRYPTOPP_IA32_SSSE3) + CheckCompilerOption("-xarch=sse4_1" CRYPTOPP_IA32_SSE41) + CheckCompilerOption("-xarch=sse4_2" CRYPTOPP_IA32_SSE42) + CheckCompilerOption("-xarch=aes" CRYPTOPP_IA32_CLMUL) + CheckCompilerOption("-xarch=aes" CRYPTOPP_IA32_AES) + CheckCompilerOption("-xarch=sha" CRYPTOPP_IA32_SHA) + CheckCompilerOption("-native" CRYPTOPP_IA32_NATIVE) + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_IA32_NATIVE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -native") + elseif (CRYPTOPP_NATIVE_ARCH) + message(WARNING "CRYPTOPP_NATIVE_ARCH enabled, but failed to detect native architecture") + endif () + + # TODO: each of these -xarch=XXX options must be added to LDFLAGS + # if the option is used during a compile. + if (CRYPTOPP_IA32_SSE2 AND NOT DISABLE_ASM) + set_source_files_properties(sse-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse2") + endif () + if (CRYPTOPP_IA32_SSSE3 AND NOT DISABLE_SSSE3) + set_source_files_properties(aria-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3") + set_source_files_properties(simon-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3") + set_source_files_properties(speck-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3") + if (CRYPTOPP_IA32_SSE41 AND NOT DISABLE_SSE4) + set_source_files_properties(blake2-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse4_1") + endif () + if (CRYPTOPP_IA32_SSE42 AND NOT DISABLE_SSE4) + set_source_files_properties(crc-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse4_2") + if (CRYPTOPP_IA32_CLMUL AND NOT DISABLE_AES) + set_source_files_properties(gcm-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes") + endif () + if (CRYPTOPP_IA32_AES AND NOT DISABLE_AES) + set_source_files_properties(rijndael-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes") + endif () + if (CRYPTOPP_IA32_SHA AND NOT DISABLE_SHA) + set_source_files_properties(sha-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sha") + set_source_files_properties(shacal2-simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sha") + endif () + endif () + endif () + + elseif (CRYPTOPP_SPARC OR CRYPTOPP_SPARC64) + + # Sparc's need -xmemalign=4i + CheckCompilerOption("-xmemalign=4i" CRYPTOPP_SUN_MEMALIGN) + + if (CRYPTOPP_SUN_MEMALIGN STREQUAL "1") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xmemalign=4i") + endif () + + # Deferred native arch; added to all CXXFLAGS + if (CRYPTOPP_NATIVE_ARCH AND CRYPTOPP_SPARC_NATIVE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -native") + elseif (CRYPTOPP_NATIVE_ARCH) + message(WARNING "CRYPTOPP_NATIVE_ARCH enabled, but failed to detect native architecture") + endif () + + endif () +endif () + +#============================================================================ +# Compile targets +#============================================================================ + +# Set global includes BEFORE adding any targets for legacy CMake versions +if (CMAKE_VERSION VERSION_LESS 2.8.12) + include_directories("${CMAKE_CURRENT_SOURCE_DIR}") +endif () + +if (USE_INTERMEDIATE_OBJECTS_TARGET) + add_library(cryptopp-object OBJECT ${cryptopp_SOURCES}) +endif () + +if (BUILD_STATIC) + if (USE_INTERMEDIATE_OBJECTS_TARGET) + add_library(cryptopp-static STATIC $) + else () + add_library(cryptopp-static STATIC ${cryptopp_SOURCES}) + endif () + + if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) + target_include_directories(cryptopp-static PUBLIC $ $) + endif () +endif () + +if (BUILD_SHARED) + if (USE_INTERMEDIATE_OBJECTS_TARGET) + add_library(cryptopp-shared SHARED $) + else () + add_library(cryptopp-shared SHARED ${cryptopp_SOURCES}) + endif () + + if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) + target_include_directories(cryptopp-shared PUBLIC $ $) + endif () +endif () + +# Set filenames for targets to be "cryptopp" +if (NOT MSVC) + set(COMPAT_VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}) + + if (BUILD_STATIC) + set_target_properties(cryptopp-static + PROPERTIES + OUTPUT_NAME cryptopp) + endif () + if (BUILD_SHARED) + set_target_properties(cryptopp-shared + PROPERTIES + SOVERSION ${COMPAT_VERSION} + OUTPUT_NAME cryptopp) + endif () +endif () + +# Targets, compatible with Crypto++ GNUMakefile +if (BUILD_STATIC) + add_custom_target(static) + add_dependencies(static cryptopp-static) +endif () +if (BUILD_SHARED) + add_custom_target(dynamic) + add_dependencies(dynamic cryptopp-shared) +endif () + +#============================================================================ +# Third-party libraries +#============================================================================ + +if (WIN32) + if (BUILD_STATIC) + target_link_libraries(cryptopp-static ws2_32) + endif () + if (BUILD_SHARED) + target_link_libraries(cryptopp-shared ws2_32) + endif () +endif () + +# This may need to be expanded to "Solaris" +if (CRYPTOPP_SOLARIS) + if (BUILD_STATIC) + target_link_libraries(cryptopp-static nsl socket) + endif () + if (BUILD_SHARED) + target_link_libraries(cryptopp-shared nsl socket) + endif () +endif () + +find_package(Threads) +if (BUILD_STATIC) + target_link_libraries(cryptopp-static ${CMAKE_THREAD_LIBS_INIT}) +endif () +if (BUILD_SHARED) + target_link_libraries(cryptopp-shared ${CMAKE_THREAD_LIBS_INIT}) +endif () + +#============================================================================ +# Tests +#============================================================================ + +enable_testing() +if (BUILD_TESTING) + add_executable(cryptest ${cryptopp_SOURCES_TEST}) + target_link_libraries(cryptest cryptopp-static) + + # Setting "cryptest" binary name to "cryptest.exe" + if (NOT (WIN32 OR CYGWIN)) + set_target_properties(cryptest PROPERTIES OUTPUT_NAME cryptest.exe) + endif () + if (NOT TARGET cryptest.exe) + add_custom_target(cryptest.exe) + add_dependencies(cryptest.exe cryptest) + endif () + + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${PROJECT_BINARY_DIR}) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${PROJECT_BINARY_DIR}) + + add_test(NAME build_cryptest COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target cryptest) + add_test(NAME cryptest COMMAND $ v) + set_tests_properties(cryptest PROPERTIES DEPENDS build_cryptest) +endif () + +#============================================================================ +# Doxygen documentation +#============================================================================ + +if (BUILD_DOCUMENTATION) + find_package(Doxygen REQUIRED) + + set(in_source_DOCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/html-docs") + set(out_source_DOCS_DIR "${PROJECT_BINARY_DIR}/html-docs") + + add_custom_target(docs ALL + COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile + ) + + if (NOT ${in_source_DOCS_DIR} STREQUAL ${out_source_DOCS_DIR}) + add_custom_command( + TARGET docs POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory "${in_source_DOCS_DIR}" "${out_source_DOCS_DIR}" + COMMAND ${CMAKE_COMMAND} -E remove_directory "${in_source_DOCS_DIR}" + ) + endif () +endif () + +#============================================================================ +# Install +#============================================================================ + +set(export_name "cryptopp-targets") + +# Runtime package +if (BUILD_SHARED) + install( + TARGETS cryptopp-shared + EXPORT ${export_name} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif () + +# Development package +if (BUILD_STATIC) + install(TARGETS cryptopp-static EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif () +install(FILES ${cryptopp_HEADERS} DESTINATION include/cryptopp) + +# CMake Package +if (NOT CMAKE_VERSION VERSION_LESS 2.8.8) # CMakePackageConfigHelpers is supported from 2.8.8 + include(CMakePackageConfigHelpers) + write_basic_package_version_file("${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake" VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}.${cryptopp_VERSION_PATCH} COMPATIBILITY SameMajorVersion) + install(FILES cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp") + install(EXPORT ${export_name} DESTINATION "lib/cmake/cryptopp") +endif () + +# Tests +if (BUILD_TESTING) + install(TARGETS cryptest DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp) +endif () + +# Documentation +if (BUILD_DOCUMENTATION) + install(DIRECTORY "${out_source_DOCS_DIR}" DESTINATION ${CMAKE_INSTALL_DOCDIR}) +endif () + +# Print a configuration summary. We want CXX and CXXFLAGS, but they are not includd in ALL. +if (NOT CMAKE_VERSION VERSION_LESS 3.0.2) + if (CRYPTOPP_I386) + message(STATUS "Platform: i386/i686") + elseif (CRYPTOPP_AMD64) + message(STATUS "Platform: x86_64") + elseif (CRYPTOPP_X32) + message(STATUS "Platform: x86_64-x32") + elseif (CRYPTOPP_ARMHF) + message(STATUS "Platform: armhf") + elseif (CRYPTOPP_ARM) + message(STATUS "Platform: arm") + elseif (CRYPTOPP_AARCH32) + message(STATUS "Platform: Aarch32") + elseif (CRYPTOPP_AARCH64) + message(STATUS "Platform: Aarch64") + elseif (CRYPTOPP_SPARC) + message(STATUS "Platform: Sparc") + elseif (CRYPTOPP_SPARC64) + message(STATUS "Platform: Sparc64") + elseif (CRYPTOPP_POWERPC) + message(STATUS "Platform: PowerPC") + elseif (CRYPTOPP_POWERPC64) + message(STATUS "Platform: PowerPC64") + elseif (CRYPTOPP_MINGW32) + message(STATUS "Platform: MinGW-32") + elseif (CRYPTOPP_MINGW32) + message(STATUS "Platform: MinGW-64") + endif () + if (CRYPTOPP_ARMV7A_NEON) + message(STATUS "NEON: TRUE") + endif () + if (CRYPTOPP_NATIVE_ARCH) + message(STATUS "Native arch: TRUE") + else () + message(STATUS "Native arch: FALSE") + endif () + message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}") + message(STATUS "Flags: ${CMAKE_CXX_FLAGS}") + message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") +endif () diff --git a/vendor/cryptopp/cryptopp/Doxyfile b/vendor/cryptopp/cryptopp/Doxyfile new file mode 100644 index 00000000..afc05177 --- /dev/null +++ b/vendor/cryptopp/cryptopp/Doxyfile @@ -0,0 +1,2375 @@ +# Doxyfile 1.8.9 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). +# +# The file can be upgraded to the latest version of Doxygen with `doxygen -u