Skip to content

Commit 727a0bc

Browse files
committed
Changes w.r.t. ML-DSA CertificateRequest PR
1 parent 3471b20 commit 727a0bc

File tree

3 files changed

+14
-44
lines changed

3 files changed

+14
-44
lines changed

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/MLDsa/MLDsaTests.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,18 @@ private static bool PlatformSupportsMLDsa()
3838
[Fact]
3939
public static void DisposeIsCalledOnImplementation()
4040
{
41-
DisposeCallsCountingMLDsa mldsa = new DisposeCallsCountingMLDsa(MLDsaAlgorithm.MLDsa44);
41+
MLDsaTestImplementation mldsa = MLDsaTestImplementation.CreateNoOp(MLDsaAlgorithm.MLDsa44);
42+
int numberOfTimesDisposeCalled = 0;
43+
mldsa.DisposeHook = (disposing) =>
44+
{
45+
numberOfTimesDisposeCalled++;
46+
};
4247

43-
Assert.Equal(0, mldsa.NumberOfTimesDisposeCalled);
48+
Assert.Equal(0, numberOfTimesDisposeCalled);
4449
mldsa.Dispose();
45-
Assert.Equal(1, mldsa.NumberOfTimesDisposeCalled);
50+
Assert.Equal(1, numberOfTimesDisposeCalled);
4651
mldsa.Dispose();
47-
Assert.Equal(1, mldsa.NumberOfTimesDisposeCalled);
48-
}
49-
50-
private class DisposeCallsCountingMLDsa : MLDsa
51-
{
52-
public DisposeCallsCountingMLDsa(MLDsaAlgorithm algorithm) : base(algorithm)
53-
{
54-
}
55-
56-
internal int NumberOfTimesDisposeCalled { get; private set; } = 0;
57-
protected override void ExportMLDsaPrivateSeedCore(Span<byte> destination) => throw new NotImplementedException();
58-
protected override void ExportMLDsaPublicKeyCore(Span<byte> destination) => throw new NotImplementedException();
59-
protected override void ExportMLDsaSecretKeyCore(Span<byte> destination) => throw new NotImplementedException();
60-
protected override void SignDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, Span<byte> destination) => throw new NotImplementedException();
61-
protected override bool VerifyDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, ReadOnlySpan<byte> signature) => throw new NotImplementedException();
62-
protected override void Dispose(bool disposing)
63-
{
64-
NumberOfTimesDisposeCalled++;
65-
base.Dispose(disposing);
66-
}
52+
Assert.Equal(1, numberOfTimesDisposeCalled);
6753
}
6854
}
6955
}

src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/MLDsaImplementation.OpenSsl.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,11 @@ internal static partial bool SupportsAny() =>
3636
Interop.Crypto.EvpPKeyMLDsaAlgs.MLDsa65 != null ||
3737
Interop.Crypto.EvpPKeyMLDsaAlgs.MLDsa87 != null;
3838

39-
internal MLDsaImplementation Duplicate()
40-
{
41-
return new MLDsaImplementation(Algorithm, _key.DuplicateHandle());
42-
}
43-
4439
internal SafeEvpPKeyHandle DuplicateHandle()
4540
{
4641
return _key.DuplicateHandle();
4742
}
4843

49-
// TODO: Delete this when public MLDsaOpenSsl is added.
50-
internal static MLDsaImplementation FromHandle(MLDsaAlgorithm algorithm, SafeEvpPKeyHandle key)
51-
{
52-
Debug.Assert(key is not null);
53-
Debug.Assert(!key.IsInvalid);
54-
Debug.Assert(algorithm is not null);
55-
56-
ThrowIfNotSupported();
57-
return new MLDsaImplementation(algorithm, key.DuplicateHandle());
58-
}
59-
6044
protected override void SignDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byte> context, Span<byte> destination) =>
6145
Interop.Crypto.MLDsaSignPure(_key, data, context, destination);
6246

src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,7 @@ public ECDiffieHellman GetECDiffieHellmanPublicKey()
615615
return null;
616616
}
617617

618-
// TODO: Use MLDsaOpenSsl when it is available.
619-
return MLDsaImplementation.FromHandle(
620-
MLDsaAlgorithm.GetMLDsaAlgorithmFromOid(KeyAlgorithm)!,
621-
_privateKey);
618+
return new MLDsaOpenSsl(_privateKey);
622619
}
623620

624621
private OpenSslX509CertificateReader CopyWithPrivateKey(SafeEvpPKeyHandle privateKey)
@@ -697,7 +694,10 @@ public ICertificatePal CopyWithPrivateKey(MLDsa privateKey)
697694
return CopyWithPrivateKey(impl.DuplicateHandle());
698695
}
699696

700-
// TODO: Special case MLDsaOpenSsl when it is available.
697+
if (privateKey is MLDsaOpenSsl implOpenSsl)
698+
{
699+
return CopyWithPrivateKey(implOpenSsl.DuplicateKeyHandle());
700+
}
701701

702702
using (MLDsaImplementation clone = MLDsaImplementation.DuplicatePrivateKey(privateKey))
703703
{

0 commit comments

Comments
 (0)