Implemented digestion (feeding one block at a time)
This commit is contained in:
@@ -3,37 +3,42 @@
|
||||
#include "GCrypt/Flexblock.h"
|
||||
|
||||
namespace Leonetienne::GCrypt {
|
||||
/** Class to apply a block cipher to messages of arbitrary length in a distributed manner
|
||||
/** Class to apply a block/-stream cipher to messages of arbitrary length in a distributed manner
|
||||
*/
|
||||
class Cipher {
|
||||
public:
|
||||
explicit Cipher(const Block& key);
|
||||
explicit Cipher(const std::string& password);
|
||||
//! Describes the direction the cipher runs in
|
||||
enum class CIPHER_DIRECTION {
|
||||
ENCIPHER,
|
||||
DECIPHER
|
||||
};
|
||||
|
||||
//! Will initialize this cipher with a key
|
||||
explicit Cipher(const Block& key, const CIPHER_DIRECTION direction);
|
||||
|
||||
//! Will initialize this cipher with a key
|
||||
explicit Cipher(const std::string& password, const CIPHER_DIRECTION direction);
|
||||
|
||||
// Disable copying
|
||||
Cipher(const Cipher& other) = delete;
|
||||
Cipher(Cipher&& other) noexcept = delete;
|
||||
|
||||
~Cipher();
|
||||
|
||||
//! Will set the key
|
||||
void SetKey(const Block& key);
|
||||
|
||||
//! Will set the key from a password
|
||||
void SetPassword(const std::string& password);
|
||||
|
||||
//! Will encipher a flexblock of data
|
||||
Flexblock Encipher(const Flexblock& data, bool printProgress = false) const;
|
||||
|
||||
//! Will decipher a flexblock of data
|
||||
Flexblock Decipher(const Flexblock& data, bool printProgress = false) const;
|
||||
//! Will digest a data block, and return it
|
||||
Block Digest(const Block& input);
|
||||
|
||||
private:
|
||||
Block key;
|
||||
const CIPHER_DIRECTION direction;
|
||||
|
||||
//! The feistel instance to be used
|
||||
Feistel feistel;
|
||||
|
||||
//! The last block, required for CBC.
|
||||
Block lastBlock;
|
||||
|
||||
//! Will zero the memory used by the key
|
||||
void ZeroKeyMemory();
|
||||
|
||||
// Initial value for cipher block chaining
|
||||
Block initializationVector;
|
||||
};
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "GCrypt/Flexblock.h"
|
||||
#include "GCrypt/Block.h"
|
||||
#include "GCrypt/Cipher.h"
|
||||
|
||||
namespace Leonetienne::GCrypt {
|
||||
/** This class is a wrapper to make working with the GhettoCipher
|
||||
@@ -26,6 +29,10 @@ namespace Leonetienne::GCrypt {
|
||||
static bool DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport = false);
|
||||
|
||||
private:
|
||||
|
||||
//! Will digest a flexblock with a key
|
||||
static Flexblock DigestFlexblock(const Flexblock& data, const Block& key, const Cipher::CIPHER_DIRECTION direction);
|
||||
|
||||
// No instanciation! >:(
|
||||
GCryptWrapper();
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <bitset>
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
namespace Leonetienne::GCrypt {
|
||||
/** Wrapper for std::bitset<T> that zeroes memory upon deletion.
|
||||
@@ -32,7 +33,7 @@ namespace Leonetienne::GCrypt {
|
||||
SecureBitset<T>& operator^=(const SecureBitset<T>& other);
|
||||
SecureBitset<T> operator&(const SecureBitset<T>& other);
|
||||
SecureBitset<T> operator|(const SecureBitset<T>& other);
|
||||
SecureBitset<T> operator^(const SecureBitset<T>& other);
|
||||
SecureBitset<T> operator^(const SecureBitset<T>& other) const;
|
||||
SecureBitset<T> operator~() const;
|
||||
SecureBitset<T>& operator<<=(const std::size_t offset);
|
||||
SecureBitset<T>& operator>>=(const std::size_t offset);
|
||||
@@ -174,7 +175,7 @@ namespace Leonetienne::GCrypt {
|
||||
}
|
||||
|
||||
template<std::size_t T>
|
||||
inline SecureBitset<T> SecureBitset<T>::operator^(const SecureBitset<T>& other) {
|
||||
inline SecureBitset<T> SecureBitset<T>::operator^(const SecureBitset<T>& other) const {
|
||||
SecureBitset bs;
|
||||
bs.bitset = bitset ^ other.bitset;
|
||||
return bs;
|
||||
|
@@ -241,7 +241,7 @@ namespace Leonetienne::GCrypt {
|
||||
|
||||
// To provide confusion, xor the blocks together
|
||||
// To provide diffusion, hash fragment to fragment' first
|
||||
b ^= Block(Cipher(fragment).Encipher(fragment.to_string()));
|
||||
b ^= Block(Cipher(fragment, Cipher::CIPHER_DIRECTION::ENCIPHER).Digest(fragment).to_string());
|
||||
}
|
||||
|
||||
return b;
|
||||
@@ -258,7 +258,7 @@ namespace Leonetienne::GCrypt {
|
||||
|
||||
// To provide confusion, xor the blocks together
|
||||
// To provide diffusion, hash fragment to fragment' first
|
||||
b ^= Block(Cipher(fragment).Encipher(fragment.to_string()));
|
||||
b ^= Block(Cipher(fragment, Cipher::CIPHER_DIRECTION::ENCIPHER).Digest(fragment).to_string());
|
||||
}
|
||||
|
||||
return b;
|
||||
|
Reference in New Issue
Block a user