chore(fortuna): add random_data() checks, batch 1

This commit is contained in:
surtur 2021-12-12 06:14:58 +01:00
parent d907c9db6e
commit b55ca33e24
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 24 additions and 1 deletions

View File

@ -16,6 +16,9 @@
namespace fortuna {
static constexpr const unsigned int min_pool_size{64};
Fortuna::Fortuna() {
try {
initialize_prng();
@ -28,7 +31,19 @@ namespace fortuna {
auto Fortuna::random_data(unsigned int n_bytes) -> void {
const auto start{std::chrono::system_clock::now()};
fmt::print("random_data starting - {}\n", start);
incr_reseed_ctr();
auto now{std::chrono::steady_clock::now()};
auto elapsed{
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch() -
now.time_since_epoch()
)
};
fmt::print("last_reseed: {} ago\n", elapsed);
if (sizeof(R.pools[0]) >= min_pool_size && elapsed > R.Gen.reseed_interval) {
// TODO(me): call to generate_random_data will be moved here
incr_reseed_ctr();
}
R.last_reseed = std::chrono::steady_clock::now();
std::string n{R.Gen.generate_random_data(n_bytes)};
fmt::print("got you {} proper bytes from generate_random_data -> {}\n",
@ -39,6 +54,8 @@ namespace fortuna {
std::chrono::duration<float> diff = end-start;
fmt::print("random_data done - {}\n", end);
fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12);
// TODO(me): eventually call reseed here
// R.Gen.reseed("");
} //random_data
} // namespace fortuna

View File

@ -6,6 +6,8 @@
#include <fmt/core.h>
#include <chrono>
namespace fortuna {
class Fortuna {
@ -66,6 +68,8 @@ public:
unsigned __int128 reseed_ctr;
#pragma GCC diagnostic pop
accumulator::Pool pools[num_of_pools];
std::chrono::steady_clock::time_point last_reseed;
}; // class R_state
fortuna::Fortuna::R_state R;

View File

@ -11,6 +11,8 @@ namespace generator {
class Generator {
public:
std::chrono::milliseconds reseed_interval{100};
Generator(); // ad noexcept: perhaps _do_ throw*
~Generator() noexcept;