ArticleslgStudy

computer science

Wiener's attack

Wiener's attack is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Wiener's attack rather than just read about it. In short: Wiener's attack, named after cryptologist Michael J. Wiener, is a type of cryptographic attack against the RSA cryptosystem.

Key takeaways

  • Wiener's attack belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Wiener's attack to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Wiener's attack from memory before moving on to harder problems.

Reference excerpt

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 d when d is small.

Background on RSA

The RSA system is a public key cryptosystem, described as follows. Two large primes p,q are chosen and the product N=pq, known as the modulus, is computed. The Euler totient of N is calculated as φ(N)=(p−1)(q−1). An integer e, called the public exponent, is chosen, and an integer d satisfying ed≡1 (mod φ(N)) is found by use of the Euclidean algorithm. The public key consists of the pair ⟨N,e⟩, while the private key is the integer d. Encryption of a message, encoded as an integer m, is performed by taking c≡me (mod N), while decryption of ciphertext c is performed by taking m≡cd (mod N). The prime factorization of N 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 d given N, or factorizing N first and then computing d as before using the Euclidean algorithm. Note that it is possible to factorize N with the knowledge of any one of p,q or φ(N).

Small private key For performance reasons, one might decide to use a small value of d in order to speed up decryption. 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<13N1/4. 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 integer k. When e′ is large enough, for example e′>N3/2, Wiener's attack cannot be applied regardless of how small d is. Using the Chinese remainder theorem: A more efficient decryption algorithm, known as CRT-RSA, may be performed by using the primes p,q as the moduli during decryption instead of N. Suppose one chooses d such that both dp≡d (mod p−1) and dq≡d (mod q−1) are small but d itself is not, then a fast decryption of the ciphertext c is performed as follows:

First compute mp=cdp (mod p),mq≡cdq (mod q). Use the Chinese remainder theorem to compute the unique value of 0≤m<N that satisfies m≡mp (mod p) and m≡mq (mod q). The resulting m satisfies m≡cd (mod N). The point is that Wiener's attack does not apply here because the value of d mod φ(N) can be large.

How the attack works Since ed≡1 (mod φ(N)), there exists an integer k such that

ed=k(p−1)(q−1)+1. Dividing by Nd=pqd gives

eN=kd(1−δ), where δ=p+q−1−1kpq is small. Importantly, the fraction e/N consists of public data and is approximated by the fraction k/d consisting of private data. Wiener's attack exploits this fact by using the continued fraction expansion of e/N to generate fractions close to e/N, known as convergents, and guessing k and d 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 d is small enough relative to N, the fraction k/d is guaranteed to be one of these convergents. The guess can be checked by using k and d to compute φ(N)=(ed−1)/k and then checking if this guess for φ(N) factorizes N by solving the quadratic equation

x2−(N−φ(N)+1)x+N=0.

Wiener's theorem Let N=pq with q<p<2q, and let d<13N1/4. Given ⟨N,e⟩ with ed≡1 (mod φ(N)), the attacker can efficiently recover d.

Example Suppose that the public keys are ⟨N,e⟩=⟨90581,17993⟩. The attack should 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)=ed−1k=17993×5−11=89964 Now, if we solve the equation

x2−(N−φ(N)+1)x+N=0 x2−618x+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<13N1/4≈5.7828.

Proof of Wiener's theorem The proof is based on approximations using continued fractions. Since ed≡1 (mod φ(N)) there exists a k such that ed=kφ(N)+1. Therefore

|eφ(N)−kd|=|ed−kφ(N)dφ(N)|=1dφ(N). Hence, k/d is an approximation of e/φ(N). Although the attacker does not know φ(N), they may use N to approximate it. To see this, note the hypothesis q<p<2q implies N=pq>q2, and so

N−φ(N)=p+q−1<3q−1<3N. Also, N−φ(N)>0 for N>1. The above estimate lets us approximate ed=kφ(N)+1 by kN+1 (relative to k):

|ed−(kN+1)|=|(kφ(N)+1)−(kN+1)|=|k(φ(N)−N)|<3kN. In fact, because N−φ(N)≥1, we can approximate ed by kN (relative to k):

|ed−kN|=|1−k(N−φ(N))|=k(N−φ(N))−1<k(N−φ(N))<3kN. Therefore,

|eN−kd|=|ed−kNNd|<3kNNd=3kdN Now, since e<φ(N),

k=ed−1φ(N)<edφ(N)<d<13N1/4. Therefore,

|eN−kd|<3kdN<1dN1/4<12d2 where the last inequality uses 2d<N1/4 from the assumption on d. Now in general, if |x−ab|<12b2, then ab is a convergent of x, so k/d appears among the convergents of e/N. We may guess k and d to be the numerator and denominator of these convergents respectively, and verify if they are correct by computing φ(N) and attempting to factorize N with these guesses. Eventually one such guess (of which there are O(log⁡N) of them ) will be correct.

Python implementation The following is a minimal implementation of Wiener's attack in Python, given a vulnerable system with public key ⟨N,e⟩, based on an online implementation.

References

Further reading Coppersmith, Don (1996). Low-Exponent RSA with Related Messages. Springer-Verlag Berlin Heidelberg. Dujella, Andrej (2004). "Continued fractions and RSA with small secret exponent". arXiv:cs/0402052. Python Implementation of Wiener's Attack. R. Stinson, Douglas (2002). Cryptography Theory and Practice (2e ed.). A CRC Press Company. pp. 200–204. ISBN 1-58488-206-9.

Worked examples

Example 1 — a first encounter with Wiener's attack

Start with the simplest possible case. Write down what Wiener's attack claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Wiener's attack before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Wiener's attack ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Wiener's attack

In research
Wiener's attack appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Wiener's attack in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Wiener's attack is common in secondary-school and first-year university syllabi. It links to neighbouring topics Asymmetric-key algorithms, Attacks on public-key cryptosystems, Cryptographic attacks, so understanding it makes those chapters shorter.
In everyday life
Look for Wiener's attack outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Wiener's attack” →

How to study Wiener's attack in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Wiener's attack means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Wiener's attack out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Wiener's attack in simple terms?

Wiener's attack, named after cryptologist Michael J. Wiener, is a type of cryptographic attack against the RSA cryptosystem.

Why does Wiener's attack matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Wiener's attack?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Wiener's attack.

Tags

  • Asymmetric-key algorithms
  • Attacks on public-key cryptosystems
  • Cryptographic attacks

Keep exploring