1
2
3
4
5
6
7
8#include "compat.h"
9#include "desc_constr.h"
10#include "caamhash_desc.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28void cnstr_shdsc_ahash(u32 * const desc, struct alginfo *adata, u32 state,
29 int digestsize, int ctx_len, bool import_ctx, int era)
30{
31 u32 op = adata->algtype;
32
33 init_sh_desc(desc, HDR_SHARE_SERIAL);
34
35
36 if (state != OP_ALG_AS_UPDATE && adata->keylen) {
37 u32 *skip_key_load;
38
39
40 skip_key_load = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
41 JUMP_COND_SHRD);
42
43 if (era < 6)
44 append_key_as_imm(desc, adata->key_virt,
45 adata->keylen_pad,
46 adata->keylen, CLASS_2 |
47 KEY_DEST_MDHA_SPLIT | KEY_ENC);
48 else
49 append_proto_dkp(desc, adata);
50
51 set_jump_tgt_here(desc, skip_key_load);
52
53 op |= OP_ALG_AAI_HMAC_PRECOMP;
54 }
55
56
57 if (import_ctx)
58 append_seq_load(desc, ctx_len, LDST_CLASS_2_CCB |
59 LDST_SRCDST_BYTE_CONTEXT);
60
61
62 append_operation(desc, op | state | OP_ALG_ENCRYPT);
63
64
65
66
67
68 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
69
70 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_LAST2 |
71 FIFOLD_TYPE_MSG | KEY_VLF);
72
73 append_seq_store(desc, digestsize, LDST_CLASS_2_CCB |
74 LDST_SRCDST_BYTE_CONTEXT);
75}
76EXPORT_SYMBOL(cnstr_shdsc_ahash);
77
78
79
80
81
82
83
84
85
86
87
88void cnstr_shdsc_sk_hash(u32 * const desc, struct alginfo *adata, u32 state,
89 int digestsize, int ctx_len, dma_addr_t key_dma)
90{
91 u32 *skip_key_load;
92
93 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
94
95
96 skip_key_load = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
97
98 if (state == OP_ALG_AS_INIT || state == OP_ALG_AS_INITFINAL) {
99 append_key_as_imm(desc, adata->key_virt, adata->keylen,
100 adata->keylen, CLASS_1 | KEY_DEST_CLASS_REG);
101 } else {
102 if (is_xcbc_aes(adata->algtype))
103
104 append_key(desc, adata->key_dma, adata->keylen,
105 CLASS_1 | KEY_DEST_CLASS_REG | KEY_ENC);
106 else
107 append_key_as_imm(desc, adata->key_virt, adata->keylen,
108 adata->keylen, CLASS_1 |
109 KEY_DEST_CLASS_REG);
110
111 append_seq_load(desc, ctx_len, LDST_CLASS_1_CCB |
112 LDST_SRCDST_BYTE_CONTEXT);
113 }
114
115 set_jump_tgt_here(desc, skip_key_load);
116
117
118 append_operation(desc, adata->algtype | state | OP_ALG_ENCRYPT);
119
120
121
122
123
124 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
125
126
127 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_LAST1 |
128 FIFOLD_TYPE_MSG | FIFOLDST_VLF);
129
130
131
132
133
134
135 append_seq_store(desc, digestsize, LDST_CLASS_1_CCB |
136 LDST_SRCDST_BYTE_CONTEXT);
137 if (is_xcbc_aes(adata->algtype) && state == OP_ALG_AS_INIT)
138
139 append_fifo_store(desc, key_dma, adata->keylen,
140 LDST_CLASS_1_CCB | FIFOST_TYPE_KEY_KEK);
141}
142EXPORT_SYMBOL(cnstr_shdsc_sk_hash);
143
144MODULE_LICENSE("Dual BSD/GPL");
145MODULE_DESCRIPTION("FSL CAAM ahash descriptors support");
146MODULE_AUTHOR("NXP Semiconductors");
147