MOTION
0.01
Framework for mixed-protocol multi-party computation
|
Go to the documentation of this file.
29 #include <type_traits>
37 class CommunicationLayer;
45 struct RunTimeStatistics;
46 struct SharedBitsData;
56 if constexpr (std::is_same_v<T, std::uint8_t>) {
58 }
else if constexpr (std::is_same_v<T, std::uint16_t>) {
60 }
else if constexpr (std::is_same_v<T, std::uint32_t>) {
62 }
else if constexpr (std::is_same_v<T, std::uint64_t>) {
65 throw std::runtime_error(
"Unknown type");
69 template <
typename T,
typename = std::enable_if_t<std::is_
unsigned_v<T>>>
70 std::size_t
RequestSbs(
const std::size_t number_of_sbs) noexcept {
72 if constexpr (std::is_same_v<T, std::uint8_t>) {
75 }
else if constexpr (std::is_same_v<T, std::uint16_t>) {
78 }
else if constexpr (std::is_same_v<T, std::uint32_t>) {
81 }
else if constexpr (std::is_same_v<T, std::uint64_t>) {
85 throw std::runtime_error(
"Unknown type");
90 template <
typename T,
typename = std::enable_if_t<std::is_
unsigned_v<T>>>
91 std::vector<T>
GetSbs(
const std::size_t offset,
const std::size_t n = 1) {
93 if constexpr (std::is_same_v<T, std::uint8_t>) {
95 }
else if constexpr (std::is_same_v<T, std::uint16_t>) {
97 }
else if constexpr (std::is_same_v<T, std::uint32_t>) {
99 }
else if constexpr (std::is_same_v<T, std::uint64_t>) {
102 throw std::runtime_error(
"Unknown type");
106 template <
typename T,
typename = std::enable_if_t<std::is_
unsigned_v<T>>>
109 if constexpr (std::is_same_v<T, std::uint8_t>) {
111 }
else if constexpr (std::is_same_v<T, std::uint16_t>) {
113 }
else if constexpr (std::is_same_v<T, std::uint32_t>) {
115 }
else if constexpr (std::is_same_v<T, std::uint64_t>) {
118 throw std::runtime_error(
"Unknown type");
123 virtual void Setup() = 0;
145 template <
typename T,
typename = std::enable_if_t<std::is_
unsigned_v<T>>>
146 inline std::vector<T>
GetSbs(
const std::vector<T>& sbs,
const std::size_t offset,
147 const std::size_t n)
const {
148 assert(offset + n <= sbs.size());
149 return std::vector(sbs.cbegin() + offset, sbs.cbegin() + offset + n);
156 std::shared_ptr<SpProvider> sp_provider,
Logger& logger,
163 void Setup()
final override;
167 void RegisterForMessages();
168 void ComputeSbs() noexcept;
179 std::size_t number_of_parties_;
180 std::shared_ptr<SpProvider> sp_provider_;
181 std::vector<std::unique_ptr<SharedBitsData>> data_;
183 std::size_t offset_sps_16_;
184 std::size_t offset_sps_32_;
185 std::size_t offset_sps_64_;
186 std::size_t offset_sps_128_;
188 std::vector<ReusableFuture<std::vector<uint8_t>>> mask_message_futures_;
189 std::vector<ReusableFuture<std::vector<uint8_t>>> reconstruct_message_futures_;
191 const std::size_t kMaxBatchSize{10
'000};
194 RunTimeStatistics& run_time_statistics_;
197 } // namespace encrypto::motion
void Setup() final override
Definition: sb_provider.cpp:138
void RecordEnd()
Definition: run_time_statistics.h:62
SbProviderFromSps(communication::CommunicationLayer &communication_layer, std::shared_ptr< SpProvider > sp_provider, Logger &logger, RunTimeStatistics &run_time_statistics)
Definition: sb_provider.cpp:86
Definition: shared_bits_data.h:35
@ kReconstructMessage
Definition: shared_bits_data.h:33
std::size_t number_of_sbs_64_
Definition: sb_provider.h:132
Definition: reusable_future.h:129
std::vector< T > GetSbs(const std::size_t offset, const std::size_t n=1)
Definition: sb_provider.h:91
const encrypto::motion::communication::Message * GetMessage(const void *buf)
Definition: message_generated.h:146
Definition: sb_provider.h:50
bool NeedSbs() const noexcept
Definition: sb_provider.cpp:43
const std::size_t my_id_
Definition: sb_provider.h:139
const std::vector< T > & GetSbsAll() noexcept
Definition: sb_provider.h:107
~SbProviderFromSps()
Definition: sb_provider.cpp:112
std::size_t number_of_sbs_16_
Definition: sb_provider.h:132
std::size_t number_of_sbs_32_
Definition: sb_provider.h:132
static std::vector< std::uint8_t > Gather(const std::vector< std::uint16_t > &ds_8, const std::vector< std::uint32_t > &ds_16, const std::vector< std::uint64_t > &ds_32, const std::vector< __uint128_t > &ds_64)
Definition: sb_provider.cpp:196
static std::vector< std::uint8_t > Scatter(std::vector< std::uint16_t > &ds_8, std::vector< std::uint32_t > &ds_16, std::vector< std::uint64_t > &ds_32, std::vector< __uint128_t > &ds_64, const std::vector< std::uint8_t > &buffer)
Definition: sb_provider.cpp:217
void LogDebug(const std::string &message)
Definition: logger.cpp:142
std::vector< std::uint64_t > sbs_64_
Definition: sb_provider.h:137
void RegisterMessageHandler(MessageHandlerFunction, const std::vector< MessageType > &message_types)
Definition: communication_layer.cpp:393
std::size_t number_of_sbs_8_
Definition: sb_provider.h:132
std::size_t GetNumberOfParties() const
Definition: communication_layer.h:65
std::vector< std::uint8_t > sbs_8_
Definition: sb_provider.h:134
bool finished_
Definition: sb_provider.h:141
Definition: sb_provider.cpp:51
std::size_t RequestSbs(const std::size_t number_of_sbs) noexcept
Definition: sb_provider.h:70
Definition: algorithm_description.cpp:35
std::vector< std::uint16_t > sbs_16_
Definition: sb_provider.h:135
void BroadcastMessage(std::vector< std::uint8_t > &&message)
Definition: communication_layer.cpp:353
Definition: sb_provider.h:153
std::size_t GetMyId() const
Definition: communication_layer.h:66
std::size_t GetNumberOfSbs() const noexcept
Definition: sb_provider.h:55
Definition: run_time_statistics.h:32
Definition: message_handler.h:38
Definition: communication_layer.h:58
void MessageReceived(const SharedBitsMessageType type, const std::uint8_t *message, const std::size_t size)
Definition: shared_bits_data.cpp:44
static void ReconstructionHelper(std::vector< std::uint16_t > &xs_8, std::vector< std::uint32_t > &xs_16, std::vector< std::uint64_t > &xs_32, std::vector< __uint128_t > &xs_64, std::size_t number_of_parties, std::function< void(const std::vector< uint8_t > &)> broadcast_function, std::vector< ReusableFuture< std::vector< std::uint8_t >>> &futures)
Definition: sb_provider.cpp:240
static constexpr auto GetByteSize(const std::vector< T > &v)
Definition: sb_provider.cpp:191
flatbuffers::FlatBufferBuilder BuildSharedBitsReconstructMessage(const std::vector< std::uint8_t > &buffer)
Definition: shared_bits_message.cpp:38
virtual void PreSetup()=0
std::vector< std::uint32_t > sbs_32_
Definition: sb_provider.h:136
void WaitFinished()
Definition: sb_provider.h:126
SbMessageHandler(SharedBitsData &data)
Definition: sb_provider.cpp:53
std::shared_ptr< FiberCondition > finished_condition_
Definition: sb_provider.h:142
const encrypto::motion::communication::SharedBitsMessage * GetSharedBitsMessage(const void *buf)
Definition: shared_bits_message_generated.h:68
void ReceivedMessage(std::size_t, std::vector< std::uint8_t > &&message)
Definition: sb_provider.cpp:62
flatbuffers::FlatBufferBuilder BuildSharedBitsMaskMessage(const std::vector< std::uint8_t > &buffer)
Definition: shared_bits_message.cpp:31
constexpr bool kDebug
Definition: config.h:36
void PreSetup() final override
Definition: sb_provider.cpp:119
void RecordStart()
Definition: run_time_statistics.h:56
void DeregisterMessageHandler(const std::vector< MessageType > &message_types)
Definition: communication_layer.cpp:414
@ kMaskMessage
Definition: shared_bits_data.h:33