71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#ifndef FORTUNA_ACCUMULATOR_H
|
|
#define FORTUNA_ACCUMULATOR_H
|
|
|
|
#include "event_adder_impl.h"
|
|
#include "generator.h"
|
|
#include "pool.h"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <exception>
|
|
#include <vector>
|
|
|
|
namespace fortuna {
|
|
namespace accumulator {
|
|
|
|
class Accumulator {
|
|
private:
|
|
static constexpr const uint8_t MAX_SOURCES{255};
|
|
std::vector<uint8_t> entropy_sources{};
|
|
fortuna::generator::Generator* Gen;
|
|
|
|
protected:
|
|
uint src_count{0};
|
|
|
|
public:
|
|
constexpr static const unsigned int init_pool_num{0};
|
|
|
|
auto add_source() -> void {
|
|
static uint src_id{this->src_count};
|
|
// make really sure we don't and a duplicate src_id
|
|
if (src_id <= this->MAX_SOURCES && !src_is_registered(src_id)) {
|
|
entropy_sources.push_back(src_id);
|
|
++src_count;
|
|
accumulator::Pool pools[32];
|
|
EventAdderImpl event_adder(src_id, pools);
|
|
[[maybe_unused]] bool scheduled;
|
|
}
|
|
}
|
|
|
|
auto src_is_registered(const uint8_t& id) -> bool;
|
|
|
|
auto set_gen(fortuna::generator::Generator& Gen) -> void;
|
|
|
|
auto get_random_data(uint n_bytes) -> std::string;
|
|
|
|
auto call_reseed(const std::string& seed) -> void;
|
|
|
|
auto wait_for(uint milliseconds) -> void;
|
|
|
|
// spawns the entropy_collector_service and pools_service threads
|
|
auto accumulator_service() -> int;
|
|
|
|
// a long lived thread collecting entropy
|
|
// listens on a unix socket, receives events
|
|
auto entropy_collector_service() -> int;
|
|
|
|
auto pools_service() -> int;
|
|
|
|
|
|
Accumulator() noexcept;
|
|
~Accumulator() noexcept;
|
|
|
|
}; // class Accumulator
|
|
|
|
} // namespace accumulator
|
|
} // namespace fortuna
|
|
|
|
#endif // FORTUNA_ACCUMULATOR_H
|