2 * caam - Freescale FSL CAAM support for crypto API
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
6 * Based on talitos crypto API driver.
8 * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
10 * --------------- ---------------
11 * | JobDesc #1 |-------------------->| ShareDesc |
12 * | *(packet 1) | | (PDB) |
13 * --------------- |------------->| (hashKey) |
15 * . | |-------->| (operation) |
16 * --------------- | | ---------------
17 * | JobDesc #2 |------| |
23 * | JobDesc #3 |------------
27 * The SharedDesc never changes for a connection unless rekeyed, but
28 * each packet will likely be in a different place. So all we need
29 * to know to process the packet is where the input is, where the
30 * output goes, and what context we want to process with. Context is
31 * in the SharedDesc, packet references in the JobDesc.
33 * So, a job desc looks like:
35 * ---------------------
37 * | ShareDesc Pointer |
44 * ---------------------
51 #include "desc_constr.h"
54 #include "sg_sw_sec4.h"
60 #define CAAM_CRA_PRIORITY 3000
61 /* max key is sum of AES_MAX_KEY_SIZE, max split key size */
62 #define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
63 CTR_RFC3686_NONCE_SIZE + \
64 SHA512_DIGEST_SIZE * 2)
65 /* max IV is max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
66 #define CAAM_MAX_IV_LENGTH 16
68 #define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
69 #define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
71 #define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
74 /* length of descriptors text */
75 #define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
76 #define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
77 #define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
78 #define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 9 * CAAM_CMD_SZ)
80 /* Note: Nonce is counted in enckeylen */
81 #define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
83 #define DESC_AEAD_NULL_BASE (3 * CAAM_CMD_SZ)
84 #define DESC_AEAD_NULL_ENC_LEN (DESC_AEAD_NULL_BASE + 11 * CAAM_CMD_SZ)
85 #define DESC_AEAD_NULL_DEC_LEN (DESC_AEAD_NULL_BASE + 13 * CAAM_CMD_SZ)
87 #define DESC_GCM_BASE (3 * CAAM_CMD_SZ)
88 #define DESC_GCM_ENC_LEN (DESC_GCM_BASE + 16 * CAAM_CMD_SZ)
89 #define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
91 #define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
92 #define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
93 #define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
95 #define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
96 #define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
97 #define DESC_RFC4543_DEC_LEN (DESC_RFC4543_BASE + 12 * CAAM_CMD_SZ)
99 #define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ)
100 #define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \
102 #define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \
105 #define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN)
106 #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
109 /* for print_hex_dumps with line references */
110 #define debug(format, arg...) printk(format, arg)
112 #define debug(format, arg...)
114 static struct list_head alg_list;
116 struct caam_alg_entry {
124 struct caam_aead_alg {
125 struct aead_alg aead;
126 struct caam_alg_entry caam;
130 /* Set DK bit in class 1 operation if shared */
131 static inline void append_dec_op1(u32 *desc, u32 type)
133 u32 *jump_cmd, *uncond_jump_cmd;
135 /* DK bit is valid only for AES */
136 if ((type & OP_ALG_ALGSEL_MASK) != OP_ALG_ALGSEL_AES) {
137 append_operation(desc, type | OP_ALG_AS_INITFINAL |
142 jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
143 append_operation(desc, type | OP_ALG_AS_INITFINAL |
145 uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL);
146 set_jump_tgt_here(desc, jump_cmd);
147 append_operation(desc, type | OP_ALG_AS_INITFINAL |
148 OP_ALG_DECRYPT | OP_ALG_AAI_DK);
149 set_jump_tgt_here(desc, uncond_jump_cmd);
153 * For aead functions, read payload and write payload,
154 * both of which are specified in req->src and req->dst
156 static inline void aead_append_src_dst(u32 *desc, u32 msg_type)
158 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
159 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
160 KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH);
164 * For ablkcipher encrypt and decrypt, read from req->src and
167 static inline void ablkcipher_append_src_dst(u32 *desc)
169 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
170 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
171 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
172 KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
173 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
177 * per-session context
180 struct device *jrdev;
181 u32 sh_desc_enc[DESC_MAX_USED_LEN];
182 u32 sh_desc_dec[DESC_MAX_USED_LEN];
183 u32 sh_desc_givenc[DESC_MAX_USED_LEN];
184 dma_addr_t sh_desc_enc_dma;
185 dma_addr_t sh_desc_dec_dma;
186 dma_addr_t sh_desc_givenc_dma;
190 u8 key[CAAM_MAX_KEY_SIZE];
192 unsigned int enckeylen;
193 unsigned int split_key_len;
194 unsigned int split_key_pad_len;
195 unsigned int authsize;
198 static void append_key_aead(u32 *desc, struct caam_ctx *ctx,
199 int keys_fit_inline, bool is_rfc3686)
202 unsigned int enckeylen = ctx->enckeylen;
206 * | ctx->key = {AUTH_KEY, ENC_KEY, NONCE}
207 * | enckeylen = encryption key size + nonce size
210 enckeylen -= CTR_RFC3686_NONCE_SIZE;
212 if (keys_fit_inline) {
213 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
214 ctx->split_key_len, CLASS_2 |
215 KEY_DEST_MDHA_SPLIT | KEY_ENC);
216 append_key_as_imm(desc, (void *)ctx->key +
217 ctx->split_key_pad_len, enckeylen,
218 enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
220 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
221 KEY_DEST_MDHA_SPLIT | KEY_ENC);
222 append_key(desc, ctx->key_dma + ctx->split_key_pad_len,
223 enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
226 /* Load Counter into CONTEXT1 reg */
228 nonce = (u32 *)((void *)ctx->key + ctx->split_key_pad_len +
230 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
231 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
234 MOVE_DEST_CLASS1CTX |
235 (16 << MOVE_OFFSET_SHIFT) |
236 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
240 static void init_sh_desc_key_aead(u32 *desc, struct caam_ctx *ctx,
241 int keys_fit_inline, bool is_rfc3686)
245 /* Note: Context registers are saved. */
246 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
248 /* Skip if already shared */
249 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
252 append_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
254 set_jump_tgt_here(desc, key_jump_cmd);
257 static int aead_null_set_sh_desc(struct crypto_aead *aead)
259 struct caam_ctx *ctx = crypto_aead_ctx(aead);
260 struct device *jrdev = ctx->jrdev;
261 bool keys_fit_inline = false;
262 u32 *key_jump_cmd, *jump_cmd, *read_move_cmd, *write_move_cmd;
266 * Job Descriptor and Shared Descriptors
267 * must all fit into the 64-word Descriptor h/w Buffer
269 if (DESC_AEAD_NULL_ENC_LEN + AEAD_DESC_JOB_IO_LEN +
270 ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
271 keys_fit_inline = true;
273 /* aead_encrypt shared descriptor */
274 desc = ctx->sh_desc_enc;
276 init_sh_desc(desc, HDR_SHARE_SERIAL);
278 /* Skip if already shared */
279 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
282 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
283 ctx->split_key_len, CLASS_2 |
284 KEY_DEST_MDHA_SPLIT | KEY_ENC);
286 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
287 KEY_DEST_MDHA_SPLIT | KEY_ENC);
288 set_jump_tgt_here(desc, key_jump_cmd);
290 /* assoclen + cryptlen = seqinlen */
291 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
293 /* Prepare to read and write cryptlen + assoclen bytes */
294 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
295 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
298 * MOVE_LEN opcode is not available in all SEC HW revisions,
299 * thus need to do some magic, i.e. self-patch the descriptor
302 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
304 (0x6 << MOVE_LEN_SHIFT));
305 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 |
308 (0x8 << MOVE_LEN_SHIFT));
310 /* Class 2 operation */
311 append_operation(desc, ctx->class2_alg_type |
312 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
314 /* Read and write cryptlen bytes */
315 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
317 set_move_tgt_here(desc, read_move_cmd);
318 set_move_tgt_here(desc, write_move_cmd);
319 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
320 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
324 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
325 LDST_SRCDST_BYTE_CONTEXT);
327 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
330 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
331 dev_err(jrdev, "unable to map shared descriptor\n");
335 print_hex_dump(KERN_ERR,
336 "aead null enc shdesc@"__stringify(__LINE__)": ",
337 DUMP_PREFIX_ADDRESS, 16, 4, desc,
338 desc_bytes(desc), 1);
342 * Job Descriptor and Shared Descriptors
343 * must all fit into the 64-word Descriptor h/w Buffer
345 keys_fit_inline = false;
346 if (DESC_AEAD_NULL_DEC_LEN + DESC_JOB_IO_LEN +
347 ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
348 keys_fit_inline = true;
350 desc = ctx->sh_desc_dec;
352 /* aead_decrypt shared descriptor */
353 init_sh_desc(desc, HDR_SHARE_SERIAL);
355 /* Skip if already shared */
356 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
359 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
360 ctx->split_key_len, CLASS_2 |
361 KEY_DEST_MDHA_SPLIT | KEY_ENC);
363 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
364 KEY_DEST_MDHA_SPLIT | KEY_ENC);
365 set_jump_tgt_here(desc, key_jump_cmd);
367 /* Class 2 operation */
368 append_operation(desc, ctx->class2_alg_type |
369 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
371 /* assoclen + cryptlen = seqoutlen */
372 append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ);
374 /* Prepare to read and write cryptlen + assoclen bytes */
375 append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ);
376 append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ);
379 * MOVE_LEN opcode is not available in all SEC HW revisions,
380 * thus need to do some magic, i.e. self-patch the descriptor
383 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
385 (0x6 << MOVE_LEN_SHIFT));
386 write_move_cmd = append_move(desc, MOVE_SRC_MATH2 |
389 (0x8 << MOVE_LEN_SHIFT));
391 /* Read and write cryptlen bytes */
392 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
395 * Insert a NOP here, since we need at least 4 instructions between
396 * code patching the descriptor buffer and the location being patched.
398 jump_cmd = append_jump(desc, JUMP_TEST_ALL);
399 set_jump_tgt_here(desc, jump_cmd);
401 set_move_tgt_here(desc, read_move_cmd);
402 set_move_tgt_here(desc, write_move_cmd);
403 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
404 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
406 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
409 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
410 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
412 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
415 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
416 dev_err(jrdev, "unable to map shared descriptor\n");
420 print_hex_dump(KERN_ERR,
421 "aead null dec shdesc@"__stringify(__LINE__)": ",
422 DUMP_PREFIX_ADDRESS, 16, 4, desc,
423 desc_bytes(desc), 1);
429 static int aead_set_sh_desc(struct crypto_aead *aead)
431 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
432 struct caam_aead_alg, aead);
433 unsigned int ivsize = crypto_aead_ivsize(aead);
434 struct caam_ctx *ctx = crypto_aead_ctx(aead);
435 struct device *jrdev = ctx->jrdev;
436 bool keys_fit_inline;
440 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
441 OP_ALG_AAI_CTR_MOD128);
442 const bool is_rfc3686 = alg->caam.rfc3686;
444 /* NULL encryption / decryption */
446 return aead_null_set_sh_desc(aead);
449 * AES-CTR needs to load IV in CONTEXT1 reg
450 * at an offset of 128bits (16bytes)
451 * CONTEXT1[255:128] = IV
458 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
461 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
467 * Job Descriptor and Shared Descriptors
468 * must all fit into the 64-word Descriptor h/w Buffer
470 keys_fit_inline = false;
471 if (DESC_AEAD_ENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
472 ctx->split_key_pad_len + ctx->enckeylen +
473 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
475 keys_fit_inline = true;
477 /* aead_encrypt shared descriptor */
478 desc = ctx->sh_desc_enc;
480 /* Note: Context registers are saved. */
481 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
483 /* Class 2 operation */
484 append_operation(desc, ctx->class2_alg_type |
485 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
487 /* Read and write assoclen bytes */
488 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
489 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
491 /* Skip assoc data */
492 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
494 /* read assoc before reading payload */
495 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
498 /* Load Counter into CONTEXT1 reg */
500 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
502 LDST_SRCDST_BYTE_CONTEXT |
503 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
506 /* Class 1 operation */
507 append_operation(desc, ctx->class1_alg_type |
508 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
510 /* Read and write cryptlen bytes */
511 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
512 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
513 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
516 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
517 LDST_SRCDST_BYTE_CONTEXT);
519 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
522 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
523 dev_err(jrdev, "unable to map shared descriptor\n");
527 print_hex_dump(KERN_ERR, "aead enc shdesc@"__stringify(__LINE__)": ",
528 DUMP_PREFIX_ADDRESS, 16, 4, desc,
529 desc_bytes(desc), 1);
534 * Job Descriptor and Shared Descriptors
535 * must all fit into the 64-word Descriptor h/w Buffer
537 keys_fit_inline = false;
538 if (DESC_AEAD_DEC_LEN + AUTHENC_DESC_JOB_IO_LEN +
539 ctx->split_key_pad_len + ctx->enckeylen +
540 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
542 keys_fit_inline = true;
544 /* aead_decrypt shared descriptor */
545 desc = ctx->sh_desc_dec;
547 /* Note: Context registers are saved. */
548 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
550 /* Class 2 operation */
551 append_operation(desc, ctx->class2_alg_type |
552 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
554 /* Read and write assoclen bytes */
555 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
556 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
558 /* Skip assoc data */
559 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
561 /* read assoc before reading payload */
562 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
565 /* Load Counter into CONTEXT1 reg */
567 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
569 LDST_SRCDST_BYTE_CONTEXT |
570 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
573 /* Choose operation */
575 append_operation(desc, ctx->class1_alg_type |
576 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
578 append_dec_op1(desc, ctx->class1_alg_type);
580 /* Read and write cryptlen bytes */
581 append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
582 append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
583 aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
586 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
587 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
589 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
592 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
593 dev_err(jrdev, "unable to map shared descriptor\n");
597 print_hex_dump(KERN_ERR, "aead dec shdesc@"__stringify(__LINE__)": ",
598 DUMP_PREFIX_ADDRESS, 16, 4, desc,
599 desc_bytes(desc), 1);
602 if (!alg->caam.geniv)
606 * Job Descriptor and Shared Descriptors
607 * must all fit into the 64-word Descriptor h/w Buffer
609 keys_fit_inline = false;
610 if (DESC_AEAD_GIVENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
611 ctx->split_key_pad_len + ctx->enckeylen +
612 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
614 keys_fit_inline = true;
616 /* aead_givencrypt shared descriptor */
617 desc = ctx->sh_desc_givenc;
619 /* Note: Context registers are saved. */
620 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
626 geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
627 NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
628 NFIFOENTRY_PTYPE_RND | (ivsize << NFIFOENTRY_DLEN_SHIFT);
629 append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
630 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
631 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
632 append_move(desc, MOVE_WAITCOMP |
633 MOVE_SRC_INFIFO | MOVE_DEST_CLASS1CTX |
634 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
635 (ivsize << MOVE_LEN_SHIFT));
636 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
639 /* Copy IV to class 1 context */
640 append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_OUTFIFO |
641 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
642 (ivsize << MOVE_LEN_SHIFT));
644 /* Return to encryption */
645 append_operation(desc, ctx->class2_alg_type |
646 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
648 /* ivsize + cryptlen = seqoutlen - authsize */
649 append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
651 /* Read and write assoclen bytes */
652 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
653 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
655 /* Skip assoc data */
656 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
658 /* read assoc before reading payload */
659 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
662 /* Copy iv from outfifo to class 2 fifo */
663 moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 |
664 NFIFOENTRY_DTYPE_MSG | (ivsize << NFIFOENTRY_DLEN_SHIFT);
665 append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB |
666 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
667 append_load_imm_u32(desc, ivsize, LDST_CLASS_2_CCB |
668 LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
670 /* Load Counter into CONTEXT1 reg */
672 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
674 LDST_SRCDST_BYTE_CONTEXT |
675 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
678 /* Class 1 operation */
679 append_operation(desc, ctx->class1_alg_type |
680 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
682 /* Will write ivsize + cryptlen */
683 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
685 /* Not need to reload iv */
686 append_seq_fifo_load(desc, ivsize,
689 /* Will read cryptlen */
690 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
691 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
694 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
695 LDST_SRCDST_BYTE_CONTEXT);
697 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
700 if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
701 dev_err(jrdev, "unable to map shared descriptor\n");
705 print_hex_dump(KERN_ERR, "aead givenc shdesc@"__stringify(__LINE__)": ",
706 DUMP_PREFIX_ADDRESS, 16, 4, desc,
707 desc_bytes(desc), 1);
714 static int aead_setauthsize(struct crypto_aead *authenc,
715 unsigned int authsize)
717 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
719 ctx->authsize = authsize;
720 aead_set_sh_desc(authenc);
725 static int gcm_set_sh_desc(struct crypto_aead *aead)
727 struct caam_ctx *ctx = crypto_aead_ctx(aead);
728 struct device *jrdev = ctx->jrdev;
729 bool keys_fit_inline = false;
730 u32 *key_jump_cmd, *zero_payload_jump_cmd,
731 *zero_assoc_jump_cmd1, *zero_assoc_jump_cmd2;
734 if (!ctx->enckeylen || !ctx->authsize)
738 * AES GCM encrypt shared descriptor
739 * Job Descriptor and Shared Descriptor
740 * must fit into the 64-word Descriptor h/w Buffer
742 if (DESC_GCM_ENC_LEN + GCM_DESC_JOB_IO_LEN +
743 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
744 keys_fit_inline = true;
746 desc = ctx->sh_desc_enc;
748 init_sh_desc(desc, HDR_SHARE_SERIAL);
750 /* skip key loading if they are loaded due to sharing */
751 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
752 JUMP_COND_SHRD | JUMP_COND_SELF);
754 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
755 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
757 append_key(desc, ctx->key_dma, ctx->enckeylen,
758 CLASS_1 | KEY_DEST_CLASS_REG);
759 set_jump_tgt_here(desc, key_jump_cmd);
761 /* class 1 operation */
762 append_operation(desc, ctx->class1_alg_type |
763 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
765 /* if assoclen + cryptlen is ZERO, skip to ICV write */
766 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
767 zero_assoc_jump_cmd2 = append_jump(desc, JUMP_TEST_ALL |
770 /* if assoclen is ZERO, skip reading the assoc data */
771 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
772 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
775 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
777 /* skip assoc data */
778 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
780 /* cryptlen = seqinlen - assoclen */
781 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
783 /* if cryptlen is ZERO jump to zero-payload commands */
784 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
787 /* read assoc data */
788 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
789 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
790 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
792 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
794 /* write encrypted data */
795 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
797 /* read payload data */
798 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
799 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
801 /* jump the zero-payload commands */
802 append_jump(desc, JUMP_TEST_ALL | 2);
804 /* zero-payload commands */
805 set_jump_tgt_here(desc, zero_payload_jump_cmd);
807 /* read assoc data */
808 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
809 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
811 /* There is no input data */
812 set_jump_tgt_here(desc, zero_assoc_jump_cmd2);
815 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
816 LDST_SRCDST_BYTE_CONTEXT);
818 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
821 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
822 dev_err(jrdev, "unable to map shared descriptor\n");
826 print_hex_dump(KERN_ERR, "gcm enc shdesc@"__stringify(__LINE__)": ",
827 DUMP_PREFIX_ADDRESS, 16, 4, desc,
828 desc_bytes(desc), 1);
832 * Job Descriptor and Shared Descriptors
833 * must all fit into the 64-word Descriptor h/w Buffer
835 keys_fit_inline = false;
836 if (DESC_GCM_DEC_LEN + GCM_DESC_JOB_IO_LEN +
837 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
838 keys_fit_inline = true;
840 desc = ctx->sh_desc_dec;
842 init_sh_desc(desc, HDR_SHARE_SERIAL);
844 /* skip key loading if they are loaded due to sharing */
845 key_jump_cmd = append_jump(desc, JUMP_JSL |
846 JUMP_TEST_ALL | JUMP_COND_SHRD |
849 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
850 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
852 append_key(desc, ctx->key_dma, ctx->enckeylen,
853 CLASS_1 | KEY_DEST_CLASS_REG);
854 set_jump_tgt_here(desc, key_jump_cmd);
856 /* class 1 operation */
857 append_operation(desc, ctx->class1_alg_type |
858 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
860 /* if assoclen is ZERO, skip reading the assoc data */
861 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
862 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
865 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
867 /* skip assoc data */
868 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
870 /* read assoc data */
871 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
872 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
874 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
876 /* cryptlen = seqoutlen - assoclen */
877 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
879 /* jump to zero-payload command if cryptlen is zero */
880 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
883 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
885 /* store encrypted data */
886 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
888 /* read payload data */
889 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
890 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
892 /* zero-payload command */
893 set_jump_tgt_here(desc, zero_payload_jump_cmd);
896 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
897 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
899 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
902 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
903 dev_err(jrdev, "unable to map shared descriptor\n");
907 print_hex_dump(KERN_ERR, "gcm dec shdesc@"__stringify(__LINE__)": ",
908 DUMP_PREFIX_ADDRESS, 16, 4, desc,
909 desc_bytes(desc), 1);
915 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
917 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
919 ctx->authsize = authsize;
920 gcm_set_sh_desc(authenc);
925 static int rfc4106_set_sh_desc(struct crypto_aead *aead)
927 struct caam_ctx *ctx = crypto_aead_ctx(aead);
928 struct device *jrdev = ctx->jrdev;
929 bool keys_fit_inline = false;
933 if (!ctx->enckeylen || !ctx->authsize)
937 * RFC4106 encrypt shared descriptor
938 * Job Descriptor and Shared Descriptor
939 * must fit into the 64-word Descriptor h/w Buffer
941 if (DESC_RFC4106_ENC_LEN + GCM_DESC_JOB_IO_LEN +
942 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
943 keys_fit_inline = true;
945 desc = ctx->sh_desc_enc;
947 init_sh_desc(desc, HDR_SHARE_SERIAL);
949 /* Skip key loading if it is loaded due to sharing */
950 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
953 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
954 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
956 append_key(desc, ctx->key_dma, ctx->enckeylen,
957 CLASS_1 | KEY_DEST_CLASS_REG);
958 set_jump_tgt_here(desc, key_jump_cmd);
960 /* Class 1 operation */
961 append_operation(desc, ctx->class1_alg_type |
962 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
964 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
965 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
967 /* Read assoc data */
968 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
969 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
972 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
974 /* Will read cryptlen bytes */
975 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
977 /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
978 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
980 /* Skip assoc data */
981 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
983 /* cryptlen = seqoutlen - assoclen */
984 append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ);
986 /* Write encrypted data */
987 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
989 /* Read payload data */
990 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
991 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
994 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
995 LDST_SRCDST_BYTE_CONTEXT);
997 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
1000 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1001 dev_err(jrdev, "unable to map shared descriptor\n");
1005 print_hex_dump(KERN_ERR, "rfc4106 enc shdesc@"__stringify(__LINE__)": ",
1006 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1007 desc_bytes(desc), 1);
1011 * Job Descriptor and Shared Descriptors
1012 * must all fit into the 64-word Descriptor h/w Buffer
1014 keys_fit_inline = false;
1015 if (DESC_RFC4106_DEC_LEN + DESC_JOB_IO_LEN +
1016 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1017 keys_fit_inline = true;
1019 desc = ctx->sh_desc_dec;
1021 init_sh_desc(desc, HDR_SHARE_SERIAL);
1023 /* Skip key loading if it is loaded due to sharing */
1024 key_jump_cmd = append_jump(desc, JUMP_JSL |
1025 JUMP_TEST_ALL | JUMP_COND_SHRD);
1026 if (keys_fit_inline)
1027 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1028 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1030 append_key(desc, ctx->key_dma, ctx->enckeylen,
1031 CLASS_1 | KEY_DEST_CLASS_REG);
1032 set_jump_tgt_here(desc, key_jump_cmd);
1034 /* Class 1 operation */
1035 append_operation(desc, ctx->class1_alg_type |
1036 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1038 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
1039 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
1041 /* Read assoc data */
1042 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1043 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
1046 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
1048 /* Will read cryptlen bytes */
1049 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
1051 /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
1052 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
1054 /* Skip assoc data */
1055 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1057 /* Will write cryptlen bytes */
1058 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1060 /* Store payload data */
1061 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1063 /* Read encrypted data */
1064 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1065 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
1068 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
1069 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1071 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1074 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
1075 dev_err(jrdev, "unable to map shared descriptor\n");
1079 print_hex_dump(KERN_ERR, "rfc4106 dec shdesc@"__stringify(__LINE__)": ",
1080 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1081 desc_bytes(desc), 1);
1087 static int rfc4106_setauthsize(struct crypto_aead *authenc,
1088 unsigned int authsize)
1090 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
1092 ctx->authsize = authsize;
1093 rfc4106_set_sh_desc(authenc);
1098 static int rfc4543_set_sh_desc(struct crypto_aead *aead)
1100 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1101 struct device *jrdev = ctx->jrdev;
1102 bool keys_fit_inline = false;
1104 u32 *read_move_cmd, *write_move_cmd;
1107 if (!ctx->enckeylen || !ctx->authsize)
1111 * RFC4543 encrypt shared descriptor
1112 * Job Descriptor and Shared Descriptor
1113 * must fit into the 64-word Descriptor h/w Buffer
1115 if (DESC_RFC4543_ENC_LEN + GCM_DESC_JOB_IO_LEN +
1116 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1117 keys_fit_inline = true;
1119 desc = ctx->sh_desc_enc;
1121 init_sh_desc(desc, HDR_SHARE_SERIAL);
1123 /* Skip key loading if it is loaded due to sharing */
1124 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1126 if (keys_fit_inline)
1127 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1128 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1130 append_key(desc, ctx->key_dma, ctx->enckeylen,
1131 CLASS_1 | KEY_DEST_CLASS_REG);
1132 set_jump_tgt_here(desc, key_jump_cmd);
1134 /* Class 1 operation */
1135 append_operation(desc, ctx->class1_alg_type |
1136 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1138 /* assoclen + cryptlen = seqinlen */
1139 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
1142 * MOVE_LEN opcode is not available in all SEC HW revisions,
1143 * thus need to do some magic, i.e. self-patch the descriptor
1146 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1147 (0x6 << MOVE_LEN_SHIFT));
1148 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1149 (0x8 << MOVE_LEN_SHIFT));
1151 /* Will read assoclen + cryptlen bytes */
1152 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1154 /* Will write assoclen + cryptlen bytes */
1155 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1157 /* Read and write assoclen + cryptlen bytes */
1158 aead_append_src_dst(desc, FIFOLD_TYPE_AAD);
1160 set_move_tgt_here(desc, read_move_cmd);
1161 set_move_tgt_here(desc, write_move_cmd);
1162 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1163 /* Move payload data to OFIFO */
1164 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1167 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
1168 LDST_SRCDST_BYTE_CONTEXT);
1170 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
1173 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1174 dev_err(jrdev, "unable to map shared descriptor\n");
1178 print_hex_dump(KERN_ERR, "rfc4543 enc shdesc@"__stringify(__LINE__)": ",
1179 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1180 desc_bytes(desc), 1);
1184 * Job Descriptor and Shared Descriptors
1185 * must all fit into the 64-word Descriptor h/w Buffer
1187 keys_fit_inline = false;
1188 if (DESC_RFC4543_DEC_LEN + GCM_DESC_JOB_IO_LEN +
1189 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1190 keys_fit_inline = true;
1192 desc = ctx->sh_desc_dec;
1194 init_sh_desc(desc, HDR_SHARE_SERIAL);
1196 /* Skip key loading if it is loaded due to sharing */
1197 key_jump_cmd = append_jump(desc, JUMP_JSL |
1198 JUMP_TEST_ALL | JUMP_COND_SHRD);
1199 if (keys_fit_inline)
1200 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1201 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1203 append_key(desc, ctx->key_dma, ctx->enckeylen,
1204 CLASS_1 | KEY_DEST_CLASS_REG);
1205 set_jump_tgt_here(desc, key_jump_cmd);
1207 /* Class 1 operation */
1208 append_operation(desc, ctx->class1_alg_type |
1209 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1211 /* assoclen + cryptlen = seqoutlen */
1212 append_math_sub(desc, REG3, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1215 * MOVE_LEN opcode is not available in all SEC HW revisions,
1216 * thus need to do some magic, i.e. self-patch the descriptor
1219 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1220 (0x6 << MOVE_LEN_SHIFT));
1221 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1222 (0x8 << MOVE_LEN_SHIFT));
1224 /* Will read assoclen + cryptlen bytes */
1225 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1227 /* Will write assoclen + cryptlen bytes */
1228 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1230 /* Store payload data */
1231 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1233 /* In-snoop assoclen + cryptlen data */
1234 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLDST_VLF |
1235 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST2FLUSH1);
1237 set_move_tgt_here(desc, read_move_cmd);
1238 set_move_tgt_here(desc, write_move_cmd);
1239 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1240 /* Move payload data to OFIFO */
1241 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1242 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
1245 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
1246 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1248 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1251 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
1252 dev_err(jrdev, "unable to map shared descriptor\n");
1256 print_hex_dump(KERN_ERR, "rfc4543 dec shdesc@"__stringify(__LINE__)": ",
1257 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1258 desc_bytes(desc), 1);
1264 static int rfc4543_setauthsize(struct crypto_aead *authenc,
1265 unsigned int authsize)
1267 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
1269 ctx->authsize = authsize;
1270 rfc4543_set_sh_desc(authenc);
1275 static u32 gen_split_aead_key(struct caam_ctx *ctx, const u8 *key_in,
1278 return gen_split_key(ctx->jrdev, ctx->key, ctx->split_key_len,
1279 ctx->split_key_pad_len, key_in, authkeylen,
1283 static int aead_setkey(struct crypto_aead *aead,
1284 const u8 *key, unsigned int keylen)
1286 /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
1287 static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
1288 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1289 struct device *jrdev = ctx->jrdev;
1290 struct crypto_authenc_keys keys;
1293 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
1296 /* Pick class 2 key length from algorithm submask */
1297 ctx->split_key_len = mdpadlen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >>
1298 OP_ALG_ALGSEL_SHIFT] * 2;
1299 ctx->split_key_pad_len = ALIGN(ctx->split_key_len, 16);
1301 if (ctx->split_key_pad_len + keys.enckeylen > CAAM_MAX_KEY_SIZE)
1305 printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n",
1306 keys.authkeylen + keys.enckeylen, keys.enckeylen,
1308 printk(KERN_ERR "split_key_len %d split_key_pad_len %d\n",
1309 ctx->split_key_len, ctx->split_key_pad_len);
1310 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1311 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1314 ret = gen_split_aead_key(ctx, keys.authkey, keys.authkeylen);
1319 /* postpend encryption key to auth split key */
1320 memcpy(ctx->key + ctx->split_key_pad_len, keys.enckey, keys.enckeylen);
1322 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len +
1323 keys.enckeylen, DMA_TO_DEVICE);
1324 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1325 dev_err(jrdev, "unable to map key i/o memory\n");
1329 print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
1330 DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
1331 ctx->split_key_pad_len + keys.enckeylen, 1);
1334 ctx->enckeylen = keys.enckeylen;
1336 ret = aead_set_sh_desc(aead);
1338 dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len +
1339 keys.enckeylen, DMA_TO_DEVICE);
1344 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
1348 static int gcm_setkey(struct crypto_aead *aead,
1349 const u8 *key, unsigned int keylen)
1351 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1352 struct device *jrdev = ctx->jrdev;
1356 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1357 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1360 memcpy(ctx->key, key, keylen);
1361 ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
1363 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1364 dev_err(jrdev, "unable to map key i/o memory\n");
1367 ctx->enckeylen = keylen;
1369 ret = gcm_set_sh_desc(aead);
1371 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1378 static int rfc4106_setkey(struct crypto_aead *aead,
1379 const u8 *key, unsigned int keylen)
1381 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1382 struct device *jrdev = ctx->jrdev;
1389 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1390 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1393 memcpy(ctx->key, key, keylen);
1396 * The last four bytes of the key material are used as the salt value
1397 * in the nonce. Update the AES key length.
1399 ctx->enckeylen = keylen - 4;
1401 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
1403 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1404 dev_err(jrdev, "unable to map key i/o memory\n");
1408 ret = rfc4106_set_sh_desc(aead);
1410 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1417 static int rfc4543_setkey(struct crypto_aead *aead,
1418 const u8 *key, unsigned int keylen)
1420 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1421 struct device *jrdev = ctx->jrdev;
1428 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1429 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1432 memcpy(ctx->key, key, keylen);
1435 * The last four bytes of the key material are used as the salt value
1436 * in the nonce. Update the AES key length.
1438 ctx->enckeylen = keylen - 4;
1440 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
1442 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1443 dev_err(jrdev, "unable to map key i/o memory\n");
1447 ret = rfc4543_set_sh_desc(aead);
1449 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1456 static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
1457 const u8 *key, unsigned int keylen)
1459 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1460 struct ablkcipher_tfm *crt = &ablkcipher->base.crt_ablkcipher;
1461 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
1462 const char *alg_name = crypto_tfm_alg_name(tfm);
1463 struct device *jrdev = ctx->jrdev;
1469 u32 ctx1_iv_off = 0;
1470 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
1471 OP_ALG_AAI_CTR_MOD128);
1472 const bool is_rfc3686 = (ctr_mode &&
1473 (strstr(alg_name, "rfc3686") != NULL));
1476 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1477 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1480 * AES-CTR needs to load IV in CONTEXT1 reg
1481 * at an offset of 128bits (16bytes)
1482 * CONTEXT1[255:128] = IV
1489 * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
1490 * | *key = {KEY, NONCE}
1493 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
1494 keylen -= CTR_RFC3686_NONCE_SIZE;
1497 memcpy(ctx->key, key, keylen);
1498 ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
1500 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1501 dev_err(jrdev, "unable to map key i/o memory\n");
1504 ctx->enckeylen = keylen;
1506 /* ablkcipher_encrypt shared descriptor */
1507 desc = ctx->sh_desc_enc;
1508 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1509 /* Skip if already shared */
1510 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1513 /* Load class1 key only */
1514 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1515 ctx->enckeylen, CLASS_1 |
1516 KEY_DEST_CLASS_REG);
1518 /* Load nonce into CONTEXT1 reg */
1520 nonce = (u32 *)(key + keylen);
1521 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1522 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1523 append_move(desc, MOVE_WAITCOMP |
1525 MOVE_DEST_CLASS1CTX |
1526 (16 << MOVE_OFFSET_SHIFT) |
1527 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1530 set_jump_tgt_here(desc, key_jump_cmd);
1533 append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
1534 LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
1536 /* Load counter into CONTEXT1 reg */
1538 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
1540 LDST_SRCDST_BYTE_CONTEXT |
1541 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1542 LDST_OFFSET_SHIFT));
1544 /* Load operation */
1545 append_operation(desc, ctx->class1_alg_type |
1546 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1548 /* Perform operation */
1549 ablkcipher_append_src_dst(desc);
1551 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
1554 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1555 dev_err(jrdev, "unable to map shared descriptor\n");
1559 print_hex_dump(KERN_ERR,
1560 "ablkcipher enc shdesc@"__stringify(__LINE__)": ",
1561 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1562 desc_bytes(desc), 1);
1564 /* ablkcipher_decrypt shared descriptor */
1565 desc = ctx->sh_desc_dec;
1567 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1568 /* Skip if already shared */
1569 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1572 /* Load class1 key only */
1573 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1574 ctx->enckeylen, CLASS_1 |
1575 KEY_DEST_CLASS_REG);
1577 /* Load nonce into CONTEXT1 reg */
1579 nonce = (u32 *)(key + keylen);
1580 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1581 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1582 append_move(desc, MOVE_WAITCOMP |
1584 MOVE_DEST_CLASS1CTX |
1585 (16 << MOVE_OFFSET_SHIFT) |
1586 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1589 set_jump_tgt_here(desc, key_jump_cmd);
1592 append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
1593 LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
1595 /* Load counter into CONTEXT1 reg */
1597 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
1599 LDST_SRCDST_BYTE_CONTEXT |
1600 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1601 LDST_OFFSET_SHIFT));
1603 /* Choose operation */
1605 append_operation(desc, ctx->class1_alg_type |
1606 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
1608 append_dec_op1(desc, ctx->class1_alg_type);
1610 /* Perform operation */
1611 ablkcipher_append_src_dst(desc);
1613 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1616 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
1617 dev_err(jrdev, "unable to map shared descriptor\n");
1622 print_hex_dump(KERN_ERR,
1623 "ablkcipher dec shdesc@"__stringify(__LINE__)": ",
1624 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1625 desc_bytes(desc), 1);
1627 /* ablkcipher_givencrypt shared descriptor */
1628 desc = ctx->sh_desc_givenc;
1630 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1631 /* Skip if already shared */
1632 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1635 /* Load class1 key only */
1636 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1637 ctx->enckeylen, CLASS_1 |
1638 KEY_DEST_CLASS_REG);
1640 /* Load Nonce into CONTEXT1 reg */
1642 nonce = (u32 *)(key + keylen);
1643 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1644 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1645 append_move(desc, MOVE_WAITCOMP |
1647 MOVE_DEST_CLASS1CTX |
1648 (16 << MOVE_OFFSET_SHIFT) |
1649 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1651 set_jump_tgt_here(desc, key_jump_cmd);
1654 geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
1655 NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
1656 NFIFOENTRY_PTYPE_RND | (crt->ivsize << NFIFOENTRY_DLEN_SHIFT);
1657 append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
1658 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
1659 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1660 append_move(desc, MOVE_WAITCOMP |
1662 MOVE_DEST_CLASS1CTX |
1663 (crt->ivsize << MOVE_LEN_SHIFT) |
1664 (ctx1_iv_off << MOVE_OFFSET_SHIFT));
1665 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
1667 /* Copy generated IV to memory */
1668 append_seq_store(desc, crt->ivsize,
1669 LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1670 (ctx1_iv_off << LDST_OFFSET_SHIFT));
1672 /* Load Counter into CONTEXT1 reg */
1674 append_load_imm_u32(desc, (u32)1, LDST_IMM |
1676 LDST_SRCDST_BYTE_CONTEXT |
1677 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1678 LDST_OFFSET_SHIFT));
1681 append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NCP |
1682 (1 << JUMP_OFFSET_SHIFT));
1684 /* Load operation */
1685 append_operation(desc, ctx->class1_alg_type |
1686 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1688 /* Perform operation */
1689 ablkcipher_append_src_dst(desc);
1691 ctx->sh_desc_givenc_dma = dma_map_single(jrdev, desc,
1694 if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
1695 dev_err(jrdev, "unable to map shared descriptor\n");
1699 print_hex_dump(KERN_ERR,
1700 "ablkcipher givenc shdesc@" __stringify(__LINE__) ": ",
1701 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1702 desc_bytes(desc), 1);
1709 * aead_edesc - s/w-extended aead descriptor
1710 * @assoc_nents: number of segments in associated data (SPI+Seq) scatterlist
1711 * @src_nents: number of segments in input scatterlist
1712 * @dst_nents: number of segments in output scatterlist
1713 * @iv_dma: dma address of iv for checking continuity and link table
1714 * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
1715 * @sec4_sg_bytes: length of dma mapped sec4_sg space
1716 * @sec4_sg_dma: bus physical mapped address of h/w link table
1717 * @hw_desc: the h/w job descriptor followed by any referenced link tables
1725 dma_addr_t sec4_sg_dma;
1726 struct sec4_sg_entry *sec4_sg;
1731 * ablkcipher_edesc - s/w-extended ablkcipher descriptor
1732 * @src_nents: number of segments in input scatterlist
1733 * @dst_nents: number of segments in output scatterlist
1734 * @iv_dma: dma address of iv for checking continuity and link table
1735 * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
1736 * @sec4_sg_bytes: length of dma mapped sec4_sg space
1737 * @sec4_sg_dma: bus physical mapped address of h/w link table
1738 * @hw_desc: the h/w job descriptor followed by any referenced link tables
1740 struct ablkcipher_edesc {
1745 dma_addr_t sec4_sg_dma;
1746 struct sec4_sg_entry *sec4_sg;
1750 static void caam_unmap(struct device *dev, struct scatterlist *src,
1751 struct scatterlist *dst, int src_nents,
1753 dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
1757 dma_unmap_sg(dev, src, src_nents ? : 1, DMA_TO_DEVICE);
1758 dma_unmap_sg(dev, dst, dst_nents ? : 1, DMA_FROM_DEVICE);
1760 dma_unmap_sg(dev, src, src_nents ? : 1, DMA_BIDIRECTIONAL);
1764 dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
1766 dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
1770 static void aead_unmap(struct device *dev,
1771 struct aead_edesc *edesc,
1772 struct aead_request *req)
1774 caam_unmap(dev, req->src, req->dst,
1775 edesc->src_nents, edesc->dst_nents, 0, 0,
1776 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
1779 static void ablkcipher_unmap(struct device *dev,
1780 struct ablkcipher_edesc *edesc,
1781 struct ablkcipher_request *req)
1783 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1784 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1786 caam_unmap(dev, req->src, req->dst,
1787 edesc->src_nents, edesc->dst_nents,
1788 edesc->iv_dma, ivsize,
1789 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
1792 static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1795 struct aead_request *req = context;
1796 struct aead_edesc *edesc;
1799 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1802 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
1805 caam_jr_strstatus(jrdev, err);
1807 aead_unmap(jrdev, edesc, req);
1811 aead_request_complete(req, err);
1814 static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
1817 struct aead_request *req = context;
1818 struct aead_edesc *edesc;
1821 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1824 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
1827 caam_jr_strstatus(jrdev, err);
1829 aead_unmap(jrdev, edesc, req);
1832 * verify hw auth check passed else return -EBADMSG
1834 if ((err & JRSTA_CCBERR_ERRID_MASK) == JRSTA_CCBERR_ERRID_ICVCHK)
1839 aead_request_complete(req, err);
1842 static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1845 struct ablkcipher_request *req = context;
1846 struct ablkcipher_edesc *edesc;
1848 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1849 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1851 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1854 edesc = (struct ablkcipher_edesc *)((char *)desc -
1855 offsetof(struct ablkcipher_edesc, hw_desc));
1858 caam_jr_strstatus(jrdev, err);
1861 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
1862 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1863 edesc->src_nents > 1 ? 100 : ivsize, 1);
1864 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
1865 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
1866 edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
1869 ablkcipher_unmap(jrdev, edesc, req);
1872 ablkcipher_request_complete(req, err);
1875 static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
1878 struct ablkcipher_request *req = context;
1879 struct ablkcipher_edesc *edesc;
1881 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1882 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1884 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1887 edesc = (struct ablkcipher_edesc *)((char *)desc -
1888 offsetof(struct ablkcipher_edesc, hw_desc));
1890 caam_jr_strstatus(jrdev, err);
1893 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
1894 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1896 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
1897 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
1898 edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
1901 ablkcipher_unmap(jrdev, edesc, req);
1904 ablkcipher_request_complete(req, err);
1908 * Fill in aead job descriptor
1910 static void init_aead_job(struct aead_request *req,
1911 struct aead_edesc *edesc,
1912 bool all_contig, bool encrypt)
1914 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1915 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1916 int authsize = ctx->authsize;
1917 u32 *desc = edesc->hw_desc;
1918 u32 out_options, in_options;
1919 dma_addr_t dst_dma, src_dma;
1920 int len, sec4_sg_index = 0;
1924 sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
1925 ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
1927 len = desc_len(sh_desc);
1928 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1931 src_dma = sg_dma_address(req->src);
1934 src_dma = edesc->sec4_sg_dma;
1935 sec4_sg_index += edesc->src_nents;
1936 in_options = LDST_SGF;
1939 append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
1943 out_options = in_options;
1945 if (unlikely(req->src != req->dst)) {
1946 if (!edesc->dst_nents) {
1947 dst_dma = sg_dma_address(req->dst);
1949 dst_dma = edesc->sec4_sg_dma +
1951 sizeof(struct sec4_sg_entry);
1952 out_options = LDST_SGF;
1957 append_seq_out_ptr(desc, dst_dma,
1958 req->assoclen + req->cryptlen + authsize,
1961 append_seq_out_ptr(desc, dst_dma,
1962 req->assoclen + req->cryptlen - authsize,
1965 /* REG3 = assoclen */
1966 append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
1969 static void init_gcm_job(struct aead_request *req,
1970 struct aead_edesc *edesc,
1971 bool all_contig, bool encrypt)
1973 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1974 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1975 unsigned int ivsize = crypto_aead_ivsize(aead);
1976 u32 *desc = edesc->hw_desc;
1977 bool generic_gcm = (ivsize == 12);
1980 init_aead_job(req, edesc, all_contig, encrypt);
1982 /* BUG This should not be specific to generic GCM. */
1984 if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
1985 last = FIFOLD_TYPE_LAST1;
1988 append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
1989 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last);
1992 append_data(desc, ctx->key + ctx->enckeylen, 4);
1994 append_data(desc, req->iv, ivsize);
1995 /* End of blank commands */
1998 static void init_authenc_job(struct aead_request *req,
1999 struct aead_edesc *edesc,
2000 bool all_contig, bool encrypt)
2002 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2003 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
2004 struct caam_aead_alg, aead);
2005 unsigned int ivsize = crypto_aead_ivsize(aead);
2006 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2007 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
2008 OP_ALG_AAI_CTR_MOD128);
2009 const bool is_rfc3686 = alg->caam.rfc3686;
2010 u32 *desc = edesc->hw_desc;
2014 * AES-CTR needs to load IV in CONTEXT1 reg
2015 * at an offset of 128bits (16bytes)
2016 * CONTEXT1[255:128] = IV
2023 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
2026 ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
2028 init_aead_job(req, edesc, all_contig, encrypt);
2030 if (ivsize && (is_rfc3686 || !(alg->caam.geniv && encrypt)))
2031 append_load_as_imm(desc, req->iv, ivsize,
2033 LDST_SRCDST_BYTE_CONTEXT |
2034 (ivoffset << LDST_OFFSET_SHIFT));
2038 * Fill in ablkcipher job descriptor
2040 static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
2041 struct ablkcipher_edesc *edesc,
2042 struct ablkcipher_request *req,
2045 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2046 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2047 u32 *desc = edesc->hw_desc;
2048 u32 out_options = 0, in_options;
2049 dma_addr_t dst_dma, src_dma;
2050 int len, sec4_sg_index = 0;
2053 print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
2054 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2056 print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ",
2057 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2058 edesc->src_nents ? 100 : req->nbytes, 1);
2061 len = desc_len(sh_desc);
2062 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
2065 src_dma = edesc->iv_dma;
2068 src_dma = edesc->sec4_sg_dma;
2069 sec4_sg_index += edesc->src_nents + 1;
2070 in_options = LDST_SGF;
2072 append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options);
2074 if (likely(req->src == req->dst)) {
2075 if (!edesc->src_nents && iv_contig) {
2076 dst_dma = sg_dma_address(req->src);
2078 dst_dma = edesc->sec4_sg_dma +
2079 sizeof(struct sec4_sg_entry);
2080 out_options = LDST_SGF;
2083 if (!edesc->dst_nents) {
2084 dst_dma = sg_dma_address(req->dst);
2086 dst_dma = edesc->sec4_sg_dma +
2087 sec4_sg_index * sizeof(struct sec4_sg_entry);
2088 out_options = LDST_SGF;
2091 append_seq_out_ptr(desc, dst_dma, req->nbytes, out_options);
2095 * Fill in ablkcipher givencrypt job descriptor
2097 static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
2098 struct ablkcipher_edesc *edesc,
2099 struct ablkcipher_request *req,
2102 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2103 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2104 u32 *desc = edesc->hw_desc;
2105 u32 out_options, in_options;
2106 dma_addr_t dst_dma, src_dma;
2107 int len, sec4_sg_index = 0;
2110 print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
2111 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2113 print_hex_dump(KERN_ERR, "src @" __stringify(__LINE__) ": ",
2114 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2115 edesc->src_nents ? 100 : req->nbytes, 1);
2118 len = desc_len(sh_desc);
2119 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
2121 if (!edesc->src_nents) {
2122 src_dma = sg_dma_address(req->src);
2125 src_dma = edesc->sec4_sg_dma;
2126 sec4_sg_index += edesc->src_nents;
2127 in_options = LDST_SGF;
2129 append_seq_in_ptr(desc, src_dma, req->nbytes, in_options);
2132 dst_dma = edesc->iv_dma;
2135 dst_dma = edesc->sec4_sg_dma +
2136 sec4_sg_index * sizeof(struct sec4_sg_entry);
2137 out_options = LDST_SGF;
2139 append_seq_out_ptr(desc, dst_dma, req->nbytes + ivsize, out_options);
2143 * allocate and map the aead extended descriptor
2145 static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
2146 int desc_bytes, bool *all_contig_ptr,
2149 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2150 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2151 struct device *jrdev = ctx->jrdev;
2152 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2153 CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
2154 int src_nents, dst_nents = 0;
2155 struct aead_edesc *edesc;
2157 bool all_contig = true;
2158 int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
2159 unsigned int authsize = ctx->authsize;
2161 if (unlikely(req->dst != req->src)) {
2162 src_nents = sg_count(req->src, req->assoclen + req->cryptlen);
2163 dst_nents = sg_count(req->dst,
2164 req->assoclen + req->cryptlen +
2165 (encrypt ? authsize : (-authsize)));
2167 src_nents = sg_count(req->src,
2168 req->assoclen + req->cryptlen +
2169 (encrypt ? authsize : 0));
2172 /* Check if data are contiguous. */
2173 all_contig = !src_nents;
2175 src_nents = src_nents ? : 1;
2176 sec4_sg_len = src_nents;
2179 sec4_sg_len += dst_nents;
2181 sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
2183 /* allocate space for base edesc and hw desc commands, link tables */
2184 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2187 dev_err(jrdev, "could not allocate extended descriptor\n");
2188 return ERR_PTR(-ENOMEM);
2191 if (likely(req->src == req->dst)) {
2192 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2194 if (unlikely(!sgc)) {
2195 dev_err(jrdev, "unable to map source\n");
2197 return ERR_PTR(-ENOMEM);
2200 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2202 if (unlikely(!sgc)) {
2203 dev_err(jrdev, "unable to map source\n");
2205 return ERR_PTR(-ENOMEM);
2208 sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
2210 if (unlikely(!sgc)) {
2211 dev_err(jrdev, "unable to map destination\n");
2212 dma_unmap_sg(jrdev, req->src, src_nents ? : 1,
2215 return ERR_PTR(-ENOMEM);
2219 edesc->src_nents = src_nents;
2220 edesc->dst_nents = dst_nents;
2221 edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
2223 *all_contig_ptr = all_contig;
2227 sg_to_sec4_sg_last(req->src, src_nents,
2228 edesc->sec4_sg + sec4_sg_index, 0);
2229 sec4_sg_index += src_nents;
2232 sg_to_sec4_sg_last(req->dst, dst_nents,
2233 edesc->sec4_sg + sec4_sg_index, 0);
2239 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2240 sec4_sg_bytes, DMA_TO_DEVICE);
2241 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2242 dev_err(jrdev, "unable to map S/G table\n");
2243 aead_unmap(jrdev, edesc, req);
2245 return ERR_PTR(-ENOMEM);
2248 edesc->sec4_sg_bytes = sec4_sg_bytes;
2253 static int gcm_encrypt(struct aead_request *req)
2255 struct aead_edesc *edesc;
2256 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2257 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2258 struct device *jrdev = ctx->jrdev;
2263 /* allocate extended descriptor */
2264 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true);
2266 return PTR_ERR(edesc);
2268 /* Create and submit job descriptor */
2269 init_gcm_job(req, edesc, all_contig, true);
2271 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2272 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2273 desc_bytes(edesc->hw_desc), 1);
2276 desc = edesc->hw_desc;
2277 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
2281 aead_unmap(jrdev, edesc, req);
2288 static int ipsec_gcm_encrypt(struct aead_request *req)
2290 if (req->assoclen < 8)
2293 return gcm_encrypt(req);
2296 static int aead_encrypt(struct aead_request *req)
2298 struct aead_edesc *edesc;
2299 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2300 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2301 struct device *jrdev = ctx->jrdev;
2306 /* allocate extended descriptor */
2307 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
2310 return PTR_ERR(edesc);
2312 /* Create and submit job descriptor */
2313 init_authenc_job(req, edesc, all_contig, true);
2315 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2316 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2317 desc_bytes(edesc->hw_desc), 1);
2320 desc = edesc->hw_desc;
2321 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
2325 aead_unmap(jrdev, edesc, req);
2332 static int gcm_decrypt(struct aead_request *req)
2334 struct aead_edesc *edesc;
2335 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2336 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2337 struct device *jrdev = ctx->jrdev;
2342 /* allocate extended descriptor */
2343 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false);
2345 return PTR_ERR(edesc);
2347 /* Create and submit job descriptor*/
2348 init_gcm_job(req, edesc, all_contig, false);
2350 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2351 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2352 desc_bytes(edesc->hw_desc), 1);
2355 desc = edesc->hw_desc;
2356 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
2360 aead_unmap(jrdev, edesc, req);
2367 static int ipsec_gcm_decrypt(struct aead_request *req)
2369 if (req->assoclen < 8)
2372 return gcm_decrypt(req);
2375 static int aead_decrypt(struct aead_request *req)
2377 struct aead_edesc *edesc;
2378 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2379 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2380 struct device *jrdev = ctx->jrdev;
2385 /* allocate extended descriptor */
2386 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
2387 &all_contig, false);
2389 return PTR_ERR(edesc);
2392 print_hex_dump(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
2393 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2394 req->assoclen + req->cryptlen, 1);
2397 /* Create and submit job descriptor*/
2398 init_authenc_job(req, edesc, all_contig, false);
2400 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2401 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2402 desc_bytes(edesc->hw_desc), 1);
2405 desc = edesc->hw_desc;
2406 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
2410 aead_unmap(jrdev, edesc, req);
2417 static int aead_givdecrypt(struct aead_request *req)
2419 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2420 unsigned int ivsize = crypto_aead_ivsize(aead);
2422 if (req->cryptlen < ivsize)
2425 req->cryptlen -= ivsize;
2426 req->assoclen += ivsize;
2428 return aead_decrypt(req);
2432 * allocate and map the ablkcipher extended descriptor for ablkcipher
2434 static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
2435 *req, int desc_bytes,
2436 bool *iv_contig_out)
2438 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2439 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2440 struct device *jrdev = ctx->jrdev;
2441 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2442 CRYPTO_TFM_REQ_MAY_SLEEP)) ?
2443 GFP_KERNEL : GFP_ATOMIC;
2444 int src_nents, dst_nents = 0, sec4_sg_bytes;
2445 struct ablkcipher_edesc *edesc;
2446 dma_addr_t iv_dma = 0;
2447 bool iv_contig = false;
2449 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2452 src_nents = sg_count(req->src, req->nbytes);
2454 if (req->dst != req->src)
2455 dst_nents = sg_count(req->dst, req->nbytes);
2457 if (likely(req->src == req->dst)) {
2458 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2461 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2463 sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
2467 iv_dma = dma_map_single(jrdev, req->info, ivsize, DMA_TO_DEVICE);
2468 if (dma_mapping_error(jrdev, iv_dma)) {
2469 dev_err(jrdev, "unable to map IV\n");
2470 return ERR_PTR(-ENOMEM);
2474 * Check if iv can be contiguous with source and destination.
2475 * If so, include it. If not, create scatterlist.
2477 if (!src_nents && iv_dma + ivsize == sg_dma_address(req->src))
2480 src_nents = src_nents ? : 1;
2481 sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
2482 sizeof(struct sec4_sg_entry);
2484 /* allocate space for base edesc and hw desc commands, link tables */
2485 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2488 dev_err(jrdev, "could not allocate extended descriptor\n");
2489 return ERR_PTR(-ENOMEM);
2492 edesc->src_nents = src_nents;
2493 edesc->dst_nents = dst_nents;
2494 edesc->sec4_sg_bytes = sec4_sg_bytes;
2495 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
2500 dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
2501 sg_to_sec4_sg_last(req->src, src_nents,
2502 edesc->sec4_sg + 1, 0);
2503 sec4_sg_index += 1 + src_nents;
2507 sg_to_sec4_sg_last(req->dst, dst_nents,
2508 edesc->sec4_sg + sec4_sg_index, 0);
2511 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2512 sec4_sg_bytes, DMA_TO_DEVICE);
2513 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2514 dev_err(jrdev, "unable to map S/G table\n");
2515 return ERR_PTR(-ENOMEM);
2518 edesc->iv_dma = iv_dma;
2521 print_hex_dump(KERN_ERR, "ablkcipher sec4_sg@"__stringify(__LINE__)": ",
2522 DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
2526 *iv_contig_out = iv_contig;
2530 static int ablkcipher_encrypt(struct ablkcipher_request *req)
2532 struct ablkcipher_edesc *edesc;
2533 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2534 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2535 struct device *jrdev = ctx->jrdev;
2540 /* allocate extended descriptor */
2541 edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
2542 CAAM_CMD_SZ, &iv_contig);
2544 return PTR_ERR(edesc);
2546 /* Create and submit job descriptor*/
2547 init_ablkcipher_job(ctx->sh_desc_enc,
2548 ctx->sh_desc_enc_dma, edesc, req, iv_contig);
2550 print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
2551 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2552 desc_bytes(edesc->hw_desc), 1);
2554 desc = edesc->hw_desc;
2555 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
2560 ablkcipher_unmap(jrdev, edesc, req);
2567 static int ablkcipher_decrypt(struct ablkcipher_request *req)
2569 struct ablkcipher_edesc *edesc;
2570 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2571 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2572 struct device *jrdev = ctx->jrdev;
2577 /* allocate extended descriptor */
2578 edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
2579 CAAM_CMD_SZ, &iv_contig);
2581 return PTR_ERR(edesc);
2583 /* Create and submit job descriptor*/
2584 init_ablkcipher_job(ctx->sh_desc_dec,
2585 ctx->sh_desc_dec_dma, edesc, req, iv_contig);
2586 desc = edesc->hw_desc;
2588 print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
2589 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2590 desc_bytes(edesc->hw_desc), 1);
2593 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_decrypt_done, req);
2597 ablkcipher_unmap(jrdev, edesc, req);
2605 * allocate and map the ablkcipher extended descriptor
2606 * for ablkcipher givencrypt
2608 static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
2609 struct skcipher_givcrypt_request *greq,
2611 bool *iv_contig_out)
2613 struct ablkcipher_request *req = &greq->creq;
2614 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2615 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2616 struct device *jrdev = ctx->jrdev;
2617 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2618 CRYPTO_TFM_REQ_MAY_SLEEP)) ?
2619 GFP_KERNEL : GFP_ATOMIC;
2620 int src_nents, dst_nents = 0, sec4_sg_bytes;
2621 struct ablkcipher_edesc *edesc;
2622 dma_addr_t iv_dma = 0;
2623 bool iv_contig = false;
2625 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2628 src_nents = sg_count(req->src, req->nbytes);
2630 if (unlikely(req->dst != req->src))
2631 dst_nents = sg_count(req->dst, req->nbytes);
2633 if (likely(req->src == req->dst)) {
2634 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2637 sgc = dma_map_sg(jrdev, req->src, src_nents ? : 1,
2639 sgc = dma_map_sg(jrdev, req->dst, dst_nents ? : 1,
2644 * Check if iv can be contiguous with source and destination.
2645 * If so, include it. If not, create scatterlist.
2647 iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE);
2648 if (dma_mapping_error(jrdev, iv_dma)) {
2649 dev_err(jrdev, "unable to map IV\n");
2650 return ERR_PTR(-ENOMEM);
2653 if (!dst_nents && iv_dma + ivsize == sg_dma_address(req->dst))
2656 dst_nents = dst_nents ? : 1;
2657 sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
2658 sizeof(struct sec4_sg_entry);
2660 /* allocate space for base edesc and hw desc commands, link tables */
2661 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2664 dev_err(jrdev, "could not allocate extended descriptor\n");
2665 return ERR_PTR(-ENOMEM);
2668 edesc->src_nents = src_nents;
2669 edesc->dst_nents = dst_nents;
2670 edesc->sec4_sg_bytes = sec4_sg_bytes;
2671 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
2676 sg_to_sec4_sg_last(req->src, src_nents, edesc->sec4_sg, 0);
2677 sec4_sg_index += src_nents;
2681 dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index,
2684 sg_to_sec4_sg_last(req->dst, dst_nents,
2685 edesc->sec4_sg + sec4_sg_index, 0);
2688 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2689 sec4_sg_bytes, DMA_TO_DEVICE);
2690 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2691 dev_err(jrdev, "unable to map S/G table\n");
2692 return ERR_PTR(-ENOMEM);
2694 edesc->iv_dma = iv_dma;
2697 print_hex_dump(KERN_ERR,
2698 "ablkcipher sec4_sg@" __stringify(__LINE__) ": ",
2699 DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
2703 *iv_contig_out = iv_contig;
2707 static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
2709 struct ablkcipher_request *req = &creq->creq;
2710 struct ablkcipher_edesc *edesc;
2711 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2712 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2713 struct device *jrdev = ctx->jrdev;
2718 /* allocate extended descriptor */
2719 edesc = ablkcipher_giv_edesc_alloc(creq, DESC_JOB_IO_LEN *
2720 CAAM_CMD_SZ, &iv_contig);
2722 return PTR_ERR(edesc);
2724 /* Create and submit job descriptor*/
2725 init_ablkcipher_giv_job(ctx->sh_desc_givenc, ctx->sh_desc_givenc_dma,
2726 edesc, req, iv_contig);
2728 print_hex_dump(KERN_ERR,
2729 "ablkcipher jobdesc@" __stringify(__LINE__) ": ",
2730 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2731 desc_bytes(edesc->hw_desc), 1);
2733 desc = edesc->hw_desc;
2734 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
2739 ablkcipher_unmap(jrdev, edesc, req);
2746 #define template_aead template_u.aead
2747 #define template_ablkcipher template_u.ablkcipher
2748 struct caam_alg_template {
2749 char name[CRYPTO_MAX_ALG_NAME];
2750 char driver_name[CRYPTO_MAX_ALG_NAME];
2751 unsigned int blocksize;
2754 struct ablkcipher_alg ablkcipher;
2756 u32 class1_alg_type;
2757 u32 class2_alg_type;
2761 static struct caam_alg_template driver_algs[] = {
2762 /* ablkcipher descriptor */
2765 .driver_name = "cbc-aes-caam",
2766 .blocksize = AES_BLOCK_SIZE,
2767 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2768 .template_ablkcipher = {
2769 .setkey = ablkcipher_setkey,
2770 .encrypt = ablkcipher_encrypt,
2771 .decrypt = ablkcipher_decrypt,
2772 .givencrypt = ablkcipher_givencrypt,
2773 .geniv = "<built-in>",
2774 .min_keysize = AES_MIN_KEY_SIZE,
2775 .max_keysize = AES_MAX_KEY_SIZE,
2776 .ivsize = AES_BLOCK_SIZE,
2778 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2781 .name = "cbc(des3_ede)",
2782 .driver_name = "cbc-3des-caam",
2783 .blocksize = DES3_EDE_BLOCK_SIZE,
2784 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2785 .template_ablkcipher = {
2786 .setkey = ablkcipher_setkey,
2787 .encrypt = ablkcipher_encrypt,
2788 .decrypt = ablkcipher_decrypt,
2789 .givencrypt = ablkcipher_givencrypt,
2790 .geniv = "<built-in>",
2791 .min_keysize = DES3_EDE_KEY_SIZE,
2792 .max_keysize = DES3_EDE_KEY_SIZE,
2793 .ivsize = DES3_EDE_BLOCK_SIZE,
2795 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2799 .driver_name = "cbc-des-caam",
2800 .blocksize = DES_BLOCK_SIZE,
2801 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2802 .template_ablkcipher = {
2803 .setkey = ablkcipher_setkey,
2804 .encrypt = ablkcipher_encrypt,
2805 .decrypt = ablkcipher_decrypt,
2806 .givencrypt = ablkcipher_givencrypt,
2807 .geniv = "<built-in>",
2808 .min_keysize = DES_KEY_SIZE,
2809 .max_keysize = DES_KEY_SIZE,
2810 .ivsize = DES_BLOCK_SIZE,
2812 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2816 .driver_name = "ctr-aes-caam",
2818 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
2819 .template_ablkcipher = {
2820 .setkey = ablkcipher_setkey,
2821 .encrypt = ablkcipher_encrypt,
2822 .decrypt = ablkcipher_decrypt,
2824 .min_keysize = AES_MIN_KEY_SIZE,
2825 .max_keysize = AES_MAX_KEY_SIZE,
2826 .ivsize = AES_BLOCK_SIZE,
2828 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
2831 .name = "rfc3686(ctr(aes))",
2832 .driver_name = "rfc3686-ctr-aes-caam",
2834 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2835 .template_ablkcipher = {
2836 .setkey = ablkcipher_setkey,
2837 .encrypt = ablkcipher_encrypt,
2838 .decrypt = ablkcipher_decrypt,
2839 .givencrypt = ablkcipher_givencrypt,
2840 .geniv = "<built-in>",
2841 .min_keysize = AES_MIN_KEY_SIZE +
2842 CTR_RFC3686_NONCE_SIZE,
2843 .max_keysize = AES_MAX_KEY_SIZE +
2844 CTR_RFC3686_NONCE_SIZE,
2845 .ivsize = CTR_RFC3686_IV_SIZE,
2847 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
2851 static struct caam_aead_alg driver_aeads[] = {
2855 .cra_name = "rfc4106(gcm(aes))",
2856 .cra_driver_name = "rfc4106-gcm-aes-caam",
2859 .setkey = rfc4106_setkey,
2860 .setauthsize = rfc4106_setauthsize,
2861 .encrypt = ipsec_gcm_encrypt,
2862 .decrypt = ipsec_gcm_decrypt,
2864 .maxauthsize = AES_BLOCK_SIZE,
2867 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2873 .cra_name = "rfc4543(gcm(aes))",
2874 .cra_driver_name = "rfc4543-gcm-aes-caam",
2877 .setkey = rfc4543_setkey,
2878 .setauthsize = rfc4543_setauthsize,
2879 .encrypt = ipsec_gcm_encrypt,
2880 .decrypt = ipsec_gcm_decrypt,
2882 .maxauthsize = AES_BLOCK_SIZE,
2885 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2888 /* Galois Counter Mode */
2892 .cra_name = "gcm(aes)",
2893 .cra_driver_name = "gcm-aes-caam",
2896 .setkey = gcm_setkey,
2897 .setauthsize = gcm_setauthsize,
2898 .encrypt = gcm_encrypt,
2899 .decrypt = gcm_decrypt,
2901 .maxauthsize = AES_BLOCK_SIZE,
2904 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2907 /* single-pass ipsec_esp descriptor */
2911 .cra_name = "authenc(hmac(md5),"
2912 "ecb(cipher_null))",
2913 .cra_driver_name = "authenc-hmac-md5-"
2914 "ecb-cipher_null-caam",
2915 .cra_blocksize = NULL_BLOCK_SIZE,
2917 .setkey = aead_setkey,
2918 .setauthsize = aead_setauthsize,
2919 .encrypt = aead_encrypt,
2920 .decrypt = aead_decrypt,
2921 .ivsize = NULL_IV_SIZE,
2922 .maxauthsize = MD5_DIGEST_SIZE,
2925 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2926 OP_ALG_AAI_HMAC_PRECOMP,
2927 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
2933 .cra_name = "authenc(hmac(sha1),"
2934 "ecb(cipher_null))",
2935 .cra_driver_name = "authenc-hmac-sha1-"
2936 "ecb-cipher_null-caam",
2937 .cra_blocksize = NULL_BLOCK_SIZE,
2939 .setkey = aead_setkey,
2940 .setauthsize = aead_setauthsize,
2941 .encrypt = aead_encrypt,
2942 .decrypt = aead_decrypt,
2943 .ivsize = NULL_IV_SIZE,
2944 .maxauthsize = SHA1_DIGEST_SIZE,
2947 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2948 OP_ALG_AAI_HMAC_PRECOMP,
2949 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
2955 .cra_name = "authenc(hmac(sha224),"
2956 "ecb(cipher_null))",
2957 .cra_driver_name = "authenc-hmac-sha224-"
2958 "ecb-cipher_null-caam",
2959 .cra_blocksize = NULL_BLOCK_SIZE,
2961 .setkey = aead_setkey,
2962 .setauthsize = aead_setauthsize,
2963 .encrypt = aead_encrypt,
2964 .decrypt = aead_decrypt,
2965 .ivsize = NULL_IV_SIZE,
2966 .maxauthsize = SHA224_DIGEST_SIZE,
2969 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2970 OP_ALG_AAI_HMAC_PRECOMP,
2971 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
2977 .cra_name = "authenc(hmac(sha256),"
2978 "ecb(cipher_null))",
2979 .cra_driver_name = "authenc-hmac-sha256-"
2980 "ecb-cipher_null-caam",
2981 .cra_blocksize = NULL_BLOCK_SIZE,
2983 .setkey = aead_setkey,
2984 .setauthsize = aead_setauthsize,
2985 .encrypt = aead_encrypt,
2986 .decrypt = aead_decrypt,
2987 .ivsize = NULL_IV_SIZE,
2988 .maxauthsize = SHA256_DIGEST_SIZE,
2991 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2992 OP_ALG_AAI_HMAC_PRECOMP,
2993 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
2999 .cra_name = "authenc(hmac(sha384),"
3000 "ecb(cipher_null))",
3001 .cra_driver_name = "authenc-hmac-sha384-"
3002 "ecb-cipher_null-caam",
3003 .cra_blocksize = NULL_BLOCK_SIZE,
3005 .setkey = aead_setkey,
3006 .setauthsize = aead_setauthsize,
3007 .encrypt = aead_encrypt,
3008 .decrypt = aead_decrypt,
3009 .ivsize = NULL_IV_SIZE,
3010 .maxauthsize = SHA384_DIGEST_SIZE,
3013 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3014 OP_ALG_AAI_HMAC_PRECOMP,
3015 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3021 .cra_name = "authenc(hmac(sha512),"
3022 "ecb(cipher_null))",
3023 .cra_driver_name = "authenc-hmac-sha512-"
3024 "ecb-cipher_null-caam",
3025 .cra_blocksize = NULL_BLOCK_SIZE,
3027 .setkey = aead_setkey,
3028 .setauthsize = aead_setauthsize,
3029 .encrypt = aead_encrypt,
3030 .decrypt = aead_decrypt,
3031 .ivsize = NULL_IV_SIZE,
3032 .maxauthsize = SHA512_DIGEST_SIZE,
3035 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3036 OP_ALG_AAI_HMAC_PRECOMP,
3037 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3043 .cra_name = "authenc(hmac(md5),cbc(aes))",
3044 .cra_driver_name = "authenc-hmac-md5-"
3046 .cra_blocksize = AES_BLOCK_SIZE,
3048 .setkey = aead_setkey,
3049 .setauthsize = aead_setauthsize,
3050 .encrypt = aead_encrypt,
3051 .decrypt = aead_decrypt,
3052 .ivsize = AES_BLOCK_SIZE,
3053 .maxauthsize = MD5_DIGEST_SIZE,
3056 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3057 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3058 OP_ALG_AAI_HMAC_PRECOMP,
3059 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3065 .cra_name = "echainiv(authenc(hmac(md5),"
3067 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3069 .cra_blocksize = AES_BLOCK_SIZE,
3071 .setkey = aead_setkey,
3072 .setauthsize = aead_setauthsize,
3073 .encrypt = aead_encrypt,
3074 .decrypt = aead_givdecrypt,
3075 .ivsize = AES_BLOCK_SIZE,
3076 .maxauthsize = MD5_DIGEST_SIZE,
3079 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3080 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3081 OP_ALG_AAI_HMAC_PRECOMP,
3082 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3089 .cra_name = "authenc(hmac(sha1),cbc(aes))",
3090 .cra_driver_name = "authenc-hmac-sha1-"
3092 .cra_blocksize = AES_BLOCK_SIZE,
3094 .setkey = aead_setkey,
3095 .setauthsize = aead_setauthsize,
3096 .encrypt = aead_encrypt,
3097 .decrypt = aead_decrypt,
3098 .ivsize = AES_BLOCK_SIZE,
3099 .maxauthsize = SHA1_DIGEST_SIZE,
3102 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3103 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3104 OP_ALG_AAI_HMAC_PRECOMP,
3105 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3111 .cra_name = "echainiv(authenc(hmac(sha1),"
3113 .cra_driver_name = "echainiv-authenc-"
3114 "hmac-sha1-cbc-aes-caam",
3115 .cra_blocksize = AES_BLOCK_SIZE,
3117 .setkey = aead_setkey,
3118 .setauthsize = aead_setauthsize,
3119 .encrypt = aead_encrypt,
3120 .decrypt = aead_givdecrypt,
3121 .ivsize = AES_BLOCK_SIZE,
3122 .maxauthsize = SHA1_DIGEST_SIZE,
3125 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3126 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3127 OP_ALG_AAI_HMAC_PRECOMP,
3128 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3135 .cra_name = "authenc(hmac(sha224),cbc(aes))",
3136 .cra_driver_name = "authenc-hmac-sha224-"
3138 .cra_blocksize = AES_BLOCK_SIZE,
3140 .setkey = aead_setkey,
3141 .setauthsize = aead_setauthsize,
3142 .encrypt = aead_encrypt,
3143 .decrypt = aead_decrypt,
3144 .ivsize = AES_BLOCK_SIZE,
3145 .maxauthsize = SHA224_DIGEST_SIZE,
3148 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3149 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3150 OP_ALG_AAI_HMAC_PRECOMP,
3151 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3157 .cra_name = "echainiv(authenc(hmac(sha224),"
3159 .cra_driver_name = "echainiv-authenc-"
3160 "hmac-sha224-cbc-aes-caam",
3161 .cra_blocksize = AES_BLOCK_SIZE,
3163 .setkey = aead_setkey,
3164 .setauthsize = aead_setauthsize,
3165 .encrypt = aead_encrypt,
3166 .decrypt = aead_givdecrypt,
3167 .ivsize = AES_BLOCK_SIZE,
3168 .maxauthsize = SHA224_DIGEST_SIZE,
3171 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3172 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3173 OP_ALG_AAI_HMAC_PRECOMP,
3174 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3181 .cra_name = "authenc(hmac(sha256),cbc(aes))",
3182 .cra_driver_name = "authenc-hmac-sha256-"
3184 .cra_blocksize = AES_BLOCK_SIZE,
3186 .setkey = aead_setkey,
3187 .setauthsize = aead_setauthsize,
3188 .encrypt = aead_encrypt,
3189 .decrypt = aead_decrypt,
3190 .ivsize = AES_BLOCK_SIZE,
3191 .maxauthsize = SHA256_DIGEST_SIZE,
3194 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3195 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3196 OP_ALG_AAI_HMAC_PRECOMP,
3197 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3203 .cra_name = "echainiv(authenc(hmac(sha256),"
3205 .cra_driver_name = "echainiv-authenc-"
3206 "hmac-sha256-cbc-aes-caam",
3207 .cra_blocksize = AES_BLOCK_SIZE,
3209 .setkey = aead_setkey,
3210 .setauthsize = aead_setauthsize,
3211 .encrypt = aead_encrypt,
3212 .decrypt = aead_givdecrypt,
3213 .ivsize = AES_BLOCK_SIZE,
3214 .maxauthsize = SHA256_DIGEST_SIZE,
3217 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3218 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3219 OP_ALG_AAI_HMAC_PRECOMP,
3220 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3227 .cra_name = "authenc(hmac(sha384),cbc(aes))",
3228 .cra_driver_name = "authenc-hmac-sha384-"
3230 .cra_blocksize = AES_BLOCK_SIZE,
3232 .setkey = aead_setkey,
3233 .setauthsize = aead_setauthsize,
3234 .encrypt = aead_encrypt,
3235 .decrypt = aead_decrypt,
3236 .ivsize = AES_BLOCK_SIZE,
3237 .maxauthsize = SHA384_DIGEST_SIZE,
3240 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3241 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3242 OP_ALG_AAI_HMAC_PRECOMP,
3243 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3249 .cra_name = "echainiv(authenc(hmac(sha384),"
3251 .cra_driver_name = "echainiv-authenc-"
3252 "hmac-sha384-cbc-aes-caam",
3253 .cra_blocksize = AES_BLOCK_SIZE,
3255 .setkey = aead_setkey,
3256 .setauthsize = aead_setauthsize,
3257 .encrypt = aead_encrypt,
3258 .decrypt = aead_givdecrypt,
3259 .ivsize = AES_BLOCK_SIZE,
3260 .maxauthsize = SHA384_DIGEST_SIZE,
3263 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3264 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3265 OP_ALG_AAI_HMAC_PRECOMP,
3266 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3273 .cra_name = "authenc(hmac(sha512),cbc(aes))",
3274 .cra_driver_name = "authenc-hmac-sha512-"
3276 .cra_blocksize = AES_BLOCK_SIZE,
3278 .setkey = aead_setkey,
3279 .setauthsize = aead_setauthsize,
3280 .encrypt = aead_encrypt,
3281 .decrypt = aead_decrypt,
3282 .ivsize = AES_BLOCK_SIZE,
3283 .maxauthsize = SHA512_DIGEST_SIZE,
3286 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3287 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3288 OP_ALG_AAI_HMAC_PRECOMP,
3289 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3295 .cra_name = "echainiv(authenc(hmac(sha512),"
3297 .cra_driver_name = "echainiv-authenc-"
3298 "hmac-sha512-cbc-aes-caam",
3299 .cra_blocksize = AES_BLOCK_SIZE,
3301 .setkey = aead_setkey,
3302 .setauthsize = aead_setauthsize,
3303 .encrypt = aead_encrypt,
3304 .decrypt = aead_givdecrypt,
3305 .ivsize = AES_BLOCK_SIZE,
3306 .maxauthsize = SHA512_DIGEST_SIZE,
3309 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3310 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3311 OP_ALG_AAI_HMAC_PRECOMP,
3312 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3319 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
3320 .cra_driver_name = "authenc-hmac-md5-"
3321 "cbc-des3_ede-caam",
3322 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3324 .setkey = aead_setkey,
3325 .setauthsize = aead_setauthsize,
3326 .encrypt = aead_encrypt,
3327 .decrypt = aead_decrypt,
3328 .ivsize = DES3_EDE_BLOCK_SIZE,
3329 .maxauthsize = MD5_DIGEST_SIZE,
3332 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3333 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3334 OP_ALG_AAI_HMAC_PRECOMP,
3335 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3341 .cra_name = "echainiv(authenc(hmac(md5),"
3343 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3344 "cbc-des3_ede-caam",
3345 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3347 .setkey = aead_setkey,
3348 .setauthsize = aead_setauthsize,
3349 .encrypt = aead_encrypt,
3350 .decrypt = aead_givdecrypt,
3351 .ivsize = DES3_EDE_BLOCK_SIZE,
3352 .maxauthsize = MD5_DIGEST_SIZE,
3355 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3356 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3357 OP_ALG_AAI_HMAC_PRECOMP,
3358 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3365 .cra_name = "authenc(hmac(sha1),"
3367 .cra_driver_name = "authenc-hmac-sha1-"
3368 "cbc-des3_ede-caam",
3369 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3371 .setkey = aead_setkey,
3372 .setauthsize = aead_setauthsize,
3373 .encrypt = aead_encrypt,
3374 .decrypt = aead_decrypt,
3375 .ivsize = DES3_EDE_BLOCK_SIZE,
3376 .maxauthsize = SHA1_DIGEST_SIZE,
3379 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3380 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3381 OP_ALG_AAI_HMAC_PRECOMP,
3382 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3388 .cra_name = "echainiv(authenc(hmac(sha1),"
3390 .cra_driver_name = "echainiv-authenc-"
3392 "cbc-des3_ede-caam",
3393 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3395 .setkey = aead_setkey,
3396 .setauthsize = aead_setauthsize,
3397 .encrypt = aead_encrypt,
3398 .decrypt = aead_givdecrypt,
3399 .ivsize = DES3_EDE_BLOCK_SIZE,
3400 .maxauthsize = SHA1_DIGEST_SIZE,
3403 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3404 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3405 OP_ALG_AAI_HMAC_PRECOMP,
3406 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3413 .cra_name = "authenc(hmac(sha224),"
3415 .cra_driver_name = "authenc-hmac-sha224-"
3416 "cbc-des3_ede-caam",
3417 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3419 .setkey = aead_setkey,
3420 .setauthsize = aead_setauthsize,
3421 .encrypt = aead_encrypt,
3422 .decrypt = aead_decrypt,
3423 .ivsize = DES3_EDE_BLOCK_SIZE,
3424 .maxauthsize = SHA224_DIGEST_SIZE,
3427 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3428 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3429 OP_ALG_AAI_HMAC_PRECOMP,
3430 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3436 .cra_name = "echainiv(authenc(hmac(sha224),"
3438 .cra_driver_name = "echainiv-authenc-"
3440 "cbc-des3_ede-caam",
3441 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3443 .setkey = aead_setkey,
3444 .setauthsize = aead_setauthsize,
3445 .encrypt = aead_encrypt,
3446 .decrypt = aead_givdecrypt,
3447 .ivsize = DES3_EDE_BLOCK_SIZE,
3448 .maxauthsize = SHA224_DIGEST_SIZE,
3451 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3452 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3453 OP_ALG_AAI_HMAC_PRECOMP,
3454 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3461 .cra_name = "authenc(hmac(sha256),"
3463 .cra_driver_name = "authenc-hmac-sha256-"
3464 "cbc-des3_ede-caam",
3465 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3467 .setkey = aead_setkey,
3468 .setauthsize = aead_setauthsize,
3469 .encrypt = aead_encrypt,
3470 .decrypt = aead_decrypt,
3471 .ivsize = DES3_EDE_BLOCK_SIZE,
3472 .maxauthsize = SHA256_DIGEST_SIZE,
3475 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3476 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3477 OP_ALG_AAI_HMAC_PRECOMP,
3478 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3484 .cra_name = "echainiv(authenc(hmac(sha256),"
3486 .cra_driver_name = "echainiv-authenc-"
3488 "cbc-des3_ede-caam",
3489 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3491 .setkey = aead_setkey,
3492 .setauthsize = aead_setauthsize,
3493 .encrypt = aead_encrypt,
3494 .decrypt = aead_givdecrypt,
3495 .ivsize = DES3_EDE_BLOCK_SIZE,
3496 .maxauthsize = SHA256_DIGEST_SIZE,
3499 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3500 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3501 OP_ALG_AAI_HMAC_PRECOMP,
3502 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3509 .cra_name = "authenc(hmac(sha384),"
3511 .cra_driver_name = "authenc-hmac-sha384-"
3512 "cbc-des3_ede-caam",
3513 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3515 .setkey = aead_setkey,
3516 .setauthsize = aead_setauthsize,
3517 .encrypt = aead_encrypt,
3518 .decrypt = aead_decrypt,
3519 .ivsize = DES3_EDE_BLOCK_SIZE,
3520 .maxauthsize = SHA384_DIGEST_SIZE,
3523 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3524 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3525 OP_ALG_AAI_HMAC_PRECOMP,
3526 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3532 .cra_name = "echainiv(authenc(hmac(sha384),"
3534 .cra_driver_name = "echainiv-authenc-"
3536 "cbc-des3_ede-caam",
3537 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3539 .setkey = aead_setkey,
3540 .setauthsize = aead_setauthsize,
3541 .encrypt = aead_encrypt,
3542 .decrypt = aead_givdecrypt,
3543 .ivsize = DES3_EDE_BLOCK_SIZE,
3544 .maxauthsize = SHA384_DIGEST_SIZE,
3547 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3548 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3549 OP_ALG_AAI_HMAC_PRECOMP,
3550 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3557 .cra_name = "authenc(hmac(sha512),"
3559 .cra_driver_name = "authenc-hmac-sha512-"
3560 "cbc-des3_ede-caam",
3561 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3563 .setkey = aead_setkey,
3564 .setauthsize = aead_setauthsize,
3565 .encrypt = aead_encrypt,
3566 .decrypt = aead_decrypt,
3567 .ivsize = DES3_EDE_BLOCK_SIZE,
3568 .maxauthsize = SHA512_DIGEST_SIZE,
3571 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3572 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3573 OP_ALG_AAI_HMAC_PRECOMP,
3574 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3580 .cra_name = "echainiv(authenc(hmac(sha512),"
3582 .cra_driver_name = "echainiv-authenc-"
3584 "cbc-des3_ede-caam",
3585 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3587 .setkey = aead_setkey,
3588 .setauthsize = aead_setauthsize,
3589 .encrypt = aead_encrypt,
3590 .decrypt = aead_givdecrypt,
3591 .ivsize = DES3_EDE_BLOCK_SIZE,
3592 .maxauthsize = SHA512_DIGEST_SIZE,
3595 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3596 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3597 OP_ALG_AAI_HMAC_PRECOMP,
3598 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3605 .cra_name = "authenc(hmac(md5),cbc(des))",
3606 .cra_driver_name = "authenc-hmac-md5-"
3608 .cra_blocksize = DES_BLOCK_SIZE,
3610 .setkey = aead_setkey,
3611 .setauthsize = aead_setauthsize,
3612 .encrypt = aead_encrypt,
3613 .decrypt = aead_decrypt,
3614 .ivsize = DES_BLOCK_SIZE,
3615 .maxauthsize = MD5_DIGEST_SIZE,
3618 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3619 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3620 OP_ALG_AAI_HMAC_PRECOMP,
3621 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3627 .cra_name = "echainiv(authenc(hmac(md5),"
3629 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3631 .cra_blocksize = DES_BLOCK_SIZE,
3633 .setkey = aead_setkey,
3634 .setauthsize = aead_setauthsize,
3635 .encrypt = aead_encrypt,
3636 .decrypt = aead_givdecrypt,
3637 .ivsize = DES_BLOCK_SIZE,
3638 .maxauthsize = MD5_DIGEST_SIZE,
3641 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3642 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3643 OP_ALG_AAI_HMAC_PRECOMP,
3644 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3651 .cra_name = "authenc(hmac(sha1),cbc(des))",
3652 .cra_driver_name = "authenc-hmac-sha1-"
3654 .cra_blocksize = DES_BLOCK_SIZE,
3656 .setkey = aead_setkey,
3657 .setauthsize = aead_setauthsize,
3658 .encrypt = aead_encrypt,
3659 .decrypt = aead_decrypt,
3660 .ivsize = DES_BLOCK_SIZE,
3661 .maxauthsize = SHA1_DIGEST_SIZE,
3664 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3665 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3666 OP_ALG_AAI_HMAC_PRECOMP,
3667 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3673 .cra_name = "echainiv(authenc(hmac(sha1),"
3675 .cra_driver_name = "echainiv-authenc-"
3676 "hmac-sha1-cbc-des-caam",
3677 .cra_blocksize = DES_BLOCK_SIZE,
3679 .setkey = aead_setkey,
3680 .setauthsize = aead_setauthsize,
3681 .encrypt = aead_encrypt,
3682 .decrypt = aead_givdecrypt,
3683 .ivsize = DES_BLOCK_SIZE,
3684 .maxauthsize = SHA1_DIGEST_SIZE,
3687 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3688 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3689 OP_ALG_AAI_HMAC_PRECOMP,
3690 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3697 .cra_name = "authenc(hmac(sha224),cbc(des))",
3698 .cra_driver_name = "authenc-hmac-sha224-"
3700 .cra_blocksize = DES_BLOCK_SIZE,
3702 .setkey = aead_setkey,
3703 .setauthsize = aead_setauthsize,
3704 .encrypt = aead_encrypt,
3705 .decrypt = aead_decrypt,
3706 .ivsize = DES_BLOCK_SIZE,
3707 .maxauthsize = SHA224_DIGEST_SIZE,
3710 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3711 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3712 OP_ALG_AAI_HMAC_PRECOMP,
3713 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3719 .cra_name = "echainiv(authenc(hmac(sha224),"
3721 .cra_driver_name = "echainiv-authenc-"
3722 "hmac-sha224-cbc-des-caam",
3723 .cra_blocksize = DES_BLOCK_SIZE,
3725 .setkey = aead_setkey,
3726 .setauthsize = aead_setauthsize,
3727 .encrypt = aead_encrypt,
3728 .decrypt = aead_givdecrypt,
3729 .ivsize = DES_BLOCK_SIZE,
3730 .maxauthsize = SHA224_DIGEST_SIZE,
3733 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3734 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3735 OP_ALG_AAI_HMAC_PRECOMP,
3736 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3743 .cra_name = "authenc(hmac(sha256),cbc(des))",
3744 .cra_driver_name = "authenc-hmac-sha256-"
3746 .cra_blocksize = DES_BLOCK_SIZE,
3748 .setkey = aead_setkey,
3749 .setauthsize = aead_setauthsize,
3750 .encrypt = aead_encrypt,
3751 .decrypt = aead_decrypt,
3752 .ivsize = DES_BLOCK_SIZE,
3753 .maxauthsize = SHA256_DIGEST_SIZE,
3756 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3757 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3758 OP_ALG_AAI_HMAC_PRECOMP,
3759 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3765 .cra_name = "echainiv(authenc(hmac(sha256),"
3767 .cra_driver_name = "echainiv-authenc-"
3768 "hmac-sha256-cbc-des-caam",
3769 .cra_blocksize = DES_BLOCK_SIZE,
3771 .setkey = aead_setkey,
3772 .setauthsize = aead_setauthsize,
3773 .encrypt = aead_encrypt,
3774 .decrypt = aead_givdecrypt,
3775 .ivsize = DES_BLOCK_SIZE,
3776 .maxauthsize = SHA256_DIGEST_SIZE,
3779 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3780 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3781 OP_ALG_AAI_HMAC_PRECOMP,
3782 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3789 .cra_name = "authenc(hmac(sha384),cbc(des))",
3790 .cra_driver_name = "authenc-hmac-sha384-"
3792 .cra_blocksize = DES_BLOCK_SIZE,
3794 .setkey = aead_setkey,
3795 .setauthsize = aead_setauthsize,
3796 .encrypt = aead_encrypt,
3797 .decrypt = aead_decrypt,
3798 .ivsize = DES_BLOCK_SIZE,
3799 .maxauthsize = SHA384_DIGEST_SIZE,
3802 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3803 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3804 OP_ALG_AAI_HMAC_PRECOMP,
3805 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3811 .cra_name = "echainiv(authenc(hmac(sha384),"
3813 .cra_driver_name = "echainiv-authenc-"
3814 "hmac-sha384-cbc-des-caam",
3815 .cra_blocksize = DES_BLOCK_SIZE,
3817 .setkey = aead_setkey,
3818 .setauthsize = aead_setauthsize,
3819 .encrypt = aead_encrypt,
3820 .decrypt = aead_givdecrypt,
3821 .ivsize = DES_BLOCK_SIZE,
3822 .maxauthsize = SHA384_DIGEST_SIZE,
3825 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3826 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3827 OP_ALG_AAI_HMAC_PRECOMP,
3828 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3835 .cra_name = "authenc(hmac(sha512),cbc(des))",
3836 .cra_driver_name = "authenc-hmac-sha512-"
3838 .cra_blocksize = DES_BLOCK_SIZE,
3840 .setkey = aead_setkey,
3841 .setauthsize = aead_setauthsize,
3842 .encrypt = aead_encrypt,
3843 .decrypt = aead_decrypt,
3844 .ivsize = DES_BLOCK_SIZE,
3845 .maxauthsize = SHA512_DIGEST_SIZE,
3848 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3849 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3850 OP_ALG_AAI_HMAC_PRECOMP,
3851 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3857 .cra_name = "echainiv(authenc(hmac(sha512),"
3859 .cra_driver_name = "echainiv-authenc-"
3860 "hmac-sha512-cbc-des-caam",
3861 .cra_blocksize = DES_BLOCK_SIZE,
3863 .setkey = aead_setkey,
3864 .setauthsize = aead_setauthsize,
3865 .encrypt = aead_encrypt,
3866 .decrypt = aead_givdecrypt,
3867 .ivsize = DES_BLOCK_SIZE,
3868 .maxauthsize = SHA512_DIGEST_SIZE,
3871 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3872 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3873 OP_ALG_AAI_HMAC_PRECOMP,
3874 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3881 .cra_name = "authenc(hmac(md5),"
3882 "rfc3686(ctr(aes)))",
3883 .cra_driver_name = "authenc-hmac-md5-"
3884 "rfc3686-ctr-aes-caam",
3887 .setkey = aead_setkey,
3888 .setauthsize = aead_setauthsize,
3889 .encrypt = aead_encrypt,
3890 .decrypt = aead_decrypt,
3891 .ivsize = CTR_RFC3686_IV_SIZE,
3892 .maxauthsize = MD5_DIGEST_SIZE,
3895 .class1_alg_type = OP_ALG_ALGSEL_AES |
3896 OP_ALG_AAI_CTR_MOD128,
3897 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3898 OP_ALG_AAI_HMAC_PRECOMP,
3899 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3906 .cra_name = "seqiv(authenc("
3907 "hmac(md5),rfc3686(ctr(aes))))",
3908 .cra_driver_name = "seqiv-authenc-hmac-md5-"
3909 "rfc3686-ctr-aes-caam",
3912 .setkey = aead_setkey,
3913 .setauthsize = aead_setauthsize,
3914 .encrypt = aead_encrypt,
3915 .decrypt = aead_givdecrypt,
3916 .ivsize = CTR_RFC3686_IV_SIZE,
3917 .maxauthsize = MD5_DIGEST_SIZE,
3920 .class1_alg_type = OP_ALG_ALGSEL_AES |
3921 OP_ALG_AAI_CTR_MOD128,
3922 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3923 OP_ALG_AAI_HMAC_PRECOMP,
3924 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3932 .cra_name = "authenc(hmac(sha1),"
3933 "rfc3686(ctr(aes)))",
3934 .cra_driver_name = "authenc-hmac-sha1-"
3935 "rfc3686-ctr-aes-caam",
3938 .setkey = aead_setkey,
3939 .setauthsize = aead_setauthsize,
3940 .encrypt = aead_encrypt,
3941 .decrypt = aead_decrypt,
3942 .ivsize = CTR_RFC3686_IV_SIZE,
3943 .maxauthsize = SHA1_DIGEST_SIZE,
3946 .class1_alg_type = OP_ALG_ALGSEL_AES |
3947 OP_ALG_AAI_CTR_MOD128,
3948 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3949 OP_ALG_AAI_HMAC_PRECOMP,
3950 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3957 .cra_name = "seqiv(authenc("
3958 "hmac(sha1),rfc3686(ctr(aes))))",
3959 .cra_driver_name = "seqiv-authenc-hmac-sha1-"
3960 "rfc3686-ctr-aes-caam",
3963 .setkey = aead_setkey,
3964 .setauthsize = aead_setauthsize,
3965 .encrypt = aead_encrypt,
3966 .decrypt = aead_givdecrypt,
3967 .ivsize = CTR_RFC3686_IV_SIZE,
3968 .maxauthsize = SHA1_DIGEST_SIZE,
3971 .class1_alg_type = OP_ALG_ALGSEL_AES |
3972 OP_ALG_AAI_CTR_MOD128,
3973 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3974 OP_ALG_AAI_HMAC_PRECOMP,
3975 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3983 .cra_name = "authenc(hmac(sha224),"
3984 "rfc3686(ctr(aes)))",
3985 .cra_driver_name = "authenc-hmac-sha224-"
3986 "rfc3686-ctr-aes-caam",
3989 .setkey = aead_setkey,
3990 .setauthsize = aead_setauthsize,
3991 .encrypt = aead_encrypt,
3992 .decrypt = aead_decrypt,
3993 .ivsize = CTR_RFC3686_IV_SIZE,
3994 .maxauthsize = SHA224_DIGEST_SIZE,
3997 .class1_alg_type = OP_ALG_ALGSEL_AES |
3998 OP_ALG_AAI_CTR_MOD128,
3999 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
4000 OP_ALG_AAI_HMAC_PRECOMP,
4001 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
4008 .cra_name = "seqiv(authenc("
4009 "hmac(sha224),rfc3686(ctr(aes))))",
4010 .cra_driver_name = "seqiv-authenc-hmac-sha224-"
4011 "rfc3686-ctr-aes-caam",
4014 .setkey = aead_setkey,
4015 .setauthsize = aead_setauthsize,
4016 .encrypt = aead_encrypt,
4017 .decrypt = aead_givdecrypt,
4018 .ivsize = CTR_RFC3686_IV_SIZE,
4019 .maxauthsize = SHA224_DIGEST_SIZE,
4022 .class1_alg_type = OP_ALG_ALGSEL_AES |
4023 OP_ALG_AAI_CTR_MOD128,
4024 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
4025 OP_ALG_AAI_HMAC_PRECOMP,
4026 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
4034 .cra_name = "authenc(hmac(sha256),"
4035 "rfc3686(ctr(aes)))",
4036 .cra_driver_name = "authenc-hmac-sha256-"
4037 "rfc3686-ctr-aes-caam",
4040 .setkey = aead_setkey,
4041 .setauthsize = aead_setauthsize,
4042 .encrypt = aead_encrypt,
4043 .decrypt = aead_decrypt,
4044 .ivsize = CTR_RFC3686_IV_SIZE,
4045 .maxauthsize = SHA256_DIGEST_SIZE,
4048 .class1_alg_type = OP_ALG_ALGSEL_AES |
4049 OP_ALG_AAI_CTR_MOD128,
4050 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
4051 OP_ALG_AAI_HMAC_PRECOMP,
4052 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
4059 .cra_name = "seqiv(authenc(hmac(sha256),"
4060 "rfc3686(ctr(aes))))",
4061 .cra_driver_name = "seqiv-authenc-hmac-sha256-"
4062 "rfc3686-ctr-aes-caam",
4065 .setkey = aead_setkey,
4066 .setauthsize = aead_setauthsize,
4067 .encrypt = aead_encrypt,
4068 .decrypt = aead_givdecrypt,
4069 .ivsize = CTR_RFC3686_IV_SIZE,
4070 .maxauthsize = SHA256_DIGEST_SIZE,
4073 .class1_alg_type = OP_ALG_ALGSEL_AES |
4074 OP_ALG_AAI_CTR_MOD128,
4075 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
4076 OP_ALG_AAI_HMAC_PRECOMP,
4077 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
4085 .cra_name = "authenc(hmac(sha384),"
4086 "rfc3686(ctr(aes)))",
4087 .cra_driver_name = "authenc-hmac-sha384-"
4088 "rfc3686-ctr-aes-caam",
4091 .setkey = aead_setkey,
4092 .setauthsize = aead_setauthsize,
4093 .encrypt = aead_encrypt,
4094 .decrypt = aead_decrypt,
4095 .ivsize = CTR_RFC3686_IV_SIZE,
4096 .maxauthsize = SHA384_DIGEST_SIZE,
4099 .class1_alg_type = OP_ALG_ALGSEL_AES |
4100 OP_ALG_AAI_CTR_MOD128,
4101 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
4102 OP_ALG_AAI_HMAC_PRECOMP,
4103 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
4110 .cra_name = "seqiv(authenc(hmac(sha384),"
4111 "rfc3686(ctr(aes))))",
4112 .cra_driver_name = "seqiv-authenc-hmac-sha384-"
4113 "rfc3686-ctr-aes-caam",
4116 .setkey = aead_setkey,
4117 .setauthsize = aead_setauthsize,
4118 .encrypt = aead_encrypt,
4119 .decrypt = aead_givdecrypt,
4120 .ivsize = CTR_RFC3686_IV_SIZE,
4121 .maxauthsize = SHA384_DIGEST_SIZE,
4124 .class1_alg_type = OP_ALG_ALGSEL_AES |
4125 OP_ALG_AAI_CTR_MOD128,
4126 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
4127 OP_ALG_AAI_HMAC_PRECOMP,
4128 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
4136 .cra_name = "authenc(hmac(sha512),"
4137 "rfc3686(ctr(aes)))",
4138 .cra_driver_name = "authenc-hmac-sha512-"
4139 "rfc3686-ctr-aes-caam",
4142 .setkey = aead_setkey,
4143 .setauthsize = aead_setauthsize,
4144 .encrypt = aead_encrypt,
4145 .decrypt = aead_decrypt,
4146 .ivsize = CTR_RFC3686_IV_SIZE,
4147 .maxauthsize = SHA512_DIGEST_SIZE,
4150 .class1_alg_type = OP_ALG_ALGSEL_AES |
4151 OP_ALG_AAI_CTR_MOD128,
4152 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
4153 OP_ALG_AAI_HMAC_PRECOMP,
4154 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
4161 .cra_name = "seqiv(authenc(hmac(sha512),"
4162 "rfc3686(ctr(aes))))",
4163 .cra_driver_name = "seqiv-authenc-hmac-sha512-"
4164 "rfc3686-ctr-aes-caam",
4167 .setkey = aead_setkey,
4168 .setauthsize = aead_setauthsize,
4169 .encrypt = aead_encrypt,
4170 .decrypt = aead_givdecrypt,
4171 .ivsize = CTR_RFC3686_IV_SIZE,
4172 .maxauthsize = SHA512_DIGEST_SIZE,
4175 .class1_alg_type = OP_ALG_ALGSEL_AES |
4176 OP_ALG_AAI_CTR_MOD128,
4177 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
4178 OP_ALG_AAI_HMAC_PRECOMP,
4179 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
4186 struct caam_crypto_alg {
4187 struct crypto_alg crypto_alg;
4188 struct list_head entry;
4189 struct caam_alg_entry caam;
4192 static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam)
4194 ctx->jrdev = caam_jr_alloc();
4195 if (IS_ERR(ctx->jrdev)) {
4196 pr_err("Job Ring Device allocation for transform failed\n");
4197 return PTR_ERR(ctx->jrdev);
4200 /* copy descriptor header template value */
4201 ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
4202 ctx->class2_alg_type = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
4203 ctx->alg_op = OP_TYPE_CLASS2_ALG | caam->alg_op;
4208 static int caam_cra_init(struct crypto_tfm *tfm)
4210 struct crypto_alg *alg = tfm->__crt_alg;
4211 struct caam_crypto_alg *caam_alg =
4212 container_of(alg, struct caam_crypto_alg, crypto_alg);
4213 struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
4215 return caam_init_common(ctx, &caam_alg->caam);
4218 static int caam_aead_init(struct crypto_aead *tfm)
4220 struct aead_alg *alg = crypto_aead_alg(tfm);
4221 struct caam_aead_alg *caam_alg =
4222 container_of(alg, struct caam_aead_alg, aead);
4223 struct caam_ctx *ctx = crypto_aead_ctx(tfm);
4225 return caam_init_common(ctx, &caam_alg->caam);
4228 static void caam_exit_common(struct caam_ctx *ctx)
4230 if (ctx->sh_desc_enc_dma &&
4231 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_enc_dma))
4232 dma_unmap_single(ctx->jrdev, ctx->sh_desc_enc_dma,
4233 desc_bytes(ctx->sh_desc_enc), DMA_TO_DEVICE);
4234 if (ctx->sh_desc_dec_dma &&
4235 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_dec_dma))
4236 dma_unmap_single(ctx->jrdev, ctx->sh_desc_dec_dma,
4237 desc_bytes(ctx->sh_desc_dec), DMA_TO_DEVICE);
4238 if (ctx->sh_desc_givenc_dma &&
4239 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_givenc_dma))
4240 dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma,
4241 desc_bytes(ctx->sh_desc_givenc),
4244 !dma_mapping_error(ctx->jrdev, ctx->key_dma))
4245 dma_unmap_single(ctx->jrdev, ctx->key_dma,
4246 ctx->enckeylen + ctx->split_key_pad_len,
4249 caam_jr_free(ctx->jrdev);
4252 static void caam_cra_exit(struct crypto_tfm *tfm)
4254 caam_exit_common(crypto_tfm_ctx(tfm));
4257 static void caam_aead_exit(struct crypto_aead *tfm)
4259 caam_exit_common(crypto_aead_ctx(tfm));
4262 static void __exit caam_algapi_exit(void)
4265 struct caam_crypto_alg *t_alg, *n;
4268 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
4269 struct caam_aead_alg *t_alg = driver_aeads + i;
4271 if (t_alg->registered)
4272 crypto_unregister_aead(&t_alg->aead);
4278 list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
4279 crypto_unregister_alg(&t_alg->crypto_alg);
4280 list_del(&t_alg->entry);
4285 static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
4288 struct caam_crypto_alg *t_alg;
4289 struct crypto_alg *alg;
4291 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
4293 pr_err("failed to allocate t_alg\n");
4294 return ERR_PTR(-ENOMEM);
4297 alg = &t_alg->crypto_alg;
4299 snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
4300 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
4301 template->driver_name);
4302 alg->cra_module = THIS_MODULE;
4303 alg->cra_init = caam_cra_init;
4304 alg->cra_exit = caam_cra_exit;
4305 alg->cra_priority = CAAM_CRA_PRIORITY;
4306 alg->cra_blocksize = template->blocksize;
4307 alg->cra_alignmask = 0;
4308 alg->cra_ctxsize = sizeof(struct caam_ctx);
4309 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
4311 switch (template->type) {
4312 case CRYPTO_ALG_TYPE_GIVCIPHER:
4313 alg->cra_type = &crypto_givcipher_type;
4314 alg->cra_ablkcipher = template->template_ablkcipher;
4316 case CRYPTO_ALG_TYPE_ABLKCIPHER:
4317 alg->cra_type = &crypto_ablkcipher_type;
4318 alg->cra_ablkcipher = template->template_ablkcipher;
4322 t_alg->caam.class1_alg_type = template->class1_alg_type;
4323 t_alg->caam.class2_alg_type = template->class2_alg_type;
4324 t_alg->caam.alg_op = template->alg_op;
4329 static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
4331 struct aead_alg *alg = &t_alg->aead;
4333 alg->base.cra_module = THIS_MODULE;
4334 alg->base.cra_priority = CAAM_CRA_PRIORITY;
4335 alg->base.cra_ctxsize = sizeof(struct caam_ctx);
4336 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
4338 alg->init = caam_aead_init;
4339 alg->exit = caam_aead_exit;
4342 static int __init caam_algapi_init(void)
4344 struct device_node *dev_node;
4345 struct platform_device *pdev;
4346 struct device *ctrldev;
4347 struct caam_drv_private *priv;
4349 u32 cha_vid, cha_inst, des_inst, aes_inst, md_inst;
4350 unsigned int md_limit = SHA512_DIGEST_SIZE;
4351 bool registered = false;
4353 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
4355 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
4360 pdev = of_find_device_by_node(dev_node);
4362 of_node_put(dev_node);
4366 ctrldev = &pdev->dev;
4367 priv = dev_get_drvdata(ctrldev);
4368 of_node_put(dev_node);
4371 * If priv is NULL, it's probably because the caam driver wasn't
4372 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
4378 INIT_LIST_HEAD(&alg_list);
4381 * Register crypto algorithms the device supports.
4382 * First, detect presence and attributes of DES, AES, and MD blocks.
4384 cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
4385 cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
4386 des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> CHA_ID_LS_DES_SHIFT;
4387 aes_inst = (cha_inst & CHA_ID_LS_AES_MASK) >> CHA_ID_LS_AES_SHIFT;
4388 md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
4390 /* If MD is present, limit digest size based on LP256 */
4391 if (md_inst && ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256))
4392 md_limit = SHA256_DIGEST_SIZE;
4394 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
4395 struct caam_crypto_alg *t_alg;
4396 struct caam_alg_template *alg = driver_algs + i;
4397 u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
4399 /* Skip DES algorithms if not supported by device */
4401 ((alg_sel == OP_ALG_ALGSEL_3DES) ||
4402 (alg_sel == OP_ALG_ALGSEL_DES)))
4405 /* Skip AES algorithms if not supported by device */
4406 if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
4409 t_alg = caam_alg_alloc(alg);
4410 if (IS_ERR(t_alg)) {
4411 err = PTR_ERR(t_alg);
4412 pr_warn("%s alg allocation failed\n", alg->driver_name);
4416 err = crypto_register_alg(&t_alg->crypto_alg);
4418 pr_warn("%s alg registration failed\n",
4419 t_alg->crypto_alg.cra_driver_name);
4424 list_add_tail(&t_alg->entry, &alg_list);
4428 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
4429 struct caam_aead_alg *t_alg = driver_aeads + i;
4430 u32 c1_alg_sel = t_alg->caam.class1_alg_type &
4432 u32 c2_alg_sel = t_alg->caam.class2_alg_type &
4434 u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
4436 /* Skip DES algorithms if not supported by device */
4438 ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
4439 (c1_alg_sel == OP_ALG_ALGSEL_DES)))
4442 /* Skip AES algorithms if not supported by device */
4443 if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
4447 * Check support for AES algorithms not available
4450 if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP)
4451 if (alg_aai == OP_ALG_AAI_GCM)
4455 * Skip algorithms requiring message digests
4456 * if MD or MD size is not supported by device.
4459 (!md_inst || (t_alg->aead.maxauthsize > md_limit)))
4462 caam_aead_alg_init(t_alg);
4464 err = crypto_register_aead(&t_alg->aead);
4466 pr_warn("%s alg registration failed\n",
4467 t_alg->aead.base.cra_driver_name);
4471 t_alg->registered = true;
4476 pr_info("caam algorithms registered in /proc/crypto\n");
4481 module_init(caam_algapi_init);
4482 module_exit(caam_algapi_exit);
4484 MODULE_LICENSE("GPL");
4485 MODULE_DESCRIPTION("FSL CAAM support for crypto API");
4486 MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");