Skip to content

Instantly share code, notes, and snippets.

@rdev5
Created May 19, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdev5/f95da22762771f6ed3f2 to your computer and use it in GitHub Desktop.
Save rdev5/f95da22762771f6ed3f2 to your computer and use it in GitHub Desktop.
FIPS-197 6.3 Parameterization of Key Length, Block Size, and Round Number - This standard explicitly defines the allowed values for the key length (Nk), block size (Nb), and number of rounds (Nr). However, future reaffirmations of this standard could include changes or additions to the allowed values for those parameters. Therefore, implementers…
/*
* 6.3 Parameterization of Key Length, Block Size, and Round Number
*/
// Number of columns (32-bit words) comprising the State. For this standard, Nb = 4.
void int Nb(int stateLen)
{
return (stateLen * 8) / 32;
}
// Number of 32-bit words comprising the Cipher Key. For this standard, Nk = 4, 6, or 8.
void int Nk(int keyLen)
{
return (keyLen * 8) / 32;
}
// Number of rounds, which is a function of Nk and Nb (which is fixed). For this standard, Nr = 10, 12, or 14.
// Section 7.6 Number of Rounds of The Rijndael Block Cipher (AES Proposal)
void int Nr(int stateNb, int keyNk)
{
const int baseNb = 4,
baseNk = 4,
minRounds = 6,
safetyMargin = 4;
int rounds = minRounds + safetyMargin;
// +1 round for every additional 32-bits in Cipher Key
rounds += keyNk - baseNk;
// +1 round for every additional 32-bits in State
rounds += stateNb - baseNb;
return rounds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment