diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 4a29cfa..e1db56d 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -227,6 +227,12 @@ template bool isEqualJacobi(const E& P1, const E& P2) { typedef typename E::Fp F; + bool zero1 = P1.isZero(); + bool zero2 = P2.isZero(); + if (zero1) { + return zero2; + } + if (zero2) return false; F s1, s2, t1, t2; F::sqr(s1, P1.z); F::sqr(s2, P2.z); @@ -452,6 +458,12 @@ template bool isEqualProj(const E& P1, const E& P2) { typedef typename E::Fp F; + bool zero1 = P1.isZero(); + bool zero2 = P2.isZero(); + if (zero1) { + return zero2; + } + if (zero2) return false; F t1, t2; F::mul(t1, P1.x, P2.z); F::mul(t2, P2.x, P1.z); diff --git a/test/ec_test.cpp b/test/ec_test.cpp index 4c93e42..a3e79e5 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -95,6 +95,9 @@ struct Test { if (Ec::getMode() != mcl::ec::Affine) { CYBOZU_TEST_ASSERT(!R.isNormalized()); } + CYBOZU_TEST_ASSERT(O == O); + CYBOZU_TEST_ASSERT(R != O); + CYBOZU_TEST_ASSERT(O != R); CYBOZU_TEST_ASSERT(R.isValid()); Ec R2 = P + P; CYBOZU_TEST_EQUAL(R, R2);