LibLogicalAccess  2.5.0
An Open Source RFID Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
logicalaccess::openssl::OpenSSLSymmetricCipher Class Referenceabstract

A OpenSSL symmetric cipher base class. More...

#include <openssl_symmetric_cipher.hpp>

Inheritance diagram for logicalaccess::openssl::OpenSSLSymmetricCipher:
logicalaccess::openssl::SymmetricCipher logicalaccess::openssl::AESCipher logicalaccess::openssl::DESCipher

Public Types

enum  EncMode {
  ENC_MODE_CBC , ENC_MODE_CFB , ENC_MODE_CFB1 , ENC_MODE_CFB8 ,
  ENC_MODE_ECB , ENC_MODE_OFB
}
 Encryption mode. More...
 
enum  Method { M_ENCRYPT , M_DECRYPT }
 A method. More...
 

Public Member Functions

 OpenSSLSymmetricCipher (EncMode mode)
 Constructor.
 
virtual ~OpenSSLSymmetricCipher ()
 
OpenSSLSymmetricCipherContext start (Method method, const SymmetricKey &key, const InitializationVector &iv, bool padding) const
 Initialize a new encryption/decryption session.
 
void cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding) override
 Cipher a buffer.
 
void decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding) override
 Decipher a buffer.
 
- Public Member Functions inherited from logicalaccess::openssl::SymmetricCipher
virtual ~SymmetricCipher ()
 Destructor.
 
virtual void cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding)=0
 Cipher a buffer.
 
void cipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key)
 
void cipher (const ByteVector &src, ByteVector &dest, const ByteVector &key, const ByteVector &iv={})
 
virtual void decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key, const InitializationVector &iv, bool padding)=0
 Decipher a buffer.
 
void decipher (const ByteVector &src, ByteVector &dest, const SymmetricKey &key)
 
void decipher (const ByteVector &src, ByteVector &dest, const ByteVector &key, const ByteVector &iv={})
 
virtual unsigned char getBlockSize () const =0
 

Static Public Member Functions

static void update (OpenSSLSymmetricCipherContext &context, const ByteVector &src)
 Add data to encrypt/decrypt.
 
static ByteVector stop (OpenSSLSymmetricCipherContext &context)
 Finalize an encryption/decryption session.
 

Protected Member Functions

virtual const EVP_CIPHER * getEVPCipher (const SymmetricKey &key) const =0
 Get the openssl EVP cipher.
 
EncMode mode () const
 Get the encryption mode.
 

Private Attributes

EncMode d_mode
 The encryption mode.
 

Detailed Description

A OpenSSL symmetric cipher base class.

This class serves as a base for all OpenSSL based symmetric cipher classes.

To cipher or decipher a buffer, you can use the start() method to get a context, use update() to fill-in a data block and stop() to get the ciphered/deciphered resulting data.

OpenSSLSymmetricCipher also provides helper methods cipher() and decipher() to quickly cipher or decipher a buffer.

Member Enumeration Documentation

◆ EncMode

Encryption mode.

Enumerator
ENC_MODE_CBC 

CBC.

ENC_MODE_CFB 

CFB.

ENC_MODE_CFB1 

CFB1.

ENC_MODE_CFB8 

CFB8.

ENC_MODE_ECB 

ECB.

ENC_MODE_OFB 

OFB.

◆ Method

A method.

Enumerator
M_ENCRYPT 
M_DECRYPT 

Constructor & Destructor Documentation

◆ OpenSSLSymmetricCipher()

logicalaccess::openssl::OpenSSLSymmetricCipher::OpenSSLSymmetricCipher ( EncMode  mode)
explicit

Constructor.

Parameters
modeThe encryption mode.

◆ ~OpenSSLSymmetricCipher()

logicalaccess::openssl::OpenSSLSymmetricCipher::~OpenSSLSymmetricCipher ( )
virtual

Member Function Documentation

◆ cipher()

void logicalaccess::openssl::OpenSSLSymmetricCipher::cipher ( const ByteVector src,
ByteVector dest,
const SymmetricKey key,
const InitializationVector iv,
bool  padding 
)
overridevirtual

Cipher a buffer.

Parameters
srcThe buffer to cipher.
destThe ciphered buffer.
keyThe key to use.
ivThe initialisation vector.
paddingWhether to use padding. In case of a failure, the call an InvalidCallException.

Implements logicalaccess::openssl::SymmetricCipher.

◆ decipher()

void logicalaccess::openssl::OpenSSLSymmetricCipher::decipher ( const ByteVector src,
ByteVector dest,
const SymmetricKey key,
const InitializationVector iv,
bool  padding 
)
overridevirtual

Decipher a buffer.

Parameters
srcThe buffer to decipher.
destThe deciphered buffer.
keyThe key to use.
ivThe initialisation vector.
paddingWhether to use padding. In case of a failure, the call a InvalidCallException.

Implements logicalaccess::openssl::SymmetricCipher.

◆ getEVPCipher()

virtual const EVP_CIPHER * logicalaccess::openssl::OpenSSLSymmetricCipher::getEVPCipher ( const SymmetricKey key) const
protectedpure virtual

Get the openssl EVP cipher.

Parameters
keyThe key.
Returns
The EVP cipher.

Implemented in logicalaccess::openssl::AESCipher, and logicalaccess::openssl::DESCipher.

◆ mode()

EncMode logicalaccess::openssl::OpenSSLSymmetricCipher::mode ( ) const
inlineprotected

Get the encryption mode.

Returns
The encryption mode.

◆ start()

OpenSSLSymmetricCipherContext logicalaccess::openssl::OpenSSLSymmetricCipher::start ( Method  method,
const SymmetricKey key,
const InitializationVector iv,
bool  padding 
) const

Initialize a new encryption/decryption session.

Parameters
methodThe method.
keyThe key to use.
ivThe initialisation vector.
paddingWhether to use padding.
Returns
A context that must be passed to stop() when cipherement is done.

◆ stop()

ByteVector logicalaccess::openssl::OpenSSLSymmetricCipher::stop ( OpenSSLSymmetricCipherContext context)
static

Finalize an encryption/decryption session.

Parameters
contextThe context.
Returns
The encrypted/decrypted data.
Warning
The value context is undefined after the call. Passing it to start(), update() or stop() will lead to undefined behavior.

◆ update()

void logicalaccess::openssl::OpenSSLSymmetricCipher::update ( OpenSSLSymmetricCipherContext context,
const ByteVector src 
)
static

Add data to encrypt/decrypt.

Parameters
contextThe context.
srcThe data to add to the encrypt/decrypt session.

Member Data Documentation

◆ d_mode

EncMode logicalaccess::openssl::OpenSSLSymmetricCipher::d_mode
private

The encryption mode.


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