Skip to content

[API Proposal]: Amend MLKem, MLDsa, and SlhDsa ImportEncryptedPkcs8PrivateKey #115024

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

Open
vcsjones opened this issue Apr 24, 2025 · 1 comment
Open
Assignees
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Security
Milestone

Comments

@vcsjones
Copy link
Member

vcsjones commented Apr 24, 2025

Background and motivation

In #114453 we approved the following APIs for ImportEncryptedPkcs8PrivateKey:

        public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source);
        public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source);
        public static MLKem ImportEncryptedPkcs8PrivateKey(string password, ReadOnlySpan<byte> source);

After some discussion, we decided that the last of the trio would be better if the source parameter were a byte[], not a ReadOnlySpan<byte>.

We decided that, since the string overloads for password exist purely for ease-of-use for other downlevel platforms, that one should take a byte array instead of a ReadOnlySpan. There is already an overload that accepts ReadOnlySpan, ReadOnlySpan, so modern targets still have access to all the span APIs that they want.

This also offers better symmetry with ImportFromEncryptedPem which uses string, byte[].

API Proposal

namespace System.Security.Cryptography
{
    public class MLDsa, MLKem, SlhDsa, CompositeMLDsa
    {
        public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source);
        public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source);
-       public static MLKem ImportEncryptedPkcs8PrivateKey(string password, ReadOnlySpan<byte> source);
+       public static MLKem ImportEncryptedPkcs8PrivateKey(string password, byte[] source);
    }
}

API Usage

Same usage, but a different type for platforms where span is cumbersome to use.

Alternative Designs

No response

Risks

No response

@vcsjones vcsjones added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Security labels Apr 24, 2025
@vcsjones vcsjones added this to the 10.0.0 milestone Apr 24, 2025
@vcsjones vcsjones self-assigned this Apr 24, 2025
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.

@PranavSenthilnathan PranavSenthilnathan added the api-ready-for-review API is ready for review, it is NOT ready for implementation label Apr 24, 2025
@vcsjones vcsjones removed the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Security
Projects
None yet
Development

No branches or pull requests

3 participants