|
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,48 +4628,16 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
|
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; |
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)]; |
4649 | 4632 |
|
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); |
4663 | 4635 |
|
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)
|
|
0 commit comments