libdpf/examples/applications/floram.cpp
Ryan Henry 0d22946a0e Checkpoint the party/runtime stack before share-program and malicious-mode work.
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>
2026-09-28 05:59:19 -06:00

61 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <cstdint>
#include <iostream>
#include <vector>
#include "dpf.hpp"
#include "dpf/app_flow.hpp"
#include "dpf/app_plans.hpp"
// Floram, the FSS read and write (Doerner and shelat, CCS 2017). Both
// parties see the memory. The address is secret-shared, so keygen is
// Doerner–Shelat rather than a dealer who knows the index. The read is
// the inner product of a unit key with that memory. The write adds a
// payload key, built from the same address shares, into subtractive
// copies of the array.
//
// c++ -std=c++17 -march=native -I include -I thirdparty \
// examples/applications/floram.cpp
int main()
{
constexpr std::size_t n = 256;
constexpr std::uint8_t address = 42;
constexpr std::uint8_t a0 = 0x15;
constexpr std::uint8_t a1 = static_cast<std::uint8_t>(address ^ a0);
constexpr std::uint64_t message = 9;
std::vector<std::uint64_t> memory(n);
memory[address] = 100;
memory[7] = 3;
auto [r0, r1] = dpf::make_dpf_doerner_shelat(a0, a1, std::uint64_t{1});
const auto word = dpf::reconstruct(
dpf::eval_full_inner_product(dpf::paired, r0, memory),
dpf::eval_full_inner_product(dpf::paired, r1, memory));
if (word != memory[address])
{
std::cerr << "floram read\n";
return 1;
}
auto [w0, w1] = dpf::make_dpf_doerner_shelat(a0, a1, message);
std::vector<std::uint64_t> s0 = memory;
std::vector<std::uint64_t> s1(n);
dpf::eval_full_add_into(s0, w0);
dpf::eval_full_add_into(s1, w1);
if (s0[address] - s1[address] != memory[address] + message
|| s0[7] - s1[7] != memory[7])
{
std::cerr << "floram write\n";
return 1;
}
{
if (int rc = dpf::app::run_measured("floram",
dpf::protocol::floram_ds_plan(0), 40))
return rc;
}
std::cout << word << "\n";
return 0;
}