rename tag name of special a

update-fork
MITSUNARI Shigeo 5 years ago
parent a03605c57f
commit 75b1a8adc7
  1. 49
      include/mcl/ec.hpp

@ -44,9 +44,9 @@ enum Mode {
}; };
enum ModeCoeffA { enum ModeCoeffA {
zero, Zero,
minus3, Minus3,
generic GenericA
}; };
namespace local { namespace local {
@ -121,11 +121,11 @@ void dblJacobi(E& R, const E& P, int specialA, const typename E::Fp& a)
S += S; S += S;
F::sqr(M, P.x); F::sqr(M, P.x);
switch (specialA) { switch (specialA) {
case zero: case Zero:
F::add(t, M, M); F::add(t, M, M);
M += t; M += t;
break; break;
case minus3: case Minus3:
if (isPzOne) { if (isPzOne) {
M -= P.z; M -= P.z;
} else { } else {
@ -136,7 +136,7 @@ void dblJacobi(E& R, const E& P, int specialA, const typename E::Fp& a)
F::add(t, M, M); F::add(t, M, M);
M += t; M += t;
break; break;
case generic: case GenericA:
default: default:
if (isPzOne) { if (isPzOne) {
t = a; t = a;
@ -173,10 +173,9 @@ void dblJacobi(E& R, const E& P, int specialA, const typename E::Fp& a)
mul| 12 mul| 12
add| 7 add| 7
*/ */
template<class E> template<class E, class F>
void addJacobi(E& R, const E& P, const E& Q, int specialA, const typename E::Fp& a) void addJacobi(E& R, const E& P, const E& Q, int specialA, const F& a)
{ {
typedef typename E::Fp F;
if (P.isZero()) { R = Q; return; } if (P.isZero()) { R = Q; return; }
if (Q.isZero()) { R = P; return; } if (Q.isZero()) { R = P; return; }
bool isPzOne = P.z.isOne(); bool isPzOne = P.z.isOne();
@ -283,10 +282,9 @@ bool isValidProj(const F& x, const F& y, const F& z, const F& a, const F& b)
mul| 8| 8| 9 mul| 8| 8| 9
add| 11|12|12 add| 11|12|12
*/ */
template<class E> template<class E, class F>
void dblProj(E& R, const E& P, int specialA, const typename E::Fp& a) void dblProj(E& R, const E& P, int specialA, const F& a)
{ {
typedef typename E::Fp F;
if (P.isZero()) { if (P.isZero()) {
R.clear(); R.clear();
return; return;
@ -294,12 +292,12 @@ void dblProj(E& R, const E& P, int specialA, const typename E::Fp& a)
const bool isPzOne = P.z.isOne(); const bool isPzOne = P.z.isOne();
F w, t, h; F w, t, h;
switch (specialA) { switch (specialA) {
case zero: case Zero:
F::sqr(w, P.x); F::sqr(w, P.x);
F::add(t, w, w); F::add(t, w, w);
w += t; w += t;
break; break;
case minus3: case Minus3:
F::sqr(w, P.x); F::sqr(w, P.x);
if (isPzOne) { if (isPzOne) {
w -= P.z; w -= P.z;
@ -310,7 +308,7 @@ void dblProj(E& R, const E& P, int specialA, const typename E::Fp& a)
F::add(t, w, w); F::add(t, w, w);
w += t; w += t;
break; break;
case generic: case GenericA:
default: default:
if (isPzOne) { if (isPzOne) {
w = a; w = a;
@ -354,10 +352,9 @@ void dblProj(E& R, const E& P, int specialA, const typename E::Fp& a)
mul| 12 mul| 12
add| 7 add| 7
*/ */
template<class E> template<class E, class F>
void addProj(E& R, const E& P, const E& Q, int specialA, const typename E::Fp& a) void addProj(E& R, const E& P, const E& Q, int specialA, const F& a)
{ {
typedef typename E::Fp F;
if (P.isZero()) { R = Q; return; } if (P.isZero()) { R = Q; return; }
if (Q.isZero()) { R = P; return; } if (Q.isZero()) { R = P; return; }
bool isPzOne = P.z.isOne(); bool isPzOne = P.z.isOne();
@ -431,10 +428,9 @@ bool isValidAffine(const F& x, const F& y, const F& a, const F& b)
} }
// y^2 = x^3 + ax + b // y^2 = x^3 + ax + b
template<class E> template<class E, class F>
static inline void dblAffine(E& R, const E& P, const typename E::Fp& a) static inline void dblAffine(E& R, const E& P, const F& a)
{ {
typedef typename E::Fp F;
if (P.isZero()) { if (P.isZero()) {
R.clear(); R.clear();
return; return;
@ -461,10 +457,9 @@ static inline void dblAffine(E& R, const E& P, const typename E::Fp& a)
R.z = 1; R.z = 1;
} }
template<class E> template<class E, class F>
void addAffine(E& R, const E& P, const E& Q, const typename E::Fp& a) void addAffine(E& R, const E& P, const E& Q, const F& a)
{ {
typedef typename E::Fp F;
if (P.isZero()) { R = Q; return; } if (P.isZero()) { R = Q; return; }
if (Q.isZero()) { R = P; return; } if (Q.isZero()) { R = P; return; }
F t; F t;
@ -571,11 +566,11 @@ public:
a_ = a; a_ = a;
b_ = b; b_ = b;
if (a_.isZero()) { if (a_.isZero()) {
specialA_ = ec::zero; specialA_ = ec::Zero;
} else if (a_ == -3) { } else if (a_ == -3) {
specialA_ = ec::minus3; specialA_ = ec::Minus3;
} else { } else {
specialA_ = ec::generic; specialA_ = ec::GenericA;
} }
ioMode_ = 0; ioMode_ = 0;
verifyOrder_ = false; verifyOrder_ = false;

Loading…
Cancel
Save