Commit Graph

61 Commits

Author SHA1 Message Date
surtur d236c73dee
fortuna: rethrow on error in ctor 2022-02-08 00:40:11 +01:00
surtur 1ec70d1161
fortuna,generator({fmt}) print with colours 2022-02-03 04:52:19 +01:00
surtur 2c215967cd
fortuna: correctly decrement in moar_random_data() 2022-02-03 03:14:55 +01:00
surtur c4dcab3046
generator: stop hex-encoding bytes in do_crypto()
in fortuna, print the random bytes as they come, without a newline, to
stdout. the idea is it can be directly piped to, say, dieharder, for,
e.g. testing purposes. also print info msg to stderr as is now customary
throughout the program.
2022-02-03 03:35:11 +01:00
surtur 3fe5c06c49
fortuna: add moar_random_data() fun 2022-02-03 02:10:06 +01:00
surtur 1da24b13da
{,generate_}random_data: use const uint64_t 2022-02-03 01:53:53 +01:00
surtur a3daa722da
chore: print info msgs to stderr 2022-02-03 00:37:20 +01:00
surtur a68166da57
fortuna: run svcs while(continue_running.load()) 2022-01-23 20:47:42 +01:00
surtur 5693b24ee0
fortuna: sleep only if sfm svc is running 2022-01-23 20:45:06 +01:00
surtur f48927738d
sfm: assert checkup_interval < seed_write_interval 2022-01-23 20:27:14 +01:00
surtur fa4c9d048e
fortuna: use die_point latch
wait on the latch in Fortuna's dtor until threads finish execution
2022-01-23 20:11:11 +01:00
surtur 680272bed4
fortuna: thread -> jthread; add die_point latch 2022-01-23 20:07:49 +01:00
surtur 580531acf2
chore: rm {accumulator,generator}_service, threads 2022-01-22 19:27:58 +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 4c77810535
chore(fortuna): lock print_mtx in {} scopes 2022-01-21 20:44:24 +01:00
surtur 3db8100089
chore(fortuna): rm dbg l_ctr 2022-01-21 19:51:54 +01:00
surtur 11931ff3b1
fortuna: fix accu thread joiner check in dtor 2022-01-21 16:03:26 +01:00
surtur b24cf7566a
fortuna: move whole ctor code into a try block 2022-01-21 06:31:46 +01:00
surtur c852c723fd
fortuna: update the init-latch logic 2022-01-21 06:27:06 +01:00
surtur 56d9631f84
fortuna: add mtx_{accu,p_pools}, locks 2022-01-20 08:14:40 +01:00
surtur 3b537e1e26
fortuna: add thread-synchronising latch 2022-01-20 08:08:11 +01:00
surtur 5b1c9ba71c
fortuna: make sleep_time vars constexpr 2022-01-20 08:00:16 +01:00
surtur 4c7e95e475
fortuna: add mtx_random_data 2022-01-20 07:55:21 +01:00
surtur a3f871a644
fortuna: move code into a try block 2022-01-20 06:06:07 +01:00
surtur 4f28612f3f
fortuna: add const and casts where appropriate 2022-01-20 05:58:36 +01:00
surtur 422eb6fd8d
fortuna(SFM service): assert '_p_pools' ptrs equal 2022-01-20 01:53:38 +01:00
surtur 7db896bcc0
Fortuna: add urandom_entropy_src_service() m. func
* 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
2022-01-17 09:35:17 +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 7fca4481c8
generator: implement time_to_reseed() fun 2022-01-15 13:35:56 +01:00
surtur c0933d355d
fortuna: improve mtx handling, introduce accu_mtx 2022-01-14 08:52:51 +01:00
surtur e0448d6d08
fortuna,generator: better printing 2022-01-14 05:20:52 +01:00
surtur 6a2362be37
fortuna: ++(informative value of print messages) 2022-01-13 06:50:37 +01:00
surtur a0df93c9ec
clang-format: BinPack{Arguments,Parameters}: false 2022-01-13 06:04:18 +01:00
surtur 8c3aee1b07
fortuna: use a proper shared_ptr to Generator 2022-01-13 03:02:31 +01:00
surtur 643e7aabf6
fortuna: add basic joinability check 2022-01-12 03:41:24 +01:00
surtur 3553968d52
fortuna: add accumulator service,thread 2022-01-10 07:57:11 +01:00
surtur 1817b4a82e
fortuna: add print mutex, impl with unique_lock
* 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
2022-01-10 07:43:55 +01:00
surtur 4b216a6f6e
refactor: clang-format 2022-01-10 04:25:03 +01:00
surtur 795b9ffe54
add proper SeedFileManager implementation
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)
2022-01-09 11:58:38 +01:00
surtur 6e62e47d7b
chore(fortuna): std::mutex -> std::unique_lock 2022-01-06 00:50:28 +01:00
surtur 3d65cde727
fortuna: properly reindent file 2022-01-04 06:57:36 +01:00
surtur 06db22bfa4
fortuna: add seed_file_manager_service() [wip] 2022-01-04 06:44:30 +01:00
surtur c6695f4be3
generator service: refactor var names,types 2022-01-03 08:53:54 +01:00
surtur 3e4fb10414
fortuna: add generator service 2022-01-03 07:49:53 +01:00
surtur b5601acfbd
refactor: non-semantic cleanup 2021-12-29 03:55:01 +01:00
surtur 7eaaef2fdb
fortuna: handle reseeds+clear pools for seed
* 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
2021-12-13 05:11:17 +01:00
surtur 65c476dbd6
add Util class + perform general refactor
* 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
2021-12-13 05:10:07 +01:00
surtur b55ca33e24
chore(fortuna): add random_data() checks, batch 1 2021-12-12 06:14:58 +01:00
surtur 2fbf5464a0
fortuna: erase -> clear 2021-12-11 01:20:34 +01:00
surtur 8b4cd4b6e8
fortuna(random_data): time-tracking precision++
using floats does wonders
2021-12-08 23:17:37 +01:00