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