Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
Algorithm Class Referenceabstract

Algorithm abstract class. More...

#include <Algorithm.hpp>

Inheritance diagram for Algorithm:
AES Blowfish Camellia ChaCha20Poly1305 IDEA RSA Serpent TripleDES Twofish

Public Types

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
}
 

Public Member Functions

 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
 

Static Public Member Functions

static std::unique_ptr< AlgorithmCreateFromName (const std::string &name, const Intent intent)
 
static std::unique_ptr< AlgorithmCreateFromType (const Type type, const Intent intent)
 
static std::string AlgoTypeEnumToStr (const Algorithm::Type e) noexcept
 
static std::string GetSupportedAlgorithmsStr () noexcept
 
static std::vector< std::pair< std::string, Algorithm::Type > > GetSupportedAlgorithms () noexcept
 

Static Public Attributes

static const std::unordered_map< Type, std::string_view > ALGORITHM_DESCRIPTIONS
 

Static Protected Member Functions

static std::vector< byte > GenerateRandomIV (const std::size_t size)
 

Protected Attributes

Type m_type {}
 
Intent m_intent {}
 

Static Protected Attributes

static std::unique_ptr< CryptoPP::AutoSeededRandomPool > m_auto_seeded_random_pool {nullptr}
 

Detailed Description

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.

Member Enumeration Documentation

◆ 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

enum Algorithm::Type : byte
strong

Algorithm type: AES, ChaCha...

Enumerator
AES 
Twofish 
TripleDES 
Blowfish 
IDEA 
ChaCha20Poly1305 
RSA 
Camellia 
Serpent 

Definition at line 74 of file Algorithm.hpp.

Constructor & Destructor Documentation

◆ Algorithm()

Algorithm::Algorithm ( const Type  type,
const Intent  intent = Intent::Encrypt|Intent::Decrypt 
)
explicitnoexcept

◆ ~Algorithm()

virtual Algorithm::~Algorithm ( )
virtualnoexcept

Member Function Documentation

◆ AlgoTypeEnumToStr()

static std::string Algorithm::AlgoTypeEnumToStr ( const Algorithm::Type  e)
staticnoexcept

Converts Algorithm::Type to std::string

◆ CreateFromName()

static std::unique_ptr<Algorithm> Algorithm::CreateFromName ( const std::string &  name,
const Intent  intent 
)
static

Creates polymorphic algorithm from algorithm type name

See also
CreateFromType()

◆ 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

Decrypts cipher with password

Parameters
passwordPassword used in encryption
cipherCipher with Enigma meta data
Returns
Recovered Buffer
Exceptions
throwsCryptoPP::Exception, std::exception on failure

Implemented in Twofish, TripleDES, Serpent, RSA, IDEA, ChaCha20Poly1305, Camellia, Blowfish, and AES.

◆ Decrypt() [2/3]

virtual void Algorithm::Decrypt ( const std::string &  password,
const fs::path &  in_filename,
const fs::path &  out_filename 
)
pure virtual

Decrypts a file with password

Parameters
passwordPassword used in encryption
in_filenameFilename to decrypt
out_filenameFilename to recover
Exceptions
throwsCryptoPP::Exception, std::exception on failure

Implemented in Twofish, TripleDES, Serpent, RSA, IDEA, ChaCha20Poly1305, Camellia, Blowfish, and AES.

◆ 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
passwordEncryption password
bufferBuffer to encrypt (text, binary...) an array of bytes
Returns
Cipher with Enigma meta data
Exceptions
throwsCryptoPP::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

Encrypts a file with password

Parameters
passwordEncryption password
in_filenameFilename to encrypt
out_filenameFilename to store encrypted cipher
Exceptions
throwsCryptoPP::Exception, std::exception on failure

Implemented in Twofish, TripleDES, Serpent, RSA, IDEA, ChaCha20Poly1305, Camellia, Blowfish, and AES.

◆ 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()

Algorithm::ENIGMA_ENUM_CLASS_BITWISE_OPERATORS ( Intent  ,
Enigma::byte   
)

◆ 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

Definition at line 153 of file Algorithm.hpp.

◆ GetTypeString()

std::string Algorithm::GetTypeString ( ) const
inlinenoexcept

Definition at line 155 of file Algorithm.hpp.

◆ SetType()

void Algorithm::SetType ( const Type  type)
inlinenoexcept

Definition at line 154 of file Algorithm.hpp.

Member Data Documentation

◆ 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::Blowfish, "Symmetric, moderate security, fast and simple"},
{Type::IDEA, "Symmetric, moderate to high security, simple and efficient"},
{Type::ChaCha20Poly1305, "Symmetric, very high security, high performance in software"},
{Type::RSA, "Asymmetric, very high security, excellent for key exchange"},
{Type::Camellia, "Symmetric, very high security, comparable to AES"},
{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

Intent Algorithm::m_intent {}
protected

Operation, Encrypt or Decrypt

Definition at line 199 of file Algorithm.hpp.

◆ m_type

Type Algorithm::m_type {}
protected

Algorithm type: AES, ChaCha, TripleDES...

Definition at line 198 of file Algorithm.hpp.


The documentation for this class was generated from the following file: