diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2019-02-13 15:21:23 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2019-02-13 15:21:23 +0800 |
commit | 1a560e0e66ccaf3c9c001df097e074618a201bbc (patch) | |
tree | 13c5947dcc470a3972aef7643914031fd75bfd85 | |
parent | 4006713fc5f4d2fdda68e511a5aed4ccec4313be (diff) | |
download | tangerine-mcl-1a560e0e66ccaf3c9c001df097e074618a201bbc.tar.gz tangerine-mcl-1a560e0e66ccaf3c9c001df097e074618a201bbc.tar.zst tangerine-mcl-1a560e0e66ccaf3c9c001df097e074618a201bbc.zip |
refactor Ec::add
-rw-r--r-- | include/mcl/ec.hpp | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 237b6c3..9f42cf1 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -487,9 +487,9 @@ public: H3 *= S1; Fp::sub(R.y, U1, H3); } - static inline void addProj(EcT& R, const EcT& P, const EcT& Q) + static inline void addProj(EcT& R, const EcT& P, const EcT& Q, bool isPzOne, bool isQzOne) { - const bool isQzOne = Q.z.isOne(); +(void)isPzOne; Fp r, PyQz, v, A, vv; if (isQzOne) { r = P.x; @@ -531,17 +531,14 @@ public: R.y -= vv; } #endif - static inline void add(EcT& R, const EcT& P0, const EcT& Q0) - { - if (P0.isZero()) { R = Q0; return; } - if (Q0.isZero()) { R = P0; return; } - if (&P0 == &Q0) { - dblNoVerifyInf(R, P0); + static inline void add(EcT& R, const EcT& P, const EcT& Q) { + if (P.isZero()) { R = Q; return; } + if (Q.isZero()) { R = P; return; } + if (&P == &Q) { + dblNoVerifyInf(R, P); return; } #ifdef MCL_EC_USE_AFFINE - const EcT& P(P0); - const EcT& Q(Q0); Fp t; Fp::neg(t, Q.y); if (P.y == t) { R.clear(); return; } @@ -563,22 +560,14 @@ public: Fp::sub(R.y, s, P.y); R.x = x3; #else - const EcT *pP = &P0; - const EcT *pQ = &Q0; - bool isPzOne = P0.z.isOne(); - bool isQzOne = Q0.z.isOne(); - if (pP->z.isOne()) { - fp::swap_(pP, pQ); - std::swap(isPzOne, isQzOne); - } - const EcT& P(*pP); - const EcT& Q(*pQ); + bool isPzOne = P.z.isOne(); + bool isQzOne = Q.z.isOne(); switch (mode_) { case ec::Jacobi: addJacobi(R, P, Q, isPzOne, isQzOne); break; case ec::Proj: - addProj(R, P, Q); + addProj(R, P, Q, isPzOne, isQzOne); break; } #endif |