mpc_engine/messages.rs
1//! This module defines message types for the MPC protocol and its sub-protocols.
2use std::sync::mpsc::{Receiver, Sender};
3
4use crate::{
5 circuit::WireIndex,
6 primitives::{
7 auth_share::BitID,
8 commitment::{Commitment, Opening},
9 mac::Mac,
10 ot::{OTReceiverSelect, OTSenderInit, OTSenderSend},
11 },
12 COMPUTATIONAL_SECURITY,
13};
14
15/// An overall message type for all messages between parties.
16///
17/// It includes:
18/// - top-level protocol messages
19/// - suprotocol messages (incomplete)
20/// - messages for the FPre subprotocol
21/// - (not currently) messages for the remaining sub-protocols which implement
22/// FPre
23#[derive(Debug)]
24pub struct Message {
25 pub(crate) from: usize,
26 pub(crate) to: usize,
27 pub(crate) payload: MessagePayload,
28}
29
30/// Messages that are actually sent between parties in the top-level MPC
31/// protocol.
32#[derive(Debug)]
33pub enum MessagePayload {
34 /// A round synchronization message
35 Sync,
36 /// Request a number of bit authentications from another party.
37 RequestBitAuth(BitID, Sender<SubMessage>, Receiver<SubMessage>),
38 /// A response to a bit authentication request.
39 BitAuth(BitID, Mac),
40 /// A commitment on a broadcast value.
41 BroadcastCommitment(Commitment),
42 /// The opening to a broadcast value.
43 BroadcastOpening(Opening),
44 /// A subchannel for running an 2-party subprotocol.
45 SubChannel(Sender<SubMessage>, Receiver<SubMessage>),
46 /// A bit mac for validity checking
47 Mac(Mac),
48 /// Values sent over to other parties in the half-AND protocol
49 HalfAndHashes(bool, bool),
50 /// Value exchanged during leaky AND-triple check
51 LeakyAndU(Mac),
52 /// A two-party bit reveal message
53 BitReveal(bool, Mac),
54 /// A garbled AND gate, to be sent to the evaluator
55 GarbledAnd(Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>),
56 /// A MAC on a wire mask share
57 WireMac(bool, Mac),
58 /// Masked input wire value
59 MaskedInput(bool),
60 /// A wire label, to be sent to the evaluator
61 WireLabel {
62 /// The wire the label belongs to
63 wire: WireIndex,
64 /// The wire label
65 label: [u8; COMPUTATIONAL_SECURITY],
66 },
67}
68
69#[derive(Debug)]
70/// Message communicated on an subprotocol channel
71pub enum SubMessage {
72 /// An OT sender commitment
73 OTCommit(OTSenderInit),
74 /// An OT receiver selection
75 OTSelect(OTReceiverSelect),
76 /// An OT sender final message
77 OTSend(OTSenderSend),
78 /// An EQ initiator commitment
79 EQCommit(Commitment),
80 /// An EQ responder message
81 EQResponse(Vec<u8>),
82 /// An EQ initiator opening
83 EQOpening(Opening),
84}