aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2019-02-13 15:41:09 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2019-02-13 15:41:09 +0800
commitbd1b8dc6239955e0bfe2b1bde09d3824e0b5e551 (patch)
tree317f59550cbe8625bcd63912fa4963341aaff344
parent1a560e0e66ccaf3c9c001df097e074618a201bbc (diff)
downloadtangerine-mcl-bd1b8dc6239955e0bfe2b1bde09d3824e0b5e551.tar.gz
tangerine-mcl-bd1b8dc6239955e0bfe2b1bde09d3824e0b5e551.tar.zst
tangerine-mcl-bd1b8dc6239955e0bfe2b1bde09d3824e0b5e551.zip
a little optimization of Ec::addProj for both are affine
-rw-r--r--include/mcl/ec.hpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp
index 9f42cf1..5ad2410 100644
--- a/include/mcl/ec.hpp
+++ b/include/mcl/ec.hpp
@@ -489,7 +489,6 @@ public:
}
static inline void addProj(EcT& R, const EcT& P, const EcT& Q, bool isPzOne, bool isQzOne)
{
-(void)isPzOne;
Fp r, PyQz, v, A, vv;
if (isQzOne) {
r = P.x;
@@ -498,8 +497,13 @@ public:
Fp::mul(r, P.x, Q.z);
Fp::mul(PyQz, P.y, Q.z);
}
- Fp::mul(A, Q.y, P.z);
- Fp::mul(v, Q.x, P.z);
+ if (isPzOne) {
+ A = Q.y;
+ v = Q.x;
+ } else {
+ Fp::mul(A, Q.y, P.z);
+ Fp::mul(v, Q.x, P.z);
+ }
v -= r;
if (v.isZero()) {
if (A == PyQz) {
@@ -517,10 +521,19 @@ public:
if (isQzOne) {
R.z = P.z;
} else {
- Fp::mul(R.z, P.z, Q.z);
+ if (isPzOne) {
+ R.z = Q.z;
+ } else {
+ Fp::mul(R.z, P.z, Q.z);
+ }
+ }
+ // R.z = 1 if isPzOne && isQzOne
+ if (isPzOne && isQzOne) {
+ R.z = vv;
+ } else {
+ A *= R.z;
+ R.z *= vv;
}
- A *= R.z;
- R.z *= vv;
A -= vv;
vv *= PyQz;
A -= r;