This source file includes following definitions.
- aead_append_src_dst
- append_dec_op1
- cnstr_shdsc_aead_null_encap
- cnstr_shdsc_aead_null_decap
- init_sh_desc_key_aead
- cnstr_shdsc_aead_encap
- cnstr_shdsc_aead_decap
- cnstr_shdsc_aead_givencap
- cnstr_shdsc_gcm_encap
- cnstr_shdsc_gcm_decap
- cnstr_shdsc_rfc4106_encap
- cnstr_shdsc_rfc4106_decap
- cnstr_shdsc_rfc4543_encap
- cnstr_shdsc_rfc4543_decap
- cnstr_shdsc_chachapoly
- skcipher_append_src_dst
- cnstr_shdsc_skcipher_encap
- cnstr_shdsc_skcipher_decap
- cnstr_shdsc_xts_skcipher_encap
- cnstr_shdsc_xts_skcipher_decap
1
2
3
4
5
6
7
8 #include "compat.h"
9 #include "desc_constr.h"
10 #include "caamalg_desc.h"
11
12
13
14
15
16 static inline void aead_append_src_dst(u32 *desc, u32 msg_type)
17 {
18 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
19 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
20 KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH);
21 }
22
23
24 static inline void append_dec_op1(u32 *desc, u32 type)
25 {
26 u32 *jump_cmd, *uncond_jump_cmd;
27
28
29 if ((type & OP_ALG_ALGSEL_MASK) != OP_ALG_ALGSEL_AES) {
30 append_operation(desc, type | OP_ALG_AS_INITFINAL |
31 OP_ALG_DECRYPT);
32 return;
33 }
34
35 jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
36 append_operation(desc, type | OP_ALG_AS_INIT | OP_ALG_DECRYPT);
37 uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL);
38 set_jump_tgt_here(desc, jump_cmd);
39 append_operation(desc, type | OP_ALG_AS_INIT | OP_ALG_DECRYPT |
40 OP_ALG_AAI_DK);
41 set_jump_tgt_here(desc, uncond_jump_cmd);
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56 void cnstr_shdsc_aead_null_encap(u32 * const desc, struct alginfo *adata,
57 unsigned int icvsize, int era)
58 {
59 u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
60
61 init_sh_desc(desc, HDR_SHARE_SERIAL);
62
63
64 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
65 JUMP_COND_SHRD);
66 if (era < 6) {
67 if (adata->key_inline)
68 append_key_as_imm(desc, adata->key_virt,
69 adata->keylen_pad, adata->keylen,
70 CLASS_2 | KEY_DEST_MDHA_SPLIT |
71 KEY_ENC);
72 else
73 append_key(desc, adata->key_dma, adata->keylen,
74 CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
75 } else {
76 append_proto_dkp(desc, adata);
77 }
78 set_jump_tgt_here(desc, key_jump_cmd);
79
80
81 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
82
83
84 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
85 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
86
87
88
89
90
91
92 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
93 MOVE_DEST_MATH3 |
94 (0x6 << MOVE_LEN_SHIFT));
95 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 |
96 MOVE_DEST_DESCBUF |
97 MOVE_WAITCOMP |
98 (0x8 << MOVE_LEN_SHIFT));
99
100
101 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
102 OP_ALG_ENCRYPT);
103
104
105 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
106
107 set_move_tgt_here(desc, read_move_cmd);
108 set_move_tgt_here(desc, write_move_cmd);
109 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
110 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
111 MOVE_AUX_LS);
112
113
114 append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
115 LDST_SRCDST_BYTE_CONTEXT);
116
117 print_hex_dump_debug("aead null enc shdesc@" __stringify(__LINE__)": ",
118 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
119 1);
120 }
121 EXPORT_SYMBOL(cnstr_shdsc_aead_null_encap);
122
123
124
125
126
127
128
129
130
131
132
133
134
135 void cnstr_shdsc_aead_null_decap(u32 * const desc, struct alginfo *adata,
136 unsigned int icvsize, int era)
137 {
138 u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd, *jump_cmd;
139
140 init_sh_desc(desc, HDR_SHARE_SERIAL);
141
142
143 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
144 JUMP_COND_SHRD);
145 if (era < 6) {
146 if (adata->key_inline)
147 append_key_as_imm(desc, adata->key_virt,
148 adata->keylen_pad, adata->keylen,
149 CLASS_2 | KEY_DEST_MDHA_SPLIT |
150 KEY_ENC);
151 else
152 append_key(desc, adata->key_dma, adata->keylen,
153 CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
154 } else {
155 append_proto_dkp(desc, adata);
156 }
157 set_jump_tgt_here(desc, key_jump_cmd);
158
159
160 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
161 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
162
163
164 append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ);
165
166
167 append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ);
168 append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ);
169
170
171
172
173
174
175 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
176 MOVE_DEST_MATH2 |
177 (0x6 << MOVE_LEN_SHIFT));
178 write_move_cmd = append_move(desc, MOVE_SRC_MATH2 |
179 MOVE_DEST_DESCBUF |
180 MOVE_WAITCOMP |
181 (0x8 << MOVE_LEN_SHIFT));
182
183
184 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
185
186
187
188
189
190 jump_cmd = append_jump(desc, JUMP_TEST_ALL);
191 set_jump_tgt_here(desc, jump_cmd);
192
193 set_move_tgt_here(desc, read_move_cmd);
194 set_move_tgt_here(desc, write_move_cmd);
195 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
196 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
197 MOVE_AUX_LS);
198 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
199
200
201 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 |
202 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
203
204 print_hex_dump_debug("aead null dec shdesc@" __stringify(__LINE__)": ",
205 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
206 1);
207 }
208 EXPORT_SYMBOL(cnstr_shdsc_aead_null_decap);
209
210 static void init_sh_desc_key_aead(u32 * const desc,
211 struct alginfo * const cdata,
212 struct alginfo * const adata,
213 const bool is_rfc3686, u32 *nonce, int era)
214 {
215 u32 *key_jump_cmd;
216 unsigned int enckeylen = cdata->keylen;
217
218
219 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
220
221
222 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
223 JUMP_COND_SHRD);
224
225
226
227
228
229
230 if (is_rfc3686)
231 enckeylen -= CTR_RFC3686_NONCE_SIZE;
232
233 if (era < 6) {
234 if (adata->key_inline)
235 append_key_as_imm(desc, adata->key_virt,
236 adata->keylen_pad, adata->keylen,
237 CLASS_2 | KEY_DEST_MDHA_SPLIT |
238 KEY_ENC);
239 else
240 append_key(desc, adata->key_dma, adata->keylen,
241 CLASS_2 | KEY_DEST_MDHA_SPLIT | KEY_ENC);
242 } else {
243 append_proto_dkp(desc, adata);
244 }
245
246 if (cdata->key_inline)
247 append_key_as_imm(desc, cdata->key_virt, enckeylen,
248 enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
249 else
250 append_key(desc, cdata->key_dma, enckeylen, CLASS_1 |
251 KEY_DEST_CLASS_REG);
252
253
254 if (is_rfc3686) {
255 append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
256 LDST_CLASS_IND_CCB |
257 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
258 append_move(desc,
259 MOVE_SRC_OUTFIFO |
260 MOVE_DEST_CLASS1CTX |
261 (16 << MOVE_OFFSET_SHIFT) |
262 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
263 }
264
265 set_jump_tgt_here(desc, key_jump_cmd);
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288 void cnstr_shdsc_aead_encap(u32 * const desc, struct alginfo *cdata,
289 struct alginfo *adata, unsigned int ivsize,
290 unsigned int icvsize, const bool is_rfc3686,
291 u32 *nonce, const u32 ctx1_iv_off, const bool is_qi,
292 int era)
293 {
294
295 init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
296
297
298 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
299 OP_ALG_ENCRYPT);
300
301 if (is_qi) {
302 u32 *wait_load_cmd;
303
304
305 append_seq_load(desc, 4, LDST_CLASS_DECO |
306 LDST_SRCDST_WORD_DECO_MATH3 |
307 (4 << LDST_OFFSET_SHIFT));
308
309 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
310 JUMP_COND_CALM | JUMP_COND_NCP |
311 JUMP_COND_NOP | JUMP_COND_NIP |
312 JUMP_COND_NIFP);
313 set_jump_tgt_here(desc, wait_load_cmd);
314
315 append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
316 LDST_SRCDST_BYTE_CONTEXT |
317 (ctx1_iv_off << LDST_OFFSET_SHIFT));
318 }
319
320
321 if (is_qi || era < 3) {
322 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
323 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
324 } else {
325 append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
326 append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
327 }
328
329
330 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
331
332
333 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
334 FIFOLDST_VLF);
335
336
337 if (is_rfc3686)
338 append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
339 LDST_SRCDST_BYTE_CONTEXT |
340 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
341 LDST_OFFSET_SHIFT));
342
343
344 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
345 OP_ALG_ENCRYPT);
346
347
348 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
349 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
350 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
351
352
353 append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
354 LDST_SRCDST_BYTE_CONTEXT);
355
356 print_hex_dump_debug("aead enc shdesc@" __stringify(__LINE__)": ",
357 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
358 1);
359 }
360 EXPORT_SYMBOL(cnstr_shdsc_aead_encap);
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382 void cnstr_shdsc_aead_decap(u32 * const desc, struct alginfo *cdata,
383 struct alginfo *adata, unsigned int ivsize,
384 unsigned int icvsize, const bool geniv,
385 const bool is_rfc3686, u32 *nonce,
386 const u32 ctx1_iv_off, const bool is_qi, int era)
387 {
388
389 init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
390
391
392 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
393 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
394
395 if (is_qi) {
396 u32 *wait_load_cmd;
397
398
399 append_seq_load(desc, 4, LDST_CLASS_DECO |
400 LDST_SRCDST_WORD_DECO_MATH3 |
401 (4 << LDST_OFFSET_SHIFT));
402
403 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
404 JUMP_COND_CALM | JUMP_COND_NCP |
405 JUMP_COND_NOP | JUMP_COND_NIP |
406 JUMP_COND_NIFP);
407 set_jump_tgt_here(desc, wait_load_cmd);
408
409 if (!geniv)
410 append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
411 LDST_SRCDST_BYTE_CONTEXT |
412 (ctx1_iv_off << LDST_OFFSET_SHIFT));
413 }
414
415
416 if (is_qi || era < 3) {
417 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
418 if (geniv)
419 append_math_add_imm_u32(desc, VARSEQOUTLEN, REG3, IMM,
420 ivsize);
421 else
422 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3,
423 CAAM_CMD_SZ);
424 } else {
425 append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
426 if (geniv)
427 append_math_add_imm_u32(desc, VARSEQOUTLEN, DPOVRD, IMM,
428 ivsize);
429 else
430 append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD,
431 CAAM_CMD_SZ);
432 }
433
434
435 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
436
437
438 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
439 KEY_VLF);
440
441 if (geniv) {
442 append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
443 LDST_SRCDST_BYTE_CONTEXT |
444 (ctx1_iv_off << LDST_OFFSET_SHIFT));
445 append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_CLASS2INFIFO |
446 (ctx1_iv_off << MOVE_OFFSET_SHIFT) | ivsize);
447 }
448
449
450 if (is_rfc3686)
451 append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
452 LDST_SRCDST_BYTE_CONTEXT |
453 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
454 LDST_OFFSET_SHIFT));
455
456
457 if (ctx1_iv_off)
458 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
459 OP_ALG_DECRYPT);
460 else
461 append_dec_op1(desc, cdata->algtype);
462
463
464 append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
465 append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
466 aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
467
468
469 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 |
470 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
471
472 print_hex_dump_debug("aead dec shdesc@" __stringify(__LINE__)": ",
473 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
474 1);
475 }
476 EXPORT_SYMBOL(cnstr_shdsc_aead_decap);
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499 void cnstr_shdsc_aead_givencap(u32 * const desc, struct alginfo *cdata,
500 struct alginfo *adata, unsigned int ivsize,
501 unsigned int icvsize, const bool is_rfc3686,
502 u32 *nonce, const u32 ctx1_iv_off,
503 const bool is_qi, int era)
504 {
505 u32 geniv, moveiv;
506 u32 *wait_cmd;
507
508
509 init_sh_desc_key_aead(desc, cdata, adata, is_rfc3686, nonce, era);
510
511 if (is_qi) {
512 u32 *wait_load_cmd;
513
514
515 append_seq_load(desc, 4, LDST_CLASS_DECO |
516 LDST_SRCDST_WORD_DECO_MATH3 |
517 (4 << LDST_OFFSET_SHIFT));
518
519 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
520 JUMP_COND_CALM | JUMP_COND_NCP |
521 JUMP_COND_NOP | JUMP_COND_NIP |
522 JUMP_COND_NIFP);
523 set_jump_tgt_here(desc, wait_load_cmd);
524 }
525
526 if (is_rfc3686) {
527 if (is_qi)
528 append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
529 LDST_SRCDST_BYTE_CONTEXT |
530 (ctx1_iv_off << LDST_OFFSET_SHIFT));
531
532 goto copy_iv;
533 }
534
535
536 geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
537 NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
538 NFIFOENTRY_PTYPE_RND | (ivsize << NFIFOENTRY_DLEN_SHIFT);
539 append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
540 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
541 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
542 append_move(desc, MOVE_WAITCOMP |
543 MOVE_SRC_INFIFO | MOVE_DEST_CLASS1CTX |
544 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
545 (ivsize << MOVE_LEN_SHIFT));
546 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
547
548 copy_iv:
549
550 append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_OUTFIFO |
551 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
552 (ivsize << MOVE_LEN_SHIFT));
553
554
555 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
556 OP_ALG_ENCRYPT);
557
558
559 if (is_qi || era < 3) {
560 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
561 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
562 } else {
563 append_math_add(desc, VARSEQINLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
564 append_math_add(desc, VARSEQOUTLEN, ZERO, DPOVRD, CAAM_CMD_SZ);
565 }
566
567
568 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
569
570
571 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
572 KEY_VLF);
573
574
575 moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 |
576 NFIFOENTRY_DTYPE_MSG | (ivsize << NFIFOENTRY_DLEN_SHIFT);
577 append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB |
578 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
579 append_load_imm_u32(desc, ivsize, LDST_CLASS_2_CCB |
580 LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
581
582
583 if (is_rfc3686)
584 append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
585 LDST_SRCDST_BYTE_CONTEXT |
586 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
587 LDST_OFFSET_SHIFT));
588
589
590 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
591 OP_ALG_ENCRYPT);
592
593
594 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
595
596
597 append_seq_fifo_load(desc, ivsize,
598 FIFOLD_CLASS_SKIP);
599
600
601 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
602
603
604
605
606
607 wait_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NIFP);
608 set_jump_tgt_here(desc, wait_cmd);
609
610 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | KEY_VLF |
611 FIFOLD_TYPE_MSG1OUT2 | FIFOLD_TYPE_LASTBOTH);
612 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
613
614
615 append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
616 LDST_SRCDST_BYTE_CONTEXT);
617
618 print_hex_dump_debug("aead givenc shdesc@" __stringify(__LINE__)": ",
619 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
620 1);
621 }
622 EXPORT_SYMBOL(cnstr_shdsc_aead_givencap);
623
624
625
626
627
628
629
630
631
632
633 void cnstr_shdsc_gcm_encap(u32 * const desc, struct alginfo *cdata,
634 unsigned int ivsize, unsigned int icvsize,
635 const bool is_qi)
636 {
637 u32 *key_jump_cmd, *zero_payload_jump_cmd, *zero_assoc_jump_cmd1,
638 *zero_assoc_jump_cmd2;
639
640 init_sh_desc(desc, HDR_SHARE_SERIAL);
641
642
643 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
644 JUMP_COND_SHRD);
645 if (cdata->key_inline)
646 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
647 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
648 else
649 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
650 KEY_DEST_CLASS_REG);
651 set_jump_tgt_here(desc, key_jump_cmd);
652
653
654 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
655 OP_ALG_ENCRYPT);
656
657 if (is_qi) {
658 u32 *wait_load_cmd;
659
660
661 append_seq_load(desc, 4, LDST_CLASS_DECO |
662 LDST_SRCDST_WORD_DECO_MATH3 |
663 (4 << LDST_OFFSET_SHIFT));
664
665 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
666 JUMP_COND_CALM | JUMP_COND_NCP |
667 JUMP_COND_NOP | JUMP_COND_NIP |
668 JUMP_COND_NIFP);
669 set_jump_tgt_here(desc, wait_load_cmd);
670
671 append_math_sub_imm_u32(desc, VARSEQOUTLEN, SEQINLEN, IMM,
672 ivsize);
673 } else {
674 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0,
675 CAAM_CMD_SZ);
676 }
677
678
679 zero_assoc_jump_cmd2 = append_jump(desc, JUMP_TEST_ALL |
680 JUMP_COND_MATH_Z);
681
682 if (is_qi)
683 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
684 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
685
686
687 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
688 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
689 JUMP_COND_MATH_Z);
690
691 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
692
693
694 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
695
696
697 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
698
699
700 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
701 JUMP_COND_MATH_Z);
702
703
704 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
705 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
706 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
707
708 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
709
710
711 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
712
713
714 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
715 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
716
717
718 if (is_qi)
719 append_jump(desc, JUMP_TEST_ALL | 4);
720 else
721 append_jump(desc, JUMP_TEST_ALL | 2);
722
723
724 set_jump_tgt_here(desc, zero_payload_jump_cmd);
725
726
727 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
728 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
729 if (is_qi)
730
731 append_jump(desc, JUMP_TEST_ALL | 2);
732
733
734 set_jump_tgt_here(desc, zero_assoc_jump_cmd2);
735
736 if (is_qi)
737 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
738 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 |
739 FIFOLD_TYPE_LAST1);
740
741
742 append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
743 LDST_SRCDST_BYTE_CONTEXT);
744
745 print_hex_dump_debug("gcm enc shdesc@" __stringify(__LINE__)": ",
746 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
747 1);
748 }
749 EXPORT_SYMBOL(cnstr_shdsc_gcm_encap);
750
751
752
753
754
755
756
757
758
759
760 void cnstr_shdsc_gcm_decap(u32 * const desc, struct alginfo *cdata,
761 unsigned int ivsize, unsigned int icvsize,
762 const bool is_qi)
763 {
764 u32 *key_jump_cmd, *zero_payload_jump_cmd, *zero_assoc_jump_cmd1;
765
766 init_sh_desc(desc, HDR_SHARE_SERIAL);
767
768
769 key_jump_cmd = append_jump(desc, JUMP_JSL |
770 JUMP_TEST_ALL | JUMP_COND_SHRD);
771 if (cdata->key_inline)
772 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
773 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
774 else
775 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
776 KEY_DEST_CLASS_REG);
777 set_jump_tgt_here(desc, key_jump_cmd);
778
779
780 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
781 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
782
783 if (is_qi) {
784 u32 *wait_load_cmd;
785
786
787 append_seq_load(desc, 4, LDST_CLASS_DECO |
788 LDST_SRCDST_WORD_DECO_MATH3 |
789 (4 << LDST_OFFSET_SHIFT));
790
791 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
792 JUMP_COND_CALM | JUMP_COND_NCP |
793 JUMP_COND_NOP | JUMP_COND_NIP |
794 JUMP_COND_NIFP);
795 set_jump_tgt_here(desc, wait_load_cmd);
796
797 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
798 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
799 }
800
801
802 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
803 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
804 JUMP_COND_MATH_Z);
805
806 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
807
808
809 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
810
811
812 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
813 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
814
815 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
816
817
818 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
819
820
821 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
822 JUMP_COND_MATH_Z);
823
824 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
825
826
827 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
828
829
830 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
831 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
832
833
834 set_jump_tgt_here(desc, zero_payload_jump_cmd);
835
836
837 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
838 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
839
840 print_hex_dump_debug("gcm dec shdesc@" __stringify(__LINE__)": ",
841 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
842 1);
843 }
844 EXPORT_SYMBOL(cnstr_shdsc_gcm_decap);
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860 void cnstr_shdsc_rfc4106_encap(u32 * const desc, struct alginfo *cdata,
861 unsigned int ivsize, unsigned int icvsize,
862 const bool is_qi)
863 {
864 u32 *key_jump_cmd, *zero_cryptlen_jump_cmd, *skip_instructions;
865 init_sh_desc(desc, HDR_SHARE_SERIAL);
866
867
868 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
869 JUMP_COND_SHRD);
870 if (cdata->key_inline)
871 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
872 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
873 else
874 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
875 KEY_DEST_CLASS_REG);
876 set_jump_tgt_here(desc, key_jump_cmd);
877
878
879 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
880 OP_ALG_ENCRYPT);
881
882 if (is_qi) {
883 u32 *wait_load_cmd;
884
885
886 append_seq_load(desc, 4, LDST_CLASS_DECO |
887 LDST_SRCDST_WORD_DECO_MATH3 |
888 (4 << LDST_OFFSET_SHIFT));
889
890 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
891 JUMP_COND_CALM | JUMP_COND_NCP |
892 JUMP_COND_NOP | JUMP_COND_NIP |
893 JUMP_COND_NIFP);
894 set_jump_tgt_here(desc, wait_load_cmd);
895
896
897 append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
898 cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
899 FIFOLD_TYPE_IV);
900 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
901 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
902 }
903
904 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize);
905 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
906
907
908 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
909
910
911 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
912
913
914 zero_cryptlen_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
915 JUMP_COND_MATH_Z);
916
917
918 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
919 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
920
921
922 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA);
923
924
925 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP);
926 append_math_add(desc, VARSEQINLEN, VARSEQOUTLEN, REG0, CAAM_CMD_SZ);
927
928
929 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
930
931
932 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
933 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
934
935
936 skip_instructions = append_jump(desc, JUMP_TEST_ALL);
937
938
939 set_jump_tgt_here(desc, zero_cryptlen_jump_cmd);
940
941
942 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
943 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
944
945 set_jump_tgt_here(desc, skip_instructions);
946
947
948 append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
949 LDST_SRCDST_BYTE_CONTEXT);
950
951 print_hex_dump_debug("rfc4106 enc shdesc@" __stringify(__LINE__)": ",
952 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
953 1);
954 }
955 EXPORT_SYMBOL(cnstr_shdsc_rfc4106_encap);
956
957
958
959
960
961
962
963
964
965
966
967 void cnstr_shdsc_rfc4106_decap(u32 * const desc, struct alginfo *cdata,
968 unsigned int ivsize, unsigned int icvsize,
969 const bool is_qi)
970 {
971 u32 *key_jump_cmd;
972
973 init_sh_desc(desc, HDR_SHARE_SERIAL);
974
975
976 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
977 JUMP_COND_SHRD);
978 if (cdata->key_inline)
979 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
980 cdata->keylen, CLASS_1 |
981 KEY_DEST_CLASS_REG);
982 else
983 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
984 KEY_DEST_CLASS_REG);
985 set_jump_tgt_here(desc, key_jump_cmd);
986
987
988 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
989 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
990
991 if (is_qi) {
992 u32 *wait_load_cmd;
993
994
995 append_seq_load(desc, 4, LDST_CLASS_DECO |
996 LDST_SRCDST_WORD_DECO_MATH3 |
997 (4 << LDST_OFFSET_SHIFT));
998
999 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1000 JUMP_COND_CALM | JUMP_COND_NCP |
1001 JUMP_COND_NOP | JUMP_COND_NIP |
1002 JUMP_COND_NIFP);
1003 set_jump_tgt_here(desc, wait_load_cmd);
1004
1005
1006 append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
1007 cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
1008 FIFOLD_TYPE_IV);
1009 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
1010 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
1011 }
1012
1013 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, ivsize);
1014 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
1015
1016
1017 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1018 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
1019
1020
1021 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_SKIP);
1022
1023
1024 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
1025
1026
1027 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
1028
1029
1030 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1031
1032
1033 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1034
1035
1036 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1037
1038
1039 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1040 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
1041
1042
1043 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
1044 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1045
1046 print_hex_dump_debug("rfc4106 dec shdesc@" __stringify(__LINE__)": ",
1047 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1048 1);
1049 }
1050 EXPORT_SYMBOL(cnstr_shdsc_rfc4106_decap);
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062 void cnstr_shdsc_rfc4543_encap(u32 * const desc, struct alginfo *cdata,
1063 unsigned int ivsize, unsigned int icvsize,
1064 const bool is_qi)
1065 {
1066 u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
1067
1068 init_sh_desc(desc, HDR_SHARE_SERIAL);
1069
1070
1071 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1072 JUMP_COND_SHRD);
1073 if (cdata->key_inline)
1074 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1075 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1076 else
1077 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
1078 KEY_DEST_CLASS_REG);
1079 set_jump_tgt_here(desc, key_jump_cmd);
1080
1081
1082 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
1083 OP_ALG_ENCRYPT);
1084
1085 if (is_qi) {
1086
1087 append_seq_fifo_load(desc, 4, FIFOLD_CLASS_SKIP);
1088
1089
1090 append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
1091 cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
1092 FIFOLD_TYPE_IV);
1093 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
1094 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
1095 }
1096
1097
1098 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
1099
1100
1101
1102
1103
1104
1105 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1106 (0x6 << MOVE_LEN_SHIFT));
1107 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1108 (0x8 << MOVE_LEN_SHIFT) | MOVE_WAITCOMP);
1109
1110
1111 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1112
1113
1114 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1115
1116
1117 aead_append_src_dst(desc, FIFOLD_TYPE_AAD);
1118
1119 set_move_tgt_here(desc, read_move_cmd);
1120 set_move_tgt_here(desc, write_move_cmd);
1121 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1122
1123 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1124
1125
1126 append_seq_store(desc, icvsize, LDST_CLASS_1_CCB |
1127 LDST_SRCDST_BYTE_CONTEXT);
1128
1129 print_hex_dump_debug("rfc4543 enc shdesc@" __stringify(__LINE__)": ",
1130 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1131 1);
1132 }
1133 EXPORT_SYMBOL(cnstr_shdsc_rfc4543_encap);
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145 void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata,
1146 unsigned int ivsize, unsigned int icvsize,
1147 const bool is_qi)
1148 {
1149 u32 *key_jump_cmd, *read_move_cmd, *write_move_cmd;
1150
1151 init_sh_desc(desc, HDR_SHARE_SERIAL);
1152
1153
1154 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1155 JUMP_COND_SHRD);
1156 if (cdata->key_inline)
1157 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1158 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1159 else
1160 append_key(desc, cdata->key_dma, cdata->keylen, CLASS_1 |
1161 KEY_DEST_CLASS_REG);
1162 set_jump_tgt_here(desc, key_jump_cmd);
1163
1164
1165 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
1166 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1167
1168 if (is_qi) {
1169
1170 append_seq_fifo_load(desc, 4, FIFOLD_CLASS_SKIP);
1171
1172
1173 append_fifo_load_as_imm(desc, (void *)(cdata->key_virt +
1174 cdata->keylen), 4, FIFOLD_CLASS_CLASS1 |
1175 FIFOLD_TYPE_IV);
1176 append_seq_fifo_load(desc, ivsize, FIFOLD_CLASS_CLASS1 |
1177 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1);
1178 }
1179
1180
1181 append_math_sub(desc, REG3, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1182
1183
1184
1185
1186
1187
1188 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1189 (0x6 << MOVE_LEN_SHIFT));
1190 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1191 (0x8 << MOVE_LEN_SHIFT) | MOVE_WAITCOMP);
1192
1193
1194 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1195
1196
1197 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1198
1199
1200 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1201
1202
1203 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLDST_VLF |
1204 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST2FLUSH1);
1205
1206 set_move_tgt_here(desc, read_move_cmd);
1207 set_move_tgt_here(desc, write_move_cmd);
1208 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1209
1210 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1211 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
1212
1213
1214 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS1 |
1215 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1216
1217 print_hex_dump_debug("rfc4543 dec shdesc@" __stringify(__LINE__)": ",
1218 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1219 1);
1220 }
1221 EXPORT_SYMBOL(cnstr_shdsc_rfc4543_decap);
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239 void cnstr_shdsc_chachapoly(u32 * const desc, struct alginfo *cdata,
1240 struct alginfo *adata, unsigned int ivsize,
1241 unsigned int icvsize, const bool encap,
1242 const bool is_qi)
1243 {
1244 u32 *key_jump_cmd, *wait_cmd;
1245 u32 nfifo;
1246 const bool is_ipsec = (ivsize != CHACHAPOLY_IV_SIZE);
1247
1248
1249 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1250
1251
1252 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1253 JUMP_COND_SHRD);
1254
1255 append_key_as_imm(desc, cdata->key_virt, cdata->keylen, cdata->keylen,
1256 CLASS_1 | KEY_DEST_CLASS_REG);
1257
1258
1259 if (is_ipsec)
1260 append_load_as_imm(desc, cdata->key_virt + cdata->keylen, 4,
1261 LDST_CLASS_1_CCB | LDST_SRCDST_BYTE_CONTEXT |
1262 4 << LDST_OFFSET_SHIFT);
1263
1264 set_jump_tgt_here(desc, key_jump_cmd);
1265
1266
1267 if (encap) {
1268 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
1269 OP_ALG_ENCRYPT);
1270 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
1271 OP_ALG_ENCRYPT);
1272 } else {
1273 append_operation(desc, adata->algtype | OP_ALG_AS_INITFINAL |
1274 OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1275 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
1276 OP_ALG_DECRYPT);
1277 }
1278
1279 if (is_qi) {
1280 u32 *wait_load_cmd;
1281 u32 ctx1_iv_off = is_ipsec ? 8 : 4;
1282
1283
1284 append_seq_load(desc, 4, LDST_CLASS_DECO |
1285 LDST_SRCDST_WORD_DECO_MATH3 |
1286 4 << LDST_OFFSET_SHIFT);
1287
1288 wait_load_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1289 JUMP_COND_CALM | JUMP_COND_NCP |
1290 JUMP_COND_NOP | JUMP_COND_NIP |
1291 JUMP_COND_NIFP);
1292 set_jump_tgt_here(desc, wait_load_cmd);
1293
1294 append_seq_load(desc, ivsize, LDST_CLASS_1_CCB |
1295 LDST_SRCDST_BYTE_CONTEXT |
1296 ctx1_iv_off << LDST_OFFSET_SHIFT);
1297 }
1298
1299
1300
1301
1302
1303
1304
1305 nfifo = NFIFOENTRY_DEST_BOTH | NFIFOENTRY_FC1 | NFIFOENTRY_FC2 |
1306 NFIFOENTRY_DTYPE_POLY | NFIFOENTRY_BND;
1307 append_load_imm_u32(desc, nfifo, LDST_CLASS_IND_CCB |
1308 LDST_SRCDST_WORD_INFO_FIFO_SM | LDLEN_MATH3);
1309
1310 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
1311 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
1312 append_seq_fifo_load(desc, 0, FIFOLD_TYPE_NOINFOFIFO |
1313 FIFOLD_CLASS_CLASS1 | LDST_VLF);
1314 append_move_len(desc, MOVE_AUX_LS | MOVE_SRC_AUX_ABLK |
1315 MOVE_DEST_OUTFIFO | MOVELEN_MRSEL_MATH3);
1316 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | LDST_VLF);
1317
1318
1319 if (is_ipsec)
1320 append_seq_fifo_store(desc, ivsize, FIFOST_TYPE_METADATA |
1321 0x2 << 25);
1322
1323 wait_cmd = append_jump(desc, JUMP_JSL | JUMP_TYPE_LOCAL |
1324 JUMP_COND_NOP | JUMP_TEST_ALL);
1325 set_jump_tgt_here(desc, wait_cmd);
1326
1327 if (encap) {
1328
1329 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1330 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0,
1331 CAAM_CMD_SZ);
1332 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
1333
1334
1335 append_seq_store(desc, icvsize, LDST_CLASS_2_CCB |
1336 LDST_SRCDST_BYTE_CONTEXT);
1337 } else {
1338
1339 append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0,
1340 CAAM_CMD_SZ);
1341 append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0,
1342 CAAM_CMD_SZ);
1343 aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
1344
1345
1346 append_seq_fifo_load(desc, icvsize, FIFOLD_CLASS_CLASS2 |
1347 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
1348 }
1349
1350 print_hex_dump_debug("chachapoly shdesc@" __stringify(__LINE__)": ",
1351 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1352 1);
1353 }
1354 EXPORT_SYMBOL(cnstr_shdsc_chachapoly);
1355
1356
1357 static inline void skcipher_append_src_dst(u32 *desc)
1358 {
1359 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1360 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1361 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
1362 KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
1363 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
1364 }
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377 void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata,
1378 unsigned int ivsize, const bool is_rfc3686,
1379 const u32 ctx1_iv_off)
1380 {
1381 u32 *key_jump_cmd;
1382 u32 options = cdata->algtype | OP_ALG_AS_INIT | OP_ALG_ENCRYPT;
1383 bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) ==
1384 OP_ALG_ALGSEL_CHACHA20);
1385
1386 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1387
1388 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1389 JUMP_COND_SHRD);
1390
1391
1392 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1393 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1394
1395
1396 if (is_rfc3686) {
1397 const u8 *nonce = cdata->key_virt + cdata->keylen;
1398
1399 append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
1400 LDST_CLASS_IND_CCB |
1401 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1402 append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO |
1403 MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) |
1404 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1405 }
1406
1407 set_jump_tgt_here(desc, key_jump_cmd);
1408
1409
1410 if (ivsize)
1411 append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
1412 LDST_CLASS_1_CCB | (ctx1_iv_off <<
1413 LDST_OFFSET_SHIFT));
1414
1415
1416 if (is_rfc3686)
1417 append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
1418 LDST_SRCDST_BYTE_CONTEXT |
1419 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1420 LDST_OFFSET_SHIFT));
1421
1422
1423 if (is_chacha20)
1424 options |= OP_ALG_AS_FINALIZE;
1425 append_operation(desc, options);
1426
1427
1428 skcipher_append_src_dst(desc);
1429
1430
1431 if (!is_chacha20 && ivsize)
1432 append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
1433 LDST_CLASS_1_CCB | (ctx1_iv_off <<
1434 LDST_OFFSET_SHIFT));
1435
1436 print_hex_dump_debug("skcipher enc shdesc@" __stringify(__LINE__)": ",
1437 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1438 1);
1439 }
1440 EXPORT_SYMBOL(cnstr_shdsc_skcipher_encap);
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453 void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata,
1454 unsigned int ivsize, const bool is_rfc3686,
1455 const u32 ctx1_iv_off)
1456 {
1457 u32 *key_jump_cmd;
1458 bool is_chacha20 = ((cdata->algtype & OP_ALG_ALGSEL_MASK) ==
1459 OP_ALG_ALGSEL_CHACHA20);
1460
1461 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1462
1463 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1464 JUMP_COND_SHRD);
1465
1466
1467 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1468 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1469
1470
1471 if (is_rfc3686) {
1472 const u8 *nonce = cdata->key_virt + cdata->keylen;
1473
1474 append_load_as_imm(desc, nonce, CTR_RFC3686_NONCE_SIZE,
1475 LDST_CLASS_IND_CCB |
1476 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1477 append_move(desc, MOVE_WAITCOMP | MOVE_SRC_OUTFIFO |
1478 MOVE_DEST_CLASS1CTX | (16 << MOVE_OFFSET_SHIFT) |
1479 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1480 }
1481
1482 set_jump_tgt_here(desc, key_jump_cmd);
1483
1484
1485 if (ivsize)
1486 append_seq_load(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
1487 LDST_CLASS_1_CCB | (ctx1_iv_off <<
1488 LDST_OFFSET_SHIFT));
1489
1490
1491 if (is_rfc3686)
1492 append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB |
1493 LDST_SRCDST_BYTE_CONTEXT |
1494 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1495 LDST_OFFSET_SHIFT));
1496
1497
1498 if (ctx1_iv_off)
1499 append_operation(desc, cdata->algtype | OP_ALG_AS_INIT |
1500 OP_ALG_DECRYPT);
1501 else
1502 append_dec_op1(desc, cdata->algtype);
1503
1504
1505 skcipher_append_src_dst(desc);
1506
1507
1508 if (!is_chacha20 && ivsize)
1509 append_seq_store(desc, ivsize, LDST_SRCDST_BYTE_CONTEXT |
1510 LDST_CLASS_1_CCB | (ctx1_iv_off <<
1511 LDST_OFFSET_SHIFT));
1512
1513 print_hex_dump_debug("skcipher dec shdesc@" __stringify(__LINE__)": ",
1514 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1515 1);
1516 }
1517 EXPORT_SYMBOL(cnstr_shdsc_skcipher_decap);
1518
1519
1520
1521
1522
1523
1524
1525 void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata)
1526 {
1527
1528
1529
1530
1531
1532
1533 __be64 sector_size = cpu_to_be64(BIT(15));
1534 u32 *key_jump_cmd;
1535
1536 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1537
1538 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1539 JUMP_COND_SHRD);
1540
1541
1542 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1543 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1544
1545
1546 append_load_as_imm(desc, (void *)§or_size, 8, LDST_CLASS_1_CCB |
1547 LDST_SRCDST_BYTE_CONTEXT |
1548 (0x28 << LDST_OFFSET_SHIFT));
1549
1550 set_jump_tgt_here(desc, key_jump_cmd);
1551
1552
1553
1554
1555
1556
1557 append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1558 (0x20 << LDST_OFFSET_SHIFT));
1559 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
1560
1561
1562 append_operation(desc, cdata->algtype | OP_ALG_AS_INITFINAL |
1563 OP_ALG_ENCRYPT);
1564
1565
1566 skcipher_append_src_dst(desc);
1567
1568
1569 append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1570 (0x20 << LDST_OFFSET_SHIFT));
1571
1572 print_hex_dump_debug("xts skcipher enc shdesc@" __stringify(__LINE__)
1573 ": ", DUMP_PREFIX_ADDRESS, 16, 4,
1574 desc, desc_bytes(desc), 1);
1575 }
1576 EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_encap);
1577
1578
1579
1580
1581
1582
1583
1584 void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata)
1585 {
1586
1587
1588
1589
1590
1591
1592 __be64 sector_size = cpu_to_be64(BIT(15));
1593 u32 *key_jump_cmd;
1594
1595 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1596
1597 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1598 JUMP_COND_SHRD);
1599
1600
1601 append_key_as_imm(desc, cdata->key_virt, cdata->keylen,
1602 cdata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
1603
1604
1605 append_load_as_imm(desc, (void *)§or_size, 8, LDST_CLASS_1_CCB |
1606 LDST_SRCDST_BYTE_CONTEXT |
1607 (0x28 << LDST_OFFSET_SHIFT));
1608
1609 set_jump_tgt_here(desc, key_jump_cmd);
1610
1611
1612
1613
1614
1615
1616 append_seq_load(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1617 (0x20 << LDST_OFFSET_SHIFT));
1618 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
1619
1620
1621 append_dec_op1(desc, cdata->algtype);
1622
1623
1624 skcipher_append_src_dst(desc);
1625
1626
1627 append_seq_store(desc, 8, LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1628 (0x20 << LDST_OFFSET_SHIFT));
1629
1630 print_hex_dump_debug("xts skcipher dec shdesc@" __stringify(__LINE__)
1631 ": ", DUMP_PREFIX_ADDRESS, 16, 4, desc,
1632 desc_bytes(desc), 1);
1633 }
1634 EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_decap);
1635
1636 MODULE_LICENSE("GPL");
1637 MODULE_DESCRIPTION("FSL CAAM descriptor support");
1638 MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");