Wiener's attack

From HandWiki

The Wiener's attack, named after cryptologist Michael J. Wiener, is a type of cryptographic attack against RSA. The attack uses the continued fraction method to expose the private key d when d is small.

Background on RSA

Fictional characters Alice and Bob are people who want to communicate securely. More specifically, Alice wants to send a message to Bob which only Bob can read. First Bob chooses two primes p and q. Then he calculates the RSA modulus N = pq. This RSA modulus is made public together with the encryption exponent e. N and e form the public key pair (e, N). By making this information public, anyone can encrypt messages to Bob. The decryption exponent d satisfies ed=1modλ(N), where λ(N) denotes the Carmichael function, though sometimes φ(N), the Euler’s phi function, is used (note: this is the order of the multiplicative group N*, which is not necessarily a cyclic group). The encryption exponent e and λ(N) also must be relatively prime so that there is a modular inverse. The factorization of N and the private key d are kept secret, so that only Bob can decrypt the message. We denote the private key pair as (d, N). The encryption of the message M is given by CMemodN and the decryption of cipher text C is given by Cd(Me)dMedMmodN (using Fermat's little theorem).

Using the Euclidean algorithm, one can efficiently recover the secret key d if one knows the factorization of N. By having the secret key d, one can efficiently factor the modulus of N.[1]

Small private key

In the RSA cryptosystem, Bob might tend to use a small value of d, rather than a large random number to improve the RSA decryption performance. However, Wiener’s attack shows that choosing a small value for d will result in an insecure system in which an attacker can recover all secret information, i.e., break the RSA system. This break is based on Wiener’s Theorem, which holds for small values of d. Wiener has proved that the attacker may efficiently find d when d<13N14.[2]

Wiener's paper also presented some countermeasures against his attack that allow fast decryption. Two techniques are described as follows.

Choosing large public key: Replace e by e, where e=e+kλ(N) for some large of k. When e is large enough, i.e. e>N32, then Wiener’s attack can not be applied regardless of how small d is.

Using the Chinese Remainder Theorem: Suppose one chooses d such that both dp=dmod(p1) and dq=dmod(q1) are small but d itself is not, then a fast decryption of C can be done as follows:

1. First compute MpCdpmodp and MqCdqmodq.
2. Use the Chinese Remainder Theorem to compute the unique value of MZ which satisfies MMpmodp and MMqmodq. The result of M satisfies MCdmodN as needed. The point is that Wiener’s attack does not apply here because the value of dmodλ(N) can be large.[3]


How Wiener's attack works

Note that

λ(N)=lcm(p1,q1)=(p1)(q1)G=φ(N)G

where G=gcd(p1,q1)

Since

ed1(modλ(N)),

there exists an integer K such that

ed=K×λ(N)+1
ed=KG(p1)(q1)+1

Defining k=Kgcd(K,G) and g=Ggcd(K,G), and substituting into the above gives:

ed=kg(p1)(q1)+1.

Divided by dpq:

epq=kdg(1δ), where δ=p+q1gkpq.

So, epq is slightly smaller than kdg, and the former is composed entirely of public information. However, a method of checking[clarification needed] and guess is still required.

By using simple algebraic manipulations and identities, a guess can be checked for accuracy.[1]

Wiener's theorem

Let  N=pq with  q<p<2q. Let d<13N14.
Given N,e with ed1 (mod λ(N)), the attacker can efficiently recover d.[2][failed verification]

Example

Suppose that the public keys are N,e=90581,17993
The attack shall determine d.
By using Wiener's Theorem and continued fractions to approximate d, first we try to find the continued fractions expansion of eN. Note that this algorithm finds fractions in their lowest terms. We know that

eN=1799390581=15+129++13=[0,5,29,4,1,3,2,4,3]

According to the continued fractions expansion of eN, all convergents kd are:

kd=0,15,29146,117589,146735,5552794,12566323,557928086,1799390581

We can verify that the first convergent does not produce a factorization of N. However, the convergent 15 yields

φ(N)=ed1k=17993×511=89964

Now, if we solve the equation

x2((Nφ(N))+1)x+N=0
x2((9058189964)+1)x+90581=0
x2618x+90581=0

then we find the roots which are x=379;239. Therefore we have found the factorization

N=90581=379×239=p×q.

Notice that, for the modulus N=90581, Wiener's Theorem will work if

d<N1435.7828.

Proof of Wiener's theorem

The proof is based on approximations using continued fractions.[2][4]
Since ed=1modλ(N), there exists a k such that edkλ(N)=1. Therefore

|eλ(N)kd|=1dλ(N).

Let G=gcd(p1,q1); note that if φ(N) is used instead of λ(N), then the proof can be replaced with G=1 and φ(N) replaced with λ(N).

Then multiplying by 1G,

|eφ(N)kGd|=1dφ(N)

Hence, kGd is an approximation of eφ(N). Although the attacker does not know φ(N), he may use N to approximate it. Indeed, since

φ(N)=Npq+1 and p+q1<3N, we have:

|p+q1|<3N
|Nφ(N)|<3N

Using N in place of φ(N) we obtain:

|eNkGd|=|edGkNNGd|=|edGkφ(N)kN+kφ(N)NGd|=|1k(Nφ(N))NGd|<|k(Nφ(N))NGd|(0<|Nφ(N)|)<|3kNNGd|=3kNNNGd3kdN

Now, kλ(N)=ed1<ed, so kλ(N)<ed. Since e<λ(N), so kλ(N)<ed<λ(N)d, then we obtain:

kλ(N)<λ(N)d
k<d

Since k<d and d<13N14. Hence we obtain:

(1) |eNkGd|<1dN14

Since d<13N14,2d<3d, then 2d<3d<N14, we obtain:

2d<N14, so (2) 12d>1N14

From (1) and (2), we can conclude that

|eNkGd|<3kdN<1d2d=12d2

If |xab|<12b2, then ab is a convergent of x, thus kGd appears among the convergents of eN. Therefore the algorithm will indeed eventually find kGd.


References

Further reading