From 1a02256b2bd283ec2a305bab4b97cc84ad519efa Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 27 Jan 2022 22:54:53 +0100 Subject: [PATCH] generator: add ctr_inc() fun --- generator.cpp | 17 +++++++++++++++++ generator.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/generator.cpp b/generator.cpp index 01c0e39..52ed7ac 100644 --- a/generator.cpp +++ b/generator.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -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 i{0}; + while (true) { + this->G.counter.at(i) = static_cast( + static_cast(this->G.counter.at(i)) + 0x01); + + if (this->G.counter.at(i) == static_cast(0x00) && + ++i < this->G.counter.size()) { + continue; + } + break; + } +} + } // namespace generator } // namespace fortuna diff --git a/generator.h b/generator.h index f4f8d2a..545f754 100644 --- a/generator.h +++ b/generator.h @@ -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;