From patchwork Fri Oct 31 06:54:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 657 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761893731; bh=Y383pT3hhGRtxCQTSqmwfjN1JfXyAOijBWJltbl1eYg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=gy7I+IznnhjNtUDqh4g2YoKAVqCz2KzKlcEoKV2gz2x2kLxz0IuClNy05sP/cgnBF HtGOEZlYNX41skht4sp6iDmJhn9sTeF2abhEz/DeWxUJhY2pWEuGf/PDO5JcByE59I WK8bGC4PZ3FrfbNkYuRDAVa3+Yuv7j0qik1H0VxaA7xyVZFLBV6iTJA4z39hV0i2pq X/Nm7XFjllR5UaRzK6yS0nis/oPxGjnIj7V4YejO+LFGMeZBSII9NF5sQZ/E3Bx0bt HaTtlh7LpkkBYpo7DTBzZUusGUH2KeXbU98u7zaTwgi/bspmRz/WO745sm/6U1LHo8 N4kdHaKr+8Dew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9091B68356 for ; Fri, 31 Oct 2025 00:55:31 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id kMvTc26mt65o for ; Fri, 31 Oct 2025 00:55:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761893731; bh=Y383pT3hhGRtxCQTSqmwfjN1JfXyAOijBWJltbl1eYg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=gy7I+IznnhjNtUDqh4g2YoKAVqCz2KzKlcEoKV2gz2x2kLxz0IuClNy05sP/cgnBF HtGOEZlYNX41skht4sp6iDmJhn9sTeF2abhEz/DeWxUJhY2pWEuGf/PDO5JcByE59I WK8bGC4PZ3FrfbNkYuRDAVa3+Yuv7j0qik1H0VxaA7xyVZFLBV6iTJA4z39hV0i2pq X/Nm7XFjllR5UaRzK6yS0nis/oPxGjnIj7V4YejO+LFGMeZBSII9NF5sQZ/E3Bx0bt HaTtlh7LpkkBYpo7DTBzZUusGUH2KeXbU98u7zaTwgi/bspmRz/WO745sm/6U1LHo8 N4kdHaKr+8Dew== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8081368321 for ; Fri, 31 Oct 2025 00:55:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761893730; bh=kIudzp3K6Spdm7KwM/KO7UD1yka1RzqEn1F8pt6Q3wE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T04WswkTZ9lFQhmmXI31H1TRGSxT3tblbBv9irp1GCwraWSQqkpsoBm3zKP9xfFkt 4Eo+KOAkcGTgQbYkSYNoPtHFkfGihxxX7Te9RkEJOwEzSyDKhyrmDXDsDyZci/UH/7 rW9aRC+/yv1J4zsuKbL2Ah1lHk2w8tEz3PZsR0+XOTJYOH4eT6P6etvz5XziA4RTot Ao1KOYNje659xp78q7LRGUpBNzjptOmeyWMnMVVidKF77xXli+caSf6Frh3hjD1kWm cdF4ZyKeSeNYBlefin+uk38Lp/wSxehXFQA1NQPVfylTcAtKwV9WHoJvYBz3cBnIoP QY4dsuCl7Eg3A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4574F682E9; Fri, 31 Oct 2025 00:55:30 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id bc7u17qmK8p3; Fri, 31 Oct 2025 00:55:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1761893726; bh=Qo4E7IWtqfb9u468IYSSiuO1sQ3sH4L1/4Vfx05vTzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNlR37nickDF1RB+sCsEzTdF0nxCVaCGdtGCRFNU1YYp3D2DyFe23AWuBoM+uoIwt aUO680SlVLJFnmkaU7dzProlyqYfaKTl2NjfJ/zJJgfKH6WDG6jsYf+z6fJTgT5K+K 0NvfpFMR1q4+ztFQxy7mSDb+O99a5XLnJLIEeIQDBO97mhXvcbHUpS2EyJw61a/Xwu pl5fdwmoGdXAkWQKffMZX7/gB0L3drmGN9ErPtUE9Jt3dLwntgh8C2GzkhOxWWAxxg Fw/0no4gC33z9qV00vZy6gOSQv/XSNbMGZk9bz/oqyeQkIhRVgY9GXy582Pd6k+Ow+ wETVFldVp4qBg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 05506682CD; Fri, 31 Oct 2025 00:55:25 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 31 Oct 2025 00:54:03 -0600 Message-ID: <20251031065439.3251464-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251031065439.3251464-1-sjg@u-boot.org> References: <20251031065439.3251464-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BMNVTYMMAHIYZRRAUFWIOFMTII3VCKQ2 X-Message-ID-Hash: BMNVTYMMAHIYZRRAUFWIOFMTII3VCKQ2 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/24] mbedtls: hash: Provide the mbedtls hash type in the hash interface List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The mbedtls hashing has not been integrated into U-Boot's hash API. As a first step, add the mbedtls hash type into struct hash_algo and provide the values. This allows looking up the type by its name. Signed-off-by: Simon Glass --- common/hash.c | 5 +++++ include/hash.h | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/common/hash.c b/common/hash.c index 0c45992d5c7..2e3b12c109a 100644 --- a/common/hash.c +++ b/common/hash.c @@ -212,6 +212,7 @@ static struct hash_algo hash_algo[] = { .digest_size = MD5_SUM_LEN, .chunk_size = CHUNKSZ_MD5, .hash_func_ws = md5_wd, + HASH_MBEDTLS_TYPE(MBEDTLS_MD_MD5) }, #endif #if CONFIG_IS_ENABLED(SHA1) @@ -233,6 +234,7 @@ static struct hash_algo hash_algo[] = { .hash_update = hash_update_sha1, .hash_finish = hash_finish_sha1, #endif + HASH_MBEDTLS_TYPE(MBEDTLS_MD_SHA1) }, #endif #if CONFIG_IS_ENABLED(SHA256) @@ -254,6 +256,7 @@ static struct hash_algo hash_algo[] = { .hash_update = hash_update_sha256, .hash_finish = hash_finish_sha256, #endif + HASH_MBEDTLS_TYPE(MBEDTLS_MD_SHA256) }, #endif #if CONFIG_IS_ENABLED(SHA384) @@ -275,6 +278,7 @@ static struct hash_algo hash_algo[] = { .hash_update = hash_update_sha384, .hash_finish = hash_finish_sha384, #endif + HASH_MBEDTLS_TYPE(MBEDTLS_MD_SHA384) }, #endif #if CONFIG_IS_ENABLED(SHA512) @@ -296,6 +300,7 @@ static struct hash_algo hash_algo[] = { .hash_update = hash_update_sha512, .hash_finish = hash_finish_sha512, #endif + HASH_MBEDTLS_TYPE(MBEDTLS_MD_SHA512) }, #endif #if CONFIG_IS_ENABLED(CRC16) diff --git a/include/hash.h b/include/hash.h index 8b3f79ec473..46a2be72f7e 100644 --- a/include/hash.h +++ b/include/hash.h @@ -10,6 +10,15 @@ #include #endif +#if !defined(USE_HOSTCC) && CONFIG_IS_ENABLED(MBEDTLS_LIB) +#include +#include + +#define HASH_MBEDTLS_TYPE(_val) .md_type = _val, +#else +#define HASH_MBEDTLS_TYPE(_val) +#endif + struct cmd_tbl; /* @@ -44,6 +53,9 @@ struct hash_algo { void (*hash_func_ws)(const unsigned char *input, unsigned int ilen, unsigned char *output, unsigned int chunk_sz); int chunk_size; /* Watchdog chunk size */ +#if !defined(USE_HOSTCC) && CONFIG_IS_ENABLED(MBEDTLS_LIB) + mbedtls_md_type_t md_type; /* mbedtls hash type */ +#endif /* * hash_init: Create the context for progressive hashing * @@ -120,7 +132,26 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, int hash_block(const char *algo_name, const void *data, unsigned int len, uint8_t *output, int *output_size); -#endif /* !USE_HOSTCC */ +#if CONFIG_IS_ENABLED(MBEDTLS_LIB) +static inline mbedtls_md_type_t hash_mbedtls_type(struct hash_algo *algo) +{ + return algo->md_type; +} +#else +static inline int hash_mbedtls_type(struct hash_algo *algo) +{ + return 0; +} +#endif + +#else /* USE_HOSTCC*/ + +static inline int hash_mbedtls_type(struct hash_algo *algo) +{ + return 0; +} + +#endif /* USE_HOSTCC */ /** * hash_lookup_algo() - Look up the hash_algo struct for an algorithm