diff options
Diffstat (limited to 'src/tests/test_rng.h')
-rw-r--r-- | src/tests/test_rng.h | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h index c14ed7fb7..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,44 @@ 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 + { + public: + void randomize(uint8_t[], size_t) override + { throw Botan::Exception("SeedCapturing_RNG has no output"); } + + void add_entropy(const byte input[], size_t len) override + { + m_samples++; + m_seed.insert(m_seed.end(), input, input + len); + } + + void clear() override {} + bool is_seeded() const override { return false; } + std::string name() const override { return "SeedCapturing"; } + + size_t samples() const { return m_samples; } + + const std::vector<uint8_t>& seed_material() const { return m_seed; } + + private: + std::vector<uint8_t> m_seed; + size_t m_samples = 0; }; } |