generator: implement time_to_reseed() fun
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-15 13:35:56 +01:00
parent c0933d355d
commit 7fca4481c8
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 19 additions and 6 deletions

View File

@ -59,8 +59,10 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
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) {
if (R.Gen.time_to_reseed(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) {
if (R.reseed_ctr % static_cast<int>(pow(2, i)) == 0) {
try {

View File

@ -10,8 +10,11 @@
#include <cryptopp/serpent.h>
#include <fmt/core.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <stdexcept>
@ -46,9 +49,12 @@ auto Generator::get_state() const -> G_state {
return G;
}
auto Generator::time_to_reseed() const -> bool {
// TODO(me): implement this
if (true) {
auto Generator::time_to_reseed(
const uint64_t& pool0_len,
const unsigned int& min_p_size,
const std::chrono::duration<int64_t, std::ratio<1, 1000>>& time_elapsed,
const std::chrono::milliseconds& gen_reseed_interval) const -> bool {
if (pool0_len >= min_p_size && time_elapsed > gen_reseed_interval) {
return true;
}
else {

View File

@ -5,6 +5,7 @@
#include <cryptopp/secblock.h>
#include <chrono>
#include <cstdint>
#include <mutex>
#include <string>
@ -28,7 +29,11 @@ public:
auto reseed(const std::string& s) -> void;
auto time_to_reseed() const -> bool;
[[optimize_for_synchronized]] auto time_to_reseed(
const uint64_t& pool0_len,
const unsigned int& min_p_size,
const std::chrono::duration<int64_t, std::ratio<1, 1000>>& time_elapsed,
const std::chrono::milliseconds& reseed_interval) const -> bool;
auto is_seeded() const -> bool {
return !(this->G.ctr == 0x00);