static void TestFp() { Console.WriteLine("TestFp"); Fp x = new Fp(); assert("x.isZero", x.IsZero()); x.Clear(); assert("0", x.GetStr(10) == "0"); assert("0.IzZero", x.IsZero()); assert("!0.IzOne", !x.IsOne()); x.SetInt(1); assert("1", x.GetStr(10) == "1"); assert("!1.IzZero", !x.IsZero()); assert("1.IzOne", x.IsOne()); x.SetInt(3); assert("3", x.GetStr(10) == "3"); assert("!3.IzZero", !x.IsZero()); assert("!3.IzOne", !x.IsOne()); x.SetInt(-5); x = -x; assert("5", x.GetStr(10) == "5"); x.SetInt(4); x = x * x; assert("16", x.GetStr(10) == "16"); assert("10", x.GetStr(16) == "10"); Fp y; y = x; assert("x == y", x.Equals(y)); x.SetInt(123); assert("123", x.GetStr(10) == "123"); assert("7b", x.GetStr(16) == "7b"); assert("y != x", !x.Equals(y)); Console.WriteLine("exception test"); try { x.SetStr("1234567891234x", 10); Console.WriteLine("x = {0}", x); } catch (Exception e) { Console.WriteLine("OK ; expected exception: {0}", e); } x.SetStr("1234567891234", 10); assert("1234567891234", x.GetStr(10) == "1234567891234"); { byte[] buf = x.Serialize(); y.Deserialize(buf); assert("x == y", x.Equals(y)); } }
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 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)); } }