|
@@ -1,52 +1,52 @@
|
|
|
#include "Bipoint.hpp"
|
|
|
|
|
|
-Bipoint<curvepoint_fp_t>::Bipoint()
|
|
|
+CurveBipoint::CurveBipoint()
|
|
|
{
|
|
|
curvepoint_fp_setneutral(point[0]);
|
|
|
curvepoint_fp_setneutral(point[1]);
|
|
|
}
|
|
|
|
|
|
-Bipoint<twistpoint_fp2_t>::Bipoint()
|
|
|
+TwistBipoint::TwistBipoint()
|
|
|
{
|
|
|
twistpoint_fp2_setneutral(point[0]);
|
|
|
twistpoint_fp2_setneutral(point[1]);
|
|
|
}
|
|
|
|
|
|
-Bipoint<curvepoint_fp_t>::Bipoint(curvepoint_fp_t p1, curvepoint_fp_t p2)
|
|
|
+CurveBipoint::CurveBipoint(curvepoint_fp_t p1, curvepoint_fp_t p2)
|
|
|
{
|
|
|
curvepoint_fp_set(point[0], p1);
|
|
|
curvepoint_fp_set(point[1], p2);
|
|
|
}
|
|
|
|
|
|
-Bipoint<twistpoint_fp2_t>::Bipoint(twistpoint_fp2_t p1, twistpoint_fp2_t p2)
|
|
|
+TwistBipoint::TwistBipoint(twistpoint_fp2_t p1, twistpoint_fp2_t p2)
|
|
|
{
|
|
|
twistpoint_fp2_set(point[0], p1);
|
|
|
twistpoint_fp2_set(point[1], p2);
|
|
|
}
|
|
|
|
|
|
-curvepoint_fp_t& Bipoint<curvepoint_fp_t>::operator[](int n)
|
|
|
+curvepoint_fp_t& CurveBipoint::operator[](int n)
|
|
|
{
|
|
|
return point[n];
|
|
|
}
|
|
|
|
|
|
-twistpoint_fp2_t& Bipoint<twistpoint_fp2_t>::operator[](int n)
|
|
|
+twistpoint_fp2_t& TwistBipoint::operator[](int n)
|
|
|
{
|
|
|
return point[n];
|
|
|
}
|
|
|
|
|
|
-const curvepoint_fp_t& Bipoint<curvepoint_fp_t>::operator[](int n) const
|
|
|
+const curvepoint_fp_t& CurveBipoint::operator[](int n) const
|
|
|
{
|
|
|
return point[n];
|
|
|
}
|
|
|
|
|
|
-const twistpoint_fp2_t& Bipoint<twistpoint_fp2_t>::operator[](int n) const
|
|
|
+const twistpoint_fp2_t& TwistBipoint::operator[](int n) const
|
|
|
{
|
|
|
return point[n];
|
|
|
}
|
|
|
|
|
|
-Bipoint<curvepoint_fp_t> Bipoint<curvepoint_fp_t>::operator+(const Bipoint<curvepoint_fp_t>& b) const
|
|
|
+CurveBipoint CurveBipoint::operator+(const CurveBipoint& b) const
|
|
|
{
|
|
|
- Bipoint<curvepoint_fp_t> 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]);
|
|
@@ -54,9 +54,9 @@ Bipoint<curvepoint_fp_t> Bipoint<curvepoint_fp_t>::operator+(const Bipoint<curve
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-Bipoint<twistpoint_fp2_t> Bipoint<twistpoint_fp2_t>::operator+(const Bipoint<twistpoint_fp2_t>& b) const
|
|
|
+TwistBipoint TwistBipoint::operator+(const TwistBipoint& b) const
|
|
|
{
|
|
|
- Bipoint<twistpoint_fp2_t> 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]);
|
|
@@ -64,83 +64,87 @@ Bipoint<twistpoint_fp2_t> Bipoint<twistpoint_fp2_t>::operator+(const Bipoint<twi
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-Bipoint<curvepoint_fp_t> Bipoint<curvepoint_fp_t>::operator*(const Scalar& mult) const
|
|
|
+CurveBipoint CurveBipoint::operator*(const Scalar& exp) const
|
|
|
{
|
|
|
- Bipoint<curvepoint_fp_t> retval;
|
|
|
+ CurveBipoint retval;
|
|
|
|
|
|
- retval[0] = mult * point[0];
|
|
|
- retval[1] = mult * point[1];
|
|
|
+ exp.mult(retval[0], point[0]);
|
|
|
+ exp.mult(retval[1], point[1]);
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-Bipoint<twistpoint_fp2_t> Bipoint<twistpoint_fp2_t>::operator*(const Scalar& mult) const
|
|
|
+TwistBipoint TwistBipoint::operator*(const Scalar& exp) const
|
|
|
{
|
|
|
- Bipoint<twistpoint_fp2_t> retval;
|
|
|
+ TwistBipoint retval;
|
|
|
|
|
|
- retval[0] = mult * point[0];
|
|
|
- retval[1] = mult * point[1];
|
|
|
+ exp.mult(retval[0], point[0]);
|
|
|
+ exp.mult(retval[1], point[1]);
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-bool Bipoint<curvepoint_fp_t>::operator==(const Bipoint<curvepoint_fp_t>& b) const
|
|
|
+bool CurveBipoint::operator==(const CurveBipoint& b) const
|
|
|
{
|
|
|
+ curvepoint_fp_t affine_point0, affine_point1, affine_b0, affine_b1;
|
|
|
+
|
|
|
+ curvepoint_fp_set(affine_point0, point[0]);
|
|
|
+ curvepoint_fp_set(affine_point1, point[1]);
|
|
|
+ curvepoint_fp_set(affine_b0, b[0]);
|
|
|
+ curvepoint_fp_set(affine_b1, b[1]);
|
|
|
+
|
|
|
+ curvepoint_fp_makeaffine(affine_point0);
|
|
|
+ curvepoint_fp_makeaffine(affine_point1);
|
|
|
+ curvepoint_fp_makeaffine(affine_b0);
|
|
|
+ curvepoint_fp_makeaffine(affine_b1);
|
|
|
+
|
|
|
bool retval;
|
|
|
|
|
|
- fpe_t point0_x1z2, point0_y1z2, point0_x2z1, point0_y2z1, point1_x1z2, point1_y1z2, point1_x2z1, point1_y2z1;
|
|
|
- fpe_mul(point0_x1z2, point[0]->m_x, b[0]->m_z);
|
|
|
- fpe_mul(point0_y1z2, point[0]->m_y, b[0]->m_z);
|
|
|
- fpe_mul(point0_x2z1, point[0]->m_z, b[0]->m_x);
|
|
|
- fpe_mul(point0_y2z1, point[0]->m_z, b[0]->m_y);
|
|
|
- fpe_mul(point1_x1z2, point[1]->m_x, b[1]->m_z);
|
|
|
- fpe_mul(point1_y1z2, point[1]->m_y, b[1]->m_z);
|
|
|
- fpe_mul(point1_x2z1, point[1]->m_z, b[1]->m_x);
|
|
|
- fpe_mul(point1_y2z1, point[1]->m_z, b[1]->m_y);
|
|
|
-
|
|
|
- retval = fpe_iseq(point0_x1z2, point0_x2z1);
|
|
|
- retval &&= fpe_iseq(point0_y1z2, point0_y2z1);
|
|
|
- retval &&= fpe_iseq(point1_x1z2, point1_x2z1);
|
|
|
- retval &&= fpe_iseq(point1_y1z2, point1_y2z1);
|
|
|
+ retval = fpe_iseq(affine_point0->m_x, affine_b0->m_x);
|
|
|
+ retval = retval && fpe_iseq(affine_point0->m_y, affine_b0->m_y);
|
|
|
+ retval = retval && fpe_iseq(affine_point1->m_x, affine_b1->m_x);
|
|
|
+ retval = retval && fpe_iseq(affine_point1->m_y, affine_b1->m_y);
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-bool Bipoint<twistpoint_fp2_t>::operator==(const Bipoint<twistpoint_fp2_t>& b) const
|
|
|
+bool TwistBipoint::operator==(const TwistBipoint& b) const
|
|
|
{
|
|
|
+ twistpoint_fp2_t affine_point0, affine_point1, affine_b0, affine_b1;
|
|
|
+
|
|
|
+ twistpoint_fp2_set(affine_point0, point[0]);
|
|
|
+ twistpoint_fp2_set(affine_point1, point[1]);
|
|
|
+ twistpoint_fp2_set(affine_b0, b[0]);
|
|
|
+ twistpoint_fp2_set(affine_b1, b[1]);
|
|
|
+
|
|
|
+ twistpoint_fp2_makeaffine(affine_point0);
|
|
|
+ twistpoint_fp2_makeaffine(affine_point1);
|
|
|
+ twistpoint_fp2_makeaffine(affine_b0);
|
|
|
+ twistpoint_fp2_makeaffine(affine_b1);
|
|
|
+
|
|
|
bool retval;
|
|
|
|
|
|
- fp2e_t point0_x1z2, point0_y1z2, point0_x2z1, point0_y2z1, point1_x1z2, point1_y1z2, point1_x2z1, point1_y2z1;
|
|
|
- fp2e_mul(point0_x1z2, point[0]->m_x, b[0]->m_z);
|
|
|
- fp2e_mul(point0_y1z2, point[0]->m_y, b[0]->m_z);
|
|
|
- fp2e_mul(point0_x2z1, point[0]->m_z, b[0]->m_x);
|
|
|
- fp2e_mul(point0_y2z1, point[0]->m_z, b[0]->m_y);
|
|
|
- fp2e_mul(point1_x1z2, point[1]->m_x, b[1]->m_z);
|
|
|
- fp2e_mul(point1_y1z2, point[1]->m_y, b[1]->m_z);
|
|
|
- fp2e_mul(point1_x2z1, point[1]->m_z, b[1]->m_x);
|
|
|
- fp2e_mul(point1_y2z1, point[1]->m_z, b[1]->m_y);
|
|
|
-
|
|
|
- retval = fp2e_iseq(point0_x1z2, point0_x2z1);
|
|
|
- retval &&= fp2e_iseq(point0_y1z2, point0_y2z1);
|
|
|
- retval &&= fp2e_iseq(point1_x1z2, point1_x2z1);
|
|
|
- retval &&= fp2e_iseq(point1_y1z2, point1_y2z1);
|
|
|
+ retval = fp2e_iseq(affine_point0->m_x, affine_b0->m_x);
|
|
|
+ retval = retval && fp2e_iseq(affine_point0->m_y, affine_b0->m_y);
|
|
|
+ retval = retval && fp2e_iseq(affine_point1->m_x, affine_b1->m_x);
|
|
|
+ retval = retval && fp2e_iseq(affine_point1->m_y, affine_b1->m_y);
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-bool Bipoint<curvepoint_fp_t>::operator!=(const Bipoint<curvepoint_fp_t>& b) const
|
|
|
+bool CurveBipoint::operator!=(const CurveBipoint& b) const
|
|
|
{
|
|
|
return !(*this == b);
|
|
|
}
|
|
|
|
|
|
-bool Bipoint<twistpoint_fp2_t>::operator!=(const Bipoint<twistpoint_fp2_t>& b) const
|
|
|
+bool TwistBipoint::operator!=(const TwistBipoint& b) const
|
|
|
{
|
|
|
return !(*this == b);
|
|
|
}
|
|
|
|
|
|
-Bipoint<curvepoint_fp_t> Bipoint<curvepoint_fp_t>::mult_by_2() const
|
|
|
+CurveBipoint CurveBipoint::mult_by_2() const
|
|
|
{
|
|
|
- Bipoint<curvepoint_fp_t> retval;
|
|
|
+ CurveBipoint retval;
|
|
|
|
|
|
curvepoint_fp_double(retval[0], point[0]);
|
|
|
curvepoint_fp_double(retval[1], point[1]);
|
|
@@ -148,9 +152,9 @@ Bipoint<curvepoint_fp_t> Bipoint<curvepoint_fp_t>::mult_by_2() const
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-Bipoint<twistpoint_fp2_t> Bipoint<twistpoint_fp2_t>::mult_by_2() const
|
|
|
+TwistBipoint TwistBipoint::mult_by_2() const
|
|
|
{
|
|
|
- Bipoint<twistpoint_fp2_t> retval;
|
|
|
+ TwistBipoint retval;
|
|
|
|
|
|
twistpoint_fp2_double(retval[0], point[0]);
|
|
|
twistpoint_fp2_double(retval[1], point[1]);
|
|
@@ -158,14 +162,58 @@ Bipoint<twistpoint_fp2_t> Bipoint<twistpoint_fp2_t>::mult_by_2() const
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-void Bipoint<curvepoint_fp_t>::make_affine()
|
|
|
+void CurveBipoint::make_affine()
|
|
|
+{
|
|
|
+ if (!(fpe_isone(point[0]->m_z)))
|
|
|
+ curvepoint_fp_makeaffine(point[0]);
|
|
|
+ if (!(fpe_isone(point[1]->m_z)))
|
|
|
+ curvepoint_fp_makeaffine(point[1]);
|
|
|
+}
|
|
|
+
|
|
|
+void TwistBipoint::make_affine()
|
|
|
{
|
|
|
- curvepoint_fp_makeaffine(point[0]);
|
|
|
- curvepoint_fp_makeaffine(point[1]);
|
|
|
+ if (!(fp2e_isone(point[0]->m_z)))
|
|
|
+ twistpoint_fp2_makeaffine(point[0]);
|
|
|
+ if (!(fp2e_isone(point[1]->m_z)))
|
|
|
+ twistpoint_fp2_makeaffine(point[1]);
|
|
|
}
|
|
|
|
|
|
-void Bipoint<twistpoint_fp2_t>::make_affine()
|
|
|
+size_t CurveBipointHash::operator()(const CurveBipoint& x) const
|
|
|
{
|
|
|
- twistpoint_fp2_makeaffine(point[0]);
|
|
|
- twistpoint_fp2_makeaffine(point[1]);
|
|
|
+ size_t retval = 0;
|
|
|
+ CurveBipoint affine_x = x;
|
|
|
+ std::hash<double> hasher;
|
|
|
+
|
|
|
+ affine_x.make_affine();
|
|
|
+
|
|
|
+ for (int i = 0; i < 2; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < 12; j++)
|
|
|
+ {
|
|
|
+ retval ^= hasher(affine_x[i]->m_x->v[j]);
|
|
|
+ retval ^= hasher(affine_x[i]->m_y->v[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+size_t TwistBipointHash::operator()(const TwistBipoint& x) const
|
|
|
+{
|
|
|
+ size_t retval = 0;
|
|
|
+ TwistBipoint affine_x = x;
|
|
|
+ std::hash<double> hasher;
|
|
|
+
|
|
|
+ affine_x.make_affine();
|
|
|
+
|
|
|
+ for (int i = 0; i < 2; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < 24; j++)
|
|
|
+ {
|
|
|
+ retval ^= hasher(affine_x[i]->m_x->v[j]);
|
|
|
+ retval ^= hasher(affine_x[i]->m_y->v[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return retval;
|
|
|
}
|