fortuna,generator: better printing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-14 05:20:52 +01:00
parent ad71199e1a
commit e0448d6d08
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 6 additions and 4 deletions

View File

@ -50,13 +50,15 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
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);
fmt::print("[i] fortuna: last_reseed: {} ago\n", elapsed);
now = std::chrono::steady_clock::now();
std::string s;
// synchronise reads and writes to the between
// {generator,accumulator,fortuna} service threads -> in member functions
const int pools_to_use{ffsll(static_cast<int>(get_reseed_ctr()))};
fmt::print("[*] fortuna: current p0 length: {}\n",
R.pools[0].get_s_length());
if (R.pools[0].get_s_length() >= min_pool_size &&
elapsed > R.Gen.reseed_interval) {
for (int i = 0; i < static_cast<int>(pools_to_use); ++i) {
@ -76,8 +78,9 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
s.clear();
}
fmt::print("[i] fortuna: reseed ctr {}\n", R.reseed_ctr);
if (R.reseed_ctr == 0) {
fmt::print("reseed ctr is 0, PRNG not seeded!\n");
fmt::print("[!] ERROR: reseed ctr is 0, PRNG not seeded!\n");
throw std::runtime_error("illegal state, PRNG not seeded");
}
else {

View File

@ -138,11 +138,10 @@ auto Generator::generate_blocks(unsigned int k_blocks) -> std::string {
auto Generator::generate_random_data(uint n) -> std::string {
std::lock_guard<std::mutex> lg(mtx);
// fmt::print("n -> {}\n", n); // debugging
if (n == 0) {
// do not do this..?
const std::string msg{"zero bytes requested, bailing\n"};
fmt::print("[*] error: {}", msg);
fmt::print("[*] g: error: {}", msg);
throw std::invalid_argument(msg);
}