From 50a0ed560f3e10db55c8e52ebd335586f76473a6 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 14 Mar 2017 20:22:34 +0900 Subject: [PATCH] add bn384.hpp --- include/mcl/bn384.hpp | 39 +++++++++++++++++++++++++++++++++++++++ test/bn384_test.cpp | 15 +++++---------- 2 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 include/mcl/bn384.hpp diff --git a/include/mcl/bn384.hpp b/include/mcl/bn384.hpp new file mode 100644 index 0000000..d5c3e81 --- /dev/null +++ b/include/mcl/bn384.hpp @@ -0,0 +1,39 @@ +#pragma once +/** + @file + @brief preset class for 384-bit optimal ate pairing over BN curves + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ +#include + +namespace mcl { namespace bn384 { + +namespace local { +struct FpTag; +struct FrTag; +} + +typedef mcl::FpT Fp; +typedef mcl::bn::BNT BN; +typedef BN::Fp2 Fp2; +typedef BN::Fp6 Fp6; +typedef BN::Fp12 Fp12; +typedef BN::G1 G1; +typedef BN::G2 G2; +typedef BN::Fp12 GT; + +/* the order of G1 is r */ +typedef mcl::FpT Fr; + +static inline void bn384init(const mcl::bn::CurveParam& cp = mcl::bn::CurveFp382_2, fp::Mode mode = fp::FP_AUTO) +{ + BN::init(cp, mode); + G1::setCompressedExpression(); + G2::setCompressedExpression(); + Fr::init(BN::param.r); +} + +} } // mcl::bn384 + diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp index 480355d..a9fc85b 100644 --- a/test/bn384_test.cpp +++ b/test/bn384_test.cpp @@ -1,20 +1,13 @@ #include #include +#include #include -typedef mcl::FpT Fp; -typedef mcl::FpT Fr; -typedef mcl::bn::BNT BN; -typedef BN::Fp2 Fp2; -typedef BN::Fp6 Fp6; -typedef BN::Fp12 Fp12; -typedef BN::G1 G1; -typedef BN::G2 G2; -typedef BN::Fp12 GT; +using namespace mcl::bn384; void testCurve(const mcl::bn::CurveParam& cp) { - BN::init(cp); + bn384init(cp); G1 P; G2 Q; BN::mapToG1(P, 1); @@ -39,4 +32,6 @@ CYBOZU_TEST_AUTO(pairing) { testCurve(mcl::bn::CurveFp382_1); testCurve(mcl::bn::CurveFp382_2); + // support 256-bit pairing + testCurve(mcl::bn::CurveFp254BNb); }