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