Merge pull request #4463 from JacobBarthelmeh/fuzzing

DSA: add check on bit length of q
pull/4474/head
Sean Parkinson 2021-10-14 08:06:53 +10:00 committed by GitHub
commit b93b7b07a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -19589,6 +19589,13 @@ static int test_wc_DsaSignVerify (void)
}
}
#if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
/* hard set q to 0 and test fail case */
mp_free(&key.q);
mp_init(&key.q);
AssertIntEQ(wc_DsaSign(hash, signature, &key, &rng), BAD_FUNC_ARG);
#endif
if (wc_FreeRng(&rng) && ret == 0) {
ret = WOLFSSL_FATAL_ERROR;
}

View File

@ -736,6 +736,18 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
}
halfSz = min(DSA_MAX_HALF_SIZE, mp_unsigned_bin_size(&key->q));
/* NIST FIPS 186-4: Sections 4.1
* q is a prime divisor where 2^(N-1) < q < 2^N and N is the bit length
* of q.
* To satisfy this constraint if N is 0 then q would still need to be
* larger than 0.5, but since there is 0 bits in q it can not be any
* value.
*/
if (halfSz == 0) {
ret = BAD_FUNC_ARG;
break;
}
tmp = out;
qMinus1 = kInv;