generator: create permanent Serpent encryption obj
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-26 22:35:45 +01:00
parent 1517b150ed
commit c40806e68d
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 6 additions and 5 deletions

View File

@ -4,10 +4,9 @@
#include "generator.h"
#include "util.h"
#include <cryptopp/ccm.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/serpent.h>
#include <cryptopp/secblock.h>
#include <fmt/core.h>
#include <algorithm>
@ -104,8 +103,7 @@ auto Generator::do_crypto() -> std::string {
std::memmove(ctr, str_ctr.c_str(), ctr_length);
try {
CryptoPP::CTR_Mode<CryptoPP::Serpent>::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
}

View File

@ -2,7 +2,9 @@
#define FORTUNA_GENERATOR_H
#include <cryptopp/cryptlib.h>
#include <cryptopp/modes.h>
#include <cryptopp/secblock.h>
#include <cryptopp/serpent.h>
#include <chrono>
#include <cstdint>
@ -42,6 +44,7 @@ public:
private:
CryptoPP::CTR_Mode<CryptoPP::Serpent>::Encryption enc;
struct G_state {
// 32*8
static constexpr const std::size_t k_length{32};