libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::Security::Gcrypt Class Reference

#include <Gcrypt.h>

Public Member Functions

 Gcrypt (int algorithm, int mode, unsigned int flags)
 Constructor. More...
 
virtual ~Gcrypt ()
 Destructor. More...
 
void reset ()
 Resets everything. More...
 
gcry_cipher_hd_t getHandle ()
 Returns the underlying gcry_cipher_hd_t. More...
 
size_t getBlockSize ()
 Returns the block size of the algorithm used in bytes. More...
 
template<typename Data >
void setIv (const Data &iv)
 Sets the IV to use. More...
 
void setIv (const void *iv, const size_t length)
 Takes same parameters as gcry_cipher_setiv() except for the handle. More...
 
template<typename Data >
void setCounter (const Data &counter)
 Sets the counter to use. More...
 
void setCounter (const void *counter, const size_t length)
 Takes same parameters as gcry_cipher_setctr() except for the handle. More...
 
template<typename Data >
void setKey (const Data &key)
 Sets the key to use. More...
 
void setKey (const void *key, const size_t length)
 Takes same parameters as gcry_cipher_setkey() except for the handle. More...
 
void encrypt (void *out, const size_t outLength, const void *in, const size_t inLength)
 Encrypts data. More...
 
template<typename DataOut , typename DataIn >
void encrypt (DataOut &out, const DataIn &in)
 Encrypt data. More...
 
void decrypt (void *out, const size_t outLength, const void *in, const size_t inLength)
 Decrypts data. More...
 
template<typename DataOut , typename DataIn >
void decrypt (DataOut &out, const DataIn &in)
 Decrypt data. More...
 
bool authenticate (const void *in, const size_t inLength)
 Authenticates encrypted data if supported by the algorithm. More...
 
template<typename DataIn >
bool authenticate (const DataIn &in)
 Authenticates encrypted data. More...
 

Static Public Member Functions

static std::string getError (int32_t errorCode)
 Gets the error message to a GCRYPT error code. More...
 

Constructor & Destructor Documentation

§ Gcrypt()

BaseLib::Security::Gcrypt::Gcrypt ( int  algorithm,
int  mode,
unsigned int  flags 
)

Constructor.

Takes the same arguments as gcry_cipher_open().

Parameters
algorithmSee https://www.gnupg.org/documentation/manuals/gcrypt/Available-ciphers.html#Available-ciphers for a list of ciphers and the according constants.
modeSee https://www.gnupg.org/documentation/manuals/gcrypt/Available-cipher-modes.html#Available-cipher-modes. Note that the mode needs to be compatible to the algorithm used.
flags0 or the bit-wise OR of the following constants: GCRY_CIPHER_SECURE (allocate everything in secure memory), GCRY_CIPHER_ENABLE_SYNC (CFB sync mode for OpenPGP), GCRY_CIPHER_CBC_CTS (Enable cipher text stealing for CBC), GCRY_CIPHER_CBC_MAC (compute CBC-MAC checksums, same as CBC but only outputs the last block)
Exceptions
GcryptExceptionOn error.

§ ~Gcrypt()

BaseLib::Security::Gcrypt::~Gcrypt ( )
virtual

Destructor.

Member Function Documentation

§ authenticate() [1/2]

bool BaseLib::Security::Gcrypt::authenticate ( const void *  in,
const size_t  inLength 
)

Authenticates encrypted data if supported by the algorithm.

Takes same parameters as gcry_cipher_authenticate() except for the handle.

§ authenticate() [2/2]

template<typename DataIn >
bool BaseLib::Security::Gcrypt::authenticate ( const DataIn &  in)

Authenticates encrypted data.

§ decrypt() [1/2]

void BaseLib::Security::Gcrypt::decrypt ( void *  out,
const size_t  outLength,
const void *  in,
const size_t  inLength 
)

Decrypts data.

Takes same parameters as gcry_cipher_decrypt() except for the handle.

Exceptions
GcryptExceptionOn error.

§ decrypt() [2/2]

template<typename DataOut , typename DataIn >
void BaseLib::Security::Gcrypt::decrypt ( DataOut &  out,
const DataIn &  in 
)

Decrypt data.

Exceptions
GcryptExceptionOn error.

§ encrypt() [1/2]

void BaseLib::Security::Gcrypt::encrypt ( void *  out,
const size_t  outLength,
const void *  in,
const size_t  inLength 
)

Encrypts data.

Takes same parameters as gcry_cipher_encrypt() except for the handle.

Exceptions
GcryptExceptionOn error.

§ encrypt() [2/2]

template<typename DataOut , typename DataIn >
void BaseLib::Security::Gcrypt::encrypt ( DataOut &  out,
const DataIn &  in 
)

Encrypt data.

Exceptions
GcryptExceptionOn error.

§ getBlockSize()

size_t BaseLib::Security::Gcrypt::getBlockSize ( )

Returns the block size of the algorithm used in bytes.

§ getError()

std::string BaseLib::Security::Gcrypt::getError ( int32_t  errorCode)
static

Gets the error message to a GCRYPT error code.

Parameters
errorCodeThe GCRYPT error code.
Returns
Returns the error message for the provided error code.

§ getHandle()

gcry_cipher_hd_t BaseLib::Security::Gcrypt::getHandle ( )
inline

Returns the underlying gcry_cipher_hd_t.

Returns
Returns the underlying gcry_cipher_hd_t.

§ reset()

void BaseLib::Security::Gcrypt::reset ( )

Resets everything.

§ setCounter() [1/2]

template<typename Data >
void BaseLib::Security::Gcrypt::setCounter ( const Data &  counter)

Sets the counter to use.

Exceptions
GcryptExceptionOn error.

§ setCounter() [2/2]

void BaseLib::Security::Gcrypt::setCounter ( const void *  counter,
const size_t  length 
)

Takes same parameters as gcry_cipher_setctr() except for the handle.

Exceptions
GcryptExceptionOn error.

§ setIv() [1/2]

template<typename Data >
void BaseLib::Security::Gcrypt::setIv ( const Data &  iv)

Sets the IV to use.

Exceptions
GcryptExceptionOn error.

§ setIv() [2/2]

void BaseLib::Security::Gcrypt::setIv ( const void *  iv,
const size_t  length 
)

Takes same parameters as gcry_cipher_setiv() except for the handle.

Exceptions
GcryptExceptionOn error.

§ setKey() [1/2]

template<typename Data >
void BaseLib::Security::Gcrypt::setKey ( const Data &  key)

Sets the key to use.

Exceptions
GcryptExceptionOn error.

§ setKey() [2/2]

void BaseLib::Security::Gcrypt::setKey ( const void *  key,
const size_t  length 
)

Takes same parameters as gcry_cipher_setkey() except for the handle.

Exceptions
GcryptExceptionOn error.

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