1 From 5b3856d1d98e6f6a58b70c1c0d7da3fb5f042e9c Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Thu, 21 Dec 2017 16:00:01 +0100
4 Subject: [PATCH 5/6] crypto: crypto4xx - perform aead icv check in the driver
6 The ccm-aes-ppc4xx now fails one of testmgr's expected
7 failure test cases as such:
9 alg: aead: decryption failed on test 10 for ccm-aes-ppc4xx: ret was 0, expected -EBADMSG
11 Upon closer inspection, it turned out that the hardware's
12 crypto flags that would indicate an authentification failure
13 are not set by the hardware. The original vendor source from
14 which this was ported does not have any special code or notes
15 about why this would happen or if there are any WAs.
17 Hence, this patch converts the aead_done callback handler to
18 perform the icv check in the driver. And this fixes the false
19 negative and the ccm-aes-ppc4xx passes the selftests once again.
22 |driver : ccm-aes-ppc4xx
35 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
37 drivers/crypto/amcc/crypto4xx_alg.c | 6 +---
38 drivers/crypto/amcc/crypto4xx_core.c | 54 ++++++++++++++++++------------------
39 2 files changed, 28 insertions(+), 32 deletions(-)
41 --- a/drivers/crypto/amcc/crypto4xx_alg.c
42 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
43 @@ -257,10 +257,6 @@ static inline bool crypto4xx_aead_need_f
44 if (is_ccm && !(req->iv[0] == 1 || req->iv[0] == 3))
47 - /* CCM - fix CBC MAC mismatch in special case */
48 - if (is_ccm && decrypt && !req->assoclen)
54 @@ -331,7 +327,7 @@ int crypto4xx_setkey_aes_ccm(struct cryp
55 sa = (struct dynamic_sa_ctl *) ctx->sa_in;
56 sa->sa_contents.w = SA_AES_CCM_CONTENTS | (keylen << 2);
58 - set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, SA_NOT_SAVE_IV,
59 + set_dynamic_sa_command_0(sa, SA_SAVE_HASH, SA_NOT_SAVE_IV,
60 SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE,
61 SA_NO_HEADER_PROC, SA_HASH_ALG_CBC_MAC,
63 --- a/drivers/crypto/amcc/crypto4xx_core.c
64 +++ b/drivers/crypto/amcc/crypto4xx_core.c
65 @@ -586,15 +586,14 @@ static void crypto4xx_aead_done(struct c
66 struct pd_uinfo *pd_uinfo,
69 - struct aead_request *aead_req;
70 - struct crypto4xx_ctx *ctx;
71 + struct aead_request *aead_req = container_of(pd_uinfo->async_req,
72 + struct aead_request, base);
73 struct scatterlist *dst = pd_uinfo->dest_va;
74 + size_t cp_len = crypto_aead_authsize(
75 + crypto_aead_reqtfm(aead_req));
79 - aead_req = container_of(pd_uinfo->async_req, struct aead_request,
81 - ctx = crypto_tfm_ctx(aead_req->base.tfm);
83 if (pd_uinfo->using_sd) {
84 crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo,
85 pd->pd_ctl_len.bf.pkt_len,
86 @@ -606,38 +605,39 @@ static void crypto4xx_aead_done(struct c
88 if (pd_uinfo->sa_va->sa_command_0.bf.dir == DIR_OUTBOUND) {
89 /* append icv at the end */
90 - size_t cp_len = crypto_aead_authsize(
91 - crypto_aead_reqtfm(aead_req));
94 crypto4xx_memcpy_from_le32(icv, pd_uinfo->sr_va->save_digest,
97 scatterwalk_map_and_copy(icv, dst, aead_req->cryptlen,
100 + /* check icv at the end */
101 + scatterwalk_map_and_copy(icv, aead_req->src,
102 + aead_req->assoclen + aead_req->cryptlen -
103 + cp_len, cp_len, 0);
105 + crypto4xx_memcpy_from_le32(icv, icv, cp_len);
107 + if (crypto_memneq(icv, pd_uinfo->sr_va->save_digest, cp_len))
111 crypto4xx_ret_sg_desc(dev, pd_uinfo);
113 if (pd->pd_ctl.bf.status & 0xff) {
114 - if (pd->pd_ctl.bf.status & 0x1) {
115 - /* authentication error */
118 - if (!__ratelimit(&dev->aead_ratelimit)) {
119 - if (pd->pd_ctl.bf.status & 2)
120 - pr_err("pad fail error\n");
121 - if (pd->pd_ctl.bf.status & 4)
122 - pr_err("seqnum fail\n");
123 - if (pd->pd_ctl.bf.status & 8)
124 - pr_err("error _notify\n");
125 - pr_err("aead return err status = 0x%02x\n",
126 - pd->pd_ctl.bf.status & 0xff);
127 - pr_err("pd pad_ctl = 0x%08x\n",
128 - pd->pd_ctl.bf.pd_pad_ctl);
131 + if (!__ratelimit(&dev->aead_ratelimit)) {
132 + if (pd->pd_ctl.bf.status & 2)
133 + pr_err("pad fail error\n");
134 + if (pd->pd_ctl.bf.status & 4)
135 + pr_err("seqnum fail\n");
136 + if (pd->pd_ctl.bf.status & 8)
137 + pr_err("error _notify\n");
138 + pr_err("aead return err status = 0x%02x\n",
139 + pd->pd_ctl.bf.status & 0xff);
140 + pr_err("pd pad_ctl = 0x%08x\n",
141 + pd->pd_ctl.bf.pd_pad_ctl);
146 if (pd_uinfo->state & PD_ENTRY_BUSY)