From 76b13b05edab0bdf26b918286670bccf9013a0bf Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 22 Sep 2018 08:51:34 +0900 Subject: mapToFunction for BLS12 is changed to calcBN --- include/mcl/bn.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'include/mcl/bn.hpp') diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp index 38f3f8d..8e9a9c6 100644 --- a/include/mcl/bn.hpp +++ b/include/mcl/bn.hpp @@ -414,6 +414,9 @@ struct MapTo { #endif #endif } + /* + 1.2~1.4 times faster than calBN + */ template void naiveMapTo(G& P, const F& t) const { @@ -480,6 +483,10 @@ struct MapTo { z_ = z; // cofactor for G1 cofactor_ = (z - 1) * (z - 1) / 3; + bool b = Fp::squareRoot(c1_, -3); + assert(b); + (void)b; + c2_ = (c1_ - 1) / 2; } void init(const mpz_class& cofactor, const mpz_class &z, bool isBN, int curveType = -1) { @@ -494,8 +501,13 @@ struct MapTo { { if (isBN_) { if (!calcBN(P, t)) return false; + // no subgroup } else { +#ifdef MCL_USE_OLD_MAPTO_FOR_BLS12 naiveMapTo(P, t); +#else + if (!calcBN(P, t)) return false; +#endif mulByCofactorBLS12(P, P); } assert(P.isValid()); @@ -510,7 +522,11 @@ struct MapTo { if (!calcBN(P, t)) return false; mulByCofactorBN(P, P); } else { - naiveMapTo(P, t); +#ifdef MCL_USE_OLD_MAPTO_FOR_BLS12 + naiveMapTo(P, t); +#else + if (!calcBN(P, t)) return false; +#endif mulByCofactorBLS12(P, P); } assert(P.isValid()); -- cgit