Skip to content

Commit 7a4f15c

Browse files
ebiggerskuba-moo
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7840e4d commit 7a4f15c

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

drivers/net/usb/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ config USB_RTL8152
101101
select MII
102102
select PHYLIB
103103
select CRC32
104-
select CRYPTO
105-
select CRYPTO_HASH
106-
select CRYPTO_SHA256
104+
select CRYPTO_LIB_SHA256
107105
help
108106
This option adds support for Realtek RTL8152 based USB 2.0
109107
10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000

drivers/net/usb/r8152.c

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <linux/atomic.h>
2727
#include <linux/acpi.h>
2828
#include <linux/firmware.h>
29-
#include <crypto/hash.h>
29+
#include <crypto/sha2.h>
3030
#include <linux/usb/r8152.h>
3131
#include <net/gso.h>
3232

@@ -4628,48 +4628,16 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
46284628
static long rtl8152_fw_verify_checksum(struct r8152 *tp,
46294629
struct fw_header *fw_hdr, size_t size)
46304630
{
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;
4636-
4637-
alg = crypto_alloc_shash("sha256", 0, 0);
4638-
if (IS_ERR(alg)) {
4639-
rc = PTR_ERR(alg);
4640-
goto out;
4641-
}
4642-
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-
}
4631+
u8 checksum[sizeof(fw_hdr->checksum)];
46494632

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;
4633+
BUILD_BUG_ON(sizeof(checksum) != SHA256_DIGEST_SIZE);
4634+
sha256(fw_hdr->version, size - sizeof(checksum), checksum);
46634635

4664-
if (memcmp(fw_hdr->checksum, checksum, sizeof(fw_hdr->checksum))) {
4636+
if (memcmp(fw_hdr->checksum, checksum, sizeof(checksum))) {
46654637
dev_err(&tp->intf->dev, "checksum fail\n");
4666-
rc = -EFAULT;
4638+
return -EFAULT;
46674639
}
4668-
4669-
free_shash:
4670-
crypto_free_shash(alg);
4671-
out:
4672-
return rc;
4640+
return 0;
46734641
}
46744642

46754643
static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)

0 commit comments

Comments
 (0)