Documentation

CslibFrontier.Crypto.Primitives.Garbling.MixedModulus

Mixed-modulus circuits and mixed-modulus circular correlation robustness #

Ball, Malkin and Rosulek [BMR16] garble mixed-modulus arithmetic circuits: every wire carries a residue modulo its own modulus, addition and multiplication by a constant act within one modulus, and a projection gate applies an arbitrary function φ : ℤ_m → ℤ_n between moduli. Wire sorts are drawn from a finite type ι; sort i has modulus μ i and wire labels of sort i are vectors of ℤ_{μ i}^{ℓ i + 1}, split as a key in ℤ_{μ i}^{ℓ i} and a colour, the last coordinate. In [BMR16] the key length is λ_m = ⌈λ / log₂ m⌉ for security parameter λ (§4.1, p. 5). Page numbers here refer to the full version, ePrint 2016/969, dated October 6, 2016.

A circuit is a typed straight-line program: MixedModulusCircuit μ P Γ Θ reads input wires of the sorts listed in Γ, appends one wire per gate, and outputs wires of the sorts listed in Θ. A wire is referred to by a typed de Bruijn reference Ref Γ i, so every gate reads only earlier wires of the right sorts and no well-formedness side condition is needed. The parameter P i j is the payload of a projection gate from sort i to sort j: for an actual circuit it is the function ℤ_{μ i} → ℤ_{μ j} (Projection); a garbling simulator is polymorphic in P, so it cannot read the projection functions, which are exactly what a garbled circuit hides.

The security of the garbling scheme rests on mixed-modulus circular correlation robustness of a tweakable hash H [BallMalkinRosulek2016, Definition 1]. A secret offset Δ_i = (δ_i, 1) is drawn for each sort, with uniform key part and colour 1. The real oracle answers a query (g, i, j, X, a, b) of source sort i and target sort j with H(g, X + a Δ_i) + b Δ_j; the ideal oracle is a uniformly random function. This file defines the two experiments and the advantage ccrAdvantage of one adversary against one hash. It states no assumption: an asymptotic assumption against efficient adversaries, and the privacy theorem of BMR16 that would rest on it, are tracked in #6068.

Definition 1 of [BMR16] (§4.3, p. 7) quantifies over polynomial-time adversaries "that query their oracle on distinct g values and a ≠ 0". In the source's own scheme (Figure 1, p. 7) the m - 1 ciphertexts of a projection gate from modulus m all use that gate's tweak, and the proof sketch of its Theorem 1 (pp. 7–8) replaces them using only the oracle of Definition 1, which takes m - 1 queries under one tweak. So the source's argument needs more than Definition 1 grants. We use a relaxed legality condition, which closes that gap: along every run, no query uses a = 0, and two queries that agree on the tweak, the source sort, X and a are equal (CCRAdversary.IsLegal). Every adversary legal for Definition 1 is legal here, so an assumption stated with this legality is stronger than Definition 1 as literally stated, and would be novel to this library. It is strictly stronger: if H' satisfies Definition 1, so does H g i (k, c) j := H' g i (k, 0) j, yet two queries under one tweak with labels (k, 0) and (k, 1), a = 1 and b = 0 get equal real answers. A run answers every call, private coin or oracle query, independently with an arbitrary reply (IsRun).

Composite moduli. [BMR16] does not restrict moduli to primes, and its gadgets use composite ones: b + 1 for a fan-in-b AND gate (§5, p. 8), the output modulus k + 1 of an equality test (§6.2, p. 11) and p + q - 1 in comparisons (§6.3, pp. 12–13). When μ i is composite with least prime factor p, a nonzero multiplier can be a zero divisor, and (μ i / p) • δ_i = 0 with probability 1 / p ^ ℓ i. Let r = μ i / p, and fix a tweak g, a target sort j, a key k and a colour c. The queries with labels (k, c) and (k, c - r), multipliers a = 1 and a' = 1 + r, and b = 0 have different ccrKeys and nonzero multipliers, and they hash the same input exactly when r • δ_i = 0. The adversary that asks both and compares the answers is legal, never evaluates H, and has ccrAdvantage at least 1 / p ^ ℓ i - 1 / μ j ^ (ℓ j + 1) against every H; for μ i = 2 ^ λ with λ ≥ 2 and ℓ i = 1 that is 1 / 2 - 1 / μ j ^ (ℓ j + 1). The single query (g, i, j, X, r, 0), compared with H g i (X + (0, r)) j, does as well and is legal for Definition 1 too, so the analogue of Definition 1 fails in the same way when the adversary can also evaluate the hash. These are arguments, not theorems stated here. The source does not address this collision: §4.3 has no analysis of zero divisors, and the only bound it states is 1 / 2 ^ λ for authenticity (p. 8). This library documents the gap rather than excluding composite moduli, which would exclude the gadgets above. With the source's key length ⌈λ / log₂ (μ i)⌉ the probability is about 2 ^ (-λ log₂ p / log₂ (μ i)) (2 ^ (-64) for μ i = 4 and λ = 128); bringing it down to 2 ^ (-λ) needs ℓ i ≥ ⌈λ / log₂ (Nat.minFac (μ i))⌉, which is the source's length when μ i is prime. The definitions here and in BMR16 take ℓ as a parameter, so this is a condition on the choice of ℓ, not on the definitions. In an asymptotic assumption (#6068) the collision probability at level κ is p(κ) ^ (-ℓ(κ)), where p(κ) is the least prime factor of the modulus at that level. For fixed moduli, or more generally a bounded least prime factor, it is negligible only if ℓ grows. With moduli that vary it can be negligible for fixed ℓ: for μ κ = p(κ) ^ 2 with a prime p(κ) ≥ 2 ^ κ and ℓ = 1 it is at most 2 ^ (-κ). So the collision argument alone does not force ℓ to grow; this observation does not prove security.

Main definitions #

References #

Typed contexts #

inductive Cslib.Crypto.Garbling.MixedModulus.Ref {ι : Type} :
List ι → ι → Type

A reference to a wire of sort i in a context Γ of wire sorts, newest wire first.

  • here {ι : Type} {Γ : List ι} {i : ι} : Ref (i :: Γ) i

    The newest wire.

  • there {ι : Type} {Γ : List ι} {i j : ι} : Ref Γ i → Ref (j :: Γ) i

    A wire before the newest one.

def Cslib.Crypto.Garbling.MixedModulus.Env {ι : Type} (X : ι → Type) :
List ι → Type

An element of X i for each wire of sort i of a context, newest wire first.

Instances For
    def Cslib.Crypto.Garbling.MixedModulus.Env.cons {ι : Type} {X : ι → Type} {Γ : List ι} {i : ι} (x : X i) (e : Env X Γ) :
    Env X (i :: Γ)

    Extend an assignment by a value for a new wire.

    def Cslib.Crypto.Garbling.MixedModulus.Env.get {ι : Type} {X : ι → Type} {Γ : List ι} {i : ι} :
    Env X Γ → Ref Γ i → X i

    The value of a wire.

    def Cslib.Crypto.Garbling.MixedModulus.Env.gather {ι : Type} {X : ι → Type} {Γ : List ι} (e : Env X Γ) {Θ : List ι} :
    Env (Ref Γ) Θ → Env X Θ

    The values of a list of wires.

    def Cslib.Crypto.Garbling.MixedModulus.Env.map {ι : Type} {X Y : ι → Type} (f : (i : ι) → X i → Y i) {Γ : List ι} :
    Env X Γ → Env Y Γ

    Apply a function to every entry.

    def Cslib.Crypto.Garbling.MixedModulus.Env.map₂ {ι : Type} {X Y Z : ι → Type} (f : (i : ι) → X i → Y i → Z i) {Γ : List ι} :
    Env X Γ → Env Y Γ → Env Z Γ

    Combine two assignments entrywise.

    @[simp]
    theorem Cslib.Crypto.Garbling.MixedModulus.Env.get_cons_here {ι : Type} {X : ι → Type} {Γ : List ι} {i : ι} (x : X i) (e : Env X Γ) :
    (cons x e).get Ref.here = x
    @[simp]
    theorem Cslib.Crypto.Garbling.MixedModulus.Env.get_cons_there {ι : Type} {X : ι → Type} {Γ : List ι} {i j : ι} (x : X j) (e : Env X Γ) (r : Ref Γ i) :
    (cons x e).get r.there = e.get r
    theorem Cslib.Crypto.Garbling.MixedModulus.Env.get_map₂ {ι : Type} {X Y Z : ι → Type} (f : (i : ι) → X i → Y i → Z i) {Γ : List ι} (e : Env X Γ) (e' : Env Y Γ) {i : ι} (r : Ref Γ i) :
    (map₂ f e e').get r = f i (e.get r) (e'.get r)
    theorem Cslib.Crypto.Garbling.MixedModulus.Env.gather_map₂ {ι : Type} {X Y Z : ι → Type} (f : (i : ι) → X i → Y i → Z i) {Γ : List ι} (e : Env X Γ) (e' : Env Y Γ) {Θ : List ι} (rs : Env (Ref Γ) Θ) :
    (map₂ f e e').gather rs = map₂ f (e.gather rs) (e'.gather rs)
    @[instance_reducible]
    instance Cslib.Crypto.Garbling.MixedModulus.Env.instFintype {ι : Type} {X : ι → Type} [(i : ι) → Fintype (X i)] (Γ : List ι) :
    Fintype (Env X Γ)
    instance Cslib.Crypto.Garbling.MixedModulus.Env.instNonempty {ι : Type} {X : ι → Type} [∀ (i : ι), Nonempty (X i)] (Γ : List ι) :
    Nonempty (Env X Γ)

    Mixed-modulus circuits #

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.Residue {ι : Type} (μ : ι → ℕ) (i : ι) :

    A residue of sort i: a wire value in ℤ_{μ i}.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.Label {ι : Type} (μ ℓ : ι → ℕ) (i : ι) :

    A wire label of sort i: a key in ℤ_{μ i}^{ℓ i} and a colour in ℤ_{μ i}, that is, a vector of ℤ_{μ i}^{ℓ i + 1} whose last coordinate is the colour.

    def Cslib.Crypto.Garbling.MixedModulus.offset {ι : Type} {μ ℓ : ι → ℕ} (δ : (i : ι) → Fin (ℓ i) → ZMod (μ i)) (i : ι) :
    Label μ ℓ i

    The offset Δ_i = (δ_i, 1) of sort i: key part δ_i and colour 1.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.Projection {ι : Type} (μ : ι → ℕ) (i j : ι) :

    The payload of an actual projection gate from sort i to sort j: a function ℤ_{μ i} → ℤ_{μ j}.

    inductive Cslib.Crypto.Garbling.MixedModulus.MixedModulusCircuit {ι : Type} (μ : ι → ℕ) (P : ι → ι → Type) :
    List ι → List ι → Type

    A mixed-modulus circuit [BMR16] with inputs of the sorts in Γ and outputs of the sorts in Θ, as a straight-line program: each gate reads earlier wires and appends a new wire. P i j is the payload of a projection gate from sort i to sort j.

    def Cslib.Crypto.Garbling.MixedModulus.MixedModulusCircuit.size {ι : Type} {μ : ι → ℕ} {P : ι → ι → Type} {Γ Θ : List ι} :
    MixedModulusCircuit μ P Γ Θ → ℕ

    The number of gates.

    def Cslib.Crypto.Garbling.MixedModulus.MixedModulusCircuit.eval {ι : Type} {μ : ι → ℕ} {Γ Θ : List ι} :
    MixedModulusCircuit μ (Projection μ) Γ Θ → Env (Residue μ) Γ → Env (Residue μ) Θ

    Evaluate a circuit on the residues of its input wires.

    Runs of oracle programs #

    def Cslib.Crypto.Garbling.MixedModulus.IsRun {Q : Type} {spec : OracleSpec Q} {α : Type} :
    OracleComp spec α → List Q → α → Prop

    A run of an oracle program: the requests it makes, in order, and its result, when each call is answered independently by an arbitrary reply. Two calls with the same request may get different replies along one run.

    theorem Cslib.Crypto.Garbling.MixedModulus.IsRun.bind {Q : Type} {spec : OracleSpec Q} {α β : Type} {p : OracleComp spec α} {k : α → OracleComp spec β} {requests : List Q} {b : β} (h : IsRun (p >>= k) requests b) :
    ∃ (r₁ : List Q) (a : α) (r₂ : List Q), IsRun p r₁ a ∧ IsRun (k a) r₂ b ∧ requests = r₁ ++ r₂

    A run of a sequence splits into a run of its first part and a run of the continuation selected by the first result.

    Mixed-modulus circular correlation robustness #

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput {ι : Type} (μ ℓ : ι → ℕ) :

    A query (g, X, a, b) of the mixed-modulus CCR oracle without its tweak g: the source sort i, the target sort j, the label X of sort i, and the multipliers a ∈ ℤ_{μ i} and b ∈ ℤ_{μ j}.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput.source {ι : Type} {μ ℓ : ι → ℕ} (r : CCRInput μ ℓ) :
    ι

    The source sort i.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput.target {ι : Type} {μ ℓ : ι → ℕ} (r : CCRInput μ ℓ) :
    ι

    The target sort j.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput.label {ι : Type} {μ ℓ : ι → ℕ} (r : CCRInput μ ℓ) :
    Label μ ℓ r.source

    The label X of the source sort.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput.a {ι : Type} {μ ℓ : ι → ℕ} (r : CCRInput μ ℓ) :
    ZMod (μ r.source)

    The multiplier a ∈ ℤ_{μ i} of the source offset.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRInput.b {ι : Type} {μ ℓ : ι → ℕ} (r : CCRInput μ ℓ) :
    ZMod (μ r.target)

    The multiplier b ∈ ℤ_{μ j} of the target offset.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.ccrSpec {ι : Type} (T : Type) (μ ℓ : ι → ℕ) :
    T × CCRInput μ ℓ → Type

    The oracle interface: a query with tweak in T is answered by a label of its target sort.

    @[reducible, inline]

    A tweakable mixed-modulus hash H(g, X): a tweak, a label of a source sort and a target sort give a label of the target sort.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRAdversary {ι : Type} (T : Type) (μ ℓ : ι → ℕ) :

    An adversary against mixed-modulus CCR: private coins and adaptive oracle queries.

    def Cslib.Crypto.Garbling.MixedModulus.ccrOracle {ι T : Type} {μ ℓ : ι → ℕ} (H : MixedModulusHash T μ ℓ) (δ : (i : ι) → Fin (ℓ i) → ZMod (μ i)) (q : T × CCRInput μ ℓ) :
    Label μ ℓ q.2.target

    The real mixed-modulus CCR oracle 𝒪_Δ(g, X, a, b) = H(g, X + a Δ_i) + b Δ_j, for offsets Δ_i = (δ_i, 1).

    def Cslib.Crypto.Garbling.MixedModulus.ccrKey {ι T : Type} {μ ℓ : ι → ℕ} (q : T × CCRInput μ ℓ) :
    T × (i : ι) × Label μ ℓ i × ZMod (μ i)

    The part of a query that must determine the whole query in a legal run: the tweak, the source sort, the label X and the multiplier a.

    def Cslib.Crypto.Garbling.MixedModulus.CCRLegal {ι T : Type} {μ ℓ : ι → ℕ} (qs : List (T × CCRInput μ ℓ)) :

    A legal list of queries: no query has a = 0, and two queries with the same tweak, source sort, label and multiplier a are equal.

    A legal adversary makes a legal list of oracle queries along every run, whatever its private coins and the oracle's replies: the oracle queries are the right components of the requests.

    noncomputable def Cslib.Crypto.Garbling.MixedModulus.ccrRealGame {ι T : Type} {μ ℓ : ι → ℕ} [Fintype ι] [DecidableEq ι] [∀ (i : ι), NeZero (μ i)] (H : MixedModulusHash T μ ℓ) (B : CCRAdversary T μ ℓ) :

    The real experiment: sample the offsets and answer every query with the real oracle.

    @[reducible, inline]
    abbrev Cslib.Crypto.Garbling.MixedModulus.CCRTable {ι : Type} (μ ℓ : ι → ℕ) :

    A reply for each query with a fixed tweak.

    @[instance_reducible]
    instance Cslib.Crypto.Garbling.MixedModulus.instFintypeCCRFunction {ι T : Type} {μ ℓ : ι → ℕ} [Fintype ι] [DecidableEq ι] [∀ (i : ι), NeZero (μ i)] [Fintype T] [DecidableEq T] :
    Fintype (T → CCRTable μ ℓ)

    Instance search does not find this product of finite function types on its own.

    noncomputable def Cslib.Crypto.Garbling.MixedModulus.ccrIdealGame {ι T : Type} {μ ℓ : ι → ℕ} [Fintype ι] [DecidableEq ι] [∀ (i : ι), NeZero (μ i)] [Fintype T] [DecidableEq T] (B : CCRAdversary T μ ℓ) :

    The ideal experiment: sample a uniformly random function and answer every query with it.

    @[reducible, inline]
    noncomputable abbrev Cslib.Crypto.Garbling.MixedModulus.ccrAdvantage {ι T : Type} {μ ℓ : ι → ℕ} [Fintype ι] [DecidableEq ι] [∀ (i : ι), NeZero (μ i)] [Fintype T] [DecidableEq T] (H : MixedModulusHash T μ ℓ) (B : CCRAdversary T μ ℓ) :

    The mixed-modulus CCR advantage of B against H.