From 4b216a6f6ec0f1cd9a4b7788b297a38860a44340 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 10 Jan 2022 04:25:03 +0100 Subject: [PATCH] refactor: clang-format --- accumulator.cpp | 6 ++-- do_task.cpp | 6 ++-- do_task.h | 5 ++-- entropy_src.h | 9 ++++-- event_adder.h | 6 ++-- event_adder_impl.h | 10 +++---- event_scheduler.h | 6 ++-- fortuna.cpp | 50 ++++++++++++++++---------------- fortuna.h | 15 ++++++---- generator.cpp | 62 ++++++++++++++++++++++------------------ generator.h | 12 ++++---- pool.h | 26 ++++++++++------- seed_file_management.cpp | 38 +++++++++++++++--------- seed_file_management.h | 6 ++-- urandom_entropy_src.h | 19 ++++++------ util.h | 51 +++++++++++++++++---------------- 16 files changed, 182 insertions(+), 145 deletions(-) diff --git a/accumulator.cpp b/accumulator.cpp index 830e877..6f52bdf 100644 --- a/accumulator.cpp +++ b/accumulator.cpp @@ -17,7 +17,7 @@ Accumulator::Accumulator() noexcept { } Accumulator::~Accumulator() noexcept {}; -} //namespace accumulator -} //namespace fortuna +} // namespace accumulator +} // namespace fortuna -#endif//FORTUNA_ACCUMULATOR_CPP +#endif // FORTUNA_ACCUMULATOR_CPP diff --git a/do_task.cpp b/do_task.cpp index 067e36e..3993698 100644 --- a/do_task.cpp +++ b/do_task.cpp @@ -13,7 +13,7 @@ auto DoTask::die_pls() -> void { } auto DoTask::thread_pls(const std::chrono::seconds& interval, - std::function callback) -> void { + std::function callback) -> void { if (th.joinable()) { die_pls(); @@ -33,6 +33,6 @@ DoTask::~DoTask() noexcept { } } -} //namespace fortuna +} // namespace fortuna -#endif//FORTUNA_DO_TASK_CPP +#endif // FORTUNA_DO_TASK_CPP diff --git a/do_task.h b/do_task.h index e26698d..94a29a5 100644 --- a/do_task.h +++ b/do_task.h @@ -12,16 +12,17 @@ class DoTask { private: std::timed_mutex do_sleep; std::thread th; + public: DoTask() noexcept = default; ~DoTask() noexcept; auto thread_pls(const std::chrono::seconds& interval, - std::function callback) -> void; + std::function callback) -> void; auto die_pls() -> void; }; // class DoTask } // namespace fortuna -#endif//FORTUNA_DO_TASK_H +#endif // FORTUNA_DO_TASK_H diff --git a/entropy_src.h b/entropy_src.h index 24c3f06..b1f35cf 100644 --- a/entropy_src.h +++ b/entropy_src.h @@ -8,6 +8,9 @@ namespace fortuna { namespace accumulator { class EntropySrc { +private: + std::unique_ptr impl; + public: virtual void schedule(accumulator::EventScheduler scheduler) = 0; virtual void event(accumulator::EventAdderImpl adder) = 0; @@ -19,6 +22,6 @@ public: ~EntropySrc() noexcept; }; -} //namespace accumulator -} //namespace fortuna -#endif//FORTUNA_ENTROPY_SRC_H +} // namespace accumulator +} // namespace fortuna +#endif // FORTUNA_ENTROPY_SRC_H diff --git a/event_adder.h b/event_adder.h index bf79559..b90fbd3 100644 --- a/event_adder.h +++ b/event_adder.h @@ -11,6 +11,6 @@ public: virtual void add(std::vector e) = 0; }; -} //namespace accumulator -} //namespace fortuna -#endif//FORTUNA_EVENT_ADDER_H +} // namespace accumulator +} // namespace fortuna +#endif // FORTUNA_EVENT_ADDER_H diff --git a/event_adder_impl.h b/event_adder_impl.h index 0168493..51266ff 100644 --- a/event_adder_impl.h +++ b/event_adder_impl.h @@ -15,7 +15,8 @@ private: static accumulator::Pool pools[p_size]; public: - EventAdderImpl(const unsigned int source_id, const accumulator::Pool pools[32]) { + EventAdderImpl(const unsigned int source_id, + const accumulator::Pool pools[32]) { this->source_id = source_id; for (unsigned int i = 0; i < this->p_size; i++) { this->pools[i] = pools[i]; @@ -27,9 +28,8 @@ public: this->pool = (this->pool + 1) % p_size; pools[this->pool].add_entropy(source_id, event); } - }; -} //namespace accumulator -} //namespace fortuna -#endif//FORTUNA_EVENT_ADDER_IMPL_H +} // namespace accumulator +} // namespace fortuna +#endif // FORTUNA_EVENT_ADDER_IMPL_H diff --git a/event_scheduler.h b/event_scheduler.h index 35a8743..792a6c6 100644 --- a/event_scheduler.h +++ b/event_scheduler.h @@ -15,8 +15,8 @@ public: ~EventScheduler() noexcept; }; -} //namespace accumulator -} //namespace fortuna +} // namespace accumulator +} // namespace fortuna -#endif//FORTUNA_EVENT_SCHEDULER_H +#endif // FORTUNA_EVENT_SCHEDULER_H diff --git a/fortuna.cpp b/fortuna.cpp index 60d39b5..b8652c0 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -20,7 +20,8 @@ auto now{std::chrono::steady_clock::now()}; Fortuna::Fortuna() { try { initialize_prng(); - } catch(CryptoPP::Exception& e) { + } + catch (CryptoPP::Exception& e) { fmt::print(stderr, "{}\n", e.what()); } th_gen = std::thread(generator_service, &R.Gen); @@ -35,12 +36,9 @@ Fortuna::~Fortuna() noexcept { auto Fortuna::random_data(unsigned int n_bytes) -> void { const auto start{std::chrono::system_clock::now()}; fmt::print("random_data starting - {}\n", start); - auto elapsed { - std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch() - - now.time_since_epoch() - ) - }; + auto elapsed{std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch() - + now.time_since_epoch())}; fmt::print("last_reseed: {} ago\n", elapsed); now = std::chrono::steady_clock::now(); std::string s; @@ -48,13 +46,15 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void { // {generator,accumulator,fortuna} service threads -> in member functions const int pools_to_use{ffsll(static_cast(get_reseed_ctr()))}; - if (R.pools[0].get_s_length() >= min_pool_size && elapsed > R.Gen.reseed_interval) { + if (R.pools[0].get_s_length() >= min_pool_size && + elapsed > R.Gen.reseed_interval) { for (int i = 0; i < static_cast(pools_to_use); ++i) { - if (R.reseed_ctr % static_cast(pow(2,i)) == 0) { + if (R.reseed_ctr % static_cast(pow(2, i)) == 0) { try { s.append(fortuna::Util::do_sha(R.pools[i].get_s())); R.pools[i].clear_pool(); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}\n", e.what()); } } @@ -68,18 +68,19 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void { if (R.reseed_ctr == 0) { fmt::print("reseed ctr is 0, PRNG not seeded!\n"); throw std::runtime_error("illegal state, PRNG not seeded"); - } else { + } + else { std::string n{R.Gen.generate_random_data(n_bytes)}; fmt::print("got you {} proper bytes from generate_random_data -> {}\n", - n_bytes, n); + n_bytes, n); n.clear(); } const auto end{std::chrono::system_clock::now()}; - std::chrono::duration diff = end-start; + std::chrono::duration diff = end - start; fmt::print("random_data done - {}\n", end); fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12); -} //random_data +} // random_data auto Fortuna::generator_service(fortuna::generator::Generator* Gen) -> void { fmt::print("[i] fortuna: starting generator service\n"); @@ -87,14 +88,13 @@ auto Fortuna::generator_service(fortuna::generator::Generator* Gen) -> void { uint sleep_time{1000}; // in ms std::chrono::system_clock::time_point time_point; - while(true) { + while (true) { fmt::print("sleeping [{}]\n", i); ++i; time_point = fortuna::Util::current_time(); fmt::print("[*] g: @{}\n", time_point); - std::this_thread::sleep_until( - time_point + std::chrono::milliseconds(sleep_time) - ); + std::this_thread::sleep_until(time_point + + std::chrono::milliseconds(sleep_time)); } } @@ -106,24 +106,26 @@ auto Fortuna::seed_file_manager_service() -> void { auto right_now{fortuna::Util::current_time()}; SeedFileManager sfm(this->accumulator); - while(true) { + while (true) { right_now = fortuna::Util::current_time(); fmt::print("[*] sfm: checkup time @{}\n", right_now); - if (! sfm.is_job_running()) { + if (!sfm.is_job_running()) { fmt::print("[*] sfm: job not running, starting\n"); try { sfm.do_stuff(); - } catch (std::exception& e) { + } + catch (std::exception& e) { fmt::print(stderr, "[!] sfm: exception caught: {}\n", e.what()); } - } else { + } + else { fmt::print("[*] sfm: job running\n"); } std::this_thread::sleep_until(right_now + - std::chrono::seconds(checkup_interval)); + std::chrono::seconds(checkup_interval)); } } } // namespace fortuna -#endif//FORTUNA_FORTUNA_CPP +#endif // FORTUNA_FORTUNA_CPP diff --git a/fortuna.h b/fortuna.h index 8e7ee74..c005687 100644 --- a/fortuna.h +++ b/fortuna.h @@ -1,8 +1,8 @@ #ifndef FORTUNA_FORTUNA_H #define FORTUNA_FORTUNA_H -#include "generator.h" #include "accumulator.h" +#include "generator.h" #include @@ -52,7 +52,8 @@ public: incr_reseed_ctr(); fmt::print("first reseed\n"); R.Gen.reseed("fortuna"); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}\n", e.what()); } fmt::print("PRNG initialized\n"); @@ -64,9 +65,10 @@ public: // PRNG state class R_state { - friend fortuna::Fortuna; + friend fortuna::Fortuna; + public: - R_state(){} + R_state() {} ~R_state() = default; protected: @@ -76,7 +78,8 @@ public: } auto initialize_pools() -> void { - for (unsigned int i = accumulator::Accumulator::init_pool_num; i < num_of_pools; ++i) { + for (unsigned int i = accumulator::Accumulator::init_pool_num; + i < num_of_pools; ++i) { pools[i].initialize_pool(i); } } @@ -96,4 +99,4 @@ public: } // namespace fortuna -#endif//FORTUNA_FORTUNA_H +#endif // FORTUNA_FORTUNA_H diff --git a/generator.cpp b/generator.cpp index 8e6862f..857a202 100644 --- a/generator.cpp +++ b/generator.cpp @@ -4,14 +4,14 @@ #include "generator.h" #include "util.h" -#include -#include -#include #include +#include +#include +#include #include -#include #include +#include #include #include @@ -21,7 +21,8 @@ namespace generator { Generator::Generator() /*noexcept*/ { try { initialize_generator(); - } catch(CryptoPP::Exception& e) { + } + catch (CryptoPP::Exception& e) { fmt::print(stderr, "{}\n", e.what()); exit(1); } @@ -29,12 +30,13 @@ Generator::Generator() /*noexcept*/ { Generator::~Generator() noexcept {}; -void Generator::initialize_generator(){ +void Generator::initialize_generator() { try { std::memset(G.k, 0x00, G.k.size()); G.ctr = 0; fmt::print("Generator initialized\n"); - } catch(CryptoPP::Exception& e) { + } + catch (CryptoPP::Exception& e) { fmt::print(stderr, "{}\n", e.what()); exit(1); } @@ -48,7 +50,8 @@ auto Generator::time_to_reseed() const -> bool { // TODO(me): implement this if (true) { return true; - } else { + } + else { return false; } } @@ -57,14 +60,15 @@ auto Generator::reseed(const std::string& s) -> void { std::unique_lock ul(reseed_mtx); // ref: https://www.cryptopp.com/wiki/SecBlock std::string da_key(reinterpret_cast(&G.k[0]), - G.k.SizeInBytes() * 8); // we need the size in bits + G.k.SizeInBytes() * 8); // we need the size in bits try { std::string a{fortuna::Util::do_sha(da_key + s)}; std::memmove(G.k, a.c_str(), G.k_length); ++G.ctr; fmt::print("[i] generator: reseeded\n"); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}", e.what()); } } @@ -90,7 +94,7 @@ auto Generator::do_crypto() -> std::string { try { CryptoPP::CTR_Mode::Encryption e; - e.SetKeyWithIV(G.k,G.k.size(),ctr); + e.SetKeyWithIV(G.k, G.k.size(), ctr); ul.unlock(); // The StreamTransformationFilter adds padding as required. ECB and @@ -98,29 +102,30 @@ auto Generator::do_crypto() -> std::string { // mode not. // the "true" param - pump all of the data immediately to its // attached transformation - CryptoPP::StringSource str_src1(plain,true, - new CryptoPP::StreamTransformationFilter(e, - new CryptoPP::StringSink(cipher) - ) // StreamTransformationFilter + CryptoPP::StringSource str_src1( + plain, true, + new CryptoPP::StreamTransformationFilter( + e, + new CryptoPP::StringSink(cipher)) // StreamTransformationFilter ); // StringSource } - catch(CryptoPP::Exception& e) { + catch (CryptoPP::Exception& e) { fmt::print(stderr, "{}\n", e.what()); exit(1); } // Pretty print cipher text - CryptoPP::StringSource str_src2(cipher,true, + CryptoPP::StringSource str_src2( + cipher, true, new CryptoPP::HexEncoder( - new CryptoPP::StringSink(encoded_c) - ) // HexEncoder + new CryptoPP::StringSink(encoded_c)) // HexEncoder ); // StringSource return encoded_c; } auto Generator::generate_blocks(unsigned int k_blocks) -> std::string { - assert ((G.ctr!=0) && "Counter is not 0, generator has been seeded"); + assert((G.ctr != 0) && "Counter is not 0, generator has been seeded"); std::string r{""}; for (uint i = 0; i < k_blocks; ++i) { r += do_crypto(); @@ -150,17 +155,18 @@ auto Generator::generate_random_data(uint n) -> std::string { try { /* do magic to compute r - * r ← first-n-bytes(GenerateBlocks(G, ceil(n/16) )) */ + * r ← first-n-bytes(GenerateBlocks(G, ceil(n/16) )) */ // n is number of bytes, i.e. pass n*8 to get number of bits - unsigned int how_many(static_cast(ceil((n*8)/16))); + unsigned int how_many(static_cast(ceil((n * 8) / 16))); // fmt::print("how_many: {}\n", how_many); // debugging std::string rr{generate_blocks(how_many)}; fmt::print("rr (output from generate_blocks): {}\n", rr); // since we're truncating hex, we need to get twice more characters - r = rr.substr(0,n*0x02ul); + r = rr.substr(0, n * 0x02ul); rr.clear(); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}", e.what()); } @@ -172,22 +178,22 @@ auto Generator::generate_random_data(uint n) -> std::string { // FIXME: +1 for the actual null-termination, not exactly sure if needed dst.resize(G.k_length + 1); CryptoPP::StringSource str_s( - nu_G_k,true,new CryptoPP::HexDecoder(new CryptoPP::StringSink(dst)) - ); + nu_G_k, true, + new CryptoPP::HexDecoder(new CryptoPP::StringSink(dst))); nu_G_k.clear(); /* clear out the old key and set a new one */ std::memset(G.k, 0x00, G.k_length); std::memmove(G.k, dst.c_str(), G.k_length); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}", e.what()); } return r; } - } // namespace generator } // namespace fortuna #endif diff --git a/generator.h b/generator.h index 4cfada0..ae662cb 100644 --- a/generator.h +++ b/generator.h @@ -40,10 +40,10 @@ private: // 32*8 static constexpr const std::size_t k_length{32}; CryptoPP::FixedSizeSecBlock k; - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" unsigned __int128 ctr; - #pragma GCC diagnostic pop +#pragma GCC diagnostic pop }; G_state G; @@ -58,6 +58,6 @@ protected: }; // class generator -} //namespace generator -} //namespace fortuna -#endif//FORTUNA_GENERATOR_H +} // namespace generator +} // namespace fortuna +#endif // FORTUNA_GENERATOR_H diff --git a/pool.h b/pool.h index f625297..d587983 100644 --- a/pool.h +++ b/pool.h @@ -27,24 +27,28 @@ public: } // add entropy contained in a random event of 1 to 32 bytes - auto add_entropy(const uint source, const std::vector &event) -> int { + auto add_entropy(const uint source, const std::vector& event) -> int { std::string event_str; const size_t event_size{event.size()}; try { if (source > 255) { - throw std::invalid_argument("source number outside of interval <0,255>\n"); + throw std::invalid_argument( + "source number outside of interval <0,255>\n"); } if (event_size < 1 || event_size > 32) { - throw std::invalid_argument("the length of the event needs to be from the interval <1,32>\n"); + throw std::invalid_argument("the length of the event needs to " + "be from the interval <1,32>\n"); } - } catch(const std::exception& e) { + } + catch (const std::exception& e) { fmt::print("{}", e.what()); } try { event_str = std::string(event.begin(), event.end()); - } catch(const std::exception& e) { + } + catch (const std::exception& e) { fmt::print("{}", e.what()); } @@ -53,7 +57,8 @@ public: size += event_size; append_s(digest); digest.clear(); - } catch(const std::exception& e) { + } + catch (const std::exception& e) { fmt::print("{}", e.what()); } @@ -77,7 +82,8 @@ protected: auto append_s(const std::string& entropy_s) -> void { try { (this->s).append(std::string(entropy_s)); - } catch(const std::exception& e) { + } + catch (const std::exception& e) { fmt::print("{}", e.what()); } } @@ -89,7 +95,7 @@ private: }; // class Pool -} //namespace accumulator -} //namespace fortuna +} // namespace accumulator +} // namespace fortuna -#endif//FORTUNA_POOL_H +#endif // FORTUNA_POOL_H diff --git a/seed_file_management.cpp b/seed_file_management.cpp index f1ca7ca..08088eb 100644 --- a/seed_file_management.cpp +++ b/seed_file_management.cpp @@ -12,10 +12,13 @@ namespace fortuna { -SeedFileManager::SeedFileManager(const fortuna::accumulator::Accumulator& accumulator) noexcept { +SeedFileManager::SeedFileManager( + const fortuna::accumulator::Accumulator& accumulator) noexcept { this->accumulator = accumulator; } -SeedFileManager::~SeedFileManager() noexcept {set_job_running(false);}; +SeedFileManager::~SeedFileManager() noexcept { + set_job_running(false); +} auto SeedFileManager::is_job_running() -> bool { return running; @@ -27,7 +30,7 @@ auto SeedFileManager::set_job_running(bool running) -> void { auto SeedFileManager::do_stuff() -> void { update_seed_file(); - do_task.thread_pls(config.write_interval, [this]{write_seed_file();}); + do_task.thread_pls(config.write_interval, [this] { write_seed_file(); }); running = true; } @@ -43,35 +46,44 @@ auto SeedFileManager::update_seed_file() -> void { throw std::runtime_error("error opening seed file"); } - f_stream.read(reinterpret_cast(buff.BytePtr()), config.seed_f_length); - if (static_cast(f_stream.gcount()) != config.seed_f_length) { + f_stream.read(reinterpret_cast(buff.BytePtr()), + config.seed_f_length); + if (static_cast(f_stream.gcount()) != + config.seed_f_length) { std::string msg{"error reading seed from file"}; - fmt::print("{} {}, length: {}\n", msg, config.seed_f_path, config.seed_f_length); + fmt::print("{} {}, length: {}\n", msg, config.seed_f_path, + config.seed_f_length); throw std::runtime_error(msg); } } try { std::string str_buff(reinterpret_cast(&buff[0]), - buff.SizeInBytes() * 8); // we need the size in bits + buff.SizeInBytes() * + 8); // we need the size in bits accumulator.call_reseed(str_buff); write_seed_file(); - } catch(std::exception& e) { + } + catch (std::exception& e) { fmt::print("{}", e.what()); } } auto SeedFileManager::write_seed_file() -> void { - const std::size_t seed_file_length_blocks = fortuna::Util::b2b(config.seed_f_length); - CryptoPP::SecByteBlock buff{seed_file_length_blocks * fortuna::Util::gen_block_size}; + const std::size_t seed_file_length_blocks = + fortuna::Util::b2b(config.seed_f_length); + CryptoPP::SecByteBlock buff{seed_file_length_blocks * + fortuna::Util::gen_block_size}; std::string da_buff{accumulator.get_random_data(seed_file_length_blocks)}; fmt::print("[*] sfm: writing seed file\n"); - std::ofstream f_stream{config.seed_f_path, std::ios::binary|std::ios::trunc}; - f_stream.write(reinterpret_cast(buff.BytePtr()), config.seed_f_length); + std::ofstream f_stream{config.seed_f_path, + std::ios::binary | std::ios::trunc}; + f_stream.write(reinterpret_cast(buff.BytePtr()), + config.seed_f_length); } } // namespace fortuna -#endif//FORTUNA_SEED_FILE_MANAGER_CPP +#endif // FORTUNA_SEED_FILE_MANAGER_CPP diff --git a/seed_file_management.h b/seed_file_management.h index 894de5e..2421ee9 100644 --- a/seed_file_management.h +++ b/seed_file_management.h @@ -11,8 +11,7 @@ namespace fortuna { class SeedFileManager { public: - struct conf - { + struct conf { // std::chrono::minutes write_interval{10}; // 10 minutes (as the standard recommends) is a lot, go with 120s std::chrono::seconds write_interval{120}; @@ -25,7 +24,8 @@ public: auto is_job_running() -> bool; auto do_stuff() -> void; - SeedFileManager(const fortuna::accumulator::Accumulator& accumulator) noexcept; + SeedFileManager( + const fortuna::accumulator::Accumulator& accumulator) noexcept; ~SeedFileManager() noexcept; protected: diff --git a/urandom_entropy_src.h b/urandom_entropy_src.h index 9d63c8b..f2dbefb 100644 --- a/urandom_entropy_src.h +++ b/urandom_entropy_src.h @@ -19,19 +19,22 @@ public: auto event(accumulator::EventAdder adder) -> void { std::ifstream file; - file.exceptions ( std::ifstream::failbit | std::ifstream::badbit ); + file.exceptions(std::ifstream::failbit | std::ifstream::badbit); try { - std::ifstream urandom("/dev/urandom", std::ios::in|std::ios::binary); + std::ifstream urandom("/dev/urandom", + std::ios::in | std::ios::binary); // check if stream is open - if(urandom) { + if (urandom) { urandom.read(reinterpret_cast(&bytes), bytes.length()); urandom.close(); - } else { + } + else { // open failed fmt::print(stderr, "Failed to open /dev/urandom\n"); } - } catch(std::ifstream::failure& e) { + } + catch (std::ifstream::failure& e) { fmt::print("io exception caugth: {}\n", e.what()); } } @@ -42,7 +45,7 @@ private: static std::vector bytes[max_event_length]; }; -} //namespace accumulator -} //namespace fortuna -#endif//FORTUNA_URANDOM_ENTROPY_SRC_H +} // namespace accumulator +} // namespace fortuna +#endif // FORTUNA_URANDOM_ENTROPY_SRC_H diff --git a/util.h b/util.h index 3109c15..2923c91 100644 --- a/util.h +++ b/util.h @@ -1,50 +1,51 @@ #ifndef FORTUNA_UTIL_H #define FORTUNA_UTIL_H +#include #include #include #include -#include #include namespace fortuna { class Util final { public: -static constexpr const std::size_t gen_block_size{32}; // 256 bits + static constexpr const std::size_t gen_block_size{32}; // 256 bits -static auto do_sha(const std::string& str_to_hash) -> const std::string { - // do sha256 - std::string digest; + static auto do_sha(const std::string& str_to_hash) -> const std::string { + // do sha256 + std::string digest; - // no reason not to go for Keccak - CryptoPP::SHA3_256 sha3_256; + // no reason not to go for Keccak + CryptoPP::SHA3_256 sha3_256; - CryptoPP::StringSource str_src(str_to_hash, true, - new CryptoPP::HashFilter ( - sha3_256, new CryptoPP::HexEncoder( - new CryptoPP::StringSink(digest), false)) - ); + CryptoPP::StringSource str_src( + str_to_hash, true, + new CryptoPP::HashFilter( + sha3_256, new CryptoPP::HexEncoder( + new CryptoPP::StringSink(digest), false))); - return digest; -} + return digest; + } -static auto current_time() -> std::chrono::time_point std::chrono::time_point< + std::chrono::system_clock, std::chrono::duration>> { - return std::chrono::system_clock::now(); -} + return std::chrono::system_clock::now(); + } -// returns number of blocks for a given number of bytes -static constexpr std::size_t b2b(std::size_t bytes) noexcept { - // returns number of blocks - return bytes == 0 ? 0 : ((bytes - 1) / gen_block_size) + 1; -} + // returns number of blocks for a given number of bytes + static constexpr std::size_t b2b(std::size_t bytes) noexcept { + // returns number of blocks + return bytes == 0 ? 0 : ((bytes - 1) / gen_block_size) + 1; + } -Util() = delete; -~Util() noexcept; + Util() = delete; + ~Util() noexcept; }; // class Util } // namespace fortuna -#endif//FORTUNA_UTIL_H +#endif // FORTUNA_UTIL_H