[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250429050430.GA7003@sol.localdomain>
Date: Mon, 28 Apr 2025 22:04:30 -0700
From: Eric Biggers <ebiggers@...nel.org>
To: Artur Rojek <artur@...clusive.pl>
Cc: Johannes Berg <johannes@...solutions.net>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, linux-wireless@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
Jakub Klama <jakub@...clusive.pl>,
Wojciech Kloska <wojciech@...clusive.pl>,
Ulf Axelsson <ulf.axelsson@...dicsemi.no>
Subject: Re: [RFC PATCH 1/2] net: wireless: Add Nordic nRF70 series Wi-Fi
driver
On Mon, Mar 24, 2025 at 10:10:44PM +0100, Artur Rojek wrote:
> +static int nrf70_verify_firmware(struct device *dev,
> + const struct nrf70_fw_header *fw)
> +{
> + struct crypto_shash *alg;
> + u8 hash[NRF70_FW_HASH_LEN];
> + int ret;
> +
> + alg = crypto_alloc_shash("sha256", 0, 0);
> + if (IS_ERR(alg)) {
> + ret = PTR_ERR(alg);
> + dev_err(dev, "Unable to allocate shash memory: %d\n", ret);
> + goto out;
> + };
> +
> + if (crypto_shash_digestsize(alg) != NRF70_FW_HASH_LEN) {
> + dev_err(dev, "Incorrect digest size\n");
> + ret = -EFAULT;
> + goto out;
> + }
> +
> + ret = crypto_shash_tfm_digest(alg, fw->data, fw->length, hash);
> + if (ret) {
> + dev_err(dev, "Unable to compute hash\n");
> + goto out;
> + }
> +
> + if (memcmp(fw->hash, hash, sizeof(hash))) {
> + dev_err(dev, "Invalid firmware checksum\n");
> + ret = -EFAULT;
> + }
> +
> +out:
> + crypto_free_shash(alg);
> +
> + return ret;
> +}
You can just use sha256() here (and select CRYPTO_LIB_SHA256 from your kconfig
option). It's much simpler than crypto_shash.
- Eric
Powered by blists - more mailing lists