diff --git a/fortuna.cpp b/fortuna.cpp index 24c3b21..60d8e0d 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -101,11 +101,8 @@ auto Fortuna::random_data(const uint64_t n_bytes) -> void { } else { const std::string n{R.Gen.generate_random_data(n_bytes)}; - fmt::print( - stderr, - "got you {} proper bytes from generate_random_data -> {}\n", - n_bytes, - n); + fmt::print("{}", n); // intentionally without a newline + fmt::print(stderr, "[i] fortuna: delivered {} bytes\n", n_bytes); } } catch (std::exception& e) { diff --git a/generator.cpp b/generator.cpp index 00f7054..41c0f97 100644 --- a/generator.cpp +++ b/generator.cpp @@ -96,7 +96,7 @@ auto Generator::do_crypto() -> std::string { // William Shakespeare, Romeo and Juliet const std::string plain{"Oh, I am fortune's fool!"}; - std::string cipher, encoded_c; + std::string cipher; std::unique_lock ul(crypt_mtx); CryptoPP::FixedSizeSecBlock ctr; std::memmove(ctr, G.ctr.data(), Generator::ctr_len); @@ -122,15 +122,9 @@ auto Generator::do_crypto() -> std::string { throw; } - // Pretty print cipher text - CryptoPP::StringSource str_src2( - cipher, - true, - new CryptoPP::HexEncoder( - new CryptoPP::StringSink(encoded_c)) // HexEncoder - ); // StringSource - - return encoded_c; + // just return the bytes, hex-encode can be done at a later point or by the + // final user/in console/perhaps not at all + return cipher; } auto Generator::generate_blocks(unsigned int k_blocks) -> std::string { @@ -177,10 +171,8 @@ auto Generator::generate_random_data(const uint64_t& n) -> std::string { static_cast(std::ceil(static_cast(n) / 16))); std::string rr{generate_blocks(how_many)}; - fmt::print(stderr, "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); // not hex-encoded anymore, just ask for n chars rr.clear(); } catch (std::exception& e) { @@ -190,14 +182,11 @@ auto Generator::generate_random_data(const uint64_t& n) -> std::string { /* re-key */ try { std::string nu_G_k{generate_blocks(2)}; - // fmt::print("nu_G_k: {}\n", nu_G_k); // debugging - std::string dst{fortuna::Util::de_hex(nu_G_k)}; - - 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); + std::memmove(G.k, nu_G_k.c_str(), G.k_length); + nu_G_k.clear(); } catch (std::exception& e) { fmt::print(stderr, "{}", e.what());