diff --git a/config.h b/config.h index ab00dc7a..0d99df57 100644 --- a/config.h +++ b/config.h @@ -546,7 +546,7 @@ NAMESPACE_END // 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(__APPLE__) && (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2)) +#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) # define CRYPTOPP_CONSTANT(x) enum {x}; #else # define CRYPTOPP_CONSTANT(x) static const int x; diff --git a/config.recommend b/config.recommend index 61fcb1df..966a6da8 100644 --- a/config.recommend +++ b/config.recommend @@ -546,7 +546,7 @@ NAMESPACE_END // 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(__APPLE__) && (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2)) +#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER) || defined(__BORLANDC__) # define CRYPTOPP_CONSTANT(x) enum {x}; #else # define CRYPTOPP_CONSTANT(x) static const int x; diff --git a/seckey.h b/seckey.h index 31286ce6..bbf1ea7a 100644 --- a/seckey.h +++ b/seckey.h @@ -71,11 +71,20 @@ public: //! \param keylength the size of the key, in bytes //! \details keylength is unused in the default implementation. CRYPTOPP_CONSTEXPR static unsigned int StaticGetDefaultRounds(size_t keylength) - {return CRYPTOPP_UNUSED(keylength), DEFAULT_ROUNDS;} + { + // Comma operator breaks Debug builds with GCC 4.0 - 4.6. + // Also see http://github.com/weidai11/cryptopp/issues/255 +#if defined(CRYPTOPP_CXX11_CONSTEXPR) + return CRYPTOPP_UNUSED(keylength), static_cast(DEFAULT_ROUNDS); +#else + CRYPTOPP_UNUSED(keylength); + return static_cast(DEFAULT_ROUNDS); +#endif + } protected: //! \brief Validates the number of rounds for an algorithm. - //! \param rounds the canddiate number of rounds + //! \param rounds the candidate number of rounds //! \param alg an Algorithm object used if the number of rounds are invalid //! \throws InvalidRounds if the number of rounds are invalid //! \details ThrowIfInvalidRounds() validates the number of rounds and throws if invalid. @@ -94,7 +103,7 @@ protected: } //! \brief Validates the number of rounds for an algorithm - //! \param param the canddiate number of rounds + //! \param param the candidate number of rounds //! \param alg an Algorithm object used if the number of rounds are invalid //! \returns the number of rounds for the algorithm //! \throws InvalidRounds if the number of rounds are invalid @@ -143,7 +152,16 @@ public: //! \details The default implementation returns KEYLENGTH. keylength is unused //! in the default implementation. CRYPTOPP_CONSTEXPR static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) - {return CRYPTOPP_UNUSED(keylength), KEYLENGTH;} + { + // Comma operator breaks Debug builds with GCC 4.0 - 4.6. + // Also see http://github.com/weidai11/cryptopp/issues/255 +#if defined(CRYPTOPP_CXX11_CONSTEXPR) + return CRYPTOPP_UNUSED(keylength), static_cast(KEYLENGTH); +#else + CRYPTOPP_UNUSED(keylength); + return static_cast(KEYLENGTH); +#endif + } }; //! \class VariableKeyLength diff --git a/validat1.cpp b/validat1.cpp index afda0d94..66285929 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -2436,6 +2436,7 @@ bool ValidateRC5() bool pass1 = true, pass2 = true; RC5Encryption enc; // 0 to 2040-bits (255-bytes) + pass1 = RC5Encryption::DEFAULT_KEYLENGTH == 16 && pass1; pass1 = enc.StaticGetValidKeyLength(0) == 0 && pass1; pass1 = enc.StaticGetValidKeyLength(254) == 254 && pass1; pass1 = enc.StaticGetValidKeyLength(255) == 255 && pass1; @@ -2444,6 +2445,7 @@ bool ValidateRC5() pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1; RC5Decryption dec; + pass2 = RC5Decryption::DEFAULT_KEYLENGTH == 16 && pass2; pass2 = dec.StaticGetValidKeyLength(0) == 0 && pass2; pass2 = dec.StaticGetValidKeyLength(254) == 254 && pass2; pass2 = dec.StaticGetValidKeyLength(255) == 255 && pass2; @@ -2684,11 +2686,13 @@ bool ValidateThreeWay() bool pass1 = true, pass2 = true; ThreeWayEncryption enc; // 96-bit only + pass1 = ThreeWayEncryption::KEYLENGTH == 12 && pass1; pass1 = enc.StaticGetValidKeyLength(8) == 12 && pass1; pass1 = enc.StaticGetValidKeyLength(12) == 12 && pass1; pass1 = enc.StaticGetValidKeyLength(16) == 12 && pass1; ThreeWayDecryption dec; // 96-bit only + pass2 = ThreeWayEncryption::KEYLENGTH == 12 && pass2; pass2 = dec.StaticGetValidKeyLength(8) == 12 && pass2; pass2 = dec.StaticGetValidKeyLength(12) == 12 && pass2; pass2 = dec.StaticGetValidKeyLength(16) == 12 && pass2;