Пример #1
0
/* this*=c mod Modulus, where c is a small int */
    public void imul(int c)
    {
        norm();
        bool s = false;

        if (c < 0)
        {
            c = -c;
            s = true;
        }
        long afx = (BIG.EXCESS(x) + 1) * (c + 1) + 1;

        if (c < ROM.NEXCESS && afx < ROM.FEXCESS)
        {
            x.imul(c);
        }
        else
        {
            if (afx < ROM.FEXCESS)
            {
                x.pmul(c);
            }
            else
            {
                DBIG d = x.pxmul(c);
                x.copy(d.mod(p));
            }
        }
        if (s)
        {
            neg();
        }
        norm();
    }
Пример #2
0
/* this+=b */
    public void add(FP b)
    {
        x.add(b.x);
        if (BIG.EXCESS(x) + 2 >= ROM.FEXCESS)
        {
            reduce();
        }
    }
Пример #3
0
/* this*=this mod Modulus */
    public void sqr()
    {
        DBIG d;
        long ea = BIG.EXCESS(x);

        if ((ea + 1) * (ea + 1) + 1 >= ROM.FEXCESS)
        {
            reduce();
        }

        d = BIG.sqr(x);
        x.copy(BIG.mod(d));
    }
Пример #4
0
/* this*=b mod Modulus */
    public void mul(FP b)
    {
        long ea = BIG.EXCESS(x);
        long eb = BIG.EXCESS(b.x);

        if ((ea + 1) * (eb + 1) + 1 >= ROM.FEXCESS)
        {
            reduce();
        }

        DBIG d = BIG.mul(x, b.x);

        x.copy(BIG.mod(d));
    }
Пример #5
0
/* this = -this mod Modulus */
    public void neg()
    {
        int  sb;
        long ov;
        BIG  m = new BIG(p);

        norm();

        ov = BIG.EXCESS(x);
        sb = 1;
        while (ov != 0)
        {
            sb++;
            ov >>= 1;
        }

        m.fshl(sb);
        x.rsub(m);

        if (BIG.EXCESS(x) >= ROM.FEXCESS)
        {
            reduce();
        }
    }