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 @@ -216,7 +216,7 @@ protected override bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out
}

bytesWritten = pkcs8.Count;
pkcs8.Array.CopyTo(destination);
pkcs8.AsSpan().CopyTo(destination);
return true;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public void NistImportPublicKeyVerify(MLDsaNistTestCase testCase)
[MemberData(nameof(MLDsaTestsData.AllPreHashMLDsaNistTestCases), MemberType = typeof(MLDsaTestsData))]
public void NistImportPublicKeyVerifyPreHash(MLDsaNistTestCase testCase)
{
if (!HashInfo.KnownHashAlgorithmOids.Contains(testCase.HashAlgOid))
{
// This test case is not supported by the current platform.
return;
}

byte[] hash = HashInfo.HashData(testCase.HashAlgOid, testCase.Message);
using MLDsa mldsa = ImportPublicKey(testCase.Algorithm, testCase.PublicKey);
Assert.Equal(testCase.ShouldPass, mldsa.VerifyPreHash(hash, testCase.Signature, testCase.HashAlgOid, testCase.Context));
Expand Down Expand Up @@ -317,7 +323,7 @@ public void SignData_PublicKeyOnlyThrows(MLDsaKeyInfo info)
public void SignPreHash_ThrowsForUnsupportedAlgorithmCombinations(MLDsaAlgorithm algorithm, HashInfo hashInfo)
{
using MLDsa mldsa = GenerateKey(algorithm);
byte[] hash = hashInfo.GetHash([1, 2, 3, 4]);
byte[] hash = new byte[hashInfo.OutputSize];

CryptographicException ce = Assert.Throws<CryptographicException>(() => mldsa.SignPreHash(hash, hashInfo.Oid));
Assert.Contains(algorithm.Name, ce.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public static IEnumerable<HashInfo> AllHashInfos()
#endif
}

internal static HashSet<string> KnownHashAlgorithmOids => field ??= AllHashInfos().Select(h => h.Oid).ToHashSet();

private HashInfo(string oid, int outputSize, HashAlgorithmName name)
{
Oid = oid;
Expand Down
Loading