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,21 +68,31 @@ auto Pool::add_entropy(const unsigned int& source,
if (all_ok) {
try {
const std::string strsource{std::to_string(source)};
{
// FIXME: check for overflow - std::string size bounding?
event_str.assign(event.begin(), event.end());
// event_str.assign(event.begin(), event.end());
// 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);
// 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)
// 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(event));
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"
"\t[i] get_s_byte_count() (byte count): {}\n"