|
@@ -1,4 +1,5 @@
|
|
|
#include <iostream>
|
|
|
+#include <sstream>
|
|
|
#include <random>
|
|
|
#include <chrono>
|
|
|
|
|
@@ -46,6 +47,57 @@ bool testDecrypt(int x)
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
+bool testSerialize(int x)
|
|
|
+{
|
|
|
+ bool retval;
|
|
|
+
|
|
|
+ BGN system;
|
|
|
+
|
|
|
+ Scalar testVal(x);
|
|
|
+ Scalar one(1);
|
|
|
+ Scalar decrypted;
|
|
|
+
|
|
|
+ CurveBipoint curveEnc, curveReceive, curveOne;
|
|
|
+ TwistBipoint twistEnc, twistReceive, twistOne;
|
|
|
+ Quadripoint quadEncA, quadEncB, quadRecA, quadRecB;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ stringstream serializer;
|
|
|
+
|
|
|
+ serializer << curveEnc;
|
|
|
+ serializer >> curveReceive;
|
|
|
+
|
|
|
+ serializer << twistEnc;
|
|
|
+ serializer >> twistReceive;
|
|
|
+
|
|
|
+ serializer << quadEncA;
|
|
|
+ serializer >> quadRecA;
|
|
|
+
|
|
|
+ serializer << quadEncB;
|
|
|
+ serializer >> quadRecB;
|
|
|
+
|
|
|
+ decrypted = system.decrypt(curveReceive);
|
|
|
+ retval = (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(twistReceive);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(quadRecA);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ decrypted = system.decrypt(quadRecB);
|
|
|
+ retval = retval && (decrypted == testVal);
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
double testCurveEncryptSpeed(default_random_engine& generator)
|
|
|
{
|
|
|
BGN system;
|
|
@@ -666,6 +718,13 @@ int main(int argc, char *argv[])
|
|
|
else
|
|
|
cout << "FAIL" << endl;
|
|
|
|
|
|
+ int serializingPoint = distribution(generator);
|
|
|
+ cout << "test_Serialization (" << serializingPoint << "): ";
|
|
|
+ if (testSerialize(serializingPoint))
|
|
|
+ cout << "PASS" << endl;
|
|
|
+ else
|
|
|
+ cout << "FAIL" << endl;
|
|
|
+
|
|
|
cout << "test_CurveEncryptSpeed (" << NUM_RUNS_PER_TEST << " runs): ";
|
|
|
cout << testCurveEncryptSpeed(generator) << " seconds" << endl;
|
|
|
|