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