Documentation

CslibFrontier.Crypto.Primitives.Garbling.Arithmetic.CRT

CRT reconstruction inside a prime-power ring #

Li and Liu [LL24] garble arithmetic over ℤ/N for N = ∏ i, m i with pairwise coprime moduli m i (typically prime powers) channel by channel, through the Chinese remainder theorem. Their bit decomposition for ℤ/N merges the channels with CRT constants in a linear bit-composition gate, followed by an exact remainder by N. With the standard CRT coefficients c i = M i * (M i⁻¹ mod m i), M i = N / m i, the residues x % m i determine x mod N as the public linear combination ∑ i, c i * (x % m i) reduced modulo N (crtSum_modEq).

The combination is computed in a larger ring ℤ/p^(2k+1) with N ^ 2 ≤ p ^ k. It does not wrap around there: each coefficient is below N (crtCoeff_lt) and the residues add up to at most N - 1 (Nat.sum_sub_one_le_prod_sub_one), so the combination is at most (N - 1) ^ 2 (crtSum_le_sq). The exact remainder gadget of ConstantDivision then recovers x mod N in the ring (constMod_crtSum).

Source mapping (ePrint 2023/1584 version of [LL24], dated 2023-10-13). Section 5 (pp. 23–24) takes N = ∏ i, p_i ^ k_i and constants c_i with x = ∑ i, c_i * x^(i) mod N for the residues x^(i) = x mod p_i ^ k_i (p. 23). Its bit decomposition for ℤ/N feeds the bits of the residues into the linear bit-composition gate over ℤ/p^(2k+1), where p ^ k > N ^ 2 exceeds the combination, and then applies mod*_N (pp. 23–24). Here the moduli m i are any positive pairwise coprime numbers rather than prime powers, the constants are the standard coefficients crtCoeff, crtSum_le_sq proves the bound on the combination that the source asserts, and the hypothesis is N ^ 2 ≤ p ^ k. The combination is computed on natural numbers: the linear bit-composition gadget and the garbled per-channel circuits are not part of this file.

Main definitions #

Main results #

References #

The CRT coefficient of channel i: M * (M⁻¹ mod m i) for M = (∏ j, m j) / m i.

The CRT combination ∑ i, crtCoeff m i * (x % m i) of the channel residues of x.

theorem Cslib.Crypto.Garbling.Arithmetic.crtCoeff_lt {s : ℕ} {m : Fin s → ℕ} (hm : ∀ (i : Fin s), 0 < m i) (i : Fin s) :
crtCoeff m i < ∏ j : Fin s, m j

Each CRT coefficient is below N = ∏ i, m i.

theorem Cslib.Crypto.Garbling.Arithmetic.crtCoeff_cast {s : ℕ} {m : Fin s → ℕ} (hm : ∀ (i : Fin s), 0 < m i) (hco : Pairwise (Function.onFun Nat.Coprime m)) (i j : Fin s) :
↑(crtCoeff m i) = if i = j then 1 else 0

In channel j, the coefficient of channel i is 1 if i = j and 0 otherwise.

theorem Cslib.Crypto.Garbling.Arithmetic.crtSum_modEq {s : ℕ} {m : Fin s → ℕ} (hm : ∀ (i : Fin s), 0 < m i) (hco : Pairwise (Function.onFun Nat.Coprime m)) (x : ℕ) :
crtSum m x ≡ x [MOD ∏ i : Fin s, m i]

CRT reconstruction: the combination of the residues of x is x modulo ∏ i, m i.

theorem Cslib.Crypto.Garbling.Arithmetic.crtSum_le_sq {s : ℕ} {m : Fin s → ℕ} (hm : ∀ (i : Fin s), 0 < m i) (x : ℕ) :
crtSum m x ≤ (∏ i : Fin s, m i - 1) ^ 2

No wrap-around: the CRT combination of the residues of any x is at most (N - 1) ^ 2 for N = ∏ i, m i.

theorem Cslib.Crypto.Garbling.Arithmetic.constMod_crtSum {s : ℕ} {m : Fin s → ℕ} (hm : ∀ (i : Fin s), 0 < m i) (hco : Pairwise (Function.onFun Nat.Coprime m)) {p k : ℕ} (hp : 1 < p) (hN : (∏ i : Fin s, m i) ^ 2 ≤ p ^ k) (x : ℕ) :
constMod p k (∏ i : Fin s, m i) ↑(crtSum m x) = ↑(x % ∏ i : Fin s, m i)

Reconstruction in ℤ/p^(2k+1): if (∏ i, m i) ^ 2 ≤ p ^ k, the remainder gadget constMod applied to the CRT combination of the residues of x returns x mod ∏ i, m i.