From e4b1172625af43092b8742144113b64375190b71 Mon Sep 17 00:00:00 2001 From: Olivier Masse Date: Tue, 4 Jul 2023 16:36:09 +0200 Subject: [PATCH] drivers: caam: fix size of CMAC update data In case of an update operation, the total input data size processed must be a multiple of a block size. The total block size is equal to the input data size and the saved buffer size. If the reallocation DMA buffer is less than the input data size, buffer length plus saved buffer size need to be adjusted to align on multiple of a block size. Depending on the memory buffer input configuration, the function caam_dmaobj_sgtbuf_build() might modify the data size to be processed in the loop. This case happens sometimes on i.MX platforms where the input buffer physical address in above 32 bits. This implies reporting the data size re-ajustment when data is saved in the context buffer. Signed-off-by: Olivier Masse Signed-off-by: Clement Faure Acked-by: Jerome Forissier --- core/drivers/crypto/caam/cipher/caam_cipher_mac.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/drivers/crypto/caam/cipher/caam_cipher_mac.c b/core/drivers/crypto/caam/cipher/caam_cipher_mac.c index 511bfc69512..f73a6f1c2cf 100644 --- a/core/drivers/crypto/caam/cipher/caam_cipher_mac.c +++ b/core/drivers/crypto/caam/cipher/caam_cipher_mac.c @@ -503,6 +503,15 @@ static TEE_Result do_update_cmac(struct drvcrypt_cipher_update *dupdate) if (ret) goto end_cmac; + /* + * Need to re-adjust the length of the data if the + * posted data block is not empty and the SGT/Buffer + * is part of the full input data to do. + */ + if (ctx->blockbuf.filled && size_done < size_todo) { + size_done -= ctx->blockbuf.filled; + src.sgtbuf.length = size_done; + } CIPHER_TRACE("Do input %zu bytes, offset %zu", size_done, offset);