diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/rng/auto_rng.h | 2 | ||||
-rw-r--r-- | src/lib/rng/hmac_drbg/hmac_drbg.cpp | 8 | ||||
-rw-r--r-- | src/lib/rng/hmac_drbg/hmac_drbg.h | 4 | ||||
-rw-r--r-- | src/lib/rng/hmac_rng/hmac_rng.cpp | 9 | ||||
-rw-r--r-- | src/lib/rng/hmac_rng/hmac_rng.h | 5 | ||||
-rw-r--r-- | src/lib/rng/rng.cpp | 8 | ||||
-rw-r--r-- | src/lib/rng/rng.h | 4 | ||||
-rw-r--r-- | src/lib/rng/system_rng/system_rng.cpp | 12 | ||||
-rw-r--r-- | src/lib/rng/system_rng/system_rng.h | 4 |
9 files changed, 29 insertions, 27 deletions
diff --git a/src/lib/rng/auto_rng.h b/src/lib/rng/auto_rng.h index b51390ae2..3085623ef 100644 --- a/src/lib/rng/auto_rng.h +++ b/src/lib/rng/auto_rng.h @@ -36,7 +36,7 @@ class BOTAN_DLL AutoSeeded_RNG final : public RandomNumberGenerator void add_entropy(const byte in[], size_t len) override { m_rng->add_entropy(in, len); } - AutoSeeded_RNG(size_t bytes_before_reseed = BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED); + AutoSeeded_RNG(size_t max_output_before_reseed = BOTAN_RNG_DEFAULT_MAX_OUTPUT_BEFORE_RESEED); private: std::unique_ptr<RandomNumberGenerator> m_rng; uint32_t m_counter = 0; diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.cpp b/src/lib/rng/hmac_drbg/hmac_drbg.cpp index 6fdd7daf9..7325804e3 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.cpp +++ b/src/lib/rng/hmac_drbg/hmac_drbg.cpp @@ -11,8 +11,8 @@ namespace Botan { HMAC_DRBG::HMAC_DRBG(MessageAuthenticationCode* hmac, - size_t max_bytes_before_reseed) : - Stateful_RNG(max_bytes_before_reseed), + size_t max_output_before_reseed) : + Stateful_RNG(max_output_before_reseed), m_mac(hmac) { m_V.resize(m_mac->output_length()); @@ -20,8 +20,8 @@ HMAC_DRBG::HMAC_DRBG(MessageAuthenticationCode* hmac, } HMAC_DRBG::HMAC_DRBG(const std::string& hmac_hash, - size_t max_bytes_before_reseed) : - Stateful_RNG(max_bytes_before_reseed) + size_t max_output_before_reseed) : + Stateful_RNG(max_output_before_reseed) { const std::string hmac = "HMAC(" + hmac_hash + ")"; diff --git a/src/lib/rng/hmac_drbg/hmac_drbg.h b/src/lib/rng/hmac_drbg/hmac_drbg.h index 8ee598470..0e294dbdb 100644 --- a/src/lib/rng/hmac_drbg/hmac_drbg.h +++ b/src/lib/rng/hmac_drbg/hmac_drbg.h @@ -23,10 +23,10 @@ class BOTAN_DLL HMAC_DRBG final : public Stateful_RNG * Initialize an HMAC_DRBG instance with the given hash function */ HMAC_DRBG(const std::string& hmac_hash, - size_t max_bytes_before_reseed = BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED); + size_t max_output_before_reseed = BOTAN_RNG_DEFAULT_MAX_OUTPUT_BEFORE_RESEED); HMAC_DRBG(MessageAuthenticationCode* hmac, - size_t max_bytes_before_reseed = BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED); + size_t max_output_before_reseed = BOTAN_RNG_DEFAULT_MAX_OUTPUT_BEFORE_RESEED); std::string name() const override; diff --git a/src/lib/rng/hmac_rng/hmac_rng.cpp b/src/lib/rng/hmac_rng/hmac_rng.cpp index 410e3040a..c100cf70f 100644 --- a/src/lib/rng/hmac_rng/hmac_rng.cpp +++ b/src/lib/rng/hmac_rng/hmac_rng.cpp @@ -12,8 +12,8 @@ namespace Botan { -HMAC_RNG::HMAC_RNG(const std::string& hash, size_t max_before_reseed) : - Stateful_RNG(max_before_reseed) +HMAC_RNG::HMAC_RNG(const std::string& hash, size_t max_output_before_reseed) : + Stateful_RNG(max_output_before_reseed) { m_extractor = MAC::create("HMAC(" + hash + ")"); if(!m_extractor) @@ -36,8 +36,9 @@ HMAC_RNG::HMAC_RNG(const std::string& hash, size_t max_before_reseed) : * HMAC_RNG Constructor */ HMAC_RNG::HMAC_RNG(MessageAuthenticationCode* extractor, - MessageAuthenticationCode* prf) : - Stateful_RNG(BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED), + MessageAuthenticationCode* prf, + size_t max_output_before_reseed) : + Stateful_RNG(max_output_before_reseed), m_extractor(extractor), m_prf(prf) { if(!m_prf->valid_keylength(m_extractor->output_length()) || diff --git a/src/lib/rng/hmac_rng/hmac_rng.h b/src/lib/rng/hmac_rng/hmac_rng.h index f2f8a610d..a2538a83a 100644 --- a/src/lib/rng/hmac_rng/hmac_rng.h +++ b/src/lib/rng/hmac_rng/hmac_rng.h @@ -42,13 +42,14 @@ class BOTAN_DLL HMAC_RNG : public Stateful_RNG * @param prf a MAC used as a PRF using HKDF construction */ HMAC_RNG(MessageAuthenticationCode* extractor, - MessageAuthenticationCode* prf); + MessageAuthenticationCode* prf, + size_t max_output_before_reseed = BOTAN_RNG_DEFAULT_MAX_OUTPUT_BEFORE_RESEED); /** * Use the specified hash for both the extractor and PRF functions */ HMAC_RNG(const std::string& hash, - size_t max_before_reseed = BOTAN_RNG_MAX_OUTPUT_BEFORE_RESEED); + size_t max_output_before_reseed = BOTAN_RNG_DEFAULT_MAX_OUTPUT_BEFORE_RESEED); private: std::unique_ptr<MessageAuthenticationCode> m_extractor; std::unique_ptr<MessageAuthenticationCode> m_prf; diff --git a/src/lib/rng/rng.cpp b/src/lib/rng/rng.cpp index 923b417dc..5501c143e 100644 --- a/src/lib/rng/rng.cpp +++ b/src/lib/rng/rng.cpp @@ -42,7 +42,7 @@ size_t RandomNumberGenerator::reseed_with_sources(Entropy_Sources& srcs, return srcs.poll(*this, poll_bits, poll_timeout); } -Stateful_RNG::Stateful_RNG(size_t bytes_before_reseed) : m_bytes_before_reseed(bytes_before_reseed) +Stateful_RNG::Stateful_RNG(size_t max_output_before_reseed) : m_max_output_before_reseed(max_output_before_reseed) { } @@ -79,7 +79,7 @@ void Stateful_RNG::reseed_check(size_t bytes_requested) { this->reseed(BOTAN_RNG_RESEED_POLL_BITS); } - else if(m_bytes_before_reseed > 0 && m_bytes_since_reseed >= m_bytes_before_reseed) + else if(m_max_output_before_reseed > 0 && m_bytes_since_reseed >= m_max_output_before_reseed) { this->reseed_with_timeout(BOTAN_RNG_RESEED_POLL_BITS, BOTAN_RNG_AUTO_RESEED_TIMEOUT); @@ -107,9 +107,9 @@ RandomNumberGenerator* RandomNumberGenerator::make_rng() return new AutoSeeded_RNG; } -AutoSeeded_RNG::AutoSeeded_RNG(size_t max_bytes_before_reseed) +AutoSeeded_RNG::AutoSeeded_RNG(size_t max_output_before_reseed) { - m_rng.reset(new BOTAN_AUTO_RNG_DRBG(BOTAN_AUTO_RNG_HASH, max_bytes_before_reseed)); + m_rng.reset(new BOTAN_AUTO_RNG_DRBG(BOTAN_AUTO_RNG_HASH, max_output_before_reseed)); size_t bits = m_rng->reseed(BOTAN_AUTO_RNG_ENTROPY_TARGET); diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h index 476928ff7..7da560b85 100644 --- a/src/lib/rng/rng.h +++ b/src/lib/rng/rng.h @@ -195,14 +195,14 @@ class BOTAN_DLL Stateful_RNG : public RandomNumberGenerator /** * Mark state as requiring a reseed on next use */ - void force_reseed() { m_bytes_since_reseed = m_bytes_before_reseed; } + void force_reseed() { m_bytes_since_reseed = m_max_output_before_reseed; } uint32_t last_pid() const { return m_last_pid; } mutable std::mutex m_mutex; private: - const size_t m_bytes_before_reseed; + const size_t m_max_output_before_reseed; size_t m_bytes_since_reseed = 0; uint32_t m_last_pid = 0; bool m_successful_initialization = false; diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp index a503c2198..135f4fabd 100644 --- a/src/lib/rng/system_rng/system_rng.cpp +++ b/src/lib/rng/system_rng/system_rng.cpp @@ -38,9 +38,9 @@ class System_RNG_Impl final : public RandomNumberGenerator void clear() override {} - void randomize(Botan::byte out[], size_t len) override; + void randomize(uint8_t out[], size_t len) override; - void add_entropy(const byte in[], size_t length) override; + void add_entropy(const uint8_t in[], size_t length) override; std::string name() const override; @@ -90,7 +90,7 @@ System_RNG_Impl::~System_RNG_Impl() #endif } -void System_RNG_Impl::add_entropy(const byte input[], size_t len) +void System_RNG_Impl::add_entropy(const uint8_t input[], size_t len) { #if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) /* @@ -102,14 +102,14 @@ void System_RNG_Impl::add_entropy(const byte input[], size_t len) for(size_t i = 0; i != len; ++i) { - byte b = input[i]; + uint8_t b = input[i]; ::CryptGenRandom(m_prov, 1, &b); } */ if(len > 0) { - secure_vector<byte> buf(input, input + len); + secure_vector<uint8_t> buf(input, input + len); ::CryptGenRandom(m_prov, static_cast<DWORD>(buf.size()), buf.data()); } #else @@ -144,7 +144,7 @@ void System_RNG_Impl::add_entropy(const byte input[], size_t len) #endif } -void System_RNG_Impl::randomize(byte buf[], size_t len) +void System_RNG_Impl::randomize(uint8_t buf[], size_t len) { #if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM) ::CryptGenRandom(m_prov, static_cast<DWORD>(len), buf); diff --git a/src/lib/rng/system_rng/system_rng.h b/src/lib/rng/system_rng/system_rng.h index a789631d6..9cf31e78b 100644 --- a/src/lib/rng/system_rng/system_rng.h +++ b/src/lib/rng/system_rng/system_rng.h @@ -27,9 +27,9 @@ class BOTAN_DLL System_RNG final : public RandomNumberGenerator public: std::string name() const override { return system_rng().name(); } - void randomize(Botan::byte out[], size_t len) override { system_rng().randomize(out, len); } + void randomize(uint8_t out[], size_t len) override { system_rng().randomize(out, len); } - void add_entropy(const byte in[], size_t length) override { system_rng().add_entropy(in, length); } + void add_entropy(const uint8_t in[], size_t length) override { system_rng().add_entropy(in, length); } bool is_seeded() const override { return true; } |