Lecture 2- Symmetric-Key-Encryption
Lecture 2- Symmetric-Key-Encryption
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:
Cryptography – Part I 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
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
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
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
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
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
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
pure mathematics is, in its way,
puremathicsnwyoflgd
❑ 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
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
• Question: how many distinct permutations are there? (in other words,
how many distinct secret keys are in the key space?)
• 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
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
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
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
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
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!
Ciphertext:
PBFPVYFBQXZTYFPBFEQJHDXXQVAPTPQJKTOYQWIPBVWLXTOXBTFXQWAX
BVCXQWAXFQJVWLEQNTOZQGGQLFXQWAKVWLXQWAEBIPBFXFQVXGTVJV
WLBTPQWAEBFPBFHCVLXBQUFEVWLXGDPEQVPQGVPPBFTIXPFHXZHVFAG
FOTHFEFBQUFTDHZBQPOTHXTYFTODXQHFTDPTOGHFQPBQWAQJJTODXQH
FOQPWTBDHHIXQVAPBFZQHCFWPFHPBFIPBQWKFABVYYDZBOTHPBQPQJT
QOTOGHFQAPBFEQJHDXXQVAVXEBQPEFZBVFOJIWFFACFCCFHQWAUVWFL
QHGFXVAFXQHFUFHILTTAVWAFFAWTEVOITDHFHFQAITIXPFHXAFQHEFZQW
GFLVWPTOFFA
Source: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
❑ Kasiski notices that repeated words are by
chance encrypted using same key letters
❑ For keyword ABCD:
Key: ABCDABCDABCDABCDABCDABCDABCD
Plaintext: CRYPTOISSHORTFORCRYPTOGRAPHY
Ciphertext: CSASTPKVSIQUTGQUCSASTPIUAQJB
Ciphertext: VHVSSPQUCEMRVBVBBBVHVSURQGIBDUGRNICJQUCERVUAXSSR
Credit: https://brilliant.org/wiki/enigma-machine/
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
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)
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
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
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
Alice Bob
eavesdropper
plaintext
cryptanalysis key
keystream
Plaintext
Ciphertext
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]
1.Stream Cipher
Cryptosystems
2.Block Cipher
secret key
Cryptography – Part I 60
56-bit Secret Key
Round Key-expansion
Function Algorithm
.
.
.
P box
32
32
32
Li Ri key
Symmetric Key Encryption 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
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.
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
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
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)
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
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
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)
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
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
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
AES Summary of One AES Round (except the last round)
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
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
secret key
(k bits)
P0 P1 Pi
K K K
ENC ENC ENC
C0 C1 Ci
P0 P1
IV
ENC ENC
K K
C1
C0
Cryptography – Part I 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.
Cryptography – Part I 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
P0 P1 Pi
Ci
C0
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
Mifare Classic Metal Layers
Nohl, et al (2008)
109
Reconstructing the Algorithm
Nohl, et al (2008)
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
The end!
?
Any questions…
112