test/crypto: add dpaa crypto test cases
[dpdk.git] / test / test / test_cryptodev_blockcipher.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Intel Corporation nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38 #include <rte_pause.h>
39
40 #include <rte_crypto.h>
41 #include <rte_cryptodev.h>
42 #include <rte_cryptodev_pmd.h>
43
44 #include "test.h"
45 #include "test_cryptodev.h"
46 #include "test_cryptodev_blockcipher.h"
47 #include "test_cryptodev_aes_test_vectors.h"
48 #include "test_cryptodev_des_test_vectors.h"
49 #include "test_cryptodev_hash_test_vectors.h"
50
51 static int
52 test_blockcipher_one_case(const struct blockcipher_test_case *t,
53         struct rte_mempool *mbuf_pool,
54         struct rte_mempool *op_mpool,
55         struct rte_mempool *sess_mpool,
56         uint8_t dev_id,
57         int driver_id,
58         char *test_msg)
59 {
60         struct rte_mbuf *ibuf = NULL;
61         struct rte_mbuf *obuf = NULL;
62         struct rte_mbuf *iobuf;
63         struct rte_crypto_sym_xform *cipher_xform = NULL;
64         struct rte_crypto_sym_xform *auth_xform = NULL;
65         struct rte_crypto_sym_xform *init_xform = NULL;
66         struct rte_crypto_sym_op *sym_op = NULL;
67         struct rte_crypto_op *op = NULL;
68         struct rte_cryptodev_info dev_info;
69         struct rte_cryptodev_sym_session *sess = NULL;
70
71         int status = TEST_SUCCESS;
72         const struct blockcipher_test_data *tdata = t->test_data;
73         uint8_t cipher_key[tdata->cipher_key.len];
74         uint8_t auth_key[tdata->auth_key.len];
75         uint32_t buf_len = tdata->ciphertext.len;
76         uint32_t digest_len = 0;
77         char *buf_p = NULL;
78         uint8_t src_pattern = 0xa5;
79         uint8_t dst_pattern = 0xb6;
80         uint8_t tmp_src_buf[MBUF_SIZE];
81         uint8_t tmp_dst_buf[MBUF_SIZE];
82
83         int openssl_pmd = rte_cryptodev_driver_id_get(
84                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
85         int scheduler_pmd = rte_cryptodev_driver_id_get(
86                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
87         int armv8_pmd = rte_cryptodev_driver_id_get(
88                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
89         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
90                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
91         int qat_pmd = rte_cryptodev_driver_id_get(
92                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
93         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
94                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
95         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
96                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
97
98         int nb_segs = 1;
99
100         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
101                 rte_cryptodev_info_get(dev_id, &dev_info);
102                 if (!(dev_info.feature_flags &
103                                 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
104                         printf("Device doesn't support scatter-gather. "
105                                         "Test Skipped.\n");
106                         return 0;
107                 }
108                 nb_segs = 3;
109         }
110
111         if (tdata->cipher_key.len)
112                 memcpy(cipher_key, tdata->cipher_key.data,
113                         tdata->cipher_key.len);
114         if (tdata->auth_key.len)
115                 memcpy(auth_key, tdata->auth_key.data,
116                         tdata->auth_key.len);
117
118         if (driver_id == dpaa2_sec_pmd ||
119                         driver_id == dpaa_sec_pmd ||
120                         driver_id == qat_pmd ||
121                         driver_id == openssl_pmd ||
122                         driver_id == armv8_pmd) { /* Fall through */
123                 digest_len = tdata->digest.len;
124         } else if (driver_id == aesni_mb_pmd ||
125                         driver_id == scheduler_pmd) {
126                 digest_len = tdata->digest.truncated_len;
127         } else {
128                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
129                         "line %u FAILED: %s",
130                         __LINE__, "Unsupported PMD type");
131                 status = TEST_FAILED;
132                 goto error_exit;
133         }
134
135         /* preparing data */
136         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
137                 buf_len += digest_len;
138
139         /* for contiguous mbuf, nb_segs is 1 */
140         ibuf = create_segmented_mbuf(mbuf_pool,
141                         tdata->ciphertext.len, nb_segs, src_pattern);
142         if (ibuf == NULL) {
143                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
144                         "line %u FAILED: %s",
145                         __LINE__, "Cannot create source mbuf");
146                 status = TEST_FAILED;
147                 goto error_exit;
148         }
149
150         /* only encryption requires plaintext.data input,
151          * decryption/(digest gen)/(digest verify) use ciphertext.data
152          * to be computed
153          */
154         if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
155                 pktmbuf_write(ibuf, 0, tdata->plaintext.len,
156                                 tdata->plaintext.data);
157         else
158                 pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
159                                 tdata->ciphertext.data);
160
161         buf_p = rte_pktmbuf_append(ibuf, digest_len);
162         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
163                 rte_memcpy(buf_p, tdata->digest.data, digest_len);
164         else
165                 memset(buf_p, 0, digest_len);
166
167         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
168                 obuf = rte_pktmbuf_alloc(mbuf_pool);
169                 if (!obuf) {
170                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
171                                 "FAILED: %s", __LINE__,
172                                 "Allocation of rte_mbuf failed");
173                         status = TEST_FAILED;
174                         goto error_exit;
175                 }
176                 memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
177
178                 buf_p = rte_pktmbuf_append(obuf, buf_len);
179                 if (!buf_p) {
180                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
181                                 "FAILED: %s", __LINE__,
182                                 "No room to append mbuf");
183                         status = TEST_FAILED;
184                         goto error_exit;
185                 }
186                 memset(buf_p, 0, buf_len);
187         }
188
189         /* Generate Crypto op data structure */
190         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
191         if (!op) {
192                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
193                         "line %u FAILED: %s",
194                         __LINE__, "Failed to allocate symmetric crypto "
195                         "operation struct");
196                 status = TEST_FAILED;
197                 goto error_exit;
198         }
199
200         sym_op = op->sym;
201
202         sym_op->m_src = ibuf;
203
204         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
205                 sym_op->m_dst = obuf;
206                 iobuf = obuf;
207         } else {
208                 sym_op->m_dst = NULL;
209                 iobuf = ibuf;
210         }
211
212         /* sessionless op requires allocate xform using
213          * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
214          * is used
215          */
216         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
217                 uint32_t n_xforms = 0;
218
219                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
220                         n_xforms++;
221                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
222                         n_xforms++;
223
224                 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
225                         == NULL) {
226                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
227                                 "FAILED: %s", __LINE__, "Failed to "
228                                 "allocate space for crypto transforms");
229                         status = TEST_FAILED;
230                         goto error_exit;
231                 }
232         } else {
233                 cipher_xform = rte_zmalloc(NULL,
234                         sizeof(struct rte_crypto_sym_xform), 0);
235
236                 auth_xform = rte_zmalloc(NULL,
237                         sizeof(struct rte_crypto_sym_xform), 0);
238
239                 if (!cipher_xform || !auth_xform) {
240                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
241                                 "FAILED: %s", __LINE__, "Failed to "
242                                 "allocate memory for crypto transforms");
243                         status = TEST_FAILED;
244                         goto error_exit;
245                 }
246         }
247
248         /* preparing xform, for sessioned op, init_xform is initialized
249          * here and later as param in rte_cryptodev_sym_session_create() call
250          */
251         if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
252                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
253                         cipher_xform = op->sym->xform;
254                         auth_xform = cipher_xform->next;
255                         auth_xform->next = NULL;
256                 } else {
257                         cipher_xform->next = auth_xform;
258                         auth_xform->next = NULL;
259                         init_xform = cipher_xform;
260                 }
261         } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
262                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
263                         auth_xform = op->sym->xform;
264                         cipher_xform = auth_xform->next;
265                         cipher_xform->next = NULL;
266                 } else {
267                         auth_xform->next = cipher_xform;
268                         cipher_xform->next = NULL;
269                         init_xform = auth_xform;
270                 }
271         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
272                         (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
273                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
274                         cipher_xform = op->sym->xform;
275                 else
276                         init_xform = cipher_xform;
277                 cipher_xform->next = NULL;
278         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
279                         (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
280                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
281                         auth_xform = op->sym->xform;
282                 else
283                         init_xform = auth_xform;
284                 auth_xform->next = NULL;
285         } else {
286                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
287                         "line %u FAILED: %s",
288                         __LINE__, "Unrecognized operation");
289                 status = TEST_FAILED;
290                 goto error_exit;
291         }
292
293         /*configure xforms & sym_op cipher and auth data*/
294         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
295                 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
296                 cipher_xform->cipher.algo = tdata->crypto_algo;
297                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
298                         cipher_xform->cipher.op =
299                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
300                 else
301                         cipher_xform->cipher.op =
302                                 RTE_CRYPTO_CIPHER_OP_DECRYPT;
303                 cipher_xform->cipher.key.data = cipher_key;
304                 cipher_xform->cipher.key.length = tdata->cipher_key.len;
305                 cipher_xform->cipher.iv.offset = IV_OFFSET;
306                 cipher_xform->cipher.iv.length = tdata->iv.len;
307
308                 sym_op->cipher.data.offset = 0;
309                 sym_op->cipher.data.length = tdata->ciphertext.len;
310                 rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
311                                 tdata->iv.data,
312                                 tdata->iv.len);
313         }
314
315         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
316                 uint32_t digest_offset = tdata->ciphertext.len;
317
318                 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
319                 auth_xform->auth.algo = tdata->auth_algo;
320                 auth_xform->auth.key.length = tdata->auth_key.len;
321                 auth_xform->auth.key.data = auth_key;
322                 auth_xform->auth.digest_length = digest_len;
323
324                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
325                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
326                         sym_op->auth.digest.data = pktmbuf_mtod_offset
327                                 (iobuf, digest_offset);
328                         sym_op->auth.digest.phys_addr =
329                                 pktmbuf_mtophys_offset(iobuf,
330                                         digest_offset);
331                 } else {
332                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
333                         sym_op->auth.digest.data = pktmbuf_mtod_offset
334                                 (sym_op->m_src, digest_offset);
335                         sym_op->auth.digest.phys_addr =
336                                 pktmbuf_mtophys_offset(sym_op->m_src,
337                                         digest_offset);
338                 }
339
340                 sym_op->auth.data.offset = 0;
341                 sym_op->auth.data.length = tdata->ciphertext.len;
342         }
343
344         /* create session for sessioned op */
345         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
346                 sess = rte_cryptodev_sym_session_create(sess_mpool);
347
348                 rte_cryptodev_sym_session_init(dev_id, sess, init_xform,
349                                 sess_mpool);
350                 if (!sess) {
351                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
352                                 "FAILED: %s", __LINE__,
353                                 "Session creation failed");
354                         status = TEST_FAILED;
355                         goto error_exit;
356                 }
357
358                 /* attach symmetric crypto session to crypto operations */
359                 rte_crypto_op_attach_sym_session(op, sess);
360         }
361
362         TEST_HEXDUMP(stdout, "m_src(before):",
363                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
364         rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
365                                                 sym_op->m_src->buf_len);
366         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
367                 TEST_HEXDUMP(stdout, "m_dst(before):",
368                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
369                 rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
370                                                 sym_op->m_dst->buf_len);
371         }
372
373         /* Process crypto operation */
374         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
375                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
376                         "line %u FAILED: %s",
377                         __LINE__, "Error sending packet for encryption");
378                 status = TEST_FAILED;
379                 goto error_exit;
380         }
381
382         op = NULL;
383
384         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
385                 rte_pause();
386
387         if (!op) {
388                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
389                         "line %u FAILED: %s",
390                         __LINE__, "Failed to process sym crypto op");
391                 status = TEST_FAILED;
392                 goto error_exit;
393         }
394
395         TEST_HEXDUMP(stdout, "m_src(after):",
396                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
397         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
398                 TEST_HEXDUMP(stdout, "m_dst(after):",
399                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
400
401         /* Verify results */
402         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
403                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
404                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
405                                 "FAILED: Digest verification failed "
406                                 "(0x%X)", __LINE__, op->status);
407                 else
408                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
409                                 "FAILED: Digest verification failed "
410                                 "(0x%X)", __LINE__, op->status);
411                 status = TEST_FAILED;
412                 goto error_exit;
413         }
414
415         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
416                 uint8_t buffer[2048];
417                 const uint8_t *compare_ref;
418                 uint32_t compare_len;
419
420                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
421                         compare_ref = tdata->ciphertext.data;
422                         compare_len = tdata->ciphertext.len;
423                 } else {
424                         compare_ref = tdata->plaintext.data;
425                         compare_len = tdata->plaintext.len;
426                 }
427
428                 if (memcmp(rte_pktmbuf_read(iobuf, 0, compare_len,
429                                 buffer), compare_ref, compare_len)) {
430                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
431                                 "FAILED: %s", __LINE__,
432                                 "Crypto data not as expected");
433                         status = TEST_FAILED;
434                         goto error_exit;
435                 }
436         }
437
438         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
439                 uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
440                                         tdata->ciphertext.len);
441
442                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
443                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
444                                 "FAILED: %s", __LINE__, "Generated "
445                                 "digest data not as expected");
446                         status = TEST_FAILED;
447                         goto error_exit;
448                 }
449         }
450
451         /* The only parts that should have changed in the buffer are
452          * plaintext/ciphertext and digest.
453          * In OOP only the dest buffer should change.
454          */
455         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
456                 struct rte_mbuf *mbuf;
457                 uint8_t value;
458                 uint32_t head_unchanged_len, changed_len = 0;
459                 uint32_t i;
460
461                 mbuf = sym_op->m_src;
462                 head_unchanged_len = mbuf->buf_len;
463
464                 for (i = 0; i < mbuf->buf_len; i++) {
465                         value = *((uint8_t *)(mbuf->buf_addr)+i);
466                         if (value != tmp_src_buf[i]) {
467                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
468         "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
469                                         __LINE__, value, tmp_src_buf[i]);
470                                 status = TEST_FAILED;
471                                 goto error_exit;
472                         }
473                 }
474
475                 mbuf = sym_op->m_dst;
476                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
477                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
478                                                 sym_op->auth.data.offset;
479                         changed_len = sym_op->auth.data.length;
480                         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
481                                 changed_len += digest_len;
482                 } else {
483                         /* cipher-only */
484                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
485                                         sym_op->cipher.data.offset;
486                         changed_len = sym_op->cipher.data.length;
487                 }
488
489                 for (i = 0; i < mbuf->buf_len; i++) {
490                         if (i == head_unchanged_len)
491                                 i += changed_len;
492                         value = *((uint8_t *)(mbuf->buf_addr)+i);
493                         if (value != tmp_dst_buf[i]) {
494                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
495                                 "line %u FAILED: OOP dst outer mbuf data "
496                                 "(0x%x) not as expected (0x%x)",
497                                 __LINE__, value, tmp_dst_buf[i]);
498                                 status = TEST_FAILED;
499                                 goto error_exit;
500                         }
501                 }
502         } else {
503                 /* In-place operation */
504                 struct rte_mbuf *mbuf;
505                 uint8_t value;
506                 uint32_t head_unchanged_len = 0, changed_len = 0;
507                 uint32_t i;
508
509                 mbuf = sym_op->m_src;
510                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
511                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
512                                         sym_op->cipher.data.offset;
513                         changed_len = sym_op->cipher.data.length;
514                 } else {
515                         /* auth-only */
516                         head_unchanged_len = rte_pktmbuf_headroom(mbuf) +
517                                         sym_op->auth.data.offset +
518                                         sym_op->auth.data.length;
519                         changed_len = 0;
520                 }
521
522                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
523                         changed_len += digest_len;
524
525                 for (i = 0; i < mbuf->buf_len; i++) {
526                         if (i == head_unchanged_len)
527                                 i += changed_len;
528                         value = *((uint8_t *)(mbuf->buf_addr)+i);
529                         if (value != tmp_src_buf[i]) {
530                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
531                                 "line %u FAILED: outer mbuf data (0x%x) "
532                                 "not as expected (0x%x)",
533                                 __LINE__, value, tmp_src_buf[i]);
534                                 status = TEST_FAILED;
535                                 goto error_exit;
536                         }
537                 }
538         }
539
540         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
541
542 error_exit:
543         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
544                 if (sess) {
545                         rte_cryptodev_sym_session_clear(dev_id, sess);
546                         rte_cryptodev_sym_session_free(sess);
547                 }
548                 if (cipher_xform)
549                         rte_free(cipher_xform);
550                 if (auth_xform)
551                         rte_free(auth_xform);
552         }
553
554         if (op)
555                 rte_crypto_op_free(op);
556
557         if (obuf)
558                 rte_pktmbuf_free(obuf);
559
560         if (ibuf)
561                 rte_pktmbuf_free(ibuf);
562
563         return status;
564 }
565
566 int
567 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
568         struct rte_mempool *op_mpool,
569         struct rte_mempool *sess_mpool,
570         uint8_t dev_id,
571         int driver_id,
572         enum blockcipher_test_type test_type)
573 {
574         int status, overall_status = TEST_SUCCESS;
575         uint32_t i, test_index = 0;
576         char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
577         uint32_t n_test_cases = 0;
578         uint32_t target_pmd_mask = 0;
579         const struct blockcipher_test_case *tcs = NULL;
580
581         int openssl_pmd = rte_cryptodev_driver_id_get(
582                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
583         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
584                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
585         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
586                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
587         int scheduler_pmd = rte_cryptodev_driver_id_get(
588                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
589         int armv8_pmd = rte_cryptodev_driver_id_get(
590                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
591         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
592                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
593         int qat_pmd = rte_cryptodev_driver_id_get(
594                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_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 == dpaa_sec_pmd)
654                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
655         else
656                 TEST_ASSERT(0, "Unrecognized cryptodev type");
657
658         for (i = 0; i < n_test_cases; i++) {
659                 const struct blockcipher_test_case *tc = &tcs[i];
660
661                 if (!(tc->pmd_mask & target_pmd_mask))
662                         continue;
663
664                 status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
665                         sess_mpool, dev_id, driver_id, test_msg);
666
667                 printf("  %u) TestCase %s %s\n", test_index ++,
668                         tc->test_descr, test_msg);
669
670                 if (status != TEST_SUCCESS) {
671                         if (overall_status == TEST_SUCCESS)
672                                 overall_status = status;
673
674                         if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
675                                 break;
676                 }
677         }
678
679         return overall_status;
680 }