4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_cryptodev.h>
35 #include "cperf_ops.h"
36 #include "cperf_test_vectors.h"
39 cperf_set_ops_null_cipher(struct rte_crypto_op **ops,
40 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
41 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
42 const struct cperf_options *options,
43 const struct cperf_test_vector *test_vector __rte_unused,
44 uint16_t iv_offset __rte_unused)
48 for (i = 0; i < nb_ops; i++) {
49 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
51 rte_crypto_op_attach_sym_session(ops[i], sess);
53 sym_op->m_src = bufs_in[i];
54 sym_op->m_dst = bufs_out[i];
56 /* cipher parameters */
57 sym_op->cipher.data.length = options->test_buffer_size;
58 sym_op->cipher.data.offset = 0;
65 cperf_set_ops_null_auth(struct rte_crypto_op **ops,
66 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
67 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
68 const struct cperf_options *options,
69 const struct cperf_test_vector *test_vector __rte_unused,
70 uint16_t iv_offset __rte_unused)
74 for (i = 0; i < nb_ops; i++) {
75 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
77 rte_crypto_op_attach_sym_session(ops[i], sess);
79 sym_op->m_src = bufs_in[i];
80 sym_op->m_dst = bufs_out[i];
83 sym_op->auth.data.length = options->test_buffer_size;
84 sym_op->auth.data.offset = 0;
91 cperf_set_ops_cipher(struct rte_crypto_op **ops,
92 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
93 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
94 const struct cperf_options *options,
95 const struct cperf_test_vector *test_vector,
100 for (i = 0; i < nb_ops; i++) {
101 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
103 rte_crypto_op_attach_sym_session(ops[i], sess);
105 sym_op->m_src = bufs_in[i];
106 sym_op->m_dst = bufs_out[i];
108 /* cipher parameters */
109 if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
110 options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
111 options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
112 sym_op->cipher.data.length = options->test_buffer_size << 3;
114 sym_op->cipher.data.length = options->test_buffer_size;
116 sym_op->cipher.data.offset = 0;
119 if (options->test == CPERF_TEST_TYPE_VERIFY) {
120 for (i = 0; i < nb_ops; i++) {
121 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
122 uint8_t *, iv_offset);
124 memcpy(iv_ptr, test_vector->cipher_iv.data,
125 test_vector->cipher_iv.length);
134 cperf_set_ops_auth(struct rte_crypto_op **ops,
135 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
136 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
137 const struct cperf_options *options,
138 const struct cperf_test_vector *test_vector,
143 for (i = 0; i < nb_ops; i++) {
144 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
146 rte_crypto_op_attach_sym_session(ops[i], sess);
148 sym_op->m_src = bufs_in[i];
149 sym_op->m_dst = bufs_out[i];
151 if (test_vector->auth_iv.length) {
152 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
155 memcpy(iv_ptr, test_vector->auth_iv.data,
156 test_vector->auth_iv.length);
159 /* authentication parameters */
160 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
161 sym_op->auth.digest.data = test_vector->digest.data;
162 sym_op->auth.digest.phys_addr =
163 test_vector->digest.phys_addr;
164 sym_op->auth.digest.length = options->auth_digest_sz;
167 uint32_t offset = options->test_buffer_size;
168 struct rte_mbuf *buf, *tbuf;
170 if (options->out_of_place) {
174 while ((tbuf->next != NULL) &&
175 (offset >= tbuf->data_len)) {
176 offset -= tbuf->data_len;
182 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
184 sym_op->auth.digest.phys_addr =
185 rte_pktmbuf_mtophys_offset(buf, offset);
186 sym_op->auth.digest.length = options->auth_digest_sz;
187 sym_op->auth.aad.phys_addr = test_vector->aad.phys_addr;
188 sym_op->auth.aad.data = test_vector->aad.data;
192 if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
193 options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
194 options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
195 sym_op->auth.data.length = options->test_buffer_size << 3;
197 sym_op->auth.data.length = options->test_buffer_size;
199 sym_op->auth.data.offset = 0;
202 if (options->test == CPERF_TEST_TYPE_VERIFY) {
203 if (test_vector->auth_iv.length) {
204 for (i = 0; i < nb_ops; i++) {
205 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
206 uint8_t *, iv_offset);
208 memcpy(iv_ptr, test_vector->auth_iv.data,
209 test_vector->auth_iv.length);
217 cperf_set_ops_cipher_auth(struct rte_crypto_op **ops,
218 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
219 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
220 const struct cperf_options *options,
221 const struct cperf_test_vector *test_vector,
226 for (i = 0; i < nb_ops; i++) {
227 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
229 rte_crypto_op_attach_sym_session(ops[i], sess);
231 sym_op->m_src = bufs_in[i];
232 sym_op->m_dst = bufs_out[i];
234 /* cipher parameters */
235 if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
236 options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
237 options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
238 sym_op->cipher.data.length = options->test_buffer_size << 3;
240 sym_op->cipher.data.length = options->test_buffer_size;
242 sym_op->cipher.data.offset = 0;
244 /* authentication parameters */
245 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
246 sym_op->auth.digest.data = test_vector->digest.data;
247 sym_op->auth.digest.phys_addr =
248 test_vector->digest.phys_addr;
249 sym_op->auth.digest.length = options->auth_digest_sz;
252 uint32_t offset = options->test_buffer_size;
253 struct rte_mbuf *buf, *tbuf;
255 if (options->out_of_place) {
259 while ((tbuf->next != NULL) &&
260 (offset >= tbuf->data_len)) {
261 offset -= tbuf->data_len;
267 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
269 sym_op->auth.digest.phys_addr =
270 rte_pktmbuf_mtophys_offset(buf, offset);
271 sym_op->auth.digest.length = options->auth_digest_sz;
272 sym_op->auth.aad.phys_addr = test_vector->aad.phys_addr;
273 sym_op->auth.aad.data = test_vector->aad.data;
276 if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
277 options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
278 options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
279 sym_op->auth.data.length = options->test_buffer_size << 3;
281 sym_op->auth.data.length = options->test_buffer_size;
283 sym_op->auth.data.offset = 0;
286 if (options->test == CPERF_TEST_TYPE_VERIFY) {
287 for (i = 0; i < nb_ops; i++) {
288 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
289 uint8_t *, iv_offset);
291 memcpy(iv_ptr, test_vector->cipher_iv.data,
292 test_vector->cipher_iv.length);
293 if (test_vector->auth_iv.length) {
295 * Copy IV after the crypto operation and
298 iv_ptr += test_vector->cipher_iv.length;
299 memcpy(iv_ptr, test_vector->auth_iv.data,
300 test_vector->auth_iv.length);
310 cperf_set_ops_aead(struct rte_crypto_op **ops,
311 struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out,
312 uint16_t nb_ops, struct rte_cryptodev_sym_session *sess,
313 const struct cperf_options *options,
314 const struct cperf_test_vector *test_vector,
319 for (i = 0; i < nb_ops; i++) {
320 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
322 rte_crypto_op_attach_sym_session(ops[i], sess);
324 sym_op->m_src = bufs_in[i];
325 sym_op->m_dst = bufs_out[i];
327 /* cipher parameters */
328 sym_op->cipher.data.length = options->test_buffer_size;
329 sym_op->cipher.data.offset =
330 RTE_ALIGN_CEIL(options->auth_aad_sz, 16);
332 sym_op->auth.aad.data = rte_pktmbuf_mtod(bufs_in[i], uint8_t *);
333 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(bufs_in[i]);
335 /* authentication parameters */
336 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
337 sym_op->auth.digest.data = test_vector->digest.data;
338 sym_op->auth.digest.phys_addr =
339 test_vector->digest.phys_addr;
340 sym_op->auth.digest.length = options->auth_digest_sz;
343 uint32_t offset = sym_op->cipher.data.length +
344 sym_op->cipher.data.offset;
345 struct rte_mbuf *buf, *tbuf;
347 if (options->out_of_place) {
351 while ((tbuf->next != NULL) &&
352 (offset >= tbuf->data_len)) {
353 offset -= tbuf->data_len;
359 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
361 sym_op->auth.digest.phys_addr =
362 rte_pktmbuf_mtophys_offset(buf, offset);
364 sym_op->auth.digest.length = options->auth_digest_sz;
367 sym_op->auth.data.length = options->test_buffer_size;
368 sym_op->auth.data.offset = options->auth_aad_sz;
371 if (options->test == CPERF_TEST_TYPE_VERIFY) {
372 for (i = 0; i < nb_ops; i++) {
373 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
374 uint8_t *, iv_offset);
376 memcpy(iv_ptr, test_vector->cipher_iv.data,
377 test_vector->cipher_iv.length);
384 static struct rte_cryptodev_sym_session *
385 cperf_create_session(uint8_t dev_id,
386 const struct cperf_options *options,
387 const struct cperf_test_vector *test_vector,
390 struct rte_crypto_sym_xform cipher_xform;
391 struct rte_crypto_sym_xform auth_xform;
392 struct rte_cryptodev_sym_session *sess = NULL;
397 if (options->op_type == CPERF_CIPHER_ONLY) {
398 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
399 cipher_xform.next = NULL;
400 cipher_xform.cipher.algo = options->cipher_algo;
401 cipher_xform.cipher.op = options->cipher_op;
402 cipher_xform.cipher.iv.offset = iv_offset;
404 /* cipher different than null */
405 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
406 cipher_xform.cipher.key.data =
407 test_vector->cipher_key.data;
408 cipher_xform.cipher.key.length =
409 test_vector->cipher_key.length;
410 cipher_xform.cipher.iv.length =
411 test_vector->cipher_iv.length;
413 cipher_xform.cipher.key.data = NULL;
414 cipher_xform.cipher.key.length = 0;
415 cipher_xform.cipher.iv.length = 0;
417 /* create crypto session */
418 sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
422 } else if (options->op_type == CPERF_AUTH_ONLY) {
423 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
424 auth_xform.next = NULL;
425 auth_xform.auth.algo = options->auth_algo;
426 auth_xform.auth.op = options->auth_op;
428 /* auth different than null */
429 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
430 auth_xform.auth.digest_length =
431 options->auth_digest_sz;
432 auth_xform.auth.add_auth_data_length =
433 options->auth_aad_sz;
434 auth_xform.auth.key.length =
435 test_vector->auth_key.length;
436 auth_xform.auth.key.data = test_vector->auth_key.data;
437 auth_xform.auth.iv.length =
438 test_vector->auth_iv.length;
440 auth_xform.auth.digest_length = 0;
441 auth_xform.auth.add_auth_data_length = 0;
442 auth_xform.auth.key.length = 0;
443 auth_xform.auth.key.data = NULL;
444 auth_xform.auth.iv.length = 0;
446 /* create crypto session */
447 sess = rte_cryptodev_sym_session_create(dev_id, &auth_xform);
451 } else if (options->op_type == CPERF_CIPHER_THEN_AUTH
452 || options->op_type == CPERF_AUTH_THEN_CIPHER
453 || options->op_type == CPERF_AEAD) {
458 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
459 cipher_xform.next = NULL;
460 cipher_xform.cipher.algo = options->cipher_algo;
461 cipher_xform.cipher.op = options->cipher_op;
462 cipher_xform.cipher.iv.offset = iv_offset;
464 /* cipher different than null */
465 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
466 cipher_xform.cipher.key.data =
467 test_vector->cipher_key.data;
468 cipher_xform.cipher.key.length =
469 test_vector->cipher_key.length;
470 cipher_xform.cipher.iv.length =
471 test_vector->cipher_iv.length;
473 cipher_xform.cipher.key.data = NULL;
474 cipher_xform.cipher.key.length = 0;
475 cipher_xform.cipher.iv.length = 0;
481 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
482 auth_xform.next = NULL;
483 auth_xform.auth.algo = options->auth_algo;
484 auth_xform.auth.op = options->auth_op;
486 /* auth different than null */
487 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
488 auth_xform.auth.digest_length = options->auth_digest_sz;
489 auth_xform.auth.add_auth_data_length =
490 options->auth_aad_sz;
491 /* auth options for aes gcm */
492 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM &&
493 options->auth_algo == RTE_CRYPTO_AUTH_AES_GCM) {
494 auth_xform.auth.key.length = 0;
495 auth_xform.auth.key.data = NULL;
496 auth_xform.auth.iv.length = 0;
497 } else { /* auth options for others */
498 auth_xform.auth.key.length =
499 test_vector->auth_key.length;
500 auth_xform.auth.key.data =
501 test_vector->auth_key.data;
502 auth_xform.auth.iv.length =
503 test_vector->auth_iv.length;
506 auth_xform.auth.digest_length = 0;
507 auth_xform.auth.add_auth_data_length = 0;
508 auth_xform.auth.key.length = 0;
509 auth_xform.auth.key.data = NULL;
510 auth_xform.auth.iv.length = 0;
513 /* create crypto session for aes gcm */
514 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM) {
515 if (options->cipher_op ==
516 RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
517 cipher_xform.next = &auth_xform;
518 /* create crypto session */
519 sess = rte_cryptodev_sym_session_create(dev_id,
521 } else { /* decrypt */
522 auth_xform.next = &cipher_xform;
523 /* create crypto session */
524 sess = rte_cryptodev_sym_session_create(dev_id,
527 } else { /* create crypto session for other */
528 /* cipher then auth */
529 if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
530 cipher_xform.next = &auth_xform;
531 /* create crypto session */
532 sess = rte_cryptodev_sym_session_create(dev_id,
534 } else { /* auth then cipher */
535 auth_xform.next = &cipher_xform;
536 /* create crypto session */
537 sess = rte_cryptodev_sym_session_create(dev_id,
546 cperf_get_op_functions(const struct cperf_options *options,
547 struct cperf_op_fns *op_fns)
549 memset(op_fns, 0, sizeof(struct cperf_op_fns));
551 op_fns->sess_create = cperf_create_session;
553 if (options->op_type == CPERF_AEAD
554 || options->op_type == CPERF_AUTH_THEN_CIPHER
555 || options->op_type == CPERF_CIPHER_THEN_AUTH) {
556 if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_GCM &&
557 options->auth_algo == RTE_CRYPTO_AUTH_AES_GCM)
558 op_fns->populate_ops = cperf_set_ops_aead;
560 op_fns->populate_ops = cperf_set_ops_cipher_auth;
563 if (options->op_type == CPERF_AUTH_ONLY) {
564 if (options->auth_algo == RTE_CRYPTO_AUTH_NULL)
565 op_fns->populate_ops = cperf_set_ops_null_auth;
567 op_fns->populate_ops = cperf_set_ops_auth;
570 if (options->op_type == CPERF_CIPHER_ONLY) {
571 if (options->cipher_algo == RTE_CRYPTO_CIPHER_NULL)
572 op_fns->populate_ops = cperf_set_ops_null_cipher;
574 op_fns->populate_ops = cperf_set_ops_cipher;