Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2024 Marvell.
3 : : */
4 : :
5 : : #include <rte_crypto_sym.h>
6 : : #include <rte_cryptodev.h>
7 : : #include <rte_security.h>
8 : :
9 : : #include <cryptodev_pmd.h>
10 : :
11 : : #include "roc_cpt.h"
12 : : #include "roc_se.h"
13 : :
14 : : #include "cn10k_cryptodev_sec.h"
15 : : #include "cn10k_tls.h"
16 : : #include "cnxk_cryptodev.h"
17 : : #include "cnxk_cryptodev_ops.h"
18 : : #include "cnxk_security.h"
19 : :
20 : : static int
21 : 0 : tls_xform_cipher_auth_verify(struct rte_crypto_sym_xform *cipher_xform,
22 : : struct rte_crypto_sym_xform *auth_xform)
23 : : {
24 : 0 : enum rte_crypto_cipher_algorithm c_algo = cipher_xform->cipher.algo;
25 : 0 : enum rte_crypto_auth_algorithm a_algo = auth_xform->auth.algo;
26 : : int ret = -ENOTSUP;
27 : :
28 [ # # # # ]: 0 : switch (c_algo) {
29 : 0 : case RTE_CRYPTO_CIPHER_NULL:
30 [ # # ]: 0 : if ((a_algo == RTE_CRYPTO_AUTH_MD5_HMAC) || (a_algo == RTE_CRYPTO_AUTH_SHA1_HMAC) ||
31 : 0 : (a_algo == RTE_CRYPTO_AUTH_SHA256_HMAC) ||
32 [ # # ]: 0 : (a_algo == RTE_CRYPTO_AUTH_SHA384_HMAC))
33 : : ret = 0;
34 : : break;
35 : 0 : case RTE_CRYPTO_CIPHER_3DES_CBC:
36 [ # # ]: 0 : if (a_algo == RTE_CRYPTO_AUTH_SHA1_HMAC)
37 : : ret = 0;
38 : : break;
39 : 0 : case RTE_CRYPTO_CIPHER_AES_CBC:
40 : 0 : if ((a_algo == RTE_CRYPTO_AUTH_SHA1_HMAC) ||
41 [ # # # # ]: 0 : (a_algo == RTE_CRYPTO_AUTH_SHA256_HMAC) ||
42 : : (a_algo == RTE_CRYPTO_AUTH_SHA384_HMAC))
43 : : ret = 0;
44 : : break;
45 : : default:
46 : : break;
47 : : }
48 : :
49 : 0 : return ret;
50 : : }
51 : :
52 : : static int
53 : 0 : tls_xform_cipher_verify(struct rte_crypto_sym_xform *crypto_xform)
54 : : {
55 : 0 : enum rte_crypto_cipher_algorithm c_algo = crypto_xform->cipher.algo;
56 : 0 : uint16_t keylen = crypto_xform->cipher.key.length;
57 : :
58 [ # # ]: 0 : if (((c_algo == RTE_CRYPTO_CIPHER_NULL) && (keylen == 0)) ||
59 [ # # # # ]: 0 : ((c_algo == RTE_CRYPTO_CIPHER_3DES_CBC) && (keylen == 24)) ||
60 [ # # ]: 0 : ((c_algo == RTE_CRYPTO_CIPHER_AES_CBC) && ((keylen == 16) || (keylen == 32))))
61 : 0 : return 0;
62 : :
63 : : return -EINVAL;
64 : : }
65 : :
66 : : static int
67 : 0 : tls_xform_auth_verify(struct rte_crypto_sym_xform *crypto_xform)
68 : : {
69 : 0 : enum rte_crypto_auth_algorithm a_algo = crypto_xform->auth.algo;
70 : 0 : uint16_t keylen = crypto_xform->auth.key.length;
71 : :
72 [ # # ]: 0 : if (((a_algo == RTE_CRYPTO_AUTH_MD5_HMAC) && (keylen == 16)) ||
73 [ # # ]: 0 : ((a_algo == RTE_CRYPTO_AUTH_SHA1_HMAC) && (keylen == 20)) ||
74 [ # # ]: 0 : ((a_algo == RTE_CRYPTO_AUTH_SHA256_HMAC) && (keylen == 32)) ||
75 [ # # ]: 0 : ((a_algo == RTE_CRYPTO_AUTH_SHA384_HMAC) && (keylen == 48)))
76 : 0 : return 0;
77 : :
78 : : return -EINVAL;
79 : : }
80 : :
81 : : static int
82 : 0 : tls_xform_aead_verify(struct rte_security_tls_record_xform *tls_xform,
83 : : struct rte_crypto_sym_xform *crypto_xform)
84 : : {
85 : 0 : uint16_t keylen = crypto_xform->aead.key.length;
86 : :
87 [ # # ]: 0 : if (tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_WRITE &&
88 [ # # ]: 0 : crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_ENCRYPT)
89 : : return -EINVAL;
90 : :
91 [ # # ]: 0 : if (tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_READ &&
92 [ # # ]: 0 : crypto_xform->aead.op != RTE_CRYPTO_AEAD_OP_DECRYPT)
93 : : return -EINVAL;
94 : :
95 [ # # ]: 0 : if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
96 [ # # ]: 0 : if ((keylen == 16) || (keylen == 32))
97 : : return 0;
98 : : }
99 : :
100 [ # # # # ]: 0 : if ((crypto_xform->aead.algo == RTE_CRYPTO_AEAD_CHACHA20_POLY1305) && (keylen == 32))
101 : 0 : return 0;
102 : :
103 : : return -EINVAL;
104 : : }
105 : :
106 : : static int
107 : 0 : cnxk_tls_xform_verify(struct rte_security_tls_record_xform *tls_xform,
108 : : struct rte_crypto_sym_xform *crypto_xform)
109 : : {
110 : : struct rte_crypto_sym_xform *auth_xform, *cipher_xform = NULL;
111 : : int ret = 0;
112 : :
113 [ # # ]: 0 : if ((tls_xform->ver != RTE_SECURITY_VERSION_TLS_1_2) &&
114 [ # # ]: 0 : (tls_xform->ver != RTE_SECURITY_VERSION_DTLS_1_2) &&
115 : : (tls_xform->ver != RTE_SECURITY_VERSION_TLS_1_3))
116 : : return -EINVAL;
117 : :
118 [ # # ]: 0 : if ((tls_xform->type != RTE_SECURITY_TLS_SESS_TYPE_READ) &&
119 : : (tls_xform->type != RTE_SECURITY_TLS_SESS_TYPE_WRITE))
120 : : return -EINVAL;
121 : :
122 [ # # ]: 0 : if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
123 : : /* optional padding is not allowed in TLS-1.2 for AEAD */
124 [ # # # # ]: 0 : if ((tls_xform->options.extra_padding_enable == 1) &&
125 : : (tls_xform->ver != RTE_SECURITY_VERSION_TLS_1_3))
126 : : return -EINVAL;
127 : :
128 : 0 : return tls_xform_aead_verify(tls_xform, crypto_xform);
129 : : }
130 : :
131 : : /* TLS-1.3 only support AEAD.
132 : : * Control should not reach here for TLS-1.3
133 : : */
134 [ # # ]: 0 : if (tls_xform->ver == RTE_SECURITY_VERSION_TLS_1_3)
135 : : return -EINVAL;
136 : :
137 [ # # ]: 0 : if (tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) {
138 : : /* Egress */
139 : :
140 : : /* First should be for auth in Egress */
141 [ # # ]: 0 : if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH)
142 : : return -EINVAL;
143 : :
144 : : /* Next if present, should be for cipher in Egress */
145 [ # # ]: 0 : if ((crypto_xform->next != NULL) &&
146 [ # # ]: 0 : (crypto_xform->next->type != RTE_CRYPTO_SYM_XFORM_CIPHER))
147 : : return -EINVAL;
148 : :
149 : : auth_xform = crypto_xform;
150 : : cipher_xform = crypto_xform->next;
151 : : } else {
152 : : /* Ingress */
153 : :
154 : : /* First can be for auth only when next is NULL in Ingress. */
155 [ # # ]: 0 : if ((crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
156 [ # # ]: 0 : (crypto_xform->next != NULL))
157 : : return -EINVAL;
158 [ # # ]: 0 : else if ((crypto_xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) ||
159 [ # # ]: 0 : (crypto_xform->next->type != RTE_CRYPTO_SYM_XFORM_AUTH))
160 : : return -EINVAL;
161 : :
162 : : cipher_xform = crypto_xform;
163 : : auth_xform = crypto_xform->next;
164 : : }
165 : :
166 [ # # ]: 0 : if (cipher_xform) {
167 [ # # ]: 0 : if ((tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) &&
168 [ # # ]: 0 : !(cipher_xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
169 [ # # ]: 0 : auth_xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE))
170 : : return -EINVAL;
171 : :
172 [ # # ]: 0 : if ((tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_READ) &&
173 [ # # ]: 0 : !(cipher_xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
174 [ # # ]: 0 : auth_xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY))
175 : : return -EINVAL;
176 : : } else {
177 [ # # ]: 0 : if ((tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) &&
178 [ # # ]: 0 : (auth_xform->auth.op != RTE_CRYPTO_AUTH_OP_GENERATE))
179 : : return -EINVAL;
180 : :
181 [ # # ]: 0 : if ((tls_xform->type == RTE_SECURITY_TLS_SESS_TYPE_READ) &&
182 [ # # ]: 0 : (auth_xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY))
183 : : return -EINVAL;
184 : : }
185 : :
186 [ # # ]: 0 : if (cipher_xform)
187 : 0 : ret = tls_xform_cipher_verify(cipher_xform);
188 : :
189 [ # # ]: 0 : if (!ret)
190 : 0 : ret = tls_xform_auth_verify(auth_xform);
191 : :
192 [ # # ]: 0 : if (cipher_xform && !ret)
193 : 0 : return tls_xform_cipher_auth_verify(cipher_xform, auth_xform);
194 : :
195 : : return ret;
196 : : }
197 : :
198 : : static int
199 : 0 : tls_write_rlens_get(struct rte_security_tls_record_xform *tls_xfrm,
200 : : struct rte_crypto_sym_xform *crypto_xfrm)
201 : : {
202 : : enum rte_crypto_cipher_algorithm c_algo = RTE_CRYPTO_CIPHER_NULL;
203 : : enum rte_crypto_auth_algorithm a_algo = RTE_CRYPTO_AUTH_NULL;
204 : : uint8_t roundup_byte, tls_hdr_len;
205 : : uint8_t mac_len, iv_len;
206 : :
207 [ # # # ]: 0 : switch (tls_xfrm->ver) {
208 : : case RTE_SECURITY_VERSION_TLS_1_2:
209 : : case RTE_SECURITY_VERSION_TLS_1_3:
210 : : tls_hdr_len = 5;
211 : : break;
212 : 0 : case RTE_SECURITY_VERSION_DTLS_1_2:
213 : : tls_hdr_len = 13;
214 : 0 : break;
215 : 0 : default:
216 : : tls_hdr_len = 0;
217 : 0 : break;
218 : : }
219 : :
220 : : /* Get Cipher and Auth algo */
221 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD)
222 : 0 : return tls_hdr_len + ROC_CPT_AES_GCM_IV_LEN + ROC_CPT_AES_GCM_MAC_LEN;
223 : :
224 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
225 : 0 : c_algo = crypto_xfrm->cipher.algo;
226 [ # # ]: 0 : if (crypto_xfrm->next)
227 : 0 : a_algo = crypto_xfrm->next->auth.algo;
228 : : } else {
229 : 0 : a_algo = crypto_xfrm->auth.algo;
230 [ # # ]: 0 : if (crypto_xfrm->next)
231 : 0 : c_algo = crypto_xfrm->next->cipher.algo;
232 : : }
233 : :
234 [ # # # # ]: 0 : switch (c_algo) {
235 : : case RTE_CRYPTO_CIPHER_NULL:
236 : : roundup_byte = 4;
237 : : iv_len = 0;
238 : : break;
239 : 0 : case RTE_CRYPTO_CIPHER_3DES_CBC:
240 : : roundup_byte = ROC_CPT_DES_BLOCK_LENGTH;
241 : : iv_len = ROC_CPT_DES_IV_LEN;
242 : 0 : break;
243 : 0 : case RTE_CRYPTO_CIPHER_AES_CBC:
244 : : roundup_byte = ROC_CPT_AES_BLOCK_LENGTH;
245 : : iv_len = ROC_CPT_AES_CBC_IV_LEN;
246 : 0 : break;
247 : 0 : default:
248 : : roundup_byte = 0;
249 : : iv_len = 0;
250 : 0 : break;
251 : : }
252 : :
253 : : switch (a_algo) {
254 : : case RTE_CRYPTO_AUTH_NULL:
255 : : mac_len = 0;
256 : : break;
257 : : case RTE_CRYPTO_AUTH_MD5_HMAC:
258 : : mac_len = 16;
259 : : break;
260 : : case RTE_CRYPTO_AUTH_SHA1_HMAC:
261 : : mac_len = 20;
262 : : break;
263 : : case RTE_CRYPTO_AUTH_SHA256_HMAC:
264 : : mac_len = 32;
265 : : break;
266 : : case RTE_CRYPTO_AUTH_SHA384_HMAC:
267 : : mac_len = 32;
268 : : break;
269 : : default:
270 : : mac_len = 0;
271 : : break;
272 : : }
273 : :
274 : 0 : return tls_hdr_len + iv_len + mac_len + roundup_byte;
275 : : }
276 : :
277 : : static void
278 : : tls_write_sa_init(struct roc_ie_ot_tls_write_sa *sa)
279 : : {
280 : : size_t offset;
281 : :
282 : : memset(sa, 0, sizeof(struct roc_ie_ot_tls_write_sa));
283 : :
284 : : offset = offsetof(struct roc_ie_ot_tls_write_sa, tls_12.w26_rsvd7);
285 : 0 : sa->w0.s.hw_ctx_off = offset / ROC_CTX_UNIT_8B;
286 : 0 : sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off;
287 : 0 : sa->w0.s.ctx_size = ROC_IE_OT_TLS_CTX_ILEN;
288 : 0 : sa->w0.s.ctx_hdr_size = ROC_IE_OT_TLS_CTX_HDR_SIZE;
289 : 0 : sa->w0.s.aop_valid = 1;
290 : : }
291 : :
292 : : static void
293 : : tls_read_sa_init(struct roc_ie_ot_tls_read_sa *sa)
294 : : {
295 : : size_t offset;
296 : :
297 : : memset(sa, 0, sizeof(struct roc_ie_ot_tls_read_sa));
298 : :
299 : : offset = offsetof(struct roc_ie_ot_tls_read_sa, tls_12.ctx);
300 : 0 : sa->w0.s.hw_ctx_off = offset / ROC_CTX_UNIT_8B;
301 : 0 : sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off;
302 : 0 : sa->w0.s.ctx_size = ROC_IE_OT_TLS_CTX_ILEN;
303 : 0 : sa->w0.s.ctx_hdr_size = ROC_IE_OT_TLS_CTX_HDR_SIZE;
304 : 0 : sa->w0.s.aop_valid = 1;
305 : : }
306 : :
307 : : static size_t
308 : : tls_read_ctx_size(struct roc_ie_ot_tls_read_sa *sa, enum rte_security_tls_version tls_ver)
309 : : {
310 : : size_t size;
311 : :
312 : : /* Variable based on Anti-replay Window */
313 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3) {
314 : : size = offsetof(struct roc_ie_ot_tls_read_sa, tls_13.ctx) +
315 : : sizeof(struct roc_ie_ot_tls_1_3_read_ctx_update_reg);
316 : : } else {
317 : : size = offsetof(struct roc_ie_ot_tls_read_sa, tls_12.ctx) +
318 : : offsetof(struct roc_ie_ot_tls_read_ctx_update_reg, ar_winbits);
319 : : }
320 : :
321 [ # # ]: 0 : if (sa->w0.s.ar_win)
322 : 0 : size += (1 << (sa->w0.s.ar_win - 1)) * sizeof(uint64_t);
323 : :
324 : : return size;
325 : : }
326 : :
327 : : static int
328 : 0 : tls_read_sa_fill(struct roc_ie_ot_tls_read_sa *read_sa,
329 : : struct rte_security_tls_record_xform *tls_xfrm,
330 : : struct rte_crypto_sym_xform *crypto_xfrm, struct cn10k_tls_opt *tls_opt,
331 : : uint8_t ctx_ilen)
332 : : {
333 [ # # ]: 0 : enum rte_security_tls_version tls_ver = tls_xfrm->ver;
334 : : struct rte_crypto_sym_xform *auth_xfrm, *cipher_xfrm;
335 : : const uint8_t *key = NULL;
336 : : uint64_t *tmp, *tmp_key;
337 : : uint32_t replay_win_sz;
338 : : uint8_t *cipher_key;
339 : : int i, length = 0;
340 : : size_t offset;
341 : :
342 : : /* Initialize the SA */
343 : : memset(read_sa, 0, sizeof(struct roc_ie_ot_tls_read_sa));
344 : :
345 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_2) {
346 : 0 : read_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_TLS_12;
347 : 0 : read_sa->tls_12.ctx.ar_valid_mask = tls_xfrm->tls_1_2.seq_no - 1;
348 [ # # ]: 0 : } else if (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2) {
349 : 0 : read_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_DTLS_12;
350 [ # # ]: 0 : } else if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3) {
351 : 0 : read_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_TLS_13;
352 : 0 : read_sa->tls_13.ctx.ar_valid_mask = tls_xfrm->tls_1_3.seq_no - 1;
353 : : }
354 : :
355 : 0 : cipher_key = read_sa->cipher_key;
356 : :
357 : : /* Set encryption algorithm */
358 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
359 : 0 : length = crypto_xfrm->aead.key.length;
360 [ # # ]: 0 : if (crypto_xfrm->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
361 : 0 : read_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_AES_GCM;
362 [ # # ]: 0 : if (length == 16)
363 : 0 : read_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_128;
364 : : else
365 : 0 : read_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
366 : : }
367 : :
368 [ # # ]: 0 : if (crypto_xfrm->aead.algo == RTE_CRYPTO_AEAD_CHACHA20_POLY1305) {
369 : 0 : read_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_CHACHA_POLY;
370 : 0 : read_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
371 : : }
372 : :
373 : 0 : key = crypto_xfrm->aead.key.data;
374 [ # # ]: 0 : memcpy(cipher_key, key, length);
375 : :
376 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_2)
377 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->tls_1_2.imp_nonce, 4);
378 [ # # ]: 0 : else if (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2)
379 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->dtls_1_2.imp_nonce, 4);
380 [ # # ]: 0 : else if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3)
381 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->tls_1_3.imp_nonce, 12);
382 : :
383 : 0 : goto key_swap;
384 : : }
385 : :
386 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
387 : : auth_xfrm = crypto_xfrm;
388 : 0 : cipher_xfrm = crypto_xfrm->next;
389 : : } else {
390 : : cipher_xfrm = crypto_xfrm;
391 : 0 : auth_xfrm = crypto_xfrm->next;
392 : : }
393 : :
394 [ # # ]: 0 : if (cipher_xfrm != NULL) {
395 [ # # ]: 0 : if (cipher_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC) {
396 : 0 : read_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_3DES;
397 : 0 : length = cipher_xfrm->cipher.key.length;
398 [ # # ]: 0 : } else if (cipher_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_AES_CBC) {
399 : 0 : read_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_AES_CBC;
400 : 0 : length = cipher_xfrm->cipher.key.length;
401 [ # # ]: 0 : if (length == 16)
402 : 0 : read_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_128;
403 [ # # ]: 0 : else if (length == 32)
404 : 0 : read_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
405 : : else
406 : : return -EINVAL;
407 : : } else {
408 : : return -EINVAL;
409 : : }
410 : :
411 : 0 : key = cipher_xfrm->cipher.key.data;
412 : 0 : memcpy(cipher_key, key, length);
413 : : }
414 : :
415 [ # # # # : 0 : switch (auth_xfrm->auth.algo) {
# ]
416 : 0 : case RTE_CRYPTO_AUTH_MD5_HMAC:
417 : 0 : read_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_MD5;
418 : 0 : tls_opt->mac_len = 0;
419 : 0 : break;
420 : 0 : case RTE_CRYPTO_AUTH_SHA1_HMAC:
421 : 0 : read_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA1;
422 : 0 : tls_opt->mac_len = 20;
423 : 0 : break;
424 : 0 : case RTE_CRYPTO_AUTH_SHA256_HMAC:
425 : 0 : read_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA2_256;
426 : 0 : tls_opt->mac_len = 32;
427 : 0 : break;
428 : 0 : case RTE_CRYPTO_AUTH_SHA384_HMAC:
429 : 0 : read_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA2_384;
430 : 0 : tls_opt->mac_len = 48;
431 : 0 : break;
432 : : default:
433 : : return -EINVAL;
434 : : }
435 : :
436 : 0 : roc_se_hmac_opad_ipad_gen(read_sa->w2.s.mac_select, auth_xfrm->auth.key.data,
437 : 0 : auth_xfrm->auth.key.length, read_sa->tls_12.opad_ipad,
438 : : ROC_SE_TLS);
439 : :
440 : : tmp = (uint64_t *)read_sa->tls_12.opad_ipad;
441 [ # # ]: 0 : for (i = 0; i < (int)(ROC_CTX_MAX_OPAD_IPAD_LEN / sizeof(uint64_t)); i++)
442 [ # # ]: 0 : tmp[i] = rte_be_to_cpu_64(tmp[i]);
443 : :
444 : 0 : key_swap:
445 : : tmp_key = (uint64_t *)cipher_key;
446 [ # # ]: 0 : for (i = 0; i < (int)(ROC_IE_OT_TLS_CTX_MAX_KEY_IV_LEN / sizeof(uint64_t)); i++)
447 [ # # ]: 0 : tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
448 : :
449 [ # # ]: 0 : if (tls_xfrm->ver == RTE_SECURITY_VERSION_DTLS_1_2) {
450 : : /* Only support power-of-two window sizes supported */
451 : 0 : replay_win_sz = tls_xfrm->dtls_1_2.ar_win_sz;
452 [ # # ]: 0 : if (replay_win_sz) {
453 [ # # ]: 0 : if (!rte_is_power_of_2(replay_win_sz) ||
454 : : replay_win_sz > ROC_IE_OT_TLS_AR_WIN_SIZE_MAX)
455 : : return -ENOTSUP;
456 : :
457 : 0 : read_sa->w0.s.ar_win = rte_log2_u32(replay_win_sz) - 5;
458 : : }
459 : : }
460 : :
461 : 0 : read_sa->w0.s.ctx_hdr_size = ROC_IE_OT_TLS_CTX_HDR_SIZE;
462 : 0 : read_sa->w0.s.aop_valid = 1;
463 : :
464 : : offset = offsetof(struct roc_ie_ot_tls_read_sa, tls_12.ctx);
465 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3)
466 : : offset = offsetof(struct roc_ie_ot_tls_read_sa, tls_13.ctx);
467 : :
468 : : /* Entire context size in 128B units */
469 : 0 : read_sa->w0.s.ctx_size =
470 : 0 : (PLT_ALIGN_CEIL(tls_read_ctx_size(read_sa, tls_ver), ROC_CTX_UNIT_128B) /
471 : 0 : ROC_CTX_UNIT_128B) -
472 : : 1;
473 : :
474 [ # # ]: 0 : if (read_sa->w0.s.ctx_size < ctx_ilen)
475 : 0 : read_sa->w0.s.ctx_size = ctx_ilen;
476 : :
477 : : /* Word offset for HW managed CTX field */
478 : 0 : read_sa->w0.s.hw_ctx_off = offset / 8;
479 : 0 : read_sa->w0.s.ctx_push_size = read_sa->w0.s.hw_ctx_off;
480 : :
481 : : rte_wmb();
482 : :
483 : 0 : return 0;
484 : : }
485 : :
486 : : static int
487 : 0 : tls_write_sa_fill(struct roc_ie_ot_tls_write_sa *write_sa,
488 : : struct rte_security_tls_record_xform *tls_xfrm,
489 : : struct rte_crypto_sym_xform *crypto_xfrm, uint8_t ctx_ilen)
490 : : {
491 : 0 : enum rte_security_tls_version tls_ver = tls_xfrm->ver;
492 : : struct rte_crypto_sym_xform *auth_xfrm, *cipher_xfrm;
493 : : const uint8_t *key = NULL;
494 : : uint8_t *cipher_key;
495 : : uint64_t *tmp_key;
496 : : int i, length = 0;
497 : : size_t offset;
498 : :
499 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_2) {
500 : 0 : write_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_TLS_12;
501 : 0 : write_sa->tls_12.seq_num = tls_xfrm->tls_1_2.seq_no - 1;
502 [ # # ]: 0 : } else if (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2) {
503 : 0 : write_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_DTLS_12;
504 : 0 : write_sa->tls_12.seq_num = ((uint64_t)tls_xfrm->dtls_1_2.epoch << 48) |
505 : 0 : (tls_xfrm->dtls_1_2.seq_no & 0x0000ffffffffffff);
506 : 0 : write_sa->tls_12.seq_num -= 1;
507 [ # # ]: 0 : } else if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3) {
508 : 0 : write_sa->w2.s.version_select = ROC_IE_OT_TLS_VERSION_TLS_13;
509 : 0 : write_sa->tls_13.seq_num = tls_xfrm->tls_1_3.seq_no - 1;
510 : : }
511 : :
512 : 0 : cipher_key = write_sa->cipher_key;
513 : :
514 : : /* Set encryption algorithm */
515 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
516 : 0 : length = crypto_xfrm->aead.key.length;
517 [ # # ]: 0 : if (crypto_xfrm->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
518 : 0 : write_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_AES_GCM;
519 [ # # ]: 0 : if (length == 16)
520 : 0 : write_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_128;
521 : : else
522 : 0 : write_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
523 : : }
524 [ # # ]: 0 : if (crypto_xfrm->aead.algo == RTE_CRYPTO_AEAD_CHACHA20_POLY1305) {
525 : 0 : write_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_CHACHA_POLY;
526 : 0 : write_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
527 : : }
528 : :
529 : 0 : key = crypto_xfrm->aead.key.data;
530 [ # # ]: 0 : memcpy(cipher_key, key, length);
531 : :
532 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_2)
533 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->tls_1_2.imp_nonce, 4);
534 [ # # ]: 0 : else if (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2)
535 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->dtls_1_2.imp_nonce, 4);
536 [ # # ]: 0 : else if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3)
537 : 0 : memcpy(((uint8_t *)cipher_key + 32), &tls_xfrm->tls_1_3.imp_nonce, 12);
538 : :
539 : 0 : goto key_swap;
540 : : }
541 : :
542 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
543 : : auth_xfrm = crypto_xfrm;
544 : 0 : cipher_xfrm = crypto_xfrm->next;
545 : : } else {
546 : : cipher_xfrm = crypto_xfrm;
547 : 0 : auth_xfrm = crypto_xfrm->next;
548 : : }
549 : :
550 [ # # ]: 0 : if (cipher_xfrm != NULL) {
551 [ # # ]: 0 : if (cipher_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC) {
552 : 0 : write_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_3DES;
553 : 0 : length = cipher_xfrm->cipher.key.length;
554 [ # # ]: 0 : } else if (cipher_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_AES_CBC) {
555 : 0 : write_sa->w2.s.cipher_select = ROC_IE_OT_TLS_CIPHER_AES_CBC;
556 : 0 : length = cipher_xfrm->cipher.key.length;
557 [ # # ]: 0 : if (length == 16)
558 : 0 : write_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_128;
559 [ # # ]: 0 : else if (length == 32)
560 : 0 : write_sa->w2.s.aes_key_len = ROC_IE_OT_TLS_AES_KEY_LEN_256;
561 : : else
562 : : return -EINVAL;
563 : : } else {
564 : : return -EINVAL;
565 : : }
566 : :
567 : 0 : key = cipher_xfrm->cipher.key.data;
568 [ # # ]: 0 : if (key != NULL && length != 0) {
569 : : /* Copy encryption key */
570 : 0 : memcpy(cipher_key, key, length);
571 : : }
572 : : }
573 : :
574 [ # # ]: 0 : if (auth_xfrm != NULL) {
575 [ # # ]: 0 : if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_MD5_HMAC)
576 : 0 : write_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_MD5;
577 [ # # ]: 0 : else if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA1_HMAC)
578 : 0 : write_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA1;
579 [ # # ]: 0 : else if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC)
580 : 0 : write_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA2_256;
581 [ # # ]: 0 : else if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA384_HMAC)
582 : 0 : write_sa->w2.s.mac_select = ROC_IE_OT_TLS_MAC_SHA2_384;
583 : : else
584 : : return -EINVAL;
585 : :
586 : 0 : roc_se_hmac_opad_ipad_gen(write_sa->w2.s.mac_select, auth_xfrm->auth.key.data,
587 : 0 : auth_xfrm->auth.key.length, write_sa->tls_12.opad_ipad,
588 : : ROC_SE_TLS);
589 : : }
590 : :
591 : 0 : tmp_key = (uint64_t *)write_sa->tls_12.opad_ipad;
592 [ # # ]: 0 : for (i = 0; i < (int)(ROC_CTX_MAX_OPAD_IPAD_LEN / sizeof(uint64_t)); i++)
593 [ # # ]: 0 : tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
594 : :
595 : 0 : key_swap:
596 : : tmp_key = (uint64_t *)cipher_key;
597 [ # # ]: 0 : for (i = 0; i < (int)(ROC_IE_OT_TLS_CTX_MAX_KEY_IV_LEN / sizeof(uint64_t)); i++)
598 [ # # ]: 0 : tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
599 : :
600 : 0 : write_sa->w0.s.ctx_hdr_size = ROC_IE_OT_TLS_CTX_HDR_SIZE;
601 : : /* Entire context size in 128B units */
602 : 0 : write_sa->w0.s.ctx_size =
603 : : (PLT_ALIGN_CEIL(sizeof(struct roc_ie_ot_tls_write_sa), ROC_CTX_UNIT_128B) /
604 : : ROC_CTX_UNIT_128B) -
605 : : 1;
606 : : offset = offsetof(struct roc_ie_ot_tls_write_sa, tls_12.w26_rsvd7);
607 : :
608 [ # # ]: 0 : if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3) {
609 : : offset = offsetof(struct roc_ie_ot_tls_write_sa, tls_13.w10_rsvd7);
610 : 0 : write_sa->w0.s.ctx_size -= 1;
611 : : }
612 : :
613 [ # # ]: 0 : if (write_sa->w0.s.ctx_size < ctx_ilen)
614 : 0 : write_sa->w0.s.ctx_size = ctx_ilen;
615 : :
616 : : /* Word offset for HW managed CTX field */
617 : 0 : write_sa->w0.s.hw_ctx_off = offset / 8;
618 : 0 : write_sa->w0.s.ctx_push_size = write_sa->w0.s.hw_ctx_off;
619 : :
620 : 0 : write_sa->w0.s.aop_valid = 1;
621 : :
622 : 0 : write_sa->w2.s.iv_at_cptr = ROC_IE_OT_TLS_IV_SRC_DEFAULT;
623 : :
624 [ # # ]: 0 : if (write_sa->w2.s.version_select != ROC_IE_OT_TLS_VERSION_TLS_13) {
625 : : #ifdef LA_IPSEC_DEBUG
626 : : if (tls_xfrm->options.iv_gen_disable == 1)
627 : : write_sa->w2.s.iv_at_cptr = ROC_IE_OT_TLS_IV_SRC_FROM_SA;
628 : : #else
629 [ # # ]: 0 : if (tls_xfrm->options.iv_gen_disable) {
630 : 0 : plt_err("Application provided IV is not supported");
631 : 0 : return -ENOTSUP;
632 : : }
633 : : #endif
634 : : }
635 : :
636 : : rte_wmb();
637 : :
638 : 0 : return 0;
639 : : }
640 : :
641 : : static int
642 : 0 : cn10k_tls_read_sa_create(struct roc_cpt *roc_cpt, struct roc_cpt_lf *lf,
643 : : struct rte_security_tls_record_xform *tls_xfrm,
644 : : struct rte_crypto_sym_xform *crypto_xfrm,
645 : : struct cn10k_sec_session *sec_sess)
646 : : {
647 : : struct roc_ie_ot_tls_read_sa *sa_dptr;
648 : 0 : uint8_t tls_ver = tls_xfrm->ver;
649 : : struct cn10k_tls_record *tls;
650 : : union cpt_inst_w4 inst_w4;
651 : : void *read_sa;
652 : : int ret = 0;
653 : :
654 : : tls = &sec_sess->tls_rec;
655 : 0 : read_sa = &tls->read_sa;
656 : :
657 : : /* Allocate memory to be used as dptr for CPT ucode WRITE_SA op */
658 : 0 : sa_dptr = plt_zmalloc(sizeof(struct roc_ie_ot_tls_read_sa), 8);
659 [ # # ]: 0 : if (sa_dptr == NULL) {
660 : 0 : plt_err("Could not allocate memory for SA DPTR");
661 : 0 : return -ENOMEM;
662 : : }
663 : :
664 : : /* Translate security parameters to SA */
665 : 0 : ret = tls_read_sa_fill(sa_dptr, tls_xfrm, crypto_xfrm, &sec_sess->tls_opt,
666 : 0 : roc_cpt->ctx_ilen);
667 [ # # ]: 0 : if (ret) {
668 : 0 : plt_err("Could not fill read session parameters");
669 : 0 : goto sa_dptr_free;
670 : : }
671 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
672 : 0 : sec_sess->iv_offset = crypto_xfrm->aead.iv.offset;
673 : 0 : sec_sess->iv_length = crypto_xfrm->aead.iv.length;
674 [ # # ]: 0 : } else if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
675 : 0 : sec_sess->iv_offset = crypto_xfrm->cipher.iv.offset;
676 : 0 : sec_sess->iv_length = crypto_xfrm->cipher.iv.length;
677 : : } else {
678 : 0 : sec_sess->iv_offset = crypto_xfrm->auth.iv.offset;
679 : 0 : sec_sess->iv_length = crypto_xfrm->auth.iv.length;
680 : : }
681 : :
682 : 0 : sec_sess->proto = RTE_SECURITY_PROTOCOL_TLS_RECORD;
683 : :
684 : : /* pre-populate CPT INST word 4 */
685 : 0 : inst_w4.u64 = 0;
686 : 0 : if ((tls_ver == RTE_SECURITY_VERSION_TLS_1_2) ||
687 [ # # ]: 0 : (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2)) {
688 : 0 : inst_w4.s.opcode_major = ROC_IE_OT_TLS_MAJOR_OP_RECORD_DEC | ROC_IE_OT_INPLACE_BIT;
689 : 0 : sec_sess->tls_opt.tail_fetch_len = 0;
690 [ # # ]: 0 : if (sa_dptr->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_3DES)
691 : 0 : sec_sess->tls_opt.tail_fetch_len = 1;
692 [ # # ]: 0 : else if (sa_dptr->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_AES_CBC)
693 : 0 : sec_sess->tls_opt.tail_fetch_len = 2;
694 [ # # ]: 0 : } else if (tls_xfrm->ver == RTE_SECURITY_VERSION_TLS_1_3) {
695 : 0 : inst_w4.s.opcode_major =
696 : : ROC_IE_OT_TLS13_MAJOR_OP_RECORD_DEC | ROC_IE_OT_INPLACE_BIT;
697 : : }
698 : :
699 : 0 : sec_sess->tls_opt.tls_ver = tls_ver;
700 [ # # ]: 0 : sec_sess->inst.w4 = inst_w4.u64;
701 : 0 : sec_sess->inst.w7 = cnxk_cpt_sec_inst_w7_get(roc_cpt, read_sa);
702 : :
703 : : memset(read_sa, 0, sizeof(struct roc_ie_ot_tls_read_sa));
704 : :
705 : : /* Copy word0 from sa_dptr to populate ctx_push_sz ctx_size fields */
706 : : memcpy(read_sa, sa_dptr, 8);
707 : :
708 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
709 : :
710 : : /* Write session using microcode opcode */
711 : 0 : ret = roc_cpt_ctx_write(lf, sa_dptr, read_sa, sizeof(struct roc_ie_ot_tls_read_sa));
712 [ # # ]: 0 : if (ret) {
713 : 0 : plt_err("Could not write read session to hardware");
714 : 0 : goto sa_dptr_free;
715 : : }
716 : :
717 : : /* Trigger CTX flush so that data is written back to DRAM */
718 : 0 : ret = roc_cpt_lf_ctx_flush(lf, read_sa, true);
719 [ # # ]: 0 : if (ret == -EFAULT) {
720 : 0 : plt_err("Could not flush TLS read session to hardware");
721 : 0 : goto sa_dptr_free;
722 : : }
723 : :
724 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
725 : :
726 : 0 : sa_dptr_free:
727 : 0 : plt_free(sa_dptr);
728 : :
729 : 0 : return ret;
730 : : }
731 : :
732 : : static int
733 : 0 : cn10k_tls_write_sa_create(struct roc_cpt *roc_cpt, struct roc_cpt_lf *lf,
734 : : struct rte_security_tls_record_xform *tls_xfrm,
735 : : struct rte_crypto_sym_xform *crypto_xfrm,
736 : : struct cn10k_sec_session *sec_sess)
737 : : {
738 : : struct roc_ie_ot_tls_write_sa *sa_dptr;
739 : 0 : uint8_t tls_ver = tls_xfrm->ver;
740 : : struct cn10k_tls_record *tls;
741 : : union cpt_inst_w4 inst_w4;
742 : : void *write_sa;
743 : : int ret = 0;
744 : :
745 : : tls = &sec_sess->tls_rec;
746 : 0 : write_sa = &tls->write_sa;
747 : :
748 : : /* Allocate memory to be used as dptr for CPT ucode WRITE_SA op */
749 : 0 : sa_dptr = plt_zmalloc(sizeof(struct roc_ie_ot_tls_write_sa), 8);
750 [ # # ]: 0 : if (sa_dptr == NULL) {
751 : 0 : plt_err("Could not allocate memory for SA DPTR");
752 : 0 : return -ENOMEM;
753 : : }
754 : :
755 : : /* Translate security parameters to SA */
756 : 0 : ret = tls_write_sa_fill(sa_dptr, tls_xfrm, crypto_xfrm, roc_cpt->ctx_ilen);
757 [ # # ]: 0 : if (ret) {
758 : 0 : plt_err("Could not fill write session parameters");
759 : 0 : goto sa_dptr_free;
760 : : }
761 : :
762 [ # # ]: 0 : if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
763 : 0 : sec_sess->iv_offset = crypto_xfrm->aead.iv.offset;
764 : 0 : sec_sess->iv_length = crypto_xfrm->aead.iv.length;
765 [ # # ]: 0 : } else if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
766 : 0 : sec_sess->iv_offset = crypto_xfrm->cipher.iv.offset;
767 : 0 : sec_sess->iv_length = crypto_xfrm->cipher.iv.length;
768 : : } else {
769 : 0 : sec_sess->iv_offset = crypto_xfrm->next->cipher.iv.offset;
770 : 0 : sec_sess->iv_length = crypto_xfrm->next->cipher.iv.length;
771 : : }
772 : :
773 : 0 : sec_sess->tls_opt.is_write = 1;
774 : 0 : sec_sess->tls_opt.pad_shift = 0;
775 : 0 : sec_sess->tls_opt.tls_ver = tls_ver;
776 : 0 : sec_sess->tls_opt.enable_padding = tls_xfrm->options.extra_padding_enable;
777 : 0 : sec_sess->max_extended_len = tls_write_rlens_get(tls_xfrm, crypto_xfrm);
778 : 0 : sec_sess->proto = RTE_SECURITY_PROTOCOL_TLS_RECORD;
779 : :
780 : : /* pre-populate CPT INST word 4 */
781 : 0 : inst_w4.u64 = 0;
782 : 0 : if ((tls_ver == RTE_SECURITY_VERSION_TLS_1_2) ||
783 [ # # ]: 0 : (tls_ver == RTE_SECURITY_VERSION_DTLS_1_2)) {
784 : 0 : inst_w4.s.opcode_major = ROC_IE_OT_TLS_MAJOR_OP_RECORD_ENC | ROC_IE_OT_INPLACE_BIT;
785 [ # # ]: 0 : if (sa_dptr->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_3DES)
786 : 0 : sec_sess->tls_opt.pad_shift = 3;
787 : : else
788 : 0 : sec_sess->tls_opt.pad_shift = 4;
789 [ # # ]: 0 : } else if (tls_ver == RTE_SECURITY_VERSION_TLS_1_3) {
790 : 0 : inst_w4.s.opcode_major =
791 : : ROC_IE_OT_TLS13_MAJOR_OP_RECORD_ENC | ROC_IE_OT_INPLACE_BIT;
792 : : }
793 [ # # ]: 0 : sec_sess->inst.w4 = inst_w4.u64;
794 : 0 : sec_sess->inst.w7 = cnxk_cpt_sec_inst_w7_get(roc_cpt, write_sa);
795 : :
796 : : memset(write_sa, 0, sizeof(struct roc_ie_ot_tls_write_sa));
797 : :
798 : : /* Copy word0 from sa_dptr to populate ctx_push_sz ctx_size fields */
799 : : memcpy(write_sa, sa_dptr, 8);
800 : :
801 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
802 : :
803 : : /* Write session using microcode opcode */
804 : 0 : ret = roc_cpt_ctx_write(lf, sa_dptr, write_sa, sizeof(struct roc_ie_ot_tls_write_sa));
805 [ # # ]: 0 : if (ret) {
806 : 0 : plt_err("Could not write tls write session to hardware");
807 : 0 : goto sa_dptr_free;
808 : : }
809 : :
810 : : /* Trigger CTX flush so that data is written back to DRAM */
811 : 0 : ret = roc_cpt_lf_ctx_flush(lf, write_sa, false);
812 [ # # ]: 0 : if (ret == -EFAULT) {
813 : 0 : plt_err("Could not flush TLS write session to hardware");
814 : 0 : goto sa_dptr_free;
815 : : }
816 : :
817 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
818 : :
819 : 0 : sa_dptr_free:
820 : 0 : plt_free(sa_dptr);
821 : :
822 : 0 : return ret;
823 : : }
824 : :
825 : : int
826 : 0 : cn10k_tls_record_session_update(struct cnxk_cpt_vf *vf, struct cnxk_cpt_qp *qp,
827 : : struct cn10k_sec_session *sess,
828 : : struct rte_security_session_conf *conf)
829 : : {
830 : : struct roc_cpt *roc_cpt;
831 : : int ret;
832 : :
833 [ # # ]: 0 : if (conf->tls_record.type == RTE_SECURITY_TLS_SESS_TYPE_READ)
834 : : return -ENOTSUP;
835 : :
836 : 0 : roc_cpt = &vf->cpt;
837 : 0 : ret = cn10k_tls_write_sa_create(roc_cpt, &qp->lf, &conf->tls_record, conf->crypto_xform,
838 : : (struct cn10k_sec_session *)sess);
839 : 0 : return ret;
840 : : }
841 : :
842 : : int
843 : 0 : cn10k_tls_record_session_create(struct cnxk_cpt_vf *vf, struct cnxk_cpt_qp *qp,
844 : : struct rte_security_tls_record_xform *tls_xfrm,
845 : : struct rte_crypto_sym_xform *crypto_xfrm,
846 : : struct rte_security_session *sess)
847 : : {
848 : : struct roc_cpt *roc_cpt;
849 : : int ret;
850 : :
851 : 0 : ret = cnxk_tls_xform_verify(tls_xfrm, crypto_xfrm);
852 [ # # ]: 0 : if (ret)
853 : : return ret;
854 : :
855 : 0 : roc_cpt = &vf->cpt;
856 : :
857 [ # # ]: 0 : if (tls_xfrm->type == RTE_SECURITY_TLS_SESS_TYPE_READ)
858 : 0 : return cn10k_tls_read_sa_create(roc_cpt, &qp->lf, tls_xfrm, crypto_xfrm,
859 : : (struct cn10k_sec_session *)sess);
860 : : else
861 : 0 : return cn10k_tls_write_sa_create(roc_cpt, &qp->lf, tls_xfrm, crypto_xfrm,
862 : : (struct cn10k_sec_session *)sess);
863 : : }
864 : :
865 : : int
866 : 0 : cn10k_sec_tls_session_destroy(struct cnxk_cpt_qp *qp, struct cn10k_sec_session *sess)
867 : : {
868 : : struct cn10k_tls_record *tls;
869 : : struct roc_cpt_lf *lf;
870 : : void *sa_dptr = NULL;
871 : : int ret;
872 : :
873 : 0 : lf = &qp->lf;
874 : :
875 : : tls = &sess->tls_rec;
876 : :
877 : : /* Trigger CTX flush to write dirty data back to DRAM */
878 : 0 : roc_cpt_lf_ctx_flush(lf, &tls->read_sa, false);
879 : :
880 : : ret = -1;
881 : :
882 [ # # ]: 0 : if (sess->tls_opt.is_write) {
883 : 0 : sa_dptr = plt_zmalloc(sizeof(struct roc_ie_ot_tls_write_sa), 8);
884 [ # # ]: 0 : if (sa_dptr != NULL) {
885 : : tls_write_sa_init(sa_dptr);
886 : :
887 : 0 : ret = roc_cpt_ctx_write(lf, sa_dptr, &tls->write_sa,
888 : : sizeof(struct roc_ie_ot_tls_write_sa));
889 : : }
890 : : } else {
891 : 0 : sa_dptr = plt_zmalloc(sizeof(struct roc_ie_ot_tls_read_sa), 8);
892 [ # # ]: 0 : if (sa_dptr != NULL) {
893 : : tls_read_sa_init(sa_dptr);
894 : :
895 : 0 : ret = roc_cpt_ctx_write(lf, sa_dptr, &tls->read_sa,
896 : : sizeof(struct roc_ie_ot_tls_read_sa));
897 : : }
898 : : }
899 : :
900 : 0 : plt_free(sa_dptr);
901 : :
902 [ # # ]: 0 : if (ret) {
903 : : /* MC write_ctx failed. Attempt reload of CTX */
904 : :
905 : : /* Wait for 1 ms so that flush is complete */
906 : : rte_delay_ms(1);
907 : :
908 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
909 : :
910 : : /* Trigger CTX reload to fetch new data from DRAM */
911 : 0 : roc_cpt_lf_ctx_reload(lf, &tls->read_sa);
912 : : }
913 : :
914 : 0 : return 0;
915 : : }
|