Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile for compiling the library #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
FROM ubuntu:latest

#################################################
# Install system dependencies.
#################################################

RUN apt-get -y update
RUN apt-get -y install cmake
RUN apt-get -y install wget
RUN apt-get -y install build-essential
RUN apt-get -y install m4
RUN apt-get -y install git

WORKDIR /paxos

#################################################
# Install local dependencies.
#################################################

COPY thirdparty/ /paxos/thirdparty/
RUN cd thirdparty/linux && bash gmp.get
RUN cd thirdparty/linux && bash gf2x.get
RUN cd thirdparty/linux && bash ntl.get

#################################################
# Build libOTe.
#################################################

COPY libOTe/ /paxos/libOTe/
RUN cd libOTe/cryptoTools/thirdparty/linux/ && bash boost.get
RUN cd libOTe/cryptoTools/thirdparty/linux/ && bash miracl.get
RUN cd libOTe && cmake . -DCMAKE_BUILD_TYPE=Release && make

#################################################
# Build libSCAPI.
#################################################

RUN apt-get install -y libssl-dev libgmp3-dev liblog4cpp5-dev zlib1g-dev
RUN cd $HOME && git clone https://github.com/cryptobiu/libscapi.git
# Use the same commit as the PaXoS experiments.
RUN cd $HOME/libscapi && git checkout 3505b6f4d9ee8382ac3ffe43bf0cef16e27add65
# Remove libscapi's packaged versions of NTL and libOTe, and instead link in our versions.
RUN rm -rf $HOME/libscapi/lib/NTL $HOME/libscapi/lib/libOTe
RUN ln -s /paxos/thirdparty/linux/ntl $HOME/libscapi/lib/NTL
RUN ln -s /paxos/libOTe $HOME/libscapi/lib/libOTe
# Copy libraries to where libscapi's build files expect them.
RUN cp $HOME/libscapi/lib/NTL/src/libntl.a $HOME/libscapi/lib/NTL/src/ntl.a
RUN mkdir -p $HOME/libscapi/lib/libOTe/cryptoTools/thirdparty/miracl/source/
RUN cp -r $HOME/libscapi/lib/libOTe/cryptoTools/thirdparty/linux/miracl/miracl/source/libmiracl.a $HOME/libscapi/lib/libOTe/cryptoTools/thirdparty/miracl/source/
# Build the remaining libraries.
RUN cd $HOME/libscapi && make libs
# Build libscapi, passing in the path to libOTe's version of Boost.
RUN cd $HOME/libscapi && rm makefile && cmake . -DCMAKE_CXX_FLAGS=-I/paxos/libOTe/cryptoTools/thirdparty/linux/boost/ && make scapi -j32

#################################################
# Build linbox.
#################################################

RUN apt-get -y install pkg-config
RUN apt-get -y install libopenblas-dev
RUN wget https://raw.githubusercontent.com/linbox-team/linbox/master/linbox-auto-install.sh
# Install NTL. Since NTL is built with GMP's directory as the prefix, this will install it into /paxos/thirdparty/linux/gmp/.
RUN cd thirdparty/linux/ntl/src && make install
# Fetch and build linbox.
RUN bash linbox-auto-install.sh --stable=yes --with-ntl=/paxos/thirdparty/linux/gmp/ --with-blas-libs="-lopenblas" --make-flags=-j32 --prefix=/usr

#################################################
# Build libxxhash.
#################################################

COPY frontend/ /paxos/frontend/
RUN cd frontend/xxHash/cmake_unofficial && cmake . -DCMAKE_BUILD_TYPE=Release && make

#################################################
# Compile PSI library.
#################################################

COPY libPSI/ /paxos/libPSI/
COPY CMakeLists.txt /paxos/
RUN cmake . -DCMAKE_BUILD_TYPE=Release && make -j32
6 changes: 3 additions & 3 deletions frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ file(GLOB_RECURSE SRC_FRONTEND ${CMAKE_SOURCE_DIR}/frontend/*.cpp)
include_directories(${CMAKE_SOURCE_DIR}/frontend/ $ENV{HOME} xxHash ${CMAKE_SOURCE_DIR}/libOTe
${CMAKE_SOURCE_DIR}/libOTe/cryptoTools/cryptoTools ${CMAKE_SOURCE_DIR}/libOTe/cryptoTools/cryptoTools/Crypto)

add_executable(frontend.exe ${SRC_FRONTEND})
add_executable(frontend ${SRC_FRONTEND})


#############################################
Expand All @@ -41,6 +41,6 @@ find_library(
NAMES tests_cryptoTools
HINTS "${libOTe_Dirs}/lib/")

target_link_libraries(frontend.exe libPSI libboost_system.a
$ENV{HOME}/PaXoS_PSI_New/frontend/xxHash/cmake_unofficial/libxxhash.so givaro blas linbox iml libntl.a gmp
target_link_libraries(frontend libPSI ${Boost_LIBRARIES}
${CMAKE_SOURCE_DIR}/frontend/xxHash/cmake_unofficial/libxxhash.so givaro blas gomp linbox ${CMAKE_SOURCE_DIR}/thirdparty/linux/ntl/src/libntl.a gmp
$ENV{HOME}/libscapi/libscapi.a crypto)
95 changes: 68 additions & 27 deletions frontend/ProtocolParty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//

#include "ProtocolParty.h"
#include "cryptoTools/Crypto/RandomOracle.h"
#include "libOTe/Base/naor-pinkas.h"

ProtocolParty::ProtocolParty(int argc, char* argv[]) : Protocol("PSI", argc, argv)
{
Expand All @@ -26,6 +28,19 @@ ProtocolParty::ProtocolParty(int argc, char* argv[]) : Protocol("PSI", argc, arg
isMalicious = stoi(this->getParser().getValueByKey(arguments, "malicious")) == 0 ? false : true;
otherParty = comm.setCommunication(io_service, partyId, 2, partiesFile)[0];

if (isMalicious)
{
bytesPerHash = 256 / 8;
}
else
{
bytesPerHash = (40 + 2 * std::log2(hashSize) + 7 ) / 8;

// some logic requires at least 8 bytes.
if (bytesPerHash < 8)
bytesPerHash = 8;
}

ConfigFile cf(partiesFile);

string portString, ipString;
Expand Down Expand Up @@ -66,6 +81,8 @@ ProtocolParty::ProtocolParty(int argc, char* argv[]) : Protocol("PSI", argc, arg
keys.resize(hashSize);
vals.resize(hashSize*fieldSizeBytes);

xors2.resize(hashSize, bytesPerHash);


// auto key = prg.generateKey(128);
prg = PrgFromOpenSSLAES(hashSize*fieldSizeBytes*2);
Expand Down Expand Up @@ -320,12 +337,14 @@ void Receiver::runOOS(){
std::vector<std::array<block, 2>> baseSend(baseCount);
BitVector baseChoice(baseCount);
baseChoice.randomize(prng0);
prng0.get((u8*)baseSend.data()->data(), sizeof(block) * 2 * baseSend.size());
for (u64 i = 0; i < baseCount; ++i)
{
baseRecv[i] = baseSend[i][baseChoice[i]];
}

//prng0.get((u8*)baseSend.data()->data(), sizeof(block) * 2 * baseSend.size());
//for (u64 i = 0; i < baseCount; ++i)
//{
// baseRecv[i] = baseSend[i][baseChoice[i]];
//}

oc::NaorPinkas base;
base.send(baseSend, prng0, recvChl);
recv.setBaseOts(baseSend);

vector<byte> sigma;
Expand All @@ -343,6 +362,8 @@ void Receiver::runOOS(){
}
recv.sendCorrection(recvChl, curStepSize);
}

std::cout << "sent OT matrix, " << sizeof(block) * recv.mT1.size() << " = " << recv.mT1.rows() << " x " << sizeof(block) * recv.mT1.stride() << std::endl;
}

void Receiver::computeXors(){
Expand All @@ -351,13 +372,14 @@ void Receiver::computeXors(){
int blockSize = baseCount/128;

vector<block> output(blockSize);
vector<byte> temp(blockSize*16);
vector<byte> temp(xors2.stride());
int size;



vector<int> indices(gamma+2);
int indicesSize;
oc::RandomOracle ro(xors2.stride());

// cout<<"Xors:"<<endl;
for (int i=0; i<hashSize; i++){
Expand All @@ -375,7 +397,11 @@ void Receiver::computeXors(){
}


EVP_EncryptUpdate(aes, temp.data(), &size, (byte*)output.data(), blockSize*16);
//EVP_EncryptUpdate(aes, temp.data(), &size, (byte*)output.data(), blockSize*16);
ro.Reset();
ro.Update((byte*)output.data(), blockSize * 16);
ro.Final((byte*)temp.data());

xorsSet.insert(((uint64_t*)temp.data())[0]);

// for (int j=0; j<20;j++){
Expand All @@ -389,27 +415,32 @@ void Receiver::computeXors(){

}

void Receiver::receiveSenderXors(){
std::vector<u64> Receiver::receiveSenderXors(){

uint64_t size;
uint64_t size, bytesPer;
otherParty->getChannel()->read((byte*)&size, 8);
otherParty->getChannel()->read((byte*)&bytesPer, 8);


vector<uint64_t> senderOutputs(size);
otherParty->getChannel()->read((byte*)senderOutputs.data(), size*8);

//vector<uint64_t> senderOutputs(size);
oc::Matrix<byte> senderOutputs(size, bytesPer);
otherParty->getChannel()->read((byte*)senderOutputs.data(), senderOutputs.size());

std::vector<u64> ret;
uint64_t count = 0;
for (int i=0; i<hashSize; i++){
if (xorsSet.find(senderOutputs[i]) != xorsSet.end()){
//auto val =
uint64_t vv = *(uint64_t*)senderOutputs[i].data();
if (xorsSet.find(vv) != xorsSet.end()){
count++;
ret.push_back(i);
// cout<<"element "<<i<<" is in the intersection"<<endl;
}
}

cout<<"found "<<count<<" matches"<<endl;


return ret;
}


Expand Down Expand Up @@ -460,7 +491,6 @@ void Receiver::checkVariables(vector<byte> & variables){


Sender::Sender(int argc, char *argv[]) : ProtocolParty(argc, argv){
xors.resize(hashSize);
}

Sender::~Sender() {
Expand Down Expand Up @@ -518,11 +548,15 @@ void Sender::runOOS(){
std::vector<std::array<block, 2>> baseSend(baseCount);
baseChoice.resize(baseCount);
baseChoice.randomize(prng0);
prng0.get((u8*)baseSend.data()->data(), sizeof(block) * 2 * baseSend.size());
for (u64 i = 0; i < baseCount; ++i)
{
baseRecv[i] = baseSend[i][baseChoice[i]];
}
//prng0.get((u8*)baseSend.data()->data(), sizeof(block) * 2 * baseSend.size());
//for (u64 i = 0; i < baseCount; ++i)
//{
// baseRecv[i] = baseSend[i][baseChoice[i]];
//}


oc::NaorPinkas base;
base.receive(baseChoice, baseRecv, prng0, sendChl);

sender.setBaseOts(baseRecv, baseChoice);

Expand Down Expand Up @@ -552,7 +586,7 @@ void Sender::computeXors(){
int size;
vector<int> indices(gamma+2);
int indicesSize;

oc::RandomOracle ro(xors2.stride());
for (int i=0; i<hashSize; i++){

indicesSize = dic->dec(keys[i], indices);
Expand All @@ -579,9 +613,12 @@ void Sender::computeXors(){
output[j] = _mm_xor_si128(output[j], codeword[j]);
}

EVP_EncryptUpdate(aes, temp.data(), &size, (byte*)output.data(), blockSize*16);

xors[i] = ((uint64_t*)temp.data())[0];
//EVP_EncryptUpdate(aes, temp.data(), &size, (byte*)output.data(), blockSize*16);
ro.Reset();
ro.Update((byte*)output.data(), blockSize * 16);
ro.Final((byte*)xors2[i].data());
//xors[i] = ((uint64_t*)temp.data())[0];
//memcpy(xors2[i].data(), temp.data(), blockSize * 16);
// for (int j=0; j<20;j++){
// cout<<(int)(((byte*)output.data())[j])<<" ";
// }
Expand All @@ -595,10 +632,14 @@ void Sender::computeXors(){

void Sender::sendXors(){

int64_t size = xors.size();
int64_t size = xors2.rows();
int64_t bytesPer = xors2.stride();

otherParty->getChannel()->write((byte*)&size, 8);
otherParty->getChannel()->write((byte*)xors.data(), size*8);
otherParty->getChannel()->write((byte*)&bytesPer, 8);
otherParty->getChannel()->write((byte*)xors2.data(), xors2.size());

std::cout << "sending final encoding, " << xors2.size() << " = " << size << " x " << bytesPer << std::endl;
}


9 changes: 5 additions & 4 deletions frontend/ProtocolParty.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cryptoTools/Network/Channel.h>
#include <cryptoTools/Network/Endpoint.h>
#include <cryptoTools/Common/Log.h>
#include <cryptoTools/Common/Matrix.h>

#include <libscapi/include/comm/MPCCommunication.hpp>
#include <libscapi/include/cryptoInfra/Protocol.hpp>
Expand All @@ -54,7 +55,7 @@ class ProtocolParty : public Protocol {
int partyId;
int times; //number of times to run the run function
int iteration; //number of the current iteration
int numOTs, tableRealSize, hashSize, fieldSize, fieldSizeBytes;
int numOTs, tableRealSize, hashSize, fieldSize, fieldSizeBytes, bytesPerHash;
int gamma;
bool isMalicious;

Expand All @@ -74,6 +75,8 @@ class ProtocolParty : public Protocol {

LinearCode code;

oc::Matrix<uint64_t> xors2;

public:

ProtocolParty(int argc, char *argv[]);
Expand Down Expand Up @@ -107,7 +110,7 @@ private :
void computeXors();
void checkVariables(vector<byte> & variables);

void receiveSenderXors();
std::vector<u64> receiveSenderXors();
public:

Receiver(int argc, char *argv[]);
Expand All @@ -122,8 +125,6 @@ private :
BitVector baseChoice;


vector<uint64_t> xors;

void runOOS();

void computeXors();
Expand Down
2 changes: 1 addition & 1 deletion libOTe/cryptoTools/frontend_cryptoTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ file(GLOB_RECURSE SRCS *.cpp)
include_directories(${CMAKE_SOURCE_DIR})

add_executable(frontend_cryptoTools ${SRCS})
target_link_libraries(frontend_cryptoTools cryptoTools tests_cryptoTools libboost_system.a)
target_link_libraries(frontend_cryptoTools cryptoTools tests_cryptoTools ${Boost_LIBRARIES})
1 change: 0 additions & 1 deletion libOTe/cryptoTools/thirdparty/linux/miracl
Submodule miracl deleted from 93b661
2 changes: 1 addition & 1 deletion libOTe/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ include_directories(${CMAKE_SOURCE_DIR})

add_executable(frontend_libOTe ${SRCS})

target_link_libraries(frontend_libOTe libOTe_Tests tests_cryptoTools libboost_system.a)
target_link_libraries(frontend_libOTe libOTe_Tests tests_cryptoTools ${Boost_LIBRARIES})