Re: [PATCH v5 4/4] crypto: starfive - Add hash and HMAC support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx/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@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux