1 From fc340115ffb8235c1bbd200c28855e6373d0dd1a Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Thu, 19 Apr 2018 18:41:55 +0200
4 Subject: [PATCH 6/8] crypto: crypto4xx - properly set IV after de- and encrypt
6 This patch fixes cts(cbc(aes)) test when cbc-aes-ppc4xx is used.
7 alg: skcipher: Test 1 failed (invalid result) on encryption for cts(cbc-aes-ppc4xx)
8 00000000: 4b 10 75 fc 2f 14 1b 6a 27 35 37 33 d1 b7 70 05
10 alg: skcipher: Failed to load transform for cts(cbc(aes)): -2
12 The CTS cipher mode expect the IV (req->iv) of skcipher_request
13 to contain the last ciphertext block after the {en,de}crypt
14 operation is complete.
16 Fix this issue for the AMCC Crypto4xx hardware engine.
17 The tcrypt test case for cts(cbc(aes)) is now correctly passed.
20 driver : cts(cbc-aes-ppc4xx)
35 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
36 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
38 drivers/crypto/amcc/crypto4xx_alg.c | 3 ++-
39 drivers/crypto/amcc/crypto4xx_core.c | 9 +++++++++
40 2 files changed, 11 insertions(+), 1 deletion(-)
42 --- a/drivers/crypto/amcc/crypto4xx_alg.c
43 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
44 @@ -141,7 +141,8 @@ static int crypto4xx_setkey_aes(struct c
48 - set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, SA_NOT_SAVE_IV,
49 + set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, (cm == CRYPTO_MODE_CBC ?
50 + SA_SAVE_IV : SA_NOT_SAVE_IV),
51 SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE,
52 SA_NO_HEADER_PROC, SA_HASH_ALG_NULL,
53 SA_CIPHER_ALG_AES, SA_PAD_TYPE_ZERO,
54 --- a/drivers/crypto/amcc/crypto4xx_core.c
55 +++ b/drivers/crypto/amcc/crypto4xx_core.c
56 @@ -545,6 +545,15 @@ static void crypto4xx_cipher_done(struct
57 addr = dma_map_page(dev->core_dev->device, sg_page(dst),
58 dst->offset, dst->length, DMA_FROM_DEVICE);
61 + if (pd_uinfo->sa_va->sa_command_0.bf.save_iv == SA_SAVE_IV) {
62 + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
64 + crypto4xx_memcpy_from_le32((u32 *)req->iv,
65 + pd_uinfo->sr_va->save_iv,
66 + crypto_skcipher_ivsize(skcipher));
69 crypto4xx_ret_sg_desc(dev, pd_uinfo);
71 if (pd_uinfo->state & PD_ENTRY_BUSY)