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