Browse Source

beginning to test

tristangurtler 3 years ago
parent
commit
c7865ddfdb

+ 4 - 0
bgn2/inc/Bipoint.hpp

@@ -1,9 +1,11 @@
 #ifndef __BIPOINT_HPP
 #define __BIPOINT_HPP
 
+#include <ostream>
 #include <functional>
 
 #include "Scalar.hpp"
+#include "print_helpers.hpp"
 
 extern "C" {
 #include "curvepoint_fp.h"
@@ -31,6 +33,7 @@ class CurveBipoint
 		void make_affine();
 
 		friend class CurveBipointHash;
+		friend std::ostream& operator<<(std::ostream& os, const CurveBipoint& output);
 	
 	private:
 		curvepoint_fp_t point[2];
@@ -63,6 +66,7 @@ class TwistBipoint
 		void make_affine();
 
 		friend class TwistBipointHash;
+		friend std::ostream& operator<<(std::ostream& os, const TwistBipoint& output);
 	
 	private:
 		twistpoint_fp2_t point[2];	

+ 2 - 0
bgn2/inc/Quadripoint.hpp

@@ -4,6 +4,7 @@
 #include <functional>
 
 #include "Scalar.hpp"
+#include "print_helpers.hpp"
 
 extern "C" {
 #include "fp12e.h"
@@ -27,6 +28,7 @@ class Quadripoint
 		Quadripoint square() const;
 
 		friend class QuadripointHash;
+		friend std::ostream& operator<<(std::ostream& os, const Quadripoint& output);
 	
 	private:
 		fp12e_t point[4];

+ 50 - 0
bgn2/inc/print_helpers.hpp

@@ -0,0 +1,50 @@
+#ifndef __PRINT_HELPERS_HPP
+#define __PRINT_HELPERS_HPP
+
+#include <iomanip>
+#include <ostream>
+
+extern "C" {
+#include "fp12e.h"
+#include "fp6e.h"
+#include "fp2e.h"
+#include "fpe.h"
+}
+
+class Fp12e {
+    public:
+        Fp12e(const fp12e_t& input);
+        friend std::ostream& operator<<(std::ostream& os, const Fp12e& output);
+
+    private:
+        fp12e_t data;
+};
+
+class Fp6e {
+    public:
+        Fp6e(const fp6e_t& input);
+        friend std::ostream& operator<<(std::ostream& os, const Fp6e& output);
+
+    private:
+        fp6e_t data;
+};
+
+class Fp2e {
+    public:
+        Fp2e(const fp2e_t& input);
+        friend std::ostream& operator<<(std::ostream& os, const Fp2e& output);
+
+    private:
+        fp2e_t data;
+};
+
+class Fpe {
+    public:
+        Fpe(const fpe_t& input);
+        friend std::ostream& operator<<(std::ostream& os, const Fpe& output);
+
+    private:
+        fpe_t data;
+};
+
+#endif

+ 28 - 0
bgn2/src/Bipoint.cpp

@@ -178,6 +178,34 @@ void TwistBipoint::make_affine()
 		twistpoint_fp2_makeaffine(point[1]);
 }
 
+std::ostream& operator<<(std::ostream& os, const CurveBipoint& output)
+{
+	os << "{[";
+	for (int i = 0; i < 2; i++)
+	{
+		os << Fpe(output[i]->m_x) << ", " << Fpe(output[i]->m_y) << ", " << Fpe(output[i]->m_z);
+		if (i < 1)
+			os << "], [";
+	}
+	os << "]}";
+
+	return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const TwistBipoint& output)
+{
+	os << "{[";
+	for (int i = 0; i < 2; i++)
+	{
+		os << Fp2e(output[i]->m_x) << ", " << Fp2e(output[i]->m_y) << ", " << Fp2e(output[i]->m_z);
+		if (i < 1)
+			os << "], [";
+	}
+	os << "]}";
+
+	return os;
+}
+
 size_t CurveBipointHash::operator()(const CurveBipoint& x) const
 {
 	size_t retval = 0;

+ 14 - 0
bgn2/src/Quadripoint.cpp

@@ -79,6 +79,20 @@ Quadripoint Quadripoint::square() const
 	return retval;	
 }
 
+std::ostream& operator<<(std::ostream& os, const Quadripoint& output)
+{
+	os << "{[";
+	for (int i = 0; i < 4; i++)
+	{
+		os << Fp12e(output[i]);
+		if (i < 3)
+			os << "], [";
+	}
+	os << "]}";
+
+	return os;
+}
+
 size_t QuadripointHash::operator()(const Quadripoint& x) const
 {
 	size_t retval = 0;

+ 12 - 0
bgn2/src/main.cpp

@@ -6,6 +6,8 @@ int main(void)
 {
     BGN system;
 
+    // const PrivateKey sk = system.get_private_key();
+
     Scalar test3(3);
     Scalar test5(5);
     Scalar decrypted3, decrypted5, decrypted6, decrypted10, decrypted15, decrypted30;
@@ -14,12 +16,22 @@ int main(void)
     std::cout << "Scalar test value (5): " << test5 << std::endl;
 
     CurveBipoint encrypted3, encrypted6;
+    // CurveBipoint pi_1_encrypted3, pi_1_curvegen_times3;
     TwistBipoint encrypted5, encrypted10;
     Quadripoint encrypted15, encrypted30;
 
     std::cout << "Performing encryptions" << std::endl;
 
     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);
 
     std::cout << "Performing additions" << std::endl;

+ 59 - 0
bgn2/src/print_helpers.cpp

@@ -0,0 +1,59 @@
+#include "print_helpers.hpp"
+
+Fp12e::Fp12e(const fp12e_t& input)
+{
+    fp12e_set(data, input);
+}
+
+Fp6e::Fp6e(const fp6e_t& input)
+{
+    fp6e_set(data, input);
+}
+
+Fp2e::Fp2e(const fp2e_t& input)
+{
+    fp2e_set(data, input);
+}
+
+Fpe::Fpe(const fpe_t& input)
+{
+    fpe_set(data, input);
+}
+
+std::ostream& operator<<(std::ostream& os, const Fp12e& output)
+{
+    os << "(" << Fp6e(output.data->m_a) << " * Z + " << Fp6e(output.data->m_b) << ")";
+
+    return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const Fp6e& output)
+{
+    os << "(" << Fp2e(output.data->m_a) << " * Y^2 + " << Fp2e(output.data->m_b) << " * Y + " << Fp2e(output.data->m_c) << ")";
+
+    return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const Fp2e& output)
+{
+    fpe_t a, b;
+    fp2e_to_2fpe(a, b, output.data);
+
+    os << "(" << Fpe(a) << " * X + " << Fpe(b) << ")";
+
+    return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const Fpe& output)
+{
+    os << "(";
+    for (int i = 0; i < 12; i++)
+    {
+        os << std::setw(10) << output.data->v[i] << std::setw(0);
+        if (i < 11)
+            os << ", ";
+    }
+    os << ")";
+
+    return os;
+}