surtur
a1cbbb209e
All checks were successful
continuous-integration/drone/push Build is passing
* handle the PRNG state with R_state nested class * add a private property R holding PRNG state to Fortuna * add R_state properties as defined in Cryptography Engineering: * a generator instance * a reseed counter * 32 pools that the collected entropy is to be distributed over * add initial definition of the Pool object and its initialization * attempt to initialize PRNG in Fortuna constructor. wrap the initialization call in a try-catch block like a cultured person * erase the string used to print data from random_data() after it's been used
69 lines
1.3 KiB
C++
69 lines
1.3 KiB
C++
#ifndef FORTUNA_FORTUNA_H
|
|
#define FORTUNA_FORTUNA_H
|
|
|
|
#include "generator.h"
|
|
#include "accumulator.h"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
namespace fortuna {
|
|
|
|
class Fortuna {
|
|
public:
|
|
// in microseconds
|
|
static constexpr const unsigned int reseed_interval{10000};
|
|
static constexpr const char num_of_pools{32};
|
|
|
|
Fortuna();
|
|
~Fortuna();
|
|
|
|
auto random_data(unsigned int) -> void;
|
|
|
|
auto set_reseed_ctr_to_null() -> void {
|
|
Fortuna::R.null_da_ctr();
|
|
}
|
|
|
|
auto initialize_prng() -> void {
|
|
// TODO(me): handle the reseeds here as per Cryptography Engineering,
|
|
// p. 153
|
|
set_reseed_ctr_to_null();
|
|
R.initialize_pools();
|
|
fmt::print("PRNG initialized\n");
|
|
};
|
|
|
|
// PRNG state
|
|
class R_state {
|
|
friend fortuna::Fortuna;
|
|
public:
|
|
R_state(){};
|
|
~R_state() = default;
|
|
|
|
protected:
|
|
auto null_da_ctr() -> void {
|
|
reseed_ctr = 0x00;
|
|
fmt::print("reseed_ctr set to 0x00\n");
|
|
}
|
|
|
|
auto initialize_pools() -> void {
|
|
for (unsigned int i = 0; i < num_of_pools; ++i) {
|
|
pools[i].initialize_pool(i);
|
|
}
|
|
}
|
|
|
|
private:
|
|
generator::Generator Gen;
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wpedantic"
|
|
unsigned __int128 reseed_ctr;
|
|
#pragma GCC diagnostic pop
|
|
accumulator::Pool pools[num_of_pools];
|
|
}; // class R_state
|
|
|
|
fortuna::Fortuna::R_state R;
|
|
|
|
}; // class Fortuna
|
|
|
|
} // namespace fortuna
|
|
|
|
#endif//FORTUNA_FORTUNA_H
|