1 // SPDX-License-Identifier: GPL-2.0
3 * CAAM/SEC 4.x functions for handling key-generation jobs
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
11 #include "desc_constr.h"
14 void split_key_done(struct device
*dev
, u32
*desc
, u32 err
,
17 struct split_key_result
*res
= context
;
20 dev_err(dev
, "%s %d: err 0x%x\n", __func__
, __LINE__
, err
);
24 caam_jr_strstatus(dev
, err
);
28 complete(&res
->completion
);
30 EXPORT_SYMBOL(split_key_done
);
32 get a split ipad/opad key
34 Split key generation-----------------------------------------------
36 [00] 0xb0810008 jobdesc: stidx=1 share=never len=8
37 [01] 0x04000014 key: class2->keyreg len=20
39 [03] 0x84410014 operation: cls2-op sha1 hmac init dec
40 [04] 0x24940000 fifold: class2 msgdata-last2 len=0 imm
41 [05] 0xa4000001 jump: class2 local all ->1 [06]
42 [06] 0x64260028 fifostr: class2 mdsplit-jdk len=40
45 int gen_split_key(struct device
*jrdev
, u8
*key_out
,
46 struct alginfo
* const adata
, const u8
*key_in
, u32 keylen
,
50 struct split_key_result result
;
54 adata
->keylen
= split_key_len(adata
->algtype
& OP_ALG_ALGSEL_MASK
);
55 adata
->keylen_pad
= split_key_pad_len(adata
->algtype
&
59 dev_err(jrdev
, "split keylen %d split keylen padded %d\n",
60 adata
->keylen
, adata
->keylen_pad
);
61 print_hex_dump(KERN_ERR
, "ctx.key@" __stringify(__LINE__
)": ",
62 DUMP_PREFIX_ADDRESS
, 16, 4, key_in
, keylen
, 1);
65 if (adata
->keylen_pad
> max_keylen
)
68 desc
= kmalloc(CAAM_CMD_SZ
* 6 + CAAM_PTR_SZ
* 2, GFP_KERNEL
| GFP_DMA
);
70 dev_err(jrdev
, "unable to allocate key input memory\n");
74 memcpy(key_out
, key_in
, keylen
);
76 dma_addr
= dma_map_single(jrdev
, key_out
, adata
->keylen_pad
,
78 if (dma_mapping_error(jrdev
, dma_addr
)) {
79 dev_err(jrdev
, "unable to map key memory\n");
83 init_job_desc(desc
, 0);
84 append_key(desc
, dma_addr
, keylen
, CLASS_2
| KEY_DEST_CLASS_REG
);
86 /* Sets MDHA up into an HMAC-INIT */
87 append_operation(desc
, (adata
->algtype
& OP_ALG_ALGSEL_MASK
) |
88 OP_ALG_AAI_HMAC
| OP_TYPE_CLASS2_ALG
| OP_ALG_DECRYPT
|
92 * do a FIFO_LOAD of zero, this will trigger the internal key expansion
93 * into both pads inside MDHA
95 append_fifo_load_as_imm(desc
, NULL
, 0, LDST_CLASS_2_CCB
|
96 FIFOLD_TYPE_MSG
| FIFOLD_TYPE_LAST2
);
99 * FIFO_STORE with the explicit split-key content store
102 append_fifo_store(desc
, dma_addr
, adata
->keylen
,
103 LDST_CLASS_2_CCB
| FIFOST_TYPE_SPLIT_KEK
);
106 print_hex_dump(KERN_ERR
, "jobdesc@"__stringify(__LINE__
)": ",
107 DUMP_PREFIX_ADDRESS
, 16, 4, desc
, desc_bytes(desc
), 1);
111 init_completion(&result
.completion
);
113 ret
= caam_jr_enqueue(jrdev
, desc
, split_key_done
, &result
);
116 wait_for_completion(&result
.completion
);
119 print_hex_dump(KERN_ERR
, "ctx.key@"__stringify(__LINE__
)": ",
120 DUMP_PREFIX_ADDRESS
, 16, 4, key_out
,
121 adata
->keylen_pad
, 1);
125 dma_unmap_single(jrdev
, dma_addr
, adata
->keylen_pad
, DMA_BIDIRECTIONAL
);
130 EXPORT_SYMBOL(gen_split_key
);