add sswuG1 for E1

update-fork
MITSUNARI Shigeo 4 years ago
parent 7333742229
commit 732c6b0993
  1. 33
      include/mcl/mapto_wb19.hpp
  2. 30
      test/mapto_wb19_test.cpp

@ -433,15 +433,15 @@ struct MapTo_WB19 {
Fp::neg(y, y); 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 xn, y;
Fp& xd = pt[2]; Fp& xd = pt.z;
sswuG1(xn, xd, y, u); sswuG1(xn, xd, y, u);
Fp::mul(pt[0], xn, xd); Fp::mul(pt.x, xn, xd);
Fp::sqr(pt[1], xd); Fp::sqr(pt.y, xd);
pt[1] *= xd; pt.y *= xd;
pt[1] *= y; pt.y *= y;
} }
// https://github.com/algorand/bls_sigs_ref // https://github.com/algorand/bls_sigs_ref
void osswu2_help(E2& P, const Fp2& t) const void osswu2_help(E2& P, const Fp2& t) const
@ -589,6 +589,27 @@ struct MapTo_WB19 {
} }
map2curve_osswu2(out, msg, msgSize, dst, strlen(dst)); 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 } // mcl

@ -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++) { for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
const char *msg = tbl[i].msg; const char *msg = tbl[i].msg;
const char *dst = tbl[i].dst; const char *dst = tbl[i].dst;
@ -856,7 +855,6 @@ void testHashToFp2v6(const T& mapto)
template<class T> template<class T>
void testHashToFp2v7(const T& mapto) void testHashToFp2v7(const T& mapto)
{ {
bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07);
{ {
const char *msg = "asdf"; const char *msg = "asdf";
PointStr s = { PointStr s = {
@ -1048,7 +1046,6 @@ void testEth2phase0()
"882730e5d03f6b42c3abc26d3372625034e1d871b65a8a6b900a56dae22da98abbe1b68f85e49fe7652a55ec3d0591c20767677e33e5cbb1207315c41a9ac03be39c2e7668edc043d6cb1d9fd93033caa8a1c5b0e84bedaeb6c64972503a43eb", "882730e5d03f6b42c3abc26d3372625034e1d871b65a8a6b900a56dae22da98abbe1b68f85e49fe7652a55ec3d0591c20767677e33e5cbb1207315c41a9ac03be39c2e7668edc043d6cb1d9fd93033caa8a1c5b0e84bedaeb6c64972503a43eb",
}, },
}; };
bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07);
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
const Uint8Vec msg = fromHexStr(tbl[i].msg); const Uint8Vec msg = fromHexStr(tbl[i].msg);
const Uint8Vec out = fromHexStr(tbl[i].out); const Uint8Vec out = fromHexStr(tbl[i].out);
@ -1103,6 +1100,30 @@ void testSswuG1(const T& mapto)
} }
} }
template<class T>
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) CYBOZU_TEST_AUTO(test)
{ {
initPairing(mcl::BLS12_381); initPairing(mcl::BLS12_381);
@ -1122,8 +1143,11 @@ CYBOZU_TEST_AUTO(test)
testVec("../misc/mapto/fips_186_3_B233.txt"); testVec("../misc/mapto/fips_186_3_B233.txt");
testVec("../misc/mapto/misc.txt"); testVec("../misc/mapto/misc.txt");
ethMsgToG2testAll("../bls_sigs_ref/test-vectors/hash_g2/"); ethMsgToG2testAll("../bls_sigs_ref/test-vectors/hash_g2/");
bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_06);
testHashToFp2v6(mapto); testHashToFp2v6(mapto);
bn::setMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE_07);
testHashToFp2v7(mapto); testHashToFp2v7(mapto);
testEth2phase0(); testEth2phase0();
testSswuG1(mapto); testSswuG1(mapto);
// testMsgToG1(mapto);
} }

Loading…
Cancel
Save