Crypto Slides
Crypto Slides
Markus Kuhn
https://www.cl.cam.ac.uk/teaching/1920/Crypto/
Objectives
By the end of the course you should
I be familiar with commonly used standardized cryptographic building
blocks;
I be able to match application requirements with concrete security
definitions and identify their absence in naive schemes;
I understand various adversarial capabilities and basic attack
algorithms and how they affect key sizes;
I understand and compare the finite groups most commonly used with
discrete-logarithm schemes;
I understand the basic number theory underlying the most common
public-key schemes, and some efficient implementation techniques.
2 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
3 / 230
Related textbooks
Main reference:
I Jonathan Katz, Yehuda Lindell:
Introduction to Modern Cryptography
2nd ed., Chapman & Hall/CRC, 2014
Further reading:
I Christof Paar, Jan Pelzl:
Understanding Cryptography
Springer, 2010
http://www.springerlink.com/content/978-3-642-04100-6/
http://www.crypto-textbook.com/
I Douglas Stinson:
Cryptography – Theory and Practice
3rd ed., CRC Press, 2005
I Menezes, van Oorschot, Vanstone:
Handbook of Applied Cryptography
CRC Press, 1996
http://www.cacr.math.uwaterloo.ca/hac/
The course notes and some of the exercises also contain URLs with more
detailed information.
4 / 230
Common information security targets
Most information-security concerns fall into three broad categories:
Digital signature
I PK , SK ← Gen public/secret key-pair generation
I S ← SignSK (M ) signature generation using secret key
I VrfyPK (M, S) = 1, signature verification using public key
?
M 0 6= M ⇒
VrfyPK (M 0 , S) = 0
7 / 230
Key exchange
Key-agreement protocol
I (PK A , SK A ) ← Gen public/secret key-pair generation by Alice
I (PK B , SK B ) ← Gen public/secret key-pair generation by Bob
I K := DH(SK A , PK B ) key derivation from exchanged public keys
= DH(PK A , SK B )
Diffie–Hellman protocol:
Alice and Bob standardize suitably chosen very large public numbers g, p and q.
Alice picks a random number 0 < x < q and Bob a secret number 0 < y < q as
their respective secret keys. They then exchange the corresponding public keys:
A→B: PK A = g x mod p
B→A: PK B = g y mod p
Alice and Bob each now can calculate
K = (g y mod p)x mod p = (g x mod p)y mod p
and use that as a shared private key. With suitably chosen parameters, outside
observers will not be able to infer x, y, or K.
Why might one also want to sign or otherwise authenticate PK A and/or PK B ?
8 / 230
Key types
I Private keys = symmetric keys
I Public/secret key pairs = asymmetric keys
Warning: this “private” vs “secret” key terminology is not universal in the literature
I Ephemeral keys / session keys are only used briefly and often
generated fresh for each communication session.
They can be used to gain privacy (observers cannot identify users from public keys
exchanged in clear) and forward secrecy (if a communication system gets compromised in
future, this will not compromise past communication).
9 / 230
When is a cryptographic scheme “secure”?
For an encryption scheme, if no adversary can . . .
I . . . find out the secret/private key?
I . . . find the plaintext message M ?
I . . . determine any character/bit of M ?
I . . . determine any information about M from C?
I . . . compute any function of the plaintext M from ciphertext C?
⇒ “semantic security”
For an integrity scheme, should we demand that no adversary can . . .
I . . . find out the secret/private key?
I . . . create a new message M 0 and matching tag/signature?
I . . . create a new M 0 that verifies with a given tag/signature?
I . . . modify or recombine a message+tag so they still verify?
I . . . create two messages with the same signature?
10 / 230
What capabilities may the adversary have?
I access to some ciphertext C
I access to some plaintext/ciphertext pairs (M, C) with
C ← EncK (M )?
I ability to trick the user of EncK into encrypting some plaintext of
the adversary’s choice and return the result?
(“oracle access” to Enc)
I ability to trick the user of DecK into decrypting some ciphertext of
the adversary’s choice and return the result?
(“oracle access” to Dec)?
I ability to modify or replace C en route?
(not limited to eavesdropping)
I how many applications of EncK or DecK can be observed?
I unlimited / polynomial / realistic ( 280 steps) computation time?
I knowledge of all algorithms used
13 / 230
Kerckhoffs’ principle today
Requirement for a modern encryption system:
1 It was evaluated assuming that the enemy knows the system.
2 Its security relies entirely on the key being secret.
Note:
I The design and implementation of a secure communication system is
a major investment and is not easily and quickly repeated.
I Relying on the enemy not knowing the encryption system is
generally frowned upon as “security by obscurity”.
I The most trusted cryptographic algorithms have been published,
standardized, and withstood years of cryptanalysis.
I A cryptographic key should be just a random choice that can be
easily replaced, by rerunning a key-generation algorithm.
I Keys can and will be lost: cryptographic systems should provide
support for easy rekeying, redistribution of keys, and quick
revocation of compromised keys.
13 / 230
A note about message length
We explicitly do not worry in the following about the adversary being
able to infer something about the length m of the plaintext message M
by looking at the length n of the ciphertext C.
Therefore, we will consider here in security definitions for encryption
schemes only messages of fixed length m.
Variable-length messages could be extended to a fixed length, by
padding, but this can be expensive. It will depend on the specific
application whether the benefits of fixed-length padding outweigh the
added transmission cost.
Nevertheless, in practice, ciphertext length must always be considered as
a potential information leak. Examples:
I Encrypted-file lengths often permit unambiguous reconstruction of
what pages a HTTPS user accessed on a public web site.
G. Danezis: Traffic analysis of the HTTP protocol over TLS.
http://www0.cs.ucl.ac.uk/staff/G.Danezis/papers/TLSanon.pdf
I Data compression can be abused to extract information from an
encrypted message if an adversary can control part of that message.
J. Kelsey: Compression and information leakage of plaintext.
http://www.iacr.org/cryptodb/archive/2002/FSE/3091/3091.pdf
Also: CVE-2012-4929/CRIME
14 / 230
Demo: leaking plaintext through compressed data length
$ cat compression-leak
#!/bin/bash
PLAINTEXT=cafe ←
KEY="N-32m5qEj/emdVr.69w1fX"
ENC="openssl enc -aes-128-ctr -pass pass:$KEY"
for t in {a,b,c,d,e,f}{a,b,c,d,e,f}{a,b,c,d,e,f}{a,b,c,d,e,f} ; do
echo -n "$t "
echo $t $PLAINTEXT | gzip -c | $ENC | wc -c
done | sort -nk2
$ ./compression-leak
15 / 230
Demo: leaking plaintext through compressed data length
$ cat compression-leak
#!/bin/bash
PLAINTEXT=cafe ←
KEY="N-32m5qEj/emdVr.69w1fX"
ENC="openssl enc -aes-128-ctr -pass pass:$KEY"
for t in {a,b,c,d,e,f}{a,b,c,d,e,f}{a,b,c,d,e,f}{a,b,c,d,e,f} ; do
echo -n "$t "
echo $t $PLAINTEXT | gzip -c | $ENC | wc -c
done | sort -nk2
$ ./compression-leak
aafe 44
acaf 44
bafe 44
bcaf 44
cafe 44 ←
ccaf 44
dafe 44
dcaf 44
eafe 44
ecaf 44
fafe 44
fcaf 44
aaaa 46
aaab 46
[. . . remaining 1282 lines not shown . . . ] 15 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
16 / 230
Historic examples of simple ciphers
Shift Cipher: Treat letters {A, . . . , Z} like integers {0, . . . , 25} = Z26 .
Choose key K ∈ Z26 , encrypt each letter individually by addition modulo
26, decrypt by subtraction modulo 26.
Example with K = 25 ≡ −1 (mod 26): IBM→HAL.
K = −3 known as Caesar Cipher, K = 13 as rot13.
The tiny key-space size 26 makes brute-force key search trivial.
Skytale
7 H R S
6
5 D L
4
3 M U W
C F G P Y
2 B K V
1 J Q X Z
0
7 S H R
6
5 D L
4
3 U WM
F C G Y P
2 B K
V
1 J X Q Z
0
13 13
12 12
11 11
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
13 13
12 12
11 11
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
21 / 230
Perfect secrecy
Computational security
The most efficient known algorithm for breaking a cipher would require
far more computational steps than all hardware available to any adversary
can perform.
Unconditional security
Adversaries have not enough information to decide (from the ciphertext)
whether one plaintext is more likely to be correct than another, even with
unlimited computational power at their disposal.
22 / 230
Perfect secrecy II
Consider a private-key encryption scheme
Enc : K × M → C, Dec : K × C → M
23 / 230
Perfect secrecy III
Having eavesdropped some ciphertext C, an adversary can then use
Bayes’ theorem to calculate for any plaintext M ∈ M
P
P(M ) · P(C|M ) P(M ) · {K|M =DecK (C)} P(K)
P(M |C) = = P .
P(C) K P(K) · P(DecK (C))
Perfect secrecy
An encryption scheme over a message space M is perfectly secret if for
every probability distribution over M, every message M ∈ M, and every
ciphertext C ∈ C with P(C) > 0 we have
One-time pad
K = C = M = {0, 1}m
I Gen : K ∈R {0, 1}m (m uniform, independent coin tosses)
I EncK (M ) = K ⊕ M (⊕ = bit-wise XOR)
I DecK (C) = K ⊕ C
Example:
0xbd4b083f6aae ⊕ “Vernam” = 0xbd4b083f6aae ⊕ 0x5665726e616d = 0xeb2e7a510bc3
25 / 230
Vernam cipher / one-time pad II
In the 1940s, the Soviet Union encrypted part of its diplomatic communication using recycled
one-time pads, leading to the success of the US decryption project VENONA.
http://www.nsa.gov/public_info/declass/venona/
26 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
27 / 230
Making the one-time pad more efficient
The one-time pad is very simple, but also very inconvenient:
one key bit for each message bit!
Many standard libraries contain pseudo-random number generators
(PRNGs). They are used in simulations, games, probabilistic algorithms,
testing, etc.
They expand a “seed value” R0 into a sequence of numbers R1 , R2 , . . .
that look very random:
Ri = f (Ri−1 , i)
The results pass numerous statistical tests for randomness (e.g. Marsaglia’s “Diehard” tests).
Can we not use R0 as a short key, split our message M into chunks
M1 , M2 , . . . and XOR with (some function g of) Ri to encrypt Mi ?
Ci = Mi ⊕ g(Ri , i)
28 / 230
Making the one-time pad more efficient
The one-time pad is very simple, but also very inconvenient:
one key bit for each message bit!
Many standard libraries contain pseudo-random number generators
(PRNGs). They are used in simulations, games, probabilistic algorithms,
testing, etc.
They expand a “seed value” R0 into a sequence of numbers R1 , R2 , . . .
that look very random:
Ri = f (Ri−1 , i)
The results pass numerous statistical tests for randomness (e.g. Marsaglia’s “Diehard” tests).
Can we not use R0 as a short key, split our message M into chunks
M1 , M2 , . . . and XOR with (some function g of) Ri to encrypt Mi ?
Ci = Mi ⊕ g(Ri , i)
Attack: guess some plain text (e.g., known file header), obtain for
example (R1 , R2 , R3 ), then solve system of linear equations over Zm :
R2 ≡ aR1 + b (mod m)
R3 ≡ aR2 + b (mod m)
Solution:
Notes:
A “polynomial-time algorithm” has constants a, b, c such that the runtime is
always less than a · `b + c if the input is ` bits long. (think Turing machine)
Technicality: we supply the security parameter ` to Gen here in unary encoding (as a sequence of `
“1” bits: 1` ), merely to remain compatible with the notion of “input size” from computational
complexity theory. In practice, Gen usually simply picks ` random bits K ∈R {0, 1}` .
30 / 230
Security definitions for encryption schemes
We define security via the rules of a game played between two players:
I a challenger, who uses an encryption scheme Π = (Gen, Enc, Dec)
I an adversary A, who tries to demonstrate a weakness in Π.
Most of these games follow a simple pattern:
1 the challenger uniformly picks at random a secret bit b ∈R {0, 1}
2 A interacts with the challenger according to the rules of the game
3 At the end, A has to output a bit b0 .
The outcome of such a game XA,Π (`) is either
I b = b0 ⇒ A won the game, we write XA,Π (`) = 1
I b 6= b0 ⇒ A lost the game, we write XA,Π (`) = 0
Advantage
One way to quantify A’s ability to guess b is
31 / 230
Negligible advantage
Security definition
An encryption scheme Π is considered “X secure” if for all probabilistic
polynomial-time (PPT) adversaries A there exists a “negligible” function
negl such that
1
P(XA,Π (`) = 1) < + negl(`).
2
Some authors prefer the equivalent definition with
Negligible functions
A function negl(`) : N → R is “negligible” if, as ` → ∞, it converges
faster to zero than 1/poly(`) does for any polynomial poly(`).
Experiment/game PrivKeav
A,Π (`):
1` 1`
M0 , M 1
b ∈R {0, 1}
K ← Gen(1` ) A
C ← EncK (Mb )
challenger C adversary
b b0
Setup:
1 The challenger generates a bit b ∈R {0, 1} and a key K ← Gen(1` ).
2 The adversary A is given input 1`
Rules for the interaction:
1 The adversary A outputs a pair of messages:
M0 , M1 ∈ {0, 1}m .
2 The challenger computes C ← EncK (Mb ) and returns
C to A
Finally, A outputs b0 . If b0 = b then A has succeeded ⇒ PrivKeav
A,Π (`) = 1
34 / 230
Indistinguishability in the presence of an eavesdropper
35 / 230
Pseudo-random generator I
Definition
G is a pseudo-random generator if both
1 e(n) > n for all n (expansion)
2 for all probabilistic, polynomial-time distinguishers D there exists a
negligible function negl such that
where both r ∈R {0, 1}e(n) and the seed s ∈R {0, 1}n are chosen at
random, and the probabilities are taken over all coin tosses used by
D and for picking r and s.
36 / 230
Pseudo-random generator II
A brute-force distinguisher D would enumerate all 2n possible outputs of
G, and return 1 if the input is one of them.
It would achieve
P(D(G(s)) = 1) = 1
2n
P(D(r) = 1) =
2e(n)
the difference of which converges to 1, which is not negligible.
But a brute-force distinguisher has a exponential run-time O(2n ), and is
therefore excluded!
37 / 230
Encrypting using a pseudo-random generator
38 / 230
Security proof for a stream cipher
Claim: ΠPRG has indistinguishability in the presence of an eavesdropper
if G is a pseudo-random generator.
Proof: (outline) If ΠPRG did not have indistinguishability in the presence
of an eavesdropper, there would be an adversary A for which
1
(`) := P(PrivKeav
A,ΠPRG (`) = 1) −
2
is not negligible.
Use that A to construct a distinguisher D for G:
I receive input W ∈ {0, 1}e(`)
I pick b ∈R {0, 1}
I run A(1` ) and receive from it M0 , M1 ∈ {0, 1}e(`)
I return C := W ⊕ Mb to A
I receive b0 from A
I return 1 if b0 = b, otherwise return 0
Now, what is |P(D(r) = 1) − P(D(G(K)) = 1)|?
39 / 230
Security proof for a stream cipher (cont’d)
40 / 230
Security proofs through reduction
Some key points about this style of “security proof”:
I We have not shown that the encryption scheme ΠPRG is “secure”.
(We don’t know how to do this!)
I We have shown that ΠPRG has one particular type of security
property, if one of its building blocks (G) has another one.
I We have “reduced” the security of construct ΠPRG to another
problem X:
instance of
instance of
problem X Reduction scheme Π A
A0
solution
attack
to X
Here: X = distinguishing output of G from random string
I We have shown how to turn any successful attack on ΠPRG into an
equally successful attack on its underlying building block G.
I “Successful attack” means finding a polynomial-time probabilistic
adversary algorithm that succeeds with non-negligible success
probability in winning the game specified by the security definition.
41 / 230
Security proofs through reduction
42 / 230
Indistinguishability in the presence of an eavesdropper
Private-key encryption scheme Π = (Gen, Enc, Dec), M = {0, 1}m , security parameter `.
Experiment/game PrivKeav
A,Π (`):
1` 1`
M0 , M 1
b ∈R {0, 1}
K ← Gen(1` ) A
C ← EncK (Mb )
challenger C adversary
b b0
Setup:
1 The challenger generates a bit b ∈R {0, 1} and a key K ← Gen(1` ).
2 The adversary A is given input 1`
Rules for the interaction:
1 The adversary A outputs a pair of messages:
M0 , M1 ∈ {0, 1}m .
2 The challenger computes C ← EncK (Mb ) and returns
C to A
Finally, A outputs b0 . If b0 = b then A has succeeded ⇒ PrivKeav
A,Π (`) = 1
← 34 / 230
Security for multiple encryptions
Private-key encryption scheme Π = (Gen, Enc, Dec), M = {0, 1}m , security parameter `.
Experiment/game PrivKmult
A,Π (`):
1` 1`
M01 , M02 , . . . , M0t
b ∈R {0, 1}
K ← Gen(1` ) M11 , M12 , . . . , M1t
A
C ← EncK (Mb )
challenger C1, C2, . . . , Ct adversary
b b0
Setup:
1 The challenger generates a bit b ∈R {0, 1} and a key K ← Gen(1` ).
2 The adversary A is given input 1`
Rules for the interaction:
1 The adversary A outputs two sequences of t messages:
M01 , M02 , . . . , M0t and M11 , M12 , . . . , M1t , where all Mji ∈ {0, 1}m .
2 The challenger computes C i ← EncK (Mbi ) and returns
C 1 , C 2 , . . . , C t to A
Finally, A outputs b0 . If b0 = b then A has succeeded ⇒ PrivKmult
A,Π (`) = 1
43 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
44 / 230
Security for multiple encryptions (cont’d)
Definition: A private-key encryption scheme Π has indistinguishable
multiple encryptions in the presence of an eavesdropper if for all
probabilistic, polynomial-time adversaries A there exists a negligible
function negl, such that
1
P(PrivKmult
A,Π (`) = 1) ≤ + negl(`)
2
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
Same definition as for indistinguishable encryptions in the presence of an eavesdropper, except for
referring to the multi-message eavesdropping experiment PrivKmultA,Π (`).
Synchronized mode
Let the PRG run for longer to produce enough output bits for all
messages:
45 / 230
Securing a stream cipher for multiple encryptions II
Unsynchronized mode
Some PRGs have two separate inputs, a key K and an “initial vector”
IV . The private key K remains constant, while IV is freshly chosen at
random for each message, and sent along with the message.
46 / 230
Security against chosen-plaintext attacks (CPA)
Private-key encryption scheme Π = (Gen, Enc, Dec), M = {0, 1}m , security parameter `.
Advantages:
I Eavesdroppers can often observe their own text being encrypted,
even where the encrypter never intended to provide an oracle.
(WW2 story: Midway Island/AF, server communication).
I CPA security provably implies security for multiple encryptions.
I CPA security allows us to build a variable-length encryption scheme
simply by using a fixed-length one many times.
48 / 230
Random functions and permutations
Random function
Consider all possible functions of the form
f : {0, 1}m → {0, 1}n
How often do you have to toss a coin to fill the value table of such a
function f with random bits?
How many different such f are there?
An m-bit to n-bit random function f is one that we have picked
uniformly at random from all these possible functions.
49 / 230
Random functions and permutations
Random function
Consider all possible functions of the form
f : {0, 1}m → {0, 1}n
How often do you have to toss a coin to fill the value table of such a
function f with random bits? n · 2m
How many different such f are there?
An m-bit to n-bit random function f is one that we have picked
uniformly at random from all these possible functions.
49 / 230
Random functions and permutations
Random function
Consider all possible functions of the form
f : {0, 1}m → {0, 1}n
How often do you have to toss a coin to fill the value table of such a
function f with random bits? n · 2m
m
How many different such f are there? 2n·2
An m-bit to n-bit random function f is one that we have picked
uniformly at random from all these possible functions.
49 / 230
Random functions and permutations
Random function
Consider all possible functions of the form
f : {0, 1}m → {0, 1}n
How often do you have to toss a coin to fill the value table of such a
function f with random bits? n · 2m
m
How many different such f are there? 2n·2
An m-bit to n-bit random function f is one that we have picked
uniformly at random from all these possible functions.
Random permutation
Consider all possible permutations of the form
g : {0, 1}n ↔ {0, 1}n
Random permutation
Consider all possible permutations of the form
g : {0, 1}n ↔ {0, 1}n
For typical key lengths (e.g., k, m ≥ 128), the set of all possible functions
FK will be a tiny subset of the set of all possible random functions f .
For a secure pseudo-random function F there must be no practical way
to distinguish between FK and a corresponding random function f for
anyone who does not know key K.
Definition
F is a pseudo-random function if for all probabilistic, polynomial-time
distinguishers D there exists a negligible function negl such that
F (·) n f (·) n
P(D K (1 ) = 1) − P(D (1 ) = 1) ≤ negl(n)
51 / 230
Pseudo-random function (formal definition)
F : {0, 1}n × {0, 1}n → {0, 1}n efficient, keyed, length preserving
key input output |input|=|output|
Definition
F is a pseudo-random function if for all probabilistic, polynomial-time
distinguishers D there exists a negligible function negl such that
F (·) n f (·) n
P(D K (1 ) = 1) − P(D (1 ) = 1) ≤ negl(n)
51 / 230
Pseudo-random function (formal definition)
F : {0, 1}n × {0, 1}n → {0, 1}n efficient, keyed, length preserving
key input output |input|=|output|
Definition
F is a pseudo-random function if for all probabilistic, polynomial-time
distinguishers D there exists a negligible function negl such that
F (·) n f (·) n
P(D K (1 ) = 1) − P(D (1 ) = 1) ≤ negl(n)
M := FK (R) ⊕ S
52 / 230
CPA-secure encryption using a pseudo-random function
We define the following fixed-length private-key encryption scheme:
M := FK (R) ⊕ S
collision probability
0.6
10 -20
0.4
10 -30
0.2
0 10 -40
10 0 10 10 10 20 10 30 10 40 10 0 10 10 10 20 10 30 10 40
40 40
number of balls thrown into 10 bins number of balls thrown into 10 bins
59 / 230
Block ciphers
Practical, efficient algorithms that try to implement a pseudo-random
permutation E (and its inverse D) are called “block ciphers”:
E : {0, 1}k × {0, 1}n → {0, 1}n
D : {0, 1}k × {0, 1}n → {0, 1}n
with DK (EK (M )) = M for all K ∈ {0, 1}k , M ∈ {0, 1}n .
Alphabet size: 2n , size of key space: 2k
EK (M ) = C = Lr kRr
61 / 230
Feistel structure II
Plaintext:
L0 R0
Feistel structure II
r = 1 round:
L0 R0
⊕ fK,1
L1 R1
Feistel structure II
r = 2 rounds:
L0 R0
⊕ fK,1
L1 R1
fK,2 ⊕
L2 R2
Feistel structure II
r = 3 rounds:
L0 R0
⊕ fK,1
L1 R1
fK,2 ⊕
L2 R2
⊕ fK,3
L3 R3
62 / 230
Feistel structure III
Decryption:
L0 R0
⊕ fK,1
L1 R1
fK,2 ⊕
L2 R2
⊕ fK,3
L3 R3
63 / 230
Feistel structure IV
This works because the Feistel structure is arranged such that during
decryption of round i, the input value for fK,i is known, as it formed half
of the output bits of round i during encryption.
Luby–Rackoff result
If f is a pseudo-random function, then r = 3 Feistel rounds build a
pseudo-random permutation and r = 4 rounds build a strong
pseudo-random permutation.
M. Luby, C. Rackoff: How to construct pseudorandom permutations from pseudorandom functions.
CRYPTO’85, LNCS 218, http://www.springerlink.com/content/27t7330g746q2168/
64 / 230
Data Encryption Standard (DES)
65 / 230
The round function f expands the 32-bit
input to 48 bits, XORs this with a 48-bit
subkey, and applies eight carefully designed
6-bit to 4-bit substitution tables
(“s-boxes”). The expansion function E
makes sure that each sbox shares one input
bit with its left and one with its right
neighbour.
66 / 230
The key schedule of DES
breaks the key into two 28-bit
halves, which are left shifted
by two bits in most rounds
(only one bit in round
1,2,9,16) before 48 bits are
selected as the subkey for
each round.
67 / 230
Strengthening DES
Two techniques have been widely used to extend the short DES key size:
TDES−1
K (C) = DES−1 −1
K1 (DESK2 (DESK3 (C)))
70 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
71 / 230
Electronic Code Book (ECB) I
ECB is the simplest mode of operation for block ciphers (DES, AES).
The message M is cut into m n-bit blocks:
Ci = EK (Mi ) i = 1, . . . , m
C = C1 kC2 k . . . kCm
M1 M2 Mm
EK EK ··· EK
C1 C2 Cm
72 / 230
Electronic Code Book (ECB) II
Warning:
Like any deterministic encryption scheme,
Electronic Code Book (ECB) mode is not CPA secure.
Another problem:
Plaintext block values are often not uniformly distributed, for example in
ASCII encoded English text, some bits have almost fixed values.
As a result, not the entire input alphabet of the block cipher is utilised,
which simplifies for an eavesdropper building and using a value table of
EK .
http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
73 / 230
Electronic Code Book (ECB) III
Plain-text bitmap:
DES-ECB encrypted:
74 / 230
Randomized encryption
Any CPA secure encryption scheme must be randomized, meaning that
the encryption algorithm has access to an r-bit random value that is not
predictable to the adversary:
Enc : {0, 1}k ×{0, 1}r ×{0, 1}l → {0, 1}m
Dec : {0, 1}k ×{0, 1}m → {0, 1}l
receives in addition to the k-bit key and l-bit plaintext also an r-bit
random value, which it uses to ensure that repeated encryption of the
same plaintext is unlikely to result in the same m-bit ciphertext.
With randomized encryption, the ciphertext will be longer than the plaintext: m > l, for example
m = r + l.
Given a fixed-length pseudo-random function F , we could encrypt a variable-length message
M kpad(M ) = M1 kM2 k . . . kMn by applying ΠPRF to its individual blocks Mi , and the result
will still be CPA secure:
EncK (M ) = (R1 , EK (R1 ) ⊕ M1 , R2 , EK (R2 ) ⊕ M2 , . . . Rn , EK (Rn ) ⊕ Mn )
But this doubles the message length!
Mi ⊕ EK Ci
76 / 230
Cipher Block Chaining (CBC) II
M1 M2 Mm
⊕ ⊕ ⊕
RND EK EK ··· EK
C0 C1 C2 Cm
initial vector
77 / 230
Cipher Block Chaining (CBC) II
M1 M2 Mm
⊕ ⊕ ⊕
RND DK DK ··· DK
C0 C1 C2 Cm
initial vector
77 / 230
Plain-text bitmap:
DES-CBC encrypted:
78 / 230
Cipher Feedback Mode (CFB)
Ci = Mi ⊕ EK (Ci−1 )
EK
Mi ⊕ Ci
M1 kM2 k . . . kMm = M
Ri = EK (Ri−1 )
EK Ri
Ci = Mi ⊕ Ri
for 0 < i ≤ m. From Rm use only the leftmost bits needed for Mm .
4 Output the cipher text C = C0 kC1 k . . . kCm
n
Again, the key K should be replaced before in the order of 2 2 n-bit blocks have been generated.
Unlike with CBC or CFB, the IV does not have to be unpredictable or random (it can be a
counter), but it must be very unlikely that the same IV is ever used again or appears as another
value Ri while the same key K is still used.
80 / 230
Counter Mode (CTR)
This mode is also a stream cipher. It obtains the pseudo-random bit
stream by encrypting an easy to generate sequence of mutually different
blocks T1 , T2 , . . . , Tm , such as the block counter i plus some offset O,
encoded as an n-bit binary value:
Ci = Mi ⊕ EK (Ti ), Ti = hO + ii, for 0 < i ≤ m
Choose O such that probability of reusing any Ti under the same K is
negligible. Send offset O as initial vector C0 = hOi.
Notation hii here means “n-bit binary representation of integer i”, where n is block length of EK .
Advantages:
I allows fast random access
I both encryption and decryption can be parallelized
I low latency
I no padding required
I no risk of short cycles
Today, Counter Mode is generally preferred over CBC, CFB, and OFB.
Alternatively, the Ti can also be generated by a maximum-length linear-feedback shift register
(replacing the operation O + i in Z2n with O(x) · xi in F2n to avoid slow carry bits).
81 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
82 / 230
Security against chosen-ciphertext attacks (CCA)
Private-key encryption scheme Π = (Gen, Enc, Dec), M = {0, 1}m , security parameter `.
Setup:
I handling of `, b, K as before
Rules for the interaction:
1 The adversary A is given oracle access to EncK and DecK :
A outputs M 1 , gets EncK (M 1 ), outputs C 2 , gets DecK (C 2 ), . . .
m
2 The adversary A outputs a pair of messages: M0 , M1 ∈ {0, 1} .
Malleability is not necessarily a bad thing. If carefully used, it can be an essential building block to
privacy-preserving technologies such as digital cash or anonymous electonic voting schemes.
Homomorphic encryption schemes are malleable by design, providing anyone not knowing the key a
means to transform the ciphertext of M into a valid encryption of f (M ) for some restricted class
of transforms f .
84 / 230
Message authentication code (MAC)
85 / 230
MAC security definition: existential unforgeability
Message authentication code Π = (Gen, Mac, Vrfy), M = {0, 1}∗ , security parameter `.
Mallory can still delay messages or replay old ones. Including in addition unique transmission
timestamps in the messages (in at least M1 and M2 ) allows the recipient to verify their
“freshness” (using a secure, accurate local clock).
88 / 230
MAC using a pseudo-random function
89 / 230
MAC using a block cipher: CBC-MAC
Blockcipher E : {0, 1}` × {0, 1}m → {0, 1}m
M1 M2 Mn
⊕ ⊕
EK EK ··· EK
CBC-MACEK (M )
M1 M2 Mn
⊕ ⊕
Padding: M k10p
p = m − (|M | mod m) − 1
EK2
Disadvantages:
I up to two additional
applications of block cipher
I need to rekey block cipher ECBC-MACEK1 ,K2 (M )
I added block if m divides |M |
91 / 230
Variable-length MAC using a block cipher: CMAC
Blockcipher E : {0, 1}` × {0, 1}m → {0, 1}m (typically AES: m = 128)
CMAC algorithm:
M1 kM2 k . . . kMn := M
r := |Mn |
if r = m then Mn := K1 ⊕ Mn
else Mn := K2 ⊕ (Mn k10m−r−1 )
return CBC-MACK (M1 kM2 k . . . kMn )
Provides existential unforgeability, without the disadvantages of ECBC.
NIST SP 800-38B, RFC 4493
92 / 230
Birthday attack against CBC-MAC, ECBC-MAC, CMAC
Let E be an m-bit block cipher, used to build MACK with m-bit tags.
Birthday/collision attack:
√
I Make t ≈ 2m oracle queries for T i := MACK (hiikRi kh0i) with
Ri ∈R {0, 1}m , 1 ≤ i ≤ t.
Here hii ∈ {0, 1}m is the m-bit binary integer notation for i.
I Look for collision T i = T j with i 6= j
I Ask oracle for T 0 := MACK (hiikRi kh1i)
I Present M := hjikRj kh1i and T := T 0 = MACK (M )
The same intermediate value
C2 occurs while calculating the hii Ri h0i
MAC of
hiikRi kh0i, hjikRj kh0i, ⊕ ⊕
hiikRi kh1i, hjikRj kh1i.
EK EK EK
Possible workaround:
Truncate MAC result to less than m bits,
such that adversary cannot easily spot col-
lisions in C2 from C3 .
C1 C2 MACK
Solution: big enough m.
93 / 230
A one-time MAC (Carter–Wegman)
The following MAC scheme is very fast and unconditionally secure, but
only if the key is used to secure only a single message.
Let F be a large finite field (e.g. Z2128 +51 or GF(2128 )).
I Pick a random key pair K = (K1 , K2 ) ∈ F2
I Split padded message P into blocks P1 , . . . , Pm ∈ F
I Evaluate the following polynomial over F to obtain the MAC:
95 / 230
Security against chosen-ciphertext attacks (CCA)
Private-key encryption scheme Π = (Gen, Enc, Dec), M = {0, 1}m , security parameter `.
Setup:
I handling of `, b, K as before
Rules for the interaction:
1 The adversary A is given oracle access to EncK and DecK :
A outputs M 1 , gets EncK (M 1 ), outputs C 2 , gets DecK (C 2 ), . . .
m
2 The adversary A outputs a pair of messages: M0 , M1 ∈ {0, 1} .
C0 = IV C1 C2 C3
DK DK DK
⊕ ⊕ ⊕
M1 M2 M3 kpad
99 / 230
Padding oracle (cont’d)
Attacker has C0 , . . . , C3 and tries to get M2 :
100 / 230
Galois Counter Mode (GCM)
CBC and CBC-MAC used together require different keys, resulting in two
encryptions per block of data.
Galois Counter Mode is a more efficient authenticated encryption
technique that requires only a single encryption, plus one XOR ⊕ and
one multiplication ⊗, per block of data:
Ci = Mi ⊕ EK (O + i)
Gi = (Gi−1 ⊕ Ci ) ⊗ H, G0 = A ⊗ H, H = EK (0)
GMACEK (A, C) = (Gn ⊕ (len(A)k len(C))) ⊗ H ⊕ EK (O)
EK EK
M1 ⊕ Mn ⊕
C1 Cn
O O+1 ··· O+n
EK EK EK
M1 ⊕ Mn ⊕
C1 Cn
A ⊗ ⊕ ⊗ ··· ⊕
⊕ len(A)k len(C)
⊗ EK (0)
⊕
GMACEK (A, C)
102 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
103 / 230
Hash functions
A hash function h : {0, 1}∗ → {0, 1}` efficiently maps arbitrary-length
input strings onto fixed-length “hash values” such that the output is
uniformly distributed in practice.
Typical applications of hash functions:
I hash table: data structure for fast t = O(1) table lookup; storage
address of a record containing value x is determined by h(x).
I Bloom filter: data structure for fast probabilistic set membership test
I fast probabilistic string comparison (record deduplication, diff, rsync)
I Rabin–Karp algorithm: substring search with rolling hash
Closely related: checksums (CRC, Fletcher, Adler-32, etc.)
108 / 230
Unkeyed hash functions
108 / 230
Weaker properties implied by collision resistance
Second-preimage resistance
For a given s and input value x, it is infeasible for any polynomial-time
adversary to find x0 with Hs (x0 ) = Hs (x) (except with negligible
probability).
109 / 230
Weaker properties implied by collision resistance
Second-preimage resistance
For a given s and input value x, it is infeasible for any polynomial-time
adversary to find x0 with Hs (x0 ) = Hs (x) (except with negligible
probability).
Preimage resistance
For a given s and output value y, it is infeasible for any polynomial-time
adversary to find x0 with Hs (x0 ) = y (except with negligible probability).
Preimage resistance
For a given s and output value y, it is infeasible for any polynomial-time
adversary to find x0 with Hs (x0 ) = y (except with negligible probability).
Preimage resistance
For a given s and output value y, it is infeasible for any polynomial-time
adversary to find x0 with Hs (x0 ) = y (except with negligible probability).
2 Append a final block xB+1 = hLi, which contains the n-bit binary
representation of input length L = |x|.
3 Set z0 := 0n (initial vector, IV)
4 compute zi := Cs (zi−1 kxi ) for i = 1, . . . , B + 1
5 Output Hs (x) := zB+1
110 / 230
xk0nd n e−L = x1 kx2 kx3 k . . . kxB−1 kxB
L
x1 x2 xB hLi
Cs Cs ··· Cs Cs
0n z z1 zB−1 zB zB+1
Hs (x)
0
111 / 230
xk0nd n e−L = x1 kx2 kx3 k . . . kxB−1 kxB
L
x1 x2 xB hLi
Cs Cs ··· Cs Cs
0n z z1 zB−1 zB zB+1
Hs (x)
0
x 6= x0
0
0 n L
−L0
x k0 n = x01 kx02 kx03 k . . . kx0B 0 −1 kx0B 0
Cs Cs ··· Cs Cs
0n zB 0 +1
Hs (x)
z00 z10 0
zB 0 −1
0
zB 0
111 / 230
Merkle–Damgård construction – security proof
If the fixed-length compression function C is collision resistant, so will be
the variable-length hash function H resulting from the Merkle–Damgård
construction.
Proof outline:
Assume Cs is collision resistant, but H is not, because some PPT
adversary A outputs x 6= x0 with Hs (x) = Hs (x0 ).
Let x1 , . . . , xB be the n-bit blocks of padded L-bit input x, and
x01 , . . . , x0B 0 be those of L0 -bit input x0 , and xB+1 = hLi, x0B 0 +1 = hL0 i.
Case L 6= L0 : Then xB+1 6= x0B 0 +1 but Hs (x) = zB+1 =
0 0 0 0
Cs (zB kxB+1 ) = Cs (zB 0 kxB 0 +1 ) = zB 0 +1 = Hs (x ), which
is a collision in Cs .
Case L = L : Now B = B 0 . Let i ∈ {1, . . . , B + 1} be the largest index
0
0
where zi−1 kxi 6= zi−1 kx0i . (Such i exists as due to
0 0
|x| = |x | and x 6= x there will be at least one 1 ≤ j ≤ B
with xj 6= x0j .) Then zk = zk0 for all k ∈ {i, . . . , B + 1}
0
and zi = Cs (zi−1 kxi ) = Cs (zi−1 kx0i ) = zi0 is a collision in
Cs .
So Cs was not collision resistant, invalidating the assumption.
112 / 230
Compression function from block ciphers
Davies–Meyer construction
One possible technique for obtaining a collision-resistant compression
function C is to use a block cipher E : {0, 1}` × {0, 1}n → {0, 1}n in the
following way:
C(K, M ) = EK (M ) ⊕ M
M EK ⊕ C(K, M )
Random oracle
I A random oracle H is a device that accepts arbitrary length strings
X ∈ {0, 1}∗ and consistently outputs for each a value
H(X) ∈ {0, 1}` which it chooses uniformly at random.
I Once it has chosen an H(X) for X, it will always output that same
answer for X consistently.
I Parties can privately query the random oracle (nobody else learns
what anyone queries), but everyone gets the same answer if they
query the same value.
I No party can infer anything about H(X) other than by querying X.
115 / 230
Ideal cipher model
A random-oracle equivalent can be defined for block ciphers:
Ideal cipher
Each key K ∈ {0, 1}` defines a random permutation EK , chosen
uniformly at random out of all (2n )! permutations. All parties have oracle
−1
access to both EK (X) and EK (X) for any (K, X). No party can infer
−1
any information about EK (X) (or EK (X)) without querying its value
for (K, X).
C(K, X) = EK (X) ⊕ X
If E is modeled as an ideal cipher, then C is a collision-resistant hash
function. Any attacker A making q < 2`/2 oracle queries to E finds a
collision with probability not higher than q 2 /2` . (negligible)
Proof: Attacker A tries to find (K, X), (K 0 , X 0 ) with
EK (X) ⊕ X = EK 0 (X 0 ) ⊕ X 0 . We assume that, before outputting
(K, X), (K 0 , X 0 ), A has previously made queries to learn EK (X) and
EK 0 (X 0 ). We also assume (wlog) A never makes redundant queries, so
−1
having learnt Y = EK (X), A will not query EK (Y ) and vice versa.
The i-th query (Ki , Xi ) to E only reveals
http://sponge.noekeon.org/
(r + c)-bit internal state, XOR r-bit input blocks at a time, stir with
pseudo-random permutation f , output r-bit output blocks at a time.
Versatile: secure hash function (variable input length) and stream cipher
(variable output length)
Advantage over Merkle–Damgård: internal state > output, flexibility.
120 / 230
Duplex construction
http://sponge.noekeon.org/
122 / 230
Probability of collision / Birthday problem
With 23 random people in a room, there is a 0.507 chance that two share a birthday. Surprised?
collision probability
0.6
10 -20
0.4
10 -30
0.2
0 10 -40
10 0 10 10 10 20 10 30 10 40 10 0 10 10 10 20 10 30 10 40
40 40
number of balls thrown into 10 bins number of balls thrown into 10 bins
123 / 230
“Birthday attacks”
If a hash function outputs `-bit words, an attacker needs to try only
2`/2 different input values, before there is a better than 50% chance of
finding a collision.
Computational security
Attacks requiring 2128 steps considered infeasible =⇒ use hash function
that outputs ` = 256 bits (e.g., SHA-256). If only second pre-image
resistance is a concern, shorter ` = 128-bit may be acceptable.
123 / 230
“Birthday attacks”
If a hash function outputs `-bit words, an attacker needs to try only
2`/2 different input values, before there is a better than 50% chance of
finding a collision.
Computational security
Attacks requiring 2128 steps considered infeasible =⇒ use hash function
that outputs ` = 256 bits (e.g., SHA-256). If only second pre-image
resistance is a concern, shorter ` = 128-bit may be acceptable.
Finding useful collisions
An attacker needs to generate a large number of plausible input
plaintexts to find a practically useful collision. For English plain text,
synonym substitution is one possibility for generating these:
A: Mallory is a {good,hardworking} and {honest,loyal} {employee,worker}
B: Mallory is a {lazy,difficult} and {lying,malicious} {employee,worker}
Both A and B can be phrased in 23 variants each =⇒ 26 pairs of phrases.
123 / 230
“Birthday attacks”
If a hash function outputs `-bit words, an attacker needs to try only
2`/2 different input values, before there is a better than 50% chance of
finding a collision.
Computational security
Attacks requiring 2128 steps considered infeasible =⇒ use hash function
that outputs ` = 256 bits (e.g., SHA-256). If only second pre-image
resistance is a concern, shorter ` = 128-bit may be acceptable.
Finding useful collisions
An attacker needs to generate a large number of plausible input
plaintexts to find a practically useful collision. For English plain text,
synonym substitution is one possibility for generating these:
A: Mallory is a {good,hardworking} and {honest,loyal} {employee,worker}
B: Mallory is a {lazy,difficult} and {lying,malicious} {employee,worker}
Both A and B can be phrased in 23 variants each =⇒ 26 pairs of phrases.
With a 64-bit hash over an entire letter, we need only such
sentences for a good chance to find a collision in steps.
123 / 230
“Birthday attacks”
If a hash function outputs `-bit words, an attacker needs to try only
2`/2 different input values, before there is a better than 50% chance of
finding a collision.
Computational security
Attacks requiring 2128 steps considered infeasible =⇒ use hash function
that outputs ` = 256 bits (e.g., SHA-256). If only second pre-image
resistance is a concern, shorter ` = 128-bit may be acceptable.
Finding useful collisions
An attacker needs to generate a large number of plausible input
plaintexts to find a practically useful collision. For English plain text,
synonym substitution is one possibility for generating these:
A: Mallory is a {good,hardworking} and {honest,loyal} {employee,worker}
B: Mallory is a {lazy,difficult} and {lying,malicious} {employee,worker}
Both A and B can be phrased in 23 variants each =⇒ 26 pairs of phrases.
With a 64-bit hash over an entire letter, we need only 11 such
sentences for a good chance to find a collision in steps.
123 / 230
“Birthday attacks”
If a hash function outputs `-bit words, an attacker needs to try only
2`/2 different input values, before there is a better than 50% chance of
finding a collision.
Computational security
Attacks requiring 2128 steps considered infeasible =⇒ use hash function
that outputs ` = 256 bits (e.g., SHA-256). If only second pre-image
resistance is a concern, shorter ` = 128-bit may be acceptable.
Finding useful collisions
An attacker needs to generate a large number of plausible input
plaintexts to find a practically useful collision. For English plain text,
synonym substitution is one possibility for generating these:
A: Mallory is a {good,hardworking} and {honest,loyal} {employee,worker}
B: Mallory is a {lazy,difficult} and {lying,malicious} {employee,worker}
Both A and B can be phrased in 23 variants each =⇒ 26 pairs of phrases.
With a 64-bit hash over an entire letter, we need only 11 such
sentences for a good chance to find a collision in 234 steps.
123 / 230
Low-memory collision search
A normal search for an `-bit collision uses O(2`/2 ) memory and time.
Algorithm for finding a
collision with O(1) memory x0
and O(2`/2 ) time:
Input: H : {0, 1}∗ → {0, 1}`
Basic idea:
Output: x 6= x0 with H(x) = H 0 (x)
x0 ← {0, 1}`+1 I Tortoise x goes at most once
x0 := x := x0 round the cycle, hare x0 at
i := 0 least once
loop I loop 1: ends when x0
i := i + 1 overtakes x for the first time
x := H(x) // x = H i (x0 ) ⇒ x0 now i steps ahead of x
0 0
x := H(H(x )) // x0 = H 2i (x0 ) ⇒ i is now an integer
0
until x = x multiple of the cycle length
x0 := x, x := x0
I loop 2: x back at start, x0 is i
for j = 1, 2, . . . , i
steps ahead, same speed
if H(x) = H(x0 ) return (x, x0 )
⇒ meet at cycle entry point
x := H(x) // x = H j (x0 )
x0 := H(x0 ) // x0 = H i+j (x0 ) Wikipedia: Cycle detection
124 / 230
Constructing meaningful collisions
Tortoise-hare algorithm gives no direct control over content of x, x0 .
Solution:
Define a text generator function g : {0, 1}` → {0, 1}∗ , e.g.
g(0000) = Mallory is a good and honest employee
g(0001) = Mallory is a lazy and lying employee
g(0010) = Mallory is a good and honest worker
g(0011) = Mallory is a lazy and lying worker
g(0100) = Mallory is a good and loyal employee
g(0101) = Mallory is a lazy and malicious employee
···
g(1111) = Mallory is a difficult and malicious worker
126 / 230
Hash and MAC
A secure hash function can be combined with a fixed-length MAC to
provide a variable-length MAC Mack (H(m)). More formally:
Let Π = (Mac, Vrfy) be a MAC for messages of length `(n) and let
ΠH = (GenH , H) be a hash function with output length `(n). Then
define variable-length MAC Π0 = (Gen0 , Mac0 , Vrfy0 ) as:
I Gen0 : Read security parameter 1n , choose uniform k ∈ {0, 1}n , run
s := GenH (1n ) and return (k, s).
I Mac0 : read key (k, s) and message m ∈ {0, 1}∗ , return tag
Mack (Hs (m)).
I Vrfy0 : read key (k, s), message m ∈ {0, 1}∗ , tag t, return
Vrfyk (Hs (m), t).
If Π offers existential unforgeability and ΠH is collision resistant, then Π0
will offer existential unforgeability.
Proof outline: If an adversary used Mac0 to get tags on a set Q of messages,
and then can produce a valid tag for m∗ 6∈ Q, then there are two cases:
I ∃m ∈ Q with Hs (m) = Hs (m∗ ) ⇒ Hs not collision resistant
I ∀m ∈ Q : Hs (m) 6= Hs (m∗ ) ⇒ Mac failed existential unforgeability
127 / 230
Hash-based message authentication code
Initial idea: hash a message M prefixed with a key K to get
MACK (M ) = h(KkM )
MACK (M ) = h(h(KkM ))
or
MACK (M ) = h(Kkh(M ))
could be used to terminate the iteration of the compression function in a
way that the adversary cannot continue. ⇒ HMAC
128 / 230
HMAC
HMAC is a standard technique widely used to form a
message-authentication code using a Merkle–Damgård-style secure hash
function h, such as MD5, SHA-1 or SHA-256:
HMACK (x) = h(K ⊕ opadkh(K ⊕ ipadkx))
Fixed padding values ipad, opad extend the key to the input size of the
compression function, to permit precomputation of its first iteration.
K ⊕ ipad x1 xB
Cs Cs ··· Cs
0n
K ⊕ opad kpadding(2n)
Cs Cs
0n HMACK (x)
http://www.ietf.org/rfc/rfc2104.txt
129 / 230
Secure commitment
Proof of prior knowledge
You have today an idea that you write down in message M . You do not
want to publish M yet, but you want to be able to prove later that you
knew M already today. Initial idea: you publish h(M ) today.
Danger: if the entropy of M is small (e.g., M is a simple choice, a PIN,
etc.), there is a high risk that your adversary can invert the
collision-resistant function h successfully via brute-force search.
Solution:
I Pick (initially) secret N ∈ {0, 1}128 uniformly at random.
I Publish h(N, M ) (as well as h and |N |).
I When the time comes to reveal M , also reveal N .
You can also commit yourself to message M , without yet revealing it’s
content, by publishing h(N, M ).
Applications: online auctions with sealed bids, online games where
several parties need to move simultaneously, etc.
Tuple (N, M ) means any form of unambiguous concatenation, e.g. N kM if length |N | is agreed.
130 / 230
Merkle tree
Problem: Untrusted file store, small trusted memory. Solution: hash tree.
Leaves contain hash values of files F0 , . . . , Fk−1 . Each inner node
contains the hash of its children. Only root h0 (and number k of files)
needs to be stored securely.
Advantages of tree (over naive alternative h0 = h(F0 , . . . , Fk−1 )):
I Update of a file Fi requires only O(log k) recalculations of hash
values along path from h(Fi ) to root (not rereading every file).
I Verification of a file requires only reading O(log k) values in all
direct children of nodes in path to root (not rereading every node).
h0 = h(h1 , h2 )
h1 = h(h3 , h4 ) h2 = h(h5 , h6 )
Store last chain value H := Rn on the host server. Give the remaining
list Rn−1 , Rn−2 , . . . , R0 as one-time passwords to the user.
?
When user enters password Ri , compare h(Ri ) = H. If they match:
I Update H := Ri on host
I grant access to user
Leslie Lamport: Password authentication with insecure communication. CACM 24(11)770–772,
1981. http://doi.acm.org/10.1145/358790.358797
132 / 230
Broadcast stream authentication
Alice sends to a group of recipients a long stream of messages
M1 , M2 , . . . , Mn . They want to verify Alice’s signature on each packet
immediately upon arrival, but it is too expensive to sign each message.
Alice calculates
C1 = h(C2 , M1 )
C2 = h(C3 , M2 )
C3 = h(C4 , M3 )
···
Cn−2 = h(Cn−1 , Mn−2 )
Cn−1 = h(Cn , Mn−1 )
Cn = h(0, Mn )
and then broadcasts the stream
C1 , Sign(C1 ), (C2 , M1 ), (C3 , M2 ), . . . , (0, Mn ).
Only the first check value is signed, all other packets are bound together
in a hash chain that is linked to that single signature.
Problem: Alice needs to know Mn before she can start to broadcast C1 . Solution: TESLA
133 / 230
Timed Efficient Stream Loss-tolerant Authentication
134 / 230
Hash chains, block chains, time-stamping services
Clients continuously produce transactions Mi (e.g., money transfers).
Block-chain time-stamping service: receives client transactions Mi ,
may order them by dependency, validates them (payment covered by
funds?), batches them into groups
G1 = (M1 , M2 , M3 )
G2 = (M4 , M5 , M6 , M7 )
G3 = (M8 , M9 )
...
B1 = (G1 , t1 , 0)
B2 = (G2 , t2 , h(B1 ))
B3 = (G3 , t3 , h(B2 ))
...
Bi = (Gi , ti , h(Bi−1 ))
135 / 230
New blocks are broadcast to and archived by clients. Clients can
I verify that ti−1 ≤ ti ≤ now
I verify h(Bi−1 )
I frequently compare latest h(Bi ) with other clients
to ensure consensus that
I each client sees the same serialization order of the same set of
validated transactions
I every client receives the exact same block-chain data
I nobody can later rewrite the transaction history
136 / 230
New blocks are broadcast to and archived by clients. Clients can
I verify that ti−1 ≤ ti ≤ now
I verify h(Bi−1 )
I frequently compare latest h(Bi ) with other clients
to ensure consensus that
I each client sees the same serialization order of the same set of
validated transactions
I every client receives the exact same block-chain data
I nobody can later rewrite the transaction history
The Bitcoin crypto currency is based on a decentralized block-chain:
I accounts identified by single-use public keys
I each transaction signed with the payer’s private key
I new blocks broadcast by “miners”, who are allowed to mint
themselves new currency as incentive for operating the service
I issuing rate of new currency is limited by requirement for miners to
solve cryptographic puzzle (adjust a field in each block such that
h(Bi ) has a required number of leading zeros, currently ≈ 68 bits)
https://blockchain.info/ https://en.bitcoin.it/
136 / 230
Key derivation functions
A secret key K should only ever be used for one single purpose, to prevent one
application of K being abused as an oracle for compromising another one.
Any cryptographic system may involve numerous applications for keys (for encryption
systems, message integrity schemes, etc.)
A key derivation function (KDF) extends a single multi-purpose key K (which may
have been manually configured by a user, or may have been the result of a
key-agreement protocol) into k single-purpose keys K1 , K2 , . . . , Kk .
Requirements:
I Use a one-way function, such that compromise of one derived key Ki does not
also compromise the master key K or any other derived keys Kj (j 6= i).
I Use an entropy-preserving function, i.e. H(Ki ) ≈ min{H(K), |Ki |}
I Include a unique application identifier A (e.g., descriptive text string, product
name, domain name, serial number), to minimize the risk that someone else
accidentally uses the same derived keys for another purpose.
Secure hash functions work well for this purpose, especially those with arbitrary-length
output (e.g., SHA-3). Split their output bit sequence into the keys needed:
K1 kK2 k . . . kKk = h(A, K)
Hash functions with fixed output-length (e.g., SHA-256) may have to be called
multiple times, with an integer counter:
K1 kK2 = h(A, K, h1i), K3 kK4 = h(A, K, h2i), . . .
ISO/IEC 11770-6
137 / 230
Password-based key derivation
Human-selected secrets (PINs, passwords, pass-phrases) usually have much
lower entropy than the > 80 bits desired for cryptographic keys.
Typical password search list: “dictionary of 64k words, 4k suffixes, 64 prefixes and 4 alteration
rules for a total of 238 passwords” http://ophcrack.sourceforge.net/tables.php
Machine-generated random strings encoded for keyboard entry (hexadecimal,
base64, etc.) still lack the full 8 bits per byte entropy of a random binary string
(e.g. only < 96 graphical characters per byte from keyboard).
Workarounds:
I Preferably generate keys with a true random bit generator.
I Ask user to enter a text string longer than the key size.
I Avoid or normalize visually similar characters: 0OQ/1lI/A4/Z2/S5/VU/nu
I Use a secure hash function to condense the passphrase to key length.
I Use a deliberately slow hash function, e.g. iterate C times.
I Use a per-user random salt value S to personalize the hash function
against pre-computed dictionary attacks.
Stored random string where practical, otherwise e.g. user name.
or similar.
Standard password-based key derivation functions, such as PBKDF2 or
Argon2, can also be used to verify passwords.
Argon2 is deliberately designed to be memory intensive to discourage fast ASIC implementations.
139 / 230
Inverting unsalted password hashes: time–memory trade-off
Target: invert h(p), where p ∈ P is a password from an assumed finite set
P of passwords (e.g., h = MD5, |P | = 958 ≈ 253 8-char ASCII strings)
Idea: define “reduction” function r : {0, 1}128 → P , then iterate h(r(·))
For example: convert input from base-2 to base-96 number, output first 8 “digits” as printable
ASCII characters, interpret DEL as string terminator.
r h r h h r h
x0 → p1 → x1 → p2 → · · · → xn−1 → pn → xn ⇒ L[xn ] := x0
m .
y ..
140 / 230
Inverting unsalted password hashes: time–memory trade-off
Target: invert h(p), where p ∈ P is a password from an assumed finite set
P of passwords (e.g., h = MD5, |P | = 958 ≈ 253 8-char ASCII strings)
Idea: define “reduction” function r : {0, 1}128 → P , then iterate h(r(·))
For example: convert input from base-2 to base-96 number, output first 8 “digits” as printable
ASCII characters, interpret DEL as string terminator.
r h r h h r h
x0 → p1 → x1 → p2 → · · · → xn−1 → pn → xn ⇒ L[xn ] := x0
m .
y ..
142 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
143 / 230
Key distribution problem
In a group of n participants, there are n(n − 1)/2 pairs who might want
to communicate at some point, requiring O(n2 ) private keys to be
exchanged securely in advance.
This gets quickly unpractical if n 2 and if participants regularly join
and leave the group.
P8 P1 P2
P7 P3
P6 P5 P4
144 / 230
Key distribution problem
In a group of n participants, there are n(n − 1)/2 pairs who might want
to communicate at some point, requiring O(n2 ) private keys to be
exchanged securely in advance.
This gets quickly unpractical if n 2 and if participants regularly join
and leave the group.
P8 P1 P2 P8 P1 P2
P7 P3 P7 TTP P3
P6 P5 P4 P6 P5 P4
144 / 230
Trusted third party – key distribution centre
Needham–Schroeder protocol
Communal trusted server S shares key KP S with each participant P .
1 A informs S that it wants to communicate with B.
2 S generates KAB and replies to A with
EncKAS (B, KAB , EncKBS (A, KAB ))
Enc is a symmetric authenticated-encryption scheme
S 1
2
B A
3
145 / 230
Kerberos
An extension of the Needham–Schroeder protocol is now widely used in
corporate computer networks between desktop computers and servers, in
the form of Kerberos and Microsoft’s Active Directory. KAS is generated
from A’s password (hash function).
Extensions include:
I timestamps and nonces to prevent replay attacks
I a “ticket-granting ticket” is issued and cached at the start of a
session, replacing the password for a limited time, allowing the
password to be instantly wiped from memory again.
I a pre-authentication step ensures that S does not reply with
anything encrypted under KAS unless the sender has demonstrated
knowledge of KAS , to hinder offline password guessing.
I mechanisms for forwarding and renewing tickets
I support for a federation of administrative domains (“realms”)
Problem: ticket message enables eavesdropper off-line dictionary attack.
146 / 230
Key distribution problem: other options
Alternative 2: hardware security modules + conditional access
1 A trusted third party generates a global key K and embeds it
securely in tamper-resistant hardware tokens (e.g., smartcard)
2 Every participant receives such a token, which also knows the
identity of its owner and that of any groups they might belong to.
3 Each token offers its holder authenticated encryption operations
EncK (·) and DecK (A, ·).
4 Each encrypted message EncK (A, M ) contains the name of the
intended recipient A (or the name of a group to which A belongs).
5 A’s smartcard will only decrypt messages addressed this way to A.
Commonly used for “broadcast encryption”, e.g. pay-TV, navigation satellites.
147 / 230
Key distribution problem: other options
Alternative 2: hardware security modules + conditional access
1 A trusted third party generates a global key K and embeds it
securely in tamper-resistant hardware tokens (e.g., smartcard)
2 Every participant receives such a token, which also knows the
identity of its owner and that of any groups they might belong to.
3 Each token offers its holder authenticated encryption operations
EncK (·) and DecK (A, ·).
4 Each encrypted message EncK (A, M ) contains the name of the
intended recipient A (or the name of a group to which A belongs).
5 A’s smartcard will only decrypt messages addressed this way to A.
Commonly used for “broadcast encryption”, e.g. pay-TV, navigation satellites.
In some practical schemes, the condition DecSK (EncPK (M )) = M may fail with negligible
probability.
148 / 230
Security against chosen-plaintext attacks (CPA)
Public-key encryption scheme Π = (Gen, Enc, Dec)
1` (PK , SK ) ← Gen(1` ) PK 1`
b ∈R {0, 1}
M0 , M 1 A
C ← EncPK (Mb )
b challenger C adversary b0
Setup:
1 The challenger generates a bit b ∈R {0, 1} and a key pair
(PK , SK ) ← Gen(1` ).
`
2 The adversary A is given input 1
Rules for the interaction:
1 The adversary A is given the public key PK
m
2 The adversary A outputs a pair of messages: M0 , M1 ∈ {0, 1} .
3 The challenger computes C ← EncPK (Mb ) and returns C to A
152 / 230
Number theory: integers, divisibility, primes, gcd
Set of integers: Z := {. . . , −2, −1, 0, 1, 2, . . .} a, b ∈ Z
If there exists c ∈ Z such that ac = b, we say “a divides b” or “a | b”.
I if 0 < a then a is a “divisor” of b
I if 1 < a < b then a is a “factor” of b
I if a does not divide b, we write “a - b”
153 / 230
Number theory: integers, divisibility, primes, gcd
Set of integers: Z := {. . . , −2, −1, 0, 1, 2, . . .} a, b ∈ Z
If there exists c ∈ Z such that ac = b, we say “a divides b” or “a | b”.
I if 0 < a then a is a “divisor” of b
I if 1 < a < b then a is a “factor” of b
I if a does not divide b, we write “a - b”
If integer p > 1 has no factors (only 1 and p as divisors), it is “prime”,
otherwise it is “composite”. Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, . . .
I every integer n > 1 has a unique prime factorization n = i pei i ,
Q
with primes pi and positive integers ei
153 / 230
Number theory: integers, divisibility, primes, gcd
Set of integers: Z := {. . . , −2, −1, 0, 1, 2, . . .} a, b ∈ Z
If there exists c ∈ Z such that ac = b, we say “a divides b” or “a | b”.
I if 0 < a then a is a “divisor” of b
I if 1 < a < b then a is a “factor” of b
I if a does not divide b, we write “a - b”
If integer p > 1 has no factors (only 1 and p as divisors), it is “prime”,
otherwise it is “composite”. Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, . . .
I every integer n > 1 has a unique prime factorization n = i pei i ,
Q
with primes pi and positive integers ei
The greatest common divisor gcd(a, b) is the largest c with c | a and c | b.
I examples: gcd(18, 12) = 6, gcd(15, 9) = 3, gcd(15, 8) = 1
I if gcd(a, b) = 1 we say a and b are “relatively prime”
I gcd(a, b) = gcd(b, a), gcd(a, 0) = a
I gcd(a, b) = gcd(a, b − a)
I if c|ab and gcd(a, c) = 1 then c|b
I if a|n and b|n and gcd(a, b) = 1 then ab|n
153 / 230
Integer division with remainder
For every integer a and positive integer b there exist unique integers q
and r with a = qb + r and 0 ≤ r < b.
The modulo operator performs integer division and outputs the
remainder:
a mod b = r ⇒ 0 ≤ r < b ∧ ∃q ∈ Z : a − qb = r
154 / 230
Integer division with remainder
For every integer a and positive integer b there exist unique integers q
and r with a = qb + r and 0 ≤ r < b.
The modulo operator performs integer division and outputs the
remainder:
a mod b = r ⇒ 0 ≤ r < b ∧ ∃q ∈ Z : a − qb = r
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 21 mod 15)
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 6)
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 6) = gcd(6, 15 mod 6)
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 6) = gcd(6, 3)
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 6) = gcd(6, 3) = 3
156 / 230
Euclid’s algorithm
gcd(21, 15) = gcd(15, 6) = gcd(6, 3) = 3 = −2 × 21 + 3 × 15
156 / 230
Euclid’s algorithm
157 / 230
Euclid’s algorithm
For all positive integers a, b, there exist integers x and y such that
gcd(a, b) = ax + by.
157 / 230
Euclid’s algorithm
For all positive integers a, b, there exist integers x and y such that
gcd(a, b) = ax + by.
Euclid’s extended algorithm also provides x and y: (WLOG a ≥ b > 0)
(gcd(a, b), x, y) :=
(b, 0, 1), if b | a
(d, y, x − yq), otherwise,
egcd(a, b) =
with (d, x, y) := egcd(b, r),
where a = qb + r, 0 ≤ r < b
157 / 230
Groups
A group (G, •) is a set G and an operator • : G × G → G that have
closure: a • b ∈ G for all a, b ∈ G
associativity: a • (b • c) = (a • b) • c for all a, b, c ∈ G
neutral element: there exists an e ∈ G such that for all a ∈ G:
a•e=e•a=a
inverse element: for each a ∈ G there exists some b ∈ G such that
a•b=b•a=e
158 / 230
Groups
A group (G, •) is a set G and an operator • : G × G → G that have
closure: a • b ∈ G for all a, b ∈ G
associativity: a • (b • c) = (a • b) • c for all a, b, c ∈ G
neutral element: there exists an e ∈ G such that for all a ∈ G:
a•e=e•a=a
inverse element: for each a ∈ G there exists some b ∈ G such that
a•b=b•a=e
If a • b = b • a for all a, b ∈ G, the group is called commutative (or abelian).
158 / 230
Groups
A group (G, •) is a set G and an operator • : G × G → G that have
closure: a • b ∈ G for all a, b ∈ G
associativity: a • (b • c) = (a • b) • c for all a, b, c ∈ G
neutral element: there exists an e ∈ G such that for all a ∈ G:
a•e=e•a=a
inverse element: for each a ∈ G there exists some b ∈ G such that
a•b=b•a=e
If a • b = b • a for all a, b ∈ G, the group is called commutative (or abelian).
Examples of abelian groups:
I (Z, +), (R, +), (R \ {0}, ·)
I (Zn , +) – set of integers modulo n with addition a + b := (a + b) mod n
I ({0, 1}n , ⊕) where a1 a2 . . . an ⊕ b1 b2 . . . bn = c1 c2 . . . cn with
(ai + bi ) mod 2 = ci (for all 1 ≤ i ≤ n, ai , bi , ci ∈ {0, 1}) “bit-wise XOR”
158 / 230
Groups
A group (G, •) is a set G and an operator • : G × G → G that have
closure: a • b ∈ G for all a, b ∈ G
associativity: a • (b • c) = (a • b) • c for all a, b, c ∈ G
neutral element: there exists an e ∈ G such that for all a ∈ G:
a•e=e•a=a
inverse element: for each a ∈ G there exists some b ∈ G such that
a•b=b•a=e
If a • b = b • a for all a, b ∈ G, the group is called commutative (or abelian).
Examples of abelian groups:
I (Z, +), (R, +), (R \ {0}, ·)
I (Zn , +) – set of integers modulo n with addition a + b := (a + b) mod n
I ({0, 1}n , ⊕) where a1 a2 . . . an ⊕ b1 b2 . . . bn = c1 c2 . . . cn with
(ai + bi ) mod 2 = ci (for all 1 ≤ i ≤ n, ai , bi , ci ∈ {0, 1}) “bit-wise XOR”
159 / 230
Permutations and groups
Permutation groups
A set P of permutations over a finite set S forms a group under
concatenation if
I closure: for any pair of permutations g, h : S ↔ S in P their
concatenation g ◦ h : x 7→ g(h(x)) is also in P .
I neutral element: the identity function x 7→ x is in P
I inverse element: for each permutation g ∈ P , the inverse
permutation g −1 is also in P .
Note that function composition is associative: f ◦ (g ◦ h) = (f ◦ g) ◦ h
The set of all permutations of a set S forms a permutation group called the “symmetric group” on
S. Non-trivial symmetric groups (|S| > 1) are not abelian.
159 / 230
Permutations and groups
Permutation groups
A set P of permutations over a finite set S forms a group under
concatenation if
I closure: for any pair of permutations g, h : S ↔ S in P their
concatenation g ◦ h : x 7→ g(h(x)) is also in P .
I neutral element: the identity function x 7→ x is in P
I inverse element: for each permutation g ∈ P , the inverse
permutation g −1 is also in P .
Note that function composition is associative: f ◦ (g ◦ h) = (f ◦ g) ◦ h
The set of all permutations of a set S forms a permutation group called the “symmetric group” on
S. Non-trivial symmetric groups (|S| > 1) are not abelian.
160 / 230
Subgroups
(H, •) is a subgroup of (G, •) if
I H is a subset of G (H ⊂ G)
I the operator • on H is the same as on G
I (H, •) is a group, that is
• for all a, b ∈ H we have a • b ∈ H
• each element of H has an inverse element in H
• the neutral element of (G, •) is also in H.
Examples of subgroups
I (nZ, +) with nZ := {ni|i ∈ Z} = {. . . , −2n, −n, 0, n, 2n, . . .}
– the set of integer multiples of n is a subgroup of (Z, +)
I (R+ , ·) – the set of positive real numbers is a subgroup of (R \ {0}, ·)
I (Q, +) is a subgroup of (R, +), which is a subgroup of (C, +)
I (Q \ {0}, ·) is a subgroup of (R \ {0}, ·), etc.
I ({0, 2, 4, 6}, +) is a subgroup of (Z8 , +)
160 / 230
Notations used with groups
When the definition of the group operator is clear from the context, it is
often customary to use the symbols of the normal arithmetic addition or
multiplication operators (“+”, “×”, “·”, “ab”) for the group operation.
There are two commonly used alternative notations:
“Additive” group: think of group operator as a kind of “+”
I write 0 for the neutral element and −g for the inverse of g ∈ G.
I write g · i := g • g • · · · • g (g ∈ G, i ∈ Z)
| {z }
i times
161 / 230
Rings
A ring (R, , ) is a set R and two operators : R × R → R and
: R × R → R such that
I (R, ) is an abelian group
I (R, ) is a monoid
I a (b c) = (a b) (a c) and (a b) c = (a c) (b c)
(distributive law)
162 / 230
Rings
A ring (R, , ) is a set R and two operators : R × R → R and
: R × R → R such that
I (R, ) is an abelian group
I (R, ) is a monoid
I a (b c) = (a b) (a c) and (a b) c = (a c) (b c)
(distributive law)
If also a b = b a, then we have a commutative ring.
162 / 230
Rings
A ring (R, , ) is a set R and two operators : R × R → R and
: R × R → R such that
I (R, ) is an abelian group
I (R, ) is a monoid
I a (b c) = (a b) (a c) and (a b) c = (a c) (b c)
(distributive law)
If also a b = b a, then we have a commutative ring.
Examples for rings:
I (Z[x], +, ·), where
( )
n
X
i
Z[x] := ai x ai ∈ Z, n ≥ 0
i=0
162 / 230
Rings
A ring (R, , ) is a set R and two operators : R × R → R and
: R × R → R such that
I (R, ) is an abelian group
I (R, ) is a monoid
I a (b c) = (a b) (a c) and (a b) c = (a c) (b c)
(distributive law)
If also a b = b a, then we have a commutative ring.
Examples for rings:
I (Z[x], +, ·), where
( )
n
X
i
Z[x] := ai x ai ∈ Z, n ≥ 0
i=0
162 / 230
Rings
A ring (R, , ) is a set R and two operators : R × R → R and
: R × R → R such that
I (R, ) is an abelian group
I (R, ) is a monoid
I a (b c) = (a b) (a c) and (a b) c = (a c) (b c)
(distributive law)
If also a b = b a, then we have a commutative ring.
Examples for rings:
I (Z[x], +, ·), where
( )
n
X
i
Z[x] := ai x ai ∈ Z, n ≥ 0
i=0
c7 x7 + · · · + c2 x2 + c1 x + c0 ci ∈ {0, 1}
Example operations:
I (x7 + x5 + x + 1) ⊕ (x7 + x6 + 1) = x6 + x5 + x
or equivalently 1010 0011 ⊕ 1100 0001 = 0110 0010
I (x6 + x4 + 1) ⊗T (x2 + 1) = [(x6 + x4 + 1)(x2 + 1)] mod T (x) =
(x8 + x4 + x2 + 1) mod (x8 + x4 + x3 + x + 1) =
(x8 + x4 + x2 + 1) (x8 + x4 + x3 + x + 1) = x3 + x2 + x
or equivalently
0101 0001 ⊗T 0000 0101 = 1 0001 0101 ⊕ 1 0001 1011 = 0000 1110
168 / 230
Multiplication and modular reduction in F2n
n−1
X n−1
X
Let a(x) = ai xi and b(x) = bi xi with ai , bi ∈ Z2
i=0 i=0
be polynomials of degree less than n that represent elements of F2n .
Let f (x) = xn + r(n) be the irreducible modulus.
n−1
X
Algorithm for calculating c(x) = [a(x) · b(x)] mod f (x) = ci xi :
i=0
then
n−1
X
[a(x)]2 = ai x2i .
i=0
170 / 230
Finite groups
Let (G, •) be a group with a finite number of elements |G|.
Practical examples here: (Zn , +), (Z∗
n , ·), (F2n , ⊕), (F2n \ {0}, ⊗)
Terminology:
Related notion: the characteristic of
I The order of a group G is its size |G| a ring or field is the order of 1 in its
additive group, i.e. the smallest i
I order of group element g in G is with 1 + 1 + · · · + 1 = 0.
ordG (g) = min{i > 0 | g i = 1}.
| {z }
i times
3 Let i = ord(g).
“⇐”: x ≡ y (mod i) ⇔ x mod i = y mod i ⇒ g x = g x mod i = g y mod i = g y .
“⇒”: Say g x = g y , then 1 = g x−y = g (x−y) mod i . Since (x − y) mod i < i, but i is the
smallest positive integer with g i = 1, we must have (x − y) mod i = 0. ⇒ x ≡ y (mod i).
hgi := {g 0 , g 1 , g 2 , . . .}
Definitions:
I We call g a generator of G if hgi = G.
I We call G cyclic if it has a generator.
Useful facts:
1 Every cyclic group of order m is isomorphic to (Zm , +). (g i ↔ i)
2 hgi is a subgroup of G (subset, a group under the same operator)
3 If |G| is prime, then G is cyclic and all g ∈ G \ {1} are generators.
Recall that ord(g) | |G|. We have ord(g) ∈ {1, |G|} if |G| is prime, which makes g either 1
or a generator.
Katz/Lindell (2nd ed.), section 8.3
173 / 230
How to find a generator?
174 / 230
(Zp , +) is a cyclic group
For every prime p every element g ∈ Zp \ {0} is a generator:
Zp = hgi = {g · i mod p | 0 ≤ i ≤ p − 1}
Note that this follows from fact 3 on slide 173: Zp is of order p, which is prime.
Example in Z7 :
(0 · 0, 0 · 1, 0 · 2, 0 · 3, 0 · 4, 0 · 5, 0 · 6, 0 · 7, . . .) = (0, 0, 0, 0, 0, 0, 0, 0, . . .)
(1 · 0, 1 · 1, 1 · 2, 1 · 3, 1 · 4, 1 · 5, 1 · 6, 0 · 7, . . .) = (0, 1, 2, 3, 4, 5, 6, 0, . . .)
(2 · 0, 2 · 1, 2 · 2, 2 · 3, 2 · 4, 2 · 5, 2 · 6, 0 · 7, . . .) = (0, 2, 4, 6, 1, 3, 5, 0, . . .)
(3 · 0, 3 · 1, 3 · 2, 3 · 3, 3 · 4, 3 · 5, 3 · 6, 0 · 7, . . .) = (0, 3, 6, 2, 5, 1, 4, 0, . . .)
(4 · 0, 4 · 1, 4 · 2, 4 · 3, 4 · 4, 4 · 5, 4 · 6, 0 · 7, . . .) = (0, 4, 1, 5, 2, 6, 3, 0, . . .)
(5 · 0, 5 · 1, 5 · 2, 5 · 3, 5 · 4, 5 · 5, 5 · 6, 0 · 7, . . .) = (0, 5, 3, 1, 6, 4, 2, 0, . . .)
(6 · 0, 6 · 1, 6 · 2, 6 · 3, 6 · 4, 6 · 5, 6 · 6, 0 · 7, . . .) = (0, 6, 5, 4, 3, 2, 1, 0, . . .)
I All the non-zero elements of group Z7 with addition mod 7 are generators
I ord(0) = 1, ord(1) = ord(2) = ord(3) = ord(4) = ord(5) = ord(6) = 7
175 / 230
(Z∗p , ·) is a cyclic group
For every prime p there exists a generator g ∈ Z∗p such that
Z∗p = {g i mod p | 0 ≤ i ≤ p − 2}
Note that this does not follow from fact 3 on slide 173: Z∗
p is of order p − 1, which is even (for
p > 3), not prime.
Example in Z∗7 :
(10 , 11 , 12 , 13 , 14 , 15 , 16 , . . .) = (1, 1, 1, 1, 1, 1, 1, . . .)
(20 , 21 , 22 , 23 , 24 , 25 , 26 , . . .) = (1, 2, 4, 1, 2, 4, 1, . . .)
(30 , 31 , 32 , 33 , 34 , 35 , 36 , . . .) = (1, 3, 2, 6, 4, 5, 1, . . .)
(40 , 41 , 42 , 43 , 44 , 45 , 46 , . . .) = (1, 4, 2, 1, 4, 2, 1, . . .)
(50 , 51 , 52 , 53 , 54 , 55 , 56 , . . .) = (1, 5, 4, 6, 2, 3, 1, . . .)
(60 , 61 , 62 , 63 , 64 , 65 , 66 , . . .) = (1, 6, 1, 6, 1, 6, 1, . . .)
Fast generator test (p. 174), using |Z∗
7 | = 6 = 2·3:
I 3 and 5 are generators of Z∗7 36/2 = 6, 36/3 = 2, 56/2 = 6, 56/3 = 4, all 6= 1.
I 1, 2, 4, 6 generate subgroups of Z∗7 : {1}, {1, 2, 4}, {1, 2, 4}, {1, 6}
I ord(1) = 1, ord(2) = 3, The order of g in Z∗p is the size of the subgroup hgi.
∗
ord(3) = 6, ord(4) = 3, Lagrange’s theorem: ordZ∗p (g) | p − 1 for all g ∈ Zp
ord(5) = 6, ord(6) = 2
176 / 230
Fermat’s and Euler’s theorem
Fermat’s little theorem: (1640)
p prime and gcd(a, p) = 1 ⇒ ap−1 mod p = 1
Recall from Lagrange’s theorem: for a ∈ Z∗ ∗
p , ord(a)|(p − 1) since |Zp | = p − 1.
178 / 230
Chinese remainder theorem
Definition: Let (G, •) and (H, ◦) be two groups. A function f : G → H
is an isomorphism from G to H if
I f is a 1-to-1 mapping (bijection)
I f (g1 • g2 ) = f (g1 ) ◦ f (g2 ) for all g1 , g2 ∈ G
178 / 230
Chinese remainder theorem
Definition: Let (G, •) and (H, ◦) be two groups. A function f : G → H
is an isomorphism from G to H if
I f is a 1-to-1 mapping (bijection)
I f (g1 • g2 ) = f (g1 ) ◦ f (g2 ) for all g1 , g2 ∈ G
y = x2 = (−x)2
1 2 3 4 5 6
Example in Z∗7 :
(12 , 22 , 32 , 42 , 52 , 62 ) = (1, 4, 2, 2, 4, 1) 1 2 3 4 5 6
Euler’s criterion:
Square-and-multiply algorithm:
n
X
ei · 2 i ,
e
Binary representation: e = n = blog2 ec, ei = 2i mod 2
i=0
Computation:
RtoL square and mult(g, e):
a := g
0 i
i−1 2 b := 1
g 2 := g, g 2 := g 2 for i := 0 to n do
n ei if be/2i c mod 2 = 1 then
Y i
g e := g2 b := b • a ← multiply
i=0 a := a • a ← square
return b
182 / 230
Safer square-and-multiply algorithms
Basic square-and-multiply algorithms are vulnerable to side-channel
attacks (e.g., power-line or electromagnetic analysis of unintended
microcontroller signal emissions). If an eavesdropper can recognize the
function-call sequence
square, multiply, square, square, square, multiply, square, multiply, . . .
then that suggests for LtoR square and mult: e = 10011 . . ..
There are often faster algorithms for squaring then just multiplying a group element with itself.
184 / 230
Discrete logarithm problem
Let (G, •) be a given cyclic group of order q = |G| with given generator g
(G = {g 0 , g 1 , . . . , g q−1 }). The “discrete logarithm problem (DLP)” is
finding for a given y ∈ G the number x ∈ Zq such that
gx = g • g • · · · • g = y
| {z }
x times
186 / 230
Diffie–Hellman problems
Let (G, •) be a cyclic group of order q = |G| with generator g
(G = {g 0 , g 1 , . . . , g q−1 }). Given elements h1 , h2 ∈ G , define
DH(h1 , h2 ) := g logg h1 ·logg h2
that is if g x1 = h1 and g x2 = h2 , then DH(h1 , h2 ) = g x1 ·x2 = hx1 2 = hx2 1 .
These two problems are related to the discrete logarithm problem:
I Computational Diffie–Hellman (CDH) problem: the adversary is
given uniformly chosen h1 , h2 ∈ G and has to output DH(h1 , h2 ).
The problem is hard if for all PPT A we have P(A(G, q, g, g x , g y ) = g xy ) ≤ negl(`).
A→B: gx
B→A: gy
W. Diffie, M.E. Hellman: New Directions in Cryptography. IEEE IT-22(6), 1976-11, pp 644–654.
188 / 230
Discrete logarithm algorithms
Several generic algorithms are known for solving the discrete logarithm
problem for any cyclic group G of order q:
I Trivial brute-force algorithm: try all g i , time |hgi| = ord(g) ≤ q.
I Pohlig–Hellman algorithm: if q is not prime, and has a known (or
easy to determine) factorization, then this algorithm reduces the
discrete-logarithm problem for G to discrete-logarithm problems for
prime-order subgroups of G.
⇒ the difficulty of finding the discrete logarithm in a group of order
q is no greater than that of finding it in a group of order q 0 , where q 0
is the largest prime factor dividing q.
I Shank’s baby-step/giant-step algorithm: requires
√ √
O( q · polylog(q)) time and O( q) memory.
I Pollard’s rho algorithm: requires O(√q · polylog(q)) time and
O(1) memory.
⇒ choose G to have a prime order q, and make q large enough such
√
that no adversary can be expected to execute q steps (e.g. q 2200 ).
189 / 230
Baby-step/giant-step algorithm
Given generator g ∈ G (|G| = q) and y ∈ G, find x ∈ Zq with g x = y.
I Powers of g form a cycle 1 = g 0 , g 1 , g 2 , . . . , g q−2 , g q−1 , g q = 1, and
y = g x sits on this cycle.
I Go around cycle in “giant steps” of n = b√qc:
g 0 , g n , g 2n , . . . , g dq/nen
y · g1 , y · g2 , . . . , y · gn
Advantages:
I Select bit-length of p and q independently, based on respective
security requirements (e.g. 128-bit security: 3072-bit p, 256-bit q)
Difficulty of Discrete Logarithm problem over G ⊆ Z∗
p with order q = |G| depends on both
p (subexponentially) and q (exponentially).
I Some operations faster than if log2 q ≈ log2 p.
Square-and-multiply exponentiation g x mod p (with x < q) run-time ∼ log2 x < log2 q.
I Prime order q has several advantages:
• simple choice of generator (pick any element 6= 1)
• G has no (non-trivial) subgroups ⇒ no small subgroup confinement
attacks
• q with small prime factors can make Decision Diffie–Hellman
problem easy to solve (Exercise 28)
Compare with slide 181 where r = 2.
192 / 230
Schnorr groups (proofs)
Let p = rq + 1 with p, q prime and G = {hr mod p|h ∈ Z∗p }. Then
∗
1 G is a subgroup of Zp .
Proof: G is closed under multiplication, as for all x, y ∈ G we have
xr y r mod p = (xy)r mod p = (xy mod p)r mod p ∈ G as (xy mod p) ∈ Z∗p.
In addition, G includes the neutral element 1r = 1
For each hr , it also includes the inverse element (h−1 )r mod p.
∗ q
4 h ∈ G ⇔ h ∈ Zp ∧ h mod p = 1. (Useful security check!)
Proof: Let h = g i with hgi = Z∗
p and 0 ≤ i < p − 1. Then
hq mod p = 1 ⇔ g iq mod p = 1 ⇔ iq mod (p − 1) = 0 ⇔ rq|iq ⇔ r|i.
Katz/Lindell (2nd ed.), section 8.3.3
193 / 230
Elliptic curves – the Weierstrass equation
An elliptic curve E over a field K is defined by the Weierstrass equation
y 2 + a1 xy + a3 y = x3 + a2 x2 + a4 x + a6
Elliptic curves were originally studied over the fields C, R, and Q, in the
context of elliptic integrals. In cryptography, they are used instead over
finite fields, in particular K = L = Zp as well as K = L = F2n .
194 / 230
Elliptic curves – simplified Weierstrass equations
An elliptic curve defined over a field K by the Weierstrass equation
y 2 + a1 xy + a3 y = x3 + a2 x2 + a4 x + a6
y 2 = x3 + ax + b
y 2 + xy = x3 + ax2 + b
with discriminant ∆ = b 6= 0.
I If a1 = 0 then
(x, y) 7→ (x + a2 , y)
leads to the “supersingular” curve
y 2 + cy = x3 + ax + b
with a, b, c ∈ K and ∆ = c4 6= 0.
Similar tricks exist for K with characteristic 3, but such K are not commonly used in cryptography.
196 / 230
Elliptic-curve group operation
2
10
8
1
7
P2
6
0 5 P1
P1 4
3
-1
2
0 P2
-2
-2 -1 0 1 2 0 1 2 3 4 5 6 7 8 9 10
9
P3
8
1
7
P2
6
0 5 P1
P1 4
3
-1
2
1
P1 +P 2 3
0 P2
-2
-2 -1 0 1 2 0 1 2 3 4 5 6 7 8 9 10
0 5 P1
P1 4
3
-1
2
1 P1 +P 2 3
P1 +P 2 3
0 P2
-2
-2 -1 0 1 2 0 1 2 3 4 5 6 7 8 9 10
Note: p = 2256 − 2224 + 2192 + 296 − 1 and q ≈ 2256 − 2224 + 2192 here are generalized resp. pseudo
Mersenne primes, for fast mod calculation on 32-bit CPUs and good use of the 256-bit space.
202 / 230
Commonly used standard curves
NIST FIPS 186-4 has standardized five such elliptic curves over integer field
(Zp ) coordinates: P-192, P-224, P-256, P-384, P-521.
Also: five random curves of the form y 2 + xy = x3 + x2 + b over binary field
(F2n ) coordinates: B-163, B-233, B-283, B-409, B-571. The number of
points on these curves is twice the order of the base point G (“cofactor 2”).
And there are five Koblitz curves of the form y 2 + xy = x3 + ax2 + 1
(a ∈ {0, 1}, with cofactors 4 or 2, resp.), also over F2n :
K-163, K-233, K-283, K-409, K-571. (Koblitz: a, b ∈ {0, 1} ⇒ faster.)
Some mistrust the NIST parameters for potentially having been carefully selected by the NSA, to
embed a vulnerability. http://safecurves.cr.yp.to/rigid.html
Brainpool (RFC 5639): seven similar curves over Zp , chosen by the German government.
The Standards for Efficient Cryptography Group SEC 2 specification lists eight curves over Zp
(secp{192,224,256}{k,r}1, secp{384,521}r1) and 12 over F2n (sect163k1,. . . ,sect571r1).
(Vers. 2.0 dropped smaller secp{112,128,160}r{1,2}, secp160k1 and sect{113,131}r{1,2}.)
The numbers indicate the bit length of one coordinate, i.e. roughly twice the
equivalent symmetric-key strength.
ANSI X9.62 (and SEC 1) define a compact binary syntax for curve points.
Curve25519 was proposed by Daniel J. Bernstein in 2005 and has since
become a highly popular P-256 alternative due to faster implementation, better
resiliency against some implementation vulnerabilities (e.g., timing attacks),
lack of patents and worries about NSA backdoors.
203 / 230
ElGamal encryption scheme
The DH key exchange requires two messages. This can be eliminated if
everyone publishes their g x as a public key in a sort of phonebook.
Assume ((G, ·), q, g) are fixed for all participants.
A chooses secret key x ∈ Z∗q and publishes g x ∈ G as her public key.
B generates for each message a new nonce y ∈ Z∗q and then sends
B→A: g y , (g x )y · M
where M ∈ G is the message that B sends to A in this asymmetric
encryption scheme. Then A calculates
[(g x )y · M ] · [(g y )q−x ] = M
to decrypt M .
In practice, this scheme is rarely used because of the difficulty of fitting
M into G. Instead, B only sends g y . Then both parties calculate
K = h(g xy ) and use that as the private session key for an efficient
blockcipher-based authenticated encryption scheme that protects the
confidentiality and integrity of the bulk of the message M:
B→A: g y , EncK (M )
204 / 230
Number theory: easy and difficult problems
Easy:
I given integer n, i and x ∈ Z∗n : calculate x−1 ∈ Z∗n or xi ∈ Z∗n
I given prime p and polynomial f (x) ∈ Zp [x]:
find x ∈ Zp with f (x) = 0
runtime grows linearly with the degree of the polynomial
Difficult:
I given safe prime p, generator g ∈ Z∗p (or large subgroup):
• given value a ∈ Z∗p : find x such that a = g x .
→ Discrete Logarithm Problem
• given values g x , g y ∈ Z∗p : find g xy .
→ Computational Diffie–Hellman Problem
• given values g x , g y , z ∈ Z∗p : tell whether z = g xy .
→ Decision Diffie–Hellman Problem
I given a random n = p · q, where p and q are `-bit primes (` ≥ 1024):
• find integers p and q such that n = p · q in N
→ Factoring Problem
• given a polynomial f (x) of degree > 1:
find x ∈ Zn such that f (x) = 0 in Zn
205 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
206 / 230
“Textbook” RSA encryption
Key generation
I Choose random prime numbers p and q (each ≈ 1024 bits long)
I n := pq (≈ 2048 bits = key length) ϕ(n) = (p − 1)(q − 1)
I pick integer values e, d such that: ed mod ϕ(n) = 1
I public key PK := (n, e)
I secret key SK := (n, d)
Encryption
I input plaintext M ∈ Z∗n , public key (n, e)
I C := M e mod n
Decryption
I input ciphertext C ∈ Z∗n , secret key (n, d)
I M := C d mod n
In Zn : (M e )d = M ed = M ed mod ϕ(n) = M 1 = M .
Common implementation tricks to speed up computation:
I Choose small e with low Hamming weight (e.g., 3, 17, 216 + 1) for faster modular encryption
I Preserve factors of n in SK = (p, q, d), decryption in both Zp and Zq , use Chinese
remainder theorem to recover result in Zn .
207 / 230
“Textbook” RSA is not secure
There are significant security problems with a naive application of the
basic “textbook” RSA encryption function C := P e mod n:
x challenger adversary x0
The trapdoor permutation is only used to communicate a “session key” h(x), the actual message
is protected by a symmetric authenticated encryption scheme. The adversary A in the PubKcca
A,Π0
game has no influence over the input of F .
PKCS #1 v2.0
212 / 230
Practical pitfalls with implementing RSA
213 / 230
1 Historic ciphers
2 Perfect secrecy
3 Semantic security
4 Block ciphers
5 Modes of operation
6 Message authenticity
7 Authenticated encryption
8 Secure hash functions
9 Secure hash applications
10 Key distribution problem
11 Number theory and group theory
12 Discrete logarithm problem
13 RSA trapdoor permutation
14 Digital signatures
214 / 230
One-time signatures
215 / 230
RSA signatures
Basic idea: n = pq, ed ≡ 1 (mod φ(n)), PK = (e, n), SK = (d, n)
S = SignSK (M ) := M d mod n
?
VrfyPK (M, S) := (S e mod n = M )
216 / 230
Schnorr identification scheme
Cyclic group G of prime order q with generator g, DLOG hard
Secret key: x ∈R Z∗q , public key: y = g x
Prover P picks k ∈R Z∗q , Verifier V picks r ∈R Z∗q
P →V : I := g k
V →P : r
P →V : s := rx + k mod q
Verifier checks
?
g s · y −r = I
Works because:
g s · y −r = g rx+k · (g x )−r = g rx+k−rx = g k = I
As secure as DLOG: an attacker who can find s1 , s2 for two challenges
r1 , r2 with same I could also calculate any discrete logarithm:
g s1 · y −r1 = I = g s2 · y −r2
g s1 −s2 = y r1 −r2 = g x(r1 −r2 )
logg y = (s1 − s2 )(r1 − r2 )−1 mod q
217 / 230
Digital Signature Algorithm (DSA)
Let (G, q, g) be system-wide choices of a cyclic group G of order q with
generator g. In addition, we need two functions H : {0, 1}∗ → Zq and
F : G → Zq where H must be collision resistant.
Both H and F are random oracles in security proofs, but common F not even preimage resistant.
Key generation: uniform secret key x ∈ Zq , then public key y := g x ∈ G.
Signing: On input of a secret key x ∈ Zq and a message m ∈ {0, 1}∗ , first
choose (for each message!) uniformly at random k ∈ Z∗q and set r := F (g k ).
Then solve the linear equation
k · s − x · r ≡ H(m) (mod q) (1)
for s := k−1 · (H(m) + xr) mod q. If r = 0 or s = 0, restart with a fresh k,
otherwise output Signx (m) ← (r, s).
Verification: On input of public key y, message m, and signature (r, s), verify
equation (1) after both sides have been turned into exponents of g:
g ks /g xr = g H(m) (2)
k s H(m) r
(g ) = g y (3)
−1 −1
g k = g H(m)s y rs (4)
? H(m)s−1 rs−1
=⇒ actually verify: r=F g y (5)
218 / 230
DSA variants
ElGamal signature scheme
The DSA idea was originally proposed by ElGamal with G = Z∗p ,
ord(g) = q = p − 1 and F (x) = x.
Unless the p and g are chosen more carefully, ElGamal signatures can be vulnerable to forgery:
D. Bleichenbacher: Generating ElGamal signatures without knowing the secret key.
EUROCRYPT ’96. http://www.springerlink.com/link.asp?id=xbwmv0b564gwlq7a
NIST DSA
In 1993, the US government standardized the Digital Signature
Algorithm, a modification of the ElGamal signature scheme where
I G is a prime-order subgroup of Z∗p
I prime number p (1024 bits), prime number q (160 bits) divides p − 1
I g = h(p−1)/q mod p, with 1 < h < p − 1 so that g > 1 (e.g., h = 2)
I H is SHA-1
I F (x) = x mod q
Generate key: random 0 < x < q, y := g x mod p.
Signature (r, s) := Signx (m): random 0 < k < q,
r := (g k mod p) mod q, s := (k −1 (H(m) + x · r)) mod q
Later versions of the DSA standard FIPS 186 added larger values for (p, q, g), as well as ECDSA,
where G is one of several elliptic-curve groups over Zp or F2n and F ((x, y)) = x mod q.
219 / 230
Elliptic-Curve Digital Signature Algorithm (ECDSA)
System-wide domain parameters:
order q of finite field Fq , a representation of Fq , curve parameters a and b, base
point P = (xP , yP ) ∈ E(Fq ), prime order n of P , cofactor h = |E(Fq )|/n.
ECDSA KeyGen: secret key d ∈R Z∗n , public key Q := dP
All that is needed for k to leak is two messages m 6= m0 signed with the
same k = k 0 (easily recognized from r = r0 = F (g k )):
s ≡ k −1 · (H(m) + xr)
s0 ≡ k −1 · (H(m0 ) + xr)
s − s0 ≡ k −1 · (H(m) − H(m0 ))
−1
k ≡ H(m) − H(m0 ) (s − s0
(mod q)
222 / 230
Public-key infrastructure I
223 / 230
Public-key infrastructure II
We can use the operator • to describe the extraction of A’s public key
PK A from a certificate CertC (A) with the certification authority public
key PK C :
PK A if certificate valid
PK C • CertC (A) =
failure otherwise
224 / 230
Public-key infrastructure III
Public keys can also be verified via several trusted intermediaries in a
certificate chain:
In today’s Transport Layer Security (TLS) practice (HTTPS, etc.), most private users use their
web-browser or operating-system vendor as their sole trusted source of PK C1 root keys.
225 / 230
Example of an X.509 certificate
$ openssl s_client -showcerts -connect www.cst.cam.ac.uk:443 >cst.crt
depth=2 C = BM, O = QuoVadis Limited, CN = QuoVadis Root CA 2 G3
depth=1 C = BM, O = QuoVadis Limited, CN = QuoVadis Global SSL ICA G3
depth=0 C = GB, ST = Cambridgeshire, L = CAMBRIDGE, O = University of Cambridge, OU = UIS, CN = www.cst.cam.ac.uk
$ openssl x509 -text -noout -in cst.crt
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
03:07:fb:5f:76:c8:1d:8f:7e:e3:5e:d6:ab:71:5d:a5:1a:c0:e6:70
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = BM, O = QuoVadis Limited, CN = QuoVadis Global SSL ICA G3
Validity
Not Before: Sep 13 15:33:05 2017 GMT
Not After : Sep 13 15:43:00 2020 GMT
Subject: C = GB, ST = Cambridgeshire, L = CAMBRIDGE, O = University of Cambridge, OU = UIS, CN = www.cst.cam.ac.uk
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (2048 bit)
Modulus:
00:c3:cb:9f:77:9d:c8:09:f1:b3:aa:f7:8f:34:e5:
8e:92:45:50:a7:35:ee:09:27:ec:b8:7c:af:07:9d:
f4:30:79:37:2e:81:ad:85:ff:f9:c4:93:ca:27:28:
a0:d1:93:27:9f:0f:b4:c8:1c:55:7b:f9:90:46:c5:
69:56:40:b5:90:d6:34:06:8f:cc:b7:e0:31:3e:2f:
d9:2f:57:13:f5:4f:7d:ef:d8:7e:16:5a:d7:72:14:
e4:0b:13:87:b2:df:2a:0f:30:f1:6d:9a:b6:0b:c8:
e0:87:0f:b5:72:a0:b9:07:2e:48:32:bb:12:dd:d3:
96:21:1c:c9:94:8f:47:1d:9a:3b:35:ec:20:45:38:
06:15:ed:4e:43:80:96:94:90:fc:25:05:88:f6:7b:
cb:27:a9:49:e4:80:20:e7:f1:f0:23:05:e8:91:77:
c3:04:2e:2e:33:ca:76:fc:00:17:a4:93:88:f4:e1:
66:ac:51:56:8d:27:91:2d:d2:5a:e7:01:83:b9:ab:
c1:94:38:54:5a:f4:e9:dc:c5:91:96:b7:17:c6:55:
bf:ea:85:41:d5:0b:d7:09:62:26:01:c9:e1:fe:b3:
57:e0:b8:f9:fc:0b:76:65:6c:43:f0:5f:30:77:38:
17:00:df:6a:27:25:1d:30:9e:19:01:e9:0c:78:cc:
c9:3d
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
X509v3 Authority Key Identifier:
keyid:B3:12:89:B5:A9:4B:35:BC:15:00:F0:80:E9:D8:78:87:F1:13:7C:76
Full Name:
URI:http://crl.quovadisglobal.com/qvsslg3.crl
$ ls -l /etc/ssl/certs/
Outlook
226 / 230
Appendix
227 / 230
Some basic discrete mathematics notation
I |A| is the number of elements (size) of the finite set A.
I A1 × A2 × · · · × An is the set of all n-tuples (a1 , a2 , . . . , an ) with
a1 ∈ A1 , a2 ∈ A2 , etc. If all the sets Ai (1 ≤ i ≤ n) are finite:
|A1 × A2 × · · · × An | = |A1 | · |A2 | · · · · · |An |.
I An is the set of all n-tuples (a1 , a2 , . . . , an ) = a1 a2 . . . an with
a1 , a2 , . . . , an ∈ A. If A is finite then |An | = |A|n .
I A≤n = ni=0 Ai and A∗ = ∞ i
S S
i=0 A
I Function f : A → B maps each element of A to an element of B:
a 7→ f (a) or b = f (a) with a ∈ A and b ∈ B.
I A function f : A1 × A2 × · · · × An → B maps each parameter tuple
to an element of B: (a1 , a2 , . . . , an ) 7→ f (a1 , a2 , . . . , an ) or
f (a1 , a2 , . . . , an ) = b.
I A permutation f : A ↔ A maps A onto itself and is invertible:
x = f −1 (f (x)). There are | Perm(A)| = |A|! = 1 · 2 · · · · · |A|
permutations over A.
I B A is the set of all functions of the form f : A → B. If A and B
are finite, there will be |B A | = |B||A| such functions.
228 / 230
Confidentiality games at a glance
1` 1`
M0 , M 1
b ∈R {0, 1}
PrivKeav K ← Gen(1` ) A
C ← EncK (Mb )
challenger C adversary
b b0
1` 1`
M01 , M02 , . . . , M0t
b ∈R {0, 1}
K ← Gen(1` ) M11 , M12 , . . . , M1t
PrivKmult A
C ← EncK (Mb )
challenger C1, C2, . . . , Ct adversary
b b0
M 1, M 2, . . . , M t
1` b ∈R {0, 1} 1`
Ct, . . . , C2, C1
K ← Gen(1` ) M0 , M1
PrivKcpa C i ← EncK (M i ) A
C ← EncK (Mb ) C 0
challenger M t+1 , . . . , M t+t adversary
b 0 b0
C t+t , . . . , C t+1
229 / 230
Integrity games at a glance
M 1, C2, . . .
1` b ∈R {0, 1} 1`
. . . , M 2, C1
K ← Gen(1` ) M0 , M1
PrivKcca C i ← EncK (M i ) A
M i ← DecK (C i ) C
M t+1 , C t+2 6= C, . . . adversary
b C ← EncK (Mb ) b0
. . . , M t+2 , C t+1
1` K ← Gen(1` ) 1`
M 1, M 2, . . . , M t
T i ← MacK (M i )
Mac-forge T t, . . . , T 2, T 1 A
b := VrfyK (M, T ) adversary
b M, T
M 6∈{M 1 ,M 2 ,...,M t }
1` K ← Gen(1` ) 1`
M 1, M 2, . . . , M t
C i ← EncK (M i )
CI Ct, . . . , C2, C1 A
(
0, DecK (C) = ⊥
b :=
b 1, DecK (C) 6= ⊥ C adversary
C6∈{C 1 ,C 2 ,...,C t }
230 / 230