Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - update rfc4106 sh desc to support zero length input

Update share descriptor for rfc4106 to skip instructions in case
cryptlen is zero. If no instructions are jumped the DECO hangs and a
timeout error is thrown.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Iuliana Prodan and committed by
Herbert Xu
d28a43ed 31bb2f0d

+33 -16
+32 -15
drivers/crypto/caam/caamalg_desc.c
··· 852 852 * @ivsize: initialization vector size 853 853 * @icvsize: integrity check value (ICV) size (truncated or full) 854 854 * @is_qi: true when called from caam/qi 855 + * 856 + * Input sequence: AAD | PTXT 857 + * Output sequence: AAD | CTXT | ICV 858 + * AAD length (assoclen), which includes the IV length, is available in Math3. 855 859 */ 856 860 void cnstr_shdsc_rfc4106_encap(u32 * const desc, struct alginfo *cdata, 857 861 unsigned int ivsize, unsigned int icvsize, 858 862 const bool is_qi) 859 863 { 860 - u32 *key_jump_cmd; 861 - 864 + u32 *key_jump_cmd, *zero_cryptlen_jump_cmd, *skip_instructions; 862 865 init_sh_desc(desc, HDR_SHARE_SERIAL); 863 866 864 867 /* Skip key loading if it is loaded due to sharing */ ··· 904 901 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize); 905 902 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); 906 903 907 - /* Read assoc data */ 904 + /* Skip AAD */ 905 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); 906 + 907 + /* Read cryptlen and set this value into VARSEQOUTLEN */ 908 + append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ); 909 + 910 + /* If cryptlen is ZERO jump to AAD command */ 911 + zero_cryptlen_jump_cmd = append_jump(desc, JUMP_TEST_ALL | 912 + JUMP_COND_MATH_Z); 913 + 914 + /* Read AAD data */ 908 915 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | 909 916 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1); 910 917 918 + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ 919 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA); 920 + 911 921 /* Skip IV */ 912 922 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP); 913 - 914 - /* Will read cryptlen bytes */ 915 - append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); 916 - 917 - /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ 918 - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG); 919 - 920 - /* Skip assoc data */ 921 - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); 922 - 923 - /* cryptlen = seqoutlen - assoclen */ 924 - append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ); 923 + append_math_add(desc, VARSEQINLEN, VARSEQOUTLEN, REG0, CAAM_CMD_SZ); 925 924 926 925 /* Write encrypted data */ 927 926 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF); ··· 931 926 /* Read payload data */ 932 927 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | 933 928 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1); 929 + 930 + /* Jump instructions to avoid double reading of AAD */ 931 + skip_instructions = append_jump(desc, JUMP_TEST_ALL); 932 + 933 + /* There is no input data, cryptlen = 0 */ 934 + set_jump_tgt_here(desc, zero_cryptlen_jump_cmd); 935 + 936 + /* Read AAD */ 937 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | 938 + FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1); 939 + 940 + set_jump_tgt_here(desc, skip_instructions); 934 941 935 942 /* Write ICV */ 936 943 append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
+1 -1
drivers/crypto/caam/caamalg_desc.h
··· 31 31 #define DESC_QI_GCM_DEC_LEN (DESC_GCM_DEC_LEN + 3 * CAAM_CMD_SZ) 32 32 33 33 #define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ) 34 - #define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ) 34 + #define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 16 * CAAM_CMD_SZ) 35 35 #define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ) 36 36 #define DESC_QI_RFC4106_ENC_LEN (DESC_RFC4106_ENC_LEN + 5 * CAAM_CMD_SZ) 37 37 #define DESC_QI_RFC4106_DEC_LEN (DESC_RFC4106_DEC_LEN + 5 * CAAM_CMD_SZ)