Chapter 1
Chapter 1
考核方式和成绩评定
Textbooks
最好的参考书
Curiosity, Passion, Love
愛因斯坦:「我沒有特殊的天賦,只是擁有熱切
的好奇心。」 ──讓孩子學會問「為什
麼」!
美国哈佛大学教授、数学诺贝尔奖“菲尔兹”奖
得主——丘成桐教授:对不懂的事情要有好奇
心,对自己选定的目标要有热情。
Curiosity, Passion, Love
5
Content of this Chapter
6/36
Content of this Chapter
7/36
Classification of the Field of Cryptology
Cryptology
Cryptography Cryptanalysis
8/36
Some Basic Facts
• Symmetric ciphers: All encryption schemes from ancient times until 1976 were
symmetric ones.
• Hybrid Schemes: The majority of today‘s protocols are hybrid schemes, i.e., the
use both
• symmteric ciphers (e.g., for encryption and message authentication) and
• asymmetric ciphers (e.g., for key exchange and digital signature).
9/36
Content of this Chapter
10/36
Symmetric Cryptography
• Alternative names: private-key, single-key or secret-key cryptography.
Oscar
(bad guy)
Unsecure
channel
(e.g. Internet)
Alice Bob
(good) x x (good)
• Problem Statement:
1) Alice and Bob would like to communicate via an unsecure channel (e.g.,
WLAN or Internet).
2) A malicious third party Oscar (the bad guy) has channel access but should
not be able to understand the communication.
11/36
Symmetric Cryptography
Oscar
Solution: Encryption with symmetric cipher.
(bad guy)
Oscar obtains only ciphertext y, that looks Unsecure
like random bits channel
y (e.g. Internet)
K K
Key Generator
Secure Channel
• x is the. plaintext
• y is the ciphertext
• K is the key
• Set of all keys {K1, K2, ...,Kn} is the key space
12/36
Symmetric Cryptography
• Important: The key must be transmitted via a secure channel between Alice and Bob.
• The secure channel can be realized, e.g., by manually installing the key for the Wi-Fi
Protected Access (WPA) protocol or a human courier.
• However, the system is only secure if an attacker does not learn the key K!
The problem of secure communication is reduced to secure transmission and
storage of the key K.
13/36
Content of this Chapter
14/36
Why do we need Cryptanalysis?
• Classical Attacks
• Mathematical Analysis
• Brute-Force Attack
• Implementation Attack: Try to extract key through reverese engineering or
power measurement, e.g., for a banking smart card.
• Social Engineering: E.g., trick a user into giving up her password
16/36
Brute-Force Attack (or Exhaustive Key Search) against Symmetric Ciphers
?
dK(y0) = x0
• How many keys to we need ?
Key length Key space Security life time
in bit (assuming brute-force as best possible attack)
64 264 Short term (few days or less)
128 2128 Long-term (several decades in the absence of
quantum computers)
256 2256 Long-term (also resistant against quantum
computers – note that QC do not exist at the
moment and might never exist)
Important: An adversary only needs to succeed with one attack. Thus, a long key space
does not help if other attacks (e.g., social engineering) are possible..
17/36
Content of this Chapter
18/36
Substitution Cipher
• Historical cipher
• Great tool for understanding brute-force vs. analytical attacks
• Encrypts letters rather than bits (like all ciphers until after WW II)
• Example (ciphertext):
iq ifcc vqqr fb rdq vfllcq na rdq cfjwhwz hr bnnb hcc
hwwhbsqvqbre hwq vhlq
• How secure is the Substitution Cipher? Let‘s look at attacks…
19/36
Attacks against the Substitution Cipher
• Q: Can we now conclude that the substitution cipher is secure since a brute-
forece attack is not feasible?
• A: No! We have to protect against all possible attacks…
20/36
2. Attack: Letter Frequency Analysis (Brute-Force Attack)
• Letters have very different frequencies in the English language
• Moreover: the frequency of plaintext letters is preserved in the ciphertext.
• For instance, “e” is the most common letter in English; almost 13% of all letters in a
typical English text are “e”.
• The next most common one is “t” with about 9%.
12.0000
10.0000
Frequency in %
8.0000
6.0000
4.0000
2.0000
0.0000
E T A O I N S H R D L C U M W F G Y P B V K J X Q Z
Letters
21/36
Breaking the Substitution Cipher with Letter Frequency Attack
• Let‘s retun to our example and identify the most frequent letter:
iq ifcc vqqr fb rdq vfllcq na rdq cfjwhwz hr bnnb hcc
hwwhbsqvqbre hwq vhlq
• By further guessing based on the frequency of the remaining letters we obtain the
plaintext:
WE WILL MEET IN THE MIDDLE OF THE LIBRARY AT NOON ALL
ARRANGEMENTS ARE MADE
22/36
Breaking the Substitution Cipher with Letter Frequency Attack
• In practice, not only frequencies of individual letters can be used for an attack,
but also the frequency of letter pairs (i.e., “th” is very common in English), letter
triples, etc.
• cf. Problem 1.1 in Understanding Cryptography for a longer ciphertext you can
try to break!
Important lesson: Even though the substitution cipher has a sufficiently large key
space of appr. 288, it can easily be defeated with analytical methods. This is an
excellent example that an encryption scheme must withstand all types of
attacks.
23/36
Content of this Chapter
24/36
Short Introduction to Modular Arithmetic
25/36
Short Introduction to Modular Arithmetic
Generally speaking, most cryptosytems are based on sets of numbers that are
1. discrete (sets with integers are particularly useful)
2. finite (i.e., if we only compute with a finiely many numbers)
Seems too abstract? --- Let‘s look at a finite set with discrete numbers we are quite familiar
with: a clock.
12
11 1
10 2
9 3
8 4
7 5
6
Interestingly, even though the numbers are incremented every hour we never leave the set of
integers:
1, 2, 3, … 11, 12, 1, 2, 3, … 11, 12, 1, 2, 3, …:
26/36
Short Introduction to Modular Arithmetic
• We develop now an arithmetic system which allows us to compute in finite sets of
integers like the 12 integers we find on a clock (1,2,3, … ,12).
• It is crucial to have an operation which „keeps the numbers within limits“, i.e., after
addition and multiplication they should never leave the set (i.e., never larger than 12).
27/36
Properties of Modular Arithmetic (1)
28/36
Properties of Modular Arithmetic (2)
Remark: This is just a convention. Algorithmically we are free to choose any other valid
remainder to compute our crypto functions.
29/36
Properties of Modular Arithmetic (3)
• How do we perform modular division?
First, note that rather than performing a division, we prefer to multiply by the inverse. Ex:
b / a≡ b x a-1 mod m
The inverse a-1 of a number a is defined such that:
a a-1 ≡ 1 mod m
Ex: What is 5 / 7 mod 9 ?
The inverse of 7 mod 9 is 4 since 7 x 4 ≡ 28 ≡ 1 mod 9, hence:
5 / 7 ≡ 5 x 4 = 20 ≡ 2 mod 9
30/36
Properties of Modular Arithmetic (4)
• Modular reduction can be performed at any point during a calculation
Let’s look first at an example. We want to compute 38 mod 7 (note that exponentiation is
extremely important in public-key cryptography).
1. Approach: Exponentiation followed by modular reduction
38 = 6561≡ 2 mod 7
Note that we have the intermediate result 6561 even though we know that the final result
can’t be larger than 6.
2. Approach: Exponentiation with intermediate modular reduction
38 = 34 34 = 81 x 81
At this point we reduce the intermediate results 81 modulo 7:
38 = 81 x 81 ≡ 4 x 4 mod 7
4 x 4 = 16 ≡ 2 mod 7
Note that we can perform all these multiplications without pocket calculator, whereas
mentally computing 38 = 6561 is a bit challenging for most of us.
• Closure: We can add and multiply any two numbers and the result is always in the ring.
• Addition and multiplication are associative, i.e., for all a,b,c Zm
a + (b + c) = (a + b) + c
a (b c) = (a b) c
and addition is commutative: a + b = b + a
• The distributive law holds: a×(b+c) = (a×b)+(a×c) for all a,b,c Zm
• There is the neutral element 0 with respect to addition, i.e., for all a Zm
a + 0 a mod m
• For all a Zm, there is always an additive inverse element –a such that
a + (-a) 0 mod m
• There is the neutral element 1 with respect to multiplication, i.e., for all a Zm
a 1 a mod m
• The multiplicative inverse a-1
a a-1 1 mod m
exists only for some, but not for all, elements in Zm.
32/36
An Algebraic View on Modulo Arithmetic: The Ring Zm (2)
Roughly speaking, a ring is a structure in which we can always add, subtract and
multiply, but we can only divide by certain elements (namely by those for which a
multiplicative inverse exists).
•We recall from above that an element a Zm has a multiplicative inverse only if:
gcd (a, m) = 1
We say that a is coprime or relatively prime to m.
33/36
Content of this Chapter
34/36
Shift (or Caesar) Cipher (1)
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
• Example for k = 7
Plaintext = ATTACK = 0, 19, 19, 0, 2, 10
Ciphertext = haahr = 7, 0, 0, 7, 17
Note that the letters ”wrap around” at the end of the alphabet, which can be mathematically
be expressed as reduction modulo 26, e.g., 19 + 7 = 26 ≡ 0 mod 26
35/36
Shift (or Caesar) Cipher (2)
36/36
Affine Cipher (1)
• Extension of the shift cipher: rather than just adding the key to the plaintext, we also
multiply by the key
• We use for this a key consisting of two parts: k = (a, b)
• Since the inverse of a is needed for inversion, we can only use values for a for which:
gcd(a, 26) = 1
There are 12 values for a that fulfill this condition.
• From this follows that the key space is only 12 x 26 = 312 (cf. Sec 1.4 in Understanding
Cryptography)
• Again, several attacks are possible, including:
• Exhaustive key search and letter frequency analysis, similar to the attack against
the substitution cipher
37/36
Lessons Learned
• Never ever develop your own crypto algorithm unless you have a team of experienced
cryptanalysts checking your design.
• Do not use unproven crypto algorithms or unproven protocols.
• Attackers always look for the weakest point of a cryptosystem. For instance, a large key
space by itself is no guarantee for a cipher being secure; the cipher might still be vulnerable
against analytical attacks.
• Key lengths for symmetric algorithms in order to thwart exhaustive key-search attacks:
• 64 bit: insecure except for data with extremely short-term value
• 128 bit: long-term security of several decades, unless quantum computers become
available (quantum computers do not exist and perhaps never will)
• 256 bit: as above, but probably secure against attacks by quantum computers.
• Modular arithmetic is a tool for expressing historical encryption schemes, such as the affine
cipher, in a mathematically elegant way.
38/36