summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
authorJiasheng Jiang <jiasheng@purdue.edu>2024-03-22 20:01:52 +0000
committerNeil Horman <nhorman@openssl.org>2024-04-01 16:02:08 -0400
commit81f2b0420abab47a7fd9fc9ef69309578115d342 (patch)
tree20b8c2fec0c8dc369f8673f94946278c322f55fc /providers
parente97f468589e807e7f4722b150458edd53f374cd0 (diff)
rands/drbg_hmac.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/23945)
Diffstat (limited to 'providers')
-rw-r--r--providers/implementations/rands/drbg_hmac.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/providers/implementations/rands/drbg_hmac.c b/providers/implementations/rands/drbg_hmac.c
index bc8a4ff578..3cd1b614e0 100644
--- a/providers/implementations/rands/drbg_hmac.c
+++ b/providers/implementations/rands/drbg_hmac.c
@@ -410,6 +410,7 @@ static int drbg_hmac_set_ctx_params_locked(void *vctx, const OSSL_PARAM params[]
PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)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(&hmac->digest, params, libctx))
return 0;
@@ -424,7 +425,10 @@ static int drbg_hmac_set_ctx_params_locked(void *vctx, const OSSL_PARAM params[]
if (md != NULL && hmac->ctx != NULL) {
/* These are taken from SP 800-90 10.1 Table 2 */
- hmac->blocklen = EVP_MD_get_size(md);
+ md_size = EVP_MD_get_size(md);
+ if (md_size <= 0)
+ return 0;
+ hmac->blocklen = (size_t)md_size;
/* See SP800-57 Part1 Rev4 5.6.1 Table 3 */
ctx->strength = 64 * (int)(hmac->blocklen >> 3);
if (ctx->strength > 256)