diff --git a/.gitignore b/.gitignore index 5302ad3..f5edb37 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ GTAGS *.d *.exe *.swp +.cvsignore diff --git a/include/mcl/bls12.hpp b/include/mcl/bls12.hpp index ff0d207..eaccb77 100644 --- a/include/mcl/bls12.hpp +++ b/include/mcl/bls12.hpp @@ -21,6 +21,15 @@ struct MapToT { typedef mcl::EcT G2; typedef util::HaveFrobenius G2withF; mpz_class z_; + mpz_class cofactor1_; + /* + #(Fp) / r = (z + 1 - t) / r = (z - 1)^2 / 3 + */ + void mulByCofactor(G1& Q, const G1& P) const + { + assert(cofactor1_ != 0); + G1::mulGeneric(Q, P, cofactor1_); + } /* Q = (z(z-1)-1)P + Frob((z-1)P) + Frob^2(2P) */ @@ -39,6 +48,7 @@ struct MapToT { void init(const mpz_class& z) { z_ = z; + cofactor1_ = (z - 1) * (z - 1) / 3; } template void calc(G& P, const F& t) const @@ -57,7 +67,7 @@ struct MapToT { void calcG1(G1& P, const Fp& t) const { calc(P, t); - assert(P.isValid()); + mulByCofactor(P, P); } /* get the element in G2 by multiplying the cofactor @@ -65,9 +75,7 @@ struct MapToT { void calcG2(G2& P, const Fp2& t) const { calc(P, t); - assert(cofactor_ != 0); mulByCofactor(P, P); - assert(!P.isZero()); } }; diff --git a/test/bls12_test.cpp b/test/bls12_test.cpp index 373fc12..4211e9f 100644 --- a/test/bls12_test.cpp +++ b/test/bls12_test.cpp @@ -339,7 +339,7 @@ CYBOZU_TEST_AUTO(naive) // testFp12pow(P, Q); testTrivial(P, Q); testSetStr(Q); -// testMapToG1(); + testMapToG1(); testMapToG2(); testPairing(P, Q, ts.e); testPrecomputed(P, Q);