# < 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

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
Init(...) | 100% | 1 | 100%
GetFieldSize() | 100% | 1 | 0%
CalculateAgreement(...) | 50% | 6 | 78.57%

# File(s)

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | ``
|  | `3` |  | `using Renci.SshNet.Security.Org.BouncyCastle.Math;`
|  | `4` |  | `using Renci.SshNet.Security.Org.BouncyCastle.Math.EC;`
|  | `5` |  | `using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters;`
|  | `6` |  | ``
|  | `7` |  | `namespace 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)`
| 9 | `15` |  | `{`
| 9 | `16` |  | `this.privKey = (ECPrivateKeyParameters)parameters;`
| 9 | `17` |  | `}`
|  | `18` |  | ``
|  | `19` |  | `public virtual int GetFieldSize()`
| 0 | `20` |  | `{`
| 0 | `21` |  | `return (privKey.Parameters.Curve.FieldSize + 7) / 8;`
| 0 | `22` |  | `}`
|  | `23` |  | ``
|  | `24` |  | `public virtual BigInteger CalculateAgreement(`
|  | `25` |  | `ECPublicKeyParameters pubKey)`
| 9 | `26` |  | `{`
| 9 | `27` |  | `ECPublicKeyParameters pub = pubKey;`
| 9 | `28` |  | `ECDomainParameters dp = privKey.Parameters;`
| 9 | `29` |  | `if (!dp.Equals(pub.Parameters))`
| 0 | `30` |  | `throw new InvalidOperationException("ECDHC public key has wrong domain parameters");`
|  | `31` |  | ``
| 9 | `32` |  | `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`
| 9 | `35` |  | `ECPoint pubPoint = ECAlgorithms.CleanPoint(dp.Curve, pub.Q);`
| 9 | `36` |  | `if (pubPoint.IsInfinity)`
| 0 | `37` |  | `throw new InvalidOperationException("Infinity is not a valid public key for ECDHC");`
|  | `38` |  | ``
| 9 | `39` |  | `ECPoint P = pubPoint.Multiply(hd).Normalize();`
| 9 | `40` |  | `if (P.IsInfinity)`
| 0 | `41` |  | `throw new InvalidOperationException("Infinity is not a valid agreement value for ECDHC");`
|  | `42` |  | ``
| 9 | `43` |  | `return P.AffineXCoord.ToBigInteger();`
| 9 | `44` |  | `}`
|  | `45` |  | `}`
|  | `46` |  | `}`

# Methods/Properties

Init(Renci.SshNet.Security.Org.BouncyCastle.Crypto.AsymmetricKeyParameter)
GetFieldSize()
CalculateAgreement(Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters)