Documentation

CslibFrontier.Crypto.Computational.RSALeastSignificantBit

The least significant bit of RSA #

The RSA least-significant-bit experiment, together with the exact inversion of RSA from a perfect least-significant-bit predictor.

For odd N and k ≥ 1, the parity of 2 ^ k * x % N is the parity of ⌊2 ^ k * x / N⌋ (two_pow_mul_mod_mod_two), and 2 ^ k * x % N is the RSA preimage of 2 ^ (k * e) * y % N when y = x ^ e % N. So the parities answered on the m public queries 2 ^ (k * e) * y % N, k = 1, …, m, are the most-significant-first binary digits (BitString.binaryValue) of ⌊2 ^ m * x / N⌋ (binaryValue_testBit_two_pow_mul_mod), which determines x once N ≤ 2 ^ m (lsbRecover). The inverter lsbInverter runs a predictor on these queries and recovers x exactly whenever the predictor is always correct on the modulus (eval_lsbInverter).

Main definitions #

Main results #

Implementation notes #

rsaLSBGame runs Cslib.Crypto.predictionExperiment on x drawn uniformly from Fin N, as rsaInversionGame does, rather than from (ZMod N)ˣ. An RSAPredictor receives the public key and a challenge residue; RSAPredictor.IsPPT reads encRSAInput, like RSAInverter.IsPPT, and writes a bit.

[KL20], Theorem 12.31, states that the least significant bit is hard-core for RSA whenever RSA is hard: under RSAOneWay gen, every PPT predictor has negligible Game.guessingAdvantage in rsaLSBGame gen. Its proof must handle predictors that are only noticeably better than a fair guess; that reconstruction is not formalized here, and the theorem is not stated as an assumption either, since a premise would stand in for its proof (#5578). RSAOneWay.not_frequently_alwaysCorrect_lsbPredictor establishes only the noiseless consequence (isPPT_lsbInverter plus succProbability_rsaInversionGame_lsbInverter) for predictors that are always correct on every residue modulo N. HardCore in CslibFrontier.Crypto.Computational.HardCore covers unkeyed functions on uniform bit strings, so it cannot express a predicate of a uniform residue under generated RSA keys; rsaLSBGame is a separate keyed game that reuses Game.guessingAdvantage.

References #

The prediction experiment #

@[reducible, inline]

A one-bit predictor for RSA: given the security parameter, a public key (N, e) and a residue modulo N, it outputs a bit, whose meaning is fixed by the experiment (the least significant bit of the preimage in rsaLSBGame) or by a correctness hypothesis. RSAPredictor.IsPPT states its efficiency on encodings.

An RSA predictor is PPT when one uniform strict PPT machine reads encRSAInput and writes the predicted bit.

noncomputable def Cslib.Crypto.rsaLSBGame (gen : RSAGen) (predictor : RSAPredictor) (n : ℕ) :

The RSA least-significant-bit experiment: sample desc ← gen n and run Cslib.Crypto.predictionExperiment on a uniform residue x modulo N. The predictor receives (pk, x ^ e % N) and wins when it returns the least significant bit x.testBit 0 of x. That every PPT predictor has negligible Game.guessingAdvantage here under RSAOneWay gen is the hard-core theorem described in the module documentation, which is not formalized.

theorem Cslib.Crypto.rsaLSBGame_eq (gen : RSAGen) (predictor : RSAPredictor) (n : ℕ) :
rsaLSBGame gen predictor n = do let desc ← gen n let x ← Probability.PMF.uniformOfFintype (Fin desc.modulus) let guess ← (predictor n desc.publicKey (desc.publicKey.eval x)).eval pure (guess == (↑x).testBit 0)

rsaLSBGame written out: the predictor sees the RSA image of a uniform residue x.

Doubling and parity #

theorem Cslib.Crypto.two_pow_mul_mod_mod_two {N : ℕ} (hN : Odd N) {k : ℕ} (hk : k ≠ 0) (x : ℕ) :
2 ^ k * x % N % 2 = 2 ^ k * x / N % 2

For odd N and k ≠ 0, the residue 2 ^ k * x % N has the parity of the quotient ⌊2 ^ k * x / N⌋.

theorem Cslib.Crypto.two_pow_mul_rsaEval (N e k x : ℕ) :
2 ^ (k * e) * rsaEval N e x % N = rsaEval N e (2 ^ k * x % N)

The doubling query 2 ^ (k * e) * y % N is the RSA image of 2 ^ k * x % N when y = x ^ e % N.

The public doubling queries 2 ^ (k * e) * y % N for k = 1, …, m.

def Cslib.Crypto.lsbRecover (N m : ℕ) (bits : List Bool) :

Recover x from the most-significant-first digits bits of q = ⌊2 ^ m * x / N⌋ as ⌈q * N / 2 ^ m⌉.

theorem Cslib.Crypto.binaryValue_testBit_two_pow_mul_mod {N x : ℕ} (hN : Odd N) (hx : x < N) (m : ℕ) :
BitString.binaryValue (List.map (fun (k : ℕ) => (2 ^ (k + 1) * x % N).testBit 0) (List.range m)) = 2 ^ m * x / N

The parities of the doubled residues are the binary digits of ⌊2 ^ m * x / N⌋.

theorem Cslib.Crypto.lsbRecover_eq {N x m : ℕ} (hx : x < N) (hm : N ≤ 2 ^ m) (bits : List Bool) (hbits : BitString.binaryValue bits = 2 ^ m * x / N) :
lsbRecover N m bits = x

Rounding ⌊2 ^ m * x / N⌋ * N / 2 ^ m up recovers x once N ≤ 2 ^ m.

theorem Cslib.Crypto.lsbRecover_lsbQueries {N e x m : ℕ} (hN : Odd N) (hx : x < N) (hm : N ≤ 2 ^ m) (oracle : ℕ → Bool) (horacle : ∀ z < N, oracle (rsaEval N e z) = z.testBit 0) :
lsbRecover N m (List.map oracle (lsbQueries N e (rsaEval N e x) m)) = x

A parity oracle that is correct on all RSA images modulo an odd N determines the preimage from the m doubling queries, once N ≤ 2 ^ m.

The inverter #

The inverter built from a least-significant-bit predictor P: on (pk, y) with pk = (N, e), run P on the N.size doubling queries and round the value of the answers.

theorem Cslib.Crypto.eval_lsbInverter {P : RSAPredictor} {n : ℕ} {pk : RSAPublicKey} (hN : Odd pk.N) (hP : ∀ (z : Fin pk.N), (P n pk (pk.eval z)).eval = PMF.pure ((↑z).testBit 0)) (x : Fin pk.N) :
(lsbInverter P n pk (pk.eval x)).eval = PMF.pure x

If P predicts the least significant bit correctly with certainty on every RSA image modulo an odd N, then lsbInverter P returns the preimage of every y = x ^ e % N with certainty.

theorem Cslib.Crypto.succProbability_rsaInversionGame_lsbInverter {gen : RSAGen} {P : RSAPredictor} {n : ℕ} (hodd : ∀ desc ∈ (gen n).support, Odd desc.modulus) (hP : ∀ desc ∈ (gen n).support, ∀ (z : Fin desc.modulus), (P n desc.publicKey (desc.publicKey.eval z)).eval = PMF.pure ((↑z).testBit 0)) :

A predictor that is always correct on the odd moduli produced by gen n yields an inverter that wins the RSA inversion experiment with probability one.

Efficiency certificates and noiseless impossibility #

Generating the m doubling queries 2 ^ ((k + 1) * e) * y % N is computable in polynomial time when N, e, and y are binary, m is unary, and 0 < N.

Computing lsbRecover N m bits = (BitString.binaryValue bits * N + 2 ^ m - 1) / 2 ^ m is computable in polynomial time when N is binary and m is unary.

lsbInverter P runs in uniform strict polynomial time whenever the predictor P is PPT.

theorem Cslib.Crypto.RSAOneWay.not_frequently_alwaysCorrect_lsbPredictor {gen : RSAGen} (hRSA : RSAOneWay gen) (hodd : ∀ᶠ (n : ℕ) in Filter.atTop, ∀ desc ∈ (gen n).support, Odd desc.modulus) {P : RSAPredictor} (hP : P.IsPPT) :
¬∃ᶠ (n : ℕ) in Filter.atTop, ∀ desc ∈ (gen n).support, ∀ (z : Fin desc.modulus), (P n desc.publicKey (desc.publicKey.eval z)).eval = PMF.pure ((↑z).testBit 0)

Under RSAOneWay gen and eventually odd moduli, no uniform strict-PPT predictor can predict x.testBit 0 with certainty on every residue modulo N for infinitely many security parameters (the noiseless corollary of isPPT_lsbInverter and succProbability_rsaInversionGame_lsbInverter).