-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add Composite ML-DSA support for HTTPS #63280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -683,6 +683,50 @@ public void ConfigureEndpoint_ThrowsWhen_The_KeyIsPublic() | |
| Assert.IsAssignableFrom<CryptographicException>(ex.InnerException); | ||
| } | ||
|
|
||
| #pragma warning disable SYSLIB5006 | ||
| private static readonly Dictionary<string, MLDsaAlgorithm> _mlDsaAlgorithms = ((IEnumerable<MLDsaAlgorithm>)[ | ||
| MLDsaAlgorithm.MLDsa44, | ||
| MLDsaAlgorithm.MLDsa65, | ||
| MLDsaAlgorithm.MLDsa87, | ||
| ]).ToDictionary(a => a.Name); | ||
|
Comment on lines
+687
to
+691
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactor allows us to add more algorithms to test without having to repeat the algorithm name in 3 different places. |
||
|
|
||
| private static readonly Dictionary<string, SlhDsaAlgorithm> _slhDsaAlgorithms = ((IEnumerable<SlhDsaAlgorithm>)[ | ||
| SlhDsaAlgorithm.SlhDsaSha2_128s, | ||
| SlhDsaAlgorithm.SlhDsaSha2_128f, | ||
| SlhDsaAlgorithm.SlhDsaSha2_192s, | ||
| SlhDsaAlgorithm.SlhDsaSha2_192f, | ||
| SlhDsaAlgorithm.SlhDsaSha2_256s, | ||
| SlhDsaAlgorithm.SlhDsaSha2_256f, | ||
| SlhDsaAlgorithm.SlhDsaShake128s, | ||
| SlhDsaAlgorithm.SlhDsaShake128f, | ||
| SlhDsaAlgorithm.SlhDsaShake192s, | ||
| SlhDsaAlgorithm.SlhDsaShake192f, | ||
| SlhDsaAlgorithm.SlhDsaShake256s, | ||
| SlhDsaAlgorithm.SlhDsaShake256f, | ||
| ]).ToDictionary(a => a.Name); | ||
|
|
||
| private static readonly Dictionary<string, CompositeMLDsaAlgorithm> _compositeMLDsaAlgorithms = ((IEnumerable<CompositeMLDsaAlgorithm>)[ | ||
| CompositeMLDsaAlgorithm.MLDsa65WithECDsaP256, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithRSA3072Pkcs15, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithEd25519, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithECDsaP384, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithRSA4096Pss, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithECDsaBrainpoolP256r1, | ||
| CompositeMLDsaAlgorithm.MLDsa44WithRSA2048Pss, | ||
| CompositeMLDsaAlgorithm.MLDsa44WithRSA2048Pkcs15, | ||
| CompositeMLDsaAlgorithm.MLDsa44WithEd25519, | ||
| CompositeMLDsaAlgorithm.MLDsa44WithECDsaP256, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithRSA4096Pss, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithECDsaBrainpoolP384r1, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithECDsaP384, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithECDsaP521, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithEd448, | ||
| CompositeMLDsaAlgorithm.MLDsa87WithRSA3072Pss, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithRSA3072Pss, | ||
| CompositeMLDsaAlgorithm.MLDsa65WithRSA4096Pkcs15, | ||
| ]).ToDictionary(a => a.Name); | ||
| #pragma warning restore SYSLIB5006 | ||
|
|
||
| public static TheoryData<string, string, string> GetPemCertificateTestData() | ||
| { | ||
| var data = new TheoryData<string, string, string>(); | ||
|
|
@@ -695,29 +739,24 @@ public static TheoryData<string, string, string> GetPemCertificateTestData() | |
| #pragma warning disable SYSLIB5006 | ||
| if (MLDsa.IsSupported) | ||
| { | ||
| algorithms.AddRange([ | ||
| "MLDsa44", | ||
| "MLDsa65", | ||
| "MLDsa87", | ||
| ]); | ||
| algorithms.AddRange(_mlDsaAlgorithms.Keys); | ||
| } | ||
|
|
||
| if (SlhDsa.IsSupported) | ||
| { | ||
| algorithms.AddRange([ | ||
| "SlhDsaSha2_128s", | ||
| "SlhDsaSha2_128f", | ||
| "SlhDsaSha2_192s", | ||
| "SlhDsaSha2_192f", | ||
| "SlhDsaSha2_256s", | ||
| "SlhDsaSha2_256f", | ||
| "SlhDsaShake_128s", | ||
| "SlhDsaShake_128f", | ||
| "SlhDsaShake_192s", | ||
| "SlhDsaShake_192f", | ||
| "SlhDsaShake_256s", | ||
| "SlhDsaShake_256f" | ||
| ]); | ||
| algorithms.AddRange(_slhDsaAlgorithms.Keys); | ||
| } | ||
|
|
||
| // Composite ML-DSA certificate generation is not supported at the time | ||
| // of writing, so we skip it. | ||
| // When it gets implemented in the future, simply remove the SkipCompositeMLDsa | ||
| // condition to include it in the tests. | ||
| const bool SkipCompositeMLDsa = true; | ||
| if (CompositeMLDsa.IsSupported && !SkipCompositeMLDsa) | ||
| { | ||
| algorithms.AddRange(_compositeMLDsaAlgorithms | ||
| .Where(kvp => CompositeMLDsa.IsAlgorithmSupported(kvp.Value)) | ||
| .Select(kvp => kvp.Key)); | ||
| } | ||
| #pragma warning restore SYSLIB5006 | ||
|
|
||
|
|
@@ -840,64 +879,35 @@ private static X509Certificate2 GenerateTestCertificateWithAlgorithm(string algo | |
| } | ||
| break; | ||
|
|
||
| case "MLDsa44": | ||
| case "MLDsa65": | ||
| case "MLDsa87": | ||
| #pragma warning disable SYSLIB5006 | ||
| var mlDsaAlgorithm = algorithmType switch | ||
| { | ||
| "MLDsa44" => MLDsaAlgorithm.MLDsa44, | ||
| "MLDsa65" => MLDsaAlgorithm.MLDsa65, | ||
| "MLDsa87" => MLDsaAlgorithm.MLDsa87, | ||
| _ => throw new ArgumentException($"Unknown ML-DSA variant: {algorithmType}") | ||
| }; | ||
| case var x when _mlDsaAlgorithms.TryGetValue(x, out var mlDsaAlgorithm): | ||
| using (var mlDsa = MLDsa.GenerateKey(mlDsaAlgorithm)) | ||
| { | ||
| var request = new CertificateRequest(distinguishedName, mlDsa); | ||
| certificate = CreateTestCertificate(request, sanBuilder); | ||
| keyPem = ExportMLDsaKeyToPem(mlDsa, keyPassword); | ||
| } | ||
| #pragma warning restore SYSLIB5006 | ||
| break; | ||
|
|
||
| case "SlhDsaSha2_128s": | ||
| case "SlhDsaSha2_128f": | ||
| case "SlhDsaSha2_192s": | ||
| case "SlhDsaSha2_192f": | ||
| case "SlhDsaSha2_256s": | ||
| case "SlhDsaSha2_256f": | ||
| case "SlhDsaShake_128s": | ||
| case "SlhDsaShake_128f": | ||
| case "SlhDsaShake_192s": | ||
| case "SlhDsaShake_192f": | ||
| case "SlhDsaShake_256s": | ||
| case "SlhDsaShake_256f": | ||
| #pragma warning disable SYSLIB5006 | ||
| var slhDsaAlgorithm = algorithmType switch | ||
| { | ||
| "SlhDsaSha2_128s" => SlhDsaAlgorithm.SlhDsaSha2_128s, | ||
| "SlhDsaSha2_128f" => SlhDsaAlgorithm.SlhDsaSha2_128f, | ||
| "SlhDsaSha2_192s" => SlhDsaAlgorithm.SlhDsaSha2_192s, | ||
| "SlhDsaSha2_192f" => SlhDsaAlgorithm.SlhDsaSha2_192f, | ||
| "SlhDsaSha2_256s" => SlhDsaAlgorithm.SlhDsaSha2_256s, | ||
| "SlhDsaSha2_256f" => SlhDsaAlgorithm.SlhDsaSha2_256f, | ||
| "SlhDsaShake_128s" => SlhDsaAlgorithm.SlhDsaShake128s, | ||
| "SlhDsaShake_128f" => SlhDsaAlgorithm.SlhDsaShake128f, | ||
| "SlhDsaShake_192s" => SlhDsaAlgorithm.SlhDsaShake192s, | ||
| "SlhDsaShake_192f" => SlhDsaAlgorithm.SlhDsaShake192f, | ||
| "SlhDsaShake_256s" => SlhDsaAlgorithm.SlhDsaShake256s, | ||
| "SlhDsaShake_256f" => SlhDsaAlgorithm.SlhDsaShake256f, | ||
| _ => throw new ArgumentException($"Unknown SLH-DSA variant: {algorithmType}") | ||
| }; | ||
| case var x when _slhDsaAlgorithms.TryGetValue(x, out var slhDsaAlgorithm): | ||
| using (var slhDsa = SlhDsa.GenerateKey(slhDsaAlgorithm)) | ||
| { | ||
| var request = new CertificateRequest(distinguishedName, slhDsa); | ||
| certificate = CreateTestCertificate(request, sanBuilder); | ||
| keyPem = ExportSlhDsaKeyToPem(slhDsa, keyPassword); | ||
| } | ||
| #pragma warning restore SYSLIB5006 | ||
| break; | ||
|
|
||
| case var x when _compositeMLDsaAlgorithms.TryGetValue(x, out var compositeMLDsaAlgorithm): | ||
| using (var compositeMLDsa = CompositeMLDsa.GenerateKey(compositeMLDsaAlgorithm)) | ||
| { | ||
| var request = new CertificateRequest(distinguishedName, compositeMLDsa); | ||
| certificate = CreateTestCertificate(request, sanBuilder); | ||
| keyPem = ExportCompositeMLDsaKeyToPem(compositeMLDsa, keyPassword); | ||
| } | ||
| break; | ||
| #pragma warning restore SYSLIB5006 | ||
|
|
||
| default: | ||
| throw new ArgumentException($"Unknown algorithm type: {algorithmType}"); | ||
| } | ||
|
|
@@ -951,6 +961,14 @@ private static string ExportSlhDsaKeyToPem(SlhDsa slhDsa, string password) | |
| ? slhDsa.ExportPkcs8PrivateKeyPem() | ||
| : slhDsa.ExportEncryptedPkcs8PrivateKeyPem(password.AsSpan(), new PbeParameters(PbeEncryptionAlgorithm.Aes256Cbc, HashAlgorithmName.SHA256, 100_000)); | ||
| } | ||
|
|
||
| private static string ExportCompositeMLDsaKeyToPem(CompositeMLDsa compositeMLDsa, string password) | ||
| { | ||
| return password is null | ||
| ? compositeMLDsa.ExportPkcs8PrivateKeyPem() | ||
| : compositeMLDsa.ExportEncryptedPkcs8PrivateKeyPem(password.AsSpan(), new PbeParameters(PbeEncryptionAlgorithm.Aes256Cbc, HashAlgorithmName.SHA256, 100_000)); | ||
| } | ||
|
|
||
| #pragma warning restore SYSLIB5006 | ||
|
|
||
| [Fact] | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem wrong? Ref https://datatracker.ietf.org/doc/draft-ietf-lamps-pq-composite-sigs/
That would equal 2.16.840.1.114027.80.9.1.0
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, good catch. We should probably fix https://github.com/dotnet/runtime/blob/f514fa50f3385d28fad10d3e1ef5b75a8dfa84f5/src/libraries/Common/src/System/Security/Cryptography/Oids.cs#L138-L155 then (that's where I copied these from).
cc @bartonjs, @PranavSenthilnathan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotnet/runtime#118795