diff --git a/generator.cpp b/generator.cpp index 232144b..f599918 100644 --- a/generator.cpp +++ b/generator.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "generator.h" #ifndef FORTUNA_GENERATOR_CPP @@ -33,11 +32,11 @@ auto Generator::get_state() -> G_state { return G_state{}; } -auto Generator::reseed(G_state G, const string& s) -> G_state { +auto Generator::reseed(const string& s) -> void { + G_state G = get_state(); string to_be_hashed = std::to_string(G.k) + s; G.k = do_sha(stoul(to_be_hashed)); G.ctr++; - return G; } auto Generator::do_sha(int64_t key_with_seed) -> int64_t { @@ -55,17 +54,19 @@ auto Generator::do_crypto(int64_t k, unsigned __int128 ctr) -> string { return ""; } -auto Generator::generate_blocks(G_state G, int k_blocks) -> tuple { +auto Generator::generate_blocks(int k_blocks) -> string { + G_state G = get_state(); assert (G.ctr!=0); string r = ""; for (int i = 0; i < k_blocks; ++i) { r += do_crypto(G.k, G.ctr); G.ctr++; } - return {r, G}; + return r; } -auto Generator::generate_random_data(G_state G, uint n) -> tuple { +auto Generator::generate_random_data(uint n) -> string { + G_state G = get_state(); string r = ""; if (n < 0){ /* this should not be possible */ @@ -77,13 +78,13 @@ auto Generator::generate_random_data(G_state G, uint n) -> tuple(generate_blocks(G,ceil(n/16))); + string rr = generate_blocks(ceil(n/16)); r = rr.substr(0,n); /* re-key */ // TODO: check conversions - G.k = stoul(std::get<0>(generate_blocks(G, 2))); - return {r, G}; + G.k = stoul(generate_blocks(2)); + return r; }; diff --git a/generator.h b/generator.h index 6288ca2..72192b1 100644 --- a/generator.h +++ b/generator.h @@ -2,7 +2,6 @@ #define FORTUNA_GENERATOR_H #include -#include namespace fortuna { namespace generator { @@ -21,17 +20,16 @@ private: int64_t k; unsigned __int128 ctr; - auto reseed(Generator::G_state G, const string& s) -> Generator::G_state; + auto reseed(const string& s) -> void; auto do_sha(int64_t key_with_seed) -> int64_t; auto do_crypto(int64_t k, unsigned __int128 ctr) -> string; - /* TODO(me): lacking objects (no more!), we have to return both the state and the string */ - auto generate_blocks(Generator::G_state G, int k_blocks) -> tuple; + auto generate_blocks(int k_blocks) -> string; /* n is the number of random bytes to generate */ - auto generate_random_data(Generator::G_state G, uint n) -> tuple; + auto generate_random_data(uint n) -> string; }; // class generator