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