void squareDecrypt (word32 text[4], squareKeySchedule roundKeys) { word32 temp[4]; /* initial key addition */ text[0] ^= roundKeys[0][0]; text[1] ^= roundKeys[0][1]; text[2] ^= roundKeys[0][2]; text[3] ^= roundKeys[0][3]; /* R - 1 full rounds */ squareRound (text, temp, Td0, Td1, Td2, Td3, roundKeys[1]); squareRound (temp, text, Td0, Td1, Td2, Td3, roundKeys[2]); squareRound (text, temp, Td0, Td1, Td2, Td3, roundKeys[3]); squareRound (temp, text, Td0, Td1, Td2, Td3, roundKeys[4]); squareRound (text, temp, Td0, Td1, Td2, Td3, roundKeys[5]); squareRound (temp, text, Td0, Td1, Td2, Td3, roundKeys[6]); squareRound (text, temp, Td0, Td1, Td2, Td3, roundKeys[7]); /* last round (diffusion becomes only transposition) */ squareFinal (text, temp, Sd, roundKeys[R]); #ifdef DESTROY_TEMPORARIES /* destroy sensitive data: */ temp[0] = temp[1] = temp[2] = temp[3] = 0L; #endif /* ?DESTROY_TEMPORARIES */ } /* squareDecrypt */
void Square::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const { word32 text[4], temp[4]; Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); /* initial key addition */ text[0] ^= roundkeys[0][0]; text[1] ^= roundkeys[0][1]; text[2] ^= roundkeys[0][2]; text[3] ^= roundkeys[0][3]; /* ROUNDS - 1 full rounds */ for (int i=1; i+1<ROUNDS; i+=2) { squareRound (text, temp, Td[0], Td[1], Td[2], Td[3], roundkeys[i]); squareRound (temp, text, Td[0], Td[1], Td[2], Td[3], roundkeys[i+1]); } squareRound (text, temp, Td[0], Td[1], Td[2], Td[3], roundkeys[ROUNDS-1]); /* last round (diffusion becomes only transposition) */ squareFinal (text, temp, Sd, roundkeys[ROUNDS]); Block::Put(xorBlock, outBlock)(text[0])(text[1])(text[2])(text[3]); }
void Square::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const { word32 text[4], temp[4]; Block::Get(inBlock)(text[0])(text[1])(text[2])(text[3]); /* initial key addition */ text[0] ^= roundkeys(0, 0); text[1] ^= roundkeys(0, 1); text[2] ^= roundkeys(0, 2); text[3] ^= roundkeys(0, 3); /* ROUNDS - 1 full rounds */ for (int i=1; i+1<ROUNDS; i+=2) { squareRound (text, temp, Te[0], Te[1], Te[2], Te[3], roundkeys4(i)); squareRound (temp, text, Te[0], Te[1], Te[2], Te[3], roundkeys4(i+1)); } squareRound (text, temp, Te[0], Te[1], Te[2], Te[3], roundkeys4(ROUNDS-1)); /* last round (diffusion becomes only transposition) */ squareFinal (text, temp, Se, roundkeys4(ROUNDS)); Block::Put(xorBlock, outBlock)(text[0])(text[1])(text[2])(text[3]); }