Skip to content

Commit c41409f

Browse files
committed
Add support for .NET 8
This allows to use Inferno completely dependency free since System.Numerics.Vectors, System.Runtime.CompilerServices.Unsafe, System.ValueTuple and System.Security.Cryptography.Cng are only required for specific target frameworks. This pull request supersedes sdrapkin#40
1 parent ea96bf9 commit c41409f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

Extensions/CngKeyExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Security.Cryptography;
3-
using System.Linq;
43

54
namespace SecurityDriven.Inferno.Extensions
65
{
6+
#if NET5_0_OR_GREATER
7+
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
8+
#endif
79
public static class CngKeyExtensions
810
{
911
static readonly CngKeyCreationParameters cngKeyCreationParameters = new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport };
@@ -46,13 +48,11 @@ public static CngKey ToPublicKeyFromBlob(this byte[] publicBlob)
4648
/// </summary>
4749
public static byte[] GetSharedDhmSecret(this CngKey privateDhmKey, CngKey publicDhmKey, byte[] contextAppend = null, byte[] contextPrepend = null)
4850
{
49-
#if (NET462 || NETCOREAPP3_1)
50-
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
51-
return ecdh.DeriveKeyMaterial(publicDhmKey);
52-
#elif NETSTANDARD2_0
51+
#if NETSTANDARD2_0
5352
throw new PlatformNotSupportedException($"ECDiffieHellman is not supported on .NET Standard 2.0. Please reference \"{typeof(CngKeyExtensions).Assembly.GetName().Name}\" from .NET Framework or .NET Core for ECDiffieHellman support.");
5453
#else
55-
#error Unknown target
54+
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
55+
return ecdh.DeriveKeyMaterial(publicDhmKey);
5656
#endif
5757
}// GetSharedDhmSecret()
5858

SecurityDriven.Inferno.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
55
<LangVersion>latest</LangVersion>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<RootNamespace>SecurityDriven.Inferno</RootNamespace>
@@ -41,11 +41,14 @@
4141
<Compile Remove="Mac\HMAC3.cs" />
4242
</ItemGroup>
4343

44-
<ItemGroup>
44+
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'net462'">
4545
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
4646
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
47-
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" Condition="'$(TargetFramework)' != 'net462'" />
4847
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
4948
</ItemGroup>
5049

50+
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'netcoreapp3.1'">
51+
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
52+
</ItemGroup>
53+
5154
</Project>

0 commit comments

Comments
 (0)