libxcks  0.1.0.1
libxcks::AbstractKeccakImpl Class Reference

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

#include <keccak.hpp>

Inheritance diagram for libxcks::AbstractKeccakImpl:
Collaboration diagram for libxcks::AbstractKeccakImpl:

Public Member Functions

 AbstractKeccakImpl ()=delete
 Disable default constructor. More...
 
 AbstractKeccakImpl (const unsigned size, const bool isSHA3Hash=true)
 Constructs a new Keccak or SHA3 implementation with a hash of size bytes. More...
 
void reset () override final
 Resets the Keccak hash to initial value. More...
 
void update (const uint8_t *buf, size_t len) override final
 Updates the Keccak hash with specified array of bytes. 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 uint8_t * getValue (uint8_t *buffer) const =0
 Returns the checksum value in the first bytes of the given address. More...
 
virtual size_t getSize () const =0
 Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) method. More...
 
virtual std::string getName () const =0
 Returns the name of the checksum or the hash algorithm. More...
 
virtual ArrayString getAltNames () const
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 
virtual ChecksumAlgoId getID () const =0
 Returns an unique identifier for the checksum or the hash algorithm. More...
 

Protected Member Functions

void finish ()
 Process the remaining bytes in the internal buffer and the usual prolog according to the standard. More...
 

Protected Attributes

uint64_t saved
 The portion of the input message that we didn't consume yet. More...
 
uint64_t state [SHA3_KECCAK_SPONGE_WORDS]
 Keccak's state in 'words'. More...
 
unsigned byteIndex
 0..7–the next byte after the set one (starts from 0; 0–none are buffered). More...
 
unsigned wordIndex
 0..24–the next word to integrate input (starts from 0). More...
 
const unsigned capacityWords
 The double size of the hash output in words (e.g. 16 for Keccak 512). More...
 
const bool useSHA3Hash
 true if result is SHA3 hash, false if "original" Keccak hash. More...
 

Static Protected Attributes

static constexpr unsigned SHA3_KECCAK_SPONGE_WORDS = (1600 / 8) / sizeof(uint64_t)
 'Words' here refers to uint64_t More...
 

Additional Inherited Members

- Static Public Member Functions inherited from libxcks::Checksum
static ArrayString getAlternativeNames ()
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 
- 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 Keccak hash from a byte stream.

This class is a rewrite in C++ of the Keccak hash computing algorithm present in the SHA3IUF's GitHub repository.

This abstract class implements the Keccak and SHA3 hashes computing.

Definition at line 43 of file keccak.hpp.

Constructor & Destructor Documentation

◆ AbstractKeccakImpl() [1/2]

libxcks::AbstractKeccakImpl::AbstractKeccakImpl ( )
delete

Disable default constructor.

◆ AbstractKeccakImpl() [2/2]

libxcks::AbstractKeccakImpl::AbstractKeccakImpl ( const unsigned  size,
const bool  isSHA3Hash = true 
)

Constructs a new Keccak or SHA3 implementation with a hash of size bytes.

Default constructor.

Parameters
[in]sizeThe size of the hash in bytes.
[in]isSHA3Hashtrue if result is SHA3 hash, false if "original" Keccak hash.

Definition at line 45 of file keccak.cpp.

Member Function Documentation

◆ finish()

void libxcks::AbstractKeccakImpl::finish ( )
protected

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

Definition at line 220 of file keccak.cpp.

◆ reset()

void libxcks::AbstractKeccakImpl::reset ( )
finaloverridevirtual

Resets the Keccak hash to initial value.

Implements libxcks::ChecksumEx.

Definition at line 56 of file keccak.cpp.

◆ update()

void libxcks::AbstractKeccakImpl::update ( const uint8_t *  buf,
size_t  len 
)
finaloverridevirtual

Updates the Keccak hash with specified array of bytes.

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

Implements libxcks::Checksum.

Definition at line 69 of file keccak.cpp.

Member Data Documentation

◆ byteIndex

unsigned libxcks::AbstractKeccakImpl::byteIndex
protected

0..7–the next byte after the set one (starts from 0; 0–none are buffered).

Definition at line 51 of file keccak.hpp.

◆ capacityWords

const unsigned libxcks::AbstractKeccakImpl::capacityWords
protected

The double size of the hash output in words (e.g. 16 for Keccak 512).

Definition at line 53 of file keccak.hpp.

◆ saved

uint64_t libxcks::AbstractKeccakImpl::saved
protected

The portion of the input message that we didn't consume yet.

Definition at line 49 of file keccak.hpp.

◆ SHA3_KECCAK_SPONGE_WORDS

constexpr unsigned libxcks::AbstractKeccakImpl::SHA3_KECCAK_SPONGE_WORDS = (1600 / 8) / sizeof(uint64_t)
staticconstexprprotected

'Words' here refers to uint64_t

Definition at line 47 of file keccak.hpp.

◆ state

uint64_t libxcks::AbstractKeccakImpl::state[SHA3_KECCAK_SPONGE_WORDS]
protected

Keccak's state in 'words'.

Definition at line 50 of file keccak.hpp.

◆ useSHA3Hash

const bool libxcks::AbstractKeccakImpl::useSHA3Hash
protected

true if result is SHA3 hash, false if "original" Keccak hash.

Definition at line 54 of file keccak.hpp.

◆ wordIndex

unsigned libxcks::AbstractKeccakImpl::wordIndex
protected

0..24–the next word to integrate input (starts from 0).

Definition at line 52 of file keccak.hpp.


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