From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Alexandru Gagniuc <mr.nuke.me@gmail.com>,
Andre Przywara <andre.przywara@arm.com>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Robert Marko <robert.marko@sartura.hr>,
Masahiro Yamada <masahiroy@kernel.org>,
Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Joe Hershberger <joe.hershberger@ni.com>
Subject: [PATCH v5 05/29] hash: Use Kconfig to enable hashing in host tools and SPL
Date: Sat, 25 Sep 2021 19:43:18 -0600 [thread overview]
Message-ID: <20210925194327.v5.5.Idf4bfa823b4e1a5b357e141a8496acece5051102@changeid> (raw)
In-Reply-To: <20210926014342.127913-1-sjg@chromium.org>
At present when building host tools, we force CONFIG_SHAxxx to be enabled
regardless of the board Kconfig setting. This is done in the image.h
header file.
For SPL we currently just assume the algorithm is desired if U-Boot proper
enables it.
Clean this up by adding new Kconfig options to enable hashing on the host,
relying on CONFIG_IS_ENABLED() to deal with the different builds.
Add new SPL Kconfigs for hardware-accelerated hashing, to maintain the
current settings.
This allows us to drop the image.h code and the I_WANT_MD5 hack.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v5:
- Drop I_WANT_MD5
- Use TOOLS_ instead of HOST_
Changes in v2:
- Add SPL_ Kconfigs also, since otherwise hashing algorithms drop from SPL
common/hash.c | 49 +++++++++++++++++++++++--------------------------
include/image.h | 5 -----
lib/Kconfig | 18 ++++++++++++++++++
tools/Kconfig | 25 +++++++++++++++++++++++++
4 files changed, 66 insertions(+), 31 deletions(-)
diff --git a/common/hash.c b/common/hash.c
index 6277fe65b3e..0fe65c959d0 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -25,6 +25,7 @@
#else
#include "mkimage.h"
#include <time.h>
+#include <linux/kconfig.h>
#endif /* !USE_HOSTCC*/
#include <hash.h>
@@ -41,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR;
static void reloc_update(void);
-#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA1) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
{
sha1_context *ctx = malloc(sizeof(sha1_context));
@@ -69,7 +70,7 @@ static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf,
}
#endif
-#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA256) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
{
sha256_context *ctx = malloc(sizeof(sha256_context));
@@ -97,7 +98,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
}
#endif
-#if defined(CONFIG_SHA384) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA384) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
static int hash_init_sha384(struct hash_algo *algo, void **ctxp)
{
sha512_context *ctx = malloc(sizeof(sha512_context));
@@ -125,7 +126,7 @@ static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void
}
#endif
-#if defined(CONFIG_SHA512) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA512) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
static int hash_init_sha512(struct hash_algo *algo, void **ctxp)
{
sha512_context *ctx = malloc(sizeof(sha512_context));
@@ -207,18 +208,13 @@ static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf,
return 0;
}
-#ifdef USE_HOSTCC
-# define I_WANT_MD5 1
-#else
-# define I_WANT_MD5 CONFIG_IS_ENABLED(MD5)
-#endif
/*
* These are the hash algorithms we support. If we have hardware acceleration
* is enable we will use that, otherwise a software version of the algorithm.
* Note that algorithm names must be in lower case.
*/
static struct hash_algo hash_algo[] = {
-#if I_WANT_MD5
+#if CONFIG_IS_ENABLED(MD5)
{
.name = "md5",
.digest_size = MD5_SUM_LEN,
@@ -226,17 +222,17 @@ static struct hash_algo hash_algo[] = {
.hash_func_ws = md5_wd,
},
#endif
-#ifdef CONFIG_SHA1
+#if CONFIG_IS_ENABLED(SHA1)
{
.name = "sha1",
.digest_size = SHA1_SUM_LEN,
.chunk_size = CHUNKSZ_SHA1,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws = hw_sha1,
#else
.hash_func_ws = sha1_csum_wd,
#endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init = hw_sha_init,
.hash_update = hw_sha_update,
.hash_finish = hw_sha_finish,
@@ -247,17 +243,17 @@ static struct hash_algo hash_algo[] = {
#endif
},
#endif
-#ifdef CONFIG_SHA256
+#if CONFIG_IS_ENABLED(SHA256)
{
.name = "sha256",
.digest_size = SHA256_SUM_LEN,
.chunk_size = CHUNKSZ_SHA256,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws = hw_sha256,
#else
.hash_func_ws = sha256_csum_wd,
#endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init = hw_sha_init,
.hash_update = hw_sha_update,
.hash_finish = hw_sha_finish,
@@ -268,17 +264,17 @@ static struct hash_algo hash_algo[] = {
#endif
},
#endif
-#ifdef CONFIG_SHA384
+#if CONFIG_IS_ENABLED(SHA384)
{
.name = "sha384",
.digest_size = SHA384_SUM_LEN,
.chunk_size = CHUNKSZ_SHA384,
-#ifdef CONFIG_SHA512_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA512_HW_ACCEL)
.hash_func_ws = hw_sha384,
#else
.hash_func_ws = sha384_csum_wd,
#endif
-#if defined(CONFIG_SHA512_HW_ACCEL) && defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) && CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init = hw_sha_init,
.hash_update = hw_sha_update,
.hash_finish = hw_sha_finish,
@@ -289,17 +285,17 @@ static struct hash_algo hash_algo[] = {
#endif
},
#endif
-#ifdef CONFIG_SHA512
+#if CONFIG_IS_ENABLED(SHA512)
{
.name = "sha512",
.digest_size = SHA512_SUM_LEN,
.chunk_size = CHUNKSZ_SHA512,
-#ifdef CONFIG_SHA512_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA512_HW_ACCEL)
.hash_func_ws = hw_sha512,
#else
.hash_func_ws = sha512_csum_wd,
#endif
-#if defined(CONFIG_SHA512_HW_ACCEL) && defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) && CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init = hw_sha_init,
.hash_update = hw_sha_update,
.hash_finish = hw_sha_finish,
@@ -331,9 +327,9 @@ static struct hash_algo hash_algo[] = {
};
/* Try to minimize code size for boards that don't want much hashing */
-#if defined(CONFIG_SHA256) || defined(CONFIG_CMD_SHA1SUM) || \
- defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_CMD_HASH) || \
- defined(CONFIG_SHA384) || defined(CONFIG_SHA512)
+#if CONFIG_IS_ENABLED(SHA256) || CONFIG_IS_ENABLED(CMD_SHA1SUM) || \
+ CONFIG_IS_ENABLED(CRC32_VERIFY) || CONFIG_IS_ENABLED(CMD_HASH) || \
+ CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512)
#define multi_hash() 1
#else
#define multi_hash() 0
@@ -438,7 +434,8 @@ int hash_block(const char *algo_name, const void *data, unsigned int len,
return 0;
}
-#if defined(CONFIG_CMD_HASH) || defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)
+#if !defined(CONFIG_SPL_BUILD) && (defined(CONFIG_CMD_HASH) || \
+ defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32))
/**
* store_result: Store the resulting sum to an address or variable
*
diff --git a/include/image.h b/include/image.h
index 73a763a6936..03857f4b500 100644
--- a/include/image.h
+++ b/include/image.h
@@ -31,11 +31,6 @@ struct fdt_region;
#define IMAGE_ENABLE_OF_LIBFDT 1
#define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
#define CONFIG_FIT_RSASSA_PSS 1
-#define CONFIG_MD5
-#define CONFIG_SHA1
-#define CONFIG_SHA256
-#define CONFIG_SHA384
-#define CONFIG_SHA512
#define IMAGE_ENABLE_IGNORE 0
#define IMAGE_INDENT_STRING ""
diff --git a/lib/Kconfig b/lib/Kconfig
index 7899e756f99..64765acfa61 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -438,6 +438,24 @@ config SPL_SHA384
The SHA384 algorithm produces a 384-bit (48-byte) hash value
(digest).
+config SPL_SHA_HW_ACCEL
+ bool "Enable hardware acceleration for SHA hash functions"
+ default y if SHA_HW_ACCEL
+ help
+ This option enables hardware acceleration for the SHA1 and SHA256
+ hashing algorithms. This affects the 'hash' command and also the
+ hash_lookup_algo() function.
+
+config SPL_SHA_PROG_HW_ACCEL
+ bool "Enable Progressive hashing support using hardware in SPL"
+ depends on SHA_PROG_HW_ACCEL
+ default y
+ help
+ This option enables hardware-acceleration for SHA progressive
+ hashing.
+ Data can be streamed in a block at a time and the hashing is
+ performed in hardware.
+
endif
if SHA_HW_ACCEL
diff --git a/tools/Kconfig b/tools/Kconfig
index ea986ab0479..6ffc2c0aa31 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -45,4 +45,29 @@ config TOOLS_FIT_SIGNATURE_MAX_SIZE
depends on TOOLS_FIT_SIGNATURE
default 0x10000000
+config TOOLS_MD5
+ def_bool y
+ help
+ Enable MD5 support in the tools builds
+
+config TOOLS_SHA1
+ def_bool y
+ help
+ Enable SHA1 support in the tools builds
+
+config TOOLS_SHA256
+ def_bool y
+ help
+ Enable SHA256 support in the tools builds
+
+config TOOLS_SHA384
+ def_bool y
+ help
+ Enable SHA384 support in the tools builds
+
+config TOOLS_SHA512
+ def_bool y
+ help
+ Enable SHA512 support in the tools builds
+
endmenu
--
2.33.0.685.g46640cef36-goog
next prev parent reply other threads:[~2021-09-26 1:45 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-26 1:43 [PATCH v5 00/29] image: Reduce #ifdefs and ad-hoc defines in image code (Part B) Simon Glass
2021-09-26 1:43 ` [PATCH v5 01/29] compiler: Rename host_build() to tools_build() Simon Glass
2021-10-05 18:09 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 02/29] kconfig: Add tools support to CONFIG_IS_ENABLED() Simon Glass
2021-09-27 16:11 ` Alex G.
2021-09-27 16:50 ` Masahiro Yamada
2021-09-27 20:17 ` Simon Glass
2021-09-27 20:17 ` Simon Glass
2021-10-05 18:11 ` Alex G.
2021-10-07 0:26 ` Tom Rini
2021-10-07 2:49 ` Simon Glass
2021-10-07 2:52 ` Tom Rini
2021-10-07 13:32 ` Simon Glass
2021-10-07 13:42 ` Tom Rini
2021-10-07 18:02 ` Simon Glass
2021-10-07 18:30 ` Tom Rini
2021-10-07 18:50 ` Simon Glass
2021-10-07 19:32 ` Alex G.
2021-10-07 19:39 ` Tom Rini
2021-10-07 20:33 ` Alex G.
2021-10-07 21:04 ` Tom Rini
2021-10-07 21:15 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 03/29] image: Add Kconfig options for FIT in the tools build Simon Glass
2021-10-05 18:17 ` Alex G.
2021-10-05 18:17 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 04/29] spl: cypto: Bring back SPL_ versions of SHA Simon Glass
2021-10-05 18:19 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` Simon Glass [this message]
2021-09-27 15:53 ` [PATCH v5 05/29] hash: Use Kconfig to enable hashing in host tools and SPL Alex G.
2021-09-27 16:06 ` Simon Glass
2021-09-27 16:12 ` Alex G.
2021-10-05 18:21 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 06/29] hash: Drop some #ifdefs in hash.c Simon Glass
2021-10-05 18:24 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 07/29] image: Drop IMAGE_ENABLE_FIT Simon Glass
2021-10-05 18:26 ` Alex G.
2021-10-09 1:39 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 08/29] image: Drop IMAGE_ENABLE_OF_LIBFDT Simon Glass
2021-10-05 18:27 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 09/29] image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host Simon Glass
2021-10-05 18:29 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 10/29] image: Use Kconfig to enable FIT_RSASSA_PSS " Simon Glass
2021-10-05 18:32 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 11/29] image: Use the correct checks for CRC32 Simon Glass
2021-10-05 18:34 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 12/29] image: Drop IMAGE_BOOT_GET_CMDLINE Simon Glass
2021-10-05 18:36 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 13/29] image: Drop IMAGE_OF_BOARD_SETUP Simon Glass
2021-10-05 18:57 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 14/29] image: Drop IMAGE_OF_SYSTEM_SETUP Simon Glass
2021-10-05 18:58 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 15/29] image: Drop IMAGE_ENABLE_IGNORE Simon Glass
2021-10-05 18:58 ` Alex G.
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 16/29] efi: Correct dependency on FIT_SIGNATURE Simon Glass
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 19/29] image: Tidy up fit_unsupported_reset() Simon Glass
2021-10-09 1:40 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 20/29] image: Drop unnecessary #ifdefs from image.h Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 21/29] image: Drop #ifdefs for fit_print_contents() Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 22/29] image: Drop most #ifdefs in image-board.c Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 23/29] image: Reduce variable scope in boot_get_ramdisk() Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 24/29] image: Split up boot_get_ramdisk() Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 25/29] image: Remove #ifdefs from select_ramdisk() Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-12-17 17:40 ` Neil Armstrong
2021-09-26 1:43 ` [PATCH v5 26/29] image: Remove some #ifdefs from image-fit and image-fit-sig Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 27/29] image: Reduce variable scope in boot_get_fdt() Simon Glass
2021-10-09 1:41 ` Tom Rini
2021-09-26 1:43 ` [PATCH v5 28/29] image: Split up boot_get_fdt() Simon Glass
2021-10-09 1:41 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210925194327.v5.5.Idf4bfa823b4e1a5b357e141a8496acece5051102@changeid \
--to=sjg@chromium.org \
--cc=andre.przywara@arm.com \
--cc=joe.hershberger@ni.com \
--cc=masahiroy@kernel.org \
--cc=mr.nuke.me@gmail.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=robert.marko@sartura.hr \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).