Sampling units modulo a product of two primes #
Paillier and Goldwasser–Micali encryption over a modulus N = p * q draw their randomness with
ProbComp.sampleModNat (n + |N|) N and use it as a unit modulo N, while the security proofs
reason about a uniform unit. The draw is within N / 2 ^ (n + |N|) ≤ 1 / 2 ^ n of a uniform
residue modulo N, and a uniform residue has statistical distance (N - φ(N)) / N from a
uniform unit. When p and q have at least n bits, this fraction is strictly less than
4 / 2 ^ n.
A draw r that is not a unit is replaced by 1 (unitOrOne N r), so the randomness that is used
is always a unit, and the replacement is computable in polynomial time.
Main definitions #
Cslib.Crypto.unitOrOne: keeprwhen it is a unit moduloN, and use1otherwise.
Main results #
Cslib.Crypto.coprime_unitOrOne,Cslib.Crypto.computableInPolyTime_unitOrOne: the result is a unit moduloN, computed in polynomial time.Cslib.Crypto.dist_uniformOfFintype_zmod_units: the statistical distance between a uniform residue moduloNand the image of a uniform unit is the fraction(N - φ(N)) / Nof non-units.Cslib.Crypto.Game.advantage_bind_units_le: restricting a uniform residue moduloNto the units changes the advantage of any continuation by at most(N - φ(N)) / N.Cslib.Crypto.sub_totient_div_lt: for distinctn-bit primespandq, the non-units modulop * qare strictly less than a4 / 2 ^ nfraction of the residues.Cslib.Crypto.Game.advantage_sampleModNat_units_le: forN = p * qwithn-bit primes, replacingProbComp.sampleModNat (n + |N|) Nby a uniform unit changes the advantage of any continuation by at most5 / 2 ^ n.
For any positive modulus N, the statistical distance between a uniform residue in ZMod N
and the image of a uniform unit in (ZMod N)ˣ is the fraction (N - φ(N)) / N of non-units.
Restricting a uniform residue modulo N to the units changes the advantage of any
continuation by at most the fraction (N - φ(N)) / N of non-units.
For N = p * q with distinct primes p and q of at least n bits, drawing
r ← ProbComp.sampleModNat (n + |N|) N instead of a uniform unit u modulo N changes the
advantage of any continuation k by at most 5 / 2 ^ n: at most 1 / 2 ^ n from the residue
sampler and at most 4 / 2 ^ n from the non-units.
Replacing a non-unit draw #
The randomness that is used: r itself when it is a unit modulo N, and 1 otherwise.
unitOrOne is computable in polynomial time.