Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

4.8 KB
Raw Blame

Cryptography - AES Key Expansion Algorithm

The AES Key Expansion Algorithm is an essential part of the Advanced Encryption Standard (AES), responsible for generating a set of round keys from the original encryption key. These round keys are used in each AES encryption and decryption round to ensure that each round is unique, even if the same plaintext and key are used repeatedly. Key expansion is crucial to AES security, as it allows AES to prevent predictable patterns in the encryption output and makes the encryption resistant to attacks.


Purpose of the Key Expansion Algorithm

The Key Expansion Algorithm's main goals are:

  • Generate Round Keys: To produce a series of keys—one for each round of AES—that will be XORed with the state matrix in the AddRoundKey transformation.
  • Ensure Security: Each round key is unique, making it more challenging for attackers to perform cryptanalysis on AES.
  • Enable Multiple Key Sizes: AES supports 128-bit, 192-bit, and 256-bit key lengths. The Key Expansion Algorithm generates the appropriate number of round keys based on the key length.

How the Key Expansion Algorithm Works

The Key Expansion Algorithm consists of a few main steps, including initialization, round key generation, and use of the Rijndael S-box for substitution.

Step 1: Initialization

  1. Input Key: The original AES key is taken as input. This key size can be 128 bits, 192 bits, or 256 bits.
  2. Word Division: The AES key is divided into words of 4 bytes (32 bits) each. For example:
    • AES-128: 4 words (128 bits)
    • AES-192: 6 words (192 bits)
    • AES-256: 8 words (256 bits)

Step 2: Number of Rounds and Round Keys

  • AES-128: 10 rounds, requiring 44 words (4 initial words and 40 words generated for the rounds).
  • AES-192: 12 rounds, requiring 52 words.
  • AES-256: 14 rounds, requiring 60 words.

Step 3: Key Expansion Process

The algorithm then generates additional words until the total number needed for all rounds is reached, using the following steps:

  1. Previous Word Selection: For each word $( W[i] )$ to be generated, the previous word $( W[i-1] )$ is considered.

  2. Rotation (RotWord): Every Nth word (where N depends on key length: 4 for AES-128, 6 for AES-192, and 8 for AES-256) undergoes RotWord—a cyclic left shift of 1 byte.

  3. Substitution (SubWord): The rotated word is passed through the S-box, a non-linear substitution table, applying substitution to each byte.

  4. Round Constant (Rcon): A round constant (Rcon) is XORed with the first byte of the word. Rcon changes each round and adds security by ensuring that round keys differ significantly from one another.

  5. XOR with Previous Words: The new word $( W[i] )$ is generated by XORing the transformed word with $( W[i - N] )$, where N is the size of the key in words (4, 6, or 8).

    The final operation for generating each word $( W[i] )$ is: $[ W[i] = W[i - N] \oplus \text{Transformed Word} ]$


Example of Key Expansion for AES-128

Let’s consider a 128-bit key. For simplicity, we illustrate the first few rounds.

  1. Initial Key (Key Schedule):

    • Split the 128-bit key into four 32-bit words $( W[0], W[1], W[2], W[3] )$.
  2. Generate Additional Words:

    • For $( i = 4, 5, \ldots, 43 )$:
      • Every fourth word $(e.g., ( W[4], W[8], W[12], \ldots ))$ undergoes RotWord and SubWord transformations, along with Rcon.
      • Each new word $( W[i] )$ is computed as $( W[i] = W[i - 4] \oplus \text{Transformed Word} )$.
  3. Repeat until 44 Words Are Generated:

    • The final 44 words are grouped into sets of 4 words each, forming round keys for each of the 10 rounds in AES-128.

Example Calculation of Rcon

Rcon values start with Rcon[1] = 0x01 and double in value with each round using a function in the Galois field GF(2^8). For instance:

  • $( Rcon[1] = 0x01 )$
  • $( Rcon[2] = 0x02 )$
  • $( Rcon[3] = 0x04 )$
  • And so on.

Security Benefits of Key Expansion

The Key Expansion Algorithm adds significant security to AES by:

  • Preventing Key Reuse: Different round keys in each round ensure each round’s transformation is unique.
  • Increased Complexity: The transformations, including substitution and rotation, make the expanded keys unpredictable.
  • Resistance to Cryptanalysis: The diversity and non-linearity of the round keys protect against various cryptanalysis methods.

Conclusion

The AES Key Expansion Algorithm is essential to the AES process, generating a series of unique round keys from the original key. Through the use of RotWord, SubWord, and round constants, it ensures that the encryption process has ample diffusion and complexity, making AES a highly secure encryption standard.