diff options
author | Jiasheng Jiang <jiasheng@purdue.edu> | 2024-03-22 19:51:28 +0000 |
---|---|---|
committer | Neil Horman <nhorman@openssl.org> | 2024-04-02 05:07:02 -0400 |
commit | 68d6dd3354597de01e7a9534be813756004e1351 (patch) | |
tree | 745665565f27013384c3415ad695223eaf62a323 /providers | |
parent | 5f8b812931e5da24df08913c05ff8e4f4494f014 (diff) |
rands/drbg_hash.c: Add checks for the EVP_MD_get_size()
Add checks for the EVP_MD_get_size() to avoid integer overflow and then explicitly cast from int to size_t.
Fixes: 8bf3665196 ("Added DRBG_HMAC & DRBG_HASH + Added defaults for setting DRBG for master/public/private + renamed generate_counter back to reseed_counter + generated new cavs data tests")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23944)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/rands/drbg_hash.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/providers/implementations/rands/drbg_hash.c b/providers/implementations/rands/drbg_hash.c index a35c1f153e..daeedb0056 100644 --- a/providers/implementations/rands/drbg_hash.c +++ b/providers/implementations/rands/drbg_hash.c @@ -507,6 +507,7 @@ static int drbg_hash_set_ctx_params_locked(void *vctx, const OSSL_PARAM params[] PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)ctx->data; OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); const EVP_MD *md; + int md_size; if (!ossl_prov_digest_load_from_params(&hash->digest, params, libctx)) return 0; @@ -517,7 +518,10 @@ static int drbg_hash_set_ctx_params_locked(void *vctx, const OSSL_PARAM params[] return 0; /* Error already raised for us */ /* These are taken from SP 800-90 10.1 Table 2 */ - hash->blocklen = EVP_MD_get_size(md); + md_size = EVP_MD_get_size(md); + if (md_size <= 0) + return 0; + hash->blocklen = md_size; /* See SP800-57 Part1 Rev4 5.6.1 Table 3 */ ctx->strength = 64 * (hash->blocklen >> 3); if (ctx->strength > 256) |