< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Multiplier.FixedPointCombMultiplier
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\math\ec\multiplier\FixedPointCombMultiplier.cs
Line coverage
93%
Covered lines: 27
Uncovered lines: 2
Coverable lines: 29
Total lines: 58
Line coverage: 93.1%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
MultiplyPositive(...)83.33%693.1%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\math\ec\multiplier\FixedPointCombMultiplier.cs

#LineLine coverage
 1using System;
 2
 3using Renci.SshNet.Security.Org.BouncyCastle.Math.Raw;
 4
 5namespace Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Multiplier
 6{
 7    internal class FixedPointCombMultiplier
 8        : AbstractECMultiplier
 9    {
 10        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
 911        {
 912            ECCurve c = p.Curve;
 913            int size = FixedPointUtilities.GetCombSize(c);
 14
 915            if (k.BitLength > size)
 016            {
 17                /*
 18                 * TODO The comb works best when the scalars are less than the (possibly unknown) order.
 19                 * Still, if we want to handle larger scalars, we could allow customization of the comb
 20                 * size, or alternatively we could deal with the 'extra' bits either by running the comb
 21                 * multiple times as necessary, or by using an alternative multiplier as prelude.
 22                 */
 023                throw new InvalidOperationException("fixed-point comb doesn't support scalars larger than the curve orde
 24            }
 25
 926            FixedPointPreCompInfo info = FixedPointUtilities.Precompute(p);
 927            ECLookupTable lookupTable = info.LookupTable;
 928            int width = info.Width;
 29
 930            int d = (size + width - 1) / width;
 31
 932            ECPoint R = c.Infinity;
 33
 934            int fullComb = d * width;
 935            uint[] K = Nat.FromBigInteger(fullComb, k);
 36
 937            int top = fullComb - 1;
 118238            for (int i = 0; i < d; ++i)
 58239            {
 58240                uint secretIndex = 0;
 41
 814842                for (int j = top - i; j >= 0; j -= d)
 349243                {
 349244                    uint secretBit = K[j >> 5] >> (j & 0x1F);
 349245                    secretIndex ^= secretBit >> 1;
 349246                    secretIndex <<= 1;
 349247                    secretIndex ^= secretBit;
 349248                }
 49
 58250                ECPoint add = lookupTable.Lookup((int)secretIndex);
 51
 58252                R = R.TwicePlus(add);
 58253            }
 54
 955            return R.Add(info.Offset);
 956        }
 57    }
 58}