New upstream version 18.02
[deb_dpdk.git] / test / test / test_cryptodev_blockcipher.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation
3  */
4
5 #include <rte_common.h>
6 #include <rte_hexdump.h>
7 #include <rte_mbuf.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_pause.h>
11
12 #include <rte_crypto.h>
13 #include <rte_cryptodev.h>
14 #include <rte_cryptodev_pmd.h>
15
16 #include "test.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"
22
23 static int
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         uint8_t dev_id,
29         int driver_id,
30         char *test_msg)
31 {
32         struct rte_mbuf *ibuf = NULL;
33         struct rte_mbuf *obuf = NULL;
34         struct rte_mbuf *iobuf;
35         struct rte_crypto_sym_xform *cipher_xform = NULL;
36         struct rte_crypto_sym_xform *auth_xform = NULL;
37         struct rte_crypto_sym_xform *init_xform = NULL;
38         struct rte_crypto_sym_op *sym_op = NULL;
39         struct rte_crypto_op *op = NULL;
40         struct rte_cryptodev_info dev_info;
41         struct rte_cryptodev_sym_session *sess = NULL;
42
43         int status = TEST_SUCCESS;
44         const struct blockcipher_test_data *tdata = t->test_data;
45         uint8_t cipher_key[tdata->cipher_key.len];
46         uint8_t auth_key[tdata->auth_key.len];
47         uint32_t buf_len = tdata->ciphertext.len;
48         uint32_t digest_len = 0;
49         char *buf_p = NULL;
50         uint8_t src_pattern = 0xa5;
51         uint8_t dst_pattern = 0xb6;
52         uint8_t tmp_src_buf[MBUF_SIZE];
53         uint8_t tmp_dst_buf[MBUF_SIZE];
54
55         int openssl_pmd = rte_cryptodev_driver_id_get(
56                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
57         int scheduler_pmd = rte_cryptodev_driver_id_get(
58                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
59         int armv8_pmd = rte_cryptodev_driver_id_get(
60                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
61         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
62                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
63         int qat_pmd = rte_cryptodev_driver_id_get(
64                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
65         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
66                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
67         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
68                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
69         int mrvl_pmd = rte_cryptodev_driver_id_get(
70                         RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
71
72         int nb_segs = 1;
73
74         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
75                 rte_cryptodev_info_get(dev_id, &dev_info);
76                 if (!(dev_info.feature_flags &
77                                 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
78                         printf("Device doesn't support scatter-gather. "
79                                         "Test Skipped.\n");
80                         return 0;
81                 }
82                 nb_segs = 3;
83         }
84
85         if (tdata->cipher_key.len)
86                 memcpy(cipher_key, tdata->cipher_key.data,
87                         tdata->cipher_key.len);
88         if (tdata->auth_key.len)
89                 memcpy(auth_key, tdata->auth_key.data,
90                         tdata->auth_key.len);
91
92         if (driver_id == dpaa2_sec_pmd ||
93                         driver_id == dpaa_sec_pmd ||
94                         driver_id == qat_pmd ||
95                         driver_id == openssl_pmd ||
96                         driver_id == armv8_pmd ||
97                         driver_id == mrvl_pmd) { /* Fall through */
98                 digest_len = tdata->digest.len;
99         } else if (driver_id == aesni_mb_pmd ||
100                         driver_id == scheduler_pmd) {
101                 digest_len = tdata->digest.truncated_len;
102         } else {
103                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
104                         "line %u FAILED: %s",
105                         __LINE__, "Unsupported PMD type");
106                 status = TEST_FAILED;
107                 goto error_exit;
108         }
109
110         /* preparing data */
111         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
112                 buf_len += digest_len;
113
114         /* for contiguous mbuf, nb_segs is 1 */
115         ibuf = create_segmented_mbuf(mbuf_pool,
116                         tdata->ciphertext.len, nb_segs, src_pattern);
117         if (ibuf == NULL) {
118                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
119                         "line %u FAILED: %s",
120                         __LINE__, "Cannot create source mbuf");
121                 status = TEST_FAILED;
122                 goto error_exit;
123         }
124
125         /* only encryption requires plaintext.data input,
126          * decryption/(digest gen)/(digest verify) use ciphertext.data
127          * to be computed
128          */
129         if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
130                 pktmbuf_write(ibuf, 0, tdata->plaintext.len,
131                                 tdata->plaintext.data);
132         else
133                 pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
134                                 tdata->ciphertext.data);
135
136         buf_p = rte_pktmbuf_append(ibuf, digest_len);
137         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
138                 rte_memcpy(buf_p, tdata->digest.data, digest_len);
139         else
140                 memset(buf_p, 0, digest_len);
141
142         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
143                 obuf = rte_pktmbuf_alloc(mbuf_pool);
144                 if (!obuf) {
145                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
146                                 "FAILED: %s", __LINE__,
147                                 "Allocation of rte_mbuf failed");
148                         status = TEST_FAILED;
149                         goto error_exit;
150                 }
151                 memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
152
153                 buf_p = rte_pktmbuf_append(obuf, buf_len);
154                 if (!buf_p) {
155                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
156                                 "FAILED: %s", __LINE__,
157                                 "No room to append mbuf");
158                         status = TEST_FAILED;
159                         goto error_exit;
160                 }
161                 memset(buf_p, 0, buf_len);
162         }
163
164         /* Generate Crypto op data structure */
165         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
166         if (!op) {
167                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
168                         "line %u FAILED: %s",
169                         __LINE__, "Failed to allocate symmetric crypto "
170                         "operation struct");
171                 status = TEST_FAILED;
172                 goto error_exit;
173         }
174
175         sym_op = op->sym;
176
177         sym_op->m_src = ibuf;
178
179         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
180                 sym_op->m_dst = obuf;
181                 iobuf = obuf;
182         } else {
183                 sym_op->m_dst = NULL;
184                 iobuf = ibuf;
185         }
186
187         /* sessionless op requires allocate xform using
188          * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
189          * is used
190          */
191         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
192                 uint32_t n_xforms = 0;
193
194                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
195                         n_xforms++;
196                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
197                         n_xforms++;
198
199                 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
200                         == NULL) {
201                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
202                                 "FAILED: %s", __LINE__, "Failed to "
203                                 "allocate space for crypto transforms");
204                         status = TEST_FAILED;
205                         goto error_exit;
206                 }
207         } else {
208                 cipher_xform = rte_zmalloc(NULL,
209                         sizeof(struct rte_crypto_sym_xform), 0);
210
211                 auth_xform = rte_zmalloc(NULL,
212                         sizeof(struct rte_crypto_sym_xform), 0);
213
214                 if (!cipher_xform || !auth_xform) {
215                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
216                                 "FAILED: %s", __LINE__, "Failed to "
217                                 "allocate memory for crypto transforms");
218                         status = TEST_FAILED;
219                         goto error_exit;
220                 }
221         }
222
223         /* preparing xform, for sessioned op, init_xform is initialized
224          * here and later as param in rte_cryptodev_sym_session_create() call
225          */
226         if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
227                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
228                         cipher_xform = op->sym->xform;
229                         auth_xform = cipher_xform->next;
230                         auth_xform->next = NULL;
231                 } else {
232                         cipher_xform->next = auth_xform;
233                         auth_xform->next = NULL;
234                         init_xform = cipher_xform;
235                 }
236         } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
237                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
238                         auth_xform = op->sym->xform;
239                         cipher_xform = auth_xform->next;
240                         cipher_xform->next = NULL;
241                 } else {
242                         auth_xform->next = cipher_xform;
243                         cipher_xform->next = NULL;
244                         init_xform = auth_xform;
245                 }
246         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
247                         (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
248                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
249                         cipher_xform = op->sym->xform;
250                 else
251                         init_xform = cipher_xform;
252                 cipher_xform->next = NULL;
253         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
254                         (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
255                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
256                         auth_xform = op->sym->xform;
257                 else
258                         init_xform = auth_xform;
259                 auth_xform->next = NULL;
260         } else {
261                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
262                         "line %u FAILED: %s",
263                         __LINE__, "Unrecognized operation");
264                 status = TEST_FAILED;
265                 goto error_exit;
266         }
267
268         /*configure xforms & sym_op cipher and auth data*/
269         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
270                 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
271                 cipher_xform->cipher.algo = tdata->crypto_algo;
272                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
273                         cipher_xform->cipher.op =
274                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
275                 else
276                         cipher_xform->cipher.op =
277                                 RTE_CRYPTO_CIPHER_OP_DECRYPT;
278                 cipher_xform->cipher.key.data = cipher_key;
279                 cipher_xform->cipher.key.length = tdata->cipher_key.len;
280                 cipher_xform->cipher.iv.offset = IV_OFFSET;
281                 cipher_xform->cipher.iv.length = tdata->iv.len;
282
283                 sym_op->cipher.data.offset = 0;
284                 sym_op->cipher.data.length = tdata->ciphertext.len;
285                 rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
286                                 tdata->iv.data,
287                                 tdata->iv.len);
288         }
289
290         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
291                 uint32_t digest_offset = tdata->ciphertext.len;
292
293                 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
294                 auth_xform->auth.algo = tdata->auth_algo;
295                 auth_xform->auth.key.length = tdata->auth_key.len;
296                 auth_xform->auth.key.data = auth_key;
297                 auth_xform->auth.digest_length = digest_len;
298
299                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
300                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
301                         sym_op->auth.digest.data = pktmbuf_mtod_offset
302                                 (iobuf, digest_offset);
303                         sym_op->auth.digest.phys_addr =
304                                 pktmbuf_iova_offset(iobuf,
305                                         digest_offset);
306                 } else {
307                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
308                         sym_op->auth.digest.data = pktmbuf_mtod_offset
309                                 (sym_op->m_src, digest_offset);
310                         sym_op->auth.digest.phys_addr =
311                                 pktmbuf_iova_offset(sym_op->m_src,
312                                         digest_offset);
313                 }
314
315                 sym_op->auth.data.offset = 0;
316                 sym_op->auth.data.length = tdata->ciphertext.len;
317         }
318
319         /* create session for sessioned op */
320         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
321                 sess = rte_cryptodev_sym_session_create(sess_mpool);
322
323                 rte_cryptodev_sym_session_init(dev_id, sess, init_xform,
324                                 sess_mpool);
325                 if (!sess) {
326                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
327                                 "FAILED: %s", __LINE__,
328                                 "Session creation failed");
329                         status = TEST_FAILED;
330                         goto error_exit;
331                 }
332
333                 /* attach symmetric crypto session to crypto operations */
334                 rte_crypto_op_attach_sym_session(op, sess);
335         }
336
337         debug_hexdump(stdout, "m_src(before):",
338                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
339         rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
340                                                 sym_op->m_src->buf_len);
341         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
342                 debug_hexdump(stdout, "m_dst(before):",
343                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
344                 rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
345                                                 sym_op->m_dst->buf_len);
346         }
347
348         /* Process crypto operation */
349         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
350                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
351                         "line %u FAILED: %s",
352                         __LINE__, "Error sending packet for encryption");
353                 status = TEST_FAILED;
354                 goto error_exit;
355         }
356
357         op = NULL;
358
359         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
360                 rte_pause();
361
362         if (!op) {
363                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
364                         "line %u FAILED: %s",
365                         __LINE__, "Failed to process sym crypto op");
366                 status = TEST_FAILED;
367                 goto error_exit;
368         }
369
370         debug_hexdump(stdout, "m_src(after):",
371                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
372         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
373                 debug_hexdump(stdout, "m_dst(after):",
374                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
375
376         /* Verify results */
377         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
378                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
379                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
380                                 "FAILED: Digest verification failed "
381                                 "(0x%X)", __LINE__, op->status);
382                 else
383                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
384                                 "FAILED: Digest verification failed "
385                                 "(0x%X)", __LINE__, op->status);
386                 status = TEST_FAILED;
387                 goto error_exit;
388         }
389
390         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
391                 uint8_t buffer[2048];
392                 const uint8_t *compare_ref;
393                 uint32_t compare_len;
394
395                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
396                         compare_ref = tdata->ciphertext.data;
397                         compare_len = tdata->ciphertext.len;
398                 } else {
399                         compare_ref = tdata->plaintext.data;
400                         compare_len = tdata->plaintext.len;
401                 }
402
403                 if (memcmp(rte_pktmbuf_read(iobuf, 0, compare_len,
404                                 buffer), compare_ref, compare_len)) {
405                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
406                                 "FAILED: %s", __LINE__,
407                                 "Crypto data not as expected");
408                         status = TEST_FAILED;
409                         goto error_exit;
410                 }
411         }
412
413         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
414                 uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
415                                         tdata->ciphertext.len);
416
417                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
418                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
419                                 "FAILED: %s", __LINE__, "Generated "
420                                 "digest data not as expected");
421                         status = TEST_FAILED;
422                         goto error_exit;
423                 }
424         }
425
426         /* The only parts that should have changed in the buffer are
427          * plaintext/ciphertext and digest.
428          * In OOP only the dest buffer should change.
429          */
430         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
431                 struct rte_mbuf *mbuf;
432                 uint8_t value;
433                 uint32_t head_unchanged_len, changed_len = 0;
434                 uint32_t i;
435
436                 mbuf = sym_op->m_src;
437                 head_unchanged_len = mbuf->buf_len;
438
439                 for (i = 0; i < mbuf->buf_len; i++) {
440                         value = *((uint8_t *)(mbuf->buf_addr)+i);
441                         if (value != tmp_src_buf[i]) {
442                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
443         "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
444                                         __LINE__, value, tmp_src_buf[i]);
445                                 status = TEST_FAILED;
446                                 goto error_exit;
447                         }
448                 }
449
450                 mbuf = sym_op->m_dst;
451                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
452                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
453                                                 sym_op->auth.data.offset;
454                         changed_len = sym_op->auth.data.length;
455                         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
456                                 changed_len += digest_len;
457                 } else {
458                         /* cipher-only */
459                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
460                                         sym_op->cipher.data.offset;
461                         changed_len = sym_op->cipher.data.length;
462                 }
463
464                 for (i = 0; i < mbuf->buf_len; i++) {
465                         if (i == head_unchanged_len)
466                                 i += changed_len;
467                         value = *((uint8_t *)(mbuf->buf_addr)+i);
468                         if (value != tmp_dst_buf[i]) {
469                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
470                                 "line %u FAILED: OOP dst outer mbuf data "
471                                 "(0x%x) not as expected (0x%x)",
472                                 __LINE__, value, tmp_dst_buf[i]);
473                                 status = TEST_FAILED;
474                                 goto error_exit;
475                         }
476                 }
477         } else {
478                 /* In-place operation */
479                 struct rte_mbuf *mbuf;
480                 uint8_t value;
481                 uint32_t head_unchanged_len = 0, changed_len = 0;
482                 uint32_t i;
483
484                 mbuf = sym_op->m_src;
485                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
486                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
487                                         sym_op->cipher.data.offset;
488                         changed_len = sym_op->cipher.data.length;
489                 } else {
490                         /* auth-only */
491                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
492                                         sym_op->auth.data.offset +
493                                         sym_op->auth.data.length;
494                         changed_len = 0;
495                 }
496
497                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
498                         changed_len += digest_len;
499
500                 for (i = 0; i < mbuf->buf_len; i++) {
501                         if (i == head_unchanged_len)
502                                 i += changed_len;
503                         value = *((uint8_t *)(mbuf->buf_addr)+i);
504                         if (value != tmp_src_buf[i]) {
505                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
506                                 "line %u FAILED: outer mbuf data (0x%x) "
507                                 "not as expected (0x%x)",
508                                 __LINE__, value, tmp_src_buf[i]);
509                                 status = TEST_FAILED;
510                                 goto error_exit;
511                         }
512                 }
513         }
514
515         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
516
517 error_exit:
518         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
519                 if (sess) {
520                         rte_cryptodev_sym_session_clear(dev_id, sess);
521                         rte_cryptodev_sym_session_free(sess);
522                 }
523                 if (cipher_xform)
524                         rte_free(cipher_xform);
525                 if (auth_xform)
526                         rte_free(auth_xform);
527         }
528
529         if (op)
530                 rte_crypto_op_free(op);
531
532         if (obuf)
533                 rte_pktmbuf_free(obuf);
534
535         if (ibuf)
536                 rte_pktmbuf_free(ibuf);
537
538         return status;
539 }
540
541 int
542 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
543         struct rte_mempool *op_mpool,
544         struct rte_mempool *sess_mpool,
545         uint8_t dev_id,
546         int driver_id,
547         enum blockcipher_test_type test_type)
548 {
549         int status, overall_status = TEST_SUCCESS;
550         uint32_t i, test_index = 0;
551         char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
552         uint32_t n_test_cases = 0;
553         uint32_t target_pmd_mask = 0;
554         const struct blockcipher_test_case *tcs = NULL;
555
556         int openssl_pmd = rte_cryptodev_driver_id_get(
557                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
558         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
559                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
560         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
561                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
562         int scheduler_pmd = rte_cryptodev_driver_id_get(
563                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
564         int armv8_pmd = rte_cryptodev_driver_id_get(
565                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
566         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
567                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
568         int qat_pmd = rte_cryptodev_driver_id_get(
569                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
570         int mrvl_pmd = rte_cryptodev_driver_id_get(
571                         RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
572
573         switch (test_type) {
574         case BLKCIPHER_AES_CHAIN_TYPE:
575                 n_test_cases = sizeof(aes_chain_test_cases) /
576                 sizeof(aes_chain_test_cases[0]);
577                 tcs = aes_chain_test_cases;
578                 break;
579         case BLKCIPHER_AES_CIPHERONLY_TYPE:
580                 n_test_cases = sizeof(aes_cipheronly_test_cases) /
581                 sizeof(aes_cipheronly_test_cases[0]);
582                 tcs = aes_cipheronly_test_cases;
583                 break;
584         case BLKCIPHER_AES_DOCSIS_TYPE:
585                 n_test_cases = sizeof(aes_docsis_test_cases) /
586                 sizeof(aes_docsis_test_cases[0]);
587                 tcs = aes_docsis_test_cases;
588                 break;
589         case BLKCIPHER_3DES_CHAIN_TYPE:
590                 n_test_cases = sizeof(triple_des_chain_test_cases) /
591                 sizeof(triple_des_chain_test_cases[0]);
592                 tcs = triple_des_chain_test_cases;
593                 break;
594         case BLKCIPHER_3DES_CIPHERONLY_TYPE:
595                 n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
596                 sizeof(triple_des_cipheronly_test_cases[0]);
597                 tcs = triple_des_cipheronly_test_cases;
598                 break;
599         case BLKCIPHER_DES_CIPHERONLY_TYPE:
600                 n_test_cases = sizeof(des_cipheronly_test_cases) /
601                 sizeof(des_cipheronly_test_cases[0]);
602                 tcs = des_cipheronly_test_cases;
603                 break;
604         case BLKCIPHER_DES_DOCSIS_TYPE:
605                 n_test_cases = sizeof(des_docsis_test_cases) /
606                 sizeof(des_docsis_test_cases[0]);
607                 tcs = des_docsis_test_cases;
608                 break;
609         case BLKCIPHER_AUTHONLY_TYPE:
610                 n_test_cases = sizeof(hash_test_cases) /
611                 sizeof(hash_test_cases[0]);
612                 tcs = hash_test_cases;
613                 break;
614         default:
615                 break;
616         }
617
618         if (driver_id == aesni_mb_pmd)
619                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB;
620         else if (driver_id == qat_pmd)
621                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT;
622         else if (driver_id == openssl_pmd)
623                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL;
624         else if (driver_id == armv8_pmd)
625                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8;
626         else if (driver_id == scheduler_pmd)
627                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER;
628         else if (driver_id == dpaa2_sec_pmd)
629                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC;
630         else if (driver_id == dpaa_sec_pmd)
631                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
632         else if (driver_id == mrvl_pmd)
633                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MRVL;
634         else
635                 TEST_ASSERT(0, "Unrecognized cryptodev type");
636
637         for (i = 0; i < n_test_cases; i++) {
638                 const struct blockcipher_test_case *tc = &tcs[i];
639
640                 if (!(tc->pmd_mask & target_pmd_mask))
641                         continue;
642
643                 status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
644                         sess_mpool, dev_id, driver_id, test_msg);
645
646                 printf("  %u) TestCase %s %s\n", test_index ++,
647                         tc->test_descr, test_msg);
648
649                 if (status != TEST_SUCCESS) {
650                         if (overall_status == TEST_SUCCESS)
651                                 overall_status = status;
652
653                         if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
654                                 break;
655                 }
656         }
657
658         return overall_status;
659 }