aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/byzantine-lab/mcl/test/bn512_test.cpp
blob: 905bfd3db800577d73a4fe72c0fa38ffb07d3732 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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;

#include "bench.hpp"

void testCurve(const mcl::CurveParam& cp)
{
    initPairing(cp, g_mode);
    G1 P;
    G2 Q;
    mapToG1(P, 1);
    mapToG2(Q, 1);
    GT e1, e2;
    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);
    pairing(e2, aP, bQ);
    GT::pow(e1, e1, a * b);
    CYBOZU_TEST_EQUAL(e1, e2);
    testBench(P, Q);
    testSquareRoot();
    testLagrange();
}

CYBOZU_TEST_AUTO(pairing)
{
    puts("BN462");
    testCurve(mcl::BN462);
    puts("BN381_1");
    testCurve(mcl::BN381_1);
    puts("BLS12_381");
    testCurve(mcl::BLS12_381);
    puts("BN254");
    testCurve(mcl::BN254);
}

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;
}