KeccakTools

Sponge Class Reference

#include <sponge.h>

Inheritance diagram for Sponge:
Collaboration diagram for Sponge:

List of all members.

Public Member Functions

 Sponge (const Transformation *aF, const PaddingRule *aPad, unsigned int aRate)
void reset ()
void absorb (const UINT8 *input, unsigned int lengthInBits)
void absorb (const vector< UINT8 > &input, unsigned int lengthInBits)
void squeeze (UINT8 *output, unsigned int desiredLengthInBits)
void squeeze (vector< 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 Transformationf
const PaddingRulepad
unsigned int capacity
unsigned int rate
bool squeezing
auto_ptr< UINT8state
MessageQueue absorbQueue
deque< UINT8squeezeBuffer

Friends

ostream & operator<< (ostream &a, const Sponge &sponge)

Detailed Description

Class implementing the sponge construction. This class uses a given transformation (inherited from class Transformation or Permutation). The following restrictions are made:

  • the input message can have any length (not necessarily a multiple of 8), but all calls to absorb() except the last one must give a multiple of 8 bits;
  • if the rate is a multiple of 8, the output stream can be given per byte only;
  • if the rate is not a multiple of 8, the output stream can be given per whole blocks only.

Constructor & Destructor Documentation

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.

Parameters:
aFA pointer to the transformation used in the sponge construction.
aPadA pointer to the padding rule used in the sponge construction.
aRateThe desired value of the rate (in bits), not necessarily a multiple of 8.

Member Function Documentation

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.

Precondition:
This function must be used in the absorbing phase only.
Parameters:
inputThe 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.
lengthInBitsThe 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::absorb ( const vector< 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.

Precondition:
This function must be used in the absorbing phase only.
Parameters:
inputThe 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.
lengthInBitsThe 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.

Parameters:
blockA 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, and ReducedRoundKeccak.

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.

Parameters:
outputThe buffer where to store the squeezed data.
desiredLengthInBitsThe 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::squeeze ( vector< 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.

Parameters:
outputThe buffer where to store the squeezed data.
desiredLengthInBitsThe 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.


Friends And Related Function Documentation

ostream& operator<< ( ostream &  a,
const Sponge sponge 
) [friend]

Method that prints a brief description of the sponge function.


Member Data Documentation

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.


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