55 lines
1.3 KiB
C
Raw Normal View History

2022-05-22 17:29:38 +02:00
#ifndef GCRYPT_GCIPHER_H
#define GCRYPT_GCIPHER_H
2022-05-16 22:35:28 +02:00
#include "GCrypt/Feistel.h"
namespace Leonetienne::GCrypt {
/** Class to apply a block/-stream cipher to messages of arbitrary length in a distributed manner
*/
2022-05-22 12:51:58 +02:00
class GCipher {
public:
//! Describes the direction the cipher runs in
2022-05-22 12:51:58 +02:00
enum class DIRECTION {
ENCIPHER,
DECIPHER
};
2022-05-26 15:47:24 +02:00
//! Empty initializer. If you use this, you must call Initialize()!
GCipher();
//! Will initialize this cipher with a key
2022-05-22 13:43:23 +02:00
explicit GCipher(const Key& key, const DIRECTION direction);
// Disable copying
2022-05-22 12:51:58 +02:00
GCipher(const GCipher& other) = delete;
GCipher(GCipher&& other) noexcept = delete;
//! Will digest a data block, and return it
Block Digest(const Block& input);
2022-05-22 20:13:41 +02:00
//! Will update the base key used
void SetKey(const Key& key);
2022-05-22 16:54:40 +02:00
void operator=(const GCipher& other);
2022-05-26 15:47:24 +02:00
//! Will initialize the cipher with a key, and a mode.
//! If called on an existing object, it will reset its state.
void Initialize(const Key& key, const DIRECTION direction);
private:
2022-05-22 16:54:40 +02:00
DIRECTION direction;
//! The feistel instance to be used
Feistel feistel;
//! The last block, required for CBC.
Block lastBlock;
2022-05-26 15:47:24 +02:00
bool isInitialized = false;
};
}
2022-05-22 17:29:38 +02:00
#endif