Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add PKCS#8, SPKI and PEM support for SLH-DSA #114943

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 20 commits into from
May 1, 2025

Conversation

PranavSenthilnathan
Copy link
Member

@PranavSenthilnathan PranavSenthilnathan commented Apr 23, 2025

Add support for PKCS#8, SPKI and PEM, both encrypted and unencrypted.

Contributes to #113506

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

// Early heuristic based bailout so no core methods are called
AssertExtensions.FalseExpression(slhDsa.TryExportPkcs8PrivateKey([], out int bytesWritten));
Assert.Equal(9, encodedMetadata.Length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird to me that this is being recomputed and reverified on every single run with every single algorithm. It's probably fine, but I'd probably just declare 9 as a local const and leave a comment as to how that value was determined.

What really matters is that it tests "one below this doesn't call the Core method, and at this size it does". So maybe I'd omit the comment, as const int MinimumOverhead = 9; says "it's a minimum" and then the test confirms it's the same minimum that the implementation uses.

There's room to argue if we want the minimum to be 9, or if we want to say that since we have a finite list of SlhDsaAlgorithm and we know they all have a minimum of (whatever it is) that we're going to push the impl limit higher. Again, it doesn't matter a whole lot to the test why we picked that number, but it would have to match if it's testing the boundary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't matter a whole lot to the test why we picked that number

I think it's worth having both the following tests: (1) the number we picked is honored in the implementation and (2) the length check will permit a minimal encoding. And by minimal encoding, I mean either a hardcoded or runtime generated ASN encoding for each algo that we believe is the smallest spec compliant PKCS#8 encoding.

If we don't have (2) it becomes very easy to just update the constant in the product and in the failing test and nothing really gets validated. By having (2) it forces us to provide a new minimal encoding to prove that the new constant still satisfies the constraint of allowing the minimal encoding.

Also, the overhead right now does not account for the Version so I'll add it in.

Copy link
Member

@bartonjs bartonjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good after the one remaining rename

@PranavSenthilnathan
Copy link
Member Author

/ba-g Failing wasm tests are unrelated.

@PranavSenthilnathan PranavSenthilnathan merged commit f6b9331 into dotnet:main May 1, 2025
83 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants