예제 #1
0
    /* double exponentiation r=x^e.y^f mod p */
    public void pow2(BIG e, FF y, BIG f, FF p)
    {
        int i, eb, fb, n = p.length;
        FF  xn = new FF(n);
        FF  yn = new FF(n);
        FF  xy = new FF(n);
        FF  ND = p.invmod2m();

        xn.copy(this);
        yn.copy(y);
        xn.nres(p);
        yn.nres(p);
        xy.copy(xn);
        xy.modmul(yn, p, ND);
        one();
        nres(p);

        for (i = 8 * ROM.MODBYTES - 1; i >= 0; i--)
        {
            eb = e.bit(i);
            fb = f.bit(i);
            modsqr(p, ND);
            if (eb == 1)
            {
                if (fb == 1)
                {
                    modmul(xy, p, ND);
                }
                else
                {
                    modmul(xn, p, ND);
                }
            }
            else
            {
                if (fb == 1)
                {
                    modmul(yn, p, ND);
                }
            }
        }
        redc(p, ND);
    }