From c40806e68da62f0eebec3a526d891db85bf12646 Mon Sep 17 00:00:00 2001 From: surtur Date: Wed, 26 Jan 2022 22:35:45 +0100 Subject: [PATCH] generator: create permanent Serpent encryption obj --- generator.cpp | 8 +++----- generator.h | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/generator.cpp b/generator.cpp index ae6f07a..5f1770a 100644 --- a/generator.cpp +++ b/generator.cpp @@ -4,10 +4,9 @@ #include "generator.h" #include "util.h" -#include #include #include -#include +#include #include #include @@ -104,8 +103,7 @@ auto Generator::do_crypto() -> std::string { std::memmove(ctr, str_ctr.c_str(), ctr_length); try { - CryptoPP::CTR_Mode::Encryption e; - e.SetKeyWithIV(G.k, G.k.size(), ctr); + this->enc.SetKeyWithIV(G.k, G.k.size(), ctr); // The StreamTransformationFilter adds padding as required. ECB and // CBC Mode must be padded to the block size of the cipher. CTR @@ -116,7 +114,7 @@ auto Generator::do_crypto() -> std::string { plain, true, new CryptoPP::StreamTransformationFilter( - e, + this->enc, new CryptoPP::StringSink(cipher)) // StreamTransformationFilter ); // StringSource } diff --git a/generator.h b/generator.h index 7f8bd71..3952190 100644 --- a/generator.h +++ b/generator.h @@ -2,7 +2,9 @@ #define FORTUNA_GENERATOR_H #include +#include #include +#include #include #include @@ -42,6 +44,7 @@ public: private: + CryptoPP::CTR_Mode::Encryption enc; struct G_state { // 32*8 static constexpr const std::size_t k_length{32};