Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ public override byte[] SignHash(byte[] hash)
{
ArgumentNullException.ThrowIfNull(hash);

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,
};
int estimatedSize = GetMaxSignatureSize(DSASignatureFormat.IeeeP1363FixedFieldConcatenation);
Copy link
Member

Choose a reason for hiding this comment

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

Is this more expensive? The implementation of the method isn't trivial, but maybe it doesn't matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe in a micro-benchmark, but ECDSA signing and verifying is going to dominate. For IeeeP1363FixedFieldConcatenation it basically boils down to AsymmetricAlgorithmHelpers.BitsToBytes(KeySize) * 2; Where BitsToBytes just does the "ceiling then divide by 8". I wouldn't be surprised if the JIT inlined BitsToBytes.


unsafe
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private unsafe bool TryEncryptOrDecrypt(ReadOnlySpan<byte> data, Span<byte> dest
// Now that the padding mode and information have been marshaled to their native counterparts, perform the encryption or decryption.
private unsafe byte[] EncryptOrDecrypt(SafeNCryptKeyHandle key, ReadOnlySpan<byte> input, AsymmetricPaddingMode paddingMode, void* paddingInfo, bool encrypt)
{
int estimatedSize = KeySize / 8;
int estimatedSize = GetMaxOutputSize();
#if DEBUG
estimatedSize = 2; // Make sure the NTE_BUFFER_TOO_SMALL scenario gets exercised.
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RS
{
unsafe
{
int estimatedSize = KeySize / 8;
int estimatedSize = GetMaxOutputSize();
switch (padding.Mode)
{
case RSASignaturePaddingMode.Pkcs1:
Expand Down