Merge pull request #4220 from SparkiDev/ecc_neg_string

ECC: where reading strings, check for neg (invalid)
This commit is contained in:
JacobBarthelmeh
2021-07-20 18:56:00 +07:00
committed by GitHub

View File

@@ -8882,6 +8882,11 @@ int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen)
if (mp_iszero(rtmp) == MP_YES || mp_iszero(stmp) == MP_YES)
err = MP_ZERO_E;
}
if (err == MP_OKAY) {
if (mp_isneg(rtmp) == MP_YES || mp_isneg(stmp) == MP_YES) {
err = MP_READ_E;
}
}
/* convert mp_ints to ECDSA sig, initializes rtmp and stmp internally */
if (err == MP_OKAY)
@@ -8993,7 +8998,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
err = mp_read_unsigned_bin(key->pubkey.x, (const byte*)qx,
key->dp->size);
if (mp_iszero(key->pubkey.x)) {
if (mp_iszero(key->pubkey.x) || mp_isneg(key->pubkey.x)) {
WOLFSSL_MSG("Invalid Qx");
err = BAD_FUNC_ARG;
}
@@ -9007,7 +9012,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
err = mp_read_unsigned_bin(key->pubkey.y, (const byte*)qy,
key->dp->size);
if (mp_iszero(key->pubkey.y)) {
if (mp_iszero(key->pubkey.y) || mp_isneg(key->pubkey.y)) {
WOLFSSL_MSG("Invalid Qy");
err = BAD_FUNC_ARG;
}
@@ -9106,7 +9111,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
err = mp_read_unsigned_bin(&key->k, (const byte*)d,
key->dp->size);
#endif /* WOLFSSL_ATECC508A */
if (mp_iszero(&key->k)) {
if (mp_iszero(&key->k) || mp_isneg(&key->k)) {
WOLFSSL_MSG("Invalid private key");
return BAD_FUNC_ARG;
}