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