aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-03-18 09:07:28 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-03-18 09:07:28 +0800
commit6e366d2454a075b00254f0799e20a2b46c2e83ce (patch)
tree9854c85137e4216eddc56abe780618f94b561e25
parentfa653e858f0dcc1a22504c51d65a3c379b9b4868 (diff)
downloaddexon-mcl-6e366d2454a075b00254f0799e20a2b46c2e83ce.tar.gz
dexon-mcl-6e366d2454a075b00254f0799e20a2b46c2e83ce.tar.zst
dexon-mcl-6e366d2454a075b00254f0799e20a2b46c2e83ce.zip
bls12::mapToG1 is ok
-rw-r--r--.gitignore1
-rw-r--r--include/mcl/bls12.hpp14
-rw-r--r--test/bls12_test.cpp2
3 files changed, 13 insertions, 4 deletions
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<Fp2> G2;
typedef util::HaveFrobenius<G2> 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<class G, class F>
void calc(G& P, const F& t) const
@@ -57,7 +67,7 @@ struct MapToT {
void calcG1(G1& P, const Fp& t) const
{
calc<G1, Fp>(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<G2, Fp2>(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);