< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Multiplier.FixedPointUtilities
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\math\ec\multiplier\FixedPointUtilities.cs
Line coverage
94%
Covered lines: 53
Uncovered lines: 3
Coverable lines: 56
Total lines: 95
Line coverage: 94.6%
Branch coverage
83%
Covered branches: 15
Total branches: 18
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%1100%
GetCombSize(...)50%2100%
GetFixedPointPreCompInfo(...)100%10%
Precompute(...)100%1100%
.ctor(...)100%1100%
Precompute(...)91.66%12100%
CheckExisting(...)100%2100%
CheckTable(...)50%2100%

File(s)

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

#LineLine coverage
 1using System;
 2
 3namespace Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Multiplier
 4{
 5    internal class FixedPointUtilities
 6    {
 17        public static readonly string PRECOMP_NAME = "bc_fixed_point";
 8
 9        public static int GetCombSize(ECCurve c)
 1810        {
 1811            BigInteger order = c.Order;
 1812            return order == null ? c.FieldSize + 1 : order.BitLength;
 1813        }
 14
 15        public static FixedPointPreCompInfo GetFixedPointPreCompInfo(PreCompInfo preCompInfo)
 016        {
 017            return preCompInfo as FixedPointPreCompInfo;
 018        }
 19
 20        public static FixedPointPreCompInfo Precompute(ECPoint p)
 921        {
 922            return (FixedPointPreCompInfo)p.Curve.Precompute(p, PRECOMP_NAME, new FixedPointCallback(p));
 923        }
 24
 25        private class FixedPointCallback
 26            : IPreCompCallback
 27        {
 28            private readonly ECPoint m_p;
 29
 930            internal FixedPointCallback(ECPoint p)
 931            {
 932                this.m_p = p;
 933            }
 34
 35            public PreCompInfo Precompute(PreCompInfo existing)
 936            {
 937                FixedPointPreCompInfo existingFP = (existing is FixedPointPreCompInfo) ? (FixedPointPreCompInfo)existing
 38
 939                ECCurve c = m_p.Curve;
 940                int bits = FixedPointUtilities.GetCombSize(c);
 941                int minWidth = bits > 250 ? 6 : 5;
 942                int n = 1 << minWidth;
 43
 944                if (CheckExisting(existingFP, n))
 645                    return existingFP;
 46
 347                int d = (bits + minWidth - 1) / minWidth;
 48
 349                ECPoint[] pow2Table = new ECPoint[minWidth + 1];
 350                pow2Table[0] = m_p;
 3651                for (int i = 1; i < minWidth; ++i)
 1552                {
 1553                    pow2Table[i] = pow2Table[i - 1].TimesPow2(d);
 1554                }
 55
 56                // This will be the 'offset' value
 357                pow2Table[minWidth] = pow2Table[0].Subtract(pow2Table[1]);
 58
 359                c.NormalizeAll(pow2Table);
 60
 361                ECPoint[] lookupTable = new ECPoint[n];
 362                lookupTable[0] = pow2Table[0];
 63
 4264                for (int bit = minWidth - 1; bit >= 0; --bit)
 1865                {
 1866                    ECPoint pow2 = pow2Table[bit];
 67
 1868                    int step = 1 << bit;
 41469                    for (int i = step; i < n; i += (step << 1))
 18970                    {
 18971                        lookupTable[i] = lookupTable[i - step].Add(pow2);
 18972                    }
 1873                }
 74
 375                c.NormalizeAll(lookupTable);
 76
 377                FixedPointPreCompInfo result = new FixedPointPreCompInfo();
 378                result.LookupTable = c.CreateCacheSafeLookupTable(lookupTable, 0, lookupTable.Length);
 379                result.Offset = pow2Table[minWidth];
 380                result.Width = minWidth;
 381                return result;
 982            }
 83
 84            private bool CheckExisting(FixedPointPreCompInfo existingFP, int n)
 985            {
 986                return existingFP != null && CheckTable(existingFP.LookupTable, n);
 987            }
 88
 89            private bool CheckTable(ECLookupTable table, int n)
 690            {
 691                return table != null && table.Size >= n;
 692            }
 93        }
 94    }
 95}