Skip to content

Commit 0b5a7f7

Browse files
chunkeeyherbertx
authored andcommitted
crypto: crypto4xx - perform aead icv check in the driver
The ccm-aes-ppc4xx now fails one of testmgr's expected failure test cases as such: |decryption failed on test 10 for ccm-aes-ppc4xx: |ret was 0, |expected -EBADMSG It doesn't look like the hardware sets the authentication failure flag. The original vendor source from which this was ported does not have any special code or notes about why this would happen or if there are any WAs. Hence, this patch converts the aead_done callback handler to perform the icv check in the driver. And this fixes the false negative and the ccm-aes-ppc4xx passes the selftests once again. |name : ccm(aes) |driver : ccm-aes-ppc4xx |module : crypto4xx |priority : 300 |refcnt : 1 |selftest : passed |internal : no |type : aead |async : yes |blocksize : 1 |ivsize : 16 |maxauthsize : 16 |geniv : <none> Signed-off-by: Christian Lamparter <chunkeey@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 333b192 commit 0b5a7f7

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

drivers/crypto/amcc/crypto4xx_alg.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ static inline bool crypto4xx_aead_need_fallback(struct aead_request *req,
256256
if (is_ccm && !(req->iv[0] == 1 || req->iv[0] == 3))
257257
return true;
258258

259-
/* CCM - fix CBC MAC mismatch in special case */
260-
if (is_ccm && decrypt && !req->assoclen)
261-
return true;
262-
263259
return false;
264260
}
265261

@@ -330,7 +326,7 @@ int crypto4xx_setkey_aes_ccm(struct crypto_aead *cipher, const u8 *key,
330326
sa = (struct dynamic_sa_ctl *) ctx->sa_in;
331327
sa->sa_contents.w = SA_AES_CCM_CONTENTS | (keylen << 2);
332328

333-
set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, SA_NOT_SAVE_IV,
329+
set_dynamic_sa_command_0(sa, SA_SAVE_HASH, SA_NOT_SAVE_IV,
334330
SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE,
335331
SA_NO_HEADER_PROC, SA_HASH_ALG_CBC_MAC,
336332
SA_CIPHER_ALG_AES,

drivers/crypto/amcc/crypto4xx_core.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,14 @@ static void crypto4xx_aead_done(struct crypto4xx_device *dev,
577577
struct pd_uinfo *pd_uinfo,
578578
struct ce_pd *pd)
579579
{
580-
struct aead_request *aead_req;
581-
struct crypto4xx_ctx *ctx;
580+
struct aead_request *aead_req = container_of(pd_uinfo->async_req,
581+
struct aead_request, base);
582582
struct scatterlist *dst = pd_uinfo->dest_va;
583+
size_t cp_len = crypto_aead_authsize(
584+
crypto_aead_reqtfm(aead_req));
585+
u32 icv[cp_len];
583586
int err = 0;
584587

585-
aead_req = container_of(pd_uinfo->async_req, struct aead_request,
586-
base);
587-
ctx = crypto_tfm_ctx(aead_req->base.tfm);
588-
589588
if (pd_uinfo->using_sd) {
590589
crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo,
591590
pd->pd_ctl_len.bf.pkt_len,
@@ -597,38 +596,39 @@ static void crypto4xx_aead_done(struct crypto4xx_device *dev,
597596

598597
if (pd_uinfo->sa_va->sa_command_0.bf.dir == DIR_OUTBOUND) {
599598
/* append icv at the end */
600-
size_t cp_len = crypto_aead_authsize(
601-
crypto_aead_reqtfm(aead_req));
602-
u32 icv[cp_len];
603-
604599
crypto4xx_memcpy_from_le32(icv, pd_uinfo->sr_va->save_digest,
605600
cp_len);
606601

607602
scatterwalk_map_and_copy(icv, dst, aead_req->cryptlen,
608603
cp_len, 1);
604+
} else {
605+
/* check icv at the end */
606+
scatterwalk_map_and_copy(icv, aead_req->src,
607+
aead_req->assoclen + aead_req->cryptlen -
608+
cp_len, cp_len, 0);
609+
610+
crypto4xx_memcpy_from_le32(icv, icv, cp_len);
611+
612+
if (crypto_memneq(icv, pd_uinfo->sr_va->save_digest, cp_len))
613+
err = -EBADMSG;
609614
}
610615

611616
crypto4xx_ret_sg_desc(dev, pd_uinfo);
612617

613618
if (pd->pd_ctl.bf.status & 0xff) {
614-
if (pd->pd_ctl.bf.status & 0x1) {
615-
/* authentication error */
616-
err = -EBADMSG;
617-
} else {
618-
if (!__ratelimit(&dev->aead_ratelimit)) {
619-
if (pd->pd_ctl.bf.status & 2)
620-
pr_err("pad fail error\n");
621-
if (pd->pd_ctl.bf.status & 4)
622-
pr_err("seqnum fail\n");
623-
if (pd->pd_ctl.bf.status & 8)
624-
pr_err("error _notify\n");
625-
pr_err("aead return err status = 0x%02x\n",
626-
pd->pd_ctl.bf.status & 0xff);
627-
pr_err("pd pad_ctl = 0x%08x\n",
628-
pd->pd_ctl.bf.pd_pad_ctl);
629-
}
630-
err = -EINVAL;
619+
if (!__ratelimit(&dev->aead_ratelimit)) {
620+
if (pd->pd_ctl.bf.status & 2)
621+
pr_err("pad fail error\n");
622+
if (pd->pd_ctl.bf.status & 4)
623+
pr_err("seqnum fail\n");
624+
if (pd->pd_ctl.bf.status & 8)
625+
pr_err("error _notify\n");
626+
pr_err("aead return err status = 0x%02x\n",
627+
pd->pd_ctl.bf.status & 0xff);
628+
pr_err("pd pad_ctl = 0x%08x\n",
629+
pd->pd_ctl.bf.pd_pad_ctl);
631630
}
631+
err = -EINVAL;
632632
}
633633

634634
if (pd_uinfo->state & PD_ENTRY_BUSY)

0 commit comments

Comments
 (0)