Skip to content

Commit 1d2d87e

Browse files
horiagherbertx
authored andcommitted
crypto: caam - fix echainiv(authenc) encrypt shared descriptor
There are a few things missed by the conversion to the new AEAD interface: 1 - echainiv(authenc) encrypt shared descriptor The shared descriptor is incorrect: due to the order of operations, at some point in time MATH3 register is being overwritten. 2 - buffer used for echainiv(authenc) encrypt shared descriptor Encrypt and givencrypt shared descriptors (for AEAD ops) are mutually exclusive and thus use the same buffer in context state: sh_desc_enc. However, there's one place missed by s/sh_desc_givenc/sh_desc_enc, leading to errors when echainiv(authenc(...)) algorithms are used: DECO: desc idx 14: Header Error. Invalid length or parity, or certain other problems. While here, also fix a typo: dma_mapping_error() is checking for validity of sh_desc_givenc_dma instead of sh_desc_enc_dma. Cc: <[email protected]> # 4.3+ Fixes: 479bcc7 ("crypto: caam - Convert authenc to new AEAD interface") Signed-off-by: Horia Geantă <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f743e70 commit 1d2d87e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
614614
keys_fit_inline = true;
615615

616616
/* aead_givencrypt shared descriptor */
617-
desc = ctx->sh_desc_givenc;
617+
desc = ctx->sh_desc_enc;
618618

619619
/* Note: Context registers are saved. */
620620
init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
@@ -645,13 +645,13 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
645645
append_operation(desc, ctx->class2_alg_type |
646646
OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
647647

648-
/* ivsize + cryptlen = seqoutlen - authsize */
649-
append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
650-
651648
/* Read and write assoclen bytes */
652649
append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
653650
append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
654651

652+
/* ivsize + cryptlen = seqoutlen - authsize */
653+
append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
654+
655655
/* Skip assoc data */
656656
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
657657

@@ -697,7 +697,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
697697
ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
698698
desc_bytes(desc),
699699
DMA_TO_DEVICE);
700-
if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
700+
if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
701701
dev_err(jrdev, "unable to map shared descriptor\n");
702702
return -ENOMEM;
703703
}

0 commit comments

Comments
 (0)