CXI
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Hash Class Reference

Computes hash values. More...

Inheritance diagram for Hash:
[legend]
Collaboration diagram for Hash:
[legend]

Public Member Functions

 Hash (void)
 
 Hash (int algo)
 
virtual ~Hash (void)
 
void init (int algo)
 
void update (const char *data, int len)
 
void update (const ByteArray &data)
 
void final (void)
 
- Public Member Functions inherited from ByteArray
 ByteArray (void)
 
 ByteArray (int len)
 
 ByteArray (const char *data, int len)
 
 ByteArray (const char *str)
 
 ByteArray (int val, int len)
 
 ByteArray (const ByteArray &ba)
 
virtual ~ByteArray (void)
 
void clear (void)
 
int length (void) const
 
char * get (void)
 
const char * get (void) const
 
void set (const char *data, int len)
 
void append (const char *data, int len)
 
void append (const ByteArray &ba)
 
void insert (const char *data, int len, int offset)
 
void fill (char value, int len, int offset)
 
int getInt (int def_val=0) const
 
void setInt (int val, int len)
 
void appendInt (int val, int len)
 
void getString (char *str, int max_size) const
 
void setString (const char *str)
 
void appendString (const char *str)
 
std::string toString (void) const
 
std::string toHexString (void) const
 
int compare (const ByteArray &ba) const
 
ByteArray sub (int offset, int len=-1) const
 
ByteArray lstrip (void) const
 
ByteArray rstrip (const std::set< char > &charsToBeStripped) const
 
void read (const char *filename)
 
void write (const char *filename) const
 
void xtrace (const char *text=0) const
 
ByteArrayoperator= (const ByteArray &ba)
 
const ByteArrayoperator+= (const ByteArray &ba)
 
const ByteArrayoperator|= (const ByteArray &ba)
 
const ByteArrayoperator^= (const ByteArray &ba)
 
char & operator[] (int idx)
 

Detailed Description

Computes hash values.

Note
The hash is calculated locally. In order to compute the hash on the CryptoServer use the cxi::Cxi::hash_compute method.

The following algorithms are support by this class (see Mechanism Parameter):

The following example illustrates the usage of the Hash class:

// create SHA-512 hash
Hash hash;
hash.update("We are what we ", 15);
hash.update("were waiting for", 16);
hash.final();
// dump hash value
hash.xtrace("hash");
void xtrace(const char *text=0) const
Definition: bytearray.cpp:611
Computes hash values.
Definition: sw/cxi_api_c/def/hash.h:19
void update(const char *data, int len)
Definition: hash.cpp:189
void init(int algo)
Definition: hash.cpp:99
void final(void)
Definition: hash.cpp:237
#define CXI_MECH_HASH_ALGO_SHA512
SHA512.
Definition: fw/cxi/def/cxi_defs.h:457

Constructor & Destructor Documentation

◆ Hash() [1/2]

Hash ( void  )

Default Constructor: create empty hash. The hash is still unspecified and has to be initialized.

◆ Hash() [2/2]

Hash ( int  algo)

Overloaded Constructor: creates and initializes hash.

◆ ~Hash()

~Hash ( void  )
virtual

Destructor: frees hash resources

Member Function Documentation

◆ init()

void init ( int  algo)

Initializes hash class

Exceptions
cxi::Exceptionif algo parameter is not allowed or memory allocation fails

◆ update() [1/2]

void update ( const char *  data,
int  len 
)

Updates a hash calculation.

Parameters
datadata to be hashed
lenlength of data to be hashed
Exceptions
cxi::Exceptionif hash wasn't initialized or already finalized

◆ update() [2/2]

void update ( const ByteArray data)

Updates a hash calculation.

Parameters
datadata to be hashed
Exceptions
cxi::Exceptionif hash wasn't initialized or already finalized

◆ final()

void final ( void  )

Finalizes a hash calculation.

Exceptions
cxi::Exceptionif hash wasn't initialized or already finalized
Note
no further operation (update, final) is allowed after having finalized the hash.