Пример #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));
            }
        }
Пример #4
0
        static void TestSS_G2()
        {
            const int n = 5;
            const int k = 3; // can't change because the following loop

            G2[] cVec = new G2[k];
            // init polynomial coefficient
            for (int i = 0; i < k; i++)
            {
                Fr x = new Fr();
                x.SetByCSPRNG();
                cVec[i].SetHashOf(x.GetStr(16));
            }

            Fr[] xVec = new Fr[n];
            G2[] yVec = new G2[n];
            // share cVec[0] with yVec[0], ..., yVec[n-1]
            for (int i = 0; i < n; i++)
            {
                xVec[i].SetHashOf(i.ToString());
                MCL.Share(ref yVec[i], cVec, xVec[i]);
            }
            // recover cVec[0] from xVecSubset and yVecSubset
            Fr[] xVecSubset = new Fr[k];
            G2[] yVecSubset = new G2[k];
            for (int i0 = 0; i0 < n; i0++)
            {
                xVecSubset[0] = xVec[i0];
                yVecSubset[0] = yVec[i0];
                for (int i1 = i0 + 1; i1 < n; i1++)
                {
                    xVecSubset[1] = xVec[i1];
                    yVecSubset[1] = yVec[i1];
                    for (int i2 = i1 + 1; i2 < n; i2++)
                    {
                        xVecSubset[2] = xVec[i2];
                        yVecSubset[2] = yVec[i2];
                        G2 s = new G2();
                        MCL.Recover(ref s, xVecSubset, yVecSubset);
                        assert("Recover", s.Equals(cVec[0]));
                    }
                }
            }
        }