From: Herbert Xu <herbert@gondor.apana.org.au>
To: Jia Jie Ho <jiajie.ho@starfivetech.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Emil Renner Berthing <kernel@esmil.dk>,
Conor Dooley <conor@kernel.org>,
linux-crypto@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH v5 4/4] crypto: starfive - Add hash and HMAC support
Date: Thu, 20 Apr 2023 18:10:23 +0800 [thread overview]
Message-ID: <ZEEPjzLIlZW6HaAM@gondor.apana.org.au> (raw)
In-Reply-To: <20230411081424.131912-5-jiajie.ho@starfivetech.com>
On Tue, Apr 11, 2023 at 04:14:24PM +0800, Jia Jie Ho wrote:
>
> +static int starfive_hash_export(struct ahash_request *req, void *out)
> +{
> + struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req);
> + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> + struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm);
> +
> + ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk);
> + ahash_request_set_callback(&rctx->ahash_fbk_req,
> + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP,
> + req->base.complete, req->base.data);
> +
> + ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src,
> + req->result, req->nbytes);
> +
> + return crypto_ahash_export(&rctx->ahash_fbk_req, out);
> +}
You can't export a freshly created request. The fallback
request needs to have been created by the usual init/update
calls.
The export function should simply invoke export.
> +static int starfive_hash_cra_init_algs(struct crypto_tfm *tfm,
> + const char *algs_hmac_name,
> + unsigned int mode,
> + const char *alg_name)
> +{
> + struct starfive_cryp_ctx *ctx = crypto_tfm_ctx(tfm);
> + struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
> +
> + ctx->cryp = starfive_cryp_find_dev(ctx);
> +
> + if (!ctx->cryp)
> + return -ENODEV;
> +
> + ctx->ahash_fbk = crypto_alloc_ahash(alg_name, 0,
> + CRYPTO_ALG_NEED_FALLBACK);
> +
> + if (IS_ERR(ctx->ahash_fbk))
> + return dev_err_probe(ctx->cryp->dev, PTR_ERR(ctx->ahash_fbk),
> + "starfive_hash: Could not load fallback driver.\n");
> +
> + crypto_hash_alg_common(ahash)->statesize = crypto_ahash_statesize(ctx->ahash_fbk);
I've just posted a patch to linux-crypto to do this properly:
https://lore.kernel.org/linux-crypto/ZEEOXIHwqKblKfBJ@gondor.apana.org.au/T/#u
Please switch to using the helper that I added.
> +static int starfive_hash256_setkey(struct crypto_ahash *tfm,
> + const u8 *key, unsigned int keylen)
> +{
> + struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm);
> + unsigned int digestsize = crypto_ahash_digestsize(tfm);
> + unsigned int blocksize;
> + int ret = 0;
> +
> + blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
Please use crypto_ahash_blocksize. We should never use crypto_ahash_tfm
in new code.
> +static int starfive_hash_cra_sha224_init(struct crypto_tfm *tfm)
> +{
> + return starfive_hash_cra_init_algs(tfm, NULL,
> + STARFIVE_HASH_SHA224,
> + "sha224-generic");
> +}
Please switch to the new API and use init_tfm/exit_tfm instead of
cra_init/cra_exit.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2023-04-20 10:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 8:14 [PATCH v5 0/4] crypto: starfive - Add drivers for crypto engine Jia Jie Ho
2023-04-11 8:14 ` [PATCH v5 1/4] dt-bindings: crypto: Add StarFive crypto module Jia Jie Ho
2023-04-11 8:14 ` [PATCH v5 2/4] crypto: starfive - Add crypto engine support Jia Jie Ho
2023-04-11 8:14 ` [PATCH v5 3/4] riscv: dts: starfive: Add crypto and DMA node for VisionFive 2 Jia Jie Ho
2023-04-11 8:14 ` [PATCH v5 4/4] crypto: starfive - Add hash and HMAC support Jia Jie Ho
2023-04-20 10:10 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZEEPjzLIlZW6HaAM@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=conor@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=jiajie.ho@starfivetech.com \
--cc=kernel@esmil.dk \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®