* [PATCH 0/4] crypto: add sha256() function
@ 2020-07-07 18:58 Eric Biggers
2020-07-07 18:58 ` [PATCH 1/4] crypto: lib/sha256 - " Eric Biggers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Biggers @ 2020-07-07 18:58 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: alsa-devel, Ard Biesheuvel, Cheng-Yi Chiang,
Enric Balletbo i Serra, Guenter Roeck, Hans de Goede, linux-efi,
Mat Martineau, Matthieu Baerts, mptcp, Tzung-Bi Shih
This series adds a function sha256() to the sha256 library so that users
who want to compute a hash in one step can just call sha256() instead of
sha256_init() + sha256_update() + sha256_final().
Patches 2-4 then convert some users to use it.
Eric Biggers (4):
crypto: lib/sha256 - add sha256() function
efi: use sha256() instead of open coding
mptcp: use sha256() instead of open coding
ASoC: cros_ec_codec: use sha256() instead of open coding
drivers/firmware/efi/embedded-firmware.c | 9 +++-----
include/crypto/sha.h | 1 +
lib/crypto/sha256.c | 10 +++++++++
net/mptcp/crypto.c | 15 +++----------
sound/soc/codecs/cros_ec_codec.c | 27 ++----------------------
5 files changed, 19 insertions(+), 43 deletions(-)
base-commit: 57c8aa43b9f272c382c253573c82be5cb68fe22d
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] crypto: lib/sha256 - add sha256() function
2020-07-07 18:58 [PATCH 0/4] crypto: add sha256() function Eric Biggers
@ 2020-07-07 18:58 ` Eric Biggers
2020-07-07 18:58 ` [PATCH 2/4] efi: use sha256() instead of open coding Eric Biggers
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2020-07-07 18:58 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: alsa-devel, Ard Biesheuvel, Cheng-Yi Chiang,
Enric Balletbo i Serra, Guenter Roeck, Hans de Goede, linux-efi,
Mat Martineau, Matthieu Baerts, mptcp, Tzung-Bi Shih
From: Eric Biggers <ebiggers@google.com>
Add a function sha256() which computes a SHA-256 digest in one step,
combining sha256_init() + sha256_update() + sha256_final().
This is similar to how we also have blake2s().
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
include/crypto/sha.h | 1 +
lib/crypto/sha256.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/include/crypto/sha.h b/include/crypto/sha.h
index 10753ff71d46..4ff3da816630 100644
--- a/include/crypto/sha.h
+++ b/include/crypto/sha.h
@@ -147,6 +147,7 @@ static inline void sha256_init(struct sha256_state *sctx)
}
void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len);
void sha256_final(struct sha256_state *sctx, u8 *out);
+void sha256(const u8 *data, unsigned int len, u8 *out);
static inline void sha224_init(struct sha256_state *sctx)
{
diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c
index 2e621697c5c3..2321f6cb322f 100644
--- a/lib/crypto/sha256.c
+++ b/lib/crypto/sha256.c
@@ -280,4 +280,14 @@ void sha224_final(struct sha256_state *sctx, u8 *out)
}
EXPORT_SYMBOL(sha224_final);
+void sha256(const u8 *data, unsigned int len, u8 *out)
+{
+ struct sha256_state sctx;
+
+ sha256_init(&sctx);
+ sha256_update(&sctx, data, len);
+ sha256_final(&sctx, out);
+}
+EXPORT_SYMBOL(sha256);
+
MODULE_LICENSE("GPL");
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] efi: use sha256() instead of open coding
2020-07-07 18:58 [PATCH 0/4] crypto: add sha256() function Eric Biggers
2020-07-07 18:58 ` [PATCH 1/4] crypto: lib/sha256 - " Eric Biggers
@ 2020-07-07 18:58 ` Eric Biggers
2020-07-08 5:47 ` [PATCH 0/4] crypto: add sha256() function Ard Biesheuvel
2020-07-08 11:01 ` Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2020-07-07 18:58 UTC (permalink / raw)
To: linux-crypto, Herbert Xu; +Cc: linux-efi, Ard Biesheuvel, Hans de Goede
From: Eric Biggers <ebiggers@google.com>
Now that there's a function that calculates the SHA-256 digest of a
buffer in one step, use it instead of sha256_init() + sha256_update() +
sha256_final().
Cc: linux-efi@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
drivers/firmware/efi/embedded-firmware.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/firmware/efi/embedded-firmware.c b/drivers/firmware/efi/embedded-firmware.c
index a1b199de9006..e97a9c9d010c 100644
--- a/drivers/firmware/efi/embedded-firmware.c
+++ b/drivers/firmware/efi/embedded-firmware.c
@@ -37,9 +37,8 @@ static const struct dmi_system_id * const embedded_fw_table[] = {
static int __init efi_check_md_for_embedded_firmware(
efi_memory_desc_t *md, const struct efi_embedded_fw_desc *desc)
{
- struct sha256_state sctx;
struct efi_embedded_fw *fw;
- u8 sha256[32];
+ u8 hash[32];
u64 i, size;
u8 *map;
@@ -54,10 +53,8 @@ static int __init efi_check_md_for_embedded_firmware(
if (memcmp(map + i, desc->prefix, EFI_EMBEDDED_FW_PREFIX_LEN))
continue;
- sha256_init(&sctx);
- sha256_update(&sctx, map + i, desc->length);
- sha256_final(&sctx, sha256);
- if (memcmp(sha256, desc->sha256, 32) == 0)
+ sha256(map + i, desc->length, hash);
+ if (memcmp(hash, desc->sha256, 32) == 0)
break;
}
if ((i + desc->length) > size) {
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/4] crypto: add sha256() function
2020-07-07 18:58 [PATCH 0/4] crypto: add sha256() function Eric Biggers
2020-07-07 18:58 ` [PATCH 1/4] crypto: lib/sha256 - " Eric Biggers
2020-07-07 18:58 ` [PATCH 2/4] efi: use sha256() instead of open coding Eric Biggers
@ 2020-07-08 5:47 ` Ard Biesheuvel
2020-07-08 11:01 ` Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2020-07-08 5:47 UTC (permalink / raw)
To: Eric Biggers
Cc: Linux Crypto Mailing List, Herbert Xu, ALSA development,
Cheng-Yi Chiang, Enric Balletbo i Serra, Guenter Roeck,
Hans de Goede, linux-efi, Mat Martineau, Matthieu Baerts, mptcp,
Tzung-Bi Shih
On Tue, 7 Jul 2020 at 21:59, Eric Biggers <ebiggers@kernel.org> wrote:
>
> This series adds a function sha256() to the sha256 library so that users
> who want to compute a hash in one step can just call sha256() instead of
> sha256_init() + sha256_update() + sha256_final().
>
> Patches 2-4 then convert some users to use it.
>
> Eric Biggers (4):
> crypto: lib/sha256 - add sha256() function
> efi: use sha256() instead of open coding
> mptcp: use sha256() instead of open coding
> ASoC: cros_ec_codec: use sha256() instead of open coding
>
For the series,
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Feel free to take the EFI patch through the crypto tree.
> drivers/firmware/efi/embedded-firmware.c | 9 +++-----
> include/crypto/sha.h | 1 +
> lib/crypto/sha256.c | 10 +++++++++
> net/mptcp/crypto.c | 15 +++----------
> sound/soc/codecs/cros_ec_codec.c | 27 ++----------------------
> 5 files changed, 19 insertions(+), 43 deletions(-)
>
>
> base-commit: 57c8aa43b9f272c382c253573c82be5cb68fe22d
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/4] crypto: add sha256() function
2020-07-07 18:58 [PATCH 0/4] crypto: add sha256() function Eric Biggers
` (2 preceding siblings ...)
2020-07-08 5:47 ` [PATCH 0/4] crypto: add sha256() function Ard Biesheuvel
@ 2020-07-08 11:01 ` Hans de Goede
3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2020-07-08 11:01 UTC (permalink / raw)
To: Eric Biggers, linux-crypto, Herbert Xu
Cc: alsa-devel, Ard Biesheuvel, Cheng-Yi Chiang,
Enric Balletbo i Serra, Guenter Roeck, linux-efi, Mat Martineau,
Matthieu Baerts, mptcp, Tzung-Bi Shih
Hi,
On 7/7/20 8:58 PM, Eric Biggers wrote:
> This series adds a function sha256() to the sha256 library so that users
> who want to compute a hash in one step can just call sha256() instead of
> sha256_init() + sha256_update() + sha256_final().
>
> Patches 2-4 then convert some users to use it.
>
> Eric Biggers (4):
> crypto: lib/sha256 - add sha256() function
> efi: use sha256() instead of open coding
> mptcp: use sha256() instead of open coding
> ASoC: cros_ec_codec: use sha256() instead of open coding
>
> drivers/firmware/efi/embedded-firmware.c | 9 +++-----
> include/crypto/sha.h | 1 +
> lib/crypto/sha256.c | 10 +++++++++
> net/mptcp/crypto.c | 15 +++----------
> sound/soc/codecs/cros_ec_codec.c | 27 ++----------------------
> 5 files changed, 19 insertions(+), 43 deletions(-)
>
>
> base-commit: 57c8aa43b9f272c382c253573c82be5cb68fe22d
I've done some quick tests on this series to make sure that
the efi embedded-firmware support did not regress.
That still works fine, so this series is;
Tested-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-08 11:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 18:58 [PATCH 0/4] crypto: add sha256() function Eric Biggers
2020-07-07 18:58 ` [PATCH 1/4] crypto: lib/sha256 - " Eric Biggers
2020-07-07 18:58 ` [PATCH 2/4] efi: use sha256() instead of open coding Eric Biggers
2020-07-08 5:47 ` [PATCH 0/4] crypto: add sha256() function Ard Biesheuvel
2020-07-08 11:01 ` Hans de Goede
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).