MOTION  0.01
Framework for mixed-protocol multi-party computation
boolean_gmw_gate.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Oleksandr Tkachenko
4 // Cryptography and Privacy Engineering Group (ENCRYPTO)
5 // TU Darmstadt, Germany
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 
25 #pragma once
26 
27 #include "boolean_gmw_share.h"
28 
29 #include <span>
30 
32 #include "protocols/gate.h"
33 #include "utility/bit_vector.h"
35 
37 
38 class InputGate final : public motion::InputGate {
39  using Base = motion::InputGate;
40 
41  public:
42  InputGate(std::span<const BitVector<>> input, std::size_t party_id, Backend& backend);
43 
44  InputGate(std::vector<BitVector<>>&& input, std::size_t party_id, Backend& backend);
45 
46  void InitializationHelper();
47 
48  ~InputGate() final = default;
49 
50  void EvaluateSetup() final override;
51 
52  void EvaluateOnline() final override;
53 
55 
56  protected:
58  std::vector<BitVector<>> input_;
59 
60  std::size_t bits_;
61  std::size_t boolean_sharing_id_;
62 };
64 
65 constexpr std::size_t kAll = std::numeric_limits<std::int64_t>::max();
66 
67 class OutputGate final : public motion::OutputGate {
68  using Base = motion::OutputGate;
69 
70  public:
71  OutputGate(const motion::SharePointer& parent, std::size_t output_owner = kAll);
72 
73  ~OutputGate() final = default;
74 
75  void EvaluateSetup() final override;
76 
77  void EvaluateOnline() final override;
78 
80 
82 
83  protected:
84  // indicates whether this party obtains the output
85  bool is_my_output_ = false;
86 
87  std::vector<ReusableFiberFuture<std::vector<std::uint8_t>>> output_message_futures_;
88 
89  std::mutex m_;
90 };
91 
92 class XorGate final : public TwoGate {
93  public:
95 
96  ~XorGate() final = default;
97 
98  void EvaluateSetup() final override;
99 
100  void EvaluateOnline() final override;
101 
103 
105 
106  XorGate() = delete;
107 
108  XorGate(const Gate&) = delete;
109 };
110 
111 class InvGate final : public OneGate {
112  public:
113  InvGate(const motion::SharePointer& parent);
114 
115  ~InvGate() final = default;
116 
117  void EvaluateSetup() final override;
118 
119  void EvaluateOnline() final override;
120 
122 
124 
125  InvGate() = delete;
126 
127  InvGate(const Gate&) = delete;
128 };
129 
130 class AndGate final : public TwoGate {
131  public:
133 
134  ~AndGate() final = default;
135 
136  void EvaluateSetup() final override;
137 
138  void EvaluateOnline() final override;
139 
141 
143 
144  AndGate() = delete;
145 
146  AndGate(const Gate&) = delete;
147 
148  private:
149  std::size_t mt_offset_;
150  std::size_t mt_bitlen_;
151 
152  std::shared_ptr<motion::Share> d_, e_;
153  std::shared_ptr<OutputGate> d_output_, e_output_;
154 };
155 
156 class MuxGate final : public ThreeGate {
157  public:
163  const motion::SharePointer& s);
164 
165  ~MuxGate() final = default;
166 
167  void EvaluateSetup() final override;
168 
169  void EvaluateOnline() final override;
170 
172 
174 
175  MuxGate() = delete;
176 
177  MuxGate(const Gate&) = delete;
178 
179  private:
180  std::vector<std::unique_ptr<XcOtReceiver>> ot_receiver_;
181  std::vector<std::unique_ptr<XcOtSender>> ot_sender_;
182 };
183 
184 } // namespace encrypto::motion::proto::boolean_gmw
encrypto::motion::Logger::LogTrace
void LogTrace(const std::string &message)
Definition: logger.cpp:110
output_message.h
encrypto::motion::proto::boolean_gmw::OutputGate::~OutputGate
~OutputGate() final=default
encrypto::motion::proto::boolean_gmw::AndGate::AndGate
AndGate()=delete
encrypto::motion::proto::boolean_gmw::InvGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare() const
Definition: boolean_gmw_gate.cpp:526
helpers.h
encrypto::motion::proto::boolean_gmw::InvGate::GetOutputAsShare
const motion::SharePointer GetOutputAsShare() const
Definition: boolean_gmw_gate.cpp:532
encrypto::motion::proto::boolean_gmw::OutputGate::output_message_futures_
std::vector< ReusableFiberFuture< std::vector< std::uint8_t > > > output_message_futures_
Definition: boolean_gmw_gate.h:87
encrypto::motion::Gate::gate_type_
GateType gate_type_
Definition: gate.h:105
encrypto::motion::proto::boolean_gmw::MuxGate::~MuxGate
~MuxGate() final=default
encrypto::motion::proto::boolean_gmw::MuxGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare() const
Definition: boolean_gmw_gate.cpp:879
boolean_gmw_gate.h
encrypto::motion::proto::boolean_gmw::XorGate::GetOutputAsShare
const motion::SharePointer GetOutputAsShare() const
Definition: boolean_gmw_gate.cpp:455
encrypto::motion::proto::boolean_gmw::InvGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:504
encrypto::motion::proto::boolean_gmw::OutputGate::GetOutputAsShare
const motion::SharePointer GetOutputAsShare() const
Definition: boolean_gmw_gate.cpp:359
encrypto::motion::proto::boolean_gmw::XorGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:414
encrypto::motion::proto::boolean_gmw::AndGate::GetOutputAsShare
const motion::SharePointer GetOutputAsShare() const
Definition: boolean_gmw_gate.cpp:707
encrypto::motion::Gate::GetCommunicationLayer
communication::CommunicationLayer & GetCommunicationLayer()
Definition: gate.cpp:92
encrypto::motion::Gate::output_wires_
std::vector< WirePointer > output_wires_
Definition: gate.h:100
encrypto::motion::TwoGate
Definition: gate.h:218
encrypto::motion::proto::boolean_gmw::XorGate
Definition: boolean_gmw_gate.h:92
encrypto::motion::TwoGate::parent_b_
std::vector< WirePointer > parent_b_
Definition: gate.h:221
encrypto::motion::Gate::GetLogger
Logger & GetLogger()
Definition: gate.cpp:100
encrypto::motion::proto::boolean_gmw::AndGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:608
encrypto::motion::communication::GetMessage
const encrypto::motion::communication::Message * GetMessage(const void *buf)
Definition: message_generated.h:146
encrypto::motion::OtProvider::RegisterSendXcOt
std::unique_ptr< XcOtSender > RegisterSendXcOt(std::size_t number_of_ots=1, std::size_t bitlength=1)
Definition: ot_provider.cpp:61
reusable_future.h
encrypto::motion::proto::boolean_gmw
Definition: backend.h:43
encrypto::motion::InputGate
Definition: gate.h:170
encrypto::motion::proto::boolean_gmw::InputGate
Definition: boolean_gmw_gate.h:38
bit_vector.h
encrypto::motion::OutputGate::output_owner_
std::int64_t output_owner_
Definition: gate.h:203
encrypto::motion::OneGate::parent_
std::vector< WirePointer > parent_
Definition: gate.h:155
encrypto::motion::proto::boolean_gmw::XorGate::~XorGate
~XorGate() final=default
encrypto::motion::proto::boolean_gmw::InputGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:100
encrypto::motion::proto::boolean_gmw::InvGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:499
backend.h
encrypto::motion::proto::boolean_gmw::InputGate::InitializationHelper
void InitializationHelper()
Definition: boolean_gmw_gate.cpp:55
encrypto::motion::ThreeGate::parent_c_
std::vector< WirePointer > parent_c_
Definition: gate.h:243
encrypto::motion::proto::boolean_gmw::InputGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:94
encrypto::motion::GateType::kNonInteractive
@ kNonInteractive
encrypto::motion::proto::boolean_gmw::OutputGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:234
encrypto::motion::proto::boolean_gmw::XorGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare() const
Definition: boolean_gmw_gate.cpp:449
encrypto::motion::proto::boolean_gmw::InputGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare()
Definition: boolean_gmw_gate.cpp:164
encrypto::motion::BitVector::Reserve
void Reserve(std::size_t number_of_bits)
Reserves new space for BitVector, so that it can contain at least number_of_bits bits.
Definition: bit_vector.h:185
encrypto::motion::BitVector<>
encrypto::motion::Logger::LogDebug
void LogDebug(const std::string &message)
Definition: logger.cpp:142
encrypto::motion::Gate::requires_online_interaction_
std::atomic< bool > requires_online_interaction_
Definition: gate.h:108
encrypto::motion::Gate::GetBaseProvider
BaseProvider & GetBaseProvider()
Definition: gate.cpp:102
encrypto::motion::Gate::GetRegister
Register & GetRegister()
Definition: gate.cpp:96
encrypto::motion::proto::boolean_gmw::SharePointer
std::shared_ptr< Share > SharePointer
Definition: backend.h:46
encrypto::motion::BitVector::XorBitVectors
static BitVector XorBitVectors(const std::vector< BitVector > &bit_vectors)
Performs XOR operation between all BitVectors in bit_vectors.
Definition: bit_vector.cpp:1064
encrypto::motion::proto::boolean_gmw::OutputGate::is_my_output_
bool is_my_output_
Definition: boolean_gmw_gate.h:85
encrypto::motion::MpcProtocol::kBooleanGmw
@ kBooleanGmw
encrypto::motion::proto::boolean_gmw::InputGate::InputGate
InputGate(std::span< const BitVector<>> input, std::size_t party_id, Backend &backend)
Definition: boolean_gmw_gate.cpp:41
encrypto::motion::TwoGate::parent_a_
std::vector< WirePointer > parent_a_
Definition: gate.h:220
encrypto::motion::Register::IncrementEvaluatedGatesOnlineCounter
void IncrementEvaluatedGatesOnlineCounter()
Definition: register.cpp:125
encrypto::motion::Backend
Definition: backend.h:88
encrypto::motion::proto::boolean_gmw::MuxGate::MuxGate
MuxGate()=delete
encrypto::motion::proto::boolean_gmw::AndGate
Definition: boolean_gmw_gate.h:130
encrypto::motion::proto::boolean_gmw::AndGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:613
encrypto::motion::BaseProvider::GetMyRandomnessGenerator
primitives::SharingRandomnessGenerator & GetMyRandomnessGenerator(std::size_t party_id)
Definition: motion_base_provider.h:57
encrypto::motion::Gate::RegisterWaitingFor
void RegisterWaitingFor(std::size_t wire_id)
Definition: gate.cpp:36
communication_layer.h
boolean_gmw_wire.h
encrypto::motion::Gate::SetOnlineIsReady
void SetOnlineIsReady()
Definition: gate.cpp:54
encrypto::motion::communication::CommunicationLayer::GetNumberOfParties
std::size_t GetNumberOfParties() const
Definition: communication_layer.h:65
encrypto::motion::communication::BuildOutputMessage
flatbuffers::FlatBufferBuilder BuildOutputMessage(std::size_t gate_id, std::vector< std::uint8_t > wire_payload)
Definition: output_message.cpp:35
encrypto::motion::Gate::backend_
Backend & backend_
Definition: gate.h:101
encrypto::motion::Gate::GetOtProvider
OtProvider & GetOtProvider(const std::size_t i)
Definition: gate.cpp:110
encrypto::motion::Gate::SetSetupIsReady
void SetSetupIsReady()
Definition: gate.cpp:46
encrypto::motion::Register::IncrementEvaluatedGatesSetupCounter
void IncrementEvaluatedGatesSetupCounter()
Definition: register.cpp:114
encrypto::motion::OneGate
Definition: gate.h:148
encrypto::motion::proto::boolean_gmw::XorGate::XorGate
XorGate()=delete
encrypto::motion::communication::GetOutputMessage
const encrypto::motion::communication::OutputMessage * GetOutputMessage(const void *buf)
Definition: output_message_generated.h:136
register.h
mt_provider.h
encrypto::motion::ThreeGate
Definition: gate.h:239
encrypto::motion::proto::boolean_gmw::InvGate
Definition: boolean_gmw_gate.h:111
encrypto::motion::proto::boolean_gmw::XorGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:409
encrypto::motion::proto::boolean_gmw::OutputGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:239
encrypto::motion::BaseProvider::GetTheirRandomnessGenerator
primitives::SharingRandomnessGenerator & GetTheirRandomnessGenerator(std::size_t party_id)
Definition: motion_base_provider.h:60
encrypto::motion::SharePointer
std::shared_ptr< Share > SharePointer
Definition: conversion_gate.h:49
encrypto::motion::Gate::gate_id_
std::int64_t gate_id_
Definition: gate.h:102
encrypto::motion::proto::boolean_gmw::InputGate::input_
std::vector< BitVector<> > input_
two-dimensional vector for storing the raw inputs
Definition: boolean_gmw_gate.h:58
encrypto::motion::proto::boolean_gmw::OutputGate::OutputGate
OutputGate(const motion::SharePointer &parent, std::size_t output_owner=kAll)
Definition: boolean_gmw_gate.cpp:170
encrypto::motion::communication::CommunicationLayer::GetMyId
std::size_t GetMyId() const
Definition: communication_layer.h:66
encrypto::motion::OutputGate
Definition: gate.h:194
encrypto::motion::proto::boolean_gmw::OutputGate
Definition: boolean_gmw_gate.h:67
encrypto::motion::proto::boolean_gmw::OutputGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare() const
Definition: boolean_gmw_gate.cpp:353
sharing_randomness_generator.h
encrypto::motion::Gate
Definition: gate.h:67
ot_flavors.h
encrypto::motion::Gate::setup_is_ready_
std::atomic< bool > setup_is_ready_
Definition: gate.h:106
encrypto::motion::proto::boolean_gmw::MuxGate::EvaluateSetup
void EvaluateSetup() final override
Definition: boolean_gmw_gate.cpp:783
encrypto::motion::proto::boolean_gmw::MuxGate::EvaluateOnline
void EvaluateOnline() final override
Definition: boolean_gmw_gate.cpp:788
encrypto::motion::proto::boolean_gmw::InputGate::boolean_sharing_id_
std::size_t boolean_sharing_id_
correlated randomness using AES CTR
Definition: boolean_gmw_gate.h:61
encrypto::motion::kVerboseDebug
constexpr bool kVerboseDebug
Definition: constants.h:50
encrypto::motion::proto::boolean_gmw::kAll
constexpr std::size_t kAll
Definition: boolean_gmw_gate.h:65
encrypto::motion::Gate::GetMtProvider
MtProvider & GetMtProvider()
Definition: gate.cpp:104
encrypto::motion::BitSpan
Non-owning non-resizeable BitVector.
Definition: bit_vector.h:578
encrypto::motion::primitives::SharingRandomnessGenerator::GetBits
BitVector GetBits(const std::size_t gate_id, const std::size_t number_of_bits)
Definition: sharing_randomness_generator.cpp:68
encrypto::motion::detail::invert
T invert(std::size_t k, T a)
Definition: sb_impl.h:82
encrypto::motion::BitVector::Append
void Append(bool bit) noexcept
Appends a bit to BitVector.
Definition: bit_vector.cpp:621
gate.h
d
static const fe d
Definition: mycurve25519_tables.h:30
encrypto::motion::proto::boolean_gmw::AndGate::GetOutputAsGmwShare
const boolean_gmw::SharePointer GetOutputAsGmwShare() const
Definition: boolean_gmw_gate.cpp:701
encrypto::motion::ThreeGate::parent_a_
std::vector< WirePointer > parent_a_
Definition: gate.h:241
encrypto::motion::proto::boolean_gmw::OutputGate::m_
std::mutex m_
Definition: boolean_gmw_gate.h:89
encrypto::motion::Gate::WaitSetup
void WaitSetup() const
Definition: gate.cpp:68
encrypto::motion::Backend::GetMtProvider
auto & GetMtProvider()
Definition: backend.h:299
encrypto::motion::Register::RegisterNextWire
void RegisterNextWire(WirePointer wire)
Definition: register.h:78
encrypto::motion::proto::boolean_gmw::MuxGate
Definition: boolean_gmw_gate.h:156
encrypto::motion::BaseProvider::WaitForSetup
void WaitForSetup() const
Definition: motion_base_provider.cpp:183
encrypto::motion::OtProvider::RegisterReceiveXcOt
std::unique_ptr< XcOtReceiver > RegisterReceiveXcOt(std::size_t number_of_ots=1, std::size_t bitlength=1)
Definition: ot_provider.cpp:113
encrypto::motion::GateType::kInteractive
@ kInteractive
encrypto::motion::kDebug
constexpr bool kDebug
Definition: config.h:36
encrypto::motion::proto::boolean_gmw::InputGate::bits_
std::size_t bits_
Number of parallel values on wires.
Definition: boolean_gmw_gate.h:60
encrypto::motion::ThreeGate::parent_b_
std::vector< WirePointer > parent_b_
Definition: gate.h:242
encrypto::motion::proto::boolean_gmw::InvGate::InvGate
InvGate()=delete
encrypto::motion::to_string
std::string to_string(std::vector< T > values)
Returns a string representation of the std::vector values.
Definition: helpers.h:455
encrypto::motion::proto::boolean_gmw::MuxGate::GetOutputAsShare
const motion::SharePointer GetOutputAsShare() const
Definition: boolean_gmw_gate.cpp:885
encrypto::motion::proto::boolean_gmw::InputGate::~InputGate
~InputGate() final=default
boolean_gmw_share.h
encrypto::motion::proto::boolean_gmw::InvGate::~InvGate
~InvGate() final=default
encrypto::motion::proto::boolean_gmw::AndGate::~AndGate
~AndGate() final=default
encrypto::motion::Register::NextGateId
std::size_t NextGateId() noexcept
Definition: register.cpp:53
encrypto::motion::InputGate::input_owner_id_
std::int64_t input_owner_id_
Definition: gate.h:179