chore(fortuna): add random_data() checks, batch 1
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d907c9db6e
commit
b55ca33e24
17
fortuna.cpp
17
fortuna.cpp
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace fortuna {
|
namespace fortuna {
|
||||||
|
static constexpr const unsigned int min_pool_size{64};
|
||||||
|
|
||||||
|
|
||||||
Fortuna::Fortuna() {
|
Fortuna::Fortuna() {
|
||||||
try {
|
try {
|
||||||
initialize_prng();
|
initialize_prng();
|
||||||
@ -28,7 +31,19 @@ namespace fortuna {
|
|||||||
auto Fortuna::random_data(unsigned int n_bytes) -> void {
|
auto Fortuna::random_data(unsigned int n_bytes) -> void {
|
||||||
const auto start{std::chrono::system_clock::now()};
|
const auto start{std::chrono::system_clock::now()};
|
||||||
fmt::print("random_data starting - {}\n", start);
|
fmt::print("random_data starting - {}\n", start);
|
||||||
|
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();
|
incr_reseed_ctr();
|
||||||
|
}
|
||||||
|
R.last_reseed = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
std::string n{R.Gen.generate_random_data(n_bytes)};
|
std::string n{R.Gen.generate_random_data(n_bytes)};
|
||||||
fmt::print("got you {} proper bytes from generate_random_data -> {}\n",
|
fmt::print("got you {} proper bytes from generate_random_data -> {}\n",
|
||||||
@ -39,6 +54,8 @@ namespace fortuna {
|
|||||||
std::chrono::duration<float> diff = end-start;
|
std::chrono::duration<float> diff = end-start;
|
||||||
fmt::print("random_data done - {}\n", end);
|
fmt::print("random_data done - {}\n", end);
|
||||||
fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12);
|
fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12);
|
||||||
|
// TODO(me): eventually call reseed here
|
||||||
|
// R.Gen.reseed("");
|
||||||
} //random_data
|
} //random_data
|
||||||
|
|
||||||
} // namespace fortuna
|
} // namespace fortuna
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace fortuna {
|
namespace fortuna {
|
||||||
|
|
||||||
class Fortuna {
|
class Fortuna {
|
||||||
@ -66,6 +68,8 @@ public:
|
|||||||
unsigned __int128 reseed_ctr;
|
unsigned __int128 reseed_ctr;
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
accumulator::Pool pools[num_of_pools];
|
accumulator::Pool pools[num_of_pools];
|
||||||
|
|
||||||
|
std::chrono::steady_clock::time_point last_reseed;
|
||||||
}; // class R_state
|
}; // class R_state
|
||||||
|
|
||||||
fortuna::Fortuna::R_state R;
|
fortuna::Fortuna::R_state R;
|
||||||
|
@ -11,6 +11,8 @@ namespace generator {
|
|||||||
|
|
||||||
class Generator {
|
class Generator {
|
||||||
public:
|
public:
|
||||||
|
std::chrono::milliseconds reseed_interval{100};
|
||||||
|
|
||||||
Generator(); // ad noexcept: perhaps _do_ throw*
|
Generator(); // ad noexcept: perhaps _do_ throw*
|
||||||
~Generator() noexcept;
|
~Generator() noexcept;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user