arcium-primitives 0.7.2

Arcium primitives
Documentation
// Secret sharing schemes.
pub mod authenticated;
pub mod reconstructible;
pub mod threat_model;
pub mod unauthenticated;

use std::{
    fmt::Debug,
    ops::{Add, Neg, Sub},
};

pub use authenticated::*;
pub use reconstructible::Reconstructible;
use serde::{de::DeserializeOwned, Serialize};
pub use threat_model::*;
pub use unauthenticated::*;
use wincode::{SchemaRead, SchemaWrite};

/// Secret share bounds, allowing arithmetic operations and reconstruction. Sharing/inputting a
/// secret might requre communication and is thus deferred to the online phase.
pub trait SecretShare:
    Reconstructible
    + PlaintextOps<<Self as Reconstructible>::Value>
    + Clone
    + Debug
    + Send
    + Sync
    + 'static
    + PartialEq
    + Serialize
    + DeserializeOwned
    + SchemaWrite<Src = Self>
    + for<'de> SchemaRead<'de, Dst = Self>
    + for<'a> Add<&'a Self, Output = Self>
    + for<'s> Sub<&'s Self, Output = Self>
    + Neg<Output = Self>
{
}

impl<T> SecretShare for T where
    T: Reconstructible
        + PlaintextOps<<Self as Reconstructible>::Value>
        + Clone
        + Debug
        + Send
        + Sync
        + 'static
        + PartialEq
        + Serialize
        + DeserializeOwned
        + SchemaWrite<Src = Self>
        + for<'de> SchemaRead<'de, Dst = Self>
        + for<'a> Add<&'a Self, Output = Self>
        + for<'a> Sub<&'a Self, Output = Self>
        + Neg<Output = Self>
{
}

/// Operates a secret share with a public plaintext (addition/subtraction). These are often
/// asymmetric (e.g., only the first peer folds the constant into its share). Scaling a share by a
/// public constant is expressed directly through `Mul` where needed, so it is not part of this
/// trait.
pub trait PlaintextOps<Plaintext = <Self as Reconstructible>::Value>: Reconstructible {
    /// Add a plaintext to the share, consuming the share and returning a new one.
    fn add_plaintext(self, ptx: &Plaintext, is_first_peer: bool) -> Self;

    /// Subtract a plaintext from the share, consuming the share and returning a new one.
    fn sub_plaintext(self, ptx: &Plaintext, is_first_peer: bool) -> Self;
}