diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-03-17 20:07:10 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-03-17 20:07:10 +0800 |
commit | faa01c6e11d5cad557429303a51209f0f995f548 (patch) | |
tree | 3319a67d8e8445469befe8c55789a088214a0b08 | |
parent | ba9de011e73403cadf820d25d085a69a2f3d8c04 (diff) | |
download | dexon-mcl-faa01c6e11d5cad557429303a51209f0f995f548.tar.gz dexon-mcl-faa01c6e11d5cad557429303a51209f0f995f548.tar.zst dexon-mcl-faa01c6e11d5cad557429303a51209f0f995f548.zip |
defaut constructor of Ec does not clear the memory
-rw-r--r-- | include/mcl/ec.hpp | 12 | ||||
-rw-r--r-- | include/mcl/window_method.hpp | 1 | ||||
-rw-r--r-- | readme.md | 4 | ||||
-rw-r--r-- | test/bn_test.cpp | 1 | ||||
-rw-r--r-- | test/ec_test.cpp | 9 |
5 files changed, 19 insertions, 8 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 16fb43e..6e3e569 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -61,12 +61,8 @@ public: */ static bool verifyOrder_; static mpz_class order_; -#ifdef MCL_EC_USE_AFFINE - EcT() : inf_(true) {} -#else - /* can't call z.clear() beforing Fp::init() */ - EcT() { memset(&z, 0, sizeof(z)); } -#endif + /* default constructor is undefined value */ + EcT() {} EcT(const Fp& _x, const Fp& _y) { set(_x, _y); @@ -737,7 +733,9 @@ public: static inline void getYfromX(Fp& y, const Fp& x, bool isYodd) { getWeierstrass(y, x); - if (!Fp::squareRoot(y, y)) throw cybozu::Exception("EcT:getYfromX") << x << isYodd; + if (!Fp::squareRoot(y, y)) { + throw cybozu::Exception("EcT:getYfromX") << x << isYodd; + } if (y.isOdd() ^ isYodd) { Fp::neg(y, y); } diff --git a/include/mcl/window_method.hpp b/include/mcl/window_method.hpp index 1dda10a..6f129d3 100644 --- a/include/mcl/window_method.hpp +++ b/include/mcl/window_method.hpp @@ -98,6 +98,7 @@ public: for (size_t i = 0; i < tblNum; i++) { tbl_[i].resize(r); EcV& w = tbl_[i]; + w[0].clear(); for (size_t d = 1; d < r; d *= 2) { for (size_t j = 0; j < d; j++) { Ec::add(w[j + d], w[j], t); @@ -116,6 +116,10 @@ mcl::bn256::BN::pairing(e, P, Q); See [test/bn_test.cpp](https://github.com/herumi/mcl/blob/master/test/bn_test.cpp).
+## Default constructor of Fp, Ec, etc.
+A default constructor does not initialize the instance.
+Set a valid value before reffering it.
+
## String format of G1 and G2
G1 and G2 have three elements of Fp (x, y, z) for Jacobi coordinate.
normalize() method normalizes it to affine coordinate (x, y, 1) or (0, 0, 0).
diff --git a/test/bn_test.cpp b/test/bn_test.cpp index 01e4a33..c41494d 100644 --- a/test/bn_test.cpp +++ b/test/bn_test.cpp @@ -89,6 +89,7 @@ void testSetStr(const G2& Q0) { G2::setCompressedExpression(); G2 Q; + Q.clear(); for (int i = 0; i < 10; i++) { G2 R; R.setStr(Q.getStr()); diff --git a/test/ec_test.cpp b/test/ec_test.cpp index 210503b..c353f29 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -28,9 +28,11 @@ struct Test { void cstr() const { Ec O; + O.clear(); CYBOZU_TEST_ASSERT(O.isZero()); CYBOZU_TEST_ASSERT(O.isValid()); Ec P; + P.clear(); Ec::neg(P, O); CYBOZU_TEST_EQUAL(P, O); } @@ -63,8 +65,9 @@ struct Test { Fp y(para.gy); Zn n = 0; CYBOZU_TEST_NO_EXCEPTION(Ec(x, y)); - CYBOZU_TEST_EXCEPTION(Ec(x, y + 1), cybozu::Exception); + CYBOZU_TEST_EXCEPTION(Ec(x, y + 1), cybozu::Exception); Ec P(x, y), Q, R, O; + O.clear(); CYBOZU_TEST_ASSERT(P.isNormalized()); { Ec::neg(Q, P); @@ -153,6 +156,7 @@ struct Test { Ec P(x, y); Ec Q; Ec R; + R.clear(); for (int i = 0; i < 100; i++) { Ec::mul(Q, P, i); CYBOZU_TEST_EQUAL(Q, R); @@ -167,6 +171,7 @@ struct Test { Ec P(x, y); Ec Q; Ec R; + R.clear(); for (int i = 0; i < 100; i++) { Ec::mul(Q, P, -i); CYBOZU_TEST_EQUAL(Q, R); @@ -194,6 +199,7 @@ struct Test { Ec P(x, y); Ec Q; Ec R; + R.clear(); for (int i = 0; i < 100; i++) { Ec::mul(Q, P, Zn(i)); CYBOZU_TEST_EQUAL(Q, R); @@ -299,6 +305,7 @@ struct Test { { std::stringstream ss; Ec Q; + Q.clear(); ss << Q; Ec R; ss >> R; |