arcium-primitives 0.8.1

Arcium primitives
Documentation
//! Threat model abstraction for both offline and online phase protocols.
//!
//! The online phase is generic over a [`ThreatModel`], a small "bundle" trait that maps a field
//! `F` to the concrete share and Beaver-triple types used to evaluate a circuit in that mode:
//!
//! - [`Malicious`] — pairwise-authenticated BDOZ shares ([`FieldShare`]) and authenticated
//!   [`Triple`]s. MAC verification happens inside `reconstruct`, so opening is checked.
//! - [`SemiHonest`] — bare additive shares ([`SubfieldElement`]) and [`UnauthenticatedTriple`]s. No
//!   MACs are carried on the wire and preprocessing is unauthenticated.
use std::{fmt::Debug, ops::Mul};

use crate::{
    algebra::field::{FieldExtension, SubfieldElement},
    correlated_randomness::triples::{BeaverTriple, Triple, UnauthenticatedTriple},
    sharing::{FieldShare, Reconstructible, SecretShare},
};

/// The threat model a protocol is secure against, determining the share and triple types used in
/// the online phase.
pub trait ThreatModel: Copy + Clone + Debug + Default + Send + Sync + 'static {
    /// The share of a subfield element of `F` held by a party. It reconstructs to a
    /// [`SubfieldElement<F>`] and can be scaled by a public subfield constant, so that generic
    /// online tasks (Beaver multiply, public-constant multiply) work in any mode.
    type Share<F: FieldExtension>: SecretShare
        + Reconstructible<Value = SubfieldElement<F>>
        + for<'a> Mul<&'a SubfieldElement<F>, Output = Self::Share<F>>;

    /// The Beaver triple over `F` consumed by multiplication (and binary AND). `Send + Sync +
    /// 'static` so it can be streamed through the async preprocessing iterator.
    type Triple<F: FieldExtension>: BeaverTriple<Share = Self::Share<F>> + Send + Sync + 'static;
}

/// Maliciously secure mode: pairwise-authenticated (BDOZ) shares and authenticated triples.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct Malicious;

/// Semi-honest (passive) mode: bare additive shares and unauthenticated triples.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct SemiHonest;

impl ThreatModel for Malicious {
    type Share<F: FieldExtension> = FieldShare<F>;
    type Triple<F: FieldExtension> = Triple<F>;
}

impl ThreatModel for SemiHonest {
    type Share<F: FieldExtension> = SubfieldElement<F>;
    type Triple<F: FieldExtension> = UnauthenticatedTriple<F>;
}