KeccakTools
|
#include <Keccak-f.h>
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 (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< LaneValue > | roundConstants |
LaneValue | mask |
Class implementing the 7 Keccak-f permutations, as well as their inverses.
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.
aWidth | The 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. |
aNrRounds | The desired number of rounds. By omitting or setting this parameter to 0, the nominal number of rounds is taken. |
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.
prefix | The name prefix. |
x | The x coordinate. |
y | The y coordinate. |
z | The 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.
prefixSymbol | The name prefix. |
laneSize | The lane size. |
z | The 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().
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).
A | The 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::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).
state | The 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. |
Method that converts a state given as an array of bytes into a vector of lanes in 64-bit words.
in | The state as an array of bytes. The array in must have a size of at least ceil(getWidth()/8.0) bytes. |
out | The state as a vector of lanes. It will be resized to 25 if necessary. |
Method that converts a vector of lanes in 64-bit words into a state given as an array of bytes.
in | The state as a vector of lanes. in.size() must be equal to 25. |
out | The 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.
index | The 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.
index | The 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.
x | The x coordinate. It can be any signed integer, as it will be reduced modulo 5. |
y | The 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.
x | The 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.
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).
state | The 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::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).
A | The 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 | ( | 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).
A | The 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).
[in] | X | The input coordinate x. |
[in] | Y | The input coordinate y. |
[out] | x | The output coordinate x. |
[out] | y | The output coordinate y. |
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).
A | The 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).
[in] | x | The input coordinate x. |
[in] | y | The input coordinate y. |
[in] | z | The input coordinate z. |
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).
A | The 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. |
roundNumber | The round number, from 0 to nrRounds - 1. |
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).
A | The 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::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).
A | The 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. |
roundNumber | The 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.
prefix | The name prefix. |
x | The x coordinate. |
y | The y coordinate. |
void KeccakF::operator() | ( | UINT8 * | state | ) | const [virtual] |
Method that applies the Keccak-f permutation onto the parameter state.
Implements Transformation.
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).
A | The 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).
[in] | x | The input coordinate x. |
[in] | y | The input coordinate y. |
[out] | X | The output coordinate x. |
[out] | Y | The output coordinate y. |
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).
A | The 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).
[in] | x | The input coordinate x. |
[in] | y | The input coordinate y. |
[in] | z | The input coordinate z. |
void KeccakF::ROL | ( | LaneValue & | L, |
int | offset | ||
) | const |
Method that implementats ROL when the lane is in a 64-bit word LaneValue.
L | The given lane. |
offset | The translation offset. It can be any signed integer, as it will be reduced modulo laneSize. |
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).
L | The given lane. |
offset | The translation offset. It can be any signed integer, as it will be reduced modulo laneSize. |
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).
A | The 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. |
roundNumber | The 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.
prefix | The name prefix. |
x | The x coordinate. |
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).
A | The 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::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.