KeccakFCodeGen Class Reference

#include <Keccak-fCodeGen.h>

Inheritance diagram for KeccakFCodeGen:

Inheritance graph
[legend]
Collaboration diagram for KeccakFCodeGen:

Collaboration graph
[legend]

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 setScheduleType (unsigned int aScheduleType)
void displayRoundConstants ()
void displayRhoOffsets (bool moduloWordLength)
void displayPi ()
void genDeclarations (ostream &fout) const
void genCodeForRound (ostream &fout, bool prepareTheta, 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
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
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
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

void KeccakFCodeGen::setInterleavingFactor ( unsigned int  anInterleavingFactor  ) 

Method to set the interleaving factor.

Parameters:
anInterleavingFactor The 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:
anOutputMacros If true, macros are output; if false, operators 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:
aScheduleType The schedule type, 1 or 2.

void KeccakFCodeGen::displayRoundConstants (  ) 

Method that displays the round constants.

void KeccakFCodeGen::displayRhoOffsets ( bool  moduloWordLength  ) 

Method that displays the translation offsets for ρ.

void KeccakFCodeGen::displayPi (  ) 

Method that displays the lane moves for π.

void KeccakFCodeGen::genDeclarations ( ostream &  fout  )  const

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

Parameters:
fout The output stream where the code is generated.

void KeccakFCodeGen::genCodeForRound ( ostream &  fout,
bool  prepareTheta,
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. The produced code assumes that the state is stored in the variables starting with letter A. It also assumes that the variables starting with D are the lanes that will be XORed into the state to perform θ. The generated code then XORs the D's into the A's for θ, moves the lanes and rotates them into the B's to perform ρ and π. The evaluation of χ is done from the B's into the variables starting with E. As χ is computed, the generated code optionally also computes sheet parities into 5 variables starting with C. The generated code also assumes that the lanes are complemented according to patterns inChiMask (after the linear steps, before χ) and outChiMask (after χ, before θ).

Parameters:
fout The output stream where the code is generated.
prepareTheta A Boolean value telling whether the sheet parities are to be computed into the C's.
inChiMask The lane complementing pattern at the input of χ (or after ρ and π).
outChiMask The lane complementing pattern at the output of χ (or before θ).
A The string with the variable name for A.
B The string with the variable name for B.
C The string with the variable name for C.
D The string with the variable name for D.
E The string with the variable name for E.
header A string to output before the generated code.

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:
fout The output stream where the code is generated.
A The string with the variable name for A.
C The string with the variable name for C.

void KeccakFCodeGen::genRoundConstants ( ostream &  fout  )  const

Method that generates the round constants for ι.

Parameters:
fout The output stream where the code is generated.

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:
fout The output stream where the code is generated.
bitsToXor The number of bits to xor (i.e., the rate of the sponge function).
A The string with the variable name for A.
state The string with the variable name for the state as an array of words.
input The string with the variable name for the input as an array of words.

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:
fout The output stream where the code is generated.
A The string with the variable name for A.
state The string with the variable name for the state as an array of words.
input The 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:
fout The output stream where the code is generated.
X The string with the variable name for target X.
Y The string with the variable name for target Y.

void KeccakFCodeGen::genMacroFile ( ostream &  fout,
bool  laneComplementing = false 
) const

Method that generates all the macros for the C code.

Parameters:
fout The output stream where the code is generated.
laneComplementing If the output must contain code using the lane complementing technique, in addition to the straightforward code.

string KeccakFCodeGen::getName (  )  const [virtual]

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

Reimplemented from KeccakF.

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]

void KeccakFCodeGen::genDeclarationsLanes ( ostream &  fout,
const string &  prefixSymbol 
) const [protected]

void KeccakFCodeGen::genDeclarationsSheets ( ostream &  fout,
const string &  prefixSymbol 
) const [protected]

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]

unsigned int KeccakFCodeGen::schedule ( unsigned int  i  )  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.

unsigned int KeccakFCodeGen::wordSize [protected]

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

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.

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.


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

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