Skip to content
Open
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
4 changes: 1 addition & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<PackageVersion Include="coverlet.msbuild" Version="10.1.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.5" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.317" />
<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.15" />
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="11.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.15" />
<PackageVersion Include="MSTest" Version="4.5.2" />
Expand All @@ -20,7 +19,6 @@
<PackageVersion Include="PolySharp" Version="1.16.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.35.0.4138" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="System.Formats.Asn1" Version="10.0.15" />
<PackageVersion Include="Testcontainers" Version="4.16.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET
#if NET && !NET11_0_OR_GREATER

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be #if NET10_0 after #1837 (same in other places). Can we call it KeyExchangeECCurve25519.net10.cs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update once #1837 is merged.

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