aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_rng.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-08-19 07:51:47 -0400
committerJack Lloyd <[email protected]>2016-08-24 11:31:54 -0400
commit80c160f08f2a69eb4e41a68380796bf31fd2f924 (patch)
tree83259da316524ed3b96b0913e5b023bc40f26a28 /src/tests/test_rng.h
parent91474f60d72937ad3c21d8aa53c14f7a0cceb9ca (diff)
RNG changes (GH #593)
Change reseed interval logic to count calls to `randomize` rather than bytes, to match SP 800-90A Changes RNG reseeding API: there is no implicit reference to the global entropy sources within the RNGs anymore. The entropy sources must be supplied with the API call. Adds support for reseding directly from another RNG (such as a system or hardware RNG). Stateful_RNG keeps optional references to both an RNG and a set of entropy sources. During a reseed, both sources are used if set. These can be provided to HMAC_DRBG constructor. For HMAC_DRBG, SP800-90A requires we output no more than 2**16 bytes per DRBG request. We treat requests longer than that as if the caller had instead made several sequential maximum-length requests. This means it is possible for one or more reseeds to trigger even in the course of generating a single (long) output (generate a 256-bit key and use ChaCha or HKDF if this is a problem). Adds RNG::randomize_with_ts_input which takes timestamps and uses them as the additional_data DRBG field. Stateful_RNG overrides this to also include the process ID and the reseed counter. AutoSeeded_RNG's `randomize` uses this. Officially deprecates RNG::make_rng and the Serialized_RNG construtor which creates an AutoSeeded_RNG. With these removed, it would be possible to perform a build with no AutoSeeded_RNG/HMAC_DRBG at all (eg, for applications which only use the system RNG). Tests courtesy @cordney in GH PRs #598 and #600
Diffstat (limited to 'src/tests/test_rng.h')
-rw-r--r--src/tests/test_rng.h34
1 files changed, 7 insertions, 27 deletions
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h
index 6c29b1d55..0379a2ee9 100644
--- a/src/tests/test_rng.h
+++ b/src/tests/test_rng.h
@@ -15,13 +15,6 @@
#include <botan/hex.h>
#include <botan/exceptn.h>
-#if defined(BOTAN_HAS_SYSTEM_RNG)
- #include <botan/system_rng.h>
-#else
- #include <botan/auto_rng.h>
-#endif
-
-
namespace Botan_Tests {
/**
@@ -43,9 +36,9 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
return out;
}
- size_t reseed_with_sources(Botan::Entropy_Sources&,
- size_t,
- std::chrono::milliseconds) override { return 0; }
+ size_t reseed(Botan::Entropy_Sources&,
+ size_t,
+ std::chrono::milliseconds) override { return 0; }
void randomize(uint8_t out[], size_t len) override
{
@@ -87,7 +80,7 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
class Fixed_Output_Position_RNG : public Fixed_Output_RNG
{
public:
- bool is_seeded() const override { return !m_buf.empty() || m_rng->is_seeded(); }
+ bool is_seeded() const override { return !m_buf.empty() || Test::rng().is_seeded(); }
uint8_t random() override
{
@@ -114,7 +107,7 @@ class Fixed_Output_Position_RNG : public Fixed_Output_RNG
}
else
{ // return random
- m_rng->randomize(out,len);
+ Test::rng().randomize(out,len);
}
}
@@ -127,32 +120,19 @@ class Fixed_Output_Position_RNG : public Fixed_Output_RNG
explicit Fixed_Output_Position_RNG(const std::vector<uint8_t>& in, uint32_t pos) :
Fixed_Output_RNG(in),
- m_pos(pos),
- m_rng{}
+ m_pos(pos)
{
-#if defined(BOTAN_HAS_SYSTEM_RNG)
- m_rng.reset(new Botan::System_RNG);
-#else
- m_rng.reset(new Botan::AutoSeeded_RNG);
-#endif
}
explicit Fixed_Output_Position_RNG(const std::string& in_str, uint32_t pos) :
Fixed_Output_RNG(in_str),
- m_pos(pos),
- m_rng{}
+ m_pos(pos)
{
-#if defined(BOTAN_HAS_SYSTEM_RNG)
- m_rng.reset(new Botan::System_RNG);
-#else
- m_rng.reset(new Botan::AutoSeeded_RNG);
-#endif
}
private:
uint32_t m_pos = 0;
uint32_t m_requests = 0;
- std::unique_ptr<RandomNumberGenerator> m_rng;
};
class SeedCapturing_RNG : public Botan::RandomNumberGenerator