Documentation

CslibFrontier.Crypto.Protocols.MPC.OTMultiplication

Two-Party Multiplication over ZMod q and Beaver Triple Generation from Batched 1-out-of-2 OT #

This module formalizes Gilboa-style two-party multiplication over ZMod q from batched 1-out-of-2 oblivious transfer (batchOTSpec / batchOTWorld) together with symmetric additive-share multiplication and preprocessing of additive Beaver multiplication triples (Beaver.TripleShare):

  1. Binary Bit-Decomposition & Gilboa's Algebraic Identity (otBitWidth, zmodToBits, val_equivFin_zmodToBits, otMul2SenderPairs, otMul2_correct, otMul2ZMod_correct): using Cslib.BitString.equivFin and Cslib.BitString.indexBits, a k-bit vector bits : BitString k evaluates to (BitString.equivFin k bits : ℕ) = ∑ i, (bits i).toNat * 2^i. The sender (holding a : R and random masks r : Fin k → R) prepares the 1-out-of-2 OT pairs m_{i, 0} = -r i and m_{i, 1} = a * 2^i - r i while the receiver selects bits i and receives t i = m_{i, bits i}. For every mask vector r, the local additive shares ∑ i, r i and ∑ i, t i satisfy (∑ i, r i) + (∑ i, t i) = a * (BitString.equivFin k bits : ℕ). Setting otBitWidth q = Nat.clog 2 q decomposes any b : ZMod q into zmodToBits b.
  2. Ideal-OT Protocols & Perfect Semi-Honest Security (otMul2BitsProtocol, otMul2Protocol, perfectSemiHonestPrivate_otMul2Bits, perfectSemiHonestPrivate_otMul2): in batchOTWorld k (ZMod q), otMul2BitsProtocol k q realizes otMul2BitsFunctionality k q with PerfectSemiHonestPrivate against every static coalition I : Finset (Fin 2). Precomposing with zmodToBits via Protocol.mapInput yields otMul2Protocol q, which for 1 < q (0 < otBitWidth q) realizes otMul2Functionality q with PerfectSemiHonestPrivate.
  3. Symmetric Additive-Share Multiplication (shareMulFromOTProtocol, perfectSemiHonestPrivate_shareMulFromOT): given additive shares (a₀, b₀) and (a₁, b₁) over ZMod q, two batched 1-out-of-2 OT invocations (for the cross-terms a₀ * b₁ and a₁ * b₀) produce additive shares c₀, c₁ satisfying c₀ + c₁ = (a₀ + a₁) * (b₀ + b₁) and realize sharedMulFunctionality 2 in batchOTWorld (otBitWidth q) (ZMod q) with PerfectSemiHonestPrivate against every static coalition I : Finset (Fin 2).
  4. Beaver Multiplication Triple Generation (TripleFromOTMulCoins, tripleFromOTMulProtocol, perfectSemiHonestPrivate_tripleFromOTMul): sampling uniform local mask pairs (a₀, b₀) and (a₁, b₁) and running shareMulFromOTProtocol q yields valid Beaver.TripleShare (ZMod q) shares realizing Beaver.beaverTripleFunctionality q 2 in batchOTWorld (otBitWidth q) (ZMod q) with PerfectSemiHonestPrivate against every static coalition I : Finset (Fin 2).

Relation to [BS23], Exercises 23.4–23.5 #

This formalization follows the OT-based multiplication and Beaver triple preprocessing exercises in [BS23], v0.6, Chapter 23, Exercises 23.4–23.5 (printed pp. 1093–1094), with two concrete differences:

Main definitions #

Main results #

References #

1. Little-endian binary decomposition and Gilboa's algebraic identity #

@[reducible]

Canonical bit-width ⌈log₂ q⌉ sufficient to represent every element of ZMod q.

Little-endian binary decomposition of b : ZMod q into otBitWidth q bits via BitString.indexBits (returning Fin.elim0 when q = 0).

@[simp]

Evaluating BitString.equivFin (otBitWidth q) (zmodToBits b) recovers b.val.

def Cslib.Crypto.Protocols.MPC.otMul2SenderPairs {R : Type u_1} [Ring R] {k : ℕ} (a : R) (r : Fin k → R) :
Fin k → Bool → R

Sender's 1-out-of-2 OT message pairs for Gilboa-style multiplication of a : R by a k-bit vector using random masks r : Fin k → R: for bit position i, m_{i, 0} = -r i and m_{i, 1} = a * 2^i - r i.

theorem Cslib.Crypto.Protocols.MPC.otMul2_correct {R : Type u_1} [Ring R] {k : ℕ} (a : R) (bits : BitString k) (r : Fin k → R) :
∑ i : Fin k, r i + ∑ i : Fin k, otMul2SenderPairs a r i (bits i) = a * ↑↑((BitString.equivFin k) bits)

Gilboa (1999) algebraic correctness: for every a : R, bits : BitString k, and mask vector r : Fin k → R, the local additive shares ∑ i, r i and ∑ i, otMul2SenderPairs a r i (bits i) sum identically to a * (BitString.equivFin k bits : ℕ).

theorem Cslib.Crypto.Protocols.MPC.otMul2ZMod_correct {q : ℕ} [NeZero q] (a b : ZMod q) (r : Fin (otBitWidth q) → ZMod q) :
∑ i : Fin (otBitWidth q), r i + ∑ i : Fin (otBitWidth q), otMul2SenderPairs a r i (zmodToBits b i) = a * b

Corollary for b : ZMod q: decomposing b into otBitWidth q bits yields additive shares summing identically to a * b for every mask vector r.

Simulation helper lemmas for shifted additive share sums #

2. otMul2BitsProtocol and otMul2Protocol in batchOTWorld #

@[reducible]

Schedule for otMul2BitsProtocol and otMul2Protocol: a single joint 2-party invocation of batchOTSpec k (ZMod q) with Party 0 as sender and Party 1 as receiver.

@[reducible]

Local coins for otMul2BitsProtocol and otMul2Protocol: Party 0 holds a mask vector Fin k → ZMod q; Party 1 uses ().

@[reducible]

Input tuple type for otMul2BitsProtocol: Party 0 inputs a : ZMod q and Party 1 inputs bits : BitString k.

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2BitsFunctionality (k q : ℕ) [NeZero q] :
Functionality 2 (OTMultBitsIn k q) fun (x : Fin 2) => ZMod q

Ideal 2-party functionality for bit-vector multiplication over ZMod q: samples uniform additive shares of a * (BitString.equivFin k bits : ℕ).

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2BitsProtocol (k q : ℕ) [NeZero q] :
Protocol 2 (batchOTSpec k (ZMod q)) (otMul2Schedule k q) (OTMultBitsIn k q) (OTMultCoins k q) fun (x : Fin 2) => ZMod q

Gilboa-style 2-party bit-vector multiplication protocol in the batchOTSpec k (ZMod q)-hybrid model.

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2BitsSim (k q : ℕ) [NeZero q] (I : Finset (Fin 2)) :
CoalitionSimulator (otMul2Schedule k q) (OTMultBitsIn k q) (OTMultCoins k q) (fun (x : Fin 2) => ZMod q) I

Coalition simulator for otMul2BitsProtocol against every static coalition I : Finset (Fin 2).

Perfect semi-honest security of otMul2BitsProtocol: for every [NeZero q], every [NeZero k], and every static coalition I : Finset (Fin 2), otMul2BitsProtocol k q realizes otMul2BitsFunctionality k q in batchOTWorld k (ZMod q).

Specialization to ZMod q × ZMod q via Protocol.mapInput #

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2Functionality (q : ℕ) [NeZero q] :
Functionality 2 (fun (x : Fin 2) => ZMod q) fun (x : Fin 2) => ZMod q

Ideal 2-party multiplication functionality over ZMod q: given (a, b) : ZMod q × ZMod q, samples uniform additive shares of a * b.

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2Protocol (q : ℕ) [NeZero q] :
Protocol 2 (batchOTSpec (otBitWidth q) (ZMod q)) (otMul2Schedule (otBitWidth q) q) (fun (x : Fin 2) => ZMod q) (OTMultCoins (otBitWidth q) q) fun (x : Fin 2) => ZMod q

Gilboa-style 2-party multiplication protocol over ZMod q in batchOTWorld (otBitWidth q) (ZMod q): Party 1 decomposes its input b : ZMod q via zmodToBits b and executes otMul2BitsProtocol.

noncomputable def Cslib.Crypto.Protocols.MPC.otMul2Sim (q : ℕ) [NeZero q] (I : Finset (Fin 2)) :
CoalitionSimulator (otMul2Schedule (otBitWidth q) q) (fun (x : Fin 2) => ZMod q) (OTMultCoins (otBitWidth q) q) (fun (x : Fin 2) => ZMod q) I

Coalition simulator for otMul2Protocol.

Perfect semi-honest security of otMul2Protocol: for every q > 1 (0 < otBitWidth q) and every static coalition I : Finset (Fin 2), otMul2Protocol q realizes otMul2Functionality q in batchOTWorld (otBitWidth q) (ZMod q).

3. Symmetric additive-share multiplication (shareMulFromOT) #

Local output share in symmetric 2-party additive-share multiplication from two instances of otMul2: a_i * b_i + ∑ j, r_i j + ∑ j, t_i j.

theorem Cslib.Crypto.Protocols.MPC.shareMulFromOT_correct {q : ℕ} [NeZero q] (xy₀ xy₁ : ZMod q × ZMod q) (r₀ r₁ : Fin (otBitWidth q) → ZMod q) :
have t₁ := fun (i : Fin (otBitWidth q)) => otMul2SenderPairs xy₀.1 r₀ i (zmodToBits xy₁.2 i); have t₀ := fun (i : Fin (otBitWidth q)) => otMul2SenderPairs xy₁.1 r₁ i (zmodToBits xy₀.2 i); shareMulFromOTOut xy₀ r₀ t₀ + shareMulFromOTOut xy₁ r₁ t₁ = (xy₀.1 + xy₁.1) * (xy₀.2 + xy₁.2)

Algebraic correctness of shareMulFromOT: for all input shares (a₀, b₀), (a₁, b₁) and all mask vectors r₀, r₁ : Fin (otBitWidth q) → ZMod q, the output shares c₀, c₁ sum identically to (a₀ + a₁) * (b₀ + b₁).

@[reducible]

Schedule for shareMulFromOTProtocol: two sequential invocations of batchOTSpec with roles (0, 1) and (1, 0).

noncomputable def Cslib.Crypto.Protocols.MPC.shareMulFromOTProtocol (q : ℕ) [NeZero q] :
Protocol 2 (batchOTSpec (otBitWidth q) (ZMod q)) (shareMulFromOTSchedule q) (fun (x : Fin 2) => ZMod q × ZMod q) (fun (x : Fin 2) => Fin (otBitWidth q) → ZMod q) fun (x : Fin 2) => ZMod q

Symmetric 2-party shared multiplication protocol over ZMod q in batchOTWorld (otBitWidth q) (ZMod q), realizing sharedMulFunctionality 2.

noncomputable def Cslib.Crypto.Protocols.MPC.shareMulFromOTSim (q : ℕ) [NeZero q] (I : Finset (Fin 2)) :
CoalitionSimulator (shareMulFromOTSchedule q) (fun (x : Fin 2) => ZMod q × ZMod q) (fun (x : Fin 2) => Fin (otBitWidth q) → ZMod q) (fun (x : Fin 2) => ZMod q) I

Coalition simulator for shareMulFromOTProtocol against every static coalition I : Finset (Fin 2).

Perfect semi-honest security of shareMulFromOTProtocol: for every q > 1 (0 < otBitWidth q) and every static coalition I : Finset (Fin 2), shareMulFromOTProtocol q realizes sharedMulFunctionality 2 in batchOTWorld (otBitWidth q) (ZMod q).

4. Beaver multiplication triple generation (tripleFromOTMul) #

Local private coins for a party in tripleFromOTMulProtocol q: its additive triple mask shares a, b : ZMod q and its batched-OT mask vector otMask : Fin (otBitWidth q) → ZMod q.

Instances For
    theorem Cslib.Crypto.Protocols.MPC.TripleFromOTMulCoins.ext {q : ℕ} {x y : TripleFromOTMulCoins q} (a : x.a = y.a) (b : x.b = y.b) (otMask : x.otMask = y.otMask) :
    x = y
    noncomputable def Cslib.Crypto.Protocols.MPC.tripleFromOTMulProtocol (q : ℕ) [NeZero q] :
    Protocol 2 (batchOTSpec (otBitWidth q) (ZMod q)) (shareMulFromOTSchedule q) (fun (x : Fin 2) => Unit) (fun (x : Fin 2) => TripleFromOTMulCoins q) fun (x : Fin 2) => Beaver.TripleShare (ZMod q)

    2-party Beaver multiplication triple generation protocol over ZMod q in batchOTWorld (otBitWidth q) (ZMod q): each party samples uniform TripleFromOTMulCoins q (a, b, otMask), runs shareMulFromOTProtocol q to obtain c, and outputs ⟨a, b, c⟩.

    noncomputable def Cslib.Crypto.Protocols.MPC.tripleFromOTMulSim (q : ℕ) [NeZero q] (I : Finset (Fin 2)) :
    CoalitionSimulator (shareMulFromOTSchedule q) (fun (x : Fin 2) => Unit) (fun (x : Fin 2) => TripleFromOTMulCoins q) (fun (x : Fin 2) => Beaver.TripleShare (ZMod q)) I

    Coalition simulator for tripleFromOTMulProtocol against every static coalition I : Finset (Fin 2).

    theorem Cslib.Crypto.Protocols.MPC.mem_support_tripleFromOTMulProtocol (q : ℕ) [NeZero q] {res : ((i : Fin 2) → PartyView (fun (x : Fin 2) => Unit) (fun (x : Fin 2) => TripleFromOTMulCoins q) (shareMulFromOTSchedule q) i) × (Fin 2 → Beaver.TripleShare (ZMod q))} (hres : res ∈ ((tripleFromOTMulProtocol q).evalWith (batchOTWorld (otBitWidth q) (ZMod q)) fun (x : Fin 2) => ()).support) :

    Every supported execution of tripleFromOTMulProtocol q outputs valid Beaver.TripleShare (ZMod q) shares in the support of Beaver.beaverTripleFunctionality q 2.

    Perfect semi-honest security of tripleFromOTMulProtocol: for every q > 1 (0 < otBitWidth q) and every static coalition I : Finset (Fin 2), tripleFromOTMulProtocol q realizes Beaver.beaverTripleFunctionality q 2 in batchOTWorld (otBitWidth q) (ZMod q).

    theorem Cslib.Crypto.Protocols.MPC.eval_restrict_output_tripleFromOTMul (q : ℕ) [NeZero q] (hq : 1 < q) (I : Finset (Fin 2)) (hI : I ≠ Finset.univ) :
    PMF.map (fun (res : ((i : Fin 2) → PartyView (fun (x : Fin 2) => Unit) (fun (x : Fin 2) => TripleFromOTMulCoins q) (shareMulFromOTSchedule q) i) × (Fin 2 → Beaver.TripleShare (ZMod q))) => I.restrict res.2) ((tripleFromOTMulProtocol q).evalWith (batchOTWorld (otBitWidth q) (ZMod q)) fun (x : Fin 2) => ()) = Probability.PMF.uniformOfFintype (↥I → Beaver.TripleShare (ZMod q))

    For every proper coalition I ≠ Finset.univ (q > 1), the marginal distribution of I's generated Beaver.TripleShare (ZMod q) shares in tripleFromOTMulProtocol q is uniform on (i : I) → Beaver.TripleShare (ZMod q).