Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_cryptodev.h>
6 : : #include <rte_ether.h>
7 : : #include <rte_ip.h>
8 : :
9 : : #include "cperf_ops.h"
10 : : #include "cperf_test_vectors.h"
11 : :
12 : : static void
13 : 0 : cperf_set_ops_asym_modex(struct rte_crypto_op **ops,
14 : : uint32_t src_buf_offset __rte_unused,
15 : : uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
16 : : void *sess,
17 : : const struct cperf_options *options,
18 : : const struct cperf_test_vector *test_vector __rte_unused,
19 : : uint16_t iv_offset __rte_unused,
20 : : uint32_t *imix_idx __rte_unused,
21 : : uint64_t *tsc_start __rte_unused)
22 : : {
23 : : uint16_t i;
24 : :
25 : 0 : for (i = 0; i < nb_ops; i++) {
26 : 0 : struct rte_crypto_asym_op *asym_op = ops[i]->asym;
27 : :
28 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
29 : 0 : asym_op->modex.base.data = options->modex_data->base.data;
30 : 0 : asym_op->modex.base.length = options->modex_data->base.len;
31 : 0 : asym_op->modex.result.data = options->modex_data->result.data;
32 : 0 : asym_op->modex.result.length = options->modex_data->result.len;
33 : : rte_crypto_op_attach_asym_session(ops[i], sess);
34 : : }
35 : 0 : }
36 : :
37 : : static void
38 : 0 : cperf_set_ops_asym_rsa(struct rte_crypto_op **ops,
39 : : uint32_t src_buf_offset __rte_unused,
40 : : uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
41 : : void *sess,
42 : : const struct cperf_options *options,
43 : : const struct cperf_test_vector *test_vector __rte_unused,
44 : : uint16_t iv_offset __rte_unused,
45 : : uint32_t *imix_idx __rte_unused,
46 : : uint64_t *tsc_start __rte_unused)
47 : : {
48 : 0 : uint8_t crypto_buf[CRYPTO_BUF_SIZE] = {0};
49 : : uint16_t i;
50 : :
51 : 0 : for (i = 0; i < nb_ops; i++) {
52 : 0 : struct rte_crypto_asym_op *asym_op = ops[i]->asym;
53 : :
54 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
55 : 0 : asym_op->rsa.op_type = options->asym_op_type;
56 : 0 : if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
57 : 0 : asym_op->rsa.message.data = rsa_plaintext.data;
58 : 0 : asym_op->rsa.message.length = rsa_plaintext.len;
59 : 0 : asym_op->rsa.sign.data = crypto_buf;
60 : 0 : asym_op->rsa.sign.length = options->rsa_data->n.length;
61 : 0 : } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
62 : 0 : asym_op->rsa.message.data = rsa_plaintext.data;
63 : 0 : asym_op->rsa.message.length = rsa_plaintext.len;
64 : 0 : asym_op->rsa.cipher.data = crypto_buf;
65 : 0 : asym_op->rsa.cipher.length = options->rsa_data->n.length;
66 : 0 : } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
67 : 0 : asym_op->rsa.cipher.data = options->rsa_data->cipher.data;
68 : 0 : asym_op->rsa.cipher.length = options->rsa_data->cipher.length;
69 : 0 : asym_op->rsa.message.data = crypto_buf;
70 : 0 : asym_op->rsa.message.length = options->rsa_data->n.length;
71 : 0 : } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
72 : 0 : asym_op->rsa.sign.data = options->rsa_data->sign.data;
73 : 0 : asym_op->rsa.sign.length = options->rsa_data->sign.length;
74 : 0 : asym_op->rsa.message.data = rsa_plaintext.data;
75 : 0 : asym_op->rsa.message.length = rsa_plaintext.len;
76 : : } else {
77 : 0 : rte_panic("Unsupported RSA operation type %d\n",
78 : : options->asym_op_type);
79 : : }
80 : : rte_crypto_op_attach_asym_session(ops[i], sess);
81 : : }
82 : 0 : }
83 : :
84 : : static void
85 : 0 : cperf_set_ops_asym_ecdsa(struct rte_crypto_op **ops,
86 : : uint32_t src_buf_offset __rte_unused,
87 : : uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
88 : : void *sess,
89 : : const struct cperf_options *options,
90 : : const struct cperf_test_vector *test_vector __rte_unused,
91 : : uint16_t iv_offset __rte_unused,
92 : : uint32_t *imix_idx __rte_unused,
93 : : uint64_t *tsc_start __rte_unused)
94 : : {
95 : : uint16_t i;
96 : :
97 : 0 : for (i = 0; i < nb_ops; i++) {
98 : : const struct cperf_ecdsa_test_data *ecdsa_curve_data = NULL;
99 : 0 : struct rte_crypto_asym_op *asym_op = ops[i]->asym;
100 : :
101 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
102 : : rte_crypto_op_attach_asym_session(ops[i], sess);
103 : :
104 : 0 : asym_op->ecdsa.op_type = options->asym_op_type;
105 : :
106 : 0 : switch (options->op_type) {
107 : 0 : case CPERF_ASYM_SECP192R1:
108 : 0 : ecdsa_curve_data = options->secp192r1_data;
109 : 0 : break;
110 : 0 : case CPERF_ASYM_SECP224R1:
111 : 0 : ecdsa_curve_data = options->secp224r1_data;
112 : 0 : break;
113 : 0 : case CPERF_ASYM_SECP256R1:
114 : 0 : ecdsa_curve_data = options->secp256r1_data;
115 : 0 : break;
116 : 0 : case CPERF_ASYM_SECP384R1:
117 : 0 : ecdsa_curve_data = options->secp384r1_data;
118 : 0 : break;
119 : 0 : case CPERF_ASYM_SECP521R1:
120 : 0 : ecdsa_curve_data = options->secp521r1_data;
121 : 0 : break;
122 : 0 : default:
123 : 0 : rte_panic("Unsupported ECDSA operation type %d\n",
124 : : options->op_type);
125 : : break;
126 : : }
127 : :
128 : 0 : asym_op->ecdsa.message.data = ecdsa_curve_data->message.data;
129 : 0 : asym_op->ecdsa.message.length = ecdsa_curve_data->message.length;
130 : :
131 : 0 : asym_op->ecdsa.k.data = ecdsa_curve_data->k.data;
132 : 0 : asym_op->ecdsa.k.length = ecdsa_curve_data->k.length;
133 : :
134 : 0 : asym_op->ecdsa.r.data = ecdsa_curve_data->sign_r.data;
135 : 0 : asym_op->ecdsa.r.length = ecdsa_curve_data->sign_r.length;
136 : 0 : asym_op->ecdsa.s.data = ecdsa_curve_data->sign_s.data;
137 : 0 : asym_op->ecdsa.s.length = ecdsa_curve_data->sign_s.length;
138 : : }
139 : 0 : }
140 : :
141 : : static void
142 : 0 : cperf_set_ops_asym_eddsa(struct rte_crypto_op **ops,
143 : : uint32_t src_buf_offset __rte_unused,
144 : : uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
145 : : void *sess,
146 : : const struct cperf_options *options,
147 : : const struct cperf_test_vector *test_vector __rte_unused,
148 : : uint16_t iv_offset __rte_unused,
149 : : uint32_t *imix_idx __rte_unused,
150 : : uint64_t *tsc_start __rte_unused)
151 : : {
152 : : uint16_t i;
153 : :
154 : 0 : for (i = 0; i < nb_ops; i++) {
155 : 0 : struct rte_crypto_asym_op *asym_op = ops[i]->asym;
156 : :
157 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
158 : : rte_crypto_op_attach_asym_session(ops[i], sess);
159 : :
160 : 0 : asym_op->eddsa.op_type = options->asym_op_type;
161 : 0 : asym_op->eddsa.message.data = options->eddsa_data->message.data;
162 : 0 : asym_op->eddsa.message.length = options->eddsa_data->message.length;
163 : :
164 : 0 : asym_op->eddsa.instance = options->eddsa_data->instance;
165 : :
166 : 0 : asym_op->eddsa.sign.data = options->eddsa_data->sign.data;
167 : 0 : asym_op->eddsa.sign.length = options->eddsa_data->sign.length;
168 : : }
169 : 0 : }
170 : :
171 : : static void
172 : 0 : cperf_set_ops_asym_sm2(struct rte_crypto_op **ops,
173 : : uint32_t src_buf_offset __rte_unused,
174 : : uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
175 : : void *sess,
176 : : const struct cperf_options *options,
177 : : const struct cperf_test_vector *test_vector __rte_unused,
178 : : uint16_t iv_offset __rte_unused,
179 : : uint32_t *imix_idx __rte_unused,
180 : : uint64_t *tsc_start __rte_unused)
181 : : {
182 : : uint16_t i;
183 : :
184 : 0 : for (i = 0; i < nb_ops; i++) {
185 : 0 : struct rte_crypto_asym_op *asym_op = ops[i]->asym;
186 : :
187 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
188 : : rte_crypto_op_attach_asym_session(ops[i], sess);
189 : :
190 : : /* Populate op with operational details */
191 : 0 : asym_op->sm2.hash = options->asym_hash_alg;
192 : :
193 : 0 : asym_op->sm2.op_type = options->asym_op_type;
194 : 0 : asym_op->sm2.message.data = options->sm2_data->message.data;
195 : 0 : asym_op->sm2.message.length = options->sm2_data->message.length;
196 : 0 : asym_op->sm2.cipher.data = options->sm2_data->cipher.data;
197 : 0 : asym_op->sm2.cipher.length = options->sm2_data->cipher.length;
198 : 0 : asym_op->sm2.id.data = options->sm2_data->id.data;
199 : 0 : asym_op->sm2.id.length = options->sm2_data->id.length;
200 : :
201 : 0 : asym_op->sm2.k.data = options->sm2_data->k.data;
202 : 0 : asym_op->sm2.k.length = options->sm2_data->k.length;
203 : :
204 : 0 : asym_op->sm2.r.data = options->sm2_data->sign_r.data;
205 : 0 : asym_op->sm2.r.length = options->sm2_data->sign_r.length;
206 : 0 : asym_op->sm2.s.data = options->sm2_data->sign_s.data;
207 : 0 : asym_op->sm2.s.length = options->sm2_data->sign_s.length;
208 : : }
209 : 0 : }
210 : :
211 : :
212 : : #ifdef RTE_LIB_SECURITY
213 : : static void
214 : 0 : test_ipsec_vec_populate(struct rte_mbuf *m, const struct cperf_options *options,
215 : : const struct cperf_test_vector *test_vector)
216 : : {
217 : 0 : struct rte_ipv4_hdr *ip = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *);
218 : :
219 : 0 : if (options->is_outbound) {
220 : 0 : memcpy(ip, test_vector->plaintext.data, sizeof(struct rte_ipv4_hdr));
221 : 0 : ip->total_length = rte_cpu_to_be_16(m->pkt_len);
222 : : }
223 : 0 : }
224 : :
225 : : static void
226 : 0 : cperf_set_ops_security(struct rte_crypto_op **ops,
227 : : uint32_t src_buf_offset __rte_unused,
228 : : uint32_t dst_buf_offset __rte_unused,
229 : : uint16_t nb_ops, void *sess,
230 : : const struct cperf_options *options,
231 : : const struct cperf_test_vector *test_vector,
232 : : uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
233 : : uint64_t *tsc_start)
234 : : {
235 : : uint16_t i;
236 : :
237 : 0 : for (i = 0; i < nb_ops; i++) {
238 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
239 : : uint32_t buf_sz;
240 : :
241 : 0 : uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ops[i],
242 : : uint32_t *, iv_offset);
243 : 0 : *per_pkt_hfn = options->pdcp_ses_hfn_en ? 0 : PDCP_DEFAULT_HFN;
244 : :
245 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
246 : : rte_security_attach_session(ops[i], sess);
247 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
248 : : src_buf_offset);
249 : :
250 : 0 : if (options->op_type == CPERF_PDCP) {
251 : 0 : sym_op->m_src->buf_len = options->segment_sz;
252 : 0 : sym_op->m_src->data_len = options->test_buffer_size;
253 : 0 : sym_op->m_src->pkt_len = sym_op->m_src->data_len;
254 : : }
255 : :
256 : 0 : if (options->op_type == CPERF_DOCSIS) {
257 : 0 : if (options->imix_distribution_count) {
258 : 0 : buf_sz = options->imix_buffer_sizes[*imix_idx];
259 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
260 : : } else
261 : 0 : buf_sz = options->test_buffer_size;
262 : :
263 : 0 : sym_op->m_src->buf_len = options->segment_sz;
264 : 0 : sym_op->m_src->data_len = buf_sz;
265 : 0 : sym_op->m_src->pkt_len = buf_sz;
266 : :
267 : : /* DOCSIS header is not CRC'ed */
268 : 0 : sym_op->auth.data.offset = options->docsis_hdr_sz;
269 : 0 : sym_op->auth.data.length = buf_sz -
270 : 0 : sym_op->auth.data.offset - RTE_ETHER_CRC_LEN;
271 : : /*
272 : : * DOCSIS header and SRC and DST MAC addresses are not
273 : : * ciphered
274 : : */
275 : 0 : sym_op->cipher.data.offset = sym_op->auth.data.offset +
276 : 0 : RTE_ETHER_HDR_LEN - RTE_ETHER_TYPE_LEN;
277 : 0 : sym_op->cipher.data.length = buf_sz -
278 : : sym_op->cipher.data.offset;
279 : : }
280 : :
281 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
282 : 0 : if (dst_buf_offset == 0)
283 : 0 : sym_op->m_dst = NULL;
284 : : else
285 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
286 : : dst_buf_offset);
287 : : }
288 : :
289 : : RTE_SET_USED(tsc_start);
290 : : RTE_SET_USED(test_vector);
291 : 0 : }
292 : :
293 : : static void
294 : 0 : cperf_set_ops_security_ipsec(struct rte_crypto_op **ops,
295 : : uint32_t src_buf_offset __rte_unused,
296 : : uint32_t dst_buf_offset __rte_unused,
297 : : uint16_t nb_ops, void *sess,
298 : : const struct cperf_options *options,
299 : : const struct cperf_test_vector *test_vector,
300 : : uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
301 : : uint64_t *tsc_start)
302 : : {
303 : 0 : const uint32_t test_buffer_size = options->test_buffer_size;
304 : : uint64_t tsc_start_temp, tsc_end_temp;
305 : : uint16_t i = 0;
306 : :
307 : : RTE_SET_USED(imix_idx);
308 : :
309 : 0 : for (i = 0; i < nb_ops; i++) {
310 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
311 : 0 : struct rte_mbuf *m = sym_op->m_src;
312 : : uint32_t offset = test_buffer_size;
313 : :
314 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
315 : : rte_security_attach_session(ops[i], sess);
316 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset);
317 : 0 : sym_op->m_src->pkt_len = test_buffer_size;
318 : :
319 : 0 : while ((m->next != NULL) && (offset >= m->data_len)) {
320 : 0 : offset -= m->data_len;
321 : : m = m->next;
322 : : }
323 : 0 : m->data_len = offset;
324 : : /*
325 : : * If there is not enough room in segment,
326 : : * place the digest in the next segment
327 : : */
328 : 0 : if (rte_pktmbuf_tailroom(m) < options->digest_sz) {
329 : : m = m->next;
330 : : offset = 0;
331 : : }
332 : 0 : m->next = NULL;
333 : :
334 : 0 : sym_op->m_dst = NULL;
335 : : }
336 : :
337 : 0 : if (options->test_file != NULL)
338 : : return;
339 : :
340 : : tsc_start_temp = rte_rdtsc_precise();
341 : :
342 : 0 : for (i = 0; i < nb_ops; i++) {
343 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
344 : 0 : struct rte_mbuf *m = sym_op->m_src;
345 : :
346 : 0 : test_ipsec_vec_populate(m, options, test_vector);
347 : : }
348 : :
349 : : tsc_end_temp = rte_rdtsc_precise();
350 : 0 : *tsc_start += tsc_end_temp - tsc_start_temp;
351 : : }
352 : :
353 : : static void
354 : 0 : cperf_set_ops_security_tls(struct rte_crypto_op **ops,
355 : : uint32_t src_buf_offset __rte_unused,
356 : : uint32_t dst_buf_offset __rte_unused,
357 : : uint16_t nb_ops, void *sess,
358 : : const struct cperf_options *options,
359 : : const struct cperf_test_vector *test_vector,
360 : : uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
361 : : uint64_t *tsc_start)
362 : : {
363 : 0 : const uint32_t test_buffer_size = options->test_buffer_size;
364 : : uint16_t i = 0;
365 : :
366 : : RTE_SET_USED(imix_idx);
367 : : RTE_SET_USED(tsc_start);
368 : : RTE_SET_USED(test_vector);
369 : :
370 : 0 : for (i = 0; i < nb_ops; i++) {
371 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
372 : 0 : struct rte_mbuf *m = sym_op->m_src;
373 : : uint32_t offset = test_buffer_size;
374 : :
375 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
376 : 0 : ops[i]->param1.tls_record.content_type = 0x17;
377 : : rte_security_attach_session(ops[i], sess);
378 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset);
379 : 0 : sym_op->m_src->pkt_len = test_buffer_size;
380 : :
381 : 0 : while ((m->next != NULL) && (offset >= m->data_len)) {
382 : 0 : offset -= m->data_len;
383 : : m = m->next;
384 : : }
385 : 0 : m->data_len = offset;
386 : : /*
387 : : * If there is not enough room in segment,
388 : : * place the digest in the next segment
389 : : */
390 : 0 : if ((rte_pktmbuf_tailroom(m)) < options->digest_sz) {
391 : : m = m->next;
392 : 0 : m->data_len = 0;
393 : : }
394 : 0 : m->next = NULL;
395 : :
396 : 0 : sym_op->m_dst = NULL;
397 : : }
398 : 0 : }
399 : : #endif
400 : :
401 : : static void
402 : 0 : cperf_set_ops_null_cipher(struct rte_crypto_op **ops,
403 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
404 : : uint16_t nb_ops, void *sess,
405 : : const struct cperf_options *options,
406 : : const struct cperf_test_vector *test_vector __rte_unused,
407 : : uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
408 : : uint64_t *tsc_start __rte_unused)
409 : : {
410 : : uint16_t i;
411 : :
412 : 0 : for (i = 0; i < nb_ops; i++) {
413 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
414 : :
415 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
416 : : rte_crypto_op_attach_sym_session(ops[i], sess);
417 : :
418 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
419 : : src_buf_offset);
420 : :
421 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
422 : 0 : if (dst_buf_offset == 0)
423 : 0 : sym_op->m_dst = NULL;
424 : : else
425 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
426 : : dst_buf_offset);
427 : :
428 : : /* cipher parameters */
429 : 0 : if (options->imix_distribution_count) {
430 : 0 : sym_op->cipher.data.length =
431 : 0 : options->imix_buffer_sizes[*imix_idx];
432 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
433 : : } else
434 : 0 : sym_op->cipher.data.length = options->test_buffer_size;
435 : 0 : sym_op->cipher.data.offset = 0;
436 : : }
437 : 0 : }
438 : :
439 : : static void
440 : 0 : cperf_set_ops_null_auth(struct rte_crypto_op **ops,
441 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
442 : : uint16_t nb_ops, void *sess,
443 : : const struct cperf_options *options,
444 : : const struct cperf_test_vector *test_vector __rte_unused,
445 : : uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
446 : : uint64_t *tsc_start __rte_unused)
447 : : {
448 : : uint16_t i;
449 : :
450 : 0 : for (i = 0; i < nb_ops; i++) {
451 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
452 : :
453 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
454 : : rte_crypto_op_attach_sym_session(ops[i], sess);
455 : :
456 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
457 : : src_buf_offset);
458 : :
459 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
460 : 0 : if (dst_buf_offset == 0)
461 : 0 : sym_op->m_dst = NULL;
462 : : else
463 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
464 : : dst_buf_offset);
465 : :
466 : : /* auth parameters */
467 : 0 : if (options->imix_distribution_count) {
468 : 0 : sym_op->auth.data.length =
469 : 0 : options->imix_buffer_sizes[*imix_idx];
470 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
471 : : } else
472 : 0 : sym_op->auth.data.length = options->test_buffer_size;
473 : 0 : sym_op->auth.data.offset = 0;
474 : : }
475 : 0 : }
476 : :
477 : : static void
478 : 0 : cperf_set_ops_cipher(struct rte_crypto_op **ops,
479 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
480 : : uint16_t nb_ops, void *sess,
481 : : const struct cperf_options *options,
482 : : const struct cperf_test_vector *test_vector,
483 : : uint16_t iv_offset, uint32_t *imix_idx,
484 : : uint64_t *tsc_start __rte_unused)
485 : : {
486 : : uint16_t i;
487 : :
488 : 0 : for (i = 0; i < nb_ops; i++) {
489 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
490 : :
491 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
492 : : rte_crypto_op_attach_sym_session(ops[i], sess);
493 : :
494 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
495 : : src_buf_offset);
496 : :
497 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
498 : 0 : if (dst_buf_offset == 0)
499 : 0 : sym_op->m_dst = NULL;
500 : : else
501 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
502 : : dst_buf_offset);
503 : :
504 : : /* cipher parameters */
505 : 0 : if (options->imix_distribution_count) {
506 : 0 : sym_op->cipher.data.length =
507 : 0 : options->imix_buffer_sizes[*imix_idx];
508 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
509 : : } else
510 : 0 : sym_op->cipher.data.length = options->test_buffer_size;
511 : :
512 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
513 : 0 : options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
514 : : options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
515 : 0 : sym_op->cipher.data.length <<= 3;
516 : :
517 : 0 : sym_op->cipher.data.offset = 0;
518 : : }
519 : :
520 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY) {
521 : 0 : for (i = 0; i < nb_ops; i++) {
522 : 0 : uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
523 : : uint8_t *, iv_offset);
524 : :
525 : 0 : memcpy(iv_ptr, test_vector->cipher_iv.data,
526 : 0 : test_vector->cipher_iv.length);
527 : :
528 : : }
529 : : }
530 : 0 : }
531 : :
532 : : static void
533 : 0 : cperf_set_ops_auth(struct rte_crypto_op **ops,
534 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
535 : : uint16_t nb_ops, void *sess,
536 : : const struct cperf_options *options,
537 : : const struct cperf_test_vector *test_vector,
538 : : uint16_t iv_offset, uint32_t *imix_idx,
539 : : uint64_t *tsc_start __rte_unused)
540 : : {
541 : : uint16_t i;
542 : :
543 : 0 : for (i = 0; i < nb_ops; i++) {
544 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
545 : :
546 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
547 : : rte_crypto_op_attach_sym_session(ops[i], sess);
548 : :
549 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
550 : : src_buf_offset);
551 : :
552 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
553 : 0 : if (dst_buf_offset == 0)
554 : 0 : sym_op->m_dst = NULL;
555 : : else
556 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
557 : : dst_buf_offset);
558 : :
559 : 0 : if (test_vector->auth_iv.length) {
560 : 0 : uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
561 : : uint8_t *,
562 : : iv_offset);
563 : 0 : memcpy(iv_ptr, test_vector->auth_iv.data,
564 : : test_vector->auth_iv.length);
565 : : }
566 : :
567 : : /* authentication parameters */
568 : 0 : if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
569 : 0 : sym_op->auth.digest.data = test_vector->digest.data;
570 : 0 : sym_op->auth.digest.phys_addr =
571 : 0 : test_vector->digest.phys_addr;
572 : : } else {
573 : :
574 : 0 : uint32_t offset = options->test_buffer_size;
575 : : struct rte_mbuf *buf, *tbuf;
576 : :
577 : 0 : if (options->out_of_place) {
578 : 0 : buf = sym_op->m_dst;
579 : : } else {
580 : 0 : tbuf = sym_op->m_src;
581 : 0 : while ((tbuf->next != NULL) &&
582 : 0 : (offset >= tbuf->data_len)) {
583 : 0 : offset -= tbuf->data_len;
584 : : tbuf = tbuf->next;
585 : : }
586 : : /*
587 : : * If there is not enough room in segment,
588 : : * place the digest in the next segment
589 : : */
590 : 0 : if ((tbuf->data_len - offset) < options->digest_sz) {
591 : : tbuf = tbuf->next;
592 : : offset = 0;
593 : : }
594 : : buf = tbuf;
595 : : }
596 : :
597 : 0 : sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
598 : : uint8_t *, offset);
599 : 0 : sym_op->auth.digest.phys_addr =
600 : 0 : rte_pktmbuf_iova_offset(buf, offset);
601 : :
602 : : }
603 : :
604 : 0 : if (options->imix_distribution_count) {
605 : 0 : sym_op->auth.data.length =
606 : 0 : options->imix_buffer_sizes[*imix_idx];
607 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
608 : : } else
609 : 0 : sym_op->auth.data.length = options->test_buffer_size;
610 : :
611 : 0 : if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
612 : 0 : options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
613 : : options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
614 : 0 : sym_op->auth.data.length <<= 3;
615 : :
616 : 0 : sym_op->auth.data.offset = 0;
617 : : }
618 : :
619 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY) {
620 : 0 : if (test_vector->auth_iv.length) {
621 : 0 : for (i = 0; i < nb_ops; i++) {
622 : 0 : uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
623 : : uint8_t *, iv_offset);
624 : :
625 : 0 : memcpy(iv_ptr, test_vector->auth_iv.data,
626 : 0 : test_vector->auth_iv.length);
627 : : }
628 : : }
629 : : }
630 : 0 : }
631 : :
632 : : static void
633 : 0 : cperf_set_ops_cipher_auth(struct rte_crypto_op **ops,
634 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
635 : : uint16_t nb_ops, void *sess,
636 : : const struct cperf_options *options,
637 : : const struct cperf_test_vector *test_vector,
638 : : uint16_t iv_offset, uint32_t *imix_idx,
639 : : uint64_t *tsc_start __rte_unused)
640 : : {
641 : : uint16_t i;
642 : :
643 : 0 : for (i = 0; i < nb_ops; i++) {
644 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
645 : :
646 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
647 : : rte_crypto_op_attach_sym_session(ops[i], sess);
648 : :
649 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
650 : : src_buf_offset);
651 : :
652 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
653 : 0 : if (dst_buf_offset == 0)
654 : 0 : sym_op->m_dst = NULL;
655 : : else
656 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
657 : : dst_buf_offset);
658 : :
659 : : /* cipher parameters */
660 : 0 : if (options->imix_distribution_count) {
661 : 0 : sym_op->cipher.data.length =
662 : 0 : options->imix_buffer_sizes[*imix_idx];
663 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
664 : : } else
665 : 0 : sym_op->cipher.data.length = options->test_buffer_size;
666 : :
667 : 0 : if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
668 : 0 : (options->op_type == CPERF_AUTH_THEN_CIPHER))
669 : 0 : sym_op->cipher.data.length += options->digest_sz;
670 : :
671 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
672 : 0 : options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
673 : : options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
674 : 0 : sym_op->cipher.data.length <<= 3;
675 : :
676 : 0 : sym_op->cipher.data.offset = 0;
677 : :
678 : : /* authentication parameters */
679 : 0 : if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
680 : 0 : sym_op->auth.digest.data = test_vector->digest.data;
681 : 0 : sym_op->auth.digest.phys_addr =
682 : 0 : test_vector->digest.phys_addr;
683 : : } else {
684 : :
685 : 0 : uint32_t offset = options->test_buffer_size;
686 : : struct rte_mbuf *buf, *tbuf;
687 : :
688 : 0 : if (options->out_of_place) {
689 : 0 : buf = sym_op->m_dst;
690 : : } else {
691 : : tbuf = sym_op->m_src;
692 : 0 : while ((tbuf->next != NULL) &&
693 : 0 : (offset >= tbuf->data_len)) {
694 : 0 : offset -= tbuf->data_len;
695 : : tbuf = tbuf->next;
696 : : }
697 : : /*
698 : : * If there is not enough room in segment,
699 : : * place the digest in the next segment
700 : : */
701 : 0 : if ((tbuf->data_len - offset) < options->digest_sz) {
702 : : tbuf = tbuf->next;
703 : : offset = 0;
704 : : }
705 : : buf = tbuf;
706 : : }
707 : :
708 : 0 : sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
709 : : uint8_t *, offset);
710 : 0 : sym_op->auth.digest.phys_addr =
711 : 0 : rte_pktmbuf_iova_offset(buf, offset);
712 : : }
713 : :
714 : 0 : if (options->imix_distribution_count) {
715 : 0 : sym_op->auth.data.length =
716 : 0 : options->imix_buffer_sizes[*imix_idx];
717 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
718 : : } else
719 : 0 : sym_op->auth.data.length = options->test_buffer_size;
720 : :
721 : 0 : if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
722 : 0 : options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
723 : : options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
724 : 0 : sym_op->auth.data.length <<= 3;
725 : :
726 : 0 : sym_op->auth.data.offset = 0;
727 : : }
728 : :
729 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY) {
730 : 0 : for (i = 0; i < nb_ops; i++) {
731 : 0 : uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
732 : : uint8_t *, iv_offset);
733 : :
734 : 0 : memcpy(iv_ptr, test_vector->cipher_iv.data,
735 : 0 : test_vector->cipher_iv.length);
736 : 0 : if (test_vector->auth_iv.length) {
737 : : /*
738 : : * Copy IV after the crypto operation and
739 : : * the cipher IV
740 : : */
741 : 0 : iv_ptr += test_vector->cipher_iv.length;
742 : 0 : memcpy(iv_ptr, test_vector->auth_iv.data,
743 : : test_vector->auth_iv.length);
744 : : }
745 : : }
746 : :
747 : : }
748 : 0 : }
749 : :
750 : : static void
751 : 0 : cperf_set_ops_aead(struct rte_crypto_op **ops,
752 : : uint32_t src_buf_offset, uint32_t dst_buf_offset,
753 : : uint16_t nb_ops, void *sess,
754 : : const struct cperf_options *options,
755 : : const struct cperf_test_vector *test_vector,
756 : : uint16_t iv_offset, uint32_t *imix_idx,
757 : : uint64_t *tsc_start __rte_unused)
758 : : {
759 : : uint16_t i;
760 : : /* AAD is placed after the IV */
761 : 0 : uint16_t aad_offset = iv_offset +
762 : 0 : ((options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) ?
763 : 0 : RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16) :
764 : : test_vector->aead_iv.length);
765 : :
766 : 0 : for (i = 0; i < nb_ops; i++) {
767 : 0 : struct rte_crypto_sym_op *sym_op = ops[i]->sym;
768 : :
769 : 0 : ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
770 : : rte_crypto_op_attach_sym_session(ops[i], sess);
771 : :
772 : 0 : sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
773 : : src_buf_offset);
774 : :
775 : : /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
776 : 0 : if (dst_buf_offset == 0)
777 : 0 : sym_op->m_dst = NULL;
778 : : else
779 : 0 : sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
780 : : dst_buf_offset);
781 : :
782 : : /* AEAD parameters */
783 : 0 : if (options->imix_distribution_count) {
784 : 0 : sym_op->aead.data.length =
785 : 0 : options->imix_buffer_sizes[*imix_idx];
786 : 0 : *imix_idx = (*imix_idx + 1) % options->pool_sz;
787 : : } else
788 : 0 : sym_op->aead.data.length = options->test_buffer_size;
789 : 0 : sym_op->aead.data.offset = 0;
790 : :
791 : 0 : sym_op->aead.aad.data = rte_crypto_op_ctod_offset(ops[i],
792 : : uint8_t *, aad_offset);
793 : 0 : sym_op->aead.aad.phys_addr = rte_crypto_op_ctophys_offset(ops[i],
794 : : aad_offset);
795 : :
796 : 0 : if (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
797 : 0 : sym_op->aead.digest.data = test_vector->digest.data;
798 : 0 : sym_op->aead.digest.phys_addr =
799 : 0 : test_vector->digest.phys_addr;
800 : : } else {
801 : :
802 : 0 : uint32_t offset = sym_op->aead.data.length +
803 : : sym_op->aead.data.offset;
804 : : struct rte_mbuf *buf, *tbuf;
805 : :
806 : 0 : if (options->out_of_place) {
807 : 0 : buf = sym_op->m_dst;
808 : : } else {
809 : : tbuf = sym_op->m_src;
810 : 0 : while ((tbuf->next != NULL) &&
811 : 0 : (offset >= tbuf->data_len)) {
812 : 0 : offset -= tbuf->data_len;
813 : : tbuf = tbuf->next;
814 : : }
815 : : /*
816 : : * If there is not enough room in segment,
817 : : * place the digest in the next segment
818 : : */
819 : 0 : if ((tbuf->data_len - offset) < options->digest_sz) {
820 : : tbuf = tbuf->next;
821 : : offset = 0;
822 : : }
823 : : buf = tbuf;
824 : : }
825 : :
826 : 0 : sym_op->aead.digest.data = rte_pktmbuf_mtod_offset(buf,
827 : : uint8_t *, offset);
828 : 0 : sym_op->aead.digest.phys_addr =
829 : 0 : rte_pktmbuf_iova_offset(buf, offset);
830 : : }
831 : : }
832 : :
833 : 0 : if ((options->test == CPERF_TEST_TYPE_VERIFY) ||
834 : 0 : (options->test == CPERF_TEST_TYPE_LATENCY) ||
835 : 0 : (options->test == CPERF_TEST_TYPE_THROUGHPUT &&
836 : 0 : (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT ||
837 : 0 : options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT))) {
838 : 0 : for (i = 0; i < nb_ops; i++) {
839 : 0 : uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
840 : : uint8_t *, iv_offset);
841 : :
842 : : /*
843 : : * If doing AES-CCM, nonce is copied one byte
844 : : * after the start of IV field, and AAD is copied
845 : : * 18 bytes after the start of the AAD field.
846 : : */
847 : 0 : if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) {
848 : 0 : memcpy(iv_ptr + 1, test_vector->aead_iv.data,
849 : 0 : test_vector->aead_iv.length);
850 : :
851 : 0 : memcpy(ops[i]->sym->aead.aad.data + 18,
852 : 0 : test_vector->aad.data,
853 : 0 : test_vector->aad.length);
854 : : } else {
855 : 0 : memcpy(iv_ptr, test_vector->aead_iv.data,
856 : 0 : test_vector->aead_iv.length);
857 : :
858 : 0 : memcpy(ops[i]->sym->aead.aad.data,
859 : 0 : test_vector->aad.data,
860 : 0 : test_vector->aad.length);
861 : : }
862 : : }
863 : : }
864 : 0 : }
865 : :
866 : : static void *
867 : 0 : create_ipsec_session(struct rte_mempool *sess_mp,
868 : : uint8_t dev_id,
869 : : const struct cperf_options *options,
870 : : const struct cperf_test_vector *test_vector,
871 : : uint16_t iv_offset)
872 : : {
873 : 0 : struct rte_crypto_sym_xform auth_xform = {0};
874 : : struct rte_crypto_sym_xform *crypto_xform;
875 : 0 : struct rte_crypto_sym_xform xform = {0};
876 : :
877 : 0 : if (options->aead_algo != 0) {
878 : : /* Setup AEAD Parameters */
879 : 0 : xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
880 : : xform.next = NULL;
881 : 0 : xform.aead.algo = options->aead_algo;
882 : 0 : xform.aead.op = options->aead_op;
883 : 0 : xform.aead.iv.offset = iv_offset;
884 : 0 : xform.aead.key.data = test_vector->aead_key.data;
885 : 0 : xform.aead.key.length = test_vector->aead_key.length;
886 : 0 : xform.aead.iv.length = test_vector->aead_iv.length;
887 : 0 : xform.aead.digest_length = options->digest_sz;
888 : 0 : xform.aead.aad_length = options->aead_aad_sz;
889 : : crypto_xform = &xform;
890 : 0 : } else if (options->cipher_algo != 0 && options->auth_algo != 0) {
891 : : /* Setup Cipher Parameters */
892 : 0 : xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
893 : 0 : xform.cipher.algo = options->cipher_algo;
894 : 0 : xform.cipher.op = options->cipher_op;
895 : 0 : xform.cipher.iv.offset = iv_offset;
896 : 0 : xform.cipher.iv.length = test_vector->cipher_iv.length;
897 : : /* cipher different than null */
898 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
899 : 0 : xform.cipher.key.data = test_vector->cipher_key.data;
900 : 0 : xform.cipher.key.length =
901 : 0 : test_vector->cipher_key.length;
902 : : } else {
903 : : xform.cipher.key.data = NULL;
904 : : xform.cipher.key.length = 0;
905 : : }
906 : :
907 : : /* Setup Auth Parameters */
908 : 0 : auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
909 : 0 : auth_xform.auth.algo = options->auth_algo;
910 : 0 : auth_xform.auth.op = options->auth_op;
911 : 0 : auth_xform.auth.iv.offset = iv_offset +
912 : : xform.cipher.iv.length;
913 : : /* auth different than null */
914 : 0 : if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
915 : 0 : auth_xform.auth.digest_length = options->digest_sz;
916 : 0 : auth_xform.auth.key.length =
917 : 0 : test_vector->auth_key.length;
918 : 0 : auth_xform.auth.key.data = test_vector->auth_key.data;
919 : 0 : auth_xform.auth.iv.length = test_vector->auth_iv.length;
920 : : } else {
921 : : auth_xform.auth.digest_length = 0;
922 : : auth_xform.auth.key.length = 0;
923 : : auth_xform.auth.key.data = NULL;
924 : : auth_xform.auth.iv.length = 0;
925 : : }
926 : :
927 : 0 : if (options->is_outbound) {
928 : : crypto_xform = &xform;
929 : 0 : xform.next = &auth_xform;
930 : : auth_xform.next = NULL;
931 : : } else {
932 : : crypto_xform = &auth_xform;
933 : 0 : auth_xform.next = &xform;
934 : : xform.next = NULL;
935 : : }
936 : : } else {
937 : : return NULL;
938 : : }
939 : :
940 : : #define CPERF_IPSEC_SRC_IP 0x01010101
941 : : #define CPERF_IPSEC_DST_IP 0x02020202
942 : : #define CPERF_IPSEC_SALT 0x0
943 : : #define CPERF_IPSEC_DEFTTL 64
944 : 0 : struct rte_security_ipsec_tunnel_param tunnel = {
945 : : .type = RTE_SECURITY_IPSEC_TUNNEL_IPV4,
946 : : {.ipv4 = {
947 : : .src_ip = { .s_addr = CPERF_IPSEC_SRC_IP},
948 : : .dst_ip = { .s_addr = CPERF_IPSEC_DST_IP},
949 : : .dscp = 0,
950 : : .df = 0,
951 : : .ttl = CPERF_IPSEC_DEFTTL,
952 : : } },
953 : : };
954 : 0 : struct rte_security_session_conf sess_conf = {
955 : : .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
956 : : .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
957 : : {.ipsec = {
958 : 0 : .spi = rte_lcore_id() + 1,
959 : : /**< For testing sake, lcore_id is taken as SPI so that
960 : : * for every core a different session is created.
961 : : */
962 : : .salt = CPERF_IPSEC_SALT,
963 : : .options = { 0 },
964 : : .replay_win_sz = 0,
965 : : .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
966 : : .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
967 : : .tunnel = tunnel,
968 : : } },
969 : : .userdata = NULL,
970 : : .crypto_xform = crypto_xform,
971 : : };
972 : :
973 : 0 : if (options->is_outbound)
974 : : sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
975 : : else
976 : 0 : sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
977 : :
978 : 0 : void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
979 : :
980 : : /* Create security session */
981 : 0 : return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
982 : : }
983 : :
984 : : static void *
985 : 0 : create_tls_session(struct rte_mempool *sess_mp,
986 : : uint8_t dev_id,
987 : : const struct cperf_options *options,
988 : : const struct cperf_test_vector *test_vector,
989 : : uint16_t iv_offset)
990 : : {
991 : 0 : struct rte_crypto_sym_xform auth_xform = {0};
992 : : struct rte_crypto_sym_xform *crypto_xform;
993 : 0 : struct rte_crypto_sym_xform xform = {0};
994 : :
995 : 0 : if (options->aead_algo != 0) {
996 : : /* Setup AEAD Parameters */
997 : 0 : xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
998 : : xform.next = NULL;
999 : 0 : xform.aead.algo = options->aead_algo;
1000 : 0 : xform.aead.op = options->aead_op;
1001 : 0 : xform.aead.iv.offset = iv_offset;
1002 : 0 : xform.aead.key.data = test_vector->aead_key.data;
1003 : 0 : xform.aead.key.length = test_vector->aead_key.length;
1004 : 0 : xform.aead.iv.length = test_vector->aead_iv.length;
1005 : 0 : xform.aead.digest_length = options->digest_sz;
1006 : 0 : xform.aead.aad_length = options->aead_aad_sz;
1007 : : crypto_xform = &xform;
1008 : 0 : } else if (options->cipher_algo != 0 && options->auth_algo != 0) {
1009 : : /* Setup Cipher Parameters */
1010 : 0 : xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1011 : 0 : xform.cipher.algo = options->cipher_algo;
1012 : 0 : xform.cipher.op = options->cipher_op;
1013 : 0 : xform.cipher.iv.offset = iv_offset;
1014 : 0 : xform.cipher.iv.length = test_vector->cipher_iv.length;
1015 : : /* cipher different than null */
1016 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
1017 : 0 : xform.cipher.key.data = test_vector->cipher_key.data;
1018 : 0 : xform.cipher.key.length = test_vector->cipher_key.length;
1019 : : } else {
1020 : : xform.cipher.key.data = NULL;
1021 : : xform.cipher.key.length = 0;
1022 : : }
1023 : :
1024 : : /* Setup Auth Parameters */
1025 : 0 : auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1026 : 0 : auth_xform.auth.algo = options->auth_algo;
1027 : 0 : auth_xform.auth.op = options->auth_op;
1028 : 0 : auth_xform.auth.iv.offset = iv_offset + xform.cipher.iv.length;
1029 : : /* auth different than null */
1030 : 0 : if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
1031 : 0 : auth_xform.auth.digest_length = options->digest_sz;
1032 : 0 : auth_xform.auth.key.length = test_vector->auth_key.length;
1033 : 0 : auth_xform.auth.key.data = test_vector->auth_key.data;
1034 : 0 : auth_xform.auth.iv.length = test_vector->auth_iv.length;
1035 : : } else {
1036 : : auth_xform.auth.digest_length = 0;
1037 : : auth_xform.auth.key.length = 0;
1038 : : auth_xform.auth.key.data = NULL;
1039 : : auth_xform.auth.iv.length = 0;
1040 : : }
1041 : :
1042 : 0 : if (options->is_outbound) {
1043 : : /* Currently supporting AUTH then Encrypt mode only for TLS. */
1044 : : crypto_xform = &auth_xform;
1045 : 0 : auth_xform.next = &xform;
1046 : : xform.next = NULL;
1047 : : } else {
1048 : : crypto_xform = &xform;
1049 : 0 : xform.next = &auth_xform;
1050 : : auth_xform.next = NULL;
1051 : : }
1052 : : } else {
1053 : : return NULL;
1054 : : }
1055 : :
1056 : : struct rte_security_tls_record_sess_options opts = {
1057 : : .iv_gen_disable = 0,
1058 : : .extra_padding_enable = 0,
1059 : : };
1060 : 0 : struct rte_security_session_conf sess_conf = {
1061 : : .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1062 : : .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD,
1063 : : {.tls_record = {
1064 : : .ver = RTE_SECURITY_VERSION_TLS_1_2,
1065 : : .options = opts,
1066 : : } },
1067 : : .userdata = NULL,
1068 : : .crypto_xform = crypto_xform,
1069 : : };
1070 : 0 : if (options->tls_version)
1071 : 0 : sess_conf.tls_record.ver = options->tls_version;
1072 : :
1073 : 0 : if (options->is_outbound)
1074 : 0 : sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_WRITE;
1075 : : else
1076 : : sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_READ;
1077 : :
1078 : 0 : void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
1079 : :
1080 : : /* Create security session */
1081 : 0 : return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
1082 : : }
1083 : :
1084 : : static void *
1085 : 0 : cperf_create_session(struct rte_mempool *sess_mp,
1086 : : uint8_t dev_id,
1087 : : const struct cperf_options *options,
1088 : : const struct cperf_test_vector *test_vector,
1089 : : uint16_t iv_offset)
1090 : : {
1091 : : const struct cperf_ecdsa_test_data *ecdsa_curve_data = NULL;
1092 : : struct rte_crypto_sym_xform cipher_xform;
1093 : : struct rte_crypto_sym_xform auth_xform;
1094 : : struct rte_crypto_sym_xform aead_xform;
1095 : : void *sess = NULL;
1096 : 0 : void *asym_sess = NULL;
1097 : 0 : struct rte_crypto_asym_xform xform = {0};
1098 : : int ret;
1099 : :
1100 : 0 : if (options->op_type == CPERF_ASYM_MODEX) {
1101 : : xform.next = NULL;
1102 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
1103 : 0 : xform.modex.modulus.data = options->modex_data->modulus.data;
1104 : 0 : xform.modex.modulus.length = options->modex_data->modulus.len;
1105 : 0 : xform.modex.exponent.data = options->modex_data->exponent.data;
1106 : 0 : xform.modex.exponent.length = options->modex_data->exponent.len;
1107 : :
1108 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform,
1109 : : sess_mp, &asym_sess);
1110 : 0 : if (ret < 0) {
1111 : 0 : RTE_LOG(ERR, USER1, "Asym session create failed\n");
1112 : 0 : return NULL;
1113 : : }
1114 : 0 : return asym_sess;
1115 : : }
1116 : :
1117 : 0 : if (options->op_type == CPERF_ASYM_RSA) {
1118 : : xform.next = NULL;
1119 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
1120 : 0 : xform.rsa.padding.type = options->rsa_data->padding;
1121 : 0 : xform.rsa.n.data = options->rsa_data->n.data;
1122 : 0 : xform.rsa.n.length = options->rsa_data->n.length;
1123 : 0 : xform.rsa.e.data = options->rsa_data->e.data;
1124 : 0 : xform.rsa.e.length = options->rsa_data->e.length;
1125 : 0 : xform.rsa.d.data = options->rsa_data->d.data;
1126 : 0 : xform.rsa.d.length = options->rsa_data->d.length;
1127 : 0 : xform.rsa.key_type = options->rsa_data->key_type;
1128 : 0 : if (xform.rsa.key_type == RTE_RSA_KEY_TYPE_QT) {
1129 : 0 : xform.rsa.qt.p.data = options->rsa_data->p.data;
1130 : 0 : xform.rsa.qt.p.length = options->rsa_data->p.length;
1131 : 0 : xform.rsa.qt.q.data = options->rsa_data->q.data;
1132 : 0 : xform.rsa.qt.q.length = options->rsa_data->q.length;
1133 : 0 : xform.rsa.qt.dP.data = options->rsa_data->dp.data;
1134 : 0 : xform.rsa.qt.dP.length = options->rsa_data->dp.length;
1135 : 0 : xform.rsa.qt.dQ.data = options->rsa_data->dq.data;
1136 : 0 : xform.rsa.qt.dQ.length = options->rsa_data->dq.length;
1137 : 0 : xform.rsa.qt.qInv.data = options->rsa_data->qinv.data;
1138 : 0 : xform.rsa.qt.qInv.length = options->rsa_data->qinv.length;
1139 : : }
1140 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform,
1141 : : sess_mp, &asym_sess);
1142 : 0 : if (ret < 0) {
1143 : 0 : RTE_LOG(ERR, USER1, "Asym session create failed\n");
1144 : 0 : return NULL;
1145 : : }
1146 : 0 : return asym_sess;
1147 : : }
1148 : :
1149 : 0 : switch (options->op_type) {
1150 : 0 : case CPERF_ASYM_SECP192R1:
1151 : 0 : ecdsa_curve_data = options->secp192r1_data;
1152 : 0 : break;
1153 : 0 : case CPERF_ASYM_SECP224R1:
1154 : 0 : ecdsa_curve_data = options->secp224r1_data;
1155 : 0 : break;
1156 : 0 : case CPERF_ASYM_SECP256R1:
1157 : 0 : ecdsa_curve_data = options->secp256r1_data;
1158 : 0 : break;
1159 : 0 : case CPERF_ASYM_SECP384R1:
1160 : 0 : ecdsa_curve_data = options->secp384r1_data;
1161 : 0 : break;
1162 : 0 : case CPERF_ASYM_SECP521R1:
1163 : 0 : ecdsa_curve_data = options->secp521r1_data;
1164 : 0 : break;
1165 : : default:
1166 : : break;
1167 : : }
1168 : :
1169 : 0 : if (ecdsa_curve_data) {
1170 : : xform.next = NULL;
1171 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1172 : 0 : xform.ec.curve_id = ecdsa_curve_data->curve;
1173 : 0 : xform.ec.pkey.data = ecdsa_curve_data->pkey.data;
1174 : 0 : xform.ec.pkey.length = ecdsa_curve_data->pkey.length;
1175 : 0 : xform.ec.q.x.data = ecdsa_curve_data->pubkey_qx.data;
1176 : 0 : xform.ec.q.x.length = ecdsa_curve_data->pubkey_qx.length;
1177 : 0 : xform.ec.q.y.data = ecdsa_curve_data->pubkey_qy.data;
1178 : 0 : xform.ec.q.y.length = ecdsa_curve_data->pubkey_qy.length;
1179 : :
1180 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform,
1181 : : sess_mp, &asym_sess);
1182 : 0 : if (ret < 0) {
1183 : 0 : RTE_LOG(ERR, USER1, "ECDSA Asym session create failed\n");
1184 : 0 : return NULL;
1185 : : }
1186 : :
1187 : 0 : return asym_sess;
1188 : : }
1189 : :
1190 : 0 : if (options->op_type == CPERF_ASYM_ED25519) {
1191 : : xform.next = NULL;
1192 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
1193 : 0 : xform.ec.curve_id = options->eddsa_data->curve;
1194 : 0 : xform.ec.pkey.data = options->eddsa_data->pkey.data;
1195 : 0 : xform.ec.pkey.length = options->eddsa_data->pkey.length;
1196 : 0 : xform.ec.q.x.data = options->eddsa_data->pubkey.data;
1197 : 0 : xform.ec.q.x.length = options->eddsa_data->pubkey.length;
1198 : :
1199 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform,
1200 : : sess_mp, &asym_sess);
1201 : 0 : if (ret < 0) {
1202 : 0 : RTE_LOG(ERR, USER1, "EdDSA Asym session create failed\n");
1203 : 0 : return NULL;
1204 : : }
1205 : :
1206 : 0 : return asym_sess;
1207 : : }
1208 : :
1209 : : if (options->op_type == CPERF_ASYM_SM2) {
1210 : : xform.next = NULL;
1211 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
1212 : 0 : xform.ec.curve_id = options->sm2_data->curve;
1213 : 0 : xform.ec.pkey.data = options->sm2_data->pkey.data;
1214 : 0 : xform.ec.pkey.length = options->sm2_data->pkey.length;
1215 : 0 : xform.ec.q.x.data = options->sm2_data->pubkey_qx.data;
1216 : 0 : xform.ec.q.x.length = options->sm2_data->pubkey_qx.length;
1217 : 0 : xform.ec.q.y.data = options->sm2_data->pubkey_qy.data;
1218 : 0 : xform.ec.q.y.length = options->sm2_data->pubkey_qy.length;
1219 : :
1220 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform,
1221 : : sess_mp, &asym_sess);
1222 : 0 : if (ret < 0) {
1223 : 0 : RTE_LOG(ERR, USER1, "SM2 Asym session create failed\n");
1224 : 0 : return NULL;
1225 : : }
1226 : :
1227 : 0 : return asym_sess;
1228 : : }
1229 : : #ifdef RTE_LIB_SECURITY
1230 : : /*
1231 : : * security only
1232 : : */
1233 : : if (options->op_type == CPERF_PDCP) {
1234 : : /* Setup Cipher Parameters */
1235 : 0 : cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1236 : 0 : cipher_xform.next = NULL;
1237 : 0 : cipher_xform.cipher.algo = options->cipher_algo;
1238 : 0 : cipher_xform.cipher.op = options->cipher_op;
1239 : 0 : cipher_xform.cipher.iv.offset = iv_offset;
1240 : 0 : cipher_xform.cipher.iv.length = 4;
1241 : :
1242 : : /* cipher different than null */
1243 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
1244 : 0 : cipher_xform.cipher.key.data = test_vector->cipher_key.data;
1245 : 0 : cipher_xform.cipher.key.length = test_vector->cipher_key.length;
1246 : : } else {
1247 : 0 : cipher_xform.cipher.key.data = NULL;
1248 : 0 : cipher_xform.cipher.key.length = 0;
1249 : : }
1250 : :
1251 : : /* Setup Auth Parameters */
1252 : 0 : if (options->auth_algo != 0) {
1253 : 0 : auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1254 : 0 : auth_xform.next = NULL;
1255 : 0 : auth_xform.auth.algo = options->auth_algo;
1256 : 0 : auth_xform.auth.op = options->auth_op;
1257 : 0 : auth_xform.auth.iv.offset = iv_offset +
1258 : : cipher_xform.cipher.iv.length;
1259 : :
1260 : : /* auth different than null */
1261 : 0 : if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
1262 : 0 : auth_xform.auth.digest_length = options->digest_sz;
1263 : 0 : auth_xform.auth.key.length = test_vector->auth_key.length;
1264 : 0 : auth_xform.auth.key.data = test_vector->auth_key.data;
1265 : 0 : auth_xform.auth.iv.length = test_vector->auth_iv.length;
1266 : : } else {
1267 : 0 : auth_xform.auth.digest_length = 0;
1268 : 0 : auth_xform.auth.key.length = 0;
1269 : 0 : auth_xform.auth.key.data = NULL;
1270 : 0 : auth_xform.auth.iv.length = 0;
1271 : : }
1272 : :
1273 : 0 : cipher_xform.next = &auth_xform;
1274 : : } else {
1275 : : cipher_xform.next = NULL;
1276 : : }
1277 : :
1278 : 0 : struct rte_security_session_conf sess_conf = {
1279 : : .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1280 : : .protocol = RTE_SECURITY_PROTOCOL_PDCP,
1281 : : {.pdcp = {
1282 : : .bearer = 0x16,
1283 : 0 : .domain = options->pdcp_domain,
1284 : : .pkt_dir = 0,
1285 : 0 : .sn_size = options->pdcp_sn_sz,
1286 : 0 : .hfn = options->pdcp_ses_hfn_en ?
1287 : 0 : PDCP_DEFAULT_HFN : 0,
1288 : : .hfn_threshold = 0x70C0A,
1289 : 0 : .sdap_enabled = options->pdcp_sdap,
1290 : 0 : .hfn_ovrd = !(options->pdcp_ses_hfn_en),
1291 : : } },
1292 : : .crypto_xform = &cipher_xform
1293 : : };
1294 : :
1295 : 0 : void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
1296 : :
1297 : : /* Create security session */
1298 : 0 : return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
1299 : : }
1300 : :
1301 : : if (options->op_type == CPERF_IPSEC) {
1302 : 0 : return create_ipsec_session(sess_mp, dev_id,
1303 : : options, test_vector, iv_offset);
1304 : : }
1305 : :
1306 : : if (options->op_type == CPERF_TLS) {
1307 : 0 : return create_tls_session(sess_mp, dev_id,
1308 : : options, test_vector, iv_offset);
1309 : : }
1310 : :
1311 : : if (options->op_type == CPERF_DOCSIS) {
1312 : : enum rte_security_docsis_direction direction;
1313 : :
1314 : 0 : cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1315 : 0 : cipher_xform.next = NULL;
1316 : 0 : cipher_xform.cipher.algo = options->cipher_algo;
1317 : 0 : cipher_xform.cipher.op = options->cipher_op;
1318 : 0 : cipher_xform.cipher.iv.offset = iv_offset;
1319 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
1320 : 0 : cipher_xform.cipher.key.data =
1321 : 0 : test_vector->cipher_key.data;
1322 : 0 : cipher_xform.cipher.key.length =
1323 : 0 : test_vector->cipher_key.length;
1324 : 0 : cipher_xform.cipher.iv.length =
1325 : 0 : test_vector->cipher_iv.length;
1326 : : } else {
1327 : 0 : cipher_xform.cipher.key.data = NULL;
1328 : 0 : cipher_xform.cipher.key.length = 0;
1329 : 0 : cipher_xform.cipher.iv.length = 0;
1330 : : }
1331 : : cipher_xform.next = NULL;
1332 : :
1333 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
1334 : : direction = RTE_SECURITY_DOCSIS_DOWNLINK;
1335 : : else
1336 : : direction = RTE_SECURITY_DOCSIS_UPLINK;
1337 : :
1338 : 0 : struct rte_security_session_conf sess_conf = {
1339 : : .action_type =
1340 : : RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1341 : : .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
1342 : : {.docsis = {
1343 : : .direction = direction,
1344 : : } },
1345 : : .crypto_xform = &cipher_xform
1346 : : };
1347 : 0 : void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
1348 : :
1349 : : /* Create security session */
1350 : 0 : return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
1351 : : }
1352 : : #endif
1353 : : /*
1354 : : * cipher only
1355 : : */
1356 : : if (options->op_type == CPERF_CIPHER_ONLY) {
1357 : 0 : cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1358 : 0 : cipher_xform.next = NULL;
1359 : 0 : cipher_xform.cipher.algo = options->cipher_algo;
1360 : 0 : cipher_xform.cipher.op = options->cipher_op;
1361 : 0 : cipher_xform.cipher.iv.offset = iv_offset;
1362 : :
1363 : : /* cipher different than null */
1364 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
1365 : 0 : cipher_xform.cipher.key.data =
1366 : 0 : test_vector->cipher_key.data;
1367 : 0 : cipher_xform.cipher.key.length =
1368 : 0 : test_vector->cipher_key.length;
1369 : 0 : cipher_xform.cipher.iv.length =
1370 : 0 : test_vector->cipher_iv.length;
1371 : : } else {
1372 : 0 : cipher_xform.cipher.key.data = NULL;
1373 : 0 : cipher_xform.cipher.key.length = 0;
1374 : 0 : cipher_xform.cipher.iv.length = 0;
1375 : : }
1376 : : /* create crypto session */
1377 : 0 : sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform,
1378 : : sess_mp);
1379 : : /*
1380 : : * auth only
1381 : : */
1382 : : } else if (options->op_type == CPERF_AUTH_ONLY) {
1383 : 0 : auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1384 : 0 : auth_xform.next = NULL;
1385 : 0 : auth_xform.auth.algo = options->auth_algo;
1386 : 0 : auth_xform.auth.op = options->auth_op;
1387 : 0 : auth_xform.auth.iv.offset = iv_offset;
1388 : :
1389 : : /* auth different than null */
1390 : 0 : if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
1391 : 0 : auth_xform.auth.digest_length =
1392 : 0 : options->digest_sz;
1393 : 0 : auth_xform.auth.key.length =
1394 : 0 : test_vector->auth_key.length;
1395 : 0 : auth_xform.auth.key.data = test_vector->auth_key.data;
1396 : 0 : auth_xform.auth.iv.length =
1397 : 0 : test_vector->auth_iv.length;
1398 : : } else {
1399 : 0 : auth_xform.auth.digest_length = 0;
1400 : 0 : auth_xform.auth.key.length = 0;
1401 : 0 : auth_xform.auth.key.data = NULL;
1402 : 0 : auth_xform.auth.iv.length = 0;
1403 : : }
1404 : : /* create crypto session */
1405 : 0 : sess = rte_cryptodev_sym_session_create(dev_id, &auth_xform,
1406 : : sess_mp);
1407 : : /*
1408 : : * cipher and auth
1409 : : */
1410 : : } else if (options->op_type == CPERF_CIPHER_THEN_AUTH
1411 : : || options->op_type == CPERF_AUTH_THEN_CIPHER) {
1412 : : /*
1413 : : * cipher
1414 : : */
1415 : 0 : cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1416 : 0 : cipher_xform.next = NULL;
1417 : 0 : cipher_xform.cipher.algo = options->cipher_algo;
1418 : 0 : cipher_xform.cipher.op = options->cipher_op;
1419 : 0 : cipher_xform.cipher.iv.offset = iv_offset;
1420 : :
1421 : : /* cipher different than null */
1422 : 0 : if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
1423 : 0 : cipher_xform.cipher.key.data =
1424 : 0 : test_vector->cipher_key.data;
1425 : 0 : cipher_xform.cipher.key.length =
1426 : 0 : test_vector->cipher_key.length;
1427 : 0 : cipher_xform.cipher.iv.length =
1428 : 0 : test_vector->cipher_iv.length;
1429 : : } else {
1430 : 0 : cipher_xform.cipher.key.data = NULL;
1431 : 0 : cipher_xform.cipher.key.length = 0;
1432 : 0 : cipher_xform.cipher.iv.length = 0;
1433 : : }
1434 : :
1435 : : /*
1436 : : * auth
1437 : : */
1438 : 0 : auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1439 : 0 : auth_xform.next = NULL;
1440 : 0 : auth_xform.auth.algo = options->auth_algo;
1441 : 0 : auth_xform.auth.op = options->auth_op;
1442 : 0 : auth_xform.auth.iv.offset = iv_offset +
1443 : 0 : cipher_xform.cipher.iv.length;
1444 : :
1445 : : /* auth different than null */
1446 : 0 : if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
1447 : 0 : auth_xform.auth.digest_length = options->digest_sz;
1448 : 0 : auth_xform.auth.iv.length = test_vector->auth_iv.length;
1449 : 0 : auth_xform.auth.key.length =
1450 : 0 : test_vector->auth_key.length;
1451 : 0 : auth_xform.auth.key.data =
1452 : 0 : test_vector->auth_key.data;
1453 : : } else {
1454 : 0 : auth_xform.auth.digest_length = 0;
1455 : 0 : auth_xform.auth.key.length = 0;
1456 : 0 : auth_xform.auth.key.data = NULL;
1457 : 0 : auth_xform.auth.iv.length = 0;
1458 : : }
1459 : :
1460 : : /* cipher then auth */
1461 : 0 : if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1462 : 0 : cipher_xform.next = &auth_xform;
1463 : : /* create crypto session */
1464 : 0 : sess = rte_cryptodev_sym_session_create(dev_id,
1465 : : &cipher_xform, sess_mp);
1466 : : } else { /* auth then cipher */
1467 : 0 : auth_xform.next = &cipher_xform;
1468 : : /* create crypto session */
1469 : 0 : sess = rte_cryptodev_sym_session_create(dev_id,
1470 : : &auth_xform, sess_mp);
1471 : : }
1472 : : } else { /* options->op_type == CPERF_AEAD */
1473 : 0 : aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
1474 : 0 : aead_xform.next = NULL;
1475 : 0 : aead_xform.aead.algo = options->aead_algo;
1476 : 0 : aead_xform.aead.op = options->aead_op;
1477 : 0 : aead_xform.aead.iv.offset = iv_offset;
1478 : :
1479 : 0 : aead_xform.aead.key.data =
1480 : 0 : test_vector->aead_key.data;
1481 : 0 : aead_xform.aead.key.length =
1482 : 0 : test_vector->aead_key.length;
1483 : 0 : aead_xform.aead.iv.length = test_vector->aead_iv.length;
1484 : :
1485 : 0 : aead_xform.aead.digest_length = options->digest_sz;
1486 : 0 : aead_xform.aead.aad_length =
1487 : 0 : options->aead_aad_sz;
1488 : :
1489 : : /* Create crypto session */
1490 : 0 : sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform,
1491 : : sess_mp);
1492 : : }
1493 : :
1494 : : return sess;
1495 : : }
1496 : :
1497 : : int
1498 : 0 : cperf_get_op_functions(const struct cperf_options *options,
1499 : : struct cperf_op_fns *op_fns)
1500 : : {
1501 : : memset(op_fns, 0, sizeof(struct cperf_op_fns));
1502 : :
1503 : 0 : op_fns->sess_create = cperf_create_session;
1504 : :
1505 : 0 : switch (options->op_type) {
1506 : 0 : case CPERF_AEAD:
1507 : 0 : op_fns->populate_ops = cperf_set_ops_aead;
1508 : 0 : break;
1509 : :
1510 : 0 : case CPERF_AUTH_THEN_CIPHER:
1511 : : case CPERF_CIPHER_THEN_AUTH:
1512 : 0 : op_fns->populate_ops = cperf_set_ops_cipher_auth;
1513 : 0 : break;
1514 : 0 : case CPERF_AUTH_ONLY:
1515 : 0 : if (options->auth_algo == RTE_CRYPTO_AUTH_NULL)
1516 : 0 : op_fns->populate_ops = cperf_set_ops_null_auth;
1517 : : else
1518 : 0 : op_fns->populate_ops = cperf_set_ops_auth;
1519 : : break;
1520 : 0 : case CPERF_CIPHER_ONLY:
1521 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_NULL)
1522 : 0 : op_fns->populate_ops = cperf_set_ops_null_cipher;
1523 : : else
1524 : 0 : op_fns->populate_ops = cperf_set_ops_cipher;
1525 : : break;
1526 : 0 : case CPERF_ASYM_MODEX:
1527 : 0 : op_fns->populate_ops = cperf_set_ops_asym_modex;
1528 : 0 : break;
1529 : 0 : case CPERF_ASYM_RSA:
1530 : 0 : op_fns->populate_ops = cperf_set_ops_asym_rsa;
1531 : 0 : break;
1532 : 0 : case CPERF_ASYM_SECP192R1:
1533 : : case CPERF_ASYM_SECP224R1:
1534 : : case CPERF_ASYM_SECP256R1:
1535 : : case CPERF_ASYM_SECP384R1:
1536 : : case CPERF_ASYM_SECP521R1:
1537 : 0 : op_fns->populate_ops = cperf_set_ops_asym_ecdsa;
1538 : 0 : break;
1539 : 0 : case CPERF_ASYM_ED25519:
1540 : 0 : op_fns->populate_ops = cperf_set_ops_asym_eddsa;
1541 : 0 : break;
1542 : 0 : case CPERF_ASYM_SM2:
1543 : 0 : op_fns->populate_ops = cperf_set_ops_asym_sm2;
1544 : 0 : break;
1545 : : #ifdef RTE_LIB_SECURITY
1546 : 0 : case CPERF_PDCP:
1547 : : case CPERF_DOCSIS:
1548 : 0 : op_fns->populate_ops = cperf_set_ops_security;
1549 : 0 : break;
1550 : 0 : case CPERF_IPSEC:
1551 : 0 : op_fns->populate_ops = cperf_set_ops_security_ipsec;
1552 : 0 : break;
1553 : 0 : case CPERF_TLS:
1554 : 0 : op_fns->populate_ops = cperf_set_ops_security_tls;
1555 : 0 : break;
1556 : : #endif
1557 : : default:
1558 : : return -1;
1559 : : }
1560 : :
1561 : : return 0;
1562 : : }
|