/* this*=this */ public void sqr() { norm(); FP2 t1 = new FP2(a); FP2 t2 = new FP2(b); FP2 t3 = new FP2(a); t3.mul(b); t1.add(b); t2.mul_ip(); t2.add(a); a.copy(t1); a.mul(t2); t2.copy(t3); t2.mul_ip(); t2.add(t3); t2.neg(); a.add(t2); b.copy(t3); b.add(t3); norm(); }
/* this-=a */ public void sub(FP2 x) { FP2 m = new FP2(x); m.neg(); add(m); }
/* set this=-this */ public void neg() { if (is_infinity()) { return; } y.neg(); y.reduce(); return; }
/* this+=this */ public int dbl() { if (INF) { return(-1); } if (y.iszilch()) { inf(); return(-1); } FP2 w1 = new FP2(x); FP2 w2 = new FP2(0); FP2 w3 = new FP2(x); FP2 w8 = new FP2(x); w1.sqr(); w8.copy(w1); w8.imul(3); w2.copy(y); w2.sqr(); w3.copy(x); w3.mul(w2); w3.imul(4); w1.copy(w3); w1.neg(); // w1.norm(); x.copy(w8); x.sqr(); x.add(w1); x.add(w1); x.norm(); z.mul(y); z.add(z); w2.add(w2); w2.sqr(); w2.add(w2); w3.sub(x); y.copy(w8); y.mul(w3); // w2.norm(); y.sub(w2); y.norm(); z.norm(); return(1); }
/* set this=-this */ public void neg() { FP2 m = new FP2(a); FP2 t = new FP2(0); m.add(b); m.neg(); m.norm(); t.copy(m); t.add(b); b.copy(m); b.add(a); a.copy(t); }
/* this=1/this */ public void inverse() { norm(); FP2 t1 = new FP2(a); FP2 t2 = new FP2(b); t1.sqr(); t2.sqr(); t2.mul_ip(); t1.sub(t2); t1.inverse(); a.mul(t1); t1.neg(); b.mul(t1); }
/* this=-conjugate(this) */ public void nconj() { a.neg(); a.norm(); }
/* this=conjugate(this) */ public void conj() { b.neg(); b.norm(); }
/* 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)); }