This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
fortuna/accumulator.h

71 lines
1.6 KiB
C
Raw Normal View History

#ifndef FORTUNA_ACCUMULATOR_H
#define FORTUNA_ACCUMULATOR_H
2021-12-29 03:49:36 +01:00
#include "event_adder_impl.h"
#include "generator.h"
#include "pool.h"
2022-01-10 06:23:26 +01:00
2022-01-06 00:30:46 +01:00
#include <fmt/core.h>
2022-01-10 06:23:26 +01:00
2021-12-28 06:13:03 +01:00
#include <algorithm>
#include <cstdint>
#include <exception>
#include <vector>
namespace fortuna {
namespace accumulator {
class Accumulator {
2021-12-28 06:13:03 +01:00
private:
static constexpr const uint8_t MAX_SOURCES{255};
std::vector<uint8_t> entropy_sources{};
2022-01-10 06:23:26 +01:00
fortuna::generator::Generator* Gen;
2021-12-28 06:13:03 +01:00
2021-12-29 03:49:36 +01:00
protected:
uint src_count{0};
public:
constexpr static const unsigned int init_pool_num{0};
2021-12-11 02:27:52 +01:00
2021-12-29 03:49:36 +01:00
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;
}
2021-12-29 03:49:36 +01:00
}
2021-12-11 02:27:52 +01:00
auto src_is_registered(const uint8_t& id) -> bool;
2022-01-10 06:23:26 +01:00
auto set_gen(fortuna::generator::Generator& Gen) -> void;
2022-01-10 06:23:26 +01:00
auto get_random_data(uint n_bytes) -> std::string;
2022-01-10 06:23:26 +01:00
auto call_reseed(const std::string& seed) -> void;
2022-01-01 09:23:42 +01:00
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;
2022-01-02 07:19:10 +01:00
Accumulator() noexcept;
2021-12-28 06:13:03 +01:00
~Accumulator() noexcept;
2022-01-10 06:23:26 +01:00
}; // class Accumulator
2022-01-10 06:23:26 +01:00
} // namespace accumulator
} // namespace fortuna
2022-01-10 06:23:26 +01:00
#endif // FORTUNA_ACCUMULATOR_H