efi: use sha256() instead of open coding
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> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
9ea9c58b40
commit
2164960df8
|
@ -37,9 +37,8 @@ static const struct dmi_system_id * const embedded_fw_table[] = {
|
||||||
static int __init efi_check_md_for_embedded_firmware(
|
static int __init efi_check_md_for_embedded_firmware(
|
||||||
efi_memory_desc_t *md, const struct efi_embedded_fw_desc *desc)
|
efi_memory_desc_t *md, const struct efi_embedded_fw_desc *desc)
|
||||||
{
|
{
|
||||||
struct sha256_state sctx;
|
|
||||||
struct efi_embedded_fw *fw;
|
struct efi_embedded_fw *fw;
|
||||||
u8 sha256[32];
|
u8 hash[32];
|
||||||
u64 i, size;
|
u64 i, size;
|
||||||
u8 *map;
|
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))
|
if (memcmp(map + i, desc->prefix, EFI_EMBEDDED_FW_PREFIX_LEN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sha256_init(&sctx);
|
sha256(map + i, desc->length, hash);
|
||||||
sha256_update(&sctx, map + i, desc->length);
|
if (memcmp(hash, desc->sha256, 32) == 0)
|
||||||
sha256_final(&sctx, sha256);
|
|
||||||
if (memcmp(sha256, desc->sha256, 32) == 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((i + desc->length) > size) {
|
if ((i + desc->length) > size) {
|
||||||
|
|
Loading…
Reference in New Issue