SHA1 / SHA256 and HMAC-SHA1 / HMAC-SHA256 Hash library
SHA1 / SHA256 and HMAC-SHA1 / HMACSHA256 Hash library
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Sha1Class Class Reference

#include <sha1.h>

+ Inheritance diagram for Sha1Class:

Classes

union  _buffer
 
union  _state
 

Public Member Functions

void init (void)
 
void initHmac (const uint8_t *secret, int secretLength)
 
uint8_t * result (void)
 
uint8_t * resultHmac (void)
 
virtual size_t write (uint8_t)
 
size_t write_L (const char *str)
 
size_t write_L (const uint8_t *buffer, size_t size)
 
size_t print (const char *str)
 
double millis ()
 
virtual size_t write (uint8_t)
 

Private Member Functions

void pad ()
 
void addUncounted (uint8_t data)
 
void hashBlock ()
 
uint32_t rol32 (uint32_t number, uint8_t bits)
 

Private Attributes

_buffer buffer
 
uint8_t bufferOffset
 
_state state
 
uint32_t byteCount
 
uint8_t keyBuffer [BLOCK_LENGTH]
 
uint8_t innerHash [HASH_LENGTH]
 
timeval tv
 

Member Function Documentation

void Sha1Class::init ( void  )

Initialized the SHA1 process Set the counter and buffers

void Sha1Class::initHmac ( const uint8_t *  secret,
int  secretLength 
)

initializes the HMAC process for SHA-1

Parameters
secretThe key to be used
secretLengthThe length of the key
uint8_t * Sha1Class::result ( void  )

Pads the last block and finalizes the hash.

Returns
returns the hash
uint8_t * Sha1Class::resultHmac ( void  )

Pads the last block and finalizes the hash.

Returns
returns the hash
size_t Sha1Class::write ( uint8_t  data)
virtual

Adds data to the buffer. Also increases the byteCount variable

size_t Sha1Class::write_L ( const char *  str)

Adds the str to the buffer Calles function in order to add the data into the buffer.

Parameters
strThe string to be added
Note
Print class does not exist in linux, so we define it here using
#if defined(SHA1_LINUX)
size_t Sha1Class::write_L ( const uint8_t *  buffer,
size_t  size 
)

Adds the string to the buffer Calles function in order to add the data into the buffer.

Parameters
*bufferThe string to be added
*sizeThe size of the string
Note
Print class does not exist in linux, so we define it here using
#if defined(SHA1_LINUX)
size_t Sha1Class::print ( const char *  str)

Adds the str to the buffer Calles functions in order to add the data into the buffer.

Parameters
strThe string to be added
Note
Print class does not exist in linux, so we define it here using
#if defined(SHA1_LINUX)
double Sha1Class::millis ( )

used in linux in order to retrieve the time in milliseconds.

Returns
returns the milliseconds in a double format.
virtual size_t Sha1Class::write ( uint8_t  )
virtual

Adds data to the buffer. Also increases the byteCount variable

void Sha1Class::pad ( )
private

Implement SHA-1 padding (fips180-2 ยง5.1.1). Pad with 0x80 followed by 0x00 until the end of the block

void Sha1Class::addUncounted ( uint8_t  data)
private

adds the data to the buffer

Parameters
data
void Sha1Class::hashBlock ( )
private

Hash a single block of data

uint32_t Sha1Class::rol32 ( uint32_t  number,
uint8_t  bits 
)
private

rol32 - rotate a 32-bit value left

Parameters
numbervalue to rotate
bitsbits to roll

Member Data Documentation

_buffer Sha1Class::buffer
private

hold the buffer for the hashing process

uint8_t Sha1Class::bufferOffset
private

indicates the position on the buffer

_state Sha1Class::state
private

identical structure with buffer

uint32_t Sha1Class::byteCount
private

Byte counter in order to initialize the hash process for a block

uint8_t Sha1Class::keyBuffer[BLOCK_LENGTH]
private

Hold the key for the HMAC process

uint8_t Sha1Class::innerHash[HASH_LENGTH]
private

holds the inner hash for the HMAC process

timeval Sha1Class::tv
private

hold the time value on linux machines (ex Raspberry Pi)