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
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ internal enum EvpAlgorithmFamilyId
DSA = 2,
ECC = 3,
MLKem = 4,
SlhDsa = 5,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private SlhDsaAlgorithm(string name, int n, int signatureSizeInBytes, string oid
/// </value>
public static SlhDsaAlgorithm SlhDsaShake256f { get; } = new SlhDsaAlgorithm("SLH-DSA-SHAKE-256f", 32, 49856, Oids.SlhDsaShake256f);

internal static SlhDsaAlgorithm? GetAlgorithmFromOid(string oid)
internal static SlhDsaAlgorithm? GetAlgorithmFromOid(string? oid)
{
return oid switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed partial class SlhDsaImplementation : SlhDsa
private SlhDsaImplementation(SlhDsaAlgorithm algorithm) : base(algorithm) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa GenerateKeyCore(SlhDsaAlgorithm algorithm) =>
internal static partial SlhDsaImplementation GenerateKeyCore(SlhDsaAlgorithm algorithm) =>
throw new PlatformNotSupportedException();

// The instance override methods are unreachable, as the constructor will always throw.
Expand All @@ -32,13 +32,13 @@ protected override void ExportSlhDsaSecretKeyCore(Span<byte> destination) =>
protected override bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out int bytesWritten) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed partial class SlhDsaImplementation : SlhDsa
private SlhDsaImplementation(/* CngKey key, */ SlhDsaAlgorithm algorithm) : base(algorithm) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa GenerateKeyCore(SlhDsaAlgorithm algorithm) =>
internal static partial SlhDsaImplementation GenerateKeyCore(SlhDsaAlgorithm algorithm) =>
throw new PlatformNotSupportedException();

protected override void SignDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, Span<byte> destination) =>
Expand All @@ -32,13 +32,13 @@ protected override void ExportSlhDsaSecretKeyCore(Span<byte> destination) =>
protected override bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out int bytesWritten) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();

internal static partial SlhDsa ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
internal static partial SlhDsaImplementation ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source) =>
throw new PlatformNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ internal sealed partial class SlhDsaImplementation : SlhDsa
{
internal static partial bool SupportsAny();

internal static partial SlhDsa GenerateKeyCore(SlhDsaAlgorithm algorithm);
internal static partial SlhDsa ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);
internal static partial SlhDsa ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);
internal static partial SlhDsa ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);
internal static partial SlhDsaImplementation GenerateKeyCore(SlhDsaAlgorithm algorithm);
internal static partial SlhDsaImplementation ImportPublicKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);
internal static partial SlhDsaImplementation ImportPkcs8PrivateKeyValue(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);
internal static partial SlhDsaImplementation ImportSecretKey(SlhDsaAlgorithm algorithm, ReadOnlySpan<byte> source);

/// <summary>
/// Duplicates an SLH-DSA private key by export/import.
/// Only intended to be used when the key type is unknown.
/// </summary>
internal static SlhDsaImplementation DuplicatePrivateKey(SlhDsa key)
{
Debug.Assert(key is not SlhDsaImplementation);
Debug.Assert(key.Algorithm.SecretKeySizeInBytes <= 128);

Span<byte> secretKey = (stackalloc byte[128])[..key.Algorithm.SecretKeySizeInBytes];
key.ExportSlhDsaSecretKey(secretKey);
try
{
return ImportSecretKey(key.Algorithm, secretKey);
}
finally
{
CryptographicOperations.ZeroMemory(secretKey);
}
}
}
}
Loading
Loading