Skip to content

Commit 05ff689

Browse files
committed
Create dedicated KeyExchangeECCurve25519 BclImpl
1 parent 8abad81 commit 05ff689

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#if NET
2+
using System.Security.Cryptography;
3+
4+
namespace Renci.SshNet.Security
5+
{
6+
internal abstract partial class KeyExchangeECCurve25519
7+
{
8+
protected sealed class BclImpl : Impl
9+
{
10+
private readonly ECCurve _curve;
11+
private readonly ECDiffieHellman _clientECDH;
12+
13+
public BclImpl(ECCurve curve)
14+
{
15+
_curve = curve;
16+
_clientECDH = ECDiffieHellman.Create();
17+
}
18+
19+
public override byte[] GenerateClientECPoint()
20+
{
21+
_clientECDH.GenerateKey(_curve);
22+
23+
var q = _clientECDH.PublicKey.ExportParameters().Q;
24+
25+
return q.X;
26+
}
27+
28+
public override byte[] CalculateAgreement(byte[] serverECPoint)
29+
{
30+
var parameters = new ECParameters
31+
{
32+
Curve = _curve,
33+
Q = new ECPoint
34+
{
35+
X = serverECPoint,
36+
Y = new byte[serverECPoint.Length]
37+
},
38+
};
39+
40+
using var serverECDH = ECDiffieHellman.Create(parameters);
41+
42+
return _clientECDH.DeriveRawSecretAgreement(serverECDH.PublicKey);
43+
}
44+
45+
protected override void Dispose(bool disposing)
46+
{
47+
base.Dispose(disposing);
48+
49+
if (disposing)
50+
{
51+
_clientECDH.Dispose();
52+
}
53+
}
54+
}
55+
}
56+
}
57+
#endif

src/Renci.SshNet/Security/KeyExchangeEC.BclImpl.cs renamed to src/Renci.SshNet/Security/KeyExchangeECDH.BclImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Renci.SshNet.Security
66
{
7-
internal abstract partial class KeyExchangeEC
7+
internal abstract partial class KeyExchangeECDH
88
{
99
protected sealed class BclImpl : Impl
1010
{

0 commit comments

Comments
 (0)