a C++ take on Fortuna CSPRNG implementation, as devised by Niels Fergusson and Bruce Schneier in Practical Cryptography 🍀
Go to file
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
lib fmtlog: bump (manually) to v2.1.1 2022-01-11 04:47:34 +01:00
.clang-format clang-format: BinPack{Arguments,Parameters}: false 2022-01-13 06:04:18 +01:00
.clang-tidy chore(clang-tidy): unify flags 2021-12-10 18:57:25 +01:00
.drone.starlark ci: rm 'build on alpine' step 2022-01-10 05:02:44 +01:00
.editorconfig add .editorconfig [skip ci] 2022-01-10 08:55:07 +01:00
.gitattributes add .gitattributes file 2021-10-24 21:34:16 +02:00
.gitignore add proper SeedFileManager implementation 2022-01-09 11:58:38 +01:00
.gitmodules feat: use fmt instead of iostreams 2021-11-18 22:05:05 +01:00
.pre-commit-config.yaml pre-commit: add check-yaml,edit cppcheck hook 2022-01-06 22:12:50 +01:00
CMakeLists.txt cmake: add libs using target_include_directories 2022-01-17 00:28:52 +01:00
LICENSE initial commit 2021-10-24 21:29:49 +02:00
Makefile makefile: smarter clean target - prevent bad stuff 2022-01-13 06:28:45 +01:00
accumulator.cpp feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
accumulator.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
do_task.cpp refactor: clang-format 2022-01-10 04:25:03 +01:00
do_task.h refactor: clang-format 2022-01-10 04:25:03 +01:00
entropy_src.h entropy_src: add ctor,dtor, rm scheduler fun 2022-01-17 07:28:32 +01:00
event_adder.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
event_adder_impl.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
event_scheduler.h scheduler: add thread_sleep, use const& param 2022-01-17 04:42:59 +01:00
event_scheduler_impl.h scheduler: add thread_sleep, use const& param 2022-01-17 04:42:59 +01:00
fortuna.cpp feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
fortuna.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
generator.cpp generator: pass param by const& 2022-01-17 07:22:19 +01:00
generator.h generator: pass param by const& 2022-01-17 07:22:19 +01:00
main.cpp fortuna: add generator service 2022-01-03 07:49:53 +01:00
pool.cpp feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
pool.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
seed_file_management.cpp chore(sfm): uint -> unsigned int 2022-01-17 07:20:16 +01:00
seed_file_management.h SeedFileManager: initialize RUNNING with constinit 2022-01-13 06:18:43 +01:00
urandom_entropy_src.cpp feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
urandom_entropy_src.h feat: "prepare to add proper entropy source" nits 2022-01-17 08:27:24 +01:00
util.h Util: add do_sha() for {const,} std::vector<char>& 2022-01-17 04:52:55 +01:00