KeccakTools

KeccakF Class Reference

#include <Keccak-f.h>

Inheritance diagram for KeccakF:
Collaboration diagram for KeccakF:

List of all members.

Public Member Functions

 KeccakF (unsigned int aWidth, unsigned int aNrRounds=0)
unsigned int getWidth () const
unsigned int getLaneSize () const
void operator() (UINT8 *state) const
void inverse (UINT8 *state) const
string getDescription () const
virtual string getName () const
string buildFileName (const string &prefix, const string &suffix) const
template<class Lane >
void forward (vector< Lane > &state) const
template<class Lane >
void inverse (vector< Lane > &state) const
template<class Lane >
void round (vector< Lane > &A, unsigned int roundNumber) const
template<class Lane >
void inverseRound (vector< Lane > &A, unsigned int roundNumber) const
template<class Lane >
void chi (vector< Lane > &A) const
template<class Lane >
void inverseChi (vector< Lane > &A) const
template<class Lane >
void theta (vector< Lane > &A) const
template<class Lane >
void inverseTheta (vector< Lane > &A) const
template<class Lane >
void pi (vector< Lane > &A) const
template<class Lane >
void inversePi (vector< Lane > &A) const
template<class Lane >
void rho (vector< Lane > &A) const
unsigned int rho (unsigned int x, unsigned int y, unsigned int z) const
template<class Lane >
void inverseRho (vector< Lane > &A) const
unsigned int inverseRho (unsigned int x, unsigned int y, unsigned int z) const
template<class Lane >
void iota (vector< Lane > &A, unsigned int roundNumber) const
template<class Lane >
void ROL (Lane &L, int offset) const
void ROL (LaneValue &L, int offset) const
void fromBytesToLanes (const UINT8 *in, vector< LaneValue > &out) const
void fromLanesToBytes (const vector< LaneValue > &in, UINT8 *out) const
string bitName (const string &prefix, unsigned int x, unsigned int y, unsigned int z) const

Static Public Member Functions

static unsigned int index (int x, int y)
static unsigned int getX (unsigned int index)
static unsigned int getY (unsigned int index)
static unsigned int index (int x)
static void pi (unsigned int x, unsigned int y, unsigned int &X, unsigned int &Y)
static void inversePi (unsigned int X, unsigned int Y, unsigned int &x, unsigned int &y)
static string buildBitName (const string &prefixSymbol, unsigned int laneSize, unsigned int z)
static string laneName (const string &prefix, unsigned int x, unsigned int y)
static string sheetName (const string &prefix, unsigned int x)

Protected Attributes

unsigned int width
unsigned int laneSize
unsigned int nominalNrRounds
unsigned int nrRounds
vector< int > rhoOffsets
vector< LaneValueroundConstants
LaneValue mask

Detailed Description

Class implementing the 7 Keccak-f permutations, as well as their inverses.


Constructor & Destructor Documentation

KeccakF::KeccakF ( unsigned int  aWidth,
unsigned int  aNrRounds = 0 
)

The constructor. The width and number of rounds are given to the constructor. If omitted or set to zero, nrRounds is set to nominalNrRounds.

Parameters:
aWidthThe width of the Keccak-f permutation. It must be one of the valid Keccak-f widths, namely 25, 50, 100, 200, 400, 800 or 1600.
aNrRoundsThe desired number of rounds. By omitting or setting this parameter to 0, the nominal number of rounds is taken.

Member Function Documentation

string KeccakF::bitName ( const string &  prefix,
unsigned int  x,
unsigned int  y,
unsigned int  z 
) const

Method that constructs a variable name for a particular bit in the state. The resulting variable name consists of the prefix, a consonant coding the y coordinate, a vowel coding the x coordinate and finally a digit (or pair of digits) coding the z coordinate (using buildBitName(), i.e., if the lane size is greater than 1). This naming convention is such that the alphabetic order is also the bit ordering for the message input at sponge level.

Parameters:
prefixThe name prefix.
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
string KeccakF::buildBitName ( const string &  prefixSymbol,
unsigned int  laneSize,
unsigned int  z 
) [static]

Function that appends the z coordinate to the given prefix. If the lane size is 1, the z coordinate is not appended. If the lane size is at most 10, the z coordinate is appended using one digit. Otherwise, the z coordinate is appended using two digits.

Parameters:
prefixSymbolThe name prefix.
laneSizeThe lane size.
zThe z coordinate.
string KeccakF::buildFileName ( const string &  prefix,
const string &  suffix 
) const

Method that builds a file name by prepending a prefix and appending a suffix to getName().

template<class Lane >
void KeccakF::chi ( vector< Lane > &  A) const

Template method that applies χ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
template<class Lane >
void KeccakF::forward ( vector< Lane > &  state) const

Template method that applies the permutation. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
stateThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
void KeccakF::fromBytesToLanes ( const UINT8 in,
vector< LaneValue > &  out 
) const

Method that converts a state given as an array of bytes into a vector of lanes in 64-bit words.

Parameters:
inThe state as an array of bytes. The array in must have a size of at least ceil(getWidth()/8.0) bytes.
outThe state as a vector of lanes. It will be resized to 25 if necessary.
void KeccakF::fromLanesToBytes ( const vector< LaneValue > &  in,
UINT8 out 
) const

Method that converts a vector of lanes in 64-bit words into a state given as an array of bytes.

Parameters:
inThe state as a vector of lanes. in.size() must be equal to 25.
outThe state as an array of bytes. The array out must have a size of at least ceil(getWidth()/8.0) bytes.
string KeccakF::getDescription ( ) const [virtual]

Method that returns a string describing the instance of the Keccak-f permutation.

Implements Transformation.

Reimplemented in KeccakFDCLC.

unsigned int KeccakF::getLaneSize ( ) const

Method that retuns the lane size of the Keccak-f instance.

string KeccakF::getName ( ) const [virtual]

Method that returns a short string that uniquely identifies the Keccak-f instance.

Reimplemented in KeccakFCodeGen, and KeccakFDCLC.

unsigned int KeccakF::getWidth ( ) const [virtual]

Method that returns the number of bits of its domain and range.

Implements Transformation.

static unsigned int KeccakF::getX ( unsigned int  index) [inline, static]

Method that extracts the x coordinate from a lane numbered according to the index() method.

Parameters:
indexThe index of a lane, between 0 and 24.
static unsigned int KeccakF::getY ( unsigned int  index) [inline, static]

Method that extracts the y coordinate from a lane numbered according to the index() method.

Parameters:
indexThe index of a lane, between 0 and 24.
unsigned int KeccakF::index ( int  x,
int  y 
) [static]

Method that maps the coordinates (x, y) onto the lanes numbered from 0 to 24. The formula is (x mod 5)+5*(y mod 5), so that the lanes are ordered in line with the bit ordering defined in the specifications.

Parameters:
xThe x coordinate. It can be any signed integer, as it will be reduced modulo 5.
yThe y coordinate. It can be any signed integer, as it will be reduced modulo 5.
unsigned int KeccakF::index ( int  x) [static]

Method that reduces modulo 5 the coordinate x expressed as a signed integer.

Parameters:
xThe x coordinate. It can be any signed integer, as it will be reduced modulo 5.
void KeccakF::inverse ( UINT8 state) const [virtual]

Method that applies the inverse of the Keccak-f permutation onto the parameter state.

Implements Permutation.

template<class Lane >
void KeccakF::inverse ( vector< Lane > &  state) const

Template method that applies the inverse permutation. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
stateThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
template<class Lane >
void KeccakF::inverseChi ( vector< Lane > &  A) const

Template method that applies the inverse of χ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
template<class Lane >
void KeccakF::inversePi ( vector< Lane > &  A) const

Template method that applies the inverse of π. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
void KeccakF::inversePi ( unsigned int  X,
unsigned int  Y,
unsigned int &  x,
unsigned int &  y 
) [static]

Method that applies the inverse π coordinate transformation to a lane position (X,Y).

Parameters:
[in]XThe input coordinate x.
[in]YThe input coordinate y.
[out]xThe output coordinate x.
[out]yThe output coordinate y.
template<class Lane >
void KeccakF::inverseRho ( vector< Lane > &  A) const

Template method that applies the inverse of ρ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
unsigned int KeccakF::inverseRho ( unsigned int  x,
unsigned int  y,
unsigned int  z 
) const [inline]

Method that applies the inverse ρ coordinate transformation to a bit position (x,y,z).

Parameters:
[in]xThe input coordinate x.
[in]yThe input coordinate y.
[in]zThe input coordinate z.
Returns:
The output coordinate z.
template<class Lane >
void KeccakF::inverseRound ( vector< Lane > &  A,
unsigned int  roundNumber 
) const

Template method that applies the inverse of the round function. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
roundNumberThe round number, from 0 to nrRounds - 1.
template<class Lane >
void KeccakF::inverseTheta ( vector< Lane > &  A) const

Template method that applies the inverse of θ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
template<class Lane >
void KeccakF::iota ( vector< Lane > &  A,
unsigned int  roundNumber 
) const

Template method that applies ι, which is its own inverse. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
roundNumberThe round number, from 0 to nrRounds - 1.
string KeccakF::laneName ( const string &  prefix,
unsigned int  x,
unsigned int  y 
) [static]

Method that constructs a variable name for a particular lane in the state. The resulting variable name consists of the prefix, a consonant coding the y coordinate and a vowel coding the x coordinate.

Parameters:
prefixThe name prefix.
xThe x coordinate.
yThe y coordinate.
void KeccakF::operator() ( UINT8 state) const [virtual]

Method that applies the Keccak-f permutation onto the parameter state.

Implements Transformation.

template<class Lane >
void KeccakF::pi ( vector< Lane > &  A) const

Template method that applies π. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
void KeccakF::pi ( unsigned int  x,
unsigned int  y,
unsigned int &  X,
unsigned int &  Y 
) [static]

Method that applies the π coordinate transformation to a lane position (x,y).

Parameters:
[in]xThe input coordinate x.
[in]yThe input coordinate y.
[out]XThe output coordinate x.
[out]YThe output coordinate y.
template<class Lane >
void KeccakF::rho ( vector< Lane > &  A) const

Template method that applies ρ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
unsigned int KeccakF::rho ( unsigned int  x,
unsigned int  y,
unsigned int  z 
) const [inline]

Method that applies the ρ coordinate transformation to a bit position (x,y,z).

Parameters:
[in]xThe input coordinate x.
[in]yThe input coordinate y.
[in]zThe input coordinate z.
Returns:
The output coordinate z.
void KeccakF::ROL ( LaneValue L,
int  offset 
) const

Method that implementats ROL when the lane is in a 64-bit word LaneValue.

Parameters:
LThe given lane.
offsetThe translation offset. It can be any signed integer, as it will be reduced modulo laneSize.
template<class Lane >
void KeccakF::ROL ( Lane &  L,
int  offset 
) const

Template method that translates a lane along the z-axis. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
LThe given lane.
offsetThe translation offset. It can be any signed integer, as it will be reduced modulo laneSize.
template<class Lane >
void KeccakF::round ( vector< Lane > &  A,
unsigned int  roundNumber 
) const

Template method that applies the round function. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.
roundNumberThe round number, from 0 to nrRounds - 1.
string KeccakF::sheetName ( const string &  prefix,
unsigned int  x 
) [static]

Method that constructs a variable name for a particular sheet in the state. The resulting variable name consists of the prefix and a vowel coding the x coordinate.

Parameters:
prefixThe name prefix.
xThe x coordinate.
template<class Lane >
void KeccakF::theta ( vector< Lane > &  A) const

Template method that applies θ. This function is a template to allow both numerical and symbolic values to be processed (see also KeccakFEquations).

Parameters:
AThe given state is organized as a vector of 25 lanes. The mapping between the coordinates (x, y) and the numbering inside the vector is defined by index(). The parameter type Lane can be a LaneValue for an actual evaluation.

Member Data Documentation

unsigned int KeccakF::laneSize [protected]

The size of the lanes.

LaneValue KeccakF::mask [protected]

A 64-bit word whose first laneSize bits are 1 and all others 0.

unsigned int KeccakF::nominalNrRounds [protected]

The nominal number of rounds, as function of the width.

unsigned int KeccakF::nrRounds [protected]

The actual number of rounds (for experiments on reduced-round version).

vector<int> KeccakF::rhoOffsets [protected]

The translation offsets for ρ.

vector<LaneValue> KeccakF::roundConstants [protected]

The round constants for ι.

unsigned int KeccakF::width [protected]

The width of the permutation.


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