All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-efi@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH v2 3/5] efi: use sha256() instead of open coding
Date: Wed,  8 Jul 2020 09:39:41 -0700	[thread overview]
Message-ID: <20200708163943.52071-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20200708163943.52071-1-ebiggers@kernel.org>

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().

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Hans de Goede <hdegoede@redhat.com>
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


  parent reply	other threads:[~2020-07-08 16:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08 16:39 [MPTCP] [PATCH v2 0/5] crypto: add sha256() function Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 ` [PATCH v2 1/5] crypto: sparc - rename sha256 to sha256_alg Eric Biggers
2020-07-08 16:39   ` Eric Biggers
2020-07-08 16:39 ` Eric Biggers [this message]
2020-07-08 16:39 ` [PATCH v2 5/5] ASoC: cros_ec_codec: use sha256() instead of open coding Eric Biggers
2020-07-08 16:39   ` Eric Biggers
2020-07-08 16:39 [MPTCP] [PATCH v2 2/5] crypto: lib/sha256 - add sha256() function Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-08 16:39 [MPTCP] [PATCH v2 4/5] mptcp: use sha256() instead of open coding Eric Biggers
2020-07-08 16:39 ` Eric Biggers
2020-07-16 11:54 [MPTCP] Re: [PATCH v2 0/5] crypto: add sha256() function Herbert Xu
2020-07-16 11:54 ` Herbert Xu
2020-07-16 11:54 ` Herbert Xu
2020-07-16 11:54 ` Herbert Xu

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=20200708163943.52071-4-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=ardb@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.