# 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

\[W = (w_0,w_1,w_2,w_3) =\] \[01000000_{16} \\ 00000000_{16} \\ 00000000_{16} \\ 00000000_{16}\]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 \(W_0,...,W_7\) with 32 bits each are given by

\[W_0 = 2B7E1516_{16} \\ W_1 = 28AED2A6_{16} \\ W_2 = ABF71588_{16} \\ W_3 = 09CF4F3C_{16} \\ W_4 = A0FAFE17_{16} \\ W_5 = 88542CB1_{16} \\ W_6 = 23A33939_{16} \\ W_7 = 2A6C7605_{16}\]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 \(W_0,...,W_7\).
- 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 \(k_0\) and \(k_1\) are given as a single array (\(W_0,...,W_7\)). In fact, \(k_0 = W_0,...,W_3\) and \(k_1 = W_4,...,W_7\). As such the first step is the initial \(k_0\) 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 \(k_0\) 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 \(k_0 = (W_0,...,W_3)\) 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 \(k_1\) 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 \(03\) here would refer to \(x + 1\) in \(GF(2^8)\). The same logic is used to turn a hex byte into a Galois Extension Field polynomial. The reduction polynomial is the AES primitive polynomial:

\[P(x) = x^8 + x^4 + x^3 + x + 1\]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 \(k_1 = W_4,...,W_7\):

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

\[F4CC6B539B60AA8F1F010F045790A2D3_{16}\]2. For the case that the input is all-zeroes, the state after the \(k_0\) 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 \(k_1 = W_4,...,W_7\):

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

\[DCD87F6F9B60AA8F1F010F045790A2D3_{16}\]3. We can see how many output bits have been altered by XORing the two output values together. This produces:

\[2814143c000000000000000000000000_{16}\]In this form, we can clearly see that only the first column is altered after the first round.

\[2814143c_{16} = 101000000101000001010000111100_2\]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: