Implemented a key class

This commit is contained in:
Leonetienne
2022-05-22 13:43:23 +02:00
parent bb76cbb2d7
commit 9fdc642bd6
13 changed files with 100 additions and 95 deletions

View File

@@ -7,9 +7,8 @@
namespace Leonetienne::GCrypt {
GCipher::GCipher(const Block& key, const DIRECTION direction)
GCipher::GCipher(const Key& key, const DIRECTION direction)
:
key { key },
direction { direction },
lastBlock(InitializationVector(key)), // Initialize our lastBlock with some deterministic initial value, based on the key
feistel(key) {
@@ -17,22 +16,6 @@ namespace Leonetienne::GCrypt {
return;
}
GCipher::GCipher(const std::string& password, const DIRECTION direction)
:
key { PasswordToKey(password) },
direction { direction },
lastBlock(InitializationVector(key)), // Initialize our lastBlock with some deterministic initial value, based on the key feistel(key) {
feistel(key) {
return;
}
GCipher::~GCipher() {
// Clear key memory
ZeroKeyMemory();
return;
}
Block GCipher::Digest(const Block& input) {
switch (direction) {
@@ -67,23 +50,5 @@ namespace Leonetienne::GCrypt {
throw std::runtime_error("Unreachable branch reached.");
}
// These pragmas only work for MSVC and g++, as far as i know. Beware!!!
#if defined _WIN32 || defined _WIN64
#pragma optimize("", off )
#elif defined __GNUG__
#pragma GCC push_options
#pragma GCC optimize ("O0")
#endif
void GCipher::ZeroKeyMemory() {
key.reset();
return;
}
#if defined _WIN32 || defined _WIN64
#pragma optimize("", on )
#elif defined __GNUG__
#pragma GCC pop_options
#endif
}