Arduino Cryptography Library
Public Member Functions | 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.
 
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.
 
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...
 

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.

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.


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