From ad7b7891fa66388a36387769290ff8658a8620c1 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Fri, 18 Sep 2020 11:16:01 +0900 Subject: [PATCH] fix bls12_test for static code --- include/mcl/bn.hpp | 6 ++++++ src/fp_static_code.hpp | 17 +++++++++++------ test/bls12_test.cpp | 3 +++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp index 3668da2..ab9e15c 100644 --- a/include/mcl/bn.hpp +++ b/include/mcl/bn.hpp @@ -854,6 +854,12 @@ struct Param { { this->cp = cp; isBLS12 = cp.curveType == MCL_BLS12_381; +#ifdef MCL_STATIC_CODE + if (!isBLS12) { + *pb = false; + return; + } +#endif gmp::setStr(pb, z, cp.z); if (!*pb) return; isNegative = z < 0; diff --git a/src/fp_static_code.hpp b/src/fp_static_code.hpp index 0da39cb..832062e 100644 --- a/src/fp_static_code.hpp +++ b/src/fp_static_code.hpp @@ -20,17 +20,15 @@ void mclx_Fp_add(Unit*, const Unit*, const Unit*); void mclx_Fp_sub(Unit*, const Unit*, const Unit*); void mclx_Fp_shr1(Unit*, const Unit*); void mclx_Fp_neg(Unit*, const Unit*); +void mclx_FpDbl_mod(Unit*, const Unit*); void mclx_Fp_mul(Unit*, const Unit*, const Unit*); void mclx_Fp_sqr(Unit*, const Unit*); void mclx_FpDbl_add(Unit*, const Unit*, const Unit*); void mclx_FpDbl_sub(Unit*, const Unit*, const Unit*); -void mclx_FpDbl_add(Unit*, const Unit*, const Unit*); -void mclx_FpDbl_sub(Unit*, const Unit*, const Unit*); Unit mclx_FpDbl_addPre(Unit*, const Unit*, const Unit*); Unit mclx_FpDbl_subPre(Unit*, const Unit*, const Unit*); void mclx_FpDbl_mulPre(Unit*, const Unit*, const Unit*); void mclx_FpDbl_sqrPre(Unit*, const Unit*); -void mclx_FpDbl_mod(Unit*, const Unit*); void mclx_Fp2_add(Unit*, const Unit*, const Unit*); void mclx_Fp2_sub(Unit*, const Unit*, const Unit*); void mclx_Fp2_neg(Unit*, const Unit*); @@ -59,15 +57,22 @@ void setStaticCode(mcl::fp::Op& op) op.fp_subA_ = mclx_Fp_sub; op.fp_shr1 = mclx_Fp_shr1; op.fp_negA_ = mclx_Fp_neg; + op.fpDbl_modA_ = mclx_FpDbl_mod; + op.fp_mulA_ = mclx_Fp_mul; + op.fp_sqrA_ = mclx_Fp_sqr; op.fpDbl_addA_ = mclx_FpDbl_add; op.fpDbl_subA_ = mclx_FpDbl_sub; op.fpDbl_addPre = mclx_FpDbl_addPre; op.fpDbl_subPre = mclx_FpDbl_subPre; op.fpDbl_mulPreA_ = mclx_FpDbl_mulPre; op.fpDbl_sqrPreA_ = mclx_FpDbl_sqrPre; - op.fpDbl_modA_ = mclx_FpDbl_mod; - op.fp_mulA_ = mclx_Fp_mul; - op.fp_sqrA_ = mclx_Fp_sqr; + op.fp2_addA_ = mclx_Fp2_add; + op.fp2_subA_ = mclx_Fp2_sub; + op.fp2_negA_ = mclx_Fp2_neg; + op.fp2_mulNF = 0; + op.fp2_mulA_ = mclx_Fp2_mul; + op.fp2_sqrA_ = mclx_Fp2_sqr; + op.fp2_mul_xiA_ = mclx_Fp2_mul_xi; } else { // Fr, sizeof(Fr) = 32 op.fp_addPre = mclx_Fr_addPre; diff --git a/test/bls12_test.cpp b/test/bls12_test.cpp index 723bf3a..94dce59 100644 --- a/test/bls12_test.cpp +++ b/test/bls12_test.cpp @@ -688,6 +688,8 @@ CYBOZU_TEST_AUTO(multi) G1 P; G2 Q; int i; + +#ifndef MCL_STATIC_CODE puts("BN254"); testCurve(mcl::BN254); i = 1; @@ -695,6 +697,7 @@ CYBOZU_TEST_AUTO(multi) CYBOZU_BENCH_C("naiveG2", 100, (BN::param.mapTo.naiveMapTo), P, i++); CYBOZU_BENCH_C("calcBN2", 100, (BN::param.mapTo.calcBN), Q, i++); CYBOZU_BENCH_C("naiveG2", 100, (BN::param.mapTo.naiveMapTo), Q, i++); +#endif puts("BLS12_381"); testCurve(mcl::BLS12_381); i = 1;