primitives/sharing/threat_model.rs
1//! Threat model abstraction for both offline and online phase protocols.
2//!
3//! The online phase is generic over a [`ThreatModel`], a small "bundle" trait that maps a field
4//! `F` to the concrete share and Beaver-triple types used to evaluate a circuit in that mode:
5//!
6//! - [`Malicious`] — pairwise-authenticated BDOZ shares ([`FieldShare`]) and authenticated
7//! [`Triple`]s. MAC verification happens inside `reconstruct`, so opening is checked.
8//! - [`SemiHonest`] — bare additive shares ([`SubfieldElement`]) and [`UnauthenticatedTriple`]s. No
9//! MACs are carried on the wire and preprocessing is unauthenticated.
10use std::{fmt::Debug, ops::Mul};
11
12use crate::{
13 algebra::field::{FieldExtension, SubfieldElement},
14 correlated_randomness::triples::{BeaverTriple, Triple, UnauthenticatedTriple},
15 sharing::{FieldShare, Reconstructible, SecretShare},
16};
17
18/// The threat model a protocol is secure against, determining the share and triple types used in
19/// the online phase.
20pub trait ThreatModel: Copy + Clone + Debug + Default + Send + Sync + 'static {
21 /// The share of a subfield element of `F` held by a party. It reconstructs to a
22 /// [`SubfieldElement<F>`] and can be scaled by a public subfield constant, so that generic
23 /// online tasks (Beaver multiply, public-constant multiply) work in any mode.
24 type Share<F: FieldExtension>: SecretShare
25 + Reconstructible<Value = SubfieldElement<F>>
26 + for<'a> Mul<&'a SubfieldElement<F>, Output = Self::Share<F>>;
27
28 /// The Beaver triple over `F` consumed by multiplication (and binary AND). `Send + Sync +
29 /// 'static` so it can be streamed through the async preprocessing iterator.
30 type Triple<F: FieldExtension>: BeaverTriple<Share = Self::Share<F>> + Send + Sync + 'static;
31}
32
33/// Maliciously secure mode: pairwise-authenticated (BDOZ) shares and authenticated triples.
34#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
35pub struct Malicious;
36
37/// Semi-honest (passive) mode: bare additive shares and unauthenticated triples.
38#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
39pub struct SemiHonest;
40
41impl ThreatModel for Malicious {
42 type Share<F: FieldExtension> = FieldShare<F>;
43 type Triple<F: FieldExtension> = Triple<F>;
44}
45
46impl ThreatModel for SemiHonest {
47 type Share<F: FieldExtension> = SubfieldElement<F>;
48 type Triple<F: FieldExtension> = UnauthenticatedTriple<F>;
49}