Skip to content

Commit 4aad0cc

Browse files
horiagherbertx
authored andcommitted
crypto: caam - fix rfc4106 encap shared descriptor
The encap shared descriptor was changed to use the new IV convention. In the process some commands were shifted, making the output length zero, caam effectively writing garbage in dst. While here, update the decap descriptor to execute the "write" commands before the "read"s (as it previously was). This makes sure the input fifo is drained before becoming full. Fixes: 4621875 ("crypto: caam - Use new IV convention") Signed-off-by: Horia Geant? <[email protected]> Signed-off-by: Tudor Ambarus <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 41656aa commit 4aad0cc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
8888

8989
#define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
90-
#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ)
91-
#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 12 * CAAM_CMD_SZ)
90+
#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
91+
#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
9292

9393
#define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
9494
#define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
@@ -989,19 +989,22 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
989989
/* Will read cryptlen bytes */
990990
append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
991991

992-
/* Read payload data */
993-
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
994-
FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
992+
/* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
993+
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
995994

996995
/* Skip assoc data */
997996
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
998997

999998
/* cryptlen = seqoutlen - assoclen */
1000-
append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
999+
append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ);
10011000

10021001
/* Write encrypted data */
10031002
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
10041003

1004+
/* Read payload data */
1005+
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1006+
FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
1007+
10051008
/* Write ICV */
10061009
append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
10071010
LDST_SRCDST_BYTE_CONTEXT);
@@ -1060,9 +1063,8 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
10601063
/* Will read cryptlen bytes */
10611064
append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
10621065

1063-
/* Read encrypted data */
1064-
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1065-
FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
1066+
/* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
1067+
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
10661068

10671069
/* Skip assoc data */
10681070
append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
@@ -1073,6 +1075,10 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
10731075
/* Store payload data */
10741076
append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
10751077

1078+
/* Read encrypted data */
1079+
append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1080+
FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
1081+
10761082
/* Read ICV */
10771083
append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
10781084
FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);

0 commit comments

Comments
 (0)