Commit Graph

22 Commits

Author SHA1 Message Date
surtur a3daa722da
chore: print info msgs to stderr 2022-02-03 00:37:20 +01:00
surtur dc1ab343eb
rename: set_gen() -> set_gen_ptr() 2022-01-30 20:48:08 +01:00
surtur df4c9d7bdb
accumulator: add noexcept where reasonable 2022-01-29 23:54:26 +01:00
surtur 74f8af7bfc
accumulator: rm unused pools_service() 2022-01-27 23:59:56 +01:00
surtur 19ea0076a3
accumulator: rm unused accumulator_service() 2022-01-27 23:59:38 +01:00
surtur 52de785399
fortuna: properly handle reseeds
* move reseed_ctr and related member functions to Accumulator

* create a std::shared_ptr<Accumulator> to Fortuna's internal
  Accumulator object and feed that into SeedFileManager instead of a
  reference, which used to get copied to a new object in SeedFileManager

* make Accumulator non-copyable, since it's only to be created once.
  instead, a shared_ptr is used to facilitate multiple-access

* handle concurrency in Accumulator as the reseed_ctr-related functions
  can now be accessed from both Fortuna and SeedFileManager, declare mtx
  as mutable (since it's also used in a const function)

* use std::scoped_lock in 'initialize_prng()' to safely lock both mutexes
2022-01-22 18:36:51 +01:00
surtur d404681889
feat: "prepare to add proper entropy source" nits
general
* make greater use of "this"

Fortuna
* declare da_pools as a proper std::array of 32 Pool objects
* declare da_pools as const
* use std::shared_ptr _p_pools to access da_pools and share access to
  it
* reflect change of pools[] -> std::array in how the array elements
  are accessed, which is a) via _p_pools pointer and b) using ".at(i)"
  function
* pass _p_pools shared_ptr to Accumulator
* refactor member function names and variable names
* add member function attribute [[optimize_for_synchronized]]
* secure conversions with static_cast-s

Accumulator
* make use of _p_pools
* add _p_pools-related member functions
* add a static constexpr variable NUM_OF_POOLS

UrandomEntropySrc
* implement event adding logic using _p_pools
* make std::vector<char> non-static in urandom_entropy_src
* implement proper urandom entropy source event "sourcing" (from
  /dev/urandom), event adding, clear bytes array at the end
* properly convert using reinterpret_cast
* protect access to the main function with std::lock_guard
* receive EventAdderImpl as a ref
* use return value from "add_entropy()" member function and create
  sanity guard checking the return code "int ret"

EventAdder
* pass event (std::vector<char>) by const&

EventAdderImpl
* make use of _p_pools shared_ptr
* implement proper pool-rotating event-adding logic

Pool
* delete all copy constructors and assignment operator, the objects
  will not be copied or assigned to
* receive parameters by const& where possible/sensible
* handle concurrency:
  * declare std:string s as mutable
  * declare a rw std::mutex intended for writing and mutable
    std::recursive_mutex for read-only operations in const member
    functions
    ref: https://herbsutter.com/2013/05/24/gotw-6a-const-correctness-part-1-3/
    ref: https://arne-mertz.de/2017/10/mutable/
  * use std::lock_guard and std::unique_lock
* refactor "add_entropy()" member function
  * get rid of intermediate "event_str" and directly use the "event"
    std::vector<char> for all operations
  * add a lock guard to prevent multiple threads (should that route be
    taken) from modifying pool resources simultaneously
  * add all_ok bool for basic sanity checking
  * add print statements (at least for now)
* rename "get_s_length()" member function to "get_s_byte_count()" and
  repurpose it to return byte count of the stored entropy std::string s
2022-01-17 08:27:24 +01:00
surtur 146bf14d68
accumulator: use const& params,uint->unsigned int 2022-01-17 04:36:15 +01:00
surtur 61dbc4b666
accumulator: fix -Wshadow, -Wconversion 2022-01-14 07:17:59 +01:00
surtur 9f738e97ec
accumulator: actually register the pool 2022-01-13 06:21:57 +01:00
surtur 767da88531
accumulator: check entropy sources before adding 2022-01-11 05:38:02 +01:00
surtur ebb1e46e1c
accumulator: move logic to source file 2022-01-10 06:23:26 +01:00
surtur a3009709cf
chore(accumulator): reorder includes 2022-01-06 00:30:46 +01:00
surtur 56b1773c28
accumulator: make ctor noexcept 2022-01-02 07:21:25 +01:00
surtur 1a325193b0
accumulator: add prototypes of service methods 2022-01-02 07:13:12 +01:00
surtur e5cba7e261
accumulator: add wait_for() 2022-01-01 09:23:42 +01:00
surtur 2086861776
accumulator: implement add_source() 2021-12-29 03:49:36 +01:00
surtur 234b87ff1f
accumulator: use a Generator pointer 2021-12-29 02:56:57 +01:00
surtur 01c402300c
accumulator: add generator-interacting methods
..and a way to work with the generator
2021-12-13 13:22:50 +01:00
surtur a6719d4947
accumulator: add add_source 2021-12-11 02:27:52 +01:00
surtur 053d2187a2
chore(accumulator): make use of init_pool_num 2021-12-09 14:11:39 +01:00
surtur a1cbbb209e
handle PRNG state in R_state + accumulator basis
* 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
2021-12-04 00:40:39 +01:00