Skip to content

Commit

Permalink
simple hahsing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrieu committed May 7, 2018
1 parent b4d2942 commit c58b548
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 32 deletions.
44 changes: 27 additions & 17 deletions Tests/PSU_Tests.cpp
Expand Up @@ -600,15 +600,20 @@ namespace tests_libOTe
}



void PSU_HashingParameters_Calculation() {
#if 0
SimpleIndex simpleIndex;
std::vector<u64> logNumBalls{ 8, 12, 16, 20, 24 };
std::vector<u64> lengthCodeWord{ 424, 432, 440, 448, 448 };
u64 statSecParam = 40, lengthItem=128, compSecParam=128;
/*std::vector<u64> logNumBalls{ 8,10, 12,14, 16,18, 20,22, 24 };
std::vector<u64> lengthCodeWord{ 424,432, 432, 440,440, 448, 448, 448, 448 };
*/
std::vector<u64> logNumBalls{ 16 };
std::vector<u64> lengthCodeWord{ 440 };

u64 statSecParam = 40, lengthItem = 128, compSecParam = 128;
u64 commCost;
double scale = 0,m=0;
double iScaleStart = 0.03,iScaleEnd=0.08;
double scale = 0, m = 0;
double iScaleStart = 0.05, iScaleEnd = 0.12;

for (u64 idxN = 0; idxN < logNumBalls.size(); idxN++)
{
Expand All @@ -618,20 +623,23 @@ namespace tests_libOTe
{
u64 numBins = iScale*numBalls;
u64 maxBinSize = simpleIndex.get_bin_size(numBins, numBalls, statSecParam);
u64 curCommCost = numBins * (maxBinSize)*lengthCodeWord[idxN]
+ numBins*maxBinSize * (maxBinSize + 2)*(statSecParam+log2(maxBinSize+2))
+ numBins * maxBinSize*(lengthCodeWord[idxN] + statSecParam)
+ numBins * maxBinSize*(compSecParam + lengthItem);

u64 polyBytes = (statSecParam + log2(pow(maxBinSize + 1, 2)*numBins));
u64 curCommCost = numBins * (maxBinSize + 1)*(
lengthCodeWord[idxN]
+ (maxBinSize + 1)*polyBytes //poly
+ (lengthCodeWord[idxN] + statSecParam) //peqt
+ (1 + lengthItem));//ot


if (iScale == iScaleStart)
{
commCost = curCommCost;
scale = iScale;
m = maxBinSize;
}
std::cout << iScale << "\t" << numBins << "\t" << maxBinSize <<"\t"
<< curCommCost << "\t" << commCost << "\t";
std::cout << iScale << "\t" << numBins << "\t" << maxBinSize << "\t"
<< curCommCost << " bits = " << (curCommCost / 8)*pow(10, -6) << " Mb \t "
<< commCost << " bits = " << (commCost / 8)*pow(10, -6) << " Mb \t ";

if (commCost > curCommCost)
{
Expand All @@ -644,15 +652,17 @@ namespace tests_libOTe
std::cout << scale << std::endl;

//std::cout << iScale << "\t" << commCost <<"\t"<< curCommCost << std::endl;
iScale += 0.0001;
}
iScale += 0.001;
}
std::cout << "##############" << std::endl;
std::cout << logNumBalls[idxN] << "\t" << scale << "\t" << m << "\t"<< (commCost/8)*pow(10,-9)<< std::endl;
std::cout << logNumBalls[idxN] << "\t" << scale << "\t" << m << "\t" << (commCost / 8)*pow(10, -6) << " Mb" << std::endl;
std::cout << "##############" << std::endl;

}
#endif
}
#endif
}



void Hashing_Test_Impl()
{
Expand Down
47 changes: 33 additions & 14 deletions libPSU/Tools/SimpleIndex.cpp
Expand Up @@ -52,7 +52,7 @@ namespace osuCrypto
}

#if 0
//template<unsigned int N = 16>
// template<unsigned int N = 16>
double getBinOverflowProb(u64 numBins, u64 numBalls, u64 binSize, double epsilon = 0.0001)
{
if (numBalls <= binSize)
Expand Down Expand Up @@ -91,7 +91,8 @@ namespace osuCrypto
return std::max<double>(0, (double)-sec);
}

u64 SimpleIndex::get_bin_size(u64 numBins, u64 numBalls, u64 statSecParam)

u64 get_bin_size(u64 numBins, u64 numBalls, u64 statSecParam)
{

auto B = std::max<u64>(1, numBalls / numBins);
Expand Down Expand Up @@ -131,30 +132,48 @@ namespace osuCrypto
u64 SimpleIndex::getMaxBinSize(u64 numBalls) {
if (numBalls <= 1 << 8)
return 63;
else if (numBalls <= 1 << 10)
return 58; //10 0.055 58 1.81555 Mb
else if (numBalls <= 1 << 12)
return 59;
return 63; //12 0.05 63 7.84829 Mb
else if (numBalls <= 1 << 14)
return 62; //14 0.053 62 33.4393 Mb
else if (numBalls <= 1 << 16)
return 66;
return 60; //16 0.058 60 141.783 Mb
else if (numBalls <= 1 << 18)
return 65; //18 0.052 65 602.201 Mb
else if (numBalls <= 1 << 20)
return 70;

return 70;
return 61; //20 0.06 61 2544.7 Mb
else if (numBalls <= 1 << 22)
return 68; //22 0.051 68 10748.8 Mb
else if (numBalls <= 1 << 24)
return 69; //24 0.051 69 45183 Mb

return 69;
}

u64 SimpleIndex::getNumBins(u64 numBalls) {

u64 temp = 0.0470*numBalls;

if (numBalls <= 1 << 8)
temp = 0.0430*numBalls;
return 11;
else if (numBalls <= 1 << 10)
return 56;
else if (numBalls <= 1 << 12)
temp = 0.0557*numBalls;
return 204;
else if (numBalls <= 1 << 14)
return 868; //0.053 868 62 267514128 bits = 33.4393 Mb
else if (numBalls <= 1 << 16)
temp = 0.0491*numBalls;
return 3801; //0.058 3801 60 1134264012 bits = 141.783 Mb
else if (numBalls <= 1 << 18)
return 13631; //0.052 13631 65 4817604330 bits = 602.201 Mb
else if (numBalls <= 1 << 20)
temp = 0.0470*numBalls;
return 62914; //0.06 62914 61 20357586292 bits = 2544.7 Mb
else if (numBalls <= 1 << 22)
return 213909; //0.051 213909 68 85990134546 bits = 10748.8 Mb
else if (numBalls <= 1 << 24)
return 855638; //0.051 855638 69 361464273100 bits = 45183 Mb

return temp;
return 855638;
}

void SimpleIndex::init(u64 numBalls, u64 statSecParam)
Expand Down
5 changes: 4 additions & 1 deletion libPSU/Tools/SimpleIndex.h
Expand Up @@ -41,7 +41,10 @@ namespace osuCrypto
block mHashSeed;
void print() ;
void print(u64 numBin);
//static u64 get_bin_size(u64 numBins, u64 numBalls, u64 statSecParam);

#if 0
static u64 get_bin_size(u64 numBins, u64 numBalls, u64 statSecParam);
#endif

u64 getMaxBinSize(u64 numBalls);
u64 getNumBins(u64 numBalls);
Expand Down
126 changes: 126 additions & 0 deletions script_PSU.get
Expand Up @@ -40,6 +40,17 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 8 -t 16 >> output & ./bin/frontend.exe -r 0 -n 8 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 8 -t 32 >> output & ./bin/frontend.exe -r 0 -n 8 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 8 -t 32 >> output & ./bin/frontend.exe -r 0 -n 8 -t 32 >> output
sleep 10


echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -82,6 +93,16 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 10 -t 16 >> output & ./bin/frontend.exe -r 0 -n 10 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 10 -t 32 >> output & ./bin/frontend.exe -r 0 -n 10 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 10 -t 32 >> output & ./bin/frontend.exe -r 0 -n 10 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -123,6 +144,17 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 12 -t 16 >> output & ./bin/frontend.exe -r 0 -n 12 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 12 -t 32 >> output & ./bin/frontend.exe -r 0 -n 12 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 12 -t 32 >> output & ./bin/frontend.exe -r 0 -n 12 -t 32 >> output
sleep 10


echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -164,6 +196,16 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 14 -t 16 >> output & ./bin/frontend.exe -r 0 -n 14 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 14 -t 32 >> output & ./bin/frontend.exe -r 0 -n 14 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 14 -t 32 >> output & ./bin/frontend.exe -r 0 -n 14 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -205,6 +247,16 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 16 -t 16 >> output & ./bin/frontend.exe -r 0 -n 16 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 16 -t 32 >> output & ./bin/frontend.exe -r 0 -n 16 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 16 -t 32 >> output & ./bin/frontend.exe -r 0 -n 16 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -246,6 +298,16 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 18 -t 16 >> output & ./bin/frontend.exe -r 0 -n 18 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 18 -t 32 >> output & ./bin/frontend.exe -r 0 -n 18 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 18 -t 32 >> output & ./bin/frontend.exe -r 0 -n 18 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

Expand Down Expand Up @@ -287,5 +349,69 @@ echo "=================================" >> output
./bin/frontend.exe -r 1 -n 20 -t 16 >> output & ./bin/frontend.exe -r 0 -n 20 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 20 -t 32 >> output & ./bin/frontend.exe -r 0 -n 20 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 20 -t 32 >> output & ./bin/frontend.exe -r 0 -n 20 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

echo "=======================================================" >> output
echo "=======================================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 1 >> output & ./bin/frontend.exe -r 0 -n 22 -t 1 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 1 >> output & ./bin/frontend.exe -r 0 -n 22 -t 1 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 2 >> output & ./bin/frontend.exe -r 0 -n 22 -t 2 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 2 >> output & ./bin/frontend.exe -r 0 -n 22 -t 2 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 4 >> output & ./bin/frontend.exe -r 0 -n 22 -t 4 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 4 >> output & ./bin/frontend.exe -r 0 -n 22 -t 4 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 16 >> output & ./bin/frontend.exe -r 0 -n 22 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 16 >> output & ./bin/frontend.exe -r 0 -n 22 -t 16 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 32 >> output & ./bin/frontend.exe -r 0 -n 22 -t 32 >> output
sleep 10

echo "=================================" >> output

./bin/frontend.exe -r 1 -n 22 -t 32 >> output & ./bin/frontend.exe -r 0 -n 22 -t 32 >> output
sleep 10

echo "=======================================================" >> output
echo "=======================================================" >> output

0 comments on commit c58b548

Please sign in to comment.