Cleanup Add and Double return values

pull/871/head
Jeffrey Walton 2019-08-05 02:05:11 -04:00
parent 88b37cff04
commit bb8e4cb74c
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 24 additions and 26 deletions

50
ecp.cpp
View File

@ -503,12 +503,10 @@ ECP::AdditionFunction::AdditionFunction(const ECP& ecp)
{ {
if (m_ecp.GetField().IsMontgomeryRepresentation()) if (m_ecp.GetField().IsMontgomeryRepresentation())
{ {
// std::cerr << "Montgomery, skipping" << std::endl;
m_alpha = A_Montgomery; m_alpha = A_Montgomery;
} }
else else
{ {
// std::cerr << "non-Montgomery, continuing" << std::endl;
if (m_ecp.m_a == 0) if (m_ecp.m_a == 0)
{ {
m_alpha = A_0; m_alpha = A_0;
@ -577,10 +575,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P) const
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else if (m_alpha == A_0) else if (m_alpha == A_0)
{ {
@ -617,10 +615,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P) const
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else if (m_alpha == A_Star) else if (m_alpha == A_Star)
{ {
@ -657,10 +655,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P) const
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else // A_Montgomery else // A_Montgomery
{ {
@ -747,10 +745,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P, const Point& Q) con
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else if (m_alpha == A_0) else if (m_alpha == A_0)
{ {
@ -791,10 +789,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P, const Point& Q) con
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else if (m_alpha == A_Star) else if (m_alpha == A_Star)
{ {
@ -858,10 +856,10 @@ ECP::Point ECP::AdditionFunction::operator()(const Point& P, const Point& Q) con
const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3); const FieldElement inv = field.MultiplicativeInverse(Z3.IsZero() ? Integer::One() : Z3);
X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv); X3 = field.Multiply(X3, inv); Y3 = field.Multiply(Y3, inv);
if (Z3.IsZero()) // More gyrations
return m_ecp.Identity(); ECP::Point result(X3*Z3.NotZero(), Y3*Z3.NotZero());
else result.identity = Z3.IsZero();
return ECP::Point(X3, Y3); return result;
} }
else // A_Montgomery else // A_Montgomery
{ {