ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
ucommon::Cipher Class Reference

A generic data ciphering class. More...

#include <secure.h>

Collaboration diagram for ucommon::Cipher:
[legend]

Classes

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

Public Types

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

Public Member Functions

 Cipher ()
 
 Cipher (const key_t key, mode_t mode, uint8_t *address=NULL, size_t size=0)
 
virtual ~Cipher ()
 
void set (uint8_t *address, size_t size=0)
 
void set (const key_t key, mode_t mode, uint8_t *address, size_t size=0)
 
secure::keybytes iv ()
 
secure::keybytes key ()
 
size_t flush (void)
 Push a final cipher block. More...
 
size_t put (const uint8_t *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...
 
size_t pad (const uint8_t *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 process (uint8_t *address, size_t size, bool flag=false)
 Process encrypted data in-place. More...
 
size_t size (void) const
 
size_t pos (void) const
 
size_t align (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 (uint8_t *address, size_t size)
 
void release (void)
 

Private Member Functions

 __DELETE_COPY (Cipher)
 

Private Attributes

Key keys
 
size_t bufsize
 
size_t bufpos
 
mode_t bufmode
 
uint8_t * bufaddr
 
void * context
 

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

Definition at line 289 of file secure.h.

Member Typedef Documentation

◆ key_t

Definition at line 401 of file secure.h.

Member Enumeration Documentation

◆ mode_t

Enumerator
ENCRYPT 
DECRYPT 

Definition at line 292 of file secure.h.

Constructor & Destructor Documentation

◆ Cipher() [1/2]

ucommon::Cipher::Cipher ( )

Definition at line 589 of file common.cpp.

References bufaddr, bufpos, bufsize, and context.

◆ Cipher() [2/2]

ucommon::Cipher::Cipher ( const key_t  key,
mode_t  mode,
uint8_t *  address = NULL,
size_t  size = 0 
)

Definition at line 581 of file common.cpp.

References bufaddr, bufpos, bufsize, context, key(), set(), and size().

Here is the call graph for this function:

◆ ~Cipher()

ucommon::Cipher::~Cipher ( )
virtual

Definition at line 596 of file common.cpp.

References flush(), and release().

Here is the call graph for this function:

Member Function Documentation

◆ __DELETE_COPY()

ucommon::Cipher::__DELETE_COPY ( Cipher  )
private

◆ align()

size_t ucommon::Cipher::align ( void  ) const
inline

Definition at line 491 of file secure.h.

References ucommon::Cipher::Key::iosize().

Here is the call graph for this function:

◆ flush()

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.

Definition at line 602 of file common.cpp.

References bufaddr, bufpos, bufsize, and push().

Referenced by pad(), puts(), set(), and ~Cipher().

Here is the call graph for this function:

◆ has()

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.

Definition at line 240 of file cipher.cpp.

References cipher, and ucommon::__context::map_cipher().

Referenced by main().

Here is the call graph for this function:

◆ iv()

secure::keybytes ucommon::Cipher::iv ( )
inline

Definition at line 428 of file secure.h.

References ucommon::Cipher::Key::iv().

Referenced by ucommon::Cipher::Key::Key(), and ucommon::Cipher::Key::set().

Here is the call graph for this function:

◆ key()

secure::keybytes ucommon::Cipher::key ( )
inline

Definition at line 432 of file secure.h.

References ucommon::Cipher::Key::key().

Referenced by ucommon::Cipher::Key::b64(), Cipher(), set(), and ucommon::Cipher::Key::set().

Here is the call graph for this function:

◆ pad()

size_t ucommon::Cipher::pad ( const uint8_t *  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.

Definition at line 301 of file cipher.cpp.

References bufaddr, bufmode, bufpos, DECRYPT, ENCRYPT, flush(), ucommon::Cipher::Key::iosize(), keys, put(), size(), and zerofill().

Referenced by process(), and puts().

Here is the call graph for this function:

◆ pos()

size_t ucommon::Cipher::pos ( void  ) const
inline

Definition at line 487 of file secure.h.

Referenced by ucommon::Cipher::Key::assign().

◆ process()

size_t ucommon::Cipher::process ( uint8_t *  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.

Definition at line 641 of file common.cpp.

References pad(), put(), and set().

Here is the call graph for this function:

◆ push()

void ucommon::Cipher::push ( uint8_t *  address,
size_t  size 
)
protectedvirtual

Definition at line 227 of file cipher.cpp.

Referenced by flush(), and put().

◆ put()

size_t ucommon::Cipher::put ( const uint8_t *  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.

Definition at line 266 of file cipher.cpp.

References bufaddr, bufmode, bufpos, bufsize, context, DECRYPT, ENCRYPT, ucommon::Cipher::Key::iosize(), keys, push(), put(), release(), and size().

Referenced by encode(), encodefile(), final(), pad(), process(), process(), put(), and puts().

Here is the call graph for this function:

◆ puts()

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.

Definition at line 614 of file common.cpp.

References bufaddr, flush(), ucommon::Cipher::Key::iosize(), keys, pad(), put(), and zerofill().

Here is the call graph for this function:

◆ release()

void ucommon::Cipher::release ( void  )
protected

Definition at line 231 of file cipher.cpp.

References ucommon::Cipher::Key::clear(), context, and keys.

Referenced by put(), set(), and ~Cipher().

Here is the call graph for this function:

◆ set() [1/2]

void ucommon::Cipher::set ( const key_t  key,
mode_t  mode,
uint8_t *  address,
size_t  size = 0 
)

Definition at line 245 of file cipher.cpp.

References ucommon::Cipher::Key::algoid, ucommon::Cipher::Key::blksize, bufaddr, bufmode, bufsize, context, ucommon::Cipher::Key::ivbuf, key(), ucommon::Cipher::Key::keybuf, keys, ucommon::Cipher::Key::keysize, release(), and size().

Here is the call graph for this function:

◆ set() [2/2]

void ucommon::Cipher::set ( uint8_t *  address,
size_t  size = 0 
)

Definition at line 633 of file common.cpp.

References bufaddr, bufpos, bufsize, flush(), and size().

Referenced by Cipher(), ucommon::Cipher::Key::Key(), main(), process(), and ucommon::Cipher::Key::set().

Here is the call graph for this function:

◆ size()

size_t ucommon::Cipher::size ( void  ) const
inline

Member Data Documentation

◆ bufaddr

uint8_t* ucommon::Cipher::bufaddr
private

Definition at line 407 of file secure.h.

Referenced by Cipher(), flush(), pad(), put(), puts(), and set().

◆ bufmode

mode_t ucommon::Cipher::bufmode
private

Definition at line 406 of file secure.h.

Referenced by pad(), put(), and set().

◆ bufpos

size_t ucommon::Cipher::bufpos
private

Definition at line 405 of file secure.h.

Referenced by Cipher(), flush(), pad(), put(), and set().

◆ bufsize

size_t ucommon::Cipher::bufsize
private

Definition at line 405 of file secure.h.

Referenced by Cipher(), flush(), put(), and set().

◆ context

void* ucommon::Cipher::context
private

Definition at line 408 of file secure.h.

Referenced by Cipher(), put(), release(), and set().

◆ keys

Key ucommon::Cipher::keys
private

Definition at line 404 of file secure.h.

Referenced by pad(), put(), puts(), release(), and set().


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