libxcks  0.1.0.1
libxcks::Whirlpool Class Referencefinal

Computes the Whirlpool hash from a byte stream. More...

#include <whirlpool.hpp>

Inheritance diagram for libxcks::Whirlpool:
Collaboration diagram for libxcks::Whirlpool:

Public Member Functions

 Whirlpool ()
 Default constructor. More...
 
void reset () override
 Resets the Whirlpool hash to initial state of computation. More...
 
uint8_t * getValue (uint8_t *buffer) const override
 Returns the Whirlpool hash value in the first 64 bytes of the given address. More...
 
size_t getSize () const override
 Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method. More...
 
void update (const uint8_t *buf, size_t len) override
 Updates the Whirlpool hash with specified array of bytes. More...
 
std::string getName () const override
 Returns the name of the checksum or the hash algorithm. More...
 
ChecksumAlgoId getID () const override
 Returns an unique identifier for the checksum or the hash algorithm. More...
 
- Public Member Functions inherited from libxcks::ChecksumEx
std::string toString (const bool hexInUpperCase=false) const override
 Returns the hash value has a string. More...
 
- Public Member Functions inherited from libxcks::Checksum
virtual ~Checksum ()
 Destructor. More...
 
virtual ArrayString getAltNames () const
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 

Static Public Member Functions

static std::string getHashName ()
 Returns the name of the hash algorithm. More...
 
static constexpr ChecksumAlgoId getIdentifier ()
 Returns an unique identifier for the hash algorithm. More...
 
static ChecksumgetNewInstance ()
 Gets a new instance of this class. More...
 
- Static Public Member Functions inherited from libxcks::Checksum
static ArrayString getAlternativeNames ()
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 

Protected Member Functions

void finish (uint8_t *const result)
 Process the remaining bytes in the internal buffer and the usual prolog according to the standard. More...
 
void process_buffer ()
 The core Whirlpool transform. More...
 

Protected Attributes

uint8_t bitLength [WHIRLPOOL_LENGTHBYTES]
 Global number of hashed bits (256-bit counter). More...
 
uint8_t buffer [WHIRLPOOL_WBLOCKBYTES]
 Buffer of data to hash. More...
 
int bufferBits
 Current number of bits on the buffer. More...
 
int bufferPos
 Current (possibly incomplete) byte slot on the buffer. More...
 
uint64_t hash [WHIRLPOOL_DIGESTQUADWORDS]
 The hashing state. More...
 

Static Protected Attributes

static const uint64_t C0 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C1 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C2 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C3 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C4 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C5 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C6 []
 Table used to compute the Whirlpool hash. More...
 
static const uint64_t C7 []
 Table used to compute the Whirlpool hash. More...
 
static const unsigned int R = 10u
 The number of rounds of the internal dedicated block cipher. More...
 
static const uint64_t rc []
 Table used to compute the Whirlpool hash. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from libxcks::ChecksumEx
static uint32_t swapOnLE (const uint32_t value)
 Swaps bytes on little endian architectures. More...
 
static uint32_t swapOnBE (const uint32_t value)
 Swaps bytes on big endian architectures. More...
 
static uint64_t swapOnLE (const uint64_t value)
 Swaps bytes on little endian architectures. More...
 
static uint64_t swapOnBE (const uint64_t value)
 Swaps bytes on big endian architectures. More...
 

Detailed Description

Computes the Whirlpool hash from a byte stream.

This class is a rewrite in C++ of the Whirlpool hash computing algorithm of the original C version written by Paulo S. L. M. Barreto and Vincent Rijmen. Please see the The WHIRLPOOL Hash Function web page for more informations.

Using this class in very simple:
Use the update method to provide to the class the bytes for computing the hash.

The Whirlpool hash value can be gotten by two ways:

The Whirlpool hash computing can be reseted by the reset method.

Definition at line 57 of file whirlpool.hpp.

Constructor & Destructor Documentation

◆ Whirlpool()

libxcks::Whirlpool::Whirlpool ( )

Default constructor.

Definition at line 600 of file whirlpool.cpp.

Member Function Documentation

◆ finish()

void libxcks::Whirlpool::finish ( uint8_t *const  result)
protected

Process the remaining bytes in the internal buffer and the usual prolog according to the standard.

Parameters
resultA buffer of 64 byte that will contain the final hash.

Definition at line 628 of file whirlpool.cpp.

◆ getHashName()

static std::string libxcks::Whirlpool::getHashName ( )
inlinestatic

Returns the name of the hash algorithm.

Returns
The name of the hash algorithm.

Definition at line 174 of file whirlpool.hpp.

◆ getID()

ChecksumAlgoId libxcks::Whirlpool::getID ( ) const
inlineoverridevirtual

Returns an unique identifier for the checksum or the hash algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getName() but it's only a convention.
Returns
An unique identifier for the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 164 of file whirlpool.hpp.

◆ getIdentifier()

static constexpr ChecksumAlgoId libxcks::Whirlpool::getIdentifier ( )
inlinestaticconstexpr

Returns an unique identifier for the hash algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getHashName() but it's only a convention.
Returns
An unique identifier for the hash algorithm.

Definition at line 188 of file whirlpool.hpp.

◆ getName()

std::string libxcks::Whirlpool::getName ( ) const
inlineoverridevirtual

Returns the name of the checksum or the hash algorithm.

Returns
The name of the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 150 of file whirlpool.hpp.

◆ getNewInstance()

static Checksum* libxcks::Whirlpool::getNewInstance ( )
inlinestatic

Gets a new instance of this class.

The caller is responsible of the deletion of the instance with the delete operator.

Returns
A new instance of this class.

Definition at line 201 of file whirlpool.hpp.

◆ getSize()

size_t libxcks::Whirlpool::getSize ( ) const
inlineoverridevirtual

Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.

Returns
The minimal size to allocate in memory to store the hash with the getValue(buffer) method.

Implements libxcks::Checksum.

Definition at line 120 of file whirlpool.hpp.

◆ getValue()

uint8_t * libxcks::Whirlpool::getValue ( uint8_t *  buffer) const
overridevirtual

Returns the Whirlpool hash value in the first 64 bytes of the given address.

Parameters
bufferThe buffer where the Whirlpool hash value will be stored.
Returns
The address of the buffer.
Remarks
On some systems it is required that buffer is correctly aligned for a 32 bits value.
The memory for the 64 bytes must have been allocated before calling this method.

Implements libxcks::Checksum.

Definition at line 1020 of file whirlpool.cpp.

◆ process_buffer()

void libxcks::Whirlpool::process_buffer ( )
protected

The core Whirlpool transform.

Definition at line 796 of file whirlpool.cpp.

◆ reset()

void libxcks::Whirlpool::reset ( )
overridevirtual

Resets the Whirlpool hash to initial state of computation.

Implements libxcks::ChecksumEx.

Definition at line 610 of file whirlpool.cpp.

◆ update()

void libxcks::Whirlpool::update ( const uint8_t *  buf,
size_t  len 
)
overridevirtual

Updates the Whirlpool hash with specified array of bytes.

Parameters
bufThe byte array to update the Whirlpool hash with.
lenThe number of bytes to use for the update.

Implements libxcks::Checksum.

Definition at line 687 of file whirlpool.cpp.

Member Data Documentation

◆ bitLength

uint8_t libxcks::Whirlpool::bitLength[WHIRLPOOL_LENGTHBYTES]
protected

Global number of hashed bits (256-bit counter).

Definition at line 70 of file whirlpool.hpp.

◆ buffer

uint8_t libxcks::Whirlpool::buffer[WHIRLPOOL_WBLOCKBYTES]
protected

Buffer of data to hash.

Definition at line 71 of file whirlpool.hpp.

◆ bufferBits

int libxcks::Whirlpool::bufferBits
protected

Current number of bits on the buffer.

Definition at line 72 of file whirlpool.hpp.

◆ bufferPos

int libxcks::Whirlpool::bufferPos
protected

Current (possibly incomplete) byte slot on the buffer.

Definition at line 73 of file whirlpool.hpp.

◆ C0

const uint64_t libxcks::Whirlpool::C0
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 77 of file whirlpool.hpp.

◆ C1

const uint64_t libxcks::Whirlpool::C1
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 78 of file whirlpool.hpp.

◆ C2

const uint64_t libxcks::Whirlpool::C2
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 79 of file whirlpool.hpp.

◆ C3

const uint64_t libxcks::Whirlpool::C3
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 80 of file whirlpool.hpp.

◆ C4

const uint64_t libxcks::Whirlpool::C4
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 81 of file whirlpool.hpp.

◆ C5

const uint64_t libxcks::Whirlpool::C5
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 82 of file whirlpool.hpp.

◆ C6

const uint64_t libxcks::Whirlpool::C6
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 83 of file whirlpool.hpp.

◆ C7

const uint64_t libxcks::Whirlpool::C7
staticprotected

Table used to compute the Whirlpool hash.

Definition at line 84 of file whirlpool.hpp.

◆ hash

uint64_t libxcks::Whirlpool::hash[WHIRLPOOL_DIGESTQUADWORDS]
protected

The hashing state.

Definition at line 74 of file whirlpool.hpp.

◆ R

const unsigned int libxcks::Whirlpool::R = 10u
staticprotected

The number of rounds of the internal dedicated block cipher.

Definition at line 87 of file whirlpool.hpp.

◆ rc

const uint64_t libxcks::Whirlpool::rc
staticprotected
Initial value:
= {
UINT64_C(0x0000000000000000),
UINT64_C(0x1823c6e887b8014f),
UINT64_C(0x36a6d2f5796f9152),
UINT64_C(0x60bc9b8ea30c7b35),
UINT64_C(0x1de0d7c22e4bfe57),
UINT64_C(0x157737e59ff04ada),
UINT64_C(0x58c9290ab1a06b85),
UINT64_C(0xbd5d10f4cb3e0567),
UINT64_C(0xe427418ba77d95d8),
UINT64_C(0xfbee7c66dd17479e),
UINT64_C(0xca2dbf07ad5a8333),
}

Table used to compute the Whirlpool hash.

Definition at line 88 of file whirlpool.hpp.


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