KeccakTools

KeccakFCodeGen Class Reference

#include <Keccak-fCodeGen.h>

Inheritance diagram for KeccakFCodeGen:
Collaboration diagram for KeccakFCodeGen:

List of all members.

Public Member Functions

 KeccakFCodeGen (unsigned int aWidth, unsigned int aNrRounds=0)
void setInterleavingFactor (unsigned int anInterleavingFactor)
void setOutputMacros (bool anOutputMacros)
void setOutputSubscripts (bool anOutputSubscripts)
void setScheduleType (unsigned int aScheduleType)
void displayRoundConstants ()
void displayRhoOffsets (bool moduloWordLength)
void displayPi ()
void genDeclarations (ostream &fout) const
void genCodePlanePerPlane (ostream &fout, bool earlyParity, SliceValue inChiMask=0, SliceValue outChiMask=0, string A="A", string B="B", string C="C", string D="D", string E="E", string header="") const
void genCodeForPrepareTheta (ostream &fout, string A="A", string C="C") const
void genRoundConstants (ostream &fout) const
void genCopyFromStateAndXor (ostream &fout, unsigned int bitsToXor, string A="X##", string state="state", string input="input") const
void genCopyToState (ostream &fout, string A="X##", string state="state", string input="input") const
void genCopyStateVariables (ostream &fout, string X="X##", string Y="Y##") const
void genMacroFile (ostream &fout, bool laneComplementing=false) const
void genCodeInPlace (ostream &fout, bool earlyParity, SliceValue inChiMask=0, SliceValue outChiMask=0, string A="A", string B="B", string C="C", string D="D", string header="") const
virtual string getName () const

Protected Member Functions

string buildWordName (const string &prefixSymbol, unsigned int x, unsigned int y, unsigned int z) const
string buildWordName (const string &prefixSymbol, unsigned int x, unsigned int z) const
string buildWordName (const string &prefixSymbol, unsigned int x) const
void genDeclarationsLanes (ostream &fout, const string &prefixSymbol) const
void genDeclarationsSheets (ostream &fout, const string &prefixSymbol) const
string strANDORnot (const string &A, const string &B, bool LC1, bool LC2, bool LOR) const
string strConst (const string &A) const
string strNOT (const string &A, bool complement=true) const
string strROL (const string &symbol, unsigned int amount) const
string strXOR (const string &A, const string &B) const
string strXOReq (const string &A, const string &B) const
unsigned int schedule (unsigned int i) const

Protected Attributes

unsigned int interleavingFactor
unsigned int wordSize
bool outputMacros
bool outputSubscripts
unsigned int scheduleType

Detailed Description

Class implementing code generation for the Keccak-f permutations.


Constructor & Destructor Documentation

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

The constructor. See KeccakF() for more details.


Member Function Documentation

string KeccakFCodeGen::buildWordName ( const string &  prefixSymbol,
unsigned int  x,
unsigned int  y,
unsigned int  z 
) const [protected]
string KeccakFCodeGen::buildWordName ( const string &  prefixSymbol,
unsigned int  x,
unsigned int  z 
) const [protected]
string KeccakFCodeGen::buildWordName ( const string &  prefixSymbol,
unsigned int  x 
) const [protected]
void KeccakFCodeGen::displayPi ( )

Method that displays the lane moves for π.

void KeccakFCodeGen::displayRhoOffsets ( bool  moduloWordLength)

Method that displays the translation offsets for ρ.

void KeccakFCodeGen::displayRoundConstants ( )

Method that displays the round constants.

void KeccakFCodeGen::genCodeForPrepareTheta ( ostream &  fout,
string  A = "A",
string  C = "C" 
) const

Method that generates C code to compute the sheet parities (C's variables) for θ in the first round.

Parameters:
foutThe output stream where the code is generated.
AThe string with the variable name for A.
CThe string with the variable name for C.
void KeccakFCodeGen::genCodeInPlace ( ostream &  fout,
bool  earlyParity,
SliceValue  inChiMask = 0,
SliceValue  outChiMask = 0,
string  A = "A",
string  B = "B",
string  C = "C",
string  D = "D",
string  header = "" 
) const

Method that generates C code to compute four rounds in place. See “Keccak implementation overview”, Section “Efficient in-place implementations” for more information. The generated code assumes that the lanes are complemented according to patterns inChiMask (after the linear steps, before χ) and outChiMask (after χ, before θ).

Parameters:
foutThe output stream where the code is generated.
earlyParityA Boolean value telling whether the sheet parities are to be computed into the C's as the output is computed. If false, the parities are computed at the beginning of each round.
inChiMaskThe lane complementing pattern at the input of χ (or after ρ and π).
outChiMaskThe lane complementing pattern at the output of χ (or before θ).
AThe string with the variable name for A.
BThe string with the variable name for B.
CThe string with the variable name for C.
DThe string with the variable name for D.
headerA string to output before the generated code.
void KeccakFCodeGen::genCodePlanePerPlane ( ostream &  fout,
bool  earlyParity,
SliceValue  inChiMask = 0,
SliceValue  outChiMask = 0,
string  A = "A",
string  B = "B",
string  C = "C",
string  D = "D",
string  E = "E",
string  header = "" 
) const

Method that generates C code to compute one round, plane per plane. See “Keccak implementation overview”, Section “Plane-per-plane processing” for more information. The generated code assumes that the lanes are complemented according to patterns inChiMask (after the linear steps, before χ) and outChiMask (after χ, before θ).

Parameters:
foutThe output stream where the code is generated.
earlyParityA Boolean value telling whether the sheet parities are to be computed into the C's while E is computed.
inChiMaskThe lane complementing pattern at the input of χ (or after ρ and π).
outChiMaskThe lane complementing pattern at the output of χ (or before θ).
AThe string with the variable name for A.
BThe string with the variable name for B.
CThe string with the variable name for C.
DThe string with the variable name for D.
EThe string with the variable name for E.
headerA string to output before the generated code.
void KeccakFCodeGen::genCopyFromStateAndXor ( ostream &  fout,
unsigned int  bitsToXor,
string  A = "X##",
string  state = "state",
string  input = "input" 
) const

Method that generates code to copy from an array of words into the state variables. It can xors a given number of words along the way.

Parameters:
foutThe output stream where the code is generated.
bitsToXorThe number of bits to xor (i.e., the rate of the sponge function).
AThe string with the variable name for A.
stateThe string with the variable name for the state as an array of words.
inputThe string with the variable name for the input as an array of words.
void KeccakFCodeGen::genCopyStateVariables ( ostream &  fout,
string  X = "X##",
string  Y = "Y##" 
) const

Method that generates code to copy from the state variables into other state variables.

Parameters:
foutThe output stream where the code is generated.
XThe string with the variable name for target X.
YThe string with the variable name for target Y.
void KeccakFCodeGen::genCopyToState ( ostream &  fout,
string  A = "X##",
string  state = "state",
string  input = "input" 
) const

Method that generates code to copy from the state variables into an array of words.

Parameters:
foutThe output stream where the code is generated.
AThe string with the variable name for A.
stateThe string with the variable name for the state as an array of words.
inputThe string with the variable name for the input as an array of words.
void KeccakFCodeGen::genDeclarations ( ostream &  fout) const

Method that generates declarations for the C code produced by genCodeForRound().

Parameters:
foutThe output stream where the code is generated.
void KeccakFCodeGen::genDeclarationsLanes ( ostream &  fout,
const string &  prefixSymbol 
) const [protected]
void KeccakFCodeGen::genDeclarationsSheets ( ostream &  fout,
const string &  prefixSymbol 
) const [protected]
void KeccakFCodeGen::genMacroFile ( ostream &  fout,
bool  laneComplementing = false 
) const

Method that generates all the macros for the C code.

Parameters:
foutThe output stream where the code is generated.
laneComplementingIf the output must contain code using the lane complementing technique, in addition to the straightforward code.
void KeccakFCodeGen::genRoundConstants ( ostream &  fout) const

Method that generates the round constants for ι.

Parameters:
foutThe output stream where the code is generated.
string KeccakFCodeGen::getName ( ) const [virtual]

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

Reimplemented from KeccakF.

unsigned int KeccakFCodeGen::schedule ( unsigned int  i) const [protected]
void KeccakFCodeGen::setInterleavingFactor ( unsigned int  anInterleavingFactor)

Method to set the interleaving factor.

Parameters:
anInterleavingFactorThe interleaving factor, see interleavingFactor.
void KeccakFCodeGen::setOutputMacros ( bool  anOutputMacros)

Method to set whether the operations should be written as macros or using regular operators.

Parameters:
anOutputMacrosIf true, macros are output; if false, operators are output.
void KeccakFCodeGen::setOutputSubscripts ( bool  anOutputSubscripts)

Method to set whether the words should be written with names or subscripts.

Parameters:
anOutputSubscriptsIf true, subscripts are output; if false, names are output.
void KeccakFCodeGen::setScheduleType ( unsigned int  aScheduleType)

Method to set whether the schedule type. It must be 1 or 2. Type 1 is best when there are more registers available. Type 2 is best when there are less registers available.

Parameters:
aScheduleTypeThe schedule type, 1 or 2.
string KeccakFCodeGen::strANDORnot ( const string &  A,
const string &  B,
bool  LC1,
bool  LC2,
bool  LOR 
) const [protected]
string KeccakFCodeGen::strConst ( const string &  A) const [protected]
string KeccakFCodeGen::strNOT ( const string &  A,
bool  complement = true 
) const [protected]
string KeccakFCodeGen::strROL ( const string &  symbol,
unsigned int  amount 
) const [protected]
string KeccakFCodeGen::strXOR ( const string &  A,
const string &  B 
) const [protected]
string KeccakFCodeGen::strXOReq ( const string &  A,
const string &  B 
) const [protected]

Member Data Documentation

unsigned int KeccakFCodeGen::interleavingFactor [protected]

The interleaving factor, i.e., the ratio between the lane size and the target word size. For instance, to generate 32-bit interleaved code for Keccak-f[1600], interleavingFactor must be set to 2 (=64/32). By default, the interleavingFactor is 1, meaning no interleaving. The interleavingFactor must divide the lane size.

bool KeccakFCodeGen::outputMacros [protected]

Tells whether the operations should be written as macros (if true) or using regular operators (if false). By default, it is false.

Tells whether the variables should be written with subscripts (if true) or using names (if false). By default, it is false.

unsigned int KeccakFCodeGen::scheduleType [protected]

Tells which type of scheduling is used in the generation of the code. It must be 1 or 2. By default, it is 1.

unsigned int KeccakFCodeGen::wordSize [protected]

The word size, which is equal to laneSize/interleavingFactor.


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