move qord trest to dsa_int_validate_pqg

This commit is contained in:
Karel Miko 2017-09-14 17:37:39 +02:00
parent 9765befd6b
commit fd94e9540f
3 changed files with 8 additions and 12 deletions

View File

@ -45,12 +45,6 @@ int dsa_set_pqg(const unsigned char *p, unsigned long plen,
key->qord = mp_unsigned_bin_size(key->q);
if (key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
(unsigned long)key->qord >= mp_unsigned_bin_size(key->p) || (mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA) {
err = CRYPT_INVALID_PACKET;
goto LBL_ERR;
}
/* do only a quick validation, without primality testing */
if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) { goto LBL_ERR; }
if (stat == 0) {

View File

@ -44,12 +44,6 @@ int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamle
key->qord = mp_unsigned_bin_size(key->q);
if (key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
(unsigned long)key->qord >= mp_unsigned_bin_size(key->p) || (mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA) {
err = CRYPT_INVALID_PACKET;
goto LBL_ERR;
}
/* quick p, q, g validation, without primality testing */
if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) {
goto LBL_ERR;

View File

@ -56,6 +56,14 @@ int dsa_int_validate_pqg(dsa_key *key, int *stat)
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(stat != NULL);
/* check q-order */
if ( key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
(unsigned long)key->qord >= mp_unsigned_bin_size(key->p) ||
(mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA ) {
err = CRYPT_OK;
goto error;
}
/* FIPS 186-4 chapter 4.1: 1 < g < p */
if (mp_cmp_d(key->g, 1) != LTC_MP_GT || mp_cmp(key->g, key->p) != LTC_MP_LT) {
return CRYPT_OK;