surtur
795b9ffe54
All checks were successful
continuous-integration/drone/push Build is passing
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)
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#ifndef FORTUNA_UTIL_H
|
|
#define FORTUNA_UTIL_H
|
|
|
|
#include <cryptopp/filters.h>
|
|
#include <cryptopp/hex.h>
|
|
#include <cryptopp/sha3.h>
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
|
|
namespace fortuna {
|
|
|
|
class Util final {
|
|
public:
|
|
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;
|
|
|
|
// 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))
|
|
);
|
|
|
|
return digest;
|
|
}
|
|
|
|
static auto current_time() -> std::chrono::time_point<std::chrono::system_clock,
|
|
std::chrono::duration<long, std::ratio<1, 1000000000>>> {
|
|
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;
|
|
}
|
|
|
|
Util() = delete;
|
|
~Util() noexcept;
|
|
|
|
}; // class Util
|
|
|
|
} // namespace fortuna
|
|
|
|
#endif//FORTUNA_UTIL_H
|