summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-10-24 15:33:07 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2017-10-24 15:33:07 +0200
commit162df3190c4e179ef968b0a467ddd4951faba336 (patch)
tree3c9628cf1abf259e1b897ac14b006e2b448cff27
parent92ed41381f40c97b52b0e96f0eaeaa9025091411 (diff)
downloaduni-162df3190c4e179ef968b0a467ddd4951faba336.tar
uni-162df3190c4e179ef968b0a467ddd4951faba336.tar.gz
uni-162df3190c4e179ef968b0a467ddd4951faba336.tar.bz2
uni-162df3190c4e179ef968b0a467ddd4951faba336.tar.xz
uni-162df3190c4e179ef968b0a467ddd4951faba336.zip
Notes on cryptography
-rw-r--r--ss2017/cryptography/Notes01.txt108
-rw-r--r--ss2017/cryptography/Notes02.txt214
-rw-r--r--ss2017/cryptography/Notes03.txt100
-rw-r--r--ss2017/cryptography/Notes04.txt78
-rw-r--r--ss2017/cryptography/Notes05.txt217
-rw-r--r--ss2017/cryptography/Notes06.txt216
-rw-r--r--ss2017/cryptography/Notes06a.txt105
-rw-r--r--ss2017/cryptography/Notes07.txt204
-rw-r--r--ss2017/cryptography/Notes08.txt382
-rw-r--r--ss2017/cryptography/Notes09.txt259
-rw-r--r--ss2017/cryptography/Notes10.txt257
-rw-r--r--ss2017/cryptography/Notes11.txt310
-rw-r--r--ss2017/cryptography/Notes12.txt274
-rw-r--r--ss2017/cryptography/Notes13.txt162
-rw-r--r--ss2017/cryptography/Notes14.txt208
-rw-r--r--ss2017/cryptography/Notes15.txt279
-rw-r--r--ss2017/cryptography/Notes16.txt318
-rw-r--r--ss2017/cryptography/Notes17.txt194
18 files changed, 3885 insertions, 0 deletions
diff --git a/ss2017/cryptography/Notes01.txt b/ss2017/cryptography/Notes01.txt
new file mode 100644
index 0000000..75c4cc6
--- /dev/null
+++ b/ss2017/cryptography/Notes01.txt
@@ -0,0 +1,108 @@
1Throughout the notes the acronym KL stands for the book "Introduction
2to Modern Cryptography" by Jonathan Katz and Yehuda Lindell, Chapman &
3Hall, 2008.
4
5Set braces {} may be used to enclose a subscript consisting of more
6than one letter. E.g x_{10} is "x sub ten". Sometimes we omit the
7underscore vor subscripting and write x1 or xi for x_1 and x_i.
8
9
101 Overview, Historic Ciphers: Caesar, Vigenere, (KL1.3)
11---------------------------------------------------------
12
13
14The Shift Cipher
15- - - - - - - - -
16
17Identify the 26 upper case alphabet letters with numbers 0..25,
18e.g. A=0, B=1. Choose an integer k:{0..25} as "key" and encrypt a
19letter x as x+k mod 26. Encrypt a text as the sequence of the
20encryption of its letter. For example, if k=3 then the text
21BEGINTHEATTACKNOW is encrypted as EHJLQWKHDWWDFNQRZ. The decryption
22of a letter x is just x-k mod 26 and the decryption of a text is
23obtained by applying this procedure letterwise.
24
25The special case k=3 is known as "Caesar Cipher" since purportedly
26Julias Caesar used it to encrypt some of his letters. The special case
27k=13 is known as ROT-13.
28
29There are two simple attacks on a shift cipher. The first one uses the
30fact that there are only 26 possible keys so one can try them all
31out. This, however, requires that one can recognize the right
32plaintext, e.g. because it is correct English.
33
34The second is based on frequencies of letters. In a standard English
35text the letters occur with typical frequencies. E.g. E is the most
36frequent letter with likelihood 12.7%. Then follows T with 9.0% and A
37with 8.2% etc. Thus, we can count the relative frequencies of the
38letters in the ciphertext and thus work out the key.
39
40An improved and more systematic attack based on frequencies goes as
41follows: Let p_i stand for the frequency of letter i, e.g. p_4 = 12.7%
42since E=4. One has
43
44 sum_{i=0..25} p_i^2 =~= 0.065
45
46So, if q_i is the frequency of the letter i *in the ciphertext* then
47we expect q_{i+k} to be close to p_i so that we can recover k by
48choosing j in such a way that the following quantity I_j is as close to
490.065 as possible.
50
51 I_j := sum_{i=0..25} p_i * q_{i+j mod 26}
52
53
54
55The Vigenere Cipher
56- - - - - - - - - -
57
58The shift cipher suffers from two problems:
59
601) the number of possible keys is too small
612) the frequency distribution of letters in the plain text shows in
62 the ciphertext
63
64A famous historic cipher not suffering from the first problem is the
65Vigenere cipher. Here one selects a word or a short text as key,
66writes the key repeatedly under the plaintext and then "adds" letters
67one above another (as numbers mod 26). Here is an example with key BEADS:
68
69THEMANANDTHEWOMANRETRIEVEDTHELETTERFROMTHEPOSTOFFICE
70BEADSBEADSBEADSBEADSBEADSBEADSBEADSBEADSBEADSBEADSBE
71ULEPSOENGLIIWREBRRHLSMEYWEXHHDFXTHJGVOPLIIPRKUSFIADI
72
73Alas, the frequency distribution of the plaintext still seeps through
74and we can use this information to break the cipher without knowing
75the key:
76
77If we know the length of the key, e.g. 5, and the ciphertext is x_0
78x_1 x_2 ... then we can apply the previous frequency analysis (with
79the I_j scores) to the 5 texts
80
81x_0 x_5 x_10 ...
82x_1 x_6 x_11 ...
83...
84x_4 x_9 x_14 ...
85
86all of which are obtained by encrypting the corresponding plaintext
87fragments with a shift cipher. Therefore, their frequency spectrum
88should be a shift of the standard one and the corresponding shift,
89hence the individual letters of the key, can be retrieved.
90
91In order to get the key length we can follow a similar approach. For a
92given shift t let q_i be the relative frequency of letter i (e.g. E
93when i=4) in the sequence x_t, x_2t, x_3t. If the shift t is the
94actual key length then this subsequence will have the frequency
95spectrum as English plaintexts just shifted by t so we expect that
96
97 J_t := sum_{i=0..25} q_i^2 =~= 0.065
98
99since the summation is invariant under the any shift. If, however, the
100shift was the wrong one then we expect the letters to appear
101completely random so that in that case the above sum is rather close
102to 1/26 = 0.038. Thus, we compute J_t for t=1,2,3,... and pick the t
103for which J_t is largest (and close to 0.065).
104
105Other historic ciphers include monoalphabetic substitution (key =
106arbitrary permutation of the 26 letters), Grand Chiffre, the German
107Enigma, etc. All these historic ciphers have been broken. See
108Wikipedia and other online resources.
diff --git a/ss2017/cryptography/Notes02.txt b/ss2017/cryptography/Notes02.txt
new file mode 100644
index 0000000..59da143
--- /dev/null
+++ b/ss2017/cryptography/Notes02.txt
@@ -0,0 +1,214 @@
12 Principles of cryptography (KL1.1, KL1.2, KL1.4, KL2)
2--------------------------------------------------------
3
4These considerations and similar ones applying to other historical
5ciphers have led to the principles for the design of cryptosystems.
6
7Before stating these we describe somewhat more formally what a
8(private-key) cryptosystem is.
9
10A cryptosystem comprises three algorithms:
11
12- A key generation algorithm Gen which outputs a key according to some
13 format an probability distribution.
14
15- An encryption algorithm Enc which given plaintext m and key k
16 produces a ciphertext Enc_k(m)
17
18- A decryption algorithm Dec which given ciphertext c and key k
19 produces a plaintext Dec_k(m).
20
21The set of all keys possibly put out by the key generator Gen is
22called keyspace (K). For every key k produced by Gen it must hold
23that Dec_k(Enc_k(m)) = m. There is also a finite set of possible
24messages M and ciphertexts C. Clearly, Gen must be randomized,
25otherwise it would always return the same key. Sometimes Enc is also
26randomized, i.e. ciphertexts may contain some random information and
27do not depend functionally on plaintext and key.
28
29One of the most important design principles is Kerckhoff's rule (19th
30century): Security of the cryptosystem should rely on secrecy of the
31key not on secrecy of the method. In other words, the cryptosystem
32should remain secure if everything about the three algorithms involved
33is publicly known. "No security through obscurity".
34
35In addition to this, the cryptosystem should withstand some or all of
36the following kinds of attack:
37
38Ciphertext only attack: an eavesdropper observes ciphertext and aims
39at determining the underlying plaintexts.
40
41Known plaintext attack (KPA): This is when the eavesdropper knows some
42ciphertext-plaintext pairs for one and the same key and tries to use
43this information to then decrypt additional ciphertexts (again
44w.r.t. the same key).
45
46Chosen plaintext attack (CPA): Here the adversary may prepare
47plaintexts of its choice and request the corresponding ciphertexts.
48
49Chosen ciphertext attack (CCA): Here the adversary can even request
50the decryption of ciphertexts of its choice.
51
52Modern cryptography, say since WW2, holds the following additional
53principles:
54
55
56Principle 1: Formulation of exact definitions
57
58Which notion of security is one aiming at?
59
60No adversary should be able to know the key ... But what if they can
61decrypt ciphertexts without knowing the key?
62
63No adversary should be able to decrypt any ciphertext unless they know
64the key. But what if they can find out some bits of the ciphertext,
65e.g. every second letter, or a block of letters somewhere in the
66middle?
67
68
69Principle 2: Reliance on precise assumptions
70
71Typically, security of a cryptosystem can be guaranteed only by making
72assumptions on the computational power of an adversary (with unlimited
73resources they could always try out all plaintexts) and also on the
74computational difficulty of solving certain algorithmic
75problems. Desirable as it would be to have unconditional security; if
76one has to work with assumptions one should at least state them
77precisely. Sometimes, security can only be proven for idealized
78versions of cryptosystems that use components not known to exist but
79which are believed to be "approximated" by existing components. Again,
80it is then important to clearly state what these idealized components
81or versions are.
82
83
84Principle 3: Rigorous proofs of security
85
86Once the desired notion of security and the assumptions are clearly
87defined one should then establish a rigorous mathematical proof of
88conditional security.
89
90"Given that Assumption X is true, Construction Y is secure according
91to the given definition."
92
93As an example, we now look at perfect security in the sense of Shannon
94and see how Vernam's cipher (patented in 1919) implements it.
95
96
97In order to get around the fact that an adversary can always try out
98all possible plaintexts but that this kind of attack "doesn't count"
99Claude Shannon suggested to use probabilities: if one out of two
100messages is selected at random and the adversary gets to see the
101ciphertexts only it has a chance of no more than 50% of determining
102the plaintext correctly from the ciphertext. For cryptosystem Pi and
103adversary A we thus define the following
104
105Eavesdropping indistinguishability experiment PrivK^eav_{A,Pi}:
106
107 1. The adversary produces two messages m0, m1 from the message space M.
108 2. Gen is used to generate a (random) key k and a bit b <- {0,1} is
109 chosen uniformly at random (50/50). The (or rather a) ciphertext
110 c = Enc_k(m_b) is then given to A.
111 3. A answers by outputting a bit b'.
112 4. The output of the experiment is defined 1 if b=b' and 0 otherwise.
113
114Definition (perfect secrecy): The encryption scheme Pi=(Gen,Enc,Dec)
115is perfectly secret if for all adversaries A it holds that
116
117 Pr[PrivK^eav_{A,Pi} = 1] = 0.5
118
119The following cryptosystems are not perfectly secure:
120
121A book cipher which uses a secret code book containing for each *word*
122another word to replace it. E,g. "bomb" gets enciphered as "cake" and
123"dollars" gets enciphered as "grams". Here the adversary could select
124m0="bomb bomb" and m1="dollar bomb". If the received ciphertext has
125the form c = x x then it will output b'=0 and if c = x y with x =/= y
126it goes for 1.
127
128The Vigenere cipher with key length uniformly chosen at random from
129{1,2} (and once the length is fixed keys also chosen at random). The
130adversary can choose m0 = aa and m1=ab. If the ciphertext has the form
131xx it goes for b'=0. Otherwise it returns b'=1.
132
133Now, if b=0 then there is a 1/2+1/2*1/26 chance that the ciphertext
134has the form xx (key length 1 or key length 2 with equal letters) and thus
135the adversary is right with probability 1/2+1/52
136
137If b=1 then the adversary is right with probability 1-1/52 (the only
138way to be wrong is key length two and two key letters of distance 1).
139
140Thus, the total probability for A to be right is 1/2*(1/2+1/52) +
1411/2*(1-1/52) = 3/4.
142
143
144Proposition: Fix a cryptosystem Pi and suppose that plaintexts and
145keys are drawn according to some, not necessarily uniform
146distribution. The sytem Pi is perfectly secret if and only if
147
148 Pr[M=m | C=c] = Pr[M=m]
149
150for every fixed plaintext m and ciphertext c such that Pr[C=c] !=
1510.
152
153Proof (sketch): Suppose that Pr[M=m | C=c] != Pr[M=m] for some c and
154m. Since sum_m Pr[M=m | C=c] = sum_m Pr[M=m] = 1 (both are probability
155measures) there must exist m_0,m_1 (one of them m) such that Pr[M=m0 |
156C=c] < Pr[M=m0] and Pr[M=m1 | C=c] > Pr[M=m1]. By Bayes' theorem it
157follows that Pr[C=c|M=m0]<Pr[C=c] and Pr[C=c|M=m1]>Pr[C=c], thus in
158particular, Pr[C=c|M=m0] < Pr[C=c|M=m1].
159
160Now, consider the adversary who presents these messages m_0, m_1 and
161if the ciphertext returned is c
162then outputs b'=1, i.e. assume that the plaintext was not
163m0 and outputs b'=0 otherwise. Its success probability is
164
1651/2*(1-Pr[C=c|M=m0]) + 1/2*Pr[C=c|M=m1] =
1661/2 + 1/2(Pr[C=c|M=m1] - Pr[C=c|M=m0])
167
168which is strictly above 1/2.
169
170For the converse, one uses the fact that all the adversary knows is
171the ciphertext, but according to the assumed equality Pr[M=m | C=c] =
172Pr[M=m] this does not help. Q.E.D.
173
174Now, such perfectly secret cryptosystems exist indeed: for fixed n:N
175put M=C=K={0,1}^n and let Gen return k:K uniformly at random. The
176encryption function is Enc_k(m) = m+k and Dec_k(m) = m+k as well,
177where + denotes pointwise addition modulo 2 (XOR). For example, if n=5
178and k=11010 and m=11100 then Enc_k(m)=00110.
179
180This system is known as Vernam's cipher or "one time pad" the point
181being that its secrecy relies on the key being chosen afresh at random
182every time one wants to use the scheme. It can also be seen as a
183special case of the Vigenere cipher with the key being as long as the
184entire text to be enciphered.
185
186Proposition: The Vernam cipher is perfectly secret.
187
188Proof: This is because for a given plaintext m the ciphertexts are
189uniformly distributed, i.e., their distributions are identical and
190independent for m0 and m1. As a result, the adversary cannot have an
191advantage. Q.E.D.
192
193The obvious disadvantage of the one-time pad is the key length,
194nevertheless it is sometimes used, e.g. purportedly during the Cold
195War for secure communication between the White House and the Kremlin.
196
197Unfortunately, this key length is the price of perfect secrecy:
198
199Theorem: If Pi is a perfectly secret cryptosystem with key space K and
200message space M then |K|>=|M|, i.e. there have to be at least as many
201possible keys as there are possible messages ("the key must be as long
202as the message").
203
204Proof: Suppose for a contradiction that |K|<|M| and that ciphertext
205c:C occurs with nonzero probability. Let M(c) = {m | Dec_k(c)=m for
206some k:K}. We must have |M(c)|<=|K| since for each m:M(c) there is at
207least one k:K such that m=Dec_k(c) and the keys thus corresponding to
208distinct messages are distinct. If now |K|<|M| there must exist some
209m' not in M(c). But then Pr[M=m'|C=c] = 0 =/= Pr[M=m'], so the scheme
210is not perfectly secret.
211
212This result is due to Claude Shannon who gives in fact a more precise
213characterisation of perfect secrecy, see (KL2.4).
214
diff --git a/ss2017/cryptography/Notes03.txt b/ss2017/cryptography/Notes03.txt
new file mode 100644
index 0000000..fb94b87
--- /dev/null
+++ b/ss2017/cryptography/Notes03.txt
@@ -0,0 +1,100 @@
1
2
33 Semantic Security (KL3.1, KL3.2)
4----------------------------------
5
6In order to formally study secrecy of schemes that use shorter keys
7one must somehow incorporate the computational power of an
8adversary. One way of doing this is to use concrete bounds:
9
10A scheme is (t,epsilon)-secure if every adversary running for time t
11succeeds in breaking the scheme (in the appropriate sense) with
12probability at most epsilon.
13
14For example, if we use keys of bit length n and the only possible
15attack is by trying out all keys (this happens e.g. with Vernam's
16cipher) then assuming that 10^9 keys can be tried out every second
17(1GHz) trying out 2^60 operations takes 35years thus several years
18even with highly parallel computers. Thus, a 60bit key takes this time
19to be broken with certainty, a 64 bit key takes this time to be broken
20with probability 1/16 etc. Currently, one recommends key lengths of
21128bit (128 *bits of security*) to make the success probability
22negligible (e.g. lower than that of a meteor crashing into the device)
23and to allow for future technological advances.
24
25Now, working with concrete runtimes and probabilities is difficult and
26brittle because of its dependency on concrete hardware configuration,
27programming language, implementation details, etc. As a result, one
28uses instead an asymptotic approach where runtimes and probabilities
29as well as sizes of keys and texts are functions of a *security
30parameter* n. One then wants that the success probability of an
31adversary whose runtime is polynomial in the security parameter is a
32*negligible function* of the security parameter, i.e. smaller than n^k
33for any k.
34
35Definition: A private-key encryption scheme is a tuple of
36probabilistic polynomial-time algorithms (Gen,Enc,Dec) such that:
37
381. Gen computes a key (in {0,1}^*) from the security parameter
39(presented in unary, i.e. as 1...1 (n times)). We write this as k <-
40Gen(n) or k <- Gen(1^n) to emphasize the unary notation.
41
422. Enc_k(m) and Dec_k(c) are as before, except that m, c are
43bitsequences (in {0,1}^*). In particular, we must have Dec_k(Enc_k(m))=m.
44
45A fixed-length private-key encryption scheme is defined analogously,
46but there is a function l(n) fixing the length of plaintexts as a
47function of the security parameter. Formally, when k is returned from
48Gen(n) then Dec_k(m) is defined only for m of length exactly l(n).
49
50For example, the one-time pad can be cast into this framework. Given
51the security parameter n, Gen generates a random bit sequence of
52length n. One has l(n)=n and Enc_k(m) = m+k etc.
53
54
55
56Indistinguishability in the presence of an eavesdropper
57- - - - - - - - - - - - - - - - - - - - - - - - - - - -
58
59We now want to adapt the notion of perfect secrecy from above to the
60asymptotic framework. An adversary thus also gets the security
61parameter n and its runtime must be bounded by a polynomial in n. It
62is allowed to use randomization (has access to random bits).
63
64Given a scheme Pi=(Gen,Enc,Dec) and an adversary A the experiment
65PrivK^eav_{A,Pi}(n) is now defined as follows:
66
67
68 1. The adversary produces two messages m0, m1 of equal length
69 and of length l(n) in the case of fixed length.
70 2. Key k is generated by Gen(n) and a bit b <- {0,1} is
71 chosen uniformly at random (50/50). The (or rather a) ciphertext
72 c = Enc_k(m_b) as well as the security parameter n are then given to A.
73 3. A answers by outputting a bit b'.
74 4. The output of the experiment is defined 1 if b=b' and 0 otherwise.
75
76
77Definition: A scheme Pi=(Gen,Enc,Dec) has *indistinguishable
78encryptions in the presence of an eavesdropper* if there is a
79negligible function negl(n) such that for all adversaries A
80
81 Pr[PrivK^eav_{A,Pi}(n) = 1] <= 1/2 + negl(n)
82
83Remark: rather than having the adversary supply m0 and m1 they could
84also be universally quantified. Randomizing over m0 and m1 would lead
85to a weaker (and unreasonable) definition though.
86
87
88*Semantic security* proper:
89
90One can show (see 3.2) that this definition is equivalent to other
91ones that give even more power to the adversary. The most compelling
92one is "semantic security" which assumes an arbitrary probability
93distribution on the plaintexts and also partial information on the
94plaintexts to be given to the adversary.
95
96We remark that in general proofs of semantic security (in the sense of
97the above definition) are constructive in that the negligible function
98bounding the probability can be read off as an explicit term. From
99this, one can --- possibly after optimizing the constructions used in
100the proof --- read off concrete bounds for fixed security parameter n.
diff --git a/ss2017/cryptography/Notes04.txt b/ss2017/cryptography/Notes04.txt
new file mode 100644
index 0000000..cabf8f9
--- /dev/null
+++ b/ss2017/cryptography/Notes04.txt
@@ -0,0 +1,78 @@
14 Pseudorandomness (3.3)
2------------------------
3
4In order to arrive at cryptosystems with keys considerably shorter
5than messages it is natural to use a generator which from a truly
6random seed produces (deterministically!) a sequence of bits that
7looks random. Indeed, such generators are often used in the
8implementation of random in standard libraries e.g. for C or Java.
9
10The question is whether a so constructed cryptosystem might be while
11not perfectly secret still enjoy semantic security. The answer is yes
12if the generator is a *pseudorandom generator*, PRG for short, in the
13following sense.
14
15Definition (pseudorandom generator): Let l(n) be a polynomial and G a
16deterministic polynomial time algorithm that for any bitstring s of
17length n outputs a bitstring G(s) of length l(n). We call G a
18*pseudorandom generator* with expansion l(n) if for any probabilistic
19polynomial time adversary D ("distinguisher") it holds that
20
21 | Pr[D(r)=1] - Pr[D(G(s))=1] | = negl(n)
22
23for some negligible function negl(n) and for all n. Here s and r are
24bitstrings of lengths n and l(n), respectively, chosen uniformly at
25random.
26
27We remark that if l(n)=n then G(s)=s is trivially a pseudorandom
28generator and if l(n)>n and G is any function sending length n
29bitstrings to length l(n) bitstrings will be vulnerable against
30distinguishers with exponential computing power. Simply let D
31enumerate all length n bitstrings s' and check for each of them
32whether its input equals G(s'). Return 1 if yes, 0 otherwise. When fed
33G(s) the distinguisher will output 1 with certainty and if fed a
34random string then it will output one with probability 2^{-(l(n)-n)}
35only. The difference between these probabilities is not negligible.
36
37In summary, pseudorandom strings are as good as truly random ones so
38long as they are used in a probabilistic polynomial time context and
39one accepts negligible probability of failure.
40
41Unfortunately, one does not know whether there exist PRG with l(n)>n
42at all, but it is generally believed that they do. At least, there do
43exist several such objects for which no (probabilistic, polynomial
44time) distinguisher is currently known despite a lot of research.
45
46
47Semantically secure cryptosystems from PRG (KL3.4.1)
48- - - - - - - - - - - - - - - - - - - - - - - - - -
49
50Assuming that we have a PRG G with expansion factor l(n). We can use
51it in order to construct a semantically secure fixed-length encryption
52scheme for messages of length l(n) as follows:
53
54Gen(n): return a random bitstring of length n as key.
55Enc_k(m): return G(k)+m /* + = bitwise XOR */
56Dec_k(c): return G(k)+c
57
58Notice that Dec_k(Enc_k(m)) = G(k)+G(k)+m = m
59
60Theorem: If G is a PRG of expansion l then the above construction has
61indistinguishable encryptions in the presence of an eavesdropper.
62
63Proof: Let Pi stand for the scheme constructed above from G and
64l(n). Assume further, that A is an adversary against Pi. We construct
65from A a distinguisher D as follows:
66
67Given a string w (either random or of the form G(s)) the distinguisher
68begins by letting the assumed adversary A produce two messages m0 and
69m1. It then selects b:{0,1} at random and sends m_b + w to the adversary A.
70If A outputs b the distinguisher returns 1 and it returns
710 otherwise. Let p be the success probability of A in the PrivK^eav
72experiment which must be shown to be 0.5+negl(n). If w is truly random
73then so is m_b+w and the chance that A finds out b is exactly 1/2. If,
74on the other hand, w is G(s) for random s, then this likelihood is
75p. The difference between the two, i.e. p-1/2 is negligible since G
76was assumed to be a PRG and as a result p=1/2+negl(n) as required.
77Q.E.D.
78
diff --git a/ss2017/cryptography/Notes05.txt b/ss2017/cryptography/Notes05.txt
new file mode 100644
index 0000000..beca359
--- /dev/null
+++ b/ss2017/cryptography/Notes05.txt
@@ -0,0 +1,217 @@
15 Security against chosen plaintext attacks (KL3.5)
2---------------------------------------------------
3
4We now consider security of cryptosystems against stronger adversaries
5which may request the encryption of arbitrary plaintexts of their
6choice. There are some practical scenarios where this might occur,
7e.g. a smartcard which can be interacted with arbitrarily or by
8preparing some situation whose description will then be transmitted by
9the opposite party in encrpyted form.
10
11
12Given a scheme Pi=(Gen,Enc,Dec) and an adversary A the experiment
13PrivK^cpa_{A,Pi}(n) is now defined as follows:
14
15
16 1. Key k is generated by Gen(n)
17 2. The adversary A is given the security parameter n and the procedure
18 Enc_k as a black box (oracle access). After some interaction with
19 the oracle it then outputs two messages m0 and m1 from {0,1}^{l(n)}
20 (or of the same length in the case of variable length schemes).
21 3. A bit b <- {0,1} is chosen uniformly at random (50/50). The
22 (or rather a) ciphertext c = Enc_k(m_b) is given to A.
23 4. A continues to have oracle access to Enc_k and then answers by
24 outputting a bit b'.
25 4. The output of the experiment is defined 1 if b=b' and 0 otherwise.
26
27
28Definition: A scheme Pi=(Gen,Enc,Dec) has *indistinguishable
29encryptions under a chosen plaintext attack* (is cpa-secure for short)
30if there is a negligible function negl(n) such that for all (pr.-polytime)
31adversaries A
32
33 Pr[PrivK^cpa_{A,Pi}(n) = 1] <= 1/2 + negl(n)
34
35There is also a "known plaintext version" where the adversary does not
36get full-blown oracle access to Enc_k but can merely request
37encryptions of a previously submitted list of plaintexts. The details
38of this are left to the reader.
39
40We first notice that no deterministic scheme can possibly be
41cpa-secure. Given c simply compute (using the oracle) c_0=Enc_k(m_0)
42and c_1=Enc_k(m_1) and return b' such that c_b'=c. Thus, any cpa-secure
43scheme must include a random element into the encryption. But naive
44ways of doing so will not be successful either. Suppose for example
45that Pi=(Gen,Enc,Dec,l) is a deterministic scheme, i.e. Enc_k( ) is a
46function. Design a new scheme Pi' as follows:
47
48For bitstrings u,v we let u || v stand for the concatenation of u and
49v. If w is a bitstring of even length 2n then we let w.1 and w.2 stand
50for its first and second halves.
51
52Gen' = Gen
53l'(n) = l(n)/2 /* w.l.o.g. l(n) is even */
54Enc'_k(m) = Enc_k(r || m) where r is a random bitstring
55 of length l(n)/2.
56Dec'_k(c) = Dec_k(c).1
57
58Clearly, Pi' has indistinguishable encryptions in the presence of an
59eavesdropper if Pi has, but Pi' does not in general withstand chosen
60plaintext attacks. Namely, consider that Enc_k(m)=G(k)+m as above. We
61then have Enc'_k(m) = G(k).1 + r || G(k).2 + m. As a result, the
62adversary can take the first half of the received ciphertext c,
63request encryptions c_0 nd c_1 of m_0 and m_1 and determine b' so that
64c.1 = (c_b').1 .
65
66In order to achieve the desired security we need a *pseudorandom function*
67
68Definition: A pseudorandom function (PRF) is a binary function on bitstrings
69
70 F : {0,1}^* x {0,1}^* -> {0,1}^*
71
72with application F(k,x) written F_k(x) such that
73
74 1) |k|=|x| implies |F_k(x)|=|k|=|x| (and F need not be defined on
75 arguments of different length)
76
77 2) F is deterministic, polynomial-time computable
78
79 3) For all probabilistic polynomial-time distinguishers D and all n
80 one has
81
82 | Pr[ D^{F_k()}(n)=1 ] - Pr[D^{f()}(n)=1] | = negl(n)
83
84 for some negligible function negl() and probabilities taken over
85 k and f(), see below.
86
87The distinguisher has access to an oracle, i.e. a subroutine of type
88{0,1}^n->{0,1}^n. In the experiment, first k:{0,1}^n is drawn
89uniformly at random and then a function f from {0,1}^n->{0,1}^n is
90drawn uniformly at random (from the 2^{n*2^n} many possibilities). The
91oracle is then instantiated with F_k() on the one hand and
92with f on the other. The probabilities for the distinguisher to output
931 in either case should differ only negligibly.
94
95So, where a pseudorandom generator expands a size n key k to a size
96l(n) bitstring that looks random a pseudorandom function expands a
97size n key to a function F_k which could be written as a size n*2^n
98bitstring. Again, this "very large" object should look
99random. However, only a polynomial portion of it can be examined by
100the distinguisher. On the other hand, which portion that is is up to
101the distinguisher to decide and not priori fixed.
102
103We remark that one often uses variants of PRF where the size of
104argument x and results are functions of a security parameter other
105than the identity function. (The security parameter must then be
106supplied explicitly to F)
107
108Relationship between PRF and PRG:
109
110It is not hard to see that every PRF can serve as a PRG. Given k
111simply output the string F(k,0) || F(k,1) || F(k,2) || ... || F(k,N) for
112sufficiently large N and where e.g. 2 stands for the encoding of 2 as
113a length n bitstring. If a distinguisher could tell this from a random
114string one could easily use it to distinguish F_k from a random
115function. Surprisingly, the converse also holds, see (KL6.5). However,
116we still do not know whether PRG exist. In practice, PRF are
117constructed using heuristic approaches.
118
119
120A CPA-secure cryptosystem from a PRF (KL3.6.2)
121- - - - - - - - - - - - - - - - - - - - - - - -
122
123Here is, how we use a PRF to construct a CPA-secure cryptosystem. Note
124that by our earlier observation the scheme itself must be randomised.
125
126
127Gen(n): return a random bitstring of length n as key.
128Enc_k(m): choose r:{0,1}^n uniformly at random and output the ciphertext
129 c := r || F_k(r)+m
130Dec_k(c): given c extract c.1=r and c.2=F_k(r)+m then return c.2+F_k(r)
131
132Notice that Dec_k(Enc_k(m)) = F(k,r)+F(k,r)+m = m
133
134Remark: A random element like r added to a piece of data is known as a
135*nonce*.
136
137Theorem: If F is a PRF then the above construction yields a fixed
138length (l(n)=n) CPA-secure cryptosystem.
139
140Proof: Let Pi stand for the scheme constructed above from F and
141l(n). Assume further, that A is an adversary against Pi. We construct
142from A a distinguisher D for the PRF F as follows:
143
144Given security parameter n and oracle access to a function h (which is
145instantiated as either F_k() or a truly random f()) the distinguisher
146begins by passing the security parameter n to the adversary A.
147
148Now, whenever the adversary queries its own oracle which it assumes to
149be of the form Enc_k() then the distinguisher chooses r:{0,1}^n at
150random and returns r || h(r)+m to A.
151
152When the adversary enters the second phase and outputs two messages
153m_0, m_1 to distinguish based on their encryptions the distinguisher
154then chooses a random bit b:{0,1} and r:{0,1}^n uniformly at random
155and returns r || h(r)+m_b to A. Further oracle queries from A are
156answered as before.
157
158When A eventually outputs a bit b' reply 1 if b=b' and 0 otherwise.
159Let us see what the adversary can do when h is a truly random
160function. Unlike in the "eavesdropper" case, A has a certain
161advantage: namely suppose it has already requested encryptions c_0 and
162c_1 of the messages m_0 and m_1 it then forwards (and it would be
163"wise" for A to do so). If it now happens by accident that
164c.1=c_0.1=c_1.1, i.e. the three random nonces used were all equal,
165then since the rest is deterministic, the adversary can pick b' such
166that c.2=c_{b'}.2 and be correct. Since, however, the adversary can
167only make polynomially many queries the likelihood for this to happen
168is negligible. If, however, the random nonce used in the preparation
169of c is different from all the ones used in oracle queries then c
170looks completely random to A and its success probability is exactly
1711/2. Summing up, if h is truly random then A's success probability is
1721/2+negl(n).
173
174If, on the other hand, h is F_k(), then let p be the success
175probability of the adversary A on our new cryptosystem. It is clear
176that our distinguisher will output 1 with probability p for we have
177used A according to the rules of the PrivK^cpa-experiment. Since F was
178assumed to be a PRF we thus know that |p-(1/2+negl(n))| is itself
179negligible. It then follows that p is bounded by 1/2 plus a negligible
180function. Q.E.D.
181
182
183Notice that this proof newly introduces negligible probabilities
184rather than (or in addition to) just move them around and thus gives
185further evidence as to why allowing negligible deviations from the
186ideal situation is reasonable.
187
188We also remark that the way the system was presented the length of the
189key equals that of the message. However, in the case of a CPA-secure
190system we can encrypt several messages with the same key without
191compromising security. We generalise this idea in the next chapter.
192
193Proposition: Let Pi=(Gen,Enc,Dec) be cpa-secure and define
194Pi'=(Gen,Enc',Dec') by Enc'_k(m1 || m2) = Enc_k(m1) || Enc_k(m2). Then
195Pi' is cpa-secure. Here m1, m2, as well as, c1,c2 are assumed to be of
196equal length.
197
198Proof: From a hypothetical cpa-adversary A' against Pi' we construct a
199cpa-adversary A against the original system Pi as follows:
200
201A runs A' and answers any oracle requests according to Pi'. E.g. if A'
202asks for an encryption of m1||m2 it requests encryptions c1 and c2 of
203m1, m2, respectively and then provides the answer c1||c2.
204
205When A' outputs the challenge m1^0||m2^0 vs m1^1||m2^1 A submits the
206challenge m2^0 vs m2^1 and receives a ciphertext c2 (which should be an
207encryption of m2^0 or m2^1). A then requests an encryption c1 of m1^0 and
208passes c1||c2 to A'.
209
210The answer bit b' supplied by A' is then output.
211
212Let p be the success probability of A'.
213
214If the secret bit b is equal to 0 then the
215success probability of A is p as well.
216
217
diff --git a/ss2017/cryptography/Notes06.txt b/ss2017/cryptography/Notes06.txt
new file mode 100644
index 0000000..a14e840
--- /dev/null
+++ b/ss2017/cryptography/Notes06.txt
@@ -0,0 +1,216 @@
1
26 Block ciphers, Modes of operation (KL3.6.3 KL3.6.4)
3-----------------------------------------------------
4
5A pseudorandom function F() with the additional property that F_k is
6invertible and the inverse F_k^{-1} is computable in polynomial time
7is known as *block cipher* or *pseudorandom permutation*. It is not
8hard to see that in this case,
9
10Enc_k(m) = F_k(m)
11Dec_k(c) = F_k^{-1}(c)
12
13is semantically secure (hence the name "block cipher"). While a simple
14PRG already suffices to build a semantically secure cryptosystem those
15based on PRF as above enjoy stronger properties as we now explain.
16
17With the help of a block cipher it is possible to design encryption
18schemes for messages of arbitrary length using various *modes of
19operation* that we now describe. In practice, the underlying block
20ciphers (or pseudorandom functions) are heuristically designed
21functions like DES or AES which we we will look at later. In some
22modes of operation it suffices to have a pseudorandom function rather
23than permutation.
24
25In each mode of operation we divide the message to be encrypted into
26blocks of size n, where n is the security parameter and hence the size
27of the messages the pseudorandom function can work with. If the length
28of the whole message is not a multiple of n we must *pad* the last
29block in some way, e.g. by adding 1000...0. There are various padding
30schemes which describe this in detail. We henceforth assume that
31padding has already taken place and that the message comprises l
32blocks m_1,...,m_l of length n each.
33
34Remark: it is possible to vary l from message to message and in this
35way to encrypt a *stream* of bits rather than a block. One thus
36effectively obtains so-called *stream ciphers*. Such stream ciphers
37are also constructed and studied in their own right, see
38e.g. KL3.4. In this course, we do not consider stream ciphers.
39
40
41ECB mode (electronic code book)
42- - - - - - - - - - - - - - - -
43
44This is the simplest mode of operation and it is actually not secure
45at all, hence obsolete and included only for historical reasons. Let F
46be a block cipher.
47
48The encryption of the plaintext m = m1..ml under ECB-mode is given by
49
50 Enc_k(m) = F_k(m1) F_k(m2) ... F_k(ml)
51
52i.e. the encodings F_k(mi) of the blocks mi are simply
53concatenated. This mode receives its name from the fact that it
54resembles a code book (which for each short message lists the
55corresponding code) albeit in electronic form.
56
57It is easy to see that ECB is not even secure against an
58eavesdropper. If, assuming blocklength 3, we choose messages m=000000
59and m'=000111 we can tell them apart on the basis of the corresponding
60ciphertexts c,c' alone because c has the form xyzxyz whereas c' does
61not. This deficiency of ECB shows in practice when it is used to
62encode images, see KL (2nd ed) for an example.
63
64
65CBC mode (cipher block chaining)
66- - - - - - - - - - - - - - - - -
67
68Here we choose a random initialisation vector IV:{0,1}^n and encrypt as
69
70Enc_k(m) = IV c1 c2 c3 ... cl
71
72where c1=F_k(IV+m1), c2=F_k(c1+m2), c3=F_k(c2+m3), ...
73
74I.e. each block is xor-ed with the encoding of the previous block
75prior to sending it through F_k.
76
77One can show that CBC-mode is CPA-secure, however it suffers from the
78disadvantage that the ith ciphertext is needed to compute the i+1-st
79one so the scheme cannot be parallelized.
80
81The following variant of CBC-mode has been used in practice (SSL 3.0, TLS 1.0):
82
83
84Chained CBC-mode (not CPA secure)
85- - - - - - - - - - - - - - - - -
86
87Rather than choosing a fresh initialisation vector each time it has
88been proposed to use instead the last ciphertext, i.e., c_l as the new
89initialisation vector. This reduces the size of the subsequent
90message by one block and should intuitively be as good as CBC-mode
91proper. However, this scheme is vulnerable to a CPA-attack as follows:
92Suppose that the attacker knows that m_1 is one out of m_1^0 and m_1^1
93and that m = m_1 m_2 m_3 has already been encrypted as IV c_1 c_2
94c_3. The attacker could now request the encryption of another message
95starting with the block
96
97 m_1' := IV + m_1^0 + c_3
98
99The first ciphertext block c_1' then satisfies
100
101 c_1' = F_k(c_3+m_1') = F_k(IV + m_1^0)
102
103
104Noticing that c_1 = F_k(IV + m_1) we then have m_1 = m_1^0 iff c_1' =
105c_1.
106
107
108
109OFB mode (output feedback)
110- - - - - - - - - - - - - -
111
112Here we only need a pseudorandom function. From a randomly chosen
113initialisation vector IV we first compute pseudorandom strings r1...rl
114as follows:
115
116r1 = F_k(IV), r2 = F_k(r1), ...
117
118and then encrypt using xor:
119
120Enc_k = IV m1+r1 m2+r2 m3+r3 ... ml+rl
121
122So, in essence, we use F_k as a pseudorandom generator of expansion
123l(n) = l*n and then apply the earlier construction of an EAV-secure
124scheme from a PRG. Due to the additional randomization via the
125initialisation vector OFB-mode is even CPA-secure.
126
127
128CTR mode (counter)
129- - - - - - - - -
130
131This mode is similar to OFB, but we compute the pseudorandom string by
132successively incrementing IV:
133
134r_i = F_k(IV+i) /* this + is binary addition, not XOR */
135
136Enc_k = IV m1+r1 m2+r2 m3+r3 ... ml+rl
137
138This has the advantage that the ri and hence the ciphertexts can be
139computed in parallel. A further advantage that it shares with OFB is
140that the pseudorandom string IVr1..rl can be computed ahead of time
141and stored until the message to be encrypted arrives. Furthermore,
142portions of the ciphertext can be decrypted without computing or
143decrypting anything else. This property is known as *random access*.
144
145
146Theorem: If F is a pseudorandom function then (randomised) counter
147mode (as described above) is CPA-secure.
148
149Proof: (Unlike KL we make the simplifying assumption that message
150length l is always the same). Let A be an adversary as in the Priv^cpa
151experiment. We transform it into a distinguisher D for the underlying
152pseudorandom function as we did in the proof of the last Theorem.
153
154Given security parameter n and oracle access to a function h (which is
155instantiated as either F_k() or a truly random f()) the distinguisher
156begins by passing the security parameter n to the adversary.
157
158Now, whenever the adversary queries its own oracle which it assumes to
159be of the form Enc_k() then the distinguisher chooses IV:{0,1}^n at
160random, computes the sequence ri=h(IV+i) and submits IV m1+r1
161... ml+rl to the adversary.
162
163When the adversary enters the second phase and outputs two messages
164m^0, m^1 to distinguish based on their descriptions the distinguisher
165then chooses a random bit b:{0,1} and IV:{0,1}^n uniformly at random
166and returns the encryption of m^b w.r.t. IV to A. Further oracle
167queries from A are answered as before.
168
169When A eventually outputs a bit b' reply 1 if b=b' and 0 otherwise.
170
171Let us see what the adversary can do when h is a truly random
172function. Again, the adversary has a certain advantage which we now
173try to bound from above.
174
175Let us assume that for any two encryptions requested the sequences of
176the counter values do not overlap, i.e. the sets
177{IV,IV+1,IV+2,...,IV+l} and {IV',IV'+1,IV'+2,...,IV'+l}, where IV and
178IV' are the respective initialisation vecotrs chosen, are disjoint. In
179this case, the ciphertexts follow a uniform random distribution and
180the adversary cannot glean any information whatsoever, i.e. has
181success probability 1/2. If they do overlap the adversary may or may
182not use the extra information but if we can show that the probability
183of this happening is negligible we are good. So, this is what we now
184try to do.
185
186Let us first consider that the overlap happens between the first and
187second oracle question. In this case, once IV has been chosen, at most
1882l values for IV' are unfavorable (or favorable depending on
189viewpoint): IV, IV-1 ... IV-l, IV+1, IV+2, ... IV+l. Thus, we have a
190probability of 2l*2^n. Now, since such a clash can happen anywhere we
191multiply this with q(n), the number of questions being asked. Thus, we
192get an overall bound of q(n)*2l/2^n on the probability of an
193overlap. Even if l is not constant, but polynomial in the security
194parameter this is negligible (noting of course that in view of the
195time bounds q(n) is polynomially bounded). As a result, the success
196probability for the adversary can be bounded by 1/2+negl(n).
197
198The rest of the argument is as before: If h is F_k(), then let p be
199the success probability of the adversary A on our new cryptosystem. It
200is clear that our distinguisher will output 1 with probability p for
201we have used A according to the rules of the
202PrivK^cpa-experiment. Since F was assumed to be a PRF we thus know that
203|p-(1/2+negl(n))| is itself negligible. It then follows that p is
204bounded by 1/2 plus a negligible function. Q.E.D.
205
206
207We close by remarking that none of the schemes presented so far is
208secure against chosen ciphertext attacks (CCA) where one may request
209the decryption of arbitrary ciphertexts different from the
210challenge. Consider, e.g. the encryption of m as r || F_k(r)+m. An
211adversary can prepare messages m0=00..0 and m1=11..1. Upon receiving a
212ciphertext c= r || s corresponding to one of these two the adversary can
213flip the first bit of s and ask for the decryption of the resulting
214ciphertext. This must be either 100..0 or 011..1 according to whether
215m was 00..0 or 11..1.
216
diff --git a/ss2017/cryptography/Notes06a.txt b/ss2017/cryptography/Notes06a.txt
new file mode 100644
index 0000000..6791ce9
--- /dev/null
+++ b/ss2017/cryptography/Notes06a.txt
@@ -0,0 +1,105 @@
1
2
3Multiple encryptions from cpa-secure cryptosystem
4- - - - - - - - - - - - - - - - - - - -- - - - - -
5
6We have seen that a block cipher can be used repeatedly with the same
7key (using e.g. CTR-mode) without compromising security. We show now
8that this is true for an arbitrary cpa-secure cryptosystem. From a
9practical point of view this is not so important because cpa-secure
10cryptosystems typically come from block ciphers, and a block cipher is
11used more efficiently through one of the modes of operation given.
12
13However, the proof of the result (cpa->multiple) is interesting at
14this point because it is the first time where we use semantic security
15(here in the cpa sense) as an assumption rather than establishing
16it. Furthermore, the result becomes practically relevant in the
17context of public key cryptography where by definition security
18against eavesdroppers and cpa security coincide.
19
20Theorem. Let Pi=(Gen,Enc,Dec) be cpa-secure. Build
21
22Pi'=(Gen,Enc',Dec')
23
24Enc'_k(m1 || m2) = Enc_k(m1) || Enc_k(m2)
25
26Then Pi' is cpa-secure, too.
27
28Proof: Consider an adversary A' against Pi'. We run A' and answer
29oracle queries honestly using Enc'_k. Adversary A' eventually
30produces
31
32m^0 = m1^0 || m2^0
33m^1 = m1^1 || m2^1
34
35and asks for a ciphertext c1 || c2. For b1,b2,b':{0,1} define
36P(b1,b2,b') to be the probability that A' outputs b' when
37c1<-Enc_k(m1^b1); c2<-Enc_k(m2^b2).
38
39The success probability of A' equals 1/2 * (P(0,0,0) + P(1,1,1))
40
41The probabilities P(0,1,0) and P(0,1,1) are somewhat funny since they
42correspond to replies to the adversary's question that are against
43the rules. However, we still know that their sum is one and this can
44be used as follows:
45
46Let us design an adversary A against the original system Pi. This
47adversary A produces m2^0 and m2^1 and receives a ciphertext c2 for
48one of the two. It can then obtain c1<-Enc_k(m1^0), forward c1||c2 to
49A' and output the bit b' it eventually receives from A'. The
50probability that this bit is correct then is 1/2 P(0,0,0) + 1/2
51P(0,1,1) by making a case distinction over the equally likely
52possibilities b=0 or b=1. So, assuming that Pi is cpa secure, we
53obtain a negligible function negl(n) so that
54
551/2 P(0,0,0) + 1/2 P(0,1,1) <= 1/2+negl(n)
56
57Similarly, by producing m1^0 and m1^1 instead and using
58c2<-Enc_k(m2^1), we obtain a bound
59
601/2 P(0,1,0) + 1/2 P(1,1,1) <= 1/2+negl(n)
61
62Summing up and using the fact that the sum of negligibles is
63negligible we get
64
651/2(P(0,0,0)+P(1,1,1)) + 1/2 <= 1 + negl(n)
66and so 1/2(P(0,0,0)+P(1,1,1)) <= 1/2 + negl(n) QED.
67
68Let us now consider the more general case where Pi is used to encode a
69sequence of message of some arbitrary length l=l(n), i.e., depending
70on n. Thus, define Pi'=(Gen,Enc',Dec') by
71
72Enc'_k(m1||...||ml) = Enc_k(m1) || ... || Enc_k(ml) etc
73
74Theorem: If Pi is cpa-secure so is Pi' as defined above.
75
76Proof: The proof is similar to the one before. Adversary A' against
77Pi' eventually produces m1^0...ml^0 and m1^1...ml^1 and waits for
78ciphertexts c1..cl. For 0<=j<=l define P_j(b') to be the probability
79that A' outputs b' assuming that
80
81c1<-Enc_k(m1^0) ... cj<-Enc_k(mj^0),
82c_{j+1}<-Enc_k(m_{j+1}^1) ... cl<-Enc_k(ml^1)
83
84The success probability for A' is 1/2 * (P_l(0) + P_0(1)) and, as
85before, we should bound this by 1/2+negl(n).
86
87For the skew probabilities it holds as before P_j(0)+P_j(1)=1.
88
89For each t=1..l we build an adversary A_t against Pi by outputting
90mt^0 and mt^1, receiving ct, requesting c1<-Enc_k(m1^0),
91c2<-Enc_k(m2^0) ... c_{t-1}<-Enc_k(m_{t-1}^0),
92c_{t+1}<-Enc_k(m_{t+1}^1)...c_l<-Enc_k(m_l^1). Notice the switch from
93^0 to ^1 after we reach t. Adversary A_t then forwards c1..cl to A'
94and returns its answer. The success probability is
951/2(P_{t}(0)+P_{t-1}(1)) which is hence bounded by 1/2 + negl(n):
96
97For all t=1..l : 1/2(P_t(0)+P_{t-1}(1)) <= 1/2+negl(n)
98
99Summing all these inequalities noticing P_t(0)+P_t(1)=1 yields
100
1011/2(P_l(0) + (l-1)*1 + P_0(1)) <= 1/2*l + negl(n) /* another
102 negligible function */
103
104and thus 1/2(P_l(0) + P_0(1)) <= 1/2 + negl(n) as required. QED
105
diff --git a/ss2017/cryptography/Notes07.txt b/ss2017/cryptography/Notes07.txt
new file mode 100644
index 0000000..6d60d56
--- /dev/null
+++ b/ss2017/cryptography/Notes07.txt
@@ -0,0 +1,204 @@
17 Practical block ciphers. Principles: s/p- and Feistel networks (5.1-5.2)
2- - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -- - - -
3
4We now describe how pseudorandom functions and block ciphers are
5practically constructed. The constructions given do not ensure the
6pseudorandom property, and in fact do not even fit into the asymptotic
7paradigm since the blocklength is typically fixed. Their design is
8guided by heuristic principles and the practical evidence that so far
9no attacks have been found. As already mentioned, there are other,
10less efficient constructions that merely require the existence of a
11PRG, but again, the latter has not yet been shown to exist
12unconditionally.
13
14In this section, a block cipher (of key length n and block length l)
15thus is simply a function F:{0,1}^n x {0,1}^l -> {0,1}^l such that F_k
16given by F_k(m)=F(k,m) is invertible (a permutation) for each k.
17
18Claude Shannon formulated two important principles guiding the design
19of block ciphers:
20
21Confusion: statistical regularities in the plaintexts, e.g. letter
22frequencies or frequencies of n-grams should not show up in the
23ciphertext.
24
25Diffusion: changing one bit of the plaintext should (on average)
26change a large proportion, e.g. one half of the bits in the
27ciphertext.
28
29These principles are not rigorously defined and should be seen rather
30as guidelines. The following procedure shows intuitively how they
31could be observed.
32
33Let us say that the key comprises 16 byte-substitutions f_1, ... f_16
34: {0,1}^8->{0,1}^8, e.g. various shifts or other operations. So k =
35(f_1,..,f_16). A first attempt at constructing a block cipher of
36length 128 would be as follows:
37
38F_k(x) = f_1(x_1) ... f_16(x_16)
39
40where x is decomposed into 16 consecutive 8-bit blocks (bytes) x_1
41.. x_16.
42
43
44This introduces confusion because each byte is subjected to a
45different permutation. However, the cipher still has insufficient
46diffusion since x1 only influences the first byte of the ciphertext
47etc. This lack of diffusion implies in particular that with chosen
48plaintexts we can learn parts of the value tables of individual key
49substitutions.
50
51To remedy this, we subject the individual bits of the ciphertext to
52some global, known permutation P:{1..128}->{1..128} of the positions
53and repeat this entire procedure several times ("rounds"). After a few
54rounds a large degree of diffusion will be reached ("avalanche
55effect") provided that the permutation mixes across block boundaries
56and that the substitutions in themselves already achieve a certain
57degree of diffusion in the sense that each input bit influences
58several output bits and vice versa.
59
60The substitutions and permutations used in each round need not always
61be the same which then leads to the following general pattern.
62Repeatedly break the text into equal size blocks, e.g. bytes which are
63subjected to individual substitutions. Afterwards, the bits are
64shuffled across the entire text using a permutation of the
65positions. The key determines the substitutions and permutations being
66used. Some of them may be independent of the key.
67
68
69S/P-networks
70- - - - - - -
71
72A substitution-permutation network (S/P-network) implements this idea
73in principle, however, neither the substitutions f_i, nor the
74permutations on positions depend on the key but are rather fixed
75upfront. In this way, confusion and diffusion are maintained, but of
76course key dependency needs to be introduced one way or another. This
77happens by XOR-ing the intermediate results with parts of or a known
78function of the key. The key itself is often called *master key* and
79the portions of it used as XOR-masks in the different rounds are known
80as *key schedule*. The substitution functions being used are commonly
81known as *S-boxes*. The permutations on positions are called *mixing
82permutations*. Thus, in an S/P-network the message is repeatedly
83subjected to the following three steps:
84
85a) XOR-ing with keys derived from the master key through a key schedule
86b) blockwise application of the S-boxes
87c) global application of a mixing permutation
88
89There are a number of principles to be followed when designing an
90S/P-network.
91
921. The S-boxes used *should be invertible* for otherwise one would not
93obtain an invertible cipher in the end.
94
952. The S-boxes *should not be linear* functions in the sense of XOR
96for then the entire cipher would be a linear function which opens it
97up to a variety of attacks based on solving linear equations, see
98below. In fact they should not even be close to linear functions in
99the sense of Hamming distance.
100
1013. The S-boxes should implement the *avalanche effect*. Changing one
102bit in the input changes at least two bits in the output no matter
103what the other bits are set to. In addition, the mixing permutations
104should spread the output bits of any given S-box, i.e. in one block to
105different S-boxes, i.e. blocks in the next round.
106
107It is not hard to see that after a modest (polynomial in the message)
108number of rounds these design principles ensure sufficient diffusion
109because after each round the number of bits affected by a single bit
110flip in the input roughly doubles.
111
112
113
114Attacks against badly designed S/P-networks
115- - - - - - - - - - - - - -- - - - - - - - -
116
117Suppose we have an S/P-network with only one round. Given a plaintext
118m and a ciphertext c we can then work out the key as follows. Undoing
119the (known!) mixing permutation and the S-boxes yields c' := m+k from
120which we retrieve k by adding m since m+k+m = k.
121
122Indeed, practical implementations of S/P-networks usually omit the
123application of S-boxes and the mixing permutation in the last round
124since it can be undone anyway as we just saw. (NB in the 2nd edition
125of KL the S/P-networks are set up in this fashion from the beginning;
126however the present approach looks more systematic)
127
128Suppose now that we have an S/P-network with two rounds. Suppose for
129the sake of concreteness that the cipher uses 16 S-boxes operating on
1304-bit each so that the total message length is 64. Suppose
131furthermore, that the key k consists of 128 bits of which the first
132half is used in the first round and the other half in the
133second. Given m and c we, being the attacker, first undo the
134S/P-operation of the second round as before. Now consider any 4-bit
135block in the output. It depends on at most four 4-bit blocks from the
136input because in the worst case each bit comes from a different
137S-box. We also know from the mixing permutation in the first round
138which these four 4-bit blocks are. Its 16 bits are transformed into
139the 4 bits of the block we're looking at using a known function and 16
140+ 4 bits of the key. These can all be tried out in 2^20 =~= 10^6 time
141which is altogether feasible. A similar argument applies to a three
142round S/P-network, however the number of key bits influencing a four
143bit block then goes up to 4+16+64 = 84 which is still a bit shorter
144than 128, but cannot really be feasibly explored by brute force.
145
146However, even after three rounds the S/P-network can be efficiently
147distinguished from a truly random permutation. Namely, each output bit
148is then not influenced by 44 of the input bits. A distinguisher can
149then toggle these bits and see whether the observed bit changes. If it
150does not for, say 10^9 out of the 2^44 possible combinations then the
151possibility that the distinguisher deals with a truly random function
152is extremely small so it has an advantage.
153
154Once we use four or more rounds (and the mixing permutations as well
155as the S-boxes) were well designed then the avalanche effect has fully
156kicked in and attacks like the ones sketched are no longer possible.
157
158Let us also see why linear S-boxes cannot be recommended: if all
159S-boxes f are linear functions in the sense that f(x+y)=f(x)+f(y) then
160for each key k the function Enc_k() is linear too, i.e., we have
161Enc_k(x+y)=Enc_k(x)+Enc_k(y). In this case, there exists for each key
162an nxn matrix A_k with 0,1 entries (n the message length) such that
163
164 Enc_k(m) = A_k m
165
166If we now have n^2 many pairs of plaintext-ciphertext we obtain n^2
167linear equations which we can solve for the entries of A_k. Once A_k
168is known then even if we do not know k itself we can decrypt arbitrary
169ciphertexts encrypted with the same key using the inverse matrix. This
170kind of attack applies to all linear encryption functions regardless
171whether they are S/P-networks. It also applies to affine linear
172ciphers, where Enc_k(m) = A_k m + b_k.
173
174
175
176Feistel networks
177- - - - - - - -
178
179Feistel networks are an alternative approach to designing practical
180pseudorandom permutations. It also operates in rounds and each round a
181key-dependent *mixing function* f_i() is applied to the second half of
182the current text which is then XOR-ed with its first half to become
183the new second half. The new first half is the old second half. Thus,
184if L_i and R_i denote the first and second halves of the text after
185round i then we have
186
187 L_0 R_0 := "plaintext"
188 L_{i+1} := R_i
189 R_{i+1} := L_i + f_i(k_i,R_i)
190
191Here k_i is the round key used in the i-th round which is derived from
192the master key through the key schedule as usual.
193
194Notice that,
195
196 R_i = L_{i+1}
197 L_i = R_{i+1}+f_i(k_i,L_{i+1})
198
199so that the Feistel network is invertible as desired no matter what
200f_i() does.
201
202One can show (KL6.4) that if the mixing functions f_i are pseudorandom
203functions then the function defined by a four round Feistel network is
204a pseudorandom permutation.
diff --git a/ss2017/cryptography/Notes08.txt b/ss2017/cryptography/Notes08.txt
new file mode 100644
index 0000000..fd5c54b
--- /dev/null
+++ b/ss2017/cryptography/Notes08.txt
@@ -0,0 +1,382 @@
1
2
38 DES (Data encryption standard) and AES (Advanced encryption standard)
4-----------------------------------------------------------------------
5
6The Data Encryption Standard (DES) was published 1975 by the
7US-administration after public consultation. It was designed and used
8as a standard for non-military secrte communication e.g. between
9government bodies but also in the private sector. It is a 16-round
10Feistel network of message length 64 and key length 56. Mainly due to
11its relatively short key length it is no longer considered secure. It
12is nevertheless still widely used in legacy applications and in the form
13of three-fold repetition (3DES) which is considered secure but
14somewhat inefficient.
15
16The Feistel mixing function of DES uses a round key k_i of length 48
17which is applied to a 32 bit long half block as follows:
18
191) The 32 bit half block is expanded to 48 bit by repeating half of
20its bits using an expansion function E() (see table below)
21
222) The round key is XOR-ed with the resulting block
23
243) The result is divided into eight 6-bit blocks to which S-boxes
25S_1..S_8 are applied (see table below). Each S-box has 6 inputs and 4
26outputs, so a 32bit block results.
27
284) a mixing permutation P is applied to the resulting 32bit.
29
30The DES key schedule is as follows: initially the master key is
31subjected to a mixing permutation on 56 bits. Thereafter, the round
32key for the each round is applied by extracting (in a round-dependent
33fashion) 48 bits from these 56 bits in such a way that the first 24
34bits stem from the first half of the (permuted) key and the second 24
35bits from the second half. See below for the exact form of the bit
36extraction functions.
37
38The DES encryption function is now obtained by enclosing the 16-round
39Feistel network FN_k described above by an initial permutation IP and
40its inverse listed below, thus Enc_k(x) = IP^{-1}(FN_k(IP(x))).
41
42The initial permutation has no influence on security. It is there only
43for historical reasons having to do with 8-bit hardware.
44
45Each S-Box can be regarded as a package consisting of four
46*invertible* operations on size 4 bitstrings. In conjunction with the
47expansion function they operate as follows: The current size 32
48bitstring is divided into 8 blocks of size 4. To the ith such block
49the ith S-box (eight in total) is applied in the following way: first
50the two neighbouring bits (modulo 32) are taken, e.g. for the block
51comprising bits 5,6,7,8 these neighbouring bits are 4 and 9. For the
52first block comprising bits 1,2,3,4 the neighbouring bits are 32 and
535. These two bits then are used to select the invertible substitution
54to be applied to the block. This intuition is reflected in the
55tabulation of the S-boxes below as binary functions of the central
56size four block and the neighbouring two bits. Also, the expansion
57function E() is designed to implement this idea, i.e. it duplicates
58the "neighbouring bits.
59"
60
61
62DES supplementary material
63- - - - - - - - - - - - -
64
65Initial permutation: The first bit of IP(x) is the 58th bit of x; the
66second bit of IP(x) is the 50th bit of x etc (read left to right and
67top to bottom).
68
69IP:
7058 50 42 34 26 18 10 2
7160 52 44 36 28 20 12 4
7262 54 46 38 30 22 14 6
7364 56 48 40 32 24 16 8
7457 49 41 33 25 17 9 1
7559 51 43 35 27 19 11 3
7661 53 45 37 29 21 13 5
7763 55 47 39 31 23 15 7
78
79
80Expansion function: to be read left to right, top to bottom. First bit
81of E(x) is the 32th, i.e. last, bit of x.
82
83E:
8432 1 2 3 4 5
854 5 6 7 8 9
868 9 10 11 12 13
8712 13 14 15 16 17
8816 17 18 19 20 21
8920 21 22 23 24 25
9024 25 26 27 28 29
9128 29 30 31 32 1
92
93
94Mixing permutation P:
95
9616 7 20 21 29 12 28 17
97 1 15 23 26 5 18 31 10
98 2 8 24 14 32 27 3 9
9919 13 30 6 22 11 4 25
100
101The S-boxes given as binary functions:
102
103S_1: to be applied to the first block
104E 4 D 1 2 F B 8 3 A 6 C 5 9 0 7
1050 F 7 4 E 2 D 1 A 6 C B 9 5 3 8
1064 1 E 8 D 6 2 B F C 9 7 3 A 5 0
107F C 8 2 4 9 1 7 5 B 3 E A 0 6 D
108
109This is to be read as follows: upon receiving a 6bit block the S-box
110uses the outer 2 bits to select the row and the inner four bits (read
111in decimal). The decimal number found there represents the output. For
112example, on input 011011 we select row #1 (0xxxx1) and the column #13
113(x1101x) (counting from 0 each time). There we find (hexa)decimal
114number 5 representing output 0101. Similarly, on input 101000 we
115select row #2, column #4, finding D=13, hence outputting 1101.
116For the remaining S-boxes S_2,...,S_8 we refer to the Internet.
117
118Initial mixing function selecting 56 out of 64 bits. The remaining 8
119bits serve as parity bits (each of the eight bytes comprising the key
120must have even parity). Does not have any influence on security.
121
122PC1:
123
12457 49 41 33 25 17 9
1251 58 50 42 34 26 18
12610 2 59 51 43 35 27
12719 11 3 60 52 44 36
128
12963 55 47 39 31 23 15
1307 62 54 46 38 30 22
13114 6 61 53 45 37 29
13221 13 5 28 20 12 4
133
134
135The ith round key is obtained from the 56bit key by rotating both
136halves i bits to the left and then selecting 48 bits with the
137following function.
138
139
140PC2:
141
14214 17 11 24 1 5
1433 28 15 6 21 10
14423 19 12 4 26 8
14516 7 27 20 13 2
14641 52 31 37 47 55
14730 40 51 45 33 48
14844 49 39 56 34 53
14946 42 50 36 29 32
150
151
152
153
154Discussion of DES
155- - - - - - - - -
156
157The S-boxes have the important property that changing one bit of the
158input always changes two bits of the output. For example, the first
159row of S_4 maps 7=0111 to 10=1010. The 1bit alterations of 7 are
16015=1111, 3=0011, 5=0101, 6=0110. These are mapped to 15=1111, 3=0011,
1616=0110, 9=1001. All of these differ from 10=1010 in two bits.
162
163Furthermore, the mixing permutation is such that any two bits from the
164same 4 bit block end up in *different* 4 bit blocks where they will
165cause more bit differences and so on thus ensuring the desired
166avalanche effect.
167
168Purportedly, the S-boxes have been designed so as to withstand a
169particular attack called *differential cryptanalysis* which was known
170to the developers but not published. Only 15 years later was this
171discovered again and published by Biham and Shamir.
172
173The text KL contains some more detail about attacks on variants of DES
174with fewer rounds which exploit the fact that the avalanche effect has
175not fully unfolded then.
176
177With today's technology the 2^56 keyspace can be completely searched
178with special hardware in several hours so that DES is no longer secure
179for critical applications. There is a variant 3DES (Triple DES) which
180uses three DES keys k1,k2,k3 (hence has key size 168) and encrypts according to the formula
181
182 Enc^3DES_{(k1,k2,k3)}(m) = Enc^DES_k3(Dec^DES_k2(Enc^DES_k1(m)))
183
184Thus, to encrypt a message we encrypt it (using DES) with key k1 then
185decrypt it with key k2 and then encrypt it with key k3.
186
187The fact that we use decryption rather than encryption in the second
188phase ensures that standard DES arises as the special case of three
189identical keys:
190
191 Enc^3DES_{(k,k,k)}(m) = Enc^DES_k(m)
192
193A version with just two phases does not provide the desired increased
194security due to the possibility of a meet-in-the-middle attack:
195suppose we (temprorarily) define 2DES by
196
197 Enc^2DES_{(k1,k2)}(m) = Enc^DES_k2(Enc^DES_k1(m))
198
199Then given a pair (m,c) where c=Enc^2DES_{(k1,k2)}(m) we can recover
200k1 and k2 in time ~2^56 as follows:
201
202Define x_k = Dec^DES_k(c) and y_q = Enc^DES_q(m) and tabulate x_k and
203y_q for any DES keys k and q. This takes 2*2^56 DES operations (and
204also requires this much space to store the tables). One can then sort
205the tables and in this way quickly find k,q so that x_k=y_q. This pair
206then is the desired 2DES key.
207
208One can also use this attack against 3DES (splitting either after the
209third or after the second phase) which reduces the effective key size
210to 112.
211
212It is not clear whether "meet-in-the-middle" is really practical
213because, at least when implemented naively, the storage requirements
214for the tables exceed current technology.
215
216
217Advanced Encryption Standard (AES)
218- - - - - - - - - - - - - - - - - -
219
220The AES which was selected by the US administration (NIST) from
221submissions to a public competition in 2000 is an S/P-network with
222block size 128bit and key sizes of 128, 192, or 256 bit (AES-128,
223AES-192, AES-256). AES-128 being the most popular variant we will only
224describe this one here. The original name of the cipher prior to being
225selected as the AES was "Rijndael" (Dutch for Rhine Valley) and chosen
226by its Belgian authors Joan Daemen and Vincent Rijmen.
227
228
229The substitution operation applies a fixed invertible function (the
230AES S-box) on size-8 bitstrings (bytes) to each of the 16 bytes of the
231text.
232
233The subsequent mixing step is in the case of AES not just a bit
234permutation but in fact an invertible linear transformation.
235
236AES operates on the byte level and the text is arranged into a 4x4
237matrix whose entries are bytes (4x4x8=128). The bytes are mostly
238understood as elements of the 256-element field GF(256). Thus, there
239is also a multiplication operation b*b' on bytes which together with
240the XOR-operation (bitwise addition mod2) endows the bytes with the
241structure of a field. In particular, each byte b:{00,...,FF} (one
242adopts hexadecimal notation) except 00 has an inverse b^{-1} such that
243b^{-1} * b = 1. Caveat: this multiplication is not multiplication of
244binary numbers mod 256. We describe below how it is defined in
245detail. For now it suffices to know that together with addition (XOR)
246it satisfies the usual algebraic laws (commutativity, associativity,
247distributivity, inverse).
248
249Now, each round comprises the following four steps:
250
2511. AddRoundKey(): Addition mod2 of the 128 bit round key derived from the
252master key according to the key schedule. Can be viewed as the
253addition of a "round key matrix".
254
2552. SubBytes(): Application of the S-Box to each of the 16 bytes of the
256text. First, each of the 16 bytes comprising the current text matrix
257is replaced with its inverse in GF(256). Exception: 00 for which there
258is no inverse is left alone (not replaced).
259
260Thereafter, each byte is transformed by the following affine map:
261
262(b_7') (1 1 1 1 1 0 0 0) (b_7) (0)
263(b_6') (0 1 1 1 1 1 0 0) (b_6) (1)
264(b_5') (0 0 1 1 1 1 1 0) (b_5) (1)
265(b_4') = (0 0 0 1 1 1 1 1) (b_4) + (0)
266(b_3') (1 0 0 0 1 1 1 1) (b_3) (0)
267(b_2') (1 1 0 0 0 1 1 1) (b_2) (0)
268(b_1') (1 1 1 0 0 0 1 1) (b_1) (1)
269(b_0') (1 1 1 1 0 0 0 1) (b_0) (1)
270
271These matrix and vector operations are understood in GF(2),
272ie. addition is (as usual) XOR of bits whereas multiplication is
273logical AND.
274
275The purpose of the inversion part is to introduce a high degree of
276nonlinearity, i.e. to not even be close to a linear function. The
277purpose of the affine transformation (which is linear) is to introduce
278a certain amount of diffusion, i.e. that changes in one bit in the
279input of the S-box result in >1 bit changes at the output. The affine
280transformation also ensures that not the entire operation of AES can
281be regarded in terms of GF(256) which could possibly result in
282vulnerabilities based on algebraic properties.
283
284Usually, the entire S-box is implemented as a 256 byte lookup table.
285
286
2873. ShiftRows(): The ith row is (cyclically) shifted i-1 columns to the
288left (i=1,2,3,4):
289
290(a b c d) (a b c d)
291(A B C D) |-> (B C D A)
292(u v w x) (w x u v)
293(U V W X) (X U V W)
294
295
2964. MixColumns(): The 4x4 text matrix is multiplied (from the left) by
297the (invertible) matrix
298
299(02 03 01 01)
300(01 02 03 01)
301(01 01 02 03)
302(03 01 01 02)
303
304The entries of this matrix are understood as hexadecimal notation for
305bytes, e.g.03 stands for the element 00000011 of GF(256). Thus, we
306have 02+01=03 but 01+01=00 and 02+03=01.
307
308In the last (16th) round, MixColumns() is replaced with another
309AddRoundKey(). Notice that---as pointed out earlier---key-independent
310steps at either the beginning or the end of the cipher could be easily
311undone by an attacker and thus are worthless.
312
313The AES key schedule thus must transform the 128bit master key into 17
314equally sized round keys. Let k be the 128bit master key. Just as the
315texts we view it as a 4x4 matrix with entries from GF(256). We now
316generate a sequence k_0,...,k_{16} of round keys (17 in number) as follows:
317
318
319k_0 = k (01 01 01 01)
320k_{i} = (k_{i-1} + (c'|0|0|0)) (00 01 01 01)
321 (00 00 01 01)
322 (00 00 00 01)
323 \______ ______/
324 V
325 M
326
327where the column c' is obtained from the last column c of k_{i-1} as follows:
328
329 (00 00 00 01) (02^i)
330c' := (01 00 00 00) SubBytes(c) + ( 00 )
331 (00 01 00 00) ( 00 )
332 (00 00 01 00) ( 00 )
333 \______ _____/
334 V
335 R
336
337Here SubBytes(c) denotes the result of the application of the AES
338S-box to each byte in the column c. The byte 02^i is 02*02*...*02 (i
339times) in GF(256). The matrix R cyclically rotates the column
340downwards. To then obtain k_i we add c' to the first column of k_{i-1}
341to obtain the first column of k_i. The next three columns are obtained
342by adding the previous one (of k_i) to the corresponding one of
343k_{i-1}. The matrix M does just that.
344
345We see that the next round key is obtained from the previous one by
346some simple linear operations and one nonlinear function of the last
347column.
348
349Decryption: We notice that all the functions used are invertible so
350the decryption just performs these inverse operations in the opposite
351order. We omit the details.
352
353
354Arithmetic in GF(256)
355- - - - - - - - - - -
356
357In order to understand how multiplication in GF(256) works one
358represents a byte b=b0..b7 as a polynomial with coefficients in
359GF(2)={0,1}
360
361b(X) = b7 * X^7 + b6 * X^6 + ... + b1 * X + b0
362
363In order to multiply two bytes one multiplies them qua polynomials and
364then takes the remainder (using polynomial division) modulo the
365polynomial
366
367p(X) = X^8 + X^4 + X^3 + X + 1
368
369For example, 03 is X+1, so 03*03 = X^2+1 = 05 (the coefficients are
370calculated modulo 2). The inverse of 03 is F6=11111010 because
371
372(X^7+X^6+X^5+X^4+X^2+X)*(X+1) = X^8+X^7+X^6+X^5+X^3+X^2+X^7+X^6+X^5+X^4+X^2+X =
373\___________ _________/ \_ _/ = X^8+X^4+X^3+X = 1 (mod p)
374 V V
375 F6 03
376
377One finds such inverses using the extended Euclidean algorithm or
378using a table of logarithms. Indeed, each element of GF(256) \ {0} can
379be written as a power of 03 (some other elements can be used in place
380of 03). One may write log(x) for the number t:{0..254} such that x =
38103^t. One then has x^{-1} = 03^{255-t}. The logarithms can also be
382used to reduce multiplication to addition mod 255.
diff --git a/ss2017/cryptography/Notes09.txt b/ss2017/cryptography/Notes09.txt
new file mode 100644
index 0000000..7c6f51d
--- /dev/null
+++ b/ss2017/cryptography/Notes09.txt
@@ -0,0 +1,259 @@
1
29 Cryptanalysis
3---------------
4
5Cryptanalysis is aimed at breaking ciphers in the sense of
6reconstructing a key from given or chosen pairs of plain- and
7ciphertext. In the first chapter, we saw how various historic ciphers
8can be broken using regularities in the statistical distribution of
9ciphertexts or rather using the fact that known properties of the
10statistical distribution of plaintexts shine through in the
11statistical distribution of plaintexts. Modern cryptographic schemes
12avoid such attacks by making sure that the statistical distribution of
13ciphertext looks close to uniform no matter what the statistical
14distribution of the plaintexts is. The principles of confusion and
15diffusion were introduced to ensure this property at least
16approximately in practice. The notion of pseudo random generator
17furnishes an ideal yet useful theoretical model.
18
19Attacks against cryptographic schemes that properly implement
20confusion and diffusion are much more complicated and in many cases,
21in particular DES and AES not known to exist except in the sense that
22the computational time needed to carry them out is close to that of a
23brute-force attack (trying out all keys) which is always
24possible. Nevertheless, it is important to know and study principles
25of such attacks in order to avoid them when designing a new cipher,
26e.g. a smaller variant of existing ones to be run in
27resource-constrained environments e.g. "Internet of Things".
28
29We have already seen that a cipher that only uses linear or affine
30linear operations is vulnerable to an attack based on solving systems
31of linear equations. In this chapter we take a brief look at three
32more principles of cryptanalysis. First, we show why feedback shift
33registers which are a popular device for generating pseudorandom
34numbers are not secure.
35
36Linear Feedback Shift Registers (LFSR): Such a device is given by a
37sequence of shift registers with some outputs fed back via XOR to the
38input. For instance:
39
40 >[D]-o->[D]-o->[D]---o------------->
41 | | | |
42 -(+)-----------(+)----
43
44When the shift registers (here noted [D]) are initialised with some
45bits then a stream of bits is generated at the output. E.g. starting from 100
46we obtain the following sequence of states:
47
48100,110,111,011,101,010,001,100,...
49and the following output sequence 00111010...
50
51Here, from xyz we get to uxy where u=x+z (mod 2). Of course, the
52sequence repeats after at most 8 steps, but until then looks rather
53random. With a chain 16 shift registers one can achieve a period
54length of 65535. In order to encrypt a stream of bits ("stream
55cipher") one can initialise the shift registers with the secret key
56and then add (XOR) the generated stream to the data stream. Due to the
57relative simplicity of implementation this has been used for a long
58time in esp. military applications.
59
60However, LFSR are linear (the sequence generated by the sum of two
61keys equals the sum of the sequences generated by the keys
62individually) and this can be exploited in various ways. The most
63interesting way uses the Berlekamp Massey algorithm which from a given
64sequence of bits computes the shortest LFSR which generates it. If one
65knows the beginning m of a plaintext and the corresponding ciphertext
66c, e.g. because the plaintext starts with the date or some formal
67greeting one can then apply the Berlekamp-Massey algorithm to m+c and
68use the computed LFSR to decode the remaining ciphertext.
69
70In order to circumvent this one can use nonlinear functions in the
71feedback loop, e.g. logical or use nonlinear combinations of several
72LFSR. The resulting stream ciphers, e.g. A5/1 and A5/2, E0 are still
73in use in GSM and Bluetooth but are known to have vulnerabilities
74too. Indeed, the design of secure stream ciphers is very difficult and
75for high security applications one resorts to block ciphers run,
76e.g. in CTR mode in order to encrypt bitstreams.
77
78
79Linear cryptanalysis
80- - - - - - - - - - -
81
82Linear cryptanalysis was developed in the 90s by Matsui and apparently
83was not known to the DES developers. Nevertheless, it can only produce
84a theoretical attack on the latter and on AES.
85
86We illustrate linear cryptanalysis with the toy cryptosystem from
87Michael Heys' tutorial
88https://www.engr.mun.ca/~howard/PAPERS/ldc_tutorial.pdf.
89
90It is an S/P network with a block length of 16 and four proper rounds,
91i.e. four rounds and an additional key mixing step. We regard each
92block as a 4x4 bit matrix. The substitution step applies the first
93S-Box of DES S_1, i.e.
94
950 1 2 3 4 5 6 7 8 9 A B C D E F
96-------------------------------
97E 4 D 1 2 F B 8 3 A 6 C 5 9 0 7
98
99separately to each of the four rows (regarded as a hexadecimal number). So
100
101(1 0 1 0) (A) (6) (0 1 1 0)
102(0 1 1 0) which is (6) becomes (B) which is (1 0 1 1)
103(1 1 0 1) (D) (9) (1 0 0 1)
104(0 0 0 1) (1) (4) (0 1 0 0)
105
106The permutation step is simply matrix transposition, thus our example
107becomes
108
109(0 1 1 0) (6)
110(1 1 0 0) which is (C)
111(1 0 0 1) (9)
112(0 1 1 0) (6)
113
114As usual, each round consists of addition mod2 of the round key,
115substitution (S), and permutation (P), i.e. transposition. After four
116rounds we add one more key. The master key simply consists of the
117concatenation of the five round keys k = k1 k2 k3 k4 k5.
118
119We can now observe that the S-box S is not completely balanced in the
120following sense. Let WX1 be (1 0 1 1)^T and WY1 = (0 1 0 0)^T. The ^T
121suffix means transposition so W1, W2 are actually columns. We now have
122
123 Pr(WX1^T x + WY1^T S(x) = 0) = 3/4
124
125where the probability is taken over uniformly distributed
126x:{0,1}^4. In other words, for 12 out of the 16 possible inputs x=(x1
127x2 x3 x4)^T and results S(x)=(y1 y2 y3 y4)^T one has x1+x3+x4=y2
128whereas for the remaining four one has x1+x3+x4=/=y2,
129i.e. x1+x3+x4=y2+1.
130
131One can find such an imbalance by exhaustive search. Another such
132imbalance is given by WX2=(0 1 0 0)^T WY2 = (0 1 0 1)^T:
133
134 Pr(WX2^T x + WY2^T S(x) = 0) = 1/4
135
136Chaining these imbalances through the whole cipher (using the first
137one on round 1 and the second one on the other rounds) one obtains a
138similar linear relationship between the plaintext, the ciphertext just
139after round four, and the four round keys that have been used until
140then: Letting P be the plaintext (now written as dim16 vector) and U
141the ciphertext prior to applying the last S-boxes, permuting, and
142mixing with the fifth and last round key we find dim16 vectors A, B
143D1, D2, D3, D4 such that
144
145 Pr(A^T P + B^T U + D1^T K1 + D2^T K2 + D3^T K3 + D4^T K4 = 0) = 15/32
146
147with keys K1 ... K4 fixed and probability taken over the plaintexts P.
148
149
150Since D1^T K1 + D2^T K2 + D3^T K3 + D4^T K4 is either 0 or 1 we have that
151
152 Prob(A^T P + B^T U = 0) = 15/32 or Prob(A^T P + B^T U = 0) = 17/32
153
154irrespective of K1,..,K4. This allows us to work out a likely value
155for K5 or rather some bits of it.
156
157Namely, given a list of plaintexts P_1..P_N and corresponding
158ciphertexts C_1..C_n we can try out all 2^16 possible choices for K_5,
159for each one compute the corresponding U_i := S^{-1}(P^{-1}(C_i+K_5)),
160and compute the ratio
161
162 p(K_5) = {i | A^T P_i + B^T U_i = 0} / N
163
164We choose a value K_5 for which this ratio is close to 15/32 or 17/32
165and discard all those where it is close to 1/2. Now, p(K_5) does not
166actually depend on all bits of K_5 but only on those where the
167corresponding bit in B^T is set for the other ones only influence
168components of U_i which are not used in p(K_5). Nevertheless, this
169allows us to considerably narrow down the possible options for
170K_5. For each of those, we can then continue in the same fashion and
171thus peel off the fourth round key etc.
172
173
174Differential cryptanalysis
175- - - - - - - - - - - - - -
176
177Differential cryptanalysis was developed by Biham and Shamir as an
178attack against DES but apparently already known to the DES
179developers. It has been used to successfully break other ciphers. It
180uses the fact that the effect of adding a round key cancels out when
181we consider differences between two plaintexts. However, this
182requires the preparation of chosen plaintexts. In more detail, the
183*differential* between two plaintexts X1 and X2 is simply X1+X2,
184i.e. the bitvector which has a 1 where X1 and X2 differ and a 0 where
185they are equal.
186
187Coming back to our 4bit example S-box for any given differential there
188then are 2^4=16 different ways of realising it. E.g. the differential
1891010 arises for the plaintext pair 0011,1001 and also for
1901111,0101. Indeed, for any plaintext X1 there is a unique X2 such that
191X1, X2 have a given differential.
192
193Given two differentials X* and Y* we are interested in the following
194question. For how many of the (16) plaintext pairs X1,X2 with
195differential X* is it the case that the results of applying the S-box
196Y1=S(X1), Y2=S(X2) have differential Y*. Tabulating these numbers by
197exhaustive search yields the following table:
198
199 Output differential
200 0 1 2 3 4 5 6 7 8 9 A B C D E F
201I 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
202n 1 0 0 0 2 0 0 0 2 0 2 4 0 4 2 0 0
203p 2 0 0 0 2 0 6 2 2 0 2 0 0 0 0 2 0
204u 3 0 0 2 0 2 0 0 0 0 4 2 0 2 0 0 4
205t 4 0 0 0 2 0 0 6 0 0 2 0 4 2 0 0 0
206 5 0 4 0 0 0 2 2 0 0 0 4 0 2 0 0 2
207d 6 0 0 0 4 0 4 0 0 0 0 0 0 2 2 2 2
208i 7 0 0 2 2 2 0 2 0 0 2 2 0 0 0 0 4
209f 8 0 0 0 0 0 0 2 2 0 0 0 4 0 4 2 2
210f 9 0 2 0 0 2 0 0 4 2 0 2 2 2 0 0 0
211' A 0 2 2 0 0 0 0 0 6 0 0 2 0 6 0 0
212i B 0 0 8 0 0 2 0 2 0 0 0 0 0 2 0 2
213a C 0 2 0 0 2 2 2 0 0 0 0 2 0 6 0 0
214l D 0 4 0 0 0 0 0 4 2 0 2 0 2 0 2 0
215 E 0 0 2 4 2 0 0 0 6 0 0 0 0 0 2 0
216 F 0 2 0 0 6 0 0 0 0 4 0 2 0 0 2 0
217
218
219The high entries 8 and 6 are of particular interest because they
220constitute a deviation of an intuitive pseudorandom permutation.
221Let us now see how we can exploit these in order to attack our cipher.
222
223We feed in a pair of 16bit plaintexts X1 X2 which differ in the second
224block by B=1011 and are equal everywhere else. With probability 8/16
225this will result in differential 2=0010 at the output of the second
226S-box. The output of the other S-boxes will be equal for X1 and X2.
227This differential 2=0010 will be propagated through the P network and
228results in a differential of 4=0100 at the entry of the third S-box of
229the second round:
230
231 Differential before P Differential after P
232 0 0 0 0 0 0 0 0
233 0 0 0 0 ------P----> 0 0 1 0
234 0 1 0 0 0 0 0 0
235 0 0 0 0 0 0 0 0
236
237
238There, with probability 6/16 it will produce differential 6=0110 at
239the output. This results in differential 2=0010 at the input of the
240second and third S-boxes of the third round. With probability 36/256
241this will lead to differential 5 at both outputs which propagates to
242differential 6=0110 at the entries to the second and fourth S-boxes of
243the final round.
244
245 0 0 0 0 0 0 0 0
246 0 0 1 0 -------P-----> 0 0 0 0
247 0 0 1 0 0 1 1 0
248 0 0 0 0 0 0 0 0
249
250Summing up, when we encipher plaintexts with differential 0B00 we will
251obtain with probability 1/2*3/8*9/64=27/1024 a differential 0606 at
252the entry to the last round. We now have to set the relevant
253components (second and fourth block) of the final key in such a way
254that this ratio (after inverting the last layer of S-boxes) is
255actually reproduced. This allows us (with high probability) to guess
256hone half of the bits of the last round key. Continuing in this way
257with other differentials combined with exhaustive search allows us to
258undo the entire last round and then to proceed from there.
259
diff --git a/ss2017/cryptography/Notes10.txt b/ss2017/cryptography/Notes10.txt
new file mode 100644
index 0000000..5457bf3
--- /dev/null
+++ b/ss2017/cryptography/Notes10.txt
@@ -0,0 +1,257 @@
1
2
310 Message integrity, CBC-MAC (KL4.1-4.5)
4-----------------------------------------
5
6So far, we wanted to prevent an eavesdropper or a more active attacker
7from getting to know the content of encrypted messages or at least
8partial information about them.
9
10Another important objective for cryptography is message integrity and
11authenticity. We want to prevent the attacker from being able to
12manipulate an encrypted message or from fabricating one such.
13
14It is not the case that encryption automatically guarantees
15integrity. For example, with the Vernam cipher and derived systems
16flipping one bit in the ciphertext results in the same bit in the
17plaintext being flipped. Also, randomly chosen ciphertexts correspond
18to plaintexts albeit probably nonsensical ones.
19
20
21Message authentication codes
22- - - - - - - - - - - - - - -
23
24Definition: A message authentication code (MAC) consists of two
25probabilistic polynomial time algorithms (Gen,Mac) where
26
271. On input n (security parameter) Gen outputs a key k of length >= n
282. Given key k and message m:{0,1}* the tag-generation algorithm Mac outputs
29 t = Mac_k(m)
30
31We assume (unlike in KL where this is a special case) that Mac is
32deterministic.
33
34If m is furthermore constrained to be from {0,1}^l(n) for some length
35function l(n), e.g. l(n)=n then the MAC is called *fixed length*. EOD
36
37The intended usage is as follows: Alice and Bob share a secret key k
38that has been obtained with Gen(). If Alice wants to send a message m
39to Bob she could compute the tag t=Mac_k(m) and transmit (m,t) either
40encrypted or not.
41
42In order to be sure that the received message (m,t) was really from
43Alice he can then compute t'=Mac_k(m) and check that t=t'. The MAC
44should be designed in such a way that no adversary can fabricate valid
45tags unless it knows the key so that if the verification succeeds Bob
46can indeed be sure that the message was from Alice. The following
47experiment formalizes this.
48
49
50The message authentication experiment Mac-forge_{A,Pi}(n):
51
52Pi = (Gen,Mac) a MAC, A an adversary, n the security parameter
53
541. A random key k is generated with Gen(n).
55
562. The adversary is given n and oracle access to Mac_k(), i.e. it can
57request arbitrary tags w.r.t k. The adversary eventually outputs a
58pair (m,t).
59
603. The output of the experiment is defined to be 1 if
61 (1) Mac_k(m)=t and (2) m has not previously been queried by A.
62
63Thus, the adversary must prepare a valid tag for a message it has not
64previously requested a tag for.
65
66We define a MAC to be secure if for all adversaries
67the probability that Mac-forge yields 1 is negligible.
68
69While this notion of security is indeed very strong there are some
70attacks it cannot withstand:
71
721) Replay attacks. The adversary can store an authenticated message
73(m,t) and send it at some later point. In order to prevent that one
74can extend message with timestamps or similar.
75
762) Timing attacks. If the check t=t'? proceeds by comparing bits
77starting from the left until the first mismatch is encountered (cf
78strcmp() from the C-library) then the time it takes to perform the
79check depends on the tags. This can be used to find out the bits of a
80valid tag one by one. According to KL this kind of attack has been
81used against an early version of the Xbox in order to install
82unlicensed games. To prevent the attack one should make sure that the
83computation time for the comparison is always the same.
84
85Construction of a fixed-length MAC from a pseudorandom function:
86
87Let F_k() be a pseudorandom function. The following then is a secure
88fixed-length MAC.
89
901. Gen(): Given n choose k:{0,1}^n uniformly at random
912. Mac(): On input k and m output the tag t=F_k(m)
92
93Theorem: The above MAC is secure.
94
95Proof sketch: As in the other security proofs it suffices to show this for
96truly random F (selected at the beginning of the experiment). The
97passage to a pseudorandom F then incurs a negligible change in
98probability. In order to produce a valid tag the adversary would have
99to correctly guess a random value from {0,1}^n which has indeed
100negligible probability. QED
101
102
103CBC-MAC
104- - - -
105
106In order to extend a fixed-length MAC to variable length messages one
107can break the message up into equal length blocks m=m_1,...m_l of
108length n each possibly padding the last block with 0s and then
109authenticate each block separately. In order that this is secure, one
110must, however augment each block with
111
112- the length l,
113- its sequence number i:{1..l}
114- a random identifier r:{0,1}^n (the same for each block)
115
116Thus, the blocks to be authenticated have length 4n each (assuming
117that l and i fit into n bits) and an appropriate MAC must be
118used. Alternatively, one can break m into blocks of size n/4....
119
120These additional data prevent the adversary from dropping blocks at
121the end (length), changing the order of blocks (sequence numbers),
122mixing blocks from two different messages (random identifier).
123
124One can show that this scheme is indeed secure, but it is rather
125inefficient since the tags are 4 times as long as the message itself.
126
127A more efficient method mimicks the CBC-mode encryption but is subtly
128different:
129
130Rather than an arbitrary MAC we need a pseudorandom function F_k,
131i.e. a block cipher. We then decompose the message m into equal sized
132blocks
133
134m = m_1 .. m_l
135
136as before (using padding if needed). We then *prepend* the message
137with another block encoding the length l (which is thus assumed
138smaller than 2^n). Then blocks are encrypted and XORed with the
139encryption of the previous block prior to encryption. The encryption
140of the last block then is the desired MAC:
141
142t_0 = F_k(l)
143t_{i+1} = F_k(t_i + m_i)
144t = t_l
145
146We will prove that this scheme is secure. Notice, however, that
147seemingly innocuous modifications thwart its security:
148
149First, let us see why we need to incorporate the length. Suppose we
150would just put:
151
152t_1 = F_k(m_1)
153t_2 = F_k(m_2+t_1)
154...
155t = t_l
156
157Then, if t=Mac_k(m_1 m_2) and t'=Mac_k(m_3+t m_4) then t'=Mac_k(m_1
158m_2 m_3 m_4) thus allowing us to forge a previously unqueried tag.
159
160Now suppose that we would start with a random initialisation vector IV
161and transmit it along with the tag:
162
163t_0 = F_k(l+IV)
164...
165
166This would allow us to modify the length: If (IV,t) is the MAC of l,m
167then (IV+l+l',t) is the MAC of l',m.
168
169It is also not ok to attach the length at the end rather than at the
170beginning. Namely, suppose that we obtain the following tags where the
171length is added in parenthesis for clarity.
172
173
174ABCDE(5) : t
175XYZKL(5) : t'
176ABCDE5UVW(9) : t''
177
178We then have that the tag of XYZKL5 U+t+t' VW(9) is also t''.
179
180We will now sketch a proof that CBC-MAC is indeed secure. We will show
181the following theorem from which the claim follows by the standard
182reasoning used in earlier security proofs.
183
184Theorem: Fix a security parameter n. For g:{0,1}^n->{0,1}^n and m=m1
185m2 ... mk write CBC_g(m) = CBC_g(m1,m2,...,mk) =
186
187 g(ml+g(m_{k-1}+ ... g(m2 + g(m1)) ... )
188
189Also let f:({0,1}^n)* -> {0,1}^n be an arbitrary function. Let D be an
190adversary which is given oracle access to a function ({0,1}^n)* ->
191{0,1}^n.
192
193Suppose that D queries its oracle on a prefix-free set, i.e. if X and
194Y are both queried then X is not a prefix of Y nor is Y a prefix of X.
195One then has
196
197 |Pr(D^{CBC_g()}(n) = 1) - Pr(D^{f()}(n) = 1)| = negl(n)
198
199where probabilities are taken over g and f chosen uniformly at random.
200
201To see why this implies the theorem we first consider that the
202difference between CBC_g and CBC_{F_k} is negligible since F_k is
203assumed to be pseudorandom. Furthermore, notice that in CBC-MAC proper
204the function CBC_{F_k} is applied to a subset of P:={|m| m |
205m:({0,1}^n)*} which itself is a prefix-free set. Thus, the whole
206business with including the length and putting it into the first
207position rather than anywhere else serves to ensure prefix-free-ness.
208
209Proof of Theorem (sketch; for details see KL, 2nd ed):
210
211Let Q={X1..Xq} be the (prefix-free) set of queries (q = number of
212queries) made by the distinguisher D to the oracle. Let l be the
213maximum number of blocks in those queries. Notice that both q---the
214number of queries---and l---their maximum length are polynomial in n
215since the distinguished is assumed to run in polynomial time. If D
216queries X and X = m1 m2 ... mk then (in the case where the oracle is
217instantiated with CBC_g()) the function g() will be evaluated at m1,
218m2+g(m1), m3+g(m2+g(m1)), ... . Write C_g(X) for this sequence (of
219length < l). We say that Q exhibits a collision if among the
220g-evaluations occurring in {C_g(X) | X:Q} one finds the situation
221g(x)=g(x') where x =/= x'. We also consider it a collision if at some
222point we have mi+g(x) = mj'+g(x') despite x=/=x' (and then necessarily
223mi=/=mj').
224
225Under the assumption that g() is random, the probability that such a
226collision is exhibited is bounded by q^2 * l^2 * negl(n) for there are
227<= q^2 * l^2 possibilities for where such a collision might occur and
228the probability for a collision at a given position is negligible.
229Since q and l are polynomial in n this probability is therefore
230negligible itself.
231
232Let us assume that no collision is exhibited. Now, for each X:Q let
233v(X) be the last value in C_g(X). We have CBC_g(X) = g(v(X)). The
234values v(X) are pairwise distinct and do not agree with any of the
235other values in {C_g(X) | X:Q}. This is where prefix-freeness is
236used. As a result, since g() is random, the answers to the queries
237g(v(X)) are uniformly random and thus adhere to the same distribution
238as f(X) for the random f. Thus, the only advantage that the
239distinguisher has stems from the possibility of a collision being
240exhibited which, as we saw above, is negligible.
241
242
243
244In conclusion, we note that an already existing implementation of
245CBC-mode (for encryption) can be turned into an implementation of
246CBC-MAC by
247
248 - using IV=0
249 - discarding all but the last blocks of the ciphertext
250 - prepending the plaintext with its length
251
252Mistakes in any one of these (e.g. using a random IV and transmitting
253it, omitting the length or placing it elsewhere, transmitting other
254blocks of the ciphertext, lead to insecurities. See the nice blog
255article "Why I hate CBC-MAC").
256
257https://blog.cryptographyengineering.com/2013/02/15/why-i-hate-cbc-mac/
diff --git a/ss2017/cryptography/Notes11.txt b/ss2017/cryptography/Notes11.txt
new file mode 100644
index 0000000..839d24b
--- /dev/null
+++ b/ss2017/cryptography/Notes11.txt
@@ -0,0 +1,310 @@
1
2
311 Hashing, Merkle-Damgard transform, SHA, HMAC
4-----------------------------------------------
5
6Hash functions serve a related but slightly different purpose to that
7of MACs. Unlike those (and private key encryption) they are not
8immediately useful on their own but rather are building blocks and
9indeed are "a workhorse of cryptography" like e.g. solving systems of
10linear equations is to engineering.
11
12Intuitively, a hash function H() transforms a long string m into a
13short digest ("hash") t=H(m) such that it is extremely difficult to
14produce two texts x =/= x' with H(x)=H(x'). Such pair x,x' is known as
15a *collision*.
16
17As such, the notion cannot really be made sense of in the context of
18computational complexity for once we have x=/=x' with H(x)=H(x') then
19we can just hardwire x,x' into a program. In order to get around this,
20we introduce as before randomly chosen keys and security parameters.
21This will allow us to formulate meaningful security goals and
22meaningful security proofs for various constructions involving hash
23functions.
24
25Definition: A *hash function* consists of a (probabilistic polytime)
26key generation algorithm Gen(n) as before and a polytime function H
27taking as input a key s ("seed") and m:{0,1}^* then
28H_s(m):{0,1}^{l(n)} where l(n) is a fixed, and typically simple,
29length function, e.g. l(n)=n.
30
31There may also be another length function l'(n)>l(n) and
32H_s:{0,1}^{l'(n)} -> {0,1}^{l(n)}. In that case, we have a
33fixed-length hash function.
34
35Definition: A hash function Pi=(Gen,H) as above is *collision resistant* if
36for all probabilistic polytime adversaries A one has
37
38 Pr[Hash-coll_{A,Pi}(n)=1] = negl(n)
39
40for some negligible function negl(n). Here, Hash-coll_{A,Pi}(n) is the
41following experiment:
42
431) s <-Gen(n) /* s = "seed" */
442) A is given s and then outputs x,x'
453) The result of the experiment is 1 if x=/=x' and H_s(x)=H_s(x') and
460 otherwise.
47
48Thus, the adversary must provide a collision given a key s and the
49probability that it succeeds in doing so should be negligible. In
50contrast, in the case of MACs the adversary does not get access to the
51key.
52
53
54
55Weaker notions of security
56- - - - - - - - - - - - - -
57
58In this context one may ask why being able to produce a collision
59should be considered dangerous. Firstly, if a hash function is
60collision resistant then it follows that it is also not possible to
61forge a message x' =/=x such that H(x)=H(x') given x. So collision
62resistance is certainly a "good enough" notion. However, one could
63instead ask for the weaker property of "second preimage resistance":
64it should be difficult to, given x, produce x'=/=x such that
65H(x)=(x').
66
67A typical application of hash functions is message integrity: If we
68send someone a message x via some untrusted channel (which can be
69modified by an adversary) and the hash value t=H(x) via a trusted
70channel then the receiver can check that the message has not been
71tampered with by checking that t=H(x') with x' being the received
72(possibly modified) message.
73
74While being able to produce an arbitrary collision may be harmless,
75being able to find a collision in a given set of texts of size ~
762^{l(n)} can be very dangerous and is not covered by "second preimage
77resistance": Consider the following scenario: we produce a letter L,
78have its hash signed by a responsible person, and then send it to some
79recipient. Now, it is very easy to produce functions
80f,g:{0,1}^{l(n)}->{0,1}^* such that for each z the string f(z) is,
81say, a different rejection letter, and g(z) is a different acceptance
82letter. E.g. by introducing various switches dear/esteemed, Sir/Madam
83or pleased/delighted etc. Or, if one is dealing with images rather
84than letters by slightly altering intensity values. Then if, one can
85produce z, z' such that H(f(z))=H(g(z')) one can have the hash
86t=H(f(z)) signed and communicate along with g(z'), for which the hash
87is also valid due to the collision. While this still requires
88collisions of a special kind it is sufficiently close to arbitrary
89collisions and for this reason one considers collision resistance as
90the "gold standard" for hash functions.
91
92
93
94Birthday paradox
95- - - - - - - - -
96
97Let us see, how many steps a brute force attack requires. In order to
98do that, we (simplifyingly) assume that H_s is a random function. Let
99us write H(x)=H_s(x). So we assume that H is drawn uniformly at random
100from {0,1}^*->{0,1}^{l} where l=l(n).
101
102Clearly, if we fix x then the likelihood for x' drawn uniformly at
103random to satisfy H(x)=H(x') is 2^{-l(n)} and thus, we need to try out
104ca N/2 values (N=2^l) to get a 50% success probability. This also
105holds, if x has been drawn at random. Things are different, if we
106randomly choose a set of values S and then *search* for a collision
107within S. Of course, if |S|>N then we find a collision with certainty,
108but perhaps surprisingly |S|>=2*sqrt(N) ensures that the likelihood of
109a collision within S is above 50%.
110
111So, to find a collision one can choose a set S of size 2*sqrt(N), sort
112it according to hash values and then search (in linear time) for the
113desired collision. If one does not find one, repeat with new data.
114
115Thus, for example if l(n)=64 then trying out 2^63 values will (with
116probability >=50%) lead to a collision with a fixed left hand side,
117but trying out 2^33 values will suffice to get an arbitrary collision
118using the birthday paradox. While 2^63 steps can only be carried out
119with special hardware resources, carrying out ~2^33 steps is trivial on
120today's computers. One must bear this in mind when trying to estimate
121"bits of security" of a hash function. Even assuming that the hash
122function does not contain systematic security holes we will only get
123one half of the hash size (size of the digest) many bits of security.
124
125
126
127Improved birthday attack
128- - - - - - - - - - - - -
129
130The implementation of the "birthday attack" sketched above takes not
131only roughly O(sqrt(N)) steps but also O(sqrt(N)) memory which is a
132more expensive resource. Indeed, storing 2^33 thirty-two byte words
133requires 64TB. We now describe a version of the birthday attack that
134runs in constant space.
135
136If we choose x0:{0,1}^l uniformly at random then, assuming as we did,
137that H is a random function then
138
139S={x0,H(x0),H(H(x0)),H(H(H(x0))),...,H^{2*sqrt(N)-1}(x0)}
140
141is also random and thus contains a collision with >=50%
142likelihood. Let us write xi:=H^i(x0). Suppose that i,j are such that
143xi=xj, but x_{i-1} =/= x_{j-1}, so x_{i-1},x_{j-1} form a
144collision. Note that xi=H(x_{i-1}). Assuming i<j and writing j=i+d we
145then also have x_i=x_{i+kd} for all k>=0 and thus x_{i+z}=x_{i+kd+z}
146for all k>=0 and z>=0. If we choose k such that kd>=i then
147x_{kd}=x_{2kd} follows with z=kd-i.
148
149This suggests the following
150algorithm for finding a collision with high likelihood:
151
152x0 <- {0,1}^l /* uniformly at random */
153x = x0;y = x0;
154for (r=1..4*sqrt(N)) {
155 x = H(x); /* x=H^r(x0) */
156 y = H(H(y)); /* y=H^{2r}(x0) */
157 if (x==y) break;}
158if (x!=y) start over with new x0; else
159y=x;x=x0; /* y=H^{kd}(x0) */
160if (x==x0) start over with new x0; else /* very unlikely */
161for (i=0..r) do {
162 x = H(x); /* x=H^i(x0) */
163 y = H(y); /* y=H^{i+kd}(x0) */
164 if (x==y) break; /* must happen before loop runs out */}
165return H^{i-1}(x0),H^{i+kd-1}(x0); /* can optimize recomputation */
166
167
168
169Merkle-Damgard Transform
170- - - - - - - - - - - - -
171
172The Merkle-Damgard Transform constructs a collision-resistant hash
173function (Gen,H) from a given *fixed length* collision-resistant hash
174function (Gen,h) with length 2*l(n), i.e. the h-hash is half as long
175as the input. The key generation remains unchanged and H is as follows.
176
1771) Given key s and input x:{0,1}^* divide message into blocks x1,x2,...,x_B
178of length l=l(n) possibly padding the last block with zeroes. Set x_{B+1}=L.
179
1802) Set z0=0...0 /* l zeroes */
181
1823) for i=1..B+1 do zi = h_s(z_{i-1} || x_i)
183
1844) Output z_{B+1}
185
186
187 x1 x2 x_B L
1880 | _____ | _____ | _____ | _____
189| |_| | |_| | |_| | |_| |
190|___| h_s |______| h_s |_...._____| h_s |_____| h_s |-----> H_s(x)
191 |_____| |_____| |_____| |_____|
192
193
194Theorem: If (Gen,h) is a collision-resistant fixed length hash
195function of length l'(n)=2*l(n) then (Gen,H) is a collision-resistant
196hash function.
197
198Proof: We first show that any collision in H_s yields a collision in
199h_s. Suppose that H_s(x)=H_s(x') and write x_1..x_B,L for the blocks
200and length of x and x'_1..x'_B' L' for x'. Also write z_1..z_{B+1},
201z'_1..z'_B' for the intermediate results. We have H_s(x)=h_s(z_B||L)
202and H_s(x')=h_s(z'_B'||L'), so, if L=/=L' we already have produced the
203desired collision in h_s. This also holds, if L=L' and z_B =/= z'_B
204(notice that B=B' in this case). If L=L' and z_B=z'_B then, since
205z_B=h_s(z_{B-1}||x_B) we get a collision unless x_B=x'_B. Continuing
206in this way, we eventually find our collision since x_i =/= x'_i for
207at least one i.
208
209Now, suppose that A is an adversary against H_s. We construct an
210adversary A' against h_s as follows. If A outputs x,x' we check
211whether H_s(x)=H_s(x') and if so, construct the corresponding
212collision h_s(y)=h_s(y') in h_s as described above and output
213y,y'. Otherwise, we output 0,0. The likelihood for succeeding, i.e.,
214for the output to be a h_s-collision is negligible by assumption and
215thus the probability that A output a collision is negligible as
216well. Notice that the computations we carried out as A' were clearly
217in polynomial time. QED
218
219The well-known and standardized cryptographic hash functions MD5,
220SHA-1, SHA-2 use the Merkle-Damgard transform. The underlying
221fixed-length hash function (called compression function) in this
222context is built using the heuristic principles that were described in
223Section 7 (Practical block ciphers. Principles: s/p- and Feistel
224networks). We remark here that MD5 and SHA-1 are no longer consider
225sufficiently secure whereas SHA-2 is.
226
227The latest standard SHA-3 which is not yet widely used but might
228eventually supersede SHA-2 does not use Merkle-Damgard but instead
229relies on the so-called *sponge construction*, see Wikipedia.
230
231
232
233MACs from hash functions
234- - - - - - - - - - - - -
235
236A natural question is whether one can use hash functions also for the
237purpose of authentication, i.e. MAC. First, we note that naive
238attempts (which according to KL have been actually used in practice!)
239
240
241do not work. Consider for example the definition Mac_k(x) = H_s(k||x)
242where s is some public seed. If H_s was constructed with the
243Merkle-Damgard transform from h_s then we can easily forge MACs as
244follows: if t is the MAC of x then t'=h_s(t||L') is the
245MAC of (x || |x|) (glossing over the padding).
246
247Suppose that we are given a *fixed-length* MAC (Gen,Mac) capable of
248authenticating messages of length l(n). Suppose furthermore, that we
249have a collision-resistant hash function (Gen',H) which produces
250hashes of length l(n). We can then build a MAC (Gen'',Mac'') for
251arbitrary length messages as follows:
252
253Gen''(n): k<-Gen(n); s<-Gen'(n);return (k,s) /* use some encoding of pairs */
254Mac''_{(k,s)}(m): return Mac_k(H_s(m))
255
256Theorem: Assuming that (Gen,Mac) is secure and (Gen',H) is
257collision-resistant then (Gen'',Mac'') is secure.
258
259Proof: Suppose that an adversary A asks questions Q and then succeeds
260in forging a MAC t=Mac''_{(k,s)}(x), i.e., x is not in Q. If H_s(x) is
261different from all the H_s(y) for y:Q then A has succeeded in forging
262a MAC for Mac_k. Namely then t=Mac_k(H_s(x)) and H_s(x) was not
263previously asked. If, however, H_s(x) is contained in {H_s(y) | y:Q}
264then A has produced a collision. Since both events occur with
265negligible probability the probability that A can forge a MAC is also
266negligible. QED
267
268Suppose that H_s() above has been constructed using the Merkle-Damgard
269construction from the fixed-length hash function h_s(). For seed s
270define a fixed-length MAC by
271
272 Mac_k(m) = h_s(k||m)
273
274We now make the assumption that h_s() is such that this is a secure
275fixed-length MAC. Notice that the abovedescribed extension attack on
276MACs of this sort does not apply due to the fixed length.
277
278If we now apply the above hash-and-MAC construction then it turns out
279that the arbitrary-length MAC obtained satisfies "essentially"
280
281Mac''_{(k,s)}(m) = H_s(k||H_s(m))
282
283because the last H_s degenerates to h_s due to the shortness of
284H_s(m). The quoted "essentially" refers to the fact that for this
285equation to hold exactly one needs to assume some conventions about
286how exactly the padding in the Merkle-Damgard construction is
287performed. We want to ignore these details here and refer to the
288literature.
289
290
291The HMAC construction
292- - - - - - - - - - -
293
294The widely used and standardised HMAC construction is essentially the
295above except that another key is added to the message m prior to
296invoking the inner hash function and that the two keys that are thus
297needed are derived from a single one by XOR-ing with certain fixed
298words ipad and opad:
299
300HMAC_{(k,s)}(m) = H_s( (k+opad) || H_s((k+ipad) || m))
301
302In practice, ipad and opad are chosen to be 00110110 and 01011100 each
303repeated as often as necessary.
304
305The additional inner keying with k+ipad allows one to weaken the
306assumptions on the collision freeness of H_s(). The details of these
307assumptions and their practical relevance are still subject to debate
308(see a 2012 paper by Koblitz and Menezes); however, no practical
309attack has been found to date and HMAC is considered secure in
310practice.
diff --git a/ss2017/cryptography/Notes12.txt b/ss2017/cryptography/Notes12.txt
new file mode 100644
index 0000000..a1299d7
--- /dev/null
+++ b/ss2017/cryptography/Notes12.txt
@@ -0,0 +1,274 @@
112 Number theory and hardness assumptions
2-----------------------------------------
3
4The next few sections are about *public-key cryptography* (different
5keys for encryption and decryption, one public, the other
6private). This area makes heavy use of number theory, in particular
7arithmetic. In this section we review the necessary mathematics and
8formulate hardness assumptions on which the security of public key
9cryptography is based.
10
11We assume standard knowledge about
12
13- arithmetic: division with remainder, gcd, extended Euclidean
14algorithm, i.e. for all integers u,v, there exists integers s, t such
15that gcd(u,v)=su+tv, Chinese remainder theorem, modular arithmetic, in
16particular inverses modulo.
17
18- groups: additive and multiplicative notation; exponentiation; the
19 additive group Z_N (addition modulo N); the multiplicative group
20 (Z_N)^* of order phi(N) (Euler's phi function); the consequence
21 x^(phi(N)) = 1 (mod N) and the special case x^{p-1}=1 (mod p); the
22 group isomorphisms derived from the Chinese remainder theorem (Z_pq
23 =~= Z_p x Z_q, Z_pq^* =~= Z_p^* x Z_q^*), primitive elements in
24 Z_p^* (cyclicity of Z_p^*).
25
26The required knowledge is part of "Logik und Diskrete Strukturen" and
27can also be looked up in KL.
28
29Next, we discuss the computational complexity of various arithmetic
30operations. We always measure runtimes in terms of the *sizes*
31(lengths in binary representation) of the numbers in question. Notice
32that the size of a number n is O(log(n)). The basic arithmetic
33operations +,-,*,/ can be performed in polynomial time (in terms of
34the sizes) with the standard algorithms taught at school. The same is
35true for gcd-computations using Euclid's algorithm. Furthermore,
36computing modular powers, i.e. a^b mod N can also be done in
37polynomial time using repeated squaring based on the binary expansion
38of N. Note though that a^b cannot be computed in polynomial time
39simply because the result is too long.
40
41Testing whether a given number n is prime can also be done in
42polynomial time; the most efficient algorithms for this use
43probabilistic polynomial time computation, however. This means that
44one has randomised algorithms which given a number n answer either
45"composite" in which case n is definitely composite or "prime" in
46which case n is prime except for a negligible error probability. The
47simplest of these tests is the Miller-Rabin test (KL 7.2.2).
48
49Using such a primality test it is also possible to generate a random
50prime number of a given size s. To that end one chooses random n of
51size s and then tests n,n+1,n+2,n+3,... for primality until a prime
52number has been found. Theorems about the distribution of prime
53numbers assert that this search is successful after a small (in any
54case expected polynomial) time.
55
56
57Factoring
58- - - - -
59
60The factoring problem asks the following question. Given a natural
61number N find a non-trivial factor of N unless N is prime (as usual
62the trivial factors are 1 and N).
63
64If N is even or has some other small divisor then this question is
65easily solved by trial division (the factoring method taught at
66school). If, however, N has only large factors, e.g. is the product of
67two primes of roughly equal size then factoring is believed to be a
68very hard problem and at any rate no efficient algorithm is
69known. Notice that trial division is linear in sqrt(N) hence
70exponential in the size of N. (sqrt(N)=2^{1/2*log(N)}). There do exist
71better algorithms for factoring, but with today's technology finding
72out the factors of a product of two ~512bit primes must be considered
73infeasible with a broad security margin.
74
75
76RSA Cryptosystem
77- - - - - - - - -
78It is believed to be hard to reconstruct x from x^e knowing merely N
79and e so this procedure is used as the basis of a public key
80cryptosystem: RSA. Intuitively, Enc_e(x)=x^e mod N and Dec_d(y)=y^d
81mod N. The encryption key e can be publicized whereas the decryption
82key d must be kept private.
83
84Consider the situation where N=pq for primes p,q. The ring Z_N of
85integers mod N contains phi(N)=(p-1)(q-1) invertible elements. Recall
86that x:Z_N is invertible if gcd(x,N)=1. The elements with a gcd > 1
87are the multiples of p and of q of which there are (q-1) + (p-1) + 1
88with the last summand corresponding to 0=pq. Thus, the number of
89invertible elements is pq-q-p+1 = (p-1)(q-1). Equivalently, with the
90Chinese Remainder Theorem we have Z_N =~= Z_p x Z_q and the invertible
91elements correspond to those pairs (x,y):Z_p x Z_q where x=/=0 and
92y=/=0.
93
94The (multiplicative) group Z^*_N of invertible elements (mod N) thus
95has order /* number of elements */ phi(N)=(p-1)(q-1). For each element
96x:Z^*_N it holds that x^phi(N) = 1 (mod N) (general result about
97groups).
98
99Now suppose that we have e such that gcd(e,phi(N))=1 and ed=1
100(mod phi(N)). Then we can solve the RSA problem,
101 i.e. determine x such that x^e = y mod N for given y, N, e.
102More precisely, if x:Z^*_N we can recover x from y:=x^e as y^d
103(all computations done mod N). Indeed, (x^e)^d = x^{ed} =
104x^{t*phi(N)+1} = x (for any t).
105
106
107Security of RSA relative to factoring
108- - - - - - - - - - - - - - - - - - -
109
110If given e we are able to find d such that x^{ed}=x holds for all
111invertible (mod N) x then we can find the factors of N as follows:
112Namely, in this case, we have a value a (=ed-1) such that x^a=1 (mod
113N) holds for all x:Z^*_N. Such value must necessarily be even as can
114be seen by taking x=-1. Now we can successively divide a by two until
115we have found a value b such that x^{2b} = 1 (mod N) holds for all x
116but x^b =/= 1 for some x. The crucial observation is that once x^b =/=
1171 for some x then x^b =/= 1 for at least 50% of all x so we can find
118such a witness value x by repeated guesses. The reason for the 50%
119bound is that {x | x^b=1} is a proper subgroup of Z^*_N and its order
120must therefore be a proper divisor of |Z^*_N|=phi(N).
121
122So, summing up, we are in possession of a value b such that x^{2b}=1
123for all x, but x^b=1 not for all x. Let us consider u := x^b mod p and
124v := x^b mod q. Since u^2=v^2=1 we have u,v:{-1,1}. Moreover, by the
125Chinese Remainder Theorem, we have Z_N^* =~= Z_p^* x Z_q^* so that if
126x is chosen uniformly at random then u and v are also uniformly at
127random and independent. As before, if one of them *may* be =/=1 then
128this happens for at least 50% of them. As a result, under the
129assumptions, the event u*v=-1 has a a likelihood of at least 50% and
130in this event gcd(x^b-1,N) yields a nontrivial divisor of N.
131
132
133Unfortunately, there is no known reduction from RSA to factoring in
134the sense that we would be able to prove that RSA is semantically
135secure on condition that factoring is hard. Namely, notwithstanding
136the above, it might be possible to break RSA without actually
137producing an exponent d such that x^ed=1 mod N. To date, it is not
138known whether RSA is sec ure relative to factoring, let alone in
139itself.
140
141
142RSA hardness assumption
143- - - - - - - - - - - -
144
145The computational hardness of RSA is thus not proven and not reducible
146to factoring but at least to some extent plausible. It is thus
147justified to formulate the following RSA hardness assumption.
148
149There exists a randomised polynomial time algorithm GenRSA() which
150given security parameter n produces (N,e,d) such that N is the product
151of two primes N=pq and d = e^{-1} mod phi(N) and such that the following
152experiment has negligible success property for all probabilistic polynomial time adversaries A:
153
154RSA-inv_A(n):
155
1561. Run GenRSA(n) to obtain (N,e,d)
1572. Choose x<-Z^*_N
1583. A is given N,e, and x^e mod N and outputs x'
1594. The output of the experiment is 1 if x=x' and 0 otherwise.
160
161
162It is believed that the RSA assumption holds with GenRSA(n) selecting
163two random primes of length n, choosing e at random and outputting
164(pq,e,e^{-1} mod phi(N)).
165
166
167Groups for cryptography
168- - - - - - - - - - - -
169
170A *group generating* algorithm G(n) is a probabilistic polynomial time
171algorithm which given security parameter n produces a description of a
172group G_n whose order is polynomial in n. The description of the group
173comprises generators, a well-formedness test, testing whether a given
174bitstring encodes a group element or not and algorithms implementing
175multiplication and inverses on these representations.
176
177For example, G(n) might determine a random prime p of length n and
178then return an algorithmic description of the group Z_p^*. As for a
179generator, it could produce a primitive element.
180
181For some applications, groups of prime order are preferred. One
182example of those is the following: If q is a prime such that p=2q+1 is
183also prime (p is then called a "strong prime") then the subgroup of
184Z^*_p consisting of the elements of the form y^2 for y:Z_^*p (the
185quadratic residues mod p) form a subgroup of Z^*_p of order q which by
186assumption is prime.
187
188Further examples are furnished by groups of points on an elliptic
189curve. The elements of such a group are pairs (x,y) of elements of
190a finite field GF(q) (q prime) such that
191
192 y^2 = x^3 + Ax + B
193
194holds for fixed parameters A, B which thus determine the elliptic
195groups. In addition to these pairs (x,y) the group contains a special
196element O.
197
198For example, if the field is GF(7) = Z_7 and A=B=3 then the group (the
199elliptic curve) has elements (1,0), (3,2), (3,5), (4,3), (4,4),
200O. Indeed, whenever x^3+3x+3 is (zero or) a quadratic residue mod 7 we find (one
201or) two points and otherwise not.
202
203The group operation, i.e. how elements of the group are added (or
204multiplied, depending on notation), is omitted for now.
205We come back to it later.
206
207
208
209
210
211Discrete logarithm and Diffie Hellman
212- - - - - - - - - - - - - - - - - - -
213
214Given a cyclic group G with generator g the discrete logarithm problem
215is the following: given h:G determine e such that h=g^e. Formally,
216suppose that we are given a group generating algorithm G(n) outputting
217for each n a cyclic group G_n and a generator g.
218
219For adversary A the experiment DLog_{A,G}(n) then is the following:
220
2211. Run G(n) to obtain (G,q,g) where G is a cyclic group of order q
222with generator g.
223
2242. Choose h<-G /* e.g. by putting h=g^d for d<-Z_q */
2253. A is given G,q,g,h and outputs e:Z_q
2264. The output of the experiment is 1 if g^e = h
227
228By definition, the discrete logarithm problem is hard for G() if for
229all adversaries A one has Pr(DLog_{A,G}(n)=1) = negl(n).
230
231It is generally believed that discrete logarithm is hard for the
232aforementioned example groups.
233
234Related problems are computational Diffie-Hellman (CDH) and decisional
235Diffie-Hellman (DDH).
236
237Computational Diffie-Hellman: given a cyclic group G of order q and
238generator g as above and h=g^x, h'=g^y determine (without knowing x,y !)
239the value g^{xy}.
240
241Decisional Diffie-Hellman: given a cyclic group G of order q and
242generator g as above and h=g^x, h'=g^y and h''=g^z determine (without
243knowing x,y,z !) whether or not g^{xy}=g^z.
244
245Clearly, a solution to the discrete logarithm problem implies a
246solution to Diffie-Hellman, but the converse is not known. As a
247result, hardness of discrete log is a weaker assumption than hardness
248of DDH (and CDH)
249
250Diffie-Hellman is important for the eponymous Diffie-Hellman
251key-exchange protocol: In order to share a common secret key Alice may
252choose random x:Z_q and send u=g^x to Bob. Bob does the same and thus
253sends v=g^y to Alice. Now, Alice and Bob can both compute the shared
254key g^{xy} as u^x (Alice) and v^y (Bob). We will show later that
255assuming DDH is hard this scheme is secure in a precise sense.
256
257Formal definition of hardness of DDH:
258
259Given a group-generating algorithm G() producing cyclic groups as
260above, we say that the decisional Diffie Hellman problem is hard for
261G() if for all probabilistic polynomial-time adversaries A and all n we have
262
263 |Pr(A(G,q,g,g^x,g^y,g^z)=1) - Pr(A(G,q,g,g^x,g^y,g^{xy}))| = negl(n)
264
265where G(n)=(G,q,g) and x,y,z <- Z_q.
266
267Thus, DDH is hard, if g^{xy} looks like a random element of G even if
268g^x and g^y are known.
269
270We close this chapter by remarking that under the assumption that RSA
271is hard thre exist pseudo random generators, pseudorandom functions,
272and permutations (see KL6 and 7.4.1). Under the assumption that
273discrete logarithm is hard for some group then there exist collision
274resistant hash functions. (KL7.4.2).
diff --git a/ss2017/cryptography/Notes13.txt b/ss2017/cryptography/Notes13.txt
new file mode 100644
index 0000000..b8e5f0a
--- /dev/null
+++ b/ss2017/cryptography/Notes13.txt
@@ -0,0 +1,162 @@
1
2
313 Diffie-Hellman key exchange and RSA
4--------------------------------------
5
6
7Diffie Hellman
8- - - - - - - -
9
10As already mentioned, the Diffie-Hellman key exchange system allows
11two people, say Alice and Bob, who do not share any secret information
12to obtain a shared secret key (which can then for example be used for
13subsequent private key cryptography). It thus avoids the need for the
14sharing of secret keys which is difficult in practice and involves
15trusted third parties or similar (see KL9.1-3 for a discussion).
16
17We now formalize what should be expected from such a key exchange protocol:
18
19The key exchange experiment KE^eav_{A,Pi}(n):
20
211. Two parties both holding n execute the protocol Pi. This results in
22 a transcript trans containing all messages exchanged and a string
23 ("key") k:{0,1}^n that is output by both parties. Thus, both
24 parties must output the same key.
25
262. b<-{0,1}. if b then k':=k else k'<-{0,1}^n
273. Adversary A is given trans and k' and outputs a bit b'.
284. Output = 1 iff b'=b
29
30The protocol Pi is deemed secure if the success probability for any
31prob.polytime adversary A is bounded by 1/2+negl(n).
32
33
34The Diffie-Hellmann protocol Pi for some cyclic group (generating
35algorithm) G() now works as follows:
36
371. Alice runs (G,q,g) := G(n) and sends (G,q,g) to Bob.
382. Alice chooses x<-Z_q and computes h1:=g^x
393. Alice sends (G,q,g,h1) to Bob
404. Bob chooses y<-Z_q and sends h2:=g^y to Alice. Bob then outputs k_B:=h1^x
415. Alice outputs k_A:=h2^x /* Note that k_A=k_B=g^{xy} */
42
43We will now show that the Diffie-Hellman protocol is secure under the
44assumption that DDH is hard for the group in question and the further
45assumption that the random key k' chosen in the KE^eav experiment is a
46random element of G rather than an arbitrary random string. Let us
47call KE'^eav the thus modified experiment. We note that a random group
48element can be taken of the form g^z for z<-Z_q.
49
50We now have
51
52Pr(KE'^eav_{A,Pi}(n)=1) = 1/2*Pr(KE'^eav(n)=1 | b=1) + 1/2*Pr(KE'^eav(n)=1 | b=0) =
531/2*(Pr(A(G,g,q,g^x,g^y,g^{xy})=1)+ Pr(A(G,g,q,g^x,g^y,g^z)=0)) =
541/2+1/2*(Pr(A(G,g,q,g^x,g^y,g^{xy})=1)- Pr(A(G,g,q,g^x,g^y,g^z)=1)) <=
551/2+1/2*|Pr(A(G,g,q,g^x,g^y,g^{xy})=1)- Pr(A(G,g,q,g^x,g^y,g^z)=1)| <=
561/2 + 1/2*negl(n) /* assuming hardness of DDH for G() */
57
58We remark that while (under assumptions) Diffie-Hellman is secure
59against passive eavesdroppers it is vulnerable against more active
60adversaries that may also send, modify, and swallow messages during
61the run of the protocol. Achieving security against those requires
62some means of authenticating messages sent between the parties; a
63precise formulation of the additional assumptions needed for this is
64beyond the scope of this book.
65
66
67
68Public key cryptosystems
69- - - - - - - - - - - - -
70
71We give a formal definition of a public key cryptosystem and its
72security.
73
74
75Definition: a public key cryptosystem Pi comprises
76
77-) a (probabilistic) key generation algorithm Gen() which given
78 security parameter n outputs a pair of keys (pk,sk) /* public, secret
79 */
80
81-) a (probabilistic) encryption algorithm which given plaintext m from
82some message space and the public key pk produces a ciphertext c:
83c<-nc_pk(m)
84
85-) a deterministic decryption algorithm which given ciphertext c and
86the secret key sk produces a plaintext m<-Dec_sk(c) in such a way that
87if c<-Enc_pk(m) then Dec_pk(End_sk(m)) = m.
88
89
90Definition: A public key scheme Pi is semantically secure in the
91presence of an eavesdropper if the for all (prob. polytime)
92adversaries A the success probability in the following experiment is
93bounded by 1/2+negl(n).
94
95Experiment PubK^eav_{A,Pi}(n):
96
971. (pk,sk)<-Gen(n)
982. Adversary A is given pk and outputs messages m0 m1
993. b <- {0,1}; c <- Enc_pk(m_b); c is given to A
1004. A outputs a bit b'
1015. Outcome is 1 if b=b' and 0 otherwise End of definition
102
103
104We notice that this is just like semantic security in the private key
105setting except that the adversary has access to the public key which
106after all is supposed to be public. This means that, since by
107Kerckhoff's principle, the encryption algorithm is also public, the
108adversary has access to an encryption oracle and thus---in the public
109key setting---semantic security in the presence of an eavesdropper
110(the one above) is as powerful as cpa security.
111
112This has the consequence that no public key cryptosystem in which
113Enc_pk() is deterministic can be semantically secure. Indeed, all the
114adversary has to do in this case is to precompute the encryptions of
115its chosen messages m0 and m1.
116
117We remark that a semantically secure public key cryptosystem can be
118combined with any cps-secure private key system by first using the
119public key to transmit a secret key. This is known as *hybrid
120encryption*. One can show (Theorem 10.13 of KL) that hybrid encryption
121yields semantically secure public-key encryption schemes.
122
123
124
125RSA cryptosystem
126- - - - - - - - -
127
128For this reason, the "textbook RSA" cryptosystem, as indicated in the
129last chapter, is actually insecure. In order to make it work, it must
130be enhanced with randomization for example as follows.
131
132Fix a length function l(n).
133
134Gen(): On input n run GenRSA(n) to obtain (N,e,d). Output
135 pk=(N,e) and sk=(N,d)
136Enc(): On input m:{0,1}^l(n) and pk=(N,e) choose
137 r<-{0,1}^{||N||-l(n)-1} and output c=(r||m)^e mod N
138 /* the -1 is there to make sure that r||m is in Z_N^* */
139Dec(): On input c and sk=(N,d) compute m'=c^d mod N and output the l(n)
140 low-order, i.e. rightmost, bits of m'
141
142Now, if the "padding" r is too short, then this does not help because
143an adversary could try out all possible values for r. It is believed
144that when r has a length comparable to |m|, then the above scheme is
145secure (relative to the RSA assumption), but unfortunately, no proof
146has been found. According to KL (Theorem 10.19) one can show that the
147scheme is secure when l(n)=O(log(n)), again under the RSA
148assumption. Note that this means that in order to increase the message
149size by just one bit one has to double the security parameter and
150hence the length of the modulus N and the ciphertexts.
151
152In practice, one does not want to waste so much bandwidth on the
153padding and uses heuristic schemes like e.g. RSA-PKCS#1v1.5 which uses
154a random padding string of length at least 64bit.
155
156Another, more modern, method is RSA-OAEP which mixes the padding with
157the actual plaintext by way of a Feistel network of cryptographic hash
158functions. Intuitively, this makes the input to the actual RSA
159encryption look like a random string which then makes the RSA
160assumption applicable. Viewed more practically, it prevents attacks
161which only recover parts of the plaintext. In the random oracle model
162(Lecture 16) RSA-OAEP can be proved semantically secure.
diff --git a/ss2017/cryptography/Notes14.txt b/ss2017/cryptography/Notes14.txt
new file mode 100644
index 0000000..e6075ff
--- /dev/null
+++ b/ss2017/cryptography/Notes14.txt
@@ -0,0 +1,208 @@
114 El Gamal and elliptic curve cryptography
2-------------------------------------------
3
4The El Gamal cryptosystem is based on the DDH assumption and is
5provably secure under the assumption of the latter. Just like DH-key
6exchange it is parametrised by a group (generating algorithm) G(n) and
7works as follows:
8
9Gen(n) :
10 (G,q,g) = G(n)
11 x <- Z_q
12 h <- g^x
13 pk = (G,q,g,h)
14 sk = (G,q,g,x)
15 output (pk,sk)
16
17Enc_(G,q,g,h)(m) :
18 check that m:G
19 y <- Z_q
20 c = (g^y,h^y*m)
21 output c
22
23Dec_(G,q,g,g,x)(c1,c2) :
24 m = c2 / c1^x
25 output m
26
27
28Let us first see that this scheme is correct: If c1=g^y and c2=h^y*m
29where h=g^x then c2 / c1^x= g^(xy) * m / g^(xy) = m
30
31We also notice that messages and ciphertexts are actually elements of
32the group G which must therefore by somehow encoded as binary
33strings. This can be done in various ways for the various groups, see
34KL for details.
35
36Theorem: If the DDH assumptions holds for a group (generating
37algorithm) G() then the El Gamal cryptosystem basd on G() is
38semantically secure.
39
40Proof: Let A be an adversary against the El Gamal system and let its
41success probability be 1/2+eps(n). We must show that eps(n) is
42negligible. We construct from A an adversary A' as in the DDH
43assumption.
44
45Suppose that A' receives g^x, g^y, u where u is either g^(xy) or g^z
46for random z and A' is to decide which of the two.
47
48We forward (G,q,g,g^x) as "public key" to A and wait for it to output
49m0,m1:G. We choose a random bit b and build c = (g^y,u*m_b) and let b'
50be the bit that A returns.
51
52If u=g^(xy) then A is played with according to the rules of the El
53Gamal cryptosystem and therefore b'=b with probability 1/2+eps(n). If
54u=g^z for random z then u*m0 is also uniformly random (since x|->x*m0
55is a bijection G->G) and therefore the probability that b'=b is
56exactly 1/2. The difference between the two probabilities is precisely
57eps(n) which under the DDH assumption will be negligible. QED
58
59
60Elliptic curve cryptography
61- - - - - - - - - - - - - -
62
63As already mentioned, elliptic curves furnish a large reservoir of
64cyclic groups for which taking discrete logarithms, CDH, and DDH are
65believed to be hard. With existing algorithms, solving these problems
66on elliptic curve groups is consistently harder than doing so for
67groups of invertible elements mod p or in a finite field.
68
69Recall that an elliptic curve over some field F of characteristic =/=
702,3 is defined by two constants a, b and comprises the points (x,y)
71that solve the equation
72
73 y^2 = x^3 + ax + b
74
75Here, one assumes that the *discriminant* 4a^3+27b^2 =/= 0 for
76otherwise the curve might be *singular*, i.e. contain anomalies like
77isolated points, sharp bends ("cusps") or similar. When viewed over
78the reals such a curve looks roughly as follows:
79
80 | |
81 | /
82 - | - /
83 / | \ _ -
84 | |
85---------------------------------------------------------------------
86 | | - _
87 \ | / \
88 -| - \
89 | |
90
91Depending on the parameters the knob to the left may also become
92detached and form a closed loop sitting to the right. In either case
93whenever a line intersects the curve in two points it meets it again
94in a third point except when the line is parallel to the y-axis in
95which case we say that the third point of intersection is at infinity,
96here denoted O.
97
98This property also holds for curves over other fields, in particular
99finite ones which are of interest for cryptography. There is an
100explicit formula for obtaining the third point of intersection. To
101wit, if (x1,y1) and (x2,y2) lie on the curve then the line through
102them is y=m(x-x1)+y1 where m=(y2-y1)/(x2-x1). Plugging this into the
103curve yields
104
105 (m(x-x1)+y1)^2 = x^3+ax+b
106
107The three solutions of this equation are x=x1, x=x2, x=m^2-x1-x2, so
108the last one is the desired third point of intersection.
109
110Now, it is a remarkable fact that the points on the curve together
111with O form an abelian group, traditionally written additively, where
112the sum of points P and Q is obtained by first taking the third curve
113point on the line through P and Q, call it R=(x_R,y_R), and then
114reflecting R on the x-axis, i.e. P+Q=(x_R,-y_R).
115
116This, however, only applies when P=/=Q and when P and Q do not have
117the same x-coordinate. In the latter case, one has P+Q=O, the special
118point at infinity. In the former case, i.e. when P=Q, one must take
119the tangent through P and intersect it with the curve.
120
121One can show using implicit differentiation that the coordinates of
122that point are given by
123
124 (((3x_1^2+a)/2y_1)^2 - 2x1, -y1+((3x_1^2+a)/2y_1)^2(x1-x2))
125
126and this formula, just as the one above for the general case, also
127makes sense for finite fields where there are no "tangents". Yet
128another special case is when P or Q is O. One simply puts O+P=P+O=P.
129
130Curves over fields of characteristic 2 or 3 are also possible, but
131then both the defining equations and the formulas for addition of
132points become slightly different (notice e.g. that in the formula
133above we divide by 2). We refer to the literature, but stress that it
134is very important not to make mistakes with the implementation of the
135addition formulas and that doing so has lead to security flaws.
136
137We have already seen that addition of points is well-defined and
138commutative. It is also clear that the inverse of a point (x,y) is
139given by (x,-y), i.e. reflection on the x-axis. Associativity of
140addition follows from nontrivial results, e.g. the Weierstrass
141p-function, but can in principle also be validated "by hand" on the
142basis of the above formulas.
143
144For integer n and point P on a curve we use the notation n.P for
145P+P+...+P with summands. This is the same as the exponent notation in
146multiplicatively written groups. Therefore, the "repeated squaring"
147method can be used here as well:
148
149 100.P = 4.P+32.P+64.P = 2.(2.(P + 2.(2.(2.(P+2.P)))))
150
151Now, the plan is to use the groups coming from elliptic curves for
152cryptosystems like Diffie-Hellman key exchange or El Gamal. For this
153to work, a couple more considerations are in order: we need to encode
154plaintexts as points on the group and we need to ascertain that the
155group is cyclic or else move to a cyclic subgroup.
156
157In order to find a cyclic group one can rely on one of the publicly
158available and recommended curves. Many of them have a prime number of
159points and hence are cyclic with any element other than O being a
160generator. Alternatively, one can try out random coefficients a and b
161until one finds a curve with a prime number of points. To do this, one
162needs to invoke Schoof's algorithm which allows one to determine the
163number of points on a given elliptic curve.
164
165If one would like to use a curve with a nonprime number, say N, of
166points, then one must factor N and it is then important that N has a
167large prime factor p, i.e. p>sqrt(N). In this case, by the
168representation theorem for finite(ly generated) abelian groups there
169is a subgroup of order p and any of its nonzero elements are
170generators. Moreover, the remaining subgroups have smaller order. To
171check whether a point P is in the subgroup of order p it suffices to
172check that p.P = O. To obtain a point in that subgroup one can pick a
173random point P and if Q := N/p.P =/= O then p.Q is in the subgroup,
174hence Q can serve as a generator.
175
176For the most, however, one uses one of the already publicised elliptic
177curves such as those recommended by the NIST "for government use".
178See http://csrc.nist.gov/groups/ST/toolkit/documents/dss/NISTReCur.pdf
179There is no need to choose a "fresh" curve for every application and
180on the other hand, some curves are "weak" and should be avoided.
181
182In order to encode plaintexts as points we can proceed as
183follows. First, we note that it suffices to store the x-coordinate of
184a point and a single bit telling whether the y-coordinate is above or
185below the x-axis, i.e., which of the two square roots of x^3 +ax+b are
186meant. This is known as point compression. As for the x-coordinates
187one fixes a bijection alpha between bitstrings of length l=log(q) and
188field elements. Now one puts t=l-k where k is chosen sufficiently
189large. Then, to encode message x of length t one searches for a string
190z of length k so that alpha(x||z) has a square root y over GF(q),
191i.e., is a quadratic residue. At that point, (alpha(x||z),y) can be
192taken as the desired encoding of x as a curve point. For random
193padding z the chance for alpha(x||z) to be a quadratic residue is
194about 1/2, so after a short number of iterations one is almost sure to
195find an appropriate encoding. We also remark that there exist
196efficient algorithms for testing whether a given field element is a
197quadratic residue and if so to compute its square root.
198
199With all this machinery in place, the Diffie-Hellman and El Gamal
200cryptosystems can be used with elliptic curve groups without any
201change, bearing in mind, of course, that instead of exponentiation
202g^x, we now use multiplication x.P and instead of multiplication we
203use addition, so that, e.g. the encryption of message m encoded as a
204point M becomes (y.P,y.Q+M) where P is the generator and Q=x.P
205
206We close by remarking that since the early 2000 elliptic curve
207cryptography (ECC) has become more and more common. Also the bitcoin
208cryptocurrency uses it.
diff --git a/ss2017/cryptography/Notes15.txt b/ss2017/cryptography/Notes15.txt
new file mode 100644
index 0000000..e76ada5
--- /dev/null
+++ b/ss2017/cryptography/Notes15.txt
@@ -0,0 +1,279 @@
1
2
315 Factoring and computing discrete logarithms
4----------------------------------------------
5
6In this chapter we survey algorithms for factoring large numbers, in
7particular products of equal sized primes, and for computing discrete
8logarithms. These algorithms or rather their runtime provide lower
9bounds on the necessary key lengths for public key cryptography for it
10relies on the difficulty of these problems.
11
12For the sections about factoring we let N=pq be a product of two
13roughly equal sized primes and n = O(log(N)) be the length of N in
14binary. The task is to find p,q from N.
15
16For the sections about discrete logarithms let G be a cyclic group of
17order q and g,y:G with g a generator. The task is to find x:Z_q such
18that g^x=y.
19
20Trial division
21- - - - - - - -
22
23In order to factor N=pq, i.e. to find p or q given N, we can try out
24divisors d=1...sqrt(N). The runtime of this is polynomial in sqrt(N),
25hence takes time exponential in n. Once n>120, hence ||sqrt(N)||=~=60
26this is no longer feasible.
27
28
29Pollard's p-1 method
30- - - - - - - - - - -
31
32Pollard's p-1 method may help when p-1 is a product of powers of small
33primes. We let p_1,...p_k be the first k primes and construct
34
35 B_k = prod_{i=1..k}p_i^{n / ||p_i||}
36
37The exponent n/||p_i|| is chosen so that if some power of p_i divides
38p-1 then that power is at most n/||p_i||. As a result, if p-1 is a
39product of powers of primes from among the set {p_1..p_k} then p-1 |
40B_k. If, in addition, q-1 does *not* divide B_k then we can find out p
41as we show shortly. In order that q-1 does *not* divide B_k we can
42repeatedly execute the method with increasing values for k hoping that
43at some point one of the two prime factors "works" and the other does
44not.
45
46OK so, now let B any number so that p-1 | B and q-1 does not divide
47B. For any x it holds that x^B mod p = 1 whereas with constant
48probability x^B mod q =/= 1. The former holds since the order of Z_p^*
49is p-1 and B is a multiple thereof. The latter holds since when x is a
50generator of Z_q^* then x^B mod q is not 1 and the proportion of those
51generators is about 50% (not hard to see or use Thm B.15 of KL).
52
53Now let y = x^B-1 mod N. We have y mod p = 0 and y mod q =/= 0. Thus,
54p divides y and q does not divide y so gcd(y,N)=p.
55
56The resulting algorithm is now as follows:
57
58for k=1,2,3,... do the following until either a factor of N is found
59or computing resources are exhausted.
60 Put B = B_k
61 for a certain number of times do the following
62 x<-Z_N
63 d = gcd(x^B-1 mod N,N)
64 if d=/=1 then a factor of N has been found.
65
66
67
68Pollard's rho method
69- - - - - - - - - - -
70
71This algorithm is based on the observation that once we have two
72distinct values x,y:Z_N such that x mod p = y mod p then p =
73gcd(x-y,N). Thus, factoring amounts to finding a collision in the
74"hash function" H(x) = x mod p. Notice that while we cannot compute
75this function we can detect whether x,y constitute a collision by gcd
76computation.
77
78Now, by the birthday paradox, a random set of size S := 2*sqrt(p) =
79O(N^{1/4}) contains such a collision with likelihood 50%. Finding it,
80requires S^2 collision tests thus, when implemented naively, this
81method is no better than trial division.
82
83However, the constant space method for collision detection described
84earlier only has a runtime of O(S), but of course, as already
85mentioned, we cannot compute H(). However, we can replace it with any
86function F which has the property that x = y (mod p) implies F(x)=F(y)
87(mod p) and which is such that for random x0 the set
88{x_0,F(x_0),F(F(x_0)),..., F^S(x_0)} is also sufficiently close to a
89random set so that it is likely to contain a collision. The function
90F(x)=x^2 + b for some b =/= 0, -2 mod N is believed to have this
91property and at any rate behaves well in practice. Just as in the
92earlier algorithm we have that F^i(x0) = F^j(x0) (mod p) implies
93F^k(x0) = F^{2k}(x0) (mod p) for some k.
94
95So, the set of the first S iterates of F() starting from random x0 is
96likely to contain a collision. But since once x,y form a collision so
97do F(x), F(y), it suffices to search for a collision among the pairs
98F^k(x0), F^{2k}(x0) which leads to the following algorithm:
99
100b <- Z_N \ {0,-2}
101F(x) = x^2+b mod N
102
103x <- Z_N
104y = x
105for k=1..2*sqrt(N) do
106 x = F(x); y=F(F(x))
107 if gcd(x-y,N) != 1 a factor is found.
108
109repeat the whole procedure until either a factor is found or resources
110are exhausted.
111
112Assuming that the function F() has the required properties (which has
113not been proved to this date!) the runtime of this algorithm is
114proportional to N^{1/4} which is still exponential in n but requires
115one to double n if one wants to stay immune against this
116method.
117
118
119The quadratic sieve method
120- - - - - - - - - - - - - -
121
122The starting point for the most efficient factoring algorithms to this
123date is the following observation made by Pierre de Fermat:
124
125If we succeed in expressing N as the difference of two
126squares N=x^2-y^2 then N=(x+y)(x-y) so we have factored N.
127
128Fermat suggested to try out successive values for x starting at
129sqrt(N) and for each of those checking whether x^2-N is a square.
130
131The first improvement one can make on this observation is that it
132suffices that N divides x^2 - y^2 for if kN = (x+y)(x-y)
133then---assuming that x != (+/-)y mod N---the factors p and q of N
134must straddle the product so that gcd(x-y,N) or gcd(x+y,N) will be
135different from 1.
136
137Thus, we seek x,y:Z_N such that x^2-y^2 = 0 (mod N) and x !=y, x!=-y mod N.
138
139Notice that by the Chinese Remainder Theorem each square has four
140roots modulo N, so given x, two out of the four roots of x^2 are good.
141
142Now, to find such x,y more efficiently we proceed as follows. We
143select a set B of small primes and try out various values x>sqrt(N) so
144that x^2 mod N can be factored (because after reduction mod N it is
145sufficiently small) and its factors are in B. In this way, we find
146numbers x_1 .. x_l such that each x_i^2 mod N is expressed as a
147product of primes in B.
148
149With each of these numbers x_i we associate a B-indexed 0,1 vector
150whose entry at p:B is the exponent of p in the factorisation of x_i
151modulo 2.
152
153For example, if B={2,3,5,11} and x_1^2 mod N is 2^5*3^2*11^2 then the
154associated vector is (1 0 0 0).
155
156If l exceeds the size of k then there is a (mod 2) linear combination
157of these vectors which results in the all zero vector. But multiplying
158the corresponding x_i together then yields a square because all prime
159factors have even exponents.
160
161Continuing the example, if x_2^2 mod N is 2^15*11, i.e. (1 0 0 1), and
162x_3^2 mod N is 11^13, i.e. (0 0 0 1) then, since 1000+1001+0001=0000,
163we obtain the following identity mod N:
164
165 (x_1*x_2*x_3)^2 = (2^10 * 3 * 11^8)^2
166
167and, heuristically, we may assume that there is a 50% chance for this
168identity to be nontrivial in the sense that it yields a good pair of
169square roots.
170
171Summing up, we build up a large basis of values x whose squares mod N
172can be completely factored, then compute a linear combination (mod 2)
173of the zero vector from the corresponding B-indexed vectors and check
174whether the resulting identity of squares mod N is nontrivial which
175then yields the desired factor.
176
177We now study the problem of finding discrete logarithms in a cyclic
178group G as above.
179
180
181The Pohlig-Hellman algorithm
182- - - - - - - - - - - - - - -
183
184If we have a factorisation of the group order q as prod_{i=1}^n q^i
185with the q_i relatively prime (gcd = 1) then, if we have values x_i
186such that
187
188 (g^{q/q_i})^x_i = y^{q/q_i}
189
190we can find x by solving (using the Chinese Remainder Theorem) the
191system of modular equations
192
193 x mod q_i = x_i
194
195Since g^{q/q_i} generates a subgroup of order q_i which is easier if
196the q_i are small. It remains to see why x satisfies the above system
197of equations. Indeed, if g^x=y then g^{q/q_i}^x = y^{q/q_i} so x mod
198q_i solves the discrete log problem of order q_i.
199
200It remains to see how to deal with groups whose order is a prime power
201q=p^f. In this case, one can expand the unknown x as
202
203 x = x_0 + x_1 * p + x_2 * p^2 + ... + x_{f-1} p^{f-1}
204
205Now, by exhaustive search or using any other algorithm we can
206determine x_0:Z_p such that g^{q/p}^{x_0} = y^{q/p} (mod p). Once we
207know x_0 we can then recursively solve (g^p)^{x'} = y/g^{x_0} which
208yields x_1,... The details are left as an exercise.
209
210
211The giant-step baby-step algorithm
212- - - - - - - - - - - - - - - - - -
213
214Here the idea is that the unknown x can be decomposed as x =
215t*[sqrt(q)] + s for some s <sqrt(q). Here [sqrt(q)] stands for the
216greatest integer <= sqrt(q). We then precompute a table of the values
217y_t := g^{t*[sqrt{q}]} for t=0..sqrt(q), this are the giant
218steps. Now, for each s we look for (using binary search or similar)
219for a t such that
220
221 g^{t*[sqrt(q)]} = y*g^{-s}
222
223Once we have found it we can output x = s*[sqrt(q)]+t. The runtime of
224this method is O(sqrt(q)) which again essentially halves the "bits of
225security".
226
227
228The index calculus method
229- - - - - - - - - - - - -
230
231Unlike the earlier methods the index calculus makes special
232assumptions on the group G for which to solve the discrete logarithm
233problem. Namely, it must be the group Z_p^* for some prime p. It can
234be generalised to the group of invertible elements in a finite field,
235but does not work in the case of ellipic curves, for instance.
236
237So, let us assume that G=Z_p^* and that g,y:Z_p^*. As before, we seek
238x such that g^x=y. As before, we write q=p-1 for the group order.
239
240Let us write log_g(z) for the discrete logarithm of some value z:Z_p^*
241so that g^{log_g(z)} = z. The idea is to precompute a table of such
242logarithms. To that end, we choose values x_1..x_l such that g^{x_i}
243can be factored modulo p into small primes from a previously fixed set
244B={p_1,...,p_k}.From
245
246 g^{x_j} = prod_{i=1}^k p_i^{e_{j,i}} (mod p)
247
248we then obtain
249
250 x_j = sum_{i=1}^k e_{j,i} * log_g(p_i) (mod q)
251
252Now, assuming that l in relation to k was chosen large enough this
253system can be olved for the unknowns log_g(p_i). We thus have obtained
254the desired "table of logarithms".
255
256It allows us to easily compute the discrete logarithm of any number
257w:Z_p^* which can be factored into primes from B: if w = prod_{i=1}^k
258p_i^{e_i} then log_g(w) = sum_{i=1}^k e_i * log(p_i) (mod q).
259
260If y itself has that property we are obviously done. Otherwise, we can
261search for a value With the latter at hand we can then --- with luck
262--- take the logarithm of our y as follows: we choose some value z:Z_q
263at random such that y*g^z can be so factored and thus taken a
264logarithm of. This helps, since log_g(y) = log_g(y*g^z)-z.
265
266Using advanced number-theoretic methods one can analyse the
267probabilities that the various random choices in this method succeed
268and thus derive an expected runtime that is subexponential (in
269||q||). Indeed, the index calculus method is currently the best known
270method for computing discrete logarithms.
271
272We also remark that it is the possibility of factoring elements of G
273into primes what makes this algorithm possible. For other groups, in
274particular the multiplicative group of a finite field, analogous
275notions of "primes" can be found, but for groups derived from elliptic
276curves no such notion has been discovered and hence these groups are
277immune against index calculus making them particularly promising for
278cryptography. Having said that, taking discrete logarithms in a group
279Z_p^* where p has 1000+ digits remains unfeasible.
diff --git a/ss2017/cryptography/Notes16.txt b/ss2017/cryptography/Notes16.txt
new file mode 100644
index 0000000..f75607d
--- /dev/null
+++ b/ss2017/cryptography/Notes16.txt
@@ -0,0 +1,318 @@
116 Chosen ciphertext and random oracles
2- - - - - - - - - - - - - - - - - - - -
3
4Many public key schemes including the ones using the RSA assumption
5presented earlier make use of an unkeyed hash function to scramble
6ciphertext and thus to enhance security, thus in particular preventing
7chosen-ciphertext attacks. In this chapter, we will formulate these
8attacks, remedies against them, and a semi-rigorous method for proving
9there relative security.
10
11
12Chosen ciphertext attacks
13- - - - - - - - - - - - -
14
15Chosen ciphertext attacks (CCA) model scenarios where the attacker can
16request the decryption of ciphertexts of its choice. This is relevant
17in a number of practical scenarios, where cryptosystems are used as
18building blocks in larger protocols. Here a "man in the middle" can
19intercept message and assume the role of one of the participants. The
20messages it fabricates will then---at least up to a point---be
21decrypted by the honest parties.
22
23None of the schemes presented to far is secure against CCA. Consider
24for example a symmetric key encryption given by Enc_k(m) =
25(r,F_k(r)+m) where r is a random nonce and F_k() is a PRF.
26
27Consider an attacker who wishes to distinguishes encryptions of m0 =
28000...0 and m1 = 1111..1 as in the PrivK^eav experiment. If the
29attacker is given (r,c) being the encryption of either m0 or m1 all it
30has to do is to request the decryption of the chosen ciphertext (r,c')
31where c' is c with the first bit flipped. Clearly, this will be
321000..000 or 0111...111 according to whether m0 or m1 has been
33encrypted and hence the attacker wins.
34
35The situation is similar in the public key setting. Suppose for
36instance that (c1,c2) is an ElGamal encryption of some message
37m. Then, as we know, c1=g^y and c2=h^y*m where y is random but private
38and h=g^x is public. Now, for any m' we have that (c1,c2*m') is a
39valid encryption of m*m'. It is clear that this allows an adversary to
40win the PubK^eav experiment: Given (c1,c2), the adversary can request
41the decryption of (c1,c2*g). The adversary thus obtains m*g and can compute
42m by multiplication with g^(-1). A similar argument can be made for
43various cryptosytems based on RSA.
44
45The property of the cryptosystems making that form of attack possible
46is known as *malleability*. From a given ciphertext it is possible to
47produce another one that corresponds to a known transformation of the
48plaintext.
49
50We now define security against chosen ciphertext attacks formally in
51the public key setting. The corresponding definition for private keys
52is analogous.
53
54Let A be a ppt adversary and Pi be a public key cryptosystem. The experiment
55PubK^cca_{A,Pi}(n) is defined as follows.
56
571. (pk,sk)<-Gen(n)
582. A is given n, the public key pk, and access to a decryption oracle Dec_sk()
59/* in the private key setting A also gets access to an encryption oracle like in CPA security */
60 A outputs two messages m0,m1
613. b<-{0,1}
624. c<-Enc_pk(m_b) is given to A
635. A continues to have access to the decryption oracle but may, of course, not
64 request the decryption of c itself. Any other ciphertext is allowed.
656. A outputs a bit b' and the outcome is 1 if b=b', 0 otherwise.
66
67The cryptosystem is deemed CCA-secure if the success probability in
68this experiment is 1/2+negl(n).
69
70
71CCA secure private key cryptography using MACs
72- - - - - - - - - - - - - - - - - - - - - - - -
73
74In the private key case such CCA-secure schemes can be constructed by
75combining a CPA-secure system PiE with a secure MAC PiM as follows:
76
77A key pair (k1,k2) is generated, k1 for PiE and k2 for the MAC PiM.
78
79The encryption of m under (k1,k2) is given by (c,t) where
80c<-Enc_{k1}(m) and t<-Mac_{k2}(c). Thus, we authenticate the
81ciphertext so as to prevent any modification.
82
83To decrypt (c,t) we first check that Mac_{k2}(c)=t and only then
84return Dec_{k1}(c). If Mac_{k2}(c) is different from t we return a
85default value _|_.
86
87One can now show that---assuming PiE and PiM are themselves
88secure---this scheme achieves CCA security. The proof idea is that
89assuming PiM is secure the probability that the adversary makes a
90query which is answered with a value different from _|_ is
91negligible. We can therefore assume that all queries are answered with
92_|_ and in this case the experiment degrades to a PrivK^cpa experiment
93against which PiE is assumed secure. For details see KL4.8.
94
95
96CCA-secure public key cryptography using hash functions
97- - - - - - - - - - - - - - - - - - - - - - - - - - - -
98
99Building CCA-secure public key systems is more difficult and typically
100uses hybrid encryption with a CCA-secure private key system and,
101additionally, a "cryptographic hash function" H(). Here we show one such
102system using RSA, which at the same time gives an example of a
103security proof based on the RSA assumption.
104
105Assume thus that Pi0=(Enc0,Dec0) is a CCA-secure private key
106cryptosystem which uses uniformly distributed keys from {0,1}^n (so
107there is no "Gen0"). Assume further that H:{0,1}^n->{0,1}^n is a
108"cryptographic hash function". We will later discuss what this should
109mean formally in this context. We will need stronger properties than
110just the collision-resistance that we have required of hash functions
111before.
112
113Finally, assume that GenRSA() is an RSA key generator for which the
114RSA hardness assumption holds.
115
116We then construct a public key cryptosystem Pi=(Gen,Enc,Dec) as follows.
117
118
119Gen(n):
120 (N,d,e)<- GenRSA(n)
121 pk = (N,e), sk=(N,d)
122 return (pk,sk)
123
124Enc_{(N,e)}(m):
125 1. r <- {0,1}^n
126 2. k = H(r)
127 3. return (r^e mod N, Enc0_k(m))
128
129Dec_{(N,d)}(c1,c2):
130 1. r = c1^d mod N
131 2. k = H(r)
132 3. return Dec0_k(c2)
133
134Why should this scheme be CCA secure? Intuitively, given the RSA-assumption,
135the attacker has no way of recovering r, hence the likelihood
136that it applies (the publicly known function) H() to r is negligible
137and as a result all H()-values it sees would look random to it. Thus,
138the key used in the private key encryption of the actual message is as
139good as random so that the security assumption on Pi2 applies and the
140entire scheme is secure.
141
142We need the function H to make the key k look random. It may be tempting
143to just try to use r as the encryption key. But the RSA-assumption gives
144us only that the attacker cannot recover r fully. It does not rule out
145that the attacker obtains a few bits of r. If we used r as key, then
146it would not be fully random and the security assumption on Pi2 could
147not be used.
148
149
150The random oracle model
151- - - - - - - - - - - -
152
153The question is under what assumptions on H() the above argument can
154be made rigorous. Assuming H() to be a PRF does not work because those
155always require a secret key. Once you know the key there is nothing
156random about a PRF. Taking a PRG also does not work, as its output
157looks random only if the input is random as well.
158Assuming that H() is merely a secure hash function does not suffice
159either because nothing prevents a good hash function from, for example,
160producing hash strings which contain predictable portions.
161E.g. if H0() is a secure hash function so is H(x) = 0.....0 H0(x).
162
163Unfortunately, there have not been found any plausible assumptions on
164the function H() under which schemes like the above could be proved
165secure. A possible way out is the random oracle model which we now describe.
166
167In this model, one instantiates H() with a function that is randomly
168chosen at the beginning of each experiment, i.e., the probabilities
169are taken over uniform random choices of H() which is therefore called
170*random oracle*. All participants in the experiment get access to H.
171It would be possible to actually implement this by using a trusted
172party, e.g. an internet server which must called for any evaluation of
173H(). It can either precompute the entire value table of H() (finite
174for a given security parameter) using random choices or alternatively,
175fill this table on demand, i.e. regurgitate H-values on previously
176requested arguments and make random choices for new requests.
177
178In practice, however, this approach is unfeasible, and so the random
179oracle, for which schemes like the above one *can be proved secure*,
180is replaced with a cryptographic hash function such as SHA-2. Whether
181or not the security proof in the random oracle model has any bearing
182on this instantiation remains open.
183
184In fact, it has been shown that there exist contrived cryptographic
185schemes which are secure in the random oracle model but insecure with
186any concrete instantiation. Nevertheless, a proof in the random oracle
187model consists strong evidence as to the security of a scheme and
188perhaps even more importantly, failure to prove a system secure in the
189random oracle model might point out actual flaws of a scheme. KL
190contains a longer discussion of the metamathematical or epistemic
191implications of the random oracle model without however being able to
192get over the central issue that a proof in the random oracle model
193does not imply anything---in the rigorous mathematical sense---about
194the "standard model" which is used in actual practice.
195
196
197
198Secure hash functions and pseudorandom functions in the random oracle model
199- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200
201As a warmup let us see how random oracles can be used to construct
202secure hash functions and pseudo random functions.
203
204We fix a length function l(n), e.g. l(n)=n or l(n)=n/2 and let H :
205{0,1}^n->{0,1}^{l(n)} be a random function.
206
207We now show that H() itself is a secure hash function. Consider a ppt
208adversary A who gets oracle access to H() and conduct the Hash-coll
209experiment from Chapter 11 with random H():
210
2111. Choose H() at random
2122. Adversary A gets oracle access to H() and outputs values x,x':{0,1}^n
213 such that x != x'.
2143. The outcome of the experiment is 1 iff H(x)=H(x')
215
216Theorem:
217
218The success probability of this experiment, taken over uniform random
219choice of H and the random choices that A might make is a negligible
220function of the security parameter.
221
222Proof. Let x1...xk be the sequence of values that A queries of H prior to
223outputting x,x'. Clearly, k is polynomial in the security parameter n
224due to the polynomial time bound on the computation time of A. The
225probability that H(xi)=H(xj) for some i!=j is therefore
226negligible. Notice that we can assume that H-values are selected "on
227demand". Thus, when x,x' are among the x1..xk the success probability
228is negligible. If, however, A chooses at least one of them afresh
229then, again, the success probability is negligible because only a
230negligible portion of the possible H-values is favourable. QED
231
232Notice that, in a way, the earlier account of hash functions in
233Chapter 11 was also based on some kind of random oracle in that we
234assumed a uniformly random selection of the seed which also does not
235happen in practice.
236
237
238A pseudorandom function from a random oracle
239- - - - - - - - - - - - - - - - - - - - - - -
240
241The random oracle can be used to obtain a PRF as follows:
242
243Theorem: Let l(n)=n/2 and define F_k(x) = H(k || x). Notice that for
244k,x:{0,1}^n we have F_k(x):{0,1}^n. Now, F_k() is a PRF in the
245following sense. Let D be a ppt distinguisher with oracle access to a
246function g():{0,1}^n->{0,1}^n *and* the random function H(). We write
247this as D^{g(),H()}(n). We then have
248
249| Pr[ D^{F_k(),H()}(n)=1 ] - Pr[ D^{f(),H()}(n)=1 ] | = negl(n)
250
251with probabilities taken over a random function f(), the key k and the
252random function H() appearing in F_k().
253
254Proof: As before, we can condition on the queries made to H() by D
255during its computation. So long as these are disjoint from those made
256as part of evaluations of F_k() we are in the situation of the
257previous theorem. But then the probability for such a coincidence is
258negligible by the randomization over k. The details are left as an
259exercise. QED
260
261It is now also possible to show that the abovedescribed hybrid
262encryption system is CCA secure; however, for simplicity, we only show
263its CPA security which is already nontrivial. Also, we have not
264seen any provably secure RSA-based cryptosystem so far.
265
266Theorem: Let Pi0 be a CPA-secure private key system and let
267Pi be the hybrid system as described above. Then for any ppt adversary, which
268is given additional access to the random oracle H(), one has
269
270Pr[ PubK^eav_{Pi,A^{H()}}(n) = 1 ] = 1/2 + negl(n)
271
272with probabilities taken over random choice of H(), the random steps
273taken within A, and those in the PubK^eav experiment.
274
275Proof sketch: For convenience we recall the steps of the experiment.
276
2771. H() is chosen at random.
2782. (N,e,d) <- GenRSA(n); pk=(N,e); sk=(N,d)
2793. A is given access to pk and H()
2804. A outputs messages m0, m1.
2815. r<-{0,1}^n; k=H(r)
2826. b<-{0,1}
2837. c1<-r^e mod N
2848. c2<-Enc0_k(m_b)
2859. A is given (c1,c2) and returns b'
28610. Outcome is 1 iff b=b'
287
288The encryption and decryption algorithms that A is given oracle access
289to essentially follow lines 5-9 and are not repeated here.
290
291Let us call QUERY the event that A queries H() on one of the random
292nonces r used either in line 5 or as part of its queries to the
293encryption oracle.
294
295The idea is that since---assuming as we do---GenRSA satisfies the RSA
296hardness assumption, the probability of QUERY is negligible.
297This is because we can use A to construct an adversary in the RSA-inv
298experiment as follows. We use A as a subroutine and run it according
299to protocol. We monitor all queries of A to H() and for each one of
300those, call it r_q, check whether r_q^e mod N is correct. If this is
301the case, then we output r_q. By the RSA hardness assumption, this
302adversary can output the correct r only with negligible probability,
303which means that the probability of QUERY must be negligible.
304
305Once we know that QUERY is a negligible event we can assume without
306loss of generality that it does not occur, i.e., oracle access to H()
307returns random values that are completely unrelated to the experiment.
308We can thus assume that A does not get access to H() at all and then
309the CPA-secure scheme Pi0 is secure by assumption.
310
311We refer to KL Theorem 13.1 for details and to KL Theorem 13.5 for a
312proof that the hybrid scheme even yields CCA security assuming Pi0 is
313CCA secure.
314
315We also remark that the deterministic version of RSA used to encrypt
316the symmetric key can be replaced by an arbitrary so-called key
317encapsulation mechanism (KEM), without essentially changing the
318proof. See KL, 2nd ed for details.
diff --git a/ss2017/cryptography/Notes17.txt b/ss2017/cryptography/Notes17.txt
new file mode 100644
index 0000000..6a15827
--- /dev/null
+++ b/ss2017/cryptography/Notes17.txt
@@ -0,0 +1,194 @@
117 Digital signatures
2---------------------
3
4Digital signatures are the public key analogues of message
5authentication schemes (MAC). They allow a *signer* to authenticate a
6message with their *private key* by producing a tag that can
7subsequently be verified by anyone who has the corresponding public
8key. Just as with MACs the tags are specific to the message being
9signed. Changing the message in any way should invalidate the tag,
10thus the "signature". Also no-one who is not in the possession of the
11private key corresponding to the public key used for verification
12should be able to produce a valid signature.
13
14Definition: a signature scheme is a triple Pi=(Gen,Sign,Vrfy) of ppt
15algorithms where
16
171. Gen(n) produces a public/private key-pair (pk,sk)
18
192. The signing algorithm Sign takes a secret key and a message m and
20produces a signature sigma<-Sign_sk(m).
21
223. The (deterministic) verification algorithm Vrfy takes a public key,
23a message m, and a signature sigma, and answers 1 or 0. If
24sigma<-Sign_sk(m) then Vrfy_pk(m,sigma) must return 1.
25
26If Sign_pk is defined only for messages of length l(n) for some
27function l() then we speak of a *fixed length* signature scheme.
28
29The signature scheme Pi=(Gen,Sign,Vrfy) is *secure* if the
30success probability of the following experiment is negligible for any
31ppt adversary A:
32
33Experiment Sig-forge_{A,Pi}(n):
34
351. (pk,sk)<-Gen(n)
36
372. A gets n, pk, and oracle access to Sign_sk(). The adversary then
38outputs (sigma,m). Let Q be the sequence of questions to the oracle
39posed so far, i.e. messages for which a signature has been requested.
40
413. The outcome of the experiment is 1 iff Vrfy_pk(m,sigma)=1 and m is not in Q.
42
43End of definition.
44
45In KL our "secure" is called "existentially unforgeable under an adaptive
46chosen-message attack" to differentiate from other, weaker notions of
47security.
48
49
50Insecure signature based on textbook RSA
51- - - - - - - - - - - - - - - - - - - - -
52
53A naive attempt at defining a signature scheme based on RSA goes as
54follows:
55
56Gen(n): (N,e,d)<-GenRSA(n);pk=(N,e);sk=(N,d)
57 output (pk,sk)
58
59Sign_{(N,d)}(m):
60 output m^d mod N
61
62Vrfy_{(N,e)}(m,sigma):
63 output 1 iff sigma^e = m (mod N)
64
65Clearly, verification of a valid signature succeeds but the scheme is
66insecure for several reasons. First, if an adversary can choose an
67arbitrary signature sigma first and then fabricate a corresponding
68"message" as m=sigma^e mod N. Notice that Vrfy_{(N,e)}(m,sigma)
69succeeds, so this adversary will win the experiment with certainty.
70
71Second, and perhaps more realistically, if the adversary would like to
72get a signature on a previously fixed message m it could request
73signatures sigma1 for random m1 and sigma2 for m2:=m/m1 (mod N). It is
74then clear that sigma1*sigma2 mod N is a valid signature for the
75original m.
76
77
78Secure signatures with random oracles
79- - - - - - - - - - - - - - - - - - -
80
81It is possible, but rather inefficient, to construct secure signature
82schemes based on the RSA assumption and a collision-resistant hash
83function, see KL12.6. In practice, one uses signature schemes based on
84cryptographic hash functions which can only be proved secure in the
85random oracle model. We thus modify our definition of secure signature
86scheme to the effect that both parties now have access to a function
87H:{0,1}^n->{0,1}^n which is selected uniformly at random at the
88beginning of the experiment.
89
90In this situation we have the following signature scheme RSA-FDH
91("full domain hash").
92
93RSA-FDH:
94
95Gen(n): (N,e,d)<-GenRSA(n);pk=(N,e);sk=(N,d)
96 output (pk,sk)
97
98Sign_{(N,d)}(m):
99 output H(m)^d mod N
100
101Vrfy_{(N,e)}(m,sigma):
102 output 1 iff sigma^e = H(m) (mod N)
103
104In practice, the random oracle H() will be replaced by a cryptographic
105hash function such as SHA-2 and the scheme is just like the
106abovedescribed insecure one with the exception that the message is
107hashed prior to signing.
108
109Let us see how this prevents the previous two attacks. Firstly, if the
110attacker starts with arbitrary sigma then in order to fabricate a
111corresponding message it would have to find m such that sigma^e=H(m)
112(mod N) and thus for a given H()-value which it *can* compute, namely
113sigma^e, find an inverse image, which is infeasible.
114
115Similarly, in order to perpetrate the other attack it would have to
116fabricate for given m two values x and y so that H(x)*H(y)=H(m).
117While this is infeasible for truly random H() and not possible with
118current knowledge for SHA-2 it is not prevented by mere
119collision-resistance.
120
121Theorem: If GenRSA() fulfills the RSA assumption then RSA-FDA is
122secure in the random oracle model.
123
124Proof: Let A be an attacker in the Sig-forge_{A,RSA-FDA}
125experiment. We may fix a polynomial q(n) bounding the queries of A to
126H() and also assume that A first queries H(m) for any message for
127which it requests a signature or which it finally outputs. We also
128assume that A makes exactly q(n) queries. All this is done in order to
129save a few case distinctions in the argument. We now build from A an
130attacker A' against GenRSA() in the RSA-inv(n) experiment from Chapter
13112 as follows.
132
133Attacker A' against GenRSA:
134
135Given N, e, y* = x^e mod N we (assuming the role of A') choose
136j<-{1..q(n)} and forward the public key pk=(N,e) to A.
137
138When A makes its i-th query m_i to H() we answer as follows:
139
140If i=j we return y*. If m_i has been asked previously, i.e., if
141m_i=m_j for some j<i, then we answer consistently using a table to
142store earlier answers. Otherwise, we choose sigma_i <-Z_N^* uniformly
143at random, answer y_i=sigma_i^e mod N and remember both y_i and
144sigma_i in our table.
145
146As a result, for all the H()-values that A has access to we know their
147e-th root modulo N.
148
149When A requests a signature on message m then, since H(m) has been
150queried before, we have stored in our table sigma so that sigma^e=H(m)
151and can thus return that very sigma which clearly is a valid
152signature.
153
154The only one message for which we do not have an e-th root is the j-th
155one. Should the adversary A request a signature for the latter we
156abort the experiment, i.e. return an arbitrary guess.
157
158Finally, A will output a pair (m,sigma). If m=m_j and sigma^e=y* (mod
159N) then we can output sigma (and we will win the RSA-inv experiment).
160
161This concludes the description of the adversary A' against GenRSA().
162
163We first note that even though we prepare the answers to A's
164H()-queries using a table and case distinctions the resulting function
165looks uniformly random from A's perspective. So, it, i.e. A, will work
166just as in the standard Sign-forge experiment.
167
168Now, A' wins the RSA-inv experiment if A produces a valid forgery
169(m,sigma) and m = m_j. If epsilon(n) is A's winning probability in
170the Sig-forge experiment then this happens with probability
171epsilon(n)*1/q(n). But by the RSA hardness assumption the latter
172quantity is negligible and therefore, since q(n) is polynomial in n,
173so is epsilon(n). QED
174
175We remark that a similar scheme based on discrete logarithms is known
176as the Schnorr signature.
177
178Hash-and-sign
179- - - - - - -
180
181We note that if the hash function used here is arbitrary length then
182the above scheme allows for the signing of messages of arbitrary
183length. The security proof can be generalised to this, but becomes
184somewhat awkward since arbitrary length random oracles have not been
185properly defined.
186
187Alternatively, one can turn any secure fixed length signature scheme
188into an arbitrary length one by first hashing the message to be signed
189with an arbitrary length collision-resistant hash function and then
190signing the hash. The proof of security is analogous to the one for
191the Hash-and-MAC paradigm given in Chapter 11. This is known as
192"Hash-and-sign".
193
194