Remove comma operator from return values for StaticGetDefaultRounds and StaticGetValidKeyLength in non-constexpr builds (Issue 255)
parent
e2f2ace688
commit
f0e7b45bcb
2
config.h
2
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
26
seckey.h
26
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<unsigned int>(DEFAULT_ROUNDS);
|
||||
#else
|
||||
CRYPTOPP_UNUSED(keylength);
|
||||
return static_cast<unsigned int>(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<size_t>(KEYLENGTH);
|
||||
#else
|
||||
CRYPTOPP_UNUSED(keylength);
|
||||
return static_cast<size_t>(KEYLENGTH);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
//! \class VariableKeyLength
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue