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