Skip to content

Commit

Permalink
drivers: caam: fix size of CMAC update data
Browse files Browse the repository at this point in the history
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 <olivier.masse@nxp.com>
Signed-off-by: Clement Faure <clement.faure@nxp.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
omasse-linaro authored and jforissier committed Jul 24, 2023
1 parent a61bc39 commit e4b1172
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/drivers/crypto/caam/cipher/caam_cipher_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e4b1172

Please sign in to comment.