From 444d9f3fb744e4b977b93bca523d64eb2b9e05b8 Mon Sep 17 00:00:00 2001 From: Karel Miko Date: Thu, 14 Sep 2017 17:38:12 +0200 Subject: [PATCH] do dsa_int_validate_* in dsa_import --- src/pk/dsa/dsa_import.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pk/dsa/dsa_import.c b/src/pk/dsa/dsa_import.c index 3934765..08d64b7 100644 --- a/src/pk/dsa/dsa_import.c +++ b/src/pk/dsa/dsa_import.c @@ -24,7 +24,7 @@ */ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) { - int err; + int err, stat; unsigned long zero = 0; unsigned char* tmpbuf = NULL; unsigned char flags[1]; @@ -116,10 +116,21 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) } LBL_OK: - key->qord = mp_unsigned_bin_size(key->q); + 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) { + /* quick p, q, g validation, without primality testing */ + if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) { + goto LBL_ERR; + } + if (stat == 0) { + err = CRYPT_INVALID_PACKET; + goto LBL_ERR; + } + /* validate x, y */ + if ((err = dsa_int_validate_xy(key, &stat)) != CRYPT_OK) { + goto LBL_ERR; + } + if (stat == 0) { err = CRYPT_INVALID_PACKET; goto LBL_ERR; }