Yate
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hasher Class Referenceabstract

An abstract hashing class. More...

#include <yateclass.h>

Inheritance diagram for Hasher:
MD5 SHA1 SHA256

Public Member Functions

virtual ~Hasher ()
 
virtual void clear ()=0
 
virtual void finalize ()=0
 
virtual const unsigned char * rawDigest ()=0
 
const StringhexDigest ()
 
bool update (const void *buf, unsigned int len)
 
bool update (const DataBlock &data)
 
bool update (const String &str)
 
Hasheroperator<< (const String &value)
 
Hasheroperator<< (const DataBlock &data)
 
Hasheroperator<< (const char *value)
 
bool hmacStart (DataBlock &opad, const void *key, unsigned int keyLen)
 
bool hmacStart (DataBlock &opad, const DataBlock &key)
 
bool hmacStart (DataBlock &opad, const String &key)
 
bool hmacFinal (const DataBlock &opad)
 
bool hmac (const void *key, unsigned int keyLen, const void *msg, unsigned int msgLen)
 
bool hmac (const DataBlock &key, const DataBlock &msg)
 
bool hmac (const String &key, const String &msg)
 
virtual unsigned int hashLength () const =0
 
virtual unsigned int hmacBlockSize () const
 

Protected Member Functions

 Hasher ()
 
virtual bool updateInternal (const void *buf, unsigned int len)=0
 

Protected Attributes

void * m_private
 
String m_hex
 

Detailed Description

An abstract hashing class.

Abstract base class representing a hash calculator

Constructor & Destructor Documentation

virtual ~Hasher ( )
virtual

Destroy the instance, free allocated memory

Hasher ( )
inlineprotected

Default constructor

Member Function Documentation

virtual void clear ( )
pure virtual

Clear the digest and prepare for reuse

Implemented in SHA256, SHA1, and MD5.

virtual void finalize ( )
pure virtual

Finalize the digest computation, make result ready. Subsequent calls to update() will fail

Implemented in SHA256, SHA1, and MD5.

Referenced by Hasher::hexDigest().

virtual unsigned int hashLength ( ) const
pure virtual

Return the length of the raw binary digest

Returns
Length of the digest in octets

Implemented in SHA256, SHA1, and MD5.

const String& hexDigest ( )
inline

Returns the standard hexadecimal representation of the message digest. The digest is finalized if if wasn't already

Returns
A String which holds the hex digest or a null one if some error occured

References Hasher::finalize().

Referenced by ClientContact::buildIdHash().

bool hmac ( const void *  key,
unsigned int  keyLen,
const void *  msg,
unsigned int  msgLen 
)

Compute a Message Authentication Code with this hash

Parameters
keySecret key
keyLenSecret key length
msgMessage to authenticate
msgLenMessage length
Returns
True if HMAC was computed correctly, result is left in hasher

Referenced by Hasher::hmac().

bool hmac ( const DataBlock key,
const DataBlock msg 
)
inline

Compute a Message Authentication Code with this hash

Parameters
keySecret key
msgMessage to authenticate
Returns
True if HMAC was computed correctly, result is left in hasher

References DataBlock::data(), Hasher::hmac(), and DataBlock::length().

bool hmac ( const String key,
const String msg 
)
inline

Compute a Message Authentication Code with this hash

Parameters
keySecret key string
msgMessage string to authenticate
Returns
True if HMAC was computed correctly, result is left in hasher

References String::c_str(), Hasher::hmac(), and String::length().

virtual unsigned int hmacBlockSize ( ) const
virtual

Return the size of the block used in HMAC calculations

Returns
HMAC block size in octets, usually 64
bool hmacFinal ( const DataBlock opad)

Finalize a HMAC calculation with this hash

Parameters
opadOuter pad as filled by hmacStart
Returns
True on success, HMAC result is left in hasher
bool hmacStart ( DataBlock opad,
const void *  key,
unsigned int  keyLen 
)

Start a HMAC calculation, initialize the hash and the outer pad

Parameters
opadOuter pad to be filled from key
keySecret key
keyLenSecret key length
Returns
True if hash and outer pad were successfully initialized

Referenced by Hasher::hmacStart().

bool hmacStart ( DataBlock opad,
const DataBlock key 
)
inline

Start a HMAC calculation, initialize the hash and the outer pad

Parameters
opadOuter pad to be filled from key
keySecret key
Returns
True if hash and outer pad were successfully initialized

References DataBlock::data(), Hasher::hmacStart(), and DataBlock::length().

bool hmacStart ( DataBlock opad,
const String key 
)
inline

Start a HMAC calculation, initialize the hash and the outer pad

Parameters
opadOuter pad to be filled from key
keySecret key string
Returns
True if hash and outer pad were successfully initialized

References String::c_str(), Hasher::hmacStart(), and String::length().

Hasher& operator<< ( const String value)
inline

Digest updating operator for Strings

Parameters
valueString to be included in digest

References Hasher::update().

Hasher& operator<< ( const DataBlock data)
inline

Digest updating operator for DataBlocks

Parameters
dataData to be included in digest

References Hasher::update().

Hasher& operator<< ( const char *  value)

Digest updating operator for C strings

Parameters
valueString to be included in digest
virtual const unsigned char* rawDigest ( )
pure virtual

Returns a pointer to the raw 16-byte binary value of the message digest. The digest is finalized if if wasn't already

Returns
Pointer to the raw digest data or NULL if some error occured

Implemented in SHA256, SHA1, and MD5.

bool update ( const void *  buf,
unsigned int  len 
)
inline

Update the digest from a buffer of data

Parameters
bufPointer to the data to be included in digest
lenLength of data in the buffer
Returns
True if success, false if finalize() was already called

References Hasher::updateInternal().

Referenced by Hasher::operator<<().

bool update ( const DataBlock data)
inline

Update the digest from the content of a DataBlock

Parameters
dataData to be included in digest
Returns
True if success, false if finalize() was already called

References DataBlock::data(), DataBlock::length(), and Hasher::updateInternal().

bool update ( const String str)
inline

Update the digest from the content of a String

Parameters
strString to be included in digest
Returns
True if success, false if finalize() was already called

References String::c_str(), String::length(), and Hasher::updateInternal().

virtual bool updateInternal ( const void *  buf,
unsigned int  len 
)
protectedpure virtual

Update the digest from a buffer of data

Parameters
bufPointer to the data to be included in digest
lenLength of data in the buffer
Returns
True if success, false if finalize() was already called

Implemented in SHA256, SHA1, and MD5.

Referenced by Hasher::update().


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