|
@@ -182,6 +182,90 @@ double testQuadDecryptSpeed(default_random_engine& generator)
|
|
|
return time_span.count();
|
|
|
}
|
|
|
|
|
|
+double testCurveDecryptSpeed(size_t max)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ testVals.push_back(Scalar(i));
|
|
|
+
|
|
|
+ vector<CurveBipoint> encryptions(max);
|
|
|
+ vector<Scalar> decryptions(max);
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ system.encrypt(encryptions[i], testVals[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ decryptions[i] = system.decrypt(encryptions[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
+double testTwistDecryptSpeed(size_t max)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ testVals.push_back(Scalar(i));
|
|
|
+
|
|
|
+ vector<TwistBipoint> encryptions(max);
|
|
|
+ vector<Scalar> decryptions(max);
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ system.encrypt(encryptions[i], testVals[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ decryptions[i] = system.decrypt(encryptions[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
+double testQuadDecryptSpeed(size_t max)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ testVals.push_back(Scalar(i));
|
|
|
+
|
|
|
+ Scalar one(1);
|
|
|
+
|
|
|
+ TwistBipoint oneEncryption;
|
|
|
+ vector<CurveBipoint> firstEncryptions(max);
|
|
|
+ vector<Quadripoint> realEncryptions(max);
|
|
|
+ vector<Scalar> decryptions(max);
|
|
|
+
|
|
|
+ system.encrypt(oneEncryption, one);
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ {
|
|
|
+ system.encrypt(firstEncryptions[i], testVals[i]);
|
|
|
+ realEncryptions[i] = system.homomorphic_multiplication(firstEncryptions[i], oneEncryption);
|
|
|
+ }
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < max; i++)
|
|
|
+ decryptions[i] = system.decrypt(realEncryptions[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
bool testAddition(int x, int y)
|
|
|
{
|
|
|
bool retval;
|
|
@@ -267,7 +351,7 @@ double testCurveAdditionSpeed(default_random_engine& generator)
|
|
|
chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
|
|
|
for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
- encSums[i] = system.homomorphic_addition(encXs[i], encYs[i]);
|
|
|
+ encSums[i] = system.homomorphic_addition_no_rerandomize(encXs[i], encYs[i]);
|
|
|
|
|
|
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
@@ -302,7 +386,7 @@ double testTwistAdditionSpeed(default_random_engine& generator)
|
|
|
chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
|
|
|
for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
- encSums[i] = system.homomorphic_addition(encXs[i], encYs[i]);
|
|
|
+ encSums[i] = system.homomorphic_addition_no_rerandomize(encXs[i], encYs[i]);
|
|
|
|
|
|
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
@@ -346,7 +430,7 @@ double testQuadAdditionSpeed(default_random_engine& generator)
|
|
|
chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
|
|
|
for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
- encSums[i] = system.homomorphic_addition(realEncXs[i], realEncYs[i]);
|
|
|
+ encSums[i] = system.homomorphic_addition_no_rerandomize(realEncXs[i], realEncYs[i]);
|
|
|
|
|
|
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
@@ -413,7 +497,139 @@ double testMultiplicationSpeed(default_random_engine& generator)
|
|
|
chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
|
|
|
for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
- encProducts[i] = system.homomorphic_multiplication(encXs[i], encYs[i]);
|
|
|
+ encProducts[i] = system.homomorphic_multiplication_no_rerandomize(encXs[i], encYs[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
+bool testRerandomize(int x)
|
|
|
+{
|
|
|
+ bool retval;
|
|
|
+
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ Scalar testVal(x);
|
|
|
+ Scalar one(1);
|
|
|
+ Scalar decrypted;
|
|
|
+
|
|
|
+ CurveBipoint curveEnc, curveRand, curveOne;
|
|
|
+ TwistBipoint twistEnc, twistRand, twistOne;
|
|
|
+ Quadripoint quadEncA, quadEncB, quadRandA, quadRandB;
|
|
|
+
|
|
|
+ system.encrypt(curveEnc, testVal);
|
|
|
+ system.encrypt(curveOne, one);
|
|
|
+ system.encrypt(twistEnc, testVal);
|
|
|
+ system.encrypt(twistOne, one);
|
|
|
+
|
|
|
+ quadEncA = system.homomorphic_multiplication(curveEnc, twistOne);
|
|
|
+ quadEncB = system.homomorphic_multiplication(curveOne, twistEnc);
|
|
|
+
|
|
|
+ curveRand = system.rerandomize(curveEnc);
|
|
|
+ twistRand = system.rerandomize(twistEnc);
|
|
|
+ quadRandA = system.rerandomize(quadEncA);
|
|
|
+ quadRandB = system.rerandomize(quadEncB);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(curveRand);
|
|
|
+ retval = (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(twistRand);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(quadRandA);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(quadRandB);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+double testCurveRerandomizeSpeed(default_random_engine& generator)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ uniform_int_distribution<int> distribution(0, MAX_VALUE_IN_TEST);
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ testVals.push_back(Scalar(distribution(generator)));
|
|
|
+
|
|
|
+ vector<CurveBipoint> encryptions(NUM_RUNS_PER_TEST);
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ system.encrypt(encryptions[i], testVals[i]);
|
|
|
+
|
|
|
+ vector<CurveBipoint> rerandomizations(NUM_RUNS_PER_TEST);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ rerandomizations[i] = system.rerandomize(encryptions[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
+double testTwistRerandomizeSpeed(default_random_engine& generator)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ uniform_int_distribution<int> distribution(0, MAX_VALUE_IN_TEST);
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ testVals.push_back(Scalar(distribution(generator)));
|
|
|
+
|
|
|
+ vector<TwistBipoint> encryptions(NUM_RUNS_PER_TEST);
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ system.encrypt(encryptions[i], testVals[i]);
|
|
|
+
|
|
|
+ vector<TwistBipoint> rerandomizations(NUM_RUNS_PER_TEST);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ rerandomizations[i] = system.rerandomize(encryptions[i]);
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
+ chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
|
+
|
|
|
+ return time_span.count();
|
|
|
+}
|
|
|
+
|
|
|
+double testQuadRerandomizeSpeed(default_random_engine& generator)
|
|
|
+{
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ uniform_int_distribution<int> distribution(0, MAX_VALUE_IN_TEST);
|
|
|
+
|
|
|
+ vector<Scalar> testVals;
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ testVals.push_back(Scalar(distribution(generator)));
|
|
|
+
|
|
|
+ Scalar one(1);
|
|
|
+
|
|
|
+ TwistBipoint oneEncryption;
|
|
|
+ vector<CurveBipoint> firstEncryptions(NUM_RUNS_PER_TEST);
|
|
|
+ vector<Quadripoint> realEncryptions(NUM_RUNS_PER_TEST);
|
|
|
+ vector<Quadripoint> rerandomizations(NUM_RUNS_PER_TEST);
|
|
|
+
|
|
|
+ system.encrypt(oneEncryption, one);
|
|
|
+
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ {
|
|
|
+ system.encrypt(firstEncryptions[i], testVals[i]);
|
|
|
+ realEncryptions[i] = system.homomorphic_multiplication(firstEncryptions[i], oneEncryption);
|
|
|
+ }
|
|
|
+
|
|
|
+ chrono::high_resolution_clock::time_point t0 = chrono::high_resolution_clock::now();
|
|
|
+
|
|
|
+ for (size_t i = 0; i < NUM_RUNS_PER_TEST; i++)
|
|
|
+ rerandomizations[i] = system.rerandomize(realEncryptions[i]);
|
|
|
|
|
|
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
|
|
|
chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t1 - t0);
|
|
@@ -465,6 +681,54 @@ int main(int argc, char *argv[])
|
|
|
cout << "test_QuadDecryptSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
cout << testQuadDecryptSpeed(generator) << " seconds" << endl;
|
|
|
|
|
|
+ int max = 10;
|
|
|
+ cout << "test_CurveDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testCurveDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 20;
|
|
|
+ cout << "test_CurveDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testCurveDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 30;
|
|
|
+ cout << "test_CurveDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testCurveDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 40;
|
|
|
+ cout << "test_CurveDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testCurveDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 50;
|
|
|
+ cout << "test_CurveDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testCurveDecryptSpeed(max) << " seconds" << endl;
|
|
|
+
|
|
|
+ max = 10;
|
|
|
+ cout << "test_TwistDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testTwistDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 20;
|
|
|
+ cout << "test_TwistDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testTwistDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 30;
|
|
|
+ cout << "test_TwistDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testTwistDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 40;
|
|
|
+ cout << "test_TwistDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testTwistDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 50;
|
|
|
+ cout << "test_TwistDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testTwistDecryptSpeed(max) << " seconds" << endl;
|
|
|
+
|
|
|
+ max = 10;
|
|
|
+ cout << "test_QuadDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testQuadDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 20;
|
|
|
+ cout << "test_QuadDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testQuadDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 30;
|
|
|
+ cout << "test_QuadDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testQuadDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 40;
|
|
|
+ cout << "test_QuadDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testQuadDecryptSpeed(max) << " seconds" << endl;
|
|
|
+ max = 50;
|
|
|
+ cout << "test_QuadDecryptSpeed (0 -> " << max << "): ";
|
|
|
+ cout << testQuadDecryptSpeed(max) << " seconds" << endl;
|
|
|
+
|
|
|
int addX = distribution(generator);
|
|
|
int addY = distribution(generator);
|
|
|
cout << "test_Addition (" << addX << ", " << addY << "): ";
|
|
@@ -493,5 +757,21 @@ int main(int argc, char *argv[])
|
|
|
cout << "test_MultiplicationSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
cout << testMultiplicationSpeed(generator) << " seconds" << endl;
|
|
|
|
|
|
+ int rerandomizingPoint = distribution(generator);
|
|
|
+ cout << "test_Rerandomize (" << rerandomizingPoint << "): ";
|
|
|
+ if (testRerandomize(rerandomizingPoint))
|
|
|
+ cout << "PASS" << endl;
|
|
|
+ else
|
|
|
+ cout << "FAIL" << endl;
|
|
|
+
|
|
|
+ cout << "test_CurveRerandomizeSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
+ cout << testCurveRerandomizeSpeed(generator) << " seconds" << endl;
|
|
|
+
|
|
|
+ cout << "test_TwistRerandomizeSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
+ cout << testTwistRerandomizeSpeed(generator) << " seconds" << endl;
|
|
|
+
|
|
|
+ cout << "test_QuadRerandomizeSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
+ cout << testQuadRerandomizeSpeed(generator) << " seconds" << endl;
|
|
|
+
|
|
|
return 0;
|
|
|
}
|