Esempio n. 1
0
/* a=1/a mod 2^256. This is very fast! */
    public virtual void invmod2m()
    {
        int i;
        BIG U = new BIG(0);
        BIG b = new BIG(0);
        BIG c = new BIG(0);

        U.inc(invmod256(lastbits(8)));

        for (i = 8; i < 256; i <<= 1)
        {
            b.copy(this);
            b.mod2m(i);
            BIG t1 = BIG.smul(U, b);
            t1.shr(i);
            c.copy(this);
            c.shr(i);
            c.mod2m(i);

            BIG t2 = BIG.smul(U, c);
            t2.mod2m(i);
            t1.add(t2);
            b = BIG.smul(t1, U);
            t1.copy(b);
            t1.mod2m(i);

            t2.one();
            t2.shl(i);
            t1.rsub(t2);
            t1.norm();
            t1.shl(i);
            U.add(t1);
        }
        this.copy(U);
    }