From a11985e6e464043268427d34ada6b55aed76f688 Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 4 Sep 2016 13:47:39 +0200 Subject: [PATCH 1/2] Update seckey.h See https://github.com/weidai11/cryptopp/issues/252 --- seckey.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/seckey.h b/seckey.h index a08eedee..3afc3b9d 100644 --- a/seckey.h +++ b/seckey.h @@ -194,12 +194,9 @@ public: //! \details keylength is provided in bytes, not bits. static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) { -#if MIN_KEYLENGTH > 0 if (keylength < (size_t)MIN_KEYLENGTH) return MIN_KEYLENGTH; - else -#endif - if (keylength > (size_t)MAX_KEYLENGTH) + else if (keylength > (size_t)MAX_KEYLENGTH) return (size_t)MAX_KEYLENGTH; else { From 262d125fb2bb0718896dc792305dcee2424cd02a Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 4 Sep 2016 14:10:43 +0200 Subject: [PATCH 2/2] Update seckey.h InvalidRounds expects a std::string, so it can be constructed in-place and the `__BORLANDC__` define can be removed. --- seckey.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/seckey.h b/seckey.h index 3afc3b9d..8a801306 100644 --- a/seckey.h +++ b/seckey.h @@ -80,16 +80,16 @@ protected: //! \throws InvalidRounds if the number of rounds are invalid inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg) { -#if defined(__BORLANDC__) - if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); -#elif (M==INT_MAX) // Coverity and result_independent_of_operands - if (rounds < MIN_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : "VariableRounds", rounds); -#else - if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) - throw InvalidRounds(alg ? alg->AlgorithmName() : "VariableRounds", rounds); -#endif + if (M == INT_MAX) // Coverity and result_independent_of_operands + { + if (rounds < MIN_ROUNDS) + throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); + } + else + { + if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS) + throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds); + } } //! \brief Validates the number of rounds for an algorithm