DSA: properly handle FIPS 186-4 (4.6 + 4.7)

This commit is contained in:
Karel Miko 2016-10-10 21:51:22 +02:00 committed by karel-m
parent 498538f6ef
commit ecbac7324e
2 changed files with 6 additions and 0 deletions

View File

@ -84,6 +84,9 @@ retry:
if (mp_iszero(r) == LTC_MP_YES) { goto retry; }
/* FIPS 186-4 4.6: use leftmost min(bitlen(q), bitlen(hash)) */
if (inlen > (unsigned long)(key->qord)) inlen = (unsigned long)(key->qord);
/* now find s = (in + xr)/k mod q */
if ((err = mp_read_unsigned_bin(tmp, (unsigned char *)in, inlen)) != CRYPT_OK) { goto error; }
if ((err = mp_mul(key->x, r, s)) != CRYPT_OK) { goto error; }

View File

@ -54,6 +54,9 @@ int dsa_verify_hash_raw( void *r, void *s,
goto error;
}
/* FIPS 186-4 4.7: use leftmost min(bitlen(q), bitlen(hash)) bits of 'hash' */
if (hashlen > (unsigned long)(key->qord)) hashlen = (unsigned long)(key->qord);
/* w = 1/s mod q */
if ((err = mp_invmod(s, key->q, w)) != CRYPT_OK) { goto error; }