Yate: Cipher Class Reference

Yate

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Cipher Class Referenceabstract

An abstract cipher. More...

`#include <yateclass.h>`

Inheritance diagram for Cipher:

## Public Types
enum | Direction { Bidir , Encrypt , Decrypt }

## Public Member Functions
virtual | ~Cipher ()
virtual void * | getObject (const String &name) const
virtual bool | valid (Direction dir=Bidir) const
virtual unsigned int | blockSize () const =0
virtual unsigned int | initVectorSize () const
unsigned int | bufferSize (unsigned int len) const
bool | bufferFull (unsigned int len) const
virtual bool | setKey (const void *key, unsigned int len, Direction dir=Bidir)=0
bool | setKey (const DataBlock &key, Direction dir=Bidir)
virtual bool | initVector (const void *vect, unsigned int len, Direction dir=Bidir)
bool | initVector (const DataBlock &vect, Direction dir=Bidir)
virtual bool | encrypt (void *outData, unsigned int len, const void *inpData=0)=0
bool | encrypt (DataBlock &data)
virtual bool | decrypt (void *outData, unsigned int len, const void *inpData=0)=0
bool | decrypt (DataBlock &data)
Public Member Functions inherited from GenObject
| GenObject ()
virtual | ~GenObject ()
virtual bool | alive () const
virtual void | destruct ()
virtual const String & | toString () const
virtual const String & | traceId () const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (NamedCounter *counter)

## Static Public Member Functions
static const TokenDict * | directions ()
static Direction | direction (const char *name, Direction defdir=Bidir)
Static Public Member Functions inherited from GenObject
static void * | getObject (const String &name, const GenObject *obj)
static bool | getObjCounting ()
static void | setObjCounting (bool enable)
static NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()

## Detailed Description

An abstract cipher.

The Cipher class provides an abstraction for data encryption classes

## Member Enumeration Documentation

## ◆ Direction

enum Direction

Cipher direction

## Constructor & Destructor Documentation

## ◆ ~Cipher()

virtual ~Cipher | ( |  | ) |
| virtual

Destructor

## Member Function Documentation

## ◆ blockSize()

virtual unsigned int blockSize | ( |  | ) | const
| pure virtual

Get the cipher block size

Returns
  Cipher block size in bytes

## ◆ bufferFull()

bool bufferFull | ( | unsigned int | len | ) | const

Check if a buffer length is multiple of block size

Parameters

  len | Length of data to encrypt or decrypt in bytes

Returns
  True if buffer length is multiple of block size

## ◆ bufferSize()

unsigned int bufferSize | ( | unsigned int | len | ) | const

Round up a buffer length to a multiple of block size

Parameters

  len | Length of data to encrypt or decrypt in bytes

Returns
  Length of required buffer in bytes

## ◆ decrypt() [1/2]

bool decrypt | ( | DataBlock & | data | ) |
| inline

Decrypt a DataBlock in place

Parameters

  data | Data block to decrypt

Returns
  True if data was successfully decrypted

References DataBlock::data(), decrypt(), and DataBlock::length().

## ◆ decrypt() [2/2]

virtual bool decrypt | ( | void * | outData,
|  | unsigned int | len,
|  | const void * | inpData = 0 )
| pure virtual

Decrypt data

Parameters

  outData | Pointer to buffer for output (decrypted) and possibly input data
  len | Length of output data, may not be multiple of block size
  inpData | Pointer to buffer containing input (encrypted) data, NULL to decrypt in place

Returns
  True if data was successfully decrypted

Referenced by decrypt().

## ◆ direction()

Direction direction | ( | const char * | name,
|  | Direction | defdir = Bidir )
| inlinestatic

Get a direction from the dictionary given the name

Parameters

  name | Name of the direction
  defdir | Default direction to return if name is empty or unknown

Returns
  Direction associated with the given name

## ◆ directions()

const TokenDict * directions | ( |  | ) |
| inlinestatic

Get the dictionary of cipher directions

Returns
  Pointer to the dictionary of cipher directions

## ◆ encrypt() [1/2]

bool encrypt | ( | DataBlock & | data | ) |
| inline

Encrypt a DataBlock in place

Parameters

  data | Data block to encrypt

Returns
  True if data was successfully encrypted

References DataBlock::data(), encrypt(), and DataBlock::length().

## ◆ encrypt() [2/2]

virtual bool encrypt | ( | void * | outData,
|  | unsigned int | len,
|  | const void * | inpData = 0 )
| pure virtual

Encrypt data

Parameters

  outData | Pointer to buffer for output (encrypted) and possibly input data
  len | Length of output data, may not be multiple of block size
  inpData | Pointer to buffer containing input (unencrypted) data, NULL to encrypt in place

Returns
  True if data was successfully encrypted

Referenced by encrypt().

## ◆ getObject()

virtual void * getObject | ( | const String & | name | ) | const
| virtual

Get a pointer to a derived class given that class name

Parameters

  name | Name of the class we are asking for

Returns
  Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

## ◆ initVector() [1/2]

bool initVector | ( | const DataBlock & | vect,
|  | Direction | dir = Bidir )
| inline

Set the Initialization Vector is applicable

Parameters

  vect | Binary Initialization Vector
  dir | Direction to set the Initialization Vector for

Returns
  True if the Initialization Vector was set successfully

References DataBlock::data(), initVector(), and DataBlock::length().

## ◆ initVector() [2/2]

virtual bool initVector | ( | const void * | vect,
|  | unsigned int | len,
|  | Direction | dir = Bidir )
| virtual

Set the Initialization Vector if applicable

Parameters

  vect | Pointer to binary Initialization Vector data
  len | Length of Initialization Vector in bytes
  dir | Direction to set the Initialization Vector for

Returns
  True if the Initialization Vector was set successfully

Referenced by initVector().

## ◆ initVectorSize()

virtual unsigned int initVectorSize | ( |  | ) | const
| virtual

Get the initialization vector size

Returns
  Initialization vector size in bytes, 0 if not applicable

## ◆ setKey() [1/2]

bool setKey | ( | const DataBlock & | key,
|  | Direction | dir = Bidir )
| inline

Set the key required to encrypt or decrypt data

Parameters

  key | Binary key data block
  dir | Direction to set key for

Returns
  True if the key was set successfully

References DataBlock::data(), DataBlock::length(), and setKey().

## ◆ setKey() [2/2]

virtual bool setKey | ( | const void * | key,
|  | unsigned int | len,
|  | Direction | dir = Bidir )
| pure virtual

Set the key required to encrypt or decrypt data

Parameters

  key | Pointer to binary key data
  len | Length of key in bytes
  dir | Direction to set key for

Returns
  True if the key was set successfully

Referenced by setKey().

## ◆ valid()

virtual bool valid | ( | Direction | dir = Bidir | ) | const
| virtual

Check if the cipher instance is valid for a specific direction

Parameters

  dir | Direction to check

Returns
  True if the cipher is able to perform operation on given direction

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

- yateclass.h