예제 #1
0
/* Line function */
    public static FP12 line(ECP2 A, ECP2 B, FP Qx, FP Qy)
    {
        ECP2 P = new ECP2();

        FP4 a, b, c;

        P.copy(A);
        FP2 ZZ = new FP2(P.getz());

        ZZ.sqr();
        int D;

        if (A == B)
        {
            D = A.dbl();             // Check this return value in amcl_ec2.c
        }
        else
        {
            D = A.add(B);
        }
        if (D < 0)
        {
            return(new FP12(1));
        }
        FP2 Z3 = new FP2(A.getz());

        c = new FP4(0);
        if (D == 0)
        {         // Addition
            FP2 X = new FP2(B.getx());
            FP2 Y = new FP2(B.gety());
            FP2 T = new FP2(P.getz());
            T.mul(Y);
            ZZ.mul(T);

            FP2 NY = new FP2(P.gety());
            NY.neg();
            ZZ.add(NY);
            Z3.pmul(Qy);
            T.mul(P.getx());
            X.mul(NY);
            T.add(X);
            a = new FP4(Z3, T);
            ZZ.neg();
            ZZ.pmul(Qx);
            b = new FP4(ZZ);
        }
        else
        {         // Doubling
            FP2 X = new FP2(P.getx());
            FP2 Y = new FP2(P.gety());
            FP2 T = new FP2(P.getx());
            T.sqr();
            T.imul(3);

            Y.sqr();
            Y.add(Y);
            Z3.mul(ZZ);
            Z3.pmul(Qy);

            X.mul(T);
            X.sub(Y);
            a = new FP4(Z3, X);
            T.neg();
            ZZ.mul(T);
            ZZ.pmul(Qx);
            b = new FP4(ZZ);
        }
        return(new FP12(a, b, c));
    }