Lecture 2- Symmetric-Key-Encryption - Notes
Lecture 2- Symmetric-Key-Encryption - Notes
1
Reminder of last week
❑ Information security
o Basic concepts and terminology
o Threats, services, mechanisms, algorithms
❑ Whereto find countermeasures and
mechanisms?
o What is a standard? Good and bad aspects.
o Standard bodies
o Internet/company standards
2
Today’s Lecture
❑ Confidentiality
o Symmetric key encryption mechanisms
❑ CILO2 and CILO5
(technology that impact systems, and
security mechanisms)
3
Cryptographic Tools:
4
Crypto – a brief introduction
❑ Cryptology ⎯ The art and science of making and breaking
“secret codes”
❑ Cryptography ⎯ making “secret codes”
o ychrpyaprtgo
o C=MK
❑ Cryptanalysis ⎯ breaking “secret codes”
o ychrpyaprtgo is cracked to ______________, QED.
❑ Crypto ⎯ all of the above (and more)
o More on non-repudiation (signature), authentication,
identification, zero-knowledge, commitment, and more…
o Any reference books?... Bruce Schneier’s Applied Cryptography, Handbook
of Applied Cryptography, Introduction to Modern Cryptography
Reference slides
5
"The history of codes and ciphers
is the story of the centuries-old
battle between codemakers and
codebreakers, an intellectual arms
race that has had a dramatic
impact on the course of history."
– Simon Singh, The Code Book
Cryptography – Part I 6
References slide
This is essentially the same remarks one can make about anything
in security – it is an ‘arms race’ between those who design secure
systems and those who wish to circumvent security
countermeasures.
6
• A symmetric-key cipher or cryptosystem is used for encrypting/decrypting a
plaintext/ciphertext
• The same key is used for encrypting and decrypting
Alice Bob
eavesdropper
plaintext
cryptanalysis key
7
Cryptanalysis
Basic assumptions
o The system is completely known to the attacker
o Only the key is secret
o Also known as Kerckhoffs Principle
o Crypto algorithms are not secret
o No “security through obscurity”
Objective of an attacker
o Identify secret key used to encrypt a ciphertext
o (OR) recover the plaintext of a ciphertext without the
secret key
-----------------
For interest
8
System is known to the attacker – what does he know about our
plaintext/ciphertext
There are different approaches
Ciphertext only (attacker sees only encrypted data), known plaintext
(attacker sees ciphertext but he knows the plaintext), chosen plaintext
(the attacker can ask our system to encrypt plaintext messages he
chooses)!
8
Examples of (Classical) Symmetric Key Encryption
Algorithms – Classical Cryptography
Ciphertexts:
1. IRXUVFRUHDQGVHYHQBHDUVDJR
2. VSRQJHEREVTXDUHSDQWV
ab c d e f g h i j k l mn o p q r s t u v wx y z
D E F G H I J K L M N O P Q R S T U VWX Y Z A B C
Caesar Cipher
• Famous early use of cryptography was by the Roman Emperor Julius Caesar
• Caesar cipher (a.k.a. shift cipher) is a type of substitution cipher
• Cipher algorithm: each letter in the plain alphabet is replaced with the letter
n places further on in the alphabet
• Key: n, the number of letters to shift
I expect you to know what a substitution cipher is, and know the
special case of Ceasar cipher type.
1. IRXUVFRUHDQGVHYHQBHDUVDJR
FOURSCORE AND SEVEN YEARS AGO
2. VSRQJHEREVTXDUHSDQWV
Sponge Bob Square Pants
9
Example
❑ Plain letters are written in lower case and
cipher letters in UPPER CASE
❑ Key is 3
abcdefghijklmnopqrstuvwxyz
DEFGHIJKLMNOPQRSTUVWXYZABC
❑ Write out plain message: hello everyone
❑ encipher each letter in turn by looking for the
corresponding letter in the cipher translation
table.
❑ This gives the ciphertext message:
KHOOR HYHUBRQH
KHOORHYHURQH
10
So as long as the message recipient
knows the key – how many letters you
have shifted the alphabet by – they can
build the cipher alphabet and decipher
the message by going through the
cipher algorithm in reverse.
KHOOR HYHUBRQH
hello everyone
11
Other simple substitution
ciphers
❑ Caesar cipher has only 25 possible
cipher alphabets
❑ Wouldn’t take long to try them all
❑ Other cipher systems use less regular
methods for generating alphabets
❑ Must still have a key to generate an
alphabet the recipient can reproduce
12
Example
❑ Take as your key a favourite quote.
❑ For example, take:
“pure mathematics is, in its way, the
poetry of logical ideas”
❑ First strip out repeating letters so
each letter is unique
13
pure mathematics is, in its way,
puremathicsnwyoflgd
14
❑ Fill in this sequence as the start of your
cipher alphabet.
a b c d e f g h ij k l m n o p q r s t u v w x y z
P U R E M A T H IC S N W Y O F L G D Z X V Q K J B
❑ Fill up the alphabet with the letters which
have not been used, in some systematic order
(here we have used reverse alphabetical
order)
❑ This cipher alphabet is less predictable than
the Caesar cipher, yet it is still simple for
both sender and receiver to generate,
provided they know the key phrase
What is the key in this case? What must both parties know?
You should know the substitution table but I would argue that the
complete phrase is the key. This allows both parties to construct
the table and encrypt/decrypt.
15
Simple Substitution: each plaintext letter is substituted by
a distinct ciphertext letter
EIMBULJIWLNYANJMVLIURAHIWAI
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
DEPARTMENTOFCOMPUTERSCIENCE
You can choose any permutation you like as long as the recipient
knows what you are using.
16
An example of simple substitution…
17
An Example
18
Question: how secure is Simple Substitution?
19
• A secret key (in Simple Substitution) is a random permutation of the alphabetic
characters.
• E.g.
• Question: how many distinct permutations are there? (in other words,
how many distinct secret keys are in the key space?)
20
• Total number of possible permutations
26!
• 26! = 403,291,461,126,605,635,584,000,000 (27 digits) 288
• Calculation: suppose we have one million 3GHz PCs which can try 3
billion permutations per second, the machines will take 4,263 years to
try all the 26! permutations…
• Not so efficient
Brute force is not the best way of doing things – all algorithms
can be brute forced! It is just that some algorithms require more
effort to brute force than others.
Also think about the practical issues involved with brute force –
how you do know when you found the right permutation? In
substitution it is easier – the plaintext must be coherent text.
21
Cracking substitution ciphers
❑ In the eighth century AD, Islamic culture
entered a golden age
❑ The most learned society of its time
❑ Cryptography was routinely used for matters
of state
❑ This led to the development of cryptanalysis,
with scholars using a combination of
mathematics, statistics and linguistics to
develop techniques for deciphering messages
when the key is unknown
22
Letter frequencies
❑ In studies of the text of the Qur’an,
scholars had noticed that some letters
appear more frequently than others
❑ In English the letters e and t are used
much more frequently than the letters z
and q, and this fact can be used to
decipher messages
❑ This process is called frequency analysis
23
Statistical Attack / Frequency Analysis
• An interesting observation on simple substitution: the relative
letter frequencies do not change during encryption
• Average letter frequencies in English (Beker and Piper, 1982)
24
Further frequency analysis
❑ Pairs of letters in words are most
likely to be: “ss”, “ee”, “tt”, “ff”, “ll”,
“mm” or “oo”.
❑ A one letter word is either “a” or “I”.
❑ Two letter words are commonly: “of”,
“to”, “in”, “it”, “is”, “be”, “as”, “at”, “so”,
“we”, “he”, “by”, “or”, “on” or “do”, in
that order.
25
Further frequency analysis
❑ Three letter words are commonly
“the” or “and”.
❑ The letter h frequently goes before e
(as in “he”, “the”, “then”, etc.) but
rarely goes after e. No other pair of
letters has such an asymmetric
relationship.
26
Further frequency analysis
❑ Another technique is to use a crib,
which is a word or phrase you can
guess will be in the message
If you know there is a certain word and where it is you know the
associated ciphertext (known plaintext approach) – this means
you know the mapping for all the word’s letters.
27
Example
NKRRU NKXK OY G ZKYZ
SKYYGMK ZU KTIOVNKX LUX AYK
GY GT KDGSVRK OT GT GXZOIRK
LUX OYWAGXKJ SGMGFOTK
a b c d e f g h ij k l m n o p q r s t u v w x y z
G K
Single letter? A?
28
Example
NeRRU heXe
heRRU NeXe OY a ZeYZ
SeYYaMe ZU eTIOVheX
eTIOVNeX LUX AYe
aY aT eDaSVRe OT aT aXZOIRe
LUX OYWAaXeJ SaMaFOTe
a b c d e f g h ij k l m n o p q r s t u v w x y z
G K N
First word
We can see that the first word has “RR” as a repeated character, so we
might try to think of a word with a repeated letter in the middle. Also,
noticing that the combination “Ne” keeps appearing in the message, you
might guess this is “he”, which appears frequently in English. So perhaps R
corresponds to l and N to h, so that the first word is “hello”?
29
Example
ahello
n heXe hOY a ZeYZ t
SeYYaMe Zo eTIOpheX
meYYaMe eTIOVheX LoX AYe
aY e x a OT
aT eDaSVle
example m aTp aXZOIRe
l e
LoX OYWAaXeJ maMaFOTe
SaMaFOTe
n o
❑ Notice all the letters are in alphabetical
positions?
a b c d e f g h ij k l m n o p q r s t u v w x y z
G K N R S U V D
We can see that the first word has “RR” as a repeated character, so we
might try to think of a word with a repeated letter in the middle. Also,
noticing that the combination “Ne” keeps appearing in the message, you
might guess this is “he”, which appears frequently in English. So perhaps R
corresponds to l and N to h, so that the first word is “hello”?
30
Example
hello heXe
here OY
is a ZeYZ
test
message Zo
meYYaMe to eTIOpheX
encipher LoX
for AYe
use
as aT
aY an example OT
in aT
an aXZOIRe
article
for OYWAaXeJ
LoX isquared maMaFOTe
magazine
❑ Could this be a Caesar cipher?
a b c d e f g h ij k l m n o p q r s t u v w x y z
G H I J K L M N OP Q R S T U V W X Y Z A B C D E F
31
Knowing the key is 6, you can now
decipher future messages from your
enemy. Be careful what information you
act on though – if you seem too knowing
your enemy might get suspicious and
change their key or algorithm!
32
Ciphertext:
PBFPVYFBQXZTYFPBFEQJHDXXQVAPTPQJKTOYQWIPBVWLXTOXBTFXQWAX
BVCXQWAXFQJVWLEQNTOZQGGQLFXQWAKVWLXQWAEBIPBFXFQVXGTVJV
WLBTPQWAEBFPBFHCVLXBQUFEVWLXGDPEQVPQGVPPBFTIXPFHXZHVFAG
FOTHFEFBQUFTDHZBQPOTHXTYFTODXQHFTDPTOGHFQPBQWAQJJTODXQH
FOQPWTBDHHIXQVAPBFZQHCFWPFHPBFIPBQWKFABVYYDZBOTHPBQPQJT
QOTOGHFQAPBFEQJHDXXQVAVXEBQPEFZBVFOJIWFFACFCCFHQWAUVWFL
QHGFXVAFXQHFUFHILTTAVWAFFAWTEVOITDHFHFQAITIXPFHXAFQHEFZQW
GFLVWPTOFFA
33
Question: How to beat frequency analysis?
34
Beating frequency analysis
❑ Methods for countering frequency
analysis were developed, including:
o Omitting spaces
o Deliberate misspellings
o Nulls – characters that have no meaning
o Codes – replacing whole words or phrases
with letters, words or phrases
35
❑ Such methods helped, but ultimately
cryptanalysts won out and each method could
be accounted for
❑ A better cipher was needed
❑ Led to different variations on substitution
ciphers using principle of polyalphabetic
substitution (repeating plaintext letter
mapped to different ciphertext based in
changing state of cipher).
36
Vigenère cipher
❑ Emerged in sixteenth century
❑ The same plain letter can be enciphered and
the same cipher letter deciphered in several
different ways, significantly disrupting
frequency analysis
❑ Uses more than one cipher alphabet and
different letters are enciphered with these
in turn (basically interwoven Caesar cipher).
❑ Cipher alphabets must be chosen by some
systematic process
Copyright information: some of the slides are taken from Peter Rowlett’s Substitution Ciphers: Ancient – Renaissance in the
History of Maths and
www.historyofmathsandx.co.uk/topics/cryptography
37
Example
❑ First, choose a word for your key
❑ Key: Choose “pauli”
❑ The Caesar cipher alphabets beginning with
the letters of the keyword are then
produced:
a b c d e f g h i j k l m n o p q r s t u v w x y z
P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
LMNOPQRSTUVWXYZABCDEFGHIJK
IJKLMNOPQRSTUVWXYZABCDEFGH
38
❑ Take as plaintext message: hello
❑ Cipher algorithm: encode each letter
using each cipher alphabet in turn,
cycling through the cipher alphabets
❑ If your plaintext is longer than the key
word then keep repeating the keyword
o hellobob >> paulipau
39
a b c d e f g h i j k l m n o p q r s t u v w x y z
P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
LMNOPQRSTUVWXYZABCDEFGHIJK
IJKLMNOPQRSTUVWXYZABCDEFGH
❑ “h” is enciphered using the “P” alphabet, giving “W”
❑ “e” is enciphered using the “A” alphabet, giving “E”
❑ “l” is enciphered using the “U” alphabet, giving “F”
❑ “l” is enciphered using the “L” alphabet, giving “W”
❑ “o” is enciphered using the “I” alphabet, giving “W”
40
❑ hello to ciphertext message: WEFWW
❑ Notice that, crucially, we have
o (a) enciphered the two letters “l” to give
different cipher letters “F” and “W”;
o and, (b) enciphered different plaintext
letters “h”, “l” and “o” to give the same
ciphertext letter “W”.
❑ Through use of multiple alphabets, the chart
of letter frequencies is distorted, providing
strong resistance to frequency analysis
41
❑ Vigenère is more complicated to
implement than single-alphabet
substitution ciphers
❑ This adds to the time taken to encipher
and decipher messages
❑ It becomes worth the time and hassle if
you know your enemy can decipher your
simple substitution cipher messages
❑ Can the Vigenère cipher be broken?
42
❑ Vigenère was for 300 years considered
undecipherable (1553-1863)
❑ Primary weakness is that if the length of the
codeword is known we can break each of the
individual Caesar ciphers independently
❑ 1863 Friedrich Kasiski published his Kasiski
Examination method
o Estimates keyword length without plaintext
knowledge or the keyword needing to be a
recognisable word
Source: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
43
❑ Kasiski notices that repeated words are by
chance encrypted using same key letters
❑ For keyword ABCD:
Key: ABCDABCDABCDABCDABCDABCDABCD
Plaintext: CRYPTOISSHORTFORCRYPTOGRAPHY
Ciphertext: CSASTPKVSIQUTGQUCSASTPIUAQJB
Ciphertext: VHVSSPQUCEMRVBVBBBVHVSURQGIBDUGRNICJQUCERVUAXSSR
44
Enigma Machine
❑ Used by Germany in World War II
o Last famous substitution cipher
❑ Polyalphabetic substitution
o To recover message receiver must have
machine configured in same initial state as
the sender
Credit: https://brilliant.org/wiki/enigma-machine/
45
Enigma Machine
❑ Sender and receiver used monthly code
books to configure machine for specific
day
❑ Plugboard (up to 10 pair swops)
o Letter swop, if codebook said A/L connect
these by wire causing A input to be seen as
L, and L as A
❑ Rotors
o Choose 3 of 5 rotors in specified order
o Set initial letter of each rotor
46
Enigma Machine
❑ This mean the machine has many states
o Approximately 267 or 160 x 1018
❑ Cryptanalysis
o One feature (turned weakness) was a plaintext
cannot encrypt to itself. So this gives clue as
to what the message is not.
o Used cribs (known plaintext to eliminate
states)
▪ Weather report, “nothing to report”, message sign
off
❑ State then calculated through search
o Bombe machines (each emulating 36 Enigmas)
The Germans also used an early stream cipher called the Lorenz
cipher (this led to development of early computer – the Colossus to aid
in cryptanalysis)
47
One-time Pad Encryption
Encryption: Plaintext Key = Ciphertext
h e l l o a l i c e
Plaintext: 68 65 6C 6C 6F 61 6C 69 63 65
Key: FF 0A B2 5D C7 C3 EE 22 3F 68
Ciphertext: 97 6F DE 31 A8 A2 82 4B 5C 0D
The idea for the one time pad was first mentioned by Frank
Miller, but originally through to be invented in 1917 by Gilbert
Vernam (called the Vernam cipher, a patent was issued for the
XOR operation) for teleprinters.
48
binary value (string) of equal length.
You need to understand that perfect secrecy means that the attacker
has now idea about any of the plaintext – this does not mean he does
not know the plaintext, this means he knows *nothing*. For example, if
we use a good cipher and we encrypt the same plaintext twice and it
gives the same ciphertext then even the plaintext is not known we lose
perfect secrecy as we know something – the message is the same.
Here the key is random value that has the same length as the plaintext.
48
One-time Pad Decryption
Decryption: Ciphertext Key = Plaintext
Ciphertext: 97 6F DE 31 A8 A2 82 4B 5C 0D
Key: FF 0A B2 5D C7 C3 EE 22 3F 68
Plaintext: 68 65 6C 6C 6F 61 6C 69 63 65
h e l l o a l i c e
If given the ciphertext there is no way we can know for sure the
message. Any ciphertext can decrypt to any possible plaintext.
49
One-time Pad Use
Ciphertext: 97 6F DE 31 A8 A2 82 4B 5C 0D
Key: F5 16 BB 53 D1 C7 E8 24 34 63
Plaintext: 62 79 65 62 79 65 6A 6F 68 6E
b y e b y e j o h n
1. How will we keep giving the pad to the recipient? Each time we
send a message we need to send a new random ‘pad’ with it.
50
• A symmetric-key cipher or cryptosystem is used for encrypting/decrypting a
plaintext/ciphertext
• The same key is used for encrypting and decrypting
Alice Bob
eavesdropper
plaintext
cryptanalysis key
What two main types: Stream and block? Can you remember the
difference?
51
Stream Ciphers
Later we will see that other schemes can have different encrypt
and decrypt functions, i.e. encrypt and then reverse the
encryption operation
52
What is important here? Sender and receiver synchronisation.
52
Stream Ciphers
keystream
Plaintext
Ciphertext
53
is bigger.
53
RC4
❑ A stream cipher
❑ Ron’s code version 4 (Ronald Rivest)
❑ Stream ciphers are generally faster than block
ciphers
❑ RC4
o Stage 1: RC4 initialization
o Stage 2: RC4 keystream generation
54
RC4 Initialization
o Setup:
byte key[N]; // secret key (e.g. N = 16, i.e. 128-bit key)
byte K[256]; // keying material
byte S[256]; // internal states
o Initialization:
for i = 0 to 255
S[i] = i
K[i] = key[i (mod N)]
j=0
for i = 0 to 255
j = (j + S[i] + K[i]) mod 256
swap(S[i], S[j])
i=j=0
❑ S[] is the permutation of 0,1,...,255
55
RC4 Keystream Generation
❑ To output a keystream byte, swap table elements and select a byte
i = (i + 1) mod 256
j = (j + S[i]) mod 256
swap(S[i], S[j])
t = (S[i] + S[j]) mod 256
KeyStreamByteSelected = S[t]
56
Questions: What are the current symmetric key cryptosystems?
1.Stream Cipher
Cryptosystems
2.Block Cipher
57
Block Ciphers
plaintext Block Ciphertext
Cipher
secret key
You must at least know the most common block ciphers like DES,
3DES and AES.
Block ciphers takes a plaintext input of fixed size (the block size,
if you do not have enough plaintext you need to pad until you have
58
a block of required size). It then generates ciphertext of a fixed size
(the block size).
58
DES (Data Encryption Standard)
❑ Ciphertext obtained from 64-bit Plaintext Block
plaintext by iterating a
round function (i.e.
cryptographic operations)
❑ Input to round function 56-bit Secret Key
16 rounds
consists of a round key Ki
and the output of the Ki
previous round
You should know the basic operation of DES, like block size, key
size and basic architecture (initial, final permutation and 16
rounds each with own round key).
59
Feistel Structure
Cryptography – Part I 60
Interest only
60
56-bit Secret Key
Round Key-expansion
Function Algorithm
.
.
.
Interest only
61
This saves resources, 1976 what is status of computers (Apple I
released 1976 – 1 MHz clock, standard 4kB memory).
Generally you need more rounds, because you are only working on half
the block at a time.
61
Li-1 Ri-1 key
32 28 28
P box
32
32
32
Li Ri key
Symmetric Key Encryption 62
62
Properties of good block cipher algorithms
• Confusion
– A small change in the key should be able to change 50% of the
ciphertext
– An attacker using a bruteforce attack shouldn’t receive any signs that
he is getting closer to the correct key
• Diffusion
– A small change in the plaintext should cause 50% of the ciphertext to
change
– Hide any statistical relation between the plaintext and the ciphertext
• Completion
– Each bit of the ciphertext depends on each bit of the key
– The attacker won’t be able to find valid parts of the key using divide
and conquer methods
63
Security of DES
❑ Security of DES depends solely on the internals of f
❑ More than thirty years of intense analysis has revealed no
“back door”
❑ The most effective attack today against DES is still the
exhaustive key search (a.k.a. bruteforce attack)
64
Bruteforce Attack | Exhaustive Key Search
Know the recommended key size, and the minimum key size.
Also note that if doing brute force search on average you need to
search half the key space (2^(n-1)).
65
Bruteforce Attack Against DES
❑ Known-Plaintext Attack: Given a plaintext x and corresponding
ciphertext y, every possible key would be tested until a key K is
found such that
E(K, x) = y
Note: there may be more than one such key K.
❑ Total number of keys = 256 7.21016 keys
❑ Assume at the speed of 106 encryptions per second, it would need
more than 1000 years to break DES.
❑ Two cryptographers, Diffie and Hellman, postulated in 1977 that a
DES cracking machine with 106 processors, each could test 106
keys per second, could be built for about US$20M.
o This machine can break DES in about 10 hours.
Only know that brute force attack (finding key with know
plaintext) is now viable against DES.
66
Exhaustive Key Search
67
Frontier Foundation (EFF).
•It performs 256 DES operations in 56 hours. 90
billion searches per second.
•Cost: US$250K (first piece), US$50K - $75K
(duplicates).
67
What Should We Use Today?
What is the main problem with DES? How should we fix? Address
key size
68
Triple DES and DESX
❑ Triple DES: two 56-bit keys
C
M
DES DES-1 DES
K1 K2 K1
❑ DESX: three keys
C = K3 DES(K2 , M K1)
M DES C
K1 K2 K3
• Similar security to DES using differential cryptanalysis and linear
cryptanalysis, which are theoretical attacks
• But much harder to break using exhaustive key search than DES.
In theory this gives us 112 and 168 bit keyspace but due to some
improved cryptanalysis attacks the keyspace is actually reduced
(in other words there are better attacks than Brute Force):
This reduced keyspace is called the ‘effective key space’
For 2-key effective key space is 80 bits (what is the effort
needed? 2^79
For 3-key effective key space is 112 bits
69
Why do we have the encrypt/decrypt/encrypt design?
Backward compatibility? K1=K2 (and = K3 in three key model) – then it
is just single DES.
DESX
What is the length of K1 K2 and K3? K1 and K3 = |M| while K2 is just a
DES key (56-bits)
69
Advanced Encryption Standard
❑ Replacement for DES
o Selection by public process and chosen algorithm design
details freely available for public use.
o Required to operate at a faster speed than Triple DES
across a number of different platforms.
❑ AES competition (late 90’s)
o NSA openly involved
o Many strong algorithms were proposed and cryptanalyzed
publicly
o Rijndael Algorithm was ultimately selected
▪ Pronounced like “Rain Doll” or “Rhine Doll”
❑ Iterated block cipher (like DES)
❑ Not using Feistel round function (unlike DES)
Symmetric Key Encryption 70
You should know the basic operation of AES, like block size, key
size and basic architecture (the basic idea of the permutation
and it having multiple rounds each with own round key).
We will now look at AES in more detail – this is for your interest.
We would like for you to know a little about the inner workings of
a cipher – but I do not expect that you remember all the lower
details but you must be able to give a basic description of the
round function and overall structure. So for example, know the
basic intention of subbyte, shiftrow, mixcolumn and add round
key (but the actual operation, like finite field arithmetic for
mixcolumn is not needed)
70
Know AES is not a Feistel design, and that AES is now recommended
for new systems.
Requirements:
128-bit block
128-256 bit key
Faster than 3DES in a number of specified platforms
70
AES (Advanced Encryption Standard)
❑ Replacement of DES
❑ Block size: 128 bits
❑ Key length: 16, 24, or 32 bytes (128, 192,
or 256 bits) – independent of block size
❑ 10 to 14 rounds (depends on key length)
❑ Substitution-Permutation Network (SPN)
❑ Each round has 4 transformations (except
the last round)
o ByteSub
o ShiftRow
o MixColumn
o AddRoundKey
Think back - what is the block size? We can only input into a block
cipher a fixed length piece of plaintext of size equal to the block.
No less, no more.
What was key size and block size for DES? 56 and 64.
71
AES Encryption Process
72
AES Encryption and Decryption
73
AES
The Four Transformations in Each Round (Except the Last Round):
• ByteSub: use an S-box to perform a byte-by-byte substitution of the data block
• ShiftRow: a permutation
• MixColumn: a substitution that makes use of arithmetic over GF(2 8)
• AddRoundKey: a simple bitwise XOR of the current data block with a round key
74
AES
ByteSub (substitute byte transformation)
• Each individual byte in a data block is mapped into a new byte using a 16x16 matrix of byte values
• The leftmost 4 bits of a data block byte are used as a row value
• The rightmost 4 bits of a data block byte are used as a column value
• E.g. a data block byte value 95 references row 9, column 5 of the S-box, which contains the value
2A. So the value 95 is substituted by 2A in ByteSub
There are two table – one for encrypt and one decrypt.
For the picture lets say we sub 00, then it is 63. For decryption
if we look up 63 then 00. Reversible.
75
AES
ByteSub
An example of the ByteSub transformation of a 128-bit data block using the S-box.
EA 04 65 85 87 F2 4D 97
83 45 5D 96 S-box EC 6E 4C 90
5C 33 98 B0 4A C3 46 E7
F0 2D AD C5 8C D8 95 A6
76
AES
ShiftRow
•The first row of the data block is not altered
•The second row: 1-byte circular left shift
•The third row: 2-byte circular left shift
•The fourth row: 3-byte circular left shift
87 F2 4D 97 87 F2 4D 97
EC 6E 4C 90 6E 4C 90 EC
4A C3 46 E7 46 E7 4A C3
8C D8 95 A6 A6 8C D8 95
Shift row just means we left rotate each row of the 4x4 data
matrix
77
AES
MixColumn
•Operate on each column individually
•Each byte of a column is mapped into a new value that is a function of all the four bytes in that
column
•Matrix multiplication over GF(28) with irreducible polynomial m(x) = x8 + x4 + x3 + x + 1
e.g.
s’0,0 = 02s0,0 + 03s1,0 + s2,0 + s3,0 mod m(x)
s’0,0 = (x)s0,0 + (x+1)s1,0 + s2,0 + s3,0 mod m(x)
Note: each si,j represents 8 bits (i.e. a polynomial of degree 7 with binary coefficients)
78
Mathematical Background: Finite Field Arithmetic
Galois Field or Finite Field: we only focus on GF(2n) here
•Informally: a field is a set in which we can do addition, subtraction, multiplication, and division
without leaving the set
•GF(2n) is a finite field containing 2n elements
•Consider a set S of all polynomials of degree n-1 or less with binary coefficients. Thus, each
polynomial has the form
f(x) = an-1xn-1 + an-2xn-2 + … + a1x + a0
where each ai takes on the value 0 or 1 only.
•There are a total of 2n different polynomials in S.
•For n = 3, GF(23) has 8 polynomials in the form of f(x) = a2x2 + a1x + a0.
They are: {0, 1, x, x + 1, x2, x2 + 1, x2 + x, x2 + x + 1}.
•Arithmetic on coefficients is performed modulo 2
•Addition:
• E.g. f(x) + g(x) = (x2 + 1) + (x2 + x + 1) = x
• This is the same as the bitwise XOR operation
• Represent each element in GF(23) by a 3-bit value: {000, 001, 010, 011, 100, 101, 110, 111}
• f(x) + g(x) = (101) + (111) = (010) x
79
Mathematical Background: Finite Field Arithmetic
• Multiplication:
• Multiply two polynomials together. If the resulting polynomial has degree greater than n-1,
then the polynomial is reduced modulo some irreducible polynomial m(x) of degree n.
• Irreducible polynomial m(x): a polynomial cannot be expressed as a product of two
polynomials, both with degree smaller than that of m(x).
• Irreducible polynomials of degree 3: (x3 + x2 + 1) and (x3 + x + 1)
• f(x) g(x) = (x2 + 1) (x2 + x + 1) mod m(x) = (x4 + x3 + x2) + (x2 + x + 1) mod m(x)
= x4 + x3 + x + 1 mod m(x)
take m(x) = (x3 + x + 1) as the irreducible polynomial, we have
f(x) g(x) = x4 + x3 + x + 1 mod (x3 + x + 1) = (x + 1)(x3 + x + 1) + (x2 + x) mod (x3 + x + 1)
= x2 +x
• Represent each element in GF(23) by a 3-bit value: {000, 001, 010, 011, 100, 101, 110, 111}
• f(x) g(x) = (101) (111) = (110)
• AES uses arithmetic in the finite field GF(28) with the irreducible polynomial
m(x) = x8 + x4 + x3 + x + 1
80
AES
MixColumn
e.g.
s’0,0 = 02s0,0 + 03s1,0 + s2,0 + s3,0 mod m(x)
s’0,0 = (x)s0,0 + (x+1)s1,0 + s2,0 + s3,0 mod m(x)
Note: each si,j represents 8 bits (i.e. a polynomial of degree 7 with binary coefficients)
81
AES
MixColumn
87 F2 4D 97 47 40 A3 4C
6E 4C 90 EC 37 D4 70 9F
46 E7 4A C3 94 E4 3A 42
A6 8C D8 95 ED A5 A6 BC
82
Example
❑ Calculate S’0,0 = 02 . S0,0 + 03. S1,0 + S2,0 + S3,0
❑ 02h(10b). 87h(10000111b) + 03h(11b). 6Eh(01101110b) +
46h(01000110b) + A6h(10100110b)
❑ (x)(x7+x2+x+1)+(x+1)(x6+x5+x3+x2+x)+(x6+x2+x)+(x7+x5+x2+x)
❑ x8+x3+x2+x+x7+x6+x4+x3+x2+x6+x5+x3+x2+x+x6+x2+x+x7+x5+x2+x
❑ x8+x3+x2+x6+x4 mod x8+x4+x3+x+1
❑ x8+x3+x2+x6+x4+(x+x+1+1) mod x8+x4+x3+x+1
❑ x6+x2+x+1+(x8+x4+x3+x+1) mod x8+x4+x3+x+1
❑ x6+x2+x+1 mod x8+x4+x3+x+1
❑ x6+x2+x+1 is 01000111b is 47h
Cryptography – Part I 83
Calculate S3’,0=
03.3E(00111110)+01.1C(00011100)+01.22(00100010)+02.C0(110000
00)
= (x+1)(x5+x4+x3+x2+x)+(x4+x3+x2)+(x5+x)+x.(x7+x6) =
x6+x5+x4+x3+x2+x5+x4+x3+x2+x +x4+x3+x2+x5+x+x8+x7
= x6+x4+x3+x2+x5+x8+x7 mod x8 + x4 + x3 + x + 1
= x8+x7+x6+x5+x4+x3+x2 +1+1+x+x mod x8 + x4 + x3 + x + 1
= (x8+x4+x3+x+1)+x7+x6+x5+x2 +x+1 mod x8 + x4 + x3 + x + 1 =
x7+x6+x5+x2 +x+1 =11100111 = E7
83
AES
AddRoundKey
47 40 A3 4C AC 19 28 57 EB 59 8B 1B
37 D4 70 9F 77 FA D1 5C 40 2E A1 C3
94 E4 3A 42
66 DC 29 00
= F2 38 13 42
ED A5 A6 BC F3 21 41 6A 1E 84 E7 D6
Finally we just XOR the round key (which we also divided into a
matrix) with the data matrix.
84
AES Summary of One AES Round (except the last round)
85
AES
Key Expansion / Key Scheduling
Review:
•A 16-byte (128-bit) Key is expanded
into 11 round keys
•Each round key is 4 words (or 16 bytes
or 128 bits) long
•Total size of the 11 round keys = 44
words (or 176 bytes)
Notations:
•Key: k0, k1, … k15
•Round Keys: w0, w1, …, w43
g next slide
86
AES
Key Expansion / Key Scheduling
Summary:
•The 16-byte key is copied into the first
four words for Round 0 key
•i.e. the key is used directly to do the
AddRoundKey at the initial
transformation
RCj is a constant.
87
Key Space
❑ The Key Space of a cipher is the set of all possible
and distinct secret keys
❑ E.g. The key space of DES is all distinct 56-bit
binary strings
❑ E.g. The size of the key space of simple
substitution for case-insensitive English alphabet
is 26!
❑ What’s the key space size of AES?
❑ What’s the key space size of one-time pad?
❑ What’s the key space size of RC4?
Study this slide – you need to know what the keyspace is, how to
calculate it, and how much exhaustive search attempts are
required for a given keyspace (see slide 52)
88
Multiple Blocks
Message Ciphertext
ENC
(n bits) (n bits)
secret key
(k bits)
Study slide
89
Modes of Operation
❑ Many modes of operation ⎯ we discuss three
❑ Electronic Codebook (ECB) mode
o Obvious thing to do
o Encrypt each block independently
o There is a serious weakness
❑ Cipher Block Chaining (CBC) mode
o Chain the blocks together
o More secure than ECB
❑ Counter Mode (CTR) mode
o Acts like a stream cipher
o Popular for random access
You need to know the three modes of operation well (plus CFB)
(understand what is going on – but you do not need to memorise
what is going on)
90
ECB Mode
❑ Notations: C=E(K, P) P=D(K,C)
❑ Given plaintext P = P0,P1,…,Pm,… (in blocks)
❑ Obvious way of using a block cipher is to encrypt
plaintext blocks independently
Encrypt Decrypt
C0 = E(K, P0), P0 = D(K, C0),
C1 = E(K, P1), P1 = D(K, C1),
C2 = E(K, P2),… P2 = D(K, C2),…
P0 P1 Pi
K K K
ENC ENC ENC
C0 C1 Ci
91
ECB Cut and Paste Attack
❑ Suppose plaintext is
Alice digs Bob. Trudy digs Tom.
❑ Assuming 64-bit blocks and 8-bit ASCII:
P0 = “Alice di”, P1 = “gs Bob. ”,
P2 = “Trudy di”, P3 = “gs Tom. ”
❑ Ciphertext: C0,C1,C2,C3
❑ Trudy cuts and pastes: C0,C3,C2,C1
❑ Decrypts as
Alice digs Tom. Trudy digs Bob.
Symmetric Key Encryption 92
92
ECB Weakness
❑ Suppose P i = Pj
❑ Then Ci = Cj and Trudy knows Pi = Pj
❑ This gives Trudy some information,
even if she does not know Pi or Pj
❑ Is this a serious issue?
This is now like a very very large substitution cipher! (with 2^n
possible permutations where n is blocksize)….
Traffic analysis – can see the same messages being sent. What if
message repeat?
93
Alice Hates ECB Mode
❑ Alice’s uncompressed image, Alice ECB encrypted
94
CBC Mode
❑ Blocks are “chained” together
❑ A random initialization vector, or IV, is required to initialize
CBC mode
❑ IV is random, but is not a secret
Encryption Decryption
C0 = E(K, IV P0), P0 = IV D(K, C0),
C1 = E(K, C0 P1), P1 = C0 D(K, C1),
C2 = E(K, C1 P2),… P2 = C1 D(K, C2),…
P0 P1
IV
ENC ENC
K K
C1
C0
95
Alice Likes CBC Mode
❑ Alice’s uncompressed image, Alice CBC encrypted
As seen with the picture, the same plaintext now delivers much
different ciphertext – and you can now longer see Alice
96
What is a ‘good’ mode?
Good properties:
❑Message dependence of ciphertext
❑Limited error propagation
❑Works without block synchronisation
❑Optimise use of decrypt/encrypt
❑Reduce padding
Cryptography – Part I 97
97
Ideally we do not want to generate too much ciphertext in comparison
to our plaintext if possible (this is not always practical, especially with
block ciphers – you need to enter a full block even if your message (or
what is left of your message is smaller than the block).
97
Type of transmission errors
❑ Transmission errors are errors (a 1
becomes a 0 or a 0 becomes a 1) that
occur in the communication channel.
❑ Transmission losses are bits that get
lost (they never arrive) in the
communication channel.
98
Error Propagation
❑A decryption process involves error
propagation if a ciphertext input
that has one incorrect bit produces a
plaintext output that has more than
one incorrect bit.
Cryptography – Part I 99
99
message is wrong.
99
Counter Mode (CTR)
❑ Use block cipher like stream cipher
Encryption Decryption
C0 = P0 E(K, IV), P0 = C0 E(K, IV),
C1 = P1 E(K, IV+1), P1 = C1 E(K, IV+1),
C2 = P2 E(K, IV+2),… P2 = C2 E(K, IV+2),…
K K K
ENC ENC ENC
P0 P1 Pi
C1 Ci
C0
Error? 1 bit
100
CTR mode is good if you store encrypted data. Consider that the IV is
also the index of the stored ciphertext block. To read the block’s
plaintext you do E(Ivi, K) and XOR it to stored C. If you edit the block
you can then simple XOR the new plaintext the E(Ivi, K) and store it.
Reading is easy, you take cipher block Ci-1 and use it to decrypt Ci, now
you can read the data. However, what happens now if you change the
plaintext? You can encrypt Ci again using Ci-1. Is that good enough?
No! Now you need to decrypt and encrypt all the remaining block as the
change in Ci means all the rest of the blocks will change.
100
Cipher Feedback Mode (CFB)
❑ One more mode…
❑ Use block cipher like stream cipher (like counter mode)
Encryption Decryption
C0 = P0 E(K, IV), P0 = C0 E(K, IV),
C1 = P1 E(K, C0), P1 = C1 E(K, C0),
C2 = P2 E(K, C1),… P2 = C2 E(K, C1),…
C0 Ci
IV
K K K
ENC ENC ENC
P0 P1 Pi
Ci
C0
101
CFB Mode
1.At the start Ci has been stored by the sender, at the same time
Ci is also stored be the receiver (from previous round) in blue
registers.
4.Ci+1 is send, and also fed back and stored by the sender (blue
register)
102
5. The sender is now finished and ready for next block to be sent.
102
CFB Error
Ci has been sent (sender has use Ci-1 to generate it Ci has been
stored for next block by the sender). There is a one bit error in
Ci > lets call error block C’i.
The receiver receives C’i, and XOR E(Ci-1, K) to get Pi. As there is
one bit error in C’i and we XOR with same KS that sender used we
get one bit error in Pi.
103
has lots of bit errors.
The receiver no stores Ci+1 for next block – it arrived without error,
and is the same data the sender will use to generate Ci+2, therefore
the error will not propagate any further and Pi+2 would be fine.
103
CBC Mode
1.At the start both sender and receiver has Ci-1 stored (in blue)
4.Ci is sent (and also stored for the next block by sender)
104
8. D(Ci) XOR Ci-1 is therefore Pi
104
CBC Error
D(C’i,K) not equal Ci-1 XOR Pi (many bit errors as input to decrypt
is one bit different than sender), so D(C’i,K) XOR Ci-1 not equal to
Pi (Pi has lots of errors, due to decrypt function).
105
The next block is fine as both parties use correct Ci+1
105
Supplementary Materials
106
Practical Cipher Knowledge
❑ I am not a cryptographer – how do I know a good
cipher?
❑ Basic cipher analysis in under a minute
o Keysize
▪ For symmetric ciphers key > 128 is now considered best practice
o Public
▪ Security cannot come from obscurity (Kerkhoffs principle)
o Standard
▪ If the cipher is as result of open competition good, if proprietary be wary?
▪ If it is old and public and still not ‘broken’ then could be OK.
o Mode of operation?
▪ Of the basic modes CBC is considered good (ECB not good)
107
107
Mifare Classic
❑ Developed in 1995 (NXP Semiconductor) – Crypto1 algorithm
o 48 bit key, stream cipher
❑ Used in a significant number of current systems
o Access control
o Travel
o Closed payment
❑ Cipher kept secret…was securely used for a long time
❑ Researchers reverse engineered cipher by analysis of the IC
architecture
o Subsequently another group also used these findings to
reconstruct the full cipher
❑ Mifare Classic also shown to have further security flaws
108
Keysize? Poor
Secrecy? Kerkhoffs principle? Bad, kept secret.
108
Mifare Classic Metal Layers
Nohl, et al (2008)
109
109
Reconstructing the Algorithm
Nohl, et al (2008)
110
110
Security through obscurity
❑ Legacy/proprietary RFID
systems available and
possibly used for security
sensitive applications.
❑ Several examples of reverse
engineering
o NXP Mifare Classic, TI DST,
NXP HiTag, Microchip
Keeloq,
HID and Atmel CryptoRF
❑ The first….
o TI DST algorithm reverse
engineered (2005), used for
Speedpass, car immobilizers
o Researchers had general
idea of cipher architecture
used black box, brute force
method
o Recover the 40-bit key in a
111 few hours and masquerade
as a real DST device
111
The end!
?
Any questions…
112
112