# Does the MixColumns step come before or after AddRoundKey in AES decryption?

I found these images depicting the AES decryption process:

In the first image, the MixColumns step comes before the AddRoundKey step, while in the second image, the AddRoundKey will come before the MixColumns.

Which order is the correct one?

• Have a look at my answer to »Why is MixColumns omitted from the last round of AES?«. Both are correct, but with a different expanded key. – Paŭlo Ebermann May 25 '12 at 17:54
• what do you mean by different expanded key? – goldroger May 25 '12 at 18:02
• Did you actually read the linked answer? You'll see that the third code block uses InvMixColumns(ExpandedKey[i]) instead of ExpandedKey[i] (in the last block, this is shown as EqExpandedKey[i]). – Paŭlo Ebermann May 25 '12 at 18:06
• @JohnPaulParreño: I'd correct my answer (I originally talked about the ShiftRows and SubBytes operation), however, I can't really say it better than that Paŭlo said in his answer that he linked to; look at that. – poncho May 25 '12 at 23:18
• possible duplicate of Why is MixColumns omitted from the last round of AES? – mikeazo Jun 4 '12 at 19:21

## 3 Answers

InvMixColumns is a linear operation. And because of that it follows:

InvMixColumn(x+RoundKey) = InvMixColumn(x) + InvMixColumn(RoundKey)
^^^^^^^^^^^^^^^^^^^^^^
"new" round key for decryption


So, the structure on the right is compatible with the structure on the left as long as you use different round keys. The idea behind this is to make the decryption structure look like encryption structure with just a couple of "Inv"s in there. But I'm actually not sure what the benefit of this is. For a block cipher like Anubis (which is similar to AES) it makes much more sense because each operation is an involution. The only difference between encryption and decryption for Anubis are the round keys. So, you can reuse the encryption code for decryption which is a nice property.

Not sure if this is answered fully, but if you check wikipedia, you'll see that AddRoundKey occurs 3 times in total with 1 time before and 1 time after the MixColumns operation.

However, if you are just considering the middle rounds then the MixColumns comes before

After the AddRoundKey step, except for the last round, where it does not happen