generator: add ctr_inc() fun
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-27 22:54:53 +01:00
parent 715523eb1a
commit 1a02256b2b
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <fmt/core.h>
#include <algorithm>
#include <atomic>
#include <cassert>
#include <chrono>
#include <cmath>
@ -216,6 +217,22 @@ auto Generator::generate_random_data(const unsigned int& n) -> std::string {
return r;
}
auto Generator::ctr_inc() -> void {
// increment the least-significant-byte-first ctr
std::atomic<uint8_t> i{0};
while (true) {
this->G.counter.at(i) = static_cast<std::byte>(
static_cast<uint8_t>(this->G.counter.at(i)) + 0x01);
if (this->G.counter.at(i) == static_cast<std::byte>(0x00) &&
++i < this->G.counter.size()) {
continue;
}
break;
}
}
} // namespace generator
} // namespace fortuna

View File

@ -66,6 +66,8 @@ private:
auto generate_blocks(unsigned int k_blocks) -> std::string;
auto ctr_inc() -> void;
protected:
auto get_state() const -> Generator::G_state;