fix(pool): properly encode full event
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-24 03:52:42 +01:00
parent d401bb6c25
commit a3251a7c8b
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -4,6 +4,7 @@
#include "pool.h"
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <atomic>
#include <climits>
@ -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<char> fullevent{static_cast<char>(source)};
fullevent.push_back(static_cast<char>(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"