4 - Module 2 - Symmetric-Key Ciphers 2023-Part 3
4 - Module 2 - Symmetric-Key Ciphers 2023-Part 3
ICT 3172:
Advanced Encryption Standards (AES)
.
History
.
Rounds
• The key size, which can be 128, 192, or 256 bits, depends on the
number of rounds.
.
Rounds
.
AES has defined three versions, with 10, 12, and 14 rounds.
Each version uses a different cipher key size (128, 192, or 256),
but the round keys are always 128 bits.
.
Data Units
• AES uses 5 units of measurement to refer to data: bits, bytes, words, blocks,
and state.
• Bit is the smallest unit; other units can be expressed in terms of smaller ones.
.
Data Units
Bit
bit is a binary digit with a value of 0 or 1. lowercase letter to refer to a bit.
Byte
• group of eight bits that can be treated as a single entity, a row matrix (1 × 8) of eight bits,
or a column matrix (8 × 1) of eight bits.
• When treated as a row matrix, the bits are inserted to the matrix from left to right; when
treated as a column matrix, the bits are inserted into the matrix from top to bottom.
• lowercase bold letter to refer to a byte.
Word
• A word is a group of 32 bits that can be treated as a single entity, a row matrix of four
bytes, or a column matrix of four bytes.
• When it is treated as a row matrix, the bytes are inserted into the matrix from left to
right; when it is considered as a column matrix, the bytes are inserted into the matrix
from top to bottom.
• We use the lowercase bold letter to show a word.
Block
• AES encrypts and decrypts data blocks.
• A block in AES is a group of 128 bits.
.
State
At the beginning and end of the cipher, AES uses the term data block; before
and after each stage, the data block is referred to as a state.
Although the states in different stages are normally called S, letter T to refer to
a temporary state.
.
States, like blocks, are made of 16 bytes, but normally are treated as matrices
of 4 × 4 bytes.
.
Example 7.1
Example: The text block is “AES uses a matrix”. We add two bogus characters at the end
to get “AESUSESAMATRIXZZ”.
Replace each character with an integer between 00 and 25. Then show each byte as an
integer with two hexadecimal digits.
.
Structure of Each Round
.
7.2 TRANSFORMATIONS
Substitution
.
SubBytes
.
Table shows the substitution table (S-box) for SubBytes transformation. The
transformation definitely provides confusion effect.
For example, two bytes, 5A16 and 5B16, which differ only in one bit (the
rightmost bit) are transformed to BE16 and 3916, which differ in four bits.
.
InvSubBytes
InvSubBytes is the inverse of SubBytes.
The transformation is done using Table 7.2.
.
.
Transformation Using the GF(28) Field
SubBytes transformation
repeats a routine, called
subbyte, 16 times.
.
In the subbyte routine, the multiplicative inverse of the byte is found in GF(2 8) with the
irreducible polynomial (x8 + x4 + x3+ x + 1) as the modulus.
This column matrix is multiplied by a constant square matrix, X, and the result is added
with a constant column matrix, y, to give the new byte.
.
The invsubbyte is doing the same thing in reverse order.
.
Example 7.3 : How the byte 0C is transformed to FE by subbyte routine and
transformed back to 0C by the invsubbyte routine.
1. subbyte:
a. Multiplicative inverse of 0C in GF(28) field is B0, which means b is
(10110000).
b. Multiplying matrix X by this matrix results in c = (10011101)
c. The result of XOR operation is d = (11111110), which is FE in hexadecimal.
2. invsubbyte:
a. The result of XOR operation is c = (10011101)
b. The result of multiplying by matrix X−1 is (11010000) or B0
c. The multiplicative inverse of B0 is 0C.
.
Algorithm
• The algorithm does not necessarily use multiplication and addition of
matrices because most of the elements in the constant square matrix
are only 0 or 1.
• The value of the constant column matrix is 0x63.
• Algorithm 7.1 calls the subbyte routine 16 time, one for each byte in
the state.
ShiftRows
• In the encryption, the transformation is called ShiftRows and the shifting is to
the left.
• The number of shifts depends on the row number (0, 1, 2, or 3) of the state
matrix.
.
ShiftRows
• In the encryption, the transformation is called ShiftRows and the shifting is to the left.
• The number of shifts depends on the row number (0, 1, 2, or 3) of the state matrix.
• This means the row 0 is not shifted at all and the last row is shifted three bytes.
.
InvShiftRows
In the decryption, the transformation is called InvShiftRows and the shifting is
to the right.
The number of shifts is the same as the row number (0, 1, 2, and 3) of the
state matrix.
.
Algorithm
Transformation is one row at a time, routine called shiftrow that shifts the byte
in a single row. Call this routine three times.
The shiftrow routine first copies the row into a temporary row matrix, t. It then
shifts the row.
.
.
Mixing
.
Mixin
g
Mixing transformation changes the contents of each byte by taking
four bytes at a time and combining them to recreate four new bytes.
To guarantee that each new byte is different (even if all four bytes are
the same), the combination process first multiplies each byte with a
different constant and then mixes them.
.
• AES defines a transformation, called MixColumns, to achieve this goal.
• These two matrices are inverses of each other when the elements are interpreted as
8-bit words (or polynomials) with coefficients in GF(2 8).
.
MixColumns
The bytes in the state column and constants matrix are interpreted as 8-bit
words (or polynomials) with coefficients in GF(2).
.
InvMixColumns
The InvMixColumns transformation is basically the same as the MixColumns
transformation.
If the two constant matrices are inverses of each other, it is easy to prove that
the two transformations are inverses of each other.
.
Algorithm 7.3 shows the code for MixColumns transformation
Algorithms for MixColumns and InvMixColumns involve multiplication and addition in the
GF(28) field.
The routine mixcolumn simply multiplies the rows of the constant matrix by a column in the
state.
The operator (•) used in the mixcolumn routine is multiplication in the GF(2 8) field.
.
Example 7.5
Figure 7.14 shows how a state is transformed using the MixColumns
transformation. The figure
also shows that the InvMixColumns transformation creates the original one.
Note that equal bytes in the old state are not equal any more in the new
state. For example, the two bytes F2 in the second row are changed to CF
and 0D.
.
Key Adding
Most important transformation is the one that includes the cipher key.
If the cipher key is not added to the state at each round, it is very easy for the
adversary to find the plaintext, given the ciphertext.
Each round key is 128 bits long. It is treated as four 32-bit words.
.
AddRoundKey
AddRoundKey adds a round key word with each state column matrix.
Since addition and subtraction in this field are the same, the AddRoundKey transformation
is the inverse of itself.
The ⊕ operator here means XORing two column matrices, each of 4 bytes.
.
7.3 KEY EXPANSION
Key-expansion process to create round key for each round,
If the number of rounds is Nr, key-expansion routine creates Nr+1 128-bit round
keys.
Remaining round keys are used for the last transformation (AddRoundKey) at the
end of each round.
.
7.3 KEY EXPANSION
key-expansion routine creates round keys word by word, where a word is an array of 4 bytes.
.
7.3 KEY EXPANSION
.
Key Expansion in AES-128
2. The rest of the words (wi for i = 4 to 43) are made as follows:
b. If (i mod 4) = 0, wi = t ⊕ wi−4.
Here t, a temporary word, is the result of applying two routines, SubWord
and RotWord, on wi−1 and XORing the result with a round constants, RCon.
In other words, we have,
.
RotWord
• The routine takes a word as an array of four bytes and shifts each byte to
the left with wrapping.
• Ex: input word [b0,b1,b2,b3] is transformed into [b1, b2,b3,b0]
SubWord
• The SubWord (substitute word) routine is similar to the SubBytes
transformation, but it is applied only to four bytes.
• The routine takes each byte in the word and substitutes another byte for it.
Round Constants
Each round constant, RCon, is a 4-byte value in which the rightmost 3 bytes are
always zero.
Table 7.4 shows the values for AES-128 version (with 10 rounds).
.
Round Constants
Each round constant, RCon, is a 4-byte value in which the rightmost three
bytes are always zero.
Table 7.4 shows the values for AES-128 version (with 10 rounds).
.
Key expansion in AES-192 and AES 256
.
8.1 USE OF MODERN BLOCK CIPHERS
The two modern block ciphers namely DES and AES, are designed to encipher
and decipher a block of text of fixed size.
DES encrypts and decrypts a block of 64 bits; AES encrypts and decrypts a
block of 128 bits.
.
Modes of operation have been devised to encipher text of any size
employing either DES or AES.
.
Electronic Codebook (ECB) Mode
If the plaintext size is not a multiple of the block size, the text is padded to
make the last block the same size as the other blocks.
.
Electronic Codebook (ECB) Mode
.
Cipher Block Chaining (CBC) Mode
When a block is enciphered, the block is sent, but a copy of it is kept in memory
to be used in the encryption of the next block.
The reader may wonder about the initial block. There is no ciphertext block
before the first block.
In this case, a phony block called the initialization vector (IV) is used.
.
Cipher Block Chaining (CBC) Mode
Figure 8.3 shows CBC mode. At the sender side, exclusive-oring is done before
encryption; at the receiver site, decryption is done before exclusive-oring.
.
Cipher Feedback (CFB) Mode
In some situations, we need to use DES or AES as secure ciphers, but the
plaintext or ciphertext block sizes are to be smaller.
For example, to encrypt and decrypt ASCII 8-bit characters, you would not want
to use one of the traditional ciphers because they are insecure.
In this mode the size of the block used in DES or AES is n, but the size of the
plaintext or ciphertext block is r, where r <=n
.
Cipher Feedback (CFB) Mode
.
Cipher Feedback (CFB) Mode
.
Output Feedback (OFB) Mode
.
Counter (CTR) Mode
.
Counter (CTR) Mode
.
END