When CBC is done in-place, the ->src is overwritten by the time the operation is done, so the output IV must be based on a backup of the ciphertext. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx> --- drivers/crypto/axis/artpec6_crypto.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 67f510c497f2..87f82c314e48 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -321,6 +321,7 @@ struct artpec6_crypto_request_context { u32 cipher_md; bool decrypt; struct artpec6_crypto_req_common common; + unsigned char last_ciphertext[AES_BLOCK_SIZE]; unsigned char iv_bounce[AES_BLOCK_SIZE] CRYPTO_MINALIGN_ATTR; }; @@ -1158,6 +1159,10 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) switch (ctx->crypto_type) { case ARTPEC6_CRYPTO_CIPHER_AES_CBC: + scatterwalk_map_and_copy(req_ctx->last_ciphertext, req->src, + req->cryptlen - sizeof(req_ctx->last_ciphertext), + sizeof(req_ctx->last_ciphertext), 0); + complete = artpec6_crypto_complete_cbc_decrypt; break; case ARTPEC6_CRYPTO_CIPHER_AES_CTR: @@ -2185,10 +2190,10 @@ artpec6_crypto_complete_cbc_decrypt(struct crypto_async_request *req) { struct skcipher_request *cipher_req = container_of(req, struct skcipher_request, base); + struct artpec6_crypto_request_context *req_ctx = skcipher_request_ctx(cipher_req); + + memcpy(cipher_req->iv, req_ctx->last_ciphertext, sizeof(req_ctx->last_ciphertext)); - scatterwalk_map_and_copy(cipher_req->iv, cipher_req->src, - cipher_req->cryptlen - AES_BLOCK_SIZE, - AES_BLOCK_SIZE, 0); req->complete(req, 0); } -- 2.34.1