Closed XinwenXiang closed 1 year ago
You can use the initialization,
#include <mcl/ecdsa.hpp>
int main()
try
{
using namespace mcl::ecdsa;
init();
Fp r;
r.setByCSPRNG();
Ec P;
mcl::ec::tryAndIncMapTo(P, r);
printf("P=%s\n", P.getStr().c_str());
} catch (std::exception& e) {
printf("err %s\n", e.what());
return 1;
}
Or
#include <mcl/bn.hpp>
int main()
try
{
using namespace mcl::bn;
bool b;
initG1only(&b, mcl::ecparam::secp256k1);
if (!b) {
puts("ERR");
return 1;
}
Fp r;
r.setByCSPRNG();
G1 P;
mapToG1(P, r);
printf("P=%s\n", P.getStr().c_str());
} catch (std::exception& e) {
printf("err %s\n", e.what());
return 1;
}
I have tried above, and I want to ask:
r is setByCSPRNG, it shoule be a rand number less than the Group order of secp256k1, if tryAndIncMap() same as maptoG1()?
Both file print P=1, it means P is the base point of G1?
The first 1
means that the following strings are affine coordinates.
https://github.com/herumi/mcl/blob/master/api.md#string-conversion
1 <x> <y> ; affine coordinate
r is setByCSPRNG, it shoule be a rand number less than the Group order of secp256k1, if tryAndIncMap() same as maptoG1()?
The r is an element of the base field of G1, so it may be greater than the group order. tryAndIncMap() is same as maptoG1() for secp256k1 on the current version.
got it! thanks for your answer
hi,
I'm trying to use secp256k1 in a C++ project , it seems that the initPairing() only support curves that support Pairing .
mcl::bn::initPairing(mcl::BLS12_381);
and I have read ecdsa.hpp, it uses this to init curve:should i use the same way to init secp256k1 in my project, and how can i get random element of G1?