Ship the TLS mesh, composer, Beaver/Yao/leaf MPC, prep/online paths, apps, and docs so the tree is pushable before elevating share_expr, security_mode, and prep resume. Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
/// @file dpf/protocol_roles.hpp
|
|
/// @brief Thin helpers for dealer, preprocess, and online roles.
|
|
/// @details Three modes:
|
|
/// - **Dealer** — sample prep and write per-party views (files or streams).
|
|
/// - **Preprocess** — exchange dealer output over the network (e.g. mux TCP).
|
|
/// - **Online** — parties read prep and run interactive rounds on peer streams.
|
|
#ifndef LIBDPF_INCLUDE_DPF_PROTOCOL_ROLES_HPP__
|
|
#define LIBDPF_INCLUDE_DPF_PROTOCOL_ROLES_HPP__
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "hedley/hedley.h"
|
|
|
|
#include "dpf/net/channel.hpp"
|
|
#include "dpf/net/stream_array.hpp"
|
|
#include "dpf/prep_source.hpp"
|
|
|
|
namespace dpf
|
|
{
|
|
namespace roles
|
|
{
|
|
|
|
/// @brief Dealer mode: write `basename-p0`, `basename-p1` prep blobs.
|
|
inline void dealer_write_files(const std::string & basename,
|
|
const prep::demand & d)
|
|
{
|
|
auto views = prep::deal_views(d);
|
|
prep::write_file(basename + "-p0", views.first);
|
|
prep::write_file(basename + "-p1", views.second);
|
|
}
|
|
|
|
/// @brief Preprocess mode: party 0 deals into mux streams; party 1 receives.
|
|
/// @details Party 0 writes its view locally and ships party 1's view on stream 0.
|
|
inline std::vector<std::uint8_t> preprocess_from_dealer_mux(net::channel & ch,
|
|
unsigned party, const prep::demand & d, net::stream_array & local_out)
|
|
{
|
|
if (local_out.size() < 1)
|
|
throw std::invalid_argument("preprocess_from_dealer_mux: need stream 0");
|
|
if (party == 0)
|
|
{
|
|
auto views = prep::deal_views(d);
|
|
local_out.write(0, views.first.data(), views.first.size());
|
|
local_out.flush(0);
|
|
ch.send_vec(views.second, net::msg::beaver_tape);
|
|
return std::move(views.first);
|
|
}
|
|
auto got = ch.recv_vec<std::uint8_t>(net::msg::beaver_tape);
|
|
local_out.write(0, got.data(), got.size());
|
|
local_out.flush(0);
|
|
return got;
|
|
}
|
|
|
|
/// @brief Online mode: open prep cursors from dealer files (`basename-p0/p1`).
|
|
HEDLEY_WARN_UNUSED_RESULT
|
|
inline std::pair<prep::cursor, prep::cursor> online_open_file_array(
|
|
const std::string & basename)
|
|
{
|
|
return {prep::cursor(prep::read_file(basename + "-p0")),
|
|
prep::cursor(prep::read_file(basename + "-p1"))};
|
|
}
|
|
|
|
} // namespace roles
|
|
} // namespace dpf
|
|
|
|
#endif
|