summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs
blob: 46d234c37ecba85ca166d0d7c5feefc1710297bc (plain) (blame)
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
31
32
33
using System;

namespace Org.BouncyCastle.Math.EC.Multiplier
{
    [Obsolete("Will be removed")]
    public class ZSignedDigitR2LMultiplier 
        : AbstractECMultiplier
    {
        /**
         * 'Zeroless' Signed Digit Right-to-Left.
         */
        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
        {
            ECPoint R0 = p.Curve.Infinity, R1 = p;

            int n = k.BitLength;
            int s = k.GetLowestSetBit();

            R1 = R1.TimesPow2(s);

            int i = s;
            while (++i < n)
            {
                R0 = R0.Add(k.TestBit(i) ? R1 : R1.Negate());
                R1 = R1.Twice();
            }

            R0 = R0.Add(R1);

            return R0;
        }
    }
}