Sponge Class Reference

#include <sponge.h>

Inheritance diagram for Sponge:

Inheritance graph
[legend]
Collaboration diagram for Sponge:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Sponge (Transformation *aF, unsigned int aCapacity)
void absorb (const UINT8 *input, unsigned int lengthInBits)
virtual void pad ()
void squeeze (UINT8 *output, unsigned int desiredLengthInBits)
unsigned int getCapacity ()
unsigned int getRate ()
virtual string getDescription () const

Protected Member Functions

void padCurrentBlock (unsigned int desiredLengthFactor)
void absorbCurrentBlock ()
void flushAndSwitchToSqueezingPhase ()
void squeezeIntoCurrentBlock ()

Protected Attributes

Transformationf
unsigned int capacity
unsigned int rate
bool squeezing
bool validInput
auto_ptr< UINT8state
deque< UINT8currentBlock
unsigned int bitsInCurrentBlock

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 capacity and the function width can have any value, provided that the rate is a multiple of 8 bits.


Constructor & Destructor Documentation

Sponge::Sponge ( Transformation aF,
unsigned int  aCapacity 
)

The constructor. The transformation and capacity are given to the constructor, while the rate is computed from the function width and the requested capacity. The rate must be a multiple of 8. The sponge construction is set to the absorbing phase.

Parameters:
aF A pointer to the transformation used in the sponge construction.
aCapacity The desired value of the capacity.


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. The last incomplete block is kept in attribute currentBlock.

Precondition:
This function must be used in the absorbing phase only.
Parameters:
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::pad (  )  [virtual]

Method to pad the data absorbed so far. By default, it calls padCurrentBlock(rate), but it can be overridden to provide other valid padding methods.

Precondition:
This function must be used in the absorbing phase only.

Reimplemented in Keccak.

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:
output The buffer where to store the squeezed data.
desiredLengthInBits The length in bits of the output. It must be a multiple of 8.

unsigned int Sponge::getCapacity (  ) 

Method that returns the capacity of the sponge function.

unsigned int Sponge::getRate (  ) 

Method that returns the rate of the sponge function.

string Sponge::getDescription (  )  const [virtual]

Method that returns a string with a description of itself.

Reimplemented in Keccak.

void Sponge::padCurrentBlock ( unsigned int  desiredLengthFactor  )  [protected]

Internal method to pad the data absorbed so far, by applying the simple padding. It appends a single bit 1, then the smallest number of bits 0 such that the data absorbed so far have a length that is a multiple of desiredLengthFactor.

Parameters:
desiredLengthFactor The number of bits that divides the length of currentBlock after padding. It must be a strictly positive multiple of 8, and it must divide rate.
Precondition:
This function must be used in the absorbing phase only.

desiredLengthFactor must be a strictly positive multiple of 8, and it must divide rate.

void Sponge::absorbCurrentBlock (  )  [protected]

Internal method that does the actual absorbing of the whole block in currentBlock. This method is called only when bitsInCurrentBlock is equal to the rate.

void Sponge::flushAndSwitchToSqueezingPhase (  )  [protected]

Internal method that absorbs the data still in currentBlock, and then switches the sponge function to the squeezing phase.

void Sponge::squeezeIntoCurrentBlock (  )  [protected]

Internal method that does the actual squeezing and stores the whole squeezed block into currentBlock.


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

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.

unsigned int Sponge::capacity [protected]

The capacity of the sponge construction.

unsigned int Sponge::rate [protected]

The rate of the sponge construction.

bool Sponge::squeezing [protected]

Boolean indicating whether the sponge is in the squeezing phase (true) or in the absorbing phase (false).

bool Sponge::validInput [protected]

Boolean indicating whether a valid sponge input has been absorbed.

auto_ptr<UINT8> Sponge::state [protected]

The state of the sponge construction.

deque<UINT8> Sponge::currentBlock [protected]

Buffer containing the partial block before it is absorbed or the partial block that is being squeezed.

unsigned int Sponge::bitsInCurrentBlock [protected]

Number of bits in currentBlock.


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

Generated on Thu Jun 17 18:20:50 2010 for KeccakTools by  doxygen 1.5.6