aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/rng/stateful_rng/stateful_rng.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/lib/rng/stateful_rng/stateful_rng.cpp b/src/lib/rng/stateful_rng/stateful_rng.cpp
index dec791793..058245d14 100644
--- a/src/lib/rng/stateful_rng/stateful_rng.cpp
+++ b/src/lib/rng/stateful_rng/stateful_rng.cpp
@@ -8,6 +8,10 @@
#include <botan/internal/os_utils.h>
#include <botan/loadstor.h>
+#if defined(BOTAN_HAS_RDRAND_RNG)
+ #include <botan/rdrand_rng.h>
+#endif
+
namespace Botan {
void Stateful_RNG::clear()
@@ -39,10 +43,21 @@ void Stateful_RNG::initialize_with(const uint8_t input[], size_t len)
void Stateful_RNG::randomize_with_ts_input(uint8_t output[], size_t output_len)
{
uint8_t additional_input[24] = { 0 };
- store_le(OS::get_system_timestamp_ns(), additional_input);
- store_le(OS::get_high_resolution_clock(), additional_input + 8);
- store_le(m_last_pid, additional_input + 16);
- store_le(static_cast<uint32_t>(m_reseed_counter), additional_input + 20);
+
+#if defined(BOTAN_HAS_RDRAND_RNG)
+ if(RDRAND_RNG::available())
+ {
+ RDRAND_RNG rdrand;
+ rdrand.randomize(additional_input, sizeof(additional_input));
+ }
+ else
+#endif
+ {
+ store_le(OS::get_system_timestamp_ns(), additional_input);
+ store_le(OS::get_high_resolution_clock(), additional_input + 8);
+ store_le(m_last_pid, additional_input + 16);
+ store_le(static_cast<uint32_t>(m_reseed_counter), additional_input + 20);
+ }
randomize_with_input(output, output_len, additional_input, sizeof(additional_input));
}