forked from osu-crypto/SpOT-PSI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,057 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,87 @@ | ||
cmake_minimum_required (VERSION 2.8) | ||
|
||
project(main) | ||
|
||
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") | ||
|
||
############################################ | ||
# If top level cmake # | ||
############################################ | ||
|
||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) | ||
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) | ||
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) | ||
|
||
############################################ | ||
# Flag and #defines # | ||
############################################ | ||
add_definitions(-DSOLUTION_DIR=\"${CMAKE_SOURCE_DIR}\") | ||
set(CMAKE_C_FLAGS "-ffunction-sections -Wall -maes -msse2 -msse4.1 -mpclmul -Wfatal-errors -pthread -Wno-strict-overflow -fPIC -Wno-ignored-attributes") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14") | ||
|
||
# Select flags. | ||
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") | ||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -g -ggdb -rdynamic") | ||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -rdynamic") | ||
|
||
############################################ | ||
# Build mode checks # | ||
############################################ | ||
|
||
# Set a default build type for single-configuration | ||
# CMake generators if no build type is set. | ||
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) | ||
SET(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") | ||
message(WARNING "\nConfiguration NOT set to Release. Please call cmake with -DCMAKE_BUILD_TYPE=Release instead of ${CMAKE_BUILD_TYPE}") | ||
|
||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | ||
#message(WARNING "Debug build.") | ||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") | ||
#message(WARNING "Release build.") | ||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO") | ||
#message(WARNING "RELWITHDEBINFO=Release with debug info build.") | ||
else() | ||
message(ERROR ": Unknown build type - ${CMAKE_BUILD_TYPE} Please use one of Debug, Release, or RELWITHDEBINFO\n\n" ) | ||
endif() | ||
endif() | ||
cmake_minimum_required (VERSION 3.6) | ||
|
||
project("libPSI") | ||
|
||
|
||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) | ||
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) | ||
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib) | ||
|
||
|
||
############################################# | ||
# Flag and #defines # | ||
############################################# | ||
add_definitions(-DSOLUTION_DIR=\"${CMAKE_SOURCE_DIR}\") | ||
set(CMAKE_C_FLAGS "-ffunction-sections -Wall -Wno-strict-aliasing -maes -msse2 -msse4.1 -mpclmul -Wno-sign-compare -Wfatal-errors -pthread") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14") | ||
|
||
# Set a default build type for single-configuration | ||
# CMake generators if no build type is set. | ||
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) | ||
SET(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
|
||
|
||
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") | ||
message(WARNING "\nConfiguration NOT set to Release. Please call cmake with -DCMAKE_BUILD_TYPE=Release instead of ${CMAKE_BUILD_TYPE}") | ||
|
||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | ||
#message(WARNING "Debug build.") | ||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") | ||
#message(WARNING "Release build.") | ||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO") | ||
#message(WARNING "RELWITHDEBINFO=Release with debug info build.") | ||
else() | ||
message(ERROR ": Unknown build type - ${CMAKE_BUILD_TYPE} Please use one of Debug, Release, or RELWITHDEBINFO\n\n" ) | ||
endif() | ||
endif() | ||
|
||
|
||
# Select flags. | ||
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") | ||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -ggdb -rdynamic") | ||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb -rdynamic") | ||
|
||
|
||
############################################# | ||
# Library/includes locations # | ||
############################################# | ||
|
||
include_directories("${CMAKE_SOURCE_DIR}") | ||
|
||
# default location for libOTe | ||
set(libOTe_Dirs "${CMAKE_SOURCE_DIR}/libOTe/") | ||
include_directories("${libOTe_Dirs}/") | ||
include_directories("${libOTe_Dirs}/cryptoTools") | ||
|
||
# default location for miracl | ||
set(Miracl_Dirs "${libOTe_Dirs}/cryptoTools/thirdparty/linux/miracl/") | ||
include_directories("${Miracl_Dirs}") | ||
|
||
# default location for NTL | ||
set(NTL_Dirs "${CMAKE_SOURCE_DIR}/thirdparty/linux/ntl/") | ||
include_directories("${NTL_Dirs}/include/") | ||
|
||
# default location for Boost | ||
set(BOOST_ROOT "${libOTe_Dirs}/cryptoTools/thirdparty/linux/boost/") | ||
|
||
|
||
############################################# | ||
# Build cryptoTools (common utilities) # | ||
# Build libPSI # | ||
############################################# | ||
#include_directories(cryptoTools) | ||
add_subdirectory(libOTe/cryptoTools) | ||
add_subdirectory(libPSI) | ||
include_directories(libPSI) | ||
|
||
|
||
############################################# | ||
# Build libOTe # | ||
# Build libPSI Tests # | ||
############################################# | ||
include_directories(libOTe) | ||
add_subdirectory(libOTe/libOTe) | ||
add_subdirectory(Tests) | ||
include_directories(Tests) | ||
|
||
|
||
############################################# | ||
# Build Frontend # | ||
############################################# | ||
add_subdirectory(frontend) | ||
add_subdirectory(frontend) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ImportGroup Label="PropertySheets" /> | ||
<PropertyGroup Label="UserMacros"> | ||
<libOTeDir>$(SolutionDir)../libOTe</libOTeDir> | ||
</PropertyGroup> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup /> | ||
<ItemGroup> | ||
<BuildMacro Include="libOTeDir"> | ||
<Value>$(libOTeDir)</Value> | ||
</BuildMacro> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
# install libraries for libOTe | ||
### Windows | ||
|
||
git submodule update --init --recursive | ||
First clone and build libOTe which should share the same parent directory. Then clone this library and open the solution in Visaul Studio. | ||
|
||
cd libOTe/cryptoTools/thirdparty/linux | ||
### Linux | ||
|
||
bash all.get | ||
|
||
libOTe, should share the same parent directory. | ||
|
||
# build this project | ||
|
||
cmake -G "Unix Makefiles" | ||
|
||
make | ||
|
||
# execute | ||
|
||
./bin/frontend | ||
ntl should build in `prtyPSI/thirdparty/linux/ntl` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
#include "PSI_Tests.h" | ||
#include "OT_Tests.h" | ||
|
||
#include "libOTe/TwoChooseOne/OTExtInterface.h" | ||
|
||
#include "libOTe/Tools/Tools.h" | ||
#include "libOTe/Tools/LinearCode.h" | ||
#include <cryptoTools/Network/Channel.h> | ||
#include <cryptoTools/Network/Endpoint.h> | ||
#include <cryptoTools/Network/IOService.h> | ||
#include <cryptoTools/Common/Log.h> | ||
|
||
#include "libOTe/TwoChooseOne/IknpOtExtReceiver.h" | ||
#include "libOTe/TwoChooseOne/IknpOtExtSender.h" | ||
|
||
#include "libOTe/TwoChooseOne/KosOtExtReceiver.h" | ||
#include "libOTe/TwoChooseOne/KosOtExtSender.h" | ||
|
||
#include "libOTe/TwoChooseOne/LzKosOtExtReceiver.h" | ||
#include "libOTe/TwoChooseOne/LzKosOtExtSender.h" | ||
|
||
#include "libOTe/TwoChooseOne/KosDotExtReceiver.h" | ||
#include "libOTe/TwoChooseOne/KosDotExtSender.h" | ||
|
||
#include "libOTe/NChooseOne/Kkrt/KkrtNcoOtReceiver.h" | ||
#include "libOTe/NChooseOne/Kkrt/KkrtNcoOtSender.h" | ||
#include "Poly/polyNTL.h" | ||
#include "PsiDefines.h" | ||
|
||
#include "PRTY/PrtySender.h" | ||
#include "PRTY/PrtyReceiver.h" | ||
#include "Tools/SimpleIndex.h" | ||
|
||
#include "Common.h" | ||
#include <thread> | ||
#include <vector> | ||
|
||
#ifdef GetMessage | ||
#undef GetMessage | ||
#endif | ||
|
||
#ifdef _MSC_VER | ||
#pragma warning(disable: 4800) | ||
#endif // _MSC_VER | ||
|
||
|
||
using namespace osuCrypto; | ||
|
||
namespace tests_libOTe | ||
{ | ||
inline void sse_trans(uint8_t *inp, int nrows, int ncols) { | ||
# define INP(x,y) inp[(x)*ncols/8 + (y)/8] | ||
# define OUT(x,y) inp[(y)*nrows/8 + (x)/8] | ||
int rr, cc, i, h; | ||
union { __m128i x; uint8_t b[16]; } tmp; | ||
__m128i vec; | ||
assert(nrows % 8 == 0 && ncols % 8 == 0); | ||
|
||
// Do the main body in 16x8 blocks: | ||
for (rr = 0; rr <= nrows - 16; rr += 16) { | ||
for (cc = 0; cc < ncols; cc += 8) { | ||
vec = _mm_set_epi8( | ||
INP(rr + 15, cc), INP(rr + 14, cc), INP(rr + 13, cc), INP(rr + 12, cc), INP(rr + 11, cc), INP(rr + 10, cc), INP(rr + 9, cc), | ||
INP(rr + 8, cc), INP(rr + 7, cc), INP(rr + 6, cc), INP(rr + 5, cc), INP(rr + 4, cc), INP(rr + 3, cc), INP(rr + 2, cc), INP(rr + 1, cc), | ||
INP(rr + 0, cc)); | ||
for (i = 8; --i >= 0; vec = _mm_slli_epi64(vec, 1)) | ||
*(uint16_t*)&OUT(rr, cc + i) = _mm_movemask_epi8(vec); | ||
} | ||
} | ||
if (rr == nrows) return; | ||
|
||
// The remainder is a block of 8x(16n+8) bits (n may be 0). | ||
// Do a PAIR of 8x8 blocks in each step: | ||
for (cc = 0; cc <= ncols - 16; cc += 16) { | ||
vec = _mm_set_epi16( | ||
*(uint16_t const*)&INP(rr + 7, cc), *(uint16_t const*)&INP(rr + 6, cc), | ||
*(uint16_t const*)&INP(rr + 5, cc), *(uint16_t const*)&INP(rr + 4, cc), | ||
*(uint16_t const*)&INP(rr + 3, cc), *(uint16_t const*)&INP(rr + 2, cc), | ||
*(uint16_t const*)&INP(rr + 1, cc), *(uint16_t const*)&INP(rr + 0, cc)); | ||
for (i = 8; --i >= 0; vec = _mm_slli_epi64(vec, 1)) { | ||
OUT(rr, cc + i) = h = _mm_movemask_epi8(vec); | ||
OUT(rr, cc + i + 8) = h >> 8; | ||
} | ||
} | ||
if (cc == ncols) return; | ||
|
||
// Do the remaining 8x8 block: | ||
for (i = 0; i < 8; ++i) | ||
tmp.b[i] = INP(rr + i, cc); | ||
for (i = 8; --i >= 0; tmp.x = _mm_slli_epi64(tmp.x, 1)) | ||
OUT(rr, cc + i) = _mm_movemask_epi8(tmp.x); | ||
#undef INP | ||
#undef OUT | ||
} | ||
|
||
void OT_Receive_Test(BitVector& choiceBits, gsl::span<block> recv, gsl::span<std::array<block, 2>> sender) | ||
{ | ||
|
||
for (u64 i = 0; i < choiceBits.size(); ++i) | ||
{ | ||
|
||
u8 choice = choiceBits[i]; | ||
const block & revcBlock = recv[i]; | ||
//(i, choice, revcBlock); | ||
const block& senderBlock = sender[i][choice]; | ||
|
||
//if (i%512==0) { | ||
// std::cout << "[" << i << ",0]--" << sender[i][0] << std::endl; | ||
// std::cout << "[" << i << ",1]--" << sender[i][1] << std::endl; | ||
// std::cout << (int)choice << "-- " << recv[i] << std::endl; | ||
//} | ||
if (neq(revcBlock, senderBlock)) | ||
throw UnitTestFail(); | ||
|
||
if (eq(revcBlock, sender[i][1 ^ choice])) | ||
throw UnitTestFail(); | ||
} | ||
|
||
} | ||
|
||
void Hashing_Test_Impl() | ||
{ | ||
setThreadName("Sender"); | ||
u64 setSize = 1<<8, psiSecParam = 40, numThreads(2); | ||
|
||
PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045)); | ||
|
||
|
||
std::vector<block> set(setSize); | ||
for (u64 i = 0; i < set.size(); ++i) | ||
set[i] = prng.get<block>(); | ||
|
||
SimpleIndex simple; | ||
simple.init(setSize); | ||
simple.insertItems(set,numThreads); | ||
simple.print(); | ||
|
||
} | ||
|
||
void myTest() { | ||
BitVector a(2); | ||
a[0] = 1; | ||
a[1] = 0; | ||
|
||
PRNG prng0(_mm_set_epi32(4253465, 3434565, 234435, 23987045)); | ||
|
||
u8 aa=a[0] ^ a[1]; | ||
std::cout << unsigned(aa) << std::endl; | ||
std::cout << sizeof(u8) << std::endl; | ||
|
||
|
||
block temp = prng0.get<block>(); | ||
|
||
u64 b1 = _mm_extract_epi64(temp, 0); | ||
u64 b2 = _mm_extract_epi64(temp, 1); | ||
//u64 b2 = *(u64*)(&temp + sizeof(u64)); | ||
|
||
block aa2 = toBlock(b1, b2); | ||
|
||
std::cout << temp << std::endl; | ||
|
||
|
||
std::cout << aa2 << std::endl; | ||
aa2 = toBlock(b2, b1); | ||
|
||
std::cout << aa2 << std::endl; | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use. | ||
|
||
namespace tests_libOTe | ||
{ | ||
void Hashing_Test_Impl(); | ||
void NTL_Poly_Test_Impl(); | ||
void myTest(); | ||
void seft_balance(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.