add basic validity tests to dsa_set
This commit is contained in:
parent
a86287b698
commit
9003e87e5a
@ -45,6 +45,11 @@ int dsa_set_pqg(const unsigned char *p, unsigned long plen,
|
|||||||
|
|
||||||
key->qord = mp_unsigned_bin_size(key->q);
|
key->qord = mp_unsigned_bin_size(key->q);
|
||||||
|
|
||||||
|
/* just a quick, basic test - use dsa_verify_key if you want more */
|
||||||
|
if (mp_cmp_d(key->p, 1) != LTC_MP_GT || mp_cmp_d(key->g, 1) != LTC_MP_GT || mp_cmp_d(key->q, 1) != LTC_MP_GT) {
|
||||||
|
goto LBL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if (key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
|
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) {
|
(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;
|
err = CRYPT_INVALID_PACKET;
|
||||||
@ -83,11 +88,15 @@ int dsa_set_key(const unsigned char *in, unsigned long inlen, int type, dsa_key
|
|||||||
if (type == PK_PRIVATE) {
|
if (type == PK_PRIVATE) {
|
||||||
key->type = PK_PRIVATE;
|
key->type = PK_PRIVATE;
|
||||||
if ((err = mp_read_unsigned_bin(key->x, (unsigned char *)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
|
if ((err = mp_read_unsigned_bin(key->x, (unsigned char *)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
|
||||||
|
if (mp_cmp_d(key->x, 1) != LTC_MP_GT) { goto LBL_ERR; }
|
||||||
if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) { goto LBL_ERR; }
|
if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) { goto LBL_ERR; }
|
||||||
|
if (mp_cmp_d(key->y, 1) != LTC_MP_GT) { goto LBL_ERR; }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
key->type = PK_PUBLIC;
|
key->type = PK_PUBLIC;
|
||||||
if ((err = mp_read_unsigned_bin(key->y, (unsigned char *)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
|
if ((err = mp_read_unsigned_bin(key->y, (unsigned char *)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
|
||||||
|
if (mp_cmp_d(key->y, 1) != LTC_MP_GT) { goto LBL_ERR; }
|
||||||
|
if (mp_cmp(key->y, key->p) != LTC_MP_LT) { goto LBL_ERR; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return CRYPT_OK;
|
return CRYPT_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user