Professional Documents
Culture Documents
Klein's and PTW Attacks On WEP
Klein's and PTW Attacks On WEP
Abstract
These notes should help for an in-depth understanding of the paper [1] by Klein and [2] by Tews, Weinmann and Pyshkin.
Notation
n
S
256;
array containing the numbers {0, ..., n 1} in some order. Each
number is present only once. S is also called a permutation;
Si RC4 internal permutation S after the i-th RC4 round. 1 i n
corresponds to the key setup algorithm, while i > n is the key
stream generation algorithm;
ji
RC4 internal variable j after the i-th RC4 round;
K
RC4 key;
l
length of K in bytes. Equals 16 for the 104-bit Wired Equivalent
Privacy (WEP);
X
RC4 key stream;
Rk WEP root key. 13 bytes for the 104-bit WEP;
IV WEP per-packet initialization vector. 3 bytes;
assignment;
swap;
bitwise XOR;
for all;
iff if and only if;
||
concatenation.
Indexing in arrays starts from 0, i.e. the first element of S is S[0]. All formulas are implicitly written modulo n, except for the values of probabilities.
In Sections 4 and 5 we present attacks on the 104-bit WEP, i.e. l = 16.
K
RC4
X
message
L
/ ciphertext
3.1
Kleins Theorem
S is random means that it is picked from the n! possible permutations such that the
probability of picking each one is 1/n!.
Then for all integers i, x, c {0, ..., n 1}, the following holds:
2
,
n
n2
Pr ( S[ S[i] + x ] + x = c ) =
, where c 6= i.
n(n 1)
Pr ( S[ S[i] + x ] + x = i ) =
(1)
(2)
Proof. To show (1) we will count the total number of different permutations
S that satisfy the condition under the Pr sign. Consider the following two
disjoint cases:
Case 1:
S[i] = i x .
(3)
It follows that i = S[i] + x and, substituting the index i in (3), we get
S[ S[i] + x ] = i x. This is equivalent to condition (1), so we are only
left with one condition. (3) puts a restriction on one element S[i]. The
remaining n 1 elements can take any of the remaining n 1 values. Thus
the total number of permutations satisfying (3) is (n 1)!.
Case 2:
S[i] 6= i x .
(4)
We now have two conditions that should be met simultaneously. Condition (1) leaves only one possibility for the element S[ S[i] + x ], leaving the
remaining elements unrestricted. Because of (4), we have that S[i] + x 6= i,
so conditions (1) and (4) apply to elements with different indices. Condition (4) leaves n 1 possibilities for the value of S[i]. The remaining n 2
elements of S can take any of the remaining n 2 unused values. Thus
Case 2 incorporates a total of (n 1)(n 2)! = (n 1)! permutations.
We have shown that Cases 1 and 2 allow a total of 2(n1)! different permutations. Since S is picked at random from n! possibilities, the probability
that we hit either of the two cases is
2(n 1)!
2
=
,
n!
n
which proves (1).
To show (2) we will again count possible permutations. We first show
that (5) holds. Suppose the opposite is true: S[i] = i x. Then S[i] + x = i,
and, substituting the index in (2), we get that S[i] + x = c. But c 6= i, so
S[i] + x 6= i, what contradicts our assumption. Thus
S[i] 6= i x .
(5)
Since S[i] + x 6= i, conditions (2) and (5) apply to elements with different
indices in S. Condition (2) leaves one possibility for the value of the element
S[ S[i] + x ]. This value is c x, and it is different from i x, because c 6= i.
So when it comes to the element S[i], it cannot take the value cx because it
3
is already used, and cannot take the value i x because of the condition (5).
The element S[i] is only left with n 2 possibilities. The remaining n 2
elements can take any of the remaining n 2 values. Thus the total number
of permutations satisfying (2) is (n2)(n2)!. This gives us the probability
(n 2)(n 2)!
n2
=
.
n!
n(n 1)
3.2
Equation (10)
(6)
(7)
After substituting ji+1 in (7) with the value from (6) we get
S [i] = Si [ ji + Si [i] + K[ i mod l ] ] .
|
{z }
{z
}
| i+1
(8)
3.3
(10)
Equation (13)
(11)
2
.
n
(12)
(13)
3.4
Equation (16)
We now use (2) substituting, as before, S with Si+n and x with Si+n [ji+n ]:
c 6= i, Pr ( Si+n [ Si+n [i] + Si+n [ji+n ] ] + Si+n [ji+n ] = c ) =
n2
(14)
n(n 1)
n2
.
n(n 1)
n2
.
n(n 1)
(15)
After denoting
= Si+n [ji+n ] c + i ,
we notice that c 6= i iff c = Si+n [ji+n ] + i 6= i iff 6= Si+n [ji+n ], and
thus (15) can be written as
n2
6= Si+n [ji+n ], Pr( i X[i 1] = ) =
.
| {z }
|
{z
}
n(n 1)
3.5
(16)
Equation (20)
(17)
1
.
n
The same reasoning applies to subsequent rounds, i.e. the probability that
Si+1 [i] stays unchanged during the next k rounds is (1 1/n)k , k < n i.
2
(18)
(19)
Substituting Si+n1 [i] in (18) with the value from (19) we get
1 n2
Pr( Si+1 [i] = Si+n [ji+n ] ) = 1
.
| {z } | {z }
n
3.6
(20)
Equation (22)
Lemma 1. If
Pr( = ) = p1 ,
Pr( = ) = p2 ,
6= , Pr( = ) = p3 ,
then
Pr( = ) = p1 p2 + (1 p1 )p3 .
Proof. Consider two cases:
Case 1: = . We find that Pr( = ) = Pr( = ) = p2 .
Case 2: 6= . If we now let = , what is allowed since 6= , we see
that Pr( = ) = Pr( = ) = p3 .
Since Case 1 happens with probability p1 , and Case 2 with probability
(1 p1 ), we get that Pr( = ) = p1 p2 + (1 p1 )p3 .
The result of Lemma 1 applies to Equations (13), (16) and (20) with the
notation for , , and introduced in these equations. It follows that
!
1 n2 2
1 n2
n2
Pr( Si+1 [i] = iX[i1] ) = 1
+ 1 1
.
n
n
n
n(n 1)
If we use n = 256, the last formula approximates to 0.0053 1.36/n. Thus
we have that
1.36
Pr( Si+1 [i] = i X[i 1] )
.
(21)
n
Consider (10) that holds unconditionally, and replace the term Si+1 [i] with
the value from (21). Since the equality under the Pr sign in (21) holds with
the given probability, we can write
1.36
Pr K[ i mod l ] = Si1 [ i X[i 1] ] (Si [i] + ji )
.
n
(22)
Note that, according to Algorithm 1, for i < l, the key bytes K[0],
K[1], ..., K[i 1] completely determine the permutation Si . Therefore
(22) expresses the dependency between the i-th key byte, the i preceding
key bytes and the (i 1)st key stream byte. We see a severe probability
deviation from the mean value 1/n. This fact will be used in our attack to
obtain information about the value of the key byte K[i].
The payload field in the 802.11 data frames MAC protocol data unit (MPDU)
consists of:
IV , padding, Rk s ID, data, ICV ,
|
{z
} | {z }
plaintext
encrypted
To recover a 13-byte Rk we do not actually need the first 2 bytes, but only need the
following 13 bytes of the data.
We compute the value k0 and store it as a candidate for Rk[0]. Note that
with a rather high probability 11.36/n, the byte Rk[0] can have a value different from k0 . Thus we need to collect more evidence about Rk[0]. Luckily,
this can be done using packets that are transmitted between the same stations (thus the same Rk4 ), but have different IVs. Each new IV provides us
with a new experiment outcome, whereas an observation of same IVs gives
no new information whatsoever, since same IVs yield identical three first
rounds of the key setup Algorithm 1. When enough votes are collected,
we can choose the highest rated value of k0 . Klein estimates the number of
unique IVs sufficient to recover the byte Rk[0] to be 25000.
After choosing the most frequent k0 , we let K[3] = k0 , what allows us to
run the fourth round of the key setup algorithm for each given IV. Using the
same collection of captured packets we now carry out similar calculations for
the byte Rk[1]. By this approach we find all the bytes of Rk and finally test
it by a trial decryption of some ciphertext for which we know the plaintext,
or a part of it.
In a case when too few unique IVs were used, the right candidate for
some Rk[i] might not be the most frequent one. Then we have to try the
second, third and so on, most frequent candidates for Rk[i], recomputing
the subsequent key bytes Rk[i + 1], ..., Rk[l 1] for each new Rk[i]. This
iterative try-and-fail process is repeated until the correct root key is found.
Note the high computational cost of correcting falsely guessed key bytes in
this approach.
Tews, Weinmann and Pyshkin extend the Kleins attack such that it is
possible to compute key bytes independently of each other.
Consider Line 4 of Algorithm 1 during an (i + 3)rd round, for some
i n 3:
ji+3 = ji+2 + Si+2 [i + 2] + K[ i + 2 mod l ] .
(23)
Similarly the (i + 2)nd round yields
ji+2 = ji+1 + Si+1 [i + 1] + K[ i + 1 mod l ] ,
and substituting ji+2 in (23) gives
ji+3 = ji+1 +
i+2
X
Sm [m] +
m=i+1
i+2
X
K[ m mod l ] .
m=i+1
We assume that the root key is not changed during the attack, what is very likely to
be true in practice.
i+2
X
Sm [m] +
m=3
i+2
X
K[ m mod l ] .
(24)
m=3
i+3
X
1
K[ m mod l ] = Si+3
[ i + 3 X[i + 2] ] (j3 +
m=3
i+3
X
Sm [m]) )
m=3
{z
1.36
.
n
(25)
m=3
The right side of the equality under the Pr sign is dependent on the first
i + 3 key setup rounds. The authors of the PTW attack note that with
a rather high probability elements in S that are used in this expression
stay unchanged since the third round of the key setup algorithm. Thus we
can replace them with the corresponding elements in S3 and still have a
significant probability deviation for small is [2, Equations 7 and 8)]:
Pr( i = S31 [ i + 3 X[i + 2] ] (j3 +
i+3
X
S3 [m]) ) >
m=3
{z
Ai
1
.
n
(26)
The PTW attack proceeds as follows. For each captured packet we run
the first three rounds of the RC4 key setup algorithm and compute the
values Ai for all i {0, 1, ..., 12}. Every new IV yields new (possibly repeating) thirteen values Ai . When a sufficient number of packets is analysed,
we choose the most frequent candidates for Ai s and assign them to the
variables i for all i {0, 1, ..., 12}. The root key bytes are then obtained
using
Rk[0] = 0 ; Rk[i] = i i1 , i {1, ..., 12} .
The root key is then checked for correctness by a trial decryption. If it
is wrong, we choose less frequent candidates for i s and try again. As
compared to Kleins attack, this approach does not require recalculation of
statistics for rightmost key bytes every time we correct a falsely guessed i .
9
References
[1] Andreas Klein. Attacks on the RC4 stream cipher. Des. Codes Cryptography, 48(3):269286, 2008.
[2] Erik Tews, Ralf-Philipp Weinmann, and Andrei Pyshkin. Breaking 104
bit WEP in less than 60 seconds. In Sehun Kim, Moti Yung, and HyungWoo Lee, editors, WISA, volume 4867 of Lecture Notes in Computer
Science, pages 188202. Springer, 2007.
10