/* return this^e mod Modulus * public FP pow(BIG e) * { * int bt; * FP r=new FP(1); * e.norm(); * x.norm(); * FP m=new FP(this); * while (true) * { * bt=e.parity(); * e.fshr(1); * if (bt==1) r.mul(m); * if (e.iszilch()) break; * m.sqr(); * } * r.x.mod(p); * return r; * } */ /* return sqrt(this) mod Modulus */ public FP Sqrt() { Reduce(); BIG b = new BIG(ROM.Modulus); if (MOD8 == 5) { b.Dec(5); b.Norm(); b.Shr(3); FP i = new FP(this); i.x.Shl(1); FP v = i.Pow(b); i.Mul(v); i.Mul(v); i.x.Dec(1); FP r = new FP(this); r.Mul(v); r.Mul(i); r.Reduce(); return(r); } else { b.Inc(1); b.Norm(); b.Shr(2); return(Pow(b)); } }
public FP Pow(BIG e) { sbyte[] w = new sbyte[1 + (BIG.NLEN * BIG.BASEBITS + 3) / 4]; FP[] tb = new FP[16]; BIG t = new BIG(e); t.Norm(); int nb = 1 + (t.NBits() + 3) / 4; for (int i = 0; i < nb; i++) { int lsbs = t.LastBits(4); t.Dec(lsbs); t.Norm(); w[i] = (sbyte)lsbs; t.FShr(4); } tb[0] = new FP(1); tb[1] = new FP(this); for (int i = 2; i < 16; i++) { tb[i] = new FP(tb[i - 1]); tb[i].Mul(this); } FP r = new FP(tb[w[nb - 1]]); for (int i = nb - 2; i >= 0; i--) { r.Sqr(); r.Sqr(); r.Sqr(); r.Sqr(); r.Mul(tb[w[i]]); } r.Reduce(); return(r); }
/* this*=s, where s is an FP */ public void PMul(FP s) { a.Mul(s); b.Mul(s); }