Skip to content
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

Increase number of attempts before failure in ECDSA-DER #33933

Merged
merged 2 commits into from
Mar 22, 2020
Merged
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 @@ -331,15 +331,17 @@ public void Rfc23279TrySignHashUnderMax()
ECDsa key = (ECDsa)keyDescription.Key;

const DSASignatureFormat SignatureFormat = DSASignatureFormat.Rfc3279DerSequence;
const int RetryCount = 10;
// Make secp521r1 (7/16 chance of being smaller) and mod-8 keys (3/4 chance of being smaller)
// have the same 1-in-a-billion chance of failure.
int retryCount = keyDescription.FieldSizeInBits % 8 == 1 ? 36 : 15;
byte[] hash = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };

int expectedSize = GetExpectedSize(keyDescription.FieldSizeInBits);
int maxSize = key.GetMaxSignatureSize(DSASignatureFormat.Rfc3279DerSequence);
Assert.True(expectedSize < maxSize, "expectedSize < maxSize");
byte[] signature = new byte[expectedSize];

for (int i = 0; i < RetryCount; i++)
for (int i = 0; i < retryCount; i++)
{
if (key.TrySignHash(hash, signature, SignatureFormat, out int written))
{
Expand All @@ -359,15 +361,17 @@ public void Rfc23279TrySignDataUnderMax()
ECDsa key = (ECDsa)keyDescription.Key;

const DSASignatureFormat SignatureFormat = DSASignatureFormat.Rfc3279DerSequence;
const int RetryCount = 10;
// Make secp521r1 (7/16 chance of being smaller) and mod-8 keys (3/4 chance of being smaller)
// have the same 1-in-a-billion chance of failure.
int retryCount = keyDescription.FieldSizeInBits % 8 == 1 ? 36 : 15;
HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA1;

int expectedSize = GetExpectedSize(keyDescription.FieldSizeInBits);
int maxSize = key.GetMaxSignatureSize(DSASignatureFormat.Rfc3279DerSequence);
Assert.True(expectedSize < maxSize, "expectedSize < maxSize");
byte[] signature = new byte[expectedSize];

for (int i = 0; i < RetryCount; i++)
for (int i = 0; i < retryCount; i++)
{
if (key.TrySignData(Array.Empty<byte>(), signature, hashAlgorithm, SignatureFormat, out int written))
{
Expand Down