diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-03-10 04:45:27 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-03-10 04:45:27 +0800 |
commit | ee2f24c79f9b818bfdfd00ef1b7d898d477f7ca3 (patch) | |
tree | 0a9ac311ad028869801608b50e739df20e3ebbd1 | |
parent | 27ae115c832770bc81d8de0b3f16e802a4f7b4d6 (diff) | |
download | dexon-mcl-ee2f24c79f9b818bfdfd00ef1b7d898d477f7ca3.tar.gz dexon-mcl-ee2f24c79f9b818bfdfd00ef1b7d898d477f7ca3.tar.zst dexon-mcl-ee2f24c79f9b818bfdfd00ef1b7d898d477f7ca3.zip |
add bn384_test
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/mcl/bn.hpp | 6 | ||||
-rw-r--r-- | test/bn384_test.cpp | 39 |
3 files changed, 44 insertions, 3 deletions
@@ -3,7 +3,7 @@ LIB_DIR=lib OBJ_DIR=obj EXE_DIR=bin SRC_SRC=fp.cpp -TEST_SRC=fp_test.cpp ec_test.cpp fp_util_test.cpp window_method_test.cpp elgamal_test.cpp fp_tower_test.cpp gmp_test.cpp bn_test.cpp bn256_test.cpp +TEST_SRC=fp_test.cpp ec_test.cpp fp_util_test.cpp window_method_test.cpp elgamal_test.cpp fp_tower_test.cpp gmp_test.cpp bn_test.cpp bn256_test.cpp bn384_test.cpp ifeq ($(CPU),x86-64) MCL_USE_XBYAK?=1 TEST_SRC+=mont_fp_test.cpp sq_test.cpp diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp index 8beaf75..6798e1e 100644 --- a/include/mcl/bn.hpp +++ b/include/mcl/bn.hpp @@ -27,9 +27,11 @@ struct CurveParam { bool operator!=(const CurveParam& rhs) const { return !operator==(rhs); } }; -const CurveParam CurveSNARK1 = { 4965661367192848881, 3, 9 }; +const CurveParam CurveSNARK1 = { mpz_class("4965661367192848881"), 3, 9 }; //const CurveParam CurveSNARK2 = { 4965661367192848881, 82, 9 }; -const CurveParam CurveFp254BNb = { -((1LL << 62) + (1LL << 55) + (1LL << 0)), 2, 1 }; +const CurveParam CurveFp254BNb = { mpz_class("-0x4080000000000001"), 2, 1 }; // -(2^62 + 2^55 + 1) +const CurveParam CurveFp382_1 = { mpz_class("-0x400011000000000000000001"), 2, 1 }; // -(2^94 + 2^76 + 2^72 + 1) // A Family of Implementation-Friendly BN Elliptic Curves +const CurveParam CurveFp382_2 = { mpz_class("-0x400040090001000000000001"), 2, 1 }; // -(2^94 + 2^78 + 2^67 + 2^64 + 2^48 + 1) // used in relic-toolkit template<class Vec> void convertToBinary(Vec& v, const mpz_class& x) diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp new file mode 100644 index 0000000..9d0532c --- /dev/null +++ b/test/bn384_test.cpp @@ -0,0 +1,39 @@ +#include <cybozu/test.hpp> +#include <cybozu/benchmark.hpp> +#include <mcl/bn.hpp> + +typedef mcl::FpT<mcl::FpTag, 384> Fp; +typedef mcl::FpT<mcl::ZnTag, 384> Fr; +typedef mcl::bn::BNT<Fp> 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; + +CYBOZU_TEST_AUTO(pairing) +{ + BN::init(mcl::bn::CurveFp382_1); + G1 P; + G2 Q; + BN::mapToG1(P, 1); + BN::mapToG2(Q, 1); + std::cout << P << std::endl; + std::cout << Q << std::endl; + GT e1, e2; + BN::pairing(e1, P, Q); + std::cout << e1 << std::endl; + mpz_class a("293842098420840298420842342342449"); + mpz_class b("2035739487659287420847209482048"); + G1 aP; + G2 bQ; + G1::mul(aP, P, a); + G2::mul(bQ, Q, b); + BN::pairing(e2, aP, bQ); + GT::pow(e1, e1, a * b); + std::cout << e1 << std::endl; + CYBOZU_TEST_EQUAL(e1, e2); + CYBOZU_BENCH("pairing", BN::pairing, e1, P, Q); + CYBOZU_BENCH("finalExp", BN::finalExp, e1, e1); +} |