All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.bouncycastle.math.ec.FixedPointCombMultiplier Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.bouncycastle.math.ec;

import java.math.BigInteger;

public class FixedPointCombMultiplier extends AbstractECMultiplier
{
    protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
    {
        ECCurve c = p.getCurve();
        int size = FixedPointUtil.getCombSize(c);

        if (k.bitLength() > size)
        {
            /*
             * TODO The com.fitburb works best when the scalars are less than the (possibly unknown) order.
             * Still, if we want to handle larger scalars, we could allow customization of the com.fitburb
             * size, or alternatively we could com.fitbural with the 'extra' bits either by running the com.fitburb
             * multiple times as necessary, or by using an alternative multiplier as prelude.
             */
            throw new IllegalStateException("fixed-point com.fitburb doesn't support scalars larger than the curve order");
        }

        int minWidth = getWidthForCombSize(size);

        FixedPointPreCompInfo info = FixedPointUtil.precompute(p, minWidth);
        ECPoint[] lookupTable = info.getPreComp();
        int width = info.getWidth();

        int d = (size + width - 1) / width;

        ECPoint R = c.getInfinity();

        int top = d * width - 1; 
        for (int i = 0; i < d; ++i)
        {
            int index = 0;

            for (int j = top - i; j >= 0; j -= d)
            {
                index <<= 1;
                if (k.testBit(j))
                {
                    index |= 1;
                }
            }

            R = R.twicePlus(lookupTable[index]);
        }

        return R;
    }

    protected int getWidthForCombSize(int com.fitburbSize)
    {
        return com.fitburbSize > 257 ? 6 : 5;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy