Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiao1254 committed Aug 8, 2020
2 parents 7c6dba7 + 4664d53 commit a256f53
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
1. Install prerequisites using instructions [here](https://github.com/emp-toolkit/emp-readme#detailed-installation).
2. `git clone https://github.com/emp-toolkit/emp-tool.git`
3. `cd emp-tool && cmake . && sudo make install`
1. Alternatively, you can also `cd emp-ot && mkdir -p build && cd build && cmake .. && sudo make install` if out-of-source build is preferred.
1. Alternatively, you can `cd emp-tool && mkdir -p build && cd build && cmake .. && sudo make install` if out-of-source build is preferred.
2. By default it will build for Release. `-DCMAKE_BUILD_TYPE=[Release|Debug]` option is also available.
3. No sudo? change [`CMAKE_INSTALL_PREFIX`](https://cmake.org/cmake/help/v2.8.8/cmake.html#variable%3aCMAKE_INSTALL_PREFIX)
3. No sudo? Change [`CMAKE_INSTALL_PREFIX`](https://cmake.org/cmake/help/v2.8.8/cmake.html#variable%3aCMAKE_INSTALL_PREFIX).

# Performance

Expand Down
15 changes: 4 additions & 11 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(NOT DEFINED OPENSSL_ROOT_DIR)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
message(STATUS "OPENSSL_ROOT_DIR set to default: ${OPENSSL_ROOT_DIR}")
endif()
endif()

if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
Expand Down Expand Up @@ -40,10 +33,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

#Compilation flags
set(CMAKE_C_FLAGS "-pthread -Wall -march=native -O3 -maes -mrdseed -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-pthread -Wall -march=native -maes -mrdseed -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -ggdb -O0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")

## Build type
if(NOT CMAKE_BUILD_TYPE)
Expand Down
28 changes: 14 additions & 14 deletions cmake/enable_rdseed.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
OPTION(ENABLE_RDSEED "Use RDSEED for True Randomness" ON)
OPTION(USE_RANDOM_DEVICE "Option description" OFF)

include(CheckCSourceRuns)

# Use rdseed if available
unset(RDSEED_COMPILE_RESULT CACHE)
unset(RDSEED_RUN_RESULT CACHE)
file(WRITE ${CMAKE_SOURCE_DIR}/rdseedtest.c "#include <stdio.h>\n#include <x86intrin.h>\nint main(){\nunsigned long long r;\n_rdseed64_step(&r);\nreturn 0;\n}\n")
try_run(RDSEED_RUN_RESULT RDSEED_COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/rdseedtest.c CMAKE_FLAGS ${CMAKE_C_FLAGS})
file(REMOVE ${CMAKE_SOURCE_DIR}/rdseedtest.c)
string(COMPARE EQUAL "${RDSEED_RUN_RESULT}" "0" RDSEED_RUN_SUCCESS)
set(CMAKE_REQUIRED_FLAGS "-mrdseed") # in case CMAKE_C_FLAGS doesn't have it, ex. if add_compile_options is used instead
check_c_source_runs("#include <x86intrin.h>\nint main(){\nunsigned long long r;\n_rdseed64_step(&r);\nreturn 0;\n}\n" RDSEED_RUN_RESULT)

IF(NOT ${RDSEED_COMPILE_RESULT} OR NOT ${RDSEED_RUN_SUCCESS})
set(ENABLE_RDSEED OFF)
ENDIF(NOT ${RDSEED_COMPILE_RESULT} OR NOT ${RDSEED_RUN_SUCCESS})
string(COMPARE EQUAL "${RDSEED_RUN_RESULT}" "1" RDSEED_RUN_SUCCESS)
IF(NOT ${RDSEED_RUN_SUCCESS})
set(USE_RANDOM_DEVICE ON)
ENDIF(NOT ${RDSEED_RUN_SUCCESS})

IF(${ENABLE_RDSEED})
ADD_DEFINITIONS(-DEMP_ENABLE_RDSEED)
message("${Green}-- Source of Randomness: rdseed${ColourReset}")
ELSE(${ENABLE_RDSEED})
IF(${USE_RANDOM_DEVICE})
ADD_DEFINITIONS(-DEMP_USE_RANDOM_DEVICE)
message("${Red}-- Source of Randomness: random_device${ColourReset}")
ENDIF(${ENABLE_RDSEED})

ELSE(${USE_RANDOM_DEVICE})
message("${Green}-- Source of Randomness: rdseed${ColourReset}")
ENDIF(${USE_RANDOM_DEVICE})
38 changes: 21 additions & 17 deletions emp-tool/circuits/integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,37 @@ inline const Bit &Integer::operator[](int index) const {
}

template<>
inline int32_t Integer::reveal<int32_t>(int party) const {
bool b[32];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), 32);
return bool_to_int<int32_t>(b);
inline uint32_t Integer::reveal<uint32_t>(int party) const {
std::bitset<32> bs;
bs.reset();
bool b[size()];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), size());
for (int i = 0; i < min(32, size()); ++i)
bs.set(i, b[i]);
return bs.to_ulong();
}

template<>
inline int64_t Integer::reveal<int64_t>(int party) const {
bool b[64];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), 64);
return bool_to_int<int64_t>(b);
inline uint64_t Integer::reveal<uint64_t>(int party) const {
std::bitset<64> bs;
bs.reset();
bool b[size()];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), size());
for (int i = 0; i < min(64, size()); ++i)
bs.set(i, b[i]);
return bs.to_ullong();
}

template<>
inline uint32_t Integer::reveal<uint32_t>(int party) const {
bool b[32];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), 32);
return bool_to_int<uint32_t>(b);
inline int32_t Integer::reveal<int32_t>(int party) const {
return reveal<uint32_t>(party);
}

template<>
inline uint64_t Integer::reveal<uint64_t>(int party) const {
bool b[64];
ProtocolExecution::prot_exec->reveal(b, party, (block *)bits.data(), 64);
return bool_to_int<uint64_t>(b);
inline int64_t Integer::reveal<int64_t>(int party) const {
return reveal<uint64_t>(party);
}


template<>
inline string Integer::reveal<string>(int party) const {
bool * b = new bool[size()];
Expand Down
4 changes: 2 additions & 2 deletions emp-tool/io/net_io_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class NetIO: public IOChannel<NetIO> { public:
}

~NetIO(){
fflush(stream);
close(consocket);
flush();
fclose(stream);
delete[] buffer;
}

Expand Down
8 changes: 4 additions & 4 deletions test/float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ void test_float(double precision, int runs = 1000) {

if(precision > 0.0) {
if (not accurate(res.reveal<double>(PUBLIC), Op()(da,db), precision)) {
cout << "Inaccuracy:\t"<<typeid(Op2).name()<<"\t"<< da <<"\t"<<db<<"\t"<<Op()(da,db)<<"\t"<<res.reveal<double>(PUBLIC)<<endl<<flush;
cout << "Inaccuracy:\t"<<typeid(Op2).name()<<"\t"<< da <<"\t"<<db<<"\t"<<Op()(da,db)<<"\t"<<res.reveal<double>(PUBLIC)<<endl;
}
} else {
if (not equal(res, Op()(da,db))) {
cout << "Inaccuracy:\t"<<typeid(Op2).name()<<"\t"<< da <<"\t"<<db<<"\t"<<Op()(da,db)<<"\t"<<res.reveal<double>(PUBLIC)<<endl<<flush;
cout << "Inaccuracy:\t"<<typeid(Op2).name()<<"\t"<< da <<"\t"<<db<<"\t"<<Op()(da,db)<<"\t"<<res.reveal<double>(PUBLIC)<<endl;
}
}
}
Expand Down Expand Up @@ -107,12 +107,12 @@ void test_float(int func_id, double precision, double minimize, int runs = 1000)
}
if(precision == 0.0) {
if (not equal(res, comp)) {
cout << "Inaccuracy:\t"<<da<<"\t"<<"\t"<<comp<<"\t"<<res.reveal<double>(PUBLIC)<<endl<<flush;
cout << "Inaccuracy:\t"<<da<<"\t"<<"\t"<<comp<<"\t"<<res.reveal<double>(PUBLIC)<<endl;
rate_cnt++;
}
} else {
if (not accurate(res.reveal<double>(PUBLIC), comp, precision)) {
cout << "Inaccuracy:\t"<<da<<"\t"<<"\t"<<comp<<"\t"<<res.reveal<double>(PUBLIC)<<endl<<flush;
cout << "Inaccuracy:\t"<<da<<"\t"<<"\t"<<comp<<"\t"<<res.reveal<double>(PUBLIC)<<endl;
rate_cnt++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void test_int(int party, int range1 = 1<<25, int range2 = 1<<25, int runs = 1000

if (res.reveal<int32_t>(PUBLIC) != Op()(ia,ib)) {
cout << a.reveal<int32_t>()<<endl;
cout << ia <<"\t"<<ib<<"\t"<<Op()(ia,ib)<<"\t"<<res.reveal<int32_t>(PUBLIC)<<endl<<flush;
cout << ia <<"\t"<<ib<<"\t"<<Op()(ia,ib)<<"\t"<<res.reveal<int32_t>(PUBLIC)<<endl;
}
assert(res.reveal<int32_t>(PUBLIC) == Op()(ia,ib));
}
Expand Down

0 comments on commit a256f53

Please sign in to comment.