Exact division by a public constant in ℤ/p^(2k+1) #
A garbled arithmetic circuit over ℤ/p^K can multiply by public constants for free and can
truncate low base-p digits with a bit-decomposition gadget, but it has no division. Li and Liu
[LL24] emulate ℤ/N for an arbitrary modulus N inside ℤ/p^(2k+1) by computing
x mod N for inputs x < p ^ k with one constant multiplication and one truncation, following
the multiply-and-shift method of Granlund and Montgomery [GM94].
The natural-number identity and the multiplier are in
CslibFrontier/Foundations/Data/Nat/ConstantDivision.lean: Nat.mul_div_pow_eq_div gives
⌊(m * x) / p ^ (k + e)⌋ = ⌊x / N⌋ when p ^ (k + e) ≤ m * N < p ^ (k + e) + p ^ e and
x < p ^ k, and Nat.constDivMultiplier_bounds shows that m = Nat.constDivMultiplier p k N
satisfies these bounds for e = ⌈log_p N⌉ and is at most p ^ (k + 1). So the product m * x
stays below p ^ (2k+1) and multiplying in ℤ/p^(2k+1) does not wrap around. Hence constDiv,
which multiplies in the ring and keeps the digits above position k + e, is exact
(constDiv_eq_div), and so is constMod x = x - N * constDiv x (constMod_eq_mod).
Source mapping (locators follow the ePrint 2023/1584 version of [LL24] dated 2023-10-13).
Section 4.2 (pp. 21–22) emulates mod-N arithmetic in a ring ℤ/p^K with p ^ K > N ^ 2
through a gate mod_N, and on p. 22 defines div*_N(x) = ⌊(m * x mod p^(2k+1)) / p^(k+kE)⌋ and
mod*_N(x) = x - N * div*_N(x) on ℤ/p^(2k+1), exact for x < p ^ k, with
kE = ⌈log_p N⌉ and m = ⌈p ^ (k + kE) / N⌉. constDiv and constMod are these two maps. In the
source div*_N is a gate ℤ/p^(2k+1) → ℤ/p^(2k+1); here constDiv returns the quotient as a
natural number and constMod casts it back into the ring. Only the values of the gates are
formalized: their garbling (constant multiplication and digit truncation as gadgets), the
circuit-level emulation of ℤ/N, its cost and its privacy are not.
Main definitions #
Cslib.Crypto.Garbling.Arithmetic.constDiv,Cslib.Crypto.Garbling.Arithmetic.constMod: division and remainder byNinℤ/p^(2k+1).
Main results #
Cslib.Crypto.Garbling.Arithmetic.constDiv_eq_div,Cslib.Crypto.Garbling.Arithmetic.constMod_eq_mod: exactness on inputs belowp ^ k.
References #
Division by N from ℤ/p^(2k+1): multiply by Nat.constDivMultiplier p k N in the ring,
then keep the base-p digits above position k + ⌈log_p N⌉, returned as a natural-number
quotient.