Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

r8152: use SHA-256 library API instead of crypto_shash API

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>

authored by

Eric Biggers and committed by
Jakub Kicinski
7a4f15ca 7840e4d6

+8 -42
+1 -3
drivers/net/usb/Kconfig
··· 101 101 select MII 102 102 select PHYLIB 103 103 select CRC32 104 - select CRYPTO 105 - select CRYPTO_HASH 106 - select CRYPTO_SHA256 104 + select CRYPTO_LIB_SHA256 107 105 help 108 106 This option adds support for Realtek RTL8152 based USB 2.0 109 107 10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
+7 -39
drivers/net/usb/r8152.c
··· 26 26 #include <linux/atomic.h> 27 27 #include <linux/acpi.h> 28 28 #include <linux/firmware.h> 29 - #include <crypto/hash.h> 29 + #include <crypto/sha2.h> 30 30 #include <linux/usb/r8152.h> 31 31 #include <net/gso.h> 32 32 ··· 4628 4628 static long rtl8152_fw_verify_checksum(struct r8152 *tp, 4629 4629 struct fw_header *fw_hdr, size_t size) 4630 4630 { 4631 - unsigned char checksum[sizeof(fw_hdr->checksum)]; 4632 - struct crypto_shash *alg; 4633 - struct shash_desc *sdesc; 4634 - size_t len; 4635 - long rc; 4631 + u8 checksum[sizeof(fw_hdr->checksum)]; 4636 4632 4637 - alg = crypto_alloc_shash("sha256", 0, 0); 4638 - if (IS_ERR(alg)) { 4639 - rc = PTR_ERR(alg); 4640 - goto out; 4641 - } 4633 + BUILD_BUG_ON(sizeof(checksum) != SHA256_DIGEST_SIZE); 4634 + sha256(fw_hdr->version, size - sizeof(checksum), checksum); 4642 4635 4643 - if (crypto_shash_digestsize(alg) != sizeof(fw_hdr->checksum)) { 4644 - rc = -EFAULT; 4645 - dev_err(&tp->intf->dev, "digestsize incorrect (%u)\n", 4646 - crypto_shash_digestsize(alg)); 4647 - goto free_shash; 4648 - } 4649 - 4650 - len = sizeof(*sdesc) + crypto_shash_descsize(alg); 4651 - sdesc = kmalloc(len, GFP_KERNEL); 4652 - if (!sdesc) { 4653 - rc = -ENOMEM; 4654 - goto free_shash; 4655 - } 4656 - sdesc->tfm = alg; 4657 - 4658 - len = size - sizeof(fw_hdr->checksum); 4659 - rc = crypto_shash_digest(sdesc, fw_hdr->version, len, checksum); 4660 - kfree(sdesc); 4661 - if (rc) 4662 - goto free_shash; 4663 - 4664 - if (memcmp(fw_hdr->checksum, checksum, sizeof(fw_hdr->checksum))) { 4636 + if (memcmp(fw_hdr->checksum, checksum, sizeof(checksum))) { 4665 4637 dev_err(&tp->intf->dev, "checksum fail\n"); 4666 - rc = -EFAULT; 4638 + return -EFAULT; 4667 4639 } 4668 - 4669 - free_shash: 4670 - crypto_free_shash(alg); 4671 - out: 4672 - return rc; 4640 + return 0; 4673 4641 } 4674 4642 4675 4643 static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)