Skip to content

Commit

Permalink
Add support for .NET 8
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0xced committed Nov 22, 2024
1 parent ea96bf9 commit e29eb48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Extensions/CngKeyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Security.Cryptography;
using System.Linq;

namespace SecurityDriven.Inferno.Extensions
{
#if NET5_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class CngKeyExtensions
{
static readonly CngKeyCreationParameters cngKeyCreationParameters = new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport };
Expand Down Expand Up @@ -46,13 +48,11 @@ public static CngKey ToPublicKeyFromBlob(this byte[] publicBlob)
/// </summary>
public static byte[] GetSharedDhmSecret(this CngKey privateDhmKey, CngKey publicDhmKey, byte[] contextAppend = null, byte[] contextPrepend = null)
{
#if (NET462 || NETCOREAPP3_1)
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
return ecdh.DeriveKeyMaterial(publicDhmKey);
#elif NETSTANDARD2_0
#if NETSTANDARD2_0
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.");
#else
#error Unknown target
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
return ecdh.DeriveKeyMaterial(publicDhmKey);
#endif
}// GetSharedDhmSecret()

Expand Down
11 changes: 7 additions & 4 deletions SecurityDriven.Inferno.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>SecurityDriven.Inferno</RootNamespace>
Expand Down Expand Up @@ -41,11 +41,14 @@
<Compile Remove="Mac\HMAC3.cs" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'net462'">
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" Condition="'$(TargetFramework)' != 'net462'" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'netcoreapp3.1'">
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
</ItemGroup>

</Project>

0 comments on commit e29eb48

Please sign in to comment.