]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.45/crypto-rockchip-update-iv-buffer-to-contain-the-next-iv.patch
Linux 4.14.121
[thirdparty/kernel/stable-queue.git] / releases / 4.19.45 / crypto-rockchip-update-iv-buffer-to-contain-the-next-iv.patch
1 From f0cfd57b43fec65761ca61d3892b983a71515f23 Mon Sep 17 00:00:00 2001
2 From: Zhang Zhijie <zhangzj@rock-chips.com>
3 Date: Fri, 12 Apr 2019 17:16:33 +0800
4 Subject: crypto: rockchip - update IV buffer to contain the next IV
5
6 From: Zhang Zhijie <zhangzj@rock-chips.com>
7
8 commit f0cfd57b43fec65761ca61d3892b983a71515f23 upstream.
9
10 The Kernel Crypto API request output the next IV data to
11 IV buffer for CBC implementation. So the last block data of
12 ciphertext should be copid into assigned IV buffer.
13
14 Reported-by: Eric Biggers <ebiggers@google.com>
15 Fixes: 433cd2c617bf ("crypto: rockchip - add crypto driver for rk3288")
16 Cc: <stable@vger.kernel.org> # v4.5+
17 Signed-off-by: Zhang Zhijie <zhangzj@rock-chips.com>
18 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20
21 ---
22 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 25 +++++++++++++++------
23 1 file changed, 18 insertions(+), 7 deletions(-)
24
25 --- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
26 +++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
27 @@ -250,9 +250,14 @@ static int rk_set_data_start(struct rk_c
28 u8 *src_last_blk = page_address(sg_page(dev->sg_src)) +
29 dev->sg_src->offset + dev->sg_src->length - ivsize;
30
31 - /* store the iv that need to be updated in chain mode */
32 - if (ctx->mode & RK_CRYPTO_DEC)
33 + /* Store the iv that need to be updated in chain mode.
34 + * And update the IV buffer to contain the next IV for decryption mode.
35 + */
36 + if (ctx->mode & RK_CRYPTO_DEC) {
37 memcpy(ctx->iv, src_last_blk, ivsize);
38 + sg_pcopy_to_buffer(dev->first, dev->src_nents, req->info,
39 + ivsize, dev->total - ivsize);
40 + }
41
42 err = dev->load_data(dev, dev->sg_src, dev->sg_dst);
43 if (!err)
44 @@ -288,13 +293,19 @@ static void rk_iv_copyback(struct rk_cry
45 struct ablkcipher_request *req =
46 ablkcipher_request_cast(dev->async_req);
47 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
48 + struct rk_cipher_ctx *ctx = crypto_ablkcipher_ctx(tfm);
49 u32 ivsize = crypto_ablkcipher_ivsize(tfm);
50
51 - if (ivsize == DES_BLOCK_SIZE)
52 - memcpy_fromio(req->info, dev->reg + RK_CRYPTO_TDES_IV_0,
53 - ivsize);
54 - else if (ivsize == AES_BLOCK_SIZE)
55 - memcpy_fromio(req->info, dev->reg + RK_CRYPTO_AES_IV_0, ivsize);
56 + /* Update the IV buffer to contain the next IV for encryption mode. */
57 + if (!(ctx->mode & RK_CRYPTO_DEC)) {
58 + if (dev->aligned) {
59 + memcpy(req->info, sg_virt(dev->sg_dst) +
60 + dev->sg_dst->length - ivsize, ivsize);
61 + } else {
62 + memcpy(req->info, dev->addr_vir +
63 + dev->count - ivsize, ivsize);
64 + }
65 + }
66 }
67
68 static void rk_update_iv(struct rk_crypto_info *dev)