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:
GenObject

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 StringtoString () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static const TokenDictdirections ()
 
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 NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Detailed Description

An abstract cipher.

The Cipher class provides an abstraction for data encryption classes

Member Enumeration Documentation

enum Direction

Cipher direction

Constructor & Destructor Documentation

virtual ~Cipher ( )
virtual

Destructor

Member Function Documentation

virtual unsigned int blockSize ( ) const
pure virtual

Get the cipher block size

Returns
Cipher block size in bytes
bool bufferFull ( unsigned int  len) const

Check if a buffer length is multiple of block size

Parameters
lenLength of data to encrypt or decrypt in bytes
Returns
True if buffer length is multiple of block size
unsigned int bufferSize ( unsigned int  len) const

Round up a buffer length to a multiple of block size

Parameters
lenLength of data to encrypt or decrypt in bytes
Returns
Length of required buffer in bytes
virtual bool decrypt ( void *  outData,
unsigned int  len,
const void *  inpData = 0 
)
pure virtual

Decrypt data

Parameters
outDataPointer to buffer for output (decrypted) and possibly input data
lenLength of output data, may not be multiple of block size
inpDataPointer to buffer containing input (encrypted) data, NULL to decrypt in place
Returns
True if data was successfully decrypted

Referenced by Cipher::decrypt().

bool decrypt ( DataBlock data)
inline

Decrypt a DataBlock in place

Parameters
dataData block to decrypt
Returns
True if data was successfully decrypted

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

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

Get a direction from the dictionary given the name

Parameters
nameName of the direction
defdirDefault direction to return if name is empty or unknown
Returns
Direction associated with the given name

References TelEngine::lookup().

static const TokenDict* directions ( )
inlinestatic

Get the dictionary of cipher directions

Returns
Pointer to the dictionary of cipher directions
virtual bool encrypt ( void *  outData,
unsigned int  len,
const void *  inpData = 0 
)
pure virtual

Encrypt data

Parameters
outDataPointer to buffer for output (encrypted) and possibly input data
lenLength of output data, may not be multiple of block size
inpDataPointer to buffer containing input (unencrypted) data, NULL to encrypt in place
Returns
True if data was successfully encrypted

Referenced by Cipher::encrypt().

bool encrypt ( DataBlock data)
inline

Encrypt a DataBlock in place

Parameters
dataData block to encrypt
Returns
True if data was successfully encrypted

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

virtual void* getObject ( const String name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName 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.

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

Set the Initialization Vector if applicable

Parameters
vectPointer to binary Initialization Vector data
lenLength of Initialization Vector in bytes
dirDirection to set the Initialization Vector for
Returns
True if the Initialization Vector was set successfully

Referenced by Cipher::initVector().

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

Set the Initialization Vector is applicable

Parameters
vectBinary Initialization Vector
dirDirection to set the Initialization Vector for
Returns
True if the Initialization Vector was set successfully

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

virtual unsigned int initVectorSize ( ) const
virtual

Get the initialization vector size

Returns
Initialization vector size in bytes, 0 if not applicable
virtual bool setKey ( const void *  key,
unsigned int  len,
Direction  dir = Bidir 
)
pure virtual

Set the key required to encrypt or decrypt data

Parameters
keyPointer to binary key data
lenLength of key in bytes
dirDirection to set key for
Returns
True if the key was set successfully

Referenced by Cipher::setKey().

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

Set the key required to encrypt or decrypt data

Parameters
keyBinary key data block
dirDirection to set key for
Returns
True if the key was set successfully

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

virtual bool valid ( Direction  dir = Bidir) const
virtual

Check if the cipher instance is valid for a specific direction

Parameters
dirDirection 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: