KeccakTools
|
#include <sponge.h>
Public Member Functions | |
Sponge (const Transformation *aF, const PaddingRule *aPad, unsigned int aRate) | |
void | reset () |
void | absorb (const UINT8 *input, unsigned int lengthInBits) |
void | squeeze (UINT8 *output, unsigned int desiredLengthInBits) |
unsigned int | getCapacity () |
unsigned int | getRate () |
virtual string | getDescription () const |
Protected Member Functions | |
void | absorbBlock (const vector< UINT8 > &block) |
void | flushAndSwitchToSqueezingPhase () |
void | squeezeIntoBuffer () |
void | fromStateToSqueezeBuffer () |
Protected Attributes | |
const Transformation * | f |
const PaddingRule * | pad |
unsigned int | capacity |
unsigned int | rate |
bool | squeezing |
auto_ptr< UINT8 > | state |
MessageQueue | absorbQueue |
deque< UINT8 > | squeezeBuffer |
Friends | |
ostream & | operator<< (ostream &a, const Sponge &sponge) |
Class implementing the sponge construction. This class uses a given transformation (inherited from class Transformation or Permutation). The following restrictions are made:
Sponge::Sponge | ( | const Transformation * | aF, |
const PaddingRule * | aPad, | ||
unsigned int | aRate | ||
) |
The constructor. The transformation, padding rule and rate are given to the constructor, while the capacity is computed from the function width and the requested rate. The sponge construction is set to the absorbing phase.
aF | A pointer to the transformation used in the sponge construction. |
aPad | A pointer to the padding rule used in the sponge construction. |
aRate | The desired value of the rate (in bits), not necessarily a multiple of 8. |
void Sponge::absorb | ( | const UINT8 * | input, |
unsigned int | lengthInBits | ||
) |
Method that absorbs data. The data is given as a sequence of bytes. Within each byte, the bits are understood to be ordered from the least significant bit to the most significant bit.
input | The data to absorb. When lengthInBits is not a multiple of 8, the last bits of data must be in the least significant bits of the last byte. |
lengthInBits | The length in bits of the data provided in input. When lengthInBits is not a multiple of 8, this function can no longer be used. |
void Sponge::absorbBlock | ( | const vector< UINT8 > & | block | ) | [protected] |
Internal method that does the actual absorbing of the whole block in block.
block | A block to absorb. |
void Sponge::flushAndSwitchToSqueezingPhase | ( | ) | [protected] |
Internal method that absorbs the data still in absorbQueue, and then switches the sponge function to the squeezing phase.
void Sponge::fromStateToSqueezeBuffer | ( | ) | [protected] |
Internal method that copies a block from state to squeezeBuffer.
unsigned int Sponge::getCapacity | ( | ) |
Method that returns the capacity of the sponge function.
string Sponge::getDescription | ( | ) | const [virtual] |
Method that returns a string with a description of itself.
Reimplemented in Keccak.
unsigned int Sponge::getRate | ( | ) |
Method that returns the rate of the sponge function.
void Sponge::reset | ( | ) |
Method to reset the sponge to the initial state.
void Sponge::squeeze | ( | UINT8 * | output, |
unsigned int | desiredLengthInBits | ||
) |
Method to extract data from the squeezing phase. If in the absorbing phase, this function also switches to the squeezing phase.
output | The buffer where to store the squeezed data. |
desiredLengthInBits | The length in bits of the output. If the rate of the sponge is a multiple of 8, desiredOutputLength must be a multiple of 8. Otherwise, desiredOutputLength must be equal to the rate. |
void Sponge::squeezeIntoBuffer | ( | ) | [protected] |
Internal method that does the actual squeezing and stores the whole squeezed block into squeezeBuffer.
ostream& operator<< | ( | ostream & | a, |
const Sponge & | sponge | ||
) | [friend] |
Method that prints a brief description of the sponge function.
MessageQueue Sponge::absorbQueue [protected] |
The message blocks not yet absorbed.
unsigned int Sponge::capacity [protected] |
The capacity of the sponge construction.
const Transformation* Sponge::f [protected] |
The transformation (or permutation) used by the sponge construction. The memory allocated by f is assumed to belong to the caller; this class does not free the allocated memory.
const PaddingRule* Sponge::pad [protected] |
The padding rule used by the sponge construction. The memory allocated by pad is assumed to belong to the caller; this class does not free the allocated memory.
unsigned int Sponge::rate [protected] |
The rate of the sponge construction.
deque<UINT8> Sponge::squeezeBuffer [protected] |
Buffer containing the partial block that is being squeezed.
bool Sponge::squeezing [protected] |
Boolean indicating whether the sponge is in the squeezing phase (true) or in the absorbing phase (false).
auto_ptr<UINT8> Sponge::state [protected] |
The state of the sponge construction.