From c58b5483f3f890e49d951f8e65999d3fe9426d01 Mon Sep 17 00:00:00 2001 From: Trieu Date: Mon, 7 May 2018 03:27:33 -0700 Subject: [PATCH] simple hahsing parameters --- Tests/PSU_Tests.cpp | 44 +++++++----- libPSU/Tools/SimpleIndex.cpp | 47 +++++++++---- libPSU/Tools/SimpleIndex.h | 5 +- script_PSU.get | 126 +++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 32 deletions(-) diff --git a/Tests/PSU_Tests.cpp b/Tests/PSU_Tests.cpp index 2b7fdfb..2ec0219 100644 --- a/Tests/PSU_Tests.cpp +++ b/Tests/PSU_Tests.cpp @@ -600,15 +600,20 @@ namespace tests_libOTe } + void PSU_HashingParameters_Calculation() { #if 0 SimpleIndex simpleIndex; - std::vector logNumBalls{ 8, 12, 16, 20, 24 }; - std::vector lengthCodeWord{ 424, 432, 440, 448, 448 }; - u64 statSecParam = 40, lengthItem=128, compSecParam=128; + /*std::vector logNumBalls{ 8,10, 12,14, 16,18, 20,22, 24 }; + std::vector lengthCodeWord{ 424,432, 432, 440,440, 448, 448, 448, 448 }; + */ + std::vector logNumBalls{ 16 }; + std::vector 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++) { @@ -618,11 +623,13 @@ 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) { @@ -630,8 +637,9 @@ namespace tests_libOTe 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) { @@ -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() { diff --git a/libPSU/Tools/SimpleIndex.cpp b/libPSU/Tools/SimpleIndex.cpp index 4382f4f..ec4e12f 100644 --- a/libPSU/Tools/SimpleIndex.cpp +++ b/libPSU/Tools/SimpleIndex.cpp @@ -52,7 +52,7 @@ namespace osuCrypto } #if 0 - //template + // template double getBinOverflowProb(u64 numBins, u64 numBalls, u64 binSize, double epsilon = 0.0001) { if (numBalls <= binSize) @@ -91,7 +91,8 @@ namespace osuCrypto return std::max(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(1, numBalls / numBins); @@ -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) diff --git a/libPSU/Tools/SimpleIndex.h b/libPSU/Tools/SimpleIndex.h index f95c8e5..d9199e7 100644 --- a/libPSU/Tools/SimpleIndex.h +++ b/libPSU/Tools/SimpleIndex.h @@ -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); diff --git a/script_PSU.get b/script_PSU.get index 585c262..015bc85 100644 --- a/script_PSU.get +++ b/script_PSU.get @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file