Example #1
0
        /* Line function */
        public static FP12 Line(ECP2 A, ECP2 B, FP Qx, FP Qy)
        {
            //System.out.println("Into line");
            FP4 a, b, c; // Edits here

            //		c=new FP4(0);
            if (A == B)
            {
                // Doubling
                FP2 XX = new FP2(A.GetX()); //X
                FP2 YY = new FP2(A.GetY()); //Y
                FP2 ZZ = new FP2(A.GetZ()); //Z
                FP2 YZ = new FP2(YY);       //Y
                YZ.Mul(ZZ);                 //YZ
                XX.Sqr();                   //X^2
                YY.Sqr();                   //Y^2
                ZZ.Sqr();                   //Z^2

                YZ.IMul(4);
                YZ.Neg();
                YZ.Norm();   //-2YZ
                YZ.PMul(Qy); //-2YZ.Ys

                XX.IMul(6);  //3X^2
                XX.PMul(Qx); //3X^2.Xs

                int sb = 3 * ROM.CURVE_B_I;
                ZZ.IMul(sb);

                if (ECP.SEXTIC_TWIST == ECP.D_TYPE)
                {
                    ZZ.Div_Ip2();
                }

                if (ECP.SEXTIC_TWIST == ECP.M_TYPE)
                {
                    ZZ.Mul_Ip();
                    ZZ.Add(ZZ);
                    YZ.Mul_Ip();
                    YZ.Norm();
                }

                ZZ.Norm(); // 3b.Z^2

                YY.Add(YY);
                ZZ.Sub(YY);
                ZZ.Norm();           // 3b.Z^2-Y^2

                a = new FP4(YZ, ZZ); // -2YZ.Ys | 3b.Z^2-Y^2 | 3X^2.Xs
                if (ECP.SEXTIC_TWIST == ECP.D_TYPE)
                {
                    b = new FP4(XX); // L(0,1) | L(0,0) | L(1,0)
                    c = new FP4(0);
                }

                if (ECP.SEXTIC_TWIST == ECP.M_TYPE)
                {
                    b = new FP4(0);
                    c = new FP4(XX);
                    c.Times_I();
                }

                A.Dbl();
            }
            else
            {
                // Addition - assume B is affine

                FP2 X1 = new FP2(A.GetX()); // X1
                FP2 Y1 = new FP2(A.GetY()); // Y1
                FP2 T1 = new FP2(A.GetZ()); // Z1
                FP2 T2 = new FP2(A.GetZ()); // Z1

                T1.Mul(B.GetY());           // T1=Z1.Y2
                T2.Mul(B.GetX());           // T2=Z1.X2

                X1.Sub(T2);
                X1.Norm();   // X1=X1-Z1.X2
                Y1.Sub(T1);
                Y1.Norm();   // Y1=Y1-Z1.Y2

                T1.Copy(X1); // T1=X1-Z1.X2
                X1.PMul(Qy); // X1=(X1-Z1.X2).Ys

                if (ECP.SEXTIC_TWIST == ECP.M_TYPE)
                {
                    X1.Mul_Ip();
                    X1.Norm();
                }

                T1.Mul(B.GetY()); // T1=(X1-Z1.X2).Y2

                T2.Copy(Y1);      // T2=Y1-Z1.Y2
                T2.Mul(B.GetX()); // T2=(Y1-Z1.Y2).X2
                T2.Sub(T1);
                T2.Norm();        // T2=(Y1-Z1.Y2).X2 - (X1-Z1.X2).Y2
                Y1.PMul(Qx);
                Y1.Neg();
                Y1.Norm();           // Y1=-(Y1-Z1.Y2).Xs

                a = new FP4(X1, T2); // (X1-Z1.X2).Ys  |  (Y1-Z1.Y2).X2 - (X1-Z1.X2).Y2  | - (Y1-Z1.Y2).Xs
                if (ECP.SEXTIC_TWIST == ECP.D_TYPE)
                {
                    b = new FP4(Y1);
                    c = new FP4(0);
                }

                if (ECP.SEXTIC_TWIST == ECP.M_TYPE)
                {
                    b = new FP4(0);
                    c = new FP4(Y1);
                    c.Times_I();
                }

                A.Add(B);
            }

            //System.out.println("Out of line");
            return(new FP12(a, b, c));
        }