Browse Source

final bugfixes associated with the issue of decryption not returning (The issue was related to the dclxvi library not handling adding two equal points correctly; it is fixed by checking if two points are equal in BGN, and using double instead of addition if so)

tristangurtler 3 years ago
parent
commit
a7a779f645

+ 3 - 3
bgn2/inc/BGN.hpp

@@ -21,9 +21,9 @@ class BGN
 		Quadripoint homomorphic_addition(const Quadripoint& a, const Quadripoint& b) const;
 		Quadripoint homomorphic_addition(const Quadripoint& a, const Quadripoint& b) const;
 		Quadripoint homomorphic_multiplication(const CurveBipoint& a, const TwistBipoint& b) const;
 		Quadripoint homomorphic_multiplication(const CurveBipoint& a, const TwistBipoint& b) const;
 
 
-		Scalar decrypt(const CurveBipoint& ciphertext) const;
-        Scalar decrypt(const TwistBipoint& ciphertext) const;
-        Scalar decrypt(const Quadripoint & ciphertext) const;
+		Scalar decrypt(const CurveBipoint& ciphertext);
+        Scalar decrypt(const TwistBipoint& ciphertext);
+        Scalar decrypt(const Quadripoint & ciphertext);
 
 
         const PublicKey& get_public_key() const;
         const PublicKey& get_public_key() const;
         const PrivateKey& get_private_key() const;
         const PrivateKey& get_private_key() const;

+ 4 - 6
bgn2/inc/Bipoint.hpp

@@ -27,9 +27,6 @@ class CurveBipoint
 		bool operator==(const CurveBipoint& b) const;
 		bool operator==(const CurveBipoint& b) const;
 		bool operator!=(const CurveBipoint& b) const;
 		bool operator!=(const CurveBipoint& b) const;
 
 
-		// "double" is a type, so you can't just name the function that I don't think, but that's all this is
-		CurveBipoint mult_by_2() const;	
-
 		void make_affine();
 		void make_affine();
 
 
 		friend class CurveBipointHash;
 		friend class CurveBipointHash;
@@ -37,6 +34,8 @@ class CurveBipoint
 	
 	
 	private:
 	private:
 		curvepoint_fp_t point[2];
 		curvepoint_fp_t point[2];
+
+		bool equal(const curvepoint_fp_t& op1, const curvepoint_fp_t& op2) const;
 };
 };
 
 
 class CurveBipointHash
 class CurveBipointHash
@@ -60,9 +59,6 @@ class TwistBipoint
 		bool operator==(const TwistBipoint& b) const;
 		bool operator==(const TwistBipoint& b) const;
 		bool operator!=(const TwistBipoint& b) const;
 		bool operator!=(const TwistBipoint& b) const;
 
 
-		// "double" is a type, so you can't just name the function that I don't think, but that's all this is
-		TwistBipoint mult_by_2() const;
-
 		void make_affine();
 		void make_affine();
 
 
 		friend class TwistBipointHash;
 		friend class TwistBipointHash;
@@ -70,6 +66,8 @@ class TwistBipoint
 	
 	
 	private:
 	private:
 		twistpoint_fp2_t point[2];	
 		twistpoint_fp2_t point[2];	
+
+		bool equal(const twistpoint_fp2_t& op1, const twistpoint_fp2_t& op2) const;
 };
 };
 
 
 class TwistBipointHash
 class TwistBipointHash

+ 10 - 4
bgn2/inc/PrivateKey.hpp

@@ -1,6 +1,7 @@
 #ifndef __PRIVATEKEY_HPP
 #ifndef __PRIVATEKEY_HPP
 #define __PRIVATEKEY_HPP
 #define __PRIVATEKEY_HPP
 
 
+#include <iostream>
 #include <unordered_map>
 #include <unordered_map>
 
 
 #include "Scalar.hpp"
 #include "Scalar.hpp"
@@ -12,9 +13,9 @@
 class PrivateKey
 class PrivateKey
 {
 {
     public:
     public:
-        Scalar decrypt(const CurveBipoint& ciphertext) const;
-        Scalar decrypt(const TwistBipoint& ciphertext) const;
-        Scalar decrypt(const Quadripoint & ciphertext) const;
+        Scalar decrypt(const CurveBipoint& ciphertext);
+        Scalar decrypt(const TwistBipoint& ciphertext);
+        Scalar decrypt(const Quadripoint & ciphertext);
     
     
     private:
     private:
         PrivateKey();
         PrivateKey();
@@ -29,7 +30,12 @@ class PrivateKey
 
 
         CurveBipoint pi_1_curvegen;
         CurveBipoint pi_1_curvegen;
         TwistBipoint pi_2_twistgen;
         TwistBipoint pi_2_twistgen;
-        Quadripoint  pi_T_pairgen;        
+        Quadripoint  pi_T_pairgen;
+
+        std::unordered_map<CurveBipoint, Scalar, CurveBipointHash> curve_memoizer;
+        std::unordered_map<TwistBipoint, Scalar, TwistBipointHash> twist_memoizer;
+        std::unordered_map<Quadripoint, Scalar, QuadripointHash> pair_memoizer;
+        Scalar curve_max_checked, twist_max_checked, pair_max_checked;
 };
 };
 
 
 #endif
 #endif

+ 0 - 2
bgn2/inc/Quadripoint.hpp

@@ -25,8 +25,6 @@ class Quadripoint
 		bool operator==(const Quadripoint& b) const;
 		bool operator==(const Quadripoint& b) const;
 		bool operator!=(const Quadripoint& b) const;
 		bool operator!=(const Quadripoint& b) const;
 
 
-		Quadripoint square() const;
-
 		friend class QuadripointHash;
 		friend class QuadripointHash;
 		friend std::ostream& operator<<(std::ostream& os, const Quadripoint& output);
 		friend std::ostream& operator<<(std::ostream& os, const Quadripoint& output);
 	
 	

+ 3 - 3
bgn2/src/BGN.cpp

@@ -103,17 +103,17 @@ Quadripoint BGN::homomorphic_multiplication(const CurveBipoint& a, const TwistBi
 	return public_key.homomorphic_multiplication(a, b);
 	return public_key.homomorphic_multiplication(a, b);
 }
 }
 
 
-Scalar BGN::decrypt(const CurveBipoint& ciphertext) const
+Scalar BGN::decrypt(const CurveBipoint& ciphertext)
 {
 {
 	return private_key.decrypt(ciphertext);
 	return private_key.decrypt(ciphertext);
 }
 }
 
 
-Scalar BGN::decrypt(const TwistBipoint& ciphertext) const
+Scalar BGN::decrypt(const TwistBipoint& ciphertext)
 {
 {
 	return private_key.decrypt(ciphertext);
 	return private_key.decrypt(ciphertext);
 }
 }
 
 
-Scalar BGN::decrypt(const Quadripoint& ciphertext) const
+Scalar BGN::decrypt(const Quadripoint& ciphertext)
 {
 {
 	return private_key.decrypt(ciphertext);
 	return private_key.decrypt(ciphertext);
 }
 }

+ 108 - 54
bgn2/src/Bipoint.cpp

@@ -48,8 +48,14 @@ CurveBipoint CurveBipoint::operator+(const CurveBipoint& b) const
 {
 {
 	CurveBipoint retval;
 	CurveBipoint retval;
 
 
-	curvepoint_fp_add_vartime(retval[0], point[0], b.point[0]);
-	curvepoint_fp_add_vartime(retval[1], point[1], b.point[1]);
+	if (equal(point[0], b[0]))
+		curvepoint_fp_double(retval[0], point[0]);
+	else
+		curvepoint_fp_add_vartime(retval[0], point[0], b[0]);
+	if (equal(point[1], b[1]))
+		curvepoint_fp_double(retval[1], point[1]);
+	else
+		curvepoint_fp_add_vartime(retval[1], point[1], b[1]);
 
 
 	return retval;
 	return retval;
 }
 }
@@ -58,8 +64,14 @@ TwistBipoint TwistBipoint::operator+(const TwistBipoint& b) const
 {
 {
 	TwistBipoint retval;
 	TwistBipoint retval;
 
 
-	twistpoint_fp2_add_vartime(retval[0], point[0], b.point[0]);
-	twistpoint_fp2_add_vartime(retval[1], point[1], b.point[1]);
+	if (equal(point[0], b[0]))
+		twistpoint_fp2_double(retval[0], point[0]);
+	else
+		twistpoint_fp2_add_vartime(retval[0], point[0], b[0]);
+	if (equal(point[1], b[1]))
+		twistpoint_fp2_double(retval[1], point[1]);
+	else
+		twistpoint_fp2_add_vartime(retval[1], point[1], b[1]);
 
 
 	return retval;
 	return retval;
 }
 }
@@ -84,68 +96,66 @@ TwistBipoint TwistBipoint::operator*(const Scalar& exp) const
 	return retval;
 	return retval;
 }
 }
 
 
-bool CurveBipoint::operator==(const CurveBipoint& b) const
+bool CurveBipoint::equal(const curvepoint_fp_t& op1, const curvepoint_fp_t& op2) const
 {
 {
-	CurveBipoint affine_this = *this;
-	CurveBipoint affine_b = b;
-	affine_this.make_affine();
-	affine_b.make_affine();
-
 	bool retval;
 	bool retval;
+	curvepoint_fp_t affine_op1, affine_op2;
+
+	curvepoint_fp_set(affine_op1, op1);
+	curvepoint_fp_set(affine_op2, op2);
+
+	if (!(fpe_isone(affine_op1->m_z) || fpe_iszero(affine_op1->m_z)))
+		curvepoint_fp_makeaffine(affine_op1);
 
 
-	retval =           fpe_iseq(affine_this[0]->m_x, affine_b[0]->m_x);
-	retval = retval && fpe_iseq(affine_this[0]->m_y, affine_b[0]->m_y); 
-	retval = retval && fpe_iseq(affine_this[1]->m_x, affine_b[1]->m_x);
-	retval = retval && fpe_iseq(affine_this[1]->m_y, affine_b[1]->m_y);
+	if (!(fpe_isone(affine_op2->m_z) || fpe_iszero(affine_op2->m_z)))
+		curvepoint_fp_makeaffine(affine_op2);
+
+	retval =           fpe_iseq(affine_op1->m_x, affine_op2->m_x);
+	retval = retval && fpe_iseq(affine_op1->m_y, affine_op2->m_y);
+	retval = retval || (fpe_iszero(affine_op1->m_z) && fpe_iszero(affine_op2->m_z));
 
 
 	return retval;
 	return retval;
 }
 }
 
 
-bool TwistBipoint::operator==(const TwistBipoint& b) const
+bool TwistBipoint::equal(const twistpoint_fp2_t& op1, const twistpoint_fp2_t& op2) const
 {
 {
-	TwistBipoint affine_this = *this;
-	TwistBipoint affine_b = b;
-	affine_this.make_affine();
-	affine_b.make_affine();
-
 	bool retval;
 	bool retval;
+	twistpoint_fp2_t affine_op1, affine_op2;
 
 
-	retval =           fp2e_iseq(affine_this[0]->m_x, affine_b[0]->m_x);
-	retval = retval && fp2e_iseq(affine_this[0]->m_y, affine_b[0]->m_y); 
-	retval = retval && fp2e_iseq(affine_this[1]->m_x, affine_b[1]->m_x);
-	retval = retval && fp2e_iseq(affine_this[1]->m_y, affine_b[1]->m_y);
+	twistpoint_fp2_set(affine_op1, op1);
+	twistpoint_fp2_set(affine_op2, op2);
+
+	if (!(fp2e_isone(affine_op1->m_z) || fp2e_iszero(affine_op1->m_z)))
+		twistpoint_fp2_makeaffine(affine_op1);
+
+	if (!(fp2e_isone(affine_op2->m_z) || fp2e_iszero(affine_op2->m_z)))
+		twistpoint_fp2_makeaffine(affine_op2);
+
+	retval =           fp2e_iseq(affine_op1->m_x, affine_op2->m_x);
+	retval = retval && fp2e_iseq(affine_op1->m_y, affine_op2->m_y);
+	retval = retval || (fp2e_iszero(affine_op1->m_z) && fp2e_iszero(affine_op2->m_z));
 
 
 	return retval;
 	return retval;
 }
 }
 
 
-bool CurveBipoint::operator!=(const CurveBipoint& b) const
+bool CurveBipoint::operator==(const CurveBipoint& b) const
 {
 {
-	return !(*this == b);
+	return equal(point[0], b[0]) && equal(point[1], b[1]);
 }
 }
 
 
-bool TwistBipoint::operator!=(const TwistBipoint& b) const
+bool TwistBipoint::operator==(const TwistBipoint& b) const
 {
 {
-	return !(*this == b);
+	return equal(point[0], b[0]) && equal(point[1], b[1]);
 }
 }
 
 
-CurveBipoint CurveBipoint::mult_by_2() const
+bool CurveBipoint::operator!=(const CurveBipoint& b) const
 {
 {
-	CurveBipoint retval;
-
-	curvepoint_fp_double(retval[0], point[0]);
-	curvepoint_fp_double(retval[1], point[1]);
-
-	return retval;
+	return !(*this == b);
 }
 }
 
 
-TwistBipoint TwistBipoint::mult_by_2() const
+bool TwistBipoint::operator!=(const TwistBipoint& b) const
 {
 {
-	TwistBipoint retval;
-
-	twistpoint_fp2_double(retval[0], point[0]);
-	twistpoint_fp2_double(retval[1], point[1]);
-
-	return retval;
+	return !(*this == b);
 }
 }
 
 
 void CurveBipoint::make_affine()
 void CurveBipoint::make_affine()
@@ -194,40 +204,84 @@ std::ostream& operator<<(std::ostream& os, const TwistBipoint& output)
 
 
 size_t CurveBipointHash::operator()(const CurveBipoint& x) const
 size_t CurveBipointHash::operator()(const CurveBipoint& x) const
 {
 {
-	size_t retval = 0;
+	size_t retval[2];
+	bool infinity[2];
 	CurveBipoint affine_x = x;
 	CurveBipoint affine_x = x;
 	std::hash<double> hasher;
 	std::hash<double> hasher;
+
+	if (fpe_iszero(affine_x[0]->m_z))
+	{
+		retval[0] = 0;
+		infinity[0] = true;
+	}
+	else
+	{
+		retval[0] = 0;
+		infinity[0] = false;
+	}
+
+	if (fpe_iszero(affine_x[1]->m_z))
+	{
+		retval[1] = 0;
+		infinity[1] = true;
+	}
+	else
+	{
+		retval[1] = 0;
+		infinity[1] = false;
+	}
 	
 	
 	affine_x.make_affine();
 	affine_x.make_affine();
 
 
 	for (int i = 0; i < 2; i++)
 	for (int i = 0; i < 2; i++)
 	{
 	{
-		for (int j = 0; j < 12; j++)
+		for (int j = 0; j < 12 && !infinity[i]; j++)
 		{
 		{
-			retval ^= hasher(affine_x[i]->m_x->v[j]);
-			retval ^= hasher(affine_x[i]->m_y->v[j]);
+			retval[i] ^= hasher(affine_x[i]->m_x->v[j]);
+			retval[i] ^= hasher(affine_x[i]->m_y->v[j]);
 		}
 		}
 	}
 	}
 
 
-	return retval;
+	return retval[0] ^ retval[1];
 }
 }
 
 
 size_t TwistBipointHash::operator()(const TwistBipoint& x) const
 size_t TwistBipointHash::operator()(const TwistBipoint& x) const
 {
 {
-	size_t retval = 0;
+	size_t retval[2];
+	bool infinity[2];
 	TwistBipoint affine_x = x;
 	TwistBipoint affine_x = x;
 	std::hash<double> hasher;
 	std::hash<double> hasher;
-	
-	affine_x.make_affine();
 
 
+	if (fp2e_iszero(affine_x[0]->m_z))
+	{
+		retval[0] = 0;
+		infinity[0] = true;
+	}
+	else
+	{
+		retval[0] = 0;
+		infinity[0] = false;
+	}
+
+	if (fp2e_iszero(affine_x[1]->m_z))
+	{
+		retval[1] = 0;
+		infinity[1] = true;
+	}
+	else
+	{
+		retval[1] = 0;
+		infinity[1] = false;
+	}
+	
 	for (int i = 0; i < 2; i++)
 	for (int i = 0; i < 2; i++)
 	{
 	{
-		for (int j = 0; j < 24; j++)
+		for (int j = 0; j < 24 && !infinity[i]; j++)
 		{
 		{
-			retval ^= hasher(affine_x[i]->m_x->v[j]);
-			retval ^= hasher(affine_x[i]->m_y->v[j]);
+			retval[i] ^= hasher(affine_x[i]->m_x->v[j]);
+			retval[i] ^= hasher(affine_x[i]->m_y->v[j]);
 		}
 		}
 	}
 	}
 
 
-	return retval;
+	return retval[0] ^ retval[1];
 }
 }

+ 45 - 33
bgn2/src/PrivateKey.cpp

@@ -1,73 +1,77 @@
 #include "PrivateKey.hpp"
 #include "PrivateKey.hpp"
 
 
-Scalar PrivateKey::decrypt(const CurveBipoint& ciphertext) const
+Scalar PrivateKey::decrypt(const CurveBipoint& ciphertext)
 {
 {
-    static std::unordered_map<CurveBipoint, Scalar, CurveBipointHash> memoizer;
-    static Scalar max_checked = Scalar(0);
-
     CurveBipoint pi_1_ciphertext = pi_1(ciphertext); 
     CurveBipoint pi_1_ciphertext = pi_1(ciphertext); 
 
 
-    auto lookup = memoizer.find(pi_1_ciphertext);
-    if (lookup != memoizer.end())
+    auto lookup = curve_memoizer.find(pi_1_ciphertext);
+    if (lookup != curve_memoizer.end())
     {
     {
         return lookup->second;
         return lookup->second;
     }
     }
 
 
-    CurveBipoint i = pi_1_curvegen * max_checked;
-    do
+    curve_max_checked++;
+    CurveBipoint i = pi_1_curvegen * curve_max_checked;
+
+    while (i != pi_1_ciphertext)
     {
     {
-        memoizer[pi_1_ciphertext] = max_checked++;
+        curve_memoizer[i] = curve_max_checked;
+
         i = i + pi_1_curvegen;
         i = i + pi_1_curvegen;
-    } while (i != pi_1_ciphertext);
+        curve_max_checked++;
+    }
+    curve_memoizer[i] = curve_max_checked;
 
 
-    return max_checked - Scalar(1);
+    return curve_max_checked;
 }
 }
 
 
-Scalar PrivateKey::decrypt(const TwistBipoint& ciphertext) const
+Scalar PrivateKey::decrypt(const TwistBipoint& ciphertext)
 {
 {
-    static std::unordered_map<TwistBipoint, Scalar, TwistBipointHash> memoizer;
-    static Scalar max_checked = Scalar(0);
-
     TwistBipoint pi_2_ciphertext = pi_2(ciphertext);
     TwistBipoint pi_2_ciphertext = pi_2(ciphertext);
 
 
-    auto lookup = memoizer.find(pi_2_ciphertext);
-    if (lookup != memoizer.end())
+    auto lookup = twist_memoizer.find(pi_2_ciphertext);
+    if (lookup != twist_memoizer.end())
     {
     {
         return lookup->second;
         return lookup->second;
     }
     }
 
 
-    TwistBipoint i = pi_2_twistgen * max_checked;
-    do
+    twist_max_checked++;
+    TwistBipoint i = pi_2_twistgen * twist_max_checked;
+    while (i != pi_2_ciphertext)
     {
     {
-        memoizer[pi_2_ciphertext] = max_checked++;
+        twist_memoizer[i] = twist_max_checked;
+
         i = i + pi_2_twistgen;
         i = i + pi_2_twistgen;
-    } while (i != pi_2_ciphertext);
+        twist_max_checked++;
+    }
+    twist_memoizer[i] = twist_max_checked;
 
 
-    return max_checked - Scalar(1);
+    return twist_max_checked;
 }
 }
 
 
 
 
-Scalar PrivateKey::decrypt(const Quadripoint& ciphertext) const
+Scalar PrivateKey::decrypt(const Quadripoint& ciphertext)
 {
 {
-    static std::unordered_map<Quadripoint, Scalar, QuadripointHash> memoizer;
-    static Scalar max_checked = Scalar(0);
-
     Quadripoint pi_T_ciphertext = pi_T(ciphertext); 
     Quadripoint pi_T_ciphertext = pi_T(ciphertext); 
 
 
-    auto lookup = memoizer.find(pi_T_ciphertext);
-    if (lookup != memoizer.end())
+    auto lookup = pair_memoizer.find(pi_T_ciphertext);
+    if (lookup != pair_memoizer.end())
     {
     {
         return lookup->second;
         return lookup->second;
     }
     }
 
 
-    Quadripoint i = pi_T_pairgen * max_checked;
-    do
+    pair_max_checked++;
+    Quadripoint i = pi_T_pairgen * pair_max_checked;
+    while (i != pi_T_ciphertext)
     {
     {
-        memoizer[pi_T_ciphertext] = max_checked++;
+        pair_memoizer[i] = pair_max_checked;
+
         i = i + pi_T_pairgen;
         i = i + pi_T_pairgen;
-    } while (i != pi_T_ciphertext);
+        pair_max_checked++;
+    }
+    pair_memoizer[i] = pair_max_checked;
 
 
-    return max_checked - Scalar(1);
+    return pair_max_checked;
 }
 }
 
 
 PrivateKey::PrivateKey()
 PrivateKey::PrivateKey()
@@ -88,6 +92,14 @@ void PrivateKey::set(const PublicKey& pub_key, const Scalar& a1, const Scalar& b
     this->pi_1_curvegen = pi_1(pub_key.get_bipoint_curvegen());
     this->pi_1_curvegen = pi_1(pub_key.get_bipoint_curvegen());
     this->pi_2_twistgen = pi_2(pub_key.get_bipoint_twistgen());
     this->pi_2_twistgen = pi_2(pub_key.get_bipoint_twistgen());
     this->pi_T_pairgen  = pi_T(pairing(pub_key.get_bipoint_curvegen(), pub_key.get_bipoint_twistgen()));
     this->pi_T_pairgen  = pi_T(pairing(pub_key.get_bipoint_curvegen(), pub_key.get_bipoint_twistgen()));
+
+    this->curve_max_checked = Scalar(0);
+    this->twist_max_checked = Scalar(0);
+    this->pair_max_checked = Scalar(0);
+
+    this->curve_memoizer[this->pi_1_curvegen * this->curve_max_checked] = this->curve_max_checked;
+    this->twist_memoizer[this->pi_2_twistgen * this->twist_max_checked] = this->twist_max_checked;
+    this->pair_memoizer[this->pi_T_pairgen * this->pair_max_checked] = this->pair_max_checked;
 }
 }
 
 
 CurveBipoint PrivateKey::pi_1(const CurveBipoint& input) const
 CurveBipoint PrivateKey::pi_1(const CurveBipoint& input) const

+ 19 - 4
bgn2/src/Quadripoint.cpp

@@ -30,10 +30,25 @@ Quadripoint Quadripoint::operator+(const Quadripoint& b) const
 {
 {
 	Quadripoint retval;
 	Quadripoint retval;
 
 
-	fp12e_mul(retval[0], point[0], b.point[0]);
-	fp12e_mul(retval[1], point[1], b.point[1]);
-	fp12e_mul(retval[2], point[2], b.point[2]);
-	fp12e_mul(retval[3], point[3], b.point[3]);
+	if (fp12e_iseq(point[0], b[0]))
+		fp12e_square(retval[0], point[0]);
+	else
+		fp12e_mul(retval[0], point[0], b[0]);
+
+	if (fp12e_iseq(point[1], b[1]))
+		fp12e_square(retval[1], point[1]);
+	else
+		fp12e_mul(retval[1], point[1], b[1]);
+
+	if (fp12e_iseq(point[2], b[2]))
+		fp12e_square(retval[2], point[2]);
+	else
+		fp12e_mul(retval[2], point[2], b[2]);
+
+	if (fp12e_iseq(point[3], b[3]))
+		fp12e_square(retval[3], point[3]);
+	else
+		fp12e_mul(retval[3], point[3], b[3]);
 
 
 	return retval;
 	return retval;
 }
 }

+ 34 - 31
bgn2/src/main.cpp

@@ -8,64 +8,67 @@ int main(void)
 
 
     // const PrivateKey sk = system.get_private_key();
     // const PrivateKey sk = system.get_private_key();
 
 
-    Scalar test3(0);
+    Scalar test0(0);
+    Scalar test1(1);
+    Scalar test3(3);
     Scalar test5(5);
     Scalar test5(5);
-    Scalar decrypted3, decrypted5, decrypted6, decrypted10, decrypted15, decrypted30;
+    Scalar decrypted0, decrypted1, decrypted3, decrypted5, decrypted6, decrypted10, decrypted15, decrypted30;
 
 
+    std::cout << "Scalar test value (0): " << test0 << std::endl;
+    // std::cout << "Scalar test value (1): " << test1 << std::endl;
     std::cout << "Scalar test value (3): " << test3 << std::endl;
     std::cout << "Scalar test value (3): " << test3 << std::endl;
     std::cout << "Scalar test value (5): " << test5 << std::endl;
     std::cout << "Scalar test value (5): " << test5 << std::endl;
 
 
-    CurveBipoint encrypted3, encrypted6;
+    CurveBipoint encrypted0, encrypted1, encrypted3, encrypted6;
     // CurveBipoint pi_1_encrypted3, pi_1_curvegen_times3;
     // CurveBipoint pi_1_encrypted3, pi_1_curvegen_times3;
     TwistBipoint encrypted5, encrypted10;
     TwistBipoint encrypted5, encrypted10;
     Quadripoint encrypted15, encrypted30;
     Quadripoint encrypted15, encrypted30;
 
 
     std::cout << "Performing encryptions" << std::endl;
     std::cout << "Performing encryptions" << std::endl;
 
 
+    system.encrypt(encrypted0, test0);
+    // system.encrypt(encrypted1, test1);
     system.encrypt(encrypted3, test3);
     system.encrypt(encrypted3, test3);
-    // pi_1_encrypted3 = sk.pi_1(encrypted3);
-    // pi_1_encrypted3.make_affine();
-    // pi_1_curvegen_times3 = sk.pi_1_curvegen * test3;
-    // pi_1_curvegen_times3.make_affine();
-    // std::cout << std:: endl;
-    // std::cout << "Partially decrypted test value (3): " << pi_1_encrypted3 << std::endl;
-    // std::cout << std:: endl;
-    // std::cout << "What it should match up to (3): " << pi_1_curvegen_times3 << std::endl;
-    // std::cout << std:: endl;
-    // system.encrypt(encrypted5, test5);
+    system.encrypt(encrypted5, test5);
 
 
-    // std::cout << "Performing additions" << std::endl;
+    std::cout << "Performing additions" << std::endl;
 
 
-    // encrypted6 = system.homomorphic_addition(encrypted3, encrypted3);
-    // encrypted10 = system.homomorphic_addition(encrypted5, encrypted5);
+    encrypted6 = system.homomorphic_addition(encrypted3, encrypted3);
+    encrypted10 = system.homomorphic_addition(encrypted5, encrypted5);
 
 
-    // std::cout << "Performing multiplication" << std::endl;
+    std::cout << "Performing multiplication" << std::endl;
 
 
-    // encrypted15 = system.homomorphic_multiplication(encrypted3, encrypted5);
+    encrypted15 = system.homomorphic_multiplication(encrypted3, encrypted5);
 
 
-    // std::cout << "Performing L2 addition" << std::endl;
+    std::cout << "Performing L2 addition" << std::endl;
 
 
-    // encrypted30 = system.homomorphic_addition(encrypted15, encrypted15);
+    encrypted30 = system.homomorphic_addition(encrypted15, encrypted15);
 
 
-    // std::cout << "Performing decryptions" << std::endl;
+    std::cout << "Performing decryptions" << std::endl;
 
 
+    decrypted0  = system.decrypt(encrypted0);
+    std::cout << "Scalar decrypted value (0):   " << decrypted0  << std::endl;
+    // decrypted1  = system.decrypt(encrypted1);
+    // std::cout << "Scalar decrypted value (1):   " << decrypted1  << std::endl;
+    // decrypted1  = system.decrypt(encrypted1);
+    // std::cout << "Scalar decrypted value (1):   " << decrypted1  << std::endl;
     decrypted3  = system.decrypt(encrypted3);
     decrypted3  = system.decrypt(encrypted3);
     std::cout << "Scalar decrypted value (3):   " << decrypted3  << std::endl;
     std::cout << "Scalar decrypted value (3):   " << decrypted3  << std::endl;
 
 
-    // decrypted5  = system.decrypt(encrypted5);
-    // std::cout << "Scalar decrypted value (5):   " << decrypted5  << std::endl;
+    decrypted5  = system.decrypt(encrypted5);
+    std::cout << "Scalar decrypted value (5):   " << decrypted5  << std::endl;
 
 
-    // decrypted6  = system.decrypt(encrypted6);
-    // std::cout << "Scalar decrypted value (6):   " << decrypted6  << std::endl;
+    decrypted6  = system.decrypt(encrypted6);
+    std::cout << "Scalar decrypted value (6):   " << decrypted6  << std::endl;
 
 
-    // decrypted10 = system.decrypt(encrypted10);
-    // std::cout << "Scalar decrypted value (10): "  << decrypted10 << std::endl;
+    decrypted10 = system.decrypt(encrypted10);
+    std::cout << "Scalar decrypted value (10): "  << decrypted10 << std::endl;
 
 
-    // decrypted15 = system.decrypt(encrypted15);
-    // std::cout << "Scalar decrypted value (15): "  << decrypted15 << std::endl;
+    decrypted15 = system.decrypt(encrypted15);
+    std::cout << "Scalar decrypted value (15): "  << decrypted15 << std::endl;
 
 
-    // decrypted30 = system.decrypt(encrypted30);
-    // std::cout << "Scalar decrypted value (30): "  << decrypted30 << std::endl;
+    decrypted30 = system.decrypt(encrypted30);
+    std::cout << "Scalar decrypted value (30): "  << decrypted30 << std::endl;
 
 
     return 0;
     return 0;
 }
 }