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