Пример #1
0
        static void TestG2()
        {
            Console.WriteLine("TestG2");
            G2 P = new G2();

            P.Clear();
            assert("P = 0", P.ToString() == "0");
            assert("P is valid", P.IsValid());
            assert("P is zero", P.IsZero());
            P.HashAndMapTo("abc");
            assert("P is valid", P.IsValid());
            assert("P is not zero", !P.IsZero());
            G2 Q = new G2();

            Q = P.Clone();
            assert("P == Q", Q.Equals(P));
            G2.Neg(Q, P);
            G2.Add(Q, Q, P);
            assert("Q is zero", Q.IsZero());
            G2.Dbl(Q, P);
            G2 R = new G2();

            G2.Add(R, P, P);
            assert("Q == R", Q.Equals(R));
            Fr x = new Fr();

            x.SetInt(3);
            G2.Add(R, R, P);
            G2.Mul(Q, P, x);
            assert("Q == R", Q.Equals(R));
        }
Пример #2
0
        static void TestG2()
        {
            Console.WriteLine("TestG2");
            G2 P = new G2();

            assert("P.isZero", P.IsZero());
            P.Clear();
            assert("P is valid", P.IsValid());
            assert("P is zero", P.IsZero());
            P.HashAndMapTo("abc");
            assert("P is valid", P.IsValid());
            assert("P is not zero", !P.IsZero());
            G2 Q = new G2();

            Q = P;
            assert("P == Q", Q.Equals(P));
            Q.Neg(P);
            Q.Add(Q, P);
            assert("Q is zero", Q.IsZero());
            Q.Dbl(P);
            G2 R = new G2();

            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;
                G2[]      xVec = new G2[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("mulVecG2", P.Equals(Q));
            }
            G2 W = G2.Zero();

            assert("W.IsZero", W.IsZero());
        }
Пример #3
0
        static void TestG2()
        {
            Console.WriteLine("TestG2");
            G2 P = new G2();

            P.Clear();
            assert("P is valid", P.IsValid());
            assert("P is zero", P.IsZero());
            P.HashAndMapTo("abc");
            assert("P is valid", P.IsValid());
            assert("P is not zero", !P.IsZero());
            G2 Q = new G2();

            Q = P;
            assert("P == Q", Q.Equals(P));
            Q.Neg(P);
            Q.Add(Q, P);
            assert("Q is zero", Q.IsZero());
            Q.Dbl(P);
            G2 R = new G2();

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