Documentation

CslibFrontier.Crypto.Computational.RSAUnitInversion

RSA with a uniform unit preimage #

[BS23], §10.6.2, p. 416, modifies the RSA attack game (Attack Game 10.3) so that the challenger draws the preimage x uniformly from the units ℤₙ* and keeps everything else the same; uRSAadv[A, ℓ, e] is the adversary's advantage there. Theorem 10.5 says that an elementary wrapper B around A has uRSAadv[A, ℓ, e] ≤ RSAadv[B, ℓ, e], so the RSA assumption implies this variant. The wrapper hands a unit challenge to A and computes an e-th root of any other challenge itself: 0 for 0, and otherwise y ^ d after factoring n with gcd(y, n).

Main definitions #

Main results #

Implementation notes #

The book states Theorem 10.5 for ℓ > 2 and odd e > 2, the parameters of its key generator RSAGen(ℓ, e). Here keys come from any law on RSADesc, and the theorem has no hypothesis on it: the proof uses only that N = p * q for distinct primes p and q and that e * d ≡ 1 modulo (p - 1) * (q - 1), so p = 2 and e = 1 are allowed. The challenge x ^ e % N is given to the inverter as a residue in Fin N, as in rsaInversionGame, and the inverter wins when it returns x; the two games differ only in the law of x. The bound compares success probabilities at each security parameter. Exercises 10.25–10.26 (§10.11, p. 431), the converse with statistical distance strictly less than 4 / 2 ^ ℓ and additive security loss 4 / 2 ^ ℓ (2 ^ -(ℓ - 2) for ℓ ≥ 2), are formalized in CslibFrontier.Crypto.Computational.RSAUnitInversion.Converse.

The wrapper finds the exponent as the book's proof describes. For a challenge y ≠ 0 that is not a unit, g = gcd(y, N) is p or q, so (g - 1) * (N / g - 1) is (p - 1) * (q - 1) and its modular inverse d' of e is a decryption exponent (rsaNonUnitRoot_rsaEval).

References #

A unit modulo N as a residue in Fin N: its value in [0, N).

The residues of units are exactly the residues coprime to N.

noncomputable def Cslib.Crypto.rsaUnitInversionGame (gen : RSAGen) (inverter : RSAInverter) (n : ℕ) :

The RSA inversion experiment with a uniform unit preimage ([BS23], §10.6.2, p. 416): sample desc ← gen n, draw x uniformly from (ZMod N)ˣ, and run Cslib.Crypto.inversionExperiment on its residue. The inverter receives (pk, x ^ e % N) and wins when it returns a preimage.

theorem Cslib.Crypto.rsaUnitInversionGame_eq (gen : RSAGen) (inverter : RSAInverter) (n : ℕ) :
rsaUnitInversionGame gen inverter n = do let desc ← gen n let x ← Probability.PMF.uniformOfFintype (ZMod desc.modulus)ˣ let x' ← (inverter n desc.publicKey (desc.publicKey.eval (desc.unitResidue x))).eval pure (decide (x' = desc.unitResidue x))

RSA evaluation is a bijection on Fin N, so an inverter wins rsaUnitInversionGame exactly when it recovers the residue of the challenge unit.

The RSA assumption with a uniform unit preimage for gen ([BS23], §10.6.2, p. 416, the variant of Attack Game 10.3 that draws x from ℤₙ*, read with Definition 10.5, p. 405): every PPT inverter recovers a uniform unit from its RSA image with negligible probability. Keys come from any law on RSADesc (RSAGen), which need not be efficiently samplable, in place of Boneh–Shoup's RSAGen(ℓ, e). It follows from RSAOneWay (RSAOneWay.rsaUnitOneWay, Theorem 10.5).

An e-th root modulo N of a challenge y that is not a unit, computed from N and e alone as in the proof of Theorem 10.5 ([BS23], p. 416): 0 for y = 0, and otherwise y ^ d' % N, where g = gcd(y, N) and d' is the inverse of e modulo (g - 1) * (N / g - 1).

theorem Cslib.Crypto.rsaNonUnitRoot_lt {N : ℕ} (hN : 0 < N) (e y : ℕ) :
theorem Cslib.Crypto.coprime_rsaEval_iff (desc : RSADesc) (x : ℕ) :
(rsaEval desc.modulus desc.e x).Coprime desc.modulus ↔ x.Coprime desc.modulus

RSA evaluation maps the residues coprime to N to residues coprime to N, and the others to others.

theorem Cslib.Crypto.rsaNonUnitRoot_rsaEval (desc : RSADesc) {x : ℕ} (hx : x < desc.modulus) (hunit : ¬x.Coprime desc.modulus) :
rsaNonUnitRoot desc.modulus desc.e (rsaEval desc.modulus desc.e x) = x

rsaNonUnitRoot inverts RSA evaluation on every residue x < N that is not coprime to N.

theorem Cslib.Crypto.rsaNonUnitRoot_eq_rsaInvert (desc : RSADesc) {y : ℕ} (hy : y < desc.modulus) (hunit : ¬y.Coprime desc.modulus) :
rsaNonUnitRoot desc.modulus desc.e y = rsaInvert desc.modulus desc.d y

On a residue y < N that is not coprime to N, rsaNonUnitRoot is trapdoor inversion: the e-th root that rsaInvert N d computes with the private exponent is computed from N and e alone.

rsaNonUnitRoot is computable in polynomial time whenever N, e and y are, and 0 < N a.

The wrapper B of Theorem 10.5 ([BS23], p. 416): on a challenge y coprime to N, run A; on any other challenge, return rsaNonUnitRoot N e y.

unitRSAToRSA A is a PPT RSAInverter whenever A is.

Theorem 10.5 ([BS23], §10.6.2, p. 416): the success probability of A with a uniform unit preimage is at most the success probability of unitRSAToRSA A in rsaInversionGame, at every security parameter and for every key generator. On a unit challenge the wrapper runs A, and on any other challenge it always wins. The book assumes ℓ > 2 and odd e > 2; here there is no condition on the key law, so p = 2 and e = 1 are allowed.

The RSA assumption implies its unit-preimage variant ([BS23], §10.6.2, p. 416, after Theorem 10.5), for every key generator.