diff options
author | René Korthaus <[email protected]> | 2019-10-24 08:39:16 +0200 |
---|---|---|
committer | René Korthaus <[email protected]> | 2019-10-24 08:39:16 +0200 |
commit | 91f92516412951e1b8f9799a9f66df2840b8eba1 (patch) | |
tree | 2f3483df94ec5aa278bb70ae50ee407872a86149 /src/lib/rng | |
parent | 2c6111c28ceb11a1064a442c449cc416e44c3eda (diff) |
Change limit to 2^24 to properly support 32 bit platforms
Diffstat (limited to 'src/lib/rng')
-rw-r--r-- | src/lib/rng/hmac_drbg/hmac_drbg.cpp | 47 | ||||
-rw-r--r-- | src/lib/rng/hmac_drbg/hmac_drbg.h | 6 |
2 files changed, 27 insertions, 26 deletions
diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.cpp b/src/lib/rng/hmac_drbg/hmac_drbg.cpp index b22f5dae9..318498d7f 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.cpp +++ b/src/lib/rng/hmac_drbg/hmac_drbg.cpp @@ -10,6 +10,26 @@ namespace Botan { +namespace { + +void check_limits(size_t reseed_interval, + size_t max_number_of_bytes_per_request) + { + // SP800-90A permits up to 2^48, but it is not usable on 32 bit + // platforms, so we only allow up to 2^24, which is still reasonably high + if(reseed_interval == 0 || reseed_interval > static_cast<size_t>(1) << 24) + { + throw Invalid_Argument("Invalid value for reseed_interval"); + } + + if(max_number_of_bytes_per_request == 0 || max_number_of_bytes_per_request > 64 * 1024) + { + throw Invalid_Argument("Invalid value for max_number_of_bytes_per_request"); + } + } + +} + HMAC_DRBG::HMAC_DRBG(std::unique_ptr<MessageAuthenticationCode> prf, RandomNumberGenerator& underlying_rng, size_t reseed_interval, @@ -20,15 +40,7 @@ HMAC_DRBG::HMAC_DRBG(std::unique_ptr<MessageAuthenticationCode> prf, { BOTAN_ASSERT_NONNULL(m_mac); - if(reseed_interval == 0 || reseed_interval > static_cast<size_t>(1) << 48) - { - throw Invalid_Argument("Invalid value for reseed_interval"); - } - - if(m_max_number_of_bytes_per_request == 0 || m_max_number_of_bytes_per_request > 64 * 1024) - { - throw Invalid_Argument("Invalid value for max_number_of_bytes_per_request"); - } + check_limits(reseed_interval, max_number_of_bytes_per_request); clear(); } @@ -37,22 +49,14 @@ HMAC_DRBG::HMAC_DRBG(std::unique_ptr<MessageAuthenticationCode> prf, RandomNumberGenerator& underlying_rng, Entropy_Sources& entropy_sources, size_t reseed_interval, - size_t max_number_of_bytes_per_request ) : + size_t max_number_of_bytes_per_request) : Stateful_RNG(underlying_rng, entropy_sources, reseed_interval), m_mac(std::move(prf)), m_max_number_of_bytes_per_request(max_number_of_bytes_per_request) { BOTAN_ASSERT_NONNULL(m_mac); - if(reseed_interval == 0 || reseed_interval > static_cast<size_t>(1) << 48) - { - throw Invalid_Argument("Invalid value for reseed_interval"); - } - - if(m_max_number_of_bytes_per_request == 0 || m_max_number_of_bytes_per_request > 64 * 1024) - { - throw Invalid_Argument("Invalid value for max_number_of_bytes_per_request"); - } + check_limits(reseed_interval, max_number_of_bytes_per_request); clear(); } @@ -67,10 +71,7 @@ HMAC_DRBG::HMAC_DRBG(std::unique_ptr<MessageAuthenticationCode> prf, { BOTAN_ASSERT_NONNULL(m_mac); - if(m_max_number_of_bytes_per_request == 0 || m_max_number_of_bytes_per_request > 64 * 1024) - { - throw Invalid_Argument("Invalid value for max_number_of_bytes_per_request"); - } + check_limits(reseed_interval, max_number_of_bytes_per_request); clear(); } diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.h b/src/lib/rng/hmac_drbg/hmac_drbg.h index 6ead498fc..1d4c81ab3 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.h +++ b/src/lib/rng/hmac_drbg/hmac_drbg.h @@ -43,7 +43,7 @@ class BOTAN_PUBLIC_API(2,0) HMAC_DRBG final : public Stateful_RNG * @param underlying_rng is a reference to some RNG which will be used * to perform the periodic reseeding * @param reseed_interval specifies a limit of how many times - * the RNG will be called before automatic reseeding is performed + * the RNG will be called before automatic reseeding is performed (max. 2^24) * @param max_number_of_bytes_per_request requests that are in size higher * than max_number_of_bytes_per_request are treated as if multiple single * requests of max_number_of_bytes_per_request size had been made. @@ -70,7 +70,7 @@ class BOTAN_PUBLIC_API(2,0) HMAC_DRBG final : public Stateful_RNG * @param prf MAC to use as a PRF * @param entropy_sources will be polled to perform reseeding periodically * @param reseed_interval specifies a limit of how many times - * the RNG will be called before automatic reseeding is performed. + * the RNG will be called before automatic reseeding is performed (max. 2^24) * @param max_number_of_bytes_per_request requests that are in size higher * than max_number_of_bytes_per_request are treated as if multiple single * requests of max_number_of_bytes_per_request size had been made. @@ -100,7 +100,7 @@ class BOTAN_PUBLIC_API(2,0) HMAC_DRBG final : public Stateful_RNG * to perform the periodic reseeding * @param entropy_sources will be polled to perform reseeding periodically * @param reseed_interval specifies a limit of how many times - * the RNG will be called before automatic reseeding is performed. + * the RNG will be called before automatic reseeding is performed (max. 2^24) * @param max_number_of_bytes_per_request requests that are in size higher * than max_number_of_bytes_per_request are treated as if multiple single * requests of max_number_of_bytes_per_request size had been made. |