diff --git a/config.compat b/config.compat index 55d22bfde..3f1dd093d 100644 --- a/config.compat +++ b/config.compat @@ -119,6 +119,21 @@ // 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, @@ -136,14 +151,18 @@ # define CRYPTOPP_USER_PRIORITY 350 #endif -// 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 +// __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 ******************** diff --git a/config.h b/config.h index c9cbb15dd..c8920928e 100644 --- a/config.h +++ b/config.h @@ -119,6 +119,21 @@ // 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, @@ -136,14 +151,18 @@ # define CRYPTOPP_USER_PRIORITY 350 #endif -// 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 +// __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 ******************** diff --git a/cpu.cpp b/cpu.cpp index ce9fc2ee2..42831c15e 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -25,11 +25,6 @@ NAMESPACE_BEGIN(CryptoPP) #ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY - -// MacPorts/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it. -#define HAVE_GCC_CONSTRUCTOR1 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0)) -#define HAVE_GCC_CONSTRUCTOR0 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !(MACPORTS_GCC_COMPILER > 0)) - extern "C" { typedef void (*SigHandler)(int); }; diff --git a/cryptlib.cpp b/cryptlib.cpp index c1f6f63e7..d58c71d5d 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -32,10 +32,6 @@ # error Cygwin does not support Windows style sockets. See http://www.cygwin.com/faq.html#faq.api.winsock #endif -// MacPorts/GCC does not provide init_priority(priority). Apple/GCC and Fink/GCC do provide it. -#define HAVE_GCC_INIT_PRIORITY (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !(MACPORTS_GCC_COMPILER > 0)) -#define HAVE_MSC_INIT_PRIORITY (_MSC_VER && (CRYPTOPP_INIT_PRIORITY > 0)) - NAMESPACE_BEGIN(CryptoPP) CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);