Based on recent discussions with @bartonjs where I needed to also obtain an estimated size. As per Jeremy, ECDsa should use 2 * ((KeySize + 7) / 8) and for RSA (KeySize + 7) / 8.
What is currently being used is this:
|
int estimatedSize = KeySize switch |
|
{ |
|
256 => 64, |
|
384 => 96, |
|
521 => 132, |
|
// If we got here, the range of legal key sizes for ECDsaCng was expanded and someone didn't update this switch. |
|
// Since it isn't a fatal error to miscalculate the estimatedSize, don't throw an exception. Just truck along. |
|
_ => KeySize / 4, |
|
}; |
and this:
|
int estimatedSize = KeySize / 8; |
For ECDsa and RSA respectively.
It is not a bug as the code handles the case where the signature buffer wasn't big enough but I think we should be consistent on how to calculate it, maybe even consider adding a GetSignatureSize() API.
Based on recent discussions with @bartonjs where I needed to also obtain an estimated size. As per Jeremy, ECDsa should use
2 * ((KeySize + 7) / 8)and for RSA(KeySize + 7) / 8.What is currently being used is this:
runtime/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.SignVerify.cs
Lines 21 to 29 in ea4ebaa
and this:
runtime/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs
Line 62 in ea4ebaa
For ECDsa and RSA respectively.
It is not a bug as the code handles the case where the signature buffer wasn't big enough but I think we should be consistent on how to calculate it, maybe even consider adding a
GetSignatureSize()API.