Lecture - 03 AES
Lecture - 03 AES
Advanced Encryption
Standard (AES)
1
14-Apr-20
Introduction
• will now introduce finite fields
• of increasing importance in cryptography
– AES, Elliptic Curve, IDEA, Public Key
• concern operations on “numbers”
– where what constitutes a “number” and the
type of operations varies considerably
• start with concepts of groups, rings, fields
from abstract algebra
Modular Arithmetic
• define modulo operator “a mod n” to be
remainder when a is divided by n
• use the term congruence for: a = b mod n
– when divided by n, a & b have same remainder
– eg. 100 = 34 mod 11
• b is called a residue of a mod n
– since with integers can always write: a = qn + b
– usually chose smallest positive remainder as residue
• ie. 0 <= b <= n-1
– process is known as modulo reduction
• eg. -12 mod 7 = -5 mod 7 = 2 mod 7 = 9 mod 7
2
14-Apr-20
Galois Fields
• finite fields play a key role in cryptography
• can show number of elements in a finite
field must be a power of a prime pn
• known as Galois fields
• denoted GF(pn)
• in particular often use the fields:
– GF(p)
– GF(2n)
3
14-Apr-20
4
14-Apr-20
Polynomial Arithmetic
• can compute using polynomials
f(x) = anxn + an-1xn-1 + … + a1x + a0 = ∑ aixi
• nb. not interested in any specific value of x
• which is known as the indeterminate
• several alternatives available
– ordinary polynomial arithmetic
– poly arithmetic with coords mod p
– poly arithmetic with coords mod p and
polynomials mod m(x)
5
14-Apr-20
Byte - b7b6b5b4b3b2b1b0
• Bytes represent finite field elements in GF(28), GF means “Galois Field”
• Correspond to a 8 term polynomial, with 0 or 1 coefficients.
Example:
x6 + x5 + x3 + x2 + 1 polynomial
6D hex
Example:
6
14-Apr-20
Multiplication is the basis for non-linear behaviour of AES: it’s easy to understand
over polynomials, but hard to predict as operation on bytes.
x
x8 + x4 + x3 + x + 1 x9 + x7 + x2 + x
x9 + x5 + x4 + x2 + x
x7 + x5 + x4
Result = x7 + x5 + x4
7
14-Apr-20
8
14-Apr-20
Origins
• clear a replacement for DES was needed
– have theoretical attacks that can break it
– have demonstrated exhaustive key search attacks
• can use Triple-DES – but slow, has small blocks
• US NIST issued call for ciphers in 1997
• 15 candidates accepted in Jun 98
• 5 were shortlisted in Aug-99
• Rijndael was selected as the AES in Oct-2000
• issued as FIPS PUB 197 standard in Nov-2001
AES Requirements
• private key symmetric block cipher
• 128-bit data, 128/192/256-bit keys
• stronger & faster than Triple-DES
• active life of 20-30 years (+ archival use)
• provide full specification & design details
• both C & Java implementations
• NIST have released all submissions &
unclassified analyses
9
14-Apr-20
AES Shortlist
• after testing and evaluation, shortlist in Aug-99:
– MARS (IBM) - complex, fast, high security margin
– RC6 (USA) - v. simple, v. fast, low security margin
– Rijndael (Belgium) - clean, fast, good security margin
– Serpent (Euro) - slow, clean, v. high security margin
– Twofish (USA) - complex, v. fast, high security margin
• then subject to further analysis & comment
• saw contrast between algorithms with
– few complex rounds verses many simple rounds
– which refined existing ciphers verses new proposals
10
14-Apr-20
Rijndael/AES
• data block of 4 columns of 4 bytes is state
• key is expanded to array of words
• has 9/11/13 rounds in which state undergoes:
– byte substitution (1 S-box used on every byte)
– shift rows (permute bytes between groups/columns)
– mix columns (subs using matrix multipy of groups)
– add round key (XOR state with key material)
– view as alternating XOR key & scramble data bytes
• initial XOR key material & incomplete last round
• with fast XOR & table lookup implementation
11
14-Apr-20
Rijndael
12
14-Apr-20
Detailed Structure
• Processes the entire data block as a single matrix during each round using substitutions and
permutation
• The key that is provided as input is expanded into an array of forty-four 32-bit words, w[i]
IN OUT
ARK BS ARK BS SR ARK
(ROUND-1..9)
SR MC
13
14-Apr-20
State
• State is a 4 by 4 array of bytes, initialised (col-by-col) with the 16-
byte plaintext block (see below)
• Final value of state is returned as ciphertext
State 0 1 2 3
0 in[0] in[4] in[8] in[12]
1 in[1] in[5] in[9] in[13]
2 in[2] in[6] in[10] in[14]
3 in[3] in[7] in[11] in[15]
0 1
1
2
3
2
5 9 13
3 4 5
6 10 14
7 11 15
6
= 7 8
S S1,1 S1,2 S1,3
9 1,0
10 11 12 13 14 15
S2,0 S2,1 S2,2 S2,3
S3,0 S3,1 S3,2 S3,3
28
14
14-Apr-20
Byte Substitution
• a simple substitution of each byte
• uses one table of 16x16 bytes containing a
permutation of all 256 8-bit values
• each byte of state is replaced by byte indexed by
row (left 4-bits) & column (right 4-bits)
– eg. byte {95} is replaced by byte in row 9 column 5
– which has value {2A}
• S-box constructed using defined transformation
of values in GF(28)
• designed to be resistant to all known attacks
Table 6.2
(a) S-box
(Table can be found on page 155 in textbook)
15
14-Apr-20
Table 6.2
Byte Substitution
16
14-Apr-20
Shift Rows
• a circular byte shift in each each
– 1st row is unchanged
– 2nd row does 1 byte circular shift to left
– 3rd row does 2 byte circular shift to left
– 4th row does 3 byte circular shift to left
• decrypt inverts using shifts to right
• since state is processed by columns, this step
permutes bytes between the columns
Shift Rows
17
14-Apr-20
MixColumn
• Apply MixColumn transformation to each
column s 02 03 01 01 s
'
0 ,c 0 ,c
'
s1,c 01 02 03 01 s 1 , c
'
s
2 ,c 01 01 02 03 s 2 , c
s'
3 ,c 03 01 01 02 s 3 , c
MixColumns()
S0,1 S’0,1
S’0,c
S0,0 S0,1 S0,2 = ({02} S0,c) ({03} S1,c) SS’
S0,3 S
2,c0,0 S’3,c S’ S’
0,1 0,2 0,3
S
S1,0 S1,1
1,1 S S S’ S’
S’
1,1 S’
= S0,c ({02} S1,c) ({03} S2,c)1,0
S’1,c1,3
1,2 S3,c1,1 1,2 S’1,3
S2,0 S
S2,1 S2,2 S2,3 S’ S’ S’2,1 S’2,2 S’2,3
2,1 S’2,c = S0,c S1,c ({02} S2,c ) ({03}2,0
S3,c
2,1)
S3,0 S3,1 S3,2 S3,3 S’3,0 S’3,1 S’3,2 S’3,3
S3,1 S’3,c = ({03} S0,c) S1,c S2,c ({02} S’ S3,c
3,1
35
ShiftRows Transformation
• Cyclically rotate LEFT last 3 ROWS of state matrix by 1, 2 and 3 bytes resp.
a b c d a b c d
e f g h Rotate left 1 Byte f g h e
i j k l Rotate left 2 Bytes k l i j
m n o p Rotate left 3 Bytes p m n o
18
14-Apr-20
ShiftRow
• Last three rows are cyclically shifted
37
Mix Columns
• each column is processed separately
• each byte is replaced by a value
dependent on all 4 bytes in the column
• effectively a matrix multiplication in GF(28)
using prime poly m(x) =x8+x4+x3+x+1
19
14-Apr-20
Mix Columns
MixColumns Transformation
• Multiply each column by {03}x3 + {01}x2 + {01}x + {02}
mod (x4 + 1)
i.e. columns are word-polynomials
• This is equivalent to replacing the 4 bytes (m,n,p,q) in a
column as follows:
m {02}m {03}n p q
n m {02}n {03}p q
p m n {02}p {03}q
q {03}m n p {02}q
20
14-Apr-20
Mix Columns
• can express each col as 4 equations
– to derive each new byte in col
• decryption requires use of inverse matrix
– with larger coefficients, hence a little harder
• have an alternate characterisation
– each column a 4-term polynomial
– with coefficients in GF(28)
– and polynomials multiplied modulo (x4+1)
21
14-Apr-20
MixColumn
• Apply MixColumn transformation to each
column s 02 03 01 01 s
'
0 ,c 0 ,c
'
s1,c 01 02 03 01 s 1 , c
'
s
2 ,c 01 01 02 03 s 2 , c
s'
3 ,c 03 01 01 02 s 3 , c
MixColumns()
S0,1 S’0,1
S’0,c
S0,0 S0,1 S0,2 = ({02} S0,c) ({03} S1,c) SS’
S0,3 S
2,c0,0 S’3,c S’ S’
0,1 0,2 0,3
S
S1,0 S1,1
1,1 S S S’ S’
S’
1,1 S’
= S0,c ({02} S1,c) ({03} S2,c)1,0
S’1,c1,3
1,2 S3,c1,1 1,2 S’1,3
S2,0 S
S2,1 S2,2 S2,3 S’ S’ S’2,1 S’2,2 S’2,3
2,1 S’2,c = S0,c S1,c ({02} S2,c ) ({03}2,0
S3,c
2,1)
S3,0 S3,1 S3,2 S3,3 S’3,0 S’3,1 S’3,2 S’3,3
S3,1 S’3,c = ({03} S0,c) S1,c S2,c ({02} S’ S3,c
3,1
43
22
14-Apr-20
AddRoundKey
• XOR each byte of the round key with its
corresponding byte in the state array
XOR
S0,1
S0,0 S0,1 S0,2 S0,3
S1,1 S S
S1,0 S1,1 1,2 1,3 S’0,1
R0,1
S2,0 S S2,2 S2,3 S’0,0 S’0,1 S’0,2 S’0,3
S2,1
2,1 R0,0 R0,1 R0,2 R0,3
S3,0 S3,1 S3,2 S3,3 R1,1 R R S’ S’
1,0 S’1,1 S’ S’
1,1 1,2 1,3
R R
1,0 1,1 1,2 1,3
S3,1 S’2,0S’
S’2,1 S’2,2 S’2,3
R2,0 R2,1 R2,2 R2,3 2,1
R2,1 S’3,0 S’3,1 S’3,2 S’3,3
R3,0 R3,1 R3,2 R3,3
S’3,1
R3,1 45
AddRoundKey Transformation
• The 128 bits of State
are bitwise XORed with
the 128 bits of the Rationale:
round key
• Operation is viewed as Is as simple as possible
and affects every bit of
a columnwise operation State
between the 4 bytes of
a State column and one The complexity of the round
key expansion plus the
word of the round key complexity of the other
stages of AES ensure
• Can also be viewed as a security
byte-level operation
23
14-Apr-20
State matrix
at beginning
of round
SubBytes
S-box
ShiftRows
02 03 01 01
01
02 03 01
MixColumns
01 01 02 03
03
01 01 02
MixColumns matrix
Round
key
AddRoundKey
State matrix
at end
of round
Constant inputs Variable input
24
14-Apr-20
k0 k4 k8 k12
w
k1 k5 k9 k13
k2 k6 k10 k14 g
k3 k7 k11 k15 B0 B1 B2 B3
w0 w1 w2 w3 g
B1 B2 B3 B0
S S S S
w'
(b) Function g
w40 w41 w42 w43
25
14-Apr-20
Description Value
i (decimal) 36
temp = w[i - 1] 7F8D292F
RotWord (temp) 8D292F7F
Table 6.4
w9 = w8 w5 = 49 80 b4 5e
Rcon(3)= 04 00 00 00
w10 = w9 w6 = de 7e c6 61 y3 Rcon(3)= 12 66 b4 8e = z 3
w11 = w10 w7 = e6 ff d3 c6
w12 = w8 z3 = c0 af df 39 RotWord(w15)= ae 7e c0 b1 = x 4
SubWord(x3)= e4 f3 ba c8 = y 4
w13 = w12 w9 = 89 2f 6b 67 Rcon(4)= 08 00 00 00
w14 = w13 w10 = 57 51 ad 06
Key Expansion w15 = w14 w11 = b1 ae 7e c0
y4 Rcon(4)= ec f3 ba c8 = 4
RotWord(w19)= 8c dd 50 43 = x 5
w16 = w12 z4 = 2c 5c 65 f1
w17 = w16 w13 = a5 73 0e 96 SubWord(x4)= 64 c1 53 1a = y 5
Rcon(5)= 10 00 00 00
w18 = w17 w14 = f2 22 a3 90
y5 Rcon(5)= 74 c1 53 1a = z 5
for w19 = w18 w15 = 43 8c dd 50
w20 = w16 z5 = 58 9d 36 eb RotWord(w23)= 40 46 bd 4c = x 6
SubWord(x5)= 09 5a 7a 29 = y 6
w21 = w20 w17 = fd ee 38 7d Rcon(6)= 20 00 00 00
w22 = w21 w18 = 0f cc 9b ed y6 Rcon(6)= 29 5a 7a 29 = z 6
w23 = w22 w19 = 4c 40 46 bd
AES Example w24 = w20 z6 = 71 c7 4c c2 RotWord(w27)= a5 a9 ef cf = x 7
SubWord(x6)= 06 d3 df 8a = y 7
w25 = w24 w21 = 8c 29 74 bf
Rcon(7)= 40 00 00 00
w26 = w25 w22 = 83 e5 ef 52
y7 Rcon(7)= 46 d3 df 8a = z 7
w27 = w26 w23 = cf a5 a9 ef
w28 = w24 z7 = 37 14 93 48 RotWord(w31)= 7d a1 4a f7 = x 8
SubWord(x7)= ff 32 d6 68 = y 8
w29 = w28 w25 = bb 3d e7 f7 Rcon(8)= 80 00 00 00
w30 = w29 w26 = 38 d8 08 a5 y8 Rcon(8)= 7f 32 d6 68 = z 8
w31 = w30 w27 = f7 7d a1 4a
w32 = w28 z8 = 48 26 45 20 RotWord(w35)= be 0b 38 3c = x 9
w33 = w32 w29 = f3 1b a2 d7 SubWord(x8)= ae 2b 07 eb = y 9
Rcon(9)= 1B 00 00 00
w34 = w33 w30 = cb c3 aa 72
y9 Rcon(9)= b5 2b 07 eb = z 9
w35 = w34 w32 = 3c be 0b 38
w36 = w32 z9 = fd 0d 42 cb RotWord(w39)= 6b 41 56 f9 = x 10
SubWord(x9)= 7f 83 b1 99 = y 10
w37 = w36 w33 = 0e 16 e0 1c Rcon(10)= 36 00 00 00
w38 = w37 w34 = c5 d5 4a 6e y10 Rcon(10)= 49 83 b1 99 = z 10
w39 = w38 w35 = f9 6b 41 56
w40 = w36 z10 = b4 8e f3 52
w41 = w40 w37 = ba 98 13 4e
w42 = w41 w38 = 7f 4d 59 20
w43 = w42 w39 = 86 26 18 76
26
14-Apr-20
Table 6.5
AES
EXAMPLE
Table 6.6
Avalanche
Effect
in AES:
Change
in Plaintext
(Table is located on page 170
in textbook)
27
14-Apr-20
AES: 5
721eb200ba06206dcbd4bce704fa654e
5955c91b4e769f3cb4a94768e98d5267
81
0ad9d85689f9f77bc1c5f71185e5fb14
Change in 6
dc60a24d137662181e45b8d3726b2920
70
db18a8ffa16d30d5f88b08d777ba4eaa
Key 7
fe8343b8f88bef66cab7e977d005a03c
74
f91b4fbfe934c9bf8f2f85812b084989
8 67
da7dad581d1725c5b72fa0f9d9d1366a
cca104a13e678500ff59025f3bafaa34
9 59
0ccb4c66bbfd912f4b511d72996345e0
(Table is located on page 171
in textbook) ff0b844a0853bf7c6934ab4364148fb9
10 53
fc8923ee501a7d207ab670686839996b
AES Implementation
• AES decryption cipher
is not identical to the Two separate changes are
needed to bring the
encryption cipher decryption structure in line
• The sequence of with the encryption structure
transformations differs
although the form of
the key schedules is
The first two stages of the
the same decryption round need to be
• Has the disadvantage interchanged
that two separate
software or firmware
modules are needed
for applications that The second two stages of the
require both encryption decryption round need to be
and decryption interchanged
28
14-Apr-20
AES Round
29
14-Apr-20
30
14-Apr-20
AES Decryption
• AES decryption is not identical to
encryption since steps done in reverse
• but can define an equivalent inverse
cipher with steps as for encryption
– but using inverses of each step
– with a different key schedule
• works since result is unchanged when
– swap byte substitution & shift rows
– swap mix columns & add (tweaked) round key
AES Decryption
31
14-Apr-20
Shift rows
Round 1
Shift rows
Round 9
Shift rows
32
14-Apr-20
Key Expansion
Ciphers
• Ciphers and inverse ciphers in AES
33
14-Apr-20
Ciphers
• Ciphers and inverse ciphers in AES
– Invertibility of SubBytes and ShiftRows
combinations
Ciphers
• Ciphers and inverse ciphers in AES
– Invertibility of MixColumns and AddRoundKey
combination
34
14-Apr-20
Ciphers
• Alternative design of ciphers and inverse
ciphers
1.69
Analysis of AES
• Security of AES
– AES is definitely more secure than DES due to
the larger-size key
– Numerous tests have failed to do statistical
analysis of the ciphertext
– There are no differential and linear attacks on
AES as yet
1.70
35
14-Apr-20
Analysis of AES
• Implementation of AES
– AES can be implemented in software,
hardware, and firmware
– The algorithms used in AES are so simple that
they can be easily implemented using cheap
processors and a minimum amount of memory
1.71
Implementation Aspects
• can efficiently implement on 8-bit CPU
– byte substitution works on bytes using a table
of 256 entries
– shift rows is simple byte shift
– add round key works on byte XOR’s
– mix columns requires matrix multiply in GF(28)
which works on byte values, can be simplified
to use table lookups & byte XOR’s
36
14-Apr-20
Implementation Aspects
• can efficiently implement on 32-bit CPU
– redefine steps to use 32-bit words
– can precompute 4 tables of 256-words
– then each column in each round can be
computed using 4 table lookups + 4 XORs
– at a cost of 4Kb to store tables
• designers believe this very efficient
implementation was a key factor in its
selection as the AES cipher
Summary
• have considered:
– the AES selection process
– the details of Rijndael – the AES cipher
– looked at the steps in each round
– the key expansion
– implementation aspects
37