test/crypto: add OCTEON TX unit tests
[dpdk.git] / test / test / test_cryptodev_blockcipher.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation
3  */
4
5 #include <rte_common.h>
6 #include <rte_hexdump.h>
7 #include <rte_mbuf.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_pause.h>
11
12 #include <rte_crypto.h>
13 #include <rte_cryptodev.h>
14 #include <rte_cryptodev_pmd.h>
15
16 #include "test.h"
17 #include "test_cryptodev.h"
18 #include "test_cryptodev_blockcipher.h"
19 #include "test_cryptodev_aes_test_vectors.h"
20 #include "test_cryptodev_des_test_vectors.h"
21 #include "test_cryptodev_hash_test_vectors.h"
22
23 static int
24 test_blockcipher_one_case(const struct blockcipher_test_case *t,
25         struct rte_mempool *mbuf_pool,
26         struct rte_mempool *op_mpool,
27         struct rte_mempool *sess_mpool,
28         uint8_t dev_id,
29         int driver_id,
30         char *test_msg)
31 {
32         struct rte_mbuf *ibuf = NULL;
33         struct rte_mbuf *obuf = NULL;
34         struct rte_mbuf *iobuf;
35         struct rte_crypto_sym_xform *cipher_xform = NULL;
36         struct rte_crypto_sym_xform *auth_xform = NULL;
37         struct rte_crypto_sym_xform *init_xform = NULL;
38         struct rte_crypto_sym_op *sym_op = NULL;
39         struct rte_crypto_op *op = NULL;
40         struct rte_cryptodev_info dev_info;
41         struct rte_cryptodev_sym_session *sess = NULL;
42
43         int status = TEST_SUCCESS;
44         const struct blockcipher_test_data *tdata = t->test_data;
45         uint8_t cipher_key[tdata->cipher_key.len];
46         uint8_t auth_key[tdata->auth_key.len];
47         uint32_t buf_len = tdata->ciphertext.len;
48         uint32_t digest_len = 0;
49         char *buf_p = NULL;
50         uint8_t src_pattern = 0xa5;
51         uint8_t dst_pattern = 0xb6;
52         uint8_t tmp_src_buf[MBUF_SIZE];
53         uint8_t tmp_dst_buf[MBUF_SIZE];
54
55         int openssl_pmd = rte_cryptodev_driver_id_get(
56                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
57         int ccp_pmd = rte_cryptodev_driver_id_get(
58                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
59         int scheduler_pmd = rte_cryptodev_driver_id_get(
60                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
61         int armv8_pmd = rte_cryptodev_driver_id_get(
62                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
63         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
64                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
65         int qat_pmd = rte_cryptodev_driver_id_get(
66                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
67         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
68                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
69         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
70                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
71         int mrvl_pmd = rte_cryptodev_driver_id_get(
72                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
73         int virtio_pmd = rte_cryptodev_driver_id_get(
74                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
75         int octeontx_pmd = rte_cryptodev_driver_id_get(
76                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
77
78         int nb_segs = 1;
79
80         rte_cryptodev_info_get(dev_id, &dev_info);
81
82         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
83                 uint64_t feat_flags = dev_info.feature_flags;
84                 uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
85
86                 if (t->feature_mask && BLOCKCIPHER_TEST_FEATURE_OOP) {
87                         if (!(feat_flags & oop_flag)) {
88                                 printf("Device doesn't support out-of-place "
89                                         "scatter-gather in input mbuf. "
90                                         "Test Skipped.\n");
91                                 return 0;
92                         }
93                 } else {
94                         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
95                                 printf("Device doesn't support in-place "
96                                         "scatter-gather mbufs. "
97                                         "Test Skipped.\n");
98                                 return 0;
99                         }
100                 }
101
102                 nb_segs = 3;
103         }
104
105         if (tdata->cipher_key.len)
106                 memcpy(cipher_key, tdata->cipher_key.data,
107                         tdata->cipher_key.len);
108         if (tdata->auth_key.len)
109                 memcpy(auth_key, tdata->auth_key.data,
110                         tdata->auth_key.len);
111
112         if (driver_id == dpaa2_sec_pmd ||
113                         driver_id == dpaa_sec_pmd ||
114                         driver_id == qat_pmd ||
115                         driver_id == openssl_pmd ||
116                         driver_id == armv8_pmd ||
117                         driver_id == mrvl_pmd ||
118                         driver_id == ccp_pmd ||
119                         driver_id == virtio_pmd ||
120                         driver_id == octeontx_pmd) { /* Fall through */
121                 digest_len = tdata->digest.len;
122         } else if (driver_id == aesni_mb_pmd ||
123                         driver_id == scheduler_pmd) {
124                 digest_len = tdata->digest.truncated_len;
125         } else {
126                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
127                         "line %u FAILED: %s",
128                         __LINE__, "Unsupported PMD type");
129                 status = TEST_FAILED;
130                 goto error_exit;
131         }
132
133         /* preparing data */
134         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
135                 buf_len += digest_len;
136
137         /* for contiguous mbuf, nb_segs is 1 */
138         ibuf = create_segmented_mbuf(mbuf_pool,
139                         tdata->ciphertext.len, nb_segs, src_pattern);
140         if (ibuf == NULL) {
141                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
142                         "line %u FAILED: %s",
143                         __LINE__, "Cannot create source mbuf");
144                 status = TEST_FAILED;
145                 goto error_exit;
146         }
147
148         /* only encryption requires plaintext.data input,
149          * decryption/(digest gen)/(digest verify) use ciphertext.data
150          * to be computed
151          */
152         if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
153                 pktmbuf_write(ibuf, 0, tdata->plaintext.len,
154                                 tdata->plaintext.data);
155         else
156                 pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
157                                 tdata->ciphertext.data);
158
159         buf_p = rte_pktmbuf_append(ibuf, digest_len);
160         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
161                 rte_memcpy(buf_p, tdata->digest.data, digest_len);
162         else
163                 memset(buf_p, 0, digest_len);
164
165         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
166                 obuf = rte_pktmbuf_alloc(mbuf_pool);
167                 if (!obuf) {
168                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
169                                 "FAILED: %s", __LINE__,
170                                 "Allocation of rte_mbuf failed");
171                         status = TEST_FAILED;
172                         goto error_exit;
173                 }
174                 memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
175
176                 buf_p = rte_pktmbuf_append(obuf, buf_len);
177                 if (!buf_p) {
178                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
179                                 "FAILED: %s", __LINE__,
180                                 "No room to append mbuf");
181                         status = TEST_FAILED;
182                         goto error_exit;
183                 }
184                 memset(buf_p, 0, buf_len);
185         }
186
187         /* Generate Crypto op data structure */
188         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
189         if (!op) {
190                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
191                         "line %u FAILED: %s",
192                         __LINE__, "Failed to allocate symmetric crypto "
193                         "operation struct");
194                 status = TEST_FAILED;
195                 goto error_exit;
196         }
197
198         sym_op = op->sym;
199
200         sym_op->m_src = ibuf;
201
202         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
203                 sym_op->m_dst = obuf;
204                 iobuf = obuf;
205         } else {
206                 sym_op->m_dst = NULL;
207                 iobuf = ibuf;
208         }
209
210         /* sessionless op requires allocate xform using
211          * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
212          * is used
213          */
214         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
215                 uint32_t n_xforms = 0;
216
217                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
218                         n_xforms++;
219                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
220                         n_xforms++;
221
222                 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
223                         == NULL) {
224                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
225                                 "FAILED: %s", __LINE__, "Failed to "
226                                 "allocate space for crypto transforms");
227                         status = TEST_FAILED;
228                         goto error_exit;
229                 }
230         } else {
231                 cipher_xform = rte_zmalloc(NULL,
232                         sizeof(struct rte_crypto_sym_xform), 0);
233
234                 auth_xform = rte_zmalloc(NULL,
235                         sizeof(struct rte_crypto_sym_xform), 0);
236
237                 if (!cipher_xform || !auth_xform) {
238                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
239                                 "FAILED: %s", __LINE__, "Failed to "
240                                 "allocate memory for crypto transforms");
241                         status = TEST_FAILED;
242                         goto error_exit;
243                 }
244         }
245
246         /* preparing xform, for sessioned op, init_xform is initialized
247          * here and later as param in rte_cryptodev_sym_session_create() call
248          */
249         if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
250                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
251                         cipher_xform = op->sym->xform;
252                         auth_xform = cipher_xform->next;
253                         auth_xform->next = NULL;
254                 } else {
255                         cipher_xform->next = auth_xform;
256                         auth_xform->next = NULL;
257                         init_xform = cipher_xform;
258                 }
259         } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
260                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
261                         auth_xform = op->sym->xform;
262                         cipher_xform = auth_xform->next;
263                         cipher_xform->next = NULL;
264                 } else {
265                         auth_xform->next = cipher_xform;
266                         cipher_xform->next = NULL;
267                         init_xform = auth_xform;
268                 }
269         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
270                         (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
271                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
272                         cipher_xform = op->sym->xform;
273                 else
274                         init_xform = cipher_xform;
275                 cipher_xform->next = NULL;
276         } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
277                         (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
278                 if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
279                         auth_xform = op->sym->xform;
280                 else
281                         init_xform = auth_xform;
282                 auth_xform->next = NULL;
283         } else {
284                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
285                         "line %u FAILED: %s",
286                         __LINE__, "Unrecognized operation");
287                 status = TEST_FAILED;
288                 goto error_exit;
289         }
290
291         /*configure xforms & sym_op cipher and auth data*/
292         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
293                 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
294                 cipher_xform->cipher.algo = tdata->crypto_algo;
295                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
296                         cipher_xform->cipher.op =
297                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
298                 else
299                         cipher_xform->cipher.op =
300                                 RTE_CRYPTO_CIPHER_OP_DECRYPT;
301                 cipher_xform->cipher.key.data = cipher_key;
302                 cipher_xform->cipher.key.length = tdata->cipher_key.len;
303                 cipher_xform->cipher.iv.offset = IV_OFFSET;
304                 cipher_xform->cipher.iv.length = tdata->iv.len;
305
306                 sym_op->cipher.data.offset = 0;
307                 sym_op->cipher.data.length = tdata->ciphertext.len;
308                 rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
309                                 tdata->iv.data,
310                                 tdata->iv.len);
311         }
312
313         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
314                 uint32_t digest_offset = tdata->ciphertext.len;
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_iova_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_iova_offset(sym_op->m_src,
335                                         digest_offset);
336                 }
337
338                 sym_op->auth.data.offset = 0;
339                 sym_op->auth.data.length = tdata->ciphertext.len;
340         }
341
342         /* create session for sessioned op */
343         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
344                 sess = rte_cryptodev_sym_session_create(sess_mpool);
345
346                 rte_cryptodev_sym_session_init(dev_id, sess, init_xform,
347                                 sess_mpool);
348                 if (!sess) {
349                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
350                                 "FAILED: %s", __LINE__,
351                                 "Session creation failed");
352                         status = TEST_FAILED;
353                         goto error_exit;
354                 }
355
356                 /* attach symmetric crypto session to crypto operations */
357                 rte_crypto_op_attach_sym_session(op, sess);
358         }
359
360         debug_hexdump(stdout, "m_src(before):",
361                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
362         rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
363                                                 sym_op->m_src->buf_len);
364         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
365                 debug_hexdump(stdout, "m_dst(before):",
366                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
367                 rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
368                                                 sym_op->m_dst->buf_len);
369         }
370
371         /* Process crypto operation */
372         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
373                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
374                         "line %u FAILED: %s",
375                         __LINE__, "Error sending packet for encryption");
376                 status = TEST_FAILED;
377                 goto error_exit;
378         }
379
380         op = NULL;
381
382         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
383                 rte_pause();
384
385         if (!op) {
386                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
387                         "line %u FAILED: %s",
388                         __LINE__, "Failed to process sym crypto op");
389                 status = TEST_FAILED;
390                 goto error_exit;
391         }
392
393         debug_hexdump(stdout, "m_src(after):",
394                         sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
395         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
396                 debug_hexdump(stdout, "m_dst(after):",
397                         sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
398
399         /* Verify results */
400         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
401                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
402                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
403                                 "FAILED: Digest verification failed "
404                                 "(0x%X)", __LINE__, op->status);
405                 else
406                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
407                                 "FAILED: Digest verification failed "
408                                 "(0x%X)", __LINE__, op->status);
409                 status = TEST_FAILED;
410                 goto error_exit;
411         }
412
413         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
414                 uint8_t buffer[2048];
415                 const uint8_t *compare_ref;
416                 uint32_t compare_len;
417
418                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
419                         compare_ref = tdata->ciphertext.data;
420                         compare_len = tdata->ciphertext.len;
421                 } else {
422                         compare_ref = tdata->plaintext.data;
423                         compare_len = tdata->plaintext.len;
424                 }
425
426                 if (memcmp(rte_pktmbuf_read(iobuf, 0, compare_len,
427                                 buffer), compare_ref, compare_len)) {
428                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
429                                 "FAILED: %s", __LINE__,
430                                 "Crypto data not as expected");
431                         status = TEST_FAILED;
432                         goto error_exit;
433                 }
434         }
435
436         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
437                 uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
438                                         tdata->ciphertext.len);
439
440                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
441                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
442                                 "FAILED: %s", __LINE__, "Generated "
443                                 "digest data not as expected");
444                         status = TEST_FAILED;
445                         goto error_exit;
446                 }
447         }
448
449         /* The only parts that should have changed in the buffer are
450          * plaintext/ciphertext and digest.
451          * In OOP only the dest buffer should change.
452          */
453         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
454                 struct rte_mbuf *mbuf;
455                 uint8_t value;
456                 uint32_t head_unchanged_len, changed_len = 0;
457                 uint32_t i;
458                 uint32_t hdroom_used = 0, tlroom_used = 0;
459                 uint32_t hdroom = 0;
460
461                 mbuf = sym_op->m_src;
462                 /*
463                  * Crypto PMDs specify the headroom & tailroom it would use
464                  * when processing the crypto operation. PMD is free to modify
465                  * this space, and so the verification check should skip that
466                  * block.
467                  */
468                 hdroom_used = dev_info.min_mbuf_headroom_req;
469                 tlroom_used = dev_info.min_mbuf_tailroom_req;
470
471                 /* Get headroom */
472                 hdroom = rte_pktmbuf_headroom(mbuf);
473
474                 head_unchanged_len = mbuf->buf_len;
475
476                 for (i = 0; i < mbuf->buf_len; i++) {
477
478                         /* Skip headroom used by PMD */
479                         if (i == hdroom - hdroom_used)
480                                 i += hdroom_used;
481
482                         /* Skip tailroom used by PMD */
483                         if (i == (hdroom + mbuf->data_len))
484                                 i += tlroom_used;
485
486                         value = *((uint8_t *)(mbuf->buf_addr)+i);
487                         if (value != tmp_src_buf[i]) {
488                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
489         "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
490                                         __LINE__, value, tmp_src_buf[i]);
491                                 status = TEST_FAILED;
492                                 goto error_exit;
493                         }
494                 }
495
496                 mbuf = sym_op->m_dst;
497                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
498                         head_unchanged_len = hdroom + sym_op->auth.data.offset;
499                         changed_len = sym_op->auth.data.length;
500                         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
501                                 changed_len += digest_len;
502                 } else {
503                         /* cipher-only */
504                         head_unchanged_len = hdroom +
505                                         sym_op->cipher.data.offset;
506                         changed_len = sym_op->cipher.data.length;
507                 }
508
509                 for (i = 0; i < mbuf->buf_len; i++) {
510                         if (i == head_unchanged_len)
511                                 i += changed_len;
512                         value = *((uint8_t *)(mbuf->buf_addr)+i);
513                         if (value != tmp_dst_buf[i]) {
514                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
515                                 "line %u FAILED: OOP dst outer mbuf data "
516                                 "(0x%x) not as expected (0x%x)",
517                                 __LINE__, value, tmp_dst_buf[i]);
518                                 status = TEST_FAILED;
519                                 goto error_exit;
520                         }
521                 }
522         } else {
523                 /* In-place operation */
524                 struct rte_mbuf *mbuf;
525                 uint8_t value;
526                 uint32_t head_unchanged_len = 0, changed_len = 0;
527                 uint32_t i;
528                 uint32_t hdroom_used = 0, tlroom_used = 0;
529                 uint32_t hdroom = 0;
530
531                 /*
532                  * Crypto PMDs specify the headroom & tailroom it would use
533                  * when processing the crypto operation. PMD is free to modify
534                  * this space, and so the verification check should skip that
535                  * block.
536                  */
537                 hdroom_used = dev_info.min_mbuf_headroom_req;
538                 tlroom_used = dev_info.min_mbuf_tailroom_req;
539
540                 mbuf = sym_op->m_src;
541
542                 /* Get headroom */
543                 hdroom = rte_pktmbuf_headroom(mbuf);
544
545                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
546                         head_unchanged_len = hdroom +
547                                         sym_op->cipher.data.offset;
548                         changed_len = sym_op->cipher.data.length;
549                 } else {
550                         /* auth-only */
551                         head_unchanged_len = hdroom +
552                                         sym_op->auth.data.offset +
553                                         sym_op->auth.data.length;
554                         changed_len = 0;
555                 }
556
557                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
558                         changed_len += digest_len;
559
560                 for (i = 0; i < mbuf->buf_len; i++) {
561
562                         /* Skip headroom used by PMD */
563                         if (i == hdroom - hdroom_used)
564                                 i += hdroom_used;
565
566                         if (i == head_unchanged_len)
567                                 i += changed_len;
568
569                         /* Skip tailroom used by PMD */
570                         if (i == (hdroom + mbuf->data_len))
571                                 i += tlroom_used;
572
573                         value = *((uint8_t *)(mbuf->buf_addr)+i);
574                         if (value != tmp_src_buf[i]) {
575                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
576                                 "line %u FAILED: outer mbuf data (0x%x) "
577                                 "not as expected (0x%x)",
578                                 __LINE__, value, tmp_src_buf[i]);
579                                 status = TEST_FAILED;
580                                 goto error_exit;
581                         }
582                 }
583         }
584
585         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
586
587 error_exit:
588         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
589                 if (sess) {
590                         rte_cryptodev_sym_session_clear(dev_id, sess);
591                         rte_cryptodev_sym_session_free(sess);
592                 }
593                 if (cipher_xform)
594                         rte_free(cipher_xform);
595                 if (auth_xform)
596                         rte_free(auth_xform);
597         }
598
599         if (op)
600                 rte_crypto_op_free(op);
601
602         if (obuf)
603                 rte_pktmbuf_free(obuf);
604
605         if (ibuf)
606                 rte_pktmbuf_free(ibuf);
607
608         return status;
609 }
610
611 int
612 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
613         struct rte_mempool *op_mpool,
614         struct rte_mempool *sess_mpool,
615         uint8_t dev_id,
616         int driver_id,
617         enum blockcipher_test_type test_type)
618 {
619         int status, overall_status = TEST_SUCCESS;
620         uint32_t i, test_index = 0;
621         char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
622         uint32_t n_test_cases = 0;
623         uint32_t target_pmd_mask = 0;
624         const struct blockcipher_test_case *tcs = NULL;
625
626         int openssl_pmd = rte_cryptodev_driver_id_get(
627                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
628         int ccp_pmd = rte_cryptodev_driver_id_get(
629                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
630         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
631                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
632         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
633                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
634         int scheduler_pmd = rte_cryptodev_driver_id_get(
635                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
636         int armv8_pmd = rte_cryptodev_driver_id_get(
637                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
638         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
639                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
640         int qat_pmd = rte_cryptodev_driver_id_get(
641                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
642         int mrvl_pmd = rte_cryptodev_driver_id_get(
643                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
644         int virtio_pmd = rte_cryptodev_driver_id_get(
645                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
646         int octeontx_pmd = rte_cryptodev_driver_id_get(
647                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
648
649         switch (test_type) {
650         case BLKCIPHER_AES_CHAIN_TYPE:
651                 n_test_cases = sizeof(aes_chain_test_cases) /
652                 sizeof(aes_chain_test_cases[0]);
653                 tcs = aes_chain_test_cases;
654                 break;
655         case BLKCIPHER_AES_CIPHERONLY_TYPE:
656                 n_test_cases = sizeof(aes_cipheronly_test_cases) /
657                 sizeof(aes_cipheronly_test_cases[0]);
658                 tcs = aes_cipheronly_test_cases;
659                 break;
660         case BLKCIPHER_AES_DOCSIS_TYPE:
661                 n_test_cases = sizeof(aes_docsis_test_cases) /
662                 sizeof(aes_docsis_test_cases[0]);
663                 tcs = aes_docsis_test_cases;
664                 break;
665         case BLKCIPHER_3DES_CHAIN_TYPE:
666                 n_test_cases = sizeof(triple_des_chain_test_cases) /
667                 sizeof(triple_des_chain_test_cases[0]);
668                 tcs = triple_des_chain_test_cases;
669                 break;
670         case BLKCIPHER_3DES_CIPHERONLY_TYPE:
671                 n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
672                 sizeof(triple_des_cipheronly_test_cases[0]);
673                 tcs = triple_des_cipheronly_test_cases;
674                 break;
675         case BLKCIPHER_DES_CIPHERONLY_TYPE:
676                 n_test_cases = sizeof(des_cipheronly_test_cases) /
677                 sizeof(des_cipheronly_test_cases[0]);
678                 tcs = des_cipheronly_test_cases;
679                 break;
680         case BLKCIPHER_DES_DOCSIS_TYPE:
681                 n_test_cases = sizeof(des_docsis_test_cases) /
682                 sizeof(des_docsis_test_cases[0]);
683                 tcs = des_docsis_test_cases;
684                 break;
685         case BLKCIPHER_AUTHONLY_TYPE:
686                 n_test_cases = sizeof(hash_test_cases) /
687                 sizeof(hash_test_cases[0]);
688                 tcs = hash_test_cases;
689                 break;
690         default:
691                 break;
692         }
693
694         if (driver_id == aesni_mb_pmd)
695                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB;
696         else if (driver_id == qat_pmd)
697                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT;
698         else if (driver_id == openssl_pmd)
699                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL;
700         else if (driver_id == armv8_pmd)
701                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8;
702         else if (driver_id == scheduler_pmd)
703                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER;
704         else if (driver_id == dpaa2_sec_pmd)
705                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC;
706         else if (driver_id == ccp_pmd)
707                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CCP;
708         else if (driver_id == dpaa_sec_pmd)
709                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
710         else if (driver_id == mrvl_pmd)
711                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MVSAM;
712         else if (driver_id == virtio_pmd)
713                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
714         else if (driver_id == octeontx_pmd)
715                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX;
716         else
717                 TEST_ASSERT(0, "Unrecognized cryptodev type");
718
719         for (i = 0; i < n_test_cases; i++) {
720                 const struct blockcipher_test_case *tc = &tcs[i];
721
722                 if (!(tc->pmd_mask & target_pmd_mask))
723                         continue;
724
725                 status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
726                         sess_mpool, dev_id, driver_id, test_msg);
727
728                 printf("  %u) TestCase %s %s\n", test_index ++,
729                         tc->test_descr, test_msg);
730
731                 if (status != TEST_SUCCESS) {
732                         if (overall_status == TEST_SUCCESS)
733                                 overall_status = status;
734
735                         if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
736                                 break;
737                 }
738         }
739
740         return overall_status;
741 }