Gcryptlib: new brace style, and moved to Leonetienne namespace
This commit is contained in:
parent
c551f5fa64
commit
acf9dea387
@ -4,7 +4,7 @@
|
|||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
#include <InitializationVector.h>
|
#include <InitializationVector.h>
|
||||||
|
|
||||||
using namespace GhettoCipher;
|
using namespace Leonetienne::GCrypt;
|
||||||
|
|
||||||
void ExampleString() {
|
void ExampleString() {
|
||||||
std::cout << "Example on how to encrypt & decrypt a string:" << std::endl;
|
std::cout << "Example on how to encrypt & decrypt a string:" << std::endl;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "SecureBitset.h"
|
#include "SecureBitset.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
typedef SecureBitset<BLOCK_SIZE> Block;
|
typedef SecureBitset<BLOCK_SIZE> Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Feistel.h"
|
#include "Feistel.h"
|
||||||
#include "Flexblock.h"
|
#include "Flexblock.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
/** Class to apply a block cipher to messages of arbitrary length in a distributed manner
|
/** Class to apply a block cipher to messages of arbitrary length in a distributed manner
|
||||||
*/
|
*/
|
||||||
class Cipher {
|
class Cipher {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
// MUST BE A POWER OF 2 > 4
|
// MUST BE A POWER OF 2 > 4
|
||||||
constexpr std::size_t BLOCK_SIZE = 512;
|
constexpr std::size_t BLOCK_SIZE = 512;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "Halfblock.h"
|
#include "Halfblock.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
/** Class to perform a feistel block chipher
|
/** Class to perform a feistel block chipher
|
||||||
*/
|
*/
|
||||||
class Feistel {
|
class Feistel {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
//! A "bitset" of variable length
|
//! A "bitset" of variable length
|
||||||
typedef std::string Flexblock;
|
typedef std::string Flexblock;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
/** This class is a wrapper to make working with the GhettoCipher
|
/** This class is a wrapper to make working with the GhettoCipher
|
||||||
* super easy with a python-like syntax
|
* super easy with a python-like syntax
|
||||||
*/
|
*/
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2);
|
constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2);
|
||||||
typedef SecureBitset<HALFBLOCK_SIZE> Halfblock;
|
typedef SecureBitset<HALFBLOCK_SIZE> Halfblock;
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
/** Will create a sudo-random Block based on a seed
|
/** Will create a sudo-random Block based on a seed
|
||||||
*/
|
*/
|
||||||
class InitializationVector {
|
class InitializationVector {
|
||||||
public:
|
public:
|
||||||
InitializationVector(const GhettoCipher::Block& seed);
|
InitializationVector(const Block& seed);
|
||||||
|
|
||||||
operator GhettoCipher::Block() const;
|
operator Block() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GhettoCipher::Block iv;
|
Block iv;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
typedef std::array<Block, N_ROUNDS> Keyset;
|
typedef std::array<Block, N_ROUNDS> Keyset;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
/** Wrapper for std::bitset<T> that zeroes memory upon deletion.
|
/** Wrapper for std::bitset<T> that zeroes memory upon deletion.
|
||||||
* This does not include ALL methods, but the ones needed.
|
* This does not include ALL methods, but the ones needed.
|
||||||
*
|
*
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "Cipher.h"
|
#include "Cipher.h"
|
||||||
#include "InitializationVector.h"
|
#include "InitializationVector.h"
|
||||||
|
|
||||||
namespace GhettoCipher {
|
namespace Leonetienne::GCrypt {
|
||||||
//! Mod-operator that works with negative values
|
//! Mod-operator that works with negative values
|
||||||
inline int Mod(const int numerator, const int denominator) {
|
inline int Mod(const int numerator, const int denominator) {
|
||||||
return (denominator + (numerator % denominator)) % denominator;
|
return (denominator + (numerator % denominator)) % denominator;
|
||||||
|
@ -4,43 +4,45 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "InitializationVector.h"
|
#include "InitializationVector.h"
|
||||||
|
|
||||||
GhettoCipher::Cipher::Cipher(const Block& key)
|
namespace Leonetienne::GCrypt {
|
||||||
|
|
||||||
|
Cipher::Cipher(const Block& key)
|
||||||
:
|
:
|
||||||
key { key },
|
key { key },
|
||||||
initializationVector(InitializationVector(key)) {
|
initializationVector(InitializationVector(key)) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Cipher::Cipher(const std::string& password)
|
Cipher::Cipher(const std::string& password)
|
||||||
:
|
:
|
||||||
key { PasswordToKey(password) },
|
key { PasswordToKey(password) },
|
||||||
initializationVector(InitializationVector(key)) {
|
initializationVector(InitializationVector(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Cipher::~Cipher() {
|
Cipher::~Cipher() {
|
||||||
// Clear key memory
|
// Clear key memory
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GhettoCipher::Cipher::SetKey(const Block& key) {
|
void Cipher::SetKey(const Block& key) {
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
this->key = key;
|
this->key = key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GhettoCipher::Cipher::SetPassword(const std::string& password) {
|
void Cipher::SetPassword(const std::string& password) {
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
key = PasswordToKey(password);
|
key = PasswordToKey(password);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Flexblock GhettoCipher::Cipher::Encipher(const Flexblock& data, bool printProgress) const {
|
Flexblock Cipher::Encipher(const Flexblock& data, bool printProgress) const {
|
||||||
// Split cleartext into blocks
|
// Split cleartext into blocks
|
||||||
std::vector<Block> blocks;
|
std::vector<Block> blocks;
|
||||||
|
|
||||||
@ -71,9 +73,9 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Encipher(const Flexblock& data, bo
|
|||||||
|
|
||||||
// Return it
|
// Return it
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bool printProgress) const {
|
Flexblock Cipher::Decipher(const Flexblock& data, bool printProgress) const {
|
||||||
// Split ciphertext into blocks
|
// Split ciphertext into blocks
|
||||||
std::vector<Block> blocks;
|
std::vector<Block> blocks;
|
||||||
|
|
||||||
@ -110,22 +112,24 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo
|
|||||||
|
|
||||||
// Return it
|
// Return it
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// These pragmas only work for MSVC and g++, as far as i know. Beware!!!
|
// These pragmas only work for MSVC and g++, as far as i know. Beware!!!
|
||||||
#if defined _WIN32 || defined _WIN64
|
#if defined _WIN32 || defined _WIN64
|
||||||
#pragma optimize("", off )
|
#pragma optimize("", off )
|
||||||
#elif defined __GNUG__
|
#elif defined __GNUG__
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize ("O0")
|
#pragma GCC optimize ("O0")
|
||||||
#endif
|
#endif
|
||||||
void GhettoCipher::Cipher::ZeroKeyMemory() {
|
void Cipher::ZeroKeyMemory() {
|
||||||
key.reset();
|
key.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if defined _WIN32 || defined _WIN64
|
#if defined _WIN32 || defined _WIN64
|
||||||
#pragma optimize("", on )
|
#pragma optimize("", on )
|
||||||
#elif defined __GNUG__
|
#elif defined __GNUG__
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,34 +3,36 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
GhettoCipher::Feistel::Feistel(const Block& key) {
|
namespace Leonetienne::GCrypt {
|
||||||
|
|
||||||
|
Feistel::Feistel(const Block& key) {
|
||||||
SetKey(key);
|
SetKey(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Feistel::~Feistel() {
|
Feistel::~Feistel() {
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GhettoCipher::Feistel::SetKey(const Block& key) {
|
void Feistel::SetKey(const Block& key) {
|
||||||
GenerateRoundKeys(key);
|
GenerateRoundKeys(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Block GhettoCipher::Feistel::Encipher(const Block& data) {
|
Block Feistel::Encipher(const Block& data) {
|
||||||
return Run(data, false);
|
return Run(data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Block GhettoCipher::Feistel::Decipher(const Block& data) {
|
Block Feistel::Decipher(const Block& data) {
|
||||||
return Run(data, true);
|
return Run(data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Block GhettoCipher::Feistel::Run(const Block& data, bool reverseKeys) {
|
Block Feistel::Run(const Block& data, bool reverseKeys) {
|
||||||
const auto splitData = FeistelSplit(data);
|
const auto splitData = FeistelSplit(data);
|
||||||
GhettoCipher::Halfblock l = splitData.first;
|
Halfblock l = splitData.first;
|
||||||
GhettoCipher::Halfblock r = splitData.second;
|
Halfblock r = splitData.second;
|
||||||
|
|
||||||
Halfblock tmp;
|
Halfblock tmp;
|
||||||
|
|
||||||
@ -55,9 +57,9 @@ GhettoCipher::Block GhettoCipher::Feistel::Run(const Block& data, bool reverseKe
|
|||||||
GenerateRoundKeys((Block)roundKeys.back());
|
GenerateRoundKeys((Block)roundKeys.back());
|
||||||
|
|
||||||
return FeistelCombine(r, l);
|
return FeistelCombine(r, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Halfblock GhettoCipher::Feistel::F(Halfblock m, const Block& key) {
|
Halfblock Feistel::F(Halfblock m, const Block& key) {
|
||||||
// Made-up F function
|
// Made-up F function
|
||||||
|
|
||||||
// Expand to full bitwidth
|
// Expand to full bitwidth
|
||||||
@ -81,22 +83,22 @@ GhettoCipher::Halfblock GhettoCipher::Feistel::F(Halfblock m, const Block& key)
|
|||||||
|
|
||||||
// Return the compressed version
|
// Return the compressed version
|
||||||
return CompressionFunction(m_expanded);
|
return CompressionFunction(m_expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<GhettoCipher::Halfblock, GhettoCipher::Halfblock> GhettoCipher::Feistel::FeistelSplit(const Block& block) {
|
std::pair<Halfblock, Halfblock> Feistel::FeistelSplit(const Block& block) {
|
||||||
const std::string bits = block.to_string();
|
const std::string bits = block.to_string();
|
||||||
|
|
||||||
Halfblock l(bits.substr(0, bits.size() / 2));
|
Halfblock l(bits.substr(0, bits.size() / 2));
|
||||||
Halfblock r(bits.substr(bits.size() / 2));
|
Halfblock r(bits.substr(bits.size() / 2));
|
||||||
|
|
||||||
return std::make_pair(l, r);
|
return std::make_pair(l, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Block GhettoCipher::Feistel::FeistelCombine(const Halfblock& l, const Halfblock& r) {
|
Block Feistel::FeistelCombine(const Halfblock& l, const Halfblock& r) {
|
||||||
return Block(l.to_string() + r.to_string());
|
return Block(l.to_string() + r.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Block GhettoCipher::Feistel::ExpansionFunction(const Halfblock& block) {
|
Block Feistel::ExpansionFunction(const Halfblock& block) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
const std::string bits = block.to_string();
|
const std::string bits = block.to_string();
|
||||||
|
|
||||||
@ -113,9 +115,9 @@ GhettoCipher::Block GhettoCipher::Feistel::ExpansionFunction(const Halfblock& bl
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Block(ss.str());
|
return Block(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Halfblock GhettoCipher::Feistel::CompressionFunction(const Block& block) {
|
Halfblock Feistel::CompressionFunction(const Block& block) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
const std::string bits = block.to_string();
|
const std::string bits = block.to_string();
|
||||||
|
|
||||||
@ -144,9 +146,9 @@ GhettoCipher::Halfblock GhettoCipher::Feistel::CompressionFunction(const Block&
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Halfblock(ss.str());
|
return Halfblock(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GhettoCipher::Feistel::SBox(const std::string& in) {
|
std::string Feistel::SBox(const std::string& in) {
|
||||||
static std::unordered_map<std::string, std::string> subMap;
|
static std::unordered_map<std::string, std::string> subMap;
|
||||||
static bool mapInitialized = false;
|
static bool mapInitialized = false;
|
||||||
if (!mapInitialized) {
|
if (!mapInitialized) {
|
||||||
@ -170,9 +172,9 @@ std::string GhettoCipher::Feistel::SBox(const std::string& in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return subMap[in];
|
return subMap[in];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey) {
|
void Feistel::GenerateRoundKeys(const Block& seedKey) {
|
||||||
// Clear initial key memory
|
// Clear initial key memory
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
roundKeys = Keyset();
|
roundKeys = Keyset();
|
||||||
@ -236,25 +238,27 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These pragmas only work for MSVC and g++, as far as i know. Beware!!!
|
// These pragmas only work for MSVC and g++, as far as i know. Beware!!!
|
||||||
#if defined _WIN32 || defined _WIN64
|
#if defined _WIN32 || defined _WIN64
|
||||||
#pragma optimize("", off )
|
#pragma optimize("", off )
|
||||||
#elif defined __GNUG__
|
#elif defined __GNUG__
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize ("O0")
|
#pragma GCC optimize ("O0")
|
||||||
#endif
|
#endif
|
||||||
void GhettoCipher::Feistel::ZeroKeyMemory() {
|
void Feistel::ZeroKeyMemory() {
|
||||||
for (Block& key : roundKeys) {
|
for (Block& key : roundKeys) {
|
||||||
key.reset();
|
key.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if defined _WIN32 || defined _WIN64
|
#if defined _WIN32 || defined _WIN64
|
||||||
#pragma optimize("", on )
|
#pragma optimize("", on )
|
||||||
#elif defined __GNUG__
|
#elif defined __GNUG__
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
#include "Cipher.h"
|
#include "Cipher.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
std::string GhettoCipher::GhettoCryptWrapper::EncryptString(const std::string& cleartext, const std::string& password) {
|
namespace Leonetienne::GCrypt {
|
||||||
|
|
||||||
|
std::string GhettoCryptWrapper::EncryptString(const std::string& cleartext, const std::string& password) {
|
||||||
// Instanciate our cipher and supply a key
|
// Instanciate our cipher and supply a key
|
||||||
const Block key = PasswordToKey(password);
|
const Block key = PasswordToKey(password);
|
||||||
Cipher cipher(key);
|
Cipher cipher(key);
|
||||||
@ -18,9 +20,9 @@ std::string GhettoCipher::GhettoCryptWrapper::EncryptString(const std::string& c
|
|||||||
|
|
||||||
// Return it
|
// Return it
|
||||||
return ciphertext;
|
return ciphertext;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GhettoCipher::GhettoCryptWrapper::DecryptString(const std::string& ciphertext, const std::string& password) {
|
std::string GhettoCryptWrapper::DecryptString(const std::string& ciphertext, const std::string& password) {
|
||||||
// Instanciate our cipher and supply a key
|
// Instanciate our cipher and supply a key
|
||||||
const Block key = PasswordToKey(password);
|
const Block key = PasswordToKey(password);
|
||||||
Cipher cipher(key);
|
Cipher cipher(key);
|
||||||
@ -36,9 +38,9 @@ std::string GhettoCipher::GhettoCryptWrapper::DecryptString(const std::string& c
|
|||||||
|
|
||||||
// Return it
|
// Return it
|
||||||
return cleartext;
|
return cleartext;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GhettoCipher::GhettoCryptWrapper::EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
|
bool GhettoCryptWrapper::EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
|
||||||
try {
|
try {
|
||||||
// Read the file to bits
|
// Read the file to bits
|
||||||
const Flexblock cleartext_bits = ReadFileToBits(filename_in);
|
const Flexblock cleartext_bits = ReadFileToBits(filename_in);
|
||||||
@ -58,9 +60,9 @@ bool GhettoCipher::GhettoCryptWrapper::EncryptFile(const std::string& filename_i
|
|||||||
catch (std::runtime_error&) {
|
catch (std::runtime_error&) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GhettoCipher::GhettoCryptWrapper::DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
|
bool GhettoCryptWrapper::DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport) {
|
||||||
try {
|
try {
|
||||||
// Read the file to bits
|
// Read the file to bits
|
||||||
const Flexblock ciphertext_bits = ReadFileToBits(filename_in);
|
const Flexblock ciphertext_bits = ReadFileToBits(filename_in);
|
||||||
@ -80,5 +82,7 @@ bool GhettoCipher::GhettoCryptWrapper::DecryptFile(const std::string& filename_i
|
|||||||
catch (std::runtime_error&) {
|
catch (std::runtime_error&) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
#include "InitializationVector.h"
|
#include "InitializationVector.h"
|
||||||
#include "Feistel.h"
|
#include "Feistel.h"
|
||||||
|
|
||||||
GhettoCipher::InitializationVector::InitializationVector(const Block& seed) {
|
namespace Leonetienne::GCrypt {
|
||||||
|
|
||||||
|
InitializationVector::InitializationVector(const Block& seed) {
|
||||||
// We'll generate our initialization vector by encrypting our seed with itself as a key
|
// We'll generate our initialization vector by encrypting our seed with itself as a key
|
||||||
// iv = E(M=seed, K=seed)
|
// iv = E(M=seed, K=seed)
|
||||||
iv = Feistel(seed).Encipher(seed);
|
iv = Feistel(seed).Encipher(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::InitializationVector::operator GhettoCipher::Block() const {
|
InitializationVector::operator Block() const {
|
||||||
return iv;
|
return iv;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user