New upstream version 18.11-rc1
[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 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                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
406                                 "FAILED: Digest verification failed "
407                                 "(0x%X)", __LINE__, op->status);
408                 else
409                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
410                                 "FAILED: Digest verification failed "
411                                 "(0x%X)", __LINE__, op->status);
412                 status = TEST_FAILED;
413                 goto error_exit;
414         }
415
416         if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
417                 uint8_t buffer[2048];
418                 const uint8_t *compare_ref;
419                 uint32_t compare_len;
420
421                 if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
422                         compare_ref = tdata->ciphertext.data;
423                         compare_len = tdata->ciphertext.len;
424                 } else {
425                         compare_ref = tdata->plaintext.data;
426                         compare_len = tdata->plaintext.len;
427                 }
428
429                 if (memcmp(rte_pktmbuf_read(iobuf, 0, compare_len,
430                                 buffer), compare_ref, compare_len)) {
431                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
432                                 "FAILED: %s", __LINE__,
433                                 "Crypto data not as expected");
434                         status = TEST_FAILED;
435                         goto error_exit;
436                 }
437         }
438
439         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
440                 uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
441                                         tdata->ciphertext.len);
442
443                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
444                         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
445                                 "FAILED: %s", __LINE__, "Generated "
446                                 "digest data not as expected");
447                         status = TEST_FAILED;
448                         goto error_exit;
449                 }
450         }
451
452         /* The only parts that should have changed in the buffer are
453          * plaintext/ciphertext and digest.
454          * In OOP only the dest buffer should change.
455          */
456         if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
457                 struct rte_mbuf *mbuf;
458                 uint8_t value;
459                 uint32_t head_unchanged_len, changed_len = 0;
460                 uint32_t i;
461                 uint32_t hdroom_used = 0, tlroom_used = 0;
462                 uint32_t hdroom = 0;
463
464                 mbuf = sym_op->m_src;
465                 /*
466                  * Crypto PMDs specify the headroom & tailroom it would use
467                  * when processing the crypto operation. PMD is free to modify
468                  * this space, and so the verification check should skip that
469                  * block.
470                  */
471                 hdroom_used = dev_info.min_mbuf_headroom_req;
472                 tlroom_used = dev_info.min_mbuf_tailroom_req;
473
474                 /* Get headroom */
475                 hdroom = rte_pktmbuf_headroom(mbuf);
476
477                 head_unchanged_len = mbuf->buf_len;
478
479                 for (i = 0; i < mbuf->buf_len; i++) {
480
481                         /* Skip headroom used by PMD */
482                         if (i == hdroom - hdroom_used)
483                                 i += hdroom_used;
484
485                         /* Skip tailroom used by PMD */
486                         if (i == (hdroom + mbuf->data_len))
487                                 i += tlroom_used;
488
489                         value = *((uint8_t *)(mbuf->buf_addr)+i);
490                         if (value != tmp_src_buf[i]) {
491                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
492         "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
493                                         __LINE__, value, tmp_src_buf[i]);
494                                 status = TEST_FAILED;
495                                 goto error_exit;
496                         }
497                 }
498
499                 mbuf = sym_op->m_dst;
500                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
501                         head_unchanged_len = hdroom + sym_op->auth.data.offset;
502                         changed_len = sym_op->auth.data.length;
503                         if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
504                                 changed_len += digest_len;
505                 } else {
506                         /* cipher-only */
507                         head_unchanged_len = hdroom +
508                                         sym_op->cipher.data.offset;
509                         changed_len = sym_op->cipher.data.length;
510                 }
511
512                 for (i = 0; i < mbuf->buf_len; i++) {
513                         if (i == head_unchanged_len)
514                                 i += changed_len;
515                         value = *((uint8_t *)(mbuf->buf_addr)+i);
516                         if (value != tmp_dst_buf[i]) {
517                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
518                                 "line %u FAILED: OOP dst outer mbuf data "
519                                 "(0x%x) not as expected (0x%x)",
520                                 __LINE__, value, tmp_dst_buf[i]);
521                                 status = TEST_FAILED;
522                                 goto error_exit;
523                         }
524                 }
525         } else {
526                 /* In-place operation */
527                 struct rte_mbuf *mbuf;
528                 uint8_t value;
529                 uint32_t head_unchanged_len = 0, changed_len = 0;
530                 uint32_t i;
531                 uint32_t hdroom_used = 0, tlroom_used = 0;
532                 uint32_t hdroom = 0;
533
534                 /*
535                  * Crypto PMDs specify the headroom & tailroom it would use
536                  * when processing the crypto operation. PMD is free to modify
537                  * this space, and so the verification check should skip that
538                  * block.
539                  */
540                 hdroom_used = dev_info.min_mbuf_headroom_req;
541                 tlroom_used = dev_info.min_mbuf_tailroom_req;
542
543                 mbuf = sym_op->m_src;
544
545                 /* Get headroom */
546                 hdroom = rte_pktmbuf_headroom(mbuf);
547
548                 if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
549                         head_unchanged_len = hdroom +
550                                         sym_op->cipher.data.offset;
551                         changed_len = sym_op->cipher.data.length;
552                 } else {
553                         /* auth-only */
554                         head_unchanged_len = hdroom +
555                                         sym_op->auth.data.offset +
556                                         sym_op->auth.data.length;
557                         changed_len = 0;
558                 }
559
560                 if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
561                         changed_len += digest_len;
562
563                 for (i = 0; i < mbuf->buf_len; i++) {
564
565                         /* Skip headroom used by PMD */
566                         if (i == hdroom - hdroom_used)
567                                 i += hdroom_used;
568
569                         if (i == head_unchanged_len)
570                                 i += changed_len;
571
572                         /* Skip tailroom used by PMD */
573                         if (i == (hdroom + mbuf->data_len))
574                                 i += tlroom_used;
575
576                         value = *((uint8_t *)(mbuf->buf_addr)+i);
577                         if (value != tmp_src_buf[i]) {
578                                 snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
579                                 "line %u FAILED: outer mbuf data (0x%x) "
580                                 "not as expected (0x%x)",
581                                 __LINE__, value, tmp_src_buf[i]);
582                                 status = TEST_FAILED;
583                                 goto error_exit;
584                         }
585                 }
586         }
587
588         snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
589
590 error_exit:
591         if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
592                 if (sess) {
593                         rte_cryptodev_sym_session_clear(dev_id, sess);
594                         rte_cryptodev_sym_session_free(sess);
595                 }
596                 if (cipher_xform)
597                         rte_free(cipher_xform);
598                 if (auth_xform)
599                         rte_free(auth_xform);
600         }
601
602         if (op)
603                 rte_crypto_op_free(op);
604
605         if (obuf)
606                 rte_pktmbuf_free(obuf);
607
608         if (ibuf)
609                 rte_pktmbuf_free(ibuf);
610
611         return status;
612 }
613
614 int
615 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
616         struct rte_mempool *op_mpool,
617         struct rte_mempool *sess_mpool,
618         uint8_t dev_id,
619         int driver_id,
620         enum blockcipher_test_type test_type)
621 {
622         int status, overall_status = TEST_SUCCESS;
623         uint32_t i, test_index = 0;
624         char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
625         uint32_t n_test_cases = 0;
626         uint32_t target_pmd_mask = 0;
627         const struct blockcipher_test_case *tcs = NULL;
628
629         int openssl_pmd = rte_cryptodev_driver_id_get(
630                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
631         int ccp_pmd = rte_cryptodev_driver_id_get(
632                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
633         int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
634                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
635         int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
636                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
637         int caam_jr_pmd = rte_cryptodev_driver_id_get(
638                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
639         int scheduler_pmd = rte_cryptodev_driver_id_get(
640                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
641         int armv8_pmd = rte_cryptodev_driver_id_get(
642                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
643         int aesni_mb_pmd = rte_cryptodev_driver_id_get(
644                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
645         int qat_pmd = rte_cryptodev_driver_id_get(
646                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
647         int mrvl_pmd = rte_cryptodev_driver_id_get(
648                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
649         int virtio_pmd = rte_cryptodev_driver_id_get(
650                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
651         int octeontx_pmd = rte_cryptodev_driver_id_get(
652                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
653
654         switch (test_type) {
655         case BLKCIPHER_AES_CHAIN_TYPE:
656                 n_test_cases = sizeof(aes_chain_test_cases) /
657                 sizeof(aes_chain_test_cases[0]);
658                 tcs = aes_chain_test_cases;
659                 break;
660         case BLKCIPHER_AES_CIPHERONLY_TYPE:
661                 n_test_cases = sizeof(aes_cipheronly_test_cases) /
662                 sizeof(aes_cipheronly_test_cases[0]);
663                 tcs = aes_cipheronly_test_cases;
664                 break;
665         case BLKCIPHER_AES_DOCSIS_TYPE:
666                 n_test_cases = sizeof(aes_docsis_test_cases) /
667                 sizeof(aes_docsis_test_cases[0]);
668                 tcs = aes_docsis_test_cases;
669                 break;
670         case BLKCIPHER_3DES_CHAIN_TYPE:
671                 n_test_cases = sizeof(triple_des_chain_test_cases) /
672                 sizeof(triple_des_chain_test_cases[0]);
673                 tcs = triple_des_chain_test_cases;
674                 break;
675         case BLKCIPHER_3DES_CIPHERONLY_TYPE:
676                 n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
677                 sizeof(triple_des_cipheronly_test_cases[0]);
678                 tcs = triple_des_cipheronly_test_cases;
679                 break;
680         case BLKCIPHER_DES_CIPHERONLY_TYPE:
681                 n_test_cases = sizeof(des_cipheronly_test_cases) /
682                 sizeof(des_cipheronly_test_cases[0]);
683                 tcs = des_cipheronly_test_cases;
684                 break;
685         case BLKCIPHER_DES_DOCSIS_TYPE:
686                 n_test_cases = sizeof(des_docsis_test_cases) /
687                 sizeof(des_docsis_test_cases[0]);
688                 tcs = des_docsis_test_cases;
689                 break;
690         case BLKCIPHER_AUTHONLY_TYPE:
691                 n_test_cases = sizeof(hash_test_cases) /
692                 sizeof(hash_test_cases[0]);
693                 tcs = hash_test_cases;
694                 break;
695         default:
696                 break;
697         }
698
699         if (driver_id == aesni_mb_pmd)
700                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB;
701         else if (driver_id == qat_pmd)
702                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT;
703         else if (driver_id == openssl_pmd)
704                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL;
705         else if (driver_id == armv8_pmd)
706                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8;
707         else if (driver_id == scheduler_pmd)
708                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER;
709         else if (driver_id == dpaa2_sec_pmd)
710                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC;
711         else if (driver_id == ccp_pmd)
712                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CCP;
713         else if (driver_id == dpaa_sec_pmd)
714                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
715         else if (driver_id == caam_jr_pmd)
716                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CAAM_JR;
717         else if (driver_id == mrvl_pmd)
718                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MVSAM;
719         else if (driver_id == virtio_pmd)
720                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
721         else if (driver_id == octeontx_pmd)
722                 target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX;
723         else
724                 TEST_ASSERT(0, "Unrecognized cryptodev type");
725
726         for (i = 0; i < n_test_cases; i++) {
727                 const struct blockcipher_test_case *tc = &tcs[i];
728
729                 if (!(tc->pmd_mask & target_pmd_mask))
730                         continue;
731
732                 status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
733                         sess_mpool, dev_id, driver_id, test_msg);
734
735                 printf("  %u) TestCase %s %s\n", test_index ++,
736                         tc->test_descr, test_msg);
737
738                 if (status != TEST_SUCCESS) {
739                         if (overall_status == TEST_SUCCESS)
740                                 overall_status = status;
741
742                         if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
743                                 break;
744                 }
745         }
746
747         return overall_status;
748 }