Re: [PATCH v3 2/2] crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
From: Herbert Xu
Date: Fri May 02 2025 - 09:01:39 EST
On Fri, May 02, 2025 at 05:21:17PM +0530, T Pratham wrote:
>
> +static int dthe_aes_crypt(struct skcipher_request *req, int enc)
> +{
> + struct dthe_tfm_ctx *ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req));
> + struct dthe_data *dev_data = dthe_get_dev(ctx);
> + struct crypto_engine *engine;
> +
> + /*
> + * If data is not a multiple of AES_BLOCK_SIZE, need to return -EINVAL
> + * If data length input is zero, no need to do any operation.
> + */
> + if (req->cryptlen % AES_BLOCK_SIZE)
> + return -EINVAL;
> +
> + if (req->cryptlen == 0)
> + return 0;
> +
> + ctx->ctx_info.aes_ctx->enc = enc;
You can't modify crypto_skcipher_ctx as a tfm is shared between
multiple request objects. If you need to keep track of the operation,
it needs to go into the request context (skcipher_request_ctx).
As a general rule, crypto_skcipher_ctx should only be used to
store key-related information and it can only be modifeid by
setkey.
Anything that is per-op should go into the request context.
> +/**
> + * struct dthe_data - DTHE_V2 driver instance data
> + * @dev: Device pointer
> + * @regs: Base address of the register space
> + * @list: list node for dev
> + * @engine: Crypto engine instance
> + * @dma_aes_rx: AES Rx DMA Channel
> + * @dma_aes_tx: AES Tx DMA Channel
> + * @dma_sha_tx: SHA Tx DMA Channel
> + * @ctx: Transform context struct
> + */
> +struct dthe_data {
> + struct device *dev;
> + void __iomem *regs;
> + struct list_head list;
> + struct crypto_engine *engine;
> +
> + struct dma_chan *dma_aes_rx;
> + struct dma_chan *dma_aes_tx;
> +
> + struct dma_chan *dma_sha_tx;
> +
> + struct dthe_tfm_ctx *ctx;
What's this field for? It doesn't seem to be used at all.
Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt