summaryrefslogtreecommitdiff
path: root/ss2017/cryptography/Notes09.txt
diff options
context:
space:
mode:
Diffstat (limited to 'ss2017/cryptography/Notes09.txt')
-rw-r--r--ss2017/cryptography/Notes09.txt259
1 files changed, 259 insertions, 0 deletions
diff --git a/ss2017/cryptography/Notes09.txt b/ss2017/cryptography/Notes09.txt
new file mode 100644
index 0000000..7c6f51d
--- /dev/null
+++ b/ss2017/cryptography/Notes09.txt
@@ -0,0 +1,259 @@
1
29 Cryptanalysis
3---------------
4
5Cryptanalysis is aimed at breaking ciphers in the sense of
6reconstructing a key from given or chosen pairs of plain- and
7ciphertext. In the first chapter, we saw how various historic ciphers
8can be broken using regularities in the statistical distribution of
9ciphertexts or rather using the fact that known properties of the
10statistical distribution of plaintexts shine through in the
11statistical distribution of plaintexts. Modern cryptographic schemes
12avoid such attacks by making sure that the statistical distribution of
13ciphertext looks close to uniform no matter what the statistical
14distribution of the plaintexts is. The principles of confusion and
15diffusion were introduced to ensure this property at least
16approximately in practice. The notion of pseudo random generator
17furnishes an ideal yet useful theoretical model.
18
19Attacks against cryptographic schemes that properly implement
20confusion and diffusion are much more complicated and in many cases,
21in particular DES and AES not known to exist except in the sense that
22the computational time needed to carry them out is close to that of a
23brute-force attack (trying out all keys) which is always
24possible. Nevertheless, it is important to know and study principles
25of such attacks in order to avoid them when designing a new cipher,
26e.g. a smaller variant of existing ones to be run in
27resource-constrained environments e.g. "Internet of Things".
28
29We have already seen that a cipher that only uses linear or affine
30linear operations is vulnerable to an attack based on solving systems
31of linear equations. In this chapter we take a brief look at three
32more principles of cryptanalysis. First, we show why feedback shift
33registers which are a popular device for generating pseudorandom
34numbers are not secure.
35
36Linear Feedback Shift Registers (LFSR): Such a device is given by a
37sequence of shift registers with some outputs fed back via XOR to the
38input. For instance:
39
40 >[D]-o->[D]-o->[D]---o------------->
41 | | | |
42 -(+)-----------(+)----
43
44When the shift registers (here noted [D]) are initialised with some
45bits then a stream of bits is generated at the output. E.g. starting from 100
46we obtain the following sequence of states:
47
48100,110,111,011,101,010,001,100,...
49and the following output sequence 00111010...
50
51Here, from xyz we get to uxy where u=x+z (mod 2). Of course, the
52sequence repeats after at most 8 steps, but until then looks rather
53random. With a chain 16 shift registers one can achieve a period
54length of 65535. In order to encrypt a stream of bits ("stream
55cipher") one can initialise the shift registers with the secret key
56and then add (XOR) the generated stream to the data stream. Due to the
57relative simplicity of implementation this has been used for a long
58time in esp. military applications.
59
60However, LFSR are linear (the sequence generated by the sum of two
61keys equals the sum of the sequences generated by the keys
62individually) and this can be exploited in various ways. The most
63interesting way uses the Berlekamp Massey algorithm which from a given
64sequence of bits computes the shortest LFSR which generates it. If one
65knows the beginning m of a plaintext and the corresponding ciphertext
66c, e.g. because the plaintext starts with the date or some formal
67greeting one can then apply the Berlekamp-Massey algorithm to m+c and
68use the computed LFSR to decode the remaining ciphertext.
69
70In order to circumvent this one can use nonlinear functions in the
71feedback loop, e.g. logical or use nonlinear combinations of several
72LFSR. The resulting stream ciphers, e.g. A5/1 and A5/2, E0 are still
73in use in GSM and Bluetooth but are known to have vulnerabilities
74too. Indeed, the design of secure stream ciphers is very difficult and
75for high security applications one resorts to block ciphers run,
76e.g. in CTR mode in order to encrypt bitstreams.
77
78
79Linear cryptanalysis
80- - - - - - - - - - -
81
82Linear cryptanalysis was developed in the 90s by Matsui and apparently
83was not known to the DES developers. Nevertheless, it can only produce
84a theoretical attack on the latter and on AES.
85
86We illustrate linear cryptanalysis with the toy cryptosystem from
87Michael Heys' tutorial
88https://www.engr.mun.ca/~howard/PAPERS/ldc_tutorial.pdf.
89
90It is an S/P network with a block length of 16 and four proper rounds,
91i.e. four rounds and an additional key mixing step. We regard each
92block as a 4x4 bit matrix. The substitution step applies the first
93S-Box of DES S_1, i.e.
94
950 1 2 3 4 5 6 7 8 9 A B C D E F
96-------------------------------
97E 4 D 1 2 F B 8 3 A 6 C 5 9 0 7
98
99separately to each of the four rows (regarded as a hexadecimal number). So
100
101(1 0 1 0) (A) (6) (0 1 1 0)
102(0 1 1 0) which is (6) becomes (B) which is (1 0 1 1)
103(1 1 0 1) (D) (9) (1 0 0 1)
104(0 0 0 1) (1) (4) (0 1 0 0)
105
106The permutation step is simply matrix transposition, thus our example
107becomes
108
109(0 1 1 0) (6)
110(1 1 0 0) which is (C)
111(1 0 0 1) (9)
112(0 1 1 0) (6)
113
114As usual, each round consists of addition mod2 of the round key,
115substitution (S), and permutation (P), i.e. transposition. After four
116rounds we add one more key. The master key simply consists of the
117concatenation of the five round keys k = k1 k2 k3 k4 k5.
118
119We can now observe that the S-box S is not completely balanced in the
120following sense. Let WX1 be (1 0 1 1)^T and WY1 = (0 1 0 0)^T. The ^T
121suffix means transposition so W1, W2 are actually columns. We now have
122
123 Pr(WX1^T x + WY1^T S(x) = 0) = 3/4
124
125where the probability is taken over uniformly distributed
126x:{0,1}^4. In other words, for 12 out of the 16 possible inputs x=(x1
127x2 x3 x4)^T and results S(x)=(y1 y2 y3 y4)^T one has x1+x3+x4=y2
128whereas for the remaining four one has x1+x3+x4=/=y2,
129i.e. x1+x3+x4=y2+1.
130
131One can find such an imbalance by exhaustive search. Another such
132imbalance is given by WX2=(0 1 0 0)^T WY2 = (0 1 0 1)^T:
133
134 Pr(WX2^T x + WY2^T S(x) = 0) = 1/4
135
136Chaining these imbalances through the whole cipher (using the first
137one on round 1 and the second one on the other rounds) one obtains a
138similar linear relationship between the plaintext, the ciphertext just
139after round four, and the four round keys that have been used until
140then: Letting P be the plaintext (now written as dim16 vector) and U
141the ciphertext prior to applying the last S-boxes, permuting, and
142mixing with the fifth and last round key we find dim16 vectors A, B
143D1, D2, D3, D4 such that
144
145 Pr(A^T P + B^T U + D1^T K1 + D2^T K2 + D3^T K3 + D4^T K4 = 0) = 15/32
146
147with keys K1 ... K4 fixed and probability taken over the plaintexts P.
148
149
150Since D1^T K1 + D2^T K2 + D3^T K3 + D4^T K4 is either 0 or 1 we have that
151
152 Prob(A^T P + B^T U = 0) = 15/32 or Prob(A^T P + B^T U = 0) = 17/32
153
154irrespective of K1,..,K4. This allows us to work out a likely value
155for K5 or rather some bits of it.
156
157Namely, given a list of plaintexts P_1..P_N and corresponding
158ciphertexts C_1..C_n we can try out all 2^16 possible choices for K_5,
159for each one compute the corresponding U_i := S^{-1}(P^{-1}(C_i+K_5)),
160and compute the ratio
161
162 p(K_5) = {i | A^T P_i + B^T U_i = 0} / N
163
164We choose a value K_5 for which this ratio is close to 15/32 or 17/32
165and discard all those where it is close to 1/2. Now, p(K_5) does not
166actually depend on all bits of K_5 but only on those where the
167corresponding bit in B^T is set for the other ones only influence
168components of U_i which are not used in p(K_5). Nevertheless, this
169allows us to considerably narrow down the possible options for
170K_5. For each of those, we can then continue in the same fashion and
171thus peel off the fourth round key etc.
172
173
174Differential cryptanalysis
175- - - - - - - - - - - - - -
176
177Differential cryptanalysis was developed by Biham and Shamir as an
178attack against DES but apparently already known to the DES
179developers. It has been used to successfully break other ciphers. It
180uses the fact that the effect of adding a round key cancels out when
181we consider differences between two plaintexts. However, this
182requires the preparation of chosen plaintexts. In more detail, the
183*differential* between two plaintexts X1 and X2 is simply X1+X2,
184i.e. the bitvector which has a 1 where X1 and X2 differ and a 0 where
185they are equal.
186
187Coming back to our 4bit example S-box for any given differential there
188then are 2^4=16 different ways of realising it. E.g. the differential
1891010 arises for the plaintext pair 0011,1001 and also for
1901111,0101. Indeed, for any plaintext X1 there is a unique X2 such that
191X1, X2 have a given differential.
192
193Given two differentials X* and Y* we are interested in the following
194question. For how many of the (16) plaintext pairs X1,X2 with
195differential X* is it the case that the results of applying the S-box
196Y1=S(X1), Y2=S(X2) have differential Y*. Tabulating these numbers by
197exhaustive search yields the following table:
198
199 Output differential
200 0 1 2 3 4 5 6 7 8 9 A B C D E F
201I 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
202n 1 0 0 0 2 0 0 0 2 0 2 4 0 4 2 0 0
203p 2 0 0 0 2 0 6 2 2 0 2 0 0 0 0 2 0
204u 3 0 0 2 0 2 0 0 0 0 4 2 0 2 0 0 4
205t 4 0 0 0 2 0 0 6 0 0 2 0 4 2 0 0 0
206 5 0 4 0 0 0 2 2 0 0 0 4 0 2 0 0 2
207d 6 0 0 0 4 0 4 0 0 0 0 0 0 2 2 2 2
208i 7 0 0 2 2 2 0 2 0 0 2 2 0 0 0 0 4
209f 8 0 0 0 0 0 0 2 2 0 0 0 4 0 4 2 2
210f 9 0 2 0 0 2 0 0 4 2 0 2 2 2 0 0 0
211' A 0 2 2 0 0 0 0 0 6 0 0 2 0 6 0 0
212i B 0 0 8 0 0 2 0 2 0 0 0 0 0 2 0 2
213a C 0 2 0 0 2 2 2 0 0 0 0 2 0 6 0 0
214l D 0 4 0 0 0 0 0 4 2 0 2 0 2 0 2 0
215 E 0 0 2 4 2 0 0 0 6 0 0 0 0 0 2 0
216 F 0 2 0 0 6 0 0 0 0 4 0 2 0 0 2 0
217
218
219The high entries 8 and 6 are of particular interest because they
220constitute a deviation of an intuitive pseudorandom permutation.
221Let us now see how we can exploit these in order to attack our cipher.
222
223We feed in a pair of 16bit plaintexts X1 X2 which differ in the second
224block by B=1011 and are equal everywhere else. With probability 8/16
225this will result in differential 2=0010 at the output of the second
226S-box. The output of the other S-boxes will be equal for X1 and X2.
227This differential 2=0010 will be propagated through the P network and
228results in a differential of 4=0100 at the entry of the third S-box of
229the second round:
230
231 Differential before P Differential after P
232 0 0 0 0 0 0 0 0
233 0 0 0 0 ------P----> 0 0 1 0
234 0 1 0 0 0 0 0 0
235 0 0 0 0 0 0 0 0
236
237
238There, with probability 6/16 it will produce differential 6=0110 at
239the output. This results in differential 2=0010 at the input of the
240second and third S-boxes of the third round. With probability 36/256
241this will lead to differential 5 at both outputs which propagates to
242differential 6=0110 at the entries to the second and fourth S-boxes of
243the final round.
244
245 0 0 0 0 0 0 0 0
246 0 0 1 0 -------P-----> 0 0 0 0
247 0 0 1 0 0 1 1 0
248 0 0 0 0 0 0 0 0
249
250Summing up, when we encipher plaintexts with differential 0B00 we will
251obtain with probability 1/2*3/8*9/64=27/1024 a differential 0606 at
252the entry to the last round. We now have to set the relevant
253components (second and fourth block) of the final key in such a way
254that this ratio (after inverting the last layer of S-boxes) is
255actually reproduced. This allows us (with high probability) to guess
256hone half of the bits of the last round key. Continuing in this way
257with other differentials combined with exhaustive search allows us to
258undo the entire last round and then to proceed from there.
259