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