crypto/libcrypto: add driver for OpenSSL library
[dpdk.git] / app / test / test_cryptodev_aes.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Intel Corporation nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
42
43 #include "test.h"
44 #include "test_cryptodev_aes.h"
45
46 #ifndef AES_TEST_MSG_LEN
47 #define AES_TEST_MSG_LEN                256
48 #endif
49
50 #define AES_TEST_OP_ENCRYPT             0x01
51 #define AES_TEST_OP_DECRYPT             0x02
52 #define AES_TEST_OP_AUTH_GEN            0x04
53 #define AES_TEST_OP_AUTH_VERIFY         0x08
54
55 #define AES_TEST_FEATURE_OOP            0x01
56 #define AES_TEST_FEATURE_SESSIONLESS    0x02
57 #define AES_TEST_FEATURE_STOPPER        0x04 /* stop upon failing */
58
59 #define AES_TEST_TARGET_PMD_MB          0x0001 /* Multi-buffer flag */
60 #define AES_TEST_TARGET_PMD_QAT         0x0002 /* QAT flag */
61
62 #define AES_TEST_OP_CIPHER              (AES_TEST_OP_ENCRYPT |          \
63                                         AES_TEST_OP_DECRYPT)
64
65 #define AES_TEST_OP_AUTH                (AES_TEST_OP_AUTH_GEN |         \
66                                         AES_TEST_OP_AUTH_VERIFY)
67
68 #define AES_TEST_OP_ENC_AUTH_GEN        (AES_TEST_OP_ENCRYPT |          \
69                                         AES_TEST_OP_AUTH_GEN)
70
71 #define AES_TEST_OP_AUTH_VERIFY_DEC     (AES_TEST_OP_DECRYPT |          \
72                                         AES_TEST_OP_AUTH_VERIFY)
73
74 struct aes_test_case {
75         const char *test_descr; /* test description */
76         const struct aes_test_data *test_data;
77         uint8_t op_mask; /* operation mask */
78         uint8_t feature_mask;
79         uint32_t pmd_mask;
80 };
81
82 static const struct aes_test_case aes_test_cases[] = {
83         {
84                 .test_descr = "AES-128-CTR HMAC-SHA1 Encryption Digest",
85                 .test_data = &aes_test_data_1,
86                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
87                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
88                         AES_TEST_TARGET_PMD_QAT
89         },
90         {
91                 .test_descr = "AES-128-CTR HMAC-SHA1 Decryption Digest "
92                         "Verify",
93                 .test_data = &aes_test_data_1,
94                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
95                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
96                         AES_TEST_TARGET_PMD_QAT
97         },
98         {
99                 .test_descr = "AES-192-CTR XCBC Encryption Digest",
100                 .test_data = &aes_test_data_2,
101                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
102                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
103                         AES_TEST_TARGET_PMD_QAT
104         },
105         {
106                 .test_descr = "AES-192-CTR XCBC Decryption Digest Verify",
107                 .test_data = &aes_test_data_2,
108                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
109                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
110                         AES_TEST_TARGET_PMD_QAT
111         },
112         {
113                 .test_descr = "AES-256-CTR HMAC-SHA1 Encryption Digest",
114                 .test_data = &aes_test_data_3,
115                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
116                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
117                         AES_TEST_TARGET_PMD_QAT
118         },
119         {
120                 .test_descr = "AES-256-CTR HMAC-SHA1 Decryption Digest "
121                         "Verify",
122                 .test_data = &aes_test_data_3,
123                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
124                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
125                         AES_TEST_TARGET_PMD_QAT
126         },
127         {
128                 .test_descr = "AES-128-CBC HMAC-SHA1 Encryption Digest",
129                 .test_data = &aes_test_data_4,
130                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
131                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
132                         AES_TEST_TARGET_PMD_QAT
133         },
134         {
135                 .test_descr = "AES-128-CBC HMAC-SHA1 Decryption Digest "
136                         "Verify",
137                 .test_data = &aes_test_data_4,
138                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
139                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
140                         AES_TEST_TARGET_PMD_QAT
141         },
142         {
143                 .test_descr = "AES-128-CBC HMAC-SHA256 Encryption Digest",
144                 .test_data = &aes_test_data_5,
145                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
146                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
147                         AES_TEST_TARGET_PMD_QAT
148         },
149         {
150                 .test_descr = "AES-128-CBC HMAC-SHA256 Decryption Digest "
151                         "Verify",
152                 .test_data = &aes_test_data_5,
153                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
154                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
155                         AES_TEST_TARGET_PMD_QAT
156         },
157         {
158                 .test_descr = "AES-128-CBC HMAC-SHA512 Encryption Digest",
159                 .test_data = &aes_test_data_6,
160                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
161                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
162                         AES_TEST_TARGET_PMD_QAT
163         },
164         {
165                 .test_descr = "AES-128-CBC HMAC-SHA512 Encryption Digest "
166                         "Sessionless",
167                 .test_data = &aes_test_data_6,
168                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
169                 .feature_mask = AES_TEST_FEATURE_SESSIONLESS,
170                 .pmd_mask = AES_TEST_TARGET_PMD_MB
171         },
172         {
173                 .test_descr = "AES-128-CBC HMAC-SHA512 Decryption Digest "
174                         "Verify",
175                 .test_data = &aes_test_data_6,
176                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
177                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
178                         AES_TEST_TARGET_PMD_QAT
179         },
180         {
181                 .test_descr = "AES-128-CBC XCBC Encryption Digest",
182                 .test_data = &aes_test_data_7,
183                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
184                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
185                         AES_TEST_TARGET_PMD_QAT
186         },
187         {
188                 .test_descr = "AES-128-CBC XCBC Decryption Digest Verify",
189                 .test_data = &aes_test_data_7,
190                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
191                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
192                         AES_TEST_TARGET_PMD_QAT
193         },
194         {
195                 .test_descr = "AES-128-CBC HMAC-SHA1 Encryption Digest "
196                         "OOP",
197                 .test_data = &aes_test_data_4,
198                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
199                 .feature_mask = AES_TEST_FEATURE_OOP,
200                 .pmd_mask = AES_TEST_TARGET_PMD_QAT
201         },
202         {
203                 .test_descr = "AES-128-CBC HMAC-SHA1 Decryption Digest "
204                         "Verify OOP",
205                 .test_data = &aes_test_data_4,
206                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
207                 .feature_mask = AES_TEST_FEATURE_OOP,
208                 .pmd_mask = AES_TEST_TARGET_PMD_QAT
209         },
210         {
211                 .test_descr = "AES-128-CBC HMAC-SHA224 Encryption Digest",
212                 .test_data = &aes_test_data_8,
213                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
214                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
215                         AES_TEST_TARGET_PMD_QAT
216         },
217         {
218                 .test_descr = "AES-128-CBC HMAC-SHA224 Decryption Digest "
219                         "Verify",
220                 .test_data = &aes_test_data_8,
221                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
222                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
223                         AES_TEST_TARGET_PMD_QAT
224         },
225         {
226                 .test_descr = "AES-128-CBC HMAC-SHA384 Encryption Digest",
227                 .test_data = &aes_test_data_9,
228                 .op_mask = AES_TEST_OP_ENC_AUTH_GEN,
229                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
230                         AES_TEST_TARGET_PMD_QAT
231         },
232         {
233                 .test_descr = "AES-128-CBC HMAC-SHA384 Decryption Digest "
234                         "Verify",
235                 .test_data = &aes_test_data_9,
236                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
237                 .pmd_mask = AES_TEST_TARGET_PMD_MB |
238                         AES_TEST_TARGET_PMD_QAT
239         },
240 };
241
242 static int
243 test_AES_one_case(const struct aes_test_case *t,
244         struct rte_mempool *mbuf_pool,
245         struct rte_mempool *op_mpool,
246         uint8_t dev_id,
247         enum rte_cryptodev_type cryptodev_type,
248         char *test_msg)
249 {
250         struct rte_mbuf *ibuf = NULL;
251         struct rte_mbuf *obuf = NULL;
252         struct rte_mbuf *iobuf;
253         struct rte_crypto_sym_xform *cipher_xform = NULL;
254         struct rte_crypto_sym_xform *auth_xform = NULL;
255         struct rte_crypto_sym_xform *init_xform = NULL;
256         struct rte_crypto_sym_op *sym_op = NULL;
257         struct rte_crypto_op *op = NULL;
258         struct rte_cryptodev_sym_session *sess = NULL;
259
260         int status = TEST_SUCCESS;
261         const struct aes_test_data *tdata = t->test_data;
262         uint8_t cipher_key[tdata->cipher_key.len];
263         uint8_t auth_key[tdata->auth_key.len];
264         uint32_t buf_len = tdata->ciphertext.len;
265         uint32_t digest_len = 0;
266         char *buf_p = NULL;
267
268         if (tdata->cipher_key.len)
269                 memcpy(cipher_key, tdata->cipher_key.data,
270                         tdata->cipher_key.len);
271         if (tdata->auth_key.len)
272                 memcpy(auth_key, tdata->auth_key.data,
273                         tdata->auth_key.len);
274
275         switch (cryptodev_type) {
276         case RTE_CRYPTODEV_QAT_SYM_PMD:
277                 digest_len = tdata->digest.len;
278                 break;
279         case RTE_CRYPTODEV_AESNI_MB_PMD:
280                 digest_len = tdata->digest.truncated_len;
281                 break;
282         default:
283                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
284                         __LINE__, "Unsupported PMD type");
285                 status = TEST_FAILED;
286                 goto error_exit;
287         }
288
289         /* preparing data */
290         ibuf = rte_pktmbuf_alloc(mbuf_pool);
291         if (!ibuf) {
292                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
293                         __LINE__, "Allocation of rte_mbuf failed");
294                 status = TEST_FAILED;
295                 goto error_exit;
296         }
297
298         if (t->op_mask & AES_TEST_OP_CIPHER)
299                 buf_len += tdata->iv.len;
300         if (t->op_mask & AES_TEST_OP_AUTH)
301                 buf_len += digest_len;
302
303         buf_p = rte_pktmbuf_append(ibuf, buf_len);
304         if (!buf_p) {
305                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
306                         __LINE__, "No room to append mbuf");
307                 status = TEST_FAILED;
308                 goto error_exit;
309         }
310
311         if (t->op_mask & AES_TEST_OP_CIPHER) {
312                 rte_memcpy(buf_p, tdata->iv.data, tdata->iv.len);
313                 buf_p += tdata->iv.len;
314         }
315
316         /* only encryption requires plaintext.data input,
317          * decryption/(digest gen)/(digest verify) use ciphertext.data
318          * to be computed */
319         if (t->op_mask & AES_TEST_OP_ENCRYPT) {
320                 rte_memcpy(buf_p, tdata->plaintext.data,
321                         tdata->plaintext.len);
322                 buf_p += tdata->plaintext.len;
323         } else {
324                 rte_memcpy(buf_p, tdata->ciphertext.data,
325                         tdata->ciphertext.len);
326                 buf_p += tdata->ciphertext.len;
327         }
328
329         if (t->op_mask & AES_TEST_OP_AUTH_VERIFY)
330                 rte_memcpy(buf_p, tdata->digest.data, digest_len);
331         else
332                 memset(buf_p, 0, digest_len);
333
334         if (t->feature_mask & AES_TEST_FEATURE_OOP) {
335                 obuf = rte_pktmbuf_alloc(mbuf_pool);
336                 if (!obuf) {
337                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
338                                 "FAILED: %s", __LINE__,
339                                 "Allocation of rte_mbuf failed");
340                         status = TEST_FAILED;
341                         goto error_exit;
342                 }
343
344                 buf_p = rte_pktmbuf_append(obuf, buf_len);
345                 if (!buf_p) {
346                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
347                                 "FAILED: %s", __LINE__,
348                                 "No room to append mbuf");
349                         status = TEST_FAILED;
350                         goto error_exit;
351                 }
352                 memset(buf_p, 0, buf_len);
353         }
354
355         /* Generate Crypto op data structure */
356         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
357         if (!op) {
358                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
359                         __LINE__, "Failed to allocate symmetric crypto "
360                         "operation struct");
361                 status = TEST_FAILED;
362                 goto error_exit;
363         }
364
365         sym_op = op->sym;
366
367         sym_op->m_src = ibuf;
368
369         if (t->feature_mask & AES_TEST_FEATURE_OOP) {
370                 sym_op->m_dst = obuf;
371                 iobuf = obuf;
372         } else {
373                 sym_op->m_dst = NULL;
374                 iobuf = ibuf;
375         }
376
377         /* sessionless op requires allocate xform using
378          * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
379          * is used */
380         if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
381                 uint32_t n_xforms = 0;
382
383                 if (t->op_mask & AES_TEST_OP_CIPHER)
384                         n_xforms++;
385                 if (t->op_mask & AES_TEST_OP_AUTH)
386                         n_xforms++;
387
388                 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
389                         == NULL) {
390                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
391                                 "FAILED: %s", __LINE__, "Failed to "
392                                 "allocate space for crypto transforms");
393                         status = TEST_FAILED;
394                         goto error_exit;
395                 }
396         } else {
397                 cipher_xform = rte_zmalloc(NULL,
398                         sizeof(struct rte_crypto_sym_xform), 0);
399
400                 auth_xform = rte_zmalloc(NULL,
401                         sizeof(struct rte_crypto_sym_xform), 0);
402
403                 if (!cipher_xform || !auth_xform) {
404                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
405                                 "FAILED: %s", __LINE__, "Failed to "
406                                 "allocate memory for crypto transforms");
407                         status = TEST_FAILED;
408                         goto error_exit;
409                 }
410         }
411
412         /* preparing xform, for sessioned op, init_xform is initialized
413          * here and later as param in rte_cryptodev_sym_session_create()
414          * call */
415         if (t->op_mask == AES_TEST_OP_ENC_AUTH_GEN) {
416                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
417                         cipher_xform = op->sym->xform;
418                         auth_xform = cipher_xform->next;
419                         auth_xform->next = NULL;
420                 } else {
421                         cipher_xform->next = auth_xform;
422                         auth_xform->next = NULL;
423                         init_xform = cipher_xform;
424                 }
425         } else if (t->op_mask == AES_TEST_OP_AUTH_VERIFY_DEC) {
426                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
427                         auth_xform = op->sym->xform;
428                         cipher_xform = auth_xform->next;
429                         cipher_xform->next = NULL;
430                 } else {
431                         auth_xform->next = cipher_xform;
432                         cipher_xform->next = NULL;
433                         init_xform = auth_xform;
434                 }
435         } else if ((t->op_mask == AES_TEST_OP_ENCRYPT) ||
436                         (t->op_mask == AES_TEST_OP_DECRYPT)) {
437                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)
438                         cipher_xform = op->sym->xform;
439                 else
440                         init_xform = cipher_xform;
441                 cipher_xform->next = NULL;
442         } else if ((t->op_mask == AES_TEST_OP_AUTH_GEN) ||
443                         (t->op_mask == AES_TEST_OP_AUTH_VERIFY)) {
444                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)
445                         auth_xform = op->sym->xform;
446                 else
447                         init_xform = auth_xform;
448                 auth_xform->next = NULL;
449         } else {
450                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
451                         __LINE__, "Unrecognized operation");
452                 status = TEST_FAILED;
453                 goto error_exit;
454         }
455
456         /*configure xforms & sym_op cipher and auth data*/
457         if (t->op_mask & AES_TEST_OP_CIPHER) {
458                 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
459                 cipher_xform->cipher.algo = tdata->crypto_algo;
460                 if (t->op_mask & AES_TEST_OP_ENCRYPT)
461                         cipher_xform->cipher.op =
462                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
463                 else
464                         cipher_xform->cipher.op =
465                                 RTE_CRYPTO_CIPHER_OP_DECRYPT;
466                 cipher_xform->cipher.key.data = cipher_key;
467                 cipher_xform->cipher.key.length = tdata->cipher_key.len;
468
469                 sym_op->cipher.data.offset = tdata->iv.len;
470                 sym_op->cipher.data.length = tdata->ciphertext.len;
471                 sym_op->cipher.iv.data = rte_pktmbuf_mtod(sym_op->m_src,
472                         uint8_t *);
473                 sym_op->cipher.iv.length = tdata->iv.len;
474                 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(
475                         sym_op->m_src);
476         }
477
478         if (t->op_mask & AES_TEST_OP_AUTH) {
479                 uint32_t auth_data_offset = 0;
480                 uint32_t digest_offset = tdata->ciphertext.len;
481
482                 if (t->op_mask & AES_TEST_OP_CIPHER) {
483                         digest_offset += tdata->iv.len;
484                         auth_data_offset += tdata->iv.len;
485                 }
486
487                 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
488                 auth_xform->auth.algo = tdata->auth_algo;
489                 auth_xform->auth.key.length = tdata->auth_key.len;
490                 auth_xform->auth.key.data = auth_key;
491                 auth_xform->auth.digest_length = digest_len;
492
493                 if (t->op_mask & AES_TEST_OP_AUTH_GEN) {
494                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
495                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
496                                 (iobuf, uint8_t *, digest_offset);
497                         sym_op->auth.digest.phys_addr =
498                                 rte_pktmbuf_mtophys_offset(iobuf,
499                                         digest_offset);
500                 } else {
501                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
502                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
503                                 (sym_op->m_src, uint8_t *, digest_offset);
504                         sym_op->auth.digest.phys_addr =
505                                 rte_pktmbuf_mtophys_offset(sym_op->m_src,
506                                         digest_offset);
507                 }
508
509                 sym_op->auth.data.offset = auth_data_offset;
510                 sym_op->auth.data.length = tdata->ciphertext.len;
511                 sym_op->auth.digest.length = digest_len;
512         }
513
514         /* create session for sessioned op */
515         if (!(t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)) {
516                 sess = rte_cryptodev_sym_session_create(dev_id,
517                         init_xform);
518                 if (!sess) {
519                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
520                                 "FAILED: %s", __LINE__,
521                                 "Session creation failed");
522                         status = TEST_FAILED;
523                         goto error_exit;
524                 }
525
526                 /* attach symmetric crypto session to crypto operations */
527                 rte_crypto_op_attach_sym_session(op, sess);
528         }
529
530         /* Process crypto operation */
531         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
532                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
533                         __LINE__, "Error sending packet for encryption");
534                 status = TEST_FAILED;
535                 goto error_exit;
536         }
537
538         op = NULL;
539
540         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
541                 rte_pause();
542
543         if (!op) {
544                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
545                         __LINE__, "Failed to process sym crypto op");
546                 status = TEST_FAILED;
547                 goto error_exit;
548         }
549
550         TEST_HEXDUMP(stdout, "m_src:",
551                 rte_pktmbuf_mtod(sym_op->m_src, uint8_t *), buf_len);
552         if (t->feature_mask & AES_TEST_FEATURE_OOP)
553                 TEST_HEXDUMP(stdout, "m_dst:",
554                         rte_pktmbuf_mtod(sym_op->m_dst, uint8_t *),
555                         buf_len);
556
557         /* Verify results */
558         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
559                 if (t->op_mask & AES_TEST_OP_AUTH_VERIFY)
560                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
561                                 "FAILED: Digest verification failed "
562                                 "(0x%X)", __LINE__, op->status);
563                 else
564                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
565                                 "FAILED: Digest verification failed "
566                                 "(0x%X)", __LINE__, op->status);
567                 status = TEST_FAILED;
568                 goto error_exit;
569         }
570
571         if (t->op_mask & AES_TEST_OP_CIPHER) {
572                 uint8_t *crypto_res;
573                 const uint8_t *compare_ref;
574                 uint32_t compare_len;
575
576                 crypto_res = rte_pktmbuf_mtod_offset(iobuf, uint8_t *,
577                         tdata->iv.len);
578
579                 if (t->op_mask & AES_TEST_OP_ENCRYPT) {
580                         compare_ref = tdata->ciphertext.data;
581                         compare_len = tdata->ciphertext.len;
582                 } else {
583                         compare_ref = tdata->plaintext.data;
584                         compare_len = tdata->plaintext.len;
585                 }
586
587                 if (memcmp(crypto_res, compare_ref, compare_len)) {
588                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
589                                 "FAILED: %s", __LINE__,
590                                 "Crypto data not as expected");
591                         status = TEST_FAILED;
592                         goto error_exit;
593                 }
594         }
595
596         if (t->op_mask & AES_TEST_OP_AUTH_GEN) {
597                 uint8_t *auth_res;
598
599                 if (t->op_mask & AES_TEST_OP_CIPHER)
600                         auth_res = rte_pktmbuf_mtod_offset(iobuf,
601                                 uint8_t *,
602                                 tdata->iv.len + tdata->ciphertext.len);
603                 else
604                         auth_res = rte_pktmbuf_mtod_offset(iobuf,
605                                 uint8_t *, tdata->ciphertext.len);
606
607                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
608                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
609                                 "FAILED: %s", __LINE__, "Generated "
610                                 "digest data not as expected");
611                         status = TEST_FAILED;
612                         goto error_exit;
613                 }
614         }
615
616         snprintf(test_msg, AES_TEST_MSG_LEN, "PASS");
617
618 error_exit:
619         if (!(t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)) {
620                 if (sess)
621                         rte_cryptodev_sym_session_free(dev_id, sess);
622                 if (cipher_xform)
623                         rte_free(cipher_xform);
624                 if (auth_xform)
625                         rte_free(auth_xform);
626         }
627
628         if (op)
629                 rte_crypto_op_free(op);
630
631         if (obuf)
632                 rte_pktmbuf_free(obuf);
633
634         if (ibuf)
635                 rte_pktmbuf_free(ibuf);
636
637         return status;
638 }
639
640 int
641 test_AES_all_tests(struct rte_mempool *mbuf_pool,
642         struct rte_mempool *op_mpool,
643         uint8_t dev_id,
644         enum rte_cryptodev_type cryptodev_type)
645 {
646         int status, overall_status = TEST_SUCCESS;
647         uint32_t i, test_index = 0;
648         char test_msg[AES_TEST_MSG_LEN + 1];
649         uint32_t n_test_cases = sizeof(aes_test_cases) /
650                         sizeof(aes_test_cases[0]);
651         uint32_t target_pmd_mask = 0;
652
653         switch (cryptodev_type) {
654         case RTE_CRYPTODEV_AESNI_MB_PMD:
655                 target_pmd_mask = AES_TEST_TARGET_PMD_MB;
656                 break;
657         case RTE_CRYPTODEV_QAT_SYM_PMD:
658                 target_pmd_mask = AES_TEST_TARGET_PMD_QAT;
659                 break;
660         default:
661                 TEST_ASSERT(-1, "Unrecognized cryptodev type");
662                 break;
663         }
664
665         for (i = 0; i < n_test_cases; i++) {
666                 const struct aes_test_case *tc = &aes_test_cases[i];
667
668                 if (!(tc->pmd_mask & target_pmd_mask))
669                         continue;
670
671                 status = test_AES_one_case(tc, mbuf_pool, op_mpool,
672                         dev_id, cryptodev_type, test_msg);
673
674                 printf("  %u) TestCase %s %s\n", test_index ++,
675                         tc->test_descr, test_msg);
676
677                 if (status != TEST_SUCCESS) {
678                         if (overall_status == TEST_SUCCESS)
679                                 overall_status = status;
680
681                         if (tc->feature_mask & AES_TEST_FEATURE_STOPPER)
682                                 break;
683                 }
684         }
685
686         return overall_status;
687 }