* 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
* implement a background service for the UrandomEntropySrc that is run
every 50ms in an endless loop in a dedicated thread "th_urandom"
* print time, progress and a simple counter (for now) to console
* protect event adder instantiation by acquiring a mutex in
std::unique_lock
* check validity of _p_pools ptr
* hardcode entropy source id as 0
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
* used for orderly printing to screen, currently only used by the two of
the services: generator_service and seed_file_manager_service
* lock the mutex in a unique_lock only when printing to screen, unlock
it immediately after printing is done
* use proper chrono type for sleep_time (instead of uint)
* also, generator_service is no longer a static method
a couple of fixes/necessary additions were made along the way, namely:
* add a default constructor for DoTask
* rework of the mutex/lock_guard/unique_lock logic in generator/fortuna
* add .fortuna.seed to the list of the ignored (.gitignore)
* add helper function to util for convertin bytes to blocks (16b==block)
* add a wrapper for around the SeedFileManager instance and a way to see
if it's dead or alive (so that it can be restarted if needed)
* the timeout for saving of the seed file has been decreased to a more
reasonable value than 10 minutes (I wouldn't want to lose potentially
up to 10 minutes worth of entropy)
* actually clear out entropy of the pools before a reseed
* correctly prepare the seed for the reseed
* add a couple of helper methods to Pool that assist with getting
length, retrieving and clearing of the collected entropy
* catch exceptions in main(), handle them gracefully
* rm duplicate do_sha() code, consolidate in Util
* make reseed() public so that it can be called from outside
* rm reseed() from do_crypto() where it has no place
* 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
commit a64b52e5a4e71785598322991688f8720e0f1693
Author: surtur <a_mirre@utb.cz>
Date: Sun Nov 21 23:39:30 2021 +0100
finalise generator
this commit adds a (nearly) complete implementation of the generator.
* wrap calls to generator in a fortuna class method random_data
* calls generator's method generate_random_data, that internally calls
generate_blocks
* use a proper 256bit key in G_state
* add reseed method implementation
* call a reseed in initialize_generator
* do_sha returns proper digest now
* add proper do_crypto implementation
* call generate_blocks internally
* handle re-keying
* optimise header includes
TODO: there are still many commented (enabled on demand) debugging statements
-> TO BE REMOVED