herumi / mcl

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

Does macros(`MCL_MAX_FP_BIT_SIZE`, `MCL_MAX_BIT_SIZE`, etc.) actually have impact on efficiency? #181

Closed xfap closed 1 year ago

xfap commented 1 year ago

Beginner for this repo.

A little confused about the role of macros MCL_MAX_FP_BIT_SIZE, MCL_MAX_BIT_SIZE, etc. Seems they are only for checking bounds or being consistent with C.

My final aim here: want to make a more unified C++ wrapper upon libmcl for pairing & ecc curve instead of including different header file for different macro.

herumi commented 1 year ago

Sorry, it's confusing for historical reasons and backward compatibility. What parameters of the pairing do you want to use? If you want to use only BLS12_381, make MCL_MAX_BIT_SIZE=384 lib/libmcl.a and use it with -DMCL_MAX_BIT_SIZE=384 and "including bls12_381.hpp".

herumi commented 1 year ago

For BLS12_381, sizeof(Fp) = 384/8, sizeof(Fr) = 256/8.

xfap commented 1 year ago

@herumi Thanks. Sorry for further some more questions. I see an example for multi instances for pairing in sample/multi.cpp. If we can use this method to have all pairing instance?

image

BTW, notice api.md only describes four kinds of pairing curves BN254 BN_SNARK1 BN381_1 BLS12_381, and in include/mcl/curve_type.h have already params for all curve declared by enum. So if the lib could actually support these pairings?

herumi commented 1 year ago

Would you like to use all pairing instances simultaneously? Could you tell me the reason? I don't recommend sample/multi.cpp because it's a special usage.

We can compute all pairings defined in the enum, but mcl supports only BLS12-381 for the standard hash-to-G1/G2 functions defined in IRTF.

xfap commented 1 year ago

Cause I want to make a universal wrapper for different paring libs, so pairing curve switching needs happen over the wrapper(where requiring support of pairing instances simultaneously), but not over the underlying lib's building args.

herumi commented 1 year ago

I don't think mcl suits that purpose, though you can make two or three instances by sample/multi.cpp. The parameters other than BLS12_381 are not standard, but what kind of application are you thinking of?

xfap commented 1 year ago

Wanner be a part for a more user-friendly crypto lib. AND another question from building error about MCL_MAX_BIT_SIZE, may you could help? When setting building args -DMCL_MAX_BIT_SIZE=1024, and initCurve will fail for curves like:

herumi commented 1 year ago

Wanner be a part for a more user-friendly crypto lib.

mcl basically assumes single instance pairing, so could you use the other library?

-DMCL_MAX_BIT_SIZE=1024 Now mcl does not support the size. The max is 512.

MCL_SECP521R1 and MCL_SECP521R1 are not parameters for pairing.

xfap commented 1 year ago

Yes, not for pairing, I set MCL_MAX_BIT_SIZE for purpose of using ecc MCL_SECP521R1. But it seems not working right. BTW, I'm working for a universal wrapper for ecc & pairing, not just pairing.

mcl basically assumes single instance pairing, so could you use the other library?

OK... maybe that's the way and I should just include only BLS12_381 except others pairing for libmcl.

xfap commented 1 year ago

Now mcl does not support the size. The max is 512.

wait...max is 512? but how could we instantiate curveMCL_SECP521R1?

herumi commented 1 year ago

Yes, not for pairing, I set MCL_MAX_BIT_SIZE for purpose of using ecc MCL_SECP521R1. But it seems not working right.

The old version supported MCL_SECP521R1, but I gave up on it now. I'll fix it later if I can afford it.

xfap commented 1 year ago

OK, very thanks for your helpful answers!

herumi commented 1 year ago

@xfap

requiring support of pairing instances simultaneously

By the way, in what situations do you need different pairings for multiple threads?