Shamir's trick: a common root from coprime exponents #
Theorem 10.6 of [BS23] (p. 416), "Shamir's trick": given a modulus n, relatively prime
exponents e and f, and units w, y modulo n with w ^ e = y ^ f, one can compute an e-th
root of y modulo n without knowing the order of (ℤ/nℤ)ˣ. The book's algorithm computes s,
t with e * s + f * t = gcd(e, f) = 1 by the extended Euclidean algorithm and outputs
x = y ^ s * w ^ t.
Cslib.Crypto.commonRoot n e f w y is that algorithm on natural numbers. It takes
s = modInv e f, the inverse of e modulo f computed by BinaryGcd.modInv, and
t = (e * s - 1) / f, so that e * s - f * t = 1, and it outputs
y ^ s * (w⁻¹) ^ t mod n with w⁻¹ = modInv w n. The cases f = 0 (which forces e = 1; the
output is y mod n) and f = 1 (the output is w mod n) are separate branches: at f = 1,
modInv e 1 = 0, so the general branch would output 1. Correctness follows from the group
identities Commute.zpow_mul_zpow_zpow_eq_right and Commute.zpow_mul_zpow_zpow_eq_left of
CslibFrontier/Foundations/Algebra/Group/ZPowCoprime.lean, applied in (ZMod n)ˣ.
Main definitions #
Cslib.Crypto.commonRoot: the algorithm of Theorem 10.6 on natural numbers.
Main results #
Cslib.Crypto.commonRoot_pow_modEq_right: for0 < n, coprimeeandf,wcoprime tonandw ^ e ≡ y ^ f [MOD n], the outputxsatisfiesx ^ e ≡ y [MOD n].Cslib.Crypto.commonRoot_pow_modEq_left: under the same hypotheses,x ^ f ≡ w [MOD n].Cslib.Crypto.commonRoot_coprime: if moreoveryis coprime ton, the output is coprime ton, so it is a unit modulonas in the book.Cslib.Crypto.commonRoot_lt: for0 < n, the output is belown.Cslib.Crypto.computableInPolyTime_commonRoot:commonRootis computable in polynomial time from polynomial-time inputs onencNat, with no condition on the inputs.
Implementation notes #
The statement differs from the book's in three ways.
- The exponents
eandfare natural numbers. The book allows negative exponents, and its proof of Theorem 10.7 (p. 417) applies the theorem withf = b' - b.rsaHashRootinRSAHash.leanorders the pair so that the exponent isb' - borb - b', whichever is positive, so natural exponents suffice there; the identities inZPowCoprime.leanalready take integer exponents. - One output
xis both ane-th root ofyand anf-th root ofw. The book's theorem states only the first. Section 10.9 (pp. 422–423) applies the theorem to aggregate two membership proofs, and recovering each proof from the aggregate (p. 422) is the second. - The book takes a positive
nand unitsw,ymodulon. Herewandyare natural numbers, not necessarily belown, and the two congruences assume only thatwis coprime ton: forf ≠ 0this makesycoprime ton, and forf = 0they do not need it.commonRoot_coprime, the book'sx ∈ ℤₙ*, also assumes thatyis coprime ton, and uses this only whenf = 0.
The certificate covers the computation on encoded numbers. Nothing here concerns an adversary or
a security game. Theorem 10.5 is in RSAUnitInversion.lean and Theorem 10.7 in RSAHash.lean;
the accumulator of §10.9 is in GUOAccumulator.lean, and its security under strong RSA in
CslibFrontier/Crypto/Computational/GUOAccumulator/Security.lean.
The common-modulus attack on plain RSA is this program on two ciphertexts:
Cslib.Crypto.commonRoot_rsaEval in RSAAttacks.lean proves that for coprime e₁, e₂ and m
coprime to N, commonRoot N e₂ e₁ (rsaEval N e₁ m) (rsaEval N e₂ m) = m % N, and
computableInPolyTime_commonRoot is the attack's polynomial-time certificate.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6, §10.6.2, Theorem 10.6, p. 416.
The algorithm of [BS23], Theorem 10.6 (Shamir's trick), on natural numbers. For a
modulus n, exponents e, f and residues w, y, it returns y mod n when f = 0, w mod n
when f = 1, and otherwise y ^ s * (w⁻¹) ^ t mod n, where s = modInv e f,
t = (e * s - 1) / f and w⁻¹ = modInv w n. When 0 < n, e and f are coprime, w is coprime
to n and w ^ e ≡ y ^ f [MOD n], the output is an e-th root of y and an f-th root of w
modulo n (commonRoot_pow_modEq_right, commonRoot_pow_modEq_left), and a unit modulo n if
y is also coprime to n (commonRoot_coprime).
The output of commonRoot is below a positive modulus.
Shamir's trick ([BS23], Theorem 10.6, p. 416). For 0 < n, coprime e and f,
w coprime to n and w ^ e ≡ y ^ f [MOD n], the output x = commonRoot n e f w y satisfies
x ^ e ≡ y [MOD n]. The book's exponents are integers; here they are natural numbers.
The output of Shamir's trick is also an f-th root of w: for 0 < n, coprime e and f,
w coprime to n and w ^ e ≡ y ^ f [MOD n], commonRoot n e f w y ^ f ≡ w [MOD n]. The book's
Theorem 10.6 does not state this; §10.9 (p. 422) uses it to split an aggregated membership
proof.
The output of Shamir's trick is a unit modulo n, as in [BS23], Theorem 10.6
(x ∈ ℤₙ*): for 0 < n, coprime e and f, w and y coprime to n and
w ^ e ≡ y ^ f [MOD n], commonRoot n e f w y is coprime to n. The hypothesis on y is used
only when f = 0, where the output is y mod n.
commonRoot is computable in polynomial time whenever n, e, f, w and y are
computable in polynomial time as natural numbers on encNat. There is no condition on the
inputs: the modular exponentiations use powMod, which returns 1 at the modulus 0.