|
@@ -1,6 +1,12 @@
|
|
|
#include "PublicKey.hpp"
|
|
|
|
|
|
-void PublicKey::encrypt(CurveBipoint& G_element, const Scalar& cleartext) const
|
|
|
+BGNPublicKey::BGNPublicKey(const BGNPublicKey& other)
|
|
|
+ : bipoint_curvegen(other.bipoint_curvegen), bipoint_twistgen(other.bipoint_twistgen),
|
|
|
+ bipoint_curve_subgroup_gen(other.bipoint_curve_subgroup_gen),
|
|
|
+ bipoint_twist_subgroup_gen(other.bipoint_twist_subgroup_gen)
|
|
|
+{ }
|
|
|
+
|
|
|
+void BGNPublicKey::encrypt(CurveBipoint& G_element, const Scalar& cleartext) const
|
|
|
{
|
|
|
Scalar lambda;
|
|
|
lambda.set_random();
|
|
@@ -12,7 +18,7 @@ void PublicKey::encrypt(CurveBipoint& G_element, const Scalar& cleartext) const
|
|
|
G_element = cleartext_as_element + random_mask;
|
|
|
}
|
|
|
|
|
|
-void PublicKey::encrypt(TwistBipoint& H_element, const Scalar& cleartext) const
|
|
|
+void BGNPublicKey::encrypt(TwistBipoint& H_element, const Scalar& cleartext) const
|
|
|
{
|
|
|
Scalar lambda;
|
|
|
lambda.set_random();
|
|
@@ -24,13 +30,13 @@ void PublicKey::encrypt(TwistBipoint& H_element, const Scalar& cleartext) const
|
|
|
H_element = cleartext_as_element + random_mask;
|
|
|
}
|
|
|
|
|
|
-void PublicKey::encrypt(CurveBipoint& G_element, TwistBipoint& H_element, const Scalar& cleartext) const
|
|
|
+void BGNPublicKey::encrypt(CurveBipoint& G_element, TwistBipoint& H_element, const Scalar& cleartext) const
|
|
|
{
|
|
|
encrypt(G_element, cleartext);
|
|
|
encrypt(H_element, cleartext);
|
|
|
}
|
|
|
|
|
|
-CurveBipoint PublicKey::homomorphic_addition(const CurveBipoint& a, const CurveBipoint& b) const
|
|
|
+CurveBipoint BGNPublicKey::homomorphic_addition(const CurveBipoint& a, const CurveBipoint& b) const
|
|
|
{
|
|
|
Scalar lambda;
|
|
|
lambda.set_random();
|
|
@@ -41,7 +47,7 @@ CurveBipoint PublicKey::homomorphic_addition(const CurveBipoint& a, const CurveB
|
|
|
return a + b + random_mask;
|
|
|
}
|
|
|
|
|
|
-TwistBipoint PublicKey::homomorphic_addition(const TwistBipoint& a, const TwistBipoint& b) const
|
|
|
+TwistBipoint BGNPublicKey::homomorphic_addition(const TwistBipoint& a, const TwistBipoint& b) const
|
|
|
{
|
|
|
Scalar lambda;
|
|
|
lambda.set_random();
|
|
@@ -52,7 +58,7 @@ TwistBipoint PublicKey::homomorphic_addition(const TwistBipoint& a, const TwistB
|
|
|
return a + b + random_mask;
|
|
|
}
|
|
|
|
|
|
-Quadripoint PublicKey::homomorphic_addition(const Quadripoint& a, const Quadripoint& b) const
|
|
|
+Quadripoint BGNPublicKey::homomorphic_addition(const Quadripoint& a, const Quadripoint& b) const
|
|
|
{
|
|
|
Quadripoint random_mask;
|
|
|
CurveBipoint random_mask_curve;
|
|
@@ -69,7 +75,7 @@ Quadripoint PublicKey::homomorphic_addition(const Quadripoint& a, const Quadripo
|
|
|
return a + b + random_mask;
|
|
|
}
|
|
|
|
|
|
-Quadripoint PublicKey::homomorphic_multiplication(const CurveBipoint& a, const TwistBipoint& b) const
|
|
|
+Quadripoint BGNPublicKey::homomorphic_multiplication(const CurveBipoint& a, const TwistBipoint& b) const
|
|
|
{
|
|
|
Quadripoint random_mask;
|
|
|
CurveBipoint random_mask_curve;
|
|
@@ -86,30 +92,69 @@ Quadripoint PublicKey::homomorphic_multiplication(const CurveBipoint& a, const T
|
|
|
return pairing(a, b) + random_mask;
|
|
|
}
|
|
|
|
|
|
-CurveBipoint PublicKey::get_bipoint_curvegen() const
|
|
|
+CurveBipoint rerandomize(const CurveBipoint& a) const
|
|
|
+{
|
|
|
+ Scalar lambda;
|
|
|
+ lambda.set_random();
|
|
|
+
|
|
|
+ CurveBipoint random_mask;
|
|
|
+ random_mask = bipoint_curve_subgroup_gen * lambda;
|
|
|
+
|
|
|
+ return a + random_mask;
|
|
|
+}
|
|
|
+
|
|
|
+TwistBipoint rerandomize(const TwistBipoint& a) const
|
|
|
+{
|
|
|
+ Scalar lambda;
|
|
|
+ lambda.set_random();
|
|
|
+
|
|
|
+ TwistBipoint random_mask;
|
|
|
+ random_mask = bipoint_twist_subgroup_gen * lambda;
|
|
|
+
|
|
|
+ return a + random_mask;
|
|
|
+}
|
|
|
+
|
|
|
+Quadripoint rerandomize(const Quadripoint& a) const
|
|
|
+{
|
|
|
+ Quadripoint random_mask;
|
|
|
+ CurveBipoint random_mask_curve;
|
|
|
+ TwistBipoint random_mask_twist;
|
|
|
+
|
|
|
+ Scalar lambda1, lambda2;
|
|
|
+ lambda1.set_random();
|
|
|
+ lambda2.set_random();
|
|
|
+
|
|
|
+ random_mask_curve = bipoint_curve_subgroup_gen * lambda1;
|
|
|
+ random_mask_twist = bipoint_twist_subgroup_gen * lambda2;
|
|
|
+ random_mask = pairing(bipoint_curvegen, random_mask_twist) + pairing(random_mask_curve, bipoint_twistgen);
|
|
|
+
|
|
|
+ return a + random_mask;
|
|
|
+}
|
|
|
+
|
|
|
+CurveBipoint BGNPublicKey::get_bipoint_curvegen() const
|
|
|
{
|
|
|
return bipoint_curvegen;
|
|
|
}
|
|
|
|
|
|
-TwistBipoint PublicKey::get_bipoint_twistgen() const
|
|
|
+TwistBipoint BGNPublicKey::get_bipoint_twistgen() const
|
|
|
{
|
|
|
return bipoint_twistgen;
|
|
|
}
|
|
|
|
|
|
-CurveBipoint PublicKey::get_bipoint_curve_subgroup_gen() const
|
|
|
+CurveBipoint BGNPublicKey::get_bipoint_curve_subgroup_gen() const
|
|
|
{
|
|
|
return bipoint_curve_subgroup_gen;
|
|
|
}
|
|
|
|
|
|
-TwistBipoint PublicKey::get_bipoint_twist_subgroup_gen() const
|
|
|
+TwistBipoint BGNPublicKey::get_bipoint_twist_subgroup_gen() const
|
|
|
{
|
|
|
return bipoint_twist_subgroup_gen;
|
|
|
}
|
|
|
|
|
|
-PublicKey::PublicKey()
|
|
|
+BGNPublicKey::BGNPublicKey()
|
|
|
{ }
|
|
|
|
|
|
-void PublicKey::set(const CurveBipoint& g, const TwistBipoint& h, const CurveBipoint& g1, const TwistBipoint& h1)
|
|
|
+void BGNPublicKey::set(const CurveBipoint& g, const TwistBipoint& h, const CurveBipoint& g1, const TwistBipoint& h1)
|
|
|
{
|
|
|
bipoint_curvegen = g;
|
|
|
bipoint_twistgen = h;
|