Skip to main content

primitives/sharing/
mod.rs

1// Secret sharing schemes.
2pub mod authenticated;
3pub mod reconstructible;
4pub mod threat_model;
5pub mod unauthenticated;
6
7use std::{
8    fmt::Debug,
9    ops::{Add, Neg, Sub},
10};
11
12pub use authenticated::*;
13pub use reconstructible::Reconstructible;
14use serde::{de::DeserializeOwned, Serialize};
15pub use threat_model::*;
16pub use unauthenticated::*;
17
18/// Secret share bounds, allowing arithmetic operations and reconstruction. Sharing/inputting a
19/// secret might requre communication and is thus deferred to the online phase.
20pub trait SecretShare:
21    Reconstructible
22    + PlaintextOps<<Self as Reconstructible>::Value>
23    + Clone
24    + Debug
25    + Send
26    + Sync
27    + 'static
28    + PartialEq
29    + Serialize
30    + DeserializeOwned
31    + for<'a> Add<&'a Self, Output = Self>
32    + for<'s> Sub<&'s Self, Output = Self>
33    + Neg<Output = Self>
34{
35}
36
37impl<T> SecretShare for T where
38    T: Reconstructible
39        + PlaintextOps<<Self as Reconstructible>::Value>
40        + Clone
41        + Debug
42        + Send
43        + Sync
44        + 'static
45        + PartialEq
46        + Serialize
47        + DeserializeOwned
48        + for<'a> Add<&'a Self, Output = Self>
49        + for<'a> Sub<&'a Self, Output = Self>
50        + Neg<Output = Self>
51{
52}
53
54/// Operates a secret share with a public plaintext (addition/subtraction). These are often
55/// asymmetric (e.g., only the first peer folds the constant into its share). Scaling a share by a
56/// public constant is expressed directly through `Mul` where needed, so it is not part of this
57/// trait.
58pub trait PlaintextOps<Plaintext = <Self as Reconstructible>::Value>: Reconstructible {
59    /// Add a plaintext to the share, consuming the share and returning a new one.
60    fn add_plaintext(self, ptx: &Plaintext, is_first_peer: bool) -> Self;
61
62    /// Subtract a plaintext from the share, consuming the share and returning a new one.
63    fn sub_plaintext(self, ptx: &Plaintext, is_first_peer: bool) -> Self;
64}