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