Skip to content

Commit

Permalink
[C#] add test of millerLoopVec
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Mar 21, 2024
1 parent 3aabb9d commit 15b61e3
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions ffi/cs/test/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,29 @@ public static Boolean Verify(G2 gen, G2 pub, G1 sig, byte[] msg)
GT e2 = new GT();
G1 g1 = new G1();
g1.HashAndMapTo(msg);
/*
e1.Pairing(g1, pub);
e2.Pairing(sig, gen);
return e1.Equals(e2);
*/
e1.MillerLoop(g1, pub);
e2.MillerLoop(sig, gen);
e1.Inv(e1);
e1.Mul(e1, e2);
e1.FinalExp(e1);
return e1.IsOne();
const int algo = 2;
switch (algo) {
case 0:
e1.Pairing(g1, pub);
e2.Pairing(sig, gen);
return e1.Equals(e2);
case 1:
e1.MillerLoop(g1, pub);
e2.MillerLoop(sig, gen);
e1.Inv(e1);
e1.Mul(e1, e2);
e1.FinalExp(e1);
return e1.IsOne();
case 2: {
G1[] v1 = new G1[] { sig, g1 };
G2[] v2 = new G2[2];
v2[0] = gen;
MCL.Neg(ref v2[1], pub);
mclBn_millerLoopVec(ref e1, v1, v2, 2);
e1.FinalExp(e1);
return e1.IsOne();
}
}
}
public static void TestDFINITY()
{
Expand Down Expand Up @@ -472,17 +484,29 @@ public static Boolean Verify(G1 gen, G1 pub, G2 sig, byte[] msg)
GT e2 = new GT();
G2 g2 = new G2();
g2.HashAndMapTo(msg);
if (false) {
e1.Pairing(pub, g2);
e2.Pairing(gen, sig);
return e1.Equals(e2);
} else {
e1.MillerLoop(pub, g2);
e2.MillerLoop(gen, sig);
e1.Inv(e1);
e1.Mul(e1, e2);
e1.FinalExp(e1);
return e1.IsOne();
const int algo = 0;
switch (algo) {
case 0:
e1.Pairing(pub, g2);
e2.Pairing(gen, sig);
return e1.Equals(e2);
case 1:
e1.MillerLoop(pub, g2);
e2.MillerLoop(gen, sig);
e1.Inv(e1);
e1.Mul(e1, e2);
e1.FinalExp(e1);
return e1.IsOne();
case 2: {
G1[] v1 = new G1[2];
v1[0] = gen;
MCL.Neg(ref v1[0], pub);
G2[] v2 = new G2[] { sig, g2 };
mclBn_millerLoopVec(ref e1, v1, v2, 2);
e1.FinalExp(e1);
return e1.IsOne();
}

}
}
public static void PutByte(String msg, byte[] b)
Expand Down

0 comments on commit 15b61e3

Please sign in to comment.