]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
r8152: use SHA-256 library API instead of crypto_shash API
authorEric Biggers <ebiggers@google.com>
Mon, 28 Apr 2025 19:16:06 +0000 (12:16 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 2 May 2025 00:59:32 +0000 (17:59 -0700)
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.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://patch.msgid.link/20250428191606.856198-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/usb/Kconfig
drivers/net/usb/r8152.c

index 3c360d4f06352ede49fd17bac61a00d024a59d10..370b32fc2588088366bd9af541bb4fb8e7e4301f 100644 (file)
@@ -101,9 +101,7 @@ config USB_RTL8152
        select MII
        select PHYLIB
        select CRC32
-       select CRYPTO
-       select CRYPTO_HASH
-       select CRYPTO_SHA256
+       select CRYPTO_LIB_SHA256
        help
          This option adds support for Realtek RTL8152 based USB 2.0
          10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
index 2cab046749a922d9a9ead575bfcaefdc829706da..67f5d30ffcbaba85b07ba7554b98d892d3dda494 100644 (file)
@@ -26,7 +26,7 @@
 #include <linux/atomic.h>
 #include <linux/acpi.h>
 #include <linux/firmware.h>
-#include <crypto/hash.h>
+#include <crypto/sha2.h>
 #include <linux/usb/r8152.h>
 #include <net/gso.h>
 
@@ -4628,48 +4628,16 @@ out:
 static long rtl8152_fw_verify_checksum(struct r8152 *tp,
                                       struct fw_header *fw_hdr, size_t size)
 {
-       unsigned char checksum[sizeof(fw_hdr->checksum)];
-       struct crypto_shash *alg;
-       struct shash_desc *sdesc;
-       size_t len;
-       long rc;
-
-       alg = crypto_alloc_shash("sha256", 0, 0);
-       if (IS_ERR(alg)) {
-               rc = PTR_ERR(alg);
-               goto out;
-       }
-
-       if (crypto_shash_digestsize(alg) != sizeof(fw_hdr->checksum)) {
-               rc = -EFAULT;
-               dev_err(&tp->intf->dev, "digestsize incorrect (%u)\n",
-                       crypto_shash_digestsize(alg));
-               goto free_shash;
-       }
+       u8 checksum[sizeof(fw_hdr->checksum)];
 
-       len = sizeof(*sdesc) + crypto_shash_descsize(alg);
-       sdesc = kmalloc(len, GFP_KERNEL);
-       if (!sdesc) {
-               rc = -ENOMEM;
-               goto free_shash;
-       }
-       sdesc->tfm = alg;
-
-       len = size - sizeof(fw_hdr->checksum);
-       rc = crypto_shash_digest(sdesc, fw_hdr->version, len, checksum);
-       kfree(sdesc);
-       if (rc)
-               goto free_shash;
+       BUILD_BUG_ON(sizeof(checksum) != SHA256_DIGEST_SIZE);
+       sha256(fw_hdr->version, size - sizeof(checksum), checksum);
 
-       if (memcmp(fw_hdr->checksum, checksum, sizeof(fw_hdr->checksum))) {
+       if (memcmp(fw_hdr->checksum, checksum, sizeof(checksum))) {
                dev_err(&tp->intf->dev, "checksum fail\n");
-               rc = -EFAULT;
+               return -EFAULT;
        }
-
-free_shash:
-       crypto_free_shash(alg);
-out:
-       return rc;
+       return 0;
 }
 
 static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)