MOTION  0.01
Framework for mixed-protocol multi-party computation
motion_base_provider.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2020 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <atomic>
26 #include <memory>
28 
30 
31 class CommunicationLayer;
32 
33 } // namespace encrypto::motion::communication
34 
36 
38 
39 } // namespace encrypto::motion::primitives
40 
41 namespace encrypto::motion {
42 
43 class FiberCondition;
44 class Logger;
45 struct HelloMessageHandler;
47 
48 class BaseProvider {
49  public:
50  BaseProvider(communication::CommunicationLayer&, std::shared_ptr<Logger> logger);
51  ~BaseProvider();
52 
53  void Setup();
54  void WaitForSetup() const;
55 
56  const std::vector<std::uint8_t>& GetAesFixedKey() const { return aes_fixed_key_; }
58  return *my_randomness_generators_.at(party_id);
59  }
61  return *their_randomness_generators_.at(party_id);
62  }
63 
64  std::vector<ReusableFiberFuture<std::vector<std::uint8_t>>> RegisterForOutputMessages(
65  std::size_t gate_id);
66 
67  private:
68  communication::CommunicationLayer& communication_layer_;
69  std::shared_ptr<Logger> logger_;
70  std::size_t number_of_parties_;
71  std::size_t my_id_;
72  std::vector<std::uint8_t> aes_fixed_key_;
73  std::vector<std::unique_ptr<primitives::SharingRandomnessGenerator>> my_randomness_generators_;
74  std::vector<std::unique_ptr<primitives::SharingRandomnessGenerator>> their_randomness_generators_;
75  std::shared_ptr<HelloMessageHandler> hello_message_handler_;
76  std::vector<std::shared_ptr<OutputMessageHandler>> output_message_handlers_;
77 
78  std::atomic_flag execute_setup_flag_ = ATOMIC_FLAG_INIT;
79  bool setup_ready_;
80  std::unique_ptr<FiberCondition> setup_ready_cond_;
81 };
82 
83 } // namespace encrypto::motion
ParsePartyArgument
std::tuple< std::size_t, std::string, std::uint16_t > ParsePartyArgument(const std::string &party_argument)
Definition: millionaires_problem_main.cpp:71
encrypto::motion::communication::MessageType::kHelloMessage
@ kHelloMessage
party.h
CheckPartyArgumentSyntax
bool CheckPartyArgumentSyntax(const std::string &party_argument)
Definition: millionaires_problem_main.cpp:66
encrypto::motion::HelloMessageHandler::logger_
std::shared_ptr< Logger > logger_
Definition: motion_base_provider.cpp:59
motion_base_provider.h
millionaires_problem.h
CreateParty
encrypto::motion::PartyPointer CreateParty(const program_options::variables_map &user_options)
Definition: millionaires_problem_main.cpp:145
encrypto::motion::HelloMessageHandler::randomness_sharing_seed_promises
std::vector< ReusablePromise< std::vector< std::uint8_t > > > randomness_sharing_seed_promises
Definition: motion_base_provider.cpp:62
encrypto::motion::HelloMessageHandler::fixed_key_aes_seed_futures
std::vector< ReusableFuture< std::vector< std::uint8_t > > > fixed_key_aes_seed_futures
Definition: motion_base_provider.cpp:61
encrypto::motion::HelloMessageHandler::randomness_sharing_seed_futures
std::vector< ReusableFuture< std::vector< std::uint8_t > > > randomness_sharing_seed_futures
Definition: motion_base_provider.cpp:63
fiber_condition.h
encrypto::motion::ReusableFuture
Definition: reusable_future.h:129
encrypto::motion::OutputMessageHandler
Definition: output_message_handler.h:33
encrypto::motion::Logger
Definition: logger.h:40
encrypto::motion::BaseProvider::Setup
void Setup()
Definition: motion_base_provider.cpp:113
encrypto::motion::PartyPointer
std::unique_ptr< Party > PartyPointer
Definition: party.h:387
encrypto::motion::HelloMessageHandler::ReceivedMessage
void ReceivedMessage(std::size_t party_id, std::vector< std::uint8_t > &&message) override
Definition: motion_base_provider.cpp:66
encrypto::motion::communication::GetMessage
const encrypto::motion::communication::Message * GetMessage(const void *buf)
Definition: message_generated.h:146
reusable_future.h
encrypto::motion::communication::GetHelloMessage
const encrypto::motion::communication::HelloMessage * GetHelloMessage(const void *buf)
Definition: hello_message_generated.h:142
encrypto::motion::FiberCondition
Wraps a boost::fibers::condition_variable with a boost::fibers::mutex and a condition checking functi...
Definition: fiber_condition.h:35
encrypto::motion::HelloMessageHandler
Definition: motion_base_provider.cpp:39
encrypto::motion::primitives::SharingRandomnessGenerator
Definition: sharing_randomness_generator.h:60
encrypto::motion::HelloMessageHandler::fixed_key_aes_seed_promises
std::vector< ReusablePromise< std::vector< std::uint8_t > > > fixed_key_aes_seed_promises
Definition: motion_base_provider.cpp:60
main
int main(int ac, char *av[])
Definition: millionaires_problem_main.cpp:49
encrypto::motion::communication::CommunicationLayer::RegisterMessageHandler
void RegisterMessageHandler(MessageHandlerFunction, const std::vector< MessageType > &message_types)
Definition: communication_layer.cpp:393
encrypto::motion::communication::TcpSetupHelper
Definition: tcp_transport.h:69
encrypto::motion::BaseProvider::GetMyRandomnessGenerator
primitives::SharingRandomnessGenerator & GetMyRandomnessGenerator(std::size_t party_id)
Definition: motion_base_provider.h:57
communication_layer.h
ParseProgramOptions
std::pair< program_options::variables_map, bool > ParseProgramOptions(int ac, char *av[])
Definition: millionaires_problem_main.cpp:82
encrypto::motion::HelloMessageHandler::HelloMessageHandler
HelloMessageHandler(std::size_t number_of_parties, std::shared_ptr< Logger > logger)
Definition: motion_base_provider.cpp:41
encrypto::motion::primitives
Definition: motion_base_provider.h:35
encrypto::motion::HelloMessageHandler::GetRandomnessSharingSeedFuture
ReusableFuture< std::vector< std::uint8_t > > GetRandomnessSharingSeedFuture()
encrypto::motion::communication::TcpPartiesConfiguration
std::vector< TcpConnectionConfiguration > TcpPartiesConfiguration
Definition: tcp_transport.h:62
hello_message.h
logger.h
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::BaseProvider::GetTheirRandomnessGenerator
primitives::SharingRandomnessGenerator & GetTheirRandomnessGenerator(std::size_t party_id)
Definition: motion_base_provider.h:60
geninput.help
help
Definition: geninput.py:150
encrypto::motion::kVersion
constexpr float kVersion
Definition: config.h:38
encrypto::motion::communication::BuildHelloMessage
flatbuffers::FlatBufferBuilder BuildHelloMessage(uint16_t source_id, uint16_t destination_id, uint16_t number_of_parties, const std::vector< uint8_t > *input_sharing_seed, const std::vector< uint8_t > *fixed_key_aes_seed, bool online_after_setup, float motion_version)
Definition: hello_message.cpp:33
encrypto::motion::communication::CommunicationLayer::SendMessage
void SendMessage(std::size_t party_id, std::vector< std::uint8_t > &&message)
Definition: communication_layer.cpp:331
encrypto::motion::communication::MessageHandler
Definition: message_handler.h:38
sharing_randomness_generator.h
encrypto::motion::communication::CommunicationLayer
Definition: communication_layer.h:58
EvaluateProtocol
encrypto::motion::RunTimeStatistics EvaluateProtocol(encrypto::motion::PartyPointer &party, std::size_t number_of_simd, encrypto::motion::MpcProtocol protocol, bool check)
Definition: aes128.cpp:56
message_handler.h
encrypto::motion::communication::MessageType::kOutputMessage
@ kOutputMessage
hello_message_generated.h
encrypto::motion::BaseProvider::BaseProvider
BaseProvider(communication::CommunicationLayer &, std::shared_ptr< Logger > logger)
Definition: motion_base_provider.cpp:81
encrypto::motion::BaseProvider::GetAesFixedKey
const std::vector< std::uint8_t > & GetAesFixedKey() const
Definition: motion_base_provider.h:56
encrypto::motion::BaseProvider
Definition: motion_base_provider.h:48
output_message_handler.h
encrypto::motion::BaseProvider::RegisterForOutputMessages
std::vector< ReusableFiberFuture< std::vector< std::uint8_t > > > RegisterForOutputMessages(std::size_t gate_id)
Definition: motion_base_provider.cpp:185
encrypto::motion::communication
Definition: backend.h:37
encrypto::motion::BaseProvider::~BaseProvider
~BaseProvider()
Definition: motion_base_provider.cpp:108
tcp_transport.h
encrypto::motion::BaseProvider::WaitForSetup
void WaitForSetup() const
Definition: motion_base_provider.cpp:183
encrypto::motion::kDebug
constexpr bool kDebug
Definition: config.h:36
kPartyArgumentRegex
const std::regex kPartyArgumentRegex("(\\d+),(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}),(\\d{1,5})")
message_generated.h
encrypto::motion::communication::CommunicationLayer::DeregisterMessageHandler
void DeregisterMessageHandler(const std::vector< MessageType > &message_types)
Definition: communication_layer.cpp:414
encrypto::motion::communication::TcpSetupHelper::SetupConnections
std::vector< std::unique_ptr< Transport > > SetupConnections()
Definition: tcp_transport.cpp:203