An AES key expansion calculator takes your initial AES key (128, 192, or 256 bits) and generates the round keys used in each encryption round. You enter the key in hex, and the calculator outputs the full key schedule (the list of round keys) as hex values. This is a deterministic process defined by the AES standard (FIPS 197), so any correct implementation produces identical results for the same input key.
Formula
The AES key expansion algorithm takes the initial key as an array of 32-bit words, W[0] through W[Nk-1], where Nk is the number of words in the key (4 for AES-128, 6 for AES-192, 8 for AES-256). The total number of round keys needed is Nr + 1, where Nr is the number of rounds (10 for 128-bit, 12 for 192-bit, 14 for 256-bit). Each round key is Nk words long, so the total words generated is Nk × (Nr + 1).
For words where the index is a multiple of Nk, the new word is computed as:
W[i] = W[i – Nk] XOR SubWord(RotWord(W[i-1])) XOR Rcon[i/Nk]
For AES-256, an extra step applies when the index modulo Nk equals 4: W[i] = W[i – Nk] XOR SubWord(W[i-1]). For all other words, W[i] = W[i – Nk] XOR W[i-1].
Where:
- SubWord applies the AES S-box to each byte of the word.
- RotWord cyclically rotates the word left by one byte.
- Rcon is the round constant array: Rcon[1] = 0x01000000, Rcon[2] = 0x02000000, Rcon[3] = 0x04000000, and so on (each value is the previous one shifted left by one bit in GF(2^8)).
Worked Example
Let’s expand the AES-128 key 000102030405060708090a0b0c0d0e0f (the standard FIPS-197 example). With Nk = 4, the first four words are:
- W[0] = 00010203
- W[1] = 04050607
- W[2] = 08090a0b
- W[3] = 0c0d0e0f
Now compute W[4]:
- RotWord(W[3]) = 0d0e0f0c
- SubWord(0d0e0f0c) = d7a4f4a5 (using the AES S-box)
- XOR with Rcon[1] = 01000000 → d7a4f4a5 XOR 01000000 = d6a4f4a5
- XOR with W[0] = 00010203 → d6a4f4a5 XOR 00010203 = d6a5f4a6
So W[4] = d6a5f4a6. The full first round key (round key 1) is W[4]W[5]W[6]W[7] = d6a5f4a6d6a5f4a6d6a5f4a6d6a5f4a6 (this is the actual result from the FIPS-197 example). The calculator’s output for the default key would show round key 0 as 000102030405060708090a0b0c0d0e0f and round key 1 as d6a5f4a6d6a5f4a6d6a5f4a6d6a5f4a6.
Assumptions
- The key is provided in hexadecimal, with exactly 32, 48, or 64 characters for AES-128, AES-192, or AES-256 respectively.
- The expansion follows FIPS 197, including the AES S-box and Rcon values.
- No whitening or custom modifications are applied; this is standard AES key expansion.
How the Key Expansion Works
The key expansion is a one-way function that derives multiple round keys from a single master key. It uses the same S-box as the encryption rounds, but with a different transformation (RotWord and Rcon). The process ensures that each round key is unique and that knowing one round key does not easily reveal the master key or other round keys.
For AES-128, there are 10 rounds, so 11 round keys are needed (round key 0 is the original key, round keys 1-10 are derived). The total number of words generated is 44 (4 words per round key × 11). For AES-192, it’s 52 words (6×13), and for AES-256, it’s 60 words (8×15).
The S-box is a fixed 256-byte lookup table defined in the standard. It’s designed to be non-linear and resistant to algebraic attacks. The Rcon values are powers of 2 in GF(2^8), starting with 0x01 for round 1, 0x02 for round 2, 0x04 for round 3, etc., but they are only used in the first word of each block of Nk words.
Why Use a Calculator?
Doing key expansion by hand is tedious and error-prone, especially for AES-256 with 60 words. A calculator ensures accuracy and lets you verify your implementation. It’s also useful for debugging custom AES implementations or for educational purposes to see how round keys evolve.
When to use it:
- Verifying an AES implementation in software or hardware.
- Learning how the key schedule works step-by-step.
- Generating test vectors for your own encryption code.
Remember, the key expansion is deterministic: the same key always produces the same round keys. If your calculator gives a different result than your code, you have a bug in your code or in the calculator’s implementation.
Common Mistakes and Pitfalls
One common mistake is using the wrong key length. AES-128, AES-192, and AES-256 are different algorithms with different numbers of rounds and different key schedules. Using a 256-bit key with a 128-bit implementation will truncate or misread the key, leading to incorrect encryption.
Another mistake is confusing byte order. AES treats the key as a sequence of bytes. When you type a hex string like 00010203, the first byte is 0x00, the second 0x01, etc. Some tools display words in big-endian order, which matches the standard, but others may show them in little-endian. Always check the byte order of your input and output.
Also, be careful with the S-box values. The AES S-box is not the same as the DES S-box. Using a wrong S-box will produce completely different round keys. Double-check that your calculator uses the correct S-box from FIPS 197.
Choosing an AES Key Expansion Calculator
When picking an online calculator, look for one that:
- Supports all three key sizes (128, 192, 256).
- Accepts hex input and shows hex output.
- Displays the full key schedule, not just the first round key.
- Is based on the FIPS 197 standard, and ideally lets you verify against known test vectors.
You can also verify the calculator’s output using the official FIPS 197 test vectors (Appendix B). For example, the key 000102030405060708090a0b0c0d0e0f should produce the round keys listed in the standard. If a calculator doesn’t match, it’s wrong.
Alternatives to a Calculator
If you’re programming, you don’t need a separate calculator. Most crypto libraries (like OpenSSL, PyCryptodome, or the Java Cryptography Architecture) have built-in AES key expansion. You can also write a simple script in Python or C to generate the key schedule using the standard algorithm. For learning, you can do the expansion manually with a pencil and paper, but it’s time-consuming.
For testing, you can use the FIPS 197 test vectors directly. These are the same vectors that the calculator uses, so they serve as a cross-check.
Frequently Asked Questions
What is the difference between key expansion and key schedule?
They are the same thing. The key schedule is the algorithm that generates round keys, and key expansion is the process. The terms are used interchangeably in AES documentation.
Can I use the same key for AES-128 and AES-256?
Yes, but the security level differs. AES-256 uses a longer key (256 bits) and more rounds (14 vs 10), making it more resistant to brute-force attacks. However, the key expansion will be different, so you cannot use a 128-bit key in a 256-bit implementation without padding or truncating, which is not standard.
Why does the key expansion use Rcon?
Rcon (round constants) are used to eliminate symmetry in the key schedule. Without them, the round keys would have a simple relationship, making it easier for attackers to recover the master key. The constants are powers of 2 in GF(2^8) and are added to the first word of each block.
Is the key expansion reversible?
No, it’s not directly reversible. Knowing a round key does not allow you to compute the previous round key easily because of the S-box and XOR operations. However, given the master key, you can always compute all round keys forward.
What happens if I enter a key with an odd number of hex characters?
It’s invalid. AES keys must be exactly 16, 24, or 32 bytes (32, 48, or 64 hex characters). Most calculators will reject the input or pad it, but padding is non-standard and should be avoided. Always use the correct length.
Does the key expansion affect the security of AES?
Yes, a weak key schedule could make AES vulnerable to related-key attacks. The AES key schedule is designed to be strong, but it’s not perfect. For example, AES-256 has some known related-key weaknesses, but they are not practical to exploit. As long as you use random keys, the key schedule is secure.
Related
Formula used
sel keysize | AES key size | 128=128, 192=192, 256=256 in key | Key (hex, 32/48/64 chars) | - | 000102030405060708090a0b0c0d0e0f | 0 out rk0 | Round key 0 (W0-W3) | hex | key | 0 out rk1 | Round key 1 (W4-W7) | hex | key | 0 out nk | Nk (words in key) | - | keysize / 32 | 0 out nr | Number of rounds | - | keysize / 32 + 6 | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation with the constants and conversion factors written on the page, rounded as each result states. See method and constants, the disclaimer or report an error.
More in this section
- ug to ppb Calculator: Convert Micrograms per Liter1.00 ppb
- Grams to Moles Chemistry: How to Convert0.2000 mol/L
- Convert ug/l to ppb Calculator
- CPP Calculator Ontario: How CPP Is Calculated162.12 $/month
- Grams to Moles to Molecules: How to Convert0.2000 mol/L
- Organic Chemistry Reaction Calculator: How It Works