static void TestG1() { Console.WriteLine("TestG1"); G1 P = new G1(); P.Clear(); assert("P = 0", P.ToString() == "0"); assert("P.IsValid", P.IsValid()); assert("P.IsZero", P.IsZero()); P.HashAndMapTo("abc"); assert("P.IsValid", P.IsValid()); assert("!P.IsZero", !P.IsZero()); G1 Q = new G1(); Q = P.Clone(); assert("P == Q", Q.Equals(P)); G1.Neg(Q, P); G1.Add(Q, Q, P); assert("P = Q", Q.IsZero()); G1.Dbl(Q, P); G1 R = new G1(); G1.Add(R, P, P); assert("Q == R", Q.Equals(R)); Fr x = new Fr(); x.SetInt(3); G1.Add(R, R, P); G1.Mul(Q, P, x); assert("Q == R", Q.Equals(R)); }
static void TestETH_mapToG1() { var tbl = new[] { new { msg = "asdf", x = "a72df17570d0eb81260042edbea415ad49bdb94a1bc1ce9d1bf147d0d48268170764bb513a3b994d662e1faba137106", y = "122b77eca1ed58795b7cd456576362f4f7bd7a572a29334b4817898a42414d31e9c0267f2dc481a4daf8bcf4a460322", }, }; G1 P = new G1(); Fp x = new Fp(); Fp y = new Fp(); foreach (var v in tbl) { P.HashAndMapTo(v.msg); x.SetStr(v.x, 16); y.SetStr(v.y, 16); Normalize(ref P, P); Console.WriteLine("x={0}", P.x.GetStr(16)); Console.WriteLine("y={0}", P.y.GetStr(16)); assert("P.x", P.x.Equals(x)); assert("P.y", P.y.Equals(y)); } }
static void TestPairing() { Console.WriteLine("TestG2"); G1 P = new G1(); P.HashAndMapTo("123"); G2 Q = new G2(); Q.HashAndMapTo("1"); Fr a = new Fr(); Fr b = new Fr(); a.SetStr("12345678912345673453", 10); b.SetStr("230498230982394243424", 10); G1 aP = new G1(); G2 bQ = new G2(); aP.Mul(P, a); bQ.Mul(Q, b); GT e1 = new GT(); GT e2 = new GT(); GT e3 = new GT(); e1.Pairing(P, Q); e2.Pairing(aP, Q); e3.Pow(e1, a); assert("e2.Equals(e3)", e2.Equals(e3)); e2.Pairing(P, bQ); e3.Pow(e1, b); assert("e2.Equals(e3)", e2.Equals(e3)); }
static void TestETH_mapToG1() { var tbl = new[] { new { msg = "asdf", dst = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", x = "bc73d15443009a8ff2ddce864136d892274dd8365c60d0d2d44cc543387348e366a8f1e1401427e37743c29ed2c939a", y = "101e26428a1b78c05458cb1cc37d2d87876ad3437096d2827f376702d4451667fe1fa82e82795495d33d466133ed1862", }, }; G1 P = new G1(); Fp x = new Fp(); Fp y = new Fp(); foreach (var v in tbl) { P.HashAndMapTo(v.msg); x.SetStr(v.x, 16); y.SetStr(v.y, 16); Normalize(ref P, P); Console.WriteLine("x={0}", P.x.GetStr(16)); Console.WriteLine("y={0}", P.y.GetStr(16)); assert("P.x", P.x.Equals(x)); assert("P.y", P.y.Equals(y)); } }
static void TestG1() { Console.WriteLine("TestG1"); G1 P = new G1(); P.Clear(); assert("P.IsValid", P.IsValid()); assert("P.IsZero", P.IsZero()); P.HashAndMapTo("abc"); assert("P.IsValid", P.IsValid()); assert("!P.IsZero", !P.IsZero()); G1 Q = new G1(); Q = P; assert("P == Q", Q.Equals(P)); Q.Neg(P); Q.Add(Q, P); assert("P = Q", Q.IsZero()); Q.Dbl(P); G1 R = new G1(); R.Add(P, P); assert("Q == R", Q.Equals(R)); Fr x = new Fr(); x.SetInt(3); R.Add(R, P); Q.Mul(P, x); assert("Q == R", Q.Equals(R)); }
static void TestG1() { Console.WriteLine("TestG1"); G1 P = new G1(); assert("P.isZero", P.IsZero()); P.Clear(); assert("P.IsValid", P.IsValid()); assert("P.IsZero", P.IsZero()); P.HashAndMapTo("abc"); assert("P.IsValid", P.IsValid()); assert("!P.IsZero", !P.IsZero()); G1 Q = new G1(); Q = P; assert("P == Q", Q.Equals(P)); Q.Neg(P); Q.Add(Q, P); assert("P = Q", Q.IsZero()); Q.Dbl(P); G1 R = new G1(); R.Add(P, P); assert("Q == R", Q.Equals(R)); Fr x = new Fr(); x.SetInt(3); R.Add(R, P); Q.Mul(P, x); assert("Q == R", Q.Equals(R)); { byte[] buf = P.Serialize(); Q.Clear(); Q.Deserialize(buf); assert("P == Q", P.Equals(Q)); } { const int n = 5; G1[] xVec = new G1[n]; Fr[] yVec = new Fr[n]; P.Clear(); for (int i = 0; i < n; i++) { xVec[i].HashAndMapTo(i.ToString()); yVec[i].SetByCSPRNG(); Q.Mul(xVec[i], yVec[i]); P.Add(P, Q); } MulVec(ref Q, xVec, yVec); assert("mulVecG1", P.Equals(Q)); } G1 W = G1.Zero(); assert("W.IsZero", W.IsZero()); }