-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: RSA.GetMaxOutputSize #78175
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsBackground and motivationThis is a proposal for the discussion in #67059. We have some helpers for {EC}DSA for getting signature sizes. This adds a complementary API for RSA, both for creating signatures and PKCS1/OAEP encryption. This is useful if you want to stackalloc or rent a buffer to hold a signature and need to know how much data you need. Remark: I considered what this might look like for ECDiffieHellman derived keys. It's a little easier for developers to reason about those sizes from API Proposalnamespace System.Security.Cryptography {
public partial class RSA {
public int GetSignatureSize();
public int GetEncryptedDataSize();
}
} API Usagebyte[] signatureBuffer = ArrayPool<byte>.Shared.Rent(rsa.GetSignatureSize());
int written = rsa.Sign(blah, blah, signatureBuffer);
ReadOnlySpan<byte> signature = signatureBuffer.AsSpan(0, written); Alternative DesignsDo nothing. Expect that developers know RisksNo response
|
Those two things are the same value, so it's unfortunate that they're two different methods. What about |
I was wrestling with that and was trying to achieve similar naming as we had for {EC}DSA. I'm not sure "Output" is the right thing there. Output of what? I agree the single method is probably "better" but haven't found a way that I was super comfortable with. |
Looks good as proposed. namespace System.Security.Cryptography;
public partial class RSA
{
public int GetMaxOutputSize();
} |
Background and motivation
This is a proposal for the discussion in #67059. We have some helpers for {EC}DSA for getting signature sizes. This adds a complementary API for RSA. The method handles a "right" size for encryption and signing, and a "worst case" for decryption.
This is useful if you want to stackalloc or rent a buffer to hold a signature and need to know how much data you need.
Remark:
I considered what this might look like for ECDiffieHellman derived keys. It's a little easier for developers to reason about those sizes from
DeriveKeyFrom{Hash,Hmac}
without a helper, so I didn't propose anything there.API Proposal
API Usage
Alternative Designs
Do nothing. Expect that developers know
(KeySize + 7) / 8
is correct.Risks
No response
The text was updated successfully, but these errors were encountered: