diff --git a/src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs b/src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs index 0bdcf5b9858800..b2c60a09dffb67 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs @@ -216,7 +216,7 @@ protected override bool TryExportPkcs8PrivateKeyCore(Span destination, out } bytesWritten = pkcs8.Count; - pkcs8.Array.CopyTo(destination); + pkcs8.AsSpan().CopyTo(destination); return true; } finally diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/MLDsa/MLDsaTestsBase.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/MLDsa/MLDsaTestsBase.cs index 6f4ed26dc51914..67ae9aedce1173 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/MLDsa/MLDsaTestsBase.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/MLDsa/MLDsaTestsBase.cs @@ -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)); @@ -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(() => mldsa.SignPreHash(hash, hashInfo.Oid)); Assert.Contains(algorithm.Name, ce.Message); diff --git a/src/libraries/Common/tests/System/Security/Cryptography/HashInfo.cs b/src/libraries/Common/tests/System/Security/Cryptography/HashInfo.cs index 60fa07254d5554..c43a9b2869cd97 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/HashInfo.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/HashInfo.cs @@ -101,6 +101,8 @@ public static IEnumerable AllHashInfos() #endif } + internal static HashSet KnownHashAlgorithmOids => field ??= AllHashInfos().Select(h => h.Oid).ToHashSet(); + private HashInfo(string oid, int outputSize, HashAlgorithmName name) { Oid = oid;