aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/java/org/spongycastle/math/ec/ZSignedDigitL2RMultiplier.java
blob: 543bb581feea016fa6d9d220394f80120fa70d5b (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
package org.spongycastle.math.ec;

import java.math.BigInteger;

public class ZSignedDigitL2RMultiplier extends AbstractECMultiplier
{
    /**
     * 'Zeroless' Signed Digit Left-to-Right.
     */
    protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
    {
        ECPoint addP = p.normalize(), subP = addP.negate();

        ECPoint R0 = addP;

        int n = k.bitLength();
        int s = k.getLowestSetBit();

        int i = n;
        while (--i > s)
        {
            R0 = R0.twicePlus(k.testBit(i) ? addP : subP);
        }

        R0 = R0.timesPow2(s);

        return R0;
    }
}