Skip to main content
Springer logoLink to Springer
. 2017 Mar 28;86(4):743–770. doi: 10.1007/s10623-017-0355-3

Analysing and exploiting the Mantin biases in RC4

Remi Bricout 1, Sean Murphy 2, Kenneth G Paterson 2,, Thyla van der Merwe 2
PMCID: PMC6936655  PMID: 31929683

Abstract

We explore the use of the Mantin biases (Mantin, Eurocrypt 2005) to recover plaintexts from RC4-encrypted traffic. We provide a more fine-grained analysis of these biases than in Mantin’s original work. We show that, in fact, the original analysis was incorrect in certain cases: the Mantin biases are sometimes non-existent, and sometimes stronger than originally predicted. We then show how to use these biases in a plaintext recovery attack. Our attack targets two unknown bytes of plaintext that are located close to sequences of known plaintext bytes, a situation that arises in practice when RC4 is used in, for example, TLS. We provide a statistical framework that enables us to make predictions about the performance of this attack and its variants. We then extend the attack using standard dynamic programming techniques to tackle the problem of recovering longer plaintexts, a setting of practical interest in recovering HTTP session cookies and user passwords that are protected by RC4 in TLS. We perform experiments showing that we can successfully recover 16-byte plaintexts with 80% success rate using 231 ciphertexts, an improvement over previous attacks.

Keywords: RC4, Cryptanalysis, Mantin bias, TLS

Introduction

RC4 is a very widely-deployed stream cipher, but its usage in particular applications such as TLS and WPA/TKIP has recently come under heavy attack – see [1, 4, 5, 79], and the concurrent work to ours, [12]. The main idea of these attacks is to exploit known and newly discovered biases in RC4 keystreams to recover fixed plaintexts that are repeatedly encrypted under RC4. Such attacks can be realised against applications using RC4, including TLS and WPA/TKIP, and in particular lead to serious breaks in application layer protocols using TLS.

Mantin [6] showed that patterns of the form ABSAB occur in RC4 keystreams with higher probability than expected for a random sequence. Here A and B are byte values and S is an arbitrary byte string of some length G. Mantin’s main result can be stated as follows. Let G0 be a small integer and let Zr denote the r-th output byte produced by RC4. Under the assumption that the RC4 state is a random permutation at step r, then

Pr(Zr,Zr+1)=(Zr+G+2,Zr+G+3)=2-161+e(-4-8G)/256256. 1

Note that for a truly random byte string Zr,,Zr+G+3, the probability that (Zr,Zr+1)=(Zr+G+2,Zr+G+3) is equal to 2-16. The relative bias is therefore equal to e(-4-8G)/256/256, which is about 1 / 256 for small G.

Mantin’s biases are particularly attractive for use in attacks on RC4 because they are a) relatively large, b) numerous, and c) persistent in RC4 keystreams. Their presence was confirmed experimentally in [6, 10]. Indeed, they have already been exploited in attacks – see [7] and the concurrent work to ours, [12]. In the current paper, we make a systematic study of their use in attacking RC4 in the broadcast setting. Our main contributions can be summarised as follows:

  1. We provide a more fine-grained analysis of the Mantin biases than in the original analysis [6], showing that in fact for certain values of A and B, the biases are non-existent, or, in some cases, stronger than predicted by (1). For example, we show that if A=1 or B=1, then the analysis in [6] fails, and so there is no reason to expect any bias for strings of the form 1BS1B or A1SA1. We also conducted large-scale experiments to confirm that our new analysis is correct. These results are important given the way in which the Mantin biases are used to attack RC4, for two reasons. Firstly, significant deviations from the expected bias behaviour would reduce the effectiveness of the attacks. Secondly, if the biases depended significantly on the values of AB and G, and this dependence was well-understood, then it could be exploited in refined attacks on RC4 (this phenomenon was exploited in [8, 9] for RC4 as deployed in WPA/TKIP, though for different biases).

  2. Fortunately, as we will see, the number of byte pairs (AB) for which Mantin’s analysis is incorrect is small, and the average behaviour is still in-line with (1). This makes it profitable to develop a statistical framework for exploiting the Mantin biases in plaintext recovery attacks for the broadcast setting. We provide such a framework which directly leads to an algorithm that recovers adjacent pairs of unknown plaintext bytes, under the assumption (also used in [7, 12] and valid in practice for attacks against protocols like TLS) that the target plaintext bytes are in the neighbourhood of known plaintext bytes.

  3. Importantly, and in contrast with [7, 12], our analysis enables us to make predictions about the numbers of ciphertexts needed to reliably recover target plaintext bytes. More precisely, our attack computes the likelihood of each possible target plaintext byte pair, and we are able to compute the distribution of the rank of the likelihood of the correct byte pair amongst the likelihoods of all possible pairs as a function of the number of ciphertexts N and the number of known plaintext bytes T. In particular, we can compute the values of (NT) needed to ensure that the median value of the rank is 1, meaning that the correct plaintext is recovered with high probability. Our approach here is to use results from order statistics, a well-established field of statistical investigation that does not appear to have been applied extensively before in cryptanalysis.

  4. Our framework extends smoothly to make predictions in practically interesting cases where, for example, some side information is known about the plaintexts, or where known plaintext bytes are present on either side of the unknown bytes.

  5. We also extend the algorithm targeting just two unknown plaintext bytes to the situation where the target is a longer sequence of unknown plaintext bytes. This is a situation of practical interest in attacking session cookies [1] and passwords [4] that are protected by RC4 in TLS. We formally justify using as a likelihood estimate for a longer sequence of plaintext bytes the sum of the logs of the likelihoods of the overlapping pairs of adjacent bytes comprising that longer sequence. As a consequence of our summation formula for likelihoods, we are able to make use of standard methods from the literature, namely beam search and the list Viterbi algorithm [11], to find longer plaintext candidates having high likelihoods. The beam search algorithm is memory-efficient but does not provide any guarantees about the quality of its outputs; the list Viterbi algorithm is memory-intensive, but is guaranteed to output a list of candidates having the L highest likelihoods, where L is a parameter of the algorithm. In practical attacks involving cookies and passwords, this type of guarantee is sufficient, since large numbers of candidates can be tested for correctness.

  6. We report on a range of experiments with the beam search and list Viterbi algorithms, evaluating their performance for different parameters. For example, using L=216 in the list Viterbi algorithm, N=231 ciphertexts, and 130 known plaintext bytes split either side of a 16-byte unknown plaintext, we are able to recover that 16-byte target plaintext with a success rate of about 80%. This is a significant improvement on the preferred attack of [1], which required around 233234 ciphertexts, and is broadly comparable with the results obtained in [12].

Further remarks on related work

AlFardan et al. [1] presented two attacks against RC4 in TLS, using single-byte biases in the first and double-byte Fluhrer–McGrew biases from [3] in the second. As in our work, their second attack uses a Viterbi algorithm (though only outputting a single plaintext candidate, so not a list Viterbi algorithm). Their second attack requires around 234 ciphertexts to reliably recover a 16-byte target plaintext. Isobe et al. [5] also gave plaintext recovery attacks for RC4 using single-byte and double-byte biases, though their attacks were less effective than those of [1] and they did not explore in detail the applicability of the attacks to TLS.

Ohigashi et al. [7] were the first to use the Mantin biases in plaintext recovery attacks against RC4. They present an attack that targets a single unknown plaintext byte and that uses multiple Mantin biases (for different values of G). Roughly speaking, the unknown plaintext byte is aligned with the second “B” in patterns of the form ABSAB for varying sizes of S, while the plaintext bytes in the other 3 positions are known; a count is made of the number of times in the RC4 output a string ABSAB is suggested for each unknown plaintext byte. In the analysis of [7], all biases are “weighted” in the same way, while, intuitively, the weaker the bias, the less reliable the information about plaintext bytes it provides. This overweights the known plaintext bytes that are far from the unknown, target bytes, and leads to a statistically sub-optimal attack. Their attack also recovers multiple plaintext bytes in a byte-by-byte fashion, meaning that if the attack goes wrong, then it tends to continue wrongly. This in turn means that the success rate of the attack decreases exponentially with the target plaintext length. Ohigashi et al. did not provide any rigorous analysis of their attacks, but instead simulated them to estimate their effectiveness.

In concurrent work to ours, Vanhoef and Piessens [12] conducted an extensive search for new biases in RC4 keystreams, and settled on using the Mantin biases in combination with the Fluhrer–McGrew biases to target the recovery of HTTP session cookies from TLS sessions. (They also presented an attack on WPA/TKIP that is based heavily on the single-byte bias attacks from [8, 9].) Like us, they use a likelihood-based analysis involving Mantin biases, but their analysis is only formalised for single values of G, and they simply take the products of likelihoods for different values of G without further formal statistical justification (though this procedure can be rigorously justified, as our work here shows). They also include in their product a likelihood term arising from the Fluhrer–McGrew biases. Given the ad hoc nature of their approach, they resort to (convincing) verification of attack performance via simulations. By contrast, we are able to provide an analytical approach which makes predictions about the distribution of the rank of our likelihood statistic for the correct plaintext bytes. Vanhoef and Piessens [12] extend their attacks to the recovery of multiple plaintext bytes using a list Viterbi algorithm, though without giving a formal justification as we do. They are able to obtain results for impressive values of L, the list size, in this algorithm. For example, their headline result is obtained using L=223 and recovers a 16-byte plaintext with 94% success rate using N=9·227 ciphertexts and roughly 256 known plaintext bytes on either side of the unknown bytes. However, it should be noted that this result applies for a restricted plaintext alphabet, which, as our analysis shows, can significantly boost the performance of attacks.

Paper organisation

In Sect. 2 we provide further background on the RC4 stream cipher. In Sect. 3, we present our refined analysis of the Mantin biases. Section 4 presents our attacks targeting adjacent pairs of unknown plaintext bytes along with their analysis using order statistics. In Sect. 5, we extend the likelihood analysis developed for pairs of unknown bytes to multiple unknown bytes, and report on our extensive experiments for this setting. Section 6 contains conclusions and open problems (Fig. 1).

Fig. 1.

Fig. 1

Algorithms implementing the RC4 stream cipher. All additions are performed modulo 256

Background

The RC4 algorithm

RC4 allows for variable-length key sizes, anywhere from 40 to 256 bits, and consists of two algorithms, namely, a key scheduling algorithm (KSA) and a pseudo-random generation algorithm (PRGA). The KSA takes as input an l-byte key and produces the initial internal state st0=(i,j,S) for the PRGA; S is the canonical representation of a permutation of the numbers from 0 to 255 where the permutation is a function of the l-byte key, and i and j are indices for S. The KSA is specified in Algorithm 1 where K represents the l-byte key array and S the 256-byte state array. Given the internal state str, the PRGA will generate a keystream byte Zr+1 as specified in Algorithm 2.

For an overview of how RC4 is used in TLS, see [1, 4]. The salient points for our analysis are as follows: in each TLS connection, RC4 is keyed with a 128-bit key that is effectively uniformly random; the key is used throughout the lifetime of a TLS connection.

Known RC4 biases

We recall the main results on biases in RC4 outputs from [3] and [6] that are relevant here. The following is the main result of [3]:

Result 1

Let Zr be the r-th output byte of RC4 given a random key (of any length), where the outputs are numbered starting from 1. Then, for sufficiently large r and for specific values, the adjacent byte pairs (Zr,Zr+1) are non-uniformly distributed as shown in Table 1.

Table 1.

Fluhrer–McGrew biases for consecutive pairs of byte values

(Zr,Zr+1) Condition on i=rmod256 Probability
(0, 0) i=1 2-16(1+2-7)
(0, 0) i1,255 2-16(1+2-8)
(0, 1) i0,1 2-16(1+2-8)
(i+1,255) i254 2-16(1+2-8)
(255,i+1) i1,254 2-16(1+2-8)
(255,i+2) i0,253,254,255 2-16(1+2-8)
(255, 0) i=254 2-16(1+2-8)
(255, 1) i=255 2-16(1+2-8)
(255, 2) i=0,1 2-16(1+2-8)
(129, 129) i=2 2-16(1+2-8)
(255, 255) i254 2-16(1-2-8)
(0,i+1) i0,255 2-16(1-2-8)

Here, i is the value of the internal variable of the RC4 keystream generation algorithm at the point when the first symbol of the pair is output; i is implemented as an 8-bit counter with wrap-around, and i=rmod256 when the output bytes Zr of RC4 are numbered starting from 1

Extensive computations in [1] confirmed the presence of these biases and also did not reveal any other significant biases in adjacent byte pairs. Further, the biases are present from position 256 onwards.

The following result is a restatement of Theorem 1 of Mantin [6], concerning the probability of occurrence of byte strings of the form ABSAB in RC4 outputs, where A and B represent bytes and S denotes an arbitrary byte string of a particular length G.

Result 2

Let G0 be a small integer. Under the assumption that the RC4 state is a random permutation at step r, then

Pr(Zr,Zr+1)=(Zr+G+2,Zr+G+3)=2-161+e(-4-8G)/256256.

The approximate correctness of the above result was experimentally confirmed in [6] for values of G up to 64 and for long keystreams. Further confirmation for the same range of G and for relatively short keystreams was provided in [10].

A fine-grained analysis of the Mantin biases

The Mantin biases, as presented in Result 2, concern the probability of occurrence of byte strings of the form ABSAB in RC4 outputs. The probabilities do not depend on the specific values of A and B, but are instead averaged over these values, and depend only on the length G of string S. Here we provide more fine-grained results about the statistics of patterns ABSAB in RC4 outputs for specific values of A and B (and in some cases, G). We then verify these through experiment with large numbers of RC4 outputs. All previous experimental confirmations of which we are aware only studied the dependence of the bias on G and so did not observe the phenomena that we catalogue below.

Our notation is the same as in [6] and in Sect. 2. Specifically, S denotes the RC4 permutation, and i and j are the algorithm’s internal indices. We use Sr to denote array S at the end of round r. Similarly we use ir and jr to denote the values of i and j at the end of round r. Also, when studying a pattern ABSAB in the RC4 output, G will denote the length of the string S.

Mantin’s analysis

In [6], Mantin explains that the pattern ABSAB is more likely to arise in RC4 output than in an unbiased random byte stream because of a particular scenario that produces this type of pattern and whose probability is higher than expected. The scenario is as follows: for a given round r, let g denote jr-1-ir-1; now suppose the following three conditions are satisfied:

  1. Sr-1[ir]=1;

  2. jr+g-1=ir-1;

  3. i and j avoid the values ir-1, ir, ir+g-1 and ir+g from round r+1 to round r+g-2, as well as value Sr-1[ir-1]+Sr-1[jr-1] from round r to round r+g-1, and value Sr[ir]+Sr[jr] from round r+1 to round r+g.

Then it can be shown that the bytes output by RC4 at rounds r+g-1 and r+g are equal to the bytes output at rounds r-1 and r, respectively. That is, a pattern ABSAB arises in the RC4 output, with S of length G=g-2. Mantin then goes on to evaluate the probability that these conditions hold, and, with some approximations, finally arrives at the expression in the statement of Result 2.

We now analyse this argument from [6] for special values of A, B and g. For each case, we will use conditions (1) and (2) to show that condition (3) cannot hold. This in turn implies that, for the special values of A, B and g, there is no reason to expect strings ABSAB to occur with the biased probabilities predicted by Mantin.

Case A=1: Since A is the output during round r-1, we know that

Sr-1[Sr-1[ir-1]+Sr-1[jr-1]]=1.

Moreover, because of condition (1) above, we have Sr-1[ir]=1. But Sr-1 is a permutation, which implies that Sr-1[ir-1]+Sr-1[jr-1]=ir. But this is in contradiction with condition (3), since it forbids the equality ik=Sr-1[ir-1]+Sr-1[jr-1] for rkr+g-1.

Case B=1: This case is similar to the previous one. Assuming that B=1, we get Sr[Sr[ir]+Sr[jr]]=1. Condition (1) gives Sr-1[ir]=1, so by the definition of RC4 (in particular, since it swaps S[i] and S[j] in each round), we have Sr[jr]=1. As before, Sr is a permutation, and so its injectivity implies Sr[ir]+Sr[jr]=jr. However, since Sr-1[ir]=1, we know that jr=jr-1+1. Then, since g=jr-1-ir-1, we obtain jr=g+ir-1+1. Finally, since i increments on each round, we get jr=ir+g, which provides the relation Sr[ir]+Sr[jr]=ir+g, giving a contradiction with condition (3).

Case A=253 and g=2: We assume now that A=253 and g=2 (i.e. jr-1=ir-1+2). Since Sr-1[ir]=1 (from condition (1)), we get jr=jr-1+1=ir-1+3. Condition (2) becomes jr+1=ir-1. From the behaviour of the RC4 algorithm (namely jr+1=jr+Sr[ir+1]), we obtain Sr[ir+1]=253. Finally, since ir=ir+1-1 and jr=ir+1+1, the value of S in entry ir+1 is not affected by round r, and so Sr-1[ir+1]=Sr[ir+1]=253. On the other hand, Sr-1[Sr-1[ir-1]+Sr-1[jr-1]]=253, because A=253. By combining these results, and noting that Sr-1 is a permutation, we get Sr-1[ir-1]+Sr-1[jr-1]=ir+1 which invalidates condition (3).

Case B=253 and g=2: Because g=2, as in the previous case, we know that Sr[ir+1]=253. The hypothesis B=253 is equivalent to writing Sr[Sr[ir]+Sr[jr]]=253. Then Sr[ir]+Sr[jr]=ir+1, and condition (3) is contradicted again.

Note that the last two cases above concern patterns of the form ABAB for specific values of A and B (G=0), while the first two cases apply concern patterns with A=0 or B=0 for any value of G0. Between them, the 4 cases account for roughly 1 / 128 of all possible patterns ABSAB.

The Mantin bias when A=B

We now focus on refining Mantin’s estimate for biases in distributions for strings of the form AASAA (i.e. when A=B). We will assume here that A1 and B1, since those cases were already treated above.

When A=B, we have that Sr-1[ir-1]+Sr-1[jr-1]=Sr[ir]+Sr[jr]. This is because these two values are the indices in S that are used for producing outputs A and B in rounds r-1 and r, respectively, and because, by assumption, the elements in these indices are not moved during these rounds. Thus Mantin’s condition (3), which states that i and j must not collide with these two values across certain rounds (amongst other things) is more likely to hold since the two values are equal. Specifically, the term (1-g256)2·e-2g/256 in Mantin’s proof of [6, Lemma 2] can be replaced with a term (1-g256)·e-g/256; when 1-g256 is approximated by e-g/256 as is the case throughout Mantin’s analysis, we finally arrive at the following:

Theorem 1

Let G0 be a small integer. Under the assumption that the RC4 state is a random permutation at step r, then

Pr(Zr,Zr+1)=(Zr+G+2,Zr+G+3)|Zr=Zr+1=2-161+e(-4-6G)/256256.

Notice here how the exponent (-4-6G)/256 replaces the usual exponent of (-4-8G)/256 appearing in Mantin’s bias, leading to larger biases in the special case A=B. Note too that this special case concerns roughly 1 / 256 of all possible patterns ABSAB.

Double-byte bias correction

As shown in Table 1, some pairs of bytes are more likely to occur in RC4 outputs for particular values of i. Some pairs are especially lucky because the bias exists for almost every value of i. This leads to additional biases in patterns of the form ABSAB that are not accounted for by Mantin’s analysis. In fact, the resulting biases are at least twice as big as Mantin’s for G=0 and do not decrease with G; so for G=64, they are ten times the size!

Case A=0 and B=0: According to Table 1, the pair of bytes (0, 0) occurs with probability 2-16(1+2-8), instead of 2-16, for all but two values of i. Hence, based on the Fluhrer–McGrew biases alone, and assuming that occurrences of these biases are pair-wise independent, we would expect the pattern 00S00 (for any size of S) to occur with probability 2-32(1+2-8)22-32(1+2-7). Assuming that the generation mechanism for the Fluhrer–McGrew biases is independent of that for the Mantin biases, the occurrence probabilities can simply be summed, and we might then expect to see 00S00 in RC4 outputs with probability 2-321+2-8e(-4-6G)/256+2-7.

Case A=0 and B=1: Here the analysis is as in the previous case, except that, since B=1, we do not expect to find any Mantin bias at all. Then, for any size of S, the pattern 01S01 can be expected to be output with probability 2-321+2-7.

Case A=255 and B=255: In this case, Table 1 indicates that the byte pair (255, 255) occurs with probability 2-16(1-2-8) for all but one value of i, that is, we have a negative bias in the majority of positions. However A=B, so the analysis in Sect. 3.2 applies for the Mantin bias. Following the same reasoning as before, the occurrence probability for this case is therefore expected to be 2-321+2-8e(-4-6G)/256-2-7.

Note that between them, the above 3 cases concern only a small proportion (3 out of 216) of all possible patterns of the form ABSAB.

Experimental validation

We have conducted experiments to confirm the above theoretical observations.

We computed the distributions of patterns of the form ABSAB for values (ABG) with AB ranging over the possible byte values and for G with 0G64. We used 238 RC4 keystreams with random 128-bit keys, each keystream containing 212 bytes, for a total of 250 keystream bytes; this computation required 72 core-days of computation on our local server (Intel Xeon cores running at 3.3Ghz, 256 GB RAM).

Our experimental results are illustrated in Figs. 2 and 3, which show the biases we observed as a function of byte values A and B, for G=0 (g=2) and aggregated over G, respectively. Note that these plots are predominately red, which aligns with the prediction of Mantin’s analysis that all strings ABSAB have a positive bias.

Fig. 2.

Fig. 2

Observed biases for strings of the form ABAB (G=0) in RC4 outputs for random 128-bit keys for different values of A (x-axis) and B (y-axis). For each position we encode the bias in the keystream for the string ABAB as a colour. The colouring scheme encodes the difference between the observed probabilities and the (expected) probability 1/232, scaled up by a factor of 232 (Color figure online)

Fig. 3.

Fig. 3

Observed biases for strings of the form ABSAB in RC4 outputs for random 128-bit keys and averaged over 0G64 for different values of A (x-axis) and B (y-axis). For each position we encode the bias in the keystream for the string ABSAB as a colour. The colouring scheme encodes the difference between the observed probabilities and the (expected) probability 1/232, scaled up by a factor of 232 (Color figure online)

The data in Fig. 2 is somewhat noisy, but it is possible to see the absence of biases for A=1, B=1, A=253 and B=253. However, when A=B, we do not see the positive bias behaviour predicted by Theorem 1, but instead a small, negative bias. We do not currently have an explanation for this behaviour. Coming now to Fig. 3, showing aggregated behaviour, the absence of biases for A=1, B=1 and the strong positive bias for A=B are clear. It is less easy to see the deviations from Mantin’s predictions arising from the double-byte bias corrections for (A,B)=(0,0),(0,1),(255,255), but they are present. Averaging over G, we empirically observed probabilities that were consistent with the theoretical values computed in Sect. 3.3: for (A,B)=(0,0), the empirical probability was 2-32(1+0.01005), for (A,B)=(1,1), it was 2-32(1+0.00834) and for (A,B)=(255,255), it was 2-32(1-0.00574).

Aside from the special case of A=B and G=0, we did not observe any additional significant deviations from the behaviour predicted by Result 2 and our refinements of that result. However, a larger-scale computation might well reveal further fine structure. For example, as suggested by a reviewer, it is possible that there is a dependence of biases on i. Since i is known to the attacker, if such biases were present and of significant size, then this would result in exploitable behaviour.

A plaintext recovery attack based on Mantin biases and its performance

Whilst we have observed that the distribution of patterns of the form ABSAB in RC4 outputs does not conform exactly with Mantin’s analysis [6], the deviations from the predicted behaviour are small, in the sense of affecting the probabilities of only a small proportion of the possible patterns. This means that, when the Mantin biases are used in statistical plaintext recovery attacks, it is reasonable to assume that the behaviour is as predicted by Result 2.

We do so henceforth, and present a plaintext recovery attack that exploits the Mantin biases. The attack is derived by first posing the plaintext recovery problem as one of maximum likelihood estimation. This enables us to also provide a concise analysis of the expected number of ciphertexts required to successfully recover the correct plaintext (and, more generally, to rank the correct plaintext within the top R candidates, for some chosen value of R).

We operate in the broadcast setting, so the same plaintext is assumed to be encrypted many times under different RC4 keystream segments, in known positions. We target the recovery of two unknown, consecutive plaintext bytes that are adjacent to a group of known plaintext bytes. These attack assumptions (partially known plaintext, broadcast setting) are fully realistic when mounting attacks that target HTTP cookies in protocols such as TLS-RC4 (see [1] for further details).

In the next section, we explain how to extend our attack targeting two consecutive plaintext bytes so as to recover longer strings of bytes.

Maximum likelihood estimation

We consider the problem of plaintext recovery for various situations arising from RC4 encryption as a maximum likelihood problem.

Notational setup

The following setup applies throughout this section, unless otherwise noted. Suppose p1,,pT,PT+1,PT+2 are T+2 successive plaintext bytes which are to be encrypted a number of times under RC4 using a number of different keystreams. We suppose that the first T plaintext bytes p1,,pT are known plaintext bytes, but that the next two plaintext bytes PT+1,PT+2 are unknown and we wish to determine them. (Throughout we use lower-case letters for known quantities, and upper-case for unknown quantities, which can be regarded as random variables.)

We let ci,1,,ci,T,ci,T+1,ci,T+2 denote the T+2 successive known ciphertext bytes obtained by encrypting the plaintext bytes p1,,pT,PT+1,PT+2 using the ith RC4 keystream zi,1,,zi,T,Zi,T+1,Zi,T+2. Thus we have that

zi,1=p1ci,1,,zi,T=pTci,TareknownkeystreambytesandZi,T+1=PT+1ci,T+1,,Zi,T+2=PT+2ci,T+2areunknownkeystreambytes.

Now the Mantin bias can be expressed in the following way. We first define a positive decreasing sequence δ0,δ1,,δT-2 by

δG=e(-4-8G/256)/256=2-8e-164e-G32[G=0,1,,T-2].

Then, from Result 2, we have:

P(Zi,T+1,Zi,T+2)=(zi,T-G-1,zi,T-G)2-16(1+δG).

By contrast, for byte pairs (a1,a2) not in the ith RC4 keystream we have

P(Zi,T+1,Zi,T+2)=(a1,a2)2-16[(a1,a2)(zi,1,zi,2),(zi,T-1,zi,T)].

A likelihood function

We now calculate the probability mass function for θ=(PT+1,PT+2) for the ith encryption based on the above probabilities. This will lead us to a likelihood function for θ.

By a straightforward calculation, we have:

P(PT+1,PT+2)=(p,p)=P(Zi,T+1,Zi,T+2)=(pci,T+1,pci,T+2).

This probability is therefore different from 2-16 if, for some G, there exists a keystream byte pair (zi,T-G-1,zi,T-G) such that

(pci,T+1,pci,T+2)=(Zi,T+1,Zi,T+2)=(zi,T-G-1,zi,T-G)=(pT-G-1ci,T-G-1,pT-Gci,T-G),

that is to say if

(p,p)=(pT-G-1ci,T-G-1ci,T+1,pT-Gci,T-Gci,T+2).

We now let xi,G denote the known 2-byte quantity

(pT-G-1ci,T-G-1ci,T+1,pT-Gci,T-Gci,T+2)

for the ith RC4 encryption, and we let xi=(xi,0,,xi,T-2)T denote the vector of such known 2-byte quantities. If we then let θ denote the value of the unknown plaintext bytes (PT+1,PT+2), then the probability mass function of xi given the parameter θ is

f(xi;θ)2-16(1+δG)xi,G=θ[G=0,,T-2]2-16otherwise.

This means that the likelihood function of the parameter θ=(PT+1,PT+2) given the data xi is given by

L(θ;xi)2-16(1+δG)θ=xi,G[G=0,,T-2]2-16otherwise.

Here the approximations arise from the fact that, for a given i, the equality θ=xi,G could hold for multiple values of G, while our analysis ignores this eventuality (which is of low probability).

We now consider the likelihood function of the parameter θ=(PT+1,PT+2) given N such data vectors x1,,xN derived from known plaintext-ciphertext bytes. If we let

SG(θ;x)=#{xi,G=θ|i=1,,N}

be a count of the number of times the Gth component of x1,,xN is equal to θ, then the joint likelihood function satisfies

L(θ;x1,,xN)2-16NG=0T-2(1+δG)SG(θ;x).

Thus if we let x denote the data x1,,xN, then the log-likelihood function is given by

L(θ;x)=logL(θ;x)=-16Nlog2+G=0T-2SG(θ;x)log(1+δG)-16Nlog2+G=0T-2δGSG(θ;x)δTS(θ;x)-16Nlog2,

where δ=(δ0,,δT-2)T and S(θ;x)=(S0(θ;x),,ST-2(θ;x))T. Thus the value of θ which maximises

δTS(θ;x)L(θ;x)+16Nlog2

is essentially the maximum likelihood estimate θ^ of the plaintext parameter θ=(PT+1,PT+2) given the known data x.

Plaintext recovery attack

The preceding analysis leads immediately to an attack recovering the two unknown bytes θ=(PT+1,PT+2) given access to N ciphertexts: for each value of θ, compute δTS(θ;x) and output the value of θ which maximises this expression.

The attack can be implemented efficiently by processing the i-th ciphertext as it becomes available, using it to compute the quantities xi,G and updating a (T-1)×216 array of integer counters by incrementing the array in positions (G,xi,G) for each G between 0 and T-2. Once all N ciphertexts are processed in this way, the array contains the counts SG(θ;x) from which the log likelihood of each candidate θ can be computed by taking inner products with the vector δ.

Note too that, since the attack produces log likelihood estimates for each of the 216 candidates θ, it is trivially adapted to output a ranked list of plaintext candidates in order of descending likelihood. This feature is important for our extended attacks in the following section.

This basic attack can be extended in several different ways (some of which can be considered in combination):

  1. To the situation where the unknown plaintext bytes are not contiguous with the known plaintext bytes. This merely requires adjusting the above analysis to use Mantin biases for the correct values of G (rather than starting from G=0). Note that because the Mantin biases decrease in strength with increasing G, the attack will be rendered less effective.

  2. To the case where known plaintext bytes are located on both sides of the unknown plaintext bytes (possibly in a non-contiguous fashion on one or both sides). Again, this only requires the above analysis to be adjusted to use the correct set of values for G. Using more biases in this way results in a stronger attack.

  3. To the case where one of two target plaintext bytes, PT+1 say, is already known. This is easily done by considering only the log likelihoods of a reduced set of candidates θ in the attack.

  4. To the situation where the plaintext space is constrained in some way, for example, where the bytes of θ are known to be ASCII characters or where base64 encoding is used. Again, this can be done by working with a reduced set of candidates θ.

Distribution of the maximum likelihood statistic and attack performance

We now proceed to evaluate the effectiveness of the above basic attack, as a function of the number of available ciphertexts, N, and the number of known plaintext bytes, T.

We let θ denote the true value of the plaintext parameter θ. The component SG(θ;x) has a binomial distribution, and there are two cases depending on whether or not θ is this true value θ, so we have

SG(θ;x)Bin(N,2-16(1+δG))andSG(θ;x)Bin(N,2-16)[θθ].

If we write μ=N2-16, then E(SG(θ;x))=2-16N(1+δG)=μ(1+δG) and E(SG(θ;x))=2-16N=μ for θθ, with Var(SG(θ;x))2-16N=μ for all θ (to a very good approximation). For the values of N and hence μ=2-16N of interest to us, these binomial random variables are very well-approximated by normal random variables, and we essentially have

SG(θ;x)N(μ(1+δG),μ)andSG(θ;x)N(μ,μ)[θθ].

Thus the vector S(θ;x)=S0(θ;x),,ST-1(θ;x)T corresponding to the true parameter θ and the vectors S(θ;x)=S0(θ;x),,ST-1(θ;x)T (for θθ) corresponding to other values of the plaintext parameter have a multivariate normal distribution. Furthermore, it is reasonable to assume that the components of these vectors are independent, so we have

S(θ;x)NT-1(μ(1+δ),μIT-1)andS(θ;x)NT-1(μ1,μIT-1)[θθ].

The maximum likelihood statistic is essentially determined by the distributions of δTS(θ;x) and δTS(θ;x) (for θθ). However, these are just rank-1 linear mappings of multivariate normal random variables and so have univariate normal distributions given by

δTS(θ;x)N(μ(δT1+|δ|2),μ|δ|2)andδTS(θ;x)N(μδT1,μ|δ|2)[θθ].

The above distributions suggest that it is convenient to consider the function

J(θ;x)=δTS(θ;x)-μ1Tδμ12|δ|=μ-12|δ|-1δTS(θ;x)-μ12|δ|-12(1Tδ)

on the parameter space. It is clear that J(θ;x) is a very good approximation to an affine transformation of the log-likelihood function, so the value of θ which maximises J(θ;x) is essentially the maximum likelihood estimate θ^ of the plaintext parameter θ=(PT+1,PT+2) given the known data x.

We note that J(θ;x) has a univariate normal distribution with unit variance in both cases as we have

J(θ;x)Nμ12|δ|,1andJ(θ;x)N0,1forθθ.

Furthermore, we may essentially regard all of these random variables J(θ;x) as independent since the random variables Sg(θ;x) are very close to being independent.

The function J(θ;x) can be thought of as a “variance-stabilised” form of log-likelihood function L(θ;x) of the plaintext parameter θ. Furthermore, the squared length of the vector δ can be calculated as

|δ|2=G=0T-2δG2=e132-e132(3-2T)216(e116-1).

This means, for instance, that |δ|0.00385 for T=2 and |δ|0.00930 for T=8, with |δ|0.0156 for large T.

Performance of plaintext ranking in the basic attack

With the above reformulation, finding the maximum likelihood estimate θ^ by maximising the function J(θ;x) can now be seen as essentially comparing a realisation of a normal N(μ12|δ|,1) random variable (corresponding to J(θ;x)) with a set R={J(θ;x)|θθ} of realisations of 216-1=65535 independent standard normal N(0,1) random variables. Thus the maximum likelihood estimate θ^ gives the true plaintext parameter θ if a realisation of an N(μ12|δ|,1) random variable exceeds the maximum of the realisations of 216-1 independent standard normal random variables.

This enables the probability that the maximum likelihood estimate is correct (and the basic attack succeeds) to be evaluated as a function of N and T (where, recall, N denotes the number of available ciphertexts and T denotes the number of known, consecutive plaintext bytes that are immediately followed by an unknown pair of bytes). However, we are able to go further and consider the rank of the correct plaintext θ in the ordered list of values J(θ;x) (from highest to lowest) as a function of N and T, that is to evaluate the performance of the ranking version of the plaintext recovery attack. Such an evaluation makes use of the following result concerning order statistics [2].

Result 3

Suppose X1,,Xk are independent standard normal N(0,1) random variables and that Φ denotes the distribution function of a standard normal N(0,1) random variable. Then Φ(X1),,Φ(Xk) are independent Uni(0,1) random variables and the order statistics X(1),,X(k) satisfy

EΦ(X(j))=jk+1.

It follows that Φ(z) is an accurate representation on a linear uniform scale between 0 and 1 of the position of a value z within X(1),,X(k). Thus the random variable giving the position (from highest to lowest) or “rank” of J(θ;x) within the set R, and hence the rank of θ, is given accurately by rounding the random variable

graphic file with name 10623_2017_355_Equ42_HTML.gif

to the nearest integer.

The distribution function Inline graphic of this (unrounded) rank Inline graphic of θ is given by

graphic file with name 10623_2017_355_Equ43_HTML.gif

where F is the distribution function of J(θ;x), that is to say of an Nμ12|δ|,1 distribution.

Figure 4 shows the cumulative distribution function of the rank Inline graphic for different numbers of ciphertexts, N, for the specific value T=26. It can be seen that as N approaches 232, it becomes highly likely that the rank of θ is rather small. On the other hand, when N drops below 228, the attack does not have much advantage over random guessing (which would produce a diagonal line on the cumulative distribution plot).

Fig. 4.

Fig. 4

Cumulative distribution function of the rank Inline graphic for different numbers of ciphertexts, N (T=26). The x-axis is a dimensionless number representing rank; the y-axis shows the probability that Inline graphic (Color figure online)

The median of Inline graphic, which is very close to the mean of Inline graphic, is the value of z satisfying Inline graphic, that is to say

graphic file with name 10623_2017_355_Equ44_HTML.gif

Table 2 shows some median rankings for the value of J(θ;x) within the set of all such 216=65536 values of J(θ;x). A median rank of “1” indicates that the maximum likelihood estimate θ^ gives the true plaintext parameter θ with high probability.

Table 2.

Median rank of maximum likelihood estimate of plaintext parameter

N 227 228 229 230 231 232 233 234 235 236 237
T=21 28,236 26,390 23,838 20,387 15,920 10,628 5353 1596 174 3 1
T=23 22,081 18,078 13,105 7664 3024 566 25 1 1 1 1
T=26 15,735 10,423 5176 1502 155 2 1 1 1 1 1

Performance of plaintext ranking in variant attacks

The above analysis is easily extended to evaluate the performance of the variant attacks described in Sect. 4.2.

For variant 1, in which the unknown plaintext bytes are not contiguous with the known plaintext bytes, we need only replace the value of |δ| with the appropriate value computed from the biases actually used in the attack. For variant 2, where known plaintext bytes are located on both sides of the unknown plaintext bytes, the same is true, but this time δ increases; the analysis is otherwise identical. For example, |δ|2 doubles when we use an additional T known plaintext bytes pT+3,,p2T+2 in concert with p1,,pT. Recalling that J(θ;x) has a Nμ12|δ|,1 distribution with μ=2-16N, it can be seen that the effect of doubling |δ|2 by using “double-sided” biases in this way is the same as that of doubling N in the attack; put another way, using double-sided biases reduces the number of ciphertexts needed to obtain a given median ranking for the value of J(θ;x) by a factor of 2.

Variants 3 and 4 both concern the case where the plaintext space for the pair (PT,PT+1) is reduced from a set of 216 candidates to some smaller set of candidates, C say. For example, in variant 3, where one of the plaintext bytes is known, |C|=28. This means that our fundamental statistical problem becomes one of distinguishing a realisation of a normal N(μ12|δ|,1) random variable (corresponding to J(θ;x)) from a now smaller set R={J(θ;x)|θC\θ} of |C|-1 realisations of independent standard normal N(0,1) random variables. Our previous analysis goes through as above, except that we simply replace 216 by |C| where appropriate, resulting in

graphic file with name 10623_2017_355_Equ45_HTML.gif

The effect of this is to divide all the entries in Table 2 by 216/|C|. For example, in variant 3 where |C|=28, we would expect a median rank of roughly 6 with N=230 ciphertexts and T=26.

Note that these two effects are cumulative. For example, using double-sided biases and assuming one byte of plaintext from the pair (PT+1,PT+2) is known has the effect of both reducing N by a factor of 2 and dividing the median rank by 28. Then, for example, with only N=229 ciphertexts and T=26 we would expect J(θ;x) to have a median rank of about 6, meaning that the correct plaintext θ can be expected to have a high ranking.

Experimental validation

We carried out an experimental validation of our statistical analysis, performing experiments with T=26 for different numbers of ciphertexts, N, and computing the cumulative distribution function of the rank Inline graphic. The results are shown in Fig. 5 for N=228, 229 and 230. Good agreement can be seen between the experimental results and the predictions made by our statistical analysis, with the experiments slightly outperforming the theoretical predictions in each case.

Fig. 5.

Fig. 5

Cumulative distribution function of the rank Inline graphic for different numbers of ciphertexts, N (T=26): N=228 (top), N=229 (middle), N=230 (bottom). In each case, the x-axis is a dimensionless number representing rank and the y-axis shows the probability that Inline graphic

Incorporating prior information about plaintext bytes

Prior information about the unknown plaintext bytes is frequently available and can be exploited (see, for example, [4]) to improve attacks.

Prior information in our setting can be incorporated using the inferential form of Bayes Theorem, which can be loosely expressed as

PosteriorLikelihood×Prior,

or equivalently in its logarithmic form as

Log-Posterior=Log-Likelihood+Log-Prior+Constant.

If we let π(θ) denote the prior probability of the plaintext parameter θ=(PT+1,PT+2) and π(θ;x) the posterior probability of the parameter θ given the data x, then we have

logπ(θ;x)=L(θ;x)+logπ(θ)+ConstantδTS(θ;x)+logπ(θ)+Constant.

This suggests that for purposes such as posterior plaintext ranking, we consider an adaptation of J(θ;x) given by

Jπ(θ;x)=δTS(θ;x)+logπ(θ)-μ1Tδμ12|δ|=J(θ;x)+logπ(θ)μ12|δ|.

We note that Jπ(θ;x) has a univariate normal distribution with unit variance as we have

Jπ(θ;x)Nμ12|δ|+logπ(θ)μ12|δ|,1andJπ(θ;x)Nlogπ(θ)μ12|δ|,1forθθ.

It is clear that when N or equivalently μ=2-16N is small, that is roughly speaking when μ|δ|2<<logπ(θ), the mean value of the posterior scoring function is given by EJπ(θ;x)μ-12|δ|-1logπ(θ) for both θ=θ and θθ. Thus when N or μ is small, the posterior scoring function essentially orders the plaintext parameters π according to the prior distribution π; analysis of the available ciphertexts does not yield enough evidence to “overturn” the evidence given by the prior distribution. By contrast when N or μ is large, that is roughly speaking when μ|δ|2>>logπ(θ), then EJπ(θ;x)μ12δ and EJπ(θ;x)0 for θθ. In this situation, the evidence of the experiment “overwhelms” the evidence given by the prior distribution, and we are essentially considering the previous scenario.

The interesting situation is therefore when μ|δ|2 and logπ(θ) are of roughly comparable size. We consider how much data is needed to “overturn” an ordering of plaintext parameters according to their prior probabilities. In this situation, the scoring function for the plaintext parameter has means given by

EJπ(θ;x)=μ12|δ|+logπ(θ)μ12|δ|andEJπ(θ;x)=logπ(θ0)μ12|δ|forθθ.

Thus the scoring function for the correct plaintext parameter θ is expected to exceed that of the plaintext parameter θ when EJπ(θ;x)>EJπ(θ0;x), that is to say when

μ>1|δ|2logπ(θ)π(θ)orequivalentlywhenN>216|δ|2logπ(θ)π(θ)

The interesting case is obviously when π(θ)>π(θ), that is to say when θ is a priori a more likely plaintext parameter than θ. In this case, the above expression indicates how many samples are likely to be required to be able to place an a posteriori rank θ above that for θ. Clearly, the answer depends on the specifics of the distribution π.

Attacks recovering multiple plaintext bytes

We now extend the preceding attacks and analysis to consider the situation where the target plaintext extends over multiple bytes. As in previous [1, 4, 5, 79] and concurrent [12] works, this is important in building practical attacks targeting HTTP cookies, passwords, etc. We are particularly interested in attack algorithms that output lists of candidates rather than single candidates, since in many practical situations, many suggested candidates can be tried one after another, as was first suggested in [1].

This problem was already addressed in [1] and [7] for attacks exploiting Fluhrer–McGrew and Mantin biases, respectively. Although not explicit in [1], the algorithm used there is a Viterbi algorithm and is guaranteed to output the best plaintext candidate on W bytes according to an approximate log likelihood metric; roughly 233234 ciphertexts were needed to recover a 16-byte plaintext with high success rate. The algorithm in [7] proceeds on a byte-by-byte basis and the success probability of it recovering the correct plaintext is the product of success rates for single bytes. This, unfortunately, means that the success rate drops rapidly as a function of the byte-length of the target plaintext. For example, with N=232 ciphertexts and T=66 known plaintext bytes, the algorithm of [7] achieves a success rate of 0.7656 for a single byte, but this would be reduced to (0.7656)16=0.014 for 16 bytes.

Throughout this section, we let W denote the byte-length of the target plaintext, and L the size of the list of plaintext candidates output by our plaintext recovery algorithms. An algorithm is declared successful if the target plaintext is to be found in the output list.

A likelihood analysis for multiple plaintext bytes

As previously, we assume plaintext bytes p1,,pT are known. Our task now is to recover the W unknown bytes θ=(PT+1,,PT+W). We let θw denote (PT+w,PT+w+1) for 1wW-1. Using the methods of Sect. 4, we can form W-1 ranked lists of values for L(θw;x), where as before x denotes the collection of N data vectors x1,,xN derived from known plaintext-ciphertext bytes. Note here that when w2, these log-likelihoods will be computed using progressively weaker Mantin biases with G1.

To evaluate the overall log-likelihood L(θ;x), we will replace this quantity with the sum:

w=1W-1L(θw;x) 2

of log-likelihoods for the byte pairs θi.

This replacement is formally justified as follows. Consider the probability mass function of a data vector xi given the unknown byte pairs θ=(θ1,,θW-1). This can be approximated as

f(xi;θ1,,θW-1)2-16(1+δG+w-1)xi,G=θw2-16otherwise.

Here, the nature of the approximation is similar to that made in our analysis in Sect. 4: it assumes that at most one low probability event xi,G=θw occurs for each i.

However, the probability mass function of a data vector xi given a single unknown byte pair θw can be approximated as

f(xi;θw)2-16(1+δG+w-1)xi,G=θw2-16otherwise,

so the product of all such probability mass functions can be approximated as

w=1W-1f(xi;θw)2-16(W-2)2-16(1+δG+w-1)xi,G=θw2-16(W-2)2-16otherwise.

This enables us to give an approximate proportionality relationship between the the probability mass function of a data vector xi given the unknown byte pairs θ=(θ1,,θW-1) and the probability mass functions of a data vector xi given single unknown byte pairs θw since we now see that

f(xi;θ1,,θW-1)w=1W-1f(xi;θw).

This can be re-formulated in terms of likelihood functions as

L(θ;xi)=L(θ1,,θW-1;xi)w=1W-1L(θw;xi).

The likelihood function of the byte pairs θ=(θ1,,θW-1) given all the data vectors x=(x1,,xN) is therefore proportional (to a good approximation) to a product of individual likelihood functions, that is to say

L(θ;x)i=1Nw=1W-1L(θw;xi)=w=1W-1i=1NL(θw;xi)=w=1W-1L(θw;x),

which can be expressed in log-likelihood terms (for some constant C) as

L(θ;x)C+w=1W-1L(θw;x).

Thus maximising the overall log-likelihood L(θ;x) can be achieved (to a good approximation) by maximising the sum w=1W-1L(θw;x) of individual log-likelihoods.

Algorithms for recovering multiple plaintext bytes

It follows from the above analysis that, to find high log-likelihood candidates for θ, we need to find sequences of overlapping byte pairs θw for which the sums in (2) are large, given the W-1 lists L(θw;x). This is a classic problem in dynamic programming that can be solved by a number of different approaches. We consider two such standard approaches:

List Viterbi

The (parallel) list Viterbi algorithm is described in detail in [11] and generalises the usual Viterbi algorithm. In its general form it finds the L lowest cost state sequences through a complete trellis of some width W on some state space, given an initial state and a final state and where each state transition in the trellis has an associated cost. The algorithm is easily adapted to the problem at hand by setting the edge weights to be the log-likelihood values L(θw;x) and interpreting the states as byte values.1 Unfortunately, the algorithm is relatively memory intensive and slow, requiring roughly 256·W times as much storage as the beam search algorithm to return a final list of L candidates.2 However, the algorithm has the advantage that it guarantees to return the L best plaintext candidates on W bytes, that is the top L candidates according to the metric represented by (2). The same algorithm appears to have been used in [12].

Beam search

In the beam search algorithm, we generate a list of L candidates on j positions T+1,,T+j, each candidate being accompanied by a partial sum w=1j-1L(θw;x). We then expand the list to include all 256·L candidates that are 1-byte extensions of candidates on the list, computing a new sum w=1jL(θw;x) for each candidate by adding a term L(θw;x). We then prune the list back to L candidates again, by keeping just the top L candidates, but now on w+1 positions. The process is initialised using the top L values for L(θ1;x) on the first two unknown plaintext bytes. The process is finalised when w=W-1, and the list need not be pruned at the final step, though we do so in our implementation to provide a fair comparison with the list Viterbi algorithm. So the algorithm is deemed successful if the correct plaintext (PT+1,,PT+W) appears on the final pruned list of L candidates. In a further enhancement, we may assume the first and last byte of the plaintext are known, and force the candidate plaintexts to begin and end with those known bytes. The beam search algorithm is fast and memory-efficient, but does not provide any guarantees about the quality of its outputs (that is to say, we do not know if it will successfully include the highest log-likelihood plaintext on its output list).

Note that both algorithms extend smoothly to the double-sided case where some plaintext bytes are known on both sides of the W unknown bytes; the only modification is to the computation of the log likelihoods L(θw;x) that are input to the algorithms. Again we will be forced to use Mantin biases starting with non-zero values of G in computing the values L(θw;x), because of the presence of a run of unknown plaintext bytes before reaching the known plaintext bytes. Both algorithms also generalise easily to the case where the plaintext space is constrained in some way, simply by considering only restricted sets of plaintext bytes when extending candidates (in beam search) or traversing the trellis (in the list Viterbi case).

Simulations

Methodology

We performed experiments with the beam search and list Viterbi algorithms, for a variety of attack parameters. We focus on recovering 16 unknown plaintext bytes, a length typical of HTTP cookies, and on attacks using single-sided and double-sided biases with, respectively, T=66 and 130 known plaintext bytes – in the case of List Viterbi, we require a trellis of width 18 as the first and last plaintext bytes need to be known, and for beam search we assume known plaintext bytes, one on either side of the 16 unknown target plaintext bytes. We are most interested in how the attack performance varies with N, the number of available ciphertexts, and L, the pruned list size/output list size in the two algorithms. Further experiments to explore how performance changes with T and W, and for the case of a constrained plaintext space, would be of interest, but we did not have the computing resources available to perform these. Notably, target plaintexts such as cookies often have symbols coming from a much reduced plaintext space, a fact exploited in [12] to reduce their attack’s ciphertext requirements.

Our experiments ran in two phases: in phase 1, we generated 212 groups, each group containing N=227 blocks of keystream bytes. On the fly, for each group, we computed and stored the single-sided and double-sided log-likelihood measures L(θw;x) for each of the 216 possible values of θw for each of 17 overlapping pairs of positions, yielding log-likelihood information for 18 consecutive unknown plaintext bytes. Then, in phase 2, we collated the measures coming from different groups to create measures for groups corresponding to progressively larger sets of blocks. This enabled us to carry out 128 plaintext recovery attacks on up to N=232 ciphertexts each, using our beam search and list-Viterbi algorithms. We ran each of these algorithms with L=216 and computed the success rate across different values of N (typical values of N are n·227 where n{8,10,11,12,13,14,15,16,18,20,24,28,32}). The properties of the list Viterbi algorithm made it easy to extract results for L<216 too.

All computations were performed on the Google Compute Engine (GCE), and we optimised various parameters internal to our code for this platform. Each list Viterbi execution with L=216 on a trellis of width 18 took around 2 hours on a single GCE core; by contrast, the execution of the beam search algorithm completed in a only a couple of minutes for the same parameter L. This favourable running time inspired us to conduct further beam search experiments for higher values of L. For L=217 each beam search experiment took about 20 minutes, and for L=218, the running time was roughly 2.5 hours per experiment. We attribute this unfortunate scaling in the running time to an increasing number of cache misses as L grows. In total for the experiments we used around 6200 GCE core-hours of computation.

Results

We present our results for the attack simulations starting with those for the list Viterbi algorithm. We then discuss a number of results for the beam search algorithm and conclude this section with a comparison of the two algorithms.

List Viterbi Figure 6 shows how the success rate varies with N, the number of ciphertexts available, for the list Viterbi algorithm with double-sided biases (130 known plaintext bytes split either side of 16 unknown bytes, with 2 of the known bytes being used in the list Viterbi algorithm and the remaining 128 being used for computing log likelihoods). Each curve represents a different value of L. It can be seen that, for fixed N, the success rate increases steadily with L and that a threshold phenomenon is observable, where above roughly 230 ciphertexts, the success rate takes off rapidly. For example, with N=231 we see a success rate 86% for L=216. We are confident that the success rate would continue to improve with increasing L and with a larger number of known plaintext bytes, bringing our results into contention with those of [12] (which used 256 known bytes instead of our 130, the significantly larger L=223 in the list Viterbi algorithm, and an undisclosed reduced plaintext space to achieve a success rate of 94% for recovering a 16-byte plaintext with 9·227 ciphertexts, a little over 230 ciphertexts).

Fig. 6.

Fig. 6

Success rate of list Viterbi algorithm in recovering a 16-byte unknown plaintext for different numbers of ciphertexts, N and different list sizes L, using double-sided biases, and 130 known plaintext bytes. The x-axis shows number of ciphertexts divided by 227

Figure 7 compares the performance of the single-sided and double-sided version of the attacks. Not surprisingly, the use of double-sided biases significantly improves the attack performance.

Fig. 7.

Fig. 7

Success rate of list Viterbi algorithm in recovering a 16-byte unknown plaintext for different numbers of ciphertexts, using single-sided and double-sided biases (with 66 and 130 known plaintext bytes, respectively) and L=216. The x-axis shows number of ciphertexts divided by 227

Beam search We note that unless otherwise stated, we use the enhancement of assuming the bytes directly adjacent to the 16 target plaintext bytes to be known, and we force our respective 18-byte candidates to start and end with these bytes. Figure 8 shows the performance of the beam search algorithm for varying numbers of ciphertexts, N, and for L=216,217 and 218. As expected, we do see an improvement in success rates as L grows. For example, with N=231 we see a success rate increase of 3% in going from L=216 to L=218. Significant gains, however, are likely to be made with larger values of L, say L=220.

Fig. 8.

Fig. 8

Success rate of beam search algorithm in recovering a 16-byte unknown plaintext for different numbers of ciphertexts, N, and different sizes of L, using double-sided biases and 130 known plaintext bytes. The x-axis shows number of ciphertexts divided by 227

In order to determine the extent to which assuming adjacent bytes to be known improves attack performance, we ran the following two sets of experiments: We assumed the first byte adjacent to the 16 target plaintext bytes to be known and used the single-sided biases to recover 17-byte candidates (in other words, W=17 with PT+1 known). We then used the single-sided biases to recover 16 unknown target bytes (W=16 and PT+1 unknown).3 Figure 9 shows that there is a small advantage to using this enhancement. For instance, with N=232 we see the success rate increase by 3%.

Fig. 9.

Fig. 9

Success rate of beam search algorithm in recovering a 17-byte plaintext (first byte known) using single sided-biases with 65 known plaintext bytes compared to recovering a 16-byte unknown plaintext using single-sided biases with 64 known plaintext bytes, for different numbers of ciphertexts, N, and for L=216. The x-axis shows number of ciphertexts divided by 227

In a further enhancement, we did not prune the list of plaintext candidates in the final stage of the beam search algorithm. In other words, we retained 28·L candidates in the last step of the process and declared success if the correct plaintext appeared on this larger list of candidates. Figure 10 shows the performance of the beam search algorithm using this enhancement in comparison to the case in which this enhancement is not used. We see a very slight improvement in attack performance as a result of this enhancement.

Fig. 10.

Fig. 10

Success rate of beam search algorithm without final list pruning compared to use of final list pruning in recovering a 16-byte unknown plaintext for different numbers of ciphertexts, N, using double-sided biases and 130 known plaintext bytes, and for L=216. The x-axis shows number of ciphertexts divided by 227

Comparing list Viterbi and beam search

Figure 11 compares the performance of list Viterbi and beam search algorithms with L set to 216 in both cases. It can be seen that the beam search algorithm performs very well, close to the optimal attack that is represented by list Viterbi. It may make for an attractive alternative in practice, especially for such large values of L where the memory consumption of the list Viterbi algorithm becomes prohibitive.

Fig. 11.

Fig. 11

Success rate of list Viterbi algorithm compared to beam search algorithm in recovering a 16-byte unknown plaintext for different numbers of ciphertexts, N, using double-sided biases, L=216, and 130 known plaintext bytes. The x-axis shows number of ciphertexts divided by 227

Conclusions

In this paper, we have thoroughly analysed the Mantin biases in the outputs of the RC4 algorithm and their exploitation in plaintext recovery attacks. We showed, perhaps surprisingly, that some aspects of Mantin’s original analysis were incorrect. Our work provides an improved understanding of the genesis of the Mantin biases. We developed a statistical framework enabling us to make accurate predictions about the performance of plaintext recovery attacks targeting adjacent pairs of plaintext bytes. A particular novelty is the introduction of order statistics, enabling the expected rank of the true plaintext amongst all possible candidates to be computed. We extended the attacks to the situation of multiple unknown plaintext bytes, and provided an experimental evaluation of two different attacks for this setting, using the list Viterbi algorithm and beam search, respectively.

Several open problems are suggested by our work. It would be valuable to extend our analysis of the performance of plaintext ranking from the 2-byte setting to the multi-byte setting to yield predictive power in the latter setting, something that is currently missing from our and all other analyses. For example, it would be desirable to have a closed-form expression for the expected rank of the true plaintext candidate amongst all possible candidates as a function of the attack parameters N, T, and W, and of the size of the plaintext space; this would enable accurate setting of the parameter L (list size) when targeting a particular success rate in a real attack. It would also be interesting and useful to find a means of rigorously integrating the Fluhrer–McGrew biases and the Mantin biases in a single statistical framework, cf. the ad hoc approach in [12].

Finally, it would be beneficial to experiment further with our proposed multi-byte plaintext recovery algorithms. Our two-byte analysis suggests that significant gains can be expected in particular in the case of a reduced plaintext space, for example for base64 or ASCII-encoded plaintexts. These are common in session cookies and passwords, respectively. Another direction would be to integrate the use of Mantin biases with suitable plaintext language models, for example simple Markov models, in an effort to further improve the performance of plaintext recovery attacks.

Acknowledgements

We would like to thank Google for their generous donation of computing resources which supported this work. We also thank an anonymous reviewer for useful comments. Paterson was supported in part by a research programme funded by Huawei Technologies and delivered through the Institute for Cyber Security Innovation at Royal Holloway, University of London, and in part by an EPSRC Leadership Fellowship, EP/H005455/1; van der Merwe was supported by the EPSRC and the UK government as part of the Centre for Doctoral Training in Cyber Security at Royal Holloway, University of London (EP/K035584/1).

Footnotes

1

Several additional notational and conceptual changes are needed compared to the original description in [11]. In particular, the initialisation process described in [11] contains a small error, and we wish to maximise rather than minimise the cost of state sequences. The basic algorithm also requires the first and last bytes of plaintext, PT+1 and PT+W to be known.

2

A low memory version of the algorithm is also given in [11] but we did not implement it.

3

Using the generated double-sided biases with W=18 for the recovery of 16-byte plaintexts would have resulted in us not being able to use some of the strongest biases for plaintext recovery; targeting bytes PT+2 to PT+17 would mean not using biases when G=0, and targeting bytes PT+1 to PT+16 would mean not using biases for each G between 0 and 2 in the recovery of PT+15 and PT+16.

Contributor Information

Remi Bricout, Email: remi.bricout@ens.fr.

Sean Murphy, Phone: +44-1784-443101, Email: s.murphy@rhul.ac.uk.

Kenneth G. Paterson, Phone: +44-1784-414393, Email: kenny.paterson@rhul.ac.uk

Thyla van der Merwe, Phone: +44-1784-443101, Email: thyla.vandermerwe.2012@live.rhul.ac.uk.

References

  • 1.AlFardan N.J., Bernstein D.J., Paterson K.G., Poettering B., Schuldt J.C.N.: On the Security of RC4 in TLS. In: Proceedings of the 22nd USENIX Conference on Security, SEC’13, pp. 305–320. USENIX Association, Berkeley, CA, USA (2013). http://dl.acm.org/citation.cfm?id=2534766.2534793
  • 2.Arnold B., Balakrishnan N., Nagaraja H.: A first course in order statistics. SIAM (2008)
  • 3.Fluhrer S.R., McGrew D.: Statistical analysis of the alleged RC4 keystream generator. In: Schneier B. (ed.) FSE. Lecture Notes in Computer Science, vol. 1978, pp. 19–30. Springer, New York (2000).
  • 4.Garman C., Paterson K.G., van der Merwe T.: Attacks only get better: Password recovery attacks against RC4 in TLS. In: USENIX Security Symposium (2015). http://www.isg.rhul.ac.uk/tls/RC4mustdie.html
  • 5.Isobe T., Ohigashi T., Watanabe Y., Morii M.: Full plaintext recovery attack on broadcast RC4. In: S. Moriai (ed.) Fast Software Encryption - 20th International Workshop, FSE 2013, Singapore, March 11-13, 2013. Revised Selected Papers. Lecture Notes in Computer Science, vol. 8424, pp. 179–202. Springer (2013). doi:10.1007/978-3-662-43933-3_10.
  • 6.Mantin I.: Predicting and distinguishing attacks on RC4 keystream generator. In: Cramer R. (ed.) EUROCRYPT. Lecture Notes in Computer Science, vol. 3494, pp. 491–506. Springer, Heidelberg (2005).
  • 7.Ohigashi T., Isobe T., Watanabe Y., Morii M.: How to recover any byte of plaintext on RC4. In: Lange, T., Lauter, K.E., Lisonek, P. (eds.) Selected Areas in Cryptography-SAC 2013-20th International Conference, Burnaby, BC, Canada, August 14-16, 2013, Revised Selected Papers. Lecture Notes in Computer Science, vol. 8282, pp. 155–173. Springer, Berlin (2013). doi:10.1007/978-3-662-43414-7_8.
  • 8.Paterson K.G., Poettering B., Schuldt J.C.N.: Big bias hunting in Amazonia: Large-scale computation and exploitation of RC4 biases (invited paper). In: Sarkar, P., Iwata, T. (eds.) Advances in Cryptology - ASIACRYPT 2014 - 20th International Conference on the Theory and Application of Cryptology and Information Security, Kaoshiung, Taiwan, R.O.C., December 7-11, 2014. Proceedings, Part I, Lecture Notes in Computer Science, vol. 8873, pp. 398–419. Springer, Berlin (2014). doi:10.1007/978-3-662-45611-8_21.
  • 9.Paterson K.G., Poettering B., Schuldt J.C.N.: Plaintext recovery attacks against WPA/TKIP. In: Cid, C., Rechberger, C. (eds.) Fast Software Encryption - 21st International Workshop, FSE 2014, London, UK, March 3-5, 2014. Revised Selected Papers. Lecture Notes in Computer Science, vol. 8540, pp. 325–349. Springer, Berlin (2014). doi:10.1007/978-3-662-46706-0_17.
  • 10.Paterson K.G., Strefler M.: A practical attack against the use of RC4 in the HIVE hidden volume encryption system. In: Bao, F., Miller, S., Zhou, J., Ahn, G. (eds.) Proceedings of the 10th ACM Symposium on Information, Computer and Communications Security, ASIA CCS ’15, Singapore, April 14-17, 2015, pp. 475–482. ACM (2015). doi:10.1145/2714576.2714596.
  • 11.Seshadri N, Sundberg CW. List Viterbi decoding algorithms with applications. IEEE Trans. Commun. 1994;42(234):313–323. doi: 10.1109/TCOMM.1994.577040. [DOI] [Google Scholar]
  • 12.Vanhoef M., Piessens F.: All your biases belong to us: Breaking RC4 in WPA-TKIP and TLS. In: USENIX Security Symposium (2015). http://www.rc4nomore.com/vanhoef-usenix2015.pdf

Articles from Designs, Codes, and Cryptography are provided here courtesy of Springer

RESOURCES