Lab Number 8
Lab Number 8
Date: 29/12/2024
Speed comes from the fact that AES is a symmetric-key cipher and requires less
computational power as compared to an asymmetric one.
Security is the direct result of a sophisticated block cipher algorithm. Data is encrypted on
a per-block basis, which is measured in bits. For instance, 128 bits of plain text will
produce 128 bits of cipher text.
The cipher involves substitution and permutation, meaning replacing inputs with specific
outputs and then shuffling those outputs, aka rounds. These rounds make up the
difference between the various key lengths. AES uses 10 rounds for 128-bit keys, 12
rounds for 192-bit keys and 14 rounds for 256-bit keys.
Key Expansion is carried out before each round. The initial key is used to derive a series
of ‘new round keys’ to ensure the same keys are not used in each round.
Byte Substitution
Shift Rows
Mix Column
Add Round Key
Operation of AES
AES is an iterative rather than Feistel cipher. It is based on ‘substitution–permutation
network’. It comprises of a series of linked operations, some of which involve replacing
inputs by specific outputs (substitutions) and others involve shuffling bits around
(permutations).
Interestingly, AES performs all its computations on bytes rather than bits. Hence, AES
treats the 128 bits of a plaintext block as 16 bytes. These 16 bytes are arranged in four
columns and four rows for processing as a matrix −
Unlike DES, the number of rounds in AES is variable and depends on the length of the
key. AES uses 10 rounds for 128-bit keys, 12 rounds for 192-bit keys and 14 rounds for
256-bit keys. Each of these rounds uses a different 128-bit round key, which is calculated
from the original AES key.
The schematic of AES structure is given in the following illustration −
Encryption Process
Here, we restrict to description of a typical round of AES encryption. Each round comprise
of four sub-processes. The first round process is depicted below −
The input to the encryption and decryption algorithms is a single 128-bit block.
In FIPS PUB 197, this block is depicted as a 4 * 4 square matrix of bytes. This block
is copied into the State array, which is modified at each stage of encryption or decryp-
tion. After the final stage, State is copied to an output matrix. Similarly, the key is depicted
as a square matrix of bytes. This key is then expanded into an array of key schedule
words. Each word is four bytes, and the total key schedule is 44 words for the 128-
bit key. Note that the ordering of bytes within a matrix is by col-
umn. So, for example, the first four bytes of a 128-bit plaintext input to the encryption
cipher occupy the first column of the in matrix, the second four bytes occupy the
second column, and so on. Similarly, the first four bytes of the expanded key, which
form a word, occupy the first column of the w matrix.
The cipher consists of N rounds, where the number of rounds depends on the
key length: 10 rounds for a 16-byte key, 12 rounds for a 24-byte key, and 14 rounds for a
32-byte key. The first N - 1 rounds consist of four distinct trans-
formation functions: SubBytes, ShiftRows, MixColumns, and AddRoundKey, which are
described subsequently. The final round contains only three transformations, and there is
a initial single transformation (AddRoundKey) before the first round,
which can be considered Round 0. Each transformation takes one or more 4 * 4
matrices as input and produces a 4 * 4 matrix as output. Figure 5.1 shows that the
output of each round is a 4 * 4 matrix, with the output of the final round being the
ciphertext. Also, the key expansion function generates N + 1 round keys, each of
which is a distinct 4 * 4 matrix. Each round key serve as one of the inputs to the
AddRoundKey transformation in each round.
Detailed Structure
Figure 5.3 shows the AES cipher in more detail, indicating the sequence of transfor-
mations in each round and showing the corresponding decryption function. As was
done in Chapter 3, we show encryption proceeding down the page and decryption
proceeding up the page.
Before delving into details, we can make several comments about the overall AES
structure.
Shiftrows
Each of the four rows of the matrix is shifted to the left. Any entries that ‘fall off’ are re-
inserted on the right side of row. Shift is carried out as follows −
First row is not shifted.
Second row is shifted one (byte) position to the left.
Third row is shifted two positions to the left.
Fourth row is shifted three positions to the left.
The result is a new matrix consisting of the same 16 bytes but shifted with respect
to each other.
MixColumns
Each column of four bytes is now transformed using a special mathematical function. This
function takes as input the four bytes of one column and outputs four completely new
bytes, which replace the original column. The result is another new matrix consisting of
16 new bytes. It should be noted that this step is not performed in the last round.
Addroundkey
The 16 bytes of the matrix are now considered as 128 bits and are XORed to the 128 bits
of the round key. If this is the last round then the output is the ciphertext. Otherwise, the
resulting 128 bits are interpreted as 16 bytes and we begin another similar round.
Decryption Process
The process of decryption of an AES ciphertext is similar to the encryption process in the
reverse order. Each round consists of the four processes conducted in the reverse order
−
AES Analysis
In present day cryptography, AES is widely adopted and supported in both hardware and
software. Till date, no practical cryptanalytic attacks against AES has been discovered.
Additionally, AES has built-in flexibility of key length, which allows a degree of ‘future-
proofing’ against progress in the ability to perform exhaustive key searches.
However, just as for DES, the AES security is assured only if it is correctly implemented
and good key management is employed.
‘
We now turn to a discussion of each of the four transformations used
in AES. For each stage, we describe the forward (encryption) algorithm, th
e inverse (decryption) algorithm, and the rationale for the stage.
Substitute Bytes Transformation
FORWARD AND INVERSE TRANSFORMATIONS The forward substitute byte transformation,
called Sub Bytes, is a simple table lookup (Figure 5.5a). AES defines a 16 * 16 matrix of byte
values, called an S-box (Table 5.2a), that contains a permutation of all possible 256 8-bit values.
Each individual byte of State is mapped into a new byte in the following
way: The leftmost 4 bits of the byte are used as a row value and the rightmost 4 bits are used as
a column value. These row and column values serve as indexes into the S-box to select a unique 8-
bit output value. For example, the hexadecimal value3 {95} references row 9, column 5
of the S-box, which contains the value {2A}. Accordingly, the value {95} is mapped
into the value {2A}.
Here is an example of the SubBytes transformation:
To see that InvSubBytes is the inverse of SubBytes, label the matrices in SubBytes
and InvSubBytes as X and B, respectively, and the vector versions of con- stants c
and d as C and D, respectively. For some 8-bit vector B, Equation (5.2) becomes
B¿ = XB Ⓧ C. We need to show that Y(XB Ⓧ C) Ⓧ D = B. To multiply out, we
must show YXB Ⓧ YC Ⓧ D = B. This becomes
We have demonstrated that YX equals the identity matrix, and the YC = D, so that
YC Ⓧ D equals the null vector.
ShiftRows Transformation
FORWARD AND INVERSE TRANSFORMATIONS The forward shift row transformation,
called ShiftRows, is depicted in Figure 5.7a. The first row of State is not altered. For
the second row, a 1-byte circular left shift is performed. For the third row, a 2-byte
circular left shift is performed. For the fourth row, a 3-byte circular left shift is
performed. The following is an example of ShiftRows.
The inverse shift row transformation, called InvShiftRows, performs the circu- lar
shifts in the opposite direction for each of the last three rows, with a 1-
byte circular right shift for the second row, and so on.
RATIONALE The shift row transformation is more substantial than it may first
appear. This is because the State, as well as the cipher input and output, is treated as
an array of four 4-byte columns. Thus, on encryption, the first 4 bytes of the plaintext
are copied to the first column of State, and so on. Furthermore, as will be seen, the
round key is applied to State column by column. Thus, a row shift moves an
individual byte from one column to another, which is a linear
distance of a multiple of 4 bytes. Also note that the transformation ensures that the 4
bytes of one column are spread out to four different columns. Figure 5.4 illustrates
the effect.
MixColumns Transformation
FORWARD AND INVERSE TRANSFORMATIONS The forward mix column transformation
, called MixColumns, operates on each column individually. Each byte of a column is
mapped into a new value that is a function of all four bytes in that column.
The transformation can be defined by the following matrix
multiplication on State (Figure 5.7b):
Each element in the product matrix is the sum of products of elements of one row and
one column. In this case, the individual additions and multiplications5 are performed
in GF(28). The MixColumns transformation on a single column of State can
be expressed as
Let us verify the first column of this example. Recall from Section 4.7 that, in
GF(28), addition is the bitwise XOR operation and that multiplication can be per-
formed according to the rule established in Equation (4.14). In particular, multipli-
cation of a value by x (i.e., by {02}) can be implemented as a 1-bit left shift followed
by a conditional bitwise XOR with (0001 1011) if the leftmost bit of the original
value (prior to the shift) is 1. Thus, to verify the MixColumns transformation on the
first column, we need to show that
The other equations can be similarly verified.
The inverse mix column transformation, called InvMixColumns, is defined by the
following matrix multiplication:
It is not immediately clear that Equation (5.5) is the inverse of Equation (5.3).
We need to show
That is, the inverse transformation matrix times the forward transformation matrix
equals the identity matrix. To verify the first column of Equation (5.6), we need to
show
For the first equation, we have {0E} . {02} = 00011100 and {09} . {03}
= {09} Ⓧ ({09} # {02}) = 00001001 Ⓧ 00010010 = 00011011. Then
1. For the CFB and OFB cipher modes (Figures 6.5 and 6.6; described in
Chapter 6), only encryption is used.
2. As with any block cipher, AES can be used to construct a message a
uthentica- tion code (Chapter 12), and for this, only encryption is used.
AddRoundKey Transformation
FORWARD AND INVERSE TRANSFORMATIONS In the forward add round
key transfor- mation, called AddRoundKey, the 128 bits of State are bitwise
XORed with the 128 bits of the round key. As shown in Figure 5.5b, the operation is
viewed as a columnwise operation between the 4 bytes of a State column and one
word of the round key; it can also be viewed as a byte-level
operation. The following is an example of AddRoundKey:
The first matrix is State, and the second matrix is the round key.
The inverse add round key transformation is identical to the forward add round
key transformation, because the XOR operation is its own inverse.
RATIONALE The add round key transformation is as simple as possible and affects
every bit of State. The complexity of the round key expansion, plus the complexity
of the other stages of AES, ensure security.
Figure 5.8 is another view of a single round of AES, emphasizing the mecha- nisms
and inputs of each transformation.