ucommon
|
A generic data ciphering class. More...
#include <secure.h>
Data Structures | |
class | Key |
Cipher key formed by hash algorithm. More... | |
Public Types | |
typedef Key * | key_t |
enum | mode_t { ENCRYPT = 1, DECRYPT = 0 } |
Public Member Functions | |
size_t | align (void) |
Cipher (key_t key, mode_t mode, unsigned char *address=NULL, size_t size=0) | |
size_t | flush (void) |
Push a final cipher block. | |
size_t | pad (const unsigned char *address, size_t size) |
This is used to process any data unaligned to the blocksize at the end of a cipher session. | |
size_t | pos (void) |
size_t | process (unsigned char *address, size_t size, bool flag=false) |
Process encrypted data in-place. | |
size_t | put (const unsigned char *data, size_t size) |
Process cipher data. | |
size_t | puts (const char *string) |
This essentially encrypts a single string and pads with NULL bytes as needed. | |
void | set (key_t key, mode_t mode, unsigned char *address, size_t size=0) |
void | set (unsigned char *address, size_t size=0) |
size_t | size (void) |
Static Public Member Functions | |
static bool | is (const char *name) |
Check if a specific cipher is supported. | |
Protected Member Functions | |
virtual void | push (unsigned char *address, size_t size) |
void | release (void) |
A generic data ciphering class.
This is used to construct cryptographic ciphers to encode and decode data as needed. The cipher type is specified by the key object. This class can be used to send output streaming to memory or in a fixed size buffer. If the latter is used, a push() method is called through a virtual when the buffer is full. Since block ciphers are used, buffers should be aligned to the block size.
size_t Cipher::flush | ( | void | ) |
Push a final cipher block.
This is used to push the final buffer into the push method for any remaining data.
static bool Cipher::is | ( | const char * | name | ) | [static] |
Check if a specific cipher is supported.
name | of cipher to check. |
size_t Cipher::pad | ( | const unsigned char * | address, |
size_t | size | ||
) |
This is used to process any data unaligned to the blocksize at the end of a cipher session.
On an encryption, it will add padding or an entire padding block with the number of bytes to strip. On decryption it will remove padding at the end. The pkcs5 method of padding with removal count is used. This also sets the address buffer to NULL to prevent further puts until reset.
address | of data to add before final pad. |
size | of data to add before final pad. |
size_t Cipher::process | ( | unsigned char * | address, |
size_t | size, | ||
bool | flag = false |
||
) |
Process encrypted data in-place.
This assumes no need to set the address buffer.
address | of data to process. |
size | of data to process. |
flag | if to pad data. |
size_t Cipher::put | ( | const unsigned char * | data, |
size_t | size | ||
) |
Process cipher data.
This requires the size to be a multiple of the cipher block size. If an unaligned sized block of data is used, it will be ignored and the size returned will be 0.
data | to process. |
size | of data to process. |
size_t Cipher::puts | ( | const char * | string | ) |
This essentially encrypts a single string and pads with NULL bytes as needed.
string | to encrypt. |