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 | 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... | |
Keccak core sponge function.
KeccakCore provides the core sponge function for different capacities. It is used to implement Hash algorithms such as SHA3.
References: http://en.wikipedia.org/wiki/SHA-3
Definition at line 29 of file KeccakCore.h.
| 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.
|
inline |
Returns the input block size for the sponge function in bytes.
The block size is (1600 - capacity()) / 8.
Definition at line 38 of file KeccakCore.h.
| size_t KeccakCore::capacity | ( | ) | const |
Returns the capacity of the sponge function in bits.
Definition at line 76 of file KeccakCore.cpp.
| void KeccakCore::extract | ( | void * | data, |
| size_t | size | ||
| ) |
Extracts data from the Keccak sponge function.
| data | The data buffer to fill with extracted data. |
| size | The 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.
Definition at line 194 of file KeccakCore.cpp.
| void KeccakCore::pad | ( | uint8_t | tag | ) |
Pads the last block of input data to blockSize().
| tag | The 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.
Definition at line 167 of file KeccakCore.cpp.
| void KeccakCore::reset | ( | ) |
Resets the Keccak sponge function ready for a new session.
Definition at line 114 of file KeccakCore.cpp.
| void KeccakCore::setCapacity | ( | size_t | capacity | ) |
Sets the capacity of the Keccak sponge function in bits.
| capacity | The capacity of the Keccak sponge function in bits which should be a multiple of 64 and between 64 and 1536. |
Definition at line 94 of file KeccakCore.cpp.
| 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.
| key | Points to the HMAC key for the hashing process. |
| len | Length of the HMAC key in bytes. |
| pad | Inner (0x36) or outer (0x5C) padding value to XOR with the formatted HMAC key. |
| hashSize | The 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 243 of file KeccakCore.cpp.
| void KeccakCore::update | ( | const void * | data, |
| size_t | size | ||
| ) |
Updates the Keccak sponge function with more input data.
| data | The extra input data to incorporate. |
| size | The 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().
Definition at line 133 of file KeccakCore.cpp.
1.8.6