diff --git a/3way.cpp b/3way.cpp index a02b5803..60bd0e13 100644 --- a/3way.cpp +++ b/3way.cpp @@ -19,9 +19,6 @@ namespace { const word32 START_E = 0x0b0b; // round constant of first encryption round const word32 START_D = 0xb1b1; // round constant of first decryption round -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - const word32 RC_MODULUS = 0x11011; -#endif } static inline word32 reverseBits(word32 a) diff --git a/Filelist.txt b/Filelist.txt index 39327299..7c0d9b4c 100644 --- a/Filelist.txt +++ b/Filelist.txt @@ -48,7 +48,6 @@ channels.h cmac.cpp cmac.h config.h -config.compat cpu.cpp cpu.h crc.cpp diff --git a/GNUmakefile b/GNUmakefile index 0d23861c..2e650f28 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -676,7 +676,7 @@ dlltest.exe: cryptopp.dll $(DLLTESTOBJS) $(CXX) -o $@ $(strip $(CXXFLAGS)) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS) # This recipe prepares the distro files -TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt CMakeLists.txt config.compat Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcxproj *.filters cryptopp.rc TestVectors/*.txt TestData/*.dat TestScripts/*.sh TestScripts/*.pl TestScripts/*.cmd +TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt CMakeLists.txt Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcxproj *.filters cryptopp.rc TestVectors/*.txt TestData/*.dat TestScripts/*.sh TestScripts/*.pl TestScripts/*.cmd EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ TestScripts/ ifeq ($(wildcard Filelist.txt),Filelist.txt) @@ -686,10 +686,10 @@ endif .PHONY: trim trim: ifneq ($(IS_DARWIN),0) - sed -i '' -e's/[[:space:]]*$$//' *.compat *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross + sed -i '' -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross make convert else - sed -i -e's/[[:space:]]*$$//' *.compat *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross + sed -i -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.sln *.vcxproj GNUmakefile GNUmakefile-cross make convert endif diff --git a/TestScripts/cryptest.sh b/TestScripts/cryptest.sh index f64e649f..ef62d123 100755 --- a/TestScripts/cryptest.sh +++ b/TestScripts/cryptest.sh @@ -30,12 +30,6 @@ # rather than all of them. Its useful at places like the GCC Compile Farm, where being nice is policy. # ./cryptest.sh nice -# You can test using original config.h with the following. 'orig', 'original' and 'config.h' are synonyms: -# ./cryptest.sh original - -# You can test 5.6.2 compatibility using config.compat with the following. 'compat', 'compatibility' and 'config.compat' are synonyms: -# ./cryptest.sh compatibility - ############################################ # Set to suite your taste @@ -177,9 +171,6 @@ do WANT_NICE=1 elif [[ ($("$EGREP" -ix "orig" <<< "$ARG") || $("$EGREP" -ix "original" <<< "$ARG") || $("$EGREP" -ix "config.h" <<< "$ARG")) ]]; then git checkout config.h > /dev/null 2>&1 - elif [[ ($("$EGREP" -ix "compat" <<< "$ARG") || $("$EGREP" -ix "compatibility" <<< "$ARG") || $("$EGREP" -ix "config.compat" <<< "$ARG")) ]]; then - git checkout config.compatibility > /dev/null 2>&1 - cp config.compatibility config.h else echo "Unknown option $ARG" fi @@ -2675,63 +2666,6 @@ if [[ "$HAVE_X32" -ne "0" ]]; then fi fi -############################################ -# Backwards compatibility -if true; then - - ############################################ - # Debug build - echo - echo "************************************" | tee -a "$TEST_RESULTS" - echo "Testing: Debug, MAINTAIN_BACKWARDS_COMPATIBILITY" | tee -a "$TEST_RESULTS" - echo - - "$MAKE" clean > /dev/null 2>&1 - rm -f adhoc.cpp > /dev/null 2>&1 - - CXXFLAGS="$DEBUG_CXXFLAGS -DCRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS ${DEPRECATED_CXXFLAGS[@]}" - CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" - - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS" - else - ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS" - fi - ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS" - fi - fi - - ############################################ - # Release build - echo - echo "************************************" | tee -a "$TEST_RESULTS" - echo "Testing: Release, MAINTAIN_BACKWARDS_COMPATIBILITY" | tee -a "$TEST_RESULTS" - echo - - "$MAKE" clean > /dev/null 2>&1 - rm -f adhoc.cpp > /dev/null 2>&1 - - CXXFLAGS="$RELEASE_CXXFLAGS -DCRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS ${DEPRECATED_CXXFLAGS[@]}" - CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" - - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS" - fi - - ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS" - fi - ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS" - fi -fi - ############################################ # init_priority if true; then diff --git a/asn.h b/asn.h index 90809ef9..ed9de52c 100644 --- a/asn.h +++ b/asn.h @@ -165,6 +165,8 @@ CRYPTOPP_DLL void CRYPTOPP_API DERReencode(BufferedTransformation &bt, BufferedT class CRYPTOPP_DLL OID { public: + virtual ~OID() {} + //! \brief Construct an OID OID() {} //! \brief Construct an OID @@ -211,6 +213,8 @@ class EncodedObjectFilter : public Filter public: enum Flag {PUT_OBJECTS=1, PUT_MESSANGE_END_AFTER_EACH_OBJECT=2, PUT_MESSANGE_END_AFTER_ALL_OBJECTS=4, PUT_MESSANGE_SERIES_END_AFTER_ALL_OBJECTS=8}; + virtual ~EncodedObjectFilter() {} + //! \brief Construct an EncodedObjectFilter //! \param attachment a BufferedTrasformation to attach to this object //! \param nObjects @@ -241,9 +245,10 @@ private: class CRYPTOPP_DLL BERGeneralDecoder : public Store { public: + virtual ~BERGeneralDecoder(); + explicit BERGeneralDecoder(BufferedTransformation &inQueue, byte asnTag); explicit BERGeneralDecoder(BERGeneralDecoder &inQueue, byte asnTag); - ~BERGeneralDecoder(); bool IsDefiniteLength() const {return m_definiteLength;} lword RemainingLength() const {CRYPTOPP_ASSERT(m_definiteLength); return m_length;} @@ -278,14 +283,10 @@ private: class CRYPTOPP_DLL DERGeneralEncoder : public ByteQueue { public: -#if defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562) + virtual ~DERGeneralEncoder(); + explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED); explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag = SEQUENCE | CONSTRUCTED); -#else - explicit DERGeneralEncoder(BufferedTransformation &outQueue, byte asnTag /*= SEQUENCE | CONSTRUCTED*/); - explicit DERGeneralEncoder(DERGeneralEncoder &outQueue, byte asnTag /*= SEQUENCE | CONSTRUCTED*/); -#endif - ~DERGeneralEncoder(); // call this to denote end of sequence void MessageEnd(); @@ -390,6 +391,8 @@ public: class CRYPTOPP_DLL X509PublicKey : public ASN1CryptoMaterial { public: + virtual ~X509PublicKey() {} + void BERDecode(BufferedTransformation &bt); void DEREncode(BufferedTransformation &bt) const; @@ -411,6 +414,8 @@ public: class CRYPTOPP_DLL PKCS8PrivateKey : public ASN1CryptoMaterial { public: + virtual ~PKCS8PrivateKey() {} + void BERDecode(BufferedTransformation &bt); void DEREncode(BufferedTransformation &bt) const; diff --git a/blumshub.h b/blumshub.h index df7c6854..486e4075 100644 --- a/blumshub.h +++ b/blumshub.h @@ -18,6 +18,8 @@ class PublicBlumBlumShub : public RandomNumberGenerator, public StreamTransformation { public: + virtual ~PublicBlumBlumShub() {} + PublicBlumBlumShub(const Integer &n, const Integer &seed); unsigned int GenerateBit(); @@ -28,10 +30,6 @@ public: bool IsSelfInverting() const {return true;} bool IsForwardTransformation() const {return true;} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~PublicBlumBlumShub() {} -#endif - protected: ModularArithmetic modn; Integer current; @@ -42,6 +40,8 @@ protected: class BlumBlumShub : public PublicBlumBlumShub { public: + virtual ~BlumBlumShub() {} + // Make sure p and q are both primes congruent to 3 mod 4 and at least 512 bits long, // seed is the secret key and should be about as big as p*q BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed); @@ -49,10 +49,6 @@ public: bool IsRandomAccess() const {return true;} void Seek(lword index); -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~BlumBlumShub() {} -#endif - protected: const Integer p, q; const Integer x0; diff --git a/config.compat b/config.compat deleted file mode 100644 index 6392a786..00000000 --- a/config.compat +++ /dev/null @@ -1,950 +0,0 @@ -// config.h - written and placed in the public domain by Wei Dai - -//! \file config.h -//! \brief Library configuration file - -#ifndef CRYPTOPP_CONFIG_H -#define CRYPTOPP_CONFIG_H - -// ***************** Important Settings ******************** - -// define this if running on a big-endian CPU -#if !defined(IS_LITTLE_ENDIAN) && (defined(__BIG_ENDIAN__) || (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || (defined(__m68k__) || defined(__MC68K__)) || defined(__sparc) || defined(__sparc__) || defined(__hppa__) || defined(__MIPSEB__) || defined(__ARMEB__) || (defined(__MWERKS__) && !defined(__INTEL__))) -# define IS_BIG_ENDIAN -#endif - -// define this if running on a little-endian CPU -// big endian will be assumed if IS_LITTLE_ENDIAN is not defined -#ifndef IS_BIG_ENDIAN -# define IS_LITTLE_ENDIAN -#endif - -// Sanity checks. Some processors have more than big-, little- and bi-endian modes. PDP mode, where order results in "4312", should -// raise red flags immediately. Additionally, mis-classified machines, like (previosuly) S/390, should raise red flags immediately. -#if defined(IS_BIG_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) -# error "IS_BIG_ENDIAN is set, but __BYTE_ORDER__ does not equal __ORDER_BIG_ENDIAN__" -#endif -#if defined(IS_LITTLE_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__) -# error "IS_LITTLE_ENDIAN is set, but __BYTE_ORDER__ does not equal __ORDER_LITTLE_ENDIAN__" -#endif - -// Define this if you want to disable all OS-dependent features, -// such as sockets and OS-provided random number generators -// #define NO_OS_DEPENDENCE - -// Define this to use features provided by Microsoft's CryptoAPI. -// Currently the only feature used is Windows random number generation. -// This macro will be ignored if NO_OS_DEPENDENCE is defined. -// #define USE_MS_CRYPTOAPI - -// Define this to use features provided by Microsoft's CryptoNG API. -// CryptoNG API is available in Vista and above and its cross platform, -// including desktop apps and store apps. Currently the only feature -// used is Windows random number generation. -// This macro will be ignored if NO_OS_DEPENDENCE is defined. -// #define USE_MS_CNGAPI - -// If the user did not make a choice, then select CryptoNG if either -// Visual Studio 2015 is available, or Windows 10 or above is available. -#if !defined(USE_MS_CRYPTOAPI) && !defined(USE_MS_CNGAPI) -# if (_MSC_VER >= 1900) || ((WINVER >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)) -# define USE_MS_CNGAPI -# else -# define USE_MS_CRYPTOAPI -# endif -#endif - -// Define this to ensure C/C++ standard compliance and respect for GCC aliasing rules and other alignment fodder. If you -// experience a break with GCC at -O3, you should try this first. Guard it in case its set on the command line (and it differs). -#ifndef CRYPTOPP_NO_UNALIGNED_DATA_ACCESS -// # define CRYPTOPP_NO_UNALIGNED_DATA_ACCESS -#endif - -// ***************** Less Important Settings *************** - -// Library version -#define CRYPTOPP_VERSION 570 - -// Define this if you want to set a prefix for TestData/ and TestVectors/ -// Be mindful of the trailing slash since its simple concatenation. -// g++ ... -DCRYPTOPP_DATA_DIR='"/tmp/cryptopp_test/share/"' -#ifndef CRYPTOPP_DATA_DIR -# define CRYPTOPP_DATA_DIR "" -#endif - -// define this to retain (as much as possible) old deprecated function and class names -// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - -// Define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2. -// Also see https://cryptopp.com/wiki/Config.h#Avoid_MAINTAIN_BACKWARDS_COMPATIBILITY -#define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - -// Define this if you want or need the library's memcpy_s and memmove_s. -// See http://github.com/weidai11/cryptopp/issues/28. -// #if !defined(CRYPTOPP_WANT_SECURE_LIB) -// # define CRYPTOPP_WANT_SECURE_LIB -// #endif - -// File system code to write to GZIP archive. -#if !defined(GZIP_OS_CODE) -# define GZIP_OS_CODE 0 -#endif - -// Try this if your CPU has 256K internal cache or a slow multiply instruction -// and you want a (possibly) faster IDEA implementation using log tables -// #define IDEA_LARGECACHE - -// Define this if, for the linear congruential RNG, you want to use -// the original constants as specified in S.K. Park and K.W. Miller's -// CACM paper. -// #define LCRNG_ORIGINAL_NUMBERS - -// Define this if you want Integer's operator<< to honor std::showbase (and -// std::noshowbase). If defined, Integer will use a suffix of 'b', 'o', 'h' -// or '.' (the last for decimal) when std::showbase is in effect. If -// std::noshowbase is set, then the suffix is not added to the Integer. If -// not defined, existing behavior is preserved and Integer will use a suffix -// of 'b', 'o', 'h' or '.' (the last for decimal). -// #define CRYPTOPP_USE_STD_SHOWBASE - -// choose which style of sockets to wrap (mostly useful for MinGW which has both) -#if !defined(NO_BERKELEY_STYLE_SOCKETS) && !defined(PREFER_BERKELEY_STYLE_SOCKETS) -# define PREFER_BERKELEY_STYLE_SOCKETS -#endif - -// #if !defined(NO_WINDOWS_STYLE_SOCKETS) && !defined(PREFER_WINDOWS_STYLE_SOCKETS) -// # define PREFER_WINDOWS_STYLE_SOCKETS -// #endif - -// set the name of Rijndael cipher, was "Rijndael" before version 5.3 -#define CRYPTOPP_RIJNDAEL_NAME "AES" - -// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT -// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT -// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike -// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to -// define it). -// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420 -#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG) -# define CRYPTOPP_DEBUG 1 -#endif - -// ***************** Initialization and Constructor priorities ******************** - -// MacPorts/GCC and Solaris/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it. -// See http://cryptopp.com/wiki/Static_Initialization_Order_Fiasco - -// CRYPTOPP_INIT_PRIORITY attempts to manage initialization of C++ static objects. -// Under GCC, the library uses init_priority attribute in the range -// [CRYPTOPP_INIT_PRIORITY, CRYPTOPP_INIT_PRIORITY+100]. Under Windows, -// CRYPTOPP_INIT_PRIORITY enlists "#pragma init_seg(lib)". -#ifndef CRYPTOPP_INIT_PRIORITY -// # define CRYPTOPP_INIT_PRIORITY 250 -#endif - -// CRYPTOPP_USER_PRIORITY is for other libraries and user code that is using Crypto++ -// and managing C++ static object creation. It is guaranteed not to conflict with -// values used by (or would be used by) the Crypto++ library. -#if defined(CRYPTOPP_INIT_PRIORITY) && (CRYPTOPP_INIT_PRIORITY > 0) -# define CRYPTOPP_USER_PRIORITY (CRYPTOPP_INIT_PRIORITY + 101) -#else -# define CRYPTOPP_USER_PRIORITY 350 -#endif - -// __attribute__(init_priority(250)) is supported -#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__)) -# define HAVE_GCC_CONSTRUCTOR1 1 -#endif - -// __attribute__(init_priority()) is supported -#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !HAVE_GCC_CONSTRUCTOR1 && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__)) -# define HAVE_GCC_CONSTRUCTOR0 1 -#endif - -#if (_MSC_VER && (CRYPTOPP_INIT_PRIORITY > 0)) -# define HAVE_MSC_INIT_PRIORITY 1 -#endif - -// ***************** Important Settings Again ******************** -// But the defaults should be ok. - -// namespace support is now required -#ifdef NO_NAMESPACE -# error namespace support is now required -#endif - -// Define this to workaround a Microsoft CryptoAPI bug where -// each call to CryptAcquireContext causes a 100 KB memory leak. -// Defining this will cause Crypto++ to make only one call to CryptAcquireContext. -#define WORKAROUND_MS_BUG_Q258000 - -#ifdef CRYPTOPP_DOXYGEN_PROCESSING -// Document the namespce exists. Put it here before CryptoPP is undefined below. -//! \namespace CryptoPP -//! \brief Crypto++ library namespace -//! \details Nearly all classes are located in the CryptoPP namespace. Within -//! the namespace, there are two additional namespaces. -//! -namespace CryptoPP { } -// Bring in the symbols fund in the weak namespace; and fold Weak1 into Weak -# define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -# define Weak1 Weak -// Avoid putting "CryptoPP::" in front of everything in Doxygen output -# define CryptoPP -# define NAMESPACE_BEGIN(x) -# define NAMESPACE_END -// Get Doxygen to generate better documentation for these typedefs -# define DOCUMENTED_TYPEDEF(x, y) class y : public x {}; -// Make "protected" "private" so the functions and members are not documented -# define protected private -#else -# define NAMESPACE_BEGIN(x) namespace x { -# define NAMESPACE_END } -# define DOCUMENTED_TYPEDEF(x, y) typedef x y; -#endif -#define ANONYMOUS_NAMESPACE_BEGIN namespace { -#define ANONYMOUS_NAMESPACE_END } -#define USING_NAMESPACE(x) using namespace x; -#define DOCUMENTED_NAMESPACE_BEGIN(x) namespace x { -#define DOCUMENTED_NAMESPACE_END } - -// What is the type of the third parameter to bind? -// For Unix, the new standard is ::socklen_t (typically unsigned int), and the old standard is int. -// Unfortunately there is no way to tell whether or not socklen_t is defined. -// To work around this, TYPE_OF_SOCKLEN_T is a macro so that you can change it from the makefile. -#ifndef TYPE_OF_SOCKLEN_T -# if defined(_WIN32) || defined(__CYGWIN__) -# define TYPE_OF_SOCKLEN_T int -# else -# define TYPE_OF_SOCKLEN_T ::socklen_t -# endif -#endif - -#if defined(__CYGWIN__) && defined(PREFER_WINDOWS_STYLE_SOCKETS) -# define __USE_W32_SOCKETS -#endif - -typedef unsigned char byte; // put in global namespace to avoid ambiguity with other byte typedefs - -NAMESPACE_BEGIN(CryptoPP) - -typedef unsigned short word16; -typedef unsigned int word32; - -#if defined(_MSC_VER) || defined(__BORLANDC__) - typedef unsigned __int64 word64; - #define W64LIT(x) x##ui64 -#elif (_LP64 || __LP64__) && ((__arm64__ || __aarch64__) || !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562)) - typedef unsigned long word64; - #define W64LIT(x) x##UL -#else - typedef unsigned long long word64; - #define W64LIT(x) x##ULL -#endif - -// define large word type, used for file offsets and such -typedef word64 lword; -const lword LWORD_MAX = W64LIT(0xffffffffffffffff); - -// Clang pretends to be VC++, too. -// See http://github.com/weidai11/cryptopp/issues/147 -#if defined(_MSC_VER) && defined(__clang__) -# error: "Unsupported configuration" -#endif - -#ifdef __GNUC__ - #define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#endif - -// Apple and LLVM's Clang. Apple Clang version 7.0 roughly equals LLVM Clang version 3.7 -#if defined(__clang__ ) && !defined(__apple_build_version__) - #define CRYPTOPP_LLVM_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) - #define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1 -#elif defined(__clang__ ) && defined(__apple_build_version__) - #define CRYPTOPP_APPLE_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) - #define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1 -#endif - -#ifdef _MSC_VER - #define CRYPTOPP_MSC_VERSION (_MSC_VER) -#endif - -// Need GCC 4.6/Clang 1.7/Apple Clang 2.0 or above due to "GCC diagnostic {push|pop}" -#if (CRYPTOPP_GCC_VERSION >= 40600) || (CRYPTOPP_LLVM_CLANG_VERSION >= 10700) || (CRYPTOPP_APPLE_CLANG_VERSION >= 20000) - #define CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 1 -#endif - -// Clang due to "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232 -// TODO: supply the upper version when LLVM fixes it. We set it to 20.0 for compilation purposes. -#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && CRYPTOPP_LLVM_CLANG_VERSION <= 200000) || (defined(CRYPTOPP_APPLE_CLANG_VERSION) && CRYPTOPP_APPLE_CLANG_VERSION <= 200000) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER) - #define CRYPTOPP_DISABLE_INTEL_ASM 1 -#endif - -// define hword, word, and dword. these are used for multiprecision integer arithmetic -// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx -#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__)) - typedef word32 hword; - typedef word64 word; -#else - #define CRYPTOPP_NATIVE_DWORD_AVAILABLE 1 - #if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__) - #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && CRYPTOPP_GCC_VERSION >= 30400 - // GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3 - // mode(TI) division broken on amd64 with GCC earlier than GCC 3.4 - typedef word32 hword; - typedef word64 word; - typedef __uint128_t dword; - typedef __uint128_t word128; - #define CRYPTOPP_WORD128_AVAILABLE 1 - #else - // if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results - typedef word16 hword; - typedef word32 word; - typedef word64 dword; - #endif - #else - // being here means the native register size is probably 32 bits or less - #define CRYPTOPP_BOOL_SLOW_WORD64 1 - typedef word16 hword; - typedef word32 word; - typedef word64 dword; - #endif -#endif -#ifndef CRYPTOPP_BOOL_SLOW_WORD64 - #define CRYPTOPP_BOOL_SLOW_WORD64 0 -#endif - -const unsigned int WORD_SIZE = sizeof(word); -const unsigned int WORD_BITS = WORD_SIZE * 8; - -NAMESPACE_END - -#ifndef CRYPTOPP_L1_CACHE_LINE_SIZE - // This should be a lower bound on the L1 cache line size. It's used for defense against timing attacks. - // Also see http://stackoverflow.com/questions/794632/programmatically-get-the-cache-line-size. - #if defined(_M_X64) || defined(__x86_64__) || (__arm64__) || (__aarch64__) - #define CRYPTOPP_L1_CACHE_LINE_SIZE 64 - #else - // L1 cache line size is 32 on Pentium III and earlier - #define CRYPTOPP_L1_CACHE_LINE_SIZE 32 - #endif -#endif - -#if defined(_MSC_VER) - #if _MSC_VER == 1200 - #include - #endif - #if _MSC_VER > 1200 || defined(_mm_free) - #define CRYPTOPP_MSVC6PP_OR_LATER // VC 6 processor pack or later - #else - #define CRYPTOPP_MSVC6_NO_PP // VC 6 without processor pack - #endif -#endif - -#ifndef CRYPTOPP_ALIGN_DATA - #if defined(CRYPTOPP_MSVC6PP_OR_LATER) - #define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x)) - #elif defined(__GNUC__) - #define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x))) - #else - #define CRYPTOPP_ALIGN_DATA(x) - #endif -#endif - -#ifndef CRYPTOPP_SECTION_ALIGN16 -#if defined(__GNUC__) && !defined(__APPLE__) - // the alignment attribute doesn't seem to work without this section attribute when -fdata-sections is turned on - #define CRYPTOPP_SECTION_ALIGN16 __attribute__((section ("CryptoPP_Align16"))) - #else - #define CRYPTOPP_SECTION_ALIGN16 - #endif -#endif - -// The section attribute attempts to initialize CPU flags to avoid Valgrind findings above -O1 -#if ((defined(__MACH__) && defined(__APPLE__)) && ((CRYPTOPP_LLVM_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70100) || (CRYPTOPP_GCC_VERSION >= 40300))) - #define CRYPTOPP_SECTION_INIT __attribute__((section ("__DATA,__data"))) -#elif (defined(__ELF__) && (CRYPTOPP_GCC_VERSION >= 40300)) - #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon"))) -#else - #define CRYPTOPP_SECTION_INIT -#endif - -#if defined(_MSC_VER) || defined(__fastcall) - #define CRYPTOPP_FASTCALL __fastcall -#else - #define CRYPTOPP_FASTCALL -#endif - -// VC60 workaround: it doesn't allow typename in some places -#if defined(_MSC_VER) && (_MSC_VER < 1300) -#define CPP_TYPENAME -#else -#define CPP_TYPENAME typename -#endif - -// VC60 workaround: can't cast unsigned __int64 to float or double -#if defined(_MSC_VER) && !defined(CRYPTOPP_MSVC6PP_OR_LATER) -#define CRYPTOPP_VC6_INT64 (__int64) -#else -#define CRYPTOPP_VC6_INT64 -#endif - -#ifdef _MSC_VER -#define CRYPTOPP_NO_VTABLE __declspec(novtable) -#else -#define CRYPTOPP_NO_VTABLE -#endif - -#ifdef _MSC_VER - // 4127: conditional expression is constant - // 4231: nonstandard extension used : 'extern' before template explicit instantiation - // 4250: dominance - // 4251: member needs to have dll-interface - // 4275: base needs to have dll-interface - // 4505: unreferenced local function - // 4512: assignment operator not generated - // 4660: explicitly instantiating a class that's already implicitly instantiated - // 4661: no suitable definition provided for explicit template instantiation request - // 4786: identifer was truncated in debug information - // 4355: 'this' : used in base member initializer list - // 4910: '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation -# pragma warning(disable: 4127 4231 4250 4251 4275 4505 4512 4660 4661 4786 4355 4910) - // Security related, possible defects - // http://blogs.msdn.com/b/vcblog/archive/2010/12/14/off-by-default-compiler-warnings-in-visual-c.aspx -# pragma warning(once: 4191 4242 4263 4264 4266 4302 4826 4905 4906 4928) -#endif - -#ifdef __BORLANDC__ -// 8037: non-const function called for const object. needed to work around BCB2006 bug -# pragma warn -8037 -#endif - -// [GCC Bug 53431] "C++ preprocessor ignores #pragma GCC diagnostic". Clang honors it. -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wunknown-pragmas" -# pragma GCC diagnostic ignored "-Wunused-function" -#endif - -// You may need to force include a C++ header on Android when using STLPort to ensure -// _STLPORT_VERSION is defined: CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -include iosfwd" -// TODO: Figure out C++17 and lack of std::uncaught_exception -#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT))) -#define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION -#endif - -#ifndef CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION -#define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE -#endif - -#ifdef CRYPTOPP_DISABLE_X86ASM // for backwards compatibility: this macro had both meanings -#define CRYPTOPP_DISABLE_ASM -#define CRYPTOPP_DISABLE_SSE2 -#endif - -// Apple's Clang prior to 5.0 cannot handle SSE2 (and Apple does not use LLVM Clang numbering...) -#if defined(CRYPTOPP_APPLE_CLANG_VERSION) && (CRYPTOPP_APPLE_CLANG_VERSION < 50000) -# define CRYPTOPP_DISABLE_ASM -#endif - -// Sun Studio 12 provides GCC inline assembly, http://blogs.oracle.com/x86be/entry/gcc_style_asm_inlining_support -// We can enable SSE2 for Sun Studio in the makefile with -D__SSE2__, but users may not compile with it. -#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(__SSE2__) && defined(__x86_64__) && (__SUNPRO_CC >= 0x5100) -# define __SSE2__ 1 -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && ((defined(_MSC_VER) && defined(_M_IX86)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)))) - // C++Builder 2010 does not allow "call label" where label is defined within inline assembly - #define CRYPTOPP_X86_ASM_AVAILABLE - - #if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__)) - #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1 - #else - #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0 - #endif - - #if !defined(CRYPTOPP_DISABLE_SSE3) && (_MSC_VER >= 1500 || (defined(__SSE3__) && defined(__SSSE3__))) - #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 1 - #else - #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0 - #endif -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && defined(_MSC_VER) && defined(_M_X64) - #define CRYPTOPP_X64_MASM_AVAILABLE -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && defined(__GNUC__) && defined(__x86_64__) - #define CRYPTOPP_X64_ASM_AVAILABLE -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || defined(__SSE2__)) && !defined(_M_ARM) - #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 0 -#endif - -// Intrinsics availible in GCC 4.3 (http://gcc.gnu.org/gcc-4.3/changes.html) and -// MSVC 2008 (http://msdn.microsoft.com/en-us/library/bb892950%28v=vs.90%29.aspx) -// SunCC could generate SSE4 at 12.1, but the intrinsics are missing until 12.4. -#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SSE4) && !defined(_M_ARM) && ((_MSC_VER >= 1500) || (defined(__SSE4_1__) && defined(__SSE4_2__))) - #define CRYPTOPP_BOOL_SSE4_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_SSE4_INTRINSICS_AVAILABLE 0 -#endif - -// Don't disgorge AES-NI from CLMUL. There will be two to four subtle breaks -#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_AESNI) && !defined(_M_ARM) && (_MSC_FULL_VER >= 150030729 || __INTEL_COMPILER >= 1110 || (defined(__AES__) && defined(__PCLMUL__))) - #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 0 -#endif - -#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SHA) && !defined(_M_ARM) && ((_MSC_VER >= 1900) || defined(__SHA__)) - #define CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE 1 -#else - #define CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE 0 -#endif - -// Requires ARMv7 and ACLE 1.0. Testing shows ARMv7 is really ARMv7a under most toolchains. -#if !defined(CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) -# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM) -# define CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE 1 -# endif -#endif - -// Requires ARMv8 and ACLE 2.0. For GCC, requires 4.8 and above. -// Microsoft plans to support ARM-64, but its not clear how to detect it. -// TODO: Add MSC_VER and ARM-64 platform define when available -#if !defined(CRYPTOPP_BOOL_ARM_CRC32_INTRINSICS_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) -# if defined(__ARM_FEATURE_CRC32) || defined(_M_ARM64) -# define CRYPTOPP_BOOL_ARM_CRC32_INTRINSICS_AVAILABLE 1 -# endif -#endif - -// Requires ARMv8 and ACLE 2.0. For GCC, requires 4.8 and above. -// Microsoft plans to support ARM-64, but its not clear how to detect it. -// TODO: Add MSC_VER and ARM-64 platform define when available -#if !defined(CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) -# if defined(__ARM_FEATURE_CRYPTO) || defined(_M_ARM64) -# define CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE 1 -# endif -#endif - -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) - #define CRYPTOPP_BOOL_ALIGN16 1 -#else - #define CRYPTOPP_BOOL_ALIGN16 0 -#endif - -// how to allocate 16-byte aligned memory (for SSE2) -#if defined(CRYPTOPP_MSVC6PP_OR_LATER) - #define CRYPTOPP_MM_MALLOC_AVAILABLE -#elif defined(__APPLE__) - #define CRYPTOPP_APPLE_MALLOC_AVAILABLE -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - #define CRYPTOPP_MALLOC_ALIGNMENT_IS_16 -#elif defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) - #define CRYPTOPP_MEMALIGN_AVAILABLE -#else - #define CRYPTOPP_NO_ALIGNED_ALLOC -#endif - -// Apple always provides 16-byte aligned, and tells us to use calloc -// http://developer.apple.com/library/mac/documentation/Performance/Conceptual/ManagingMemory/Articles/MemoryAlloc.html - -// how to disable inlining -#if defined(_MSC_VER) && _MSC_VER >= 1300 -# define CRYPTOPP_NOINLINE_DOTDOTDOT -# define CRYPTOPP_NOINLINE __declspec(noinline) -#elif defined(__GNUC__) -# define CRYPTOPP_NOINLINE_DOTDOTDOT -# define CRYPTOPP_NOINLINE __attribute__((noinline)) -#else -# define CRYPTOPP_NOINLINE_DOTDOTDOT ... -# define CRYPTOPP_NOINLINE -#endif - -// How to declare class constants -// Use enum for OS X 10.5 ld, http://github.com/weidai11/cryptopp/issues/255 -#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) || defined(CRYPTOPP_DOXYGEN_PROCESSING) -# define CRYPTOPP_CONSTANT(x) enum {x}; -#else -# define CRYPTOPP_CONSTANT(x) static const int x; -#endif - -// Linux provides X32, which is 32-bit integers, longs and pointers on x86_64 using the full x86_64 register set. -// Detect via __ILP32__ (http://wiki.debian.org/X32Port). However, __ILP32__ shows up in more places than -// the System V ABI specs calls out, like on some Solaris installations and just about any 32-bit system with Clang. -#if (defined(__ILP32__) || defined(_ILP32)) && defined(__x86_64__) - #define CRYPTOPP_BOOL_X32 1 -#else - #define CRYPTOPP_BOOL_X32 0 -#endif - -// see http://predef.sourceforge.net/prearch.html -#if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__)) && !CRYPTOPP_BOOL_X32 - #define CRYPTOPP_BOOL_X86 1 -#else - #define CRYPTOPP_BOOL_X86 0 -#endif - -#if (defined(_M_X64) || defined(__x86_64__)) && !CRYPTOPP_BOOL_X32 - #define CRYPTOPP_BOOL_X64 1 -#else - #define CRYPTOPP_BOOL_X64 0 -#endif - -// Undo the ASM and Intrinsic related defines due to X32. -#if CRYPTOPP_BOOL_X32 -# undef CRYPTOPP_BOOL_X64 -# undef CRYPTOPP_X64_ASM_AVAILABLE -# undef CRYPTOPP_X64_MASM_AVAILABLE -#endif - -#if defined(__arm__) || defined(__aarch32__) || defined(_M_ARM) - #define CRYPTOPP_BOOL_ARM32 1 -#else - #define CRYPTOPP_BOOL_ARM32 0 -#endif - -// Microsoft plans to support ARM-64, but its not clear how to detect it. -// TODO: Add MSC_VER and ARM-64 platform define when available -#if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) - #define CRYPTOPP_BOOL_ARM64 1 -#else - #define CRYPTOPP_BOOL_ARM64 0 -#endif - -#if !defined(CRYPTOPP_NO_UNALIGNED_DATA_ACCESS) && !defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) -#if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || defined(__powerpc__) || (__ARM_FEATURE_UNALIGNED >= 1)) - #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS -#endif -#endif - -// ***************** determine availability of OS features ******************** - -#ifndef NO_OS_DEPENDENCE - -#if defined(_WIN32) || defined(__CYGWIN__) -#define CRYPTOPP_WIN32_AVAILABLE -#endif - -#if defined(__unix__) || defined(__MACH__) || defined(__NetBSD__) || defined(__sun) -#define CRYPTOPP_UNIX_AVAILABLE -#endif - -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) -#define CRYPTOPP_BSD_AVAILABLE -#endif - -#if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) -# define HIGHRES_TIMER_AVAILABLE -#endif - -#ifdef CRYPTOPP_WIN32_AVAILABLE -# if !defined(WINAPI_FAMILY) -# define THREAD_TIMER_AVAILABLE -# elif defined(WINAPI_FAMILY) -# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) -# define THREAD_TIMER_AVAILABLE -# endif -# endif -#endif - -#ifdef CRYPTOPP_UNIX_AVAILABLE -# define HAS_BERKELEY_STYLE_SOCKETS -# define SOCKETS_AVAILABLE -#endif - -// Sockets are only available under Windows Runtime desktop partition apps (despite the MSDN literature) -#ifdef CRYPTOPP_WIN32_AVAILABLE -# define HAS_WINDOWS_STYLE_SOCKETS -# if !defined(WINAPI_FAMILY) -# define SOCKETS_AVAILABLE -# elif defined(WINAPI_FAMILY) -# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) -# define SOCKETS_AVAILABLE -# endif -# endif -#endif - -#if defined(HAS_WINDOWS_STYLE_SOCKETS) && (!defined(HAS_BERKELEY_STYLE_SOCKETS) || defined(PREFER_WINDOWS_STYLE_SOCKETS)) -# define USE_WINDOWS_STYLE_SOCKETS -#else -# define USE_BERKELEY_STYLE_SOCKETS -#endif - -#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(SOCKETS_AVAILABLE) && !defined(USE_BERKELEY_STYLE_SOCKETS) -# define WINDOWS_PIPES_AVAILABLE -#endif - -#if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING) -# define NONBLOCKING_RNG_AVAILABLE -# define BLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -# define HAS_PTHREADS -# define THREADS_AVAILABLE -#endif - -// Newlib on Cygwin is a problem. __NEWLIB__ is not defined yet; use __CYGWIN__ as a proxy -// Also see https://github.com/weidai11/cryptopp/issues/315 -#if defined(CRYPTOPP_UNIX_AVAILABLE) && !defined(__CYGWIN__) -# define UNIX_SIGNALS_AVAILABLE 1 -#endif - -#ifdef CRYPTOPP_WIN32_AVAILABLE -# if !defined(WINAPI_FAMILY) -# define HAS_WINTHREADS -# define THREADS_AVAILABLE -# define NONBLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -# elif defined(WINAPI_FAMILY) -# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) -# define HAS_WINTHREADS -# define THREADS_AVAILABLE -# define NONBLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -# elif !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) -# if ((WINVER >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)) -# define NONBLOCKING_RNG_AVAILABLE -# define OS_RNG_AVAILABLE -# endif -# endif -# endif -#endif - -#endif // NO_OS_DEPENDENCE - -// ***************** DLL related ******************** - -#if defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) - -#ifdef CRYPTOPP_EXPORTS -#define CRYPTOPP_IS_DLL -#define CRYPTOPP_DLL __declspec(dllexport) -#elif defined(CRYPTOPP_IMPORTS) -#define CRYPTOPP_IS_DLL -#define CRYPTOPP_DLL __declspec(dllimport) -#else -#define CRYPTOPP_DLL -#endif - -#define CRYPTOPP_API __cdecl - -#else // not CRYPTOPP_WIN32_AVAILABLE - -#define CRYPTOPP_DLL -#define CRYPTOPP_API - -#endif // CRYPTOPP_WIN32_AVAILABLE - -#if defined(__MWERKS__) -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern class CRYPTOPP_DLL -#elif defined(__BORLANDC__) || defined(__SUNPRO_CC) -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL -#else -#define CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS extern template class CRYPTOPP_DLL -#endif - -#if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_IMPORTS) -#define CRYPTOPP_DLL_TEMPLATE_CLASS template class CRYPTOPP_DLL -#else -#define CRYPTOPP_DLL_TEMPLATE_CLASS CRYPTOPP_EXTERN_DLL_TEMPLATE_CLASS -#endif - -#if defined(__MWERKS__) -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern class -#elif defined(__BORLANDC__) || defined(__SUNPRO_CC) -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS template class -#else -#define CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS extern template class -#endif - -#if defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES) && !defined(CRYPTOPP_EXPORTS) -#define CRYPTOPP_STATIC_TEMPLATE_CLASS template class -#else -#define CRYPTOPP_STATIC_TEMPLATE_CLASS CRYPTOPP_EXTERN_STATIC_TEMPLATE_CLASS -#endif - -// ************** Unused variable *************** - -// Portable way to suppress warnings. -// Moved from misc.h due to circular depenedencies. -#define CRYPTOPP_UNUSED(x) ((void)(x)) - -// ************** Deprecated *************** - -#if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) -# define CRYPTOPP_DEPRECATED(msg) __attribute__((deprecated (msg))); -#elif (CRYPTOPP_GCC_VERSION) -# define CRYPTOPP_DEPRECATED(msg) __attribute__((deprecated)); -#else -# define CRYPTOPP_DEPRECATED(msg) -#endif - -// ***************** C++11 related ******************** - -// Visual Studio began at VS2010, http://msdn.microsoft.com/en-us/library/hh567368%28v=vs.110%29.aspx. -// Intel and C++11 language features, http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler -// GCC and C++11 language features, http://gcc.gnu.org/projects/cxx0x.html -// Clang and C++11 language features, http://clang.llvm.org/cxx_status.html -#if ((_MSC_VER >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION) -# define CRYPTOPP_CXX11 1 -#endif - -// Hack ahead. Apple's standard library does not have C++'s unique_ptr in C++11. We can't -// test for unique_ptr directly because some of the non-Apple Clangs on OS X fail the same -// way. However, modern standard libraries have , so we test for it instead. -// Thanks to Jonathan Wakely for devising the clever test for modern/ancient versions. -// TODO: test under Xcode 3, where g++ is really g++. -#if defined(__APPLE__) && defined(__clang__) -# if !(defined(__has_include) && __has_include()) -# undef CRYPTOPP_CXX11 -# endif -#endif - -// C++11 or C++14 is available -#if defined(CRYPTOPP_CXX11) - -// atomics: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.1/3.2; Intel 13.0; SunCC 12.5. -#if (CRYPTOPP_MSC_VERSION >= 1700) -# define CRYPTOPP_CXX11_ATOMICS 1 -#elif (__INTEL_COMPILER >= 1300) -# define CRYPTOPP_CXX11_ATOMICS 1 -#elif defined(__clang__) -# if __has_feature(cxx_atomic) -# define CRYPTOPP_CXX11_ATOMICS 1 -# endif -#elif (CRYPTOPP_GCC_VERSION >= 40400) -# define CRYPTOPP_CXX11_ATOMICS 1 -#elif (__SUNPRO_CC >= 0x5140) -# define CRYPTOPP_CXX11_ATOMICS 1 -#endif // atomics - -// synchronization: MS at VS2012 (17.00); GCC at 4.4; Clang at 3.3; Xcode 5.0; Intel 12.0; SunCC 12.4. -// TODO: verify Clang and Intel versions; find __has_feature(x) extension for Clang -#if (CRYPTOPP_MSC_VERSION >= 1700) -# define CRYPTOPP_CXX11_SYNCHRONIZATION 1 -#elif (__INTEL_COMPILER >= 1200) -# define CRYPTOPP_CXX11_SYNCHRONIZATION 1 -#elif (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50000) -# define CRYPTOPP_CXX11_SYNCHRONIZATION 1 -#elif (CRYPTOPP_GCC_VERSION >= 40400) -# define CRYPTOPP_CXX11_SYNCHRONIZATION 1 -#elif (__SUNPRO_CC >= 0x5130) -# define CRYPTOPP_CXX11_SYNCHRONIZATION 1 -#endif // synchronization - -// alignof/alignas: MS at VS2015 (19.00); GCC at 4.8; Clang at 3.3; Intel 15.0; SunCC 12.4. -#if (CRYPTOPP_MSC_VERSION >= 1900) -# define CRYPTOPP_CXX11_ALIGNAS 1 -# define CRYPTOPP_CXX11_ALIGNOF 1 -#elif (__INTEL_COMPILER >= 1500) -# define CRYPTOPP_CXX11_ALIGNAS 1 -# define CRYPTOPP_CXX11_ALIGNOF 1 -#elif defined(__clang__) -# if __has_feature(cxx_alignas) -# define CRYPTOPP_CXX11_ALIGNAS 1 -# endif -# if __has_feature(cxx_alignof) -# define CRYPTOPP_CXX11_ALIGNOF 1 -# endif -#elif (CRYPTOPP_GCC_VERSION >= 40800) -# define CRYPTOPP_CXX11_ALIGNAS 1 -# define CRYPTOPP_CXX11_ALIGNOF 1 -#elif (__SUNPRO_CC >= 0x5130) -# define CRYPTOPP_CXX11_ALIGNAS 1 -# define CRYPTOPP_CXX11_ALIGNOF 1 -#endif // alignof/alignas - -// noexcept: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.0; Intel 14.0; SunCC 12.4. -#if (CRYPTOPP_MSC_VERSION >= 1900) -# define CRYPTOPP_CXX11_NOEXCEPT 1 -#elif (__INTEL_COMPILER >= 1400) -# define CRYPTOPP_CXX11_NOEXCEPT 1 -#elif defined(__clang__) -# if __has_feature(cxx_noexcept) -# define CRYPTOPP_CXX11_NOEXCEPT 1 -# endif -#elif (CRYPTOPP_GCC_VERSION >= 40600) -# define CRYPTOPP_CXX11_NOEXCEPT 1 -#elif (__SUNPRO_CC >= 0x5130) -# define CRYPTOPP_CXX11_NOEXCEPT 1 -#endif // noexcept compilers - -// variadic templates: MS at VS2013 (18.00); GCC at 4.3; Clang at 2.9; Intel 12.1; SunCC 12.4. -#if (CRYPTOPP_MSC_VERSION >= 1800) -# define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1 -#elif (__INTEL_COMPILER >= 1210) -# define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1 -#elif defined(__clang__) -# if __has_feature(cxx_variadic_templates) -# define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1 -# endif -#elif (CRYPTOPP_GCC_VERSION >= 40300) -# define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1 -#elif (__SUNPRO_CC >= 0x5130) -# define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1 -#endif // variadic templates - -// constexpr: MS at VS2015 (19.00); GCC at 4.6; Clang at 3.0; Intel 16.0; SunCC 12.4. -// Intel has mis-supported the feature since at least ICPC 13.00 -#if (CRYPTOPP_MSC_VERSION >= 1900) -# define CRYPTOPP_CXX11_CONSTEXPR 1 -#elif (__INTEL_COMPILER >= 1600) -# define CRYPTOPP_CXX11_CONSTEXPR 1 -#elif defined(__clang__) -# if __has_feature(cxx_constexpr) -# define CRYPTOPP_CXX11_CONSTEXPR 1 -# endif -#elif (CRYPTOPP_GCC_VERSION >= 40600) -# define CRYPTOPP_CXX11_CONSTEXPR 1 -#elif (__SUNPRO_CC >= 0x5130) -# define CRYPTOPP_CXX11_CONSTEXPR 1 -#endif // constexpr compilers - -// TODO: Emplacement, R-values and Move semantics -// Needed because we are catching warnings with GCC and MSC - -#endif // CRYPTOPP_CXX11 - -#if defined(CRYPTOPP_CXX11_NOEXCEPT) -# define CRYPTOPP_THROW noexcept(false) -# define CRYPTOPP_NO_THROW noexcept(true) -#else -# define CRYPTOPP_THROW -# define CRYPTOPP_NO_THROW -#endif // CRYPTOPP_CXX11_NOEXCEPT - -// http://stackoverflow.com/a/13867690/608639 -#if defined(CRYPTOPP_CXX11_CONSTEXPR) -# define CRYPTOPP_STATIC_CONSTEXPR static constexpr const -# define CRYPTOPP_CONSTEXPR constexpr -#else -# define CRYPTOPP_STATIC_CONSTEXPR static const -# define CRYPTOPP_CONSTEXPR -#endif // CRYPTOPP_CXX11_CONSTEXPR - -// Hack... CRYPTOPP_ALIGN_DATA is defined earlier, before C++11 alignas availability is determined -#if defined(CRYPTOPP_CXX11_ALIGNAS) -# undef CRYPTOPP_ALIGN_DATA -# define CRYPTOPP_ALIGN_DATA(x) alignas(x) -#endif // CRYPTOPP_CXX11_ALIGNAS - -// Hack... CRYPTOPP_CONSTANT is defined earlier, before C++11 constexpr availability is determined -// http://stackoverflow.com/q/35213098/608639 -#if defined(CRYPTOPP_CXX11_CONSTEXPR) -# undef CRYPTOPP_CONSTANT -# define CRYPTOPP_CONSTANT(x) constexpr static int x; -#endif - -// OK to comment the following out, but please report it so we can fix it. -// C++17 value taken from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4567.pdf. -#if (defined(__cplusplus) && (__cplusplus >= 199711L) && (__cplusplus < 201402L)) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) -# error "std::uncaught_exception is not available. This is likely a configuration error." -#endif - -#endif diff --git a/config.h b/config.h index f2a007fb..3051e43d 100644 --- a/config.h +++ b/config.h @@ -75,10 +75,6 @@ // define this to retain (as much as possible) old deprecated function and class names // #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -// Define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2. -// Also see https://cryptopp.com/wiki/Config.h#Avoid_MAINTAIN_BACKWARDS_COMPATIBILITY -// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - // Define this if you want or need the library's memcpy_s and memmove_s. // See http://github.com/weidai11/cryptopp/issues/28. // #if !defined(CRYPTOPP_WANT_SECURE_LIB) diff --git a/cryptest.sh b/cryptest.sh index f64e649f..ef62d123 100755 --- a/cryptest.sh +++ b/cryptest.sh @@ -30,12 +30,6 @@ # rather than all of them. Its useful at places like the GCC Compile Farm, where being nice is policy. # ./cryptest.sh nice -# You can test using original config.h with the following. 'orig', 'original' and 'config.h' are synonyms: -# ./cryptest.sh original - -# You can test 5.6.2 compatibility using config.compat with the following. 'compat', 'compatibility' and 'config.compat' are synonyms: -# ./cryptest.sh compatibility - ############################################ # Set to suite your taste @@ -177,9 +171,6 @@ do WANT_NICE=1 elif [[ ($("$EGREP" -ix "orig" <<< "$ARG") || $("$EGREP" -ix "original" <<< "$ARG") || $("$EGREP" -ix "config.h" <<< "$ARG")) ]]; then git checkout config.h > /dev/null 2>&1 - elif [[ ($("$EGREP" -ix "compat" <<< "$ARG") || $("$EGREP" -ix "compatibility" <<< "$ARG") || $("$EGREP" -ix "config.compat" <<< "$ARG")) ]]; then - git checkout config.compatibility > /dev/null 2>&1 - cp config.compatibility config.h else echo "Unknown option $ARG" fi @@ -2675,63 +2666,6 @@ if [[ "$HAVE_X32" -ne "0" ]]; then fi fi -############################################ -# Backwards compatibility -if true; then - - ############################################ - # Debug build - echo - echo "************************************" | tee -a "$TEST_RESULTS" - echo "Testing: Debug, MAINTAIN_BACKWARDS_COMPATIBILITY" | tee -a "$TEST_RESULTS" - echo - - "$MAKE" clean > /dev/null 2>&1 - rm -f adhoc.cpp > /dev/null 2>&1 - - CXXFLAGS="$DEBUG_CXXFLAGS -DCRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS ${DEPRECATED_CXXFLAGS[@]}" - CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" - - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS" - else - ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS" - fi - ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS" - fi - fi - - ############################################ - # Release build - echo - echo "************************************" | tee -a "$TEST_RESULTS" - echo "Testing: Release, MAINTAIN_BACKWARDS_COMPATIBILITY" | tee -a "$TEST_RESULTS" - echo - - "$MAKE" clean > /dev/null 2>&1 - rm -f adhoc.cpp > /dev/null 2>&1 - - CXXFLAGS="$RELEASE_CXXFLAGS -DCRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS ${DEPRECATED_CXXFLAGS[@]}" - CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" - - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS" - fi - - ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS" - fi - ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" - if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then - echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS" - fi -fi - ############################################ # init_priority if true; then diff --git a/cryptlib.h b/cryptlib.h index 91f2c216..4c936108 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -159,9 +159,10 @@ public: OTHER_ERROR }; + virtual ~Exception() throw() {} + //! \brief Construct a new Exception explicit Exception(ErrorType errorType, const std::string &s) : m_errorType(errorType), m_what(s) {} - virtual ~Exception() throw() {} //! \brief Retrieves a C-string describing the exception const char *what() const throw() {return (m_what.c_str());} @@ -218,9 +219,9 @@ public: class CRYPTOPP_DLL OS_Error : public Exception { public: + virtual ~OS_Error() throw() {} OS_Error(ErrorType errorType, const std::string &s, const std::string& operation, int errorCode) : Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {} - ~OS_Error() throw() {} //! \brief Retrieve the operating system API that reported the error const std::string & GetOperation() const {return m_operation;} @@ -496,9 +497,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Algorithm : public Clonable { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~Algorithm() {} -#endif //! \brief Interface for all crypto algorithms //! \param checkSelfTestStatus determines whether the object can proceed if the self @@ -735,9 +734,7 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~BlockTransformation() {} -#endif //! \brief Encrypt or decrypt a block //! \param inBlock the input message before processing @@ -826,9 +823,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~StreamTransformation() {} -#endif //! \brief Provides a reference to this object //! \return A reference to this object @@ -935,9 +930,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HashTransformation : public Algorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~HashTransformation() {} -#endif //! \brief Provides a reference to this object //! \return A reference to this object @@ -1128,9 +1121,7 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipher : public MessageAuthenticationCode, public StreamTransformation { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~AuthenticatedSymmetricCipher() {} -#endif //! \brief Exception thrown when the object is in the wrong state for the operation //! \details this indicates that a member function was called in the wrong state, for example trying to encrypt @@ -1197,9 +1188,7 @@ typedef SymmetricCipher StreamCipher; class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~RandomNumberGenerator() {} -#endif //! \brief Update RNG state with additional unpredictable values //! \param input the entropy to add to the generator @@ -1366,9 +1355,7 @@ public: // placed up here for CW8 static const std::string &NULL_CHANNEL; // same as DEFAULT_CHANNEL, for backwards compatibility -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~BufferedTransformation() {} -#endif //! \brief Construct a BufferedTransformation BufferedTransformation() : Algorithm(false) {} @@ -2055,10 +2042,6 @@ CRYPTOPP_DLL BufferedTransformation & TheBitBucket(); class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoMaterial : public NameValuePairs { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~CryptoMaterial() {} -#endif - //! Exception thrown when invalid crypto material is detected class CRYPTOPP_DLL InvalidMaterial : public InvalidDataFormat { @@ -2066,6 +2049,8 @@ public: explicit InvalidMaterial(const std::string &s) : InvalidDataFormat(s) {} }; + virtual ~CryptoMaterial() {} + //! \brief Assign values to this object //! \details This function can be used to create a public key from a private key. virtual void AssignFrom(const NameValuePairs &source) =0; @@ -2170,9 +2155,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GeneratableCryptoMaterial : virtual public CryptoMaterial { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~GeneratableCryptoMaterial() {} -#endif //! \brief Generate a random key or crypto parameters //! \param rng a RandomNumberGenerator to produce keying material @@ -2213,9 +2196,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoParameters : public GeneratableCrypt class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AsymmetricAlgorithm : public Algorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~AsymmetricAlgorithm() {} -#endif //! \brief Retrieves a reference to CryptoMaterial //! \return a reference to the crypto material @@ -2242,9 +2223,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PublicKeyAlgorithm() {} -#endif // VC60 workaround: no co-variant return type @@ -2270,9 +2249,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PrivateKeyAlgorithm() {} -#endif //! \brief Retrieves a reference to a Private Key //! \return a reference the private key @@ -2293,9 +2270,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyAgreementAlgorithm : public AsymmetricAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~KeyAgreementAlgorithm() {} -#endif //! \brief Retrieves a reference to Crypto Parameters //! \return a reference the crypto parameters @@ -2351,8 +2326,8 @@ public: virtual size_t FixedMaxPlaintextLength() const {return 0;} #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - size_t MaxPlainTextLength(size_t cipherTextLength) const {return MaxPlaintextLength(cipherTextLength);} - size_t CipherTextLength(size_t plainTextLength) const {return CiphertextLength(plainTextLength);} + //size_t MaxPlainTextLength(size_t cipherTextLength) const {return MaxPlaintextLength(cipherTextLength);} + //size_t CipherTextLength(size_t plainTextLength) const {return CiphertextLength(plainTextLength);} #endif }; @@ -2397,9 +2372,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Decryptor : public PK_CryptoSystem, public PrivateKeyAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PK_Decryptor() {} -#endif //! \brief Decrypt a byte string //! \param rng a RandomNumberGenerator derived class @@ -2446,9 +2419,9 @@ public: }; #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef PK_CryptoSystem PK_FixedLengthCryptoSystem; -typedef PK_Encryptor PK_FixedLengthEncryptor; -typedef PK_Decryptor PK_FixedLengthDecryptor; +//typedef PK_CryptoSystem PK_FixedLengthCryptoSystem; +//typedef PK_Encryptor PK_FixedLengthEncryptor; +//typedef PK_Decryptor PK_FixedLengthDecryptor; #endif //! \class PK_SignatureScheme @@ -2553,9 +2526,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Signer : public PK_SignatureScheme, public PrivateKeyAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PK_Signer() {} -#endif //! \brief Create a new HashTransformation to accumulate the message to be signed //! \param rng a RandomNumberGenerator derived class @@ -2620,9 +2591,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_Verifier : public PK_SignatureScheme, public PublicKeyAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PK_Verifier() {} -#endif //! \brief Create a new HashTransformation to accumulate the message to be verified //! \return a pointer to a PK_MessageAccumulator @@ -2694,9 +2663,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyAgreementDomain : public KeyAgreementAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~SimpleKeyAgreementDomain() {} -#endif //! \brief Provides the size of the agreed value //! \return size of agreed value produced in this domain @@ -2759,9 +2726,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~AuthenticatedKeyAgreementDomain() {} -#endif //! \brief Provides the size of the agreed value //! \return size of agreed value produced in this domain @@ -2893,9 +2858,10 @@ public: UnexpectedMethodCall(const std::string &s) : Exception(OTHER_ERROR, s) {} }; - ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {} virtual ~ProtocolSession() {} + ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {} + virtual void InitializeSession(RandomNumberGenerator &rng, const NameValuePairs ¶meters) =0; bool GetThrowOnProtocolError() const {return m_throwOnProtocolError;} @@ -2924,9 +2890,7 @@ private: class KeyAgreementSession : public ProtocolSession { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~KeyAgreementSession() {} -#endif virtual unsigned int GetAgreedValueLength() const =0; virtual void GetAgreedValue(byte *agreedValue) const =0; @@ -2935,9 +2899,7 @@ public: class PasswordAuthenticatedKeyAgreementSession : public KeyAgreementSession { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PasswordAuthenticatedKeyAgreementSession() {} -#endif void InitializePasswordAuthenticatedKeyAgreementSession(RandomNumberGenerator &rng, const byte *myId, unsigned int myIdLength, @@ -2948,9 +2910,7 @@ public: class PasswordAuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PasswordAuthenticatedKeyAgreementDomain() {} -#endif //! return whether the domain parameters stored in this object are valid virtual bool ValidateDomainParameters(RandomNumberGenerator &rng) const diff --git a/default.cpp b/default.cpp index e2ad6d65..48d5d644 100644 --- a/default.cpp +++ b/default.cpp @@ -240,7 +240,7 @@ DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(const char *passphrase, Buffere , m_mac(NewDefaultEncryptorMAC((const byte *)passphrase, strlen(passphrase))) , m_throwException(throwException) { - SetFilter(new DefaultDecryptor(passphrase, m_hashVerifier=new HashVerifier(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException)); + SetFilter(new DefaultDecryptor(passphrase, m_hashVerifier=new HashVerificationFilter(*m_mac, NULL, HashVerificationFilter::PUT_MESSAGE), throwException)); } DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment, bool throwException) @@ -248,7 +248,7 @@ DefaultDecryptorWithMAC::DefaultDecryptorWithMAC(const byte *passphrase, size_t , m_mac(NewDefaultEncryptorMAC(passphrase, passphraseLength)) , m_throwException(throwException) { - SetFilter(new DefaultDecryptor(passphrase, passphraseLength, m_hashVerifier=new HashVerifier(*m_mac, NULL, HashVerifier::PUT_MESSAGE), throwException)); + SetFilter(new DefaultDecryptor(passphrase, passphraseLength, m_hashVerifier=new HashVerificationFilter(*m_mac, NULL, HashVerificationFilter::PUT_MESSAGE), throwException)); } DefaultDecryptor::State DefaultDecryptorWithMAC::CurrentState() const diff --git a/default.h b/default.h index 0d5eebbb..e2e82449 100644 --- a/default.h +++ b/default.h @@ -167,7 +167,7 @@ protected: private: member_ptr m_mac; - HashVerifier *m_hashVerifier; + HashVerificationFilter *m_hashVerifier; bool m_throwException; } CRYPTOPP_DEPRECATED ("DefaultDecryptorWithMAC will be changing in the near future because the algorithms are no longer secure"); diff --git a/dh.h b/dh.h index ddc1534e..1b7260a0 100644 --- a/dh.h +++ b/dh.h @@ -32,9 +32,7 @@ public: typedef DL_KeyAgreementAlgorithm_DH DH_Algorithm; typedef DH_Domain Domain; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DH_Domain() {} -#endif //! \brief Construct a Diffie-Hellman domain DH_Domain() {} diff --git a/dh2.h b/dh2.h index 83f7552e..884cc0b2 100644 --- a/dh2.h +++ b/dh2.h @@ -20,10 +20,7 @@ NAMESPACE_BEGIN(CryptoPP) class DH2 : public AuthenticatedKeyAgreementDomain { public: - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DH2() {} -#endif //! \brief Construct a DH2 DH2(SimpleKeyAgreementDomain &domain) diff --git a/ec2n.h b/ec2n.h index ab3ceeee..8795a5a7 100644 --- a/ec2n.h +++ b/ec2n.h @@ -28,9 +28,7 @@ public: typedef Field::Element FieldElement; typedef EC2NPoint Point; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~EC2N() {} -#endif //! \brief Construct an EC2N EC2N() {} @@ -108,9 +106,7 @@ template<> class EcPrecomputation : public DL_GroupPrecomputation & GetGroup() const {return m_ec;} diff --git a/eccrypto.h b/eccrypto.h index 49031483..ca04a54e 100644 --- a/eccrypto.h +++ b/eccrypto.h @@ -38,9 +38,7 @@ public: typedef Point Element; typedef IncompatibleCofactorMultiplication DefaultCofactorOption; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_EC() {} -#endif DL_GroupParameters_EC() : m_compress(false), m_encodeAsOID(true) {} DL_GroupParameters_EC(const OID &oid) @@ -156,9 +154,7 @@ class DL_PublicKey_EC : public DL_PublicKeyImpl > public: typedef typename EC::Point Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PublicKey_EC() {} -#endif void Initialize(const DL_GroupParameters_EC ¶ms, const Element &Q) {this->AccessGroupParameters() = params; this->SetPublicElement(Q);} @@ -179,9 +175,7 @@ class DL_PrivateKey_EC : public DL_PrivateKeyImpl > public: typedef typename EC::Point Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PrivateKey_EC() {} -#endif void Initialize(const DL_GroupParameters_EC ¶ms, const Integer &x) {this->AccessGroupParameters() = params; this->SetPrivateExponent(x);} @@ -206,10 +200,6 @@ template , COFACTOR_OPTION> Domain; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECDH() {} -#endif }; //! \class ECMQV @@ -221,10 +211,6 @@ template , COFACTOR_OPTION> Domain; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECMQV() {} -#endif }; //! \class ECHMQV @@ -237,10 +223,6 @@ template , COFACTOR_OPTION, HASH> Domain; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECHMQV() {} -#endif }; typedef ECHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA1 >::Domain ECHMQV160; @@ -259,10 +241,6 @@ template , COFACTOR_OPTION, HASH> Domain; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECFHMQV() {} -#endif }; typedef ECFHMQV< ECP, DL_GroupParameters_EC< ECP >::DefaultCofactorOption, SHA1 >::Domain ECFHMQV160; @@ -278,10 +256,6 @@ struct DL_Keys_EC { typedef DL_PublicKey_EC PublicKey; typedef DL_PrivateKey_EC PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Keys_EC() {} -#endif }; // Forward declaration; documented below @@ -296,10 +270,6 @@ struct DL_Keys_ECDSA { typedef DL_PublicKey_EC PublicKey; typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, ECDSA > PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Keys_ECDSA() {} -#endif }; //! \class DL_Algorithm_ECDSA @@ -310,10 +280,6 @@ class DL_Algorithm_ECDSA : public DL_Algorithm_GDSA { public: CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECDSA";} - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Algorithm_ECDSA() {} -#endif }; //! \class DL_Algorithm_ECNR @@ -324,10 +290,6 @@ class DL_Algorithm_ECNR : public DL_Algorithm_NR { public: CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECNR";} - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Algorithm_ECNR() {} -#endif }; //! \class ECDSA @@ -338,9 +300,6 @@ public: template struct ECDSA : public DL_SS, DL_Algorithm_ECDSA, DL_SignatureMessageEncodingMethod_DSA, H> { -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECDSA() {} -#endif }; //! \class ECNR @@ -350,9 +309,6 @@ struct ECDSA : public DL_SS, DL_Algorithm_ECDSA, DL_Signat template struct ECNR : public DL_SS, DL_Algorithm_ECNR, DL_SignatureMessageEncodingMethod_NR, H> { -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECNR() {} -#endif }; @@ -400,10 +356,6 @@ struct ECIES ECIES > { static std::string CRYPTOPP_API StaticAlgorithmName() {return "ECIES";} // TODO: fix this after name is standardized - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~ECIES() {} -#endif }; NAMESPACE_END diff --git a/ecp.h b/ecp.h index 93ab6267..4f6c35f7 100644 --- a/ecp.h +++ b/ecp.h @@ -26,9 +26,7 @@ public: typedef Integer FieldElement; typedef ECPPoint Point; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~ECP() {} -#endif //! \brief Construct an ECP ECP() {} @@ -116,9 +114,7 @@ template<> class EcPrecomputation : public DL_GroupPrecomputation &groupParams, byte *derivedKey, size_t derivedLength, const Integer &agreedElement, const Integer &ephemeralPublicKey, const NameValuePairs &derivationParams) const { @@ -103,10 +100,7 @@ template class ElGamalObjectImpl : public DL_ObjectImplBase, public ElGamalBase { public: - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~ElGamalObjectImpl() {} -#endif size_t FixedMaxPlaintextLength() const {return this->MaxPlaintextLength(FixedCiphertextLength());} size_t FixedCiphertextLength() const {return this->CiphertextLength(0);} @@ -138,7 +132,7 @@ struct ElGamal { typedef DL_CryptoSchemeOptions SchemeOptions; - CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "ElgamalEnc/Crypto++Padding";} + CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "ElgamalEnc/Crypto++Padding";} typedef SchemeOptions::GroupParameters GroupParameters; //! implements PK_Encryptor interface diff --git a/eprecomp.h b/eprecomp.h index cf44ce6c..611f4f21 100644 --- a/eprecomp.h +++ b/eprecomp.h @@ -19,16 +19,14 @@ class DL_GroupPrecomputation public: typedef T Element; + virtual ~DL_GroupPrecomputation() {} + virtual bool NeedConversions() const {return false;} virtual Element ConvertIn(const Element &v) const {return v;} virtual Element ConvertOut(const Element &v) const {return v;} virtual const AbstractGroup & GetGroup() const =0; virtual Element BERDecodeElement(BufferedTransformation &bt) const =0; virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_GroupPrecomputation() {} -#endif }; template @@ -37,6 +35,8 @@ class DL_FixedBasePrecomputation public: typedef T Element; + virtual ~DL_FixedBasePrecomputation() {} + virtual bool IsInitialized() const =0; virtual void SetBase(const DL_GroupPrecomputation &group, const Element &base) =0; virtual const Element & GetBase(const DL_GroupPrecomputation &group) const =0; @@ -45,10 +45,6 @@ public: virtual void Save(const DL_GroupPrecomputation &group, BufferedTransformation &storedPrecomputation) const =0; virtual Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const =0; virtual Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const =0; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_FixedBasePrecomputation() {} -#endif }; template @@ -57,6 +53,8 @@ class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation public: typedef T Element; + virtual ~DL_FixedBasePrecomputationImpl() {} + DL_FixedBasePrecomputationImpl() : m_windowSize(0) {} // DL_FixedBasePrecomputation @@ -71,10 +69,6 @@ public: Element Exponentiate(const DL_GroupPrecomputation &group, const Integer &exponent) const; Element CascadeExponentiate(const DL_GroupPrecomputation &group, const Integer &exponent, const DL_FixedBasePrecomputation &pc2, const Integer &exponent2) const; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_FixedBasePrecomputationImpl() {} -#endif - private: void PrepareCascade(const DL_GroupPrecomputation &group, std::vector > &eb, const Integer &exponent) const; diff --git a/factory.h b/factory.h index 9ff74dc4..43df9f20 100644 --- a/factory.h +++ b/factory.h @@ -1,3 +1,5 @@ +// factory.h - written and placed in the public domain by Wei Dai + #ifndef CRYPTOPP_OBJFACT_H #define CRYPTOPP_OBJFACT_H @@ -93,14 +95,16 @@ ObjectFactoryRegistry & ObjectFactoryRegistry -struct RegisterDefaultFactoryFor { -RegisterDefaultFactoryFor(const char *name=NULL) +struct RegisterDefaultFactoryFor { - // BCB2006 workaround - std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName()); - ObjectFactoryRegistry::Registry(). + RegisterDefaultFactoryFor(const char *name=NULL) + { + // BCB2006 workaround + std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName()); + ObjectFactoryRegistry::Registry(). RegisterFactory(n, new DefaultObjectFactory); -}}; + } +}; template void RegisterAsymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL) diff --git a/fhmqv.h b/fhmqv.h index b5eceb79..260324a1 100644 --- a/fhmqv.h +++ b/fhmqv.h @@ -28,9 +28,7 @@ public: typedef typename GroupParameters::Element Element; typedef FHMQV_Domain Domain; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~FHMQV_Domain() {} -#endif + virtual ~FHMQV_Domain() {} FHMQV_Domain(bool clientRole = true): m_role(clientRole ? RoleClient : RoleServer) {} diff --git a/filters.cpp b/filters.cpp index 9366ca79..3cce0d25 100644 --- a/filters.cpp +++ b/filters.cpp @@ -312,13 +312,6 @@ void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t lengt m_size += length; } -#if !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562) -FilterWithBufferedInput::FilterWithBufferedInput() - : Filter(), m_firstSize(SIZE_MAX), m_blockSize(0), m_lastSize(SIZE_MAX), m_firstInputDone(false) -{ -} -#endif - FilterWithBufferedInput::FilterWithBufferedInput(BufferedTransformation *attachment) : Filter(attachment), m_firstSize(SIZE_MAX), m_blockSize(0), m_lastSize(SIZE_MAX), m_firstInputDone(false) { diff --git a/filters.h b/filters.h index 87355152..34ef6765 100644 --- a/filters.h +++ b/filters.h @@ -36,9 +36,7 @@ NAMESPACE_BEGIN(CryptoPP) class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~Filter() {} -#endif //! \name ATTACHMENT //@{ @@ -149,18 +147,20 @@ protected: //! \note There should be a MessageEnd() immediately before MessageSeriesEnd(). bool OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL); -private: - member_ptr m_attachment; - protected: size_t m_inputPosition; int m_continueAt; + +private: + member_ptr m_attachment; }; //! \class FilterPutSpaceHelper //! \brief Create a working space in a BufferedTransformation struct CRYPTOPP_DLL FilterPutSpaceHelper { + virtual ~FilterPutSpaceHelper() {} + //! \brief Create a working space in a BufferedTransformation //! \param target BufferedTransformation for the working space //! \param channel channel for the working space @@ -220,6 +220,8 @@ struct CRYPTOPP_DLL FilterPutSpaceHelper class CRYPTOPP_DLL MeterFilter : public Bufferless { public: + virtual ~MeterFilter() {} + //! \brief Construct a MeterFilter //! \param attachment an optional attached transformation //! \param transparent flag indicating if the filter should function transparently @@ -315,11 +317,7 @@ public: class CRYPTOPP_DLL FilterWithBufferedInput : public Filter { public: - -#if !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562) - //! default FilterWithBufferedInput for temporaries - FilterWithBufferedInput(); -#endif + virtual ~FilterWithBufferedInput() {} //! \brief Construct a FilterWithBufferedInput with an attached transformation //! \param attachment an attached transformation @@ -434,6 +432,8 @@ protected: class CRYPTOPP_DLL FilterWithInputQueue : public Filter { public: + virtual ~FilterWithInputQueue() {} + //! \brief Construct a FilterWithInputQueue //! \param attachment an optional attached transformation FilterWithInputQueue(BufferedTransformation *attachment=NULL) : Filter(attachment) {} @@ -491,6 +491,8 @@ struct BlockPaddingSchemeDef class CRYPTOPP_DLL StreamTransformationFilter : public FilterWithBufferedInput, public BlockPaddingSchemeDef, private FilterPutSpaceHelper { public: + virtual ~StreamTransformationFilter() {} + //! \brief Construct a StreamTransformationFilter //! \param c reference to a StreamTransformation //! \param attachment an optional attached transformation @@ -514,15 +516,13 @@ protected: unsigned int m_optimalBufferSize; }; -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef StreamTransformationFilter StreamCipherFilter; -#endif - //! \class HashFilter //! \brief Filter wrapper for HashTransformation class CRYPTOPP_DLL HashFilter : public Bufferless, private FilterPutSpaceHelper { public: + virtual ~HashFilter() {} + //! \brief Construct a HashFilter //! \param hm reference to a HashTransformation //! \param attachment an optional attached transformation @@ -550,6 +550,8 @@ private: class CRYPTOPP_DLL HashVerificationFilter : public FilterWithBufferedInput { public: + virtual ~HashVerificationFilter() {} + //! \class HashVerificationFailed //! \brief Exception thrown when a data integrity check failure is encountered class HashVerificationFailed : public Exception @@ -606,8 +608,6 @@ private: SecByteBlock m_expectedHash; }; -typedef HashVerificationFilter HashVerifier; // for backwards compatibility - //! \class AuthenticatedEncryptionFilter //! \brief Filter wrapper for encrypting with AuthenticatedSymmetricCipher //! \details AuthenticatedEncryptionFilter() is a wrapper for encrypting with AuthenticatedSymmetricCipher(), @@ -617,6 +617,8 @@ typedef HashVerificationFilter HashVerifier; // for backwards compatibility class CRYPTOPP_DLL AuthenticatedEncryptionFilter : public StreamTransformationFilter { public: + virtual ~AuthenticatedEncryptionFilter() {} + //! \brief Construct a AuthenticatedEncryptionFilter //! \param c reference to a AuthenticatedSymmetricCipher //! \param attachment an optional attached transformation @@ -671,6 +673,8 @@ public: DEFAULT_FLAGS = THROW_EXCEPTION }; + virtual ~AuthenticatedDecryptionFilter() {} + //! \brief Construct a AuthenticatedDecryptionFilter //! \param c reference to a AuthenticatedSymmetricCipher //! \param attachment an optional attached transformation @@ -713,6 +717,8 @@ protected: class CRYPTOPP_DLL SignerFilter : public Unflushable { public: + virtual ~SignerFilter() {} + //! \brief Construct a SignerFilter //! \param rng a RandomNumberGenerator derived class //! \param signer a PK_Signer derived class @@ -767,6 +773,8 @@ public: DEFAULT_FLAGS = SIGNATURE_AT_BEGIN | PUT_RESULT }; + virtual ~SignatureVerificationFilter() {} + //! \brief Construct a SignatureVerificationFilter //! \param verifier a PK_Verifier derived class //! \param attachment an optional attached transformation @@ -815,6 +823,8 @@ public: PASS_EVERYTHING = PASS_SIGNALS | PASS_WAIT_OBJECTS }; + virtual ~Redirector() {} + //! \brief Construct a Redirector Redirector() : m_target(NULL), m_behavior(PASS_EVERYTHING) {} @@ -893,6 +903,8 @@ private: class CRYPTOPP_DLL OutputProxy : public CustomSignalPropagation { public: + virtual ~OutputProxy() {} + //! \brief Construct an OutputProxy //! \param owner the owning transformation //! \param passSignal flag indicating if signals should be passed @@ -939,6 +951,8 @@ private: class CRYPTOPP_DLL ProxyFilter : public FilterWithBufferedInput { public: + virtual ~ProxyFilter() {} + //! \brief Construct a ProxyFilter //! \param filter an output filter //! \param firstSize the first Put size @@ -1024,8 +1038,7 @@ template class StringSinkTemplate : public Bufferless { public: - // VC60 workaround: no T::char_type - typedef typename T::traits_type::char_type char_type; + virtual ~StringSinkTemplate() {} //! \brief Construct a StringSinkTemplate //! \param output std::basic_string type @@ -1038,6 +1051,8 @@ public: size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) { CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); + typedef typename T::traits_type::char_type char_type; + if (length > 0) { typename T::size_type size = m_output->size(); @@ -1063,6 +1078,8 @@ CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate; class RandomNumberSink : public Bufferless { public: + virtual ~RandomNumberSink() {} + //! \brief Construct a RandomNumberSink RandomNumberSink() : m_rng(NULL) {} @@ -1084,6 +1101,8 @@ private: class CRYPTOPP_DLL ArraySink : public Bufferless { public: + virtual ~ArraySink() {} + //! \brief Construct an ArraySink //! \param parameters a set of NameValuePairs to initialize this object //! \details Name::OutputBuffer() is a mandatory parameter using this constructor. @@ -1119,6 +1138,8 @@ protected: class CRYPTOPP_DLL ArrayXorSink : public ArraySink { public: + virtual ~ArrayXorSink() {} + //! \brief Construct an ArrayXorSink //! \param buf pointer to a memory buffer //! \param size length of the memory buffer @@ -1165,6 +1186,8 @@ private: class CRYPTOPP_DLL RandomNumberStore : public Store { public: + virtual ~RandomNumberStore() {} + RandomNumberStore() : m_rng(NULL), m_length(0), m_count(0) {} @@ -1216,9 +1239,7 @@ private: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~Source() {} -#endif //! \brief Construct a Source //! \param attachment an optional attached transformation @@ -1291,6 +1312,8 @@ template class SourceTemplate : public Source { public: + virtual ~SourceTemplate() {} + //! \brief Construct a SourceTemplate //! \tparam T the class or type //! \param attachment an attached transformation diff --git a/gfpcrypt.cpp b/gfpcrypt.cpp index 80fbd1b8..3d2b9251 100644 --- a/gfpcrypt.cpp +++ b/gfpcrypt.cpp @@ -204,7 +204,6 @@ void DL_GroupParameters_IntegerBased::GenerateRandom(RandomNumberGenerator &rng, Initialize(p, q, g); } -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 void DL_GroupParameters_IntegerBased::EncodeElement(bool reversible, const Element &element, byte *encoded) const { CRYPTOPP_UNUSED(reversible); @@ -216,7 +215,6 @@ unsigned int DL_GroupParameters_IntegerBased::GetEncodedElementSize(bool reversi CRYPTOPP_UNUSED(reversible); return GetModulus().ByteCount(); } -#endif Integer DL_GroupParameters_IntegerBased::DecodeElement(const byte *encoded, bool checkForGroupMembership) const { diff --git a/gfpcrypt.h b/gfpcrypt.h index 1b343d3f..e1e0a22b 100644 --- a/gfpcrypt.h +++ b/gfpcrypt.h @@ -35,10 +35,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE DL_GroupParameters_IntegerBased : public A typedef DL_GroupParameters_IntegerBased ThisClass; public: - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_IntegerBased() {} -#endif void Initialize(const DL_GroupParameters_IntegerBased ¶ms) {Initialize(params.GetModulus(), params.GetSubgroupOrder(), params.GetSubgroupGenerator());} @@ -66,16 +63,9 @@ public: bool ValidateElement(unsigned int level, const Integer &element, const DL_FixedBasePrecomputation *precomp) const; bool FastSubgroupCheckAvailable() const {return GetCofactor() == 2;} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - // Cygwin i386 crash at -O3; see . + // Cygwin i386 crash at -O3; see http://github.com/weidai11/cryptopp/issues/40. void EncodeElement(bool reversible, const Element &element, byte *encoded) const; unsigned int GetEncodedElementSize(bool reversible) const; -#else - void EncodeElement(bool reversible, const Element &element, byte *encoded) const - {CRYPTOPP_UNUSED(reversible); element.Encode(encoded, GetModulus().ByteCount());} - unsigned int GetEncodedElementSize(bool reversible) const - {CRYPTOPP_UNUSED(reversible); return GetModulus().ByteCount();} -#endif Integer DecodeElement(const byte *encoded, bool checkForGroupMembership) const; Integer ConvertElementToInteger(const Element &element) const @@ -115,9 +105,7 @@ class CRYPTOPP_NO_VTABLE DL_GroupParameters_IntegerBasedImpl : public DL_GroupPa public: typedef typename GROUP_PRECOMP::Element Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_IntegerBasedImpl() {} -#endif // GeneratibleCryptoMaterial interface bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const @@ -151,10 +139,7 @@ CRYPTOPP_DLL_TEMPLATE_CLASS DL_GroupParameters_IntegerBasedImpl { public: - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_GFP() {} -#endif // DL_GroupParameters bool IsIdentity(const Integer &element) const {return element == Integer::One();} @@ -181,9 +166,7 @@ class CRYPTOPP_DLL DL_GroupParameters_GFP_DefaultSafePrime : public DL_GroupPara public: typedef NoCofactorMultiplication DefaultCofactorOption; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_GFP_DefaultSafePrime() {} -#endif protected: unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;} @@ -196,11 +179,9 @@ template class DL_Algorithm_GDSA : public DL_ElgamalLikeSignatureAlgorithm { public: - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "DSA-1363";} + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "DSA-1363";} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_Algorithm_GDSA() {} -#endif void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const { @@ -236,9 +217,7 @@ class DL_Algorithm_NR : public DL_ElgamalLikeSignatureAlgorithm public: CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "NR";} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_Algorithm_NR() {} -#endif void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const { @@ -267,9 +246,7 @@ template class DL_PublicKey_GFP : public DL_PublicKeyImpl { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PublicKey_GFP() {} -#endif void Initialize(const DL_GroupParameters_IntegerBased ¶ms, const Integer &y) {this->AccessGroupParameters().Initialize(params); this->SetPublicElement(y);} @@ -292,9 +269,7 @@ template class DL_PrivateKey_GFP : public DL_PrivateKeyImpl { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PrivateKey_GFP() {} -#endif void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits) {this->GenerateRandomWithKeySize(rng, modulusBits);} @@ -317,10 +292,6 @@ struct DL_SignatureKeys_GFP typedef DL_GroupParameters_GFP GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SignatureKeys_GFP() {} -#endif }; //! \class DL_CryptoKeys_GFP @@ -330,10 +301,6 @@ struct DL_CryptoKeys_GFP typedef DL_GroupParameters_GFP_DefaultSafePrime GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_CryptoKeys_GFP() {} -#endif }; //! \class DL_PublicKey_GFP_OldFormat @@ -345,9 +312,7 @@ template class DL_PublicKey_GFP_OldFormat : public BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PublicKey_GFP_OldFormat() {} -#endif void BERDecode(BufferedTransformation &bt) { @@ -392,9 +357,7 @@ template class DL_PrivateKey_GFP_OldFormat : public BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_PrivateKey_GFP_OldFormat() {} -#endif void BERDecode(BufferedTransformation &bt) { @@ -444,9 +407,6 @@ struct GDSA : public DL_SS< DL_SignatureMessageEncodingMethod_DSA, H> { -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~GDSA() {} -#endif }; //! \class NR @@ -460,9 +420,6 @@ struct NR : public DL_SS< DL_SignatureMessageEncodingMethod_NR, H> { -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~NR() {} -#endif }; //! \class DL_GroupParameters_DSA @@ -472,9 +429,7 @@ struct NR : public DL_SS< class CRYPTOPP_DLL DL_GroupParameters_DSA : public DL_GroupParameters_GFP { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_GroupParameters_DSA() {} -#endif /*! also checks that the lengths of p and q are allowed by the DSA standard */ bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const; @@ -498,10 +453,6 @@ struct DL_Keys_DSA { typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_WithSignaturePairwiseConsistencyTest, DSA2 > PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Keys_DSA() {} -#endif }; //! \class DSA2 @@ -521,13 +472,9 @@ class DSA2 : public DL_SS< public: static std::string CRYPTOPP_API StaticAlgorithmName() {return "DSA/" + (std::string)H::StaticAlgorithmName();} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DSA2() {} -#endif - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY - enum {MIN_PRIME_LENGTH = 1024, MAX_PRIME_LENGTH = 3072, PRIME_LENGTH_MULTIPLE = 1024}; -#endif + //#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY + //enum {MIN_PRIME_LENGTH = 1024, MAX_PRIME_LENGTH = 3072, PRIME_LENGTH_MULTIPLE = 1024}; + //#endif }; //! DSA with SHA-1, typedef'd for backwards compatibility @@ -555,9 +502,7 @@ template class DL_EncryptionAlgorithm_Xor : public DL_SymmetricEncryptionAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~DL_EncryptionAlgorithm_Xor() {} -#endif bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;} size_t GetSymmetricKeyLength(size_t plaintextLength) const @@ -640,6 +585,8 @@ template class DL_KeyDerivationAlgorithm_P1363 : public DL_KeyDerivationAlgorithm { public: + virtual ~DL_KeyDerivationAlgorithm_P1363() {} + bool ParameterSupported(const char *name) const {return strcmp(name, Name::KeyDerivationParameters()) == 0;} void Derive(const DL_GroupParameters ¶ms, byte *derivedKey, size_t derivedLength, const T &agreedElement, const T &ephemeralPublicKey, const NameValuePairs ¶meters) const { @@ -660,10 +607,6 @@ public: parameters.GetValue(Name::KeyDerivationParameters(), derivationParameters); KDF::DeriveKey(derivedKey, derivedLength, agreedSecret, agreedSecret.size(), derivationParameters.begin(), derivationParameters.size()); } - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_KeyDerivationAlgorithm_P1363() {} -#endif }; //! \class DLIES @@ -710,10 +653,6 @@ struct DLIES DLIES<> > { static std::string CRYPTOPP_API StaticAlgorithmName() {return "DLIES";} // TODO: fix this after name is standardized - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DLIES() {} -#endif }; NAMESPACE_END diff --git a/hmqv.h b/hmqv.h index 7cbc1c5b..c7e81255 100644 --- a/hmqv.h +++ b/hmqv.h @@ -27,9 +27,7 @@ public: typedef typename GroupParameters::Element Element; typedef HMQV_Domain Domain; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~HMQV_Domain() {} -#endif + virtual ~HMQV_Domain() {} HMQV_Domain(bool clientRole = true): m_role(clientRole ? RoleClient : RoleServer) {} @@ -258,7 +256,7 @@ protected: if(sigma) { if (e1len != 0 || s1len != 0) { - CRYPTOPP_ASSERT(0); + CRYPTOPP_ASSERT(0); } Integer x = GetAbstractGroupParameters().ConvertElementToInteger(*sigma); SecByteBlock sbb(x.MinEncodedSize()); @@ -266,7 +264,7 @@ protected: hash.Update(sbb.BytePtr(), sbb.SizeInBytes()); } else { if (e1len == 0 || s1len == 0) { - CRYPTOPP_ASSERT(0); + CRYPTOPP_ASSERT(0); } hash.Update(e1, e1len); hash.Update(s1, s1len); diff --git a/iterhash.h b/iterhash.h index 43d58d90..fd883af3 100644 --- a/iterhash.h +++ b/iterhash.h @@ -104,14 +104,12 @@ public: typedef T_Endianness ByteOrderClass; typedef T_HashWordType HashWordType; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~IteratedHash() { } -#endif - CRYPTOPP_CONSTANT(BLOCKSIZE = T_BlockSize) // BCB2006 workaround: can't use BLOCKSIZE here CRYPTOPP_COMPILE_ASSERT((T_BlockSize & (T_BlockSize - 1)) == 0); // blockSize is a power of 2 + virtual ~IteratedHash() {} + //! \brief Provides the block size of the hash //! \return the block size of the hash, in bytes //! \details BlockSize() returns T_BlockSize. @@ -153,13 +151,10 @@ class CRYPTOPP_NO_VTABLE IteratedHashWithStaticTransform : public ClonableImpl, T_Transform> > { public: - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~IteratedHashWithStaticTransform() { } -#endif - CRYPTOPP_CONSTANT(DIGESTSIZE = T_DigestSize ? T_DigestSize : T_StateSize) + virtual ~IteratedHashWithStaticTransform() {} + //! \brief Provides the digest size of the hash //! \return the digest size of the hash, in bytes //! \details DigestSize() returns DIGESTSIZE. diff --git a/luc.h b/luc.h index ead0a4fc..beb07c0e 100644 --- a/luc.h +++ b/luc.h @@ -1,9 +1,14 @@ +// luc.h - written and placed in the public domain by Wei Dai + +//! \file luc.h +//! \brief Classes for the LUC cryptosystem +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. + #ifndef CRYPTOPP_LUC_H #define CRYPTOPP_LUC_H -/** \file -*/ - #include "cryptlib.h" #include "gfpcrypt.h" #include "integer.h" @@ -24,17 +29,17 @@ NAMESPACE_BEGIN(CryptoPP) -//! The LUC function. -/*! This class is here for historical and pedagogical interest. It has no - practical advantages over other trapdoor functions and probably shouldn't - be used in production software. The discrete log based LUC schemes - defined later in this .h file may be of more practical interest. -*/ +//! \brief The LUC function. +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. class LUCFunction : public TrapdoorFunction, public PublicKey { typedef LUCFunction ThisClass; public: + virtual ~LUCFunction() {} + void Initialize(const Integer &n, const Integer &e) {m_n = n; m_e = e;} @@ -56,20 +61,21 @@ public: void SetModulus(const Integer &n) {m_n = n;} void SetPublicExponent(const Integer &e) {m_e = e;} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~LUCFunction() {} -#endif - protected: Integer m_n, m_e; }; -//! _ +//! \brief The LUC inverse function. +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. class InvertibleLUCFunction : public LUCFunction, public TrapdoorFunctionInverse, public PrivateKey { typedef InvertibleLUCFunction ThisClass; public: + virtual ~InvertibleLUCFunction() {} + void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &eStart=17); void Initialize(const Integer &n, const Integer &e, const Integer &p, const Integer &q, const Integer &u) {m_n = n; m_e = e; m_p = p; m_q = q; m_u = u;} @@ -94,10 +100,6 @@ public: void SetPrime2(const Integer &q) {m_q = q;} void SetMultiplicativeInverseOfPrime2ModPrime1(const Integer &u) {m_u = u;} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~InvertibleLUCFunction() {} -#endif - protected: Integer m_p, m_q, m_u; }; @@ -109,13 +111,19 @@ struct LUC typedef InvertibleLUCFunction PrivateKey; }; -//! LUC cryptosystem +//! \brief LUC cryptosystem +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. template struct LUCES : public TF_ES { }; -//! LUC signature scheme with appendix +//! \brief LUC signature scheme with appendix +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. template struct LUCSS : public TF_SS { @@ -134,6 +142,8 @@ typedef LUCSS::Verifier LUCSSA_PKCS1v15_SHA_Verifier; class DL_GroupPrecomputation_LUC : public DL_GroupPrecomputation { public: + virtual ~DL_GroupPrecomputation_LUC() {} + const AbstractGroup & GetGroup() const {CRYPTOPP_ASSERT(false); throw 0;} Element BERDecodeElement(BufferedTransformation &bt) const {return Integer(bt);} void DEREncodeElement(BufferedTransformation &bt, const Element &v) const {v.DEREncode(bt);} @@ -142,10 +152,6 @@ public: void SetModulus(const Integer &v) {m_p = v;} const Integer & GetModulus() const {return m_p;} -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_GroupPrecomputation_LUC() {} -#endif - private: Integer m_p; }; @@ -154,6 +160,8 @@ private: class DL_BasePrecomputation_LUC : public DL_FixedBasePrecomputation { public: + virtual ~DL_BasePrecomputation_LUC() {} + // DL_FixedBasePrecomputation bool IsInitialized() const {return m_g.NotZero();} void SetBase(const DL_GroupPrecomputation &group, const Integer &base) @@ -174,10 +182,6 @@ public: throw NotImplemented("DL_BasePrecomputation_LUC: CascadeExponentiate not implemented"); } -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_BasePrecomputation_LUC() {} -#endif - private: Integer m_g; }; @@ -186,6 +190,8 @@ private: class DL_GroupParameters_LUC : public DL_GroupParameters_IntegerBasedImpl { public: + virtual ~DL_GroupParameters_LUC() {} + // DL_GroupParameters bool IsIdentity(const Integer &element) const {return element == Integer::Two();} void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const; @@ -206,10 +212,6 @@ public: return GetValueHelper(this, name, valueType, pValue).Assignable(); } -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_GroupParameters_LUC() {} -#endif - private: int GetFieldType() const {return 2;} }; @@ -220,10 +222,6 @@ class DL_GroupParameters_LUC_DefaultSafePrime : public DL_GroupParameters_LUC public: typedef NoCofactorMultiplication DefaultCofactorOption; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_GroupParameters_LUC_DefaultSafePrime() {} -#endif - protected: unsigned int GetDefaultSubgroupOrderSize(unsigned int modulusSize) const {return modulusSize-1;} }; @@ -234,15 +232,13 @@ class DL_Algorithm_LUC_HMP : public DL_ElgamalLikeSignatureAlgorithm public: CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "LUC-HMP";} + virtual ~DL_Algorithm_LUC_HMP() {} + void Sign(const DL_GroupParameters ¶ms, const Integer &x, const Integer &k, const Integer &e, Integer &r, Integer &s) const; bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const; size_t RLen(const DL_GroupParameters ¶ms) const {return params.GetGroupOrder().ByteCount();} - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Algorithm_LUC_HMP() {} -#endif }; //! _ @@ -251,13 +247,12 @@ struct DL_SignatureKeys_LUC typedef DL_GroupParameters_LUC GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SignatureKeys_LUC() {} -#endif }; -//! LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen +//! \brief LUC-HMP, based on "Digital signature schemes based on Lucas functions" by Patrick Horster, Markus Michels, Holger Petersen +//! \details This class is here for historical and pedagogical interest. It has no practical advantages over other +//! trapdoor functions and probably shouldn't be used in production software. The discrete log based LUC schemes +//! defined later in this .h file may be of more practical interest. template struct LUC_HMP : public DL_SS { @@ -269,10 +264,6 @@ struct DL_CryptoKeys_LUC typedef DL_GroupParameters_LUC_DefaultSafePrime GroupParameters; typedef DL_PublicKey_GFP PublicKey; typedef DL_PrivateKey_GFP PrivateKey; - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_CryptoKeys_LUC() {} -#endif }; //! LUC-IES @@ -286,10 +277,6 @@ struct LUC_IES LUC_IES<> > { static std::string StaticAlgorithmName() {return "LUC-IES";} // non-standard name - -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~LUC_IES() {} -#endif }; // ******************************************************** diff --git a/misc.cpp b/misc.cpp index dda21544..9d30fa96 100644 --- a/misc.cpp +++ b/misc.cpp @@ -133,7 +133,6 @@ bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count) return acc8 == 0; } -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 std::string StringNarrow(const wchar_t *str, bool throwOnError) { CRYPTOPP_ASSERT(str); @@ -150,15 +149,19 @@ std::string StringNarrow(const wchar_t *str, bool throwOnError) err = wcstombs_s(&size, NULL, 0, str, len*sizeof(wchar_t)); CRYPTOPP_ASSERT(err == 0); - if (err != 0) {goto CONVERSION_ERROR;} + if (err != 0) + { + if (throwOnError) + throw InvalidArgument("StringNarrow: wcstombs_s() call failed with error " + IntToString(err)); + else + return std::string(); + } result.resize(size); err = wcstombs_s(&size, &result[0], size, str, len*sizeof(wchar_t)); CRYPTOPP_ASSERT(err == 0); - if (err != 0) { -CONVERSION_ERROR: if (throwOnError) throw InvalidArgument("StringNarrow: wcstombs_s() call failed with error " + IntToString(err)); else @@ -171,15 +174,19 @@ CONVERSION_ERROR: #else size_t size = wcstombs(NULL, str, 0); CRYPTOPP_ASSERT(size != (size_t)-1); - if (size == (size_t)-1) {goto CONVERSION_ERROR;} + if (size == (size_t)-1) + { + if (throwOnError) + throw InvalidArgument("StringNarrow: wcstombs() call failed"); + else + return std::string(); + } result.resize(size); size = wcstombs(&result[0], str, size); CRYPTOPP_ASSERT(size != (size_t)-1); - if (size == (size_t)-1) { -CONVERSION_ERROR: if (throwOnError) throw InvalidArgument("StringNarrow: wcstombs() call failed"); else @@ -189,7 +196,6 @@ CONVERSION_ERROR: return result; } -#endif // StringNarrow and CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #if !(defined(_MSC_VER) && (_MSC_VER < 1300)) using std::new_handler; diff --git a/misc.h b/misc.h index 2793d06e..721c518a 100644 --- a/misc.h +++ b/misc.h @@ -1091,7 +1091,7 @@ void SecureWipeBuffer(T *buf, size_t n) // GCC 4.3.2 on Cygwin optimizes away the first store if this loop is done in the forward direction volatile T *p = buf+n; while (n--) - *((volatile T*)(--p)) = 0; + *(--p) = 0; } #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) @@ -1217,65 +1217,7 @@ inline void SecureWipeArray(T *buf, size_t n) //! \note If you try to convert, say, the Chinese character for "bone" from UTF-16 (0x9AA8) to UTF-8 //! (0xE9 0xAA 0xA8), then you must ensure the locale is available. If the locale is not available, //! then a 0x21 error is returned on Windows which eventually results in an InvalidArgument() exception. -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 std::string StringNarrow(const wchar_t *str, bool throwOnError = true); -#else -static std::string StringNarrow(const wchar_t *str, bool throwOnError = true) -{ - CRYPTOPP_ASSERT(str); - std::string result; - - // Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55 -#if (CRYPTOPP_MSC_VERSION >= 1400) - size_t len=0, size=0; - errno_t err = 0; - - //const wchar_t* ptr = str; - //while (*ptr++) len++; - len = wcslen(str)+1; - - err = wcstombs_s(&size, NULL, 0, str, len*sizeof(wchar_t)); - CRYPTOPP_ASSERT(err == 0); - if (err != 0) {goto CONVERSION_ERROR;} - - result.resize(size); - err = wcstombs_s(&size, &result[0], size, str, len*sizeof(wchar_t)); - CRYPTOPP_ASSERT(err == 0); - - if (err != 0) - { -CONVERSION_ERROR: - if (throwOnError) - throw InvalidArgument("StringNarrow: wcstombs_s() call failed with error " + IntToString(err)); - else - return std::string(); - } - - // The safe routine's size includes the NULL. - if (!result.empty() && result[size - 1] == '\0') - result.erase(size - 1); -#else - size_t size = wcstombs(NULL, str, 0); - CRYPTOPP_ASSERT(size != (size_t)-1); - if (size == (size_t)-1) {goto CONVERSION_ERROR;} - - result.resize(size); - size = wcstombs(&result[0], str, size); - CRYPTOPP_ASSERT(size != (size_t)-1); - - if (size == (size_t)-1) - { -CONVERSION_ERROR: - if (throwOnError) - throw InvalidArgument("StringNarrow: wcstombs() call failed"); - else - return std::string(); - } -#endif - - return result; -} -#endif // StringNarrow and CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 #ifdef CRYPTOPP_DOXYGEN_PROCESSING diff --git a/modarith.h b/modarith.h index 8f965fc5..452bb580 100644 --- a/modarith.h +++ b/modarith.h @@ -38,9 +38,7 @@ public: typedef int RandomizationParameter; typedef Integer Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~ModularArithmetic() {} -#endif //! \brief Construct a ModularArithmetic //! \param modulus congruence class modulus @@ -273,9 +271,7 @@ protected: class CRYPTOPP_DLL MontgomeryRepresentation : public ModularArithmetic { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~MontgomeryRepresentation() {} -#endif //! \brief Construct a MontgomeryRepresentation //! \param modulus congruence class modulus diff --git a/modes.cpp b/modes.cpp index 8441cd1f..5bd6af13 100644 --- a/modes.cpp +++ b/modes.cpp @@ -25,13 +25,10 @@ void Modes_TestInstantiations() } #endif -// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 void CipherModeBase::ResizeBuffers() { m_register.New(m_cipher->BlockSize()); } -#endif void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount) { @@ -163,14 +160,11 @@ void BlockOrientedCipherModeBase::UncheckedSetKey(const byte *key, unsigned int } } -// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 void BlockOrientedCipherModeBase::ResizeBuffers() { CipherModeBase::ResizeBuffers(); m_buffer.New(BlockSize()); } -#endif void ECB_OneWay::ProcessData(byte *outString, const byte *inString, size_t length) { @@ -218,14 +212,11 @@ void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString, memcpy(outString, m_register, BlockSize()); } -// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 void CBC_Decryption::ResizeBuffers() { BlockOrientedCipherModeBase::ResizeBuffers(); m_temp.New(BlockSize()); } -#endif void CBC_Decryption::ProcessData(byte *outString, const byte *inString, size_t length) { diff --git a/modes.h b/modes.h index 2a22024c..bcfb25e1 100644 --- a/modes.h +++ b/modes.h @@ -43,6 +43,7 @@ struct CipherModeDocumentation : public SymmetricCipherDocumentation class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher { public: + virtual ~CipherModeBase() {} size_t MinKeyLength() const {return m_cipher->MinKeyLength();} size_t MaxKeyLength() const {return m_cipher->MaxKeyLength();} size_t DefaultKeyLength() const {return m_cipher->DefaultKeyLength();} @@ -80,15 +81,7 @@ protected: throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode"); } -// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual void ResizeBuffers(); -#else - virtual void ResizeBuffers() - { - m_register.New(m_cipher->BlockSize()); - } -#endif BlockCipher *m_cipher; AlignedSecByteBlock m_register; @@ -118,9 +111,11 @@ void ModePolicyCommonTemplate::CipherSetKey(const NameValuePai class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate { public: - IV_Requirement IVRequirement() const {return RANDOM_IV;} CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CFB";} + virtual ~CFB_ModePolicy() {} + IV_Requirement IVRequirement() const {return RANDOM_IV;} + protected: unsigned int GetBytesPerIteration() const {return m_feedbackSize;} byte * GetRegisterBegin() {return m_register + BlockSize() - m_feedbackSize;} @@ -148,9 +143,10 @@ inline void CopyOrZero(void *dest, const void *src, size_t s) class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate { public: + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "OFB";} + bool CipherIsRandomAccess() const {return false;} IV_Requirement IVRequirement() const {return UNIQUE_IV;} - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "OFB";} private: unsigned int GetBytesPerIteration() const {return BlockSize();} @@ -164,13 +160,14 @@ private: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate { public: + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CTR";} + + virtual ~CTR_ModePolicy() {} bool CipherIsRandomAccess() const {return true;} IV_Requirement IVRequirement() const {return RANDOM_IV;} - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CTR";} protected: virtual void IncrementCounterBy256(); - unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();} unsigned int GetBytesPerIteration() const {return BlockSize();} unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();} @@ -189,6 +186,7 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase { public: + virtual ~BlockOrientedCipherModeBase() {} void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); unsigned int MandatoryBlockSize() const {return BlockSize();} bool IsRandomAccess() const {return false;} @@ -198,17 +196,7 @@ public: protected: bool RequireAlignedInput() const {return true;} - - // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - void ResizeBuffers(); -#else - void ResizeBuffers() - { - CipherModeBase::ResizeBuffers(); - m_buffer.New(BlockSize()); - } -#endif + virtual void ResizeBuffers(); SecByteBlock m_buffer; }; @@ -218,12 +206,13 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase { public: + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECB";} + void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs) {m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();} IV_Requirement IVRequirement() const {return NOT_RESYNCHRONIZABLE;} unsigned int OptimalBlockSize() const {return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();} void ProcessData(byte *outString, const byte *inString, size_t length); - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECB";} }; //! \class CBC_ModeBase @@ -231,10 +220,11 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase { public: + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC";} + IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;} bool RequireAlignedInput() const {return false;} unsigned int MinLastBlockSize() const {return 0;} - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC";} }; //! \class CBC_Encryption @@ -250,10 +240,11 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption { public: + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} + void SetStolenIV(byte *iv) {m_stolenIV = iv;} unsigned int MinLastBlockSize() const {return BlockSize()+1;} void ProcessLastBlock(byte *outString, const byte *inString, size_t length); - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} protected: void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) @@ -270,20 +261,11 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase { public: + virtual ~CBC_Decryption() {} void ProcessData(byte *outString, const byte *inString, size_t length); protected: - - // Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46 -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - void ResizeBuffers(); -#else - void ResizeBuffers() - { - BlockOrientedCipherModeBase::ResizeBuffers(); - m_temp.New(BlockSize()); - } -#endif + virtual void ResizeBuffers(); AlignedSecByteBlock m_temp; }; @@ -303,6 +285,9 @@ template class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder, public AlgorithmImpl > { public: + static std::string CRYPTOPP_API StaticAlgorithmName() + {return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();} + CipherModeFinalTemplate_CipherHolder() { this->m_cipher = &this->m_object; @@ -323,9 +308,6 @@ public: this->m_cipher = &this->m_object; this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))(Name::FeedbackSize(), feedbackSize)); } - - static std::string CRYPTOPP_API StaticAlgorithmName() - {return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();} }; //! \class CipherModeFinalTemplate_ExternalCipher @@ -481,10 +463,10 @@ struct CBC_CTS_Mode_ExternalCipher : public CipherModeDocumentation }; #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef CFB_Mode_ExternalCipher::Encryption CFBEncryption; -typedef CFB_Mode_ExternalCipher::Decryption CFBDecryption; -typedef OFB_Mode_ExternalCipher::Encryption OFB; -typedef CTR_Mode_ExternalCipher::Encryption CounterMode; +//typedef CFB_Mode_ExternalCipher::Encryption CFBEncryption; +//typedef CFB_Mode_ExternalCipher::Decryption CFBDecryption; +//typedef OFB_Mode_ExternalCipher::Encryption OFB; +//typedef CTR_Mode_ExternalCipher::Encryption CounterMode; #endif NAMESPACE_END diff --git a/modexppc.h b/modexppc.h index a1a0a9c7..c2978871 100644 --- a/modexppc.h +++ b/modexppc.h @@ -16,6 +16,8 @@ CRYPTOPP_DLL_TEMPLATE_CLASS DL_FixedBasePrecomputationImpl; class ModExpPrecomputation : public DL_GroupPrecomputation { public: + virtual ~ModExpPrecomputation() {} + // DL_GroupPrecomputation bool NeedConversions() const {return true;} Element ConvertIn(const Element &v) const {return m_mr->ConvertIn(v);} diff --git a/oaep.h b/oaep.h index 732f54d0..b299f71f 100644 --- a/oaep.h +++ b/oaep.h @@ -7,7 +7,7 @@ NAMESPACE_BEGIN(CryptoPP) -//! _ +//! \brief OAEP padding base class class CRYPTOPP_DLL OAEP_Base : public PK_EncryptionMessageEncodingMethod { public: @@ -22,7 +22,8 @@ protected: virtual MaskGeneratingFunction * NewMGF() const =0; }; -//! EME-OAEP, for use with classes derived from TF_ES +//! \brief OAEP padding +//! \sa EME-OAEP, for use with classes derived from TF_ES template class OAEP : public OAEP_Base, public EncryptionStandard { diff --git a/oids.h b/oids.h index 99b66117..ddaaff41 100644 --- a/oids.h +++ b/oids.h @@ -46,8 +46,8 @@ DEFINE_OID(1, iso) DEFINE_OID(dod()+1, internet) DEFINE_OID(internet()+4, internet_private) DEFINE_OID(internet_private()+1, enterprise) - DEFINE_OID(enterprise()+11591,GNU) - DEFINE_OID(GNU()+15,ellipticCurve) + DEFINE_OID(enterprise()+11591,gnu) + DEFINE_OID(gnu()+15,ellipticCurve) DEFINE_OID(ellipticCurve()+1,curve25519) DEFINE_OID(ellipticCurve()+2,curve448) DEFINE_OID(ellipticCurve()+3,curve25519ph) diff --git a/pssr.h b/pssr.h index 54622d44..73eb66fa 100644 --- a/pssr.h +++ b/pssr.h @@ -20,17 +20,15 @@ NAMESPACE_BEGIN(CryptoPP) class CRYPTOPP_DLL PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PSSR_MEM_Base() {} -#endif -private: +protected: virtual bool AllowRecovery() const =0; virtual size_t SaltLen(size_t hashLen) const =0; virtual size_t MinPadLen(size_t hashLen) const =0; virtual const MaskGeneratingFunction & GetMGF() const =0; -public: +private: size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const; size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const; bool IsProbabilistic() const; diff --git a/pubkey.h b/pubkey.h index 1f7800f7..65503166 100644 --- a/pubkey.h +++ b/pubkey.h @@ -105,9 +105,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomizedTrapdoorFunction : public TrapdoorFunctionBounds { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~RandomizedTrapdoorFunction() { } -#endif + virtual ~RandomizedTrapdoorFunction() {} //! \brief Applies the trapdoor function, using random data if required //! \param rng a \p RandomNumberGenerator derived class @@ -133,9 +131,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TrapdoorFunction : public RandomizedTrapdoorFunction { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TrapdoorFunction() { } -#endif + virtual ~TrapdoorFunction() {} //! \brief Applies the trapdoor function //! \param rng a \p RandomNumberGenerator derived class @@ -244,9 +240,7 @@ template class CRYPTOPP_NO_VTABLE TF_Base { protected: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_Base() { } -#endif + virtual ~TF_Base() {} virtual const TrapdoorFunctionBounds & GetTrapdoorFunctionBounds() const =0; @@ -266,9 +260,7 @@ template class CRYPTOPP_NO_VTABLE PK_FixedLengthCryptoSystemImpl : public BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~PK_FixedLengthCryptoSystemImpl() { } -#endif + virtual ~PK_FixedLengthCryptoSystemImpl() {} size_t MaxPlaintextLength(size_t ciphertextLength) const {return ciphertextLength == FixedCiphertextLength() ? FixedMaxPlaintextLength() : 0;} @@ -287,9 +279,7 @@ template class CRYPTOPP_NO_VTABLE TF_CryptoSystemBase : public PK_FixedLengthCryptoSystemImpl, protected BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_CryptoSystemBase() { } -#endif + virtual ~TF_CryptoSystemBase() {} bool ParameterSupported(const char *name) const {return this->GetMessageEncodingInterface().ParameterSupported(name);} size_t FixedMaxPlaintextLength() const {return this->GetMessageEncodingInterface().MaxUnpaddedLength(PaddedBlockBitLength());} @@ -306,9 +296,7 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_DecryptorBase : public TF_CryptoSystemBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_DecryptorBase() { } -#endif + virtual ~TF_DecryptorBase() {} DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters = g_nullNameValuePairs) const; }; @@ -318,9 +306,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_EncryptorBase : public TF_CryptoSystemBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_EncryptorBase() { } -#endif + virtual ~TF_EncryptorBase() {} void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters = g_nullNameValuePairs) const; }; @@ -496,9 +482,7 @@ template class CRYPTOPP_NO_VTABLE TF_SignatureSchemeBase : public INTERFACE, protected BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_SignatureSchemeBase() { } -#endif + virtual ~TF_SignatureSchemeBase() {} size_t SignatureLength() const {return this->GetTrapdoorFunctionBounds().MaxPreimage().ByteCount();} @@ -526,9 +510,7 @@ protected: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_SignerBase : public TF_SignatureSchemeBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_SignerBase() { } -#endif + virtual ~TF_SignerBase() {} void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const; size_t SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart=true) const; @@ -538,9 +520,7 @@ public: class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE TF_VerifierBase : public TF_SignatureSchemeBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_VerifierBase() { } -#endif + virtual ~TF_VerifierBase() {} void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const; bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const; @@ -575,9 +555,7 @@ public: typedef SCHEME_OPTIONS SchemeOptions; typedef KEY_CLASS KeyClass; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_ObjectImplBase() { } -#endif + virtual ~TF_ObjectImplBase() {} PublicKey & AccessPublicKey() {return AccessKey();} const PublicKey & GetPublicKey() const {return GetKey();} @@ -626,9 +604,7 @@ template class TF_ObjectImplExtRef : public TF_ObjectImplBase { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~TF_ObjectImplExtRef() { } -#endif + virtual ~TF_ObjectImplExtRef() {} TF_ObjectImplExtRef(const KEY *pKey = NULL) : m_pKey(pKey) {} void SetKeyPtr(const KEY *pKey) {m_pKey = pKey;} @@ -647,9 +623,7 @@ class CRYPTOPP_NO_VTABLE TF_ObjectImpl : public TF_ObjectImplBase class CRYPTOPP_NO_VTABLE DL_Key { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Key() { } -#endif + virtual ~DL_Key() {} //! \brief Retrieves abstract group parameters //! \return a const reference to the group parameters @@ -1025,9 +993,7 @@ class CRYPTOPP_NO_VTABLE DL_PublicKey : public DL_Key public: typedef T Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_PublicKey() { } -#endif + virtual ~DL_PublicKey() {} bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const { @@ -1064,9 +1030,7 @@ class CRYPTOPP_NO_VTABLE DL_PrivateKey : public DL_Key public: typedef T Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_PrivateKey() { } -#endif + virtual ~DL_PrivateKey() {} void MakePublicKey(DL_PublicKey &pub) const { @@ -1114,15 +1078,9 @@ class DL_KeyImpl : public PK public: typedef GP GroupParameters; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_KeyImpl() { } -#endif + virtual ~DL_KeyImpl() {} O GetAlgorithmID() const {return GetGroupParameters().GetAlgorithmID();} -// void BERDecode(BufferedTransformation &bt) -// {PK::BERDecode(bt);} -// void DEREncode(BufferedTransformation &bt) const -// {PK::DEREncode(bt);} bool BERDecodeAlgorithmParameters(BufferedTransformation &bt) {AccessGroupParameters().BERDecode(bt); return true;} bool DEREncodeAlgorithmParameters(BufferedTransformation &bt) const @@ -1145,9 +1103,7 @@ class DL_PrivateKeyImpl : public DL_PrivateKey, public public: typedef typename GP::Element Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_PrivateKeyImpl() { } -#endif + virtual ~DL_PrivateKeyImpl() {} // GeneratableCryptoMaterial bool Validate(RandomNumberGenerator &rng, unsigned int level) const @@ -1177,10 +1133,7 @@ public: { if (!params.GetThisObject(this->AccessGroupParameters())) this->AccessGroupParameters().GenerateRandom(rng, params); -// std::pair seed; Integer x(rng, Integer::One(), GetAbstractGroupParameters().GetMaxExponent()); -// Integer::ANY, Integer::Zero(), Integer::One(), -// params.GetValue("DeterministicKeyGenerationSeed", seed) ? &seed : NULL); SetPrivateExponent(x); } @@ -1218,9 +1171,7 @@ template class DL_PrivateKey_WithSignaturePairwiseConsistencyTest : public BASE { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_PrivateKey_WithSignaturePairwiseConsistencyTest() { } -#endif + virtual ~DL_PrivateKey_WithSignaturePairwiseConsistencyTest() {} void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms) { @@ -1242,9 +1193,7 @@ class DL_PublicKeyImpl : public DL_PublicKey, public DL_Ke public: typedef typename GP::Element Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_PublicKeyImpl() { } -#endif + virtual ~DL_PublicKeyImpl() {} // CryptoMaterial bool Validate(RandomNumberGenerator &rng, unsigned int level) const @@ -1305,9 +1254,7 @@ template class CRYPTOPP_NO_VTABLE DL_ElgamalLikeSignatureAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_ElgamalLikeSignatureAlgorithm() { } -#endif + virtual ~DL_ElgamalLikeSignatureAlgorithm() {} virtual void Sign(const DL_GroupParameters ¶ms, const Integer &privateKey, const Integer &k, const Integer &e, Integer &r, Integer &s) const =0; virtual bool Verify(const DL_GroupParameters ¶ms, const DL_PublicKey &publicKey, const Integer &e, const Integer &r, const Integer &s) const =0; @@ -1330,9 +1277,7 @@ class CRYPTOPP_NO_VTABLE DL_KeyAgreementAlgorithm public: typedef T Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_KeyAgreementAlgorithm() { } -#endif + virtual ~DL_KeyAgreementAlgorithm() {} virtual Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters ¶ms, const DL_FixedBasePrecomputation &publicPrecomputation, const Integer &privateExponent) const =0; virtual Element AgreeWithStaticPrivateKey(const DL_GroupParameters ¶ms, const Element &publicElement, bool validateOtherPublicKey, const Integer &privateExponent) const =0; @@ -1343,9 +1288,7 @@ template class CRYPTOPP_NO_VTABLE DL_KeyDerivationAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_KeyDerivationAlgorithm() { } -#endif + virtual ~DL_KeyDerivationAlgorithm() {} virtual bool ParameterSupported(const char *name) const {CRYPTOPP_UNUSED(name); return false;} @@ -1356,9 +1299,7 @@ public: class CRYPTOPP_NO_VTABLE DL_SymmetricEncryptionAlgorithm { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SymmetricEncryptionAlgorithm() { } -#endif + virtual ~DL_SymmetricEncryptionAlgorithm() {} virtual bool ParameterSupported(const char *name) const {CRYPTOPP_UNUSED(name); return false;} @@ -1378,9 +1319,7 @@ protected: typedef KI KeyInterface; typedef typename KI::Element Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_Base() { } -#endif + virtual ~DL_Base() {} const DL_GroupParameters & GetAbstractGroupParameters() const {return GetKeyInterface().GetAbstractGroupParameters();} DL_GroupParameters & AccessAbstractGroupParameters() {return AccessKeyInterface().AccessAbstractGroupParameters();} @@ -1398,9 +1337,7 @@ template class CRYPTOPP_NO_VTABLE DL_SignatureSchemeBase : public INTERFACE, public DL_Base { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SignatureSchemeBase() { } -#endif + virtual ~DL_SignatureSchemeBase() {} //! \brief Provides the signature length //! \returns signature length, in bytes @@ -1454,9 +1391,7 @@ template class CRYPTOPP_NO_VTABLE DL_SignerBase : public DL_SignatureSchemeBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SignerBase() { } -#endif + virtual ~DL_SignerBase() {} //! \brief Testing interface //! \param k Integer @@ -1552,9 +1487,7 @@ template class CRYPTOPP_NO_VTABLE DL_VerifierBase : public DL_SignatureSchemeBase > { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_VerifierBase() { } -#endif + virtual ~DL_VerifierBase() {} void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const { @@ -1629,9 +1562,7 @@ class CRYPTOPP_NO_VTABLE DL_CryptoSystemBase : public PK, public DL_Base public: typedef typename DL_Base::Element Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_CryptoSystemBase() { } -#endif + virtual ~DL_CryptoSystemBase() {} size_t MaxPlaintextLength(size_t ciphertextLength) const { @@ -1662,9 +1593,7 @@ class CRYPTOPP_NO_VTABLE DL_DecryptorBase : public DL_CryptoSystemBase & GetSignatureAlgorithm() const @@ -1902,9 +1825,7 @@ class CRYPTOPP_NO_VTABLE DL_SimpleKeyAgreementDomainBase : public SimpleKeyAgree public: typedef T Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_SimpleKeyAgreementDomainBase() { } -#endif + virtual ~DL_SimpleKeyAgreementDomainBase() {} CryptoParameters & AccessCryptoParameters() {return AccessAbstractGroupParameters();} unsigned int AgreedValueLength() const {return GetAbstractGroupParameters().GetEncodedElementSize(false);} @@ -1975,20 +1896,18 @@ typedef EnumToType NoCo typedef EnumToType CompatibleCofactorMultiplication; typedef EnumToType IncompatibleCofactorMultiplication; -//! \details Diffie-Hellman key agreement algorithm +//! \brief Diffie-Hellman key agreement algorithm template class DL_KeyAgreementAlgorithm_DH : public DL_KeyAgreementAlgorithm { public: typedef ELEMENT Element; -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 - virtual ~DL_KeyAgreementAlgorithm_DH() {} -#endif - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return COFACTOR_OPTION::ToEnum() == INCOMPATIBLE_COFACTOR_MULTIPLICTION ? "DHC" : "DH";} + virtual ~DL_KeyAgreementAlgorithm_DH() {} + Element AgreeWithEphemeralPrivateKey(const DL_GroupParameters ¶ms, const DL_FixedBasePrecomputation &publicPrecomputation, const Integer &privateExponent) const { return publicPrecomputation.Exponentiate(params.GetGroupPrecomputation(), @@ -2052,38 +1971,6 @@ public: PK_FinalTemplate(const Integer &v1) {this->AccessKey().Initialize(v1);} -#if (defined(_MSC_VER) && _MSC_VER < 1300) - - template - PK_FinalTemplate(T1 &v1, T2 &v2) - {this->AccessKey().Initialize(v1, v2);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3) - {this->AccessKey().Initialize(v1, v2, v3);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4) - {this->AccessKey().Initialize(v1, v2, v3, v4);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7);} - - template - PK_FinalTemplate(T1 &v1, T2 &v2, T3 &v3, T4 &v4, T5 &v5, T6 &v6, T7 &v7, T8 &v8) - {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} - -#else - template PK_FinalTemplate(const T1 &v1, const T2 &v2) {this->AccessKey().Initialize(v1, v2);} @@ -2139,8 +2026,6 @@ public: template PK_FinalTemplate(T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5, const T6 &v6, const T7 &v7, const T8 &v8) {this->AccessKey().Initialize(v1, v2, v3, v4, v5, v6, v7, v8);} - -#endif }; //! \brief Base class for public key encryption standard classes. diff --git a/pwdbased.h b/pwdbased.h index cc0bcedb..0a23cbbe 100644 --- a/pwdbased.h +++ b/pwdbased.h @@ -17,9 +17,7 @@ NAMESPACE_BEGIN(CryptoPP) class PasswordBasedKeyDerivationFunction { public: -#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~PasswordBasedKeyDerivationFunction() {} -#endif //! \brief Provides the maximum derived key length //! \returns maximum derived key length, in bytes diff --git a/rabin.h b/rabin.h index 2bc5c1d4..dcc86c5e 100644 --- a/rabin.h +++ b/rabin.h @@ -1,7 +1,6 @@ // rabin.h - written and placed in the public domain by Wei Dai -//! \file -//! \headerfile rabin.h +//! \file rabin.h //! \brief Classes for Rabin encryption and signature schemes #ifndef CRYPTOPP_RABIN_H diff --git a/sha.cpp b/sha.cpp index 72b4ee25..e3b2c91f 100644 --- a/sha.cpp +++ b/sha.cpp @@ -357,17 +357,8 @@ extern const word32 SHA256_K[64] = { #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_GENERATE_X64_MASM)) -static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 *data, size_t len -#if defined(_MSC_VER) && (_MSC_VER == 1200) - , ... // VC60 workaround: prevent VC 6 from inlining this function -#endif - ) +static void CRYPTOPP_FASTCALL X86_SHA256_HashBlocks(word32 *state, const word32 *data, size_t len) { -#if defined(_MSC_VER) && (_MSC_VER == 1200) - AS2(mov ecx, [state]) - AS2(mov edx, [data]) -#endif - #define LOCALS_SIZE 8*4 + 16*4 + 4*WORD_SZ #define H(i) [BASE+ASM_MOD(1024+7-(i),8)*4] #define G(i) H(i+1) diff --git a/strciphr.h b/strciphr.h index 9d1e093a..a45a4c3e 100644 --- a/strciphr.h +++ b/strciphr.h @@ -66,9 +66,7 @@ template class SymmetricCipherFinal : public AlgorithmImpl, INFO> { public: + virtual ~SymmetricCipherFinal() {} + //! \brief Construct a stream cipher SymmetricCipherFinal() {} diff --git a/wait.h b/wait.h index 8c7ba6ef..6012148c 100644 --- a/wait.h +++ b/wait.h @@ -187,11 +187,7 @@ public: bool Wait(unsigned long milliseconds); #ifdef USE_WINDOWS_STYLE_SOCKETS -# ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 virtual ~WaitObjectContainer(); -# else - ~WaitObjectContainer(); -#endif void AddHandle(HANDLE handle, CallStack const& callStack); #else void AddReadFd(int fd, CallStack const& callStack); @@ -234,6 +230,6 @@ NAMESPACE_END # pragma warning(pop) #endif -#endif +#endif // NO_OS_DEPENDENCE -#endif +#endif // CRYPTOPP_WAIT_H diff --git a/winpipes.h b/winpipes.h index 941d8a83..13896527 100644 --- a/winpipes.h +++ b/winpipes.h @@ -16,6 +16,8 @@ NAMESPACE_BEGIN(CryptoPP) class WindowsHandle { public: + virtual ~WindowsHandle() {} + WindowsHandle(HANDLE h = INVALID_HANDLE_VALUE, bool own=false); WindowsHandle(const WindowsHandle &h) : m_h(h.m_h), m_own(false) {} virtual ~WindowsHandle();