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