generator: rm bogus reseed+add lock guards
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9e6efc9d38
commit
158545f401
|
@ -4,10 +4,6 @@
|
|||
#include "generator.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <cryptopp/osrng.h>
|
||||
#include <cryptopp/hex.h>
|
||||
#include <cryptopp/filters.h>
|
||||
|
@ -15,6 +11,10 @@
|
|||
#include <cryptopp/ccm.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace fortuna {
|
||||
namespace generator {
|
||||
|
||||
|
@ -38,13 +38,6 @@ void Generator::initialize_generator(){
|
|||
fmt::print(stderr, "{}\n", e.what());
|
||||
exit(1);
|
||||
}
|
||||
try {
|
||||
// FIXME: hardcoded seed for the time being
|
||||
reseed("fortuna");
|
||||
} catch(CryptoPP::Exception& e) {
|
||||
fmt::print(stderr, "{}\n", e.what());
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
auto Generator::get_state() -> G_state {
|
||||
|
@ -60,9 +53,11 @@ auto Generator::reseed(const std::string& s) -> void {
|
|||
// fmt::print("concat \"da_key + s\" -> {}\n", to_be_hashed); // debugging
|
||||
|
||||
try {
|
||||
std::lock_guard<std::mutex> lg(mtx);
|
||||
std::string a{fortuna::Util::do_sha(da_key + s)};
|
||||
std::memmove(&G.k[0], &a[0], G.k.SizeInBytes());
|
||||
++G.ctr;
|
||||
fmt::print("[i] generator: reseeded\n");
|
||||
} catch(std::exception& e) {
|
||||
fmt::print("{}", e.what());
|
||||
}
|
||||
|
@ -153,6 +148,7 @@ auto Generator::generate_blocks(unsigned int k_blocks) -> std::string {
|
|||
}
|
||||
|
||||
auto Generator::generate_random_data(uint n) -> std::string {
|
||||
std::lock_guard<std::mutex> lg(mtx);
|
||||
// fmt::print("n -> {}\n", n); // debugging
|
||||
if (n == 0) {
|
||||
// do not do this..?
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <cryptopp/cryptlib.h>
|
||||
#include <cryptopp/secblock.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace fortuna {
|
||||
|
@ -12,6 +14,7 @@ namespace generator {
|
|||
class Generator {
|
||||
public:
|
||||
std::chrono::milliseconds reseed_interval{100};
|
||||
std::mutex mtx;
|
||||
|
||||
Generator(); // ad noexcept: perhaps _do_ throw*
|
||||
Generator(const Generator& Gen) = delete; // no
|
||||
|
@ -27,7 +30,6 @@ public:
|
|||
return !(this->G.ctr == 0x00);
|
||||
};
|
||||
|
||||
auto generator_service() -> int;
|
||||
|
||||
private:
|
||||
struct G_state {
|
||||
|
|
Reference in New Issue