Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiao1254 committed May 12, 2019
1 parent aa3c177 commit 5f25a4b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ before_install:
script:
- cat /proc/cpuinfo || true
- cmake -DCMAKE_BUILD_TYPE=$TYPE . && make
- ./run ./bin/bench_mpc 12345
- ./run ./bin/aes 12345
- ./run ./bin/sha1 12345
- ./run ./bin/sha256 12345
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ endmacro()

add_test (test_mpc)
add_test (test_mpc_individual)
add_test (bench_mpc)
add_test (aes)
add_test (sha1)
add_test (sha256)
11 changes: 0 additions & 11 deletions test/bench_mpc.cpp → test/aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void bench_once(NetIOMP<nP> * ios[2], ThreadPool * pool, string filename) {
delete mpc;
}
int main(int argc, char** argv) {
int func = 0;
parse_party_and_port(argv, &party, &port);
if(party > nP)return 0;
NetIOMP<nP> io(party, port);
Expand All @@ -60,16 +59,6 @@ int main(int argc, char** argv) {
NetIOMP<nP> *ios[2] = {&io, &io2};
ThreadPool pool(2*(nP-1)+2);

// for(int i = 0; i < 10; ++i)
if(func == 0)
bench_once(ios, &pool, circuit_file_location+"AES-non-expanded.txt");
// for(int i = 0; i < 10; ++i)
if(func == 1)
bench_once(ios, &pool, circuit_file_location+"sha-1.txt");
// for(int i = 0; i < 10; ++i)
if(func == 2)
bench_once(ios, &pool, circuit_file_location+"sha-256.txt");

// bench_once(ios, &pool, "/home/wangxiao/git/emp-toolkit/constantmpc/circ.txt");
return 0;
}
64 changes: 64 additions & 0 deletions test/sha1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <emp-tool/emp-tool.h>
#include "emp-agmpc/emp-agmpc.h"
using namespace std;
using namespace emp;

const string circuit_file_location = macro_xstr(EMP_CIRCUIT_PATH);

const static int nP = 3;
int party, port;
void bench_once(NetIOMP<nP> * ios[2], ThreadPool * pool, string filename) {
if(party == 1)cout <<"CIRCUIT:\t"<<filename<<endl;
//string file = circuit_file_location+"/"+filename;
CircuitFile cf(filename.c_str());

auto start = clock_start();
CMPC<nP>* mpc = new CMPC<nP>(ios, pool, party, &cf);
ios[0]->flush();
ios[1]->flush();
double t2 = time_from(start);
// ios[0]->sync();
// ios[1]->sync();
if(party == 1)cout <<"Setup:\t"<<party<<"\t"<< t2 <<"\n"<<flush;

start = clock_start();
mpc->function_independent();
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
if(party == 1)cout <<"FUNC_IND:\t"<<party<<"\t"<<t2<<" \n"<<flush;

start = clock_start();
mpc->function_dependent();
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
if(party == 1)cout <<"FUNC_DEP:\t"<<party<<"\t"<<t2<<" \n"<<flush;

bool *in = new bool[cf.n1+cf.n2]; bool *out = new bool[cf.n3];
memset(in, false, cf.n1+cf.n2);
start = clock_start();
mpc->online(in, out);
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
// uint64_t band2 = io.count();
// if(party == 1)cout <<"bandwidth\t"<<party<<"\t"<<band2<<endl;
if(party == 1)cout <<"ONLINE:\t"<<party<<"\t"<<t2<<" \n"<<flush;
delete mpc;
}
int main(int argc, char** argv) {
parse_party_and_port(argv, &party, &port);
if(party > nP)return 0;
NetIOMP<nP> io(party, port);
#ifdef LOCALHOST
NetIOMP<nP> io2(party, port+2*(nP+1)*(nP+1)+1);
#else
NetIOMP<nP> io2(party, port+2*(nP+1));
#endif
NetIOMP<nP> *ios[2] = {&io, &io2};
ThreadPool pool(2*(nP-1)+2);

bench_once(ios, &pool, circuit_file_location+"sha-1.txt");
return 0;
}
64 changes: 64 additions & 0 deletions test/sha256.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <emp-tool/emp-tool.h>
#include "emp-agmpc/emp-agmpc.h"
using namespace std;
using namespace emp;

const string circuit_file_location = macro_xstr(EMP_CIRCUIT_PATH);

const static int nP = 3;
int party, port;
void bench_once(NetIOMP<nP> * ios[2], ThreadPool * pool, string filename) {
if(party == 1)cout <<"CIRCUIT:\t"<<filename<<endl;
//string file = circuit_file_location+"/"+filename;
CircuitFile cf(filename.c_str());

auto start = clock_start();
CMPC<nP>* mpc = new CMPC<nP>(ios, pool, party, &cf);
ios[0]->flush();
ios[1]->flush();
double t2 = time_from(start);
// ios[0]->sync();
// ios[1]->sync();
if(party == 1)cout <<"Setup:\t"<<party<<"\t"<< t2 <<"\n"<<flush;

start = clock_start();
mpc->function_independent();
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
if(party == 1)cout <<"FUNC_IND:\t"<<party<<"\t"<<t2<<" \n"<<flush;

start = clock_start();
mpc->function_dependent();
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
if(party == 1)cout <<"FUNC_DEP:\t"<<party<<"\t"<<t2<<" \n"<<flush;

bool *in = new bool[cf.n1+cf.n2]; bool *out = new bool[cf.n3];
memset(in, false, cf.n1+cf.n2);
start = clock_start();
mpc->online(in, out);
ios[0]->flush();
ios[1]->flush();
t2 = time_from(start);
// uint64_t band2 = io.count();
// if(party == 1)cout <<"bandwidth\t"<<party<<"\t"<<band2<<endl;
if(party == 1)cout <<"ONLINE:\t"<<party<<"\t"<<t2<<" \n"<<flush;
delete mpc;
}
int main(int argc, char** argv) {
parse_party_and_port(argv, &party, &port);
if(party > nP)return 0;
NetIOMP<nP> io(party, port);
#ifdef LOCALHOST
NetIOMP<nP> io2(party, port+2*(nP+1)*(nP+1)+1);
#else
NetIOMP<nP> io2(party, port+2*(nP+1));
#endif
NetIOMP<nP> *ios[2] = {&io, &io2};
ThreadPool pool(2*(nP-1)+2);

bench_once(ios, &pool, circuit_file_location+"sha-256.txt");
return 0;
}

0 comments on commit 5f25a4b

Please sign in to comment.