// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2015 Freescale Semiconductor, Inc.
+ * Copyright 2021 NXP
*/
#include <common.h>
return ret;
ret = algo->hash_init(algo, &ctx);
- if (ret)
+ if (ret) {
+ if (ctx)
+ free(ctx);
return ret;
+ }
/* Update hash for ESBC key */
#ifdef CONFIG_KEY_REVOCATION
/* Copy hash at destination buffer */
ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
- if (ret)
+ if (ret) {
+ if (ctx)
+ free(ctx);
return ret;
+ }
for (i = 0; i < SHA256_BYTES; i++)
img->img_key_hash[i] = hash_val[i];
ret = algo->hash_init(algo, &ctx);
/* Copy hash at destination buffer */
- if (ret)
+ if (ret) {
+ free(ctx);
return ret;
+ }
/* Update hash for CSF Header */
ret = algo->hash_update(algo, ctx,
(u8 *)&img->hdr, sizeof(struct fsl_secboot_img_hdr), 0);
- if (ret)
+ if (ret) {
+ free(ctx);
return ret;
+ }
/* Update the hash with that of srk table if srk flag is 1
* If IE Table is selected, key is not added in the hash
key_hash = 1;
}
#endif
- if (ret)
+ if (ret) {
+ free(ctx);
return ret;
- if (!key_hash)
+ }
+ if (!key_hash) {
+ free(ctx);
return ERROR_KEY_TABLE_NOT_FOUND;
+ }
/* Update hash for actual Image */
ret = algo->hash_update(algo, ctx,
(u8 *)(*(img->img_addr_ptr)), img->img_size, 1);
- if (ret)
+ if (ret) {
+ free(ctx);
return ret;
+ }
/* Copy hash at destination buffer */
ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
- if (ret)
+ if (ret) {
+ free(ctx);
return ret;
-
+ }
return 0;
}