From 16941931015aa3aeb079eb4c9f8b83a702de6d0d Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 15 Nov 2016 04:15:17 -0500 Subject: Make StaticGetValidKeyLength constexpr in seckey.h --- seckey.h | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'seckey.h') diff --git a/seckey.h b/seckey.h index 86dd5a0a..1cb2a0a1 100644 --- a/seckey.h +++ b/seckey.h @@ -72,14 +72,7 @@ public: //! \details keylength is unused in the default implementation. CRYPTOPP_STATIC_CONSTEXPR unsigned int StaticGetDefaultRounds(size_t 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(DEFAULT_ROUNDS); -#else - CRYPTOPP_UNUSED(keylength); - return static_cast(DEFAULT_ROUNDS); -#endif } protected: @@ -153,14 +146,7 @@ public: //! in the default implementation. CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t 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 } }; @@ -212,18 +198,11 @@ public: //! then keylength is returned. Otherwise, the function returns keylength rounded //! \a down to the next smaller multiple of KEYLENGTH_MULTIPLE. //! \details keylength is provided in bytes, not bits. - // TODO: Figure out how to make this CRYPTOPP_CONSTEXPR - static size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) + CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength) { - if (keylength < (size_t)MIN_KEYLENGTH) - return MIN_KEYLENGTH; - else if (keylength > (size_t)MAX_KEYLENGTH) - return (size_t)MAX_KEYLENGTH; - else - { - keylength += KEYLENGTH_MULTIPLE-1; - return keylength - keylength%KEYLENGTH_MULTIPLE; - } + return (keylength <= N) ? N : + (keylength >= M) ? M : + (keylength+Q-1) - (keylength+Q-1)%Q; } }; -- cgit v1.2.1