# Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 4 Solutions - Ex4.10

- 20 mins- Return to index
- Exercise 4.1
- Exercise 4.2
- Exercise 4.3
- Exercise 4.4
- Exercise 4.5
- Exercise 4.6
- Exercise 4.7
- Exercise 4.8
- Exercise 4.9
- Exercise 4.10
- Exercise 4.11
- Exercise 4.12
- Exercise 4.13
- Exercise 4.14
- Exercise 4.15
- Exercise 4.16

## Exercise 4.10

In the following, we check the diffusion properties of AES after a single round. Let

be the input in 32-bit chunks to a 128-bit AES. The subkeys for the computation of the result of the first round of AES are with 32 bits each are given by

Use this book to figure out how the input is processed in the first round (e.g., SBoxes). For the solution, you might also want to write a short computer program or use an existing one. In any case, indicate all intermediate steps for the computation of *ShiftRows*, *SubBytes* and *MixColumns*!

- Compute the output of the first round of AES to the input W and the subkeys .
- Compute the output of the first round of AES for the case that
*all*input bits are zero. - How many output bits have changed? Remark that we only consider a single round — after every further round, more output bits will be affected (
*avalanche effect*).

### Solution

*Feedback kindly provided by Lisa Roy in the comment section has allowed me to correct some errors in earlier versions of this answer. Given that we have now converged upon a common answer, I can be reasonably sure of correctness.*

*Note*: From now on the state is represented as a 4x4 grid of bytes expressed in hexadecimal. This makes other transformations easier to represent also. The ordering of the bytes within the grid is as follows:

1. This question is slightly confusingly expressed and it took me a while to figure out what is meant. The keys and are given as a single array (). In fact, and . As such the first step is the initial key adition which occurs before we get into applying the rounds. The first word of the input is the only one that isn’t all-zeroes. As such, the state after addition is:

*Note*: From now on the state is represented as a 4x4 grid of bytes expressed in hexadecimal. This makes other transformations easier to represent also.

It’s worth noting that the four columns correspond exactly to the subkey bytes with the exception of the first cell, which was slightly altered by the XOR operation.

After applying the ByteSubstitution (S-box) layer, the state is as follows:

The ShiftRows layer is a very simple transformation. The first row remains unchainged. The other rows are rotated right by a number of positions; the second by 3, the third by 2 and the fourth by 1. This gives the following:

The final transformation (other than the addition) is the MixColumn layer. This involves a Galois Extension Field matrix multiplication with the following description:

The C values refer to the outputted column. The B values refer to the input columns which were the output of the ShiftRows layer. The indexes here are preserved from prior to the shift. Each new column can be calculated left-to-right using this procedure.

it should also be noted that here would refer to in . The same logic is used to turn a hex byte into a Galois Extension Field polynomial. The reduction polynomial is the AES primitive polynomial:

As such the calculation to be performed is as follows for each of the columns:

This produces the following state:

All that’s left to do after this is the KeyAddition layer for :

Therefore, the output of the first round of encryption is as follows (remembering to read it out column-wise):

2. For the case that the input is all-zeroes, the state after the key addition will be as follows (only the first byte is different from part 1):

After applying the ByteSubstitution (S-box) layer, the state is as follows:

After applying the ShiftRows layer, the state is as follows:

Up until this point, only one byte (in fact only one bit) has been altered in compared to part 1. The MixColumn introduces some diffusion, and after this layer is applied, the state is as follows:

The first column of the state now has a different set of values than in part 1, the others are unaltered. All that’s left to do after this is the KeyAddition layer for :

Therefore, the output of the first round of encryption is as follows (remembering to read it out column-wise):

3. We can see how many output bits have been altered by XORing the two output values together. This produces:

In this form, we can clearly see that only the first column is altered after the first round.

The 1s in the binary above correspond to output bits which have changed. There are ten of them, so therefore the number of output bits which have changed due to a 1 bit change in input, in this instance, is 10 after the first round. The ShiftRows operations in further rounds will diffuse this effect to other columns.

I wrote a python script which can perform the operations involved in computing an AES round: