summaryrefslogtreecommitdiff
path: root/ss2017/cryptography/Notes06.txt
diff options
context:
space:
mode:
Diffstat (limited to 'ss2017/cryptography/Notes06.txt')
-rw-r--r--ss2017/cryptography/Notes06.txt216
1 files changed, 216 insertions, 0 deletions
diff --git a/ss2017/cryptography/Notes06.txt b/ss2017/cryptography/Notes06.txt
new file mode 100644
index 0000000..a14e840
--- /dev/null
+++ b/ss2017/cryptography/Notes06.txt
@@ -0,0 +1,216 @@
1
26 Block ciphers, Modes of operation (KL3.6.3 KL3.6.4)
3-----------------------------------------------------
4
5A pseudorandom function F() with the additional property that F_k is
6invertible and the inverse F_k^{-1} is computable in polynomial time
7is known as *block cipher* or *pseudorandom permutation*. It is not
8hard to see that in this case,
9
10Enc_k(m) = F_k(m)
11Dec_k(c) = F_k^{-1}(c)
12
13is semantically secure (hence the name "block cipher"). While a simple
14PRG already suffices to build a semantically secure cryptosystem those
15based on PRF as above enjoy stronger properties as we now explain.
16
17With the help of a block cipher it is possible to design encryption
18schemes for messages of arbitrary length using various *modes of
19operation* that we now describe. In practice, the underlying block
20ciphers (or pseudorandom functions) are heuristically designed
21functions like DES or AES which we we will look at later. In some
22modes of operation it suffices to have a pseudorandom function rather
23than permutation.
24
25In each mode of operation we divide the message to be encrypted into
26blocks of size n, where n is the security parameter and hence the size
27of the messages the pseudorandom function can work with. If the length
28of the whole message is not a multiple of n we must *pad* the last
29block in some way, e.g. by adding 1000...0. There are various padding
30schemes which describe this in detail. We henceforth assume that
31padding has already taken place and that the message comprises l
32blocks m_1,...,m_l of length n each.
33
34Remark: it is possible to vary l from message to message and in this
35way to encrypt a *stream* of bits rather than a block. One thus
36effectively obtains so-called *stream ciphers*. Such stream ciphers
37are also constructed and studied in their own right, see
38e.g. KL3.4. In this course, we do not consider stream ciphers.
39
40
41ECB mode (electronic code book)
42- - - - - - - - - - - - - - - -
43
44This is the simplest mode of operation and it is actually not secure
45at all, hence obsolete and included only for historical reasons. Let F
46be a block cipher.
47
48The encryption of the plaintext m = m1..ml under ECB-mode is given by
49
50 Enc_k(m) = F_k(m1) F_k(m2) ... F_k(ml)
51
52i.e. the encodings F_k(mi) of the blocks mi are simply
53concatenated. This mode receives its name from the fact that it
54resembles a code book (which for each short message lists the
55corresponding code) albeit in electronic form.
56
57It is easy to see that ECB is not even secure against an
58eavesdropper. If, assuming blocklength 3, we choose messages m=000000
59and m'=000111 we can tell them apart on the basis of the corresponding
60ciphertexts c,c' alone because c has the form xyzxyz whereas c' does
61not. This deficiency of ECB shows in practice when it is used to
62encode images, see KL (2nd ed) for an example.
63
64
65CBC mode (cipher block chaining)
66- - - - - - - - - - - - - - - - -
67
68Here we choose a random initialisation vector IV:{0,1}^n and encrypt as
69
70Enc_k(m) = IV c1 c2 c3 ... cl
71
72where c1=F_k(IV+m1), c2=F_k(c1+m2), c3=F_k(c2+m3), ...
73
74I.e. each block is xor-ed with the encoding of the previous block
75prior to sending it through F_k.
76
77One can show that CBC-mode is CPA-secure, however it suffers from the
78disadvantage that the ith ciphertext is needed to compute the i+1-st
79one so the scheme cannot be parallelized.
80
81The following variant of CBC-mode has been used in practice (SSL 3.0, TLS 1.0):
82
83
84Chained CBC-mode (not CPA secure)
85- - - - - - - - - - - - - - - - -
86
87Rather than choosing a fresh initialisation vector each time it has
88been proposed to use instead the last ciphertext, i.e., c_l as the new
89initialisation vector. This reduces the size of the subsequent
90message by one block and should intuitively be as good as CBC-mode
91proper. However, this scheme is vulnerable to a CPA-attack as follows:
92Suppose that the attacker knows that m_1 is one out of m_1^0 and m_1^1
93and that m = m_1 m_2 m_3 has already been encrypted as IV c_1 c_2
94c_3. The attacker could now request the encryption of another message
95starting with the block
96
97 m_1' := IV + m_1^0 + c_3
98
99The first ciphertext block c_1' then satisfies
100
101 c_1' = F_k(c_3+m_1') = F_k(IV + m_1^0)
102
103
104Noticing that c_1 = F_k(IV + m_1) we then have m_1 = m_1^0 iff c_1' =
105c_1.
106
107
108
109OFB mode (output feedback)
110- - - - - - - - - - - - - -
111
112Here we only need a pseudorandom function. From a randomly chosen
113initialisation vector IV we first compute pseudorandom strings r1...rl
114as follows:
115
116r1 = F_k(IV), r2 = F_k(r1), ...
117
118and then encrypt using xor:
119
120Enc_k = IV m1+r1 m2+r2 m3+r3 ... ml+rl
121
122So, in essence, we use F_k as a pseudorandom generator of expansion
123l(n) = l*n and then apply the earlier construction of an EAV-secure
124scheme from a PRG. Due to the additional randomization via the
125initialisation vector OFB-mode is even CPA-secure.
126
127
128CTR mode (counter)
129- - - - - - - - -
130
131This mode is similar to OFB, but we compute the pseudorandom string by
132successively incrementing IV:
133
134r_i = F_k(IV+i) /* this + is binary addition, not XOR */
135
136Enc_k = IV m1+r1 m2+r2 m3+r3 ... ml+rl
137
138This has the advantage that the ri and hence the ciphertexts can be
139computed in parallel. A further advantage that it shares with OFB is
140that the pseudorandom string IVr1..rl can be computed ahead of time
141and stored until the message to be encrypted arrives. Furthermore,
142portions of the ciphertext can be decrypted without computing or
143decrypting anything else. This property is known as *random access*.
144
145
146Theorem: If F is a pseudorandom function then (randomised) counter
147mode (as described above) is CPA-secure.
148
149Proof: (Unlike KL we make the simplifying assumption that message
150length l is always the same). Let A be an adversary as in the Priv^cpa
151experiment. We transform it into a distinguisher D for the underlying
152pseudorandom function as we did in the proof of the last Theorem.
153
154Given security parameter n and oracle access to a function h (which is
155instantiated as either F_k() or a truly random f()) the distinguisher
156begins by passing the security parameter n to the adversary.
157
158Now, whenever the adversary queries its own oracle which it assumes to
159be of the form Enc_k() then the distinguisher chooses IV:{0,1}^n at
160random, computes the sequence ri=h(IV+i) and submits IV m1+r1
161... ml+rl to the adversary.
162
163When the adversary enters the second phase and outputs two messages
164m^0, m^1 to distinguish based on their descriptions the distinguisher
165then chooses a random bit b:{0,1} and IV:{0,1}^n uniformly at random
166and returns the encryption of m^b w.r.t. IV to A. Further oracle
167queries from A are answered as before.
168
169When A eventually outputs a bit b' reply 1 if b=b' and 0 otherwise.
170
171Let us see what the adversary can do when h is a truly random
172function. Again, the adversary has a certain advantage which we now
173try to bound from above.
174
175Let us assume that for any two encryptions requested the sequences of
176the counter values do not overlap, i.e. the sets
177{IV,IV+1,IV+2,...,IV+l} and {IV',IV'+1,IV'+2,...,IV'+l}, where IV and
178IV' are the respective initialisation vecotrs chosen, are disjoint. In
179this case, the ciphertexts follow a uniform random distribution and
180the adversary cannot glean any information whatsoever, i.e. has
181success probability 1/2. If they do overlap the adversary may or may
182not use the extra information but if we can show that the probability
183of this happening is negligible we are good. So, this is what we now
184try to do.
185
186Let us first consider that the overlap happens between the first and
187second oracle question. In this case, once IV has been chosen, at most
1882l values for IV' are unfavorable (or favorable depending on
189viewpoint): IV, IV-1 ... IV-l, IV+1, IV+2, ... IV+l. Thus, we have a
190probability of 2l*2^n. Now, since such a clash can happen anywhere we
191multiply this with q(n), the number of questions being asked. Thus, we
192get an overall bound of q(n)*2l/2^n on the probability of an
193overlap. Even if l is not constant, but polynomial in the security
194parameter this is negligible (noting of course that in view of the
195time bounds q(n) is polynomially bounded). As a result, the success
196probability for the adversary can be bounded by 1/2+negl(n).
197
198The rest of the argument is as before: If h is F_k(), then let p be
199the success probability of the adversary A on our new cryptosystem. It
200is clear that our distinguisher will output 1 with probability p for
201we have used A according to the rules of the
202PrivK^cpa-experiment. Since F was assumed to be a PRF we thus know that
203|p-(1/2+negl(n))| is itself negligible. It then follows that p is
204bounded by 1/2 plus a negligible function. Q.E.D.
205
206
207We close by remarking that none of the schemes presented so far is
208secure against chosen ciphertext attacks (CCA) where one may request
209the decryption of arbitrary ciphertexts different from the
210challenge. Consider, e.g. the encryption of m as r || F_k(r)+m. An
211adversary can prepare messages m0=00..0 and m1=11..1. Upon receiving a
212ciphertext c= r || s corresponding to one of these two the adversary can
213flip the first bit of s and ask for the decryption of the resulting
214ciphertext. This must be either 100..0 or 011..1 according to whether
215m was 00..0 or 11..1.
216