mpc_engine/
lib.rs

1#![deny(missing_docs)]
2#![deny(rustdoc::broken_intra_doc_links)]
3//! This crate is an executable specification of an MPC engine based on the
4//! WRK17 protocol.
5
6use circuit::CircuitError;
7use messages::{Message, SubMessage};
8use primitives::commitment::COMMITMENT_LENGTH;
9
10#[derive(Debug)]
11/// An error type.
12///
13/// We generally expect to definitely panic in two cases:
14/// * Insufficient randomness was provided for a given operation
15/// * A channel handle was prematurely dropped (this indicates a bug in the
16///   specification)
17///
18/// In other cases, the errors might be the result of a buggy protocol
19/// participant, or a detected attempt at cheating. These cases should be
20/// handled by the surrounding application in order to gracefully shut down or,
21/// if possible remove the cheater in a secure way, so these errors should be
22/// handled there.
23pub enum Error {
24    /// An error during circuit processing
25    Circuit(CircuitError),
26    /// A specific subprotocol message was expected but a different one was
27    /// received.
28    UnexpectedSubprotocolMessage(SubMessage),
29    /// A specific top-level message was expected but a different one was
30    /// received
31    UnexpectedMessage(Message),
32    /// Failed to open a commitment
33    BadCommitment([u8; COMMITMENT_LENGTH], [u8; COMMITMENT_LENGTH]),
34    /// Failed to deserialize an authenticated bit
35    InvalidSerialization,
36    /// A malicious security check has failed
37    CheckFailed(String),
38    /// Error from the curve implementation
39    CurveError,
40    /// Error from the AEAD
41    AEADError,
42    /// Miscellaneous error.
43    OtherError,
44}
45
46impl From<p256::Error> for Error {
47    fn from(_value: p256::Error) -> Self {
48        Self::CurveError
49    }
50}
51
52impl From<hacspec_chacha20poly1305::Error> for Error {
53    fn from(value: hacspec_chacha20poly1305::Error) -> Self {
54        match value {
55            hacspec_chacha20poly1305::Error::InvalidTag => Self::AEADError,
56        }
57    }
58}
59
60/// The computational security parameter, in bytes.
61pub const COMPUTATIONAL_SECURITY: usize = 128 / 8;
62
63/// The statistical security parameter, in bytes.
64pub const STATISTICAL_SECURITY: usize = 5; // for 5 * 8 = 40 bits of statistical security
65
66// NOTE: The `broadcast` module implements a broadcast utility via a trusted
67// third-party message relay, in lieu of a secure peer-to-peer broadcast
68// sub-protocol.
69pub mod broadcast;
70pub mod circuit;
71pub mod messages;
72pub mod party;
73pub mod primitives;
74pub mod utils;