forked from sshnet/SSH.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyExchangeECCurve25519.BouncyCastleImpl.cs
More file actions
38 lines (30 loc) · 1.19 KB
/
KeyExchangeECCurve25519.BouncyCastleImpl.cs
File metadata and controls
38 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Org.BouncyCastle.Crypto.Agreement;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Renci.SshNet.Abstractions;
namespace Renci.SshNet.Security
{
internal partial class KeyExchangeECCurve25519
{
protected sealed class BouncyCastleImpl : Impl
{
private X25519Agreement _keyAgreement;
public override byte[] GenerateClientPublicKey()
{
var g = new X25519KeyPairGenerator();
g.Init(new X25519KeyGenerationParameters(CryptoAbstraction.SecureRandom));
var aKeyPair = g.GenerateKeyPair();
_keyAgreement = new X25519Agreement();
_keyAgreement.Init(aKeyPair.Private);
return ((X25519PublicKeyParameters)aKeyPair.Public).GetEncoded();
}
public override byte[] CalculateAgreement(byte[] serverPublicKey)
{
var publicKey = new X25519PublicKeyParameters(serverPublicKey);
var k1 = new byte[_keyAgreement.AgreementSize];
_keyAgreement.CalculateAgreement(publicKey, k1, 0);
return k1;
}
}
}
}