/* this=1/this */ public void Inverse() { FP4 f0 = new FP4(a); FP4 f1 = new FP4(b); FP4 f2 = new FP4(a); FP4 f3 = new FP4(0); Norm(); f0.Sqr(); f1.Mul(c); f1.Times_I(); f0.Sub(f1); f0.Norm(); f1.Copy(c); f1.Sqr(); f1.Times_I(); f2.Mul(b); f1.Sub(f2); f1.Norm(); f2.Copy(b); f2.Sqr(); f3.Copy(a); f3.Mul(c); f2.Sub(f3); f2.Norm(); f3.Copy(b); f3.Mul(f2); f3.Times_I(); a.Mul(f0); f3.Add(a); c.Mul(f1); c.Times_I(); f3.Add(c); f3.Norm(); f3.Inverse(); a.Copy(f0); a.Mul(f3); b.Copy(f1); b.Mul(f3); c.Copy(f2); c.Mul(f3); }
/* Granger-Scott Unitary Squaring */ public void USqr() { //System.out.println("Into usqr"); FP4 A = new FP4(a); FP4 B = new FP4(c); FP4 C = new FP4(b); FP4 D = new FP4(0); a.Sqr(); D.Copy(a); D.Add(a); a.Add(D); a.Norm(); A.NConj(); A.Add(A); a.Add(A); B.Sqr(); B.Times_I(); D.Copy(B); D.Add(B); B.Add(D); B.Norm(); C.Sqr(); D.Copy(C); D.Add(C); C.Add(D); C.Norm(); b.Conj(); b.Add(b); c.NConj(); c.Add(c); b.Add(B); c.Add(C); //System.out.println("Out of usqr 1"); Reduce(); //System.out.println("Out of usqr 2"); }
/* XTR xtr_d function */ public void Xtr_D() { FP4 w = new FP4(this); Sqr(); w.Conj(); w.Add(w); w.Norm(); Sub(w); Reduce(); }
/* Chung-Hasan SQR2 method from http://cacr.uwaterloo.ca/techreports/2006/cacr2006-24.pdf */ public void Sqr() { //System.out.println("Into sqr"); FP4 A = new FP4(a); FP4 B = new FP4(b); FP4 C = new FP4(c); FP4 D = new FP4(a); A.Sqr(); B.Mul(c); B.Add(B); B.Norm(); C.Sqr(); D.Mul(b); D.Add(D); c.Add(a); c.Add(b); c.Norm(); c.Sqr(); a.Copy(A); A.Add(B); A.Norm(); A.Add(C); A.Add(D); A.Norm(); A.Neg(); B.Times_I(); C.Times_I(); a.Add(B); b.Copy(C); b.Add(D); c.Add(A); //System.out.println("Out of sqr"); Norm(); }
/* XTR xtr_a function */ public void Xtr_A(FP4 w, FP4 y, FP4 z) { FP4 r = new FP4(w); FP4 t = new FP4(w); //y.norm(); r.Sub(y); r.Norm(); r.PMul(a); t.Add(y); t.Norm(); t.PMul(b); t.Times_I(); Copy(r); Add(t); Add(z); Norm(); }
/* Special case of multiplication arises from special form of ATE pairing line function */ public void SMul(FP12 y, int type) { //System.out.println("Into smul"); if (type == ECP.D_TYPE) { FP4 z0 = new FP4(a); FP4 z2 = new FP4(b); FP4 z3 = new FP4(b); FP4 t0 = new FP4(0); FP4 t1 = new FP4(y.a); z0.Mul(y.a); z2.PMul(y.b.Real()); b.Add(a); t1.Real().Add(y.b.Real()); t1.Norm(); b.Norm(); b.Mul(t1); z3.Add(c); z3.Norm(); z3.PMul(y.b.Real()); t0.Copy(z0); t0.Neg(); t1.Copy(z2); t1.Neg(); b.Add(t0); b.Add(t1); z3.Add(t1); z2.Add(t0); t0.Copy(a); t0.Add(c); t0.Norm(); z3.Norm(); t0.Mul(y.a); c.Copy(z2); c.Add(t0); z3.Times_I(); a.Copy(z0); a.Add(z3); } if (type == ECP.M_TYPE) { FP4 z0 = new FP4(a); FP4 z1 = new FP4(0); FP4 z2 = new FP4(0); FP4 z3 = new FP4(0); FP4 t0 = new FP4(a); FP4 t1 = new FP4(0); z0.Mul(y.a); t0.Add(b); t0.Norm(); z1.Copy(t0); z1.Mul(y.a); t0.Copy(b); t0.Add(c); t0.Norm(); z3.Copy(t0); //z3.mul(y.c); z3.PMul(y.c.GetB()); z3.Times_I(); t0.Copy(z0); t0.Neg(); z1.Add(t0); b.Copy(z1); z2.Copy(t0); t0.Copy(a); t0.Add(c); t1.Copy(y.a); t1.Add(y.c); t0.Norm(); t1.Norm(); t0.Mul(t1); z2.Add(t0); t0.Copy(c); t0.PMul(y.c.GetB()); t0.Times_I(); t1.Copy(t0); t1.Neg(); c.Copy(z2); c.Add(t1); z3.Add(t1); t0.Times_I(); b.Add(t0); z3.Norm(); z3.Times_I(); a.Copy(z0); a.Add(z3); } Norm(); //System.out.println("Out of smul"); }
/* FP12 full multiplication this=this*y */ public void mul(FP12 y) { //System.out.println("Into mul"); FP4 z0 = new FP4(a); FP4 z1 = new FP4(0); FP4 z2 = new FP4(b); FP4 z3 = new FP4(0); FP4 t0 = new FP4(a); FP4 t1 = new FP4(y.a); z0.Mul(y.a); z2.Mul(y.b); t0.Add(b); t1.Add(y.b); t0.Norm(); t1.Norm(); z1.Copy(t0); z1.Mul(t1); t0.Copy(b); t0.Add(c); t1.Copy(y.b); t1.Add(y.c); t0.Norm(); t1.Norm(); z3.Copy(t0); z3.Mul(t1); t0.Copy(z0); t0.Neg(); t1.Copy(z2); t1.Neg(); z1.Add(t0); //z1.norm(); b.Copy(z1); b.Add(t1); z3.Add(t1); z2.Add(t0); t0.Copy(a); t0.Add(c); t1.Copy(y.a); t1.Add(y.c); t0.Norm(); t1.Norm(); t0.Mul(t1); z2.Add(t0); t0.Copy(c); t0.Mul(y.c); t1.Copy(t0); t1.Neg(); // z2.norm(); // z3.norm(); // b.norm(); c.Copy(z2); c.Add(t1); z3.Add(t1); t0.Times_I(); b.Add(t0); z3.Norm(); z3.Times_I(); a.Copy(z0); a.Add(z3); Norm(); //System.out.println("Out of mul"); }