rename curveParam

dev
MITSUNARI Shigeo 7 years ago
parent 1cdd69e265
commit 3b815cf485
  1. 4
      include/mcl/bls12.hpp
  2. 2
      include/mcl/bls12_381.hpp
  3. 3
      include/mcl/bn.h
  4. 15
      include/mcl/curve_type.h
  5. 43
      include/mcl/pairing_util.hpp
  6. 2
      test/bls12_test.cpp
  7. 6
      test/bn384_test.cpp
  8. 6
      test/bn512_test.cpp
  9. 2
      test/bn_test.cpp

@ -88,7 +88,7 @@ struct ParamT : public util::CommonParamT<Fp> {
typedef mcl::EcT<Fp2> G2;
MapToT<Fp> mapTo;
void init(const CurveParam& cp = CurveFp381, fp::Mode mode = fp::FP_AUTO)
void init(const CurveParam& cp = mcl::BLS12_381, fp::Mode mode = fp::FP_AUTO)
{
Common::initCommonParam(cp, mode);
mapTo.init(this->z);
@ -107,7 +107,7 @@ struct BLS12T : mcl::util::BasePairingT<BLS12T<Fp>, Fp, ParamT<Fp> > {
typedef util::HaveFrobenius<G2> G2withF;
typedef mcl::FpDblT<Fp> FpDbl;
typedef mcl::Fp2DblT<Fp> Fp2Dbl;
static void init(const mcl::bls12::CurveParam& cp = CurveFp381, fp::Mode mode = fp::FP_AUTO)
static void init(const mcl::CurveParam& cp = mcl::BLS12_381, fp::Mode mode = fp::FP_AUTO)
{
Base::param.init(cp, mode);
G2withF::init(cp.isMtype);

@ -27,7 +27,7 @@ typedef BLS12::Fp12 GT;
/* the order of G1 is r */
typedef mcl::FpT<local::FrTag, 256> Fr;
static inline void initPairing(const mcl::bls12::CurveParam& cp = mcl::bls12::CurveFp381, fp::Mode mode = fp::FP_AUTO)
static inline void initPairing(const mcl::bls12::CurveParam& cp = mcl::BLS12_381, fp::Mode mode = fp::FP_AUTO)
{
BLS12::init(cp, mode);
G1::setCompressedExpression();

@ -85,8 +85,6 @@ typedef struct {
*/
MCLBN_DLL_API int mclBn_setErrFile(const char *name);
#ifndef MCL_CURVE_TYPE_DEFINED
#define MCL_CURVE_TYPE_DEFINED
enum {
mclBn_CurveFp254BNb = 0,
mclBn_CurveFp382_1 = 1,
@ -95,7 +93,6 @@ enum {
mclBn_CurveSNARK1 = 4,
mclBls12_CurveFp381 = 5
};
#endif
/*
init library

@ -7,14 +7,11 @@
http://opensource.org/licenses/BSD-3-Clause
*/
#ifndef MCL_CURVE_TYPE_DEFINED
#define MCL_CURVE_TYPE_DEFINED
enum {
mclBn_CurveFp254BNb = 0,
mclBn_CurveFp382_1 = 1,
mclBn_CurveFp382_2 = 2,
mclBn_CurveFp462 = 3,
mclBn_CurveSNARK1 = 4,
mclBls12_CurveFp381 = 5
MCL_BN254BNb = 0,
MCL_BN382_1 = 1,
MCL_BN382_2 = 2,
MCL_BN462 = 3,
MCL_BN_SNARK1 = 4,
MCL_BLS12_381 = 5
};
#endif

@ -37,32 +37,31 @@ struct CurveParam {
bool operator!=(const CurveParam& rhs) const { return !operator==(rhs); }
};
namespace bn {
const CurveParam CurveFp254BNb = { "-0x4080000000000001", 2, 1, false, mclBn_CurveFp254BNb }; // -(2^62 + 2^55 + 1)
const CurveParam BN254BNb = { "-0x4080000000000001", 2, 1, false, MCL_BN254BNb }; // -(2^62 + 2^55 + 1)
// provisional(experimental) param with maxBitSize = 384
const CurveParam CurveFp382_1 = { "-0x400011000000000000000001", 2, 1, false, mclBn_CurveFp382_1 }; // -(2^94 + 2^76 + 2^72 + 1) // A Family of Implementation-Friendly BN Elliptic Curves
const CurveParam CurveFp382_2 = { "-0x400040090001000000000001", 2, 1, false, mclBn_CurveFp382_2 }; // -(2^94 + 2^78 + 2^67 + 2^64 + 2^48 + 1) // used in relic-toolkit
const CurveParam CurveFp462 = { "0x4001fffffffffffffffffffffbfff", 5, 2, false, mclBn_CurveFp462 }; // 2^114 + 2^101 - 2^14 - 1 // https://eprint.iacr.org/2017/334
const CurveParam CurveSNARK1 = { "4965661367192848881", 3, 9, false, mclBn_CurveSNARK1 };
const CurveParam BN382_1 = { "-0x400011000000000000000001", 2, 1, false, MCL_BN382_1 }; // -(2^94 + 2^76 + 2^72 + 1) // A Family of Implementation-Friendly BN Elliptic Curves
const CurveParam BN382_2 = { "-0x400040090001000000000001", 2, 1, false, MCL_BN382_2 }; // -(2^94 + 2^78 + 2^67 + 2^64 + 2^48 + 1) // used in relic-toolkit
const CurveParam BN462 = { "0x4001fffffffffffffffffffffbfff", 5, 2, false, MCL_BN462 }; // 2^114 + 2^101 - 2^14 - 1 // https://eprint.iacr.org/2017/334
const CurveParam BN_SNARK1 = { "4965661367192848881", 3, 9, false, MCL_BN_SNARK1 };
const CurveParam BLS12_381 = { "-0xd201000000010000", 4, 1, true, MCL_BLS12_381 };
namespace bn {
static const CurveParam& CurveFp254BNb = BN254BNb;
static const CurveParam& CurveFp382_1 = BN382_1;
static const CurveParam& CurveFp382_2 = BN382_2;
static const CurveParam& CurveFp462 = BN462;
static const CurveParam& CurveSNARK1 = BN_SNARK1;
} // mcl::bn
namespace bls12 {
const CurveParam CurveFp381 = { "-0xd201000000010000", 4, 1, true, mclBls12_CurveFp381 };
} // mcl::bls12
inline const CurveParam& getCurveParam(int type)
{
switch (type) {
case mclBn_CurveFp254BNb: return bn::CurveFp254BNb;
case mclBn_CurveFp382_1: return bn::CurveFp382_1;
case mclBn_CurveFp382_2: return bn::CurveFp382_2;
case mclBn_CurveFp462: return bn::CurveFp462;
case mclBn_CurveSNARK1: return bn::CurveSNARK1;
case mclBls12_CurveFp381: return bls12::CurveFp381;
case MCL_BN254BNb: return mcl::BN254BNb;
case MCL_BN382_1: return mcl::BN382_1;
case MCL_BN382_2: return mcl::BN382_2;
case MCL_BN462: return mcl::BN462;
case MCL_BN_SNARK1: return mcl::BN_SNARK1;
case MCL_BLS12_381: return mcl::BLS12_381;
default:
throw cybozu::Exception("getCurveParam:bad type") << type;
}
@ -135,7 +134,7 @@ struct CommonParamT {
void initCommonParam(const CurveParam& cp, fp::Mode mode)
{
this->cp = cp;
isBLS12 = cp.curveType == mclBls12_CurveFp381;
isBLS12 = cp.curveType == MCL_BLS12_381;
z = mpz_class(cp.z);
isNegative = z < 0;
if (isNegative) {
@ -421,7 +420,7 @@ struct BasePairingT {
z = 1;
return;
}
assert(param.cp.curveType == mclBn_CurveFp254BNb);
assert(param.cp.curveType == MCL_BN254BNb);
Fp12 x_org = x;
Fp12 d62;
Fp2 c55nume, c55denomi, c62nume, c62denomi;
@ -452,7 +451,7 @@ struct BasePairingT {
static void pow_z(Fp12& y, const Fp12& x)
{
#if 1
if (param.cp.curveType == mclBn_CurveFp254BNb) {
if (param.cp.curveType == MCL_BN254BNb) {
Compress::fixed_power(y, x);
} else {
Fp12 orgX = x;

@ -34,7 +34,7 @@ const struct TestSet {
const char *e;
} g_testSetTbl[] = {
{
mcl::bls12::CurveFp381,
mcl::BLS12_381,
"CurveFp381",
"0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",
"0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",

@ -40,11 +40,11 @@ CYBOZU_TEST_AUTO(pairing)
{
puts("CurveFp254BNb");
// support 256-bit pairing
testCurve(mcl::bn::CurveFp254BNb);
testCurve(mcl::BN254BNb);
puts("CurveFp382_1");
testCurve(mcl::bn::CurveFp382_1);
testCurve(mcl::BN382_1);
puts("CurveFp382_2");
testCurve(mcl::bn::CurveFp382_2);
testCurve(mcl::BN382_2);
// Q is not on EcT, but bad order
{
const char *s = "1 18d3d8c085a5a5e7553c3a4eb628e88b8465bf4de2612e35a0a4eb018fb0c82e9698896031e62fd7633ffd824a859474 1dc6edfcf33e29575d4791faed8e7203832217423bf7f7fbf1f6b36625b12e7132c15fbc15562ce93362a322fb83dd0d 65836963b1f7b6959030ddfa15ab38ce056097e91dedffd996c1808624fa7e2644a77be606290aa555cda8481cfb3cb 1b77b708d3d4f65aeedf54b58393463a42f0dc5856baadb5ce608036baeca398c5d9e6b169473a8838098fd72fd28b50";

@ -39,11 +39,11 @@ void testCurve(const mcl::bn::CurveParam& cp)
CYBOZU_TEST_AUTO(pairing)
{
puts("CurveFp462");
testCurve(mcl::bn::CurveFp462);
testCurve(mcl::BN462);
puts("CurveFp382_1");
testCurve(mcl::bn::CurveFp382_1);
testCurve(mcl::BN382_1);
puts("CurveFp382_2");
testCurve(mcl::bn::CurveFp382_2);
testCurve(mcl::BN382_2);
puts("CurveFp254BNb");
testCurve(mcl::bn::CurveFp254BNb);
}

@ -168,7 +168,7 @@ void testCyclotomic()
void testCompress(const G1& P, const G2& Q)
{
if (BN::param.cp.curveType != mclBn_CurveFp254BNb) return;
if (BN::param.cp.curveType != MCL_BN254BNb) return;
Fp12 a;
BN::pairing(a, P, Q);
BN::mapToCyclotomic(a, a);

Loading…
Cancel
Save