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