Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef __ROC_SE_H__
6 : : #define __ROC_SE_H__
7 : :
8 : : /* SE opcodes */
9 : : #define ROC_SE_MAJOR_OP_FC 0x33
10 : : #define ROC_SE_FC_MINOR_OP_ENCRYPT 0x0
11 : : #define ROC_SE_FC_MINOR_OP_DECRYPT 0x1
12 : : #define ROC_SE_FC_MINOR_OP_HMAC_FIRST 0x10
13 : : #define ROC_SE_FC_MINOR_OP_DOCSIS 0x40
14 : :
15 : : #define ROC_SE_MAJOR_OP_HASH 0x34
16 : : #define ROC_SE_MAJOR_OP_HMAC 0x35
17 : : #define ROC_SE_MAJOR_OP_PDCP 0x37
18 : : #define ROC_SE_MAJOR_OP_KASUMI 0x38
19 : : #define ROC_SE_MAJOR_OP_PDCP_CHAIN 0x3C
20 : : #define ROC_SE_MAJOR_OP_SM 0x3D
21 : :
22 : : #define ROC_SE_MAJOR_OP_MISC 0x01ULL
23 : : #define ROC_SE_MISC_MINOR_OP_PASSTHROUGH 0x03ULL
24 : : #define ROC_SE_MISC_MINOR_OP_DUMMY 0x04ULL
25 : : #define ROC_SE_MISC_MINOR_OP_HW_SUPPORT 0x08ULL
26 : :
27 : : #define ROC_SE_MAX_AAD_SIZE 64
28 : : #define ROC_SE_MAX_MAC_LEN 64
29 : :
30 : : #define ROC_SE_OFF_CTRL_LEN 8
31 : :
32 : : #define ROC_SE_SM4_KEY_LEN 16
33 : :
34 : : #define ROC_SE_ZS_EA 0x1
35 : : #define ROC_SE_ZS_IA 0x2
36 : : #define ROC_SE_K_F8 0x4
37 : : #define ROC_SE_K_F9 0x8
38 : :
39 : : #define ROC_SE_FC_GEN 0x1
40 : : #define ROC_SE_PDCP 0x2
41 : : #define ROC_SE_KASUMI 0x3
42 : : #define ROC_SE_HASH_HMAC 0x4
43 : : #define ROC_SE_PDCP_CHAIN 0x5
44 : : #define ROC_SE_SM 0x6
45 : :
46 : : #define ROC_SE_OP_CIPHER_ENCRYPT 0x1
47 : : #define ROC_SE_OP_CIPHER_DECRYPT 0x2
48 : : #define ROC_SE_OP_CIPHER_MASK \
49 : : (ROC_SE_OP_CIPHER_ENCRYPT | ROC_SE_OP_CIPHER_DECRYPT)
50 : :
51 : : #define ROC_SE_OP_AUTH_VERIFY 0x4
52 : : #define ROC_SE_OP_AUTH_GENERATE 0x8
53 : : #define ROC_SE_OP_AUTH_MASK \
54 : : (ROC_SE_OP_AUTH_VERIFY | ROC_SE_OP_AUTH_GENERATE)
55 : :
56 : : #define ROC_SE_OP_ENCODE (ROC_SE_OP_CIPHER_ENCRYPT | ROC_SE_OP_AUTH_GENERATE)
57 : : #define ROC_SE_OP_DECODE (ROC_SE_OP_CIPHER_DECRYPT | ROC_SE_OP_AUTH_VERIFY)
58 : :
59 : : #define ROC_SE_ALWAYS_USE_SEPARATE_BUF
60 : :
61 : : /*
62 : : * Parameters for Flexi Crypto
63 : : * requests
64 : : */
65 : : #define ROC_SE_VALID_AAD_BUF 0x01
66 : : #define ROC_SE_VALID_MAC_BUF 0x02
67 : : #define ROC_SE_VALID_IV_BUF 0x04
68 : : #define ROC_SE_SINGLE_BUF_INPLACE 0x08
69 : : #define ROC_SE_SINGLE_BUF_HEADROOM 0x10
70 : :
71 : : #define ROC_SE_ENCR_IV_OFFSET(__d_offs) (((__d_offs) >> 32) & 0xffff)
72 : : #define ROC_SE_ENCR_OFFSET(__d_offs) (((__d_offs) >> 16) & 0xffff)
73 : : #define ROC_SE_AUTH_OFFSET(__d_offs) ((__d_offs) & 0xffff)
74 : : #define ROC_SE_ENCR_DLEN(__d_lens) ((__d_lens) >> 32)
75 : : #define ROC_SE_AUTH_DLEN(__d_lens) ((__d_lens) & 0xffffffff)
76 : :
77 : : typedef enum { ROC_SE_FROM_CTX = 0, ROC_SE_FROM_DPTR = 1 } roc_se_input_type;
78 : :
79 : : typedef enum {
80 : : ROC_SE_MD5_TYPE = 1,
81 : : ROC_SE_SHA1_TYPE = 2,
82 : : ROC_SE_SHA2_SHA224 = 3,
83 : : ROC_SE_SHA2_SHA256 = 4,
84 : : ROC_SE_SHA2_SHA384 = 5,
85 : : ROC_SE_SHA2_SHA512 = 6,
86 : : ROC_SE_GMAC_TYPE = 7,
87 : : ROC_SE_POLY1305 = 8,
88 : : ROC_SE_SM3 = 9,
89 : : ROC_SE_SHA3_SHA224 = 10,
90 : : ROC_SE_SHA3_SHA256 = 11,
91 : : ROC_SE_SHA3_SHA384 = 12,
92 : : ROC_SE_SHA3_SHA512 = 13,
93 : : ROC_SE_SHA3_SHAKE128 = 14,
94 : : ROC_SE_SHA3_SHAKE256 = 15,
95 : :
96 : : /* These are only for software use */
97 : : ROC_SE_ZUC_EIA3 = 0x90,
98 : : ROC_SE_SNOW3G_UIA2 = 0x91,
99 : : ROC_SE_AES_CMAC_EIA2 = 0x92,
100 : : ROC_SE_KASUMI_F9_CBC = 0x93,
101 : : ROC_SE_KASUMI_F9_ECB = 0x94,
102 : : } roc_se_auth_type;
103 : :
104 : : typedef enum {
105 : : /* To support passthrough */
106 : : ROC_SE_PASSTHROUGH = 0x0,
107 : : /*
108 : : * These are defined by MC for Flexi crypto
109 : : * for field of 4 bits
110 : : */
111 : : ROC_SE_DES3_CBC = 0x1,
112 : : ROC_SE_DES3_ECB = 0x2,
113 : : ROC_SE_AES_CBC = 0x3,
114 : : ROC_SE_AES_ECB = 0x4,
115 : : ROC_SE_AES_CFB = 0x5,
116 : : ROC_SE_AES_CTR = 0x6,
117 : : ROC_SE_AES_GCM = 0x7,
118 : : ROC_SE_AES_XTS = 0x8,
119 : : ROC_SE_CHACHA20 = 0x9,
120 : : ROC_SE_AES_CCM = 0xA,
121 : :
122 : : /* These are only for software use */
123 : : ROC_SE_ZUC_EEA3 = 0x90,
124 : : ROC_SE_SNOW3G_UEA2 = 0x91,
125 : : ROC_SE_AES_CTR_EEA2 = 0x92,
126 : : ROC_SE_KASUMI_F8_CBC = 0x93,
127 : : ROC_SE_KASUMI_F8_ECB = 0x94,
128 : : ROC_SE_AES_DOCSISBPI = 0x95,
129 : : ROC_SE_DES_DOCSISBPI = 0x96,
130 : : } roc_se_cipher_type;
131 : :
132 : : typedef enum {
133 : : ROC_SM4_ECB = 0x0,
134 : : ROC_SM4_CBC = 0x1,
135 : : ROC_SM4_CTR = 0x2,
136 : : ROC_SM4_CFB = 0x3,
137 : : ROC_SM4_OFB = 0x4,
138 : : } roc_sm_cipher_type;
139 : :
140 : : typedef enum {
141 : : /* Microcode errors */
142 : : ROC_SE_NO_ERR = 0x00,
143 : : ROC_SE_ERR_OPCODE_UNSUPPORTED = 0x01,
144 : :
145 : : /* SCATTER GATHER */
146 : : ROC_SE_ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
147 : : ROC_SE_ERR_SCATTER_GATHER_LIST = 0x03,
148 : : ROC_SE_ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
149 : :
150 : : /* SE GC */
151 : : ROC_SE_ERR_GC_LENGTH_INVALID = 0x41,
152 : : ROC_SE_ERR_GC_RANDOM_LEN_INVALID = 0x42,
153 : : ROC_SE_ERR_GC_DATA_LEN_INVALID = 0x43,
154 : : ROC_SE_ERR_GC_DRBG_TYPE_INVALID = 0x44,
155 : : ROC_SE_ERR_GC_CTX_LEN_INVALID = 0x45,
156 : : ROC_SE_ERR_GC_CIPHER_UNSUPPORTED = 0x46,
157 : : ROC_SE_ERR_GC_AUTH_UNSUPPORTED = 0x47,
158 : : ROC_SE_ERR_GC_OFFSET_INVALID = 0x48,
159 : : ROC_SE_ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
160 : : ROC_SE_ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
161 : : ROC_SE_ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
162 : : ROC_SE_ERR_GC_ICV_MISCOMPARE = 0x4c,
163 : : ROC_SE_ERR_GC_DATA_UNALIGNED = 0x4d,
164 : :
165 : : /* API Layer */
166 : : ROC_SE_ERR_REQ_PENDING = 0xfe,
167 : : ROC_SE_ERR_REQ_TIMEOUT = 0xff,
168 : :
169 : : } roc_se_error_code;
170 : :
171 : : typedef enum {
172 : : ROC_SE_AES_128_BIT = 0x1,
173 : : ROC_SE_AES_192_BIT = 0x2,
174 : : ROC_SE_AES_256_BIT = 0x3
175 : : } roc_se_aes_type;
176 : :
177 : : typedef enum {
178 : : ROC_SE_PDCP_MAC_LEN_32_BIT = 0x1,
179 : : ROC_SE_PDCP_MAC_LEN_64_BIT = 0x2,
180 : : ROC_SE_PDCP_MAC_LEN_128_BIT = 0x3
181 : : } roc_se_pdcp_mac_len_type;
182 : :
183 : : struct roc_se_enc_context {
184 : : uint64_t iv_source : 1;
185 : : uint64_t aes_key : 2;
186 : : uint64_t rsvd_59 : 1;
187 : : uint64_t enc_cipher : 4;
188 : : uint64_t auth_input_type : 1;
189 : : uint64_t auth_key_src : 1;
190 : : uint64_t rsvd_50_51 : 2;
191 : : uint64_t hash_type : 4;
192 : : uint64_t mac_len : 8;
193 : : uint64_t rsvd_16_39 : 24;
194 : : uint64_t hmac_key_sz : 16;
195 : : uint8_t encr_key[32];
196 : : uint8_t encr_iv[16];
197 : : };
198 : :
199 : : struct roc_se_hmac_context {
200 : : uint8_t ipad[64];
201 : : uint8_t opad[64];
202 : : };
203 : :
204 : : struct roc_se_context {
205 : : struct roc_se_enc_context enc;
206 : : struct roc_se_hmac_context hmac;
207 : : };
208 : :
209 : : struct roc_se_sm_context {
210 : : uint64_t rsvd_56_60 : 5;
211 : : uint64_t enc_cipher : 3;
212 : : uint64_t rsvd_0_55 : 56;
213 : : uint8_t encr_key[16];
214 : : };
215 : :
216 : : struct roc_se_otk_zuc_ctx {
217 : : union {
218 : : uint64_t u64;
219 : : struct {
220 : : uint64_t rsvd_56 : 57;
221 : : uint64_t mac_len : 2;
222 : : uint64_t key_len : 2;
223 : : uint64_t lfsr_state : 1;
224 : : uint64_t alg_type : 2;
225 : : } s;
226 : : } w0;
227 : : uint8_t ci_key[32];
228 : : uint8_t encr_auth_iv[24];
229 : : uint8_t zuc_const[32];
230 : : };
231 : :
232 : : struct roc_se_onk_zuc_ctx {
233 : : uint8_t encr_auth_iv[16];
234 : : uint8_t ci_key[16];
235 : : uint8_t zuc_const[32];
236 : : };
237 : :
238 : : struct roc_se_onk_zuc_chain_ctx {
239 : : union {
240 : : uint64_t u64;
241 : : struct {
242 : : uint64_t cipher_type : 2;
243 : : uint64_t rsvd58_59 : 2;
244 : : uint64_t auth_type : 2;
245 : : uint64_t rsvd62_63 : 2;
246 : : uint64_t mac_len : 4;
247 : : uint64_t ci_key_len : 2;
248 : : uint64_t auth_key_len : 2;
249 : : uint64_t rsvd42_47 : 6;
250 : : uint64_t state_conf : 2;
251 : : uint64_t rsvd0_39 : 40;
252 : : } s;
253 : : } w0;
254 : : union {
255 : : struct {
256 : : uint8_t encr_lfsr_state[72];
257 : : uint8_t auth_lfsr_state[72];
258 : : };
259 : : struct {
260 : : uint8_t ci_key[32];
261 : : uint8_t ci_zuc_const[32];
262 : : uint8_t rsvd[8];
263 : : uint8_t auth_key[32];
264 : : uint8_t auth_zuc_const[32];
265 : : uint8_t rsvd1[8];
266 : : };
267 : : } st;
268 : : };
269 : :
270 : : struct roc_se_zuc_snow3g_chain_ctx {
271 : : union {
272 : : struct roc_se_onk_zuc_chain_ctx onk_ctx;
273 : : } zuc;
274 : : };
275 : :
276 : : struct roc_se_zuc_snow3g_ctx {
277 : : union {
278 : : struct roc_se_onk_zuc_ctx onk_ctx;
279 : : struct roc_se_otk_zuc_ctx otk_ctx;
280 : : } zuc;
281 : : };
282 : :
283 : : struct roc_se_kasumi_ctx {
284 : : uint8_t reg_A[8];
285 : : uint8_t ci_key[16];
286 : : };
287 : :
288 : : /* Buffer pointer */
289 : : struct roc_se_buf_ptr {
290 : : void *vaddr;
291 : : uint32_t size;
292 : : uint32_t resv;
293 : : };
294 : :
295 : : /* IOV Pointer */
296 : : struct roc_se_iov_ptr {
297 : : int buf_cnt;
298 : : struct roc_se_buf_ptr bufs[];
299 : : };
300 : :
301 : : #define ROC_SE_PDCP_ALG_TYPE_ZUC 0
302 : : #define ROC_SE_PDCP_ALG_TYPE_SNOW3G 1
303 : : #define ROC_SE_PDCP_ALG_TYPE_AES_CTR 2
304 : : #define ROC_SE_PDCP_ALG_TYPE_AES_CMAC 3
305 : : #define ROC_SE_PDCP_CHAIN_ALG_TYPE_SNOW3G 1
306 : : #define ROC_SE_PDCP_CHAIN_ALG_TYPE_ZUC 3
307 : :
308 : : #define ROC_SE_PDCP_CHAIN_CTX_LFSR 0
309 : : #define ROC_SE_PDCP_CHAIN_CTX_KEY_IV 1
310 : :
311 : : struct roc_se_ctx {
312 : : /* Below fields are accessed by sw */
313 : : uint64_t enc_cipher : 8;
314 : : uint64_t hash_type : 8;
315 : : uint64_t mac_len : 8;
316 : : uint64_t auth_key_len : 16;
317 : : uint64_t fc_type : 4;
318 : : uint64_t hmac : 1;
319 : : uint64_t zsk_flags : 3;
320 : : uint64_t k_ecb : 1;
321 : : uint64_t pdcp_ci_alg : 2;
322 : : uint64_t pdcp_auth_alg : 2;
323 : : uint64_t ciph_then_auth : 1;
324 : : uint64_t auth_then_ciph : 1;
325 : : uint64_t eia2 : 1;
326 : : /* auth_iv_offset passed to PDCP_CHAIN opcode based on FVC bit */
327 : : uint8_t pdcp_iv_offset;
328 : : union cpt_inst_w4 template_w4;
329 : : /* Below fields are accessed by hardware */
330 : : struct se_ctx_s {
331 : : /* Word0 */
332 : : union {
333 : : struct {
334 : : uint64_t rsvd : 48;
335 : :
336 : : uint64_t ctx_push_size : 7;
337 : : uint64_t rsvd1 : 1;
338 : :
339 : : uint64_t ctx_hdr_size : 2;
340 : : uint64_t aop_valid : 1;
341 : : uint64_t rsvd2 : 1;
342 : : uint64_t ctx_size : 4;
343 : : } s;
344 : : uint64_t u64;
345 : : } w0;
346 : : union {
347 : : struct roc_se_context fctx;
348 : : struct roc_se_zuc_snow3g_ctx zs_ctx;
349 : : struct roc_se_zuc_snow3g_chain_ctx zs_ch_ctx;
350 : : struct roc_se_kasumi_ctx k_ctx;
351 : : struct roc_se_sm_context sm_ctx;
352 : : };
353 : : } se_ctx __plt_aligned(ROC_ALIGN);
354 : : uint8_t *auth_key;
355 : : } __plt_aligned(ROC_ALIGN);
356 : :
357 : : struct roc_se_fc_params {
358 : : union {
359 : : struct roc_se_buf_ptr bufs[1];
360 : : struct {
361 : : struct roc_se_iov_ptr *src_iov;
362 : : struct roc_se_iov_ptr *dst_iov;
363 : : };
364 : : };
365 : : const void *iv_buf;
366 : : const void *auth_iv_buf;
367 : : struct roc_se_ctx *ctx;
368 : : struct roc_se_buf_ptr meta_buf;
369 : : uint8_t cipher_iv_len;
370 : : uint8_t auth_iv_len;
371 : : uint8_t pdcp_iv_offset;
372 : :
373 : : struct roc_se_buf_ptr aad_buf;
374 : : struct roc_se_buf_ptr mac_buf;
375 : : };
376 : :
377 : : static inline void
378 : : roc_se_zuc_bytes_swap(uint8_t *arr, int len)
379 : : {
380 : : int start, end;
381 : : uint8_t tmp;
382 : :
383 : : if (len <= 0)
384 : : return;
385 : :
386 : : start = 0;
387 : : end = len - 1;
388 : :
389 [ # # # # ]: 0 : while (start < end) {
390 : 0 : tmp = arr[start];
391 : 0 : arr[start] = arr[end];
392 : 0 : arr[end] = tmp;
393 : 0 : start++;
394 : 0 : end--;
395 : : }
396 : : }
397 : :
398 : : int __roc_api roc_se_auth_key_set(struct roc_se_ctx *se_ctx, roc_se_auth_type type,
399 : : const uint8_t *key, uint16_t key_len, uint16_t mac_len);
400 : :
401 : : int __roc_api roc_se_ciph_key_set(struct roc_se_ctx *se_ctx, roc_se_cipher_type type,
402 : : const uint8_t *key, uint16_t key_len);
403 : :
404 : : void __roc_api roc_se_ctx_swap(struct roc_se_ctx *se_ctx);
405 : : void __roc_api roc_se_ctx_init(struct roc_se_ctx *se_ctx);
406 : :
407 : : #endif /* __ROC_SE_H__ */
|