Example #1
0
        /* Multiply P by e in group G2 */
        public static ECP2 G2Mul(ECP2 P, BIG e)
        {
            ECP2 R;

            if (USE_GS_G2)
            {
                ECP2[] Q = new ECP2[4];
                FP2    f = new FP2(new BIG(ROM.Fra), new BIG(ROM.Frb));

                if (ECP.SEXTIC_TWIST == ECP.M_TYPE)
                {
                    f.Inverse();
                    f.Norm();
                }

                BIG   q = new BIG(ROM.CURVE_Order);
                BIG[] u = GS(e);

                BIG t = new BIG(0);
                int i, np, nn;
                //P.affine();

                Q[0] = new ECP2();
                Q[0].Copy(P);
                for (i = 1; i < 4; i++)
                {
                    Q[i] = new ECP2();
                    Q[i].Copy(Q[i - 1]);
                    Q[i].Frob(f);
                }

                for (i = 0; i < 4; i++)
                {
                    np = u[i].NBits();
                    t.Copy(BIG.ModNeg(u[i], q));
                    nn = t.NBits();
                    if (nn < np)
                    {
                        u[i].Copy(t);
                        Q[i].Neg();
                    }

                    u[i].Norm();
                    //Q[i].affine();
                }

                R = ECP2.Mul4(Q, u);
            }
            else
            {
                R = P.Mul(e);
            }

            return(R);
        }