From b1f9f25ad3e1f77297ba5501f38ad6e6a334f93f Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Thu, 7 Nov 2019 20:12:52 -0500 Subject: [PATCH 01/16] add incomplete docker setup for aby3 Currently, building the framework fails error message is in README. --- aby3/Dockerfile | 21 +++++++++++++++++++++ aby3/README.md | 7 +++++++ aby3/breaks.sh | 2 ++ aby3/install.sh | 17 +++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 aby3/Dockerfile create mode 100644 aby3/README.md create mode 100644 aby3/breaks.sh create mode 100644 aby3/install.sh diff --git a/aby3/Dockerfile b/aby3/Dockerfile new file mode 100644 index 0000000..50d4a4c --- /dev/null +++ b/aby3/Dockerfile @@ -0,0 +1,21 @@ +FROM ubuntu:18.04 +WORKDIR /root +RUN apt-get update && apt-get install -y \ + bzip2 \ + clang \ + g++ \ + git \ + cmake \ + make \ + vim \ + wget +#ADD source/ /root/source +#ADD README.md . + +ADD install.sh . +RUN ["bash", "install.sh"] +# this breaks +ADD breaks.sh . +RUN ["bash", "breaks.sh"] +CMD ["/bin/bash"] + diff --git a/aby3/README.md b/aby3/README.md new file mode 100644 index 0000000..6a05b6e --- /dev/null +++ b/aby3/README.md @@ -0,0 +1,7 @@ +ABY^3 was developed by Peter Rindal. + +Currently fails to build with error +``` +error: no matching function for call to 'osuCrypto::Channel::asyncSend(unsigned char*&, long unsigned int&, osuCrypto::OblvPermutation::send(osuCrypto::Channel&, osuCrypto::Channel&, osuCrypto::Matrix, std::__cxx11::string)::)' + recvrChl.asyncSend(data, size, [a = std::move(src)](){}); +``` diff --git a/aby3/breaks.sh b/aby3/breaks.sh new file mode 100644 index 0000000..0cef004 --- /dev/null +++ b/aby3/breaks.sh @@ -0,0 +1,2 @@ +cd aby3 +make -j diff --git a/aby3/install.sh b/aby3/install.sh new file mode 100644 index 0000000..b38c538 --- /dev/null +++ b/aby3/install.sh @@ -0,0 +1,17 @@ +git clone --recursive https://github.com/osu-crypto/libOTe.git +cd libOTe/cryptoTools/thirdparty/linux +bash boost.get +bash miracl.get +cd ../../.. +cmake -DENABLE_CIRCUITS=ON -DENABLE_SIMPLESTOT=ON . +make -j +cd ../ +git clone https://github.com/marsella/aby3.git +cd aby3 +#git checkout -b MPCSOK e4e3f989327d2b937e3d21fbbe05a3ab56696e84 +cd thirdparty/linux +bash eigen.get +bash function2.get +cd ../.. +cmake . + From dea8a4dac75f2aa348aa2d741ea49ff0c64ce3e3 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Fri, 15 Nov 2019 14:53:39 -0500 Subject: [PATCH 02/16] comment out broken aby3 call --- aby3/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aby3/Dockerfile b/aby3/Dockerfile index 50d4a4c..5667b20 100644 --- a/aby3/Dockerfile +++ b/aby3/Dockerfile @@ -16,6 +16,6 @@ ADD install.sh . RUN ["bash", "install.sh"] # this breaks ADD breaks.sh . -RUN ["bash", "breaks.sh"] +#RUN ["bash", "breaks.sh"] CMD ["/bin/bash"] From 557f2c1453292f9d11e13984b98954f14655eea8 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Mon, 18 Nov 2019 19:48:57 -0500 Subject: [PATCH 03/16] update install for aby3 it's still broken, but now compatible with PR's changes --- aby3/Dockerfile | 3 ++- aby3/install.sh | 9 +-------- aby3/install_dependencies.sh | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 aby3/install_dependencies.sh diff --git a/aby3/Dockerfile b/aby3/Dockerfile index 5667b20..63f5fd1 100644 --- a/aby3/Dockerfile +++ b/aby3/Dockerfile @@ -5,13 +5,14 @@ RUN apt-get update && apt-get install -y \ clang \ g++ \ git \ - cmake \ make \ vim \ wget #ADD source/ /root/source #ADD README.md . +ADD install_dependencies.sh . +RUN ["bash", "install_dependencies.sh"] ADD install.sh . RUN ["bash", "install.sh"] # this breaks diff --git a/aby3/install.sh b/aby3/install.sh index b38c538..6939393 100644 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -1,11 +1,4 @@ -git clone --recursive https://github.com/osu-crypto/libOTe.git -cd libOTe/cryptoTools/thirdparty/linux -bash boost.get -bash miracl.get -cd ../../.. -cmake -DENABLE_CIRCUITS=ON -DENABLE_SIMPLESTOT=ON . -make -j -cd ../ +cd ~ git clone https://github.com/marsella/aby3.git cd aby3 #git checkout -b MPCSOK e4e3f989327d2b937e3d21fbbe05a3ab56696e84 diff --git a/aby3/install_dependencies.sh b/aby3/install_dependencies.sh new file mode 100644 index 0000000..f35d04b --- /dev/null +++ b/aby3/install_dependencies.sh @@ -0,0 +1,15 @@ +alias wget="wget -nv" +wget https://github.com/Kitware/CMake/releases/download/v3.16.0-rc4/cmake-3.16.0-rc4-Linux-x86_64.tar.gz +tar xzvf cmake-3.16.0-rc4-Linux-x86_64.tar.gz +cd cmake-3.16.0-rc4-Linux-x86_64 +mv bin/* /usr/bin/ +cp -r share/* /usr/share/ + +cd +git clone --recursive https://github.com/osu-crypto/libOTe.git +cd libOTe/cryptoTools/thirdparty/linux +bash boost.get +bash miracl.get +cd ../../.. +cmake -DENABLE_CIRCUITS=ON -DENABLE_SIMPLESTOT=ON . +make -j From 5112f816bdb897dabdc64cde9414189b810bd530 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Tue, 31 Mar 2020 19:03:04 -0400 Subject: [PATCH 04/16] fix build --- aby3/install.sh | 5 +++-- aby3/install_dependencies.sh | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aby3/install.sh b/aby3/install.sh index 6939393..109c519 100644 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -1,10 +1,11 @@ cd ~ -git clone https://github.com/marsella/aby3.git +git clone https://github.com/ladnir/aby3.git cd aby3 -#git checkout -b MPCSOK e4e3f989327d2b937e3d21fbbe05a3ab56696e84 +git checkout -b MPCSOK 4d17c6476135723a2ed3d596dbba1709d0c6b4ae cd thirdparty/linux bash eigen.get bash function2.get cd ../.. cmake . +make -j diff --git a/aby3/install_dependencies.sh b/aby3/install_dependencies.sh index f35d04b..64d8d92 100644 --- a/aby3/install_dependencies.sh +++ b/aby3/install_dependencies.sh @@ -9,7 +9,6 @@ cd git clone --recursive https://github.com/osu-crypto/libOTe.git cd libOTe/cryptoTools/thirdparty/linux bash boost.get -bash miracl.get cd ../../.. -cmake -DENABLE_CIRCUITS=ON -DENABLE_SIMPLESTOT=ON . +cmake -DENABLE_CIRCUITS=ON . make -j From af8f63152894b4c733b2923a13f490d8d1f32c7c Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Fri, 10 Apr 2020 11:36:19 -0400 Subject: [PATCH 05/16] add framework for writing aby3 tests --- aby3/Dockerfile | 6 ++--- aby3/breaks.sh | 2 -- aby3/install.sh | 10 +++++++- aby3/source/CMakeLists.txt | 14 ++++++++++++ aby3/source/innerprod.cpp | 5 ++++ aby3/source/innerprod.h | 2 ++ aby3/source/main.cpp | 47 ++++++++++++++++++++++++++++++++++++++ aby3/source/mult3.cpp | 5 ++++ aby3/source/mult3.h | 3 +++ aby3/source/xtabs.cpp | 4 ++++ aby3/source/xtabs.h | 3 +++ 11 files changed, 94 insertions(+), 7 deletions(-) delete mode 100644 aby3/breaks.sh create mode 100644 aby3/source/CMakeLists.txt create mode 100644 aby3/source/innerprod.cpp create mode 100644 aby3/source/innerprod.h create mode 100644 aby3/source/main.cpp create mode 100644 aby3/source/mult3.cpp create mode 100644 aby3/source/mult3.h create mode 100644 aby3/source/xtabs.cpp create mode 100644 aby3/source/xtabs.h diff --git a/aby3/Dockerfile b/aby3/Dockerfile index 63f5fd1..764b534 100644 --- a/aby3/Dockerfile +++ b/aby3/Dockerfile @@ -8,15 +8,13 @@ RUN apt-get update && apt-get install -y \ make \ vim \ wget -#ADD source/ /root/source + +ADD source/ /root/source #ADD README.md . ADD install_dependencies.sh . RUN ["bash", "install_dependencies.sh"] ADD install.sh . RUN ["bash", "install.sh"] -# this breaks -ADD breaks.sh . -#RUN ["bash", "breaks.sh"] CMD ["/bin/bash"] diff --git a/aby3/breaks.sh b/aby3/breaks.sh deleted file mode 100644 index 0cef004..0000000 --- a/aby3/breaks.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd aby3 -make -j diff --git a/aby3/install.sh b/aby3/install.sh index 109c519..63daf19 100644 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -1,3 +1,4 @@ +# download aby3 cd ~ git clone https://github.com/ladnir/aby3.git cd aby3 @@ -5,7 +6,14 @@ git checkout -b MPCSOK 4d17c6476135723a2ed3d596dbba1709d0c6b4ae cd thirdparty/linux bash eigen.get bash function2.get -cd ../.. + +# put our files in place +cd ~/aby3/ +mkdir samples +mv ~/source/* samples +printf "add_subdirectory(samples)\n" >> CMakeLists.txt + +# build entire library cmake . make -j diff --git a/aby3/source/CMakeLists.txt b/aby3/source/CMakeLists.txt new file mode 100644 index 0000000..58a7927 --- /dev/null +++ b/aby3/source/CMakeLists.txt @@ -0,0 +1,14 @@ + +#project(samples) + +############################################# +# Build samples.exe # +############################################# + +file(GLOB_RECURSE SRC_SAMPLES ${CMAKE_SOURCE_DIR}/samples/*.cpp) +include_directories(${CMAKE_SOURCE_DIR}/samples/) + +add_executable(samples.exe ${SRC_SAMPLES}) + +target_link_libraries(samples.exe aby3_Tests) + diff --git a/aby3/source/innerprod.cpp b/aby3/source/innerprod.cpp new file mode 100644 index 0000000..9b9b229 --- /dev/null +++ b/aby3/source/innerprod.cpp @@ -0,0 +1,5 @@ +#include + +void innerprod_test(){ + std::cout << "testing innerprod..." << std::endl; +} diff --git a/aby3/source/innerprod.h b/aby3/source/innerprod.h new file mode 100644 index 0000000..ca16e6a --- /dev/null +++ b/aby3/source/innerprod.h @@ -0,0 +1,2 @@ +#pragma once +void innerprod_test(); diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp new file mode 100644 index 0000000..1033fd6 --- /dev/null +++ b/aby3/source/main.cpp @@ -0,0 +1,47 @@ +#include "mult3.h" +#include "innerprod.h" +#include "xtabs.h" + +// testing and command line parsing +#include +#include +std::vector unitTestTag{ "u", "unitTest" }; + + +void help() +{ + std::cout << "-u ~~ to run all tests" << std::endl; + std::cout << "-u n1 [n2 ...] ~~ to run test n1, n2, ..." << std::endl; + std::cout << "-u -list ~~ to list all tests" << std::endl; +} + +int main(int argc, char** argv) +{ + try { + + oc::CLP cmd(argc, argv); + + // this assigns the appropriate test function to each command-line arg + // functions are defined in their respective .h files + if (cmd.isSet(unitTestTag)) + { + oc::TestCollection sample_tests([](oc::TestCollection& tc) { + tc.add("mult3 ", mult3_test); + tc.add("innerprod", innerprod_test); + tc.add("xtabs ", xtabs_test); + }); + + sample_tests.runIf(cmd); + return 0; + } + + help(); + + } + catch (std::exception& e) + { + std::cout << e.what() << std::endl; + } + + return 0; +} diff --git a/aby3/source/mult3.cpp b/aby3/source/mult3.cpp new file mode 100644 index 0000000..2f5e59c --- /dev/null +++ b/aby3/source/mult3.cpp @@ -0,0 +1,5 @@ +#include + +void mult3_test(){ + std::cout << "testing mult3..." << std::endl; +} diff --git a/aby3/source/mult3.h b/aby3/source/mult3.h new file mode 100644 index 0000000..2cd3408 --- /dev/null +++ b/aby3/source/mult3.h @@ -0,0 +1,3 @@ +#pragma once +void mult3_test(); + diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp new file mode 100644 index 0000000..3a4dbd4 --- /dev/null +++ b/aby3/source/xtabs.cpp @@ -0,0 +1,4 @@ +#include +void xtabs_test(){ + std::cout << "testing xtabs..." << std::endl; +} diff --git a/aby3/source/xtabs.h b/aby3/source/xtabs.h new file mode 100644 index 0000000..cfb0717 --- /dev/null +++ b/aby3/source/xtabs.h @@ -0,0 +1,3 @@ +#pragma once + +void xtabs_test(); From 8429ce556938906eb1c586bc0dc859261acca220 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Fri, 10 Apr 2020 17:42:38 -0400 Subject: [PATCH 06/16] add working aby3 mult3 program --- aby3/source/main.cpp | 35 ++++++++++---- aby3/source/mult3.cpp | 107 +++++++++++++++++++++++++++++++++++++++++- aby3/source/mult3.h | 3 +- 3 files changed, 134 insertions(+), 11 deletions(-) diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp index 1033fd6..00f3d04 100644 --- a/aby3/source/main.cpp +++ b/aby3/source/main.cpp @@ -6,6 +6,7 @@ #include #include std::vector unitTestTag{ "u", "unitTest" }; +std::vector playerTag{ "p", "player" }; void help() @@ -13,6 +14,8 @@ void help() std::cout << "-u ~~ to run all tests" << std::endl; std::cout << "-u n1 [n2 ...] ~~ to run test n1, n2, ..." << std::endl; std::cout << "-u -list ~~ to list all tests" << std::endl; + + std::cout << "-p party ~~ indicate which party you are" << std::endl; } int main(int argc, char** argv) @@ -21,17 +24,33 @@ int main(int argc, char** argv) oc::CLP cmd(argc, argv); - // this assigns the appropriate test function to each command-line arg - // functions are defined in their respective .h files + oc::u64 player; + if (cmd.isSet(playerTag)) { + player = cmd.getOr(playerTag, -1); + } else { + std::cout << "You need to specify which player you are" << std::endl; + return 0; + } + + // this calls the appropriate test function based on command-line arg + // functions are defined in their respective .h files if (cmd.isSet(unitTestTag)) { - oc::TestCollection sample_tests([](oc::TestCollection& tc) { - tc.add("mult3 ", mult3_test); - tc.add("innerprod", innerprod_test); - tc.add("xtabs ", xtabs_test); - }); + std::string none = ""; + if (cmd.getOr(unitTestTag, none).compare("mult3") == 0) { + // hardcodes input value + int value = 3 + player; + mult3_test(player, value); + } + if (cmd.getOr(unitTestTag, none).compare("innerprod") == 0) { + //innerprod_test(player); + innerprod_test(); + } + if (cmd.getOr(unitTestTag, none).compare("xtabs") == 0) { + //xtabs_test(player); + xtabs_test(); + } - sample_tests.runIf(cmd); return 0; } diff --git a/aby3/source/mult3.cpp b/aby3/source/mult3.cpp index 2f5e59c..db7451a 100644 --- a/aby3/source/mult3.cpp +++ b/aby3/source/mult3.cpp @@ -1,5 +1,108 @@ #include +#include -void mult3_test(){ - std::cout << "testing mult3..." << std::endl; +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" + +#include "mult3.h" + +using namespace oc; +using namespace aby3; +/* + * mult3 + * + * multiplies three numbers together + * lots of this code is ported from Peter Rindal's aby3Tutorial.cpp + * + */ + +// This function sets up the basic classes that we will +// use to perform some computation. This mostly consists +// of creating Channels (network sockets) to the other +// parties and then establishing some shared randomness. +void setup( + u64 partyIdx, + IOService& ios, + Sh3Encryptor& enc, + Sh3Evaluator& eval, + Sh3Runtime& runtime) +{ + // A CommPkg is a pair of Channels (network sockets) to the other parties. + // See cryptoTools\frontend_cryptoTools\Tutorials\Network.cpp + // for details. + // since we're running them all locally, they're sitting on 3 different ports. + CommPkg comm; + switch (partyIdx) + { + case 0: + comm.mNext = Session(ios, "127.0.0.1:1313", SessionMode::Server, "01").addChannel(); + comm.mPrev = Session(ios, "127.0.0.1:1314", SessionMode::Server, "02").addChannel(); + break; + case 1: + comm.mNext = Session(ios, "127.0.0.1:1315", SessionMode::Server, "12").addChannel(); + comm.mPrev = Session(ios, "127.0.0.1:1313", SessionMode::Client, "01").addChannel(); + break; + default: + comm.mNext = Session(ios, "127.0.0.1:1314", SessionMode::Client, "02").addChannel(); + comm.mPrev = Session(ios, "127.0.0.1:1315", SessionMode::Client, "12").addChannel(); + break; + } + + // in a real work example, where parties + // have different IPs, you have to give the + // Clients the IP of the server and you give + // the servers their own IP (to listen to). + + + // Establishes some shared randomness needed for the later protocols + enc.init(partyIdx, comm, sysRandomSeed()); + + // Establishes some shared randomness needed for the later protocols + eval.init(partyIdx, comm, sysRandomSeed()); + + // Copies the Channels and will use them for later protcols. + runtime.init(partyIdx, comm); +} +void mult3_test(u64 partyIdx, int value){ + if (partyIdx == 0) + std::cout << "testing mult3..." << std::endl; + + IOService ios; + + // Sh3Encryptor allows us to generate and reconstruct secret shared values. + Sh3Encryptor enc; + // Sh3Evaluator will allow us to perform some of the + // most common interactive protocols, e.g. multiplication. + Sh3Evaluator eval; + // Sh3Runtime does networking and helps schedule operations in parallel + Sh3Runtime runtime; + setup(partyIdx, ios, enc, eval, runtime); + + std::vector sharedVec(3); + + /* Convert clear values from each player to secure types. + * tutorial suggests doing this asynchronously by task &='ing each call + * instead of calling .get() immediately + * This didn't compile for me; the runtime destructor was getting called way too early. + */ + for (u64 i = 0; i < sharedVec.size(); ++i) { + if (i % 3 == partyIdx) + enc.localInt(runtime, value, sharedVec[i]).get(); + else + enc.remoteInt(runtime, sharedVec[i]).get(); + } + + /* multiply them together */ + si64 prod = sharedVec[0]; + Sh3Task task = runtime.noDependencies(); + for (u64 i = 1; i < sharedVec.size(); ++i) + task = eval.asyncMul(task, prod, sharedVec[i], prod); + + task.get(); + + /* reveal result */ + i64 result; + enc.revealAll(runtime, prod, result).get(); + std::cout << "product: " << result << std::endl; } diff --git a/aby3/source/mult3.h b/aby3/source/mult3.h index 2cd3408..c58576c 100644 --- a/aby3/source/mult3.h +++ b/aby3/source/mult3.h @@ -1,3 +1,4 @@ #pragma once -void mult3_test(); +#include +void mult3_test(oc::u64 partyIdx, int value); From c8ab51299cfbec7031c6338a18eb509c7c52d484 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Mon, 13 Apr 2020 18:27:06 -0400 Subject: [PATCH 07/16] add working innerprod example for aby3 also pulls out some setup code to main. --- aby3/source/innerprod.cpp | 60 +++++++++++++++++++++++++++++-- aby3/source/innerprod.h | 4 ++- aby3/source/main.cpp | 75 +++++++++++++++++++++++++++++++++++++-- aby3/source/mult3.cpp | 50 ++------------------------ 4 files changed, 136 insertions(+), 53 deletions(-) diff --git a/aby3/source/innerprod.cpp b/aby3/source/innerprod.cpp index 9b9b229..7f1935c 100644 --- a/aby3/source/innerprod.cpp +++ b/aby3/source/innerprod.cpp @@ -1,5 +1,61 @@ #include +#include -void innerprod_test(){ - std::cout << "testing innerprod..." << std::endl; +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" + +#include "util.h" +#include "innerprod.h" + +using namespace oc; +using namespace aby3; + +void innerprod_test(oc::u64 partyIdx, std::vectorvalues) { + if (partyIdx == 0) + std::cout << "testing innerprod..." << std::endl; + + IOService ios; + Sh3Encryptor enc; + Sh3Evaluator eval; + Sh3Runtime runtime; + setup_samples(partyIdx, ios, enc, eval, runtime); + + // encrypt (only parties 0,1 provide input) + u64 rows = values.size(); + std::vector A(rows); + std::vector B(rows); + + // note: this fails if you try to make multiple local/remote calls in the same if/else statement + // maybe could fix this with tasks? + for (int i=0; i<10; i++) { + if (partyIdx == 0) { + enc.localInt(runtime, values[i], A[i]).get(); + } else { + enc.remoteInt(runtime, A[i]).get(); + } + + if (partyIdx == 1) { + enc.localInt(runtime, values[i], B[i]).get(); + } else { + enc.remoteInt(runtime, B[i]).get(); + } + } + + // parallel multiplications + std::vector prods(rows); + Sh3Task task = runtime.noDependencies(); + for (u64 i = 0; i < rows; ++i) + task = eval.asyncMul(task, B[i], A[i], prods[i]); + task.get(); + + // addition + si64 sum = prods[0]; + for (u64 i = 1; i < rows; ++i) + sum = sum + (si64) prods[i]; + + // reveal result + i64 result; + enc.revealAll(runtime, sum, result).get(); + std::cout << "result: " << result << std::endl; } diff --git a/aby3/source/innerprod.h b/aby3/source/innerprod.h index ca16e6a..7bec7a0 100644 --- a/aby3/source/innerprod.h +++ b/aby3/source/innerprod.h @@ -1,2 +1,4 @@ #pragma once -void innerprod_test(); +#include +#include "util.h" +void innerprod_test(oc::u64 partyIdx, std::vectorvalues); diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp index 00f3d04..def939d 100644 --- a/aby3/source/main.cpp +++ b/aby3/source/main.cpp @@ -8,6 +8,24 @@ std::vector unitTestTag{ "u", "unitTest" }; std::vector playerTag{ "p", "player" }; +// convenience function +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" + +// This function sets up the basic classes that we will +// use to perform some computation. This mostly consists +// of creating Channels (network sockets) to the other +// parties and then establishing some shared randomness. +void setup_samples( + aby3::u64 partyIdx, + oc::IOService& ios, + aby3::Sh3Encryptor& enc, + aby3::Sh3Evaluator& eval, + aby3::Sh3Runtime& runtime); + + void help() { @@ -43,8 +61,11 @@ int main(int argc, char** argv) mult3_test(player, value); } if (cmd.getOr(unitTestTag, none).compare("innerprod") == 0) { - //innerprod_test(player); - innerprod_test(); + std::vector values(10); + for(uint i=0; i sharedVec(3); From 7ea462d112641843ee1e28ad92bdd58b26d8b1ee Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Tue, 28 Apr 2020 17:33:01 -0400 Subject: [PATCH 08/16] add outline for xtabs with Tables doesn't do comparison because I can't figure out how. also cleans up some old includes in innerprod / mult3 --- aby3/source/innerprod.cpp | 1 - aby3/source/innerprod.h | 13 +++++++- aby3/source/mult3.cpp | 1 - aby3/source/mult3.h | 12 +++++++ aby3/source/xtabs.cpp | 68 ++++++++++++++++++++++++++++++++++++++- aby3/source/xtabs.h | 15 ++++++++- 6 files changed, 105 insertions(+), 5 deletions(-) diff --git a/aby3/source/innerprod.cpp b/aby3/source/innerprod.cpp index 7f1935c..1d0a885 100644 --- a/aby3/source/innerprod.cpp +++ b/aby3/source/innerprod.cpp @@ -5,7 +5,6 @@ #include "aby3/sh3/Sh3Encryptor.h" #include "aby3/sh3/Sh3Evaluator.h" -#include "util.h" #include "innerprod.h" using namespace oc; diff --git a/aby3/source/innerprod.h b/aby3/source/innerprod.h index 7bec7a0..4240379 100644 --- a/aby3/source/innerprod.h +++ b/aby3/source/innerprod.h @@ -1,4 +1,15 @@ #pragma once #include -#include "util.h" void innerprod_test(oc::u64 partyIdx, std::vectorvalues); + +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" +void setup_samples( + aby3::u64 partyIdx, + oc::IOService& ios, + aby3::Sh3Encryptor& enc, + aby3::Sh3Evaluator& eval, + aby3::Sh3Runtime& runtime); + diff --git a/aby3/source/mult3.cpp b/aby3/source/mult3.cpp index f82af73..5b4c5c4 100644 --- a/aby3/source/mult3.cpp +++ b/aby3/source/mult3.cpp @@ -6,7 +6,6 @@ #include "aby3/sh3/Sh3Evaluator.h" #include "mult3.h" -#include "util.h" using namespace oc; using namespace aby3; diff --git a/aby3/source/mult3.h b/aby3/source/mult3.h index c58576c..b13fdef 100644 --- a/aby3/source/mult3.h +++ b/aby3/source/mult3.h @@ -2,3 +2,15 @@ #include void mult3_test(oc::u64 partyIdx, int value); +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" +void setup_samples( + aby3::u64 partyIdx, + oc::IOService& ios, + aby3::Sh3Encryptor& enc, + aby3::Sh3Evaluator& eval, + aby3::Sh3Runtime& runtime); + + diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp index 3a4dbd4..1ee337e 100644 --- a/aby3/source/xtabs.cpp +++ b/aby3/source/xtabs.cpp @@ -1,4 +1,70 @@ #include -void xtabs_test(){ +#include +#include +#include "xtabs.h" + +#include "aby3-DB/DBServer.h" + +using namespace oc; +using namespace aby3; +using namespace std; + +void xtabs_test( u64 partyIdx, std::vector ids, std::vector values){ std::cout << "testing xtabs..." << std::endl; + + IOService ios; + + DBServer srv; + if (partyIdx == 0) { + Session s01(ios, "127.0.0.1:3030", SessionMode::Server, "01"); + Session s02(ios, "127.0.0.1:3031", SessionMode::Server, "02"); + srv.init(0, s02, s01); + + } else if (partyIdx == 1) { + Session s10(ios, "127.0.0.1:3030", SessionMode::Client, "01"); + Session s12(ios, "127.0.0.1:3032", SessionMode::Server, "12"); + srv.init(1, s10, s12); + } else { + Session s20(ios, "127.0.0.1:3031", SessionMode::Client, "02"); + Session s21(ios, "127.0.0.1:3032", SessionMode::Client, "12"); + srv.init(2, s21, s20); + } + + // 80 bits; + u32 hashSize = 80; + + PRNG prng(ZeroBlock); + + auto keyBitCount = srv.mKeyBitCount; + // to start: just have id column. + std::vector + catCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, + ColumnInfo{ "cat", TypeID::IntID, keyBitCount }}, + valCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, + ColumnInfo{ "val", TypeID::IntID, keyBitCount } }; + + u64 rows = 10; + assert (ids.size() == rows); + assert (values.size() == rows); + + Table a(rows, catCols) + , b(rows, valCols); + + // ? + auto intersectionSize = rows; + + // todo initialize properly + Table catData, valData; + for (auto& c : valData.mColumns) prng.get(c.mData.data(), c.mData.size()); + for (auto& c : catData.mColumns) prng.get(c.mData.data(), c.mData.size()); + + + + + + + + + } + diff --git a/aby3/source/xtabs.h b/aby3/source/xtabs.h index cfb0717..99ed039 100644 --- a/aby3/source/xtabs.h +++ b/aby3/source/xtabs.h @@ -1,3 +1,16 @@ #pragma once -void xtabs_test(); +#include +void xtabs_test(oc::u64 partyIdx, std::vector ids, std::vector values); + +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" +void setup_samples( + aby3::u64 partyIdx, + oc::IOService& ios, + aby3::Sh3Encryptor& enc, + aby3::Sh3Evaluator& eval, + aby3::Sh3Runtime& runtime); + From 2c24585ad0dbdb8d3e21b33c5b79d25d7f7c06d4 Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Sat, 2 May 2020 15:03:39 -0400 Subject: [PATCH 09/16] read data correctly for aby3 xtabs reads into Tables, converts to secure doesn't do any operations yet --- aby3/source/xtabs.cpp | 72 +++++++++++++++++++++++++++---------------- aby3/source/xtabs.h | 11 ------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp index 1ee337e..15b2199 100644 --- a/aby3/source/xtabs.cpp +++ b/aby3/source/xtabs.cpp @@ -4,6 +4,10 @@ #include "xtabs.h" #include "aby3-DB/DBServer.h" +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" using namespace oc; using namespace aby3; @@ -30,41 +34,57 @@ void xtabs_test( u64 partyIdx, std::vector ids, std::vector values){ srv.init(2, s21, s20); } - // 80 bits; - u32 hashSize = 80; - PRNG prng(ZeroBlock); auto keyBitCount = srv.mKeyBitCount; - // to start: just have id column. std::vector - catCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, - ColumnInfo{ "cat", TypeID::IntID, keyBitCount }}, - valCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, - ColumnInfo{ "val", TypeID::IntID, keyBitCount } }; + catCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, + ColumnInfo{ "cat", TypeID::IntID, keyBitCount }}, + valCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, + ColumnInfo{ "val", TypeID::IntID, keyBitCount } }; u64 rows = 10; assert (ids.size() == rows); assert (values.size() == rows); - Table a(rows, catCols) - , b(rows, valCols); - - // ? - auto intersectionSize = rows; - - // todo initialize properly - Table catData, valData; - for (auto& c : valData.mColumns) prng.get(c.mData.data(), c.mData.size()); - for (auto& c : catData.mColumns) prng.get(c.mData.data(), c.mData.size()); - - - - - - - - + Table catData(rows, catCols) + , valData(rows, valCols); + + // initializes data into Table (still in the clear) + for (u64 i = 0; i < rows; ++i) { + if (partyIdx == 0) { + catData.mColumns[0].mData(i, 0) = ids[i]; + catData.mColumns[0].mData(i, 1) = values[i] % 5; + } else if (partyIdx == 1) { + valData.mColumns[0].mData(i, 0) = ids[i]; + valData.mColumns[0].mData(i, 1) = values[i]; + } + } + /* + *prints out data in the clear + for (u64 i = 0; i < rows; ++i) { + for (u64 j=0; j < catData.mColumns[0].mData.cols(); ++j) { + cout << valData.mColumns[0].mData(i,j) << ", "; + } + cout << endl; + } + */ + + SharedTable catTable, valTable; + catTable = (partyIdx == 0) ? srv.localInput(catData) : srv.remoteInput(0); + valTable = (partyIdx == 1) ? srv.localInput(valData) : srv.remoteInput(1); + + Table revealTable(rows, catCols); + // catTable.mColumns[0] is a SharedColumn, which extends sbMatrix (shared binary matrix). This has a similar interface to si64 matrix, but with the element-wise access removed (e.g. can't do sbmat(0,0)). + // TODO: explore ways around this? + // srv.mEnc.revealAll(srv.mRt, catTable.mColumns[0], revealTable.mColumns[0].mData(0,0)) + + /* + SelectQuery select; + auto keyjoin= select.joinOn(catTable["key"], valTable["key"]); + select.addOutput("key", keyjoin); + */ } + diff --git a/aby3/source/xtabs.h b/aby3/source/xtabs.h index 99ed039..8f7a0ab 100644 --- a/aby3/source/xtabs.h +++ b/aby3/source/xtabs.h @@ -3,14 +3,3 @@ #include void xtabs_test(oc::u64 partyIdx, std::vector ids, std::vector values); -#include -#include "aby3/sh3/Sh3Runtime.h" -#include "aby3/sh3/Sh3Encryptor.h" -#include "aby3/sh3/Sh3Evaluator.h" -void setup_samples( - aby3::u64 partyIdx, - oc::IOService& ios, - aby3::Sh3Encryptor& enc, - aby3::Sh3Evaluator& eval, - aby3::Sh3Runtime& runtime); - From 1c8a6999a45c7fc0ad0afa316b83f993720df1fb Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Thu, 25 Jan 2024 16:55:30 +0100 Subject: [PATCH 10/16] add install script --- aby3/Dockerfile | 12 ++++++++++++ aby3/install.sh | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 aby3/Dockerfile create mode 100755 aby3/install.sh diff --git a/aby3/Dockerfile b/aby3/Dockerfile new file mode 100644 index 0000000..d429197 --- /dev/null +++ b/aby3/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:22.04 + +WORKDIR /root + +RUN apt update \ + && apt install -y vim git build-essential python3 cmake + +ADD install.sh . +RUN ./install.sh + +WORKDIR /root/aby3 +ADD source . diff --git a/aby3/install.sh b/aby3/install.sh new file mode 100755 index 0000000..2ab65e9 --- /dev/null +++ b/aby3/install.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -ex + +git clone https://github.com/gutjuri/aby3.git +cd aby3/ +git checkout fix-build-script +python3 build.py --setup +python3 build.py From a7d213f7ca246ac9792a1645a3ecd3f15beeabcb Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Thu, 25 Jan 2024 17:10:24 +0100 Subject: [PATCH 11/16] remove dependency installation --- aby3/install_dependencies.sh | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 aby3/install_dependencies.sh diff --git a/aby3/install_dependencies.sh b/aby3/install_dependencies.sh deleted file mode 100644 index 64d8d92..0000000 --- a/aby3/install_dependencies.sh +++ /dev/null @@ -1,14 +0,0 @@ -alias wget="wget -nv" -wget https://github.com/Kitware/CMake/releases/download/v3.16.0-rc4/cmake-3.16.0-rc4-Linux-x86_64.tar.gz -tar xzvf cmake-3.16.0-rc4-Linux-x86_64.tar.gz -cd cmake-3.16.0-rc4-Linux-x86_64 -mv bin/* /usr/bin/ -cp -r share/* /usr/share/ - -cd -git clone --recursive https://github.com/osu-crypto/libOTe.git -cd libOTe/cryptoTools/thirdparty/linux -bash boost.get -cd ../../.. -cmake -DENABLE_CIRCUITS=ON . -make -j From 88deed58499e381e6abbcb56bb90b161a223a21b Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Fri, 26 Jan 2024 13:38:29 +0100 Subject: [PATCH 12/16] make aby3 compile again --- .vscode/settings.json | 50 ++++++++++++++ aby3/Dockerfile | 6 +- aby3/install.sh | 5 +- aby3/run_example.sh | 16 +++++ aby3/source/CMakeLists.txt | 5 +- aby3/source/innerprod.cpp | 36 ++++++---- aby3/source/innerprod.h | 11 ++- aby3/source/main.cpp | 82 ++++++++++++----------- aby3/source/mult3.cpp | 24 ++++--- aby3/source/mult3.h | 10 ++- aby3/source/xtabs.cpp | 133 +++++++++++++++++++------------------ aby3/source/xtabs.h | 11 ++- 12 files changed, 246 insertions(+), 143 deletions(-) create mode 100644 .vscode/settings.json create mode 100755 aby3/run_example.sh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0d39b48 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/aby3/Dockerfile b/aby3/Dockerfile index d429197..521296e 100644 --- a/aby3/Dockerfile +++ b/aby3/Dockerfile @@ -9,4 +9,8 @@ ADD install.sh . RUN ./install.sh WORKDIR /root/aby3 -ADD source . +ADD source ./samples +# build our examples +RUN python3 build.py + +ADD run_example.sh . diff --git a/aby3/install.sh b/aby3/install.sh index 2ab65e9..ef5ecb0 100755 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -4,6 +4,9 @@ set -ex git clone https://github.com/gutjuri/aby3.git cd aby3/ -git checkout fix-build-script +git checkout fix-buildscript-fix python3 build.py --setup python3 build.py + +mkdir samples +printf "add_subdirectory(samples)\n" >> CMakeLists.txt diff --git a/aby3/run_example.sh b/aby3/run_example.sh new file mode 100755 index 0000000..ad24f5c --- /dev/null +++ b/aby3/run_example.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -ex + +SAMPLE=$1 + +BIN=out/build/linux/samples/samples.exe + +if [ $SAMPLE = mult3 -o $SAMPLE = innerprod -o $SAMPLE = xtabs ]; then + $BIN -p 0 -u $SAMPLE & + $BIN -p 1 -u $SAMPLE & + $BIN -p 2 -u $SAMPLE +else + echo "Bad sample name. Supported samples: mult3, innerprod, xtabs" + exit 1 +fi diff --git a/aby3/source/CMakeLists.txt b/aby3/source/CMakeLists.txt index 58a7927..7dede90 100644 --- a/aby3/source/CMakeLists.txt +++ b/aby3/source/CMakeLists.txt @@ -10,5 +10,8 @@ include_directories(${CMAKE_SOURCE_DIR}/samples/) add_executable(samples.exe ${SRC_SAMPLES}) +target_link_libraries(samples.exe com-psi) +target_link_libraries(samples.exe aby3-ML) +target_link_libraries(samples.exe com-psi_Tests) target_link_libraries(samples.exe aby3_Tests) - +target_link_libraries(samples.exe oc::tests_cryptoTools) diff --git a/aby3/source/innerprod.cpp b/aby3/source/innerprod.cpp index 1d0a885..2c279cb 100644 --- a/aby3/source/innerprod.cpp +++ b/aby3/source/innerprod.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "aby3/sh3/Sh3Runtime.h" @@ -10,10 +10,11 @@ using namespace oc; using namespace aby3; -void innerprod_test(oc::u64 partyIdx, std::vectorvalues) { +void innerprod_test(oc::u64 partyIdx, std::vector values) +{ if (partyIdx == 0) - std::cout << "testing innerprod..." << std::endl; - + std::cout << "testing innerprod..." << std::endl; + IOService ios; Sh3Encryptor enc; Sh3Evaluator eval; @@ -24,23 +25,30 @@ void innerprod_test(oc::u64 partyIdx, std::vectorvalues) { u64 rows = values.size(); std::vector A(rows); std::vector B(rows); - + // note: this fails if you try to make multiple local/remote calls in the same if/else statement - // maybe could fix this with tasks? - for (int i=0; i<10; i++) { - if (partyIdx == 0) { + // maybe could fix this with tasks? + for (int i = 0; i < 10; i++) + { + if (partyIdx == 0) + { enc.localInt(runtime, values[i], A[i]).get(); - } else { + } + else + { enc.remoteInt(runtime, A[i]).get(); } - - if (partyIdx == 1) { + + if (partyIdx == 1) + { enc.localInt(runtime, values[i], B[i]).get(); - } else { + } + else + { enc.remoteInt(runtime, B[i]).get(); } } - + // parallel multiplications std::vector prods(rows); Sh3Task task = runtime.noDependencies(); @@ -51,7 +59,7 @@ void innerprod_test(oc::u64 partyIdx, std::vectorvalues) { // addition si64 sum = prods[0]; for (u64 i = 1; i < rows; ++i) - sum = sum + (si64) prods[i]; + sum = sum + (si64)prods[i]; // reveal result i64 result; diff --git a/aby3/source/innerprod.h b/aby3/source/innerprod.h index 4240379..a312a01 100644 --- a/aby3/source/innerprod.h +++ b/aby3/source/innerprod.h @@ -1,6 +1,6 @@ #pragma once #include -void innerprod_test(oc::u64 partyIdx, std::vectorvalues); +void innerprod_test(oc::u64 partyIdx, std::vector values); #include #include "aby3/sh3/Sh3Runtime.h" @@ -8,8 +8,7 @@ void innerprod_test(oc::u64 partyIdx, std::vectorvalues); #include "aby3/sh3/Sh3Evaluator.h" void setup_samples( aby3::u64 partyIdx, - oc::IOService& ios, - aby3::Sh3Encryptor& enc, - aby3::Sh3Evaluator& eval, - aby3::Sh3Runtime& runtime); - + oc::IOService &ios, + aby3::Sh3Encryptor &enc, + aby3::Sh3Evaluator &eval, + aby3::Sh3Runtime &runtime); diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp index def939d..4e15fe5 100644 --- a/aby3/source/main.cpp +++ b/aby3/source/main.cpp @@ -5,8 +5,8 @@ // testing and command line parsing #include #include -std::vector unitTestTag{ "u", "unitTest" }; -std::vector playerTag{ "p", "player" }; +std::vector unitTestTag{"u", "unitTest"}; +std::vector playerTag{"p", "player"}; // convenience function #include @@ -14,18 +14,16 @@ std::vector playerTag{ "p", "player" }; #include "aby3/sh3/Sh3Encryptor.h" #include "aby3/sh3/Sh3Evaluator.h" -// This function sets up the basic classes that we will +// This function sets up the basic classes that we will // use to perform some computation. This mostly consists -// of creating Channels (network sockets) to the other +// of creating Channels (network sockets) to the other // parties and then establishing some shared randomness. void setup_samples( aby3::u64 partyIdx, - oc::IOService& ios, - aby3::Sh3Encryptor& enc, - aby3::Sh3Evaluator& eval, - aby3::Sh3Runtime& runtime); - - + oc::IOService &ios, + aby3::Sh3Encryptor &enc, + aby3::Sh3Evaluator &eval, + aby3::Sh3Runtime &runtime); void help() { @@ -36,49 +34,58 @@ void help() std::cout << "-p party ~~ indicate which party you are" << std::endl; } -int main(int argc, char** argv) +int main(int argc, char **argv) { - try { + try + { oc::CLP cmd(argc, argv); oc::u64 player; - if (cmd.isSet(playerTag)) { + if (cmd.isSet(playerTag)) + { player = cmd.getOr(playerTag, -1); - } else { - std::cout << "You need to specify which player you are" << std::endl; + } + else + { + std::cout << "You need to specify which party you are" << std::endl; return 0; } - // this calls the appropriate test function based on command-line arg - // functions are defined in their respective .h files + // this calls the appropriate test function based on command-line arg + // functions are defined in their respective .h files if (cmd.isSet(unitTestTag)) { std::string none = ""; - if (cmd.getOr(unitTestTag, none).compare("mult3") == 0) { - // hardcodes input value - int value = 3 + player; + if (cmd.getOr(unitTestTag, none).compare("mult3") == 0) + { + // hardcoded input value. expected result: 3*4*5 = 60 + int value = 3 + player; mult3_test(player, value); } - if (cmd.getOr(unitTestTag, none).compare("innerprod") == 0) { + if (cmd.getOr(unitTestTag, none).compare("innerprod") == 0) + { std::vector values(10); - for(uint i=0; i ids{1,2,3,4}; + std::vector values{4,5,6,7}; + xtabs_test(player, ids, values); } return 0; } - help(); - + help(); } - catch (std::exception& e) + catch (std::exception &e) { std::cout << e.what() << std::endl; } @@ -92,13 +99,13 @@ using namespace aby3; using namespace oc; void setup_samples( aby3::u64 partyIdx, - oc::IOService& ios, - aby3::Sh3Encryptor& enc, - aby3::Sh3Evaluator& eval, - aby3::Sh3Runtime& runtime) + oc::IOService &ios, + aby3::Sh3Encryptor &enc, + aby3::Sh3Evaluator &eval, + aby3::Sh3Runtime &runtime) { // A CommPkg is a pair of Channels (network sockets) to the other parties. - // See cryptoTools\frontend_cryptoTools\Tutorials\Network.cpp + // See cryptoTools\frontend_cryptoTools\Tutorials\Network.cpp // for details. // since we're running them all locally, they're sitting on 3 different ports. aby3::CommPkg comm; @@ -118,12 +125,11 @@ void setup_samples( break; } - // in a real work example, where parties - // have different IPs, you have to give the + // in a real work example, where parties + // have different IPs, you have to give the // Clients the IP of the server and you give // the servers their own IP (to listen to). - // Establishes some shared randomness needed for the later protocols enc.init(partyIdx, comm, sysRandomSeed()); @@ -133,5 +139,3 @@ void setup_samples( // Copies the Channels and will use them for later protcols. runtime.init(partyIdx, comm); } - - diff --git a/aby3/source/mult3.cpp b/aby3/source/mult3.cpp index 5b4c5c4..cad7052 100644 --- a/aby3/source/mult3.cpp +++ b/aby3/source/mult3.cpp @@ -10,25 +10,26 @@ using namespace oc; using namespace aby3; /* - * mult3 - * + * mult3 + * * multiplies three numbers together * lots of this code is ported from Peter Rindal's aby3Tutorial.cpp * */ -void mult3_test(u64 partyIdx, int value){ - if (partyIdx == 0) +void mult3_test(u64 partyIdx, int value) +{ + if (partyIdx == 0) std::cout << "testing mult3..." << std::endl; - + IOService ios; - // Sh3Encryptor allows us to generate and reconstruct secret shared values. + // Sh3Encryptor allows us to generate and reconstruct secret shared values. Sh3Encryptor enc; - // Sh3Evaluator will allow us to perform some of the + // Sh3Evaluator will allow us to perform some of the // most common interactive protocols, e.g. multiplication. Sh3Evaluator eval; - // Sh3Runtime does networking and helps schedule operations in parallel + // Sh3Runtime does networking and helps schedule operations in parallel Sh3Runtime runtime; setup_samples(partyIdx, ios, enc, eval, runtime); @@ -39,13 +40,14 @@ void mult3_test(u64 partyIdx, int value){ * instead of calling .get() immediately * This didn't compile for me; the runtime destructor was getting called way too early. */ - for (u64 i = 0; i < sharedVec.size(); ++i) { + for (u64 i = 0; i < sharedVec.size(); ++i) + { if (i % 3 == partyIdx) enc.localInt(runtime, value, sharedVec[i]).get(); else enc.remoteInt(runtime, sharedVec[i]).get(); } - + /* multiply them together */ si64 prod = sharedVec[0]; Sh3Task task = runtime.noDependencies(); @@ -53,7 +55,7 @@ void mult3_test(u64 partyIdx, int value){ task = eval.asyncMul(task, prod, sharedVec[i], prod); task.get(); - + /* reveal result */ i64 result; enc.revealAll(runtime, prod, result).get(); diff --git a/aby3/source/mult3.h b/aby3/source/mult3.h index b13fdef..e08ed7d 100644 --- a/aby3/source/mult3.h +++ b/aby3/source/mult3.h @@ -8,9 +8,7 @@ void mult3_test(oc::u64 partyIdx, int value); #include "aby3/sh3/Sh3Evaluator.h" void setup_samples( aby3::u64 partyIdx, - oc::IOService& ios, - aby3::Sh3Encryptor& enc, - aby3::Sh3Evaluator& eval, - aby3::Sh3Runtime& runtime); - - + oc::IOService &ios, + aby3::Sh3Encryptor &enc, + aby3::Sh3Evaluator &eval, + aby3::Sh3Runtime &runtime); diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp index 15b2199..da87943 100644 --- a/aby3/source/xtabs.cpp +++ b/aby3/source/xtabs.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "xtabs.h" @@ -13,78 +13,85 @@ using namespace oc; using namespace aby3; using namespace std; -void xtabs_test( u64 partyIdx, std::vector ids, std::vector values){ - std::cout << "testing xtabs..." << std::endl; +void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) +{ + std::cout << "testing xtabs..." << std::endl; - IOService ios; - - DBServer srv; - if (partyIdx == 0) { - Session s01(ios, "127.0.0.1:3030", SessionMode::Server, "01"); - Session s02(ios, "127.0.0.1:3031", SessionMode::Server, "02"); - srv.init(0, s02, s01); - - } else if (partyIdx == 1) { - Session s10(ios, "127.0.0.1:3030", SessionMode::Client, "01"); - Session s12(ios, "127.0.0.1:3032", SessionMode::Server, "12"); - srv.init(1, s10, s12); - } else { - Session s20(ios, "127.0.0.1:3031", SessionMode::Client, "02"); - Session s21(ios, "127.0.0.1:3032", SessionMode::Client, "12"); - srv.init(2, s21, s20); - } + IOService ios; + + DBServer srv; + + PRNG prng(ZeroBlock); - PRNG prng(ZeroBlock); + if (partyIdx == 0) + { + Session s01(ios, "127.0.0.1:3030", SessionMode::Server, "01"); + Session s02(ios, "127.0.0.1:3031", SessionMode::Server, "02"); + srv.init(0, s02, s01, prng); + } + else if (partyIdx == 1) + { + Session s10(ios, "127.0.0.1:3030", SessionMode::Client, "01"); + Session s12(ios, "127.0.0.1:3032", SessionMode::Server, "12"); + srv.init(1, s10, s12, prng); + } + else + { + Session s20(ios, "127.0.0.1:3031", SessionMode::Client, "02"); + Session s21(ios, "127.0.0.1:3032", SessionMode::Client, "12"); + srv.init(2, s21, s20, prng); + } - auto keyBitCount = srv.mKeyBitCount; - std::vector - catCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, - ColumnInfo{ "cat", TypeID::IntID, keyBitCount }}, - valCols = { ColumnInfo{ "key", TypeID::IntID, keyBitCount }, - ColumnInfo{ "val", TypeID::IntID, keyBitCount } }; + auto keyBitCount = srv.mKeyBitCount; + std::vector + catCols = {ColumnInfo{"key", TypeID::IntID, keyBitCount}, + ColumnInfo{"cat", TypeID::IntID, keyBitCount}}, + valCols = {ColumnInfo{"key", TypeID::IntID, keyBitCount}, + ColumnInfo{"val", TypeID::IntID, keyBitCount}}; - u64 rows = 10; - assert (ids.size() == rows); - assert (values.size() == rows); + u64 rows = 10; + assert(ids.size() == rows); + assert(values.size() == rows); - Table catData(rows, catCols) - , valData(rows, valCols); + Table catData(rows, catCols), valData(rows, valCols); - // initializes data into Table (still in the clear) - for (u64 i = 0; i < rows; ++i) { - if (partyIdx == 0) { - catData.mColumns[0].mData(i, 0) = ids[i]; - catData.mColumns[0].mData(i, 1) = values[i] % 5; - } else if (partyIdx == 1) { - valData.mColumns[0].mData(i, 0) = ids[i]; - valData.mColumns[0].mData(i, 1) = values[i]; - } + // initializes data into Table (still in the clear) + for (u64 i = 0; i < rows; ++i) + { + if (partyIdx == 0) + { + catData.mColumns[0].mData(i, 0) = ids[i]; + catData.mColumns[0].mData(i, 1) = values[i] % 5; } + else if (partyIdx == 1) + { + valData.mColumns[0].mData(i, 0) = ids[i]; + valData.mColumns[0].mData(i, 1) = values[i]; + } + } - /* - *prints out data in the clear - for (u64 i = 0; i < rows; ++i) { - for (u64 j=0; j < catData.mColumns[0].mData.cols(); ++j) { - cout << valData.mColumns[0].mData(i,j) << ", "; - } - cout << endl; + /* + *prints out data in the clear + for (u64 i = 0; i < rows; ++i) { + for (u64 j=0; j < catData.mColumns[0].mData.cols(); ++j) { + cout << valData.mColumns[0].mData(i,j) << ", "; } - */ + cout << endl; + } + */ - SharedTable catTable, valTable; - catTable = (partyIdx == 0) ? srv.localInput(catData) : srv.remoteInput(0); - valTable = (partyIdx == 1) ? srv.localInput(valData) : srv.remoteInput(1); + SharedTable catTable, valTable; + catTable = (partyIdx == 0) ? srv.localInput(catData) : srv.remoteInput(0); + valTable = (partyIdx == 1) ? srv.localInput(valData) : srv.remoteInput(1); - Table revealTable(rows, catCols); - // catTable.mColumns[0] is a SharedColumn, which extends sbMatrix (shared binary matrix). This has a similar interface to si64 matrix, but with the element-wise access removed (e.g. can't do sbmat(0,0)). - // TODO: explore ways around this? - // srv.mEnc.revealAll(srv.mRt, catTable.mColumns[0], revealTable.mColumns[0].mData(0,0)) + Table revealTable(rows, catCols); + // catTable.mColumns[0] is a SharedColumn, which extends sbMatrix (shared binary matrix). This has a similar interface to si64 matrix, but with the element-wise access removed (e.g. can't do sbmat(0,0)). + // TODO: explore ways around this? + // srv.mEnc.revealAll(srv.mRt, catTable.mColumns[0], revealTable.mColumns[0].mData(0,0)) - /* - SelectQuery select; - auto keyjoin= select.joinOn(catTable["key"], valTable["key"]); - select.addOutput("key", keyjoin); - */ + /* + SelectQuery select; + auto keyjoin= select.joinOn(catTable["key"], valTable["key"]); + select.addOutput("key", keyjoin); + */ } - - diff --git a/aby3/source/xtabs.h b/aby3/source/xtabs.h index 8f7a0ab..c4089b8 100644 --- a/aby3/source/xtabs.h +++ b/aby3/source/xtabs.h @@ -1,5 +1,14 @@ #pragma once - #include void xtabs_test(oc::u64 partyIdx, std::vector ids, std::vector values); +#include +#include "aby3/sh3/Sh3Runtime.h" +#include "aby3/sh3/Sh3Encryptor.h" +#include "aby3/sh3/Sh3Evaluator.h" +void setup_samples( + aby3::u64 partyIdx, + oc::IOService &ios, + aby3::Sh3Encryptor &enc, + aby3::Sh3Evaluator &eval, + aby3::Sh3Runtime &runtime); From 272c7d0b83515ec8c19a358f3fe0845d9693e415 Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Mon, 29 Jan 2024 17:02:40 +0100 Subject: [PATCH 13/16] Continue xtabs example --- aby3/Dockerfile | 2 ++ aby3/source/main.cpp | 6 +++--- aby3/source/xtabs.cpp | 46 +++++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/aby3/Dockerfile b/aby3/Dockerfile index 521296e..79a5d1d 100644 --- a/aby3/Dockerfile +++ b/aby3/Dockerfile @@ -14,3 +14,5 @@ ADD source ./samples RUN python3 build.py ADD run_example.sh . + +ENTRYPOINT ./run_example.sh xtabs diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp index 4e15fe5..48a9e70 100644 --- a/aby3/source/main.cpp +++ b/aby3/source/main.cpp @@ -69,14 +69,14 @@ int main(int argc, char **argv) // expected result: (0*0) + (1*2) + (2*4) + ... = 570 for (uint i = 0; i < values.size(); i++) { - values[i] = (player+1) * i; + values[i] = (player + 1) * i; } innerprod_test(player, values); } if (cmd.getOr(unitTestTag, none).compare("xtabs") == 0) { - std::vector ids{1,2,3,4}; - std::vector values{4,5,6,7}; + std::vector ids{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + std::vector values{11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; xtabs_test(player, ids, values); } diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp index da87943..cea2d57 100644 --- a/aby3/source/xtabs.cpp +++ b/aby3/source/xtabs.cpp @@ -49,7 +49,7 @@ void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) valCols = {ColumnInfo{"key", TypeID::IntID, keyBitCount}, ColumnInfo{"val", TypeID::IntID, keyBitCount}}; - u64 rows = 10; + u64 rows = ids.size(); assert(ids.size() == rows); assert(values.size() == rows); @@ -61,7 +61,7 @@ void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) if (partyIdx == 0) { catData.mColumns[0].mData(i, 0) = ids[i]; - catData.mColumns[0].mData(i, 1) = values[i] % 5; + catData.mColumns[0].mData(i, 1) = values[i]; } else if (partyIdx == 1) { @@ -70,28 +70,32 @@ void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) } } - /* - *prints out data in the clear - for (u64 i = 0; i < rows; ++i) { - for (u64 j=0; j < catData.mColumns[0].mData.cols(); ++j) { - cout << valData.mColumns[0].mData(i,j) << ", "; - } - cout << endl; - } - */ - SharedTable catTable, valTable; catTable = (partyIdx == 0) ? srv.localInput(catData) : srv.remoteInput(0); valTable = (partyIdx == 1) ? srv.localInput(valData) : srv.remoteInput(1); - Table revealTable(rows, catCols); - // catTable.mColumns[0] is a SharedColumn, which extends sbMatrix (shared binary matrix). This has a similar interface to si64 matrix, but with the element-wise access removed (e.g. can't do sbmat(0,0)). - // TODO: explore ways around this? - // srv.mEnc.revealAll(srv.mRt, catTable.mColumns[0], revealTable.mColumns[0].mData(0,0)) + // i64Matrix keys(catTable.mColumns[0].rows(), catTable.mColumns[0].i64Cols()); + // srv.mEnc.revealAll(srv.mRt.mComm, catTable.mColumns[0], keys); + // + // if (partyIdx == 0) + //{ + // std::cout << keys << std::endl; + //} + + auto res = srv.join(catTable["key"], valTable["key"], {catTable["cat"], valTable["val"]}); + cout << "not reached " << endl; + // for (auto c : res.mColumns) { + // cout << c.mName << "xXx"; + // } + + aby3::i64Matrix cats(res.mColumns[0].rows(), res.mColumns[0].i64Cols()); + aby3::i64Matrix vals(res.mColumns[1].rows(), res.mColumns[1].i64Cols()); - /* - SelectQuery select; - auto keyjoin= select.joinOn(catTable["key"], valTable["key"]); - select.addOutput("key", keyjoin); - */ + srv.mEnc.revealAll(srv.mRt.mComm, res.mColumns[0], cats); + srv.mEnc.revealAll(srv.mRt.mComm, res.mColumns[1], vals); + + if (partyIdx == 0) + { + std::cout << cats << std::endl; + } } From 5861e63a732c26ee1da6aea9f5a90ee588b33db0 Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Mon, 29 Jan 2024 17:04:38 +0100 Subject: [PATCH 14/16] add workflow for ABY3 --- .github/workflows/test-aby3.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/test-aby3.yml diff --git a/.github/workflows/test-aby3.yml b/.github/workflows/test-aby3.yml new file mode 100644 index 0000000..fd140ea --- /dev/null +++ b/.github/workflows/test-aby3.yml @@ -0,0 +1,28 @@ +name: Build and test the Docker container for ABY3 + +on: + push: + branches: [ master ] + paths: + - aby3/* + pull_request: + branches: [ master ] + paths: + - aby3/* + +jobs: + build: + name: Build container for ABY3 + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + - uses: docker/setup-buildx-action@v2 + - uses: docker/build-push-action@v4 + with: + context: aby3 + tags: aby3 + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + push: false From e68567b26c22e3588f312f305369c610b1891263 Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Mon, 29 Jan 2024 17:11:29 +0100 Subject: [PATCH 15/16] specify correct ABY3 repo --- aby3/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aby3/install.sh b/aby3/install.sh index ef5ecb0..2a47bce 100755 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -2,9 +2,9 @@ set -ex -git clone https://github.com/gutjuri/aby3.git +git clone https://github.com/ladnir/aby3.git cd aby3/ -git checkout fix-buildscript-fix +git checkout 0849df6 python3 build.py --setup python3 build.py From bdb331970368abe10fbf80fb58a9a593e8c07655 Mon Sep 17 00:00:00 2001 From: Juri Dispan Date: Fri, 12 Apr 2024 15:53:44 +0200 Subject: [PATCH 16/16] debug --- aby3/install.sh | 2 +- aby3/source/main.cpp | 6 +++--- aby3/source/xtabs.cpp | 11 +++++++++-- aby3/source/xtabs.h | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/aby3/install.sh b/aby3/install.sh index 2a47bce..96403c5 100755 --- a/aby3/install.sh +++ b/aby3/install.sh @@ -4,7 +4,7 @@ set -ex git clone https://github.com/ladnir/aby3.git cd aby3/ -git checkout 0849df6 +git checkout 854ca1b python3 build.py --setup python3 build.py diff --git a/aby3/source/main.cpp b/aby3/source/main.cpp index 48a9e70..ff675d4 100644 --- a/aby3/source/main.cpp +++ b/aby3/source/main.cpp @@ -75,9 +75,9 @@ int main(int argc, char **argv) } if (cmd.getOr(unitTestTag, none).compare("xtabs") == 0) { - std::vector ids{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - std::vector values{11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; - xtabs_test(player, ids, values); + std::vector ids{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector values{0, 2, 2, 3, 4, 5, 6, 7, 8, 9}; + xtabs_test(player, ids, values, 10); } return 0; diff --git a/aby3/source/xtabs.cpp b/aby3/source/xtabs.cpp index cea2d57..d259ed2 100644 --- a/aby3/source/xtabs.cpp +++ b/aby3/source/xtabs.cpp @@ -13,7 +13,7 @@ using namespace oc; using namespace aby3; using namespace std; -void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) +void xtabs_test(u64 partyIdx, std::vector ids, std::vector values, int nCats) { std::cout << "testing xtabs..." << std::endl; @@ -91,11 +91,18 @@ void xtabs_test(u64 partyIdx, std::vector ids, std::vector values) aby3::i64Matrix cats(res.mColumns[0].rows(), res.mColumns[0].i64Cols()); aby3::i64Matrix vals(res.mColumns[1].rows(), res.mColumns[1].i64Cols()); - srv.mEnc.revealAll(srv.mRt.mComm, res.mColumns[0], cats); + srv.mEnc.revealAll(srv.mRt.mComm, res.mColumns[0], cats); //debug srv.mEnc.revealAll(srv.mRt.mComm, res.mColumns[1], vals); if (partyIdx == 0) { std::cout << cats << std::endl; } + + std::vector sums(nCats); + for (int i = 0; i < res.mColumns[0].rows(); i++) { + for(int c = 0; c < nCats; c++) { + // if res(0, i) == c then + } + } } diff --git a/aby3/source/xtabs.h b/aby3/source/xtabs.h index c4089b8..3f6cef0 100644 --- a/aby3/source/xtabs.h +++ b/aby3/source/xtabs.h @@ -1,6 +1,6 @@ #pragma once #include -void xtabs_test(oc::u64 partyIdx, std::vector ids, std::vector values); +void xtabs_test(oc::u64 partyIdx, std::vector ids, std::vector values, int nCats); #include #include "aby3/sh3/Sh3Runtime.h"