Skip to content

Commit

Permalink
hashing para + 2psi map
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrieu committed Aug 14, 2017
1 parent 27d81db commit d18d314
Show file tree
Hide file tree
Showing 17 changed files with 2,812 additions and 187 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For programmable OPRF, this code implements:
* Polynomial-based OPPRF
* BloomFilter-based OPPRF

For PSI, we implement 2-party PSI (2PSI) and multi-party PSI (nPSI) in augmented-semihonest model and standard semihonest model.
For PSI, we implement multi-party PSI (nPSI) in augmented-semihonest model and standard semihonest model.

## Installations

Expand Down Expand Up @@ -37,27 +37,17 @@ The database is generated randomly. The outputs include the average online/offli
#### Flags:
-u unit test which computes PSI of 5 paries, 2 dishonestly colluding, each with set size 2^12 in semihonest setting
-n number of parties
-p party ID
-p party ID
-m set size
-t number of corrupted parties (in semihonest setting)
-a run in augmented semihonest model. Table-based OPPRF is by default.
0: Table-based; 1: POLY-seperated; 2-POLY-combined; 3-BloomFilter
-r optimized 3PSI when r = 1
-r optimized 3PSI when r = 1
#### Examples:
##### 1. Unit test:
./bin/frontend.exe -u

##### 2. two-party PSI:
Compute PSI of 2 parties, each holds 2^2 items

./bin/frontend.exe -n 2 -m 12 -p 0 & ./bin/frontend.exe -n 2 -m 12 -p 1

##### 3. three-party PSI:
Compute optimized PSI of 3 parties, each holds 2^2 items

./bin/frontend.exe -n 3 -r 1 -m 12 -p 0 & ./bin/frontend.exe -n 3 -r 1 -m 12 -p 1 & ./bin/frontend.exe -n 3 -r 1 -m 12 -p 2

##### 4. nPSI:
##### 2. nPSI:
Compute PSI of 5 parties, 2 dishonestly colluding, each with set size 2^12 in semihonest setting

./bin/frontend.exe -n 5 -t 2 -m 12 -p 0
Expand Down
2 changes: 1 addition & 1 deletion cryptoTools/cryptoTools.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\libs\miracl;D:\libs\boost;D:\libs;$(ProjectDir);$(SolutionDir)/thirdparty/win;C:\libs;$(SolutionDir)/thirdparty/win/boost;C:\libs\boost;$(SolutionDir)/thirdparty/win/miracl;C:\libs\miracl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)/thirdparty/win;$(SolutionDir)/thirdparty/win/boost;$(SolutionDir)/thirdparty/win/miracl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
Expand Down
162 changes: 108 additions & 54 deletions frontend/PsiMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,36 +2106,37 @@ void tparty(u64 myIdx, u64 nParties, u64 tParties, u64 setSize, u64 nTrials)
ios.stop();
}

void zero_sharing(std::vector<std::vector<PRNG>>& mPRNGSeeds) {
PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
//TODO(remove this hack: unconditional zero - sharing);
//only one time => very mirror effect on perfomance
std::vector<std::vector<block>> mSeeds(nParties);
mPRNGSeeds.resize(nParties);
//std::vector<std::vector<PRNG>> mPRNGSeeds(nParties);
for (u64 i = 0; i < nParties; ++i)
{
mSeeds[i].resize(nParties);
for (u64 j = 0; j < nParties; ++j)
{
if (i <= j)
mSeeds[i][j] = prng.get<block>();
else
mSeeds[i][j] = mSeeds[j][i];
}
}
for (u64 i = 0; i < nParties; ++i)
{
mPRNGSeeds[i].resize(nParties);
for (u64 j = 0; j < nParties; ++j)
{
mPRNGSeeds[i][j].SetSeed(mSeeds[i][j]);
}
}
}


void aug_party(u64 myIdx, u64 nParties, u64 setSize, std::vector<PRNG>& mSeedPrng, u64 opt, u64 nTrials)
//std::vector<PRNG> zero_sharing(u64 id) {
// PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
// //TODO(remove this hack: unconditional zero - sharing);
// //only one time => very mirror effect on perfomance
// std::vector<std::vector<block>> mSeeds(nParties);
// //mPRNGSeeds.resize(nParties);
// std::vector<std::vector<PRNG>> mPRNGSeeds(nParties);
// for (u64 i = 0; i < nParties; ++i)
// {
// mSeeds[i].resize(nParties);
// for (u64 j = 0; j < nParties; ++j)
// {
// if (i <= j)
// mSeeds[i][j] = prng.get<block>();
// else
// mSeeds[i][j] = mSeeds[j][i];
// }
// }
// for (u64 i = 0; i < nParties; ++i)
// {
// mPRNGSeeds[i].resize(nParties);
// for (u64 j = 0; j < nParties; ++j)
// {
// mPRNGSeeds[i][j].SetSeed(mSeeds[i][j]);
// }
// }
// return mPRNGSeeds[id];
//}


void aug_party(u64 myIdx, u64 nParties, u64 setSize, u64 opt, u64 nTrials)
{
//opt = 1;

Expand Down Expand Up @@ -2250,6 +2251,35 @@ void aug_party(u64 myIdx, u64 nParties, u64 setSize, std::vector<PRNG>& mSeedPr
//##########################

auto start = timer.setTimePoint("start");





PRNG prng_zs(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
//TODO(remove this hack: unconditional zero - sharing);
//only one time => very mirror effect on perfomance
std::vector<std::vector<block>> mSeeds(nParties);

for (u64 i = 0; i < nParties; ++i)
{
mSeeds[i].resize(nParties);
for (u64 j = 0; j < nParties; ++j)
{
if (i <= j)
mSeeds[i][j] = prng_zs.get<block>();
else
mSeeds[i][j] = mSeeds[j][i];
}
}

std::vector<PRNG> mSeedPrng(nParties);
for (u64 j = 0; j < nParties; ++j)
{
mSeedPrng[j].SetSeed(mSeeds[myIdx][j]);
}


if (myIdx == leaderIdx) //leader
for (u32 i = 0; i < recvPayLoads.size(); i++)
{
Expand Down Expand Up @@ -2538,10 +2568,10 @@ void aug_party(u64 myIdx, u64 nParties, u64 setSize, std::vector<PRNG>& mSeedPr
<< "onlineTime: " << onlineTime << " ms\n"
//<< "Bandwidth: Send: " << Mbps << " Mbps,\t Recv: " << MbpsRecv << " Mbps\n"
<< "Total time: " << time << " s\n";
if (myIdx == clientdx)
std::cout << "Total Comm: Send:" << (dataSent / std::pow(2.0, 20)) << " MB"
//if (myIdx == clientdx)
// std::cout << "Total Comm: Send:" << (dataSent / std::pow(2.0, 20)) << " MB"
//<< "\t Recv: " << (dataRecv / std::pow(2.0, 20)) << " MB\n"
<< "------------------\n";
// << "------------------\n";

offlineAvgTime += offlineTime;
hashingAvgTime += hashingTime;
Expand Down Expand Up @@ -2657,7 +2687,7 @@ void aug_party(u64 myIdx, u64 nParties, u64 setSize, std::vector<PRNG>& mSeedPr

void OPPRFnt_EmptrySet_Test_Main()
{
u64 setSize = 1 << 5, psiSecParam = 40, bitSize = 128;
u64 setSize = 1 << 8, psiSecParam = 40, bitSize = 128;

u64 nParties = 5;
u64 tParties = 1;
Expand All @@ -2681,7 +2711,7 @@ void OPPRFnt_EmptrySet_Test_Main()

void OPPRFn_EmptrySet_Test_Main()
{
u64 setSize = 1 << 5, psiSecParam = 40, bitSize = 128;
u64 setSize = 1 << 8, psiSecParam = 40, bitSize = 128;
u64 nParties = 4;
PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
mSet.resize(setSize);
Expand All @@ -2705,7 +2735,7 @@ void OPPRFn_EmptrySet_Test_Main()

void OPPRF3_EmptrySet_Test_Main()
{
u64 setSize = 1 << 5, psiSecParam = 40, bitSize = 128;
u64 setSize = 1 << 8, psiSecParam = 40, bitSize = 128;
nParties = 3;
std::vector<std::thread> pThrds(nParties);
for (u64 pIdx = 0; pIdx < pThrds.size(); ++pIdx)
Expand Down Expand Up @@ -2876,11 +2906,11 @@ void party2(u64 myIdx, u64 setSize, u64 nTrials)

if (myIdx == 1) {
//I am a sender to my next neigbour
send.getOPRFkeysCombined(0, bins, chls[0], false);
send.sendPlain(0, bins, chls[0]);
}
else if (myIdx == 0) {
//I am a recv to my previous neigbour
recv.getOPRFkeysCombined(1, bins, chls[1], false);
recv.recvPlain(1, bins, chls[1]);
}
auto getOPRFDone = timer.setTimePoint("getOPRFDone");
#ifdef PRINT
Expand All @@ -2898,18 +2928,18 @@ void party2(u64 myIdx, u64 setSize, u64 nTrials)
#endif


//##########################
//### online phasing - secretsharing
//##########################
////##########################
////### online phasing - secretsharing
////##########################

if (myIdx == 0)
{
recv.recvPlain(1, bins, chls[1]);
}
else if (myIdx == 1)
{
send.sendPlain(0, bins, chls[0]);
}
//if (myIdx == 0)
//{
// recv.recvPlain(1, bins, chls[1]);
//}
//else if (myIdx == 1)
//{
// send.sendPlain(0, bins, chls[0]);
//}


if (myIdx == 0) {
Expand Down Expand Up @@ -2970,7 +3000,7 @@ void party2(u64 myIdx, u64 setSize, u64 nTrials)

void OPPRF2_EmptrySet_Test_Main()
{
u64 setSize = 1 << 5, psiSecParam = 40, bitSize = 128;
u64 setSize = 1 << 8, psiSecParam = 40, bitSize = 128;
PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
mSet.resize(setSize);
for (u64 i = 0; i < setSize; ++i)
Expand All @@ -2993,15 +3023,15 @@ void OPPRF2_EmptrySet_Test_Main()

void OPPRFn_Aug_EmptrySet_Test_Impl()
{
u64 setSize = 1 << 5, psiSecParam = 40, bitSize = 128;
u64 setSize = 1 << 8, psiSecParam = 40, bitSize = 128;
PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
mSet.resize(setSize);
for (u64 i = 0; i < setSize; ++i)
{
mSet[i] = prng.get<block>();
}

nParties = 4;
nParties = 5;

/*std::vector<std::vector<block>> mSeeds(nParties);
std::vector<std::vector<PRNG>> mPRNGSeeds(nParties);
Expand All @@ -3025,8 +3055,32 @@ void OPPRFn_Aug_EmptrySet_Test_Impl()
}
}*/

// PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
//TODO(remove this hack: unconditional zero - sharing);
//only one time => very mirror effect on perfomance
std::vector<std::vector<block>> mSeeds(nParties);
std::vector<std::vector<PRNG>> mPRNGSeeds(nParties);
zero_sharing(mPRNGSeeds);
mPRNGSeeds.resize(nParties);

for (u64 i = 0; i < nParties; ++i)
{
mSeeds[i].resize(nParties);
for (u64 j = 0; j < nParties; ++j)
{
if (i <= j)
mSeeds[i][j] = prng.get<block>();
else
mSeeds[i][j] = mSeeds[j][i];
}
}
for (u64 i = 0; i < nParties; ++i)
{
mPRNGSeeds[i].resize(nParties);
for (u64 j = 0; j < nParties; ++j)
{
mPRNGSeeds[i][j].SetSeed(mSeeds[i][j]);
}
}


//for (u64 i = 0; i < 1; ++i)
Expand Down Expand Up @@ -3060,7 +3114,7 @@ void OPPRFn_Aug_EmptrySet_Test_Impl()
{
pThrds[pIdx] = std::thread([&, pIdx]() {
// Channel_party_test(pIdx);
aug_party(pIdx, nParties, mSet.size(), mPRNGSeeds[pIdx], opt, 1);
aug_party(pIdx, nParties, mSet.size(), opt, 1);
});
}
for (u64 pIdx = 0; pIdx < pThrds.size(); ++pIdx)
Expand Down
5 changes: 3 additions & 2 deletions frontend/PsiMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ void party3(u64 myIdx, u64 setSize, u64 nTrials);
void party2(u64 myIdx, u64 setSize, u64 nTrials);
void party(u64 myIdx, u64 nParties, u64 setSize, std::vector<block>& mSet);
void tparty(u64 myIdx, u64 nParties, u64 tParties, u64 setSize, u64 nTrials);
void aug_party(u64 myIdx, u64 nParties, u64 setSize, std::vector<PRNG>& mSeedPrng,u64 opt, u64 nTrials);
void aug_party(u64 myIdx, u64 nParties, u64 setSize, u64 opt, u64 nTrials);
void OPPRFn_Aug_EmptrySet_Test_Impl();
void OPPRFnt_EmptrySet_Test_Impl();
void getBinSizeDistribution(u64 setSize, std::vector<block> set, u64 psiSecParam);
//void OPPRFn_EmptrySet_Test();
void Transpose_Test();
void zero_sharing(std::vector<std::vector<PRNG>>& mPRNGSeeds);
//void zero_sharing(std::vector<std::vector<PRNG>>& mPRNGSeeds);
//std::vector<PRNG> zero_sharing(u64 id);
2 changes: 1 addition & 1 deletion frontend/frontend.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)/cryptoTools;$(solutionDir)thirdparty\win\boost\;$(SolutionDir)/libOPRF;$(SolutionDir)thirdparty\win\;$(SolutionDir)thirdparty/win/NTL/include;$(SolutionDir)thirdparty/win/miracl;D:\libs\boost;C:/libs/boost;C:/libs/;C:/libs/NTL/include;C:/libs/miracl;C:\Program Files %28x86%29\Visual Leak Detector\include;D:\libs\miracl;$(SolutionDir)/libOTe</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir);$(SolutionDir)/cryptoTools;$(solutionDir)thirdparty\win\boost\;$(SolutionDir)/libOPRF;$(SolutionDir)thirdparty\win\;$(SolutionDir)thirdparty/win/NTL/include;$(SolutionDir)thirdparty/win/miracl;C:/libs/NTL/include;$(SolutionDir)/libOTe</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>SOLUTION_DIR=R"**($(SolutionDir))**";_WIN32_WINNT=0x0501;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
Expand Down
9 changes: 2 additions & 7 deletions frontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ int main(int argc, char** argv)
//return 0;

u64 trials = 1;
std::vector<block> mSet;

u64 pSetSize = 5, psiSecParam = 40, bitSize = 128;

u64 nParties, tParties, opt_basedOPPRF, setSize, isAug;
Expand Down Expand Up @@ -134,11 +132,8 @@ int main(int argc, char** argv)
tparty(pIdx, nParties, tParties, setSize, trials);
}
else if (argv[3][1] == 'a')
{
std::vector<std::vector<PRNG>> mPRNGSeeds(nParties);
zero_sharing(mPRNGSeeds);
//cout << nParties << " " << opt_basedOPPRF << " " << setSize << " " << pIdx << "\n";
aug_party(pIdx, nParties, mSet.size(), mPRNGSeeds[pIdx], opt_basedOPPRF, trials);
{
aug_party(pIdx, nParties, setSize,opt_basedOPPRF, trials);
}
}
else
Expand Down
8 changes: 4 additions & 4 deletions libOPRF/Hashing/CuckooHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace osuCrypto
//u64 mSenderBinStashSize;

CuckooParams k2n24s40CuckooParams
{ { 1.11,0.17 },{ 3,2 },{ 31,63 } };
{ { 1.12,0.17 },{ 3,2 },{ 31,63 } };
CuckooParams k2n20s40CuckooParams
{ { 1.12,0.17 },{ 3,2 },{ 30,63 } };
{ { 1.13,0.17 },{ 3,2 },{ 30,63 } };
CuckooParams k2n16s40CuckooParams
{ { 1.13,0.16 },{ 3,2 },{ 29,63 }};
{ { 1.14,0.16 },{ 3,2 },{ 29,63 }};
CuckooParams k2n14s40CuckooParams
{ { 1.14,0.16 },{ 3,2 },{ 28,63 } };
{ { 1.15,0.16 },{ 3,2 },{ 28,63 } };
CuckooParams k2n12s40CuckooParams
{ { 1.17,0.15 },{ 3,2 },{ 27,63 } };
CuckooParams k2n08s40CuckooParams
Expand Down
8 changes: 4 additions & 4 deletions libOPRF/Hashing/SimpleHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace osuCrypto
{

SimpleParams k2n24s40SimpleParams
{ { 1.11,0.17 },{ 3,2 },{ 31,63 },{5,6} };
{ { 1.12,0.17 },{ 3,2 },{ 31,63 },{5,6} };
SimpleParams k2n20s40SimpleParams
{ { 1.12,0.17 },{ 3,2 },{ 30,63 } ,{ 5,6 } };
{ { 1.13,0.17 },{ 3,2 },{ 30,63 } ,{ 5,6 } };
SimpleParams k2n16s40SimpleParams
{ { 1.13,0.16 },{ 3,2 },{ 29,63 },{ 5,6 } };
{ { 1.14,0.16 },{ 3,2 },{ 29,63 },{ 5,6 } };
SimpleParams k2n14s40SimpleParams
{ { 1.14,0.16 },{ 3,2 },{ 28,63 },{ 5,6 } };
{ { 1.15,0.16 },{ 3,2 },{ 28,63 },{ 5,6 } };
SimpleParams k2n12s40SimpleParams
{ { 1.17,0.15 },{ 3,2 },{ 27,63 },{ 5,6 } };
SimpleParams k2n08s40SimpleParams
Expand Down
1 change: 0 additions & 1 deletion libOPRF/OPPRF/OPPRFReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace osuCrypto
void recvPlain(u64 IdxTheirParty, binSet& bins, const std::vector<Channel*>& chls);



};


Expand Down
Loading

0 comments on commit d18d314

Please sign in to comment.