AES key schedule

From HandWiki
Short description: Method for expanding key to round keys in AES

AES uses a key schedule to expand a short key into a number of separate round keys. The three AES variants have a different number of rounds. Each variant requires a separate 128-bit round key for each round plus one more.[note 1] The key schedule produces the needed round keys from the initial key.

Round constants

Values of rci in hexadecimal
i 1 2 3 4 5 6 7 8 9 10
rci 01 02 04 08 10 20 40 80 1B 36

The round constant rconi for round i of the key expansion is the 32-bit word:[note 2]

[math]\displaystyle{ rcon_i = \begin{bmatrix} rc_i & 00_{16} & 00_{16} & 00_{16} \end{bmatrix} }[/math]

where rci is an eight-bit value defined as :

[math]\displaystyle{ rc_i = \begin{cases} 1 & \text{if } i = 1 \\ 2 \cdot rc_{i-1} & \text{if } i \gt 1 \text{ and } rc_{i-1} \lt 80_{16} \\ (2 \cdot rc_{i-1}) \oplus \text {11B}_{16} & \text{if } i \gt 1 \text{ and } rc_{i-1} \ge 80_{16} \end{cases} }[/math]

where [math]\displaystyle{ \oplus }[/math] is the bitwise XOR operator and constants such as 0016 and 11B16 are given in hexadecimal. Equivalently:

[math]\displaystyle{ rc_i = x^{i-1} }[/math]

where the bits of rci are treated as the coefficients of an element of the finite field [math]\displaystyle{ \rm{GF}(2)[x]/(x^8 + x^ 4 + x^3 + x + 1) }[/math], so that e.g. [math]\displaystyle{ rc_{10} = 36_{16} = 00110110_2 }[/math] represents the polynomial [math]\displaystyle{ x^5 + x^4 + x^2 + x }[/math].

AES uses up to rcon10 for AES-128 (as 11 round keys are needed), up to rcon8 for AES-192, and up to rcon7 for AES-256.[note 3]

The key schedule

AES key schedule for a 128-bit key.

Define:

  • N as the length of the key in 32-bit words: 4 words for AES-128, 6 words for AES-192, and 8 words for AES-256
  • K0, K1, ... KN-1 as the 32-bit words of the original key
  • R as the number of round keys needed: 11 round keys for AES-128, 13 keys for AES-192, and 15 keys for AES-256[note 4]
  • W0, W1, ... W4R-1 as the 32-bit words of the expanded key[note 5]

Also define RotWord as a one-byte left circular shift:[note 6]

[math]\displaystyle{ \operatorname{RotWord}(\begin{bmatrix} b_0 & b_1 & b_2 & b_3 \end{bmatrix}) = \begin{bmatrix} b_1 & b_2 & b_3 & b_0 \end{bmatrix} }[/math]

and SubWord as an application of the AES S-box to each of the four bytes of the word:

[math]\displaystyle{ \operatorname{SubWord}(\begin{bmatrix} b_0 & b_1 & b_2 & b_3 \end{bmatrix}) = \begin{bmatrix} \operatorname{S}(b_0) & \operatorname{S}(b_1) & \operatorname{S}(b_2) & \operatorname{S}(b_3) \end{bmatrix} }[/math]

Then for [math]\displaystyle{ i = 0 \ldots 4R-1 }[/math]:

[math]\displaystyle{ W_i = \begin{cases} K_i & \text{if } i \lt N \\ W_{i-N} \oplus \operatorname{SubWord}(\operatorname{RotWord}(W_{i-1})) \oplus rcon_{i/N} & \text {if } i \ge N \text{ and } i \equiv 0 \pmod{N} \\ W_{i-N} \oplus \operatorname{SubWord}(W_{i-1}) & \text{if } i \ge N \text{, } N \gt 6 \text{, and } i \equiv 4 \pmod{N} \\ W_{i-N} \oplus W_{i-1} & \text{otherwise.} \\ \end{cases} }[/math]

Notes

  1. Non-AES Rijndael variants require up to 256 bits of expanded key per round
  2. In FIPS-197 the [math]\displaystyle{ rc_i }[/math] value is the least significant byte at index 0
  3. The Rijndael variants with larger block sizes use more of these constants, up to rcon29 for Rijndael with 128-bit keys and 256 bit blocks (needs 15 round keys of each 256 bit, which means 30 full rounds of key expansion, which means 29 calls to the key schedule core using the round constants). The remaining constants for i ≥ 11 are: 6C, D8, AB, 4D, 9A, 2F, 5E, BC, 63, C6, 97, 35, 6A, D4, B3, 7D, FA, EF and C5
  4. Other Rijndael variants require max(N, B) + 7 round keys, where B is the block size in words
  5. Other Rijndael variants require BR words of expanded key, where B is the block size in words
  6. Rotation is opposite of byte order direction. FIPS-197 byte addresses in arrays are increasing from left to right[ref 1] in little endian but rotation is from right to left. In AES-NI[ref 2] and in the Linux kernel's lib/crypto/aes.c[ref 3], the byte ordering is increasing from right to left in little endian but rotation is from left to right.

References

External links