Algorithm abstract class.
More...
#include <Algorithm.hpp>
|
enum class | Intent : Enigma::byte { None = 0 << 0
, Encrypt = 1 << 1
, Decrypt = 1 << 2
, All = Encrypt | Decrypt
} |
|
enum class | Type : byte {
AES = 0x01
, Twofish
, TripleDES
, Blowfish
,
IDEA
, ChaCha20Poly1305
, RSA
, Camellia
,
Serpent
} |
|
|
| ENIGMA_ENUM_CLASS_BITWISE_OPERATORS (Intent, Enigma::byte) |
|
| Algorithm (const Type type, const Intent intent=Intent::Encrypt|Intent::Decrypt) noexcept |
|
virtual | ~Algorithm () noexcept |
|
virtual std::vector< byte > | Encrypt (const std::string &password, const byte *buffer, const std::size_t buffSize)=0 |
|
virtual std::vector< byte > | Encrypt (const std::string &password, const std::vector< byte > &buffer)=0 |
|
virtual std::vector< byte > | Decrypt (const std::string &password, const byte *cipher, const std::size_t cipherSize)=0 |
|
virtual std::vector< byte > | Decrypt (const std::string &password, const std::vector< byte > &cipher)=0 |
|
virtual void | Encrypt (const std::string &password, const fs::path &in_filename, const fs::path &out_filename)=0 |
|
virtual void | Decrypt (const std::string &password, const fs::path &in_filename, const fs::path &out_filename)=0 |
|
Type | GetType () const noexcept |
|
void | SetType (const Type type) noexcept |
|
std::string | GetTypeString () const noexcept |
|
Algorithm abstract class.
All encryption algorithms like AES, Twofish.. inherit from this class
- Todo:
- add more encryption algorithms
Definition at line 53 of file Algorithm.hpp.
◆ Intent
Intention of creating an instance of an Algorithm.
helps to avoid initializing resources not needed for an specific operation. (for example when encrypting, we initialize a random seeder which is not needed when decrypting)
Enumerator |
---|
None | |
Encrypt | |
Decrypt | |
All | |
Definition at line 62 of file Algorithm.hpp.
◆ Type
Algorithm type: AES, ChaCha...
Enumerator |
---|
AES | |
Twofish | |
TripleDES | |
Blowfish | |
IDEA | |
ChaCha20Poly1305 | |
RSA | |
Camellia | |
Serpent | |
Definition at line 74 of file Algorithm.hpp.
◆ Algorithm()
◆ ~Algorithm()
virtual Algorithm::~Algorithm |
( |
| ) |
|
|
virtualnoexcept |
◆ AlgoTypeEnumToStr()
◆ CreateFromName()
static std::unique_ptr<Algorithm> Algorithm::CreateFromName |
( |
const std::string & |
name, |
|
|
const Intent |
intent |
|
) |
| |
|
static |
◆ CreateFromType()
static std::unique_ptr<Algorithm> Algorithm::CreateFromType |
( |
const Type |
type, |
|
|
const Intent |
intent |
|
) |
| |
|
static |
Creates polymorphic algorithm from algorithm type
◆ Decrypt() [1/3]
virtual std::vector<byte> Algorithm::Decrypt |
( |
const std::string & |
password, |
|
|
const byte * |
cipher, |
|
|
const std::size_t |
cipherSize |
|
) |
| |
|
pure virtual |
◆ Decrypt() [2/3]
virtual void Algorithm::Decrypt |
( |
const std::string & |
password, |
|
|
const fs::path & |
in_filename, |
|
|
const fs::path & |
out_filename |
|
) |
| |
|
pure virtual |
◆ Decrypt() [3/3]
virtual std::vector<byte> Algorithm::Decrypt |
( |
const std::string & |
password, |
|
|
const std::vector< byte > & |
cipher |
|
) |
| |
|
pure virtual |
◆ Encrypt() [1/3]
virtual std::vector<byte> Algorithm::Encrypt |
( |
const std::string & |
password, |
|
|
const byte * |
buffer, |
|
|
const std::size_t |
buffSize |
|
) |
| |
|
pure virtual |
Encrypts buffer with password
- Parameters
-
password | Encryption password |
buffer | Buffer to encrypt (text, binary...) an array of bytes |
- Returns
- Cipher with Enigma meta data
- Exceptions
-
throws | CryptoPP::Exception, std::exception on failure |
Implemented in Twofish, TripleDES, Serpent, RSA, IDEA, ChaCha20Poly1305, Camellia, Blowfish, and AES.
◆ Encrypt() [2/3]
virtual void Algorithm::Encrypt |
( |
const std::string & |
password, |
|
|
const fs::path & |
in_filename, |
|
|
const fs::path & |
out_filename |
|
) |
| |
|
pure virtual |
◆ Encrypt() [3/3]
virtual std::vector<byte> Algorithm::Encrypt |
( |
const std::string & |
password, |
|
|
const std::vector< byte > & |
buffer |
|
) |
| |
|
pure virtual |
◆ ENIGMA_ENUM_CLASS_BITWISE_OPERATORS()
◆ GenerateRandomIV()
static std::vector<byte> Algorithm::GenerateRandomIV |
( |
const std::size_t |
size | ) |
|
|
staticprotected |
Generates random IV (aka Salt) with a desired length
◆ GetSupportedAlgorithms()
static std::vector<std::pair<std::string, Algorithm::Type> > Algorithm::GetSupportedAlgorithms |
( |
| ) |
|
|
staticnoexcept |
Returns a vector of supported algorithms represented as pair of algo name string, algo type. orderd as enum Type
◆ GetSupportedAlgorithmsStr()
static std::string Algorithm::GetSupportedAlgorithmsStr |
( |
| ) |
|
|
staticnoexcept |
Returns a string of supported algorithms represented as "[Algo1, Algo2, Algo3...]" orderd as enum Type
◆ GetType()
Type Algorithm::GetType |
( |
| ) |
const |
|
inlinenoexcept |
◆ GetTypeString()
std::string Algorithm::GetTypeString |
( |
| ) |
const |
|
inlinenoexcept |
◆ SetType()
void Algorithm::SetType |
( |
const Type |
type | ) |
|
|
inlinenoexcept |
◆ ALGORITHM_DESCRIPTIONS
const std::unordered_map<Type, std::string_view> Algorithm::ALGORITHM_DESCRIPTIONS |
|
inlinestatic |
Initial value:= {
{
Type::AES,
"Symmetric, extremely high security, efficient, widely supported"},
{
Type::Twofish,
"Symmetric, high security, flexible and efficient"},
{
Type::TripleDES,
"Symmetric, moderate security, suitable for legacy systems"},
{
Type::IDEA,
"Symmetric, moderate to high security, simple and efficient"},
{
Type::RSA,
"Asymmetric, very high security, excellent for key exchange"},
{
Type::Serpent,
"Symmetric, high security, conservative design"},
}
Definition at line 88 of file Algorithm.hpp.
◆ m_auto_seeded_random_pool
std::unique_ptr<CryptoPP::AutoSeededRandomPool> Algorithm::m_auto_seeded_random_pool {nullptr} |
|
inlinestaticprotected |
To generate random IV on encryption
Definition at line 200 of file Algorithm.hpp.
◆ m_intent
◆ m_type
Type Algorithm::m_type {} |
|
protected |
The documentation for this class was generated from the following file: