Cryptology City: BGW (GRR) and Beaver multiplication on Shamir shares
DefinitionCityBGWcryptographysecret-sharing
Multiplication protocols on degree- Shamir sharings over a finite field , with parties at points .
- and .
- and .
- on a finite sample space.
- GRR multiplication. Coins ; party sends party the subshare ; party outputs . The view of is ('s input pairs , 's coins, every subshare sent to a member of ).
- Beaver multiplication. A triple is , dealing , , . The opened vectors are and ; with , , party outputs . The view of is ('s triple shares, both opened vectors).
Definition code
import Mathlib
/-!
# Cryptology City: BGW multiplication on Shamir shares
Parties `0, …, n-1` hold Shamir shares of degree `≤ t` over a finite field `F`,
at distinct nonzero evaluation points `α : Fin n → F`.
-/
namespace CityBGW
open Finset
variable {F : Type*} [Field F] [Fintype F] [DecidableEq F]
/-- The polynomial `s + c₀ x + c₁ x² + ⋯ + c_{m-1} xᵐ` evaluated at `x`. -/
def poly {m : ℕ} (s : F) (c : Fin m → F) (x : F) : F :=
s + ∑ j : Fin m, c j * x ^ (j.val + 1)
/-- Shamir sharing of the secret `s` with coefficients `c`: party `i` gets `poly s c (α i)`. -/
def share {n m : ℕ} (α : Fin n → F) (s : F) (c : Fin m → F) : Fin n → F :=
fun i => poly s c (α i)
/-- The Lagrange recombination vector at `0` for the points `α`:
`λᵢ = ∏_{k ≠ i} α k / (α k - α i)`. -/
def lam {n : ℕ} (α : Fin n → F) (i : Fin n) : F :=
∏ k ∈ univ.erase i, α k / (α k - α i)
/-- Reconstruction of a share vector: `∑ᵢ λᵢ · vᵢ`. -/
def recon {n : ℕ} (α : Fin n → F) (v : Fin n → F) : F :=
∑ i, lam α i * v i
open Classical in
/-- Uniform probability of an event on a finite sample space, as a counting ratio. -/
noncomputable def prob {Ω : Type*} [Fintype Ω] (E : Ω → Prop) : ℚ :=
((univ.filter E).card : ℚ) / (Fintype.card Ω : ℚ)
/-! ## The Gennaro–Rabin–Rabin multiplication protocol (BGW degree reduction) -/
/-- Coins of the multiplication protocol: party `i` reshares with coefficients `r i`. -/
abbrev Coins (n t : ℕ) (F : Type*) := Fin n → Fin t → F
/-- The subshare that party `i` sends to party `k`: party `i` reshares its local
product `aᵢ bᵢ` with a fresh degree-`t` polynomial with coefficients `r i`. -/
def subshare {n t : ℕ} (α : Fin n → F) (a b : Fin n → F) (r : Coins n t F)
(i k : Fin n) : F :=
poly (a i * b i) (r i) (α k)
/-- Party `k`'s output share: `cₖ = ∑ᵢ λᵢ · (subshare from i to k)`. -/
def mulOut {n t : ℕ} (α : Fin n → F) (a b : Fin n → F) (r : Coins n t F) : Fin n → F :=
fun k => ∑ i, lam α i * subshare α a b r i k
/-- The view of a coalition `T`: its input shares, its own coins, and every
subshare it receives. -/
abbrev View (n t : ℕ) (F : Type*) (T : Finset (Fin n)) :=
(T → F × F) × (T → Fin t → F) × (Fin n → T → F)
/-- The view of `T` in an execution with input shares `a`, `b` and coins `r`. -/
def view {n t : ℕ} (α : Fin n → F) (T : Finset (Fin n)) (a b : Fin n → F)
(r : Coins n t F) : View n t F T :=
(fun k => (a k, b k), fun k => r k, fun i k => subshare α a b r i k)
/-! ## Multiplication with a Beaver triple -/
/-- A Beaver triple sharing: secrets `x`, `y` and degree-`t` coefficient vectors
for `x`, `y` and `x * y`. -/
abbrev Triple (t : ℕ) (F : Type*) := F × F × (Fin t → F) × (Fin t → F) × (Fin t → F)
/-- The shares of `x`, `y` and `z = x y` dealt from a triple. -/
def tripleShares {n t : ℕ} (α : Fin n → F) (τ : Triple t F) : Fin n → F × F × F :=
fun i => (share α τ.1 τ.2.2.1 i, share α τ.2.1 τ.2.2.2.1 i,
share α (τ.1 * τ.2.1) τ.2.2.2.2 i)
/-- The two share vectors opened in Beaver multiplication: `a - x` and `b - y`. -/
def opened {n t : ℕ} (α : Fin n → F) (a b : Fin n → F) (τ : Triple t F) :
(Fin n → F) × (Fin n → F) :=
(fun i => a i - (tripleShares α τ i).1, fun i => b i - (tripleShares α τ i).2.1)
/-- Output shares of Beaver multiplication, with `δ = recon (a - x)`, `ε = recon (b - y)`:
`zᵢ + ε xᵢ + δ yᵢ + δ ε`. -/
def beaverOut {n t : ℕ} (α : Fin n → F) (a b : Fin n → F) (τ : Triple t F) : Fin n → F :=
fun i =>
let δ := recon α (opened α a b τ).1
let ε := recon α (opened α a b τ).2
(tripleShares α τ i).2.2 + ε * (tripleShares α τ i).1 + δ * (tripleShares α τ i).2.1 + δ * ε
/-- The view of a coalition `T` in Beaver multiplication: its triple shares and
both opened vectors. -/
def beaverView {n t : ℕ} (α : Fin n → F) (T : Finset (Fin n)) (a b : Fin n → F)
(τ : Triple t F) : (T → F × F × F) × (Fin n → F) × (Fin n → F) :=
(fun k => tripleShares α τ k, opened α a b τ)
end CityBGW