From a3251a7c8b539dc19c21dfcb3245411962d75533 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 24 Jan 2022 03:52:42 +0100 Subject: [PATCH] fix(pool): properly encode full event --- pool.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pool.cpp b/pool.cpp index 388f4bd..be643cb 100644 --- a/pool.cpp +++ b/pool.cpp @@ -4,6 +4,7 @@ #include "pool.h" #include +#include #include #include @@ -67,20 +68,30 @@ auto Pool::add_entropy(const unsigned int& source, if (all_ok) { try { - // FIXME: check for overflow - std::string size bounding? - event_str.assign(event.begin(), event.end()); - - // FIXME: check size for overflow - // also, atm this counts event size but actually what gets appended - // are digests of 64 characters (hex-encoded 32 bytes) - size += event_size; - + const std::string strsource{std::to_string(source)}; { - const std::string digest(fortuna::Util::do_sha(event)); + // FIXME: check for overflow - std::string size bounding? + // event_str.assign(event.begin(), event.end()); - fmt::print("\t[i] add_entropy(digest): {}\n", digest); + // as per Cryptography Engineering, p. 148 (180/385) + std::vector fullevent{static_cast(source)}; + fullevent.push_back(static_cast(event_size)); + fullevent.insert( + std::end(fullevent), std::begin(event), std::end(event)); + fmt::print("\t[i] add_entropy(fullevent): {}\n", fullevent); - append_s(digest); + // FIXME: check size for overflow + // also, atm this counts event size but actually what gets + // appended are digests of 64 characters (hex-encoded 32 bytes) + size += event_size; + + { + const std::string digest(fortuna::Util::do_sha(fullevent)); + + fmt::print("\t[i] add_entropy(digest): {}\n", digest); + + append_s(digest); + } } fmt::print("\t[i] s.length() (simple char count): {}\n"