diff options
author | Jack Lloyd <[email protected]> | 2018-11-21 08:52:50 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-21 08:52:50 -0500 |
commit | 00a33abd87b981827b86b26d477bc261ff9a6a16 (patch) | |
tree | 7387cf5698b48d65c69db5a07758f0f5d9d8813e /src/lib/rng | |
parent | fd2d283eda8f293a4f2bd5f1c33e63a447e24883 (diff) |
When available use RDRAND for Stateful_RNG additional data
Diffstat (limited to 'src/lib/rng')
-rw-r--r-- | src/lib/rng/stateful_rng/stateful_rng.cpp | 23 |
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)); } |