Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,14 @@ on:
- main

jobs:
compile-libwrapper:
runs-on: ubuntu-latest
container: docker.io/hdvanegasm/ajax:latest
steps:
- uses: actions/checkout@v4

- name: compile libwrapper
run: |
cd thfhe/triples
sh build.sh

- name: upload compiled libwrapper
uses: actions/upload-artifact@v5
with:
name: libwrapper
path: thfhe/triples/build/libwrapper.so

check:
name: cargo check
runs-on: ubuntu-latest
needs: compile-libwrapper
container:
image: docker.io/hdvanegasm/ajax:latest
steps:
- uses: actions/checkout@v4

- name: download compiled libwrapper
uses: actions/download-artifact@v5
with:
name: libwrapper
path: thfhe/triples/build

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
Expand Down Expand Up @@ -75,18 +51,11 @@ jobs:
test-stable:
name: cargo test
runs-on: ubuntu-latest
needs: compile-libwrapper
container:
image: docker.io/hdvanegasm/ajax:latest
steps:
- uses: actions/checkout@v4

- name: download compiled libwrapper
uses: actions/download-artifact@v5
with:
name: libwrapper
path: thfhe/triples/build

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -98,6 +67,8 @@ jobs:
doc:
name: cargo doc
runs-on: ubuntu-latest
container:
image: docker.io/hdvanegasm/ajax:latest
steps:
- uses: actions/checkout@v4

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]

members = ["mpc", "network", "emp-bindings"]
members = ["mpc", "network", "emp-bindings", "thfhe"]

resolver = "2"

[workspace.dependencies]
thiserror = "2"
rand = "0.8"
bytemuck = "1.23.1"
libp2p = { version = "0.56.0", features = ["tokio", "quic", "gossipsub", "macros", "tcp", "dns", "noise", "yamux", "ping"] }
libp2p = { version = "0.56.0", features = ["tokio", "quic", "gossipsub", "macros", "tcp", "dns", "noise", "yamux", "ping", "rsa"] }
libp2p-stream = "0.4.0-alpha"
tokio = { version = "1", features = ["full"] }
tracing = "0.1.43"
Expand Down
3 changes: 3 additions & 0 deletions emp-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ rand = { workspace = true }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }

[build-dependencies]
cmake = "0.1"

[features]
verify = []
37 changes: 29 additions & 8 deletions emp-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@ use std::env;
use std::path::PathBuf;

fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let lib_path = PathBuf::from(manifest_dir)
.parent()
.unwrap()
.join("thfhe/triples/build");
let dst_triples = cmake::Config::new("triples")
.define("CMAKE_BUILD_TYPE", "Release")
.build();

// Include the local library in the wrapper
println!("cargo:rustc-link-search=native={}", lib_path.display());
println!("cargo:rustc-link-search=native=/usr/local/lib");
println!(
"cargo:rustc-link-search=native={}",
dst_triples.join("lib").display()
);
println!(
"cargo:rustc-link-search=native={}",
dst_triples.join("lib64").display()
);

// Link the wrapper library.
println!("cargo:rustc-link-lib=dylib=wrapper");

// Include dependencies.

println!("cargo:rustc-link-search=native={}", "/usr/local/lib");
println!("cargo:rustc-link-lib=wrapper");
println!("cargo:rustc-link-lib=emp-tool");
println!("cargo:rustc-link-lib=mpc");
println!("cargo:rustc-link-lib=ssl");
println!("cargo:rustc-link-lib=gmp");
println!("cargo:rustc-link-lib=crypto");

println!("cargo:rustc-link-arg=-Wl,-rpath={}", lib_path.display());
println!(
"cargo:rustc-link-arg=-Wl,-rpath={}",
dst_triples.join("lib").display()
);

// Re-run the build if some C/C++ code changes
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=triples/CMakeLists.txt");
println!("cargo:rerun-if-changed=triples/src");
println!("cargo:rerun-if-changed=triples/include");
println!("cargo:rerun-if-changed=triples/internal");
}
4 changes: 2 additions & 2 deletions emp-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use std::time::Instant;
#[allow(unused_imports)]
use tracing_subscriber::{fmt, EnvFilter};

pub mod bench;
pub mod constants;
pub mod countio;
pub mod utils;
pub mod bench;

#[repr(C)]
pub(crate) struct OleF2kWrapper {
Expand Down Expand Up @@ -236,7 +236,7 @@ pub fn generate_triples(
num_triples: usize,
) -> Result<Vec<(u64, u64, u64)>, Box<dyn std::error::Error>> {
assert!(party < total_party);
assert!(ip_list.len() == total_party);
assert_eq!(ip_list.len(), total_party);

// Initialize CountNetIO channels
let start_io = Instant::now();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ find_path(CMAKE_FOLDER NAMES cmake/emp-tool-config.cmake)
include(${CMAKE_FOLDER}/cmake/emp-base.cmake)

find_package(emp-ot REQUIRED)
find_package(emp-tool REQUIRED)
include_directories(${EMP-OT_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

Expand Down Expand Up @@ -45,17 +46,14 @@ target_link_libraries(wrapper
OpenSSL::Crypto
)

# ===== RPATH fix: ensure binaries find libwrapper.so relative to themselves =====
# $ORIGIN means "directory where the binary is located"
set_target_properties(wrapper PROPERTIES
INSTALL_RPATH "$ORIGIN"
BUILD_WITH_INSTALL_RPATH ON
)

# ===== Installation rules =====
install(FILES cmake/otls-config.cmake DESTINATION cmake/)
include(GNUInstallDirs)
install(DIRECTORY src DESTINATION include)
install(TARGETS wrapper LIBRARY DESTINATION lib)
install(TARGETS wrapper
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# ===== Enable and add tests =====
enable_testing()
Expand Down
5 changes: 3 additions & 2 deletions thfhe/triples/build.sh → emp-bindings/triples/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# This is for building the triples module of thfhe.

rm -rf build
mkdir build && cd build
mkdir build && cd build || exit
cmake ..
make
cp bin/test_triples ../test_triples
export LD_LIBRARY_PATH=$(pwd)/build:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=$(pwd)/build:$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
Original file line number Diff line number Diff line change
@@ -1,64 +1,54 @@
#ifndef PRIMUS_OLE_F2K_H
#define PRIMUS_OLE_F2K_H
#include "emp-ot/emp-ot.h"
#include <iostream>

/* Define OLE for the power-of-2 field with Block */
template <typename IO>
class OLEF2K
{
template<typename IO>
class OLEF2K {
public:
IO *io;
COT<IO> *ot;
GaloisFieldPacking pack;
OLEF2K(IO *io, COT<IO> *ot) : io(io), ot(ot) {}

OLEF2K(IO *io, COT<IO> *ot) : io(io), ot(ot) {
}

/* Compute the inner product of two block vectors*/
void inner_prod(block *res, const block *a, const block *b, int sz)
{
void inner_prod(block *res, const block *a, const block *b, int sz) {
block r = zero_block;
block r1;
for (int i = 0; i < sz; i++)
{
for (int i = 0; i < sz; i++) {
gfmul_reflect(a[i], b[i], &r1);
r = r ^ r1;
}
*res = r;
}

/* Compute the OLE protocol with inputs in, and put the output to out */
void compute(block *out, const block *in, int length)
{
void compute(block *out, const block *in, int length) {
block *raw0 = new block[length * 128];
if (!cmpBlock(&ot->Delta, &zero_block, 1))
{
if (!cmpBlock(&ot->Delta, &zero_block, 1)) {
block *raw1 = new block[length * 128];
ot->send_rot(raw0, raw1, length * 128);
for (int i = 0; i < length; ++i)
{
for (int j = 0; j < 128; ++j)
{
for (int i = 0; i < length; ++i) {
for (int j = 0; j < 128; ++j) {
block msg = raw0[i * 128 + j] ^ raw1[i * 128 + j] ^ in[i];
io->send_block(&msg, 1);
}
inner_prod(out + i, raw0 + i * 128, pack.base, 128);
}
delete[] raw1;
}
else
{
} else {
bool *bits = new bool[length * 128];
for (int i = 0; i < length; ++i)
block_to_bool(bits + i * 128, in[i]);

ot->recv_rot(raw0, bits, length * 128);

for (int i = 0; i < length; ++i)
{
for (int i = 0; i < length; ++i) {
block tmp[128];
io->recv_block(tmp, 128);
for (int j = 0; j < 128; ++j)
{
for (int j = 0; j < 128; ++j) {
if (bits[i * 128 + j])
raw0[i * 128 + j] ^= tmp[j];
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def get_local_ip():


def read_ip_list(path):

with open(path, "r") as f:
return [line.strip() for line in f if line.strip()]

Expand All @@ -27,7 +26,7 @@ def main():

parties_num = sys.argv[1]
base_port = sys.argv[2]
ip_file = Path("../batch/iplist/ip.txt")
ip_file = Path("../../thfhe/batch/iplist/ip.txt")

if not ip_file.exists():
print(f"erro: {ip_file} not exist")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions mpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ libp2p.workspace = true
futures.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
log = "0.4.28"

[dev-dependencies]
thfhe = { path = "../thfhe" }

[features]
default = ["concrete-ntt"]
Expand Down
Loading
Loading