Documentation

CslibFrontier.Crypto.Computational.RSAHash

Collision resistance from RSA #

[BS23], §10.6.2, defines a hash function from an RSA modulus n, a prime encryption exponent e and a random unit y modulo n (p. 415): H_rsa(a, b) = a ^ e * y ^ b for a unit a modulo n and 0 ≤ b < e. Theorem 10.7 (pp. 416–417) says that H_rsa is collision resistant under the RSA assumption, with the bound (10.3) CRadv[A, H_rsa] ≤ RSAadv[B, ℓ, e]. The proof turns a collision (a, b) ≠ (a', b') into (a / a') ^ e = y ^ (b' - b); then b ≠ b', so b' - b is coprime to the prime e, and Shamir's trick (Theorem 10.6) gives an e-th root of y. That is a win in the RSA game with a uniform unit preimage, and Theorem 10.5 bounds it by the RSA advantage.

Here rsaHash is an instance of Cslib.Crypto.collisionGameFor, as Cslib.Crypto.PrimeOrderGroupFamily.groupHash in CslibFrontier/Crypto/Computational/DiscreteLog/GroupHash.lean is for the discrete-logarithm hash H_dl. The key is an RSAHashKey, drawn by rsaHashSetup. A message is a word, and validRSAHashInput accepts the words that encode a pair (a, b) with a < N coprime to N and b < e.

Main definitions #

Main results #

Implementation notes #

The statements differ from the book's in four ways.

The book's proof applies Theorem 10.6 with f = b' - b, which may be negative. rsaHashRoot orders the pair instead: it takes f = b' - b and w = a * a'⁻¹ when b < b', and f = b - b' and w = a' * a⁻¹ otherwise, so Cslib.Crypto.commonRoot keeps natural exponents.

The use of H_rsa as a compression function in the Merkle–Damgård construction (p. 416) is not formalized; Exercises 10.25–10.26 (§10.11, p. 431) are in CslibFrontier/Crypto/Computational/RSAUnitInversion/Converse.lean. The accumulator of §10.9 is in GUOAccumulator.lean, and its security under strong RSA in CslibFrontier/Crypto/Computational/GUOAccumulator/Security.lean.

References #

The key of the RSA hash ([BS23], §10.6.2, p. 415): an RSA public key (N, e) and a base y.

  • publicKey : RSAPublicKey

    The public key (N, e).

  • base : ℕ

    The base y, a unit modulo N in the experiment.

theorem Cslib.Crypto.encRSAHashKey_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → RSAPublicKey} {x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encRSAPublicKey budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { publicKey := x0 x, base := x1 x }) encIn encRSAHashKey budget
@[reducible, inline]

The tuple of the fields of encRSAHashKey.

theorem Cslib.Crypto.encRSAHashKey_base_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → RSAHashKey} :

The encoding of an RSA hash key: the public key, framed, and the base in binary.

theorem Cslib.Crypto.encRSAHashKey_publicKey_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → RSAHashKey} :
theorem Cslib.Crypto.encRSAHashKey_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → RSAPublicKey} {T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encRSAPublicKey T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { publicKey := x0 x, base := x1 x }) encIn encRSAHashKey (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
noncomputable def Cslib.Crypto.rsaHashSetup (gen : RSAGen) (n : ℕ) :

The key law of the RSA hash ([BS23], §10.6.2, p. 415): draw desc ← gen n and a uniform unit y modulo N, and return the public key with base y.

The RSA hash H_rsa(a, b) = a ^ e * y ^ b ([BS23], §10.6.2, p. 415), on the pair (a, b) that the word m decodes to, as a natural number below N (for 0 < N).

The domain ℤₙ* × I_e of the RSA hash ([BS23], §10.6.2, p. 415) on words: m is the encoding of the pair (a, b) it decodes to, a < N is coprime to N, and b < e.

def Cslib.Crypto.rsaHashRoot (N e y a b a' b' : ℕ) :

The e-th root of y modulo N from a collision (a, b), (a', b') of the RSA hash, as in the proof of [BS23], Theorem 10.7 (p. 417): Shamir's trick (commonRoot) with f = b' - b and w = a * a'⁻¹ mod N when b < b', and with f = b - b' and w = a' * a⁻¹ mod N otherwise.

theorem Cslib.Crypto.rsaHashRoot_lt {N : ℕ} (hN : 0 < N) (e y a b a' b' : ℕ) :
rsaHashRoot N e y a b a' b' < N

The output of rsaHashRoot is below a positive modulus.

theorem Cslib.Crypto.rsaEval_rsaHashRoot {N e y a b a' b' : ℕ} (hy : y < N) (hyN : y.Coprime N) (ha : a.Coprime N) (ha' : a'.Coprime N) (hef : e.Coprime (b.dist b')) (h : a ^ e * y ^ b ≡ a' ^ e * y ^ b' [MOD N]) :
rsaEval N e (rsaHashRoot N e y a b a' b') = y

The root from a collision ([BS23], proof of Theorem 10.7, p. 417). For e coprime to b.dist b' (b' - b if b ≤ b', else b - b'), units y, a and a' modulo N with y < N and a ^ e * y ^ b ≡ a' ^ e * y ^ b' [MOD N], rsaHashRoot returns an e-th root of y. As in the book, a prime e greater than both b and b', with b ≠ b', is coprime to b.dist b'; b = b' is allowed and forces e = 1.

The adversary B' of the proof of [BS23], Theorem 10.7 (p. 417): on a public key (N, e) and a challenge y, run the collision finder on the key (N, e, y), decode its two words to pairs and return rsaHashRoot of them. It does not check that the pair is a collision.

The reduction of Theorem 10.7 ([BS23], p. 417): at every security parameter n where e is prime for every key in the support of gen n, the success probability of a collision finder A against the RSA hash is at most that of rsaHashToRSA A in the RSA game with a uniform unit preimage. The book proves equality, CRadv[A, H_rsa] = uRSAadv[B', ℓ, e]; rsaHashToRSA does not test its pair, so it can also win when the pair is not a collision.

The bound (10.3) ([BS23], Theorem 10.7, p. 417): at every security parameter n where e is prime for every key in the support of gen n, the success probability of a collision finder A against the RSA hash is at most that of the elementary wrapper unitRSAToRSA (rsaHashToRSA A) in rsaInversionGame.

Theorem 10.7 from the unit-preimage RSA assumption ([BS23], §10.6.2, pp. 416–417): if RSAUnitOneWay gen holds and, for all sufficiently large n, e is prime for every key in the support of gen n, then the RSA hash is collision resistant on validRSAHashInput under rsaHashSetup gen.

Theorem 10.7 ([BS23], §10.6.2, pp. 416–417): if RSAOneWay gen holds and, for all sufficiently large n, e is prime for every key in the support of gen n, then the RSA hash is collision resistant on validRSAHashInput under rsaHashSetup gen.