Re: [PATCH v8 1/3] crypto: ti - Add support for AES-CTR in DTHEv2 driver

From: Herbert Xu

Date: Fri Feb 06 2026 - 04:39:23 EST


On Tue, Jan 20, 2026 at 08:14:06PM +0530, T Pratham wrote:
>
> + /*
> + * CTR mode can operate on any input length, but the hardware
> + * requires input length to be a multiple of the block size.
> + * We need to handle the padding in the driver.
> + */
> + if (ctx->aes_mode == DTHE_AES_CTR && req->cryptlen % AES_BLOCK_SIZE) {
> + struct scatterlist *sg;
> + int i = 0;
> + unsigned int curr_len = 0;
> +
> + len -= req->cryptlen % AES_BLOCK_SIZE;
> + src_nents = sg_nents_for_len(req->src, len);
> + dst_nents = sg_nents_for_len(req->dst, len);
> +
> + /*
> + * Need to truncate the src and dst to len, else DMA complains.
> + * Lengths restored at end
> + */
> + for_each_sg(req->src, sg, src_nents - 1, i) {
> + curr_len += sg->length;
> + }
> + curr_len += sg->length;
> + src_bkup_len = sg->length;
> + sg->length -= curr_len % AES_BLOCK_SIZE;

Please don't modify the SG lists since they may be used elsewhere.
There is no harm in mapping a bit more data than what you will
end up using.

Just truncate the length written to the hardware instead.

Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt