herumi / mcl

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

mclBnFr_getBigEndian missing in bn.h #190

Closed MisterEJ closed 6 months ago

MisterEJ commented 8 months ago

Hi

I noticed that getBigEndian is missing from bn.h and bn.hpp while there are getLittleEndian representations.

mclBnFr_getBigEndian
mclBnFp_getBigEndian

Is there a specific reason for it not being implemented?

In addition, is there a correct way to apply a patch?

herumi commented 8 months ago

If you use BLS12_381, then serialize() deals with buffer as big-endian. So you can use serialize() as getBigEndian().

#include <mcl/bls12_381.hpp>

int main()
{
  using namespace mcl::bn;
  initPairing(mcl::BLS12_381);
  Fp x;
  x = 0x1234;
  printf("x=%s\n", x.serializeToHexStr().c_str());
  Fp::setETHserialization(true);
  printf("x=%s\n", x.serializeToHexStr().c_str());
}
x=341200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
x=000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234

Is this feature good enough for you?