27 #include <fmt/format.h>
43 class CommunicationLayer;
58 Party(std::unique_ptr<communication::CommunicationLayer> parties);
66 template <MpcProtocol P>
68 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
78 return backend_->BooleanGmwInput(party_id, input);
81 return backend_->BmrInput(party_id, input);
84 throw(std::runtime_error(
85 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
90 template <MpcProtocol P>
92 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
102 return backend_->BooleanGmwInput(party_id, std::move(input));
105 return backend_->BmrInput(party_id, input);
108 throw(std::runtime_error(
109 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
114 template <MpcProtocol P>
116 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
126 return backend_->BooleanGmwInput(party_id, input);
129 return backend_->BmrInput(party_id, input);
132 throw(std::runtime_error(
133 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
138 template <MpcProtocol P>
140 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
150 return backend_->BooleanGmwInput(party_id, std::move(input));
153 return backend_->BmrInput(party_id, input);
156 throw(std::runtime_error(
157 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
162 template <
MpcProtocol P,
typename T = std::uint8_t,
163 typename = std::enable_if_t<std::is_unsigned_v<T>>>
165 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
168 return backend_->ConstantArithmeticGmwInput(input);
171 return backend_->ArithmeticGmwInput(party_id, input);
174 throw std::runtime_error(
175 "Non-binary types have to be converted to BitVectors in BooleanGMW, "
176 "consider using TODO function for the input");
179 throw std::runtime_error(
180 "Non-binary types have to be converted to BitVectors in BMR, "
181 "consider using TODO function for the input");
184 throw(std::runtime_error(
185 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
190 template <
MpcProtocol P,
typename T = std::uint8_t,
191 typename = std::enable_if_t<std::is_unsigned_v<T>>>
193 std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
196 return backend_->ConstantArithmeticGmwInput(std::move(input));
199 return backend_->ArithmeticGmwInput(party_id, std::move(input));
202 throw(std::runtime_error(
203 fmt::format(
"Non-binary types have to be converted to BitVectors in BooleanGMW, "
204 "consider using TODO function for the input")));
207 throw(std::runtime_error(
208 fmt::format(
"Non-binary types have to be converted to BitVectors in BMR, "
209 "consider using TODO function for the input")));
212 throw(std::runtime_error(
213 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
218 template <
MpcProtocol P,
typename T = std::uint8_t,
219 typename = std::enable_if_t<std::is_unsigned_v<T>>>
220 SharePointer In(T input, std::size_t party_id = std::numeric_limits<std::size_t>::max()) {
221 if constexpr (std::is_same_v<T, bool>) {
223 return backend_->BooleanGmwInput(party_id, input);
225 return backend_->BmrInput(party_id, input);
227 return In<P, T>(std::vector<T>{input}, party_id);
231 template <
MpcProtocol P,
typename T = std::uint8_t,
232 typename = std::enable_if_t<std::is_unsigned_v<T>>>
242 std::make_shared<encrypto::motion::proto::arithmetic_gmw::Wire<T>>(input, *backend_);
243 register_pointer->RegisterNextWire(wire);
244 wire->SetOnlineFinished();
246 return std::make_shared<encrypto::motion::proto::arithmetic_gmw::Share<T>>(wire);
249 throw std::runtime_error(
250 "Non-binary types have to be converted to BitVectors in BooleanGMW, "
251 "consider using TODO function for the input");
254 throw std::runtime_error(
255 "Non-binary types have to be converted to BitVectors in BMR, "
256 "consider using TODO function for the input");
259 throw(std::runtime_error(
260 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
265 template <
MpcProtocol P,
typename T = std::uint8_t,
266 typename = std::enable_if_t<std::is_unsigned_v<T>>>
276 std::make_shared<encrypto::motion::proto::arithmetic_gmw::Wire<T>>(input, *backend_);
277 register_pointer->RegisterNextWire(wire);
278 wire->SetOnlineFinished();
280 return std::make_shared<encrypto::motion::proto::arithmetic_gmw::Share<T>>(wire);
283 throw std::runtime_error(
284 "Non-binary types have to be converted to BitVectors in BooleanGMW, "
285 "consider using TODO function for the input");
288 throw std::runtime_error(
289 "Non-binary types have to be converted to BitVectors in BMR, "
290 "consider using TODO function for the input");
293 throw(std::runtime_error(
294 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
299 template <MpcProtocol P>
309 std::vector<encrypto::motion::WirePointer> wires(input.size());
312 for (std::size_t i = 0; i < wires.size(); i++) {
314 std::make_shared<encrypto::motion::proto::boolean_gmw::Wire>(input[i], *backend_);
315 register_pointer->RegisterNextWire(wires[i]);
316 wires[i]->SetOnlineFinished();
319 return std::make_shared<encrypto::motion::proto::boolean_gmw::Share>(wires);
325 throw(std::runtime_error(
326 fmt::format(
"Unknown MPC protocol with id {}",
static_cast<unsigned int>(P))));
343 void Run(std::size_t repetitions = 1);
369 std::unique_ptr<communication::CommunicationLayer> communication_layer_;
371 std::shared_ptr<Logger> logger_;
373 std::atomic<bool> finished_ =
false;
374 std::atomic<bool> connected_ =
false;
376 void EvaluateCircuit();
385 const bool logging =
false);