diff mbox series

[12/23] image: switch sha256 to mbedtls

Message ID 20240416190019.81016-13-raymond.mao@linaro.org
State RFC
Delegated to: Tom Rini
Headers show
Series Integrate MbedTLS v3.6 LTS with U-Boot | expand

Commit Message

Raymond Mao April 16, 2024, 7 p.m. UTC
When MBEDTLS_LIB_CRYPTO is enabled, use the APIs of sha256 from
hash shim layer instead.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
---
 boot/image-pre-load.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c
index b504ab42a5..85d5ff3ab7 100644
--- a/boot/image-pre-load.c
+++ b/boot/image-pre-load.c
@@ -8,8 +8,11 @@ 
 DECLARE_GLOBAL_DATA_PTR;
 #include <image.h>
 #include <mapmem.h>
-
+#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO)
+#include <mbedtls/sha256.h>
+#else
 #include <u-boot/sha256.h>
+#endif
 
 /*
  * Offset of the image
@@ -240,8 +243,13 @@  static int image_pre_load_sig_check_img_sig_sha256(struct image_sig_info *info,
 		goto out_sig_header;
 	}
 
+#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO)
+	sha256_csum_wd_mb(header + offset_img_sig, info->sig_size,
+			  sha256_img_sig, CHUNKSZ_SHA256);
+#else
 	sha256_csum_wd(header + offset_img_sig, info->sig_size,
 		       sha256_img_sig, CHUNKSZ_SHA256);
+#endif
 
 	ret = memcmp(sig_header->sha256_img_sig, sha256_img_sig, SHA256_SUM_LEN);
 	if (ret) {