Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NafL2RMultiplier.java « ec « math « bouncycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91d91d1175cc6267f3853deec798b243e021f468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.bouncycastle.math.ec;

import java.math.BigInteger;

/**
 * Class implementing the NAF (Non-Adjacent Form) multiplication algorithm (left-to-right).
 */
public class NafL2RMultiplier extends AbstractECMultiplier
{
    protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
    {
        int[] naf = WNafUtil.generateCompactNaf(k);

        ECPoint addP = p.normalize(), subP = addP.negate();

        ECPoint R = p.getCurve().getInfinity();

        int i = naf.length;
        while (--i >= 0)
        {
            int ni = naf[i];
            int digit = ni >> 16, zeroes = ni & 0xFFFF;

            R = R.twicePlus(digit < 0 ? subP : addP);
            R = R.timesPow2(zeroes);
        }

        return R;
    }
}