From a148e716c06551b5ac143477c919548c9a682a03 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 14 Mar 2017 22:27:53 +0900 Subject: start to support 384-bit curve --- src/bls.cpp | 37 ++++++++++++++++++++++++++++--------- src/bls_if.cpp | 4 ++-- 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/bls.cpp b/src/bls.cpp index e065911..ff747bf 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -5,13 +5,13 @@ http://opensource.org/licenses/BSD-3-Clause */ #include -#include +#include #include #include #include #include -using namespace mcl::bn256; +using namespace mcl::bn384; typedef std::vector FrVec; #define PUT(x) std::cout << #x << "=" << x << std::endl; @@ -156,9 +156,23 @@ std::ostream& writeAsHex(std::ostream& os, const T& t) return os << str; } -void init() -{ - BN::init(mcl::bn::CurveFp254BNb); +void init(int curve) +{ + mcl::bn::CurveParam cp; + switch (curve) { + case bls::CurveFp254BNb: + cp = mcl::bn::CurveFp254BNb; + break; + case bls::CurveFp382_1: + cp = mcl::bn::CurveFp382_1; + break; + case bls::CurveFp382_2: + cp = mcl::bn::CurveFp382_2; + break; + default: + throw cybozu::Exception("bls:init:bad curve") << curve; + } + BN::init(cp); G1::setCompressedExpression(); G2::setCompressedExpression(); Fr::init(BN::param.r); @@ -167,10 +181,15 @@ void init() assert(sizeof(SecretKey) == sizeof(impl::SecretKey)); assert(sizeof(PublicKey) == sizeof(impl::PublicKey)); assert(sizeof(Sign) == sizeof(impl::Sign)); - static const G2 Q( - Fp2("12723517038133731887338407189719511622662176727675373276651903807414909099441", "4168783608814932154536427934509895782246573715297911553964171371032945126671"), - Fp2("13891744915211034074451795021214165905772212241412891944830863846330766296736", "7937318970632701341203597196594272556916396164729705624521405069090520231616") - ); + static G2 Q; + if (curve == bls::CurveFp254BNb) { + Q.set( + Fp2("12723517038133731887338407189719511622662176727675373276651903807414909099441", "4168783608814932154536427934509895782246573715297911553964171371032945126671"), + Fp2("13891744915211034074451795021214165905772212241412891944830863846330766296736", "7937318970632701341203597196594272556916396164729705624521405069090520231616") + ); + } else { + BN::mapToG2(Q, 1); + } static std::vector Qcoeff; BN::precomputeG2(Qcoeff, Q); diff --git a/src/bls_if.cpp b/src/bls_if.cpp index 0bea838..091bace 100644 --- a/src/bls_if.cpp +++ b/src/bls_if.cpp @@ -43,9 +43,9 @@ size_t getStrT(const Outer *p, char *buf, size_t maxBufSize) return 0; } -void blsInit() +void blsInit(int curve) { - bls::init(); + bls::init(curve); } blsId *blsIdCreate() -- cgit v1.2.3