Documentation

CslibFrontier.Crypto.Computational.RSAHalfPredicate

The half predicate of RSA #

Boneh and Shoup's Exercise 12.21 ("Baby Bleichenbacher attack", [BS23], pp. 519–520) considers, for a residue x modulo n, the predicate P_x(r) that is 1 when x · r mod n, treated as an integer in [0, n), exceeds n / 2. Part (a) asks to learn x from about log₂ n values of P_x; part (b) asks to recover the e-th root of c from an oracle that says whether the e-th root of its input exceeds n / 2.

Here the predicate is written decide (N < 2 * y), which is y > N / 2 over the reals. For odd N and y < N, it equals the parity of 2 * y % N, so P_x(2 ^ k) is the parity of 2 ^ (k + 1) * x % N. These are the bits from which lsbRecover recovers x (lsbRecover_map_decide_lt_two_mul, part (a)). For part (b), halfToLSBPredictor H asks a half oracle H about y * ((N + 1) / 2) ^ e % N, the RSA image of half the preimage of y. For odd N, half of w exceeds N / 2 exactly when w is odd, so halfToLSBPredictor H predicts the least significant bit and lsbInverter inverts RSA with it. By lsbInverter_halfToLSBPredictor, the inverter on y = w ^ e % N calls H at 2 ^ (k * e) * y % N, the RSA images of 2 ^ k * w % N, for k < N.size, and returns lsbRecover of the answers: part (a) at the points r = 2 ^ k.

Part (a) needs an odd modulus: for the modulus 6 = 2 * 3, P_0 and P_3 agree at every point. The inverter of part (b) needs one because halving needs 2 to be invertible modulo N. The efficiency certificate is relative, as for isPPT_lsbInverter: the inverter is PPT whenever H is. Under RSAOneWay and eventually odd moduli no always-correct H is PPT (RSAOneWay.not_frequently_alwaysCorrect_halfPredictor), so the certificate does not count the work of an oracle that holds the secret key. The inverter is not stated as an oracle program with a query bound.

Main definitions #

Main results #

References #

theorem Cslib.Crypto.lsbRecover_map_decide_lt_two_mul {N x m : ℕ} (hN : Odd N) (hx : x < N) (hm : N ≤ 2 ^ m) :
lsbRecover N m (List.map (fun (k : ℕ) => decide (N < 2 * (x * 2 ^ k % N))) (List.range m)) = x

Exercise 12.21(a) ([BS23], p. 519): for odd N with N ≤ 2 ^ m and x < N, the values of the half predicate P_x(r) = [x * r % N > N / 2] at r = 2 ^ 0, …, 2 ^ (m - 1) determine x, which lsbRecover computes from them.

A half predictor as a least-significant-bit predictor: on y, ask the half predictor H about y * ((N + 1) / 2) ^ e % N, which is the RSA image of half the preimage of y modulo odd N.

theorem Cslib.Crypto.lsbInverter_halfToLSBPredictor {H : RSAPredictor} {n : ℕ} {pk : RSAPublicKey} (hN : Odd pk.N) (y : Fin pk.N) :
lsbInverter (halfToLSBPredictor H) n pk y = do let bits ← List.mapM (fun (k : ℕ) => H n pk ⟨2 ^ (k * pk.e) * ↑y % pk.N, ⋯⟩) (List.range pk.N.size) pure ⟨lsbRecover pk.N pk.N.size bits % pk.N, ⋯⟩

Where the inverter asks the half oracle. For odd N, lsbInverter (halfToLSBPredictor H) on y calls H at the residues 2 ^ (k * e) * y % N for k = 0, …, N.size - 1, in this order, and returns lsbRecover N N.size of the answers, reduced modulo N. When y = w ^ e % N, these residues are the RSA images of 2 ^ k * w % N (two_pow_mul_rsaEval).

theorem Cslib.Crypto.eval_halfToLSBPredictor {H : RSAPredictor} {n : ℕ} {pk : RSAPublicKey} (hN : Odd pk.N) (hH : ∀ (w : Fin pk.N), (H n pk (pk.eval w)).eval = PMF.pure (decide (pk.N < 2 * ↑w))) (z : Fin pk.N) :
(halfToLSBPredictor H n pk (pk.eval z)).eval = PMF.pure ((↑z).testBit 0)

If H says correctly, on every RSA image modulo an odd N, whether the preimage exceeds N / 2, then halfToLSBPredictor H predicts the least significant bit of the preimage correctly.

theorem Cslib.Crypto.succProbability_rsaInversionGame_halfToLSBPredictor {gen : RSAGen} {H : RSAPredictor} {n : ℕ} (hodd : ∀ desc ∈ (gen n).support, Odd desc.modulus) (hH : ∀ desc ∈ (gen n).support, ∀ (w : Fin desc.modulus), (H n desc.publicKey (desc.publicKey.eval w)).eval = PMF.pure (decide (desc.modulus < 2 * ↑w))) :

Exercise 12.21(b) ([BS23], pp. 519–520): if the moduli of gen n are odd and H says correctly, on every RSA image, whether the e-th root exceeds N / 2, then the inverter lsbInverter (halfToLSBPredictor H) recovers the e-th root with probability 1. It asks H about the RSA images of 2 ^ k * x % N for k < N.size, part (a)'s points (lsbInverter_halfToLSBPredictor). The pointwise form, every challenge inverted, is eval_lsbInverter applied to eval_halfToLSBPredictor.

halfToLSBPredictor H is PPT whenever H is: the halving step y ↦ y * ((N + 1) / 2) ^ e % N is computable in polynomial time.

theorem Cslib.Crypto.RSAOneWay.not_frequently_alwaysCorrect_halfPredictor {gen : RSAGen} (hRSA : RSAOneWay gen) (hodd : ∀ᶠ (n : ℕ) in Filter.atTop, ∀ desc ∈ (gen n).support, Odd desc.modulus) {H : RSAPredictor} (hH : H.IsPPT) :
¬∃ᶠ (n : ℕ) in Filter.atTop, ∀ desc ∈ (gen n).support, ∀ (w : Fin desc.modulus), (H n desc.publicKey (desc.publicKey.eval w)).eval = PMF.pure (decide (desc.modulus < 2 * ↑w))

Under RSAOneWay gen and eventually odd moduli, no uniform strict-PPT predictor says with certainty, on every RSA image modulo N, whether the preimage exceeds N / 2, for infinitely many security parameters. This is the hardness reading of isPPT_halfToLSBPredictor: no polynomial-time algorithm computes the half predicate of the RSA preimage exactly from the public key. It is not part (b), whose oracle may hold the secret key.