* [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API
@ 2025-04-28 19:09 Eric Biggers
2025-04-29 5:54 ` Greg Kroah-Hartman
2025-04-30 20:08 ` Danilo Krummrich
0 siblings, 2 replies; 4+ messages in thread
From: Eric Biggers @ 2025-04-28 19:09 UTC (permalink / raw)
To: Luis Chamberlain, Russ Weight, Danilo Krummrich,
Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel
Cc: linux-crypto, Arnd Bergmann, Amadeusz Sławiński
From: Eric Biggers <ebiggers@google.com>
This user of SHA-256 does not support any other algorithm, so the
crypto_shash abstraction provides no value. Just use the SHA-256
library API instead, which is much simpler and easier to use.
Also take advantage of printk's built-in hex conversion using %*phN.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
This patch is targeting the firmware_loader tree for 6.16.
drivers/base/firmware_loader/Kconfig | 4 +---
drivers/base/firmware_loader/main.c | 34 ++++------------------------
2 files changed, 5 insertions(+), 33 deletions(-)
diff --git a/drivers/base/firmware_loader/Kconfig b/drivers/base/firmware_loader/Kconfig
index a037016742651..752b9a9bea038 100644
--- a/drivers/base/firmware_loader/Kconfig
+++ b/drivers/base/firmware_loader/Kconfig
@@ -1,12 +1,11 @@
# SPDX-License-Identifier: GPL-2.0
menu "Firmware loader"
config FW_LOADER
tristate "Firmware loading facility" if EXPERT
- select CRYPTO_HASH if FW_LOADER_DEBUG
- select CRYPTO_SHA256 if FW_LOADER_DEBUG
+ select CRYPTO_LIB_SHA256 if FW_LOADER_DEBUG
default y
help
This enables the firmware loading facility in the kernel. The kernel
will first look for built-in firmware, if it has any. Next, it will
look for the requested firmware in a series of filesystem paths:
@@ -26,11 +25,10 @@ config FW_LOADER
You also want to be sure to enable this built-in if you are going to
enable built-in firmware (CONFIG_EXTRA_FIRMWARE).
config FW_LOADER_DEBUG
bool "Log filenames and checksums for loaded firmware"
- depends on CRYPTO = FW_LOADER || CRYPTO=y
depends on DYNAMIC_DEBUG
depends on FW_LOADER
default FW_LOADER
help
Select this option to use dynamic debug to log firmware filenames and
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index cb0912ea3e627..44486b2c71728 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -804,45 +804,19 @@ static void fw_abort_batch_reqs(struct firmware *fw)
fw_state_aborted(fw_priv);
mutex_unlock(&fw_lock);
}
#if defined(CONFIG_FW_LOADER_DEBUG)
-#include <crypto/hash.h>
#include <crypto/sha2.h>
static void fw_log_firmware_info(const struct firmware *fw, const char *name, struct device *device)
{
- struct shash_desc *shash;
- struct crypto_shash *alg;
- u8 *sha256buf;
- char *outbuf;
+ u8 digest[SHA256_DIGEST_SIZE];
- alg = crypto_alloc_shash("sha256", 0, 0);
- if (IS_ERR(alg))
- return;
-
- sha256buf = kmalloc(SHA256_DIGEST_SIZE, GFP_KERNEL);
- outbuf = kmalloc(SHA256_BLOCK_SIZE + 1, GFP_KERNEL);
- shash = kmalloc(sizeof(*shash) + crypto_shash_descsize(alg), GFP_KERNEL);
- if (!sha256buf || !outbuf || !shash)
- goto out_free;
-
- shash->tfm = alg;
-
- if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0)
- goto out_free;
-
- for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
- sprintf(&outbuf[i * 2], "%02x", sha256buf[i]);
- outbuf[SHA256_BLOCK_SIZE] = 0;
- dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf);
-
-out_free:
- kfree(shash);
- kfree(outbuf);
- kfree(sha256buf);
- crypto_free_shash(alg);
+ sha256(fw->data, fw->size, digest);
+ dev_dbg(device, "Loaded FW: %s, sha256: %*phN\n",
+ name, SHA256_DIGEST_SIZE, digest);
}
#else
static void fw_log_firmware_info(const struct firmware *fw, const char *name,
struct device *device)
{}
base-commit: 33035b665157558254b3c21c3f049fd728e72368
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API
2025-04-28 19:09 [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API Eric Biggers
@ 2025-04-29 5:54 ` Greg Kroah-Hartman
2025-04-29 16:42 ` Eric Biggers
2025-04-30 20:08 ` Danilo Krummrich
1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-04-29 5:54 UTC (permalink / raw)
To: Eric Biggers
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich,
Rafael J . Wysocki, linux-kernel, linux-crypto, Arnd Bergmann,
Amadeusz Sławiński
On Mon, Apr 28, 2025 at 12:09:09PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> This user of SHA-256 does not support any other algorithm, so the
> crypto_shash abstraction provides no value. Just use the SHA-256
> library API instead, which is much simpler and easier to use.
>
> Also take advantage of printk's built-in hex conversion using %*phN.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>
> This patch is targeting the firmware_loader tree for 6.16.
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API
2025-04-29 5:54 ` Greg Kroah-Hartman
@ 2025-04-29 16:42 ` Eric Biggers
0 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2025-04-29 16:42 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich,
Rafael J . Wysocki, linux-kernel, linux-crypto, Arnd Bergmann,
Amadeusz Sławiński
On Tue, Apr 29, 2025 at 07:54:42AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Apr 28, 2025 at 12:09:09PM -0700, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> >
> > This user of SHA-256 does not support any other algorithm, so the
> > crypto_shash abstraction provides no value. Just use the SHA-256
> > library API instead, which is much simpler and easier to use.
> >
> > Also take advantage of printk's built-in hex conversion using %*phN.
> >
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > ---
> >
> > This patch is targeting the firmware_loader tree for 6.16.
>
>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg, it looks like you normally take patches to this file. You can go ahead
and take it if you want. Thanks!
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API
2025-04-28 19:09 [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API Eric Biggers
2025-04-29 5:54 ` Greg Kroah-Hartman
@ 2025-04-30 20:08 ` Danilo Krummrich
1 sibling, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2025-04-30 20:08 UTC (permalink / raw)
To: Eric Biggers
Cc: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman,
Rafael J . Wysocki, linux-kernel, linux-crypto, Arnd Bergmann,
Amadeusz Sławiński
On Mon, Apr 28, 2025 at 12:09:09PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> This user of SHA-256 does not support any other algorithm, so the
> crypto_shash abstraction provides no value. Just use the SHA-256
> library API instead, which is much simpler and easier to use.
>
> Also take advantage of printk's built-in hex conversion using %*phN.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
Applied to driver-core-testing, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-30 20:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 19:09 [PATCH] firmware_loader: use SHA-256 library API instead of crypto_shash API Eric Biggers
2025-04-29 5:54 ` Greg Kroah-Hartman
2025-04-29 16:42 ` Eric Biggers
2025-04-30 20:08 ` Danilo Krummrich
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).