Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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));
            {
                byte[] buf = P.Serialize();
                Q.Clear();
                Q.Deserialize(buf);
                assert("P == Q", P.Equals(Q));
            }
        }