From 885bd91f27fd31d46f33861b94a814fa4537ab5f Mon Sep 17 00:00:00 2001 From: Ryan Everett <ryan.everett@arm.com> Date: Fri, 8 Nov 2024 15:03:15 +0000 Subject: [PATCH] fix(mbedtls): fix error return code for calc_hash Make this function return values from crypto_ret_value. The previous method of returning the mbedtls error code on failure meant that the authentication module couldn't correctly parse failures from this function. Change-Id: I9fe6eba1fc79e8f81004f8cd202781aea907e963 Signed-off-by: Ryan Everett <ryan.everett@arm.com> --- drivers/auth/mbedtls/mbedtls_crypto.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/auth/mbedtls/mbedtls_crypto.c b/drivers/auth/mbedtls/mbedtls_crypto.c index 9bfcaac0b..8fe426bb8 100644 --- a/drivers/auth/mbedtls/mbedtls_crypto.c +++ b/drivers/auth/mbedtls/mbedtls_crypto.c @@ -275,6 +275,7 @@ static int calc_hash(enum crypto_md_algo md_algo, void *data_ptr, unsigned char output[CRYPTO_MD_MAX_SIZE]) { const mbedtls_md_info_t *md_info; + int rc; md_info = mbedtls_md_info_from_type(md_type(md_algo)); if (md_info == NULL) { @@ -286,7 +287,12 @@ static int calc_hash(enum crypto_md_algo md_algo, void *data_ptr, * 'output' hash buffer pointer considering its size is always * bigger than or equal to MBEDTLS_MD_MAX_SIZE. */ - return mbedtls_md(md_info, data_ptr, data_len, output); + rc = mbedtls_md(md_info, data_ptr, data_len, output); + if (rc != 0) { + return CRYPTO_ERR_HASH; + } + + return CRYPTO_SUCCESS; } #endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \ CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */