< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Crypto.Agreement.ECDHCBasicAgreement
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\agreement\ECDHCBasicAgreement.cs
Line coverage
70%
Covered lines: 14
Uncovered lines: 6
Coverable lines: 20
Total lines: 46
Line coverage: 70%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Init(...)100%1100%
GetFieldSize()100%10%
CalculateAgreement(...)50%678.57%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\crypto\agreement\ECDHCBasicAgreement.cs

#LineLine coverage
 1using System;
 2
 3using Renci.SshNet.Security.Org.BouncyCastle.Math;
 4using Renci.SshNet.Security.Org.BouncyCastle.Math.EC;
 5using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters;
 6
 7namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Agreement
 8{
 9    internal class ECDHCBasicAgreement
 10    {
 11        private ECPrivateKeyParameters privKey;
 12
 13        public virtual void Init(
 14            AsymmetricKeyParameter parameters)
 915        {
 916            this.privKey = (ECPrivateKeyParameters)parameters;
 917        }
 18
 19        public virtual int GetFieldSize()
 020        {
 021            return (privKey.Parameters.Curve.FieldSize + 7) / 8;
 022        }
 23
 24        public virtual BigInteger CalculateAgreement(
 25            ECPublicKeyParameters pubKey)
 926        {
 927            ECPublicKeyParameters pub = pubKey;
 928            ECDomainParameters dp = privKey.Parameters;
 929            if (!dp.Equals(pub.Parameters))
 030                throw new InvalidOperationException("ECDHC public key has wrong domain parameters");
 31
 932            BigInteger hd = dp.H.Multiply(privKey.D).Mod(dp.N);
 33
 34            // Always perform calculations on the exact curve specified by our private key's parameters
 935            ECPoint pubPoint = ECAlgorithms.CleanPoint(dp.Curve, pub.Q);
 936            if (pubPoint.IsInfinity)
 037                throw new InvalidOperationException("Infinity is not a valid public key for ECDHC");
 38
 939            ECPoint P = pubPoint.Multiply(hd).Normalize();
 940            if (P.IsInfinity)
 041                throw new InvalidOperationException("Infinity is not a valid agreement value for ECDHC");
 42
 943            return P.AffineXCoord.ToBigInteger();
 944        }
 45    }
 46}