defaut constructor of Ec does not clear the memory

dev
MITSUNARI Shigeo 8 years ago
parent ba9de011e7
commit faa01c6e11
  1. 12
      include/mcl/ec.hpp
  2. 1
      include/mcl/window_method.hpp
  3. 4
      readme.md
  4. 1
      test/bn_test.cpp
  5. 9
      test/ec_test.cpp

@ -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);
}

@ -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).

@ -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());

@ -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;

Loading…
Cancel
Save