| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * Shared descriptors for aead, ablkcipher algorithms |
|---|
| 3 | + * Shared descriptors for aead, skcipher algorithms |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * Copyright 2016 NXP |
|---|
| 5 | + * Copyright 2016-2019 NXP |
|---|
| 5 | 6 | */ |
|---|
| 6 | 7 | |
|---|
| 7 | 8 | #include "compat.h" |
|---|
| .. | .. |
|---|
| 32 | 33 | } |
|---|
| 33 | 34 | |
|---|
| 34 | 35 | jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD); |
|---|
| 35 | | - append_operation(desc, type | OP_ALG_AS_INITFINAL | |
|---|
| 36 | | - OP_ALG_DECRYPT); |
|---|
| 36 | + append_operation(desc, type | OP_ALG_AS_INIT | OP_ALG_DECRYPT); |
|---|
| 37 | 37 | uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL); |
|---|
| 38 | 38 | set_jump_tgt_here(desc, jump_cmd); |
|---|
| 39 | | - append_operation(desc, type | OP_ALG_AS_INITFINAL | |
|---|
| 40 | | - OP_ALG_DECRYPT | OP_ALG_AAI_DK); |
|---|
| 39 | + append_operation(desc, type | OP_ALG_AS_INIT | OP_ALG_DECRYPT | |
|---|
| 40 | + OP_ALG_AAI_DK); |
|---|
| 41 | 41 | set_jump_tgt_here(desc, uncond_jump_cmd); |
|---|
| 42 | 42 | } |
|---|
| 43 | 43 | |
|---|
| .. | .. |
|---|
| 114 | 114 | append_seq_store(desc, icvsize, LDST_CLASS_2_CCB | |
|---|
| 115 | 115 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 116 | 116 | |
|---|
| 117 | | -#ifdef DEBUG |
|---|
| 118 | | - print_hex_dump(KERN_ERR, |
|---|
| 119 | | - "aead null enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 120 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 121 | | -#endif |
|---|
| 117 | + print_hex_dump_debug("aead null enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 118 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 119 | + 1); |
|---|
| 122 | 120 | } |
|---|
| 123 | 121 | EXPORT_SYMBOL(cnstr_shdsc_aead_null_encap); |
|---|
| 124 | 122 | |
|---|
| .. | .. |
|---|
| 203 | 201 | append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 | |
|---|
| 204 | 202 | FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV); |
|---|
| 205 | 203 | |
|---|
| 206 | | -#ifdef DEBUG |
|---|
| 207 | | - print_hex_dump(KERN_ERR, |
|---|
| 208 | | - "aead null dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 209 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 210 | | -#endif |
|---|
| 204 | + print_hex_dump_debug("aead null dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 205 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 206 | + 1); |
|---|
| 211 | 207 | } |
|---|
| 212 | 208 | EXPORT_SYMBOL(cnstr_shdsc_aead_null_decap); |
|---|
| 213 | 209 | |
|---|
| .. | .. |
|---|
| 357 | 353 | append_seq_store(desc, icvsize, LDST_CLASS_2_CCB | |
|---|
| 358 | 354 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 359 | 355 | |
|---|
| 360 | | -#ifdef DEBUG |
|---|
| 361 | | - print_hex_dump(KERN_ERR, "aead enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 362 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 363 | | -#endif |
|---|
| 356 | + print_hex_dump_debug("aead enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 357 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 358 | + 1); |
|---|
| 364 | 359 | } |
|---|
| 365 | 360 | EXPORT_SYMBOL(cnstr_shdsc_aead_encap); |
|---|
| 366 | 361 | |
|---|
| .. | .. |
|---|
| 378 | 373 | * with OP_ALG_AAI_HMAC_PRECOMP. |
|---|
| 379 | 374 | * @ivsize: initialization vector size |
|---|
| 380 | 375 | * @icvsize: integrity check value (ICV) size (truncated or full) |
|---|
| 376 | + * @geniv: whether to generate Encrypted Chain IV |
|---|
| 381 | 377 | * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template |
|---|
| 382 | 378 | * @nonce: pointer to rfc3686 nonce |
|---|
| 383 | 379 | * @ctx1_iv_off: IV offset in CONTEXT1 register |
|---|
| .. | .. |
|---|
| 474 | 470 | append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 | |
|---|
| 475 | 471 | FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV); |
|---|
| 476 | 472 | |
|---|
| 477 | | -#ifdef DEBUG |
|---|
| 478 | | - print_hex_dump(KERN_ERR, "aead dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 479 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 480 | | -#endif |
|---|
| 473 | + print_hex_dump_debug("aead dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 474 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 475 | + 1); |
|---|
| 481 | 476 | } |
|---|
| 482 | 477 | EXPORT_SYMBOL(cnstr_shdsc_aead_decap); |
|---|
| 483 | 478 | |
|---|
| .. | .. |
|---|
| 621 | 616 | append_seq_store(desc, icvsize, LDST_CLASS_2_CCB | |
|---|
| 622 | 617 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 623 | 618 | |
|---|
| 624 | | -#ifdef DEBUG |
|---|
| 625 | | - print_hex_dump(KERN_ERR, |
|---|
| 626 | | - "aead givenc shdesc@" __stringify(__LINE__)": ", |
|---|
| 627 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 628 | | -#endif |
|---|
| 619 | + print_hex_dump_debug("aead givenc shdesc@" __stringify(__LINE__)": ", |
|---|
| 620 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 621 | + 1); |
|---|
| 629 | 622 | } |
|---|
| 630 | 623 | EXPORT_SYMBOL(cnstr_shdsc_aead_givencap); |
|---|
| 631 | 624 | |
|---|
| .. | .. |
|---|
| 750 | 743 | append_seq_store(desc, icvsize, LDST_CLASS_1_CCB | |
|---|
| 751 | 744 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 752 | 745 | |
|---|
| 753 | | -#ifdef DEBUG |
|---|
| 754 | | - print_hex_dump(KERN_ERR, "gcm enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 755 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 756 | | -#endif |
|---|
| 746 | + print_hex_dump_debug("gcm enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 747 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 748 | + 1); |
|---|
| 757 | 749 | } |
|---|
| 758 | 750 | EXPORT_SYMBOL(cnstr_shdsc_gcm_encap); |
|---|
| 759 | 751 | |
|---|
| .. | .. |
|---|
| 846 | 838 | append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 | |
|---|
| 847 | 839 | FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1); |
|---|
| 848 | 840 | |
|---|
| 849 | | -#ifdef DEBUG |
|---|
| 850 | | - print_hex_dump(KERN_ERR, "gcm dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 851 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 852 | | -#endif |
|---|
| 841 | + print_hex_dump_debug("gcm dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 842 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 843 | + 1); |
|---|
| 853 | 844 | } |
|---|
| 854 | 845 | EXPORT_SYMBOL(cnstr_shdsc_gcm_decap); |
|---|
| 855 | 846 | |
|---|
| .. | .. |
|---|
| 862 | 853 | * @ivsize: initialization vector size |
|---|
| 863 | 854 | * @icvsize: integrity check value (ICV) size (truncated or full) |
|---|
| 864 | 855 | * @is_qi: true when called from caam/qi |
|---|
| 856 | + * |
|---|
| 857 | + * Input sequence: AAD | PTXT |
|---|
| 858 | + * Output sequence: AAD | CTXT | ICV |
|---|
| 859 | + * AAD length (assoclen), which includes the IV length, is available in Math3. |
|---|
| 865 | 860 | */ |
|---|
| 866 | 861 | void cnstr_shdsc_rfc4106_encap(u32 * const desc, struct alginfo *cdata, |
|---|
| 867 | 862 | unsigned int ivsize, unsigned int icvsize, |
|---|
| 868 | 863 | const bool is_qi) |
|---|
| 869 | 864 | { |
|---|
| 870 | | - u32 *key_jump_cmd; |
|---|
| 871 | | - |
|---|
| 865 | + u32 *key_jump_cmd, *zero_cryptlen_jump_cmd, *skip_instructions; |
|---|
| 872 | 866 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
|---|
| 873 | 867 | |
|---|
| 874 | 868 | /* Skip key loading if it is loaded due to sharing */ |
|---|
| .. | .. |
|---|
| 911 | 905 | append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize); |
|---|
| 912 | 906 | append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); |
|---|
| 913 | 907 | |
|---|
| 914 | | - /* Read assoc data */ |
|---|
| 908 | + /* Skip AAD */ |
|---|
| 909 | + append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); |
|---|
| 910 | + |
|---|
| 911 | + /* Read cryptlen and set this value into VARSEQOUTLEN */ |
|---|
| 912 | + append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ); |
|---|
| 913 | + |
|---|
| 914 | + /* If cryptlen is ZERO jump to AAD command */ |
|---|
| 915 | + zero_cryptlen_jump_cmd = append_jump(desc, JUMP_TEST_ALL | |
|---|
| 916 | + JUMP_COND_MATH_Z); |
|---|
| 917 | + |
|---|
| 918 | + /* Read AAD data */ |
|---|
| 915 | 919 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | |
|---|
| 916 | 920 | FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1); |
|---|
| 917 | 921 | |
|---|
| 922 | + /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ |
|---|
| 923 | + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA); |
|---|
| 924 | + |
|---|
| 918 | 925 | /* Skip IV */ |
|---|
| 919 | 926 | append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP); |
|---|
| 920 | | - |
|---|
| 921 | | - /* Will read cryptlen bytes */ |
|---|
| 922 | | - append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
|---|
| 923 | | - |
|---|
| 924 | | - /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */ |
|---|
| 925 | | - append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG); |
|---|
| 926 | | - |
|---|
| 927 | | - /* Skip assoc data */ |
|---|
| 928 | | - append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF); |
|---|
| 929 | | - |
|---|
| 930 | | - /* cryptlen = seqoutlen - assoclen */ |
|---|
| 931 | | - append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ); |
|---|
| 927 | + append_math_add(desc, VARSEQINLEN, VARSEQOUTLEN, REG0, CAAM_CMD_SZ); |
|---|
| 932 | 928 | |
|---|
| 933 | 929 | /* Write encrypted data */ |
|---|
| 934 | 930 | append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF); |
|---|
| .. | .. |
|---|
| 937 | 933 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | |
|---|
| 938 | 934 | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1); |
|---|
| 939 | 935 | |
|---|
| 936 | + /* Jump instructions to avoid double reading of AAD */ |
|---|
| 937 | + skip_instructions = append_jump(desc, JUMP_TEST_ALL); |
|---|
| 938 | + |
|---|
| 939 | + /* There is no input data, cryptlen = 0 */ |
|---|
| 940 | + set_jump_tgt_here(desc, zero_cryptlen_jump_cmd); |
|---|
| 941 | + |
|---|
| 942 | + /* Read AAD */ |
|---|
| 943 | + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF | |
|---|
| 944 | + FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1); |
|---|
| 945 | + |
|---|
| 946 | + set_jump_tgt_here(desc, skip_instructions); |
|---|
| 947 | + |
|---|
| 940 | 948 | /* Write ICV */ |
|---|
| 941 | 949 | append_seq_store(desc, icvsize, LDST_CLASS_1_CCB | |
|---|
| 942 | 950 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 943 | 951 | |
|---|
| 944 | | -#ifdef DEBUG |
|---|
| 945 | | - print_hex_dump(KERN_ERR, |
|---|
| 946 | | - "rfc4106 enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 947 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 948 | | -#endif |
|---|
| 952 | + print_hex_dump_debug("rfc4106 enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 953 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 954 | + 1); |
|---|
| 949 | 955 | } |
|---|
| 950 | 956 | EXPORT_SYMBOL(cnstr_shdsc_rfc4106_encap); |
|---|
| 951 | 957 | |
|---|
| .. | .. |
|---|
| 1038 | 1044 | append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 | |
|---|
| 1039 | 1045 | FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1); |
|---|
| 1040 | 1046 | |
|---|
| 1041 | | -#ifdef DEBUG |
|---|
| 1042 | | - print_hex_dump(KERN_ERR, |
|---|
| 1043 | | - "rfc4106 dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1044 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1045 | | -#endif |
|---|
| 1047 | + print_hex_dump_debug("rfc4106 dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1048 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1049 | + 1); |
|---|
| 1046 | 1050 | } |
|---|
| 1047 | 1051 | EXPORT_SYMBOL(cnstr_shdsc_rfc4106_decap); |
|---|
| 1048 | 1052 | |
|---|
| .. | .. |
|---|
| 1123 | 1127 | append_seq_store(desc, icvsize, LDST_CLASS_1_CCB | |
|---|
| 1124 | 1128 | LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 1125 | 1129 | |
|---|
| 1126 | | -#ifdef DEBUG |
|---|
| 1127 | | - print_hex_dump(KERN_ERR, |
|---|
| 1128 | | - "rfc4543 enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 1129 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1130 | | -#endif |
|---|
| 1130 | + print_hex_dump_debug("rfc4543 enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 1131 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1132 | + 1); |
|---|
| 1131 | 1133 | } |
|---|
| 1132 | 1134 | EXPORT_SYMBOL(cnstr_shdsc_rfc4543_encap); |
|---|
| 1133 | 1135 | |
|---|
| .. | .. |
|---|
| 1213 | 1215 | append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 | |
|---|
| 1214 | 1216 | FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1); |
|---|
| 1215 | 1217 | |
|---|
| 1216 | | -#ifdef DEBUG |
|---|
| 1217 | | - print_hex_dump(KERN_ERR, |
|---|
| 1218 | | - "rfc4543 dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1219 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1220 | | -#endif |
|---|
| 1218 | + print_hex_dump_debug("rfc4543 dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1219 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1220 | + 1); |
|---|
| 1221 | 1221 | } |
|---|
| 1222 | 1222 | EXPORT_SYMBOL(cnstr_shdsc_rfc4543_decap); |
|---|
| 1223 | 1223 | |
|---|
| 1224 | | -/* |
|---|
| 1225 | | - * For ablkcipher encrypt and decrypt, read from req->src and |
|---|
| 1226 | | - * write to req->dst |
|---|
| 1224 | +/** |
|---|
| 1225 | + * cnstr_shdsc_chachapoly - Chacha20 + Poly1305 generic AEAD (rfc7539) and |
|---|
| 1226 | + * IPsec ESP (rfc7634, a.k.a. rfc7539esp) shared |
|---|
| 1227 | + * descriptor (non-protocol). |
|---|
| 1228 | + * @desc: pointer to buffer used for descriptor construction |
|---|
| 1229 | + * @cdata: pointer to block cipher transform definitions |
|---|
| 1230 | + * Valid algorithm values - OP_ALG_ALGSEL_CHACHA20 ANDed with |
|---|
| 1231 | + * OP_ALG_AAI_AEAD. |
|---|
| 1232 | + * @adata: pointer to authentication transform definitions |
|---|
| 1233 | + * Valid algorithm values - OP_ALG_ALGSEL_POLY1305 ANDed with |
|---|
| 1234 | + * OP_ALG_AAI_AEAD. |
|---|
| 1235 | + * @ivsize: initialization vector size |
|---|
| 1236 | + * @icvsize: integrity check value (ICV) size (truncated or full) |
|---|
| 1237 | + * @encap: true if encapsulation, false if decapsulation |
|---|
| 1238 | + * @is_qi: true when called from caam/qi |
|---|
| 1227 | 1239 | */ |
|---|
| 1228 | | -static inline void ablkcipher_append_src_dst(u32 *desc) |
|---|
| 1240 | +void cnstr_shdsc_chachapoly(u32 * const desc, struct alginfo *cdata, |
|---|
| 1241 | + struct alginfo *adata, unsigned int ivsize, |
|---|
| 1242 | + unsigned int icvsize, const bool encap, |
|---|
| 1243 | + const bool is_qi) |
|---|
| 1244 | +{ |
|---|
| 1245 | + u32 *key_jump_cmd, *wait_cmd; |
|---|
| 1246 | + u32 nfifo; |
|---|
| 1247 | + const bool is_ipsec = (ivsize != CHACHAPOLY_IV_SIZE); |
|---|
| 1248 | + |
|---|
| 1249 | + /* Note: Context registers are saved. */ |
|---|
| 1250 | + init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); |
|---|
| 1251 | + |
|---|
| 1252 | + /* skip key loading if they are loaded due to sharing */ |
|---|
| 1253 | + key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
|---|
| 1254 | + JUMP_COND_SHRD); |
|---|
| 1255 | + |
|---|
| 1256 | + append_key_as_imm(desc, cdata->key_virt, cdata->keylen, cdata->keylen, |
|---|
| 1257 | + CLASS_1 | KEY_DEST_CLASS_REG); |
|---|
| 1258 | + |
|---|
| 1259 | + /* For IPsec load the salt from keymat in the context register */ |
|---|
| 1260 | + if (is_ipsec) |
|---|
| 1261 | + append_load_as_imm(desc, cdata->key_virt + cdata->keylen, 4, |
|---|
| 1262 | + LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1263 | + 4 << LDST_OFFSET_SHIFT); |
|---|
| 1264 | + |
|---|
| 1265 | + set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1266 | + |
|---|
| 1267 | + /* Class 2 and 1 operations: Poly & ChaCha */ |
|---|
| 1268 | + if (encap) { |
|---|
| 1269 | + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1270 | + OP_ALG_ENCRYPT); |
|---|
| 1271 | + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1272 | + OP_ALG_ENCRYPT); |
|---|
| 1273 | + } else { |
|---|
| 1274 | + append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1275 | + OP_ALG_DECRYPT | OP_ALG_ICV_ON); |
|---|
| 1276 | + append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1277 | + OP_ALG_DECRYPT); |
|---|
| 1278 | + } |
|---|
| 1279 | + |
|---|
| 1280 | + if (is_qi) { |
|---|
| 1281 | + u32 *wait_load_cmd; |
|---|
| 1282 | + u32 ctx1_iv_off = is_ipsec ? 8 : 4; |
|---|
| 1283 | + |
|---|
| 1284 | + /* REG3 = assoclen */ |
|---|
| 1285 | + append_seq_load(desc, 4, LDST_CLASS_DECO | |
|---|
| 1286 | + LDST_SRCDST_WORD_DECO_MATH3 | |
|---|
| 1287 | + 4 << LDST_OFFSET_SHIFT); |
|---|
| 1288 | + |
|---|
| 1289 | + wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
|---|
| 1290 | + JUMP_COND_CALM | JUMP_COND_NCP | |
|---|
| 1291 | + JUMP_COND_NOP | JUMP_COND_NIP | |
|---|
| 1292 | + JUMP_COND_NIFP); |
|---|
| 1293 | + set_jump_tgt_here(desc, wait_load_cmd); |
|---|
| 1294 | + |
|---|
| 1295 | + append_seq_load(desc, ivsize, LDST_CLASS_1_CCB | |
|---|
| 1296 | + LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1297 | + ctx1_iv_off << LDST_OFFSET_SHIFT); |
|---|
| 1298 | + } |
|---|
| 1299 | + |
|---|
| 1300 | + /* |
|---|
| 1301 | + * MAGIC with NFIFO |
|---|
| 1302 | + * Read associated data from the input and send them to class1 and |
|---|
| 1303 | + * class2 alignment blocks. From class1 send data to output fifo and |
|---|
| 1304 | + * then write it to memory since we don't need to encrypt AD. |
|---|
| 1305 | + */ |
|---|
| 1306 | + nfifo = NFIFOENTRY_DEST_BOTH | NFIFOENTRY_FC1 | NFIFOENTRY_FC2 | |
|---|
| 1307 | + NFIFOENTRY_DTYPE_POLY | NFIFOENTRY_BND; |
|---|
| 1308 | + append_load_imm_u32(desc, nfifo, LDST_CLASS_IND_CCB | |
|---|
| 1309 | + LDST_SRCDST_WORD_INFO_FIFO_SM | LDLEN_MATH3); |
|---|
| 1310 | + |
|---|
| 1311 | + append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ); |
|---|
| 1312 | + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); |
|---|
| 1313 | + append_seq_fifo_load(desc, 0, FIFOLD_TYPE_NOINFOFIFO | |
|---|
| 1314 | + FIFOLD_CLASS_CLASS1 | LDST_VLF); |
|---|
| 1315 | + append_move_len(desc, MOVE_AUX_LS | MOVE_SRC_AUX_ABLK | |
|---|
| 1316 | + MOVE_DEST_OUTFIFO | MOVELEN_MRSEL_MATH3); |
|---|
| 1317 | + append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | LDST_VLF); |
|---|
| 1318 | + |
|---|
| 1319 | + /* IPsec - copy IV at the output */ |
|---|
| 1320 | + if (is_ipsec) |
|---|
| 1321 | + append_seq_fifo_store(desc, ivsize, FIFOST_TYPE_METADATA | |
|---|
| 1322 | + 0x2 << 25); |
|---|
| 1323 | + |
|---|
| 1324 | + wait_cmd = append_jump(desc, JUMP_JSL | JUMP_TYPE_LOCAL | |
|---|
| 1325 | + JUMP_COND_NOP | JUMP_TEST_ALL); |
|---|
| 1326 | + set_jump_tgt_here(desc, wait_cmd); |
|---|
| 1327 | + |
|---|
| 1328 | + if (encap) { |
|---|
| 1329 | + /* Read and write cryptlen bytes */ |
|---|
| 1330 | + append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
|---|
| 1331 | + append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, |
|---|
| 1332 | + CAAM_CMD_SZ); |
|---|
| 1333 | + aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2); |
|---|
| 1334 | + |
|---|
| 1335 | + /* Write ICV */ |
|---|
| 1336 | + append_seq_store(desc, icvsize, LDST_CLASS_2_CCB | |
|---|
| 1337 | + LDST_SRCDST_BYTE_CONTEXT); |
|---|
| 1338 | + } else { |
|---|
| 1339 | + /* Read and write cryptlen bytes */ |
|---|
| 1340 | + append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, |
|---|
| 1341 | + CAAM_CMD_SZ); |
|---|
| 1342 | + append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, |
|---|
| 1343 | + CAAM_CMD_SZ); |
|---|
| 1344 | + aead_append_src_dst(desc, FIFOLD_TYPE_MSG); |
|---|
| 1345 | + |
|---|
| 1346 | + /* Load ICV for verification */ |
|---|
| 1347 | + append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 | |
|---|
| 1348 | + FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV); |
|---|
| 1349 | + } |
|---|
| 1350 | + |
|---|
| 1351 | + print_hex_dump_debug("chachapoly shdesc@" __stringify(__LINE__)": ", |
|---|
| 1352 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1353 | + 1); |
|---|
| 1354 | +} |
|---|
| 1355 | +EXPORT_SYMBOL(cnstr_shdsc_chachapoly); |
|---|
| 1356 | + |
|---|
| 1357 | +/* For skcipher encrypt and decrypt, read from req->src and write to req->dst */ |
|---|
| 1358 | +static inline void skcipher_append_src_dst(u32 *desc) |
|---|
| 1229 | 1359 | { |
|---|
| 1230 | 1360 | append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
|---|
| 1231 | 1361 | append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
|---|
| .. | .. |
|---|
| 1235 | 1365 | } |
|---|
| 1236 | 1366 | |
|---|
| 1237 | 1367 | /** |
|---|
| 1238 | | - * cnstr_shdsc_ablkcipher_encap - ablkcipher encapsulation shared descriptor |
|---|
| 1368 | + * cnstr_shdsc_skcipher_encap - skcipher encapsulation shared descriptor |
|---|
| 1239 | 1369 | * @desc: pointer to buffer used for descriptor construction |
|---|
| 1240 | 1370 | * @cdata: pointer to block cipher transform definitions |
|---|
| 1241 | 1371 | * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed |
|---|
| 1242 | | - * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128. |
|---|
| 1372 | + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128 |
|---|
| 1373 | + * - OP_ALG_ALGSEL_CHACHA20 |
|---|
| 1243 | 1374 | * @ivsize: initialization vector size |
|---|
| 1244 | 1375 | * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template |
|---|
| 1245 | 1376 | * @ctx1_iv_off: IV offset in CONTEXT1 register |
|---|
| 1246 | 1377 | */ |
|---|
| 1247 | | -void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata, |
|---|
| 1248 | | - unsigned int ivsize, const bool is_rfc3686, |
|---|
| 1249 | | - const u32 ctx1_iv_off) |
|---|
| 1378 | +void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata, |
|---|
| 1379 | + unsigned int ivsize, const bool is_rfc3686, |
|---|
| 1380 | + const u32 ctx1_iv_off) |
|---|
| 1250 | 1381 | { |
|---|
| 1251 | 1382 | u32 *key_jump_cmd; |
|---|
| 1383 | + u32 options = cdata->algtype | OP_ALG_AS_INIT | OP_ALG_ENCRYPT; |
|---|
| 1384 | + bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) == |
|---|
| 1385 | + OP_ALG_ALGSEL_CHACHA20); |
|---|
| 1252 | 1386 | |
|---|
| 1253 | 1387 | init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); |
|---|
| 1254 | 1388 | /* Skip if already shared */ |
|---|
| .. | .. |
|---|
| 1273 | 1407 | |
|---|
| 1274 | 1408 | set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1275 | 1409 | |
|---|
| 1276 | | - /* Load iv */ |
|---|
| 1277 | | - append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1278 | | - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); |
|---|
| 1410 | + /* Load IV, if there is one */ |
|---|
| 1411 | + if (ivsize) |
|---|
| 1412 | + append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1413 | + LDST_CLASS_1_CCB | (ctx1_iv_off << |
|---|
| 1414 | + LDST_OFFSET_SHIFT)); |
|---|
| 1279 | 1415 | |
|---|
| 1280 | 1416 | /* Load counter into CONTEXT1 reg */ |
|---|
| 1281 | 1417 | if (is_rfc3686) |
|---|
| .. | .. |
|---|
| 1285 | 1421 | LDST_OFFSET_SHIFT)); |
|---|
| 1286 | 1422 | |
|---|
| 1287 | 1423 | /* Load operation */ |
|---|
| 1288 | | - append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1289 | | - OP_ALG_ENCRYPT); |
|---|
| 1424 | + if (is_chacha20) |
|---|
| 1425 | + options |= OP_ALG_AS_FINALIZE; |
|---|
| 1426 | + append_operation(desc, options); |
|---|
| 1290 | 1427 | |
|---|
| 1291 | 1428 | /* Perform operation */ |
|---|
| 1292 | | - ablkcipher_append_src_dst(desc); |
|---|
| 1429 | + skcipher_append_src_dst(desc); |
|---|
| 1293 | 1430 | |
|---|
| 1294 | | -#ifdef DEBUG |
|---|
| 1295 | | - print_hex_dump(KERN_ERR, |
|---|
| 1296 | | - "ablkcipher enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 1297 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1298 | | -#endif |
|---|
| 1431 | + /* Store IV */ |
|---|
| 1432 | + if (!is_chacha20 && ivsize) |
|---|
| 1433 | + append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1434 | + LDST_CLASS_1_CCB | (ctx1_iv_off << |
|---|
| 1435 | + LDST_OFFSET_SHIFT)); |
|---|
| 1436 | + |
|---|
| 1437 | + print_hex_dump_debug("skcipher enc shdesc@" __stringify(__LINE__)": ", |
|---|
| 1438 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1439 | + 1); |
|---|
| 1299 | 1440 | } |
|---|
| 1300 | | -EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_encap); |
|---|
| 1441 | +EXPORT_SYMBOL(cnstr_shdsc_skcipher_encap); |
|---|
| 1301 | 1442 | |
|---|
| 1302 | 1443 | /** |
|---|
| 1303 | | - * cnstr_shdsc_ablkcipher_decap - ablkcipher decapsulation shared descriptor |
|---|
| 1444 | + * cnstr_shdsc_skcipher_decap - skcipher decapsulation shared descriptor |
|---|
| 1304 | 1445 | * @desc: pointer to buffer used for descriptor construction |
|---|
| 1305 | 1446 | * @cdata: pointer to block cipher transform definitions |
|---|
| 1306 | 1447 | * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed |
|---|
| 1307 | | - * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128. |
|---|
| 1448 | + * with OP_ALG_AAI_CBC or OP_ALG_AAI_CTR_MOD128 |
|---|
| 1449 | + * - OP_ALG_ALGSEL_CHACHA20 |
|---|
| 1308 | 1450 | * @ivsize: initialization vector size |
|---|
| 1309 | 1451 | * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template |
|---|
| 1310 | 1452 | * @ctx1_iv_off: IV offset in CONTEXT1 register |
|---|
| 1311 | 1453 | */ |
|---|
| 1312 | | -void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata, |
|---|
| 1313 | | - unsigned int ivsize, const bool is_rfc3686, |
|---|
| 1314 | | - const u32 ctx1_iv_off) |
|---|
| 1454 | +void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata, |
|---|
| 1455 | + unsigned int ivsize, const bool is_rfc3686, |
|---|
| 1456 | + const u32 ctx1_iv_off) |
|---|
| 1315 | 1457 | { |
|---|
| 1316 | 1458 | u32 *key_jump_cmd; |
|---|
| 1459 | + bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) == |
|---|
| 1460 | + OP_ALG_ALGSEL_CHACHA20); |
|---|
| 1317 | 1461 | |
|---|
| 1318 | 1462 | init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); |
|---|
| 1319 | 1463 | /* Skip if already shared */ |
|---|
| .. | .. |
|---|
| 1338 | 1482 | |
|---|
| 1339 | 1483 | set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1340 | 1484 | |
|---|
| 1341 | | - /* load IV */ |
|---|
| 1342 | | - append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1343 | | - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); |
|---|
| 1485 | + /* Load IV, if there is one */ |
|---|
| 1486 | + if (ivsize) |
|---|
| 1487 | + append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1488 | + LDST_CLASS_1_CCB | (ctx1_iv_off << |
|---|
| 1489 | + LDST_OFFSET_SHIFT)); |
|---|
| 1344 | 1490 | |
|---|
| 1345 | 1491 | /* Load counter into CONTEXT1 reg */ |
|---|
| 1346 | 1492 | if (is_rfc3686) |
|---|
| .. | .. |
|---|
| 1351 | 1497 | |
|---|
| 1352 | 1498 | /* Choose operation */ |
|---|
| 1353 | 1499 | if (ctx1_iv_off) |
|---|
| 1354 | | - append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1500 | + append_operation(desc, cdata->algtype | OP_ALG_AS_INIT | |
|---|
| 1355 | 1501 | OP_ALG_DECRYPT); |
|---|
| 1356 | 1502 | else |
|---|
| 1357 | 1503 | append_dec_op1(desc, cdata->algtype); |
|---|
| 1358 | 1504 | |
|---|
| 1359 | 1505 | /* Perform operation */ |
|---|
| 1360 | | - ablkcipher_append_src_dst(desc); |
|---|
| 1506 | + skcipher_append_src_dst(desc); |
|---|
| 1361 | 1507 | |
|---|
| 1362 | | -#ifdef DEBUG |
|---|
| 1363 | | - print_hex_dump(KERN_ERR, |
|---|
| 1364 | | - "ablkcipher dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1365 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1366 | | -#endif |
|---|
| 1508 | + /* Store IV */ |
|---|
| 1509 | + if (!is_chacha20 && ivsize) |
|---|
| 1510 | + append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1511 | + LDST_CLASS_1_CCB | (ctx1_iv_off << |
|---|
| 1512 | + LDST_OFFSET_SHIFT)); |
|---|
| 1513 | + |
|---|
| 1514 | + print_hex_dump_debug("skcipher dec shdesc@" __stringify(__LINE__)": ", |
|---|
| 1515 | + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), |
|---|
| 1516 | + 1); |
|---|
| 1367 | 1517 | } |
|---|
| 1368 | | -EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_decap); |
|---|
| 1518 | +EXPORT_SYMBOL(cnstr_shdsc_skcipher_decap); |
|---|
| 1369 | 1519 | |
|---|
| 1370 | 1520 | /** |
|---|
| 1371 | | - * cnstr_shdsc_ablkcipher_givencap - ablkcipher encapsulation shared descriptor |
|---|
| 1372 | | - * with HW-generated initialization vector. |
|---|
| 1373 | | - * @desc: pointer to buffer used for descriptor construction |
|---|
| 1374 | | - * @cdata: pointer to block cipher transform definitions |
|---|
| 1375 | | - * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed |
|---|
| 1376 | | - * with OP_ALG_AAI_CBC. |
|---|
| 1377 | | - * @ivsize: initialization vector size |
|---|
| 1378 | | - * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template |
|---|
| 1379 | | - * @ctx1_iv_off: IV offset in CONTEXT1 register |
|---|
| 1380 | | - */ |
|---|
| 1381 | | -void cnstr_shdsc_ablkcipher_givencap(u32 * const desc, struct alginfo *cdata, |
|---|
| 1382 | | - unsigned int ivsize, const bool is_rfc3686, |
|---|
| 1383 | | - const u32 ctx1_iv_off) |
|---|
| 1384 | | -{ |
|---|
| 1385 | | - u32 *key_jump_cmd, geniv; |
|---|
| 1386 | | - |
|---|
| 1387 | | - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); |
|---|
| 1388 | | - /* Skip if already shared */ |
|---|
| 1389 | | - key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
|---|
| 1390 | | - JUMP_COND_SHRD); |
|---|
| 1391 | | - |
|---|
| 1392 | | - /* Load class1 key only */ |
|---|
| 1393 | | - append_key_as_imm(desc, cdata->key_virt, cdata->keylen, |
|---|
| 1394 | | - cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG); |
|---|
| 1395 | | - |
|---|
| 1396 | | - /* Load Nonce into CONTEXT1 reg */ |
|---|
| 1397 | | - if (is_rfc3686) { |
|---|
| 1398 | | - const u8 *nonce = cdata->key_virt + cdata->keylen; |
|---|
| 1399 | | - |
|---|
| 1400 | | - append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE, |
|---|
| 1401 | | - LDST_CLASS_IND_CCB | |
|---|
| 1402 | | - LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM); |
|---|
| 1403 | | - append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO | |
|---|
| 1404 | | - MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) | |
|---|
| 1405 | | - (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT)); |
|---|
| 1406 | | - } |
|---|
| 1407 | | - set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1408 | | - |
|---|
| 1409 | | - /* Generate IV */ |
|---|
| 1410 | | - geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO | |
|---|
| 1411 | | - NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 | NFIFOENTRY_PTYPE_RND | |
|---|
| 1412 | | - (ivsize << NFIFOENTRY_DLEN_SHIFT); |
|---|
| 1413 | | - append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB | |
|---|
| 1414 | | - LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM); |
|---|
| 1415 | | - append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO); |
|---|
| 1416 | | - append_move(desc, MOVE_WAITCOMP | MOVE_SRC_INFIFO | |
|---|
| 1417 | | - MOVE_DEST_CLASS1CTX | (ivsize << MOVE_LEN_SHIFT) | |
|---|
| 1418 | | - (ctx1_iv_off << MOVE_OFFSET_SHIFT)); |
|---|
| 1419 | | - append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO); |
|---|
| 1420 | | - |
|---|
| 1421 | | - /* Copy generated IV to memory */ |
|---|
| 1422 | | - append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1423 | | - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); |
|---|
| 1424 | | - |
|---|
| 1425 | | - /* Load Counter into CONTEXT1 reg */ |
|---|
| 1426 | | - if (is_rfc3686) |
|---|
| 1427 | | - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB | |
|---|
| 1428 | | - LDST_SRCDST_BYTE_CONTEXT | |
|---|
| 1429 | | - ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) << |
|---|
| 1430 | | - LDST_OFFSET_SHIFT)); |
|---|
| 1431 | | - |
|---|
| 1432 | | - if (ctx1_iv_off) |
|---|
| 1433 | | - append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NCP | |
|---|
| 1434 | | - (1 << JUMP_OFFSET_SHIFT)); |
|---|
| 1435 | | - |
|---|
| 1436 | | - /* Load operation */ |
|---|
| 1437 | | - append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1438 | | - OP_ALG_ENCRYPT); |
|---|
| 1439 | | - |
|---|
| 1440 | | - /* Perform operation */ |
|---|
| 1441 | | - ablkcipher_append_src_dst(desc); |
|---|
| 1442 | | - |
|---|
| 1443 | | -#ifdef DEBUG |
|---|
| 1444 | | - print_hex_dump(KERN_ERR, |
|---|
| 1445 | | - "ablkcipher givenc shdesc@" __stringify(__LINE__) ": ", |
|---|
| 1446 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1447 | | -#endif |
|---|
| 1448 | | -} |
|---|
| 1449 | | -EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_givencap); |
|---|
| 1450 | | - |
|---|
| 1451 | | -/** |
|---|
| 1452 | | - * cnstr_shdsc_xts_ablkcipher_encap - xts ablkcipher encapsulation shared |
|---|
| 1453 | | - * descriptor |
|---|
| 1521 | + * cnstr_shdsc_xts_skcipher_encap - xts skcipher encapsulation shared descriptor |
|---|
| 1454 | 1522 | * @desc: pointer to buffer used for descriptor construction |
|---|
| 1455 | 1523 | * @cdata: pointer to block cipher transform definitions |
|---|
| 1456 | 1524 | * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS. |
|---|
| 1457 | 1525 | */ |
|---|
| 1458 | | -void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata) |
|---|
| 1526 | +void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata) |
|---|
| 1459 | 1527 | { |
|---|
| 1460 | 1528 | /* |
|---|
| 1461 | 1529 | * Set sector size to a big value, practically disabling |
|---|
| .. | .. |
|---|
| 1483 | 1551 | set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1484 | 1552 | |
|---|
| 1485 | 1553 | /* |
|---|
| 1486 | | - * create sequence for loading the sector index |
|---|
| 1487 | | - * Upper 8B of IV - will be used as sector index |
|---|
| 1488 | | - * Lower 8B of IV - will be discarded |
|---|
| 1554 | + * create sequence for loading the sector index / 16B tweak value |
|---|
| 1555 | + * Lower 8B of IV - sector index / tweak lower half |
|---|
| 1556 | + * Upper 8B of IV - upper half of 16B tweak |
|---|
| 1489 | 1557 | */ |
|---|
| 1490 | 1558 | append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1491 | 1559 | (0x20 << LDST_OFFSET_SHIFT)); |
|---|
| 1492 | | - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP); |
|---|
| 1560 | + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1561 | + (0x30 << LDST_OFFSET_SHIFT)); |
|---|
| 1493 | 1562 | |
|---|
| 1494 | 1563 | /* Load operation */ |
|---|
| 1495 | 1564 | append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL | |
|---|
| 1496 | 1565 | OP_ALG_ENCRYPT); |
|---|
| 1497 | 1566 | |
|---|
| 1498 | 1567 | /* Perform operation */ |
|---|
| 1499 | | - ablkcipher_append_src_dst(desc); |
|---|
| 1568 | + skcipher_append_src_dst(desc); |
|---|
| 1500 | 1569 | |
|---|
| 1501 | | -#ifdef DEBUG |
|---|
| 1502 | | - print_hex_dump(KERN_ERR, |
|---|
| 1503 | | - "xts ablkcipher enc shdesc@" __stringify(__LINE__) ": ", |
|---|
| 1504 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1505 | | -#endif |
|---|
| 1570 | + /* Store lower 8B and upper 8B of IV */ |
|---|
| 1571 | + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1572 | + (0x20 << LDST_OFFSET_SHIFT)); |
|---|
| 1573 | + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1574 | + (0x30 << LDST_OFFSET_SHIFT)); |
|---|
| 1575 | + |
|---|
| 1576 | + print_hex_dump_debug("xts skcipher enc shdesc@" __stringify(__LINE__) |
|---|
| 1577 | + ": ", DUMP_PREFIX_ADDRESS, 16, 4, |
|---|
| 1578 | + desc, desc_bytes(desc), 1); |
|---|
| 1506 | 1579 | } |
|---|
| 1507 | | -EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_encap); |
|---|
| 1580 | +EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_encap); |
|---|
| 1508 | 1581 | |
|---|
| 1509 | 1582 | /** |
|---|
| 1510 | | - * cnstr_shdsc_xts_ablkcipher_decap - xts ablkcipher decapsulation shared |
|---|
| 1511 | | - * descriptor |
|---|
| 1583 | + * cnstr_shdsc_xts_skcipher_decap - xts skcipher decapsulation shared descriptor |
|---|
| 1512 | 1584 | * @desc: pointer to buffer used for descriptor construction |
|---|
| 1513 | 1585 | * @cdata: pointer to block cipher transform definitions |
|---|
| 1514 | 1586 | * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS. |
|---|
| 1515 | 1587 | */ |
|---|
| 1516 | | -void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata) |
|---|
| 1588 | +void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata) |
|---|
| 1517 | 1589 | { |
|---|
| 1518 | 1590 | /* |
|---|
| 1519 | 1591 | * Set sector size to a big value, practically disabling |
|---|
| .. | .. |
|---|
| 1541 | 1613 | set_jump_tgt_here(desc, key_jump_cmd); |
|---|
| 1542 | 1614 | |
|---|
| 1543 | 1615 | /* |
|---|
| 1544 | | - * create sequence for loading the sector index |
|---|
| 1545 | | - * Upper 8B of IV - will be used as sector index |
|---|
| 1546 | | - * Lower 8B of IV - will be discarded |
|---|
| 1616 | + * create sequence for loading the sector index / 16B tweak value |
|---|
| 1617 | + * Lower 8B of IV - sector index / tweak lower half |
|---|
| 1618 | + * Upper 8B of IV - upper half of 16B tweak |
|---|
| 1547 | 1619 | */ |
|---|
| 1548 | 1620 | append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1549 | 1621 | (0x20 << LDST_OFFSET_SHIFT)); |
|---|
| 1550 | | - append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP); |
|---|
| 1551 | | - |
|---|
| 1622 | + append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1623 | + (0x30 << LDST_OFFSET_SHIFT)); |
|---|
| 1552 | 1624 | /* Load operation */ |
|---|
| 1553 | 1625 | append_dec_op1(desc, cdata->algtype); |
|---|
| 1554 | 1626 | |
|---|
| 1555 | 1627 | /* Perform operation */ |
|---|
| 1556 | | - ablkcipher_append_src_dst(desc); |
|---|
| 1628 | + skcipher_append_src_dst(desc); |
|---|
| 1557 | 1629 | |
|---|
| 1558 | | -#ifdef DEBUG |
|---|
| 1559 | | - print_hex_dump(KERN_ERR, |
|---|
| 1560 | | - "xts ablkcipher dec shdesc@" __stringify(__LINE__) ": ", |
|---|
| 1561 | | - DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); |
|---|
| 1562 | | -#endif |
|---|
| 1630 | + /* Store lower 8B and upper 8B of IV */ |
|---|
| 1631 | + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1632 | + (0x20 << LDST_OFFSET_SHIFT)); |
|---|
| 1633 | + append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB | |
|---|
| 1634 | + (0x30 << LDST_OFFSET_SHIFT)); |
|---|
| 1635 | + |
|---|
| 1636 | + print_hex_dump_debug("xts skcipher dec shdesc@" __stringify(__LINE__) |
|---|
| 1637 | + ": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, |
|---|
| 1638 | + desc_bytes(desc), 1); |
|---|
| 1563 | 1639 | } |
|---|
| 1564 | | -EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_decap); |
|---|
| 1640 | +EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_decap); |
|---|
| 1565 | 1641 | |
|---|
| 1566 | 1642 | MODULE_LICENSE("GPL"); |
|---|
| 1567 | 1643 | MODULE_DESCRIPTION("FSL CAAM descriptor support"); |
|---|