diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-04 11:58:49 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-04 11:58:49 +0800 |
commit | 0d9e994f57db742eb3266bd130d3e4aec7bd7553 (patch) | |
tree | a20c300aa78d6e66da9b4a72ce198b95dba00477 | |
parent | 16babbe104c4d1cf1832387ce043ec8a68a76440 (diff) | |
download | dexon-mcl-0d9e994f57db742eb3266bd130d3e4aec7bd7553.tar.gz dexon-mcl-0d9e994f57db742eb3266bd130d3e4aec7bd7553.tar.zst dexon-mcl-0d9e994f57db742eb3266bd130d3e4aec7bd7553.zip |
fix clear GLV for BLS12
-rw-r--r-- | include/mcl/bn.hpp | 7 | ||||
-rw-r--r-- | test/bls12_test.cpp | 30 | ||||
-rw-r--r-- | test/bn384_test.cpp | 8 |
3 files changed, 41 insertions, 4 deletions
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp index a962ab5..93e8f8d 100644 --- a/include/mcl/bn.hpp +++ b/include/mcl/bn.hpp @@ -991,7 +991,12 @@ struct BNT { { param.init(cp, mode); G2withF::init(cp.isMtype); - if (!param.isBLS12) { + if (param.isBLS12) { + // not supported yet + G1::setMulArrayGLV(0); + G2::setMulArrayGLV(0); + Fp12::setPowArrayGLV(0); + } else { G1::setMulArrayGLV(mulArrayGLV1); G2::setMulArrayGLV(mulArrayGLV2); Fp12::setPowArrayGLV(powArrayGLV2); diff --git a/test/bls12_test.cpp b/test/bls12_test.cpp index f43c68f..0aaf842 100644 --- a/test/bls12_test.cpp +++ b/test/bls12_test.cpp @@ -592,6 +592,36 @@ const char *eStr = CYBOZU_TEST_EQUAL(e1, e2); } +void testCurve(const mcl::CurveParam& cp) +{ + initPairing(cp, g_mode); + G1 P; + G2 Q; + BLS12::mapToG1(P, 1); + BLS12::mapToG2(Q, 1); + GT e1, e2; + BLS12::pairing(e1, P, Q); + cybozu::XorShift rg; + mpz_class a, b; + Fr r; + r.setRand(rg); a = r.getMpz(); + r.setRand(rg); b = r.getMpz(); + G1 aP; + G2 bQ; + G1::mul(aP, P, a); + G2::mul(bQ, Q, b); + BLS12::pairing(e2, aP, bQ); + GT::pow(e1, e1, a * b); + CYBOZU_TEST_EQUAL(e1, e2); +} +CYBOZU_TEST_AUTO(multi) +{ + puts("BN254BNb"); + testCurve(mcl::BN254BNb); + puts("BLS12_381"); + testCurve(mcl::BLS12_381); +} + int main(int argc, char *argv[]) try { diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp index 5349e86..abb6f84 100644 --- a/test/bn384_test.cpp +++ b/test/bn384_test.cpp @@ -38,13 +38,15 @@ void testCurve(const mcl::CurveParam& cp) CYBOZU_TEST_AUTO(pairing) { - puts("CurveFp254BNb"); + puts("BN254BNb"); // support 256-bit pairing testCurve(mcl::BN254BNb); - puts("CurveFp382_1"); + puts("BN382_1"); testCurve(mcl::BN382_1); - puts("CurveFp382_2"); + puts("BN382_2"); testCurve(mcl::BN382_2); + puts("BLS12_381"); + testCurve(mcl::BLS12_381); // Q is not on EcT, but bad order { const char *s = "1 18d3d8c085a5a5e7553c3a4eb628e88b8465bf4de2612e35a0a4eb018fb0c82e9698896031e62fd7633ffd824a859474 1dc6edfcf33e29575d4791faed8e7203832217423bf7f7fbf1f6b36625b12e7132c15fbc15562ce93362a322fb83dd0d 65836963b1f7b6959030ddfa15ab38ce056097e91dedffd996c1808624fa7e2644a77be606290aa555cda8481cfb3cb 1b77b708d3d4f65aeedf54b58393463a42f0dc5856baadb5ce608036baeca398c5d9e6b169473a8838098fd72fd28b50"; |