[PATCH 02/10] nvme: add nvme_auth_generate_psk()
Christoph Hellwig
hch at lst.de
Tue Jan 28 00:53:36 PST 2025
> + * Generate a PSK for TLS as specified in NVMe base specification, section 8.13.5.9:
Please fix your comment to stay in 80 characters. The line wrapping
here makes the text almost unreadable.
> +int nvme_auth_generate_psk(u8 hmac_id, u8 *skey, size_t skey_len,
> + u8 *c1, u8 *c2, size_t hash_len, u8 **ret_psk,size_t *ret_len)
Missing whitespace before the last size_t.
> +{
> + struct crypto_shash *tfm;
> + struct shash_desc *shash;
> + u8 *psk;
> + const char *hmac_name;
> + int ret, psk_len;
> +
> + if (!c1 || !c2) {
> + pr_warn("%s: invalid parameter\n", __func__);
> + return -EINVAL;
> + }
No a very useful error message. Given that this is a violation of
the API contract either a WARN_ON_ONCE or just letting the crypto
algorithm fail should be fine.
> + tfm = crypto_alloc_shash(hmac_name, 0, 0);
> + if (IS_ERR(tfm))
> + return PTR_ERR(tfm);
> +
> + psk_len = crypto_shash_digestsize(tfm);
> + psk = kzalloc(psk_len, GFP_KERNEL);
> + if (!psk) {
> + ret = -ENOMEM;
> + goto out_free_tfm;
> + }
> +
> + shash = kmalloc(sizeof(struct shash_desc) +
> + crypto_shash_descsize(tfm),
> + GFP_KERNEL);
> + if (!shash) {
> + ret = -ENOMEM;
> + goto out_free_psk;
> + }
Is there a good reason this can't use SHASH_DESC_ON_STACK()?
More information about the Linux-nvme
mailing list