a portable and fast pairing-based cryptography library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mcl/test/bn384_test.cpp

68 lines
1.6 KiB

#define CYBOZU_TEST_DISABLE_AUTO_RUN
8 years ago
#include <cybozu/test.hpp>
#include <cybozu/benchmark.hpp>
#include <cybozu/option.hpp>
#include <cybozu/xorshift.hpp>
8 years ago
#include <mcl/bn384.hpp>
8 years ago
#include <mcl/bn.hpp>
8 years ago
using namespace mcl::bn384;
8 years ago
mcl::fp::Mode g_mode;
void testCurve(const mcl::bn::CurveParam& cp)
8 years ago
{
bn384init(cp, g_mode);
8 years ago
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();
8 years ago
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);
8 years ago
CYBOZU_BENCH("pairing", BN::pairing, e1, P, Q);
CYBOZU_BENCH("finalExp", BN::finalExp, e1, e1);
}
CYBOZU_TEST_AUTO(pairing)
{
testCurve(mcl::bn::CurveFp382_1);
testCurve(mcl::bn::CurveFp382_2);
8 years ago
// support 256-bit pairing
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;
}