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