From 73337422293c5af62e4068bc0d8e712e29cb58fa Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 29 Jun 2020 11:41:45 +0900 Subject: [PATCH] rename vars in mapto --- include/mcl/mapto_wb19.hpp | 46 +++++++++++++++++++++----------------- test/mapto_wb19_test.cpp | 32 +++++++++++++------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/include/mcl/mapto_wb19.hpp b/include/mcl/mapto_wb19.hpp index c5da874..53430b2 100644 --- a/include/mcl/mapto_wb19.hpp +++ b/include/mcl/mapto_wb19.hpp @@ -70,10 +70,11 @@ template int PointT::specialA_; template struct MapTo_WB19 { - typedef local::PointT Point; + typedef local::PointT E1; + typedef local::PointT E2; mpz_class sqrtConst; // (p^2 - 9) / 16 - Fp2 Ep_a; - Fp2 Ep_b; + Fp2 g2A; + Fp2 g2B; Fp2 root4[4]; Fp2 etas[4]; Fp2 xnum[4]; @@ -94,14 +95,17 @@ struct MapTo_WB19 { void init() { bool b; - Ep_a.a = 0; - Ep_a.b = 240; - Ep_b.a = 1012; - Ep_b.b = 1012; - Point::a_.clear(); - Point::b_.a = 4; - Point::b_.b = 4; - Point::specialA_ = ec::Zero; + g2A.a = 0; + g2A.b = 240; + g2B.a = 1012; + g2B.b = 1012; + E1::a_.clear(); + E1::b_ = 4; + E1::specialA_ = ec::Zero; + E2::a_.clear(); + E2::b_.a = 4; + E2::b_.b = 4; + E2::specialA_ = ec::Zero; sqrtConst = Fp::getOp().mp; sqrtConst *= sqrtConst; sqrtConst -= 9; @@ -297,7 +301,7 @@ struct MapTo_WB19 { } } // refer (xnum, xden, ynum, yden) - void iso3(G2& Q, const Point& P) const + void iso3(G2& Q, const E2& P) const { Fp2 zpows[3]; Fp2::sqr(zpows[0], P.z); @@ -321,7 +325,7 @@ struct MapTo_WB19 { Q.y *= t; } // refer (g1xnum, g1xden, g1ynum, g1yden) - void iso11(G1& Q, const Point& P) const + void iso11(G1& Q, const E2& P) const { Fp2 zpows[3]; Fp2::sqr(zpows[0], P.z); @@ -440,7 +444,7 @@ struct MapTo_WB19 { pt[1] *= y; } // https://github.com/algorand/bls_sigs_ref - void osswu2_help(Point& P, const Fp2& t) const + void osswu2_help(E2& P, const Fp2& t) const { Fp2 t2, t2xi; Fp2::sqr(t2, t); @@ -452,20 +456,20 @@ struct MapTo_WB19 { den += den2; Fp2 x0_num, x0_den; Fp2::add(x0_num, den, 1); - x0_num *= Ep_b; + x0_num *= g2B; if (den.isZero()) { - mul_xi(x0_den, Ep_a); + mul_xi(x0_den, g2A); } else { - Fp2::mul(x0_den, -Ep_a, den); + Fp2::mul(x0_den, -g2A, den); } Fp2 x0_den2, x0_den3, gx0_den, gx0_num; Fp2::sqr(x0_den2, x0_den); Fp2::mul(x0_den3, x0_den2, x0_den); gx0_den = x0_den3; - Fp2::mul(gx0_num, Ep_b, gx0_den); + Fp2::mul(gx0_num, g2B, gx0_den); Fp2 tmp, tmp1, tmp2; - Fp2::mul(tmp, Ep_a, x0_num); + Fp2::mul(tmp, g2A, x0_num); tmp *= x0_den2; gx0_num += tmp; Fp2::sqr(tmp, x0_num); @@ -538,10 +542,10 @@ struct MapTo_WB19 { } void opt_swu2_map(G2& P, const Fp2& t, const Fp2 *t2 = 0) const { - Point Pp; + E2 Pp; osswu2_help(Pp, t); if (t2) { - Point P2; + E2 P2; osswu2_help(P2, *t2); ec::addJacobi(Pp, Pp, P2); } diff --git a/test/mapto_wb19_test.cpp b/test/mapto_wb19_test.cpp index 8ea5f58..9652c69 100644 --- a/test/mapto_wb19_test.cpp +++ b/test/mapto_wb19_test.cpp @@ -12,7 +12,7 @@ using namespace mcl; using namespace mcl::bn; typedef mcl::MapTo_WB19 MapTo; -typedef MapTo::Point Point; +typedef MapTo::E2 E2; void dump(const void *msg, size_t msgSize) { @@ -72,8 +72,8 @@ void set(Fp2& x, const Fp2Str& s) x.b.setStr(s.b); } -template -void set(Point& P, const PointStr& s) +template +void set(E2& P, const PointStr& s) { set(P.x, s.x); set(P.y, s.y); @@ -128,7 +128,7 @@ bool sqr_div(const MapTo& mapto, Fp2& z, const Fp2& u, const Fp2& v) } // Proj -void py_ecc_iso_map_G2(const MapTo& mapto, G2& Q, const Point& P) +void py_ecc_iso_map_G2(const MapTo& mapto, G2& Q, const E2& P) { Fp2 zpows[3]; zpows[0] = P.z; @@ -148,7 +148,7 @@ void py_ecc_iso_map_G2(const MapTo& mapto, G2& Q, const Point& P) } // https://github.com/ethereum/py_ecc -void py_ecc_optimized_swu_G2(const MapTo& mapto, Point& P, const Fp2& t) +void py_ecc_optimized_swu_G2(const MapTo& mapto, E2& P, const Fp2& t) { Fp2 t2, t2xi, t2xi2; Fp2::sqr(t2, t); @@ -158,11 +158,11 @@ void py_ecc_optimized_swu_G2(const MapTo& mapto, Point& P, const Fp2& t) // (t^2 * xi)^2 + (t^2 * xi) Fp2::add(deno, t2xi2, t2xi); Fp2::add(nume, deno, 1); - nume *= mapto.Ep_b; + nume *= mapto.g2B; if (deno.isZero()) { - mapto.mul_xi(deno, mapto.Ep_a); + mapto.mul_xi(deno, mapto.g2A); } else { - deno *= -mapto.Ep_a; + deno *= -mapto.g2A; } Fp2 u, v; { @@ -170,8 +170,8 @@ void py_ecc_optimized_swu_G2(const MapTo& mapto, Point& P, const Fp2& t) Fp2::sqr(deno2, deno); Fp2::mul(v, deno2, deno); - Fp2::mul(u, mapto.Ep_b, v); - Fp2::mul(tmp, mapto.Ep_a, nume); + Fp2::mul(u, mapto.g2B, v); + Fp2::mul(tmp, mapto.g2A, nume); tmp *= deno2; u += tmp; Fp2::sqr(tmp, nume); @@ -210,7 +210,7 @@ void py_ecc_optimized_swu_G2(const MapTo& mapto, Point& P, const Fp2& t) // Proj void py_ecc_map_to_curve_G2(const MapTo& mapto, G2& out, const Fp2& t) { - Point P; + E2 P; py_ecc_optimized_swu_G2(mapto, P, t); py_ecc_iso_map_G2(mapto, out, P); } @@ -521,7 +521,7 @@ void osswu2_helpTest(const T& mapto) }; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { Fp2 t, x, y, z; - Point P; + E2 P; set(t, tbl[i].t); set(x, tbl[i].x); set(y, tbl[i].y); @@ -587,11 +587,11 @@ void addTest() }, }; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { - Point P, Q, R; + E2 P, Q, R; set(P, tbl[i].P); set(Q, tbl[i].Q); set(R, tbl[i].R); - Point E; + E2 E; ec::addJacobi(E, P, Q); CYBOZU_TEST_ASSERT(R.isEqual(E)); } @@ -642,7 +642,7 @@ void iso3Test(const T& mapto) "0xb7b36b9b1bbcf801d21ca5164aa9a0e71df2b4710c67dc0cd275b786800935fc29defbdf9c7e23dc84e26af13ba761d", } }; - typename T::Point P; + typename T::E2 P; G2 Q1, Q2; set(P, Ps); set(Q1, Qs); @@ -748,7 +748,7 @@ void py_eccTest2(const T& mapto) }; Fp2 t; set(t, ts); - Point p, q; + E2 p, q; py_ecc_optimized_swu_G2(mapto, p, t); set(q, out1s); CYBOZU_TEST_EQUAL(p.x, q.x);