KeccakTools
|
#include <Keccak-fCodeGen.h>
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 |
Class implementing code generation for the Keccak-f permutations.
KeccakFCodeGen::KeccakFCodeGen | ( | unsigned int | aWidth, |
unsigned int | aNrRounds = 0 |
||
) |
The constructor. See KeccakF() for more details.
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::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.
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::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 θ).
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::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.
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::genCopyStateVariables | ( | ostream & | fout, |
string | X = "X##" , |
||
string | Y = "Y##" |
||
) | const |
Method that generates code to copy from the state variables into other state variables.
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::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.
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::genDeclarations | ( | ostream & | fout | ) | const |
Method that generates declarations for the C code produced by genCodeForRound().
fout | The 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.
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. |
void KeccakFCodeGen::genRoundConstants | ( | ostream & | fout | ) | const |
Method that generates the round constants for ι.
fout | The 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.
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.
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.
aScheduleType | The 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] |
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.
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.