Documentation

CslibFrontier.Crypto.Protocols.OPRF.DiffieHellman

Diffie–Hellman oblivious pseudorandom functions: algebra and message laws #

[BS23], Section 11.6.3 (pp. 454–456), defines the function F′(k, x) = H′(x, H(x)^k) of equation (11.21) over a cyclic group G of prime order q with generator g, and gives two protocols, OPRF1 and OPRF2, by which a sender holding the key k and a receiver holding the input x evaluate F′(k, x). Here G is written additively as a ZMod q-module, so H(x)^k is k • H x, g^k is k • g, equation (11.21) is H' x (k • H x), and the hashed input H(x) is an element h : G:

This module defines maskedBlind and maskedUnblind (exposed so tests and downstream protocols can unfold them directly), and proves the OPRF2 identities and five exact PMF laws for the receiver's message in each protocol and for the joint distribution against a deviating OPRF2 sender that adds d v to its response.

Deviations from [BS23] #

Main definitions #

Main results #

References #

Protocol OPRF2 blinding and unblinding #

def Cslib.Crypto.Protocols.OPRF.maskedBlind {G : Type} [AddCommGroup G] {q : ℕ} [Module (ZMod q) G] (g : G) (ρ : (ZMod q)ˣ) (τ : ZMod q) (h : G) :
G

The receiver's blinding step in Protocol OPRF2 ([BS23], Section 11.6.3, p. 456): the OPRF1 message ρ • h masked by τ • g.

def Cslib.Crypto.Protocols.OPRF.maskedUnblind {G : Type} [AddCommGroup G] {q : ℕ} [Module (ZMod q) G] (u : G) (ρ : (ZMod q)ˣ) (τ : ZMod q) (w : G) :
G

The receiver's unblinding step in Protocol OPRF2 ([BS23], Section 11.6.3, p. 456), given the sender's public key u = k • g: subtract τ • u from w and multiply by ρ⁻¹.

theorem Cslib.Crypto.Protocols.OPRF.maskedUnblind_smul_maskedBlind_add {G : Type} [AddCommGroup G] {q : ℕ} [Module (ZMod q) G] (g : G) (ρ : (ZMod q)ˣ) (τ k : ZMod q) (h d : G) :
maskedUnblind (k • g) ρ τ (k • maskedBlind g ρ τ h + d) = k • h + ρ⁻¹ • d

In Protocol OPRF2 ([BS23], Section 11.6.3, p. 456), if the sender answers v = maskedBlind g ρ τ h with k • v + d, the receiver's unblinded group element is k • h + ρ⁻¹ • d.

theorem Cslib.Crypto.Protocols.OPRF.maskedUnblind_smul_maskedBlind {G : Type} [AddCommGroup G] {q : ℕ} [Module (ZMod q) G] (g : G) (ρ : (ZMod q)ˣ) (τ k : ZMod q) (h : G) :
maskedUnblind (k • g) ρ τ (k • maskedBlind g ρ τ h) = k • h

Correctness of Protocol OPRF2 ([BS23], Section 11.6.3, p. 456) at the level of group elements: when the sender responds honestly under public key k • g, maskedUnblind recovers k • h.

What the sender sees #

theorem Cslib.Crypto.Protocols.OPRF.uniformOfFintype_bind_units_smul_smul {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {α : Type u_1} (a : (ZMod q)ˣ) (h : G) (f : G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (ρ • a • h)) = (Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (ρ • h)

Without primality of q, hashed inputs that differ by an invertible factor a : (ZMod q)ˣ induce the same OPRF1 message distribution under a uniform ρ : (ZMod q)ˣ.

theorem Cslib.Crypto.Protocols.OPRF.uniformOfFintype_bind_units_smul_of_ne_zero {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {α : Type u_1} [Fact (Nat.Prime q)] {g h : G} (hg : Function.Surjective fun (c : ZMod q) => c • g) (hh : h ≠ 0) (f : G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (ρ • h)) = (Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (ρ • g)

The receiver's message law in Protocol OPRF1 ([BS23], Section 11.6.3, p. 455): in a group of prime order q generated by g, for every nonzero hashed input h ≠ 0, ρ • h under uniform ρ : (ZMod q)ˣ has the same distribution as ρ • g (which is never 0 since g ≠ 0).

The book's statement that "the sender just sees a random group element, statistically independent of x" needs H(x) ≠ 1 (H x ≠ 0), which the book does not state; for a random oracle H : X → G, H(x) ≠ 1 fails with probability 1 / q per input. Because ρ is drawn from (ZMod q)ˣ, if h = 0 then ρ • 0 = 0 always, whereas if h ≠ 0 then ρ • h has the law of ρ • g and is never 0. Thus, for a fixed H, the message distribution is independent of x only among inputs with H x ≠ 0.

theorem Cslib.Crypto.Protocols.OPRF.uniformOfFintype_bind_maskedBlind {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {α : Type u_1} {g : G} (hg : Function.Surjective fun (c : ZMod q) => c • g) (ρ : (ZMod q)ˣ) (h : G) (f : G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => f (maskedBlind g ρ τ h)) = (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => f (τ • g)

The receiver's message law in Protocol OPRF2 ([BS23], Section 11.6.3, p. 456): when g generates G, for every hashed input h and every ρ : (ZMod q)ˣ, maskedBlind g ρ τ h under uniform τ : ZMod q has the distribution of τ • g, so the message leaks nothing about h or ρ. This is Cslib.Crypto.uniformOfFintype_bind_smul_add applied at ρ • h.

theorem Cslib.Crypto.Protocols.OPRF.uniformOfFintype_bind_maskedUnblind_add {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {α : Type u_1} {g : G} (hg : Function.Surjective fun (c : ZMod q) => c • g) (k : ZMod q) (h : G) (d : G → G) (f : G → G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => f (maskedBlind g ρ τ h) (maskedUnblind (k • g) ρ τ (k • maskedBlind g ρ τ h + d (maskedBlind g ρ τ h)))) = (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => (Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (τ • g) (k • h + ρ • d (τ • g))

Joint law of the receiver's message and unblinded group element against a deviating OPRF2 sender ([BS23], Section 11.6.3, p. 456), without primality of q: when g generates G and the sender adds d v to its honest response on message v, the message v and the element computed by the receiver have the joint distribution of (τ • g, k • h + ρ • d (τ • g)) for independent uniform τ : ZMod q and ρ : (ZMod q)ˣ.

theorem Cslib.Crypto.Protocols.OPRF.uniformOfFintype_bind_maskedUnblind_add_of_ne_zero {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {α : Type u_1} [Fact (Nat.Prime q)] {g : G} (hg : Function.Surjective fun (c : ZMod q) => c • g) (k : ZMod q) (h : G) (d : G → G) (hd : ∀ (v : G), d v ≠ 0) (f : G → G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => f (maskedBlind g ρ τ h) (maskedUnblind (k • g) ρ τ (k • maskedBlind g ρ τ h + d (maskedBlind g ρ τ h)))) = (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (τ : ZMod q) => (Probability.PMF.uniformOfFintype (ZMod q)ˣ).bind fun (ρ : (ZMod q)ˣ) => f (τ • g) (k • h + ρ • g)

Joint law of the receiver's message and unblinded group element against a deviating OPRF2 sender in a prime-order group ([BS23], Section 11.6.3, p. 456): when q is prime, g generates G, and the sender's deviation d v on every message v is nonzero, the message and the element computed by the receiver are jointly distributed as (τ • g, k • h + ρ • g) for independent uniform τ : ZMod q and ρ : (ZMod q)ˣ.

The book's statement that for a wrong answer (d ≠ 0), the error term ρ⁻¹ • d (printed d^(1/ρ)) "is just a random group element (uniformly distributed over G)" omits 0: because ρ is a unit and d v ≠ 0, ρ⁻¹ • d v is never 0, and instead has the law of ρ • g for uniform ρ : (ZMod q)ˣ (which is never 0 since g ≠ 0; for prime q and g ≠ 0, this is the uniform distribution on G \ {0}, which this module does not prove).