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