fix(pool): properly encode full event
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d401bb6c25
commit
a3251a7c8b
33
pool.cpp
33
pool.cpp
|
@ -4,6 +4,7 @@
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <fmt/ranges.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
@ -67,20 +68,30 @@ auto Pool::add_entropy(const unsigned int& source,
|
||||||
|
|
||||||
if (all_ok) {
|
if (all_ok) {
|
||||||
try {
|
try {
|
||||||
// FIXME: check for overflow - std::string size bounding?
|
const std::string strsource{std::to_string(source)};
|
||||||
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 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"
|
fmt::print("\t[i] s.length() (simple char count): {}\n"
|
||||||
|
|
Reference in New Issue