diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index de5f4126e1..f2092fac3d 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -123,6 +123,7 @@ ECC Curve Sizes: #include #include +#include #include #include #include @@ -136,9 +137,6 @@ ECC Curve Sizes: #include #endif -#ifdef HAVE_X963_KDF - #include -#endif #ifdef WOLF_CRYPTO_CB #include @@ -5381,6 +5379,11 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, if (in == NULL || out == NULL || outlen == NULL || key == NULL) { return ECC_BAD_ARG_E; } + if ((inlen > WC_MAX_DIGEST_SIZE) || + (inlen < WC_MIN_DIGEST_SIZE)) + { + return BAD_LENGTH_E; + } #ifdef WOLF_CRYPTO_CB if (key->devId != INVALID_DEVID) { @@ -5698,6 +5701,11 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng, if (in == NULL || r == NULL || s == NULL || key == NULL || rng == NULL) { return ECC_BAD_ARG_E; } + if ((inlen > WC_MAX_DIGEST_SIZE) || + (inlen < WC_MIN_DIGEST_SIZE)) + { + return BAD_LENGTH_E; + } /* is this a private key? */ if (key->type != ECC_PRIVATEKEY && key->type != ECC_PRIVATEKEY_ONLY) { @@ -6879,6 +6887,12 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, return ECC_BAD_ARG_E; } + /* Check hash length */ + if ((hashlen > WC_MAX_DIGEST_SIZE) || + (hashlen < WC_MIN_DIGEST_SIZE)) { + return BAD_LENGTH_E; + } + #ifdef WOLF_CRYPTO_CB if (key->devId != INVALID_DEVID) { err = wc_CryptoCb_EccVerify(sig, siglen, hash, hashlen, res, key); @@ -7084,6 +7098,12 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, if (r == NULL || s == NULL || hash == NULL || res == NULL || key == NULL) return ECC_BAD_ARG_E; + /* Check hash length */ + if ((hashlen > WC_MAX_DIGEST_SIZE) || + (hashlen < WC_MIN_DIGEST_SIZE)) { + return BAD_LENGTH_E; + } + /* default to invalid signature */ *res = 0;