From 732c6b09934901f0b63fda447e458e82a416b82d Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 29 Jun 2020 15:09:58 +0900 Subject: [PATCH] add sswuG1 for E1 --- include/mcl/mapto_wb19.hpp | 33 +++++++++++++++++++++++++++------ test/mapto_wb19_test.cpp | 30 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/include/mcl/mapto_wb19.hpp b/include/mcl/mapto_wb19.hpp index 53430b2..bb97655 100644 --- a/include/mcl/mapto_wb19.hpp +++ b/include/mcl/mapto_wb19.hpp @@ -433,15 +433,15 @@ struct MapTo_WB19 { Fp::neg(y, y); } } - void sswuG1(Fp pt[3], const Fp& u) const + void sswuG1(E1& pt, const Fp& u) const { Fp xn, y; - Fp& xd = pt[2]; + Fp& xd = pt.z; sswuG1(xn, xd, y, u); - Fp::mul(pt[0], xn, xd); - Fp::sqr(pt[1], xd); - pt[1] *= xd; - pt[1] *= y; + Fp::mul(pt.x, xn, xd); + Fp::sqr(pt.y, xd); + pt.y *= xd; + pt.y *= y; } // https://github.com/algorand/bls_sigs_ref void osswu2_help(E2& P, const Fp2& t) const @@ -589,6 +589,27 @@ struct MapTo_WB19 { } map2curve_osswu2(out, msg, msgSize, dst, strlen(dst)); } +#if 0 + void msgToG1(G1& out, const void *msg, size_t msgSize) const + { + assert(draftVersion_ == 7); + const char *dst = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; + const size_t dstSize = strlen(dst); + uint8_t md[128]; + mcl::fp::expand_message_xmd(md, sizeof(md), msg, msgSize, dst, dstSize); + Fp u[2]; + for (size_t i = 0; i < 2; i++) { + bool b; + u[i].setBigEndianMod(&b, &md[64 * i], 64); + assert(b); (void)b; + } + E1 P1, P2; + sswuG1(P1, u[0]); + sswuG1(P2, u[1]); + ec::addJacobi(P1, P1, P2); // ok + // ec::normalizeJacobi(P1); + } +#endif }; } // mcl diff --git a/test/mapto_wb19_test.cpp b/test/mapto_wb19_test.cpp index 9652c69..fee202e 100644 --- a/test/mapto_wb19_test.cpp +++ b/test/mapto_wb19_test.cpp @@ -812,7 +812,6 @@ void testHashToFp2v6(const T& mapto) } }, }; - bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_06); for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { const char *msg = tbl[i].msg; const char *dst = tbl[i].dst; @@ -856,7 +855,6 @@ void testHashToFp2v6(const T& mapto) template void testHashToFp2v7(const T& mapto) { - bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07); { const char *msg = "asdf"; PointStr s = { @@ -1048,7 +1046,6 @@ void testEth2phase0() "882730e5d03f6b42c3abc26d3372625034e1d871b65a8a6b900a56dae22da98abbe1b68f85e49fe7652a55ec3d0591c20767677e33e5cbb1207315c41a9ac03be39c2e7668edc043d6cb1d9fd93033caa8a1c5b0e84bedaeb6c64972503a43eb", }, }; - bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07); for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { const Uint8Vec msg = fromHexStr(tbl[i].msg); const Uint8Vec out = fromHexStr(tbl[i].out); @@ -1103,6 +1100,30 @@ void testSswuG1(const T& mapto) } } +template +void testMsgToG1(const T& mapto) +{ + const struct { + const char *msg; + const char *x; + const char *y; + const char *z; + } tbl[] = { + { + "asdf", + "0", + "0", + "0", + }, + }; + for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { + const char *msg = tbl[i].msg; + const size_t msgSize = strlen(msg); + G1 P; + mapto.msgToG1(P, msg, msgSize); + } +} + CYBOZU_TEST_AUTO(test) { initPairing(mcl::BLS12_381); @@ -1122,8 +1143,11 @@ CYBOZU_TEST_AUTO(test) testVec("../misc/mapto/fips_186_3_B233.txt"); testVec("../misc/mapto/misc.txt"); ethMsgToG2testAll("../bls_sigs_ref/test-vectors/hash_g2/"); + bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_06); testHashToFp2v6(mapto); + bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07); testHashToFp2v7(mapto); testEth2phase0(); testSswuG1(mapto); +// testMsgToG1(mapto); }