Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

ucc::Cipher Class Reference

A generic data ciphering class. More...

#include <secure.h>

Collaboration diagram for ucc::Cipher:
Collaboration graph
[legend]

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)
 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 (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 (unsigned char *data, size_t size)
 Process cipher data.
size_t puts (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 (char *name)
 Check if a specific cipher is supported.

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@gnutelephony.org>

Definition at line 233 of file secure.h.


Member Function Documentation

size_t ucc::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 ucc::Cipher::is ( char *  name  )  [static]

Check if a specific cipher is supported.

Parameters:
name of cipher to check.
Returns:
true if supported, false if not.
size_t ucc::Cipher::pad ( 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:
address of data to add before final pad.
size of data to add before final pad.
Returns:
actual bytes encrypted or decrypted.
size_t ucc::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:
address of data to process.
size of data to process.
flag if to pad data.
Returns:
bytes processed and written back to buffer.
size_t ucc::Cipher::put ( 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:
data to process.
size of data to process.
Returns:
size of processed output, should be same as size or 0 if error.
size_t ucc::Cipher::puts ( char *  string  ) 

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

Parameters:
string to encrypt.
Returns:
total encrypted size.

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