Wiener's attack

Last updated

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

Contents

Background on RSA

The RSA system is a public key cryptosystem, described as follows. Two large primes are chosen and the product , known as the modulus, is computed. The Euler totient of is calculated as . An integer , called the public exponent, is chosen, and an integer satisfying is found by use of the Euclidean algorithm.

The public key consists of the pair , while the private key is the integer . Encryption of a message, encoded as an integer , is performed by taking , while decryption of ciphertext is performed by taking . The prime factorization of is also private and may be included in the private key for a more efficient decryption algorithm.

A possible attack on this system involves either directly finding given , or factorizing first and then computing as before using the Euclidean algorithm. Note that it is possible to factorize with the knowledge of any one of or .

Small private key

For performance reasons, one might decide to use a small value of in order to speed up decryption. However, Wiener's attack shows that choosing a small value for 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 . Wiener has proved that the attacker may efficiently find when . [1]

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 by , where for some large integer . When is large enough, for example , Wiener's attack cannot be applied regardless of how small is.

Using the Chinese remainder theorem : A more efficient decryption algorithm, known as CRT-RSA, may be performed by using the primes as the moduli during decryption instead of .

Suppose one chooses such that both and are small but itself is not, then a fast decryption of the ciphertext is performed as follows:

  1. First compute .
  2. Use the Chinese remainder theorem to compute the unique value of that satisfies and . The resulting satisfies . The point is that Wiener's attack does not apply here because the value of can be large. [1]

How the attack works

Since , there exists an integer such that

Dividing by gives

, where is small.

Importantly, the fraction consists of public data and is approximated by the fraction consisting of private data. Wiener's attack exploits this fact by using the continued fraction expansion of to generate fractions close to , known as convergents, and guessing and to be the numerator and denominator of these approximating fractions. Note that the continued fraction for a rational number appears as a byproduct of the Euclidean algorithm and may be computed quickly. When the denominator is small enough relative to , the fraction is guaranteed to be one of these convergents.

The guess can be checked by using and to compute and then checking if this guess for factorizes by solving the quadratic equation

Wiener's theorem

Let with , and let .

Given with , the attacker can efficiently recover . [1] [2]

Example

Suppose that the public keys are . The attack should determine . By using Wiener's theorem and continued fractions to approximate , first we try to find the continued fractions expansion of . Note that this algorithm finds fractions in their lowest terms. We know that

According to the continued fractions expansion of , all convergents are

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

Now, if we solve the equation

then we find the roots which are . Therefore we have found the factorization

.

Notice that, for the modulus , Wiener's theorem will work if

.

Proof of Wiener's theorem

The proof is based on approximations using continued fractions. [1]

Since there exists a such that . Therefore

.

Hence, is an approximation of . Although the attacker does not know , they may use to approximate it.

To see this, note the hypothesis implies , and so

.

Also, for .

The above estimate lets us approximate by (relative to ):

.

In fact, because , we can approximate by (relative to ):

.

Therefore,

Now, since ,

Therefore,

where the last inequality uses from the assumption on .

Now in general, if , then is a convergent of , so appears among the convergents of . We may guess and to be the numerator and denominator of these convergents respectively, and verify if they are correct by computing and attempting to factorize with these guesses. Eventually one such guess (of which there are of them [1.1] ) will be correct.

Python implementation

The following is a minimal implementation of Wiener's attack in Python, given a vulnerable system with public key , based on an online implementation [3] .

importmath# Convergents of num/den as fractionsdefconvergents(num,den):# The Euclidean algorithm gives the denominators, then compute convergentsni,di=(0,1),(1,0)whileden!=0:div=num//dennum,den=den,num%denni=(ni[1],div*ni[1]+ni[0])di=(di[1],div*di[1]+di[0])yield(ni[1],di[1])# Factorizes N when successfuldefwiener(N,e):fork_guess,d_guessinconvergents(e,N):ifk_guess==0:continuephi_guess=(e*d_guess-1)//k_guess# Solve the quadraticcoeff=N-phi_guess+1disc=coeff*coeff-4*Nifcoeff<=0orcoeff>=N+1ordisc<0:continueroot_disc=math.isqrt(disc)ifroot_disc*root_disc!=disc:continuereturn((coeff+root_disc)//2,(coeff-root_disc)//2)returnNone

References

  1. 1 2 3 4 Boneh, Dan. "Twenty years of attacks on the RSA cryptosystem" (PDF). Notices of the American Mathematical Society . 46 (2): 203–213.
    1. ↑ Proof of Theorem 2
  2. ↑ Wiener, Michael J. (1990). "Cryptanalysis of short RSA secret exponents". IEEE Transactions on Information Theory. 36 (3). IEEE: 553–558. Bibcode:1990ITIT...36..553W. doi:10.1109/18.54902.
  3. ↑ Kedmi, Sagi. "Crypto Classics: Wiener's RSA Attack". Sagi Kedmi. Retrieved 1 November 2026.

Further reading