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 [math]\displaystyle{ ed=1 \bmod \lambda (N) }[/math], where [math]\displaystyle{ \lambda (N) }[/math] denotes the Carmichael function, though sometimes [math]\displaystyle{ \varphi(N) }[/math], the Euler’s phi function, is used (note: this is the order of the multiplicative group [math]\displaystyle{ \mathbb{Z}_N^* }[/math], which is not necessarily a cyclic group). The encryption exponent e and [math]\displaystyle{ \lambda (N) }[/math] 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 [math]\displaystyle{ C\equiv M^e\bmod N }[/math] and the decryption of cipher text [math]\displaystyle{ C }[/math] is given by [math]\displaystyle{ C^d\equiv (M^e)^d\equiv M^{ed}\equiv M \bmod N }[/math] (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 [math]\displaystyle{ d\lt \frac{1}{3}N^{\frac{1}{4}} }[/math].[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 [math]\displaystyle{ e }[/math] by [math]\displaystyle{ e' }[/math], where [math]\displaystyle{ e'=e+k \cdot \lambda (N) }[/math] for some large of [math]\displaystyle{ k }[/math]. When [math]\displaystyle{ e' }[/math] is large enough, i.e. [math]\displaystyle{ e'\gt N^{ \frac{3}{2}} }[/math], then Wiener’s attack can not be applied regardless of how small [math]\displaystyle{ d }[/math] is.

Using the Chinese Remainder Theorem: Suppose one chooses d such that both [math]\displaystyle{ d_p = d \bmod (p-1) }[/math] and [math]\displaystyle{ d_{q} = d \bmod (q-1) }[/math] are small but [math]\displaystyle{ d }[/math] itself is not, then a fast decryption of [math]\displaystyle{ C }[/math] can be done as follows:

1. First compute [math]\displaystyle{ M_p\equiv C^{d_p} \bmod p }[/math] and [math]\displaystyle{ M_q\equiv C^{d_q} \bmod q }[/math].
2. Use the Chinese Remainder Theorem to compute the unique value of [math]\displaystyle{ M \in \mathbb{Z_N} }[/math] which satisfies [math]\displaystyle{ M\equiv M_p \bmod p }[/math] and [math]\displaystyle{ M\equiv M_q \bmod q }[/math]. The result of [math]\displaystyle{ M }[/math] satisfies [math]\displaystyle{ M\equiv C^{d} \bmod N }[/math] as needed. The point is that Wiener’s attack does not apply here because the value of [math]\displaystyle{ d \bmod \lambda (N) }[/math] can be large.[3]


How Wiener's attack works

Note that

[math]\displaystyle{ \lambda(N) = \operatorname{lcm}(p-1, q-1) = \frac{(p-1)(q-1)}{G} = \frac{\varphi(N)}{G} }[/math]

where [math]\displaystyle{ G = \gcd (p-1, q-1) }[/math]

Since

[math]\displaystyle{ ed\equiv 1 \pmod{\lambda(N)} }[/math],

there exists an integer K such that

[math]\displaystyle{ ed = K \times \lambda(N)+1 }[/math]
[math]\displaystyle{ ed = \frac {K}{G} (p-1)(q-1)+1 }[/math]

Defining [math]\displaystyle{ k = \frac {K}{\gcd(K,G)} }[/math] and [math]\displaystyle{ g= \frac {G}{\gcd(K,G)} }[/math], and substituting into the above gives:

[math]\displaystyle{ ed = \frac {k}{g} (p-1) (q-1)+1 }[/math].

Divided by [math]\displaystyle{ dpq }[/math]:

[math]\displaystyle{ \frac{e}{pq} = \frac{k}{dg} (1- \delta) }[/math], where [math]\displaystyle{ \delta = \frac {p+q-1- \frac {g}{k}}{pq} }[/math].

So, [math]\displaystyle{ \frac {e}{pq} }[/math] is slightly smaller than [math]\displaystyle{ \frac {k}{dg} }[/math], 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 [math]\displaystyle{ \ N = pq }[/math] with [math]\displaystyle{ \ q \lt p \lt 2q }[/math]. Let [math]\displaystyle{ d \lt \frac{1}{3} N^{\frac{1}{4}} }[/math].
Given [math]\displaystyle{ \left \langle N,e\right \rangle }[/math] with [math]\displaystyle{ ed \equiv 1\ (\mathrm{mod}\ \lambda (N)) }[/math], the attacker can efficiently recover [math]\displaystyle{ d }[/math].[2][failed verification]

Example

Suppose that the public keys are [math]\displaystyle{ \left \langle N,e\right \rangle = \left \langle 90581,17993\right \rangle }[/math]
The attack shall determine [math]\displaystyle{ d }[/math].
By using Wiener's Theorem and continued fractions to approximate [math]\displaystyle{ d }[/math], first we try to find the continued fractions expansion of [math]\displaystyle{ \frac{e}{N} }[/math]. Note that this algorithm finds fractions in their lowest terms. We know that

[math]\displaystyle{ \frac{e}{N} = \frac{17993}{90581} = \cfrac{1}{5 + \cfrac{1}{29 +\dots + \cfrac{1}{3}}} = \left [0,5,29,4,1,3,2,4,3 \right ] }[/math]

According to the continued fractions expansion of [math]\displaystyle{ \frac{e}{N} }[/math], all convergents [math]\displaystyle{ \frac{k}{d} }[/math] are:

[math]\displaystyle{ \frac{k}{d} = 0, \frac{1}{5}, \frac{29}{146}, \frac{117}{589}, \frac{146}{735}, \frac{555}{2794}, \frac{1256}{6323}, \frac{5579}{28086}, \frac{17993}{90581} }[/math]

We can verify that the first convergent does not produce a factorization of [math]\displaystyle{ N }[/math]. However, the convergent [math]\displaystyle{ \frac{1}{5} }[/math] yields

[math]\displaystyle{ \varphi (N) = \frac{ed - 1}{k} = \frac{17993\times5 - 1}{1} = 89964 }[/math]

Now, if we solve the equation

[math]\displaystyle{ x^2 - \left ( \left (N - \varphi (N) \right ) + 1 \right )x + N = 0 }[/math]
[math]\displaystyle{ x^2 - \left ( \left (90581 - 89964 \right ) + 1 \right )x + 90581 = 0 }[/math]
[math]\displaystyle{ x^2 - 618x + 90581 = 0 }[/math]

then we find the roots which are [math]\displaystyle{ x = 379 ; 239 }[/math]. Therefore we have found the factorization

[math]\displaystyle{ N = 90581 = 379 \times 239 = p \times q }[/math].

Notice that, for the modulus [math]\displaystyle{ N = 90581 }[/math], Wiener's Theorem will work if

[math]\displaystyle{ d \lt \frac{N^{ \frac{1}{4}}}{3} \approx 5.7828 }[/math].

Proof of Wiener's theorem

The proof is based on approximations using continued fractions.[2][4]
Since [math]\displaystyle{ ed = 1\bmod \lambda (N) }[/math], there exists a [math]\displaystyle{ \mathit {k} }[/math] such that [math]\displaystyle{ ed - k \lambda (N) = 1 }[/math]. Therefore

[math]\displaystyle{ \left | \frac {e}{\lambda (N)}- \frac {k}{d} \right \vert = \frac{1}{d \lambda (N)} }[/math].

Let [math]\displaystyle{ G = \gcd (p-1, q-1) }[/math]; note that if [math]\displaystyle{ \varphi(N) }[/math] is used instead of [math]\displaystyle{ \lambda(N) }[/math], then the proof can be replaced with [math]\displaystyle{ G = 1 }[/math] and [math]\displaystyle{ \varphi(N) }[/math] replaced with [math]\displaystyle{ \lambda(N) }[/math].

Then multiplying by [math]\displaystyle{ \frac{1}{G} }[/math],

[math]\displaystyle{ \left | \frac {e}{\varphi (N)}- \frac {k}{Gd} \right \vert = \frac{1}{d \varphi (N)} }[/math]

Hence, [math]\displaystyle{ \frac {k}{Gd} }[/math] is an approximation of [math]\displaystyle{ \frac{e}{\varphi(N)} }[/math]. Although the attacker does not know [math]\displaystyle{ \varphi(N) }[/math], he may use [math]\displaystyle{ N }[/math] to approximate it. Indeed, since

[math]\displaystyle{ \varphi(N)= N-p-q+1 }[/math] and [math]\displaystyle{ p+q-1\lt 3 \sqrt{N} }[/math], we have:

[math]\displaystyle{ \left \vert p+q-1 \right \vert \lt 3 \sqrt{N} }[/math]
[math]\displaystyle{ \left \vert N-\varphi (N) \right \vert \lt 3 \sqrt{N} }[/math]

Using [math]\displaystyle{ N }[/math] in place of [math]\displaystyle{ \varphi(N) }[/math] we obtain:

[math]\displaystyle{ \begin{align} \left \vert \frac{e}{N}- \frac{k}{Gd} \right \vert &= \left \vert \frac{edG-kN}{NGd} \right \vert \\ &= \left \vert \frac{edG-k \varphi (N)-kN+k \varphi (N)}{NGd} \right \vert \\ &= \left \vert \frac{1-k(N- \varphi (N))}{NGd} \right \vert \\ &\lt \left \vert \frac{-k(N- \varphi (N))}{NGd} \right \vert (\because 0 \lt |N-\varphi (N)|)\\ &\lt \left \vert \frac{3k \sqrt{N}}{NGd} \right \vert = \frac {3k \sqrt{N}}{\sqrt{N} \sqrt{N}Gd} \le \frac {3k}{d \sqrt{N}} \end{align} }[/math]

Now, [math]\displaystyle{ k \lambda (N)=ed-1\lt ed }[/math], so [math]\displaystyle{ k \lambda (N)\lt ed }[/math]. Since [math]\displaystyle{ e\lt \lambda (N) }[/math], so [math]\displaystyle{ k \lambda (N)\lt ed\lt \lambda (N)d }[/math], then we obtain:

[math]\displaystyle{ k \lambda (N)\lt \lambda (N)d }[/math]
[math]\displaystyle{ k\lt d }[/math]

Since [math]\displaystyle{ k\lt d }[/math] and [math]\displaystyle{ d\lt \frac{1}{3} N^{\frac{1}{4}} }[/math]. Hence we obtain:

(1) [math]\displaystyle{ \left \vert \frac{e}{N}- \frac{k}{Gd} \right \vert \lt \frac{1}{dN^{\frac{1}{4}}} }[/math]

Since [math]\displaystyle{ d\lt \frac{1}{3}N^{ \frac{1}{4}},2d\lt 3d, }[/math] then [math]\displaystyle{ 2d\lt 3d\lt N^{\frac{1}{4}} }[/math], we obtain:

[math]\displaystyle{ 2d\lt N^{\frac{1}{4}} }[/math], so (2) [math]\displaystyle{ \frac{1}{2d}\gt \frac{1}{N^{\frac{1}{4}}} }[/math]

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

[math]\displaystyle{ \left \vert \frac{e}{N}- \frac{k}{Gd} \right \vert \lt \frac{3k}{d \sqrt{N}}\lt \frac{1}{d \cdot 2d}= \frac{1}{2d^2} }[/math]

If [math]\displaystyle{ \left \vert x - \frac{a}{b} \right \vert \lt \frac{1}{2b^2} }[/math], then [math]\displaystyle{ \frac{a}{b} }[/math] is a convergent of [math]\displaystyle{ x }[/math], thus [math]\displaystyle{ \frac{k}{Gd} }[/math] appears among the convergents of [math]\displaystyle{ \frac{e}{N} }[/math]. Therefore the algorithm will indeed eventually find [math]\displaystyle{ \frac{k}{Gd} }[/math].


References

Further reading