AES explained on a single paper
AES (FIPS-197) is a symmetric block cipher algorithm, which first originated as Rijndael by Daemen and Rijmen as an effort to replace the aging DES (Data Encryption Standard) with a secure encryption algorithm (at NIST’s call for public cipher submissions 1997).
AES works by utilizing fixed 128-bit blocks made as a 4x4 grid of bytes.
- State block: is the data block to be encrypted
- Cipher block: is the key block to encrypt the data
In the example below, the hex value “0xAAABACADBABBBCBD
CACBCCCDDADBDCDD”, is a 16 byte block
Unlike Rijndael’s key lengths, the key lengths in AES are only 3 variants
(THIS IS THE CIPHER BLOCK, NOT THE STATE BLOCK)
Now for the interesting part
- AddRoundKey: is (at the beginning) simply S⊕C (State XOR Cipher)
- SubBytes: a predefined mathematical standard substitution box (S-Box) used to map each byte to a different hex value from that box
- For example 0xAC is made row number 0xA and column number 0xC
- Which returns 0x91 as a replacement for 0xAC - ShiftRows: each row from SubBytes will be shifted left p+1, p=0 in the first row
4. MixColunms: is (in simple terms) the dot product of the predefined standard coefficients matrix and resulting ShiftRows value (Coefficients ⋅ ShiftRows)
5. AddRoundKey: here we’ll stop for a moment
- In each round, the Cipher block is rotated (RotWord) mathematically
- then the rotated value is also mapped to the same S-Box
- then a Round Constant (Rcon), an also predefined 10x4 standard matrix is XORed one column at a round
Get iBitSploit’s stories in your inbox
Join Medium for free to get updates from this writer.
Here’s a quick example:
This illustrates how the RoundKey is calculated:
- Blue bytes array is from the matrix of the Cipher block
- Orange bytes are the RotWord of the Cipher block, mapped to the S-Box
- Yellow bytes are the Round Constant matrix from the relevant column
But this happens ONLY to the first column of the Cipher block, the rest would be calculated like the following:
- Blue bytes are once again from the cipher block
- Dark grey are the formerly calculated column
Then after finalizing the first RoundKey we move to the next round, so we also make the next and following rounds dependent on the former rounds
We can achieve this by using the same strategy, but work on the RoundKey past the current one, for instance:
Then of course, the later columns would be calculated without the need for the Rcon matrix
At the end, we have a list of ordered RoundKeys for each round
We perform XOR again on the resulting MixColunms
MixColunms ⊕ AddRoundKey
Remember, the Rcon table is 10 for our case because we are using the AES-128 variant for this example, 9 columns of the Rcon table are the main rounds, then 1 final round resulting in a total of 10
The final round happens without the MixColunms stage, because there would be no other operation to be performed after the last round
ending up with 11 RoundKeys in total
- 1 Initial Key
- 9 Looped Rounds
- 1 Final round
Finally we get our encrypted text as parallel blocks (AES rounds process one 16-byte block at a time)
To have our result as usable data, we need to implement operation modes, which will be in the following post
Thanks for reading, I have used the following references and resources while researching the algorithm:
https://www.youtube.com/watch?v=O4xNJsjtN6E&t=428s
https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.197-upd1.pdf
https://formaestudio.com/rijndaelinspector/archivos/Rijndael_Animation_v4_eng-html5.html





