Skip to content
Merged
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
92 changes: 92 additions & 0 deletions src/libraries/Common/src/System/Security/Cryptography/SlhDsaCng.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;

namespace System.Security.Cryptography
{
/// <summary>
/// Provides a Cryptography Next Generation (CNG) implementation of the Stateless Hash-Based Digital Signature
/// Algorithm (SLH-DSA).
/// </summary>
/// <remarks>
/// <para>
/// This algorithm is specified by FIPS-205.
/// </para>
/// <para>
/// Developers are encouraged to program against the <see cref="SlhDsa" /> base class,
/// rather than any specific derived class.
/// The derived classes are intended for interop with the underlying system
/// cryptographic libraries.
/// </para>
/// </remarks>
[Experimental(Experimentals.PostQuantumCryptographyDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
public sealed partial class SlhDsaCng : SlhDsa
{
/// <summary>
/// Initializes a new instance of the <see cref="SlhDsaCng"/> class by using the specified <see cref="CngKey"/>.
/// </summary>
/// <param name="key">
/// The key that will be used as input to the cryptographic operations performed by the current object.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="key"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="key"/> does not specify a Stateless Hash-Based Digital Signature Algorithm (SLH-DSA) group.
/// </exception>
/// <exception cref="PlatformNotSupportedException">
/// Cryptography Next Generation (CNG) classes are not supported on this system.
/// </exception>
[SupportedOSPlatform("windows")]
public SlhDsaCng(CngKey key) : base(SlhDsaAlgorithm.SlhDsaShake256f) // We need to pass something to the base so we can throw PNSE.
{
ArgumentNullException.ThrowIfNull(key);
throw new PlatformNotSupportedException();
}

/// <summary>
/// Gets a new <see cref="CngKey" /> representing the key used by the current instance.
/// </summary>
/// <exception cref="ObjectDisposedException">
/// This instance has been disposed.
/// </exception>
/// <remarks>
/// This <see cref="CngKey"/> object is not the same as the one passed to <see cref="SlhDsaCng(CngKey)"/>,
/// if that constructor was used. However, it will point to the same CNG key.
/// </remarks>
public CngKey GetKey()
{
throw new PlatformNotSupportedException();
}

/// <inheritdoc />
protected override void SignDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, Span<byte> destination) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override bool VerifyDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, ReadOnlySpan<byte> signature) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override void SignPreHashCore(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> context, string hashAlgorithmOid, Span<byte> destination) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override bool VerifyPreHashCore(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> context, string hashAlgorithmOid, ReadOnlySpan<byte> signature) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override void ExportSlhDsaPublicKeyCore(Span<byte> destination) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override void ExportSlhDsaSecretKeyCore(Span<byte> destination) =>
throw new PlatformNotSupportedException();

/// <inheritdoc />
protected override bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out int bytesWritten) =>
throw new PlatformNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.MLKemCng))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.SlhDsa))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.SlhDsaAlgorithm))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.SlhDsaCng))]
#endif
#if NET || NETSTANDARD2_1_OR_GREATER
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.PbeEncryptionAlgorithm))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
<Compile Include="$(CommonPath)Interop\Windows\BCrypt\Interop.BCryptGenerateKeyPair.cs"
Link="Common\Interop\Windows\BCrypt\Interop.BCryptGenerateKeyPair.cs" />
<Compile Include="$(CommonPath)Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs"
Link="Common\Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs" />
Link="Common\Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\BCrypt\Interop.BCryptImportKeyPair.cs"
Link="Common\Interop\Windows\BCrypt\Interop.BCryptImportKeyPair.cs" />
<Compile Include="$(CommonPath)Interop\Windows\BCrypt\Interop.BCryptPropertyStrings.cs"
Expand Down Expand Up @@ -464,6 +464,8 @@
Link="Common\System\Security\Cryptography\MLKemCng.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\MLKemCng.Windows.cs"
Link="Common\System\Security\Cryptography\MLKemCng.Windows.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\SlhDsaCng.cs"
Link="Common\System\Security\Cryptography\SlhDsaCng.cs" />
<Compile Include="$(CommonPath)Interop\Windows\NCrypt\Interop.AsymmetricPaddingMode.cs"
Link="Common\Interop\Windows\NCrypt\Interop.AsymmetricPaddingMode.cs" />
<Compile Include="$(CommonPath)Interop\Windows\NCrypt\Interop.ErrorCode.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ public CngAlgorithm(string algorithm) { }
public static System.Security.Cryptography.CngAlgorithm Sha256 { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithm Sha384 { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithm Sha512 { get { throw null; } }
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.CngAlgorithm SlhDsa { get { throw null; } }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.CngAlgorithm? other) { throw null; }
public override int GetHashCode() { throw null; }
Expand All @@ -362,6 +364,8 @@ public CngAlgorithmGroup(string algorithmGroup) { }
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.CngAlgorithmGroup MLKem { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithmGroup Rsa { get { throw null; } }
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Security.Cryptography.CngAlgorithmGroup SlhDsa { get { throw null; } }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.CngAlgorithmGroup? other) { throw null; }
public override int GetHashCode() { throw null; }
Expand Down Expand Up @@ -3110,6 +3114,20 @@ internal SlhDsaAlgorithm() { }
public override string ToString() { throw null; }
}
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed partial class SlhDsaCng : System.Security.Cryptography.SlhDsa
{
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public SlhDsaCng(System.Security.Cryptography.CngKey key) : base (default(System.Security.Cryptography.SlhDsaAlgorithm)) { }
protected override void ExportSlhDsaPublicKeyCore(System.Span<byte> destination) { }
protected override void ExportSlhDsaSecretKeyCore(System.Span<byte> destination) { }
public System.Security.Cryptography.CngKey GetKey() { throw null; }
protected override void SignDataCore(System.ReadOnlySpan<byte> data, System.ReadOnlySpan<byte> context, System.Span<byte> destination) { }
protected override void SignPreHashCore(System.ReadOnlySpan<byte> hash, System.ReadOnlySpan<byte> context, string hashAlgorithmOid, System.Span<byte> destination) { }
protected override bool TryExportPkcs8PrivateKeyCore(System.Span<byte> destination, out int bytesWritten) { throw null; }
protected override bool VerifyDataCore(System.ReadOnlySpan<byte> data, System.ReadOnlySpan<byte> context, System.ReadOnlySpan<byte> signature) { throw null; }
protected override bool VerifyPreHashCore(System.ReadOnlySpan<byte> hash, System.ReadOnlySpan<byte> context, string hashAlgorithmOid, System.ReadOnlySpan<byte> signature) { throw null; }
}
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed partial class SlhDsaOpenSsl : System.Security.Cryptography.SlhDsa
{
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@
Link="Common\System\Security\Cryptography\SlhDsa.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\SlhDsaAlgorithm.cs"
Link="Common\System\Security\Cryptography\SlhDsaAlgorithm.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\SlhDsaCng.cs"
Link="Common\System\Security\Cryptography\SlhDsaCng.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\SlhDsaImplementation.cs"
Link="Common\System\Security\Cryptography\SlhDsaImplementation.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\SP800108HmacCounterKdf.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ public static CngAlgorithm Sha512
[Experimental(Experimentals.PostQuantumCryptographyDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
public static CngAlgorithm MLKem => field ??= new CngAlgorithm("ML-KEM"); // BCRYPT_MLKEM_ALGORITHM

/// <summary>
/// Gets a new <see cref="CngAlgorithm"/> object that specifies the Stateless Hash-Based Digital Signature
/// Algorithm (SLH-DSA).
/// </summary>
/// <value>
/// A new <see cref="CngAlgorithm"/> object that specifies the Stateless Hash-Based Digital Signature
/// Algorithm (SLH-DSA).
/// </value>
[Experimental(Experimentals.PostQuantumCryptographyDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
public static CngAlgorithm SlhDsa => field ??= new CngAlgorithm("SLH-DSA"); // BCRYPT_SLHDSA_ALGORITHM

private static CngAlgorithm? s_ecdh;
private static CngAlgorithm? s_ecdhp256;
private static CngAlgorithm? s_ecdhp384;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ public static CngAlgorithmGroup Rsa
public static CngAlgorithmGroup MLKem =>
field ??= new CngAlgorithmGroup("MLKEM"); // NCRYPT_MLKEM_ALGORITHM_GROUP

/// <summary>
/// Gets a <see cref="CngAlgorithmGroup" /> object that specifies the Stateless Hash-Based Digital Signature
/// Algorithm (SLH-DSA) family of algorithms.
/// </summary>
/// <value>
/// An object that specifies the SLH-DSA family of algorithms.
/// </value>
[Experimental(Experimentals.PostQuantumCryptographyDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
public static CngAlgorithmGroup SlhDsa =>
field ??= new CngAlgorithmGroup("SLHDSA"); // NCRYPT_SLHDSA_ALGORITHM_GROUP

private static CngAlgorithmGroup? s_dh;
private static CngAlgorithmGroup? s_dsa;
private static CngAlgorithmGroup? s_ecdh;
Expand Down
Loading