aboutsummaryrefslogtreecommitdiffstats
path: root/test/bls12_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/bls12_test.cpp')
-rw-r--r--test/bls12_test.cpp80
1 files changed, 43 insertions, 37 deletions
diff --git a/test/bls12_test.cpp b/test/bls12_test.cpp
index b0344fe..261d10c 100644
--- a/test/bls12_test.cpp
+++ b/test/bls12_test.cpp
@@ -95,8 +95,8 @@ void finalExpC(Fp12& y, const Fp12& x)
void pairingC(Fp12& e, const G1& P, const G2& Q)
{
- BN::millerLoop(e, P, Q);
- BN::finalExp(e, e);
+ millerLoop(e, P, Q);
+ finalExp(e, e);
}
void testIoAll(const G1& P, const G2& Q)
{
@@ -152,7 +152,7 @@ void testMapToG1()
{
G1 g;
for (int i = 1; i < 10; i++) {
- BN::mapToG1(g, i);
+ mapToG1(g, i);
CYBOZU_TEST_ASSERT(!g.isZero());
G1 gr;
G1::mul(gr, g, BN::param.r);
@@ -164,7 +164,7 @@ void testMapToG2()
{
G2 g;
for (int i = 1; i < 10; i++) {
- BN::mapToG2(g, i);
+ mapToG2(g, i);
CYBOZU_TEST_ASSERT(!g.isZero());
G2 gr;
G2::mul(gr, g, BN::param.r);
@@ -172,18 +172,18 @@ void testMapToG2()
}
Fp x;
x.setHashOf("abc");
- BN::mapToG2(g, Fp2(x, 0));
+ mapToG2(g, Fp2(x, 0));
CYBOZU_TEST_ASSERT(g.isValid());
}
void testPrecomputed(const G1& P, const G2& Q)
{
Fp12 e1, e2;
- BN::pairing(e1, P, Q);
+ pairing(e1, P, Q);
std::vector<Fp6> Qcoeff;
- BN::precomputeG2(Qcoeff, Q);
- BN::precomputedMillerLoop(e2, P, Qcoeff);
- BN::finalExp(e2, e2);
+ precomputeG2(Qcoeff, Q);
+ precomputedMillerLoop(e2, P, Qcoeff);
+ finalExp(e2, e2);
CYBOZU_TEST_EQUAL(e1, e2);
}
@@ -191,7 +191,7 @@ void testPrecomputed(const G1& P, const G2& Q)
void testFp12pow(const G1& P, const G2& Q)
{
Fp12 e, e1, e2;
- BN::pairing(e, P, Q);
+ pairing(e, P, Q);
cybozu::XorShift rg;
for (int i = -10; i < 10; i++) {
mpz_class xm = i;
@@ -204,7 +204,7 @@ void testFp12pow(const G1& P, const G2& Q)
x.setRand(rg);
mpz_class xm = x.getMpz();
Fp12::pow(e1, e, xm);
- BN::param.glv2.pow(e2, e, xm);
+ param.glv2.pow(e2, e, xm);
CYBOZU_TEST_EQUAL(e1, e2);
}
}
@@ -219,22 +219,22 @@ void testMillerLoop2(const G1& P1, const G2& Q1)
G1 P2;
G2::mul(Q2, Q1, c1);
G1::mul(P2, P1, c2);
- BN::pairing(e1, P1, Q1);
- BN::pairing(e2, P2, Q2);
+ pairing(e1, P1, Q1);
+ pairing(e2, P2, Q2);
e1 *= e2;
std::vector<Fp6> Q1coeff, Q2coeff;
- BN::precomputeG2(Q1coeff, Q1);
- BN::precomputeG2(Q2coeff, Q2);
- BN::precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff);
- BN::finalExp(e2, e2);
+ precomputeG2(Q1coeff, Q1);
+ precomputeG2(Q2coeff, Q2);
+ precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff);
+ finalExp(e2, e2);
CYBOZU_TEST_EQUAL(e1, e2);
}
void testPairing(const G1& P, const G2& Q, const char *eStr)
{
Fp12 e1;
- BN::pairing(e1, P, Q);
+ pairing(e1, P, Q);
Fp12 e2;
{
std::stringstream ss(eStr);
@@ -261,8 +261,8 @@ void testPairing(const G1& P, const G2& Q, const char *eStr)
G1 T;
G1::mulCT(T, P, a);
CYBOZU_TEST_EQUAL(Pa, T);
- BN::pairing(e1, Pa, Q);
- BN::pairing(e2, P, Qa);
+ pairing(e1, Pa, Q);
+ pairing(e2, P, Qa);
CYBOZU_TEST_EQUAL(ea, e1);
CYBOZU_TEST_EQUAL(ea, e2);
}
@@ -273,22 +273,22 @@ void testTrivial(const G1& P, const G2& Q)
G1 Z1; Z1.clear();
G2 Z2; Z2.clear();
Fp12 e;
- BN::pairing(e, Z1, Q);
+ pairing(e, Z1, Q);
CYBOZU_TEST_EQUAL(e, 1);
- BN::pairing(e, P, Z2);
+ pairing(e, P, Z2);
CYBOZU_TEST_EQUAL(e, 1);
- BN::pairing(e, Z1, Z2);
+ pairing(e, Z1, Z2);
CYBOZU_TEST_EQUAL(e, 1);
std::vector<Fp6> Qcoeff;
- BN::precomputeG2(Qcoeff, Z2);
- BN::precomputedMillerLoop(e, P, Qcoeff);
- BN::finalExp(e, e);
+ precomputeG2(Qcoeff, Z2);
+ precomputedMillerLoop(e, P, Qcoeff);
+ finalExp(e, e);
CYBOZU_TEST_EQUAL(e, 1);
- BN::precomputeG2(Qcoeff, Q);
- BN::precomputedMillerLoop(e, Z1, Qcoeff);
- BN::finalExp(e, e);
+ precomputeG2(Qcoeff, Q);
+ precomputedMillerLoop(e, Z1, Qcoeff);
+ finalExp(e, e);
CYBOZU_TEST_EQUAL(e, 1);
}
@@ -305,7 +305,7 @@ CYBOZU_TEST_AUTO(naive)
#ifdef ONLY_BENCH
{
Fp12 e;
- for (int i = 0; i < 1000; i++) BN::pairing(e, P, Q);
+ for (int i = 0; i < 1000; i++) pairing(e, P, Q);
}
clk.put();
return;
@@ -362,10 +362,10 @@ const char *e1Str =
Fp12 e0, e1, e2;
e0.setStr(e0Str, 16);
e1.setStr(e1Str, 16);
- BN::finalExp(e2, e0);
+ finalExp(e2, e0);
// finalExpC(e2, e0);
CYBOZU_TEST_EQUAL(e1, e2);
- CYBOZU_BENCH_C("finalExp", 100, BN::finalExp, e2, e0);
+ CYBOZU_BENCH_C("finalExp", 100, finalExp, e2, e0);
}
CYBOZU_TEST_AUTO(addLine)
@@ -589,7 +589,7 @@ const char *eStr =
Q.setStr(qStr, mode);
Fp12 e1, e2;
e1.setStr(eStr, 16);
- BN::pairing(e2, P, Q);
+ pairing(e2, P, Q);
CYBOZU_TEST_EQUAL(e1, e2);
}
@@ -598,10 +598,10 @@ void testCurve(const mcl::CurveParam& cp)
initPairing(cp, g_mode);
G1 P;
G2 Q;
- BN::mapToG1(P, 1);
- BN::mapToG2(Q, 1);
+ mapToG1(P, 1);
+ mapToG2(Q, 1);
GT e1, e2;
- BN::pairing(e1, P, Q);
+ pairing(e1, P, Q);
cybozu::XorShift rg;
mpz_class a, b;
Fr r;
@@ -611,7 +611,7 @@ void testCurve(const mcl::CurveParam& cp)
G2 bQ;
G1::mul(aP, P, a);
G2::mul(bQ, Q, b);
- BN::pairing(e2, aP, bQ);
+ pairing(e2, aP, bQ);
GT::pow(e1, e1, a * b);
CYBOZU_TEST_EQUAL(e1, e2);
}
@@ -623,6 +623,12 @@ CYBOZU_TEST_AUTO(multi)
testCurve(mcl::BLS12_381);
}
+CYBOZU_TEST_AUTO(BLS12_G1mulCofactor)
+{
+ if (BN::param.cp.curveType != MCL_BLS12_381) return;
+
+}
+
int main(int argc, char *argv[])
try
{