UCommon
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
ucommon::Cipher Class Reference

A generic data ciphering class. More...

#include <secure.h>

Data Structures

class  Key
 Cipher key formed by hash algorithm. More...
 

Public Types

typedef Keykey_t
 
enum  mode_t { ENCRYPT = 1, DECRYPT = 0 }
 

Public Member Functions

size_t align (void) const
 
 Cipher (key_t key, mode_t mode, unsigned char *address=((void *) 0), size_t size=0)
 
size_t flush (void)
 Push a final cipher block. More...
 
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. More...
 
size_t pos (void) const
 
size_t process (unsigned char *address, size_t size, bool flag=false)
 Process encrypted data in-place. More...
 
size_t put (const unsigned char *data, size_t size)
 Process cipher data. More...
 
size_t puts (const char *string)
 This essentially encrypts a single string and pads with NULL bytes as needed. More...
 
void set (unsigned char *address, size_t size=0)
 
void set (key_t key, mode_t mode, unsigned char *address, size_t size=0)
 
size_t size (void) const
 

Static Public Member Functions

static bool has (const char *name)
 Check if a specific cipher is supported. More...
 

Protected Member Functions

virtual void push (unsigned char *address, size_t size)
 
void release (void)
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
Examples:
cipher.cpp.

Definition at line 263 of file secure.h.

Member Function Documentation

size_t ucommon::Cipher::flush ( void  )

Push a final cipher block.

This is used to push the final buffer into the push method for any remaining data.

Examples:
cipher.cpp.
static bool ucommon::Cipher::has ( const char *  name)
static

Check if a specific cipher is supported.

Parameters
nameof cipher to check.
Returns
true if supported, false if not.
size_t ucommon::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.

Parameters
addressof data to add before final pad.
sizeof data to add before final pad.
Returns
actual bytes encrypted or decrypted.
size_t ucommon::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.

Parameters
addressof data to process.
sizeof data to process.
flagif to pad data.
Returns
bytes processed and written back to buffer.
size_t ucommon::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.

Parameters
datato process.
sizeof data to process.
Returns
size of processed output, should be same as size or 0 if error.
Examples:
cipher.cpp.
size_t ucommon::Cipher::puts ( const char *  string)

This essentially encrypts a single string and pads with NULL bytes as needed.

Parameters
stringto encrypt.
Returns
total encrypted size.
Examples:
cipher.cpp.

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