BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
Public Member Functions | Private Member Functions | Private Attributes | List of all members
KeccakCore Class Reference

Keccak core sponge function. More...

#include <KeccakCore.h>

Public Member Functions

 KeccakCore ()
 Constructs a new Keccak sponge function. More...
 
 ~KeccakCore ()
 Destroys this Keccak sponge function after clearing all sensitive information. More...
 
size_t capacity () const
 Returns the capacity of the sponge function in bits. More...
 
void setCapacity (size_t capacity)
 Sets the capacity of the Keccak sponge function in bits. More...
 
size_t blockSize () const
 Returns the input block size for the sponge function in bytes. More...
 
void reset ()
 Resets the Keccak sponge function ready for a new session. More...
 
void update (const void *data, size_t size)
 Updates the Keccak sponge function with more input data. More...
 
void pad (uint8_t tag)
 Pads the last block of input data to blockSize(). More...
 
void extract (void *data, size_t size)
 Extracts data from the Keccak sponge function. More...
 
void encrypt (void *output, const void *input, size_t size)
 Extracts data from the Keccak sponge function and uses it to encrypt a buffer. More...
 
void clear ()
 Clears all sensitive data from this object. More...
 
void setHMACKey (const void *key, size_t len, uint8_t pad, size_t hashSize)
 Sets a HMAC key for a Keccak-based hash algorithm. More...
 

Private Member Functions

void keccakp ()
 Transform the state with the KECCAK-p sponge function with b = 1600. More...
 

Private Attributes

struct {
   uint64_t   A [5][5]
 
   uint8_t   inputSize
 
   uint8_t   outputSize
 
state
 
uint8_t _blockSize
 

Detailed Description

Keccak core sponge function.

KeccakCore provides the core sponge function for different capacities. It is used to implement algorithms such as SHA3 and SHAKE.

References: http://en.wikipedia.org/wiki/SHA-3

See also
SHA3_256, SHAKE256

Definition at line 29 of file KeccakCore.h.

Constructor & Destructor Documentation

◆ KeccakCore()

KeccakCore::KeccakCore ( )

Constructs a new Keccak sponge function.

The capacity() will initially be set to 1536, which normally won't be of much use to the caller. The constructor should be followed by a call to setCapacity() to select the capacity of interest.

Definition at line 54 of file KeccakCore.cpp.

◆ ~KeccakCore()

KeccakCore::~KeccakCore ( )

Destroys this Keccak sponge function after clearing all sensitive information.

Definition at line 66 of file KeccakCore.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ blockSize()

size_t KeccakCore::blockSize ( ) const
inline

Returns the input block size for the sponge function in bytes.

The block size is (1600 - capacity()) / 8.

See also
capacity()

Definition at line 38 of file KeccakCore.h.

Here is the caller graph for this function:

◆ capacity()

size_t KeccakCore::capacity ( ) const

Returns the capacity of the sponge function in bits.

See also
setCapacity(), blockSize()

Definition at line 76 of file KeccakCore.cpp.

Here is the caller graph for this function:

◆ clear()

void KeccakCore::clear ( )

Clears all sensitive data from this object.

Definition at line 275 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt()

void KeccakCore::encrypt ( void *  output,
const void *  input,
size_t  size 
)

Extracts data from the Keccak sponge function and uses it to encrypt a buffer.

Parameters
outputThe output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer.
inputThe input buffer to read from.
sizeThe number of bytes to encrypt.

This function extracts data from the sponge function and then XOR's it with input to generate the output.

If more than blockSize() bytes are required, the sponge function will be invoked to generate additional data.

See also
update(), reset(), extract()

Definition at line 240 of file KeccakCore.cpp.

Here is the call graph for this function:

◆ extract()

void KeccakCore::extract ( void *  data,
size_t  size 
)

Extracts data from the Keccak sponge function.

Parameters
dataThe data buffer to fill with extracted data.
sizeThe number number of bytes of extracted data that are required.

If more than blockSize() bytes are required, the sponge function will be invoked to generate additional data.

See also
update(), reset(), encrypt()

Definition at line 194 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ keccakp()

void KeccakCore::keccakp ( )
private

Transform the state with the KECCAK-p sponge function with b = 1600.

Definition at line 324 of file KeccakCore.cpp.

Here is the caller graph for this function:

◆ pad()

void KeccakCore::pad ( uint8_t  tag)

Pads the last block of input data to blockSize().

Parameters
tagThe tag byte to add to the padding to identify SHA3 (0x06), SHAKE (0x1F), or the plain pre-standardized version of Keccak (0x01).

The sponge function will be invoked to process the completed padding block.

See also
update(), extract()

Definition at line 167 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void KeccakCore::reset ( )

Resets the Keccak sponge function ready for a new session.

See also
update(), extract()

Definition at line 114 of file KeccakCore.cpp.

Here is the caller graph for this function:

◆ setCapacity()

void KeccakCore::setCapacity ( size_t  capacity)

Sets the capacity of the Keccak sponge function in bits.

Parameters
capacityThe capacity of the Keccak sponge function in bits which should be a multiple of 64 and between 64 and 1536.
Note
It is possible to create a sponge function with this constructor that doesn't strictly conform with the capacity and hash size constraints defined in the relevant standards. It is the responsibility of callers to only use standard parameter combinations.
See also
capacity(), blockSize()

Definition at line 94 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHMACKey()

void KeccakCore::setHMACKey ( const void *  key,
size_t  len,
uint8_t  pad,
size_t  hashSize 
)

Sets a HMAC key for a Keccak-based hash algorithm.

Parameters
keyPoints to the HMAC key for the hashing process.
lenLength of the HMAC key in bytes.
padInner (0x36) or outer (0x5C) padding value to XOR with the formatted HMAC key.
hashSizeThe size of the output from the hash algorithm.

This function is intended to help classes implement Hash::resetHMAC() and Hash::finalizeHMAC() by directly formatting the HMAC key into the internal block buffer and resetting the hash.

Definition at line 293 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void KeccakCore::update ( const void *  data,
size_t  size 
)

Updates the Keccak sponge function with more input data.

Parameters
dataThe extra input data to incorporate.
sizeThe size of the new data to incorporate.

This function will invoke the sponge function whenever a full blockSize() bytes of input data have been accumulated. Call pad() after the last block to finalize the input before calling extract().

See also
pad(), extract(), reset()

Definition at line 133 of file KeccakCore.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _blockSize

uint8_t KeccakCore::_blockSize
private

Definition at line 58 of file KeccakCore.h.

◆ A

uint64_t KeccakCore::A[5][5]

Definition at line 54 of file KeccakCore.h.

◆ inputSize

uint8_t KeccakCore::inputSize

Definition at line 55 of file KeccakCore.h.

◆ outputSize

uint8_t KeccakCore::outputSize

Definition at line 56 of file KeccakCore.h.

◆ state

struct { ... } KeccakCore::state

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