Skip to content

Commit

Permalink
clearing...
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrieu committed Mar 17, 2018
1 parent ac30376 commit dcc6cec
Show file tree
Hide file tree
Showing 30 changed files with 2,057 additions and 330 deletions.
130 changes: 73 additions & 57 deletions CMakeLists.txt
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)

14 changes: 14 additions & 0 deletions ExternalDependancies.props
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>
18 changes: 5 additions & 13 deletions README.md
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`
171 changes: 171 additions & 0 deletions Tests/PSI_Tests.cpp
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;



}
}
10 changes: 10 additions & 0 deletions Tests/PSI_Tests.h
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();
}
6 changes: 3 additions & 3 deletions Tests/Tests.vcxproj.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)../libOTe;$(ProjectDir)../libOTe/cryptoTools/;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\boost\;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\;$(ProjectDir)../libOTe/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/miracl</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)../libOTe;$(ProjectDir)../libOTe/cryptoTools/;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\boost\;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\;$(ProjectDir)../libOTe/cryptoTools/thirdparty/win/miracl;C:/libs/boost;C:/libs/;C:/libs/miracl;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\NTL\;C:/libs/NTL;C:/libs/NTL/include;$(ProjectDir)../libOTe/cryptoTools/thirdparty\win\NTL\include;$(SolutionDir)/libPSI;$(SolutionDir)/libPSI/</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
Expand Down Expand Up @@ -79,7 +79,7 @@
<ClCompile Include="BaseOT_Tests.cpp" />
<ClCompile Include="Common.cpp" />
<ClCompile Include="NcoOT_Tests.cpp" />
<ClCompile Include="nOPRF_Tests.cpp" />
<ClCompile Include="PSI_Tests.cpp" />
<ClCompile Include="OTOracleReceiver.cpp" />
<ClCompile Include="OTOracleSender.cpp" />
<ClCompile Include="OT_Tests.cpp" />
Expand All @@ -90,7 +90,7 @@
<ClInclude Include="BaseOT_Tests.h" />
<ClInclude Include="Common.h" />
<ClInclude Include="NcoOT_Tests.h" />
<ClInclude Include="nOPRF_Tests.h" />
<ClInclude Include="PSI_Tests.h" />
<ClInclude Include="OTOracleReceiver.h" />
<ClInclude Include="OTOracleSender.h" />
<ClInclude Include="OT_Tests.h" />
Expand Down
Loading

0 comments on commit dcc6cec

Please sign in to comment.