Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.5" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.125" />
<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.10" />
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="11.0.0-preview.7.26381.103" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.10" />
<PackageVersion Include="MSTest" Version="4.3.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET
#if NET && !NET11_0_OR_GREATER
using System.Security.Cryptography;

namespace Renci.SshNet.Security
Expand Down
41 changes: 41 additions & 0 deletions src/Renci.SshNet/Security/KeyExchangeECCurve25519.BclImpl2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#if NETFRAMEWORK || NET11_0_OR_GREATER
using System.Security.Cryptography;

namespace Renci.SshNet.Security
{
internal partial class KeyExchangeECCurve25519
{
protected sealed class BclImpl : Impl
{
private readonly X25519DiffieHellman _clientX25519DH;

public BclImpl()
{
_clientX25519DH = X25519DiffieHellman.GenerateKey();
}

public override byte[] GenerateClientPublicKey()
{
return _clientX25519DH.ExportPublicKey();
}

public override byte[] CalculateAgreement(byte[] serverPublicKey)
{
using var serverX25519DH = X25519DiffieHellman.ImportPublicKey(serverPublicKey);

return _clientX25519DH.DeriveRawSecretAgreement(serverX25519DH.ExportPublicKey());
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
_clientX25519DH.Dispose();
}
}
}
}
}
#endif
14 changes: 10 additions & 4 deletions src/Renci.SshNet/Security/KeyExchangeECCurve25519.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace Renci.SshNet.Security
internal partial class KeyExchangeECCurve25519 : KeyExchangeEC
{
#pragma warning disable SA1401 // Fields should be private
#if NET
protected Impl _impl;
#else
#if NETSTANDARD
protected BouncyCastleImpl _impl;
#else
protected Impl _impl;
#endif
#pragma warning restore SA1401 // Fields should be private

Expand All @@ -38,12 +38,18 @@ protected override int HashSize
public override void Start(Session session, KeyExchangeInitMessage message, bool sendClientInitMessage)
{
base.Start(session, message, sendClientInitMessage);
#if NET
#if NET && !NET11_0_OR_GREATER
if (System.OperatingSystem.IsWindowsVersionAtLeast(10))
{
_impl = new BclImpl();
}
else
#elif NETFRAMEWORK || NET11_0_OR_GREATER
if (X25519DiffieHellman.IsSupported)
{
_impl = new BclImpl();
}
else
#endif
{
_impl = new BouncyCastleImpl();
Expand Down
Loading