fortuna: move code into a try block
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-20 06:06:07 +01:00
parent 4f28612f3f
commit a3f871a644
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -62,48 +62,54 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
now.time_since_epoch())};
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",
this->R._p_pools->at(0).get_s_byte_count());
if (R.Gen.time_to_reseed(R._p_pools->at(0).get_s_byte_count(),
min_pool_size,
elapsed,
R.Gen.reseed_interval)) {
for (int i = 0; i < static_cast<int>(pools_to_use); ++i) {
if (this->R.reseed_ctr %
static_cast<uint64_t>(pow(2, static_cast<double>(i))) ==
0) {
try {
try {
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",
this->R._p_pools->at(0).get_s_byte_count());
if (R.Gen.time_to_reseed(R._p_pools->at(0).get_s_byte_count(),
min_pool_size,
elapsed,
R.Gen.reseed_interval)) {
// if (R.pools[0].get_s_byte_count() >= min_pool_size &&
// elapsed > R.Gen.reseed_interval) {
for (int i = 0; i < static_cast<int>(pools_to_use); ++i) {
if (this->R.reseed_ctr %
static_cast<uint64_t>(pow(2, static_cast<double>(i))) ==
0) {
s.append(fortuna::Util::do_sha(
this->R._p_pools->at(static_cast<uint64_t>(i))
.get_s()));
this->R._p_pools->at(static_cast<uint64_t>(i)).clear_pool();
}
catch (std::exception& e) {
fmt::print("{}\n", e.what());
}
}
incr_reseed_ctr();
R.Gen.reseed(s);
R.last_reseed = std::chrono::steady_clock::now();
s.clear();
}
incr_reseed_ctr();
R.Gen.reseed(s);
R.last_reseed = std::chrono::steady_clock::now();
s.clear();
}
fmt::print("[i] fortuna: reseed ctr {}\n", R.reseed_ctr);
if (R.reseed_ctr == 0) {
fmt::print("[!] ERROR: reseed ctr is 0, PRNG not seeded!\n");
throw std::runtime_error("illegal state, PRNG not seeded");
fmt::print("[i] fortuna: reseed ctr {}\n", R.reseed_ctr);
if (R.reseed_ctr == 0) {
fmt::print("[!] ERROR: reseed ctr is 0, PRNG not seeded!\n");
throw std::runtime_error("illegal state, PRNG not seeded");
}
else {
const std::string n{R.Gen.generate_random_data(n_bytes)};
fmt::print(
"got you {} proper bytes from generate_random_data -> {}\n",
n_bytes,
n);
}
}
else {
const std::string n{R.Gen.generate_random_data(n_bytes)};
fmt::print("got you {} proper bytes from generate_random_data -> {}\n",
n_bytes,
n);
catch (std::exception& e) {
fmt::print("{}\n", e.what());
}
const auto end{std::chrono::system_clock::now()};