1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2017 Intel Corporation
5 #include <rte_common.h>
6 #include <rte_hexdump.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_pause.h>
12 #include <rte_crypto.h>
13 #include <rte_cryptodev.h>
14 #include <rte_cryptodev_pmd.h>
17 #include "test_cryptodev.h"
18 #include "test_cryptodev_blockcipher.h"
19 #include "test_cryptodev_aes_test_vectors.h"
20 #include "test_cryptodev_des_test_vectors.h"
21 #include "test_cryptodev_hash_test_vectors.h"
24 test_blockcipher_one_case(const struct blockcipher_test_case
*t
,
25 struct rte_mempool
*mbuf_pool
,
26 struct rte_mempool
*op_mpool
,
27 struct rte_mempool
*sess_mpool
,
28 struct rte_mempool
*sess_priv_mpool
,
33 struct rte_mbuf
*ibuf
= NULL
;
34 struct rte_mbuf
*obuf
= NULL
;
35 struct rte_mbuf
*iobuf
;
36 struct rte_crypto_sym_xform
*cipher_xform
= NULL
;
37 struct rte_crypto_sym_xform
*auth_xform
= NULL
;
38 struct rte_crypto_sym_xform
*init_xform
= NULL
;
39 struct rte_crypto_sym_op
*sym_op
= NULL
;
40 struct rte_crypto_op
*op
= NULL
;
41 struct rte_cryptodev_info dev_info
;
42 struct rte_cryptodev_sym_session
*sess
= NULL
;
44 int status
= TEST_SUCCESS
;
45 const struct blockcipher_test_data
*tdata
= t
->test_data
;
46 uint8_t cipher_key
[tdata
->cipher_key
.len
];
47 uint8_t auth_key
[tdata
->auth_key
.len
];
48 uint32_t buf_len
= tdata
->ciphertext
.len
;
49 uint32_t digest_len
= 0;
51 uint8_t src_pattern
= 0xa5;
52 uint8_t dst_pattern
= 0xb6;
53 uint8_t tmp_src_buf
[MBUF_SIZE
];
54 uint8_t tmp_dst_buf
[MBUF_SIZE
];
56 int openssl_pmd
= rte_cryptodev_driver_id_get(
57 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD
));
58 int ccp_pmd
= rte_cryptodev_driver_id_get(
59 RTE_STR(CRYPTODEV_NAME_CCP_PMD
));
60 int scheduler_pmd
= rte_cryptodev_driver_id_get(
61 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD
));
62 int armv8_pmd
= rte_cryptodev_driver_id_get(
63 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD
));
64 int aesni_mb_pmd
= rte_cryptodev_driver_id_get(
65 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD
));
66 int qat_pmd
= rte_cryptodev_driver_id_get(
67 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD
));
68 int dpaa2_sec_pmd
= rte_cryptodev_driver_id_get(
69 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD
));
70 int dpaa_sec_pmd
= rte_cryptodev_driver_id_get(
71 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD
));
72 int caam_jr_pmd
= rte_cryptodev_driver_id_get(
73 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD
));
74 int mrvl_pmd
= rte_cryptodev_driver_id_get(
75 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD
));
76 int virtio_pmd
= rte_cryptodev_driver_id_get(
77 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD
));
78 int octeontx_pmd
= rte_cryptodev_driver_id_get(
79 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD
));
82 uint32_t nb_iterates
= 0;
84 rte_cryptodev_info_get(dev_id
, &dev_info
);
86 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SG
) {
87 uint64_t feat_flags
= dev_info
.feature_flags
;
88 uint64_t oop_flag
= RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT
;
90 if (t
->feature_mask
&& BLOCKCIPHER_TEST_FEATURE_OOP
) {
91 if (!(feat_flags
& oop_flag
)) {
92 printf("Device doesn't support out-of-place "
93 "scatter-gather in input mbuf. "
98 if (!(feat_flags
& RTE_CRYPTODEV_FF_IN_PLACE_SGL
)) {
99 printf("Device doesn't support in-place "
100 "scatter-gather mbufs. "
109 if (tdata
->cipher_key
.len
)
110 memcpy(cipher_key
, tdata
->cipher_key
.data
,
111 tdata
->cipher_key
.len
);
112 if (tdata
->auth_key
.len
)
113 memcpy(auth_key
, tdata
->auth_key
.data
,
114 tdata
->auth_key
.len
);
116 if (driver_id
== dpaa2_sec_pmd
||
117 driver_id
== dpaa_sec_pmd
||
118 driver_id
== caam_jr_pmd
||
119 driver_id
== qat_pmd
||
120 driver_id
== openssl_pmd
||
121 driver_id
== armv8_pmd
||
122 driver_id
== mrvl_pmd
||
123 driver_id
== ccp_pmd
||
124 driver_id
== virtio_pmd
||
125 driver_id
== octeontx_pmd
) { /* Fall through */
126 digest_len
= tdata
->digest
.len
;
127 } else if (driver_id
== aesni_mb_pmd
||
128 driver_id
== scheduler_pmd
) {
129 digest_len
= tdata
->digest
.truncated_len
;
131 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
132 "line %u FAILED: %s",
133 __LINE__
, "Unsupported PMD type");
134 status
= TEST_FAILED
;
139 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH
)
140 buf_len
+= digest_len
;
142 /* for contiguous mbuf, nb_segs is 1 */
143 ibuf
= create_segmented_mbuf(mbuf_pool
,
144 tdata
->ciphertext
.len
, nb_segs
, src_pattern
);
146 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
147 "line %u FAILED: %s",
148 __LINE__
, "Cannot create source mbuf");
149 status
= TEST_FAILED
;
153 /* only encryption requires plaintext.data input,
154 * decryption/(digest gen)/(digest verify) use ciphertext.data
157 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_ENCRYPT
)
158 pktmbuf_write(ibuf
, 0, tdata
->plaintext
.len
,
159 tdata
->plaintext
.data
);
161 pktmbuf_write(ibuf
, 0, tdata
->ciphertext
.len
,
162 tdata
->ciphertext
.data
);
164 buf_p
= rte_pktmbuf_append(ibuf
, digest_len
);
165 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_VERIFY
)
166 rte_memcpy(buf_p
, tdata
->digest
.data
, digest_len
);
168 memset(buf_p
, 0, digest_len
);
170 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_OOP
) {
171 obuf
= rte_pktmbuf_alloc(mbuf_pool
);
173 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
174 "FAILED: %s", __LINE__
,
175 "Allocation of rte_mbuf failed");
176 status
= TEST_FAILED
;
179 memset(obuf
->buf_addr
, dst_pattern
, obuf
->buf_len
);
181 buf_p
= rte_pktmbuf_append(obuf
, buf_len
);
183 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
184 "FAILED: %s", __LINE__
,
185 "No room to append mbuf");
186 status
= TEST_FAILED
;
189 memset(buf_p
, 0, buf_len
);
192 /* Generate Crypto op data structure */
193 op
= rte_crypto_op_alloc(op_mpool
, RTE_CRYPTO_OP_TYPE_SYMMETRIC
);
195 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
196 "line %u FAILED: %s",
197 __LINE__
, "Failed to allocate symmetric crypto "
199 status
= TEST_FAILED
;
207 struct rte_mbuf
*tmp_buf
= ibuf
;
212 rte_pktmbuf_reset(ibuf
);
213 rte_pktmbuf_reset(obuf
);
215 rte_pktmbuf_append(ibuf
, tdata
->ciphertext
.len
);
217 /* only encryption requires plaintext.data input,
218 * decryption/(digest gen)/(digest verify) use ciphertext.data
221 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_ENCRYPT
)
222 pktmbuf_write(ibuf
, 0, tdata
->plaintext
.len
,
223 tdata
->plaintext
.data
);
225 pktmbuf_write(ibuf
, 0, tdata
->ciphertext
.len
,
226 tdata
->ciphertext
.data
);
228 buf_p
= rte_pktmbuf_append(ibuf
, digest_len
);
229 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_VERIFY
)
230 rte_memcpy(buf_p
, tdata
->digest
.data
, digest_len
);
232 memset(buf_p
, 0, digest_len
);
234 memset(obuf
->buf_addr
, dst_pattern
, obuf
->buf_len
);
236 buf_p
= rte_pktmbuf_append(obuf
, buf_len
);
238 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
239 "FAILED: %s", __LINE__
,
240 "No room to append mbuf");
241 status
= TEST_FAILED
;
244 memset(buf_p
, 0, buf_len
);
247 sym_op
->m_src
= ibuf
;
249 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_OOP
) {
250 sym_op
->m_dst
= obuf
;
253 sym_op
->m_dst
= NULL
;
257 /* sessionless op requires allocate xform using
258 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
261 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
) {
262 uint32_t n_xforms
= 0;
264 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_CIPHER
)
266 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH
)
269 if (rte_crypto_op_sym_xforms_alloc(op
, n_xforms
)
271 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
272 "FAILED: %s", __LINE__
, "Failed to "
273 "allocate space for crypto transforms");
274 status
= TEST_FAILED
;
278 cipher_xform
= rte_zmalloc(NULL
,
279 sizeof(struct rte_crypto_sym_xform
), 0);
281 auth_xform
= rte_zmalloc(NULL
,
282 sizeof(struct rte_crypto_sym_xform
), 0);
284 if (!cipher_xform
|| !auth_xform
) {
285 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
286 "FAILED: %s", __LINE__
, "Failed to "
287 "allocate memory for crypto transforms");
288 status
= TEST_FAILED
;
293 /* preparing xform, for sessioned op, init_xform is initialized
294 * here and later as param in rte_cryptodev_sym_session_create() call
296 if (t
->op_mask
== BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN
) {
297 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
) {
298 cipher_xform
= op
->sym
->xform
;
299 auth_xform
= cipher_xform
->next
;
300 auth_xform
->next
= NULL
;
302 cipher_xform
->next
= auth_xform
;
303 auth_xform
->next
= NULL
;
304 init_xform
= cipher_xform
;
306 } else if (t
->op_mask
== BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC
) {
307 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
) {
308 auth_xform
= op
->sym
->xform
;
309 cipher_xform
= auth_xform
->next
;
310 cipher_xform
->next
= NULL
;
312 auth_xform
->next
= cipher_xform
;
313 cipher_xform
->next
= NULL
;
314 init_xform
= auth_xform
;
316 } else if ((t
->op_mask
== BLOCKCIPHER_TEST_OP_ENCRYPT
) ||
317 (t
->op_mask
== BLOCKCIPHER_TEST_OP_DECRYPT
)) {
318 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
)
319 cipher_xform
= op
->sym
->xform
;
321 init_xform
= cipher_xform
;
322 cipher_xform
->next
= NULL
;
323 } else if ((t
->op_mask
== BLOCKCIPHER_TEST_OP_AUTH_GEN
) ||
324 (t
->op_mask
== BLOCKCIPHER_TEST_OP_AUTH_VERIFY
)) {
325 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
)
326 auth_xform
= op
->sym
->xform
;
328 init_xform
= auth_xform
;
329 auth_xform
->next
= NULL
;
331 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
332 "line %u FAILED: %s",
333 __LINE__
, "Unrecognized operation");
334 status
= TEST_FAILED
;
338 /*configure xforms & sym_op cipher and auth data*/
339 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_CIPHER
) {
340 cipher_xform
->type
= RTE_CRYPTO_SYM_XFORM_CIPHER
;
341 cipher_xform
->cipher
.algo
= tdata
->crypto_algo
;
342 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_ENCRYPT
)
343 cipher_xform
->cipher
.op
=
344 RTE_CRYPTO_CIPHER_OP_ENCRYPT
;
346 cipher_xform
->cipher
.op
=
347 RTE_CRYPTO_CIPHER_OP_DECRYPT
;
348 cipher_xform
->cipher
.key
.data
= cipher_key
;
349 cipher_xform
->cipher
.key
.length
= tdata
->cipher_key
.len
;
350 cipher_xform
->cipher
.iv
.offset
= IV_OFFSET
;
351 cipher_xform
->cipher
.iv
.length
= tdata
->iv
.len
;
353 sym_op
->cipher
.data
.offset
= tdata
->cipher_offset
;
354 sym_op
->cipher
.data
.length
= tdata
->ciphertext
.len
-
355 tdata
->cipher_offset
;
356 rte_memcpy(rte_crypto_op_ctod_offset(op
, uint8_t *, IV_OFFSET
),
361 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH
) {
362 uint32_t digest_offset
= tdata
->ciphertext
.len
;
364 auth_xform
->type
= RTE_CRYPTO_SYM_XFORM_AUTH
;
365 auth_xform
->auth
.algo
= tdata
->auth_algo
;
366 auth_xform
->auth
.key
.length
= tdata
->auth_key
.len
;
367 auth_xform
->auth
.key
.data
= auth_key
;
368 auth_xform
->auth
.digest_length
= digest_len
;
370 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_GEN
) {
371 auth_xform
->auth
.op
= RTE_CRYPTO_AUTH_OP_GENERATE
;
372 sym_op
->auth
.digest
.data
= pktmbuf_mtod_offset
373 (iobuf
, digest_offset
);
374 sym_op
->auth
.digest
.phys_addr
=
375 pktmbuf_iova_offset(iobuf
,
378 auth_xform
->auth
.op
= RTE_CRYPTO_AUTH_OP_VERIFY
;
379 sym_op
->auth
.digest
.data
= pktmbuf_mtod_offset
380 (sym_op
->m_src
, digest_offset
);
381 sym_op
->auth
.digest
.phys_addr
=
382 pktmbuf_iova_offset(sym_op
->m_src
,
386 sym_op
->auth
.data
.offset
= tdata
->auth_offset
;
387 sym_op
->auth
.data
.length
= tdata
->ciphertext
.len
-
392 * Create session for sessioned op. For mbuf iteration test,
393 * skip the session creation for the second iteration.
395 if (!(t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
) &&
397 sess
= rte_cryptodev_sym_session_create(sess_mpool
);
399 rte_cryptodev_sym_session_init(dev_id
, sess
, init_xform
,
402 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
403 "FAILED: %s", __LINE__
,
404 "Session creation failed");
405 status
= TEST_FAILED
;
409 /* attach symmetric crypto session to crypto operations */
410 rte_crypto_op_attach_sym_session(op
, sess
);
413 debug_hexdump(stdout
, "m_src(before):",
414 sym_op
->m_src
->buf_addr
, sym_op
->m_src
->buf_len
);
415 rte_memcpy(tmp_src_buf
, sym_op
->m_src
->buf_addr
,
416 sym_op
->m_src
->buf_len
);
417 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_OOP
) {
418 debug_hexdump(stdout
, "m_dst(before):",
419 sym_op
->m_dst
->buf_addr
, sym_op
->m_dst
->buf_len
);
420 rte_memcpy(tmp_dst_buf
, sym_op
->m_dst
->buf_addr
,
421 sym_op
->m_dst
->buf_len
);
424 /* Process crypto operation */
425 if (rte_cryptodev_enqueue_burst(dev_id
, 0, &op
, 1) != 1) {
426 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
427 "line %u FAILED: %s",
428 __LINE__
, "Error sending packet for encryption");
429 status
= TEST_FAILED
;
435 while (rte_cryptodev_dequeue_burst(dev_id
, 0, &op
, 1) == 0)
439 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
440 "line %u FAILED: %s",
441 __LINE__
, "Failed to process sym crypto op");
442 status
= TEST_FAILED
;
446 debug_hexdump(stdout
, "m_src(after):",
447 sym_op
->m_src
->buf_addr
, sym_op
->m_src
->buf_len
);
448 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_OOP
)
449 debug_hexdump(stdout
, "m_dst(after):",
450 sym_op
->m_dst
->buf_addr
, sym_op
->m_dst
->buf_len
);
453 if (op
->status
!= RTE_CRYPTO_OP_STATUS_SUCCESS
) {
454 if ((t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_VERIFY
) &&
455 (op
->status
== RTE_CRYPTO_OP_STATUS_AUTH_FAILED
))
456 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
457 "FAILED: Digest verification failed "
458 "(0x%X)", __LINE__
, op
->status
);
460 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
461 "FAILED: Operation failed "
462 "(0x%X)", __LINE__
, op
->status
);
463 status
= TEST_FAILED
;
467 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_CIPHER
) {
468 uint8_t buffer
[2048];
469 const uint8_t *compare_ref
;
470 uint32_t compare_len
;
472 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_ENCRYPT
) {
473 compare_ref
= tdata
->ciphertext
.data
+
474 tdata
->cipher_offset
;
475 compare_len
= tdata
->ciphertext
.len
-
476 tdata
->cipher_offset
;
478 compare_ref
= tdata
->plaintext
.data
+
479 tdata
->cipher_offset
;
480 compare_len
= tdata
->plaintext
.len
-
481 tdata
->cipher_offset
;
484 if (memcmp(rte_pktmbuf_read(iobuf
, tdata
->cipher_offset
,
485 compare_len
, buffer
), compare_ref
,
487 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
488 "FAILED: %s", __LINE__
,
489 "Crypto data not as expected");
490 status
= TEST_FAILED
;
495 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_GEN
) {
496 uint8_t *auth_res
= pktmbuf_mtod_offset(iobuf
,
497 tdata
->ciphertext
.len
);
499 if (memcmp(auth_res
, tdata
->digest
.data
, digest_len
)) {
500 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "line %u "
501 "FAILED: %s", __LINE__
, "Generated "
502 "digest data not as expected");
503 status
= TEST_FAILED
;
508 /* The only parts that should have changed in the buffer are
509 * plaintext/ciphertext and digest.
510 * In OOP only the dest buffer should change.
512 if (t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_OOP
) {
513 struct rte_mbuf
*mbuf
;
515 uint32_t head_unchanged_len
, changed_len
= 0;
517 uint32_t hdroom_used
= 0, tlroom_used
= 0;
520 mbuf
= sym_op
->m_src
;
522 * Crypto PMDs specify the headroom & tailroom it would use
523 * when processing the crypto operation. PMD is free to modify
524 * this space, and so the verification check should skip that
527 hdroom_used
= dev_info
.min_mbuf_headroom_req
;
528 tlroom_used
= dev_info
.min_mbuf_tailroom_req
;
531 hdroom
= rte_pktmbuf_headroom(mbuf
);
533 head_unchanged_len
= mbuf
->buf_len
;
535 for (i
= 0; i
< mbuf
->buf_len
; i
++) {
537 /* Skip headroom used by PMD */
538 if (i
== hdroom
- hdroom_used
)
541 /* Skip tailroom used by PMD */
542 if (i
== (hdroom
+ mbuf
->data_len
))
545 value
= *((uint8_t *)(mbuf
->buf_addr
)+i
);
546 if (value
!= tmp_src_buf
[i
]) {
547 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
548 "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
549 __LINE__
, value
, tmp_src_buf
[i
]);
550 status
= TEST_FAILED
;
555 mbuf
= sym_op
->m_dst
;
556 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH
) {
557 head_unchanged_len
= hdroom
+ sym_op
->auth
.data
.offset
;
558 changed_len
= sym_op
->auth
.data
.length
;
559 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_GEN
)
560 changed_len
+= digest_len
;
563 head_unchanged_len
= hdroom
+
564 sym_op
->cipher
.data
.offset
;
565 changed_len
= sym_op
->cipher
.data
.length
;
568 for (i
= 0; i
< mbuf
->buf_len
; i
++) {
569 if (i
== head_unchanged_len
)
571 value
= *((uint8_t *)(mbuf
->buf_addr
)+i
);
572 if (value
!= tmp_dst_buf
[i
]) {
573 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
574 "line %u FAILED: OOP dst outer mbuf data "
575 "(0x%x) not as expected (0x%x)",
576 __LINE__
, value
, tmp_dst_buf
[i
]);
577 status
= TEST_FAILED
;
587 /* In-place operation */
588 struct rte_mbuf
*mbuf
;
590 uint32_t head_unchanged_len
= 0, changed_len
= 0;
592 uint32_t hdroom_used
= 0, tlroom_used
= 0;
596 * Crypto PMDs specify the headroom & tailroom it would use
597 * when processing the crypto operation. PMD is free to modify
598 * this space, and so the verification check should skip that
601 hdroom_used
= dev_info
.min_mbuf_headroom_req
;
602 tlroom_used
= dev_info
.min_mbuf_tailroom_req
;
604 mbuf
= sym_op
->m_src
;
607 hdroom
= rte_pktmbuf_headroom(mbuf
);
609 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_CIPHER
) {
610 head_unchanged_len
= hdroom
+
611 sym_op
->cipher
.data
.offset
;
612 changed_len
= sym_op
->cipher
.data
.length
;
615 head_unchanged_len
= hdroom
+
616 sym_op
->auth
.data
.offset
+
617 sym_op
->auth
.data
.length
;
621 if (t
->op_mask
& BLOCKCIPHER_TEST_OP_AUTH_GEN
)
622 changed_len
+= digest_len
;
624 for (i
= 0; i
< mbuf
->buf_len
; i
++) {
626 /* Skip headroom used by PMD */
627 if (i
== hdroom
- hdroom_used
)
630 if (i
== head_unchanged_len
)
633 /* Skip tailroom used by PMD */
634 if (i
== (hdroom
+ mbuf
->data_len
))
637 value
= *((uint8_t *)(mbuf
->buf_addr
)+i
);
638 if (value
!= tmp_src_buf
[i
]) {
639 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
,
640 "line %u FAILED: outer mbuf data (0x%x) "
641 "not as expected (0x%x)",
642 __LINE__
, value
, tmp_src_buf
[i
]);
643 status
= TEST_FAILED
;
649 snprintf(test_msg
, BLOCKCIPHER_TEST_MSG_LEN
, "PASS");
652 if (!(t
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_SESSIONLESS
)) {
654 rte_cryptodev_sym_session_clear(dev_id
, sess
);
655 rte_cryptodev_sym_session_free(sess
);
658 rte_free(cipher_xform
);
660 rte_free(auth_xform
);
664 rte_crypto_op_free(op
);
667 rte_pktmbuf_free(obuf
);
670 rte_pktmbuf_free(ibuf
);
676 test_blockcipher_all_tests(struct rte_mempool
*mbuf_pool
,
677 struct rte_mempool
*op_mpool
,
678 struct rte_mempool
*sess_mpool
,
679 struct rte_mempool
*sess_priv_mpool
,
682 enum blockcipher_test_type test_type
)
684 int status
, overall_status
= TEST_SUCCESS
;
685 uint32_t i
, test_index
= 0;
686 char test_msg
[BLOCKCIPHER_TEST_MSG_LEN
+ 1];
687 uint32_t n_test_cases
= 0;
688 uint32_t target_pmd_mask
= 0;
689 const struct blockcipher_test_case
*tcs
= NULL
;
691 int openssl_pmd
= rte_cryptodev_driver_id_get(
692 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD
));
693 int ccp_pmd
= rte_cryptodev_driver_id_get(
694 RTE_STR(CRYPTODEV_NAME_CCP_PMD
));
695 int dpaa2_sec_pmd
= rte_cryptodev_driver_id_get(
696 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD
));
697 int dpaa_sec_pmd
= rte_cryptodev_driver_id_get(
698 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD
));
699 int caam_jr_pmd
= rte_cryptodev_driver_id_get(
700 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD
));
701 int scheduler_pmd
= rte_cryptodev_driver_id_get(
702 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD
));
703 int armv8_pmd
= rte_cryptodev_driver_id_get(
704 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD
));
705 int aesni_mb_pmd
= rte_cryptodev_driver_id_get(
706 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD
));
707 int qat_pmd
= rte_cryptodev_driver_id_get(
708 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD
));
709 int mrvl_pmd
= rte_cryptodev_driver_id_get(
710 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD
));
711 int virtio_pmd
= rte_cryptodev_driver_id_get(
712 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD
));
713 int octeontx_pmd
= rte_cryptodev_driver_id_get(
714 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD
));
717 case BLKCIPHER_AES_CHAIN_TYPE
:
718 n_test_cases
= sizeof(aes_chain_test_cases
) /
719 sizeof(aes_chain_test_cases
[0]);
720 tcs
= aes_chain_test_cases
;
722 case BLKCIPHER_AES_CIPHERONLY_TYPE
:
723 n_test_cases
= sizeof(aes_cipheronly_test_cases
) /
724 sizeof(aes_cipheronly_test_cases
[0]);
725 tcs
= aes_cipheronly_test_cases
;
727 case BLKCIPHER_AES_DOCSIS_TYPE
:
728 n_test_cases
= sizeof(aes_docsis_test_cases
) /
729 sizeof(aes_docsis_test_cases
[0]);
730 tcs
= aes_docsis_test_cases
;
732 case BLKCIPHER_3DES_CHAIN_TYPE
:
733 n_test_cases
= sizeof(triple_des_chain_test_cases
) /
734 sizeof(triple_des_chain_test_cases
[0]);
735 tcs
= triple_des_chain_test_cases
;
737 case BLKCIPHER_3DES_CIPHERONLY_TYPE
:
738 n_test_cases
= sizeof(triple_des_cipheronly_test_cases
) /
739 sizeof(triple_des_cipheronly_test_cases
[0]);
740 tcs
= triple_des_cipheronly_test_cases
;
742 case BLKCIPHER_DES_CIPHERONLY_TYPE
:
743 n_test_cases
= sizeof(des_cipheronly_test_cases
) /
744 sizeof(des_cipheronly_test_cases
[0]);
745 tcs
= des_cipheronly_test_cases
;
747 case BLKCIPHER_DES_DOCSIS_TYPE
:
748 n_test_cases
= sizeof(des_docsis_test_cases
) /
749 sizeof(des_docsis_test_cases
[0]);
750 tcs
= des_docsis_test_cases
;
752 case BLKCIPHER_AUTHONLY_TYPE
:
753 n_test_cases
= sizeof(hash_test_cases
) /
754 sizeof(hash_test_cases
[0]);
755 tcs
= hash_test_cases
;
761 if (driver_id
== aesni_mb_pmd
)
762 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_MB
;
763 else if (driver_id
== qat_pmd
)
764 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_QAT
;
765 else if (driver_id
== openssl_pmd
)
766 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL
;
767 else if (driver_id
== armv8_pmd
)
768 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_ARMV8
;
769 else if (driver_id
== scheduler_pmd
)
770 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER
;
771 else if (driver_id
== dpaa2_sec_pmd
)
772 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC
;
773 else if (driver_id
== ccp_pmd
)
774 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_CCP
;
775 else if (driver_id
== dpaa_sec_pmd
)
776 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC
;
777 else if (driver_id
== caam_jr_pmd
)
778 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_CAAM_JR
;
779 else if (driver_id
== mrvl_pmd
)
780 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_MVSAM
;
781 else if (driver_id
== virtio_pmd
)
782 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
;
783 else if (driver_id
== octeontx_pmd
)
784 target_pmd_mask
= BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX
;
786 TEST_ASSERT(0, "Unrecognized cryptodev type");
788 for (i
= 0; i
< n_test_cases
; i
++) {
789 const struct blockcipher_test_case
*tc
= &tcs
[i
];
791 if (!(tc
->pmd_mask
& target_pmd_mask
))
794 status
= test_blockcipher_one_case(tc
, mbuf_pool
, op_mpool
,
795 sess_mpool
, sess_priv_mpool
, dev_id
, driver_id
,
798 printf(" %u) TestCase %s %s\n", test_index
++,
799 tc
->test_descr
, test_msg
);
801 if (status
!= TEST_SUCCESS
) {
802 if (overall_status
== TEST_SUCCESS
)
803 overall_status
= status
;
805 if (tc
->feature_mask
& BLOCKCIPHER_TEST_FEATURE_STOPPER
)
810 return overall_status
;