aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/rng/rng.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-09-04 19:29:59 -0400
committerJack Lloyd <[email protected]>2018-09-06 11:24:16 -0400
commit8cbe5195b2ea82bf7a58f1a3b8afcc8c53a7537b (patch)
treee24dba4d3e8df8024b8ffffc797d2d15c0908f76 /src/lib/rng/rng.cpp
parent992d2803181b34415c25e013a40ab935eb71a9e3 (diff)
Add RandomNumberGenerator::accepts_input
Diffstat (limited to 'src/lib/rng/rng.cpp')
-rw-r--r--src/lib/rng/rng.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/lib/rng/rng.cpp b/src/lib/rng/rng.cpp
index 2cf3b7b81..2947ac629 100644
--- a/src/lib/rng/rng.cpp
+++ b/src/lib/rng/rng.cpp
@@ -17,15 +17,22 @@ namespace Botan {
void RandomNumberGenerator::randomize_with_ts_input(uint8_t output[], size_t output_len)
{
- /*
- Form additional input which is provided to the PRNG implementation
- to paramaterize the KDF output.
- */
- uint8_t additional_input[16] = { 0 };
- store_le(OS::get_system_timestamp_ns(), additional_input);
- store_le(OS::get_high_resolution_clock(), additional_input + 8);
+ if(this->accepts_input())
+ {
+ /*
+ Form additional input which is provided to the PRNG implementation
+ to paramaterize the KDF output.
+ */
+ uint8_t additional_input[16] = { 0 };
+ store_le(OS::get_system_timestamp_ns(), additional_input);
+ store_le(OS::get_high_resolution_clock(), additional_input + 8);
- randomize_with_input(output, output_len, additional_input, sizeof(additional_input));
+ this->randomize_with_input(output, output_len, additional_input, sizeof(additional_input));
+ }
+ else
+ {
+ this->randomize(output, output_len);
+ }
}
void RandomNumberGenerator::randomize_with_input(uint8_t output[], size_t output_len,
@@ -39,14 +46,24 @@ size_t RandomNumberGenerator::reseed(Entropy_Sources& srcs,
size_t poll_bits,
std::chrono::milliseconds poll_timeout)
{
- return srcs.poll(*this, poll_bits, poll_timeout);
+ if(this->accepts_input())
+ {
+ return srcs.poll(*this, poll_bits, poll_timeout);
+ }
+ else
+ {
+ return 0;
+ }
}
void RandomNumberGenerator::reseed_from_rng(RandomNumberGenerator& rng, size_t poll_bits)
{
- secure_vector<uint8_t> buf(poll_bits / 8);
- rng.randomize(buf.data(), buf.size());
- this->add_entropy(buf.data(), buf.size());
+ if(this->accepts_input())
+ {
+ secure_vector<uint8_t> buf(poll_bits / 8);
+ rng.randomize(buf.data(), buf.size());
+ this->add_entropy(buf.data(), buf.size());
+ }
}
RandomNumberGenerator* RandomNumberGenerator::make_rng()