Documentation

CslibFrontier.Crypto.Computational.GoldwasserMicali.TextbookKeyGen

Textbook Goldwasser–Micali QNR_N^{+1} key generation and IND-CPA security #

Formalizes the strict-PPT textbook Goldwasser–Micali key generator over general distinct odd primes p ≠ q (ModulusDesc, without restricting to Blum moduli p ≡ q ≡ 3 (mod 4)) and its single-bit and bitwise multi-bit chosen-plaintext security steps toward #5293 from QuadraticResiduosityHard alone, parameterized by a modulus generator gen : ℕ → ProbComp ModulusDesc (native prime-pair modulus generation remains tracked in #5293 §3; after [KL20], Section 15.4.4, Construction 15.28 and Theorem 15.29, locator not verified, #5578):

Main definitions #

Main results #

References #

Euler-criterion nonresidue test and capped fair-bit rejection sampler #

Euler-criterion test for quadratic nonresidues modulo an odd prime p: returns true when 0 < a < p and a ^ ((p - 1) / 2) mod p = p - 1.

Capped strict-PPT sampler for a quadratic nonresidue modulo p at security parameter n: run 3 * (n + 1) independent (encNat p).length-bit fair-coin rejection blocks testing isNonresidueModPrime p ∘ BitString.binaryValue, returning 1 if all blocks reject.

For an odd prime p, isNonresidueModPrime p a holds iff a is the canonical natural representative of a non-square unit in (ZMod p)ˣ.

Polynomial-time Chinese remainder recombination (Cslib.crtCombine + BinaryGcd.modInv) #

Encoded Goldwasser–Micali public key ⟨p * q, crtCombine p q (z_p % p) z_q (modInv p q)⟩ built from prime factors (p, q) and per-prime residues (z_p, z_q).

Textbook Goldwasser–Micali key generation (after [KL20], Section 15.4.4, Construction 15.28, locator not verified, #5578): draw d ← gen n, independently sample z_p and z_q via capped fair-bit rejection sampling (sampleNonresidueModPrime), and output pk = textbookPublicKey d.p d.q z_p z_q and sk = ⟨d.p, d.q⟩.

Key pairs in the support of textbookKeyGen gen n arise from a supported ModulusDesc and per-prime residues (z_p, z_q).

On canonical natural representatives of (u_p, u_q) : (ZMod d.p)ˣ × (ZMod d.q)ˣ, crtCombine d.p d.q (u_p.val.val % d.p) u_q.val.val (BinaryGcd.modInv d.p d.q) computes the canonical natural representative of (ZMod.unitsChineseRemainder hcop).symm (u_p, u_q).

Combining accepted per-prime nonresidues (z_p, z_q) via Cslib.crtCombine and BinaryGcd.modInv yields the canonical natural representative of an element of positiveNonresidues d.p d.q (QNR_N^{+1}).

Construct a valid KeyDesc (z ∈ QNR_N^{+1}) from d : ModulusDesc and any pair (z_p, z_q) passing isNonresidueModPrime.

@[simp]

Underlying modulus descriptor of KeyDesc.ofNonresidues d hp hq.

@[simp]

Public nonresidue z of KeyDesc.ofNonresidues d hp hq.

Polynomial-time and uniform strict-PPT certificates #

Rejection-sampling law, 1 / 2 ^ n closeness to publicKeyLaw, and correctness #

At security parameter n, sampleNonresidueModPrime n p fails to output a quadratic nonresidue modulo p (isNonresidueModPrime p a = false) with probability at most 1 / 2 ^ (n + 1).

Statistical closeness of textbookKeyGen gen to publicKeyLaw (after [KL20], Section 15.4.4, Construction 15.28, locator not verified): for any modulus sampler gen : ℕ → ProbComp ModulusDesc (without any Blum or bit-length hypothesis), the public-key marginal of textbookKeyGen gen n is within 1 / 2 ^ n statistical distance (CloseTo) of the exact uniform QNR_N^{+1} law publicKeyLaw (fun k => ProbComp.eval (gen k)) n.

Conditional deterministic and statistical decryption correctness #

Deterministic conditional correctness for 1-bit encryption: whenever z_p and z_q satisfy isNonresidueModPrime for d : ModulusDesc, every supported ciphertext of encrypt under textbookPublicKey d.p d.q z_p z_q decrypts to m.

Deterministic conditional correctness for bitwise multi-bit encryption: whenever z_p and z_q satisfy isNonresidueModPrime for d : ModulusDesc, every supported ciphertext of encryptWord under textbookPublicKey d.p d.q z_p z_q decrypts to bits.

Over keys ← textbookKeyGen gen n, the probability that keys fails to arise from a valid KeyDesc (z ∈ QNR_N^{+1}) is at most 1 / 2 ^ n. Outside that 1 / 2 ^ n rejection tail, every 1-bit and multi-bit encryption under keys.1 decrypts deterministically with zero error under keys.2.

theorem Cslib.Crypto.GoldwasserMicali.closeTo_decrypt_encrypt_textbookKeyGen (gen : ℕ → ProbComp ModulusDesc) (n : ℕ) (m : Bool) :
Probability.CloseTo (do let keys ← textbookKeyGen gen n let ct ← encrypt n keys.1 m pure (decrypt keys.2 ct)).eval (PMF.pure m) ↑(1 / 2 ^ n)

Statistical round-trip decryption correctness for 1-bit Goldwasser–Micali under textbookKeyGen gen: for every message bit m, generating keys and encrypting m decrypts to m up to at most 1 / 2 ^ n statistical distance (CloseTo).

theorem Cslib.Crypto.GoldwasserMicali.closeTo_decryptWord_encryptWord_textbookKeyGen (gen : ℕ → ProbComp ModulusDesc) (n : ℕ) (bits : List Bool) :
Probability.CloseTo (do let keys ← textbookKeyGen gen n let ct ← encryptWord n keys.1 bits pure (decryptWord keys.2 ct)).eval (PMF.pure bits) ↑(1 / 2 ^ n)

Statistical round-trip decryption correctness for bitwise multi-bit Goldwasser–Micali under textbookKeyGen gen: for every bit word bits, generating keys and encrypting bits with encryptWord decrypts via decryptWord to bits up to at most 1 / 2 ^ n statistical distance (CloseTo).

Single-bit and multi-bit IND-CPA security from QuadraticResiduosityHard alone #

theorem Cslib.Crypto.GoldwasserMicali.advantage_textbookGame_le_qr {gen : ℕ → ProbComp ModulusDesc} {n : ℕ} (hsize : ∀ d ∈ (gen n).eval.support, n ≤ d.p.size ∧ n ≤ d.q.size) (adversary : Encryption.Adversary) :
Encryption.advantage (Encryption.game (textbookKeyGen gen) encrypt adversary) n ≤ 2 * (qrRealGame (fun (k : ℕ) => (gen k).eval) (qrDistinguisher adversary) n).advantage (qrIdealGame (fun (k : ℕ) => (gen k).eval) (qrDistinguisher adversary) n) + 12 / 2 ^ n

Quantitative single-bit IND-CPA step for (textbookKeyGen gen, encrypt) (after [KL20], Section 15.4.4, Theorem 15.29, locator not verified): when gen n draws distinct odd primes of at least n bits, every adversary's IND-CPA advantage is at most twice qrDistinguisher adversary's QR advantage plus 12 / 2 ^ n (10 / 2 ^ n from unit sampling and 2 / 2 ^ n from capped QNR_N^{+1} key generation).

Single-bit IND-CPA step toward #5293 for textbook Goldwasser–Micali encryption (textbookKeyGen gen, encrypt) from QuadraticResiduosityHard alone, parameterized by a modulus generator gen : ℕ → ProbComp ModulusDesc (native modulus generation tracked in #5293 §3; after [KL20], Section 15.4.4, Construction 15.28 and Theorem 15.29, locator not verified, #5578). Let gen draw distinct odd n-bit primes (ModulusDesc, with no Blum restriction). If quadratic residuosity is hard relative to gen, then (textbookKeyGen gen, encrypt) satisfies Encryption.INDCPA against all uniform strict-PPT adversaries. Neither indistinguishability of keys from an ideal law nor computability of gen is assumed.

theorem Cslib.Crypto.GoldwasserMicali.length_textbookPublicKey_le {p q B : ℕ} (hp_pos : 0 < p) (hq_pos : 0 < q) (hp : p.size ≤ B) (hq : q.size ≤ B) (z_p z_q : ℕ) :
(textbookPublicKey p q z_p z_q).length ≤ 6 * B + 1

Encoded bit length of textbookPublicKey p q z_p z_q in terms of an upper bound B on p.size and q.size, valid for all z_p, z_q : ℕ whenever 0 < p and 0 < q.

theorem Cslib.Crypto.GoldwasserMicali.advantage_textbookWordGame_le_qr (maxLen : ℕ → ℕ) {gen : ℕ → ProbComp ModulusDesc} {n : ℕ} (hsize : ∀ d ∈ (gen n).eval.support, n ≤ d.p.size ∧ n ≤ d.q.size) (adversary : Encryption.WordAdversary) :
Encryption.advantage (Encryption.gameOn (Encryption.validBoundedWords maxLen) (textbookKeyGen gen) encryptWord adversary) n ≤ 2 * (qrRealGame (fun (k : ℕ) => (gen k).eval) (qrWordDistinguisher maxLen adversary) n).advantage (qrIdealGame (fun (k : ℕ) => (gen k).eval) (qrWordDistinguisher maxLen adversary) n) + (10 * ↑(maxLen n) + 2) / 2 ^ n

Quantitative multi-bit IND-CPA step for (textbookKeyGen gen, encryptWord) on bounded-length words (after [KL20], Section 15.4.4, locator not verified, #5578): via lossy quadratic-residue public keys, bitwise encryption of equal-length words of length at most maxLen n reduces to QuadraticResiduosityHard with factor-2 loss (independent of maxLen n) plus (10 * maxLen n + 2) / 2 ^ n.

theorem Cslib.Crypto.GoldwasserMicali.wordINDCPA_textbookGoldwasserMicali {gen : ℕ → ProbComp ModulusDesc} {sizeBound : ℕ → ℕ} (hbound : PolynomiallyBounded sizeBound) (hsize : ∀ (n : ℕ), ∀ d ∈ (gen n).eval.support, n ≤ d.p.size ∧ n ≤ d.q.size) (hupper : ∀ (n : ℕ), ∀ d ∈ (gen n).eval.support, d.p.size ≤ sizeBound n ∧ d.q.size ≤ sizeBound n) (hQR : QuadraticResiduosityHard fun (n : ℕ) => (gen n).eval) :

Multi-bit IND-CPA step toward #5293 for textbook bitwise Goldwasser–Micali encryption (textbookKeyGen gen, encryptWord) from QuadraticResiduosityHard alone, parameterized by a modulus generator gen : ℕ → ProbComp ModulusDesc (native modulus generation tracked in #5293 §3; after [KL20], Section 15.4.4, Construction 15.28 and Theorem 15.29, locator not verified, #5578). Let gen draw distinct odd primes (ModulusDesc, with no Blum restriction) whose bit-lengths are at least n and at most sizeBound n for a polynomially bounded function sizeBound (for example fun n => n + c, or the output cap of any uniform strict-PPT gen). If quadratic residuosity is hard relative to gen, then (textbookKeyGen gen, encryptWord) satisfies Encryption.WordINDCPA against all uniform strict-PPT word adversaries, with factor-2 QR reduction loss independent of message length (advantage_textbookWordGame_le_qr).