diff --git a/mp-spdz-rs/README.md b/mp-spdz-rs/README.md index 2ef620f..5091ffc 100644 --- a/mp-spdz-rs/README.md +++ b/mp-spdz-rs/README.md @@ -2,8 +2,8 @@ 1. Run `git submodule update --init --recursive` to clone the submodules in this repo. 2. Install `libsodium` & `gmp` via: ```zsh -brew install libsodium gmp -yum install libsodium gmp -apt-get install libsodium gmp +brew install libsodium gmp boost ntl +yum install libsodium gmp boost ntl +apt-get install libsodium gmp boost ntl ``` based on your local package manager. \ No newline at end of file diff --git a/mp-spdz-rs/build.rs b/mp-spdz-rs/build.rs index 7e0284b..504eb25 100644 --- a/mp-spdz-rs/build.rs +++ b/mp-spdz-rs/build.rs @@ -3,19 +3,31 @@ use itertools::Itertools; // Build entrypoint fn main() { // Resolve the libsodium and gmp include paths - let libsodium_include = find_package("libsodium"); - let gmp_include = find_package("gmp"); + let libsodium_include = find_include_path("libsodium"); + let gmp_include = find_include_path("gmp"); + let ntl_include = find_include_path("ntl"); // Build the c++ bridge cxx_build::bridge("src/lib.rs") - .file("src/include/MP-SPDZ/FHE/Ring_Element.cpp") + .file("src/include/MP-SPDZ/FHE/Ring.cpp") + .file("src/include/MP-SPDZ/FHE/NTL-Subs.cpp") + .file("src/include/MP-SPDZ/Math/bigint.cpp") .include("src/include/MP-SPDZ") .include("src/include/MP-SPDZ/deps") .include(libsodium_include) .include(gmp_include) + .include(ntl_include) + .define("USE_NTL", None) .std("c++17") .compile("mp-spdz-cxx"); + // Linker args + println!("cargo:rustc-link-arg=-L{}", find_lib_path("ntl")); + println!("cargo:rustc-link-arg=-lntl"); + println!("cargo:rustc-link-arg=-L{}", find_lib_path("gmp")); + println!("cargo:rustc-link-arg=-lgmp"); + + // Build cache flags println!("cargo:rerun-if-changed=src/lib.rs"); println!("cargo:rerun-if-changed=../MP-SPDZ"); } @@ -32,6 +44,18 @@ fn get_host_triple() -> Vec { host_triple.split('-').map(|s| s.to_string()).collect_vec() } +/// Find the include location for a package +fn find_include_path(name: &str) -> String { + let base_path = find_package(name); + format!("{base_path}/include") +} + +/// Find the lib location for a package +fn find_lib_path(name: &str) -> String { + let base_path = find_package(name); + format!("{base_path}/lib") +} + /// Resolve a package's include location /// /// Windows is not supported @@ -65,7 +89,7 @@ fn find_package_macos(name: &str) -> String { // Parse the output from stdout let path = parse_utf8(&output.stdout).trim().to_string(); - format!("{path}/include") + path } /// Find a package on Linux diff --git a/mp-spdz-rs/src/lib.rs b/mp-spdz-rs/src/lib.rs index ee2ed90..a9fd0fc 100644 --- a/mp-spdz-rs/src/lib.rs +++ b/mp-spdz-rs/src/lib.rs @@ -6,24 +6,20 @@ #[cxx::bridge] pub mod ffi { - struct Test { - a: i32, - b: i32, - } - unsafe extern "C++" { - include!("FHE/Ring_Element.h"); + include!("FHE/Ring.h"); - fn test_method(); + type Ring; + fn new_ring(m: i32) -> UniquePtr; } } #[cfg(test)] mod test { - use crate::ffi::test_method; + use super::ffi::*; #[test] fn test_dummy() { - test_method(); + let ring = new_ring(10); } }