Attacks on plain RSA, factoring from RSA secrets, and the RSA-to-factoring hierarchy #
Algebraic attacks on plain (textbook) RSA encryption c = m ^ e % N (rsaEval), the elementary
steps that recover the factorization of N from secret RSA data, and the polynomial-time
reductions connecting RSAOneWay, RSAKeyRecoveryHard, TotientHard, and
ModulusFactoringHard.
- Malleability.
rsaEvalis multiplicative, so anyone can turn an encryption ofminto an encryption ofm * s % N. - Common modulus. Two encryptions
c₁,c₂of the same unitmunder one modulusNand coprime exponentse₁, e₂revealm: Shamir's trickcommonRoot N e₂ e₁ c₁ c₂fromRSACommonRoot.leanreturnsm % N(commonRoot_rsaEval). - Small messages and the broadcast attack. If
m ^ e < N, the ciphertext ism ^ eover the integers, somis its integere-th root. If the samemis sent to receivers with pairwise coprime moduli whose product exceedsm ^ e, the Chinese remainder combination of the ciphertexts is againm ^ e. - Factoring from
φ(N)andTotientHard ↔ ModulusFactoringHard.N = p * qandφ(N) = (p - 1) * (q - 1)determinep + qand(p - q) ^ 2, hencepandqin polynomial time (factorOfTotient,computableInPolyTime_factorOfTotient), giving the polynomial-time equivalencetotientHard_iff_modulusFactoringHard(after [KL20], Theorem 9.49). - Computing
dfromφ(N)andRSAOneWay ⇒ RSAKeyRecoveryHard ⇒ TotientHard ⇔ ModulusFactoringHard. Given(N, e)andφ(N), the unsigned extended Euclidean algorithmBinaryGcd.modInv e φ(N)recovers a valid private exponentd', andrsaInvert N d'invertsrsaEval N eon all residues moduloN(RSAOneWay.rsaKeyRecoveryHard,RSAOneWay.totientHard,RSAOneWay.modulusFactoringHard). - Factoring from
x ^ 2 ≡ y ^ 2 [MOD N], nontrivial square roots of1, and(N, e, d). Anyx, ywithx ^ 2 ≡ y ^ 2 [MOD N],x ≢ y [MOD N], andx + y ≢ 0 [MOD N]yield a proper factorgcd(x + y, N)ofN, andgcd(x - y, N)wheny ≤ x(gcd_sub_proper_of_sq_modEq,gcd_add_proper_of_sq_modEq) Boneh–Shoup, §16.4.1, p. 697. Takingy = 1recovers the nontrivial-square-root factoring lemmasgcd_sub_one_proper_of_sq_modEq_oneandgcd_add_one_proper_of_sq_modEq_oneArora–Barak, Lemma 20.24, and every unitxmoduloNsatisfiesx ^ (e * d - 1) ≡ 1.
Main definitions #
Cslib.Crypto.factorOfTotient: the two factors ofNcomputed fromNandφ(N).Cslib.Crypto.totientGame,Cslib.Crypto.TotientHard,Cslib.Crypto.factorToTotient,Cslib.Crypto.totientToFactor: the Euler totient computation experiment, assumption, and PPT reductions to and from integer factoring.Cslib.Crypto.rsaKeyRecoveryGame,Cslib.Crypto.RSAKeyRecoveryHard,Cslib.Crypto.totientToKeyRecovery,Cslib.Crypto.keyRecoveryToRSA,Cslib.Crypto.factorToRSA: the RSA private-exponent recovery experiment, assumption, and PPT reductions to totient computation, integer factoring, and RSA inversion.
Main results #
Cslib.Crypto.rsaEval_mul,Cslib.Crypto.rsaInvert_rsaEval_mul: plain RSA is multiplicatively homomorphic, and the blinded ciphertext decrypts tom * s % N.Cslib.Crypto.commonRoot_rsaEval: the common-modulus attackcommonRoot N e₂ e₁ c₁ c₂recoversm % Nfor every unitmand coprimee₁,e₂.Cslib.Crypto.rsaEval_eq_pow_of_pow_lt,Cslib.Crypto.eq_of_pow_eq_rsaEval: a short message is the unique integere-th root of its ciphertext.Cslib.Crypto.chineseRemainderOfList_rsaEval_eq_pow: the broadcast attack.Cslib.Crypto.factorOfTotient_eq,Cslib.Crypto.RSADesc.factorOfTotient_eq,Cslib.Crypto.computableInPolyTime_factorOfTotient: factoring fromφ(N)in polynomial time.Cslib.Crypto.totientHard_iff_modulusFactoringHard: computingφ(N)fromN = p * qis polynomial-time equivalent to factoringN(after [KL20], Theorem 9.49).Cslib.Crypto.RSAKeyRecoveryHard.totientHard,Cslib.Crypto.RSAKeyRecoveryHard.modulusFactoringHard,Cslib.Crypto.RSAOneWay.rsaKeyRecoveryHard,Cslib.Crypto.RSAOneWay.totientHard,Cslib.Crypto.RSAOneWay.modulusFactoringHard:RSAOneWayimplies private-exponent recovery hardness, totient hardness, and integer factoring hardness.Cslib.Crypto.gcd_sub_proper_of_sq_modEq,Cslib.Crypto.gcd_add_proper_of_sq_modEq,Cslib.Crypto.gcd_sub_one_proper_of_sq_modEq_one,Cslib.Crypto.gcd_add_one_proper_of_sq_modEq_one,Cslib.Crypto.RSADesc.pow_mul_sub_one_modEq_one,Cslib.Crypto.RSADesc.gcd_sub_one_proper,Cslib.Crypto.RSADesc.gcd_add_one_proper: factoring fromx ^ 2 ≡ y ^ 2 [MOD N], from a nontrivial square root of1moduloN, and the number-theoretic steps of factoring from(N, e, d).
Implementation notes #
The common-modulus attack is the program commonRoot of RSACommonRoot.lean on the two
ciphertexts, so computableInPolyTime_commonRoot is its polynomial-time certificate; its
correctness statement requires coprime exponents and m coprime to N.
The deterministic polynomial-time reductions
TotientHard gen ↔ ModulusFactoringHard (fun n => (gen n).map RSADesc.modulus) ([KL20],
Theorem 9.49) and RSAOneWay gen → RSAKeyRecoveryHard gen → TotientHard gen are proved in full.
The two statements on factoring from (N, e, d) are the deterministic ingredients of the reverse
direction ModulusFactoringHard → RSAKeyRecoveryHard ([KL20], Theorem 9.50 and
Corollary 9.51, Section 9.2.5), which also needs the probability bound that a random unit leads to
a nontrivial square root of 1; that probabilistic algorithm and its analysis are not formalized
here, so Theorem 9.50 and Corollary 9.51 themselves are not claimed. For
x ^ 2 ≡ y ^ 2 [MOD N] ([BS23], Section 16.4.1, p. 697), only the deterministic
gcd-factoring conclusion is formalized; the heuristic probability over random x, y is excluded.
References #
- S. Arora and B. Barak, Computational Complexity: A Modern Approach (2007 draft), Lemma 20.24.
- J. Katz, Y. Lindell, Introduction to Modern Cryptography, Section 9.2.5, pp. 333–336 (Theorem 9.49, Theorem 9.50, and Corollary 9.51) and Section 12.5.1, pp. 436–440 (plain RSA encryption Construction 12.26 and its attacks for small messages and for one message sent to several receivers). This is the source of the definitions.
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography,
Section 16.4.1, p. 697 (factoring from
x ^ 2 ≡ y ^ 2 [MOD N]); context only for the remainder: the book has no private-exponent recovery experiment, Section 10.3, Attack Game 10.3 (p. 404) and Definition 10.5 (p. 405) state the RSA assumption, and Section 16.4, p. 696, gives the algorithm that factorsN, computesdand then inverts.
Malleability #
Malleability of plain RSA: multiplying a ciphertext of m by the encryption of any s gives
a ciphertext that decrypts to m * s % N.
Common modulus #
The common-modulus attack on plain RSA: from the encryptions c₁ = rsaEval N e₁ m and
c₂ = rsaEval N e₂ m of one message m under the same modulus N and coprime exponents e₁,
e₂, Shamir's trick commonRoot N e₂ e₁ c₁ c₂ recovers m % N whenever m is coprime to N.
The attack is therefore the program commonRoot on the ciphertexts, and
computableInPolyTime_commonRoot at (N, e₂, e₁, c₁, c₂) is its polynomial-time certificate.
Small messages and the broadcast attack #
The broadcast attack: if one message m is encrypted under pairwise coprime moduli N i
(i ∈ l) with a common exponent e and m ^ e is smaller than the product of the moduli, then
the Chinese remainder combination of the ciphertexts is m ^ e over the integers.
The broadcast attack recovers the message: m is the unique integer e-th root of the Chinese
remainder combination of its ciphertexts.
Factoring from φ(N) #
For positive q ≤ p, factorOfTotient recovers (p, q) from p * q and
(p - 1) * (q - 1).
Factoring from x ^ 2 ≡ y ^ 2, nontrivial square roots of 1, and (N, e, d) #
Square-congruence factoring (gcd(x - y, N)): for any N and y ≤ x, if
x ^ 2 ≡ y ^ 2 [MOD N], x ≢ y [MOD N], and x + y ≢ 0 [MOD N], then gcd(x - y, N) is a
proper factor of N Boneh–Shoup, §16.4.1, p. 697.
Square-congruence factoring (gcd(x + y, N)): for any N, x, and y, if
x ^ 2 ≡ y ^ 2 [MOD N], x ≢ y [MOD N], and x + y ≢ 0 [MOD N], then gcd(x + y, N) is a
proper factor of N Boneh–Shoup, §16.4.1, p. 697.
Nontrivial square root of 1 gives a proper factor (gcd(y - 1, N)): for any N and y,
if y ^ 2 ≡ 1 [MOD N], y ≢ 1 [MOD N], and y + 1 ≢ 0 [MOD N], then gcd(y - 1, N) is a proper
factor of N Arora–Barak, Lemma 20.24.
Nontrivial square root of 1 gives a proper factor (gcd(y + 1, N)): for any N and y,
if y ^ 2 ≡ 1 [MOD N], y ≢ 1 [MOD N], and y + 1 ≢ 0 [MOD N], then gcd(y + 1, N) is a proper
factor of N Arora–Barak, Lemma 20.24.
Equivalence of computing φ(N) and factoring, and RSA-to-factoring reductions #
factorOfTotient is computable in polynomial time on binary naturals.
The Euler totient hardness assumption for gen: every uniform PPT algorithm has negligible
probability of computing φ(N) = (p - 1) * (q - 1) from N = p * q. This assumption is novel to
this library: [KL20], Section 9.2.5, Theorem 9.49 shows that computing φ(N) is
equivalent to factoring N but states no separate assumption. It is equivalent to
ModulusFactoringHard for the modulus law of gen (totientHard_iff_modulusFactoringHard), so it
is exactly as plausible as factoring. Keys come from any law on RSADesc, which need not be
efficiently samplable.
factorToTotient F is uniform PPT whenever F is uniform PPT.
totientToFactor T is uniform PPT whenever T is uniform PPT.
totientGame gen (factorToTotient F) n equals modulusFactoringGame on the pushed-forward
RSA modulus distribution.
The success probability of T in totientGame is at most the factoring success probability of
totientToFactor T.
If computing φ(N) is hard for gen, then factoring N is hard for
(gen n).map RSADesc.modulus.
If factoring N is hard for (gen n).map RSADesc.modulus, then computing φ(N) is hard for
gen.
After [KL20], Theorem 9.49: computing φ(N) from N = p * q is polynomial-time
equivalent to factoring N.
The RSA private-exponent recovery experiment ([KL20], Section 9.2.5, Theorem 9.50):
sample desc ← gen n, run K n desc.publicKey, and accept when K returns an exponent d' with
desc.e * d' ≡ 1 [MOD desc.totient].
The RSA private-exponent recovery hardness assumption for gen: every uniform PPT algorithm
given (N, e) has negligible probability of finding a valid private exponent d' with
e * d' ≡ 1 [MOD φ(N)]. This assumption is novel to this library: [KL20],
Section 9.2.5, Theorem 9.50 shows that computing d is as hard as factoring N (a direction not
formalized here) but states no separate assumption. It follows from RSAOneWay
(RSAOneWay.rsaKeyRecoveryHard), which makes it plausible, and implies TotientHard
(RSAKeyRecoveryHard.totientHard). Keys come from any law on RSADesc, which need not be
efficiently samplable.
Explicit PPT reduction from RSA private-exponent recovery to computing φ(N): given
pk = (N, e), run T n N to obtain φ' and return the modular inverse
BinaryGcd.modInv e φ'.
totientToKeyRecovery T is uniform PPT whenever T is uniform PPT.
The success probability of T in totientGame is at most the key-recovery success probability
of totientToKeyRecovery T.
If RSA private-exponent recovery is hard for gen, then computing φ(N) is hard for gen.
If RSA private-exponent recovery is hard for gen, then factoring N is hard for
(gen n).map RSADesc.modulus.
Explicit PPT reduction from RSA inversion to RSA private-exponent recovery: given (n, pk, y),
run K n pk to obtain candidate private exponent d' and return rsaInvert pk.N d' y.
Explicit PPT reduction from RSA inversion to integer factoring: factor pk.N, compute φ(N),
invert pk.e modulo φ(N) via BinaryGcd.modInv, and raise the challenge y to that exponent
modulo pk.N.
keyRecoveryToRSA K is a PPT RSAInverter whenever K is uniform PPT.
factorToRSA F is a PPT RSAInverter whenever F is uniform PPT.
The key-recovery success probability of K is at most the RSA inversion success probability of
keyRecoveryToRSA K.
The factoring success probability of F is at most the RSA inversion success probability of
factorToRSA F.
RSA one-wayness implies private-exponent recovery hardness.
RSA one-wayness implies Euler totient computation hardness.
RSA one-wayness implies integer factoring hardness on (gen n).map RSADesc.modulus.