app/test: add aes-sha224-hmac for qat
[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         },
231         {
232                 .test_descr = "AES-128-CBC HMAC-SHA384 Decryption Digest "
233                         "Verify",
234                 .test_data = &aes_test_data_9,
235                 .op_mask = AES_TEST_OP_AUTH_VERIFY_DEC,
236                 .pmd_mask = AES_TEST_TARGET_PMD_MB
237         },
238 };
239
240 static int
241 test_AES_one_case(const struct aes_test_case *t,
242         struct rte_mempool *mbuf_pool,
243         struct rte_mempool *op_mpool,
244         uint8_t dev_id,
245         enum rte_cryptodev_type cryptodev_type,
246         char *test_msg)
247 {
248         struct rte_mbuf *ibuf = NULL;
249         struct rte_mbuf *obuf = NULL;
250         struct rte_mbuf *iobuf;
251         struct rte_crypto_sym_xform *cipher_xform = NULL;
252         struct rte_crypto_sym_xform *auth_xform = NULL;
253         struct rte_crypto_sym_xform *init_xform = NULL;
254         struct rte_crypto_sym_op *sym_op = NULL;
255         struct rte_crypto_op *op = NULL;
256         struct rte_cryptodev_sym_session *sess = NULL;
257
258         int status = TEST_SUCCESS;
259         const struct aes_test_data *tdata = t->test_data;
260         uint8_t cipher_key[tdata->cipher_key.len];
261         uint8_t auth_key[tdata->auth_key.len];
262         uint32_t buf_len = tdata->ciphertext.len;
263         uint32_t digest_len = 0;
264         char *buf_p = NULL;
265
266         if (tdata->cipher_key.len)
267                 memcpy(cipher_key, tdata->cipher_key.data,
268                         tdata->cipher_key.len);
269         if (tdata->auth_key.len)
270                 memcpy(auth_key, tdata->auth_key.data,
271                         tdata->auth_key.len);
272
273         switch (cryptodev_type) {
274         case RTE_CRYPTODEV_QAT_SYM_PMD:
275                 digest_len = tdata->digest.len;
276                 break;
277         case RTE_CRYPTODEV_AESNI_MB_PMD:
278                 digest_len = tdata->digest.truncated_len;
279                 break;
280         default:
281                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
282                         __LINE__, "Unsupported PMD type");
283                 status = TEST_FAILED;
284                 goto error_exit;
285         }
286
287         /* preparing data */
288         ibuf = rte_pktmbuf_alloc(mbuf_pool);
289         if (!ibuf) {
290                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
291                         __LINE__, "Allocation of rte_mbuf failed");
292                 status = TEST_FAILED;
293                 goto error_exit;
294         }
295
296         if (t->op_mask & AES_TEST_OP_CIPHER)
297                 buf_len += tdata->iv.len;
298         if (t->op_mask & AES_TEST_OP_AUTH)
299                 buf_len += digest_len;
300
301         buf_p = rte_pktmbuf_append(ibuf, buf_len);
302         if (!buf_p) {
303                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
304                         __LINE__, "No room to append mbuf");
305                 status = TEST_FAILED;
306                 goto error_exit;
307         }
308
309         if (t->op_mask & AES_TEST_OP_CIPHER) {
310                 rte_memcpy(buf_p, tdata->iv.data, tdata->iv.len);
311                 buf_p += tdata->iv.len;
312         }
313
314         /* only encryption requires plaintext.data input,
315          * decryption/(digest gen)/(digest verify) use ciphertext.data
316          * to be computed */
317         if (t->op_mask & AES_TEST_OP_ENCRYPT) {
318                 rte_memcpy(buf_p, tdata->plaintext.data,
319                         tdata->plaintext.len);
320                 buf_p += tdata->plaintext.len;
321         } else {
322                 rte_memcpy(buf_p, tdata->ciphertext.data,
323                         tdata->ciphertext.len);
324                 buf_p += tdata->ciphertext.len;
325         }
326
327         if (t->op_mask & AES_TEST_OP_AUTH_VERIFY)
328                 rte_memcpy(buf_p, tdata->digest.data, digest_len);
329         else
330                 memset(buf_p, 0, digest_len);
331
332         if (t->feature_mask & AES_TEST_FEATURE_OOP) {
333                 obuf = rte_pktmbuf_alloc(mbuf_pool);
334                 if (!obuf) {
335                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
336                                 "FAILED: %s", __LINE__,
337                                 "Allocation of rte_mbuf failed");
338                         status = TEST_FAILED;
339                         goto error_exit;
340                 }
341
342                 buf_p = rte_pktmbuf_append(obuf, buf_len);
343                 if (!buf_p) {
344                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
345                                 "FAILED: %s", __LINE__,
346                                 "No room to append mbuf");
347                         status = TEST_FAILED;
348                         goto error_exit;
349                 }
350                 memset(buf_p, 0, buf_len);
351         }
352
353         /* Generate Crypto op data structure */
354         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
355         if (!op) {
356                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
357                         __LINE__, "Failed to allocate symmetric crypto "
358                         "operation struct");
359                 status = TEST_FAILED;
360                 goto error_exit;
361         }
362
363         sym_op = op->sym;
364
365         sym_op->m_src = ibuf;
366
367         if (t->feature_mask & AES_TEST_FEATURE_OOP) {
368                 sym_op->m_dst = obuf;
369                 iobuf = obuf;
370         } else {
371                 sym_op->m_dst = NULL;
372                 iobuf = ibuf;
373         }
374
375         /* sessionless op requires allocate xform using
376          * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
377          * is used */
378         if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
379                 uint32_t n_xforms = 0;
380
381                 if (t->op_mask & AES_TEST_OP_CIPHER)
382                         n_xforms++;
383                 if (t->op_mask & AES_TEST_OP_AUTH)
384                         n_xforms++;
385
386                 if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
387                         == NULL) {
388                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
389                                 "FAILED: %s", __LINE__, "Failed to "
390                                 "allocate space for crypto transforms");
391                         status = TEST_FAILED;
392                         goto error_exit;
393                 }
394         } else {
395                 cipher_xform = rte_zmalloc(NULL,
396                         sizeof(struct rte_crypto_sym_xform), 0);
397
398                 auth_xform = rte_zmalloc(NULL,
399                         sizeof(struct rte_crypto_sym_xform), 0);
400
401                 if (!cipher_xform || !auth_xform) {
402                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
403                                 "FAILED: %s", __LINE__, "Failed to "
404                                 "allocate memory for crypto transforms");
405                         status = TEST_FAILED;
406                         goto error_exit;
407                 }
408         }
409
410         /* preparing xform, for sessioned op, init_xform is initialized
411          * here and later as param in rte_cryptodev_sym_session_create()
412          * call */
413         if (t->op_mask == AES_TEST_OP_ENC_AUTH_GEN) {
414                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
415                         cipher_xform = op->sym->xform;
416                         auth_xform = cipher_xform->next;
417                         auth_xform->next = NULL;
418                 } else {
419                         cipher_xform->next = auth_xform;
420                         auth_xform->next = NULL;
421                         init_xform = cipher_xform;
422                 }
423         } else if (t->op_mask == AES_TEST_OP_AUTH_VERIFY_DEC) {
424                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS) {
425                         auth_xform = op->sym->xform;
426                         cipher_xform = auth_xform->next;
427                         cipher_xform->next = NULL;
428                 } else {
429                         auth_xform->next = cipher_xform;
430                         cipher_xform->next = NULL;
431                         init_xform = auth_xform;
432                 }
433         } else if ((t->op_mask == AES_TEST_OP_ENCRYPT) ||
434                         (t->op_mask == AES_TEST_OP_DECRYPT)) {
435                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)
436                         cipher_xform = op->sym->xform;
437                 else
438                         init_xform = cipher_xform;
439                 cipher_xform->next = NULL;
440         } else if ((t->op_mask == AES_TEST_OP_AUTH_GEN) ||
441                         (t->op_mask == AES_TEST_OP_AUTH_VERIFY)) {
442                 if (t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)
443                         auth_xform = op->sym->xform;
444                 else
445                         init_xform = auth_xform;
446                 auth_xform->next = NULL;
447         } else {
448                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
449                         __LINE__, "Unrecognized operation");
450                 status = TEST_FAILED;
451                 goto error_exit;
452         }
453
454         /*configure xforms & sym_op cipher and auth data*/
455         if (t->op_mask & AES_TEST_OP_CIPHER) {
456                 cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
457                 cipher_xform->cipher.algo = tdata->crypto_algo;
458                 if (t->op_mask & AES_TEST_OP_ENCRYPT)
459                         cipher_xform->cipher.op =
460                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
461                 else
462                         cipher_xform->cipher.op =
463                                 RTE_CRYPTO_CIPHER_OP_DECRYPT;
464                 cipher_xform->cipher.key.data = cipher_key;
465                 cipher_xform->cipher.key.length = tdata->cipher_key.len;
466
467                 sym_op->cipher.data.offset = tdata->iv.len;
468                 sym_op->cipher.data.length = tdata->ciphertext.len;
469                 sym_op->cipher.iv.data = rte_pktmbuf_mtod(sym_op->m_src,
470                         uint8_t *);
471                 sym_op->cipher.iv.length = tdata->iv.len;
472                 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(
473                         sym_op->m_src);
474         }
475
476         if (t->op_mask & AES_TEST_OP_AUTH) {
477                 uint32_t auth_data_offset = 0;
478                 uint32_t digest_offset = tdata->ciphertext.len;
479
480                 if (t->op_mask & AES_TEST_OP_CIPHER) {
481                         digest_offset += tdata->iv.len;
482                         auth_data_offset += tdata->iv.len;
483                 }
484
485                 auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
486                 auth_xform->auth.algo = tdata->auth_algo;
487                 auth_xform->auth.key.length = tdata->auth_key.len;
488                 auth_xform->auth.key.data = auth_key;
489                 auth_xform->auth.digest_length = digest_len;
490
491                 if (t->op_mask & AES_TEST_OP_AUTH_GEN) {
492                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
493                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
494                                 (iobuf, uint8_t *, digest_offset);
495                         sym_op->auth.digest.phys_addr =
496                                 rte_pktmbuf_mtophys_offset(iobuf,
497                                         digest_offset);
498                 } else {
499                         auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
500                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
501                                 (sym_op->m_src, uint8_t *, digest_offset);
502                         sym_op->auth.digest.phys_addr =
503                                 rte_pktmbuf_mtophys_offset(sym_op->m_src,
504                                         digest_offset);
505                 }
506
507                 sym_op->auth.data.offset = auth_data_offset;
508                 sym_op->auth.data.length = tdata->ciphertext.len;
509                 sym_op->auth.digest.length = digest_len;
510         }
511
512         /* create session for sessioned op */
513         if (!(t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)) {
514                 sess = rte_cryptodev_sym_session_create(dev_id,
515                         init_xform);
516                 if (!sess) {
517                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
518                                 "FAILED: %s", __LINE__,
519                                 "Session creation failed");
520                         status = TEST_FAILED;
521                         goto error_exit;
522                 }
523
524                 /* attach symmetric crypto session to crypto operations */
525                 rte_crypto_op_attach_sym_session(op, sess);
526         }
527
528         /* Process crypto operation */
529         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
530                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
531                         __LINE__, "Error sending packet for encryption");
532                 status = TEST_FAILED;
533                 goto error_exit;
534         }
535
536         op = NULL;
537
538         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
539                 rte_pause();
540
541         if (!op) {
542                 snprintf(test_msg, AES_TEST_MSG_LEN, "line %u FAILED: %s",
543                         __LINE__, "Failed to process sym crypto op");
544                 status = TEST_FAILED;
545                 goto error_exit;
546         }
547
548         TEST_HEXDUMP(stdout, "m_src:",
549                 rte_pktmbuf_mtod(sym_op->m_src, uint8_t *), buf_len);
550         if (t->feature_mask & AES_TEST_FEATURE_OOP)
551                 TEST_HEXDUMP(stdout, "m_dst:",
552                         rte_pktmbuf_mtod(sym_op->m_dst, uint8_t *),
553                         buf_len);
554
555         /* Verify results */
556         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
557                 if (t->op_mask & AES_TEST_OP_AUTH_VERIFY)
558                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
559                                 "FAILED: Digest verification failed "
560                                 "(0x%X)", __LINE__, op->status);
561                 else
562                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
563                                 "FAILED: Digest verification failed "
564                                 "(0x%X)", __LINE__, op->status);
565                 status = TEST_FAILED;
566                 goto error_exit;
567         }
568
569         if (t->op_mask & AES_TEST_OP_CIPHER) {
570                 uint8_t *crypto_res;
571                 const uint8_t *compare_ref;
572                 uint32_t compare_len;
573
574                 crypto_res = rte_pktmbuf_mtod_offset(iobuf, uint8_t *,
575                         tdata->iv.len);
576
577                 if (t->op_mask & AES_TEST_OP_ENCRYPT) {
578                         compare_ref = tdata->ciphertext.data;
579                         compare_len = tdata->ciphertext.len;
580                 } else {
581                         compare_ref = tdata->plaintext.data;
582                         compare_len = tdata->plaintext.len;
583                 }
584
585                 if (memcmp(crypto_res, compare_ref, compare_len)) {
586                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
587                                 "FAILED: %s", __LINE__,
588                                 "Crypto data not as expected");
589                         status = TEST_FAILED;
590                         goto error_exit;
591                 }
592         }
593
594         if (t->op_mask & AES_TEST_OP_AUTH_GEN) {
595                 uint8_t *auth_res;
596
597                 if (t->op_mask & AES_TEST_OP_CIPHER)
598                         auth_res = rte_pktmbuf_mtod_offset(iobuf,
599                                 uint8_t *,
600                                 tdata->iv.len + tdata->ciphertext.len);
601                 else
602                         auth_res = rte_pktmbuf_mtod_offset(iobuf,
603                                 uint8_t *, tdata->ciphertext.len);
604
605                 if (memcmp(auth_res, tdata->digest.data, digest_len)) {
606                         snprintf(test_msg, AES_TEST_MSG_LEN, "line %u "
607                                 "FAILED: %s", __LINE__, "Generated "
608                                 "digest data not as expected");
609                         status = TEST_FAILED;
610                         goto error_exit;
611                 }
612         }
613
614         snprintf(test_msg, AES_TEST_MSG_LEN, "PASS");
615
616 error_exit:
617         if (!(t->feature_mask & AES_TEST_FEATURE_SESSIONLESS)) {
618                 if (sess)
619                         rte_cryptodev_sym_session_free(dev_id, sess);
620                 if (cipher_xform)
621                         rte_free(cipher_xform);
622                 if (auth_xform)
623                         rte_free(auth_xform);
624         }
625
626         if (op)
627                 rte_crypto_op_free(op);
628
629         if (obuf)
630                 rte_pktmbuf_free(obuf);
631
632         if (ibuf)
633                 rte_pktmbuf_free(ibuf);
634
635         return status;
636 }
637
638 int
639 test_AES_all_tests(struct rte_mempool *mbuf_pool,
640         struct rte_mempool *op_mpool,
641         uint8_t dev_id,
642         enum rte_cryptodev_type cryptodev_type)
643 {
644         int status, overall_status = TEST_SUCCESS;
645         uint32_t i, test_index = 0;
646         char test_msg[AES_TEST_MSG_LEN + 1];
647         uint32_t n_test_cases = sizeof(aes_test_cases) /
648                         sizeof(aes_test_cases[0]);
649         uint32_t target_pmd_mask = 0;
650
651         switch (cryptodev_type) {
652         case RTE_CRYPTODEV_AESNI_MB_PMD:
653                 target_pmd_mask = AES_TEST_TARGET_PMD_MB;
654                 break;
655         case RTE_CRYPTODEV_QAT_SYM_PMD:
656                 target_pmd_mask = AES_TEST_TARGET_PMD_QAT;
657                 break;
658         default:
659                 TEST_ASSERT(-1, "Unrecognized cryptodev type");
660                 break;
661         }
662
663         for (i = 0; i < n_test_cases; i++) {
664                 const struct aes_test_case *tc = &aes_test_cases[i];
665
666                 if (!(tc->pmd_mask & target_pmd_mask))
667                         continue;
668
669                 status = test_AES_one_case(tc, mbuf_pool, op_mpool,
670                         dev_id, cryptodev_type, test_msg);
671
672                 printf("  %u) TestCase %s %s\n", test_index ++,
673                         tc->test_descr, test_msg);
674
675                 if (status != TEST_SUCCESS) {
676                         if (overall_status == TEST_SUCCESS)
677                                 overall_status = status;
678
679                         if (tc->feature_mask & AES_TEST_FEATURE_STOPPER)
680                                 break;
681                 }
682         }
683
684         return overall_status;
685 }