/* f=f^e */ /* Note that this method requires a lot of RAM! Better to use compressed XTR method, see FP4.java */ public static FP12 GTPow(FP12 d, BIG e) { FP12 r; if (USE_GS_GT) { FP12[] g = new FP12[4]; FP2 f = new FP2(new BIG(ROM.Fra), new BIG(ROM.Frb)); BIG q = new BIG(ROM.CURVE_Order); BIG t = new BIG(0); int i, np, nn; BIG[] u = GS(e); g[0] = new FP12(d); for (i = 1; i < 4; i++) { g[i] = new FP12(0); g[i].Copy(g[i - 1]); g[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); g[i].Conj(); } u[i].Norm(); } r = FP12.Pow4(g, u); } else { r = d.Pow(e); } return(r); }
/* final exponentiation - keep separate for multi-pairings and to avoid thrashing stack */ public static FP12 FExp(FP12 m) { FP2 f = new FP2(new BIG(ROM.Fra), new BIG(ROM.Frb)); BIG x = new BIG(ROM.CURVE_Bnx); FP12 r = new FP12(m); /* Easy part of final exp */ FP12 lv = new FP12(r); lv.Inverse(); r.Conj(); r.mul(lv); lv.Copy(r); r.Frob(f); r.Frob(f); r.mul(lv); /* Hard part of final exp */ if (ECP.CURVE_PAIRING_TYPE == ECP.BN) { FP12 x0, x1, x2, x3, x4, x5; lv.Copy(r); lv.Frob(f); x0 = new FP12(lv); x0.Frob(f); lv.mul(r); x0.mul(lv); x0.Frob(f); x1 = new FP12(r); x1.Conj(); x4 = r.Pow(x); if (ECP.SIGN_OF_X == ECP.POSITIVEX) { x4.Conj(); } x3 = new FP12(x4); x3.Frob(f); x2 = x4.Pow(x); if (ECP.SIGN_OF_X == ECP.POSITIVEX) { x2.Conj(); } x5 = new FP12(x2); x5.Conj(); lv = x2.Pow(x); if (ECP.SIGN_OF_X == ECP.POSITIVEX) { lv.Conj(); } x2.Frob(f); r.Copy(x2); r.Conj(); x4.mul(r); x2.Frob(f); r.Copy(lv); r.Frob(f); lv.mul(r); lv.USqr(); lv.mul(x4); lv.mul(x5); r.Copy(x3); r.mul(x5); r.mul(lv); lv.mul(x2); r.USqr(); r.mul(lv); r.USqr(); lv.Copy(r); lv.mul(x1); r.mul(x0); lv.USqr(); r.mul(lv); r.Reduce(); } else { FP12 y0, y1, y2, y3; // Ghamman & Fouotsa Method y0 = new FP12(r); y0.USqr(); y1 = y0.Pow(x); if (ECP.SIGN_OF_X == ECP.NEGATIVEX) { y1.Conj(); } x.FShr(1); y2 = y1.Pow(x); if (ECP.SIGN_OF_X == ECP.NEGATIVEX) { y2.Conj(); } x.FShl(1); y3 = new FP12(r); y3.Conj(); y1.mul(y3); y1.Conj(); y1.mul(y2); y2 = y1.Pow(x); if (ECP.SIGN_OF_X == ECP.NEGATIVEX) { y2.Conj(); } y3 = y2.Pow(x); if (ECP.SIGN_OF_X == ECP.NEGATIVEX) { y3.Conj(); } y1.Conj(); y3.mul(y1); y1.Conj(); y1.Frob(f); y1.Frob(f); y1.Frob(f); y2.Frob(f); y2.Frob(f); y1.mul(y2); y2 = y3.Pow(x); if (ECP.SIGN_OF_X == ECP.NEGATIVEX) { y2.Conj(); } y2.mul(y0); y2.mul(r); y1.mul(y2); y2.Copy(y3); y2.Frob(f); y1.mul(y2); r.Copy(y1); r.Reduce(); } return(r); }