1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! This module defines message types for the MPC protocol and its sub-protocols.
use std::sync::mpsc::{Receiver, Sender};

use crate::{
    circuit::WireIndex,
    primitives::{
        auth_share::BitID,
        commitment::{Commitment, Opening},
        mac::Mac,
        ot::{OTReceiverSelect, OTSenderInit, OTSenderSend},
    },
    COMPUTATIONAL_SECURITY,
};

/// An overall message type for all messages between parties.
///
/// It includes:
/// - top-level protocol messages
/// - suprotocol messages (incomplete)
///   - messages for the FPre subprotocol
///   - (not currently) messages for the remaining sub-protocols which implement
///     FPre
#[derive(Debug)]
pub struct Message {
    pub(crate) from: usize,
    pub(crate) to: usize,
    pub(crate) payload: MessagePayload,
}

/// Messages that are actually sent between parties in the top-level MPC
/// protocol.
#[derive(Debug)]
pub enum MessagePayload {
    /// A round synchronization message
    Sync,
    /// Request a number of bit authentications from another party.
    RequestBitAuth(BitID, Sender<SubMessage>, Receiver<SubMessage>),
    /// A response to a bit authentication request.
    BitAuth(BitID, Mac),
    /// A commitment on a broadcast value.
    BroadcastCommitment(Commitment),
    /// The opening to a broadcast value.
    BroadcastOpening(Opening),
    /// A subchannel for running an 2-party subprotocol.
    SubChannel(Sender<SubMessage>, Receiver<SubMessage>),
    /// A bit mac for validity checking
    Mac(Mac),
    /// Values sent over to other parties in the half-AND protocol
    HalfAndHashes(bool, bool),
    /// Value exchanged during leaky AND-triple check
    LeakyAndU(Mac),
    /// A two-party bit reveal message
    BitReveal(bool, Mac),
    /// A garbled AND gate, to be sent to the evaluator
    GarbledAnd(Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>),
    /// A MAC on a wire mask share
    WireMac(bool, Mac),
    /// Masked input wire value
    MaskedInput(bool),
    /// A wire label, to be sent to the evaluator
    WireLabel {
        /// The wire the label belongs to
        wire: WireIndex,
        /// The wire label
        label: [u8; COMPUTATIONAL_SECURITY],
    },
}

#[derive(Debug)]
/// Message communicated on an subprotocol channel
pub enum SubMessage {
    /// An OT sender commitment
    OTCommit(OTSenderInit),
    /// An OT receiver selection
    OTSelect(OTReceiverSelect),
    /// An OT sender final message
    OTSend(OTSenderSend),
    /// An EQ initiator commitment
    EQCommit(Commitment),
    /// An EQ responder message
    EQResponse(Vec<u8>),
    /// An EQ initiator opening
    EQOpening(Opening),
}