herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
452 stars 152 forks source link

Base points? #24

Closed Scratch-net closed 5 years ago

Scratch-net commented 5 years ago

Hi! Could not find base points for BLS12_381 (G1, G2). Is there something like in Relic https://github.com/relic-toolkit/relic/blob/086643803fc64bb109112b16160cb5c8a7ab5e66/src/epx/relic_ep2_curve.c#L89

I could use to multiply by a base point?

herumi commented 5 years ago

You can use the parameters defined in Relic.

using namespace mcl::bn;
Fp X0(B12_P381_X0, 16);
Fp X1(B12_P381_X1, 16);
Fp Y0(B12_P381_Y0, 16);
Fp Y1(B12_P381_Y1, 16);

G2 Q(Fp2(X0, X1), Fp2(Y0, Y1));
std::cout << "Q=" << Q.getStr(mcl::IoEcAffine|16) << std::endl;

Or use mcl::bn::hashAndMapToG1 or hashAndMapToG2. These functions generate an element of G1/G2 from any byte sequence. mapToG1 and mapToG2 generate an element of G1/G2 from Fp/Fp2.

G1 P;
G2 Q;
hashAndMapToG1(P, "abc");
hashAndMapToG2(Q, "abc");
Scratch-net commented 5 years ago

Thanks, that's what I thought