bootutil/crypto: SHA256 init functions should return a status

SHA-256 init functions should return the status of the init
instead of being void. This would allow the callers to implement
proper error recovery, otherwise on error the SHA-256 operation
will enter an undefined behaviour.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I162ceb8e6dc90dc3c6b83c8a85fbd17b41c0b5d6
This commit is contained in:
Antonio de Angelis 2023-04-14 10:02:15 +01:00 committed by Dávid Vincze
parent f92a2193f4
commit 0361ad3d42
1 changed files with 8 additions and 10 deletions

View File

@ -71,14 +71,10 @@ extern "C" {
typedef psa_hash_operation_t bootutil_sha256_context;
static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
{
*ctx = psa_hash_operation_init();
psa_status_t status = psa_hash_setup(ctx, PSA_ALG_SHA_256);
if (status != PSA_SUCCESS) {
MCUBOOT_LOG_ERR("Failed setting up a hash operation for PSA Crypto APIs");
while(1) {}
}
return (int)psa_hash_setup(ctx, PSA_ALG_SHA_256);
}
static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
@ -105,10 +101,10 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
typedef mbedtls_sha256_context bootutil_sha256_context;
static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
{
mbedtls_sha256_init(ctx);
(void)mbedtls_sha256_starts_ret(ctx, 0);
return mbedtls_sha256_starts_ret(ctx, 0);
}
static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
@ -135,9 +131,10 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
#if defined(MCUBOOT_USE_TINYCRYPT)
typedef struct tc_sha256_state_struct bootutil_sha256_context;
static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
{
tc_sha256_init(ctx);
return 0;
}
static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
@ -160,9 +157,10 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
#endif /* MCUBOOT_USE_TINYCRYPT */
#if defined(MCUBOOT_USE_CC310)
static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
{
cc310_sha256_init(ctx);
return 0;
}
static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)