aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-09-18 09:43:43 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-09-18 09:43:43 +0800
commit5c43cc4e0f4c0223f54f066a4ecc8545dc33fdce (patch)
tree331f3f0d0143e48deedea286de4d343fe3098c8a
parentb810c822c8914f6739635c570b4230c796137fdc (diff)
downloadtangerine-mcl-5c43cc4e0f4c0223f54f066a4ecc8545dc33fdce.tar.gz
tangerine-mcl-5c43cc4e0f4c0223f54f066a4ecc8545dc33fdce.tar.zst
tangerine-mcl-5c43cc4e0f4c0223f54f066a4ecc8545dc33fdce.zip
add BN462 parameter (but not run)
-rw-r--r--Makefile2
-rw-r--r--include/mcl/bn.hpp10
-rw-r--r--test/bn384_test.cpp9
-rw-r--r--test/bn512_test.cpp71
4 files changed, 79 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index edc03f2..afc2d3d 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ LIB_DIR=lib
OBJ_DIR=obj
EXE_DIR=bin
SRC_SRC=fp.cpp bn_c256.cpp bn_c384.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 bn384_test.cpp glv_test.cpp paillier_test.cpp she_test.cpp vint_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 bn384_test.cpp glv_test.cpp paillier_test.cpp she_test.cpp vint_test.cpp #bn512_test.cpp
TEST_SRC+=bn_c256_test.cpp bn_c384_test.cpp
ifeq ($(CPU),x86-64)
MCL_USE_XBYAK?=1
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp
index 8882f08..9b94a36 100644
--- a/include/mcl/bn.hpp
+++ b/include/mcl/bn.hpp
@@ -178,7 +178,7 @@ struct GLV1 {
void mul(G1& Q, const G1& P, mpz_class x, bool constTime = false) const
{
typedef mcl::fp::Unit Unit;
- const size_t maxUnit = 384 / 2 / mcl::fp::UnitBitSize;
+ const size_t maxUnit = 512 / 2 / mcl::fp::UnitBitSize;
const int splitN = 2;
mpz_class u[splitN];
G1 in[splitN];
@@ -358,7 +358,7 @@ struct GLV2 {
}
#endif
typedef mcl::fp::Unit Unit;
- const size_t maxUnit = 384 / 2 / mcl::fp::UnitBitSize;
+ const size_t maxUnit = 512 / 2 / mcl::fp::UnitBitSize;
const int splitN = 4;
mpz_class u[splitN];
T in[splitN];
@@ -527,7 +527,11 @@ struct ParamT {
Fp2::init(cp.xi_a);
b = cp.b;
Fp2 xi(cp.xi_a, 1);
- b_div_xi = Fp2(b) / xi;
+ if (cp == CurveFp462) {
+ b_div_xi = xi * b;
+ } else {
+ b_div_xi = Fp2(b) / xi;
+ }
is_b_div_xi_1_m1i = b_div_xi == Fp2(1, -1);
G1::init(0, b, mcl::ec::Proj);
G2::init(0, b_div_xi, mcl::ec::Proj);
diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp
index ea9f95f..39cbbb1 100644
--- a/test/bn384_test.cpp
+++ b/test/bn384_test.cpp
@@ -39,15 +39,6 @@ void testCurve(const mcl::bn::CurveParam& cp)
CYBOZU_BENCH_C("G2::dbl", 500, G2::dbl, bQ, bQ);
CYBOZU_BENCH("pairing", BN::pairing, e1, P, Q);
CYBOZU_BENCH("finalExp", BN::finalExp, e1, e1);
-{
-#define PUT(x) std::cout << #x << "=" << x << std::endl;
- G1 PP;
- G1::mul(PP, P, BN::param.r);
- PUT(BN::param.r);
- PUT(PP);
- G2 QQ;
- G2::mul(QQ, Q, BN::param.r);
-}
}
CYBOZU_TEST_AUTO(pairing)
diff --git a/test/bn512_test.cpp b/test/bn512_test.cpp
new file mode 100644
index 0000000..3db9d31
--- /dev/null
+++ b/test/bn512_test.cpp
@@ -0,0 +1,71 @@
+#define CYBOZU_TEST_DISABLE_AUTO_RUN
+#include <cybozu/test.hpp>
+#include <cybozu/benchmark.hpp>
+#include <cybozu/option.hpp>
+#include <cybozu/xorshift.hpp>
+#include <mcl/bn512.hpp>
+#include <mcl/bn.hpp>
+
+using namespace mcl::bn512;
+
+mcl::fp::Mode g_mode;
+
+void testCurve(const mcl::bn::CurveParam& cp)
+{
+ initPairing(cp, g_mode);
+ G1 P;
+ G2 Q;
+ BN::mapToG1(P, 1);
+ BN::mapToG2(Q, 1);
+ GT e1, e2;
+ BN::pairing(e1, P, Q);
+ cybozu::XorShift rg;
+ mpz_class a, b;
+ Fr r;
+ r.setRand(rg); a = r.getMpz();
+ r.setRand(rg); b = r.getMpz();
+ 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);
+ CYBOZU_TEST_EQUAL(e1, e2);
+ CYBOZU_BENCH_C("G1::mulCT", 500, G1::mul, aP, aP, a);
+ CYBOZU_BENCH_C("G1::add", 500, G1::add, aP, aP, P);
+ CYBOZU_BENCH_C("G1::dbl", 500, G1::dbl, aP, aP);
+ CYBOZU_BENCH_C("G2::mulCT", 500, G2::mul, bQ, bQ, b);
+ CYBOZU_BENCH_C("G2::add", 500, G2::add, bQ, bQ, Q);
+ CYBOZU_BENCH_C("G2::dbl", 500, G2::dbl, bQ, bQ);
+ CYBOZU_BENCH("pairing", BN::pairing, e1, P, Q);
+ CYBOZU_BENCH("finalExp", BN::finalExp, e1, e1);
+}
+
+CYBOZU_TEST_AUTO(pairing)
+{
+ puts("CurveFp462");
+ testCurve(mcl::bn::CurveFp462);
+ puts("CurveFp382_1");
+ testCurve(mcl::bn::CurveFp382_1);
+ puts("CurveFp382_2");
+ testCurve(mcl::bn::CurveFp382_2);
+ puts("CurveFp254BNb");
+ testCurve(mcl::bn::CurveFp254BNb);
+}
+
+int main(int argc, char *argv[])
+ try
+{
+ cybozu::Option opt;
+ std::string mode;
+ opt.appendOpt(&mode, "auto", "m", ": mode(gmp/gmp_mont/llvm/llvm_mont/xbyak)");
+ if (!opt.parse(argc, argv)) {
+ opt.usage();
+ return 1;
+ }
+ g_mode = mcl::fp::StrToMode(mode);
+ return cybozu::test::autoRun.run(argc, argv);
+} catch (std::exception& e) {
+ printf("ERR %s\n", e.what());
+ return 1;
+}