test/crypto: fix session init failure for wireless case
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2019 Intel Corporation
3  */
4
5 #include <time.h>
6
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_mbuf.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
13 #include <rte_bus_vdev.h>
14
15 #include <rte_crypto.h>
16 #include <rte_cryptodev.h>
17 #include <rte_cryptodev_pmd.h>
18 #include <rte_string_fns.h>
19
20 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
21 #include <rte_cryptodev_scheduler.h>
22 #include <rte_cryptodev_scheduler_operations.h>
23 #endif
24
25 #include <rte_lcore.h>
26
27 #include "test.h"
28 #include "test_cryptodev.h"
29
30 #include "test_cryptodev_blockcipher.h"
31 #include "test_cryptodev_aes_test_vectors.h"
32 #include "test_cryptodev_des_test_vectors.h"
33 #include "test_cryptodev_hash_test_vectors.h"
34 #include "test_cryptodev_kasumi_test_vectors.h"
35 #include "test_cryptodev_kasumi_hash_test_vectors.h"
36 #include "test_cryptodev_snow3g_test_vectors.h"
37 #include "test_cryptodev_snow3g_hash_test_vectors.h"
38 #include "test_cryptodev_zuc_test_vectors.h"
39 #include "test_cryptodev_aead_test_vectors.h"
40 #include "test_cryptodev_hmac_test_vectors.h"
41
42 #define VDEV_ARGS_SIZE 100
43 #define MAX_NB_SESSIONS 4
44
45 #define IN_PLACE 0
46 #define OUT_OF_PLACE 1
47
48 static int gbl_driver_id;
49
50 struct crypto_testsuite_params {
51         struct rte_mempool *mbuf_pool;
52         struct rte_mempool *large_mbuf_pool;
53         struct rte_mempool *op_mpool;
54         struct rte_mempool *session_mpool;
55         struct rte_mempool *session_priv_mpool;
56         struct rte_cryptodev_config conf;
57         struct rte_cryptodev_qp_conf qp_conf;
58
59         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
60         uint8_t valid_dev_count;
61 };
62
63 struct crypto_unittest_params {
64         struct rte_crypto_sym_xform cipher_xform;
65         struct rte_crypto_sym_xform auth_xform;
66         struct rte_crypto_sym_xform aead_xform;
67
68         struct rte_cryptodev_sym_session *sess;
69
70         struct rte_crypto_op *op;
71
72         struct rte_mbuf *obuf, *ibuf;
73
74         uint8_t *digest;
75 };
76
77 #define ALIGN_POW2_ROUNDUP(num, align) \
78         (((num) + (align) - 1) & ~((align) - 1))
79
80 /*
81  * Forward declarations.
82  */
83 static int
84 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
85                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
86                 uint8_t *hmac_key);
87
88 static int
89 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
90                 struct crypto_unittest_params *ut_params,
91                 struct crypto_testsuite_params *ts_param,
92                 const uint8_t *cipher,
93                 const uint8_t *digest,
94                 const uint8_t *iv);
95
96 static struct rte_mbuf *
97 setup_test_string(struct rte_mempool *mpool,
98                 const char *string, size_t len, uint8_t blocksize)
99 {
100         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
101         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
102
103         memset(m->buf_addr, 0, m->buf_len);
104         if (m) {
105                 char *dst = rte_pktmbuf_append(m, t_len);
106
107                 if (!dst) {
108                         rte_pktmbuf_free(m);
109                         return NULL;
110                 }
111                 if (string != NULL)
112                         rte_memcpy(dst, string, t_len);
113                 else
114                         memset(dst, 0, t_len);
115         }
116
117         return m;
118 }
119
120 /* Get number of bytes in X bits (rounding up) */
121 static uint32_t
122 ceil_byte_length(uint32_t num_bits)
123 {
124         if (num_bits % 8)
125                 return ((num_bits >> 3) + 1);
126         else
127                 return (num_bits >> 3);
128 }
129
130 static struct rte_crypto_op *
131 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
132 {
133         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
134                 printf("Error sending packet for encryption");
135                 return NULL;
136         }
137
138         op = NULL;
139
140         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
141                 rte_pause();
142
143         return op;
144 }
145
146 static struct crypto_testsuite_params testsuite_params = { NULL };
147 static struct crypto_unittest_params unittest_params;
148
149 static int
150 testsuite_setup(void)
151 {
152         struct crypto_testsuite_params *ts_params = &testsuite_params;
153         struct rte_cryptodev_info info;
154         uint32_t i = 0, nb_devs, dev_id;
155         int ret;
156         uint16_t qp_id;
157
158         memset(ts_params, 0, sizeof(*ts_params));
159
160         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
161         if (ts_params->mbuf_pool == NULL) {
162                 /* Not already created so create */
163                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
164                                 "CRYPTO_MBUFPOOL",
165                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
166                                 rte_socket_id());
167                 if (ts_params->mbuf_pool == NULL) {
168                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
169                         return TEST_FAILED;
170                 }
171         }
172
173         ts_params->large_mbuf_pool = rte_mempool_lookup(
174                         "CRYPTO_LARGE_MBUFPOOL");
175         if (ts_params->large_mbuf_pool == NULL) {
176                 /* Not already created so create */
177                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
178                                 "CRYPTO_LARGE_MBUFPOOL",
179                                 1, 0, 0, UINT16_MAX,
180                                 rte_socket_id());
181                 if (ts_params->large_mbuf_pool == NULL) {
182                         RTE_LOG(ERR, USER1,
183                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
184                         return TEST_FAILED;
185                 }
186         }
187
188         ts_params->op_mpool = rte_crypto_op_pool_create(
189                         "MBUF_CRYPTO_SYM_OP_POOL",
190                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
191                         NUM_MBUFS, MBUF_CACHE_SIZE,
192                         DEFAULT_NUM_XFORMS *
193                         sizeof(struct rte_crypto_sym_xform) +
194                         MAXIMUM_IV_LENGTH,
195                         rte_socket_id());
196         if (ts_params->op_mpool == NULL) {
197                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
198                 return TEST_FAILED;
199         }
200
201         /* Create an AESNI MB device if required */
202         if (gbl_driver_id == rte_cryptodev_driver_id_get(
203                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
204                 nb_devs = rte_cryptodev_device_count_by_driver(
205                                 rte_cryptodev_driver_id_get(
206                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
207                 if (nb_devs < 1) {
208                         ret = rte_vdev_init(
209                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
210
211                         TEST_ASSERT(ret == 0,
212                                 "Failed to create instance of"
213                                 " pmd : %s",
214                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
215                 }
216         }
217
218         /* Create an AESNI GCM device if required */
219         if (gbl_driver_id == rte_cryptodev_driver_id_get(
220                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
221                 nb_devs = rte_cryptodev_device_count_by_driver(
222                                 rte_cryptodev_driver_id_get(
223                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
224                 if (nb_devs < 1) {
225                         TEST_ASSERT_SUCCESS(rte_vdev_init(
226                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
227                                 "Failed to create instance of"
228                                 " pmd : %s",
229                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
230                 }
231         }
232
233         /* Create a SNOW 3G device if required */
234         if (gbl_driver_id == rte_cryptodev_driver_id_get(
235                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
236                 nb_devs = rte_cryptodev_device_count_by_driver(
237                                 rte_cryptodev_driver_id_get(
238                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
239                 if (nb_devs < 1) {
240                         TEST_ASSERT_SUCCESS(rte_vdev_init(
241                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
242                                 "Failed to create instance of"
243                                 " pmd : %s",
244                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
245                 }
246         }
247
248         /* Create a KASUMI device if required */
249         if (gbl_driver_id == rte_cryptodev_driver_id_get(
250                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
251                 nb_devs = rte_cryptodev_device_count_by_driver(
252                                 rte_cryptodev_driver_id_get(
253                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
254                 if (nb_devs < 1) {
255                         TEST_ASSERT_SUCCESS(rte_vdev_init(
256                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
257                                 "Failed to create instance of"
258                                 " pmd : %s",
259                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
260                 }
261         }
262
263         /* Create a ZUC device if required */
264         if (gbl_driver_id == rte_cryptodev_driver_id_get(
265                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
266                 nb_devs = rte_cryptodev_device_count_by_driver(
267                                 rte_cryptodev_driver_id_get(
268                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
269                 if (nb_devs < 1) {
270                         TEST_ASSERT_SUCCESS(rte_vdev_init(
271                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
272                                 "Failed to create instance of"
273                                 " pmd : %s",
274                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
275                 }
276         }
277
278         /* Create a NULL device if required */
279         if (gbl_driver_id == rte_cryptodev_driver_id_get(
280                         RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
281                 nb_devs = rte_cryptodev_device_count_by_driver(
282                                 rte_cryptodev_driver_id_get(
283                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
284                 if (nb_devs < 1) {
285                         ret = rte_vdev_init(
286                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
287
288                         TEST_ASSERT(ret == 0,
289                                 "Failed to create instance of"
290                                 " pmd : %s",
291                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
292                 }
293         }
294
295         /* Create an OPENSSL device if required */
296         if (gbl_driver_id == rte_cryptodev_driver_id_get(
297                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
298                 nb_devs = rte_cryptodev_device_count_by_driver(
299                                 rte_cryptodev_driver_id_get(
300                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
301                 if (nb_devs < 1) {
302                         ret = rte_vdev_init(
303                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
304                                 NULL);
305
306                         TEST_ASSERT(ret == 0, "Failed to create "
307                                 "instance of pmd : %s",
308                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
309                 }
310         }
311
312         /* Create a ARMv8 device if required */
313         if (gbl_driver_id == rte_cryptodev_driver_id_get(
314                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
315                 nb_devs = rte_cryptodev_device_count_by_driver(
316                                 rte_cryptodev_driver_id_get(
317                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
318                 if (nb_devs < 1) {
319                         ret = rte_vdev_init(
320                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
321                                 NULL);
322
323                         TEST_ASSERT(ret == 0, "Failed to create "
324                                 "instance of pmd : %s",
325                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
326                 }
327         }
328
329         /* Create a MVSAM device if required */
330         if (gbl_driver_id == rte_cryptodev_driver_id_get(
331                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) {
332                 nb_devs = rte_cryptodev_device_count_by_driver(
333                                 rte_cryptodev_driver_id_get(
334                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)));
335                 if (nb_devs < 1) {
336                         ret = rte_vdev_init(
337                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD),
338                                 NULL);
339
340                         TEST_ASSERT(ret == 0, "Failed to create "
341                                 "instance of pmd : %s",
342                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
343                 }
344         }
345
346         /* Create an CCP device if required */
347         if (gbl_driver_id == rte_cryptodev_driver_id_get(
348                         RTE_STR(CRYPTODEV_NAME_CCP_PMD))) {
349                 nb_devs = rte_cryptodev_device_count_by_driver(
350                                 rte_cryptodev_driver_id_get(
351                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)));
352                 if (nb_devs < 1) {
353                         ret = rte_vdev_init(
354                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD),
355                                 NULL);
356
357                         TEST_ASSERT(ret == 0, "Failed to create "
358                                 "instance of pmd : %s",
359                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD));
360                 }
361         }
362
363 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
364         char vdev_args[VDEV_ARGS_SIZE] = {""};
365         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
366                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
367         uint16_t slave_core_count = 0;
368         uint16_t socket_id = 0;
369
370         if (gbl_driver_id == rte_cryptodev_driver_id_get(
371                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
372
373                 /* Identify the Slave Cores
374                  * Use 2 slave cores for the device args
375                  */
376                 RTE_LCORE_FOREACH_SLAVE(i) {
377                         if (slave_core_count > 1)
378                                 break;
379                         snprintf(vdev_args, sizeof(vdev_args),
380                                         "%s%d", temp_str, i);
381                         strcpy(temp_str, vdev_args);
382                         strlcat(temp_str, ";", sizeof(temp_str));
383                         slave_core_count++;
384                         socket_id = rte_lcore_to_socket_id(i);
385                 }
386                 if (slave_core_count != 2) {
387                         RTE_LOG(ERR, USER1,
388                                 "Cryptodev scheduler test require at least "
389                                 "two slave cores to run. "
390                                 "Please use the correct coremask.\n");
391                         return TEST_FAILED;
392                 }
393                 strcpy(temp_str, vdev_args);
394                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
395                                 temp_str, socket_id);
396                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
397                 nb_devs = rte_cryptodev_device_count_by_driver(
398                                 rte_cryptodev_driver_id_get(
399                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
400                 if (nb_devs < 1) {
401                         ret = rte_vdev_init(
402                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
403                                         vdev_args);
404                         TEST_ASSERT(ret == 0,
405                                 "Failed to create instance %u of"
406                                 " pmd : %s",
407                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
408                 }
409         }
410 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
411
412         nb_devs = rte_cryptodev_count();
413         if (nb_devs < 1) {
414                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
415                 return TEST_SKIPPED;
416         }
417
418         /* Create list of valid crypto devs */
419         for (i = 0; i < nb_devs; i++) {
420                 rte_cryptodev_info_get(i, &info);
421                 if (info.driver_id == gbl_driver_id)
422                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
423         }
424
425         if (ts_params->valid_dev_count < 1)
426                 return TEST_FAILED;
427
428         /* Set up all the qps on the first of the valid devices found */
429
430         dev_id = ts_params->valid_devs[0];
431
432         rte_cryptodev_info_get(dev_id, &info);
433
434         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
435         ts_params->conf.socket_id = SOCKET_ID_ANY;
436         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
437
438         unsigned int session_size =
439                 rte_cryptodev_sym_get_private_session_size(dev_id);
440
441         /*
442          * Create mempool with maximum number of sessions * 2,
443          * to include the session headers
444          */
445         if (info.sym.max_nb_sessions != 0 &&
446                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
447                 RTE_LOG(ERR, USER1, "Device does not support "
448                                 "at least %u sessions\n",
449                                 MAX_NB_SESSIONS);
450                 return TEST_FAILED;
451         }
452
453         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
454                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
455                         SOCKET_ID_ANY);
456         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
457                         "session mempool allocation failed");
458
459         ts_params->session_priv_mpool = rte_mempool_create(
460                         "test_sess_mp_priv",
461                         MAX_NB_SESSIONS,
462                         session_size,
463                         0, 0, NULL, NULL, NULL,
464                         NULL, SOCKET_ID_ANY,
465                         0);
466         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
467                         "session mempool allocation failed");
468
469
470
471         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
472                         &ts_params->conf),
473                         "Failed to configure cryptodev %u with %u qps",
474                         dev_id, ts_params->conf.nb_queue_pairs);
475
476         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
477         ts_params->qp_conf.mp_session = ts_params->session_mpool;
478         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
479
480         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
481                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
482                         dev_id, qp_id, &ts_params->qp_conf,
483                         rte_cryptodev_socket_id(dev_id)),
484                         "Failed to setup queue pair %u on cryptodev %u",
485                         qp_id, dev_id);
486         }
487
488         return TEST_SUCCESS;
489 }
490
491 static void
492 testsuite_teardown(void)
493 {
494         struct crypto_testsuite_params *ts_params = &testsuite_params;
495
496         if (ts_params->mbuf_pool != NULL) {
497                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
498                 rte_mempool_avail_count(ts_params->mbuf_pool));
499         }
500
501         if (ts_params->op_mpool != NULL) {
502                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
503                 rte_mempool_avail_count(ts_params->op_mpool));
504         }
505
506         /* Free session mempools */
507         if (ts_params->session_priv_mpool != NULL) {
508                 rte_mempool_free(ts_params->session_priv_mpool);
509                 ts_params->session_priv_mpool = NULL;
510         }
511
512         if (ts_params->session_mpool != NULL) {
513                 rte_mempool_free(ts_params->session_mpool);
514                 ts_params->session_mpool = NULL;
515         }
516 }
517
518 static int
519 ut_setup(void)
520 {
521         struct crypto_testsuite_params *ts_params = &testsuite_params;
522         struct crypto_unittest_params *ut_params = &unittest_params;
523
524         uint16_t qp_id;
525
526         /* Clear unit test parameters before running test */
527         memset(ut_params, 0, sizeof(*ut_params));
528
529         /* Reconfigure device to default parameters */
530         ts_params->conf.socket_id = SOCKET_ID_ANY;
531         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
532         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
533         ts_params->qp_conf.mp_session = ts_params->session_mpool;
534         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
535
536         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
537                         &ts_params->conf),
538                         "Failed to configure cryptodev %u",
539                         ts_params->valid_devs[0]);
540
541         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
542                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
543                         ts_params->valid_devs[0], qp_id,
544                         &ts_params->qp_conf,
545                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
546                         "Failed to setup queue pair %u on cryptodev %u",
547                         qp_id, ts_params->valid_devs[0]);
548         }
549
550
551         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
552
553         /* Start the device */
554         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
555                         "Failed to start cryptodev %u",
556                         ts_params->valid_devs[0]);
557
558         return TEST_SUCCESS;
559 }
560
561 static void
562 ut_teardown(void)
563 {
564         struct crypto_testsuite_params *ts_params = &testsuite_params;
565         struct crypto_unittest_params *ut_params = &unittest_params;
566         struct rte_cryptodev_stats stats;
567
568         /* free crypto session structure */
569         if (ut_params->sess) {
570                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
571                                 ut_params->sess);
572                 rte_cryptodev_sym_session_free(ut_params->sess);
573                 ut_params->sess = NULL;
574         }
575
576         /* free crypto operation structure */
577         if (ut_params->op)
578                 rte_crypto_op_free(ut_params->op);
579
580         /*
581          * free mbuf - both obuf and ibuf are usually the same,
582          * so check if they point at the same address is necessary,
583          * to avoid freeing the mbuf twice.
584          */
585         if (ut_params->obuf) {
586                 rte_pktmbuf_free(ut_params->obuf);
587                 if (ut_params->ibuf == ut_params->obuf)
588                         ut_params->ibuf = 0;
589                 ut_params->obuf = 0;
590         }
591         if (ut_params->ibuf) {
592                 rte_pktmbuf_free(ut_params->ibuf);
593                 ut_params->ibuf = 0;
594         }
595
596         if (ts_params->mbuf_pool != NULL)
597                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
598                         rte_mempool_avail_count(ts_params->mbuf_pool));
599
600         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
601
602         /* Stop the device */
603         rte_cryptodev_stop(ts_params->valid_devs[0]);
604 }
605
606 static int
607 test_device_configure_invalid_dev_id(void)
608 {
609         struct crypto_testsuite_params *ts_params = &testsuite_params;
610         uint16_t dev_id, num_devs = 0;
611
612         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
613                         "Need at least %d devices for test", 1);
614
615         /* valid dev_id values */
616         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
617
618         /* Stop the device in case it's started so it can be configured */
619         rte_cryptodev_stop(dev_id);
620
621         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
622                         "Failed test for rte_cryptodev_configure: "
623                         "invalid dev_num %u", dev_id);
624
625         /* invalid dev_id values */
626         dev_id = num_devs;
627
628         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
629                         "Failed test for rte_cryptodev_configure: "
630                         "invalid dev_num %u", dev_id);
631
632         dev_id = 0xff;
633
634         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
635                         "Failed test for rte_cryptodev_configure:"
636                         "invalid dev_num %u", dev_id);
637
638         return TEST_SUCCESS;
639 }
640
641 static int
642 test_device_configure_invalid_queue_pair_ids(void)
643 {
644         struct crypto_testsuite_params *ts_params = &testsuite_params;
645         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
646
647         /* Stop the device in case it's started so it can be configured */
648         rte_cryptodev_stop(ts_params->valid_devs[0]);
649
650         /* valid - one queue pairs */
651         ts_params->conf.nb_queue_pairs = 1;
652
653         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
654                         &ts_params->conf),
655                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
656                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
657
658
659         /* valid - max value queue pairs */
660         ts_params->conf.nb_queue_pairs = orig_nb_qps;
661
662         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
663                         &ts_params->conf),
664                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
665                         ts_params->valid_devs[0],
666                         ts_params->conf.nb_queue_pairs);
667
668
669         /* invalid - zero queue pairs */
670         ts_params->conf.nb_queue_pairs = 0;
671
672         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
673                         &ts_params->conf),
674                         "Failed test for rte_cryptodev_configure, dev_id %u,"
675                         " invalid qps: %u",
676                         ts_params->valid_devs[0],
677                         ts_params->conf.nb_queue_pairs);
678
679
680         /* invalid - max value supported by field queue pairs */
681         ts_params->conf.nb_queue_pairs = UINT16_MAX;
682
683         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
684                         &ts_params->conf),
685                         "Failed test for rte_cryptodev_configure, dev_id %u,"
686                         " invalid qps: %u",
687                         ts_params->valid_devs[0],
688                         ts_params->conf.nb_queue_pairs);
689
690
691         /* invalid - max value + 1 queue pairs */
692         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
693
694         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
695                         &ts_params->conf),
696                         "Failed test for rte_cryptodev_configure, dev_id %u,"
697                         " invalid qps: %u",
698                         ts_params->valid_devs[0],
699                         ts_params->conf.nb_queue_pairs);
700
701         /* revert to original testsuite value */
702         ts_params->conf.nb_queue_pairs = orig_nb_qps;
703
704         return TEST_SUCCESS;
705 }
706
707 static int
708 test_queue_pair_descriptor_setup(void)
709 {
710         struct crypto_testsuite_params *ts_params = &testsuite_params;
711         struct rte_cryptodev_info dev_info;
712         struct rte_cryptodev_qp_conf qp_conf = {
713                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
714         };
715
716         uint16_t qp_id;
717
718         /* Stop the device in case it's started so it can be configured */
719         rte_cryptodev_stop(ts_params->valid_devs[0]);
720
721
722         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
723
724         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
725                         &ts_params->conf),
726                         "Failed to configure cryptodev %u",
727                         ts_params->valid_devs[0]);
728
729         /*
730          * Test various ring sizes on this device. memzones can't be
731          * freed so are re-used if ring is released and re-created.
732          */
733         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
734         qp_conf.mp_session = ts_params->session_mpool;
735         qp_conf.mp_session_private = ts_params->session_priv_mpool;
736
737         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
738                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
739                                 ts_params->valid_devs[0], qp_id, &qp_conf,
740                                 rte_cryptodev_socket_id(
741                                                 ts_params->valid_devs[0])),
742                                 "Failed test for "
743                                 "rte_cryptodev_queue_pair_setup: num_inflights "
744                                 "%u on qp %u on cryptodev %u",
745                                 qp_conf.nb_descriptors, qp_id,
746                                 ts_params->valid_devs[0]);
747         }
748
749         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
750
751         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
752                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
753                                 ts_params->valid_devs[0], qp_id, &qp_conf,
754                                 rte_cryptodev_socket_id(
755                                                 ts_params->valid_devs[0])),
756                                 "Failed test for"
757                                 " rte_cryptodev_queue_pair_setup: num_inflights"
758                                 " %u on qp %u on cryptodev %u",
759                                 qp_conf.nb_descriptors, qp_id,
760                                 ts_params->valid_devs[0]);
761         }
762
763         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
764
765         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
766                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
767                                 ts_params->valid_devs[0], qp_id, &qp_conf,
768                                 rte_cryptodev_socket_id(
769                                                 ts_params->valid_devs[0])),
770                                 "Failed test for "
771                                 "rte_cryptodev_queue_pair_setup: num_inflights"
772                                 " %u on qp %u on cryptodev %u",
773                                 qp_conf.nb_descriptors, qp_id,
774                                 ts_params->valid_devs[0]);
775         }
776
777         /* invalid number of descriptors - max supported + 2 */
778         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
779
780         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
781                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
782                                 ts_params->valid_devs[0], qp_id, &qp_conf,
783                                 rte_cryptodev_socket_id(
784                                                 ts_params->valid_devs[0])),
785                                 "Unexpectedly passed test for "
786                                 "rte_cryptodev_queue_pair_setup:"
787                                 "num_inflights %u on qp %u on cryptodev %u",
788                                 qp_conf.nb_descriptors, qp_id,
789                                 ts_params->valid_devs[0]);
790         }
791
792         /* invalid number of descriptors - max value of parameter */
793         qp_conf.nb_descriptors = UINT32_MAX-1;
794
795         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
796                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
797                                 ts_params->valid_devs[0], qp_id, &qp_conf,
798                                 rte_cryptodev_socket_id(
799                                                 ts_params->valid_devs[0])),
800                                 "Unexpectedly passed test for "
801                                 "rte_cryptodev_queue_pair_setup:"
802                                 "num_inflights %u on qp %u on cryptodev %u",
803                                 qp_conf.nb_descriptors, qp_id,
804                                 ts_params->valid_devs[0]);
805         }
806
807         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
808
809         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
810                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
811                                 ts_params->valid_devs[0], qp_id, &qp_conf,
812                                 rte_cryptodev_socket_id(
813                                                 ts_params->valid_devs[0])),
814                                 "Failed test for"
815                                 " rte_cryptodev_queue_pair_setup:"
816                                 "num_inflights %u on qp %u on cryptodev %u",
817                                 qp_conf.nb_descriptors, qp_id,
818                                 ts_params->valid_devs[0]);
819         }
820
821         /* invalid number of descriptors - max supported + 1 */
822         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
823
824         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
825                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
826                                 ts_params->valid_devs[0], qp_id, &qp_conf,
827                                 rte_cryptodev_socket_id(
828                                                 ts_params->valid_devs[0])),
829                                 "Unexpectedly passed test for "
830                                 "rte_cryptodev_queue_pair_setup:"
831                                 "num_inflights %u on qp %u on cryptodev %u",
832                                 qp_conf.nb_descriptors, qp_id,
833                                 ts_params->valid_devs[0]);
834         }
835
836         /* test invalid queue pair id */
837         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
838
839         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
840
841         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
842                         ts_params->valid_devs[0],
843                         qp_id, &qp_conf,
844                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
845                         "Failed test for rte_cryptodev_queue_pair_setup:"
846                         "invalid qp %u on cryptodev %u",
847                         qp_id, ts_params->valid_devs[0]);
848
849         qp_id = 0xffff; /*invalid*/
850
851         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
852                         ts_params->valid_devs[0],
853                         qp_id, &qp_conf,
854                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
855                         "Failed test for rte_cryptodev_queue_pair_setup:"
856                         "invalid qp %u on cryptodev %u",
857                         qp_id, ts_params->valid_devs[0]);
858
859         return TEST_SUCCESS;
860 }
861
862 /* ***** Plaintext data for tests ***** */
863
864 const char catch_22_quote_1[] =
865                 "There was only one catch and that was Catch-22, which "
866                 "specified that a concern for one's safety in the face of "
867                 "dangers that were real and immediate was the process of a "
868                 "rational mind. Orr was crazy and could be grounded. All he "
869                 "had to do was ask; and as soon as he did, he would no longer "
870                 "be crazy and would have to fly more missions. Orr would be "
871                 "crazy to fly more missions and sane if he didn't, but if he "
872                 "was sane he had to fly them. If he flew them he was crazy "
873                 "and didn't have to; but if he didn't want to he was sane and "
874                 "had to. Yossarian was moved very deeply by the absolute "
875                 "simplicity of this clause of Catch-22 and let out a "
876                 "respectful whistle. \"That's some catch, that Catch-22\", he "
877                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
878
879 const char catch_22_quote[] =
880                 "What a lousy earth! He wondered how many people were "
881                 "destitute that same night even in his own prosperous country, "
882                 "how many homes were shanties, how many husbands were drunk "
883                 "and wives socked, and how many children were bullied, abused, "
884                 "or abandoned. How many families hungered for food they could "
885                 "not afford to buy? How many hearts were broken? How many "
886                 "suicides would take place that same night, how many people "
887                 "would go insane? How many cockroaches and landlords would "
888                 "triumph? How many winners were losers, successes failures, "
889                 "and rich men poor men? How many wise guys were stupid? How "
890                 "many happy endings were unhappy endings? How many honest men "
891                 "were liars, brave men cowards, loyal men traitors, how many "
892                 "sainted men were corrupt, how many people in positions of "
893                 "trust had sold their souls to bodyguards, how many had never "
894                 "had souls? How many straight-and-narrow paths were crooked "
895                 "paths? How many best families were worst families and how "
896                 "many good people were bad people? When you added them all up "
897                 "and then subtracted, you might be left with only the children, "
898                 "and perhaps with Albert Einstein and an old violinist or "
899                 "sculptor somewhere.";
900
901 #define QUOTE_480_BYTES         (480)
902 #define QUOTE_512_BYTES         (512)
903 #define QUOTE_768_BYTES         (768)
904 #define QUOTE_1024_BYTES        (1024)
905
906
907
908 /* ***** SHA1 Hash Tests ***** */
909
910 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
911
912 static uint8_t hmac_sha1_key[] = {
913         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
914         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
915         0xDE, 0xF4, 0xDE, 0xAD };
916
917 /* ***** SHA224 Hash Tests ***** */
918
919 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
920
921
922 /* ***** AES-CBC Cipher Tests ***** */
923
924 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
925 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
926
927 static uint8_t aes_cbc_key[] = {
928         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
929         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
930
931 static uint8_t aes_cbc_iv[] = {
932         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
933         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
934
935
936 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
937
938 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
939         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
940         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
941         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
942         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
943         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
944         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
945         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
946         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
947         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
948         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
949         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
950         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
951         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
952         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
953         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
954         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
955         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
956         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
957         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
958         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
959         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
960         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
961         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
962         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
963         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
964         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
965         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
966         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
967         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
968         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
969         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
970         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
971         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
972         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
973         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
974         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
975         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
976         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
977         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
978         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
979         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
980         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
981         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
982         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
983         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
984         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
985         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
986         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
987         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
988         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
989         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
990         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
991         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
992         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
993         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
994         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
995         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
996         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
997         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
998         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
999         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1000         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1001         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1002         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1003 };
1004
1005 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1006         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1007         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1008         0x18, 0x8c, 0x1d, 0x32
1009 };
1010
1011
1012 /* Multisession Vector context Test */
1013 /*Begin Session 0 */
1014 static uint8_t ms_aes_cbc_key0[] = {
1015         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1016         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1017 };
1018
1019 static uint8_t ms_aes_cbc_iv0[] = {
1020         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1021         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1022 };
1023
1024 static const uint8_t ms_aes_cbc_cipher0[] = {
1025                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1026                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1027                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1028                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1029                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1030                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1031                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1032                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1033                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1034                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1035                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1036                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1037                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1038                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1039                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1040                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1041                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1042                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1043                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1044                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1045                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1046                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1047                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1048                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1049                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1050                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1051                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1052                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1053                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1054                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1055                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1056                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1057                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1058                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1059                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1060                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1061                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1062                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1063                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1064                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1065                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1066                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1067                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1068                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1069                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1070                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1071                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1072                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1073                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1074                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1075                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1076                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1077                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1078                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1079                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1080                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1081                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1082                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1083                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1084                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1085                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1086                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1087                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1088                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1089 };
1090
1091
1092 static  uint8_t ms_hmac_key0[] = {
1093                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1094                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1095                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1096                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1097                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1098                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1099                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1100                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1101 };
1102
1103 static const uint8_t ms_hmac_digest0[] = {
1104                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1105                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1106                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1107                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1108                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1109                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1110                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1111                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1112                 };
1113
1114 /* End Session 0 */
1115 /* Begin session 1 */
1116
1117 static  uint8_t ms_aes_cbc_key1[] = {
1118                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1119                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1120 };
1121
1122 static  uint8_t ms_aes_cbc_iv1[] = {
1123         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1124         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1125 };
1126
1127 static const uint8_t ms_aes_cbc_cipher1[] = {
1128                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1129                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1130                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1131                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1132                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1133                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1134                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1135                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1136                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1137                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1138                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1139                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1140                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1141                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1142                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1143                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1144                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1145                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1146                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1147                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1148                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1149                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1150                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1151                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1152                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1153                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1154                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1155                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1156                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1157                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1158                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1159                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1160                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1161                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1162                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1163                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1164                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1165                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1166                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1167                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1168                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1169                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1170                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1171                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1172                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1173                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1174                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1175                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1176                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1177                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1178                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1179                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1180                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1181                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1182                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1183                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1184                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1185                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1186                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1187                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1188                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1189                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1190                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1191                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1192
1193 };
1194
1195 static uint8_t ms_hmac_key1[] = {
1196                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1197                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1198                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1199                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1200                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1201                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1202                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1203                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1204 };
1205
1206 static const uint8_t ms_hmac_digest1[] = {
1207                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1208                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1209                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1210                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1211                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1212                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1213                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1214                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1215 };
1216 /* End Session 1  */
1217 /* Begin Session 2 */
1218 static  uint8_t ms_aes_cbc_key2[] = {
1219                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1220                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1221 };
1222
1223 static  uint8_t ms_aes_cbc_iv2[] = {
1224                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1225                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1226 };
1227
1228 static const uint8_t ms_aes_cbc_cipher2[] = {
1229                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1230                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1231                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1232                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1233                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1234                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1235                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1236                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1237                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1238                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1239                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1240                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1241                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1242                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1243                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1244                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1245                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1246                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1247                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1248                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1249                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1250                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1251                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1252                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1253                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1254                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1255                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1256                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1257                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1258                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1259                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1260                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1261                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1262                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1263                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1264                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1265                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1266                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1267                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1268                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1269                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1270                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1271                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1272                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1273                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1274                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1275                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1276                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1277                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1278                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1279                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1280                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1281                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1282                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1283                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1284                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1285                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1286                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1287                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1288                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1289                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1290                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1291                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1292                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1293 };
1294
1295 static  uint8_t ms_hmac_key2[] = {
1296                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1297                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1298                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1299                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1300                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1301                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1302                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1303                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1304 };
1305
1306 static const uint8_t ms_hmac_digest2[] = {
1307                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1308                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1309                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1310                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1311                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1312                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1313                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1314                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1315 };
1316
1317 /* End Session 2 */
1318
1319
1320 static int
1321 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1322 {
1323         struct crypto_testsuite_params *ts_params = &testsuite_params;
1324         struct crypto_unittest_params *ut_params = &unittest_params;
1325
1326         /* Generate test mbuf data and space for digest */
1327         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1328                         catch_22_quote, QUOTE_512_BYTES, 0);
1329
1330         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1331                         DIGEST_BYTE_LENGTH_SHA1);
1332         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1333
1334         /* Setup Cipher Parameters */
1335         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1336         ut_params->cipher_xform.next = &ut_params->auth_xform;
1337
1338         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1339         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1340         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1341         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1342         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1343         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1344
1345         /* Setup HMAC Parameters */
1346         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1347
1348         ut_params->auth_xform.next = NULL;
1349
1350         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1351         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1352         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1353         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1354         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1355
1356         ut_params->sess = rte_cryptodev_sym_session_create(
1357                         ts_params->session_mpool);
1358
1359         /* Create crypto session*/
1360         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1361                         ut_params->sess, &ut_params->cipher_xform,
1362                         ts_params->session_priv_mpool);
1363         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1364
1365         /* Generate crypto op data structure */
1366         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1367                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1368         TEST_ASSERT_NOT_NULL(ut_params->op,
1369                         "Failed to allocate symmetric crypto operation struct");
1370
1371         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1372
1373         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1374
1375         /* set crypto operation source mbuf */
1376         sym_op->m_src = ut_params->ibuf;
1377
1378         /* Set crypto operation authentication parameters */
1379         sym_op->auth.digest.data = ut_params->digest;
1380         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1381                         ut_params->ibuf, QUOTE_512_BYTES);
1382
1383         sym_op->auth.data.offset = 0;
1384         sym_op->auth.data.length = QUOTE_512_BYTES;
1385
1386         /* Copy IV at the end of the crypto operation */
1387         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1388                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1389
1390         /* Set crypto operation cipher parameters */
1391         sym_op->cipher.data.offset = 0;
1392         sym_op->cipher.data.length = QUOTE_512_BYTES;
1393
1394         /* Process crypto operation */
1395         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1396                         ut_params->op), "failed to process sym crypto op");
1397
1398         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1399                         "crypto op processing failed");
1400
1401         /* Validate obuf */
1402         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1403                         uint8_t *);
1404
1405         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1406                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1407                         QUOTE_512_BYTES,
1408                         "ciphertext data not as expected");
1409
1410         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1411
1412         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1413                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1414                         gbl_driver_id == rte_cryptodev_driver_id_get(
1415                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1416                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1417                                         DIGEST_BYTE_LENGTH_SHA1,
1418                         "Generated digest data not as expected");
1419
1420         return TEST_SUCCESS;
1421 }
1422
1423 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1424
1425 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1426
1427 static uint8_t hmac_sha512_key[] = {
1428         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1429         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1430         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1431         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1432         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1433         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1434         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1435         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1436
1437 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1438         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1439         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1440         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1441         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1442         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1443         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1444         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1445         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1446
1447
1448
1449 static int
1450 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1451                 struct crypto_unittest_params *ut_params,
1452                 uint8_t *cipher_key,
1453                 uint8_t *hmac_key);
1454
1455 static int
1456 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1457                 struct crypto_unittest_params *ut_params,
1458                 struct crypto_testsuite_params *ts_params,
1459                 const uint8_t *cipher,
1460                 const uint8_t *digest,
1461                 const uint8_t *iv);
1462
1463
1464 static int
1465 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1466                 struct crypto_unittest_params *ut_params,
1467                 uint8_t *cipher_key,
1468                 uint8_t *hmac_key)
1469 {
1470
1471         /* Setup Cipher Parameters */
1472         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1473         ut_params->cipher_xform.next = NULL;
1474
1475         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1476         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1477         ut_params->cipher_xform.cipher.key.data = cipher_key;
1478         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1479         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1480         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1481
1482         /* Setup HMAC Parameters */
1483         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1484         ut_params->auth_xform.next = &ut_params->cipher_xform;
1485
1486         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1487         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1488         ut_params->auth_xform.auth.key.data = hmac_key;
1489         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1490         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1491
1492         return TEST_SUCCESS;
1493 }
1494
1495
1496 static int
1497 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1498                 struct crypto_unittest_params *ut_params,
1499                 struct crypto_testsuite_params *ts_params,
1500                 const uint8_t *cipher,
1501                 const uint8_t *digest,
1502                 const uint8_t *iv)
1503 {
1504         /* Generate test mbuf data and digest */
1505         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1506                         (const char *)
1507                         cipher,
1508                         QUOTE_512_BYTES, 0);
1509
1510         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1511                         DIGEST_BYTE_LENGTH_SHA512);
1512         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1513
1514         rte_memcpy(ut_params->digest,
1515                         digest,
1516                         DIGEST_BYTE_LENGTH_SHA512);
1517
1518         /* Generate Crypto op data structure */
1519         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1520                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1521         TEST_ASSERT_NOT_NULL(ut_params->op,
1522                         "Failed to allocate symmetric crypto operation struct");
1523
1524         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1525
1526         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1527
1528         /* set crypto operation source mbuf */
1529         sym_op->m_src = ut_params->ibuf;
1530
1531         sym_op->auth.digest.data = ut_params->digest;
1532         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1533                         ut_params->ibuf, QUOTE_512_BYTES);
1534
1535         sym_op->auth.data.offset = 0;
1536         sym_op->auth.data.length = QUOTE_512_BYTES;
1537
1538         /* Copy IV at the end of the crypto operation */
1539         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1540                         iv, CIPHER_IV_LENGTH_AES_CBC);
1541
1542         sym_op->cipher.data.offset = 0;
1543         sym_op->cipher.data.length = QUOTE_512_BYTES;
1544
1545         /* Process crypto operation */
1546         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1547                         ut_params->op), "failed to process sym crypto op");
1548
1549         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1550                         "crypto op processing failed");
1551
1552         ut_params->obuf = ut_params->op->sym->m_src;
1553
1554         /* Validate obuf */
1555         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1556                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1557                         catch_22_quote,
1558                         QUOTE_512_BYTES,
1559                         "Plaintext data not as expected");
1560
1561         /* Validate obuf */
1562         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1563                         "Digest verification failed");
1564
1565         return TEST_SUCCESS;
1566 }
1567
1568 static int
1569 test_AES_cipheronly_mb_all(void)
1570 {
1571         struct crypto_testsuite_params *ts_params = &testsuite_params;
1572         int status;
1573
1574         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1575                 ts_params->op_mpool,
1576                 ts_params->session_mpool, ts_params->session_priv_mpool,
1577                 ts_params->valid_devs[0],
1578                 rte_cryptodev_driver_id_get(
1579                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1580                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1581
1582         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1583
1584         return TEST_SUCCESS;
1585 }
1586
1587 static int
1588 test_AES_docsis_mb_all(void)
1589 {
1590         struct crypto_testsuite_params *ts_params = &testsuite_params;
1591         int status;
1592
1593         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1594                 ts_params->op_mpool,
1595                 ts_params->session_mpool, ts_params->session_priv_mpool,
1596                 ts_params->valid_devs[0],
1597                 rte_cryptodev_driver_id_get(
1598                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1599                 BLKCIPHER_AES_DOCSIS_TYPE);
1600
1601         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1602
1603         return TEST_SUCCESS;
1604 }
1605
1606 static int
1607 test_AES_docsis_qat_all(void)
1608 {
1609         struct crypto_testsuite_params *ts_params = &testsuite_params;
1610         int status;
1611
1612         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1613                 ts_params->op_mpool,
1614                 ts_params->session_mpool, ts_params->session_priv_mpool,
1615                 ts_params->valid_devs[0],
1616                 rte_cryptodev_driver_id_get(
1617                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1618                 BLKCIPHER_AES_DOCSIS_TYPE);
1619
1620         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1621
1622         return TEST_SUCCESS;
1623 }
1624
1625 static int
1626 test_DES_docsis_qat_all(void)
1627 {
1628         struct crypto_testsuite_params *ts_params = &testsuite_params;
1629         int status;
1630
1631         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1632                 ts_params->op_mpool,
1633                 ts_params->session_mpool, ts_params->session_priv_mpool,
1634                 ts_params->valid_devs[0],
1635                 rte_cryptodev_driver_id_get(
1636                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1637                 BLKCIPHER_DES_DOCSIS_TYPE);
1638
1639         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1640
1641         return TEST_SUCCESS;
1642 }
1643
1644 static int
1645 test_authonly_mb_all(void)
1646 {
1647         struct crypto_testsuite_params *ts_params = &testsuite_params;
1648         int status;
1649
1650         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1651                 ts_params->op_mpool,
1652                 ts_params->session_mpool, ts_params->session_priv_mpool,
1653                 ts_params->valid_devs[0],
1654                 rte_cryptodev_driver_id_get(
1655                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1656                 BLKCIPHER_AUTHONLY_TYPE);
1657
1658         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1659
1660         return TEST_SUCCESS;
1661 }
1662
1663 static int
1664 test_authonly_qat_all(void)
1665 {
1666         struct crypto_testsuite_params *ts_params = &testsuite_params;
1667         int status;
1668
1669         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1670                 ts_params->op_mpool,
1671                 ts_params->session_mpool, ts_params->session_priv_mpool,
1672                 ts_params->valid_devs[0],
1673                 rte_cryptodev_driver_id_get(
1674                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1675                 BLKCIPHER_AUTHONLY_TYPE);
1676
1677         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1678
1679         return TEST_SUCCESS;
1680 }
1681
1682 static int
1683 test_AES_chain_null_all(void)
1684 {
1685         struct crypto_testsuite_params *ts_params = &testsuite_params;
1686         int status;
1687
1688         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1689                 ts_params->op_mpool,
1690                 ts_params->session_mpool, ts_params->session_priv_mpool,
1691                 ts_params->valid_devs[0],
1692                 rte_cryptodev_driver_id_get(
1693                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)),
1694                 BLKCIPHER_AES_CHAIN_TYPE);
1695
1696         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1697
1698         return TEST_SUCCESS;
1699 }
1700
1701 static int
1702 test_AES_cipheronly_null_all(void)
1703 {
1704         struct crypto_testsuite_params *ts_params = &testsuite_params;
1705         int status;
1706
1707         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1708                 ts_params->op_mpool,
1709                 ts_params->session_mpool, ts_params->session_priv_mpool,
1710                 ts_params->valid_devs[0],
1711                 rte_cryptodev_driver_id_get(
1712                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)),
1713                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1714
1715         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1716
1717         return TEST_SUCCESS;
1718 }
1719
1720 static int
1721 test_authonly_null_all(void)
1722 {
1723         struct crypto_testsuite_params *ts_params = &testsuite_params;
1724         int status;
1725
1726         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1727                 ts_params->op_mpool,
1728                 ts_params->session_mpool, ts_params->session_priv_mpool,
1729                 ts_params->valid_devs[0],
1730                 rte_cryptodev_driver_id_get(
1731                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)),
1732                 BLKCIPHER_AUTHONLY_TYPE);
1733
1734         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1735
1736         return TEST_SUCCESS;
1737 }
1738
1739 static int
1740 test_AES_chain_mb_all(void)
1741 {
1742         struct crypto_testsuite_params *ts_params = &testsuite_params;
1743         int status;
1744
1745         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1746                 ts_params->op_mpool,
1747                 ts_params->session_mpool, ts_params->session_priv_mpool,
1748                 ts_params->valid_devs[0],
1749                 rte_cryptodev_driver_id_get(
1750                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1751                 BLKCIPHER_AES_CHAIN_TYPE);
1752
1753         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1754
1755         return TEST_SUCCESS;
1756 }
1757
1758 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
1759
1760 static int
1761 test_AES_cipheronly_scheduler_all(void)
1762 {
1763         struct crypto_testsuite_params *ts_params = &testsuite_params;
1764         int status;
1765
1766         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1767                 ts_params->op_mpool,
1768                 ts_params->session_mpool, ts_params->session_priv_mpool,
1769                 ts_params->valid_devs[0],
1770                 rte_cryptodev_driver_id_get(
1771                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1772                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1773
1774         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1775
1776         return TEST_SUCCESS;
1777 }
1778
1779 static int
1780 test_AES_chain_scheduler_all(void)
1781 {
1782         struct crypto_testsuite_params *ts_params = &testsuite_params;
1783         int status;
1784
1785         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1786                 ts_params->op_mpool,
1787                 ts_params->session_mpool, ts_params->session_priv_mpool,
1788                 ts_params->valid_devs[0],
1789                 rte_cryptodev_driver_id_get(
1790                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1791                 BLKCIPHER_AES_CHAIN_TYPE);
1792
1793         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1794
1795         return TEST_SUCCESS;
1796 }
1797
1798 static int
1799 test_authonly_scheduler_all(void)
1800 {
1801         struct crypto_testsuite_params *ts_params = &testsuite_params;
1802         int status;
1803
1804         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1805                 ts_params->op_mpool,
1806                 ts_params->session_mpool, ts_params->session_priv_mpool,
1807                 ts_params->valid_devs[0],
1808                 rte_cryptodev_driver_id_get(
1809                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1810                 BLKCIPHER_AUTHONLY_TYPE);
1811
1812         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1813
1814         return TEST_SUCCESS;
1815 }
1816
1817 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
1818
1819 static int
1820 test_AES_chain_openssl_all(void)
1821 {
1822         struct crypto_testsuite_params *ts_params = &testsuite_params;
1823         int status;
1824
1825         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1826                 ts_params->op_mpool,
1827                 ts_params->session_mpool, ts_params->session_priv_mpool,
1828                 ts_params->valid_devs[0],
1829                 rte_cryptodev_driver_id_get(
1830                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
1831                 BLKCIPHER_AES_CHAIN_TYPE);
1832
1833         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1834
1835         return TEST_SUCCESS;
1836 }
1837
1838 static int
1839 test_AES_cipheronly_openssl_all(void)
1840 {
1841         struct crypto_testsuite_params *ts_params = &testsuite_params;
1842         int status;
1843
1844         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1845                 ts_params->op_mpool,
1846                 ts_params->session_mpool, ts_params->session_priv_mpool,
1847                 ts_params->valid_devs[0],
1848                 rte_cryptodev_driver_id_get(
1849                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
1850                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1851
1852         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1853
1854         return TEST_SUCCESS;
1855 }
1856
1857 static int
1858 test_AES_chain_ccp_all(void)
1859 {
1860         struct crypto_testsuite_params *ts_params = &testsuite_params;
1861         int status;
1862
1863         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1864                 ts_params->op_mpool,
1865                 ts_params->session_mpool, ts_params->session_priv_mpool,
1866                 ts_params->valid_devs[0],
1867                 rte_cryptodev_driver_id_get(
1868                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
1869                 BLKCIPHER_AES_CHAIN_TYPE);
1870
1871         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1872
1873         return TEST_SUCCESS;
1874 }
1875
1876 static int
1877 test_AES_cipheronly_ccp_all(void)
1878 {
1879         struct crypto_testsuite_params *ts_params = &testsuite_params;
1880         int status;
1881
1882         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1883                 ts_params->op_mpool,
1884                 ts_params->session_mpool, ts_params->session_priv_mpool,
1885                 ts_params->valid_devs[0],
1886                 rte_cryptodev_driver_id_get(
1887                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
1888                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1889
1890         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1891
1892         return TEST_SUCCESS;
1893 }
1894
1895 static int
1896 test_AES_chain_qat_all(void)
1897 {
1898         struct crypto_testsuite_params *ts_params = &testsuite_params;
1899         int status;
1900
1901         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1902                 ts_params->op_mpool,
1903                 ts_params->session_mpool, ts_params->session_priv_mpool,
1904                 ts_params->valid_devs[0],
1905                 rte_cryptodev_driver_id_get(
1906                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1907                 BLKCIPHER_AES_CHAIN_TYPE);
1908
1909         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1910
1911         return TEST_SUCCESS;
1912 }
1913
1914 static int
1915 test_AES_cipheronly_qat_all(void)
1916 {
1917         struct crypto_testsuite_params *ts_params = &testsuite_params;
1918         int status;
1919
1920         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1921                 ts_params->op_mpool,
1922                 ts_params->session_mpool, ts_params->session_priv_mpool,
1923                 ts_params->valid_devs[0],
1924                 rte_cryptodev_driver_id_get(
1925                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1926                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1927
1928         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1929
1930         return TEST_SUCCESS;
1931 }
1932
1933 static int
1934 test_AES_cipheronly_virtio_all(void)
1935 {
1936         struct crypto_testsuite_params *ts_params = &testsuite_params;
1937         int status;
1938
1939         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1940                 ts_params->op_mpool,
1941                 ts_params->session_mpool, ts_params->session_priv_mpool,
1942                 ts_params->valid_devs[0],
1943                 rte_cryptodev_driver_id_get(
1944                 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)),
1945                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1946
1947         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1948
1949         return TEST_SUCCESS;
1950 }
1951
1952 static int
1953 test_AES_chain_caam_jr_all(void)
1954 {
1955         struct crypto_testsuite_params *ts_params = &testsuite_params;
1956         int status;
1957
1958         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1959                 ts_params->op_mpool,
1960                 ts_params->session_mpool, ts_params->session_priv_mpool,
1961                 ts_params->valid_devs[0],
1962                 rte_cryptodev_driver_id_get(
1963                 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)),
1964                 BLKCIPHER_AES_CHAIN_TYPE);
1965
1966         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1967
1968         return TEST_SUCCESS;
1969 }
1970
1971 static int
1972 test_AES_cipheronly_caam_jr_all(void)
1973 {
1974         struct crypto_testsuite_params *ts_params = &testsuite_params;
1975         int status;
1976
1977         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1978                 ts_params->op_mpool,
1979                 ts_params->session_mpool, ts_params->session_priv_mpool,
1980                 ts_params->valid_devs[0],
1981                 rte_cryptodev_driver_id_get(
1982                 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)),
1983                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1984
1985         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1986
1987         return TEST_SUCCESS;
1988 }
1989
1990 static int
1991 test_authonly_caam_jr_all(void)
1992 {
1993         struct crypto_testsuite_params *ts_params = &testsuite_params;
1994         int status;
1995
1996         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1997                 ts_params->op_mpool,
1998                 ts_params->session_mpool, ts_params->session_priv_mpool,
1999                 ts_params->valid_devs[0],
2000                 rte_cryptodev_driver_id_get(
2001                 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)),
2002                 BLKCIPHER_AUTHONLY_TYPE);
2003
2004         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2005
2006         return TEST_SUCCESS;
2007 }
2008
2009
2010 static int
2011 test_AES_chain_dpaa_sec_all(void)
2012 {
2013         struct crypto_testsuite_params *ts_params = &testsuite_params;
2014         int status;
2015
2016         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2017                 ts_params->op_mpool,
2018                 ts_params->session_mpool, ts_params->session_priv_mpool,
2019                 ts_params->valid_devs[0],
2020                 rte_cryptodev_driver_id_get(
2021                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
2022                 BLKCIPHER_AES_CHAIN_TYPE);
2023
2024         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2025
2026         return TEST_SUCCESS;
2027 }
2028
2029 static int
2030 test_AES_cipheronly_dpaa_sec_all(void)
2031 {
2032         struct crypto_testsuite_params *ts_params = &testsuite_params;
2033         int status;
2034
2035         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2036                 ts_params->op_mpool,
2037                 ts_params->session_mpool, ts_params->session_priv_mpool,
2038                 ts_params->valid_devs[0],
2039                 rte_cryptodev_driver_id_get(
2040                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
2041                 BLKCIPHER_AES_CIPHERONLY_TYPE);
2042
2043         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2044
2045         return TEST_SUCCESS;
2046 }
2047
2048 static int
2049 test_authonly_dpaa_sec_all(void)
2050 {
2051         struct crypto_testsuite_params *ts_params = &testsuite_params;
2052         int status;
2053
2054         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2055                 ts_params->op_mpool,
2056                 ts_params->session_mpool, ts_params->session_priv_mpool,
2057                 ts_params->valid_devs[0],
2058                 rte_cryptodev_driver_id_get(
2059                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
2060                 BLKCIPHER_AUTHONLY_TYPE);
2061
2062         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2063
2064         return TEST_SUCCESS;
2065 }
2066
2067 static int
2068 test_AES_chain_dpaa2_sec_all(void)
2069 {
2070         struct crypto_testsuite_params *ts_params = &testsuite_params;
2071         int status;
2072
2073         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2074                 ts_params->op_mpool,
2075                 ts_params->session_mpool, ts_params->session_priv_mpool,
2076                 ts_params->valid_devs[0],
2077                 rte_cryptodev_driver_id_get(
2078                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
2079                 BLKCIPHER_AES_CHAIN_TYPE);
2080
2081         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2082
2083         return TEST_SUCCESS;
2084 }
2085
2086 static int
2087 test_AES_cipheronly_dpaa2_sec_all(void)
2088 {
2089         struct crypto_testsuite_params *ts_params = &testsuite_params;
2090         int status;
2091
2092         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2093                 ts_params->op_mpool,
2094                 ts_params->session_mpool, ts_params->session_priv_mpool,
2095                 ts_params->valid_devs[0],
2096                 rte_cryptodev_driver_id_get(
2097                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
2098                 BLKCIPHER_AES_CIPHERONLY_TYPE);
2099
2100         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2101
2102         return TEST_SUCCESS;
2103 }
2104
2105 static int
2106 test_authonly_dpaa2_sec_all(void)
2107 {
2108         struct crypto_testsuite_params *ts_params = &testsuite_params;
2109         int status;
2110
2111         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2112                 ts_params->op_mpool,
2113                 ts_params->session_mpool, ts_params->session_priv_mpool,
2114                 ts_params->valid_devs[0],
2115                 rte_cryptodev_driver_id_get(
2116                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
2117                 BLKCIPHER_AUTHONLY_TYPE);
2118
2119         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2120
2121         return TEST_SUCCESS;
2122 }
2123
2124 static int
2125 test_authonly_openssl_all(void)
2126 {
2127         struct crypto_testsuite_params *ts_params = &testsuite_params;
2128         int status;
2129
2130         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2131                 ts_params->op_mpool,
2132                 ts_params->session_mpool, ts_params->session_priv_mpool,
2133                 ts_params->valid_devs[0],
2134                 rte_cryptodev_driver_id_get(
2135                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
2136                 BLKCIPHER_AUTHONLY_TYPE);
2137
2138         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2139
2140         return TEST_SUCCESS;
2141 }
2142
2143 static int
2144 test_authonly_ccp_all(void)
2145 {
2146         struct crypto_testsuite_params *ts_params = &testsuite_params;
2147         int status;
2148
2149         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2150                 ts_params->op_mpool,
2151                 ts_params->session_mpool, ts_params->session_priv_mpool,
2152                 ts_params->valid_devs[0],
2153                 rte_cryptodev_driver_id_get(
2154                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
2155                 BLKCIPHER_AUTHONLY_TYPE);
2156
2157         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2158
2159         return TEST_SUCCESS;
2160 }
2161
2162 static int
2163 test_AES_chain_armv8_all(void)
2164 {
2165         struct crypto_testsuite_params *ts_params = &testsuite_params;
2166         int status;
2167
2168         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2169                 ts_params->op_mpool,
2170                 ts_params->session_mpool, ts_params->session_priv_mpool,
2171                 ts_params->valid_devs[0],
2172                 rte_cryptodev_driver_id_get(
2173                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)),
2174                 BLKCIPHER_AES_CHAIN_TYPE);
2175
2176         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2177
2178         return TEST_SUCCESS;
2179 }
2180
2181 static int
2182 test_AES_chain_mrvl_all(void)
2183 {
2184         struct crypto_testsuite_params *ts_params = &testsuite_params;
2185         int status;
2186
2187         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2188                 ts_params->op_mpool,
2189                 ts_params->session_mpool, ts_params->session_priv_mpool,
2190                 ts_params->valid_devs[0],
2191                 rte_cryptodev_driver_id_get(
2192                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)),
2193                 BLKCIPHER_AES_CHAIN_TYPE);
2194
2195         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2196
2197         return TEST_SUCCESS;
2198 }
2199
2200 static int
2201 test_AES_cipheronly_mrvl_all(void)
2202 {
2203         struct crypto_testsuite_params *ts_params = &testsuite_params;
2204         int status;
2205
2206         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2207                 ts_params->op_mpool,
2208                 ts_params->session_mpool, ts_params->session_priv_mpool,
2209                 ts_params->valid_devs[0],
2210                 rte_cryptodev_driver_id_get(
2211                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)),
2212                 BLKCIPHER_AES_CIPHERONLY_TYPE);
2213
2214         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2215
2216         return TEST_SUCCESS;
2217 }
2218
2219 static int
2220 test_authonly_mrvl_all(void)
2221 {
2222         struct crypto_testsuite_params *ts_params = &testsuite_params;
2223         int status;
2224
2225         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2226                 ts_params->op_mpool,
2227                 ts_params->session_mpool, ts_params->session_priv_mpool,
2228                 ts_params->valid_devs[0],
2229                 rte_cryptodev_driver_id_get(
2230                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)),
2231                 BLKCIPHER_AUTHONLY_TYPE);
2232
2233         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2234
2235         return TEST_SUCCESS;
2236 }
2237
2238 static int
2239 test_3DES_chain_mrvl_all(void)
2240 {
2241         struct crypto_testsuite_params *ts_params = &testsuite_params;
2242         int status;
2243
2244         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2245                 ts_params->op_mpool,
2246                 ts_params->session_mpool, ts_params->session_priv_mpool,
2247                 ts_params->valid_devs[0],
2248                 rte_cryptodev_driver_id_get(
2249                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)),
2250                 BLKCIPHER_3DES_CHAIN_TYPE);
2251
2252         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2253
2254         return TEST_SUCCESS;
2255 }
2256
2257 static int
2258 test_3DES_cipheronly_mrvl_all(void)
2259 {
2260         struct crypto_testsuite_params *ts_params = &testsuite_params;
2261         int status;
2262
2263         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2264                 ts_params->op_mpool,
2265                 ts_params->session_mpool, ts_params->session_priv_mpool,
2266                 ts_params->valid_devs[0],
2267                 rte_cryptodev_driver_id_get(
2268                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)),
2269                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
2270
2271         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2272
2273         return TEST_SUCCESS;
2274 }
2275
2276 static int
2277 test_AES_chain_octeontx_all(void)
2278 {
2279         struct crypto_testsuite_params *ts_params = &testsuite_params;
2280         int status;
2281
2282         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2283                 ts_params->op_mpool, ts_params->session_mpool,
2284                 ts_params->session_priv_mpool,
2285                 ts_params->valid_devs[0],
2286                 rte_cryptodev_driver_id_get(
2287                 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)),
2288                 BLKCIPHER_AES_CHAIN_TYPE);
2289
2290         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2291
2292         return TEST_SUCCESS;
2293 }
2294
2295 static int
2296 test_AES_cipheronly_octeontx_all(void)
2297 {
2298         struct crypto_testsuite_params *ts_params = &testsuite_params;
2299         int status;
2300
2301         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2302                 ts_params->op_mpool, ts_params->session_mpool,
2303                 ts_params->session_priv_mpool,
2304                 ts_params->valid_devs[0],
2305                 rte_cryptodev_driver_id_get(
2306                 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)),
2307                 BLKCIPHER_AES_CIPHERONLY_TYPE);
2308
2309         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2310
2311         return TEST_SUCCESS;
2312 }
2313
2314 static int
2315 test_3DES_chain_octeontx_all(void)
2316 {
2317         struct crypto_testsuite_params *ts_params = &testsuite_params;
2318         int status;
2319
2320         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2321                 ts_params->op_mpool, ts_params->session_mpool,
2322                 ts_params->session_priv_mpool,
2323                 ts_params->valid_devs[0],
2324                 rte_cryptodev_driver_id_get(
2325                 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)),
2326                 BLKCIPHER_3DES_CHAIN_TYPE);
2327
2328         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2329
2330         return TEST_SUCCESS;
2331 }
2332
2333 static int
2334 test_3DES_cipheronly_octeontx_all(void)
2335 {
2336         struct crypto_testsuite_params *ts_params = &testsuite_params;
2337         int status;
2338
2339         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2340                 ts_params->op_mpool, ts_params->session_mpool,
2341                 ts_params->session_priv_mpool,
2342                 ts_params->valid_devs[0],
2343                 rte_cryptodev_driver_id_get(
2344                 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)),
2345                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
2346
2347         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2348
2349         return TEST_SUCCESS;
2350 }
2351
2352 static int
2353 test_authonly_octeontx_all(void)
2354 {
2355         struct crypto_testsuite_params *ts_params = &testsuite_params;
2356         int status;
2357
2358         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2359                 ts_params->op_mpool, ts_params->session_mpool,
2360                 ts_params->session_priv_mpool,
2361                 ts_params->valid_devs[0],
2362                 rte_cryptodev_driver_id_get(
2363                 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)),
2364                 BLKCIPHER_AUTHONLY_TYPE);
2365
2366         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2367
2368         return TEST_SUCCESS;
2369 }
2370
2371 /* ***** SNOW 3G Tests ***** */
2372 static int
2373 create_wireless_algo_hash_session(uint8_t dev_id,
2374         const uint8_t *key, const uint8_t key_len,
2375         const uint8_t iv_len, const uint8_t auth_len,
2376         enum rte_crypto_auth_operation op,
2377         enum rte_crypto_auth_algorithm algo)
2378 {
2379         uint8_t hash_key[key_len];
2380         int status;
2381
2382         struct crypto_testsuite_params *ts_params = &testsuite_params;
2383         struct crypto_unittest_params *ut_params = &unittest_params;
2384
2385         memcpy(hash_key, key, key_len);
2386
2387         debug_hexdump(stdout, "key:", key, key_len);
2388
2389         /* Setup Authentication Parameters */
2390         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2391         ut_params->auth_xform.next = NULL;
2392
2393         ut_params->auth_xform.auth.op = op;
2394         ut_params->auth_xform.auth.algo = algo;
2395         ut_params->auth_xform.auth.key.length = key_len;
2396         ut_params->auth_xform.auth.key.data = hash_key;
2397         ut_params->auth_xform.auth.digest_length = auth_len;
2398         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2399         ut_params->auth_xform.auth.iv.length = iv_len;
2400         ut_params->sess = rte_cryptodev_sym_session_create(
2401                         ts_params->session_mpool);
2402
2403         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2404                         &ut_params->auth_xform,
2405                         ts_params->session_priv_mpool);
2406         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2407         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2408         return 0;
2409 }
2410
2411 static int
2412 create_wireless_algo_cipher_session(uint8_t dev_id,
2413                         enum rte_crypto_cipher_operation op,
2414                         enum rte_crypto_cipher_algorithm algo,
2415                         const uint8_t *key, const uint8_t key_len,
2416                         uint8_t iv_len)
2417 {
2418         uint8_t cipher_key[key_len];
2419         int status;
2420         struct crypto_testsuite_params *ts_params = &testsuite_params;
2421         struct crypto_unittest_params *ut_params = &unittest_params;
2422
2423         memcpy(cipher_key, key, key_len);
2424
2425         /* Setup Cipher Parameters */
2426         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2427         ut_params->cipher_xform.next = NULL;
2428
2429         ut_params->cipher_xform.cipher.algo = algo;
2430         ut_params->cipher_xform.cipher.op = op;
2431         ut_params->cipher_xform.cipher.key.data = cipher_key;
2432         ut_params->cipher_xform.cipher.key.length = key_len;
2433         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2434         ut_params->cipher_xform.cipher.iv.length = iv_len;
2435
2436         debug_hexdump(stdout, "key:", key, key_len);
2437
2438         /* Create Crypto session */
2439         ut_params->sess = rte_cryptodev_sym_session_create(
2440                         ts_params->session_mpool);
2441
2442         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2443                         &ut_params->cipher_xform,
2444                         ts_params->session_priv_mpool);
2445         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2446         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2447         return 0;
2448 }
2449
2450 static int
2451 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2452                         unsigned int cipher_len,
2453                         unsigned int cipher_offset)
2454 {
2455         struct crypto_testsuite_params *ts_params = &testsuite_params;
2456         struct crypto_unittest_params *ut_params = &unittest_params;
2457
2458         /* Generate Crypto op data structure */
2459         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2460                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2461         TEST_ASSERT_NOT_NULL(ut_params->op,
2462                                 "Failed to allocate pktmbuf offload");
2463
2464         /* Set crypto operation data parameters */
2465         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2466
2467         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2468
2469         /* set crypto operation source mbuf */
2470         sym_op->m_src = ut_params->ibuf;
2471
2472         /* iv */
2473         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2474                         iv, iv_len);
2475         sym_op->cipher.data.length = cipher_len;
2476         sym_op->cipher.data.offset = cipher_offset;
2477         return 0;
2478 }
2479
2480 static int
2481 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2482                         unsigned int cipher_len,
2483                         unsigned int cipher_offset)
2484 {
2485         struct crypto_testsuite_params *ts_params = &testsuite_params;
2486         struct crypto_unittest_params *ut_params = &unittest_params;
2487
2488         /* Generate Crypto op data structure */
2489         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2490                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2491         TEST_ASSERT_NOT_NULL(ut_params->op,
2492                                 "Failed to allocate pktmbuf offload");
2493
2494         /* Set crypto operation data parameters */
2495         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2496
2497         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2498
2499         /* set crypto operation source mbuf */
2500         sym_op->m_src = ut_params->ibuf;
2501         sym_op->m_dst = ut_params->obuf;
2502
2503         /* iv */
2504         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2505                         iv, iv_len);
2506         sym_op->cipher.data.length = cipher_len;
2507         sym_op->cipher.data.offset = cipher_offset;
2508         return 0;
2509 }
2510
2511 static int
2512 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2513                 enum rte_crypto_cipher_operation cipher_op,
2514                 enum rte_crypto_auth_operation auth_op,
2515                 enum rte_crypto_auth_algorithm auth_algo,
2516                 enum rte_crypto_cipher_algorithm cipher_algo,
2517                 const uint8_t *key, uint8_t key_len,
2518                 uint8_t auth_iv_len, uint8_t auth_len,
2519                 uint8_t cipher_iv_len)
2520
2521 {
2522         uint8_t cipher_auth_key[key_len];
2523         int status;
2524
2525         struct crypto_testsuite_params *ts_params = &testsuite_params;
2526         struct crypto_unittest_params *ut_params = &unittest_params;
2527
2528         memcpy(cipher_auth_key, key, key_len);
2529
2530         /* Setup Authentication Parameters */
2531         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2532         ut_params->auth_xform.next = NULL;
2533
2534         ut_params->auth_xform.auth.op = auth_op;
2535         ut_params->auth_xform.auth.algo = auth_algo;
2536         ut_params->auth_xform.auth.key.length = key_len;
2537         /* Hash key = cipher key */
2538         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2539         ut_params->auth_xform.auth.digest_length = auth_len;
2540         /* Auth IV will be after cipher IV */
2541         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2542         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2543
2544         /* Setup Cipher Parameters */
2545         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2546         ut_params->cipher_xform.next = &ut_params->auth_xform;
2547
2548         ut_params->cipher_xform.cipher.algo = cipher_algo;
2549         ut_params->cipher_xform.cipher.op = cipher_op;
2550         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2551         ut_params->cipher_xform.cipher.key.length = key_len;
2552         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2553         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2554
2555         debug_hexdump(stdout, "key:", key, key_len);
2556
2557         /* Create Crypto session*/
2558         ut_params->sess = rte_cryptodev_sym_session_create(
2559                         ts_params->session_mpool);
2560
2561         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2562                         &ut_params->cipher_xform,
2563                         ts_params->session_priv_mpool);
2564
2565         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2566         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2567         return 0;
2568 }
2569
2570 static int
2571 create_wireless_cipher_auth_session(uint8_t dev_id,
2572                 enum rte_crypto_cipher_operation cipher_op,
2573                 enum rte_crypto_auth_operation auth_op,
2574                 enum rte_crypto_auth_algorithm auth_algo,
2575                 enum rte_crypto_cipher_algorithm cipher_algo,
2576                 const struct wireless_test_data *tdata)
2577 {
2578         const uint8_t key_len = tdata->key.len;
2579         uint8_t cipher_auth_key[key_len];
2580         int status;
2581
2582         struct crypto_testsuite_params *ts_params = &testsuite_params;
2583         struct crypto_unittest_params *ut_params = &unittest_params;
2584         const uint8_t *key = tdata->key.data;
2585         const uint8_t auth_len = tdata->digest.len;
2586         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2587         uint8_t auth_iv_len = tdata->auth_iv.len;
2588
2589         memcpy(cipher_auth_key, key, key_len);
2590
2591         /* Setup Authentication Parameters */
2592         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2593         ut_params->auth_xform.next = NULL;
2594
2595         ut_params->auth_xform.auth.op = auth_op;
2596         ut_params->auth_xform.auth.algo = auth_algo;
2597         ut_params->auth_xform.auth.key.length = key_len;
2598         /* Hash key = cipher key */
2599         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2600         ut_params->auth_xform.auth.digest_length = auth_len;
2601         /* Auth IV will be after cipher IV */
2602         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2603         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2604
2605         /* Setup Cipher Parameters */
2606         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2607         ut_params->cipher_xform.next = &ut_params->auth_xform;
2608
2609         ut_params->cipher_xform.cipher.algo = cipher_algo;
2610         ut_params->cipher_xform.cipher.op = cipher_op;
2611         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2612         ut_params->cipher_xform.cipher.key.length = key_len;
2613         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2614         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2615
2616
2617         debug_hexdump(stdout, "key:", key, key_len);
2618
2619         /* Create Crypto session*/
2620         ut_params->sess = rte_cryptodev_sym_session_create(
2621                         ts_params->session_mpool);
2622
2623         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2624                         &ut_params->cipher_xform,
2625                         ts_params->session_priv_mpool);
2626
2627         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2628         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2629         return 0;
2630 }
2631
2632 static int
2633 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2634                 const struct wireless_test_data *tdata)
2635 {
2636         return create_wireless_cipher_auth_session(dev_id,
2637                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2638                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2639                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2640 }
2641
2642 static int
2643 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2644                 enum rte_crypto_cipher_operation cipher_op,
2645                 enum rte_crypto_auth_operation auth_op,
2646                 enum rte_crypto_auth_algorithm auth_algo,
2647                 enum rte_crypto_cipher_algorithm cipher_algo,
2648                 const uint8_t *key, const uint8_t key_len,
2649                 uint8_t auth_iv_len, uint8_t auth_len,
2650                 uint8_t cipher_iv_len)
2651 {
2652         uint8_t auth_cipher_key[key_len];
2653         int status;
2654         struct crypto_testsuite_params *ts_params = &testsuite_params;
2655         struct crypto_unittest_params *ut_params = &unittest_params;
2656
2657         memcpy(auth_cipher_key, key, key_len);
2658
2659         /* Setup Authentication Parameters */
2660         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2661         ut_params->auth_xform.auth.op = auth_op;
2662         ut_params->auth_xform.next = &ut_params->cipher_xform;
2663         ut_params->auth_xform.auth.algo = auth_algo;
2664         ut_params->auth_xform.auth.key.length = key_len;
2665         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2666         ut_params->auth_xform.auth.digest_length = auth_len;
2667         /* Auth IV will be after cipher IV */
2668         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2669         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2670
2671         /* Setup Cipher Parameters */
2672         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2673         ut_params->cipher_xform.next = NULL;
2674         ut_params->cipher_xform.cipher.algo = cipher_algo;
2675         ut_params->cipher_xform.cipher.op = cipher_op;
2676         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2677         ut_params->cipher_xform.cipher.key.length = key_len;
2678         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2679         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2680
2681         debug_hexdump(stdout, "key:", key, key_len);
2682
2683         /* Create Crypto session*/
2684         ut_params->sess = rte_cryptodev_sym_session_create(
2685                         ts_params->session_mpool);
2686
2687         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2688                         &ut_params->auth_xform,
2689                         ts_params->session_priv_mpool);
2690         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2691         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2692
2693         return 0;
2694 }
2695
2696 static int
2697 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2698                 unsigned int auth_tag_len,
2699                 const uint8_t *iv, unsigned int iv_len,
2700                 unsigned int data_pad_len,
2701                 enum rte_crypto_auth_operation op,
2702                 unsigned int auth_len, unsigned int auth_offset)
2703 {
2704         struct crypto_testsuite_params *ts_params = &testsuite_params;
2705
2706         struct crypto_unittest_params *ut_params = &unittest_params;
2707
2708         /* Generate Crypto op data structure */
2709         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2710                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2711         TEST_ASSERT_NOT_NULL(ut_params->op,
2712                 "Failed to allocate pktmbuf offload");
2713
2714         /* Set crypto operation data parameters */
2715         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2716
2717         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2718
2719         /* set crypto operation source mbuf */
2720         sym_op->m_src = ut_params->ibuf;
2721
2722         /* iv */
2723         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2724                         iv, iv_len);
2725         /* digest */
2726         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2727                                         ut_params->ibuf, auth_tag_len);
2728
2729         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2730                                 "no room to append auth tag");
2731         ut_params->digest = sym_op->auth.digest.data;
2732         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2733                         ut_params->ibuf, data_pad_len);
2734         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2735                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2736         else
2737                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2738
2739         debug_hexdump(stdout, "digest:",
2740                 sym_op->auth.digest.data,
2741                 auth_tag_len);
2742
2743         sym_op->auth.data.length = auth_len;
2744         sym_op->auth.data.offset = auth_offset;
2745
2746         return 0;
2747 }
2748
2749 static int
2750 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2751         enum rte_crypto_auth_operation op)
2752 {
2753         struct crypto_testsuite_params *ts_params = &testsuite_params;
2754         struct crypto_unittest_params *ut_params = &unittest_params;
2755
2756         const uint8_t *auth_tag = tdata->digest.data;
2757         const unsigned int auth_tag_len = tdata->digest.len;
2758         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2759         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2760
2761         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2762         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2763         const uint8_t *auth_iv = tdata->auth_iv.data;
2764         const uint8_t auth_iv_len = tdata->auth_iv.len;
2765         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2766         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2767
2768         /* Generate Crypto op data structure */
2769         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2770                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2771         TEST_ASSERT_NOT_NULL(ut_params->op,
2772                         "Failed to allocate pktmbuf offload");
2773         /* Set crypto operation data parameters */
2774         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2775
2776         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2777
2778         /* set crypto operation source mbuf */
2779         sym_op->m_src = ut_params->ibuf;
2780
2781         /* digest */
2782         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2783                         ut_params->ibuf, auth_tag_len);
2784
2785         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2786                         "no room to append auth tag");
2787         ut_params->digest = sym_op->auth.digest.data;
2788         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2789                         ut_params->ibuf, data_pad_len);
2790         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2791                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2792         else
2793                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2794
2795         debug_hexdump(stdout, "digest:",
2796                 sym_op->auth.digest.data,
2797                 auth_tag_len);
2798
2799         /* Copy cipher and auth IVs at the end of the crypto operation */
2800         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2801                                                 IV_OFFSET);
2802         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2803         iv_ptr += cipher_iv_len;
2804         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2805
2806         sym_op->cipher.data.length = cipher_len;
2807         sym_op->cipher.data.offset = 0;
2808         sym_op->auth.data.length = auth_len;
2809         sym_op->auth.data.offset = 0;
2810
2811         return 0;
2812 }
2813
2814 static int
2815 create_zuc_cipher_hash_generate_operation(
2816                 const struct wireless_test_data *tdata)
2817 {
2818         return create_wireless_cipher_hash_operation(tdata,
2819                 RTE_CRYPTO_AUTH_OP_GENERATE);
2820 }
2821
2822 static int
2823 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2824                 const unsigned auth_tag_len,
2825                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2826                 unsigned data_pad_len,
2827                 enum rte_crypto_auth_operation op,
2828                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2829                 const unsigned cipher_len, const unsigned cipher_offset,
2830                 const unsigned auth_len, const unsigned auth_offset)
2831 {
2832         struct crypto_testsuite_params *ts_params = &testsuite_params;
2833         struct crypto_unittest_params *ut_params = &unittest_params;
2834
2835         /* Generate Crypto op data structure */
2836         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2837                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2838         TEST_ASSERT_NOT_NULL(ut_params->op,
2839                         "Failed to allocate pktmbuf offload");
2840         /* Set crypto operation data parameters */
2841         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2842
2843         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2844
2845         /* set crypto operation source mbuf */
2846         sym_op->m_src = ut_params->ibuf;
2847
2848         /* digest */
2849         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2850                         ut_params->ibuf, auth_tag_len);
2851
2852         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2853                         "no room to append auth tag");
2854         ut_params->digest = sym_op->auth.digest.data;
2855         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2856                         ut_params->ibuf, data_pad_len);
2857         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2858                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2859         else
2860                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2861
2862         debug_hexdump(stdout, "digest:",
2863                 sym_op->auth.digest.data,
2864                 auth_tag_len);
2865
2866         /* Copy cipher and auth IVs at the end of the crypto operation */
2867         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2868                                                 IV_OFFSET);
2869         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2870         iv_ptr += cipher_iv_len;
2871         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2872
2873         sym_op->cipher.data.length = cipher_len;
2874         sym_op->cipher.data.offset = cipher_offset;
2875         sym_op->auth.data.length = auth_len;
2876         sym_op->auth.data.offset = auth_offset;
2877
2878         return 0;
2879 }
2880
2881 static int
2882 create_wireless_algo_auth_cipher_operation(unsigned int auth_tag_len,
2883                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2884                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2885                 unsigned int data_pad_len,
2886                 unsigned int cipher_len, unsigned int cipher_offset,
2887                 unsigned int auth_len, unsigned int auth_offset,
2888                 uint8_t op_mode, uint8_t do_sgl)
2889 {
2890         struct crypto_testsuite_params *ts_params = &testsuite_params;
2891         struct crypto_unittest_params *ut_params = &unittest_params;
2892
2893         /* Generate Crypto op data structure */
2894         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2895                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2896         TEST_ASSERT_NOT_NULL(ut_params->op,
2897                         "Failed to allocate pktmbuf offload");
2898
2899         /* Set crypto operation data parameters */
2900         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2901
2902         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2903
2904         /* set crypto operation mbufs */
2905         sym_op->m_src = ut_params->ibuf;
2906         if (op_mode == OUT_OF_PLACE)
2907                 sym_op->m_dst = ut_params->obuf;
2908
2909         /* digest */
2910         if (!do_sgl) {
2911                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2912                         (op_mode == IN_PLACE ?
2913                                 ut_params->ibuf : ut_params->obuf),
2914                         uint8_t *, data_pad_len);
2915                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2916                         (op_mode == IN_PLACE ?
2917                                 ut_params->ibuf : ut_params->obuf),
2918                         data_pad_len);
2919                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2920         } else {
2921                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2922                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2923                                 sym_op->m_src : sym_op->m_dst);
2924                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2925                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2926                         sgl_buf = sgl_buf->next;
2927                 }
2928                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2929                                 uint8_t *, remaining_off);
2930                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2931                                 remaining_off);
2932                 memset(sym_op->auth.digest.data, 0, remaining_off);
2933                 while (sgl_buf->next != NULL) {
2934                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2935                                 0, rte_pktmbuf_data_len(sgl_buf));
2936                         sgl_buf = sgl_buf->next;
2937                 }
2938         }
2939
2940         /* Copy cipher and auth IVs at the end of the crypto operation */
2941         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2942                         ut_params->op, uint8_t *, IV_OFFSET);
2943
2944         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2945         iv_ptr += cipher_iv_len;
2946         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2947
2948         sym_op->cipher.data.length = cipher_len;
2949         sym_op->cipher.data.offset = cipher_offset;
2950
2951         sym_op->auth.data.length = auth_len;
2952         sym_op->auth.data.offset = auth_offset;
2953
2954         return 0;
2955 }
2956
2957 static int
2958 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2959 {
2960         struct crypto_testsuite_params *ts_params = &testsuite_params;
2961         struct crypto_unittest_params *ut_params = &unittest_params;
2962
2963         int retval;
2964         unsigned plaintext_pad_len;
2965         unsigned plaintext_len;
2966         uint8_t *plaintext;
2967
2968         /* Create SNOW 3G session */
2969         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2970                         tdata->key.data, tdata->key.len,
2971                         tdata->auth_iv.len, tdata->digest.len,
2972                         RTE_CRYPTO_AUTH_OP_GENERATE,
2973                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2974         if (retval < 0)
2975                 return retval;
2976
2977         /* alloc mbuf and set payload */
2978         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2979
2980         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2981         rte_pktmbuf_tailroom(ut_params->ibuf));
2982
2983         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2984         /* Append data which is padded to a multiple of */
2985         /* the algorithms block size */
2986         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2987         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2988                                 plaintext_pad_len);
2989         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2990
2991         /* Create SNOW 3G operation */
2992         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2993                         tdata->auth_iv.data, tdata->auth_iv.len,
2994                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2995                         tdata->validAuthLenInBits.len,
2996                         0);
2997         if (retval < 0)
2998                 return retval;
2999
3000         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3001                                 ut_params->op);
3002         ut_params->obuf = ut_params->op->sym->m_src;
3003         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3004         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3005                         + plaintext_pad_len;
3006
3007         /* Validate obuf */
3008         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3009         ut_params->digest,
3010         tdata->digest.data,
3011         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3012         "SNOW 3G Generated auth tag not as expected");
3013
3014         return 0;
3015 }
3016
3017 static int
3018 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3019 {
3020         struct crypto_testsuite_params *ts_params = &testsuite_params;
3021         struct crypto_unittest_params *ut_params = &unittest_params;
3022
3023         int retval;
3024         unsigned plaintext_pad_len;
3025         unsigned plaintext_len;
3026         uint8_t *plaintext;
3027
3028         /* Create SNOW 3G session */
3029         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3030                                 tdata->key.data, tdata->key.len,
3031                                 tdata->auth_iv.len, tdata->digest.len,
3032                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3033                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3034         if (retval < 0)
3035                 return retval;
3036         /* alloc mbuf and set payload */
3037         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3038
3039         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3040         rte_pktmbuf_tailroom(ut_params->ibuf));
3041
3042         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3043         /* Append data which is padded to a multiple of */
3044         /* the algorithms block size */
3045         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3046         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3047                                 plaintext_pad_len);
3048         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3049
3050         /* Create SNOW 3G operation */
3051         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3052                         tdata->digest.len,
3053                         tdata->auth_iv.data, tdata->auth_iv.len,
3054                         plaintext_pad_len,
3055                         RTE_CRYPTO_AUTH_OP_VERIFY,
3056                         tdata->validAuthLenInBits.len,
3057                         0);
3058         if (retval < 0)
3059                 return retval;
3060
3061         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3062                                 ut_params->op);
3063         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3064         ut_params->obuf = ut_params->op->sym->m_src;
3065         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3066                                 + plaintext_pad_len;
3067
3068         /* Validate obuf */
3069         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3070                 return 0;
3071         else
3072                 return -1;
3073
3074         return 0;
3075 }
3076
3077 static int
3078 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3079 {
3080         struct crypto_testsuite_params *ts_params = &testsuite_params;
3081         struct crypto_unittest_params *ut_params = &unittest_params;
3082
3083         int retval;
3084         unsigned plaintext_pad_len;
3085         unsigned plaintext_len;
3086         uint8_t *plaintext;
3087
3088         /* Create KASUMI session */
3089         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3090                         tdata->key.data, tdata->key.len,
3091                         0, tdata->digest.len,
3092                         RTE_CRYPTO_AUTH_OP_GENERATE,
3093                         RTE_CRYPTO_AUTH_KASUMI_F9);
3094         if (retval < 0)
3095                 return retval;
3096
3097         /* alloc mbuf and set payload */
3098         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3099
3100         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3101         rte_pktmbuf_tailroom(ut_params->ibuf));
3102
3103         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3104         /* Append data which is padded to a multiple of */
3105         /* the algorithms block size */
3106         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3107         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3108                                 plaintext_pad_len);
3109         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3110
3111         /* Create KASUMI operation */
3112         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3113                         NULL, 0,
3114                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3115                         tdata->plaintext.len,
3116                         0);
3117         if (retval < 0)
3118                 return retval;
3119
3120         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3121                                 ut_params->op);
3122         ut_params->obuf = ut_params->op->sym->m_src;
3123         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3124         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3125                         + plaintext_pad_len;
3126
3127         /* Validate obuf */
3128         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3129         ut_params->digest,
3130         tdata->digest.data,
3131         DIGEST_BYTE_LENGTH_KASUMI_F9,
3132         "KASUMI Generated auth tag not as expected");
3133
3134         return 0;
3135 }
3136
3137 static int
3138 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3139 {
3140         struct crypto_testsuite_params *ts_params = &testsuite_params;
3141         struct crypto_unittest_params *ut_params = &unittest_params;
3142
3143         int retval;
3144         unsigned plaintext_pad_len;
3145         unsigned plaintext_len;
3146         uint8_t *plaintext;
3147
3148         /* Create KASUMI session */
3149         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3150                                 tdata->key.data, tdata->key.len,
3151                                 0, tdata->digest.len,
3152                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3153                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3154         if (retval < 0)
3155                 return retval;
3156         /* alloc mbuf and set payload */
3157         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3158
3159         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3160         rte_pktmbuf_tailroom(ut_params->ibuf));
3161
3162         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3163         /* Append data which is padded to a multiple */
3164         /* of the algorithms block size */
3165         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3166         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3167                                 plaintext_pad_len);
3168         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3169
3170         /* Create KASUMI operation */
3171         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3172                         tdata->digest.len,
3173                         NULL, 0,
3174                         plaintext_pad_len,
3175                         RTE_CRYPTO_AUTH_OP_VERIFY,
3176                         tdata->plaintext.len,
3177                         0);
3178         if (retval < 0)
3179                 return retval;
3180
3181         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3182                                 ut_params->op);
3183         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3184         ut_params->obuf = ut_params->op->sym->m_src;
3185         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3186                                 + plaintext_pad_len;
3187
3188         /* Validate obuf */
3189         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3190                 return 0;
3191         else
3192                 return -1;
3193
3194         return 0;
3195 }
3196
3197 static int
3198 test_snow3g_hash_generate_test_case_1(void)
3199 {
3200         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3201 }
3202
3203 static int
3204 test_snow3g_hash_generate_test_case_2(void)
3205 {
3206         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3207 }
3208
3209 static int
3210 test_snow3g_hash_generate_test_case_3(void)
3211 {
3212         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3213 }
3214
3215 static int
3216 test_snow3g_hash_generate_test_case_4(void)
3217 {
3218         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3219 }
3220
3221 static int
3222 test_snow3g_hash_generate_test_case_5(void)
3223 {
3224         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3225 }
3226
3227 static int
3228 test_snow3g_hash_generate_test_case_6(void)
3229 {
3230         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3231 }
3232
3233 static int
3234 test_snow3g_hash_verify_test_case_1(void)
3235 {
3236         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3237
3238 }
3239
3240 static int
3241 test_snow3g_hash_verify_test_case_2(void)
3242 {
3243         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3244 }
3245
3246 static int
3247 test_snow3g_hash_verify_test_case_3(void)
3248 {
3249         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3250 }
3251
3252 static int
3253 test_snow3g_hash_verify_test_case_4(void)
3254 {
3255         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3256 }
3257
3258 static int
3259 test_snow3g_hash_verify_test_case_5(void)
3260 {
3261         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3262 }
3263
3264 static int
3265 test_snow3g_hash_verify_test_case_6(void)
3266 {
3267         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3268 }
3269
3270 static int
3271 test_kasumi_hash_generate_test_case_1(void)
3272 {
3273         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3274 }
3275
3276 static int
3277 test_kasumi_hash_generate_test_case_2(void)
3278 {
3279         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3280 }
3281
3282 static int
3283 test_kasumi_hash_generate_test_case_3(void)
3284 {
3285         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3286 }
3287
3288 static int
3289 test_kasumi_hash_generate_test_case_4(void)
3290 {
3291         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3292 }
3293
3294 static int
3295 test_kasumi_hash_generate_test_case_5(void)
3296 {
3297         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3298 }
3299
3300 static int
3301 test_kasumi_hash_generate_test_case_6(void)
3302 {
3303         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3304 }
3305
3306 static int
3307 test_kasumi_hash_verify_test_case_1(void)
3308 {
3309         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3310 }
3311
3312 static int
3313 test_kasumi_hash_verify_test_case_2(void)
3314 {
3315         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3316 }
3317
3318 static int
3319 test_kasumi_hash_verify_test_case_3(void)
3320 {
3321         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3322 }
3323
3324 static int
3325 test_kasumi_hash_verify_test_case_4(void)
3326 {
3327         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3328 }
3329
3330 static int
3331 test_kasumi_hash_verify_test_case_5(void)
3332 {
3333         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3334 }
3335
3336 static int
3337 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3338 {
3339         struct crypto_testsuite_params *ts_params = &testsuite_params;
3340         struct crypto_unittest_params *ut_params = &unittest_params;
3341
3342         int retval;
3343         uint8_t *plaintext, *ciphertext;
3344         unsigned plaintext_pad_len;
3345         unsigned plaintext_len;
3346
3347         /* Create KASUMI session */
3348         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3349                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3350                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3351                                         tdata->key.data, tdata->key.len,
3352                                         tdata->cipher_iv.len);
3353         if (retval < 0)
3354                 return retval;
3355
3356         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3357
3358         /* Clear mbuf payload */
3359         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3360                rte_pktmbuf_tailroom(ut_params->ibuf));
3361
3362         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3363         /* Append data which is padded to a multiple */
3364         /* of the algorithms block size */
3365         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3366         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3367                                 plaintext_pad_len);
3368         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3369
3370         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3371
3372         /* Create KASUMI operation */
3373         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3374                                 tdata->cipher_iv.len,
3375                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3376                                 tdata->validCipherOffsetInBits.len);
3377         if (retval < 0)
3378                 return retval;
3379
3380         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3381                                                 ut_params->op);
3382         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3383
3384         ut_params->obuf = ut_params->op->sym->m_dst;
3385         if (ut_params->obuf)
3386                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3387         else
3388                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3389
3390         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3391
3392         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3393                                 (tdata->validCipherOffsetInBits.len >> 3);
3394         /* Validate obuf */
3395         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3396                 ciphertext,
3397                 reference_ciphertext,
3398                 tdata->validCipherLenInBits.len,
3399                 "KASUMI Ciphertext data not as expected");
3400         return 0;
3401 }
3402
3403 static int
3404 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3405 {
3406         struct crypto_testsuite_params *ts_params = &testsuite_params;
3407         struct crypto_unittest_params *ut_params = &unittest_params;
3408
3409         int retval;
3410
3411         unsigned int plaintext_pad_len;
3412         unsigned int plaintext_len;
3413
3414         uint8_t buffer[10000];
3415         const uint8_t *ciphertext;
3416
3417         struct rte_cryptodev_info dev_info;
3418
3419         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3420
3421         uint64_t feat_flags = dev_info.feature_flags;
3422
3423         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3424                 printf("Device doesn't support in-place scatter-gather. "
3425                                 "Test Skipped.\n");
3426                 return -ENOTSUP;
3427         }
3428
3429         /* Create KASUMI session */
3430         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3431                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3432                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3433                                         tdata->key.data, tdata->key.len,
3434                                         tdata->cipher_iv.len);
3435         if (retval < 0)
3436                 return retval;
3437
3438         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3439
3440
3441         /* Append data which is padded to a multiple */
3442         /* of the algorithms block size */
3443         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3444
3445         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3446                         plaintext_pad_len, 10, 0);
3447
3448         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3449
3450         /* Create KASUMI operation */
3451         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3452                                 tdata->cipher_iv.len,
3453                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3454                                 tdata->validCipherOffsetInBits.len);
3455         if (retval < 0)
3456                 return retval;
3457
3458         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3459                                                 ut_params->op);
3460         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3461
3462         ut_params->obuf = ut_params->op->sym->m_dst;
3463
3464         if (ut_params->obuf)
3465                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3466                                 plaintext_len, buffer);
3467         else
3468                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3469                                 tdata->validCipherOffsetInBits.len >> 3,
3470                                 plaintext_len, buffer);
3471
3472         /* Validate obuf */
3473         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3474
3475         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3476                                 (tdata->validCipherOffsetInBits.len >> 3);
3477         /* Validate obuf */
3478         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3479                 ciphertext,
3480                 reference_ciphertext,
3481                 tdata->validCipherLenInBits.len,
3482                 "KASUMI Ciphertext data not as expected");
3483         return 0;
3484 }
3485
3486 static int
3487 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3488 {
3489         struct crypto_testsuite_params *ts_params = &testsuite_params;
3490         struct crypto_unittest_params *ut_params = &unittest_params;
3491
3492         int retval;
3493         uint8_t *plaintext, *ciphertext;
3494         unsigned plaintext_pad_len;
3495         unsigned plaintext_len;
3496
3497         /* Create KASUMI session */
3498         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3499                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3500                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3501                                         tdata->key.data, tdata->key.len,
3502                                         tdata->cipher_iv.len);
3503         if (retval < 0)
3504                 return retval;
3505
3506         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3507         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3508
3509         /* Clear mbuf payload */
3510         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3511                rte_pktmbuf_tailroom(ut_params->ibuf));
3512
3513         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3514         /* Append data which is padded to a multiple */
3515         /* of the algorithms block size */
3516         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3517         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3518                                 plaintext_pad_len);
3519         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3520         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3521
3522         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3523
3524         /* Create KASUMI operation */
3525         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3526                                 tdata->cipher_iv.len,
3527                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3528                                 tdata->validCipherOffsetInBits.len);
3529         if (retval < 0)
3530                 return retval;
3531
3532         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3533                                                 ut_params->op);
3534         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3535
3536         ut_params->obuf = ut_params->op->sym->m_dst;
3537         if (ut_params->obuf)
3538                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3539         else
3540                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3541
3542         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3543
3544         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3545                                 (tdata->validCipherOffsetInBits.len >> 3);
3546         /* Validate obuf */
3547         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3548                 ciphertext,
3549                 reference_ciphertext,
3550                 tdata->validCipherLenInBits.len,
3551                 "KASUMI Ciphertext data not as expected");
3552         return 0;
3553 }
3554
3555 static int
3556 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3557 {
3558         struct crypto_testsuite_params *ts_params = &testsuite_params;
3559         struct crypto_unittest_params *ut_params = &unittest_params;
3560
3561         int retval;
3562         unsigned int plaintext_pad_len;
3563         unsigned int plaintext_len;
3564
3565         const uint8_t *ciphertext;
3566         uint8_t buffer[2048];
3567
3568         struct rte_cryptodev_info dev_info;
3569
3570         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3571
3572         uint64_t feat_flags = dev_info.feature_flags;
3573         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3574                 printf("Device doesn't support out-of-place scatter-gather "
3575                                 "in both input and output mbufs. "
3576                                 "Test Skipped.\n");
3577                 return -ENOTSUP;
3578         }
3579
3580         /* Create KASUMI session */
3581         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3582                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3583                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3584                                         tdata->key.data, tdata->key.len,
3585                                         tdata->cipher_iv.len);
3586         if (retval < 0)
3587                 return retval;
3588
3589         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3590         /* Append data which is padded to a multiple */
3591         /* of the algorithms block size */
3592         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3593
3594         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3595                         plaintext_pad_len, 10, 0);
3596         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3597                         plaintext_pad_len, 3, 0);
3598
3599         /* Append data which is padded to a multiple */
3600         /* of the algorithms block size */
3601         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3602
3603         /* Create KASUMI operation */
3604         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3605                                 tdata->cipher_iv.len,
3606                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3607                                 tdata->validCipherOffsetInBits.len);
3608         if (retval < 0)
3609                 return retval;
3610
3611         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3612                                                 ut_params->op);
3613         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3614
3615         ut_params->obuf = ut_params->op->sym->m_dst;
3616         if (ut_params->obuf)
3617                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3618                                 plaintext_pad_len, buffer);
3619         else
3620                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3621                                 tdata->validCipherOffsetInBits.len >> 3,
3622                                 plaintext_pad_len, buffer);
3623
3624         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3625                                 (tdata->validCipherOffsetInBits.len >> 3);
3626         /* Validate obuf */
3627         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3628                 ciphertext,
3629                 reference_ciphertext,
3630                 tdata->validCipherLenInBits.len,
3631                 "KASUMI Ciphertext data not as expected");
3632         return 0;
3633 }
3634
3635
3636 static int
3637 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3638 {
3639         struct crypto_testsuite_params *ts_params = &testsuite_params;
3640         struct crypto_unittest_params *ut_params = &unittest_params;
3641
3642         int retval;
3643         uint8_t *ciphertext, *plaintext;
3644         unsigned ciphertext_pad_len;
3645         unsigned ciphertext_len;
3646
3647         /* Create KASUMI session */
3648         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3649                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3650                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3651                                         tdata->key.data, tdata->key.len,
3652                                         tdata->cipher_iv.len);
3653         if (retval < 0)
3654                 return retval;
3655
3656         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3657         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3658
3659         /* Clear mbuf payload */
3660         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3661                rte_pktmbuf_tailroom(ut_params->ibuf));
3662
3663         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3664         /* Append data which is padded to a multiple */
3665         /* of the algorithms block size */
3666         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3667         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3668                                 ciphertext_pad_len);
3669         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3670         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3671
3672         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3673
3674         /* Create KASUMI operation */
3675         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3676                                 tdata->cipher_iv.len,
3677                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3678                                 tdata->validCipherOffsetInBits.len);
3679         if (retval < 0)
3680                 return retval;
3681
3682         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3683                                                 ut_params->op);
3684         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3685
3686         ut_params->obuf = ut_params->op->sym->m_dst;
3687         if (ut_params->obuf)
3688                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3689         else
3690                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3691
3692         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3693
3694         const uint8_t *reference_plaintext = tdata->plaintext.data +
3695                                 (tdata->validCipherOffsetInBits.len >> 3);
3696         /* Validate obuf */
3697         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3698                 plaintext,
3699                 reference_plaintext,
3700                 tdata->validCipherLenInBits.len,
3701                 "KASUMI Plaintext data not as expected");
3702         return 0;
3703 }
3704
3705 static int
3706 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3707 {
3708         struct crypto_testsuite_params *ts_params = &testsuite_params;
3709         struct crypto_unittest_params *ut_params = &unittest_params;
3710
3711         int retval;
3712         uint8_t *ciphertext, *plaintext;
3713         unsigned ciphertext_pad_len;
3714         unsigned ciphertext_len;
3715
3716         /* Create KASUMI session */
3717         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3718                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3719                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3720                                         tdata->key.data, tdata->key.len,
3721                                         tdata->cipher_iv.len);
3722         if (retval < 0)
3723                 return retval;
3724
3725         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3726
3727         /* Clear mbuf payload */
3728         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3729                rte_pktmbuf_tailroom(ut_params->ibuf));
3730
3731         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3732         /* Append data which is padded to a multiple */
3733         /* of the algorithms block size */
3734         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3735         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3736                                 ciphertext_pad_len);
3737         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3738
3739         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3740
3741         /* Create KASUMI operation */
3742         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3743                                         tdata->cipher_iv.len,
3744                                         tdata->ciphertext.len,
3745                                         tdata->validCipherOffsetInBits.len);
3746         if (retval < 0)
3747                 return retval;
3748
3749         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3750                                                 ut_params->op);
3751         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3752
3753         ut_params->obuf = ut_params->op->sym->m_dst;
3754         if (ut_params->obuf)
3755                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3756         else
3757                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3758
3759         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3760
3761         const uint8_t *reference_plaintext = tdata->plaintext.data +
3762                                 (tdata->validCipherOffsetInBits.len >> 3);
3763         /* Validate obuf */
3764         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3765                 plaintext,
3766                 reference_plaintext,
3767                 tdata->validCipherLenInBits.len,
3768                 "KASUMI Plaintext data not as expected");
3769         return 0;
3770 }
3771
3772 static int
3773 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3774 {
3775         struct crypto_testsuite_params *ts_params = &testsuite_params;
3776         struct crypto_unittest_params *ut_params = &unittest_params;
3777
3778         int retval;
3779         uint8_t *plaintext, *ciphertext;
3780         unsigned plaintext_pad_len;
3781         unsigned plaintext_len;
3782
3783         /* Create SNOW 3G session */
3784         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3785                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3786                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3787                                         tdata->key.data, tdata->key.len,
3788                                         tdata->cipher_iv.len);
3789         if (retval < 0)
3790                 return retval;
3791
3792         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3793
3794         /* Clear mbuf payload */
3795         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3796                rte_pktmbuf_tailroom(ut_params->ibuf));
3797
3798         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3799         /* Append data which is padded to a multiple of */
3800         /* the algorithms block size */
3801         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3802         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3803                                 plaintext_pad_len);
3804         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3805
3806         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3807
3808         /* Create SNOW 3G operation */
3809         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3810                                         tdata->cipher_iv.len,
3811                                         tdata->validCipherLenInBits.len,
3812                                         0);
3813         if (retval < 0)
3814                 return retval;
3815
3816         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3817                                                 ut_params->op);
3818         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3819
3820         ut_params->obuf = ut_params->op->sym->m_dst;
3821         if (ut_params->obuf)
3822                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3823         else
3824                 ciphertext = plaintext;
3825
3826         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3827
3828         /* Validate obuf */
3829         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3830                 ciphertext,
3831                 tdata->ciphertext.data,
3832                 tdata->validDataLenInBits.len,
3833                 "SNOW 3G Ciphertext data not as expected");
3834         return 0;
3835 }
3836
3837
3838 static int
3839 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3840 {
3841         struct crypto_testsuite_params *ts_params = &testsuite_params;
3842         struct crypto_unittest_params *ut_params = &unittest_params;
3843         uint8_t *plaintext, *ciphertext;
3844
3845         int retval;
3846         unsigned plaintext_pad_len;
3847         unsigned plaintext_len;
3848
3849         /* Create SNOW 3G session */
3850         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3851                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3852                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3853                                         tdata->key.data, tdata->key.len,
3854                                         tdata->cipher_iv.len);
3855         if (retval < 0)
3856                 return retval;
3857
3858         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3859         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3860
3861         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3862                         "Failed to allocate input buffer in mempool");
3863         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3864                         "Failed to allocate output buffer in mempool");
3865
3866         /* Clear mbuf payload */
3867         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3868                rte_pktmbuf_tailroom(ut_params->ibuf));
3869
3870         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3871         /* Append data which is padded to a multiple of */
3872         /* the algorithms block size */
3873         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3874         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3875                                 plaintext_pad_len);
3876         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3877         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3878
3879         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3880
3881         /* Create SNOW 3G operation */
3882         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3883                                         tdata->cipher_iv.len,
3884                                         tdata->validCipherLenInBits.len,
3885                                         0);
3886         if (retval < 0)
3887                 return retval;
3888
3889         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3890                                                 ut_params->op);
3891         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3892
3893         ut_params->obuf = ut_params->op->sym->m_dst;
3894         if (ut_params->obuf)
3895                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3896         else
3897                 ciphertext = plaintext;
3898
3899         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3900
3901         /* Validate obuf */
3902         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3903                 ciphertext,
3904                 tdata->ciphertext.data,
3905                 tdata->validDataLenInBits.len,
3906                 "SNOW 3G Ciphertext data not as expected");
3907         return 0;
3908 }
3909
3910 static int
3911 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3912 {
3913         struct crypto_testsuite_params *ts_params = &testsuite_params;
3914         struct crypto_unittest_params *ut_params = &unittest_params;
3915
3916         int retval;
3917         unsigned int plaintext_pad_len;
3918         unsigned int plaintext_len;
3919         uint8_t buffer[10000];
3920         const uint8_t *ciphertext;
3921
3922         struct rte_cryptodev_info dev_info;
3923
3924         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3925
3926         uint64_t feat_flags = dev_info.feature_flags;
3927
3928         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3929                 printf("Device doesn't support out-of-place scatter-gather "
3930                                 "in both input and output mbufs. "
3931                                 "Test Skipped.\n");
3932                 return -ENOTSUP;
3933         }
3934
3935         /* Create SNOW 3G session */
3936         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3937                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3938                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3939                                         tdata->key.data, tdata->key.len,
3940                                         tdata->cipher_iv.len);
3941         if (retval < 0)
3942                 return retval;
3943
3944         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3945         /* Append data which is padded to a multiple of */
3946         /* the algorithms block size */
3947         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3948
3949         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3950                         plaintext_pad_len, 10, 0);
3951         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3952                         plaintext_pad_len, 3, 0);
3953
3954         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3955                         "Failed to allocate input buffer in mempool");
3956         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3957                         "Failed to allocate output buffer in mempool");
3958
3959         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3960
3961         /* Create SNOW 3G operation */
3962         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3963                                         tdata->cipher_iv.len,
3964                                         tdata->validCipherLenInBits.len,
3965                                         0);
3966         if (retval < 0)
3967                 return retval;
3968
3969         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3970                                                 ut_params->op);
3971         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3972
3973         ut_params->obuf = ut_params->op->sym->m_dst;
3974         if (ut_params->obuf)
3975                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3976                                 plaintext_len, buffer);
3977         else
3978                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3979                                 plaintext_len, buffer);
3980
3981         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3982
3983         /* Validate obuf */
3984         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3985                 ciphertext,
3986                 tdata->ciphertext.data,
3987                 tdata->validDataLenInBits.len,
3988                 "SNOW 3G Ciphertext data not as expected");
3989
3990         return 0;
3991 }
3992
3993 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3994 static void
3995 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3996 {
3997         uint8_t curr_byte, prev_byte;
3998         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3999         uint8_t lower_byte_mask = (1 << offset) - 1;
4000         unsigned i;
4001
4002         prev_byte = buffer[0];
4003         buffer[0] >>= offset;
4004
4005         for (i = 1; i < length_in_bytes; i++) {
4006                 curr_byte = buffer[i];
4007                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4008                                 (curr_byte >> offset);
4009                 prev_byte = curr_byte;
4010         }
4011 }
4012
4013 static int
4014 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4015 {
4016         struct crypto_testsuite_params *ts_params = &testsuite_params;
4017         struct crypto_unittest_params *ut_params = &unittest_params;
4018         uint8_t *plaintext, *ciphertext;
4019         int retval;
4020         uint32_t plaintext_len;
4021         uint32_t plaintext_pad_len;
4022         uint8_t extra_offset = 4;
4023         uint8_t *expected_ciphertext_shifted;
4024
4025         /* Create SNOW 3G session */
4026         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4027                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4028                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4029                                         tdata->key.data, tdata->key.len,
4030                                         tdata->cipher_iv.len);
4031         if (retval < 0)
4032                 return retval;
4033
4034         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4035         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4036
4037         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4038                         "Failed to allocate input buffer in mempool");
4039         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4040                         "Failed to allocate output buffer in mempool");
4041
4042         /* Clear mbuf payload */
4043         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4044                rte_pktmbuf_tailroom(ut_params->ibuf));
4045
4046         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4047         /*
4048          * Append data which is padded to a
4049          * multiple of the algorithms block size
4050          */
4051         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4052
4053         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4054                                                 plaintext_pad_len);
4055
4056         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4057
4058         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4059         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4060
4061 #ifdef RTE_APP_TEST_DEBUG
4062         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4063 #endif
4064         /* Create SNOW 3G operation */
4065         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4066                                         tdata->cipher_iv.len,
4067                                         tdata->validCipherLenInBits.len,
4068                                         extra_offset);
4069         if (retval < 0)
4070                 return retval;
4071
4072         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4073                                                 ut_params->op);
4074         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4075
4076         ut_params->obuf = ut_params->op->sym->m_dst;
4077         if (ut_params->obuf)
4078                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4079         else
4080                 ciphertext = plaintext;
4081
4082 #ifdef RTE_APP_TEST_DEBUG
4083         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4084 #endif
4085
4086         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4087
4088         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4089                         "failed to reserve memory for ciphertext shifted\n");
4090
4091         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4092                         ceil_byte_length(tdata->ciphertext.len));
4093         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4094                         extra_offset);
4095         /* Validate obuf */
4096         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4097                 ciphertext,
4098                 expected_ciphertext_shifted,
4099                 tdata->validDataLenInBits.len,
4100                 extra_offset,
4101                 "SNOW 3G Ciphertext data not as expected");
4102         return 0;
4103 }
4104
4105 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4106 {
4107         struct crypto_testsuite_params *ts_params = &testsuite_params;
4108         struct crypto_unittest_params *ut_params = &unittest_params;
4109
4110         int retval;
4111
4112         uint8_t *plaintext, *ciphertext;
4113         unsigned ciphertext_pad_len;
4114         unsigned ciphertext_len;
4115
4116         /* Create SNOW 3G session */
4117         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4118                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4119                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4120                                         tdata->key.data, tdata->key.len,
4121                                         tdata->cipher_iv.len);
4122         if (retval < 0)
4123                 return retval;
4124
4125         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4126
4127         /* Clear mbuf payload */
4128         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4129                rte_pktmbuf_tailroom(ut_params->ibuf));
4130
4131         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4132         /* Append data which is padded to a multiple of */
4133         /* the algorithms block size */
4134         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4135         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4136                                 ciphertext_pad_len);
4137         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4138
4139         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4140
4141         /* Create SNOW 3G operation */
4142         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4143                                         tdata->cipher_iv.len,
4144                                         tdata->validCipherLenInBits.len,
4145                                         tdata->cipher.offset_bits);
4146         if (retval < 0)
4147                 return retval;
4148
4149         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4150                                                 ut_params->op);
4151         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4152         ut_params->obuf = ut_params->op->sym->m_dst;
4153         if (ut_params->obuf)
4154                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4155         else
4156                 plaintext = ciphertext;
4157
4158         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4159
4160         /* Validate obuf */
4161         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4162                                 tdata->plaintext.data,
4163                                 tdata->validDataLenInBits.len,
4164                                 "SNOW 3G Plaintext data not as expected");
4165         return 0;
4166 }
4167
4168 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4169 {
4170         struct crypto_testsuite_params *ts_params = &testsuite_params;
4171         struct crypto_unittest_params *ut_params = &unittest_params;
4172
4173         int retval;
4174
4175         uint8_t *plaintext, *ciphertext;
4176         unsigned ciphertext_pad_len;
4177         unsigned ciphertext_len;
4178
4179         /* Create SNOW 3G session */
4180         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4181                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4182                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4183                                         tdata->key.data, tdata->key.len,
4184                                         tdata->cipher_iv.len);
4185         if (retval < 0)
4186                 return retval;
4187
4188         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4189         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4190
4191         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4192                         "Failed to allocate input buffer");
4193         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4194                         "Failed to allocate output buffer");
4195
4196         /* Clear mbuf payload */
4197         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4198                rte_pktmbuf_tailroom(ut_params->ibuf));
4199
4200         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4201                        rte_pktmbuf_tailroom(ut_params->obuf));
4202
4203         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4204         /* Append data which is padded to a multiple of */
4205         /* the algorithms block size */
4206         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4207         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4208                                 ciphertext_pad_len);
4209         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4210         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4211
4212         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4213
4214         /* Create SNOW 3G operation */
4215         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4216                                         tdata->cipher_iv.len,
4217                                         tdata->validCipherLenInBits.len,
4218                                         0);
4219         if (retval < 0)
4220                 return retval;
4221
4222         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4223                                                 ut_params->op);
4224         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4225         ut_params->obuf = ut_params->op->sym->m_dst;
4226         if (ut_params->obuf)
4227                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4228         else
4229                 plaintext = ciphertext;
4230
4231         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4232
4233         /* Validate obuf */
4234         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4235                                 tdata->plaintext.data,
4236                                 tdata->validDataLenInBits.len,
4237                                 "SNOW 3G Plaintext data not as expected");
4238         return 0;
4239 }
4240
4241 static int
4242 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4243 {
4244         struct crypto_testsuite_params *ts_params = &testsuite_params;
4245         struct crypto_unittest_params *ut_params = &unittest_params;
4246
4247         int retval;
4248
4249         uint8_t *plaintext, *ciphertext;
4250         unsigned int plaintext_pad_len;
4251         unsigned int plaintext_len;
4252
4253         struct rte_cryptodev_sym_capability_idx cap_idx;
4254
4255         /* Check if device supports ZUC EEA3 */
4256         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4257         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4258
4259         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4260                         &cap_idx) == NULL)
4261                 return -ENOTSUP;
4262
4263         /* Check if device supports ZUC EIA3 */
4264         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4265         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4266
4267         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4268                         &cap_idx) == NULL)
4269                 return -ENOTSUP;
4270
4271         /* Create ZUC session */
4272         retval = create_zuc_cipher_auth_encrypt_generate_session(
4273                         ts_params->valid_devs[0],
4274                         tdata);
4275         if (retval < 0)
4276                 return retval;
4277         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4278
4279         /* clear mbuf payload */
4280         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4281                         rte_pktmbuf_tailroom(ut_params->ibuf));
4282
4283         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4284         /* Append data which is padded to a multiple of */
4285         /* the algorithms block size */
4286         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4287         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4288                                 plaintext_pad_len);
4289         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4290
4291         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4292
4293         /* Create ZUC operation */
4294         retval = create_zuc_cipher_hash_generate_operation(tdata);
4295         if (retval < 0)
4296                 return retval;
4297
4298         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4299                         ut_params->op);
4300         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4301         ut_params->obuf = ut_params->op->sym->m_src;
4302         if (ut_params->obuf)
4303                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4304         else
4305                 ciphertext = plaintext;
4306
4307         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4308         /* Validate obuf */
4309         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4310                         ciphertext,
4311                         tdata->ciphertext.data,
4312                         tdata->validDataLenInBits.len,
4313                         "ZUC Ciphertext data not as expected");
4314
4315         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4316             + plaintext_pad_len;
4317
4318         /* Validate obuf */
4319         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4320                         ut_params->digest,
4321                         tdata->digest.data,
4322                         4,
4323                         "ZUC Generated auth tag not as expected");
4324         return 0;
4325 }
4326
4327 static int
4328 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4329 {
4330         struct crypto_testsuite_params *ts_params = &testsuite_params;
4331         struct crypto_unittest_params *ut_params = &unittest_params;
4332
4333         int retval;
4334
4335         uint8_t *plaintext, *ciphertext;
4336         unsigned plaintext_pad_len;
4337         unsigned plaintext_len;
4338
4339         /* Create SNOW 3G session */
4340         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4341                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4342                         RTE_CRYPTO_AUTH_OP_GENERATE,
4343                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4344                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4345                         tdata->key.data, tdata->key.len,
4346                         tdata->auth_iv.len, tdata->digest.len,
4347                         tdata->cipher_iv.len);
4348         if (retval < 0)
4349                 return retval;
4350         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4351
4352         /* clear mbuf payload */
4353         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4354                         rte_pktmbuf_tailroom(ut_params->ibuf));
4355
4356         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4357         /* Append data which is padded to a multiple of */
4358         /* the algorithms block size */
4359         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4360         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4361                                 plaintext_pad_len);
4362         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4363
4364         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4365
4366         /* Create SNOW 3G operation */
4367         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4368                         tdata->digest.len, tdata->auth_iv.data,
4369                         tdata->auth_iv.len,
4370                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4371                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4372                         tdata->validCipherLenInBits.len,
4373                         0,
4374                         tdata->validAuthLenInBits.len,
4375                         0
4376                         );
4377         if (retval < 0)
4378                 return retval;
4379
4380         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4381                         ut_params->op);
4382         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4383         ut_params->obuf = ut_params->op->sym->m_src;
4384         if (ut_params->obuf)
4385                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4386         else
4387                 ciphertext = plaintext;
4388
4389         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4390         /* Validate obuf */
4391         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4392                         ciphertext,
4393                         tdata->ciphertext.data,
4394                         tdata->validDataLenInBits.len,
4395                         "SNOW 3G Ciphertext data not as expected");
4396
4397         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4398             + plaintext_pad_len;
4399
4400         /* Validate obuf */
4401         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4402                         ut_params->digest,
4403                         tdata->digest.data,
4404                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4405                         "SNOW 3G Generated auth tag not as expected");
4406         return 0;
4407 }
4408
4409 static int
4410 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4411         uint8_t op_mode, uint8_t verify)
4412 {
4413         struct crypto_testsuite_params *ts_params = &testsuite_params;
4414         struct crypto_unittest_params *ut_params = &unittest_params;
4415
4416         int retval;
4417
4418         uint8_t *plaintext = NULL, *ciphertext = NULL;
4419         unsigned int plaintext_pad_len;
4420         unsigned int plaintext_len;
4421         unsigned int ciphertext_pad_len;
4422         unsigned int ciphertext_len;
4423
4424         struct rte_cryptodev_info dev_info;
4425
4426         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4427
4428         uint64_t feat_flags = dev_info.feature_flags;
4429
4430         if (op_mode == OUT_OF_PLACE) {
4431                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4432                         printf("Device doesn't support digest encrypted.\n");
4433                         return -ENOTSUP;
4434                 }
4435         }
4436
4437         /* Create SNOW 3G session */
4438         retval = create_wireless_algo_auth_cipher_session(
4439                         ts_params->valid_devs[0],
4440                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4441                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4442                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4443                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4444                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4445                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4446                         tdata->key.data, tdata->key.len,
4447                         tdata->auth_iv.len, tdata->digest.len,
4448                         tdata->cipher_iv.len);
4449
4450         if (retval < 0)
4451                 return retval;
4452
4453         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4454         if (op_mode == OUT_OF_PLACE)
4455                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4456
4457         /* clear mbuf payload */
4458         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4459                 rte_pktmbuf_tailroom(ut_params->ibuf));
4460         if (op_mode == OUT_OF_PLACE)
4461                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4462                         rte_pktmbuf_tailroom(ut_params->obuf));
4463
4464         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4465         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4466         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4467         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4468
4469         if (verify) {
4470                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4471                                         ciphertext_pad_len);
4472                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4473                 if (op_mode == OUT_OF_PLACE)
4474                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4475                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4476                         ciphertext_len);
4477         } else {
4478                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4479                                         plaintext_pad_len);
4480                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4481                 if (op_mode == OUT_OF_PLACE)
4482                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4483                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4484         }
4485
4486         /* Create SNOW 3G operation */
4487         retval = create_wireless_algo_auth_cipher_operation(
4488                 tdata->digest.len,
4489                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4490                 tdata->auth_iv.data, tdata->auth_iv.len,
4491                 (tdata->digest.offset_bytes == 0 ?
4492                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4493                         : tdata->digest.offset_bytes),
4494                 tdata->validCipherLenInBits.len,
4495                 tdata->cipher.offset_bits,
4496                 tdata->validAuthLenInBits.len,
4497                 tdata->auth.offset_bits,
4498                 op_mode, 0);
4499
4500         if (retval < 0)
4501                 return retval;
4502
4503         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4504                         ut_params->op);
4505
4506         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4507
4508         ut_params->obuf = (op_mode == IN_PLACE ?
4509                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4510
4511         if (verify) {
4512                 if (ut_params->obuf)
4513                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4514                                                         uint8_t *);
4515                 else
4516                         plaintext = ciphertext +
4517                                 (tdata->cipher.offset_bits >> 3);
4518
4519                 debug_hexdump(stdout, "plaintext:", plaintext,
4520                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4521                 debug_hexdump(stdout, "plaintext expected:",
4522                         tdata->plaintext.data,
4523                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4524         } else {
4525                 if (ut_params->obuf)
4526                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4527                                                         uint8_t *);
4528                 else
4529                         ciphertext = plaintext;
4530
4531                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4532                         ciphertext_len);
4533                 debug_hexdump(stdout, "ciphertext expected:",
4534                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4535
4536                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4537                         + (tdata->digest.offset_bytes == 0 ?
4538                 plaintext_pad_len : tdata->digest.offset_bytes);
4539
4540                 debug_hexdump(stdout, "digest:", ut_params->digest,
4541                         tdata->digest.len);
4542                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4543                                 tdata->digest.len);
4544         }
4545
4546         /* Validate obuf */
4547         if (verify) {
4548                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4549                         plaintext,
4550                         tdata->plaintext.data,
4551                         tdata->plaintext.len >> 3,
4552                         "SNOW 3G Plaintext data not as expected");
4553         } else {
4554                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4555                         ciphertext,
4556                         tdata->ciphertext.data,
4557                         tdata->validDataLenInBits.len,
4558                         "SNOW 3G Ciphertext data not as expected");
4559
4560                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4561                         ut_params->digest,
4562                         tdata->digest.data,
4563                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4564                         "SNOW 3G Generated auth tag not as expected");
4565         }
4566         return 0;
4567 }
4568
4569 static int
4570 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4571         uint8_t op_mode, uint8_t verify)
4572 {
4573         struct crypto_testsuite_params *ts_params = &testsuite_params;
4574         struct crypto_unittest_params *ut_params = &unittest_params;
4575
4576         int retval;
4577
4578         const uint8_t *plaintext = NULL;
4579         const uint8_t *ciphertext = NULL;
4580         const uint8_t *digest = NULL;
4581         unsigned int plaintext_pad_len;
4582         unsigned int plaintext_len;
4583         unsigned int ciphertext_pad_len;
4584         unsigned int ciphertext_len;
4585         uint8_t buffer[10000];
4586         uint8_t digest_buffer[10000];
4587
4588         struct rte_cryptodev_info dev_info;
4589
4590         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4591
4592         uint64_t feat_flags = dev_info.feature_flags;
4593
4594         if (op_mode == IN_PLACE) {
4595                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4596                         printf("Device doesn't support in-place scatter-gather "
4597                                         "in both input and output mbufs.\n");
4598                         return -ENOTSUP;
4599                 }
4600         } else {
4601                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4602                         printf("Device doesn't support out-of-place scatter-gather "
4603                                         "in both input and output mbufs.\n");
4604                         return -ENOTSUP;
4605                 }
4606                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4607                         printf("Device doesn't support digest encrypted.\n");
4608                         return -ENOTSUP;
4609                 }
4610         }
4611
4612         /* Create SNOW 3G session */
4613         retval = create_wireless_algo_auth_cipher_session(
4614                         ts_params->valid_devs[0],
4615                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4616                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4617                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4618                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4619                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4620                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4621                         tdata->key.data, tdata->key.len,
4622                         tdata->auth_iv.len, tdata->digest.len,
4623                         tdata->cipher_iv.len);
4624
4625         if (retval < 0)
4626                 return retval;
4627
4628         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4629         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4630         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4631         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4632
4633         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4634                         plaintext_pad_len, 15, 0);
4635         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4636                         "Failed to allocate input buffer in mempool");
4637
4638         if (op_mode == OUT_OF_PLACE) {
4639                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4640                                 plaintext_pad_len, 15, 0);
4641                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4642                                 "Failed to allocate output buffer in mempool");
4643         }
4644
4645         if (verify) {
4646                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4647                         tdata->ciphertext.data);
4648                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4649                                         ciphertext_len, buffer);
4650                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4651                         ciphertext_len);
4652         } else {
4653                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4654                         tdata->plaintext.data);
4655                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4656                                         plaintext_len, buffer);
4657                 debug_hexdump(stdout, "plaintext:", plaintext,
4658                         plaintext_len);
4659         }
4660         memset(buffer, 0, sizeof(buffer));
4661
4662         /* Create SNOW 3G operation */
4663         retval = create_wireless_algo_auth_cipher_operation(
4664                 tdata->digest.len,
4665                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4666                 tdata->auth_iv.data, tdata->auth_iv.len,
4667                 (tdata->digest.offset_bytes == 0 ?
4668                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4669                         : tdata->digest.offset_bytes),
4670                 tdata->validCipherLenInBits.len,
4671                 tdata->cipher.offset_bits,
4672                 tdata->validAuthLenInBits.len,
4673                 tdata->auth.offset_bits,
4674                 op_mode, 1);
4675
4676         if (retval < 0)
4677                 return retval;
4678
4679         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4680                         ut_params->op);
4681
4682         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4683
4684         ut_params->obuf = (op_mode == IN_PLACE ?
4685                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4686
4687         if (verify) {
4688                 if (ut_params->obuf)
4689                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4690                                         plaintext_len, buffer);
4691                 else
4692                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4693                                         plaintext_len, buffer);
4694
4695                 debug_hexdump(stdout, "plaintext:", plaintext,
4696                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4697                 debug_hexdump(stdout, "plaintext expected:",
4698                         tdata->plaintext.data,
4699                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4700         } else {
4701                 if (ut_params->obuf)
4702                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4703                                         ciphertext_len, buffer);
4704                 else
4705                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4706                                         ciphertext_len, buffer);
4707
4708                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4709                         ciphertext_len);
4710                 debug_hexdump(stdout, "ciphertext expected:",
4711                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4712
4713                 if (ut_params->obuf)
4714                         digest = rte_pktmbuf_read(ut_params->obuf,
4715                                 (tdata->digest.offset_bytes == 0 ?
4716                                 plaintext_pad_len : tdata->digest.offset_bytes),
4717                                 tdata->digest.len, digest_buffer);
4718                 else
4719                         digest = rte_pktmbuf_read(ut_params->ibuf,
4720                                 (tdata->digest.offset_bytes == 0 ?
4721                                 plaintext_pad_len : tdata->digest.offset_bytes),
4722                                 tdata->digest.len, digest_buffer);
4723
4724                 debug_hexdump(stdout, "digest:", digest,
4725                         tdata->digest.len);
4726                 debug_hexdump(stdout, "digest expected:",
4727                         tdata->digest.data, tdata->digest.len);
4728         }
4729
4730         /* Validate obuf */
4731         if (verify) {
4732                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4733                         plaintext,
4734                         tdata->plaintext.data,
4735                         tdata->plaintext.len >> 3,
4736                         "SNOW 3G Plaintext data not as expected");
4737         } else {
4738                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4739                         ciphertext,
4740                         tdata->ciphertext.data,
4741                         tdata->validDataLenInBits.len,
4742                         "SNOW 3G Ciphertext data not as expected");
4743
4744                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4745                         digest,
4746                         tdata->digest.data,
4747                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4748                         "SNOW 3G Generated auth tag not as expected");
4749         }
4750         return 0;
4751 }
4752
4753 static int
4754 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4755         uint8_t op_mode, uint8_t verify)
4756 {
4757         struct crypto_testsuite_params *ts_params = &testsuite_params;
4758         struct crypto_unittest_params *ut_params = &unittest_params;
4759
4760         int retval;
4761
4762         uint8_t *plaintext = NULL, *ciphertext = NULL;
4763         unsigned int plaintext_pad_len;
4764         unsigned int plaintext_len;
4765         unsigned int ciphertext_pad_len;
4766         unsigned int ciphertext_len;
4767
4768         struct rte_cryptodev_info dev_info;
4769
4770         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4771
4772         uint64_t feat_flags = dev_info.feature_flags;
4773
4774         if (op_mode == OUT_OF_PLACE) {
4775                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4776                         printf("Device doesn't support digest encrypted.\n");
4777                         return -ENOTSUP;
4778                 }
4779         }
4780
4781         /* Create KASUMI session */
4782         retval = create_wireless_algo_auth_cipher_session(
4783                         ts_params->valid_devs[0],
4784                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4785                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4786                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4787                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4788                         RTE_CRYPTO_AUTH_KASUMI_F9,
4789                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4790                         tdata->key.data, tdata->key.len,
4791                         0, tdata->digest.len,
4792                         tdata->cipher_iv.len);
4793
4794         if (retval < 0)
4795                 return retval;
4796
4797         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4798         if (op_mode == OUT_OF_PLACE)
4799                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4800
4801         /* clear mbuf payload */
4802         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4803                 rte_pktmbuf_tailroom(ut_params->ibuf));
4804         if (op_mode == OUT_OF_PLACE)
4805                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4806                         rte_pktmbuf_tailroom(ut_params->obuf));
4807
4808         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4809         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4810         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4811         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4812
4813         if (verify) {
4814                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4815                                         ciphertext_pad_len);
4816                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4817                 if (op_mode == OUT_OF_PLACE)
4818                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4819                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4820                         ciphertext_len);
4821         } else {
4822                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4823                                         plaintext_pad_len);
4824                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4825                 if (op_mode == OUT_OF_PLACE)
4826                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4827                 debug_hexdump(stdout, "plaintext:", plaintext,
4828                         plaintext_len);
4829         }
4830
4831         /* Create KASUMI operation */
4832         retval = create_wireless_algo_auth_cipher_operation(
4833                 tdata->digest.len,
4834                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4835                 NULL, 0,
4836                 (tdata->digest.offset_bytes == 0 ?
4837                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4838                         : tdata->digest.offset_bytes),
4839                 tdata->validCipherLenInBits.len,
4840                 tdata->validCipherOffsetInBits.len,
4841                 tdata->validAuthLenInBits.len,
4842                 0,
4843                 op_mode, 0);
4844
4845         if (retval < 0)
4846                 return retval;
4847
4848         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4849                         ut_params->op);
4850
4851         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4852
4853         ut_params->obuf = (op_mode == IN_PLACE ?
4854                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4855
4856
4857         if (verify) {
4858                 if (ut_params->obuf)
4859                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4860                                                         uint8_t *);
4861                 else
4862                         plaintext = ciphertext;
4863
4864                 debug_hexdump(stdout, "plaintext:", plaintext,
4865                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4866                 debug_hexdump(stdout, "plaintext expected:",
4867                         tdata->plaintext.data,
4868                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4869         } else {
4870                 if (ut_params->obuf)
4871                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4872                                                         uint8_t *);
4873                 else
4874                         ciphertext = plaintext;
4875
4876                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4877                         ciphertext_len);
4878                 debug_hexdump(stdout, "ciphertext expected:",
4879                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4880
4881                 ut_params->digest = rte_pktmbuf_mtod(
4882                         ut_params->obuf, uint8_t *) +
4883                         (tdata->digest.offset_bytes == 0 ?
4884                         plaintext_pad_len : tdata->digest.offset_bytes);
4885
4886                 debug_hexdump(stdout, "digest:", ut_params->digest,
4887                         tdata->digest.len);
4888                 debug_hexdump(stdout, "digest expected:",
4889                         tdata->digest.data, tdata->digest.len);
4890         }
4891
4892         /* Validate obuf */
4893         if (verify) {
4894                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4895                         plaintext,
4896                         tdata->plaintext.data,
4897                         tdata->plaintext.len >> 3,
4898                         "KASUMI Plaintext data not as expected");
4899         } else {
4900                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4901                         ciphertext,
4902                         tdata->ciphertext.data,
4903                         tdata->ciphertext.len >> 3,
4904                         "KASUMI Ciphertext data not as expected");
4905
4906                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4907                         ut_params->digest,
4908                         tdata->digest.data,
4909                         DIGEST_BYTE_LENGTH_KASUMI_F9,
4910                         "KASUMI Generated auth tag not as expected");
4911         }
4912         return 0;
4913 }
4914
4915 static int
4916 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
4917         uint8_t op_mode, uint8_t verify)
4918 {
4919         struct crypto_testsuite_params *ts_params = &testsuite_params;
4920         struct crypto_unittest_params *ut_params = &unittest_params;
4921
4922         int retval;
4923
4924         const uint8_t *plaintext = NULL;
4925         const uint8_t *ciphertext = NULL;
4926         const uint8_t *digest = NULL;
4927         unsigned int plaintext_pad_len;
4928         unsigned int plaintext_len;
4929         unsigned int ciphertext_pad_len;
4930         unsigned int ciphertext_len;
4931         uint8_t buffer[10000];
4932         uint8_t digest_buffer[10000];
4933
4934         struct rte_cryptodev_info dev_info;
4935
4936         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4937
4938         uint64_t feat_flags = dev_info.feature_flags;
4939
4940         if (op_mode == IN_PLACE) {
4941                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4942                         printf("Device doesn't support in-place scatter-gather "
4943                                         "in both input and output mbufs.\n");
4944                         return -ENOTSUP;
4945                 }
4946         } else {
4947                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4948                         printf("Device doesn't support out-of-place scatter-gather "
4949                                         "in both input and output mbufs.\n");
4950                         return -ENOTSUP;
4951                 }
4952                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4953                         printf("Device doesn't support digest encrypted.\n");
4954                         return -ENOTSUP;
4955                 }
4956         }
4957
4958         /* Create KASUMI session */
4959         retval = create_wireless_algo_auth_cipher_session(
4960                         ts_params->valid_devs[0],
4961                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4962                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4963                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4964                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4965                         RTE_CRYPTO_AUTH_KASUMI_F9,
4966                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4967                         tdata->key.data, tdata->key.len,
4968                         0, tdata->digest.len,
4969                         tdata->cipher_iv.len);
4970
4971         if (retval < 0)
4972                 return retval;
4973
4974         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4975         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4976         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4977         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4978
4979         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4980                         plaintext_pad_len, 15, 0);
4981         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4982                         "Failed to allocate input buffer in mempool");
4983
4984         if (op_mode == OUT_OF_PLACE) {
4985                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4986                                 plaintext_pad_len, 15, 0);
4987                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4988                                 "Failed to allocate output buffer in mempool");
4989         }
4990
4991         if (verify) {
4992                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4993                         tdata->ciphertext.data);
4994                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4995                                         ciphertext_len, buffer);
4996                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4997                         ciphertext_len);
4998         } else {
4999                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5000                         tdata->plaintext.data);
5001                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5002                                         plaintext_len, buffer);
5003                 debug_hexdump(stdout, "plaintext:", plaintext,
5004                         plaintext_len);
5005         }
5006         memset(buffer, 0, sizeof(buffer));
5007
5008         /* Create KASUMI operation */
5009         retval = create_wireless_algo_auth_cipher_operation(
5010                 tdata->digest.len,
5011                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5012                 NULL, 0,
5013                 (tdata->digest.offset_bytes == 0 ?
5014                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5015                         : tdata->digest.offset_bytes),
5016                 tdata->validCipherLenInBits.len,
5017                 tdata->validCipherOffsetInBits.len,
5018                 tdata->validAuthLenInBits.len,
5019                 0,
5020                 op_mode, 1);
5021
5022         if (retval < 0)
5023                 return retval;
5024
5025         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5026                         ut_params->op);
5027
5028         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5029
5030         ut_params->obuf = (op_mode == IN_PLACE ?
5031                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5032
5033         if (verify) {
5034                 if (ut_params->obuf)
5035                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5036                                         plaintext_len, buffer);
5037                 else
5038                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5039                                         plaintext_len, buffer);
5040
5041                 debug_hexdump(stdout, "plaintext:", plaintext,
5042                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5043                 debug_hexdump(stdout, "plaintext expected:",
5044                         tdata->plaintext.data,
5045                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5046         } else {
5047                 if (ut_params->obuf)
5048                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5049                                         ciphertext_len, buffer);
5050                 else
5051                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5052                                         ciphertext_len, buffer);
5053
5054                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5055                         ciphertext_len);
5056                 debug_hexdump(stdout, "ciphertext expected:",
5057                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5058
5059                 if (ut_params->obuf)
5060                         digest = rte_pktmbuf_read(ut_params->obuf,
5061                                 (tdata->digest.offset_bytes == 0 ?
5062                                 plaintext_pad_len : tdata->digest.offset_bytes),
5063                                 tdata->digest.len, digest_buffer);
5064                 else
5065                         digest = rte_pktmbuf_read(ut_params->ibuf,
5066                                 (tdata->digest.offset_bytes == 0 ?
5067                                 plaintext_pad_len : tdata->digest.offset_bytes),
5068                                 tdata->digest.len, digest_buffer);
5069
5070                 debug_hexdump(stdout, "digest:", digest,
5071                         tdata->digest.len);
5072                 debug_hexdump(stdout, "digest expected:",
5073                         tdata->digest.data, tdata->digest.len);
5074         }
5075
5076         /* Validate obuf */
5077         if (verify) {
5078                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5079                         plaintext,
5080                         tdata->plaintext.data,
5081                         tdata->plaintext.len >> 3,
5082                         "KASUMI Plaintext data not as expected");
5083         } else {
5084                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5085                         ciphertext,
5086                         tdata->ciphertext.data,
5087                         tdata->validDataLenInBits.len,
5088                         "KASUMI Ciphertext data not as expected");
5089
5090                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5091                         digest,
5092                         tdata->digest.data,
5093                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5094                         "KASUMI Generated auth tag not as expected");
5095         }
5096         return 0;
5097 }
5098
5099 static int
5100 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5101 {
5102         struct crypto_testsuite_params *ts_params = &testsuite_params;
5103         struct crypto_unittest_params *ut_params = &unittest_params;
5104
5105         int retval;
5106
5107         uint8_t *plaintext, *ciphertext;
5108         unsigned plaintext_pad_len;
5109         unsigned plaintext_len;
5110
5111         /* Create KASUMI session */
5112         retval = create_wireless_algo_cipher_auth_session(
5113                         ts_params->valid_devs[0],
5114                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5115                         RTE_CRYPTO_AUTH_OP_GENERATE,
5116                         RTE_CRYPTO_AUTH_KASUMI_F9,
5117                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5118                         tdata->key.data, tdata->key.len,
5119                         0, tdata->digest.len,
5120                         tdata->cipher_iv.len);
5121         if (retval < 0)
5122                 return retval;
5123
5124         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5125
5126         /* clear mbuf payload */
5127         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5128                         rte_pktmbuf_tailroom(ut_params->ibuf));
5129
5130         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5131         /* Append data which is padded to a multiple of */
5132         /* the algorithms block size */
5133         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5134         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5135                                 plaintext_pad_len);
5136         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5137
5138         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5139
5140         /* Create KASUMI operation */
5141         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5142                                 tdata->digest.len, NULL, 0,
5143                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5144                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5145                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5146                                 tdata->validCipherOffsetInBits.len,
5147                                 tdata->validAuthLenInBits.len,
5148                                 0
5149                                 );
5150         if (retval < 0)
5151                 return retval;
5152
5153         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5154                         ut_params->op);
5155         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5156
5157         if (ut_params->op->sym->m_dst)
5158                 ut_params->obuf = ut_params->op->sym->m_dst;
5159         else
5160                 ut_params->obuf = ut_params->op->sym->m_src;
5161
5162         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5163                                 tdata->validCipherOffsetInBits.len >> 3);
5164
5165         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5166                         + plaintext_pad_len;
5167
5168         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5169                                 (tdata->validCipherOffsetInBits.len >> 3);
5170         /* Validate obuf */
5171         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5172                 ciphertext,
5173                 reference_ciphertext,
5174                 tdata->validCipherLenInBits.len,
5175                 "KASUMI Ciphertext data not as expected");
5176
5177         /* Validate obuf */
5178         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5179                 ut_params->digest,
5180                 tdata->digest.data,
5181                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5182                 "KASUMI Generated auth tag not as expected");
5183         return 0;
5184 }
5185
5186 static int
5187 test_zuc_encryption(const struct wireless_test_data *tdata)
5188 {
5189         struct crypto_testsuite_params *ts_params = &testsuite_params;
5190         struct crypto_unittest_params *ut_params = &unittest_params;
5191
5192         int retval;
5193         uint8_t *plaintext, *ciphertext;
5194         unsigned plaintext_pad_len;
5195         unsigned plaintext_len;
5196
5197         struct rte_cryptodev_sym_capability_idx cap_idx;
5198
5199         /* Check if device supports ZUC EEA3 */
5200         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5201         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5202
5203         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5204                         &cap_idx) == NULL)
5205                 return -ENOTSUP;
5206
5207         /* Create ZUC session */
5208         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5209                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5210                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5211                                         tdata->key.data, tdata->key.len,
5212                                         tdata->cipher_iv.len);
5213         if (retval < 0)
5214                 return retval;
5215
5216         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5217
5218         /* Clear mbuf payload */
5219         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5220                rte_pktmbuf_tailroom(ut_params->ibuf));
5221
5222         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5223         /* Append data which is padded to a multiple */
5224         /* of the algorithms block size */
5225         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5226         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5227                                 plaintext_pad_len);
5228         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5229
5230         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5231
5232         /* Create ZUC operation */
5233         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5234                                         tdata->cipher_iv.len,
5235                                         tdata->plaintext.len,
5236                                         0);
5237         if (retval < 0)
5238                 return retval;
5239
5240         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5241                                                 ut_params->op);
5242         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5243
5244         ut_params->obuf = ut_params->op->sym->m_dst;
5245         if (ut_params->obuf)
5246                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5247         else
5248                 ciphertext = plaintext;
5249
5250         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5251
5252         /* Validate obuf */
5253         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5254                 ciphertext,
5255                 tdata->ciphertext.data,
5256                 tdata->validCipherLenInBits.len,
5257                 "ZUC Ciphertext data not as expected");
5258         return 0;
5259 }
5260
5261 static int
5262 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5263 {
5264         struct crypto_testsuite_params *ts_params = &testsuite_params;
5265         struct crypto_unittest_params *ut_params = &unittest_params;
5266
5267         int retval;
5268
5269         unsigned int plaintext_pad_len;
5270         unsigned int plaintext_len;
5271         const uint8_t *ciphertext;
5272         uint8_t ciphertext_buffer[2048];
5273         struct rte_cryptodev_info dev_info;
5274
5275         struct rte_cryptodev_sym_capability_idx cap_idx;
5276
5277         /* Check if device supports ZUC EEA3 */
5278         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5279         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5280
5281         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5282                         &cap_idx) == NULL)
5283                 return -ENOTSUP;
5284
5285         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5286
5287         uint64_t feat_flags = dev_info.feature_flags;
5288
5289         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5290                 printf("Device doesn't support in-place scatter-gather. "
5291                                 "Test Skipped.\n");
5292                 return -ENOTSUP;
5293         }
5294
5295         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5296
5297         /* Append data which is padded to a multiple */
5298         /* of the algorithms block size */
5299         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5300
5301         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5302                         plaintext_pad_len, 10, 0);
5303
5304         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5305                         tdata->plaintext.data);
5306
5307         /* Create ZUC session */
5308         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5309                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5310                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5311                         tdata->key.data, tdata->key.len,
5312                         tdata->cipher_iv.len);
5313         if (retval < 0)
5314                 return retval;
5315
5316         /* Clear mbuf payload */
5317
5318         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5319
5320         /* Create ZUC operation */
5321         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5322                         tdata->cipher_iv.len, tdata->plaintext.len,
5323                         0);
5324         if (retval < 0)
5325                 return retval;
5326
5327         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5328                                                 ut_params->op);
5329         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5330
5331         ut_params->obuf = ut_params->op->sym->m_dst;
5332         if (ut_params->obuf)
5333                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5334                         0, plaintext_len, ciphertext_buffer);
5335         else
5336                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5337                         0, plaintext_len, ciphertext_buffer);
5338
5339         /* Validate obuf */
5340         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5341
5342         /* Validate obuf */
5343         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5344                 ciphertext,
5345                 tdata->ciphertext.data,
5346                 tdata->validCipherLenInBits.len,
5347                 "ZUC Ciphertext data not as expected");
5348
5349         return 0;
5350 }
5351
5352 static int
5353 test_zuc_authentication(const struct wireless_test_data *tdata)
5354 {
5355         struct crypto_testsuite_params *ts_params = &testsuite_params;
5356         struct crypto_unittest_params *ut_params = &unittest_params;
5357
5358         int retval;
5359         unsigned plaintext_pad_len;
5360         unsigned plaintext_len;
5361         uint8_t *plaintext;
5362
5363         struct rte_cryptodev_sym_capability_idx cap_idx;
5364
5365         /* Check if device supports ZUC EIA3 */
5366         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5367         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5368
5369         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5370                         &cap_idx) == NULL)
5371                 return -ENOTSUP;
5372
5373         /* Create ZUC session */
5374         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
5375                         tdata->key.data, tdata->key.len,
5376                         tdata->auth_iv.len, tdata->digest.len,
5377                         RTE_CRYPTO_AUTH_OP_GENERATE,
5378                         RTE_CRYPTO_AUTH_ZUC_EIA3);
5379         if (retval < 0)
5380                 return retval;
5381
5382         /* alloc mbuf and set payload */
5383         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5384
5385         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5386         rte_pktmbuf_tailroom(ut_params->ibuf));
5387
5388         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5389         /* Append data which is padded to a multiple of */
5390         /* the algorithms block size */
5391         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5392         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5393                                 plaintext_pad_len);
5394         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5395
5396         /* Create ZUC operation */
5397         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5398                         tdata->auth_iv.data, tdata->auth_iv.len,
5399                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5400                         tdata->validAuthLenInBits.len,
5401                         0);
5402         if (retval < 0)
5403                 return retval;
5404
5405         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5406                                 ut_params->op);
5407         ut_params->obuf = ut_params->op->sym->m_src;
5408         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5409         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5410                         + plaintext_pad_len;
5411
5412         /* Validate obuf */
5413         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5414         ut_params->digest,
5415         tdata->digest.data,
5416         DIGEST_BYTE_LENGTH_KASUMI_F9,
5417         "ZUC Generated auth tag not as expected");
5418
5419         return 0;
5420 }
5421
5422 static int
5423 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5424         uint8_t op_mode, uint8_t verify)
5425 {
5426         struct crypto_testsuite_params *ts_params = &testsuite_params;
5427         struct crypto_unittest_params *ut_params = &unittest_params;
5428
5429         int retval;
5430
5431         uint8_t *plaintext = NULL, *ciphertext = NULL;
5432         unsigned int plaintext_pad_len;
5433         unsigned int plaintext_len;
5434         unsigned int ciphertext_pad_len;
5435         unsigned int ciphertext_len;
5436
5437         struct rte_cryptodev_info dev_info;
5438         struct rte_cryptodev_sym_capability_idx cap_idx;
5439
5440         /* Check if device supports ZUC EIA3 */
5441         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5442         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5443
5444         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5445                         &cap_idx) == NULL)
5446                 return -ENOTSUP;
5447
5448         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5449
5450         uint64_t feat_flags = dev_info.feature_flags;
5451
5452         if (op_mode == OUT_OF_PLACE) {
5453                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5454                         printf("Device doesn't support digest encrypted.\n");
5455                         return -ENOTSUP;
5456                 }
5457         }
5458
5459         /* Create ZUC session */
5460         retval = create_wireless_algo_auth_cipher_session(
5461                         ts_params->valid_devs[0],
5462                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5463                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5464                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5465                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5466                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5467                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5468                         tdata->key.data, tdata->key.len,
5469                         tdata->auth_iv.len, tdata->digest.len,
5470                         tdata->cipher_iv.len);
5471
5472         if (retval < 0)
5473                 return retval;
5474
5475         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5476         if (op_mode == OUT_OF_PLACE)
5477                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5478
5479         /* clear mbuf payload */
5480         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5481                 rte_pktmbuf_tailroom(ut_params->ibuf));
5482         if (op_mode == OUT_OF_PLACE)
5483                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5484                         rte_pktmbuf_tailroom(ut_params->obuf));
5485
5486         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5487         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5488         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5489         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5490
5491         if (verify) {
5492                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5493                                         ciphertext_pad_len);
5494                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5495                 if (op_mode == OUT_OF_PLACE)
5496                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5497                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5498                         ciphertext_len);
5499         } else {
5500                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5501                                         plaintext_pad_len);
5502                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5503                 if (op_mode == OUT_OF_PLACE)
5504                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5505                 debug_hexdump(stdout, "plaintext:", plaintext,
5506                         plaintext_len);
5507         }
5508
5509         /* Create ZUC operation */
5510         retval = create_wireless_algo_auth_cipher_operation(
5511                 tdata->digest.len,
5512                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5513                 tdata->auth_iv.data, tdata->auth_iv.len,
5514                 (tdata->digest.offset_bytes == 0 ?
5515                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5516                         : tdata->digest.offset_bytes),
5517                 tdata->validCipherLenInBits.len,
5518                 tdata->validCipherOffsetInBits.len,
5519                 tdata->validAuthLenInBits.len,
5520                 0,
5521                 op_mode, 0);
5522
5523         if (retval < 0)
5524                 return retval;
5525
5526         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5527                         ut_params->op);
5528
5529         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5530
5531         ut_params->obuf = (op_mode == IN_PLACE ?
5532                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5533
5534
5535         if (verify) {
5536                 if (ut_params->obuf)
5537                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5538                                                         uint8_t *);
5539                 else
5540                         plaintext = ciphertext;
5541
5542                 debug_hexdump(stdout, "plaintext:", plaintext,
5543                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5544                 debug_hexdump(stdout, "plaintext expected:",
5545                         tdata->plaintext.data,
5546                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5547         } else {
5548                 if (ut_params->obuf)
5549                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5550                                                         uint8_t *);
5551                 else
5552                         ciphertext = plaintext;
5553
5554                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5555                         ciphertext_len);
5556                 debug_hexdump(stdout, "ciphertext expected:",
5557                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5558
5559                 ut_params->digest = rte_pktmbuf_mtod(
5560                         ut_params->obuf, uint8_t *) +
5561                         (tdata->digest.offset_bytes == 0 ?
5562                         plaintext_pad_len : tdata->digest.offset_bytes);
5563
5564                 debug_hexdump(stdout, "digest:", ut_params->digest,
5565                         tdata->digest.len);
5566                 debug_hexdump(stdout, "digest expected:",
5567                         tdata->digest.data, tdata->digest.len);
5568         }
5569
5570         /* Validate obuf */
5571         if (verify) {
5572                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5573                         plaintext,
5574                         tdata->plaintext.data,
5575                         tdata->plaintext.len >> 3,
5576                         "ZUC Plaintext data not as expected");
5577         } else {
5578                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5579                         ciphertext,
5580                         tdata->ciphertext.data,
5581                         tdata->ciphertext.len >> 3,
5582                         "ZUC Ciphertext data not as expected");
5583
5584                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5585                         ut_params->digest,
5586                         tdata->digest.data,
5587                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5588                         "ZUC Generated auth tag not as expected");
5589         }
5590         return 0;
5591 }
5592
5593 static int
5594 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5595         uint8_t op_mode, uint8_t verify)
5596 {
5597         struct crypto_testsuite_params *ts_params = &testsuite_params;
5598         struct crypto_unittest_params *ut_params = &unittest_params;
5599
5600         int retval;
5601
5602         const uint8_t *plaintext = NULL;
5603         const uint8_t *ciphertext = NULL;
5604         const uint8_t *digest = NULL;
5605         unsigned int plaintext_pad_len;
5606         unsigned int plaintext_len;
5607         unsigned int ciphertext_pad_len;
5608         unsigned int ciphertext_len;
5609         uint8_t buffer[10000];
5610         uint8_t digest_buffer[10000];
5611
5612         struct rte_cryptodev_info dev_info;
5613         struct rte_cryptodev_sym_capability_idx cap_idx;
5614
5615         /* Check if device supports ZUC EIA3 */
5616         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5617         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5618
5619         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5620                         &cap_idx) == NULL)
5621                 return -ENOTSUP;
5622
5623         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5624
5625         uint64_t feat_flags = dev_info.feature_flags;
5626
5627         if (op_mode == IN_PLACE) {
5628                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5629                         printf("Device doesn't support in-place scatter-gather "
5630                                         "in both input and output mbufs.\n");
5631                         return -ENOTSUP;
5632                 }
5633         } else {
5634                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5635                         printf("Device doesn't support out-of-place scatter-gather "
5636                                         "in both input and output mbufs.\n");
5637                         return -ENOTSUP;
5638                 }
5639                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5640                         printf("Device doesn't support digest encrypted.\n");
5641                         return -ENOTSUP;
5642                 }
5643         }
5644
5645         /* Create ZUC session */
5646         retval = create_wireless_algo_auth_cipher_session(
5647                         ts_params->valid_devs[0],
5648                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5649                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5650                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5651                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5652                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5653                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5654                         tdata->key.data, tdata->key.len,
5655                         tdata->auth_iv.len, tdata->digest.len,
5656                         tdata->cipher_iv.len);
5657
5658         if (retval < 0)
5659                 return retval;
5660
5661         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5662         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5663         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5664         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5665
5666         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5667                         plaintext_pad_len, 15, 0);
5668         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5669                         "Failed to allocate input buffer in mempool");
5670
5671         if (op_mode == OUT_OF_PLACE) {
5672                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5673                                 plaintext_pad_len, 15, 0);
5674                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5675                                 "Failed to allocate output buffer in mempool");
5676         }
5677
5678         if (verify) {
5679                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5680                         tdata->ciphertext.data);
5681                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5682                                         ciphertext_len, buffer);
5683                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5684                         ciphertext_len);
5685         } else {
5686                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5687                         tdata->plaintext.data);
5688                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5689                                         plaintext_len, buffer);
5690                 debug_hexdump(stdout, "plaintext:", plaintext,
5691                         plaintext_len);
5692         }
5693         memset(buffer, 0, sizeof(buffer));
5694
5695         /* Create ZUC operation */
5696         retval = create_wireless_algo_auth_cipher_operation(
5697                 tdata->digest.len,
5698                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5699                 NULL, 0,
5700                 (tdata->digest.offset_bytes == 0 ?
5701                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5702                         : tdata->digest.offset_bytes),
5703                 tdata->validCipherLenInBits.len,
5704                 tdata->validCipherOffsetInBits.len,
5705                 tdata->validAuthLenInBits.len,
5706                 0,
5707                 op_mode, 1);
5708
5709         if (retval < 0)
5710                 return retval;
5711
5712         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5713                         ut_params->op);
5714
5715         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5716
5717         ut_params->obuf = (op_mode == IN_PLACE ?
5718                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5719
5720         if (verify) {
5721                 if (ut_params->obuf)
5722                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5723                                         plaintext_len, buffer);
5724                 else
5725                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5726                                         plaintext_len, buffer);
5727
5728                 debug_hexdump(stdout, "plaintext:", plaintext,
5729                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5730                 debug_hexdump(stdout, "plaintext expected:",
5731                         tdata->plaintext.data,
5732                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5733         } else {
5734                 if (ut_params->obuf)
5735                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5736                                         ciphertext_len, buffer);
5737                 else
5738                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5739                                         ciphertext_len, buffer);
5740
5741                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5742                         ciphertext_len);
5743                 debug_hexdump(stdout, "ciphertext expected:",
5744                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5745
5746                 if (ut_params->obuf)
5747                         digest = rte_pktmbuf_read(ut_params->obuf,
5748                                 (tdata->digest.offset_bytes == 0 ?
5749                                 plaintext_pad_len : tdata->digest.offset_bytes),
5750                                 tdata->digest.len, digest_buffer);
5751                 else
5752                         digest = rte_pktmbuf_read(ut_params->ibuf,
5753                                 (tdata->digest.offset_bytes == 0 ?
5754                                 plaintext_pad_len : tdata->digest.offset_bytes),
5755                                 tdata->digest.len, digest_buffer);
5756
5757                 debug_hexdump(stdout, "digest:", digest,
5758                         tdata->digest.len);
5759                 debug_hexdump(stdout, "digest expected:",
5760                         tdata->digest.data, tdata->digest.len);
5761         }
5762
5763         /* Validate obuf */
5764         if (verify) {
5765                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5766                         plaintext,
5767                         tdata->plaintext.data,
5768                         tdata->plaintext.len >> 3,
5769                         "ZUC Plaintext data not as expected");
5770         } else {
5771                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5772                         ciphertext,
5773                         tdata->ciphertext.data,
5774                         tdata->validDataLenInBits.len,
5775                         "ZUC Ciphertext data not as expected");
5776
5777                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5778                         digest,
5779                         tdata->digest.data,
5780                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5781                         "ZUC Generated auth tag not as expected");
5782         }
5783         return 0;
5784 }
5785
5786 static int
5787 test_kasumi_encryption_test_case_1(void)
5788 {
5789         return test_kasumi_encryption(&kasumi_test_case_1);
5790 }
5791
5792 static int
5793 test_kasumi_encryption_test_case_1_sgl(void)
5794 {
5795         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
5796 }
5797
5798 static int
5799 test_kasumi_encryption_test_case_1_oop(void)
5800 {
5801         return test_kasumi_encryption_oop(&kasumi_test_case_1);
5802 }
5803
5804 static int
5805 test_kasumi_encryption_test_case_1_oop_sgl(void)
5806 {
5807         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
5808 }
5809
5810 static int
5811 test_kasumi_encryption_test_case_2(void)
5812 {
5813         return test_kasumi_encryption(&kasumi_test_case_2);
5814 }
5815
5816 static int
5817 test_kasumi_encryption_test_case_3(void)
5818 {
5819         return test_kasumi_encryption(&kasumi_test_case_3);
5820 }
5821
5822 static int
5823 test_kasumi_encryption_test_case_4(void)
5824 {
5825         return test_kasumi_encryption(&kasumi_test_case_4);
5826 }
5827
5828 static int
5829 test_kasumi_encryption_test_case_5(void)
5830 {
5831         return test_kasumi_encryption(&kasumi_test_case_5);
5832 }
5833
5834 static int
5835 test_kasumi_decryption_test_case_1(void)
5836 {
5837         return test_kasumi_decryption(&kasumi_test_case_1);
5838 }
5839
5840 static int
5841 test_kasumi_decryption_test_case_1_oop(void)
5842 {
5843         return test_kasumi_decryption_oop(&kasumi_test_case_1);
5844 }
5845
5846 static int
5847 test_kasumi_decryption_test_case_2(void)
5848 {
5849         return test_kasumi_decryption(&kasumi_test_case_2);
5850 }
5851
5852 static int
5853 test_kasumi_decryption_test_case_3(void)
5854 {
5855         return test_kasumi_decryption(&kasumi_test_case_3);
5856 }
5857
5858 static int
5859 test_kasumi_decryption_test_case_4(void)
5860 {
5861         return test_kasumi_decryption(&kasumi_test_case_4);
5862 }
5863
5864 static int
5865 test_kasumi_decryption_test_case_5(void)
5866 {
5867         return test_kasumi_decryption(&kasumi_test_case_5);
5868 }
5869 static int
5870 test_snow3g_encryption_test_case_1(void)
5871 {
5872         return test_snow3g_encryption(&snow3g_test_case_1);
5873 }
5874
5875 static int
5876 test_snow3g_encryption_test_case_1_oop(void)
5877 {
5878         return test_snow3g_encryption_oop(&snow3g_test_case_1);
5879 }
5880
5881 static int
5882 test_snow3g_encryption_test_case_1_oop_sgl(void)
5883 {
5884         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
5885 }
5886
5887
5888 static int
5889 test_snow3g_encryption_test_case_1_offset_oop(void)
5890 {
5891         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
5892 }
5893
5894 static int
5895 test_snow3g_encryption_test_case_2(void)
5896 {
5897         return test_snow3g_encryption(&snow3g_test_case_2);
5898 }
5899
5900 static int
5901 test_snow3g_encryption_test_case_3(void)
5902 {
5903         return test_snow3g_encryption(&snow3g_test_case_3);
5904 }
5905
5906 static int
5907 test_snow3g_encryption_test_case_4(void)
5908 {
5909         return test_snow3g_encryption(&snow3g_test_case_4);
5910 }
5911
5912 static int
5913 test_snow3g_encryption_test_case_5(void)
5914 {
5915         return test_snow3g_encryption(&snow3g_test_case_5);
5916 }
5917
5918 static int
5919 test_snow3g_decryption_test_case_1(void)
5920 {
5921         return test_snow3g_decryption(&snow3g_test_case_1);
5922 }
5923
5924 static int
5925 test_snow3g_decryption_test_case_1_oop(void)
5926 {
5927         return test_snow3g_decryption_oop(&snow3g_test_case_1);
5928 }
5929
5930 static int
5931 test_snow3g_decryption_test_case_2(void)
5932 {
5933         return test_snow3g_decryption(&snow3g_test_case_2);
5934 }
5935
5936 static int
5937 test_snow3g_decryption_test_case_3(void)
5938 {
5939         return test_snow3g_decryption(&snow3g_test_case_3);
5940 }
5941
5942 static int
5943 test_snow3g_decryption_test_case_4(void)
5944 {
5945         return test_snow3g_decryption(&snow3g_test_case_4);
5946 }
5947
5948 static int
5949 test_snow3g_decryption_test_case_5(void)
5950 {
5951         return test_snow3g_decryption(&snow3g_test_case_5);
5952 }
5953
5954 /*
5955  * Function prepares snow3g_hash_test_data from snow3g_test_data.
5956  * Pattern digest from snow3g_test_data must be allocated as
5957  * 4 last bytes in plaintext.
5958  */
5959 static void
5960 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
5961                 struct snow3g_hash_test_data *output)
5962 {
5963         if ((pattern != NULL) && (output != NULL)) {
5964                 output->key.len = pattern->key.len;
5965
5966                 memcpy(output->key.data,
5967                 pattern->key.data, pattern->key.len);
5968
5969                 output->auth_iv.len = pattern->auth_iv.len;
5970
5971                 memcpy(output->auth_iv.data,
5972                 pattern->auth_iv.data, pattern->auth_iv.len);
5973
5974                 output->plaintext.len = pattern->plaintext.len;
5975
5976                 memcpy(output->plaintext.data,
5977                 pattern->plaintext.data, pattern->plaintext.len >> 3);
5978
5979                 output->digest.len = pattern->digest.len;
5980
5981                 memcpy(output->digest.data,
5982                 &pattern->plaintext.data[pattern->digest.offset_bytes],
5983                 pattern->digest.len);
5984
5985                 output->validAuthLenInBits.len =
5986                 pattern->validAuthLenInBits.len;
5987         }
5988 }
5989
5990 /*
5991  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
5992  */
5993 static int
5994 test_snow3g_decryption_with_digest_test_case_1(void)
5995 {
5996         struct snow3g_hash_test_data snow3g_hash_data;
5997
5998         /*
5999          * Function prepare data for hash veryfication test case.
6000          * Digest is allocated in 4 last bytes in plaintext, pattern.
6001          */
6002         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6003
6004         return test_snow3g_decryption(&snow3g_test_case_7) &
6005                         test_snow3g_authentication_verify(&snow3g_hash_data);
6006 }
6007
6008 static int
6009 test_snow3g_cipher_auth_test_case_1(void)
6010 {
6011         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6012 }
6013
6014 static int
6015 test_snow3g_auth_cipher_test_case_1(void)
6016 {
6017         return test_snow3g_auth_cipher(
6018                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6019 }
6020
6021 static int
6022 test_snow3g_auth_cipher_test_case_2(void)
6023 {
6024         return test_snow3g_auth_cipher(
6025                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6026 }
6027
6028 static int
6029 test_snow3g_auth_cipher_test_case_2_oop(void)
6030 {
6031         return test_snow3g_auth_cipher(
6032                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6033 }
6034
6035 static int
6036 test_snow3g_auth_cipher_part_digest_enc(void)
6037 {
6038         return test_snow3g_auth_cipher(
6039                 &snow3g_auth_cipher_partial_digest_encryption,
6040                         IN_PLACE, 0);
6041 }
6042
6043 static int
6044 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6045 {
6046         return test_snow3g_auth_cipher(
6047                 &snow3g_auth_cipher_partial_digest_encryption,
6048                         OUT_OF_PLACE, 0);
6049 }
6050
6051 static int
6052 test_snow3g_auth_cipher_test_case_3_sgl(void)
6053 {
6054         return test_snow3g_auth_cipher_sgl(
6055                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6056 }
6057
6058 static int
6059 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6060 {
6061         return test_snow3g_auth_cipher_sgl(
6062                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6063 }
6064
6065 static int
6066 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6067 {
6068         return test_snow3g_auth_cipher_sgl(
6069                 &snow3g_auth_cipher_partial_digest_encryption,
6070                         IN_PLACE, 0);
6071 }
6072
6073 static int
6074 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6075 {
6076         return test_snow3g_auth_cipher_sgl(
6077                 &snow3g_auth_cipher_partial_digest_encryption,
6078                         OUT_OF_PLACE, 0);
6079 }
6080
6081 static int
6082 test_snow3g_auth_cipher_verify_test_case_1(void)
6083 {
6084         return test_snow3g_auth_cipher(
6085                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6086 }
6087
6088 static int
6089 test_snow3g_auth_cipher_verify_test_case_2(void)
6090 {
6091         return test_snow3g_auth_cipher(
6092                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6093 }
6094
6095 static int
6096 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6097 {
6098         return test_snow3g_auth_cipher(
6099                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6100 }
6101
6102 static int
6103 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6104 {
6105         return test_snow3g_auth_cipher(
6106                 &snow3g_auth_cipher_partial_digest_encryption,
6107                         IN_PLACE, 1);
6108 }
6109
6110 static int
6111 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6112 {
6113         return test_snow3g_auth_cipher(
6114                 &snow3g_auth_cipher_partial_digest_encryption,
6115                         OUT_OF_PLACE, 1);
6116 }
6117
6118 static int
6119 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6120 {
6121         return test_snow3g_auth_cipher_sgl(
6122                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6123 }
6124
6125 static int
6126 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6127 {
6128         return test_snow3g_auth_cipher_sgl(
6129                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6130 }
6131
6132 static int
6133 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6134 {
6135         return test_snow3g_auth_cipher_sgl(
6136                 &snow3g_auth_cipher_partial_digest_encryption,
6137                         IN_PLACE, 1);
6138 }
6139
6140 static int
6141 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6142 {
6143         return test_snow3g_auth_cipher_sgl(
6144                 &snow3g_auth_cipher_partial_digest_encryption,
6145                         OUT_OF_PLACE, 1);
6146 }
6147
6148 static int
6149 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6150 {
6151         return test_snow3g_auth_cipher(
6152                 &snow3g_test_case_7, IN_PLACE, 0);
6153 }
6154
6155 static int
6156 test_kasumi_auth_cipher_test_case_1(void)
6157 {
6158         return test_kasumi_auth_cipher(
6159                 &kasumi_test_case_3, IN_PLACE, 0);
6160 }
6161
6162 static int
6163 test_kasumi_auth_cipher_test_case_2(void)
6164 {
6165         return test_kasumi_auth_cipher(
6166                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6167 }
6168
6169 static int
6170 test_kasumi_auth_cipher_test_case_2_oop(void)
6171 {
6172         return test_kasumi_auth_cipher(
6173                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6174 }
6175
6176 static int
6177 test_kasumi_auth_cipher_test_case_2_sgl(void)
6178 {
6179         return test_kasumi_auth_cipher_sgl(
6180                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6181 }
6182
6183 static int
6184 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6185 {
6186         return test_kasumi_auth_cipher_sgl(
6187                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6188 }
6189
6190 static int
6191 test_kasumi_auth_cipher_verify_test_case_1(void)
6192 {
6193         return test_kasumi_auth_cipher(
6194                 &kasumi_test_case_3, IN_PLACE, 1);
6195 }
6196
6197 static int
6198 test_kasumi_auth_cipher_verify_test_case_2(void)
6199 {
6200         return test_kasumi_auth_cipher(
6201                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6202 }
6203
6204 static int
6205 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6206 {
6207         return test_kasumi_auth_cipher(
6208                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6209 }
6210
6211 static int
6212 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6213 {
6214         return test_kasumi_auth_cipher_sgl(
6215                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6216 }
6217
6218 static int
6219 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6220 {
6221         return test_kasumi_auth_cipher_sgl(
6222                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6223 }
6224
6225 static int
6226 test_kasumi_cipher_auth_test_case_1(void)
6227 {
6228         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6229 }
6230
6231 static int
6232 test_zuc_encryption_test_case_1(void)
6233 {
6234         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6235 }
6236
6237 static int
6238 test_zuc_encryption_test_case_2(void)
6239 {
6240         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6241 }
6242
6243 static int
6244 test_zuc_encryption_test_case_3(void)
6245 {
6246         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6247 }
6248
6249 static int
6250 test_zuc_encryption_test_case_4(void)
6251 {
6252         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6253 }
6254
6255 static int
6256 test_zuc_encryption_test_case_5(void)
6257 {
6258         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6259 }
6260
6261 static int
6262 test_zuc_encryption_test_case_6_sgl(void)
6263 {
6264         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6265 }
6266
6267 static int
6268 test_zuc_hash_generate_test_case_1(void)
6269 {
6270         return test_zuc_authentication(&zuc_test_case_auth_1b);
6271 }
6272
6273 static int
6274 test_zuc_hash_generate_test_case_2(void)
6275 {
6276         return test_zuc_authentication(&zuc_test_case_auth_90b);
6277 }
6278
6279 static int
6280 test_zuc_hash_generate_test_case_3(void)
6281 {
6282         return test_zuc_authentication(&zuc_test_case_auth_577b);
6283 }
6284
6285 static int
6286 test_zuc_hash_generate_test_case_4(void)
6287 {
6288         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6289 }
6290
6291 static int
6292 test_zuc_hash_generate_test_case_5(void)
6293 {
6294         return test_zuc_authentication(&zuc_test_auth_5670b);
6295 }
6296
6297 static int
6298 test_zuc_hash_generate_test_case_6(void)
6299 {
6300         return test_zuc_authentication(&zuc_test_case_auth_128b);
6301 }
6302
6303 static int
6304 test_zuc_hash_generate_test_case_7(void)
6305 {
6306         return test_zuc_authentication(&zuc_test_case_auth_2080b);
6307 }
6308
6309 static int
6310 test_zuc_hash_generate_test_case_8(void)
6311 {
6312         return test_zuc_authentication(&zuc_test_case_auth_584b);
6313 }
6314
6315 static int
6316 test_zuc_cipher_auth_test_case_1(void)
6317 {
6318         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
6319 }
6320
6321 static int
6322 test_zuc_cipher_auth_test_case_2(void)
6323 {
6324         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
6325 }
6326
6327 static int
6328 test_zuc_auth_cipher_test_case_1(void)
6329 {
6330         return test_zuc_auth_cipher(
6331                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6332 }
6333
6334 static int
6335 test_zuc_auth_cipher_test_case_1_oop(void)
6336 {
6337         return test_zuc_auth_cipher(
6338                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6339 }
6340
6341 static int
6342 test_zuc_auth_cipher_test_case_1_sgl(void)
6343 {
6344         return test_zuc_auth_cipher_sgl(
6345                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6346 }
6347
6348 static int
6349 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
6350 {
6351         return test_zuc_auth_cipher_sgl(
6352                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6353 }
6354
6355 static int
6356 test_zuc_auth_cipher_verify_test_case_1(void)
6357 {
6358         return test_zuc_auth_cipher(
6359                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6360 }
6361
6362 static int
6363 test_zuc_auth_cipher_verify_test_case_1_oop(void)
6364 {
6365         return test_zuc_auth_cipher(
6366                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6367 }
6368
6369 static int
6370 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6371 {
6372         return test_zuc_auth_cipher_sgl(
6373                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6374 }
6375
6376 static int
6377 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6378 {
6379         return test_zuc_auth_cipher_sgl(
6380                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6381 }
6382
6383 static int
6384 test_3DES_chain_qat_all(void)
6385 {
6386         struct crypto_testsuite_params *ts_params = &testsuite_params;
6387         int status;
6388
6389         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6390                 ts_params->op_mpool,
6391                 ts_params->session_mpool, ts_params->session_priv_mpool,
6392                 ts_params->valid_devs[0],
6393                 rte_cryptodev_driver_id_get(
6394                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
6395                 BLKCIPHER_3DES_CHAIN_TYPE);
6396
6397         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6398
6399         return TEST_SUCCESS;
6400 }
6401
6402 static int
6403 test_DES_cipheronly_qat_all(void)
6404 {
6405         struct crypto_testsuite_params *ts_params = &testsuite_params;
6406         int status;
6407
6408         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6409                 ts_params->op_mpool,
6410                 ts_params->session_mpool, ts_params->session_priv_mpool,
6411                 ts_params->valid_devs[0],
6412                 rte_cryptodev_driver_id_get(
6413                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
6414                 BLKCIPHER_DES_CIPHERONLY_TYPE);
6415
6416         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6417
6418         return TEST_SUCCESS;
6419 }
6420
6421 static int
6422 test_DES_cipheronly_openssl_all(void)
6423 {
6424         struct crypto_testsuite_params *ts_params = &testsuite_params;
6425         int status;
6426
6427         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6428                 ts_params->op_mpool,
6429                 ts_params->session_mpool, ts_params->session_priv_mpool,
6430                 ts_params->valid_devs[0],
6431                 rte_cryptodev_driver_id_get(
6432                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
6433                 BLKCIPHER_DES_CIPHERONLY_TYPE);
6434
6435         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6436
6437         return TEST_SUCCESS;
6438 }
6439
6440 static int
6441 test_DES_docsis_openssl_all(void)
6442 {
6443         struct crypto_testsuite_params *ts_params = &testsuite_params;
6444         int status;
6445
6446         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6447                 ts_params->op_mpool,
6448                 ts_params->session_mpool, ts_params->session_priv_mpool,
6449                 ts_params->valid_devs[0],
6450                 rte_cryptodev_driver_id_get(
6451                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
6452                 BLKCIPHER_DES_DOCSIS_TYPE);
6453
6454         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6455
6456         return TEST_SUCCESS;
6457 }
6458
6459 static int
6460 test_DES_cipheronly_mb_all(void)
6461 {
6462         struct crypto_testsuite_params *ts_params = &testsuite_params;
6463         int status;
6464
6465         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6466                 ts_params->op_mpool,
6467                 ts_params->session_mpool, ts_params->session_priv_mpool,
6468                 ts_params->valid_devs[0],
6469                 rte_cryptodev_driver_id_get(
6470                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
6471                 BLKCIPHER_DES_CIPHERONLY_TYPE);
6472
6473         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6474
6475         return TEST_SUCCESS;
6476 }
6477 static int
6478 test_3DES_cipheronly_mb_all(void)
6479 {
6480         struct crypto_testsuite_params *ts_params = &testsuite_params;
6481         int status;
6482
6483         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6484                 ts_params->op_mpool,
6485                 ts_params->session_mpool, ts_params->session_priv_mpool,
6486                 ts_params->valid_devs[0],
6487                 rte_cryptodev_driver_id_get(
6488                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
6489                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6490
6491         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6492
6493         return TEST_SUCCESS;
6494 }
6495
6496 static int
6497 test_DES_docsis_mb_all(void)
6498 {
6499         struct crypto_testsuite_params *ts_params = &testsuite_params;
6500         int status;
6501
6502         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6503                 ts_params->op_mpool,
6504                 ts_params->session_mpool, ts_params->session_priv_mpool,
6505                 ts_params->valid_devs[0],
6506                 rte_cryptodev_driver_id_get(
6507                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
6508                 BLKCIPHER_DES_DOCSIS_TYPE);
6509
6510         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6511
6512         return TEST_SUCCESS;
6513 }
6514
6515 static int
6516 test_3DES_chain_caam_jr_all(void)
6517 {
6518         struct crypto_testsuite_params *ts_params = &testsuite_params;
6519         int status;
6520
6521         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6522                 ts_params->op_mpool,
6523                 ts_params->session_mpool, ts_params->session_priv_mpool,
6524                 ts_params->valid_devs[0],
6525                 rte_cryptodev_driver_id_get(
6526                 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)),
6527                 BLKCIPHER_3DES_CHAIN_TYPE);
6528
6529         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6530
6531         return TEST_SUCCESS;
6532 }
6533
6534 static int
6535 test_3DES_cipheronly_caam_jr_all(void)
6536 {
6537         struct crypto_testsuite_params *ts_params = &testsuite_params;
6538         int status;
6539
6540         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6541                 ts_params->op_mpool,
6542                 ts_params->session_mpool, ts_params->session_priv_mpool,
6543                 ts_params->valid_devs[0],
6544                 rte_cryptodev_driver_id_get(
6545                 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)),
6546                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6547
6548         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6549
6550         return TEST_SUCCESS;
6551 }
6552
6553 static int
6554 test_3DES_chain_dpaa_sec_all(void)
6555 {
6556         struct crypto_testsuite_params *ts_params = &testsuite_params;
6557         int status;
6558
6559         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6560                 ts_params->op_mpool,
6561                 ts_params->session_mpool, ts_params->session_priv_mpool,
6562                 ts_params->valid_devs[0],
6563                 rte_cryptodev_driver_id_get(
6564                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
6565                 BLKCIPHER_3DES_CHAIN_TYPE);
6566
6567         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6568
6569         return TEST_SUCCESS;
6570 }
6571
6572 static int
6573 test_3DES_cipheronly_dpaa_sec_all(void)
6574 {
6575         struct crypto_testsuite_params *ts_params = &testsuite_params;
6576         int status;
6577
6578         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6579                 ts_params->op_mpool,
6580                 ts_params->session_mpool, ts_params->session_priv_mpool,
6581                 ts_params->valid_devs[0],
6582                 rte_cryptodev_driver_id_get(
6583                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
6584                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6585
6586         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6587
6588         return TEST_SUCCESS;
6589 }
6590
6591 static int
6592 test_3DES_chain_dpaa2_sec_all(void)
6593 {
6594         struct crypto_testsuite_params *ts_params = &testsuite_params;
6595         int status;
6596
6597         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6598                 ts_params->op_mpool,
6599                 ts_params->session_mpool, ts_params->session_priv_mpool,
6600                 ts_params->valid_devs[0],
6601                 rte_cryptodev_driver_id_get(
6602                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
6603                 BLKCIPHER_3DES_CHAIN_TYPE);
6604
6605         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6606
6607         return TEST_SUCCESS;
6608 }
6609
6610 static int
6611 test_3DES_cipheronly_dpaa2_sec_all(void)
6612 {
6613         struct crypto_testsuite_params *ts_params = &testsuite_params;
6614         int status;
6615
6616         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6617                 ts_params->op_mpool,
6618                 ts_params->session_mpool, ts_params->session_priv_mpool,
6619                 ts_params->valid_devs[0],
6620                 rte_cryptodev_driver_id_get(
6621                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
6622                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6623
6624         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6625
6626         return TEST_SUCCESS;
6627 }
6628
6629 static int
6630 test_3DES_chain_ccp_all(void)
6631 {
6632         struct crypto_testsuite_params *ts_params = &testsuite_params;
6633         int status;
6634
6635         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6636                 ts_params->op_mpool,
6637                 ts_params->session_mpool, ts_params->session_priv_mpool,
6638                 ts_params->valid_devs[0],
6639                 rte_cryptodev_driver_id_get(
6640                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
6641                 BLKCIPHER_3DES_CHAIN_TYPE);
6642
6643         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6644
6645         return TEST_SUCCESS;
6646 }
6647
6648 static int
6649 test_3DES_cipheronly_ccp_all(void)
6650 {
6651         struct crypto_testsuite_params *ts_params = &testsuite_params;
6652         int status;
6653
6654         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6655                 ts_params->op_mpool,
6656                 ts_params->session_mpool, ts_params->session_priv_mpool,
6657                 ts_params->valid_devs[0],
6658                 rte_cryptodev_driver_id_get(
6659                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
6660                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6661
6662         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6663
6664         return TEST_SUCCESS;
6665 }
6666
6667 static int
6668 test_3DES_cipheronly_qat_all(void)
6669 {
6670         struct crypto_testsuite_params *ts_params = &testsuite_params;
6671         int status;
6672
6673         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6674                 ts_params->op_mpool,
6675                 ts_params->session_mpool, ts_params->session_priv_mpool,
6676                 ts_params->valid_devs[0],
6677                 rte_cryptodev_driver_id_get(
6678                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
6679                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6680
6681         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6682
6683         return TEST_SUCCESS;
6684 }
6685
6686 static int
6687 test_3DES_chain_openssl_all(void)
6688 {
6689         struct crypto_testsuite_params *ts_params = &testsuite_params;
6690         int status;
6691
6692         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6693                 ts_params->op_mpool,
6694                 ts_params->session_mpool, ts_params->session_priv_mpool,
6695                 ts_params->valid_devs[0],
6696                 rte_cryptodev_driver_id_get(
6697                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
6698                 BLKCIPHER_3DES_CHAIN_TYPE);
6699
6700         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6701
6702         return TEST_SUCCESS;
6703 }
6704
6705 static int
6706 test_3DES_cipheronly_openssl_all(void)
6707 {
6708         struct crypto_testsuite_params *ts_params = &testsuite_params;
6709         int status;
6710
6711         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
6712                 ts_params->op_mpool,
6713                 ts_params->session_mpool, ts_params->session_priv_mpool,
6714                 ts_params->valid_devs[0],
6715                 rte_cryptodev_driver_id_get(
6716                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
6717                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
6718
6719         TEST_ASSERT_EQUAL(status, 0, "Test failed");
6720
6721         return TEST_SUCCESS;
6722 }
6723
6724 /* ***** AEAD algorithm Tests ***** */
6725
6726 static int
6727 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
6728                 enum rte_crypto_aead_operation op,
6729                 const uint8_t *key, const uint8_t key_len,
6730                 const uint16_t aad_len, const uint8_t auth_len,
6731                 uint8_t iv_len)
6732 {
6733         uint8_t aead_key[key_len];
6734
6735         struct crypto_testsuite_params *ts_params = &testsuite_params;
6736         struct crypto_unittest_params *ut_params = &unittest_params;
6737
6738         memcpy(aead_key, key, key_len);
6739
6740         /* Setup AEAD Parameters */
6741         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
6742         ut_params->aead_xform.next = NULL;
6743         ut_params->aead_xform.aead.algo = algo;
6744         ut_params->aead_xform.aead.op = op;
6745         ut_params->aead_xform.aead.key.data = aead_key;
6746         ut_params->aead_xform.aead.key.length = key_len;
6747         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
6748         ut_params->aead_xform.aead.iv.length = iv_len;
6749         ut_params->aead_xform.aead.digest_length = auth_len;
6750         ut_params->aead_xform.aead.aad_length = aad_len;
6751
6752         debug_hexdump(stdout, "key:", key, key_len);
6753
6754         /* Create Crypto session*/
6755         ut_params->sess = rte_cryptodev_sym_session_create(
6756                         ts_params->session_mpool);
6757
6758         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6759                         &ut_params->aead_xform,
6760                         ts_params->session_priv_mpool);
6761
6762         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6763
6764         return 0;
6765 }
6766
6767 static int
6768 create_aead_xform(struct rte_crypto_op *op,
6769                 enum rte_crypto_aead_algorithm algo,
6770                 enum rte_crypto_aead_operation aead_op,
6771                 uint8_t *key, const uint8_t key_len,
6772                 const uint8_t aad_len, const uint8_t auth_len,
6773                 uint8_t iv_len)
6774 {
6775         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
6776                         "failed to allocate space for crypto transform");
6777
6778         struct rte_crypto_sym_op *sym_op = op->sym;
6779
6780         /* Setup AEAD Parameters */
6781         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
6782         sym_op->xform->next = NULL;
6783         sym_op->xform->aead.algo = algo;
6784         sym_op->xform->aead.op = aead_op;
6785         sym_op->xform->aead.key.data = key;
6786         sym_op->xform->aead.key.length = key_len;
6787         sym_op->xform->aead.iv.offset = IV_OFFSET;
6788         sym_op->xform->aead.iv.length = iv_len;
6789         sym_op->xform->aead.digest_length = auth_len;
6790         sym_op->xform->aead.aad_length = aad_len;
6791
6792         debug_hexdump(stdout, "key:", key, key_len);
6793
6794         return 0;
6795 }
6796
6797 static int
6798 create_aead_operation(enum rte_crypto_aead_operation op,
6799                 const struct aead_test_data *tdata)
6800 {
6801         struct crypto_testsuite_params *ts_params = &testsuite_params;
6802         struct crypto_unittest_params *ut_params = &unittest_params;
6803
6804         uint8_t *plaintext, *ciphertext;
6805         unsigned int aad_pad_len, plaintext_pad_len;
6806
6807         /* Generate Crypto op data structure */
6808         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6809                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6810         TEST_ASSERT_NOT_NULL(ut_params->op,
6811                         "Failed to allocate symmetric crypto operation struct");
6812
6813         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6814
6815         /* Append aad data */
6816         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
6817                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
6818                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6819                                 aad_pad_len);
6820                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6821                                 "no room to append aad");
6822
6823                 sym_op->aead.aad.phys_addr =
6824                                 rte_pktmbuf_iova(ut_params->ibuf);
6825                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
6826                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
6827                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6828                         tdata->aad.len);
6829
6830                 /* Append IV at the end of the crypto operation*/
6831                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6832                                 uint8_t *, IV_OFFSET);
6833
6834                 /* Copy IV 1 byte after the IV pointer, according to the API */
6835                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
6836                 debug_hexdump(stdout, "iv:", iv_ptr,
6837                         tdata->iv.len);
6838         } else {
6839                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6840                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6841                                 aad_pad_len);
6842                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6843                                 "no room to append aad");
6844
6845                 sym_op->aead.aad.phys_addr =
6846                                 rte_pktmbuf_iova(ut_params->ibuf);
6847                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
6848                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6849                         tdata->aad.len);
6850
6851                 /* Append IV at the end of the crypto operation*/
6852                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6853                                 uint8_t *, IV_OFFSET);
6854
6855                 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
6856                 debug_hexdump(stdout, "iv:", iv_ptr,
6857                         tdata->iv.len);
6858         }
6859
6860         /* Append plaintext/ciphertext */
6861         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6862                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6863                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6864                                 plaintext_pad_len);
6865                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6866
6867                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6868                 debug_hexdump(stdout, "plaintext:", plaintext,
6869                                 tdata->plaintext.len);
6870
6871                 if (ut_params->obuf) {
6872                         ciphertext = (uint8_t *)rte_pktmbuf_append(
6873                                         ut_params->obuf,
6874                                         plaintext_pad_len + aad_pad_len);
6875                         TEST_ASSERT_NOT_NULL(ciphertext,
6876                                         "no room to append ciphertext");
6877
6878                         memset(ciphertext + aad_pad_len, 0,
6879                                         tdata->ciphertext.len);
6880                 }
6881         } else {
6882                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
6883                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6884                                 plaintext_pad_len);
6885                 TEST_ASSERT_NOT_NULL(ciphertext,
6886                                 "no room to append ciphertext");
6887
6888                 memcpy(ciphertext, tdata->ciphertext.data,
6889                                 tdata->ciphertext.len);
6890                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6891                                 tdata->ciphertext.len);
6892
6893                 if (ut_params->obuf) {
6894                         plaintext = (uint8_t *)rte_pktmbuf_append(
6895                                         ut_params->obuf,
6896                                         plaintext_pad_len + aad_pad_len);
6897                         TEST_ASSERT_NOT_NULL(plaintext,
6898                                         "no room to append plaintext");
6899
6900                         memset(plaintext + aad_pad_len, 0,
6901                                         tdata->plaintext.len);
6902                 }
6903         }
6904
6905         /* Append digest data */
6906         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6907                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6908                                 ut_params->obuf ? ut_params->obuf :
6909                                                 ut_params->ibuf,
6910                                                 tdata->auth_tag.len);
6911                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6912                                 "no room to append digest");
6913                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
6914                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6915                                 ut_params->obuf ? ut_params->obuf :
6916                                                 ut_params->ibuf,
6917                                                 plaintext_pad_len +
6918                                                 aad_pad_len);
6919         } else {
6920                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6921                                 ut_params->ibuf, tdata->auth_tag.len);
6922                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6923                                 "no room to append digest");
6924                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6925                                 ut_params->ibuf,
6926                                 plaintext_pad_len + aad_pad_len);
6927
6928                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
6929                         tdata->auth_tag.len);
6930                 debug_hexdump(stdout, "digest:",
6931                         sym_op->aead.digest.data,
6932                         tdata->auth_tag.len);
6933         }
6934
6935         sym_op->aead.data.length = tdata->plaintext.len;
6936         sym_op->aead.data.offset = aad_pad_len;
6937
6938         return 0;
6939 }
6940
6941 static int
6942 test_authenticated_encryption(const struct aead_test_data *tdata)
6943 {
6944         struct crypto_testsuite_params *ts_params = &testsuite_params;
6945         struct crypto_unittest_params *ut_params = &unittest_params;
6946
6947         int retval;
6948         uint8_t *ciphertext, *auth_tag;
6949         uint16_t plaintext_pad_len;
6950         uint32_t i;
6951
6952         /* Create AEAD session */
6953         retval = create_aead_session(ts_params->valid_devs[0],
6954                         tdata->algo,
6955                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
6956                         tdata->key.data, tdata->key.len,
6957                         tdata->aad.len, tdata->auth_tag.len,
6958                         tdata->iv.len);
6959         if (retval < 0)
6960                 return retval;
6961
6962         if (tdata->aad.len > MBUF_SIZE) {
6963                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6964                 /* Populate full size of add data */
6965                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
6966                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
6967         } else
6968                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6969
6970         /* clear mbuf payload */
6971         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6972                         rte_pktmbuf_tailroom(ut_params->ibuf));
6973
6974         /* Create AEAD operation */
6975         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
6976         if (retval < 0)
6977                 return retval;
6978
6979         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6980
6981         ut_params->op->sym->m_src = ut_params->ibuf;
6982
6983         /* Process crypto operation */
6984         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6985                         ut_params->op), "failed to process sym crypto op");
6986
6987         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6988                         "crypto op processing failed");
6989
6990         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6991
6992         if (ut_params->op->sym->m_dst) {
6993                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
6994                                 uint8_t *);
6995                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6996                                 uint8_t *, plaintext_pad_len);
6997         } else {
6998                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
6999                                 uint8_t *,
7000                                 ut_params->op->sym->cipher.data.offset);
7001                 auth_tag = ciphertext + plaintext_pad_len;
7002         }
7003
7004         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7005         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7006
7007         /* Validate obuf */
7008         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7009                         ciphertext,
7010                         tdata->ciphertext.data,
7011                         tdata->ciphertext.len,
7012                         "Ciphertext data not as expected");
7013
7014         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7015                         auth_tag,
7016                         tdata->auth_tag.data,
7017                         tdata->auth_tag.len,
7018                         "Generated auth tag not as expected");
7019
7020         return 0;
7021
7022 }
7023
7024 static int
7025 test_AES_GCM_authenticated_encryption_test_case_1(void)
7026 {
7027         return test_authenticated_encryption(&gcm_test_case_1);
7028 }
7029
7030 static int
7031 test_AES_GCM_authenticated_encryption_test_case_2(void)
7032 {
7033         return test_authenticated_encryption(&gcm_test_case_2);
7034 }
7035
7036 static int
7037 test_AES_GCM_authenticated_encryption_test_case_3(void)
7038 {
7039         return test_authenticated_encryption(&gcm_test_case_3);
7040 }
7041
7042 static int
7043 test_AES_GCM_authenticated_encryption_test_case_4(void)
7044 {
7045         return test_authenticated_encryption(&gcm_test_case_4);
7046 }
7047
7048 static int
7049 test_AES_GCM_authenticated_encryption_test_case_5(void)
7050 {
7051         return test_authenticated_encryption(&gcm_test_case_5);
7052 }
7053
7054 static int
7055 test_AES_GCM_authenticated_encryption_test_case_6(void)
7056 {
7057         return test_authenticated_encryption(&gcm_test_case_6);
7058 }
7059
7060 static int
7061 test_AES_GCM_authenticated_encryption_test_case_7(void)
7062 {
7063         return test_authenticated_encryption(&gcm_test_case_7);
7064 }
7065
7066 static int
7067 test_AES_GCM_auth_encryption_test_case_192_1(void)
7068 {
7069         return test_authenticated_encryption(&gcm_test_case_192_1);
7070 }
7071
7072 static int
7073 test_AES_GCM_auth_encryption_test_case_192_2(void)
7074 {
7075         return test_authenticated_encryption(&gcm_test_case_192_2);
7076 }
7077
7078 static int
7079 test_AES_GCM_auth_encryption_test_case_192_3(void)
7080 {
7081         return test_authenticated_encryption(&gcm_test_case_192_3);
7082 }
7083
7084 static int
7085 test_AES_GCM_auth_encryption_test_case_192_4(void)
7086 {
7087         return test_authenticated_encryption(&gcm_test_case_192_4);
7088 }
7089
7090 static int
7091 test_AES_GCM_auth_encryption_test_case_192_5(void)
7092 {
7093         return test_authenticated_encryption(&gcm_test_case_192_5);
7094 }
7095
7096 static int
7097 test_AES_GCM_auth_encryption_test_case_192_6(void)
7098 {
7099         return test_authenticated_encryption(&gcm_test_case_192_6);
7100 }
7101
7102 static int
7103 test_AES_GCM_auth_encryption_test_case_192_7(void)
7104 {
7105         return test_authenticated_encryption(&gcm_test_case_192_7);
7106 }
7107
7108 static int
7109 test_AES_GCM_auth_encryption_test_case_256_1(void)
7110 {
7111         return test_authenticated_encryption(&gcm_test_case_256_1);
7112 }
7113
7114 static int
7115 test_AES_GCM_auth_encryption_test_case_256_2(void)
7116 {
7117         return test_authenticated_encryption(&gcm_test_case_256_2);
7118 }
7119
7120 static int
7121 test_AES_GCM_auth_encryption_test_case_256_3(void)
7122 {
7123         return test_authenticated_encryption(&gcm_test_case_256_3);
7124 }
7125
7126 static int
7127 test_AES_GCM_auth_encryption_test_case_256_4(void)
7128 {
7129         return test_authenticated_encryption(&gcm_test_case_256_4);
7130 }
7131
7132 static int
7133 test_AES_GCM_auth_encryption_test_case_256_5(void)
7134 {
7135         return test_authenticated_encryption(&gcm_test_case_256_5);
7136 }
7137
7138 static int
7139 test_AES_GCM_auth_encryption_test_case_256_6(void)
7140 {
7141         return test_authenticated_encryption(&gcm_test_case_256_6);
7142 }
7143
7144 static int
7145 test_AES_GCM_auth_encryption_test_case_256_7(void)
7146 {
7147         return test_authenticated_encryption(&gcm_test_case_256_7);
7148 }
7149
7150 static int
7151 test_AES_GCM_auth_encryption_test_case_aad_1(void)
7152 {
7153         return test_authenticated_encryption(&gcm_test_case_aad_1);
7154 }
7155
7156 static int
7157 test_AES_GCM_auth_encryption_test_case_aad_2(void)
7158 {
7159         return test_authenticated_encryption(&gcm_test_case_aad_2);
7160 }
7161
7162 static int
7163 test_authenticated_decryption(const struct aead_test_data *tdata)
7164 {
7165         struct crypto_testsuite_params *ts_params = &testsuite_params;
7166         struct crypto_unittest_params *ut_params = &unittest_params;
7167
7168         int retval;
7169         uint8_t *plaintext;
7170         uint32_t i;
7171
7172         /* Create AEAD session */
7173         retval = create_aead_session(ts_params->valid_devs[0],
7174                         tdata->algo,
7175                         RTE_CRYPTO_AEAD_OP_DECRYPT,
7176                         tdata->key.data, tdata->key.len,
7177                         tdata->aad.len, tdata->auth_tag.len,
7178                         tdata->iv.len);
7179         if (retval < 0)
7180                 return retval;
7181
7182         /* alloc mbuf and set payload */
7183         if (tdata->aad.len > MBUF_SIZE) {
7184                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7185                 /* Populate full size of add data */
7186                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7187                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7188         } else
7189                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7190
7191         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7192                         rte_pktmbuf_tailroom(ut_params->ibuf));
7193
7194         /* Create AEAD operation */
7195         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
7196         if (retval < 0)
7197                 return retval;
7198
7199         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7200
7201         ut_params->op->sym->m_src = ut_params->ibuf;
7202
7203         /* Process crypto operation */
7204         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7205                         ut_params->op), "failed to process sym crypto op");
7206
7207         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7208                         "crypto op processing failed");
7209
7210         if (ut_params->op->sym->m_dst)
7211                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7212                                 uint8_t *);
7213         else
7214                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7215                                 uint8_t *,
7216                                 ut_params->op->sym->cipher.data.offset);
7217
7218         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
7219
7220         /* Validate obuf */
7221         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7222                         plaintext,
7223                         tdata->plaintext.data,
7224                         tdata->plaintext.len,
7225                         "Plaintext data not as expected");
7226
7227         TEST_ASSERT_EQUAL(ut_params->op->status,
7228                         RTE_CRYPTO_OP_STATUS_SUCCESS,
7229                         "Authentication failed");
7230         return 0;
7231 }
7232
7233 static int
7234 test_AES_GCM_authenticated_decryption_test_case_1(void)
7235 {
7236         return test_authenticated_decryption(&gcm_test_case_1);
7237 }
7238
7239 static int
7240 test_AES_GCM_authenticated_decryption_test_case_2(void)
7241 {
7242         return test_authenticated_decryption(&gcm_test_case_2);
7243 }
7244
7245 static int
7246 test_AES_GCM_authenticated_decryption_test_case_3(void)
7247 {
7248         return test_authenticated_decryption(&gcm_test_case_3);
7249 }
7250
7251 static int
7252 test_AES_GCM_authenticated_decryption_test_case_4(void)
7253 {
7254         return test_authenticated_decryption(&gcm_test_case_4);
7255 }
7256
7257 static int
7258 test_AES_GCM_authenticated_decryption_test_case_5(void)
7259 {
7260         return test_authenticated_decryption(&gcm_test_case_5);
7261 }
7262
7263 static int
7264 test_AES_GCM_authenticated_decryption_test_case_6(void)
7265 {
7266         return test_authenticated_decryption(&gcm_test_case_6);
7267 }
7268
7269 static int
7270 test_AES_GCM_authenticated_decryption_test_case_7(void)
7271 {
7272         return test_authenticated_decryption(&gcm_test_case_7);
7273 }
7274
7275 static int
7276 test_AES_GCM_auth_decryption_test_case_192_1(void)
7277 {
7278         return test_authenticated_decryption(&gcm_test_case_192_1);
7279 }
7280
7281 static int
7282 test_AES_GCM_auth_decryption_test_case_192_2(void)
7283 {
7284         return test_authenticated_decryption(&gcm_test_case_192_2);
7285 }
7286
7287 static int
7288 test_AES_GCM_auth_decryption_test_case_192_3(void)
7289 {
7290         return test_authenticated_decryption(&gcm_test_case_192_3);
7291 }
7292
7293 static int
7294 test_AES_GCM_auth_decryption_test_case_192_4(void)
7295 {
7296         return test_authenticated_decryption(&gcm_test_case_192_4);
7297 }
7298
7299 static int
7300 test_AES_GCM_auth_decryption_test_case_192_5(void)
7301 {
7302         return test_authenticated_decryption(&gcm_test_case_192_5);
7303 }
7304
7305 static int
7306 test_AES_GCM_auth_decryption_test_case_192_6(void)
7307 {
7308         return test_authenticated_decryption(&gcm_test_case_192_6);
7309 }
7310
7311 static int
7312 test_AES_GCM_auth_decryption_test_case_192_7(void)
7313 {
7314         return test_authenticated_decryption(&gcm_test_case_192_7);
7315 }
7316
7317 static int
7318 test_AES_GCM_auth_decryption_test_case_256_1(void)
7319 {
7320         return test_authenticated_decryption(&gcm_test_case_256_1);
7321 }
7322
7323 static int
7324 test_AES_GCM_auth_decryption_test_case_256_2(void)
7325 {
7326         return test_authenticated_decryption(&gcm_test_case_256_2);
7327 }
7328
7329 static int
7330 test_AES_GCM_auth_decryption_test_case_256_3(void)
7331 {
7332         return test_authenticated_decryption(&gcm_test_case_256_3);
7333 }
7334
7335 static int
7336 test_AES_GCM_auth_decryption_test_case_256_4(void)
7337 {
7338         return test_authenticated_decryption(&gcm_test_case_256_4);
7339 }
7340
7341 static int
7342 test_AES_GCM_auth_decryption_test_case_256_5(void)
7343 {
7344         return test_authenticated_decryption(&gcm_test_case_256_5);
7345 }
7346
7347 static int
7348 test_AES_GCM_auth_decryption_test_case_256_6(void)
7349 {
7350         return test_authenticated_decryption(&gcm_test_case_256_6);
7351 }
7352
7353 static int
7354 test_AES_GCM_auth_decryption_test_case_256_7(void)
7355 {
7356         return test_authenticated_decryption(&gcm_test_case_256_7);
7357 }
7358
7359 static int
7360 test_AES_GCM_auth_decryption_test_case_aad_1(void)
7361 {
7362         return test_authenticated_decryption(&gcm_test_case_aad_1);
7363 }
7364
7365 static int
7366 test_AES_GCM_auth_decryption_test_case_aad_2(void)
7367 {
7368         return test_authenticated_decryption(&gcm_test_case_aad_2);
7369 }
7370
7371 static int
7372 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
7373 {
7374         struct crypto_testsuite_params *ts_params = &testsuite_params;
7375         struct crypto_unittest_params *ut_params = &unittest_params;
7376
7377         int retval;
7378         uint8_t *ciphertext, *auth_tag;
7379         uint16_t plaintext_pad_len;
7380
7381         /* Create AEAD session */
7382         retval = create_aead_session(ts_params->valid_devs[0],
7383                         tdata->algo,
7384                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7385                         tdata->key.data, tdata->key.len,
7386                         tdata->aad.len, tdata->auth_tag.len,
7387                         tdata->iv.len);
7388         if (retval < 0)
7389                 return retval;
7390
7391         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7392         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7393
7394         /* clear mbuf payload */
7395         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7396                         rte_pktmbuf_tailroom(ut_params->ibuf));
7397         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7398                         rte_pktmbuf_tailroom(ut_params->obuf));
7399
7400         /* Create AEAD operation */
7401         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7402         if (retval < 0)
7403                 return retval;
7404
7405         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7406
7407         ut_params->op->sym->m_src = ut_params->ibuf;
7408         ut_params->op->sym->m_dst = ut_params->obuf;
7409
7410         /* Process crypto operation */
7411         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7412                         ut_params->op), "failed to process sym crypto op");
7413
7414         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7415                         "crypto op processing failed");
7416
7417         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7418
7419         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
7420                         ut_params->op->sym->cipher.data.offset);
7421         auth_tag = ciphertext + plaintext_pad_len;
7422
7423         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7424         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7425
7426         /* Validate obuf */
7427         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7428                         ciphertext,
7429                         tdata->ciphertext.data,
7430                         tdata->ciphertext.len,
7431                         "Ciphertext data not as expected");
7432
7433         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7434                         auth_tag,
7435                         tdata->auth_tag.data,
7436                         tdata->auth_tag.len,
7437                         "Generated auth tag not as expected");
7438
7439         return 0;
7440
7441 }
7442
7443 static int
7444 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
7445 {
7446         return test_authenticated_encryption_oop(&gcm_test_case_5);
7447 }
7448
7449 static int
7450 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
7451 {
7452         struct crypto_testsuite_params *ts_params = &testsuite_params;
7453         struct crypto_unittest_params *ut_params = &unittest_params;
7454
7455         int retval;
7456         uint8_t *plaintext;
7457
7458         /* Create AEAD session */
7459         retval = create_aead_session(ts_params->valid_devs[0],
7460                         tdata->algo,
7461                         RTE_CRYPTO_AEAD_OP_DECRYPT,
7462                         tdata->key.data, tdata->key.len,
7463                         tdata->aad.len, tdata->auth_tag.len,
7464                         tdata->iv.len);
7465         if (retval < 0)
7466                 return retval;
7467
7468         /* alloc mbuf and set payload */
7469         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7470         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7471
7472         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7473                         rte_pktmbuf_tailroom(ut_params->ibuf));
7474         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7475                         rte_pktmbuf_tailroom(ut_params->obuf));
7476
7477         /* Create AEAD operation */
7478         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
7479         if (retval < 0)
7480                 return retval;
7481
7482         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7483
7484         ut_params->op->sym->m_src = ut_params->ibuf;
7485         ut_params->op->sym->m_dst = ut_params->obuf;
7486
7487         /* Process crypto operation */
7488         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7489                         ut_params->op), "failed to process sym crypto op");
7490
7491         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7492                         "crypto op processing failed");
7493
7494         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
7495                         ut_params->op->sym->cipher.data.offset);
7496
7497         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
7498
7499         /* Validate obuf */
7500         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7501                         plaintext,
7502                         tdata->plaintext.data,
7503                         tdata->plaintext.len,
7504                         "Plaintext data not as expected");
7505
7506         TEST_ASSERT_EQUAL(ut_params->op->status,
7507                         RTE_CRYPTO_OP_STATUS_SUCCESS,
7508                         "Authentication failed");
7509         return 0;
7510 }
7511
7512 static int
7513 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
7514 {
7515         return test_authenticated_decryption_oop(&gcm_test_case_5);
7516 }
7517
7518 static int
7519 test_authenticated_encryption_sessionless(
7520                 const struct aead_test_data *tdata)
7521 {
7522         struct crypto_testsuite_params *ts_params = &testsuite_params;
7523         struct crypto_unittest_params *ut_params = &unittest_params;
7524
7525         int retval;
7526         uint8_t *ciphertext, *auth_tag;
7527         uint16_t plaintext_pad_len;
7528         uint8_t key[tdata->key.len + 1];
7529
7530         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7531
7532         /* clear mbuf payload */
7533         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7534                         rte_pktmbuf_tailroom(ut_params->ibuf));
7535
7536         /* Create AEAD operation */
7537         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7538         if (retval < 0)
7539                 return retval;
7540
7541         /* Create GCM xform */
7542         memcpy(key, tdata->key.data, tdata->key.len);
7543         retval = create_aead_xform(ut_params->op,
7544                         tdata->algo,
7545                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7546                         key, tdata->key.len,
7547                         tdata->aad.len, tdata->auth_tag.len,
7548                         tdata->iv.len);
7549         if (retval < 0)
7550                 return retval;
7551
7552         ut_params->op->sym->m_src = ut_params->ibuf;
7553
7554         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
7555                         RTE_CRYPTO_OP_SESSIONLESS,
7556                         "crypto op session type not sessionless");
7557
7558         /* Process crypto operation */
7559         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7560                         ut_params->op), "failed to process sym crypto op");
7561
7562         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7563
7564         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7565                         "crypto op status not success");
7566
7567         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7568
7569         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
7570                         ut_params->op->sym->cipher.data.offset);
7571         auth_tag = ciphertext + plaintext_pad_len;
7572
7573         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7574         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7575
7576         /* Validate obuf */
7577         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7578                         ciphertext,
7579                         tdata->ciphertext.data,
7580                         tdata->ciphertext.len,
7581                         "Ciphertext data not as expected");
7582
7583         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7584                         auth_tag,
7585                         tdata->auth_tag.data,
7586                         tdata->auth_tag.len,
7587                         "Generated auth tag not as expected");
7588
7589         return 0;
7590
7591 }
7592
7593 static int
7594 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
7595 {
7596         return test_authenticated_encryption_sessionless(
7597                         &gcm_test_case_5);
7598 }
7599
7600 static int
7601 test_authenticated_decryption_sessionless(
7602                 const struct aead_test_data *tdata)
7603 {
7604         struct crypto_testsuite_params *ts_params = &testsuite_params;
7605         struct crypto_unittest_params *ut_params = &unittest_params;
7606
7607         int retval;
7608         uint8_t *plaintext;
7609         uint8_t key[tdata->key.len + 1];
7610
7611         /* alloc mbuf and set payload */
7612         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7613
7614         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7615                         rte_pktmbuf_tailroom(ut_params->ibuf));
7616
7617         /* Create AEAD operation */
7618         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
7619         if (retval < 0)
7620                 return retval;
7621
7622         /* Create AEAD xform */
7623         memcpy(key, tdata->key.data, tdata->key.len);
7624         retval = create_aead_xform(ut_params->op,
7625                         tdata->algo,
7626                         RTE_CRYPTO_AEAD_OP_DECRYPT,
7627                         key, tdata->key.len,
7628                         tdata->aad.len, tdata->auth_tag.len,
7629                         tdata->iv.len);
7630         if (retval < 0)
7631                 return retval;
7632
7633         ut_params->op->sym->m_src = ut_params->ibuf;
7634
7635         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
7636                         RTE_CRYPTO_OP_SESSIONLESS,
7637                         "crypto op session type not sessionless");
7638
7639         /* Process crypto operation */
7640         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7641                         ut_params->op), "failed to process sym crypto op");
7642
7643         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7644
7645         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7646                         "crypto op status not success");
7647
7648         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
7649                         ut_params->op->sym->cipher.data.offset);
7650
7651         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
7652
7653         /* Validate obuf */
7654         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7655                         plaintext,
7656                         tdata->plaintext.data,
7657                         tdata->plaintext.len,
7658                         "Plaintext data not as expected");
7659
7660         TEST_ASSERT_EQUAL(ut_params->op->status,
7661                         RTE_CRYPTO_OP_STATUS_SUCCESS,
7662                         "Authentication failed");
7663         return 0;
7664 }
7665
7666 static int
7667 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
7668 {
7669         return test_authenticated_decryption_sessionless(
7670                         &gcm_test_case_5);
7671 }
7672
7673 static int
7674 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
7675 {
7676         return test_authenticated_encryption(&ccm_test_case_128_1);
7677 }
7678
7679 static int
7680 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
7681 {
7682         return test_authenticated_encryption(&ccm_test_case_128_2);
7683 }
7684
7685 static int
7686 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
7687 {
7688         return test_authenticated_encryption(&ccm_test_case_128_3);
7689 }
7690
7691 static int
7692 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
7693 {
7694         return test_authenticated_decryption(&ccm_test_case_128_1);
7695 }
7696
7697 static int
7698 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
7699 {
7700         return test_authenticated_decryption(&ccm_test_case_128_2);
7701 }
7702
7703 static int
7704 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
7705 {
7706         return test_authenticated_decryption(&ccm_test_case_128_3);
7707 }
7708
7709 static int
7710 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
7711 {
7712         return test_authenticated_encryption(&ccm_test_case_192_1);
7713 }
7714
7715 static int
7716 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
7717 {
7718         return test_authenticated_encryption(&ccm_test_case_192_2);
7719 }
7720
7721 static int
7722 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
7723 {
7724         return test_authenticated_encryption(&ccm_test_case_192_3);
7725 }
7726
7727 static int
7728 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
7729 {
7730         return test_authenticated_decryption(&ccm_test_case_192_1);
7731 }
7732
7733 static int
7734 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
7735 {
7736         return test_authenticated_decryption(&ccm_test_case_192_2);
7737 }
7738
7739 static int
7740 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
7741 {
7742         return test_authenticated_decryption(&ccm_test_case_192_3);
7743 }
7744
7745 static int
7746 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
7747 {
7748         return test_authenticated_encryption(&ccm_test_case_256_1);
7749 }
7750
7751 static int
7752 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
7753 {
7754         return test_authenticated_encryption(&ccm_test_case_256_2);
7755 }
7756
7757 static int
7758 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
7759 {
7760         return test_authenticated_encryption(&ccm_test_case_256_3);
7761 }
7762
7763 static int
7764 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
7765 {
7766         return test_authenticated_decryption(&ccm_test_case_256_1);
7767 }
7768
7769 static int
7770 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
7771 {
7772         return test_authenticated_decryption(&ccm_test_case_256_2);
7773 }
7774
7775 static int
7776 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
7777 {
7778         return test_authenticated_decryption(&ccm_test_case_256_3);
7779 }
7780
7781 static int
7782 test_stats(void)
7783 {
7784         struct crypto_testsuite_params *ts_params = &testsuite_params;
7785         struct rte_cryptodev_stats stats;
7786         struct rte_cryptodev *dev;
7787         cryptodev_stats_get_t temp_pfn;
7788
7789         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
7790         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
7791                         &stats) == -ENODEV),
7792                 "rte_cryptodev_stats_get invalid dev failed");
7793         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
7794                 "rte_cryptodev_stats_get invalid Param failed");
7795         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
7796         temp_pfn = dev->dev_ops->stats_get;
7797         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
7798         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
7799                         == -ENOTSUP),
7800                 "rte_cryptodev_stats_get invalid Param failed");
7801         dev->dev_ops->stats_get = temp_pfn;
7802
7803         /* Test expected values */
7804         ut_setup();
7805         test_AES_CBC_HMAC_SHA1_encrypt_digest();
7806         ut_teardown();
7807         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
7808                         &stats),
7809                 "rte_cryptodev_stats_get failed");
7810         TEST_ASSERT((stats.enqueued_count == 1),
7811                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7812         TEST_ASSERT((stats.dequeued_count == 1),
7813                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7814         TEST_ASSERT((stats.enqueue_err_count == 0),
7815                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7816         TEST_ASSERT((stats.dequeue_err_count == 0),
7817                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7818
7819         /* invalid device but should ignore and not reset device stats*/
7820         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
7821         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
7822                         &stats),
7823                 "rte_cryptodev_stats_get failed");
7824         TEST_ASSERT((stats.enqueued_count == 1),
7825                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7826
7827         /* check that a valid reset clears stats */
7828         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
7829         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
7830                         &stats),
7831                                           "rte_cryptodev_stats_get failed");
7832         TEST_ASSERT((stats.enqueued_count == 0),
7833                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7834         TEST_ASSERT((stats.dequeued_count == 0),
7835                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
7836
7837         return TEST_SUCCESS;
7838 }
7839
7840 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
7841                                    struct crypto_unittest_params *ut_params,
7842                                    enum rte_crypto_auth_operation op,
7843                                    const struct HMAC_MD5_vector *test_case)
7844 {
7845         uint8_t key[64];
7846
7847         memcpy(key, test_case->key.data, test_case->key.len);
7848
7849         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7850         ut_params->auth_xform.next = NULL;
7851         ut_params->auth_xform.auth.op = op;
7852
7853         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
7854
7855         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
7856         ut_params->auth_xform.auth.key.length = test_case->key.len;
7857         ut_params->auth_xform.auth.key.data = key;
7858
7859         ut_params->sess = rte_cryptodev_sym_session_create(
7860                         ts_params->session_mpool);
7861
7862         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7863                         ut_params->sess, &ut_params->auth_xform,
7864                         ts_params->session_priv_mpool);
7865
7866         if (ut_params->sess == NULL)
7867                 return TEST_FAILED;
7868
7869         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7870
7871         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7872                         rte_pktmbuf_tailroom(ut_params->ibuf));
7873
7874         return 0;
7875 }
7876
7877 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
7878                               const struct HMAC_MD5_vector *test_case,
7879                               uint8_t **plaintext)
7880 {
7881         uint16_t plaintext_pad_len;
7882
7883         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7884
7885         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
7886                                 16);
7887
7888         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7889                         plaintext_pad_len);
7890         memcpy(*plaintext, test_case->plaintext.data,
7891                         test_case->plaintext.len);
7892
7893         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7894                         ut_params->ibuf, MD5_DIGEST_LEN);
7895         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7896                         "no room to append digest");
7897         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7898                         ut_params->ibuf, plaintext_pad_len);
7899
7900         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
7901                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
7902                            test_case->auth_tag.len);
7903         }
7904
7905         sym_op->auth.data.offset = 0;
7906         sym_op->auth.data.length = test_case->plaintext.len;
7907
7908         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7909         ut_params->op->sym->m_src = ut_params->ibuf;
7910
7911         return 0;
7912 }
7913
7914 static int
7915 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
7916 {
7917         uint16_t plaintext_pad_len;
7918         uint8_t *plaintext, *auth_tag;
7919
7920         struct crypto_testsuite_params *ts_params = &testsuite_params;
7921         struct crypto_unittest_params *ut_params = &unittest_params;
7922
7923         if (MD5_HMAC_create_session(ts_params, ut_params,
7924                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
7925                 return TEST_FAILED;
7926
7927         /* Generate Crypto op data structure */
7928         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7929                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7930         TEST_ASSERT_NOT_NULL(ut_params->op,
7931                         "Failed to allocate symmetric crypto operation struct");
7932
7933         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
7934                                 16);
7935
7936         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
7937                 return TEST_FAILED;
7938
7939         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7940                         ut_params->op), "failed to process sym crypto op");
7941
7942         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7943                         "crypto op processing failed");
7944
7945         if (ut_params->op->sym->m_dst) {
7946                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7947                                 uint8_t *, plaintext_pad_len);
7948         } else {
7949                 auth_tag = plaintext + plaintext_pad_len;
7950         }
7951
7952         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7953                         auth_tag,
7954                         test_case->auth_tag.data,
7955                         test_case->auth_tag.len,
7956                         "HMAC_MD5 generated tag not as expected");
7957
7958         return TEST_SUCCESS;
7959 }
7960
7961 static int
7962 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
7963 {
7964         uint8_t *plaintext;
7965
7966         struct crypto_testsuite_params *ts_params = &testsuite_params;
7967         struct crypto_unittest_params *ut_params = &unittest_params;
7968
7969         if (MD5_HMAC_create_session(ts_params, ut_params,
7970                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
7971                 return TEST_FAILED;
7972         }
7973
7974         /* Generate Crypto op data structure */
7975         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7976                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7977         TEST_ASSERT_NOT_NULL(ut_params->op,
7978                         "Failed to allocate symmetric crypto operation struct");
7979
7980         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
7981                 return TEST_FAILED;
7982
7983         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7984                         ut_params->op), "failed to process sym crypto op");
7985
7986         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7987                         "HMAC_MD5 crypto op processing failed");
7988
7989         return TEST_SUCCESS;
7990 }
7991
7992 static int
7993 test_MD5_HMAC_generate_case_1(void)
7994 {
7995         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
7996 }
7997
7998 static int
7999 test_MD5_HMAC_verify_case_1(void)
8000 {
8001         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
8002 }
8003
8004 static int
8005 test_MD5_HMAC_generate_case_2(void)
8006 {
8007         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
8008 }
8009
8010 static int
8011 test_MD5_HMAC_verify_case_2(void)
8012 {
8013         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
8014 }
8015
8016 static int
8017 test_multi_session(void)
8018 {
8019         struct crypto_testsuite_params *ts_params = &testsuite_params;
8020         struct crypto_unittest_params *ut_params = &unittest_params;
8021
8022         struct rte_cryptodev_info dev_info;
8023         struct rte_cryptodev_sym_session **sessions;
8024
8025         uint16_t i;
8026
8027         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
8028                         aes_cbc_key, hmac_sha512_key);
8029
8030
8031         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8032
8033         sessions = rte_malloc(NULL,
8034                         (sizeof(struct rte_cryptodev_sym_session *) *
8035                         MAX_NB_SESSIONS) + 1, 0);
8036
8037         /* Create multiple crypto sessions*/
8038         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8039
8040                 sessions[i] = rte_cryptodev_sym_session_create(
8041                                 ts_params->session_mpool);
8042
8043                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8044                                 sessions[i], &ut_params->auth_xform,
8045                                 ts_params->session_priv_mpool);
8046                 TEST_ASSERT_NOT_NULL(sessions[i],
8047                                 "Session creation failed at session number %u",
8048                                 i);
8049
8050                 /* Attempt to send a request on each session */
8051                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
8052                         sessions[i],
8053                         ut_params,
8054                         ts_params,
8055                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
8056                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
8057                         aes_cbc_iv),
8058                         "Failed to perform decrypt on request number %u.", i);
8059                 /* free crypto operation structure */
8060                 if (ut_params->op)
8061                         rte_crypto_op_free(ut_params->op);
8062
8063                 /*
8064                  * free mbuf - both obuf and ibuf are usually the same,
8065                  * so check if they point at the same address is necessary,
8066                  * to avoid freeing the mbuf twice.
8067                  */
8068                 if (ut_params->obuf) {
8069                         rte_pktmbuf_free(ut_params->obuf);
8070                         if (ut_params->ibuf == ut_params->obuf)
8071                                 ut_params->ibuf = 0;
8072                         ut_params->obuf = 0;
8073                 }
8074                 if (ut_params->ibuf) {
8075                         rte_pktmbuf_free(ut_params->ibuf);
8076                         ut_params->ibuf = 0;
8077                 }
8078         }
8079
8080         /* Next session create should fail */
8081         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8082                         sessions[i], &ut_params->auth_xform,
8083                         ts_params->session_priv_mpool);
8084         TEST_ASSERT_NULL(sessions[i],
8085                         "Session creation succeeded unexpectedly!");
8086
8087         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8088                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
8089                                 sessions[i]);
8090                 rte_cryptodev_sym_session_free(sessions[i]);
8091         }
8092
8093         rte_free(sessions);
8094
8095         return TEST_SUCCESS;
8096 }
8097
8098 struct multi_session_params {
8099         struct crypto_unittest_params ut_params;
8100         uint8_t *cipher_key;
8101         uint8_t *hmac_key;
8102         const uint8_t *cipher;
8103         const uint8_t *digest;
8104         uint8_t *iv;
8105 };
8106
8107 #define MB_SESSION_NUMBER 3
8108
8109 static int
8110 test_multi_session_random_usage(void)
8111 {
8112         struct crypto_testsuite_params *ts_params = &testsuite_params;
8113         struct rte_cryptodev_info dev_info;
8114         struct rte_cryptodev_sym_session **sessions;
8115         uint32_t i, j;
8116         struct multi_session_params ut_paramz[] = {
8117
8118                 {
8119                         .cipher_key = ms_aes_cbc_key0,
8120                         .hmac_key = ms_hmac_key0,
8121                         .cipher = ms_aes_cbc_cipher0,
8122                         .digest = ms_hmac_digest0,
8123                         .iv = ms_aes_cbc_iv0
8124                 },
8125                 {
8126                         .cipher_key = ms_aes_cbc_key1,
8127                         .hmac_key = ms_hmac_key1,
8128                         .cipher = ms_aes_cbc_cipher1,
8129                         .digest = ms_hmac_digest1,
8130                         .iv = ms_aes_cbc_iv1
8131                 },
8132                 {
8133                         .cipher_key = ms_aes_cbc_key2,
8134                         .hmac_key = ms_hmac_key2,
8135                         .cipher = ms_aes_cbc_cipher2,
8136                         .digest = ms_hmac_digest2,
8137                         .iv = ms_aes_cbc_iv2
8138                 },
8139
8140         };
8141
8142         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8143
8144         sessions = rte_malloc(NULL,
8145                         (sizeof(struct rte_cryptodev_sym_session *)
8146                                         * MAX_NB_SESSIONS) + 1, 0);
8147
8148         for (i = 0; i < MB_SESSION_NUMBER; i++) {
8149                 sessions[i] = rte_cryptodev_sym_session_create(
8150                                 ts_params->session_mpool);
8151
8152                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
8153                                 sizeof(struct crypto_unittest_params));
8154
8155                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
8156                                 &ut_paramz[i].ut_params,
8157                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
8158
8159                 /* Create multiple crypto sessions*/
8160                 rte_cryptodev_sym_session_init(
8161                                 ts_params->valid_devs[0],
8162                                 sessions[i],
8163                                 &ut_paramz[i].ut_params.auth_xform,
8164                                 ts_params->session_priv_mpool);
8165
8166                 TEST_ASSERT_NOT_NULL(sessions[i],
8167                                 "Session creation failed at session number %u",
8168                                 i);
8169
8170         }
8171
8172         srand(time(NULL));
8173         for (i = 0; i < 40000; i++) {
8174
8175                 j = rand() % MB_SESSION_NUMBER;
8176
8177                 TEST_ASSERT_SUCCESS(
8178                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
8179                                         sessions[j],
8180                                         &ut_paramz[j].ut_params,
8181                                         ts_params, ut_paramz[j].cipher,
8182                                         ut_paramz[j].digest,
8183                                         ut_paramz[j].iv),
8184                         "Failed to perform decrypt on request number %u.", i);
8185
8186                 if (ut_paramz[j].ut_params.op)
8187                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
8188
8189                 /*
8190                  * free mbuf - both obuf and ibuf are usually the same,
8191                  * so check if they point at the same address is necessary,
8192                  * to avoid freeing the mbuf twice.
8193                  */
8194                 if (ut_paramz[j].ut_params.obuf) {
8195                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
8196                         if (ut_paramz[j].ut_params.ibuf
8197                                         == ut_paramz[j].ut_params.obuf)
8198                                 ut_paramz[j].ut_params.ibuf = 0;
8199                         ut_paramz[j].ut_params.obuf = 0;
8200                 }
8201                 if (ut_paramz[j].ut_params.ibuf) {
8202                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
8203                         ut_paramz[j].ut_params.ibuf = 0;
8204                 }
8205         }
8206
8207         for (i = 0; i < MB_SESSION_NUMBER; i++) {
8208                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
8209                                 sessions[i]);
8210                 rte_cryptodev_sym_session_free(sessions[i]);
8211         }
8212
8213         rte_free(sessions);
8214
8215         return TEST_SUCCESS;
8216 }
8217
8218 static int
8219 test_null_cipher_only_operation(void)
8220 {
8221         struct crypto_testsuite_params *ts_params = &testsuite_params;
8222         struct crypto_unittest_params *ut_params = &unittest_params;
8223
8224         /* Generate test mbuf data and space for digest */
8225         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
8226                         catch_22_quote, QUOTE_512_BYTES, 0);
8227
8228         /* Setup Cipher Parameters */
8229         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8230         ut_params->cipher_xform.next = NULL;
8231
8232         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
8233         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8234
8235         ut_params->sess = rte_cryptodev_sym_session_create(
8236                         ts_params->session_mpool);
8237
8238         /* Create Crypto session*/
8239         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8240                                 ut_params->sess,
8241                                 &ut_params->cipher_xform,
8242                                 ts_params->session_priv_mpool);
8243         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8244
8245         /* Generate Crypto op data structure */
8246         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8247                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8248         TEST_ASSERT_NOT_NULL(ut_params->op,
8249                         "Failed to allocate symmetric crypto operation struct");
8250
8251         /* Set crypto operation data parameters */
8252         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8253
8254         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8255
8256         /* set crypto operation source mbuf */
8257         sym_op->m_src = ut_params->ibuf;
8258
8259         sym_op->cipher.data.offset = 0;
8260         sym_op->cipher.data.length = QUOTE_512_BYTES;
8261
8262         /* Process crypto operation */
8263         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8264                         ut_params->op);
8265         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
8266
8267         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8268                         "crypto operation processing failed");
8269
8270         /* Validate obuf */
8271         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8272                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
8273                         catch_22_quote,
8274                         QUOTE_512_BYTES,
8275                         "Ciphertext data not as expected");
8276
8277         return TEST_SUCCESS;
8278 }
8279 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
8280                         0xab, 0xab, 0xab, 0xab,
8281                         0xab, 0xab, 0xab, 0xab,
8282                         0xab, 0xab, 0xab, 0xab};
8283 static int
8284 test_null_auth_only_operation(void)
8285 {
8286         struct crypto_testsuite_params *ts_params = &testsuite_params;
8287         struct crypto_unittest_params *ut_params = &unittest_params;
8288         uint8_t *digest;
8289
8290         /* Generate test mbuf data and space for digest */
8291         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
8292                         catch_22_quote, QUOTE_512_BYTES, 0);
8293
8294         /* create a pointer for digest, but don't expect anything to be written
8295          * here in a NULL auth algo so no mbuf append done.
8296          */
8297         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8298                         QUOTE_512_BYTES);
8299         /* prefill the memory pointed to by digest */
8300         memcpy(digest, orig_data, sizeof(orig_data));
8301
8302         /* Setup HMAC Parameters */
8303         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8304         ut_params->auth_xform.next = NULL;
8305
8306         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
8307         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
8308
8309         ut_params->sess = rte_cryptodev_sym_session_create(
8310                         ts_params->session_mpool);
8311
8312         /* Create Crypto session*/
8313         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8314                         ut_params->sess, &ut_params->auth_xform,
8315                         ts_params->session_priv_mpool);
8316         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8317
8318         /* Generate Crypto op data structure */
8319         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8320                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8321         TEST_ASSERT_NOT_NULL(ut_params->op,
8322                         "Failed to allocate symmetric crypto operation struct");
8323
8324         /* Set crypto operation data parameters */
8325         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8326
8327         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8328
8329         sym_op->m_src = ut_params->ibuf;
8330
8331         sym_op->auth.data.offset = 0;
8332         sym_op->auth.data.length = QUOTE_512_BYTES;
8333         sym_op->auth.digest.data = digest;
8334         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
8335                         QUOTE_512_BYTES);
8336
8337         /* Process crypto operation */
8338         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8339                         ut_params->op);
8340         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
8341
8342         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8343                         "crypto operation processing failed");
8344         /* Make sure memory pointed to by digest hasn't been overwritten */
8345         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8346                         orig_data,
8347                         digest,
8348                         sizeof(orig_data),
8349                         "Memory at digest ptr overwritten unexpectedly");
8350
8351         return TEST_SUCCESS;
8352 }
8353
8354
8355 static int
8356 test_null_cipher_auth_operation(void)
8357 {
8358         struct crypto_testsuite_params *ts_params = &testsuite_params;
8359         struct crypto_unittest_params *ut_params = &unittest_params;
8360         uint8_t *digest;
8361
8362         /* Generate test mbuf data and space for digest */
8363         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
8364                         catch_22_quote, QUOTE_512_BYTES, 0);
8365
8366         /* create a pointer for digest, but don't expect anything to be written
8367          * here in a NULL auth algo so no mbuf append done.
8368          */
8369         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8370                         QUOTE_512_BYTES);
8371         /* prefill the memory pointed to by digest */
8372         memcpy(digest, orig_data, sizeof(orig_data));
8373
8374         /* Setup Cipher Parameters */
8375         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8376         ut_params->cipher_xform.next = &ut_params->auth_xform;
8377
8378         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
8379         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8380
8381         /* Setup HMAC Parameters */
8382         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8383         ut_params->auth_xform.next = NULL;
8384
8385         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
8386         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
8387
8388         ut_params->sess = rte_cryptodev_sym_session_create(
8389                         ts_params->session_mpool);
8390
8391         /* Create Crypto session*/
8392         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8393                         ut_params->sess, &ut_params->cipher_xform,
8394                         ts_params->session_priv_mpool);
8395         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8396
8397         /* Generate Crypto op data structure */
8398         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8399                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8400         TEST_ASSERT_NOT_NULL(ut_params->op,
8401                         "Failed to allocate symmetric crypto operation struct");
8402
8403         /* Set crypto operation data parameters */
8404         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8405
8406         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8407
8408         sym_op->m_src = ut_params->ibuf;
8409
8410         sym_op->cipher.data.offset = 0;
8411         sym_op->cipher.data.length = QUOTE_512_BYTES;
8412
8413         sym_op->auth.data.offset = 0;
8414         sym_op->auth.data.length = QUOTE_512_BYTES;
8415         sym_op->auth.digest.data = digest;
8416         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
8417                         QUOTE_512_BYTES);
8418
8419         /* Process crypto operation */
8420         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8421                         ut_params->op);
8422         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
8423
8424         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8425                         "crypto operation processing failed");
8426
8427         /* Validate obuf */
8428         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8429                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
8430                         catch_22_quote,
8431                         QUOTE_512_BYTES,
8432                         "Ciphertext data not as expected");
8433         /* Make sure memory pointed to by digest hasn't been overwritten */
8434         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8435                         orig_data,
8436                         digest,
8437                         sizeof(orig_data),
8438                         "Memory at digest ptr overwritten unexpectedly");
8439
8440         return TEST_SUCCESS;
8441 }
8442
8443 static int
8444 test_null_auth_cipher_operation(void)
8445 {
8446         struct crypto_testsuite_params *ts_params = &testsuite_params;
8447         struct crypto_unittest_params *ut_params = &unittest_params;
8448         uint8_t *digest;
8449
8450         /* Generate test mbuf data */
8451         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
8452                         catch_22_quote, QUOTE_512_BYTES, 0);
8453
8454         /* create a pointer for digest, but don't expect anything to be written
8455          * here in a NULL auth algo so no mbuf append done.
8456          */
8457         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8458                                 QUOTE_512_BYTES);
8459         /* prefill the memory pointed to by digest */
8460         memcpy(digest, orig_data, sizeof(orig_data));
8461
8462         /* Setup Cipher Parameters */
8463         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8464         ut_params->cipher_xform.next = NULL;
8465
8466         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
8467         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8468
8469         /* Setup HMAC Parameters */
8470         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8471         ut_params->auth_xform.next = &ut_params->cipher_xform;
8472
8473         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
8474         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
8475
8476         ut_params->sess = rte_cryptodev_sym_session_create(
8477                         ts_params->session_mpool);
8478
8479         /* Create Crypto session*/
8480         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8481                         ut_params->sess, &ut_params->cipher_xform,
8482                         ts_params->session_priv_mpool);
8483         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8484
8485         /* Generate Crypto op data structure */
8486         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8487                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8488         TEST_ASSERT_NOT_NULL(ut_params->op,
8489                         "Failed to allocate symmetric crypto operation struct");
8490
8491         /* Set crypto operation data parameters */
8492         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8493
8494         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8495
8496         sym_op->m_src = ut_params->ibuf;
8497
8498         sym_op->cipher.data.offset = 0;
8499         sym_op->cipher.data.length = QUOTE_512_BYTES;
8500
8501         sym_op->auth.data.offset = 0;
8502         sym_op->auth.data.length = QUOTE_512_BYTES;
8503         sym_op->auth.digest.data = digest;
8504         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
8505                                         QUOTE_512_BYTES);
8506
8507         /* Process crypto operation */
8508         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8509                         ut_params->op);
8510         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
8511
8512         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8513                         "crypto operation processing failed");
8514
8515         /* Validate obuf */
8516         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8517                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
8518                         catch_22_quote,
8519                         QUOTE_512_BYTES,
8520                         "Ciphertext data not as expected");
8521         /* Make sure memory pointed to by digest hasn't been overwritten */
8522         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8523                         orig_data,
8524                         digest,
8525                         sizeof(orig_data),
8526                         "Memory at digest ptr overwritten unexpectedly");
8527
8528         return TEST_SUCCESS;
8529 }
8530
8531
8532 static int
8533 test_null_invalid_operation(void)
8534 {
8535         struct crypto_testsuite_params *ts_params = &testsuite_params;
8536         struct crypto_unittest_params *ut_params = &unittest_params;
8537         int ret;
8538
8539         /* Setup Cipher Parameters */
8540         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8541         ut_params->cipher_xform.next = NULL;
8542
8543         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
8544         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8545
8546         ut_params->sess = rte_cryptodev_sym_session_create(
8547                         ts_params->session_mpool);
8548
8549         /* Create Crypto session*/
8550         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8551                         ut_params->sess, &ut_params->cipher_xform,
8552                         ts_params->session_priv_mpool);
8553         TEST_ASSERT(ret < 0,
8554                         "Session creation succeeded unexpectedly");
8555
8556
8557         /* Setup HMAC Parameters */
8558         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8559         ut_params->auth_xform.next = NULL;
8560
8561         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
8562         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
8563
8564         ut_params->sess = rte_cryptodev_sym_session_create(
8565                         ts_params->session_mpool);
8566
8567         /* Create Crypto session*/
8568         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8569                         ut_params->sess, &ut_params->auth_xform,
8570                         ts_params->session_priv_mpool);
8571         TEST_ASSERT(ret < 0,
8572                         "Session creation succeeded unexpectedly");
8573
8574         return TEST_SUCCESS;
8575 }
8576
8577
8578 #define NULL_BURST_LENGTH (32)
8579
8580 static int
8581 test_null_burst_operation(void)
8582 {
8583         struct crypto_testsuite_params *ts_params = &testsuite_params;
8584         struct crypto_unittest_params *ut_params = &unittest_params;
8585
8586         unsigned i, burst_len = NULL_BURST_LENGTH;
8587
8588         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
8589         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
8590
8591         /* Setup Cipher Parameters */
8592         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8593         ut_params->cipher_xform.next = &ut_params->auth_xform;
8594
8595         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
8596         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8597
8598         /* Setup HMAC Parameters */
8599         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8600         ut_params->auth_xform.next = NULL;
8601
8602         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
8603         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
8604
8605         ut_params->sess = rte_cryptodev_sym_session_create(
8606                         ts_params->session_mpool);
8607
8608         /* Create Crypto session*/
8609         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8610                         ut_params->sess, &ut_params->cipher_xform,
8611                         ts_params->session_priv_mpool);
8612         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8613
8614         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
8615                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
8616                         burst_len, "failed to generate burst of crypto ops");
8617
8618         /* Generate an operation for each mbuf in burst */
8619         for (i = 0; i < burst_len; i++) {
8620                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8621
8622                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
8623
8624                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
8625                                 sizeof(unsigned));
8626                 *data = i;
8627
8628                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
8629
8630                 burst[i]->sym->m_src = m;
8631         }
8632
8633         /* Process crypto operation */
8634         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
8635                         0, burst, burst_len),
8636                         burst_len,
8637                         "Error enqueuing burst");
8638
8639         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
8640                         0, burst_dequeued, burst_len),
8641                         burst_len,
8642                         "Error dequeuing burst");
8643
8644
8645         for (i = 0; i < burst_len; i++) {
8646                 TEST_ASSERT_EQUAL(
8647                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
8648                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
8649                                         uint32_t *),
8650                         "data not as expected");
8651
8652                 rte_pktmbuf_free(burst[i]->sym->m_src);
8653                 rte_crypto_op_free(burst[i]);
8654         }
8655
8656         return TEST_SUCCESS;
8657 }
8658
8659 static void
8660 generate_gmac_large_plaintext(uint8_t *data)
8661 {
8662         uint16_t i;
8663
8664         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
8665                 memcpy(&data[i], &data[0], 32);
8666 }
8667
8668 static int
8669 create_gmac_operation(enum rte_crypto_auth_operation op,
8670                 const struct gmac_test_data *tdata)
8671 {
8672         struct crypto_testsuite_params *ts_params = &testsuite_params;
8673         struct crypto_unittest_params *ut_params = &unittest_params;
8674         struct rte_crypto_sym_op *sym_op;
8675
8676         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8677
8678         /* Generate Crypto op data structure */
8679         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8680                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8681         TEST_ASSERT_NOT_NULL(ut_params->op,
8682                         "Failed to allocate symmetric crypto operation struct");
8683
8684         sym_op = ut_params->op->sym;
8685
8686         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
8687                         ut_params->ibuf, tdata->gmac_tag.len);
8688         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
8689                         "no room to append digest");
8690
8691         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
8692                         ut_params->ibuf, plaintext_pad_len);
8693
8694         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
8695                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
8696                                 tdata->gmac_tag.len);
8697                 debug_hexdump(stdout, "digest:",
8698                                 sym_op->auth.digest.data,
8699                                 tdata->gmac_tag.len);
8700         }
8701
8702         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8703                         uint8_t *, IV_OFFSET);
8704
8705         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8706
8707         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
8708
8709         sym_op->cipher.data.length = 0;
8710         sym_op->cipher.data.offset = 0;
8711
8712         sym_op->auth.data.offset = 0;
8713         sym_op->auth.data.length = tdata->plaintext.len;
8714
8715         return 0;
8716 }
8717
8718 static int create_gmac_session(uint8_t dev_id,
8719                 const struct gmac_test_data *tdata,
8720                 enum rte_crypto_auth_operation auth_op)
8721 {
8722         uint8_t auth_key[tdata->key.len];
8723
8724         struct crypto_testsuite_params *ts_params = &testsuite_params;
8725         struct crypto_unittest_params *ut_params = &unittest_params;
8726
8727         memcpy(auth_key, tdata->key.data, tdata->key.len);
8728
8729         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8730         ut_params->auth_xform.next = NULL;
8731
8732         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
8733         ut_params->auth_xform.auth.op = auth_op;
8734         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
8735         ut_params->auth_xform.auth.key.length = tdata->key.len;
8736         ut_params->auth_xform.auth.key.data = auth_key;
8737         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
8738         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
8739
8740
8741         ut_params->sess = rte_cryptodev_sym_session_create(
8742                         ts_params->session_mpool);
8743
8744         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
8745                         &ut_params->auth_xform,
8746                         ts_params->session_priv_mpool);
8747
8748         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8749
8750         return 0;
8751 }
8752
8753 static int
8754 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
8755 {
8756         struct crypto_testsuite_params *ts_params = &testsuite_params;
8757         struct crypto_unittest_params *ut_params = &unittest_params;
8758
8759         int retval;
8760
8761         uint8_t *auth_tag, *plaintext;
8762         uint16_t plaintext_pad_len;
8763
8764         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
8765                               "No GMAC length in the source data");
8766
8767         retval = create_gmac_session(ts_params->valid_devs[0],
8768                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
8769
8770         if (retval < 0)
8771                 return retval;
8772
8773         if (tdata->plaintext.len > MBUF_SIZE)
8774                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8775         else
8776                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8777         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
8778                         "Failed to allocate input buffer in mempool");
8779
8780         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8781                         rte_pktmbuf_tailroom(ut_params->ibuf));
8782
8783         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8784         /*
8785          * Runtime generate the large plain text instead of use hard code
8786          * plain text vector. It is done to avoid create huge source file
8787          * with the test vector.
8788          */
8789         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
8790                 generate_gmac_large_plaintext(tdata->plaintext.data);
8791
8792         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8793                                 plaintext_pad_len);
8794         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8795
8796         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8797         debug_hexdump(stdout, "plaintext:", plaintext,
8798                         tdata->plaintext.len);
8799
8800         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
8801                         tdata);
8802
8803         if (retval < 0)
8804                 return retval;
8805
8806         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8807
8808         ut_params->op->sym->m_src = ut_params->ibuf;
8809
8810         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8811                         ut_params->op), "failed to process sym crypto op");
8812
8813         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8814                         "crypto op processing failed");
8815
8816         if (ut_params->op->sym->m_dst) {
8817                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8818                                 uint8_t *, plaintext_pad_len);
8819         } else {
8820                 auth_tag = plaintext + plaintext_pad_len;
8821         }
8822
8823         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
8824
8825         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8826                         auth_tag,
8827                         tdata->gmac_tag.data,
8828                         tdata->gmac_tag.len,
8829                         "GMAC Generated auth tag not as expected");
8830
8831         return 0;
8832 }
8833
8834 static int
8835 test_AES_GMAC_authentication_test_case_1(void)
8836 {
8837         return test_AES_GMAC_authentication(&gmac_test_case_1);
8838 }
8839
8840 static int
8841 test_AES_GMAC_authentication_test_case_2(void)
8842 {
8843         return test_AES_GMAC_authentication(&gmac_test_case_2);
8844 }
8845
8846 static int
8847 test_AES_GMAC_authentication_test_case_3(void)
8848 {
8849         return test_AES_GMAC_authentication(&gmac_test_case_3);
8850 }
8851
8852 static int
8853 test_AES_GMAC_authentication_test_case_4(void)
8854 {
8855         return test_AES_GMAC_authentication(&gmac_test_case_4);
8856 }
8857
8858 static int
8859 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
8860 {
8861         struct crypto_testsuite_params *ts_params = &testsuite_params;
8862         struct crypto_unittest_params *ut_params = &unittest_params;
8863         int retval;
8864         uint32_t plaintext_pad_len;
8865         uint8_t *plaintext;
8866
8867         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
8868                               "No GMAC length in the source data");
8869
8870         retval = create_gmac_session(ts_params->valid_devs[0],
8871                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
8872
8873         if (retval < 0)
8874                 return retval;
8875
8876         if (tdata->plaintext.len > MBUF_SIZE)
8877                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8878         else
8879                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8880         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
8881                         "Failed to allocate input buffer in mempool");
8882
8883         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8884                         rte_pktmbuf_tailroom(ut_params->ibuf));
8885
8886         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8887
8888         /*
8889          * Runtime generate the large plain text instead of use hard code
8890          * plain text vector. It is done to avoid create huge source file
8891          * with the test vector.
8892          */
8893         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
8894                 generate_gmac_large_plaintext(tdata->plaintext.data);
8895
8896         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8897                                 plaintext_pad_len);
8898         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8899
8900         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8901         debug_hexdump(stdout, "plaintext:", plaintext,
8902                         tdata->plaintext.len);
8903
8904         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
8905                         tdata);
8906
8907         if (retval < 0)
8908                 return retval;
8909
8910         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8911
8912         ut_params->op->sym->m_src = ut_params->ibuf;
8913
8914         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8915                         ut_params->op), "failed to process sym crypto op");
8916
8917         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8918                         "crypto op processing failed");
8919
8920         return 0;
8921
8922 }
8923
8924 static int
8925 test_AES_GMAC_authentication_verify_test_case_1(void)
8926 {
8927         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
8928 }
8929
8930 static int
8931 test_AES_GMAC_authentication_verify_test_case_2(void)
8932 {
8933         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
8934 }
8935
8936 static int
8937 test_AES_GMAC_authentication_verify_test_case_3(void)
8938 {
8939         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
8940 }
8941
8942 static int
8943 test_AES_GMAC_authentication_verify_test_case_4(void)
8944 {
8945         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
8946 }
8947
8948 struct test_crypto_vector {
8949         enum rte_crypto_cipher_algorithm crypto_algo;
8950
8951         struct {
8952                 uint8_t data[64];
8953                 unsigned int len;
8954         } cipher_key;
8955
8956         struct {
8957                 uint8_t data[64];
8958                 unsigned int len;
8959         } iv;
8960
8961         struct {
8962                 const uint8_t *data;
8963                 unsigned int len;
8964         } plaintext;
8965
8966         struct {
8967                 const uint8_t *data;
8968                 unsigned int len;
8969         } ciphertext;
8970
8971         enum rte_crypto_auth_algorithm auth_algo;
8972
8973         struct {
8974                 uint8_t data[128];
8975                 unsigned int len;
8976         } auth_key;
8977
8978         struct {
8979                 const uint8_t *data;
8980                 unsigned int len;
8981         } aad;
8982
8983         struct {
8984                 uint8_t data[128];
8985                 unsigned int len;
8986         } digest;
8987 };
8988
8989 static const struct test_crypto_vector
8990 hmac_sha1_test_crypto_vector = {
8991         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
8992         .plaintext = {
8993                 .data = plaintext_hash,
8994                 .len = 512
8995         },
8996         .auth_key = {
8997                 .data = {
8998                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
8999                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
9000                         0xDE, 0xF4, 0xDE, 0xAD
9001                 },
9002                 .len = 20
9003         },
9004         .digest = {
9005                 .data = {
9006                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
9007                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
9008                         0x3F, 0x91, 0x64, 0x59
9009                 },
9010                 .len = 20
9011         }
9012 };
9013
9014 static const struct test_crypto_vector
9015 aes128_gmac_test_vector = {
9016         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
9017         .plaintext = {
9018                 .data = plaintext_hash,
9019                 .len = 512
9020         },
9021         .iv = {
9022                 .data = {
9023                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9024                         0x08, 0x09, 0x0A, 0x0B
9025                 },
9026                 .len = 12
9027         },
9028         .auth_key = {
9029                 .data = {
9030                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
9031                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
9032                 },
9033                 .len = 16
9034         },
9035         .digest = {
9036                 .data = {
9037                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
9038                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
9039                 },
9040                 .len = 16
9041         }
9042 };
9043
9044 static const struct test_crypto_vector
9045 aes128cbc_hmac_sha1_test_vector = {
9046         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
9047         .cipher_key = {
9048                 .data = {
9049                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
9050                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
9051                 },
9052                 .len = 16
9053         },
9054         .iv = {
9055                 .data = {
9056                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9057                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
9058                 },
9059                 .len = 16
9060         },
9061         .plaintext = {
9062                 .data = plaintext_hash,
9063                 .len = 512
9064         },
9065         .ciphertext = {
9066                 .data = ciphertext512_aes128cbc,
9067                 .len = 512
9068         },
9069         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
9070         .auth_key = {
9071                 .data = {
9072                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
9073                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
9074                         0xDE, 0xF4, 0xDE, 0xAD
9075                 },
9076                 .len = 20
9077         },
9078         .digest = {
9079                 .data = {
9080                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
9081                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
9082                         0x18, 0x8C, 0x1D, 0x32
9083                 },
9084                 .len = 20
9085         }
9086 };
9087
9088 static void
9089 data_corruption(uint8_t *data)
9090 {
9091         data[0] += 1;
9092 }
9093
9094 static void
9095 tag_corruption(uint8_t *data, unsigned int tag_offset)
9096 {
9097         data[tag_offset] += 1;
9098 }
9099
9100 static int
9101 create_auth_session(struct crypto_unittest_params *ut_params,
9102                 uint8_t dev_id,
9103                 const struct test_crypto_vector *reference,
9104                 enum rte_crypto_auth_operation auth_op)
9105 {
9106         struct crypto_testsuite_params *ts_params = &testsuite_params;
9107         uint8_t auth_key[reference->auth_key.len + 1];
9108
9109         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
9110
9111         /* Setup Authentication Parameters */
9112         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9113         ut_params->auth_xform.auth.op = auth_op;
9114         ut_params->auth_xform.next = NULL;
9115         ut_params->auth_xform.auth.algo = reference->auth_algo;
9116         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
9117         ut_params->auth_xform.auth.key.data = auth_key;
9118         ut_params->auth_xform.auth.digest_length = reference->digest.len;
9119
9120         /* Create Crypto session*/
9121         ut_params->sess = rte_cryptodev_sym_session_create(
9122                         ts_params->session_mpool);
9123
9124         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
9125                                 &ut_params->auth_xform,
9126                                 ts_params->session_priv_mpool);
9127
9128         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9129
9130         return 0;
9131 }
9132
9133 static int
9134 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
9135                 uint8_t dev_id,
9136                 const struct test_crypto_vector *reference,
9137                 enum rte_crypto_auth_operation auth_op,
9138                 enum rte_crypto_cipher_operation cipher_op)
9139 {
9140         struct crypto_testsuite_params *ts_params = &testsuite_params;
9141         uint8_t cipher_key[reference->cipher_key.len + 1];
9142         uint8_t auth_key[reference->auth_key.len + 1];
9143
9144         memcpy(cipher_key, reference->cipher_key.data,
9145                         reference->cipher_key.len);
9146         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
9147
9148         /* Setup Authentication Parameters */
9149         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9150         ut_params->auth_xform.auth.op = auth_op;
9151         ut_params->auth_xform.auth.algo = reference->auth_algo;
9152         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
9153         ut_params->auth_xform.auth.key.data = auth_key;
9154         ut_params->auth_xform.auth.digest_length = reference->digest.len;
9155
9156         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
9157                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
9158                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
9159         } else {
9160                 ut_params->auth_xform.next = &ut_params->cipher_xform;
9161
9162                 /* Setup Cipher Parameters */
9163                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9164                 ut_params->cipher_xform.next = NULL;
9165                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
9166                 ut_params->cipher_xform.cipher.op = cipher_op;
9167                 ut_params->cipher_xform.cipher.key.data = cipher_key;
9168                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
9169                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9170                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
9171         }
9172
9173         /* Create Crypto session*/
9174         ut_params->sess = rte_cryptodev_sym_session_create(
9175                         ts_params->session_mpool);
9176
9177         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
9178                                 &ut_params->auth_xform,
9179                                 ts_params->session_priv_mpool);
9180
9181         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9182
9183         return 0;
9184 }
9185
9186 static int
9187 create_auth_operation(struct crypto_testsuite_params *ts_params,
9188                 struct crypto_unittest_params *ut_params,
9189                 const struct test_crypto_vector *reference,
9190                 unsigned int auth_generate)
9191 {
9192         /* Generate Crypto op data structure */
9193         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9194                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9195         TEST_ASSERT_NOT_NULL(ut_params->op,
9196                         "Failed to allocate pktmbuf offload");
9197
9198         /* Set crypto operation data parameters */
9199         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9200
9201         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9202
9203         /* set crypto operation source mbuf */
9204         sym_op->m_src = ut_params->ibuf;
9205
9206         /* digest */
9207         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9208                         ut_params->ibuf, reference->digest.len);
9209
9210         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9211                         "no room to append auth tag");
9212
9213         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9214                         ut_params->ibuf, reference->plaintext.len);
9215
9216         if (auth_generate)
9217                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
9218         else
9219                 memcpy(sym_op->auth.digest.data,
9220                                 reference->digest.data,
9221                                 reference->digest.len);
9222
9223         debug_hexdump(stdout, "digest:",
9224                         sym_op->auth.digest.data,
9225                         reference->digest.len);
9226
9227         sym_op->auth.data.length = reference->plaintext.len;
9228         sym_op->auth.data.offset = 0;
9229
9230         return 0;
9231 }
9232
9233 static int
9234 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
9235                 struct crypto_unittest_params *ut_params,
9236                 const struct test_crypto_vector *reference,
9237                 unsigned int auth_generate)
9238 {
9239         /* Generate Crypto op data structure */
9240         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9241                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9242         TEST_ASSERT_NOT_NULL(ut_params->op,
9243                         "Failed to allocate pktmbuf offload");
9244
9245         /* Set crypto operation data parameters */
9246         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9247
9248         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9249
9250         /* set crypto operation source mbuf */
9251         sym_op->m_src = ut_params->ibuf;
9252
9253         /* digest */
9254         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9255                         ut_params->ibuf, reference->digest.len);
9256
9257         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9258                         "no room to append auth tag");
9259
9260         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9261                         ut_params->ibuf, reference->ciphertext.len);
9262
9263         if (auth_generate)
9264                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
9265         else
9266                 memcpy(sym_op->auth.digest.data,
9267                                 reference->digest.data,
9268                                 reference->digest.len);
9269
9270         debug_hexdump(stdout, "digest:",
9271                         sym_op->auth.digest.data,
9272                         reference->digest.len);
9273
9274         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
9275                         reference->iv.data, reference->iv.len);
9276
9277         sym_op->cipher.data.length = 0;
9278         sym_op->cipher.data.offset = 0;
9279
9280         sym_op->auth.data.length = reference->plaintext.len;
9281         sym_op->auth.data.offset = 0;
9282
9283         return 0;
9284 }
9285
9286 static int
9287 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
9288                 struct crypto_unittest_params *ut_params,
9289                 const struct test_crypto_vector *reference,
9290                 unsigned int auth_generate)
9291 {
9292         /* Generate Crypto op data structure */
9293         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9294                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9295         TEST_ASSERT_NOT_NULL(ut_params->op,
9296                         "Failed to allocate pktmbuf offload");
9297
9298         /* Set crypto operation data parameters */
9299         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9300
9301         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9302
9303         /* set crypto operation source mbuf */
9304         sym_op->m_src = ut_params->ibuf;
9305
9306         /* digest */
9307         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9308                         ut_params->ibuf, reference->digest.len);
9309
9310         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9311                         "no room to append auth tag");
9312
9313         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9314                         ut_params->ibuf, reference->ciphertext.len);
9315
9316         if (auth_generate)
9317                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
9318         else
9319                 memcpy(sym_op->auth.digest.data,
9320                                 reference->digest.data,
9321                                 reference->digest.len);
9322
9323         debug_hexdump(stdout, "digest:",
9324                         sym_op->auth.digest.data,
9325                         reference->digest.len);
9326
9327         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
9328                         reference->iv.data, reference->iv.len);
9329
9330         sym_op->cipher.data.length = reference->ciphertext.len;
9331         sym_op->cipher.data.offset = 0;
9332
9333         sym_op->auth.data.length = reference->ciphertext.len;
9334         sym_op->auth.data.offset = 0;
9335
9336         return 0;
9337 }
9338
9339 static int
9340 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
9341                 struct crypto_unittest_params *ut_params,
9342                 const struct test_crypto_vector *reference)
9343 {
9344         return create_auth_operation(ts_params, ut_params, reference, 0);
9345 }
9346
9347 static int
9348 create_auth_verify_GMAC_operation(
9349                 struct crypto_testsuite_params *ts_params,
9350                 struct crypto_unittest_params *ut_params,
9351                 const struct test_crypto_vector *reference)
9352 {
9353         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
9354 }
9355
9356 static int
9357 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
9358                 struct crypto_unittest_params *ut_params,
9359                 const struct test_crypto_vector *reference)
9360 {
9361         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
9362 }
9363
9364 static int
9365 test_authentication_verify_fail_when_data_corruption(
9366                 struct crypto_testsuite_params *ts_params,
9367                 struct crypto_unittest_params *ut_params,
9368                 const struct test_crypto_vector *reference,
9369                 unsigned int data_corrupted)
9370 {
9371         int retval;
9372
9373         uint8_t *plaintext;
9374
9375         /* Create session */
9376         retval = create_auth_session(ut_params,
9377                         ts_params->valid_devs[0],
9378                         reference,
9379                         RTE_CRYPTO_AUTH_OP_VERIFY);
9380         if (retval < 0)
9381                 return retval;
9382
9383         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9384         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9385                         "Failed to allocate input buffer in mempool");
9386
9387         /* clear mbuf payload */
9388         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9389                         rte_pktmbuf_tailroom(ut_params->ibuf));
9390
9391         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9392                         reference->plaintext.len);
9393         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9394         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
9395
9396         debug_hexdump(stdout, "plaintext:", plaintext,
9397                 reference->plaintext.len);
9398
9399         /* Create operation */
9400         retval = create_auth_verify_operation(ts_params, ut_params, reference);
9401
9402         if (retval < 0)
9403                 return retval;
9404
9405         if (data_corrupted)
9406                 data_corruption(plaintext);
9407         else
9408                 tag_corruption(plaintext, reference->plaintext.len);
9409
9410         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9411                         ut_params->op);
9412         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9413         TEST_ASSERT_EQUAL(ut_params->op->status,
9414                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
9415                         "authentication not failed");
9416
9417         ut_params->obuf = ut_params->op->sym->m_src;
9418         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
9419
9420         return 0;
9421 }
9422
9423 static int
9424 test_authentication_verify_GMAC_fail_when_corruption(
9425                 struct crypto_testsuite_params *ts_params,
9426                 struct crypto_unittest_params *ut_params,
9427                 const struct test_crypto_vector *reference,
9428                 unsigned int data_corrupted)
9429 {
9430         int retval;
9431         uint8_t *plaintext;
9432
9433         /* Create session */
9434         retval = create_auth_cipher_session(ut_params,
9435                         ts_params->valid_devs[0],
9436                         reference,
9437                         RTE_CRYPTO_AUTH_OP_VERIFY,
9438                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
9439         if (retval < 0)
9440                 return retval;
9441
9442         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9443         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9444                         "Failed to allocate input buffer in mempool");
9445
9446         /* clear mbuf payload */
9447         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9448                         rte_pktmbuf_tailroom(ut_params->ibuf));
9449
9450         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9451                         reference->plaintext.len);
9452         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9453         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
9454
9455         debug_hexdump(stdout, "plaintext:", plaintext,
9456                 reference->plaintext.len);
9457
9458         /* Create operation */
9459         retval = create_auth_verify_GMAC_operation(ts_params,
9460                         ut_params,
9461                         reference);
9462
9463         if (retval < 0)
9464                 return retval;
9465
9466         if (data_corrupted)
9467                 data_corruption(plaintext);
9468         else
9469                 tag_corruption(plaintext, reference->aad.len);
9470
9471         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9472                         ut_params->op);
9473         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9474         TEST_ASSERT_EQUAL(ut_params->op->status,
9475                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
9476                         "authentication not failed");
9477
9478         ut_params->obuf = ut_params->op->sym->m_src;
9479         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
9480
9481         return 0;
9482 }
9483
9484 static int
9485 test_authenticated_decryption_fail_when_corruption(
9486                 struct crypto_testsuite_params *ts_params,
9487                 struct crypto_unittest_params *ut_params,
9488                 const struct test_crypto_vector *reference,
9489                 unsigned int data_corrupted)
9490 {
9491         int retval;
9492
9493         uint8_t *ciphertext;
9494
9495         /* Create session */
9496         retval = create_auth_cipher_session(ut_params,
9497                         ts_params->valid_devs[0],
9498                         reference,
9499                         RTE_CRYPTO_AUTH_OP_VERIFY,
9500                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
9501         if (retval < 0)
9502                 return retval;
9503
9504         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9505         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9506                         "Failed to allocate input buffer in mempool");
9507
9508         /* clear mbuf payload */
9509         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9510                         rte_pktmbuf_tailroom(ut_params->ibuf));
9511
9512         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9513                         reference->ciphertext.len);
9514         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
9515         memcpy(ciphertext, reference->ciphertext.data,
9516                         reference->ciphertext.len);
9517
9518         /* Create operation */
9519         retval = create_cipher_auth_verify_operation(ts_params,
9520                         ut_params,
9521                         reference);
9522
9523         if (retval < 0)
9524                 return retval;
9525
9526         if (data_corrupted)
9527                 data_corruption(ciphertext);
9528         else
9529                 tag_corruption(ciphertext, reference->ciphertext.len);
9530
9531         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9532                         ut_params->op);
9533
9534         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9535         TEST_ASSERT_EQUAL(ut_params->op->status,
9536                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
9537                         "authentication not failed");
9538
9539         ut_params->obuf = ut_params->op->sym->m_src;
9540         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
9541
9542         return 0;
9543 }
9544
9545 static int
9546 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
9547                 const struct aead_test_data *tdata,
9548                 void *digest_mem, uint64_t digest_phys)
9549 {
9550         struct crypto_testsuite_params *ts_params = &testsuite_params;
9551         struct crypto_unittest_params *ut_params = &unittest_params;
9552
9553         const unsigned int auth_tag_len = tdata->auth_tag.len;
9554         const unsigned int iv_len = tdata->iv.len;
9555         unsigned int aad_len = tdata->aad.len;
9556
9557         /* Generate Crypto op data structure */
9558         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9559                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9560         TEST_ASSERT_NOT_NULL(ut_params->op,
9561                 "Failed to allocate symmetric crypto operation struct");
9562
9563         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9564
9565         sym_op->aead.digest.data = digest_mem;
9566
9567         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
9568                         "no room to append digest");
9569
9570         sym_op->aead.digest.phys_addr = digest_phys;
9571
9572         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
9573                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
9574                                 auth_tag_len);
9575                 debug_hexdump(stdout, "digest:",
9576                                 sym_op->aead.digest.data,
9577                                 auth_tag_len);
9578         }
9579
9580         /* Append aad data */
9581         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
9582                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9583                                 uint8_t *, IV_OFFSET);
9584
9585                 /* Copy IV 1 byte after the IV pointer, according to the API */
9586                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
9587
9588                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
9589
9590                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
9591                                 ut_params->ibuf, aad_len);
9592                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
9593                                 "no room to prepend aad");
9594                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
9595                                 ut_params->ibuf);
9596
9597                 memset(sym_op->aead.aad.data, 0, aad_len);
9598                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
9599                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
9600
9601                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
9602                 debug_hexdump(stdout, "aad:",
9603                                 sym_op->aead.aad.data, aad_len);
9604         } else {
9605                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9606                                 uint8_t *, IV_OFFSET);
9607
9608                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
9609
9610                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
9611                                 ut_params->ibuf, aad_len);
9612                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
9613                                 "no room to prepend aad");
9614                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
9615                                 ut_params->ibuf);
9616
9617                 memset(sym_op->aead.aad.data, 0, aad_len);
9618                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
9619
9620                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
9621                 debug_hexdump(stdout, "aad:",
9622                                 sym_op->aead.aad.data, aad_len);
9623         }
9624
9625         sym_op->aead.data.length = tdata->plaintext.len;
9626         sym_op->aead.data.offset = aad_len;
9627
9628         return 0;
9629 }
9630
9631 #define SGL_MAX_NO      16
9632
9633 static int
9634 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
9635                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
9636 {
9637         struct crypto_testsuite_params *ts_params = &testsuite_params;
9638         struct crypto_unittest_params *ut_params = &unittest_params;
9639         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
9640         int retval;
9641         int to_trn = 0;
9642         int to_trn_tbl[SGL_MAX_NO];
9643         int segs = 1;
9644         unsigned int trn_data = 0;
9645         uint8_t *plaintext, *ciphertext, *auth_tag;
9646
9647         if (fragsz > tdata->plaintext.len)
9648                 fragsz = tdata->plaintext.len;
9649
9650         uint16_t plaintext_len = fragsz;
9651         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
9652
9653         if (fragsz_oop > tdata->plaintext.len)
9654                 frag_size_oop = tdata->plaintext.len;
9655
9656         int ecx = 0;
9657         void *digest_mem = NULL;
9658
9659         uint32_t prepend_len = tdata->aad.len;
9660
9661         if (tdata->plaintext.len % fragsz != 0) {
9662                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
9663                         return 1;
9664         }       else {
9665                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
9666                         return 1;
9667         }
9668
9669         /*
9670          * For out-op-place we need to alloc another mbuf
9671          */
9672         if (oop) {
9673                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9674                 rte_pktmbuf_append(ut_params->obuf,
9675                                 frag_size_oop + prepend_len);
9676                 buf_oop = ut_params->obuf;
9677         }
9678
9679         /* Create AEAD session */
9680         retval = create_aead_session(ts_params->valid_devs[0],
9681                         tdata->algo,
9682                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9683                         tdata->key.data, tdata->key.len,
9684                         tdata->aad.len, tdata->auth_tag.len,
9685                         tdata->iv.len);
9686         if (retval < 0)
9687                 return retval;
9688
9689         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9690
9691         /* clear mbuf payload */
9692         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9693                         rte_pktmbuf_tailroom(ut_params->ibuf));
9694
9695         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9696                         plaintext_len);
9697
9698         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
9699
9700         trn_data += plaintext_len;
9701
9702         buf = ut_params->ibuf;
9703
9704         /*
9705          * Loop until no more fragments
9706          */
9707
9708         while (trn_data < tdata->plaintext.len) {
9709                 ++segs;
9710                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
9711                                 (tdata->plaintext.len - trn_data) : fragsz;
9712
9713                 to_trn_tbl[ecx++] = to_trn;
9714
9715                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9716                 buf = buf->next;
9717
9718                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
9719                                 rte_pktmbuf_tailroom(buf));
9720
9721                 /* OOP */
9722                 if (oop && !fragsz_oop) {
9723                         buf_last_oop = buf_oop->next =
9724                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
9725                         buf_oop = buf_oop->next;
9726                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9727                                         0, rte_pktmbuf_tailroom(buf_oop));
9728                         rte_pktmbuf_append(buf_oop, to_trn);
9729                 }
9730
9731                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
9732                                 to_trn);
9733
9734                 memcpy(plaintext, tdata->plaintext.data + trn_data,
9735                                 to_trn);
9736                 trn_data += to_trn;
9737                 if (trn_data  == tdata->plaintext.len) {
9738                         if (oop) {
9739                                 if (!fragsz_oop)
9740                                         digest_mem = rte_pktmbuf_append(buf_oop,
9741                                                 tdata->auth_tag.len);
9742                         } else
9743                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
9744                                         tdata->auth_tag.len);
9745                 }
9746         }
9747
9748         uint64_t digest_phys = 0;
9749
9750         ut_params->ibuf->nb_segs = segs;
9751
9752         segs = 1;
9753         if (fragsz_oop && oop) {
9754                 to_trn = 0;
9755                 ecx = 0;
9756
9757                 if (frag_size_oop == tdata->plaintext.len) {
9758                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
9759                                 tdata->auth_tag.len);
9760
9761                         digest_phys = rte_pktmbuf_iova_offset(
9762                                         ut_params->obuf,
9763                                         tdata->plaintext.len + prepend_len);
9764                 }
9765
9766                 trn_data = frag_size_oop;
9767                 while (trn_data < tdata->plaintext.len) {
9768                         ++segs;
9769                         to_trn =
9770                                 (tdata->plaintext.len - trn_data <
9771                                                 frag_size_oop) ?
9772                                 (tdata->plaintext.len - trn_data) :
9773                                                 frag_size_oop;
9774
9775                         to_trn_tbl[ecx++] = to_trn;
9776
9777                         buf_last_oop = buf_oop->next =
9778                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
9779                         buf_oop = buf_oop->next;
9780                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9781                                         0, rte_pktmbuf_tailroom(buf_oop));
9782                         rte_pktmbuf_append(buf_oop, to_trn);
9783
9784                         trn_data += to_trn;
9785
9786                         if (trn_data  == tdata->plaintext.len) {
9787                                 digest_mem = rte_pktmbuf_append(buf_oop,
9788                                         tdata->auth_tag.len);
9789                         }
9790                 }
9791
9792                 ut_params->obuf->nb_segs = segs;
9793         }
9794
9795         /*
9796          * Place digest at the end of the last buffer
9797          */
9798         if (!digest_phys)
9799                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
9800         if (oop && buf_last_oop)
9801                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
9802
9803         if (!digest_mem && !oop) {
9804                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9805                                 + tdata->auth_tag.len);
9806                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
9807                                 tdata->plaintext.len);
9808         }
9809
9810         /* Create AEAD operation */
9811         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
9812                         tdata, digest_mem, digest_phys);
9813
9814         if (retval < 0)
9815                 return retval;
9816
9817         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9818
9819         ut_params->op->sym->m_src = ut_params->ibuf;
9820         if (oop)
9821                 ut_params->op->sym->m_dst = ut_params->obuf;
9822
9823         /* Process crypto operation */
9824         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9825                         ut_params->op), "failed to process sym crypto op");
9826
9827         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9828                         "crypto op processing failed");
9829
9830
9831         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9832                         uint8_t *, prepend_len);
9833         if (oop) {
9834                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9835                                 uint8_t *, prepend_len);
9836         }
9837
9838         if (fragsz_oop)
9839                 fragsz = fragsz_oop;
9840
9841         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9842                         ciphertext,
9843                         tdata->ciphertext.data,
9844                         fragsz,
9845                         "Ciphertext data not as expected");
9846
9847         buf = ut_params->op->sym->m_src->next;
9848         if (oop)
9849                 buf = ut_params->op->sym->m_dst->next;
9850
9851         unsigned int off = fragsz;
9852
9853         ecx = 0;
9854         while (buf) {
9855                 ciphertext = rte_pktmbuf_mtod(buf,
9856                                 uint8_t *);
9857
9858                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
9859                                 ciphertext,
9860                                 tdata->ciphertext.data + off,
9861                                 to_trn_tbl[ecx],
9862                                 "Ciphertext data not as expected");
9863
9864                 off += to_trn_tbl[ecx++];
9865                 buf = buf->next;
9866         }
9867
9868         auth_tag = digest_mem;
9869         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9870                         auth_tag,
9871                         tdata->auth_tag.data,
9872                         tdata->auth_tag.len,
9873                         "Generated auth tag not as expected");
9874
9875         return 0;
9876 }
9877
9878 static int
9879 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
9880 {
9881         return test_authenticated_encryption_SGL(
9882                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
9883 }
9884
9885 static int
9886 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
9887 {
9888         return test_authenticated_encryption_SGL(
9889                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
9890 }
9891
9892 static int
9893 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
9894 {
9895         return test_authenticated_encryption_SGL(
9896                         &gcm_test_case_8, OUT_OF_PLACE, 400,
9897                         gcm_test_case_8.plaintext.len);
9898 }
9899
9900 static int
9901 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
9902 {
9903
9904         return test_authenticated_encryption_SGL(
9905                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
9906 }
9907
9908 static int
9909 test_authentication_verify_fail_when_data_corrupted(
9910                 struct crypto_testsuite_params *ts_params,
9911                 struct crypto_unittest_params *ut_params,
9912                 const struct test_crypto_vector *reference)
9913 {
9914         return test_authentication_verify_fail_when_data_corruption(
9915                         ts_params, ut_params, reference, 1);
9916 }
9917
9918 static int
9919 test_authentication_verify_fail_when_tag_corrupted(
9920                 struct crypto_testsuite_params *ts_params,
9921                 struct crypto_unittest_params *ut_params,
9922                 const struct test_crypto_vector *reference)
9923 {
9924         return test_authentication_verify_fail_when_data_corruption(
9925                         ts_params, ut_params, reference, 0);
9926 }
9927
9928 static int
9929 test_authentication_verify_GMAC_fail_when_data_corrupted(
9930                 struct crypto_testsuite_params *ts_params,
9931                 struct crypto_unittest_params *ut_params,
9932                 const struct test_crypto_vector *reference)
9933 {
9934         return test_authentication_verify_GMAC_fail_when_corruption(
9935                         ts_params, ut_params, reference, 1);
9936 }
9937
9938 static int
9939 test_authentication_verify_GMAC_fail_when_tag_corrupted(
9940                 struct crypto_testsuite_params *ts_params,
9941                 struct crypto_unittest_params *ut_params,
9942                 const struct test_crypto_vector *reference)
9943 {
9944         return test_authentication_verify_GMAC_fail_when_corruption(
9945                         ts_params, ut_params, reference, 0);
9946 }
9947
9948 static int
9949 test_authenticated_decryption_fail_when_data_corrupted(
9950                 struct crypto_testsuite_params *ts_params,
9951                 struct crypto_unittest_params *ut_params,
9952                 const struct test_crypto_vector *reference)
9953 {
9954         return test_authenticated_decryption_fail_when_corruption(
9955                         ts_params, ut_params, reference, 1);
9956 }
9957
9958 static int
9959 test_authenticated_decryption_fail_when_tag_corrupted(
9960                 struct crypto_testsuite_params *ts_params,
9961                 struct crypto_unittest_params *ut_params,
9962                 const struct test_crypto_vector *reference)
9963 {
9964         return test_authenticated_decryption_fail_when_corruption(
9965                         ts_params, ut_params, reference, 0);
9966 }
9967
9968 static int
9969 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
9970 {
9971         return test_authentication_verify_fail_when_data_corrupted(
9972                         &testsuite_params, &unittest_params,
9973                         &hmac_sha1_test_crypto_vector);
9974 }
9975
9976 static int
9977 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
9978 {
9979         return test_authentication_verify_fail_when_tag_corrupted(
9980                         &testsuite_params, &unittest_params,
9981                         &hmac_sha1_test_crypto_vector);
9982 }
9983
9984 static int
9985 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
9986 {
9987         return test_authentication_verify_GMAC_fail_when_data_corrupted(
9988                         &testsuite_params, &unittest_params,
9989                         &aes128_gmac_test_vector);
9990 }
9991
9992 static int
9993 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
9994 {
9995         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
9996                         &testsuite_params, &unittest_params,
9997                         &aes128_gmac_test_vector);
9998 }
9999
10000 static int
10001 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
10002 {
10003         return test_authenticated_decryption_fail_when_data_corrupted(
10004                         &testsuite_params,
10005                         &unittest_params,
10006                         &aes128cbc_hmac_sha1_test_vector);
10007 }
10008
10009 static int
10010 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
10011 {
10012         return test_authenticated_decryption_fail_when_tag_corrupted(
10013                         &testsuite_params,
10014                         &unittest_params,
10015                         &aes128cbc_hmac_sha1_test_vector);
10016 }
10017
10018 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
10019
10020 /* global AESNI slave IDs for the scheduler test */
10021 uint8_t aesni_ids[2];
10022
10023 static int
10024 test_scheduler_attach_slave_op(void)
10025 {
10026         struct crypto_testsuite_params *ts_params = &testsuite_params;
10027         uint8_t sched_id = ts_params->valid_devs[0];
10028         uint32_t nb_devs, i, nb_devs_attached = 0;
10029         int ret;
10030         char vdev_name[32];
10031
10032         /* create 2 AESNI_MB if necessary */
10033         nb_devs = rte_cryptodev_device_count_by_driver(
10034                         rte_cryptodev_driver_id_get(
10035                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
10036         if (nb_devs < 2) {
10037                 for (i = nb_devs; i < 2; i++) {
10038                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
10039                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
10040                                         i);
10041                         ret = rte_vdev_init(vdev_name, NULL);
10042
10043                         TEST_ASSERT(ret == 0,
10044                                 "Failed to create instance %u of"
10045                                 " pmd : %s",
10046                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
10047                 }
10048         }
10049
10050         /* attach 2 AESNI_MB cdevs */
10051         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
10052                         i++) {
10053                 struct rte_cryptodev_info info;
10054                 unsigned int session_size;
10055
10056                 rte_cryptodev_info_get(i, &info);
10057                 if (info.driver_id != rte_cryptodev_driver_id_get(
10058                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
10059                         continue;
10060
10061                 session_size = rte_cryptodev_sym_get_private_session_size(i);
10062                 /*
10063                  * Create the session mempool again, since now there are new devices
10064                  * to use the mempool.
10065                  */
10066                 if (ts_params->session_mpool) {
10067                         rte_mempool_free(ts_params->session_mpool);
10068                         ts_params->session_mpool = NULL;
10069                 }
10070                 if (ts_params->session_priv_mpool) {
10071                         rte_mempool_free(ts_params->session_priv_mpool);
10072                         ts_params->session_priv_mpool = NULL;
10073                 }
10074
10075                 if (info.sym.max_nb_sessions != 0 &&
10076                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
10077                         RTE_LOG(ERR, USER1,
10078                                         "Device does not support "
10079                                         "at least %u sessions\n",
10080                                         MAX_NB_SESSIONS);
10081                         return TEST_FAILED;
10082                 }
10083                 /*
10084                  * Create mempool with maximum number of sessions,
10085                  * to include the session headers
10086                  */
10087                 if (ts_params->session_mpool == NULL) {
10088                         ts_params->session_mpool =
10089                                 rte_cryptodev_sym_session_pool_create(
10090                                                 "test_sess_mp",
10091                                                 MAX_NB_SESSIONS, 0, 0, 0,
10092                                                 SOCKET_ID_ANY);
10093                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
10094                                         "session mempool allocation failed");
10095                 }
10096
10097                 /*
10098                  * Create mempool with maximum number of sessions,
10099                  * to include device specific session private data
10100                  */
10101                 if (ts_params->session_priv_mpool == NULL) {
10102                         ts_params->session_priv_mpool = rte_mempool_create(
10103                                         "test_sess_mp_priv",
10104                                         MAX_NB_SESSIONS,
10105                                         session_size,
10106                                         0, 0, NULL, NULL, NULL,
10107                                         NULL, SOCKET_ID_ANY,
10108                                         0);
10109
10110                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
10111                                         "session mempool allocation failed");
10112                 }
10113
10114                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
10115                 ts_params->qp_conf.mp_session_private =
10116                                 ts_params->session_priv_mpool;
10117
10118                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
10119                                 (uint8_t)i);
10120
10121                 TEST_ASSERT(ret == 0,
10122                         "Failed to attach device %u of pmd : %s", i,
10123                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
10124
10125                 aesni_ids[nb_devs_attached] = (uint8_t)i;
10126
10127                 nb_devs_attached++;
10128         }
10129
10130         return 0;
10131 }
10132
10133 static int
10134 test_scheduler_detach_slave_op(void)
10135 {
10136         struct crypto_testsuite_params *ts_params = &testsuite_params;
10137         uint8_t sched_id = ts_params->valid_devs[0];
10138         uint32_t i;
10139         int ret;
10140
10141         for (i = 0; i < 2; i++) {
10142                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
10143                                 aesni_ids[i]);
10144                 TEST_ASSERT(ret == 0,
10145                         "Failed to detach device %u", aesni_ids[i]);
10146         }
10147
10148         return 0;
10149 }
10150
10151 static int
10152 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
10153 {
10154         struct crypto_testsuite_params *ts_params = &testsuite_params;
10155         uint8_t sched_id = ts_params->valid_devs[0];
10156         /* set mode */
10157         return rte_cryptodev_scheduler_mode_set(sched_id,
10158                 scheduler_mode);
10159 }
10160
10161 static int
10162 test_scheduler_mode_roundrobin_op(void)
10163 {
10164         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
10165                         0, "Failed to set roundrobin mode");
10166         return 0;
10167
10168 }
10169
10170 static int
10171 test_scheduler_mode_multicore_op(void)
10172 {
10173         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
10174                         0, "Failed to set multicore mode");
10175
10176         return 0;
10177 }
10178
10179 static int
10180 test_scheduler_mode_failover_op(void)
10181 {
10182         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
10183                         0, "Failed to set failover mode");
10184
10185         return 0;
10186 }
10187
10188 static int
10189 test_scheduler_mode_pkt_size_distr_op(void)
10190 {
10191         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
10192                         0, "Failed to set pktsize mode");
10193
10194         return 0;
10195 }
10196
10197 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
10198         .suite_name = "Crypto Device Scheduler Unit Test Suite",
10199         .setup = testsuite_setup,
10200         .teardown = testsuite_teardown,
10201         .unit_test_cases = {
10202                 /* Multi Core */
10203                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
10204                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
10205                 TEST_CASE_ST(ut_setup, ut_teardown,
10206                                         test_AES_chain_scheduler_all),
10207                 TEST_CASE_ST(ut_setup, ut_teardown,
10208                                         test_AES_cipheronly_scheduler_all),
10209                 TEST_CASE_ST(ut_setup, ut_teardown,
10210                                         test_authonly_scheduler_all),
10211                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
10212
10213                 /* Round Robin */
10214                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
10215                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
10216                 TEST_CASE_ST(ut_setup, ut_teardown,
10217                                 test_AES_chain_scheduler_all),
10218                 TEST_CASE_ST(ut_setup, ut_teardown,
10219                                 test_AES_cipheronly_scheduler_all),
10220                 TEST_CASE_ST(ut_setup, ut_teardown,
10221                                 test_authonly_scheduler_all),
10222                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
10223
10224                 /* Fail over */
10225                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
10226                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
10227                 TEST_CASE_ST(ut_setup, ut_teardown,
10228                                         test_AES_chain_scheduler_all),
10229                 TEST_CASE_ST(ut_setup, ut_teardown,
10230                                         test_AES_cipheronly_scheduler_all),
10231                 TEST_CASE_ST(ut_setup, ut_teardown,
10232                                         test_authonly_scheduler_all),
10233                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
10234
10235                 /* PKT SIZE */
10236                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
10237                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
10238                 TEST_CASE_ST(ut_setup, ut_teardown,
10239                                         test_AES_chain_scheduler_all),
10240                 TEST_CASE_ST(ut_setup, ut_teardown,
10241                                         test_AES_cipheronly_scheduler_all),
10242                 TEST_CASE_ST(ut_setup, ut_teardown,
10243                                         test_authonly_scheduler_all),
10244                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
10245
10246                 TEST_CASES_END() /**< NULL terminate unit test array */
10247         }
10248 };
10249
10250 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
10251
10252 static struct unit_test_suite cryptodev_qat_testsuite  = {
10253         .suite_name = "Crypto QAT Unit Test Suite",
10254         .setup = testsuite_setup,
10255         .teardown = testsuite_teardown,
10256         .unit_test_cases = {
10257                 TEST_CASE_ST(ut_setup, ut_teardown,
10258                                 test_device_configure_invalid_dev_id),
10259                 TEST_CASE_ST(ut_setup, ut_teardown,
10260                                 test_device_configure_invalid_queue_pair_ids),
10261                 TEST_CASE_ST(ut_setup, ut_teardown,
10262                                 test_queue_pair_descriptor_setup),
10263                 TEST_CASE_ST(ut_setup, ut_teardown,
10264                                 test_multi_session),
10265
10266                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
10267                 TEST_CASE_ST(ut_setup, ut_teardown,
10268                                                 test_AES_cipheronly_qat_all),
10269                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
10270                 TEST_CASE_ST(ut_setup, ut_teardown,
10271                                                 test_3DES_cipheronly_qat_all),
10272                 TEST_CASE_ST(ut_setup, ut_teardown,
10273                                                 test_DES_cipheronly_qat_all),
10274                 TEST_CASE_ST(ut_setup, ut_teardown,
10275                                                 test_AES_docsis_qat_all),
10276                 TEST_CASE_ST(ut_setup, ut_teardown,
10277                                                 test_DES_docsis_qat_all),
10278                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_qat_all),
10279                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
10280
10281                 /** AES CCM Authenticated Encryption 128 bits key */
10282                 TEST_CASE_ST(ut_setup, ut_teardown,
10283                         test_AES_CCM_authenticated_encryption_test_case_128_1),
10284                 TEST_CASE_ST(ut_setup, ut_teardown,
10285                         test_AES_CCM_authenticated_encryption_test_case_128_2),
10286                 TEST_CASE_ST(ut_setup, ut_teardown,
10287                         test_AES_CCM_authenticated_encryption_test_case_128_3),
10288
10289                 /** AES CCM Authenticated Decryption 128 bits key*/
10290                 TEST_CASE_ST(ut_setup, ut_teardown,
10291                         test_AES_CCM_authenticated_decryption_test_case_128_1),
10292                 TEST_CASE_ST(ut_setup, ut_teardown,
10293                         test_AES_CCM_authenticated_decryption_test_case_128_2),
10294                 TEST_CASE_ST(ut_setup, ut_teardown,
10295                         test_AES_CCM_authenticated_decryption_test_case_128_3),
10296
10297                 /** AES GCM Authenticated Encryption */
10298                 TEST_CASE_ST(ut_setup, ut_teardown,
10299                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
10300                 TEST_CASE_ST(ut_setup, ut_teardown,
10301                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
10302                 TEST_CASE_ST(ut_setup, ut_teardown,
10303                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
10304                 TEST_CASE_ST(ut_setup, ut_teardown,
10305                         test_AES_GCM_authenticated_encryption_test_case_1),
10306                 TEST_CASE_ST(ut_setup, ut_teardown,
10307                         test_AES_GCM_authenticated_encryption_test_case_2),
10308                 TEST_CASE_ST(ut_setup, ut_teardown,
10309                         test_AES_GCM_authenticated_encryption_test_case_3),
10310                 TEST_CASE_ST(ut_setup, ut_teardown,
10311                         test_AES_GCM_authenticated_encryption_test_case_4),
10312                 TEST_CASE_ST(ut_setup, ut_teardown,
10313                         test_AES_GCM_authenticated_encryption_test_case_5),
10314                 TEST_CASE_ST(ut_setup, ut_teardown,
10315                         test_AES_GCM_authenticated_encryption_test_case_6),
10316                 TEST_CASE_ST(ut_setup, ut_teardown,
10317                         test_AES_GCM_authenticated_encryption_test_case_7),
10318
10319                 /** AES GCM Authenticated Decryption */
10320                 TEST_CASE_ST(ut_setup, ut_teardown,
10321                         test_AES_GCM_authenticated_decryption_test_case_1),
10322                 TEST_CASE_ST(ut_setup, ut_teardown,
10323                         test_AES_GCM_authenticated_decryption_test_case_2),
10324                 TEST_CASE_ST(ut_setup, ut_teardown,
10325                         test_AES_GCM_authenticated_decryption_test_case_3),
10326                 TEST_CASE_ST(ut_setup, ut_teardown,
10327                         test_AES_GCM_authenticated_decryption_test_case_4),
10328                 TEST_CASE_ST(ut_setup, ut_teardown,
10329                         test_AES_GCM_authenticated_decryption_test_case_5),
10330                 TEST_CASE_ST(ut_setup, ut_teardown,
10331                         test_AES_GCM_authenticated_decryption_test_case_6),
10332                 TEST_CASE_ST(ut_setup, ut_teardown,
10333                         test_AES_GCM_authenticated_decryption_test_case_7),
10334
10335                 /** AES GCM Authenticated Encryption 192 bits key */
10336                 TEST_CASE_ST(ut_setup, ut_teardown,
10337                         test_AES_GCM_auth_encryption_test_case_192_1),
10338                 TEST_CASE_ST(ut_setup, ut_teardown,
10339                         test_AES_GCM_auth_encryption_test_case_192_2),
10340                 TEST_CASE_ST(ut_setup, ut_teardown,
10341                         test_AES_GCM_auth_encryption_test_case_192_3),
10342                 TEST_CASE_ST(ut_setup, ut_teardown,
10343                         test_AES_GCM_auth_encryption_test_case_192_4),
10344                 TEST_CASE_ST(ut_setup, ut_teardown,
10345                         test_AES_GCM_auth_encryption_test_case_192_5),
10346                 TEST_CASE_ST(ut_setup, ut_teardown,
10347                         test_AES_GCM_auth_encryption_test_case_192_6),
10348                 TEST_CASE_ST(ut_setup, ut_teardown,
10349                         test_AES_GCM_auth_encryption_test_case_192_7),
10350
10351                 /** AES GCM Authenticated Decryption 192 bits key */
10352                 TEST_CASE_ST(ut_setup, ut_teardown,
10353                         test_AES_GCM_auth_decryption_test_case_192_1),
10354                 TEST_CASE_ST(ut_setup, ut_teardown,
10355                         test_AES_GCM_auth_decryption_test_case_192_2),
10356                 TEST_CASE_ST(ut_setup, ut_teardown,
10357                         test_AES_GCM_auth_decryption_test_case_192_3),
10358                 TEST_CASE_ST(ut_setup, ut_teardown,
10359                         test_AES_GCM_auth_decryption_test_case_192_4),
10360                 TEST_CASE_ST(ut_setup, ut_teardown,
10361                         test_AES_GCM_auth_decryption_test_case_192_5),
10362                 TEST_CASE_ST(ut_setup, ut_teardown,
10363                         test_AES_GCM_auth_decryption_test_case_192_6),
10364                 TEST_CASE_ST(ut_setup, ut_teardown,
10365                         test_AES_GCM_auth_decryption_test_case_192_7),
10366
10367                 /** AES GCM Authenticated Encryption 256 bits key */
10368                 TEST_CASE_ST(ut_setup, ut_teardown,
10369                         test_AES_GCM_auth_encryption_test_case_256_1),
10370                 TEST_CASE_ST(ut_setup, ut_teardown,
10371                         test_AES_GCM_auth_encryption_test_case_256_2),
10372                 TEST_CASE_ST(ut_setup, ut_teardown,
10373                         test_AES_GCM_auth_encryption_test_case_256_3),
10374                 TEST_CASE_ST(ut_setup, ut_teardown,
10375                         test_AES_GCM_auth_encryption_test_case_256_4),
10376                 TEST_CASE_ST(ut_setup, ut_teardown,
10377                         test_AES_GCM_auth_encryption_test_case_256_5),
10378                 TEST_CASE_ST(ut_setup, ut_teardown,
10379                         test_AES_GCM_auth_encryption_test_case_256_6),
10380                 TEST_CASE_ST(ut_setup, ut_teardown,
10381                         test_AES_GCM_auth_encryption_test_case_256_7),
10382
10383                 /** AES GMAC Authentication */
10384                 TEST_CASE_ST(ut_setup, ut_teardown,
10385                         test_AES_GMAC_authentication_test_case_1),
10386                 TEST_CASE_ST(ut_setup, ut_teardown,
10387                         test_AES_GMAC_authentication_verify_test_case_1),
10388                 TEST_CASE_ST(ut_setup, ut_teardown,
10389                         test_AES_GMAC_authentication_test_case_2),
10390                 TEST_CASE_ST(ut_setup, ut_teardown,
10391                         test_AES_GMAC_authentication_verify_test_case_2),
10392                 TEST_CASE_ST(ut_setup, ut_teardown,
10393                         test_AES_GMAC_authentication_test_case_3),
10394                 TEST_CASE_ST(ut_setup, ut_teardown,
10395                         test_AES_GMAC_authentication_verify_test_case_3),
10396
10397                 /** SNOW 3G encrypt only (UEA2) */
10398                 TEST_CASE_ST(ut_setup, ut_teardown,
10399                         test_snow3g_encryption_test_case_1),
10400                 TEST_CASE_ST(ut_setup, ut_teardown,
10401                         test_snow3g_encryption_test_case_2),
10402                 TEST_CASE_ST(ut_setup, ut_teardown,
10403                         test_snow3g_encryption_test_case_3),
10404                 TEST_CASE_ST(ut_setup, ut_teardown,
10405                         test_snow3g_encryption_test_case_4),
10406                 TEST_CASE_ST(ut_setup, ut_teardown,
10407                         test_snow3g_encryption_test_case_5),
10408
10409                 TEST_CASE_ST(ut_setup, ut_teardown,
10410                         test_snow3g_encryption_test_case_1_oop),
10411                 TEST_CASE_ST(ut_setup, ut_teardown,
10412                         test_snow3g_decryption_test_case_1_oop),
10413
10414                 /** SNOW 3G generate auth, then encrypt (UEA2) */
10415                 TEST_CASE_ST(ut_setup, ut_teardown,
10416                         test_snow3g_auth_cipher_test_case_1),
10417                 TEST_CASE_ST(ut_setup, ut_teardown,
10418                         test_snow3g_auth_cipher_test_case_2),
10419                 TEST_CASE_ST(ut_setup, ut_teardown,
10420                         test_snow3g_auth_cipher_test_case_2_oop),
10421                 TEST_CASE_ST(ut_setup, ut_teardown,
10422                         test_snow3g_auth_cipher_part_digest_enc),
10423                 TEST_CASE_ST(ut_setup, ut_teardown,
10424                         test_snow3g_auth_cipher_part_digest_enc_oop),
10425                 TEST_CASE_ST(ut_setup, ut_teardown,
10426                         test_snow3g_auth_cipher_test_case_3_sgl),
10427                 TEST_CASE_ST(ut_setup, ut_teardown,
10428                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
10429                 TEST_CASE_ST(ut_setup, ut_teardown,
10430                         test_snow3g_auth_cipher_part_digest_enc_sgl),
10431                 TEST_CASE_ST(ut_setup, ut_teardown,
10432                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
10433
10434                 /** SNOW 3G decrypt (UEA2), then verify auth */
10435                 TEST_CASE_ST(ut_setup, ut_teardown,
10436                         test_snow3g_auth_cipher_verify_test_case_1),
10437                 TEST_CASE_ST(ut_setup, ut_teardown,
10438                         test_snow3g_auth_cipher_verify_test_case_2),
10439                 TEST_CASE_ST(ut_setup, ut_teardown,
10440                         test_snow3g_auth_cipher_verify_test_case_2_oop),
10441                 TEST_CASE_ST(ut_setup, ut_teardown,
10442                         test_snow3g_auth_cipher_verify_part_digest_enc),
10443                 TEST_CASE_ST(ut_setup, ut_teardown,
10444                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
10445                 TEST_CASE_ST(ut_setup, ut_teardown,
10446                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
10447                 TEST_CASE_ST(ut_setup, ut_teardown,
10448                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
10449                 TEST_CASE_ST(ut_setup, ut_teardown,
10450                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
10451                 TEST_CASE_ST(ut_setup, ut_teardown,
10452                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
10453
10454                 /** SNOW 3G decrypt only (UEA2) */
10455                 TEST_CASE_ST(ut_setup, ut_teardown,
10456                         test_snow3g_decryption_test_case_1),
10457                 TEST_CASE_ST(ut_setup, ut_teardown,
10458                         test_snow3g_decryption_test_case_2),
10459                 TEST_CASE_ST(ut_setup, ut_teardown,
10460                         test_snow3g_decryption_test_case_3),
10461                 TEST_CASE_ST(ut_setup, ut_teardown,
10462                         test_snow3g_decryption_test_case_4),
10463                 TEST_CASE_ST(ut_setup, ut_teardown,
10464                         test_snow3g_decryption_test_case_5),
10465                 TEST_CASE_ST(ut_setup, ut_teardown,
10466                         test_snow3g_decryption_with_digest_test_case_1),
10467                 TEST_CASE_ST(ut_setup, ut_teardown,
10468                         test_snow3g_hash_generate_test_case_1),
10469                 TEST_CASE_ST(ut_setup, ut_teardown,
10470                         test_snow3g_hash_generate_test_case_2),
10471                 TEST_CASE_ST(ut_setup, ut_teardown,
10472                         test_snow3g_hash_generate_test_case_3),
10473                 TEST_CASE_ST(ut_setup, ut_teardown,
10474                         test_snow3g_hash_verify_test_case_1),
10475                 TEST_CASE_ST(ut_setup, ut_teardown,
10476                         test_snow3g_hash_verify_test_case_2),
10477                 TEST_CASE_ST(ut_setup, ut_teardown,
10478                         test_snow3g_hash_verify_test_case_3),
10479                 TEST_CASE_ST(ut_setup, ut_teardown,
10480                         test_snow3g_cipher_auth_test_case_1),
10481                 TEST_CASE_ST(ut_setup, ut_teardown,
10482                         test_snow3g_auth_cipher_with_digest_test_case_1),
10483
10484                 /** ZUC encrypt only (EEA3) */
10485                 TEST_CASE_ST(ut_setup, ut_teardown,
10486                         test_zuc_encryption_test_case_1),
10487                 TEST_CASE_ST(ut_setup, ut_teardown,
10488                         test_zuc_encryption_test_case_2),
10489                 TEST_CASE_ST(ut_setup, ut_teardown,
10490                         test_zuc_encryption_test_case_3),
10491                 TEST_CASE_ST(ut_setup, ut_teardown,
10492                         test_zuc_encryption_test_case_4),
10493                 TEST_CASE_ST(ut_setup, ut_teardown,
10494                         test_zuc_encryption_test_case_5),
10495
10496                 /** ZUC authenticate (EIA3) */
10497                 TEST_CASE_ST(ut_setup, ut_teardown,
10498                         test_zuc_hash_generate_test_case_6),
10499                 TEST_CASE_ST(ut_setup, ut_teardown,
10500                         test_zuc_hash_generate_test_case_7),
10501                 TEST_CASE_ST(ut_setup, ut_teardown,
10502                         test_zuc_hash_generate_test_case_8),
10503
10504                 /** ZUC alg-chain (EEA3/EIA3) */
10505                 TEST_CASE_ST(ut_setup, ut_teardown,
10506                         test_zuc_cipher_auth_test_case_1),
10507                 TEST_CASE_ST(ut_setup, ut_teardown,
10508                         test_zuc_cipher_auth_test_case_2),
10509
10510                 /** ZUC generate auth, then encrypt (EEA3) */
10511                 TEST_CASE_ST(ut_setup, ut_teardown,
10512                         test_zuc_auth_cipher_test_case_1),
10513                 TEST_CASE_ST(ut_setup, ut_teardown,
10514                         test_zuc_auth_cipher_test_case_1_oop),
10515                 TEST_CASE_ST(ut_setup, ut_teardown,
10516                         test_zuc_auth_cipher_test_case_1_sgl),
10517                 TEST_CASE_ST(ut_setup, ut_teardown,
10518                         test_zuc_auth_cipher_test_case_1_oop_sgl),
10519
10520                 /** ZUC decrypt (EEA3), then verify auth */
10521                 TEST_CASE_ST(ut_setup, ut_teardown,
10522                         test_zuc_auth_cipher_verify_test_case_1),
10523                 TEST_CASE_ST(ut_setup, ut_teardown,
10524                         test_zuc_auth_cipher_verify_test_case_1_oop),
10525                 TEST_CASE_ST(ut_setup, ut_teardown,
10526                         test_zuc_auth_cipher_verify_test_case_1_sgl),
10527                 TEST_CASE_ST(ut_setup, ut_teardown,
10528                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
10529
10530                 /** HMAC_MD5 Authentication */
10531                 TEST_CASE_ST(ut_setup, ut_teardown,
10532                         test_MD5_HMAC_generate_case_1),
10533                 TEST_CASE_ST(ut_setup, ut_teardown,
10534                         test_MD5_HMAC_verify_case_1),
10535                 TEST_CASE_ST(ut_setup, ut_teardown,
10536                         test_MD5_HMAC_generate_case_2),
10537                 TEST_CASE_ST(ut_setup, ut_teardown,
10538                         test_MD5_HMAC_verify_case_2),
10539
10540                 /** NULL algo tests done in chain_all,
10541                  * cipheronly and authonly suites
10542                  */
10543
10544                 /** KASUMI tests */
10545                 TEST_CASE_ST(ut_setup, ut_teardown,
10546                         test_kasumi_hash_generate_test_case_1),
10547                 TEST_CASE_ST(ut_setup, ut_teardown,
10548                         test_kasumi_hash_generate_test_case_2),
10549                 TEST_CASE_ST(ut_setup, ut_teardown,
10550                         test_kasumi_hash_generate_test_case_3),
10551                 TEST_CASE_ST(ut_setup, ut_teardown,
10552                         test_kasumi_hash_generate_test_case_4),
10553                 TEST_CASE_ST(ut_setup, ut_teardown,
10554                         test_kasumi_hash_generate_test_case_5),
10555                 TEST_CASE_ST(ut_setup, ut_teardown,
10556                         test_kasumi_hash_generate_test_case_6),
10557
10558                 TEST_CASE_ST(ut_setup, ut_teardown,
10559                         test_kasumi_hash_verify_test_case_1),
10560                 TEST_CASE_ST(ut_setup, ut_teardown,
10561                         test_kasumi_hash_verify_test_case_2),
10562                 TEST_CASE_ST(ut_setup, ut_teardown,
10563                         test_kasumi_hash_verify_test_case_3),
10564                 TEST_CASE_ST(ut_setup, ut_teardown,
10565                         test_kasumi_hash_verify_test_case_4),
10566                 TEST_CASE_ST(ut_setup, ut_teardown,
10567                         test_kasumi_hash_verify_test_case_5),
10568
10569                 TEST_CASE_ST(ut_setup, ut_teardown,
10570                         test_kasumi_encryption_test_case_1),
10571                 TEST_CASE_ST(ut_setup, ut_teardown,
10572                         test_kasumi_encryption_test_case_3),
10573                 TEST_CASE_ST(ut_setup, ut_teardown,
10574                         test_kasumi_cipher_auth_test_case_1),
10575
10576                 /** KASUMI generate auth, then encrypt (F8) */
10577                 TEST_CASE_ST(ut_setup, ut_teardown,
10578                         test_kasumi_auth_cipher_test_case_1),
10579                 TEST_CASE_ST(ut_setup, ut_teardown,
10580                         test_kasumi_auth_cipher_test_case_2),
10581                 TEST_CASE_ST(ut_setup, ut_teardown,
10582                         test_kasumi_auth_cipher_test_case_2_oop),
10583                 TEST_CASE_ST(ut_setup, ut_teardown,
10584                         test_kasumi_auth_cipher_test_case_2_sgl),
10585                 TEST_CASE_ST(ut_setup, ut_teardown,
10586                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
10587
10588                 /** KASUMI decrypt (F8), then verify auth */
10589                 TEST_CASE_ST(ut_setup, ut_teardown,
10590                         test_kasumi_auth_cipher_verify_test_case_1),
10591                 TEST_CASE_ST(ut_setup, ut_teardown,
10592                         test_kasumi_auth_cipher_verify_test_case_2),
10593                 TEST_CASE_ST(ut_setup, ut_teardown,
10594                         test_kasumi_auth_cipher_verify_test_case_2_oop),
10595                 TEST_CASE_ST(ut_setup, ut_teardown,
10596                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
10597                 TEST_CASE_ST(ut_setup, ut_teardown,
10598                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
10599
10600                 /** Negative tests */
10601                 TEST_CASE_ST(ut_setup, ut_teardown,
10602                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
10603                 TEST_CASE_ST(ut_setup, ut_teardown,
10604                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
10605                 TEST_CASE_ST(ut_setup, ut_teardown,
10606                         authentication_verify_AES128_GMAC_fail_data_corrupt),
10607                 TEST_CASE_ST(ut_setup, ut_teardown,
10608                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
10609                 TEST_CASE_ST(ut_setup, ut_teardown,
10610                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
10611                 TEST_CASE_ST(ut_setup, ut_teardown,
10612                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
10613
10614                 TEST_CASES_END() /**< NULL terminate unit test array */
10615         }
10616 };
10617
10618 static struct unit_test_suite cryptodev_virtio_testsuite = {
10619         .suite_name = "Crypto VIRTIO Unit Test Suite",
10620         .setup = testsuite_setup,
10621         .teardown = testsuite_teardown,
10622         .unit_test_cases = {
10623                 TEST_CASE_ST(ut_setup, ut_teardown,
10624                                 test_AES_cipheronly_virtio_all),
10625
10626                 TEST_CASES_END() /**< NULL terminate unit test array */
10627         }
10628 };
10629
10630 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
10631         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
10632         .setup = testsuite_setup,
10633         .teardown = testsuite_teardown,
10634         .unit_test_cases = {
10635 #if IMB_VERSION_NUM >= IMB_VERSION(0, 51, 0)
10636                 TEST_CASE_ST(ut_setup, ut_teardown,
10637                         test_AES_GCM_authenticated_encryption_test_case_1),
10638                 TEST_CASE_ST(ut_setup, ut_teardown,
10639                         test_AES_GCM_authenticated_encryption_test_case_2),
10640                 TEST_CASE_ST(ut_setup, ut_teardown,
10641                         test_AES_GCM_authenticated_encryption_test_case_3),
10642                 TEST_CASE_ST(ut_setup, ut_teardown,
10643                         test_AES_GCM_authenticated_encryption_test_case_4),
10644                 TEST_CASE_ST(ut_setup, ut_teardown,
10645                         test_AES_GCM_authenticated_encryption_test_case_5),
10646                 TEST_CASE_ST(ut_setup, ut_teardown,
10647                         test_AES_GCM_authenticated_encryption_test_case_6),
10648                 TEST_CASE_ST(ut_setup, ut_teardown,
10649                         test_AES_GCM_authenticated_encryption_test_case_7),
10650
10651                 /** AES GCM Authenticated Decryption */
10652                 TEST_CASE_ST(ut_setup, ut_teardown,
10653                         test_AES_GCM_authenticated_decryption_test_case_1),
10654                 TEST_CASE_ST(ut_setup, ut_teardown,
10655                         test_AES_GCM_authenticated_decryption_test_case_2),
10656                 TEST_CASE_ST(ut_setup, ut_teardown,
10657                         test_AES_GCM_authenticated_decryption_test_case_3),
10658                 TEST_CASE_ST(ut_setup, ut_teardown,
10659                         test_AES_GCM_authenticated_decryption_test_case_4),
10660                 TEST_CASE_ST(ut_setup, ut_teardown,
10661                         test_AES_GCM_authenticated_decryption_test_case_5),
10662                 TEST_CASE_ST(ut_setup, ut_teardown,
10663                         test_AES_GCM_authenticated_decryption_test_case_6),
10664                 TEST_CASE_ST(ut_setup, ut_teardown,
10665                         test_AES_GCM_authenticated_decryption_test_case_7),
10666
10667                 /** AES GCM Authenticated Encryption 192 bits key */
10668                 TEST_CASE_ST(ut_setup, ut_teardown,
10669                         test_AES_GCM_auth_encryption_test_case_192_1),
10670                 TEST_CASE_ST(ut_setup, ut_teardown,
10671                         test_AES_GCM_auth_encryption_test_case_192_2),
10672                 TEST_CASE_ST(ut_setup, ut_teardown,
10673                         test_AES_GCM_auth_encryption_test_case_192_3),
10674                 TEST_CASE_ST(ut_setup, ut_teardown,
10675                         test_AES_GCM_auth_encryption_test_case_192_4),
10676                 TEST_CASE_ST(ut_setup, ut_teardown,
10677                         test_AES_GCM_auth_encryption_test_case_192_5),
10678                 TEST_CASE_ST(ut_setup, ut_teardown,
10679                         test_AES_GCM_auth_encryption_test_case_192_6),
10680                 TEST_CASE_ST(ut_setup, ut_teardown,
10681                         test_AES_GCM_auth_encryption_test_case_192_7),
10682
10683                 /** AES GCM Authenticated Decryption 192 bits key */
10684                 TEST_CASE_ST(ut_setup, ut_teardown,
10685                         test_AES_GCM_auth_decryption_test_case_192_1),
10686                 TEST_CASE_ST(ut_setup, ut_teardown,
10687                         test_AES_GCM_auth_decryption_test_case_192_2),
10688                 TEST_CASE_ST(ut_setup, ut_teardown,
10689                         test_AES_GCM_auth_decryption_test_case_192_3),
10690                 TEST_CASE_ST(ut_setup, ut_teardown,
10691                         test_AES_GCM_auth_decryption_test_case_192_4),
10692                 TEST_CASE_ST(ut_setup, ut_teardown,
10693                         test_AES_GCM_auth_decryption_test_case_192_5),
10694                 TEST_CASE_ST(ut_setup, ut_teardown,
10695                         test_AES_GCM_auth_decryption_test_case_192_6),
10696                 TEST_CASE_ST(ut_setup, ut_teardown,
10697                         test_AES_GCM_auth_decryption_test_case_192_7),
10698
10699                 /** AES GCM Authenticated Encryption 256 bits key */
10700                 TEST_CASE_ST(ut_setup, ut_teardown,
10701                         test_AES_GCM_auth_encryption_test_case_256_1),
10702                 TEST_CASE_ST(ut_setup, ut_teardown,
10703                         test_AES_GCM_auth_encryption_test_case_256_2),
10704                 TEST_CASE_ST(ut_setup, ut_teardown,
10705                         test_AES_GCM_auth_encryption_test_case_256_3),
10706                 TEST_CASE_ST(ut_setup, ut_teardown,
10707                         test_AES_GCM_auth_encryption_test_case_256_4),
10708                 TEST_CASE_ST(ut_setup, ut_teardown,
10709                         test_AES_GCM_auth_encryption_test_case_256_5),
10710                 TEST_CASE_ST(ut_setup, ut_teardown,
10711                         test_AES_GCM_auth_encryption_test_case_256_6),
10712                 TEST_CASE_ST(ut_setup, ut_teardown,
10713                         test_AES_GCM_auth_encryption_test_case_256_7),
10714
10715                 /** AES GCM Authenticated Decryption 256 bits key */
10716                 TEST_CASE_ST(ut_setup, ut_teardown,
10717                         test_AES_GCM_auth_decryption_test_case_256_1),
10718                 TEST_CASE_ST(ut_setup, ut_teardown,
10719                         test_AES_GCM_auth_decryption_test_case_256_2),
10720                 TEST_CASE_ST(ut_setup, ut_teardown,
10721                         test_AES_GCM_auth_decryption_test_case_256_3),
10722                 TEST_CASE_ST(ut_setup, ut_teardown,
10723                         test_AES_GCM_auth_decryption_test_case_256_4),
10724                 TEST_CASE_ST(ut_setup, ut_teardown,
10725                         test_AES_GCM_auth_decryption_test_case_256_5),
10726                 TEST_CASE_ST(ut_setup, ut_teardown,
10727                         test_AES_GCM_auth_decryption_test_case_256_6),
10728                 TEST_CASE_ST(ut_setup, ut_teardown,
10729                         test_AES_GCM_auth_decryption_test_case_256_7),
10730
10731                 /** AES GCM Authenticated Encryption big aad size */
10732                 TEST_CASE_ST(ut_setup, ut_teardown,
10733                         test_AES_GCM_auth_encryption_test_case_aad_1),
10734                 TEST_CASE_ST(ut_setup, ut_teardown,
10735                         test_AES_GCM_auth_encryption_test_case_aad_2),
10736
10737                 /** AES GCM Authenticated Decryption big aad size */
10738                 TEST_CASE_ST(ut_setup, ut_teardown,
10739                         test_AES_GCM_auth_decryption_test_case_aad_1),
10740                 TEST_CASE_ST(ut_setup, ut_teardown,
10741                         test_AES_GCM_auth_decryption_test_case_aad_2),
10742
10743                 /** Session-less tests */
10744                 TEST_CASE_ST(ut_setup, ut_teardown,
10745                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
10746                 TEST_CASE_ST(ut_setup, ut_teardown,
10747                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
10748
10749                 /** AES GMAC Authentication */
10750                 TEST_CASE_ST(ut_setup, ut_teardown,
10751                         test_AES_GMAC_authentication_test_case_1),
10752                 TEST_CASE_ST(ut_setup, ut_teardown,
10753                         test_AES_GMAC_authentication_verify_test_case_1),
10754                 TEST_CASE_ST(ut_setup, ut_teardown,
10755                         test_AES_GMAC_authentication_test_case_2),
10756                 TEST_CASE_ST(ut_setup, ut_teardown,
10757                         test_AES_GMAC_authentication_verify_test_case_2),
10758                 TEST_CASE_ST(ut_setup, ut_teardown,
10759                         test_AES_GMAC_authentication_test_case_3),
10760                 TEST_CASE_ST(ut_setup, ut_teardown,
10761                         test_AES_GMAC_authentication_verify_test_case_3),
10762 #endif /* IMB_VERSION_NUM >= IMB_VERSION(0, 51, 0) */
10763
10764                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
10765                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
10766                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
10767                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
10768                 TEST_CASE_ST(ut_setup, ut_teardown,
10769                                                 test_DES_cipheronly_mb_all),
10770                 TEST_CASE_ST(ut_setup, ut_teardown,
10771                                                 test_DES_docsis_mb_all),
10772                 TEST_CASE_ST(ut_setup, ut_teardown,
10773                                                 test_3DES_cipheronly_mb_all),
10774                 TEST_CASE_ST(ut_setup, ut_teardown,
10775                         test_AES_CCM_authenticated_encryption_test_case_128_1),
10776                 TEST_CASE_ST(ut_setup, ut_teardown,
10777                         test_AES_CCM_authenticated_decryption_test_case_128_1),
10778                 TEST_CASE_ST(ut_setup, ut_teardown,
10779                         test_AES_CCM_authenticated_encryption_test_case_128_2),
10780                 TEST_CASE_ST(ut_setup, ut_teardown,
10781                         test_AES_CCM_authenticated_decryption_test_case_128_2),
10782                 TEST_CASE_ST(ut_setup, ut_teardown,
10783                         test_AES_CCM_authenticated_encryption_test_case_128_3),
10784                 TEST_CASE_ST(ut_setup, ut_teardown,
10785                         test_AES_CCM_authenticated_decryption_test_case_128_3),
10786
10787                 TEST_CASES_END() /**< NULL terminate unit test array */
10788         }
10789 };
10790
10791 static struct unit_test_suite cryptodev_openssl_testsuite  = {
10792         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
10793         .setup = testsuite_setup,
10794         .teardown = testsuite_teardown,
10795         .unit_test_cases = {
10796                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
10797                 TEST_CASE_ST(ut_setup, ut_teardown,
10798                                 test_multi_session_random_usage),
10799                 TEST_CASE_ST(ut_setup, ut_teardown,
10800                                 test_AES_chain_openssl_all),
10801                 TEST_CASE_ST(ut_setup, ut_teardown,
10802                                 test_AES_cipheronly_openssl_all),
10803                 TEST_CASE_ST(ut_setup, ut_teardown,
10804                                 test_3DES_chain_openssl_all),
10805                 TEST_CASE_ST(ut_setup, ut_teardown,
10806                                 test_3DES_cipheronly_openssl_all),
10807                 TEST_CASE_ST(ut_setup, ut_teardown,
10808                                 test_DES_cipheronly_openssl_all),
10809                 TEST_CASE_ST(ut_setup, ut_teardown,
10810                                 test_DES_docsis_openssl_all),
10811                 TEST_CASE_ST(ut_setup, ut_teardown,
10812                                 test_authonly_openssl_all),
10813
10814                 /** AES GCM Authenticated Encryption */
10815                 TEST_CASE_ST(ut_setup, ut_teardown,
10816                         test_AES_GCM_authenticated_encryption_test_case_1),
10817                 TEST_CASE_ST(ut_setup, ut_teardown,
10818                         test_AES_GCM_authenticated_encryption_test_case_2),
10819                 TEST_CASE_ST(ut_setup, ut_teardown,
10820                         test_AES_GCM_authenticated_encryption_test_case_3),
10821                 TEST_CASE_ST(ut_setup, ut_teardown,
10822                         test_AES_GCM_authenticated_encryption_test_case_4),
10823                 TEST_CASE_ST(ut_setup, ut_teardown,
10824                         test_AES_GCM_authenticated_encryption_test_case_5),
10825                 TEST_CASE_ST(ut_setup, ut_teardown,
10826                         test_AES_GCM_authenticated_encryption_test_case_6),
10827                 TEST_CASE_ST(ut_setup, ut_teardown,
10828                         test_AES_GCM_authenticated_encryption_test_case_7),
10829
10830                 /** AES GCM Authenticated Decryption */
10831                 TEST_CASE_ST(ut_setup, ut_teardown,
10832                         test_AES_GCM_authenticated_decryption_test_case_1),
10833                 TEST_CASE_ST(ut_setup, ut_teardown,
10834                         test_AES_GCM_authenticated_decryption_test_case_2),
10835                 TEST_CASE_ST(ut_setup, ut_teardown,
10836                         test_AES_GCM_authenticated_decryption_test_case_3),
10837                 TEST_CASE_ST(ut_setup, ut_teardown,
10838                         test_AES_GCM_authenticated_decryption_test_case_4),
10839                 TEST_CASE_ST(ut_setup, ut_teardown,
10840                         test_AES_GCM_authenticated_decryption_test_case_5),
10841                 TEST_CASE_ST(ut_setup, ut_teardown,
10842                         test_AES_GCM_authenticated_decryption_test_case_6),
10843                 TEST_CASE_ST(ut_setup, ut_teardown,
10844                         test_AES_GCM_authenticated_decryption_test_case_7),
10845
10846
10847                 /** AES GCM Authenticated Encryption 192 bits key */
10848                 TEST_CASE_ST(ut_setup, ut_teardown,
10849                         test_AES_GCM_auth_encryption_test_case_192_1),
10850                 TEST_CASE_ST(ut_setup, ut_teardown,
10851                         test_AES_GCM_auth_encryption_test_case_192_2),
10852                 TEST_CASE_ST(ut_setup, ut_teardown,
10853                         test_AES_GCM_auth_encryption_test_case_192_3),
10854                 TEST_CASE_ST(ut_setup, ut_teardown,
10855                         test_AES_GCM_auth_encryption_test_case_192_4),
10856                 TEST_CASE_ST(ut_setup, ut_teardown,
10857                         test_AES_GCM_auth_encryption_test_case_192_5),
10858                 TEST_CASE_ST(ut_setup, ut_teardown,
10859                         test_AES_GCM_auth_encryption_test_case_192_6),
10860                 TEST_CASE_ST(ut_setup, ut_teardown,
10861                         test_AES_GCM_auth_encryption_test_case_192_7),
10862
10863                 /** AES GCM Authenticated Decryption 192 bits key */
10864                 TEST_CASE_ST(ut_setup, ut_teardown,
10865                         test_AES_GCM_auth_decryption_test_case_192_1),
10866                 TEST_CASE_ST(ut_setup, ut_teardown,
10867                         test_AES_GCM_auth_decryption_test_case_192_2),
10868                 TEST_CASE_ST(ut_setup, ut_teardown,
10869                         test_AES_GCM_auth_decryption_test_case_192_3),
10870                 TEST_CASE_ST(ut_setup, ut_teardown,
10871                         test_AES_GCM_auth_decryption_test_case_192_4),
10872                 TEST_CASE_ST(ut_setup, ut_teardown,
10873                         test_AES_GCM_auth_decryption_test_case_192_5),
10874                 TEST_CASE_ST(ut_setup, ut_teardown,
10875                         test_AES_GCM_auth_decryption_test_case_192_6),
10876                 TEST_CASE_ST(ut_setup, ut_teardown,
10877                         test_AES_GCM_auth_decryption_test_case_192_7),
10878
10879                 /** AES GCM Authenticated Encryption 256 bits key */
10880                 TEST_CASE_ST(ut_setup, ut_teardown,
10881                         test_AES_GCM_auth_encryption_test_case_256_1),
10882                 TEST_CASE_ST(ut_setup, ut_teardown,
10883                         test_AES_GCM_auth_encryption_test_case_256_2),
10884                 TEST_CASE_ST(ut_setup, ut_teardown,
10885                         test_AES_GCM_auth_encryption_test_case_256_3),
10886                 TEST_CASE_ST(ut_setup, ut_teardown,
10887                         test_AES_GCM_auth_encryption_test_case_256_4),
10888                 TEST_CASE_ST(ut_setup, ut_teardown,
10889                         test_AES_GCM_auth_encryption_test_case_256_5),
10890                 TEST_CASE_ST(ut_setup, ut_teardown,
10891                         test_AES_GCM_auth_encryption_test_case_256_6),
10892                 TEST_CASE_ST(ut_setup, ut_teardown,
10893                         test_AES_GCM_auth_encryption_test_case_256_7),
10894
10895                 /** AES GCM Authenticated Decryption 256 bits key */
10896                 TEST_CASE_ST(ut_setup, ut_teardown,
10897                         test_AES_GCM_auth_decryption_test_case_256_1),
10898                 TEST_CASE_ST(ut_setup, ut_teardown,
10899                         test_AES_GCM_auth_decryption_test_case_256_2),
10900                 TEST_CASE_ST(ut_setup, ut_teardown,
10901                         test_AES_GCM_auth_decryption_test_case_256_3),
10902                 TEST_CASE_ST(ut_setup, ut_teardown,
10903                         test_AES_GCM_auth_decryption_test_case_256_4),
10904                 TEST_CASE_ST(ut_setup, ut_teardown,
10905                         test_AES_GCM_auth_decryption_test_case_256_5),
10906                 TEST_CASE_ST(ut_setup, ut_teardown,
10907                         test_AES_GCM_auth_decryption_test_case_256_6),
10908                 TEST_CASE_ST(ut_setup, ut_teardown,
10909                         test_AES_GCM_auth_decryption_test_case_256_7),
10910
10911                 /** AES GMAC Authentication */
10912                 TEST_CASE_ST(ut_setup, ut_teardown,
10913                         test_AES_GMAC_authentication_test_case_1),
10914                 TEST_CASE_ST(ut_setup, ut_teardown,
10915                         test_AES_GMAC_authentication_verify_test_case_1),
10916                 TEST_CASE_ST(ut_setup, ut_teardown,
10917                         test_AES_GMAC_authentication_test_case_2),
10918                 TEST_CASE_ST(ut_setup, ut_teardown,
10919                         test_AES_GMAC_authentication_verify_test_case_2),
10920                 TEST_CASE_ST(ut_setup, ut_teardown,
10921                         test_AES_GMAC_authentication_test_case_3),
10922                 TEST_CASE_ST(ut_setup, ut_teardown,
10923                         test_AES_GMAC_authentication_verify_test_case_3),
10924                 TEST_CASE_ST(ut_setup, ut_teardown,
10925                         test_AES_GMAC_authentication_test_case_4),
10926                 TEST_CASE_ST(ut_setup, ut_teardown,
10927                         test_AES_GMAC_authentication_verify_test_case_4),
10928
10929                 /** AES CCM Authenticated Encryption 128 bits key */
10930                 TEST_CASE_ST(ut_setup, ut_teardown,
10931                         test_AES_CCM_authenticated_encryption_test_case_128_1),
10932                 TEST_CASE_ST(ut_setup, ut_teardown,
10933                         test_AES_CCM_authenticated_encryption_test_case_128_2),
10934                 TEST_CASE_ST(ut_setup, ut_teardown,
10935                         test_AES_CCM_authenticated_encryption_test_case_128_3),
10936
10937                 /** AES CCM Authenticated Decryption 128 bits key*/
10938                 TEST_CASE_ST(ut_setup, ut_teardown,
10939                         test_AES_CCM_authenticated_decryption_test_case_128_1),
10940                 TEST_CASE_ST(ut_setup, ut_teardown,
10941                         test_AES_CCM_authenticated_decryption_test_case_128_2),
10942                 TEST_CASE_ST(ut_setup, ut_teardown,
10943                         test_AES_CCM_authenticated_decryption_test_case_128_3),
10944
10945                 /** AES CCM Authenticated Encryption 192 bits key */
10946                 TEST_CASE_ST(ut_setup, ut_teardown,
10947                         test_AES_CCM_authenticated_encryption_test_case_192_1),
10948                 TEST_CASE_ST(ut_setup, ut_teardown,
10949                         test_AES_CCM_authenticated_encryption_test_case_192_2),
10950                 TEST_CASE_ST(ut_setup, ut_teardown,
10951                         test_AES_CCM_authenticated_encryption_test_case_192_3),
10952
10953                 /** AES CCM Authenticated Decryption 192 bits key*/
10954                 TEST_CASE_ST(ut_setup, ut_teardown,
10955                         test_AES_CCM_authenticated_decryption_test_case_192_1),
10956                 TEST_CASE_ST(ut_setup, ut_teardown,
10957                         test_AES_CCM_authenticated_decryption_test_case_192_2),
10958                 TEST_CASE_ST(ut_setup, ut_teardown,
10959                         test_AES_CCM_authenticated_decryption_test_case_192_3),
10960
10961                 /** AES CCM Authenticated Encryption 256 bits key */
10962                 TEST_CASE_ST(ut_setup, ut_teardown,
10963                         test_AES_CCM_authenticated_encryption_test_case_256_1),
10964                 TEST_CASE_ST(ut_setup, ut_teardown,
10965                         test_AES_CCM_authenticated_encryption_test_case_256_2),
10966                 TEST_CASE_ST(ut_setup, ut_teardown,
10967                         test_AES_CCM_authenticated_encryption_test_case_256_3),
10968
10969                 /** AES CCM Authenticated Decryption 256 bits key*/
10970                 TEST_CASE_ST(ut_setup, ut_teardown,
10971                         test_AES_CCM_authenticated_decryption_test_case_256_1),
10972                 TEST_CASE_ST(ut_setup, ut_teardown,
10973                         test_AES_CCM_authenticated_decryption_test_case_256_2),
10974                 TEST_CASE_ST(ut_setup, ut_teardown,
10975                         test_AES_CCM_authenticated_decryption_test_case_256_3),
10976
10977                 /** Scatter-Gather */
10978                 TEST_CASE_ST(ut_setup, ut_teardown,
10979                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
10980
10981                 /** Negative tests */
10982                 TEST_CASE_ST(ut_setup, ut_teardown,
10983                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
10984                 TEST_CASE_ST(ut_setup, ut_teardown,
10985                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
10986                 TEST_CASE_ST(ut_setup, ut_teardown,
10987                         authentication_verify_AES128_GMAC_fail_data_corrupt),
10988                 TEST_CASE_ST(ut_setup, ut_teardown,
10989                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
10990                 TEST_CASE_ST(ut_setup, ut_teardown,
10991                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
10992                 TEST_CASE_ST(ut_setup, ut_teardown,
10993                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
10994
10995                 TEST_CASES_END() /**< NULL terminate unit test array */
10996         }
10997 };
10998
10999 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
11000         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
11001         .setup = testsuite_setup,
11002         .teardown = testsuite_teardown,
11003         .unit_test_cases = {
11004                 /** AES GCM Authenticated Encryption */
11005                 TEST_CASE_ST(ut_setup, ut_teardown,
11006                         test_AES_GCM_authenticated_encryption_test_case_1),
11007                 TEST_CASE_ST(ut_setup, ut_teardown,
11008                         test_AES_GCM_authenticated_encryption_test_case_2),
11009                 TEST_CASE_ST(ut_setup, ut_teardown,
11010                         test_AES_GCM_authenticated_encryption_test_case_3),
11011                 TEST_CASE_ST(ut_setup, ut_teardown,
11012                         test_AES_GCM_authenticated_encryption_test_case_4),
11013                 TEST_CASE_ST(ut_setup, ut_teardown,
11014                         test_AES_GCM_authenticated_encryption_test_case_5),
11015                 TEST_CASE_ST(ut_setup, ut_teardown,
11016                         test_AES_GCM_authenticated_encryption_test_case_6),
11017                 TEST_CASE_ST(ut_setup, ut_teardown,
11018                         test_AES_GCM_authenticated_encryption_test_case_7),
11019
11020                 /** AES GCM Authenticated Decryption */
11021                 TEST_CASE_ST(ut_setup, ut_teardown,
11022                         test_AES_GCM_authenticated_decryption_test_case_1),
11023                 TEST_CASE_ST(ut_setup, ut_teardown,
11024                         test_AES_GCM_authenticated_decryption_test_case_2),
11025                 TEST_CASE_ST(ut_setup, ut_teardown,
11026                         test_AES_GCM_authenticated_decryption_test_case_3),
11027                 TEST_CASE_ST(ut_setup, ut_teardown,
11028                         test_AES_GCM_authenticated_decryption_test_case_4),
11029                 TEST_CASE_ST(ut_setup, ut_teardown,
11030                         test_AES_GCM_authenticated_decryption_test_case_5),
11031                 TEST_CASE_ST(ut_setup, ut_teardown,
11032                         test_AES_GCM_authenticated_decryption_test_case_6),
11033                 TEST_CASE_ST(ut_setup, ut_teardown,
11034                         test_AES_GCM_authenticated_decryption_test_case_7),
11035
11036                 /** AES GCM Authenticated Encryption 192 bits key */
11037                 TEST_CASE_ST(ut_setup, ut_teardown,
11038                         test_AES_GCM_auth_encryption_test_case_192_1),
11039                 TEST_CASE_ST(ut_setup, ut_teardown,
11040                         test_AES_GCM_auth_encryption_test_case_192_2),
11041                 TEST_CASE_ST(ut_setup, ut_teardown,
11042                         test_AES_GCM_auth_encryption_test_case_192_3),
11043                 TEST_CASE_ST(ut_setup, ut_teardown,
11044                         test_AES_GCM_auth_encryption_test_case_192_4),
11045                 TEST_CASE_ST(ut_setup, ut_teardown,
11046                         test_AES_GCM_auth_encryption_test_case_192_5),
11047                 TEST_CASE_ST(ut_setup, ut_teardown,
11048                         test_AES_GCM_auth_encryption_test_case_192_6),
11049                 TEST_CASE_ST(ut_setup, ut_teardown,
11050                         test_AES_GCM_auth_encryption_test_case_192_7),
11051
11052                 /** AES GCM Authenticated Decryption 192 bits key */
11053                 TEST_CASE_ST(ut_setup, ut_teardown,
11054                         test_AES_GCM_auth_decryption_test_case_192_1),
11055                 TEST_CASE_ST(ut_setup, ut_teardown,
11056                         test_AES_GCM_auth_decryption_test_case_192_2),
11057                 TEST_CASE_ST(ut_setup, ut_teardown,
11058                         test_AES_GCM_auth_decryption_test_case_192_3),
11059                 TEST_CASE_ST(ut_setup, ut_teardown,
11060                         test_AES_GCM_auth_decryption_test_case_192_4),
11061                 TEST_CASE_ST(ut_setup, ut_teardown,
11062                         test_AES_GCM_auth_decryption_test_case_192_5),
11063                 TEST_CASE_ST(ut_setup, ut_teardown,
11064                         test_AES_GCM_auth_decryption_test_case_192_6),
11065                 TEST_CASE_ST(ut_setup, ut_teardown,
11066                         test_AES_GCM_auth_decryption_test_case_192_7),
11067
11068                 /** AES GCM Authenticated Encryption 256 bits key */
11069                 TEST_CASE_ST(ut_setup, ut_teardown,
11070                         test_AES_GCM_auth_encryption_test_case_256_1),
11071                 TEST_CASE_ST(ut_setup, ut_teardown,
11072                         test_AES_GCM_auth_encryption_test_case_256_2),
11073                 TEST_CASE_ST(ut_setup, ut_teardown,
11074                         test_AES_GCM_auth_encryption_test_case_256_3),
11075                 TEST_CASE_ST(ut_setup, ut_teardown,
11076                         test_AES_GCM_auth_encryption_test_case_256_4),
11077                 TEST_CASE_ST(ut_setup, ut_teardown,
11078                         test_AES_GCM_auth_encryption_test_case_256_5),
11079                 TEST_CASE_ST(ut_setup, ut_teardown,
11080                         test_AES_GCM_auth_encryption_test_case_256_6),
11081                 TEST_CASE_ST(ut_setup, ut_teardown,
11082                         test_AES_GCM_auth_encryption_test_case_256_7),
11083
11084                 /** AES GCM Authenticated Decryption 256 bits key */
11085                 TEST_CASE_ST(ut_setup, ut_teardown,
11086                         test_AES_GCM_auth_decryption_test_case_256_1),
11087                 TEST_CASE_ST(ut_setup, ut_teardown,
11088                         test_AES_GCM_auth_decryption_test_case_256_2),
11089                 TEST_CASE_ST(ut_setup, ut_teardown,
11090                         test_AES_GCM_auth_decryption_test_case_256_3),
11091                 TEST_CASE_ST(ut_setup, ut_teardown,
11092                         test_AES_GCM_auth_decryption_test_case_256_4),
11093                 TEST_CASE_ST(ut_setup, ut_teardown,
11094                         test_AES_GCM_auth_decryption_test_case_256_5),
11095                 TEST_CASE_ST(ut_setup, ut_teardown,
11096                         test_AES_GCM_auth_decryption_test_case_256_6),
11097                 TEST_CASE_ST(ut_setup, ut_teardown,
11098                         test_AES_GCM_auth_decryption_test_case_256_7),
11099
11100                 /** AES GCM Authenticated Encryption big aad size */
11101                 TEST_CASE_ST(ut_setup, ut_teardown,
11102                         test_AES_GCM_auth_encryption_test_case_aad_1),
11103                 TEST_CASE_ST(ut_setup, ut_teardown,
11104                         test_AES_GCM_auth_encryption_test_case_aad_2),
11105
11106                 /** AES GCM Authenticated Decryption big aad size */
11107                 TEST_CASE_ST(ut_setup, ut_teardown,
11108                         test_AES_GCM_auth_decryption_test_case_aad_1),
11109                 TEST_CASE_ST(ut_setup, ut_teardown,
11110                         test_AES_GCM_auth_decryption_test_case_aad_2),
11111
11112                 /** AES GMAC Authentication */
11113                 TEST_CASE_ST(ut_setup, ut_teardown,
11114                         test_AES_GMAC_authentication_test_case_1),
11115                 TEST_CASE_ST(ut_setup, ut_teardown,
11116                         test_AES_GMAC_authentication_verify_test_case_1),
11117                 TEST_CASE_ST(ut_setup, ut_teardown,
11118                         test_AES_GMAC_authentication_test_case_3),
11119                 TEST_CASE_ST(ut_setup, ut_teardown,
11120                         test_AES_GMAC_authentication_verify_test_case_3),
11121                 TEST_CASE_ST(ut_setup, ut_teardown,
11122                         test_AES_GMAC_authentication_test_case_4),
11123                 TEST_CASE_ST(ut_setup, ut_teardown,
11124                         test_AES_GMAC_authentication_verify_test_case_4),
11125
11126                 /** Negative tests */
11127                 TEST_CASE_ST(ut_setup, ut_teardown,
11128                         authentication_verify_AES128_GMAC_fail_data_corrupt),
11129                 TEST_CASE_ST(ut_setup, ut_teardown,
11130                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
11131
11132                 /** Out of place tests */
11133                 TEST_CASE_ST(ut_setup, ut_teardown,
11134                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
11135                 TEST_CASE_ST(ut_setup, ut_teardown,
11136                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
11137
11138                 /** Session-less tests */
11139                 TEST_CASE_ST(ut_setup, ut_teardown,
11140                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
11141                 TEST_CASE_ST(ut_setup, ut_teardown,
11142                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
11143
11144                 /** Scatter-Gather */
11145                 TEST_CASE_ST(ut_setup, ut_teardown,
11146                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11147
11148                 TEST_CASES_END() /**< NULL terminate unit test array */
11149         }
11150 };
11151
11152 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
11153         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
11154         .setup = testsuite_setup,
11155         .teardown = testsuite_teardown,
11156         .unit_test_cases = {
11157                 /** KASUMI encrypt only (UEA1) */
11158                 TEST_CASE_ST(ut_setup, ut_teardown,
11159                         test_kasumi_encryption_test_case_1),
11160                 TEST_CASE_ST(ut_setup, ut_teardown,
11161                         test_kasumi_encryption_test_case_1_sgl),
11162                 TEST_CASE_ST(ut_setup, ut_teardown,
11163                         test_kasumi_encryption_test_case_2),
11164                 TEST_CASE_ST(ut_setup, ut_teardown,
11165                         test_kasumi_encryption_test_case_3),
11166                 TEST_CASE_ST(ut_setup, ut_teardown,
11167                         test_kasumi_encryption_test_case_4),
11168                 TEST_CASE_ST(ut_setup, ut_teardown,
11169                         test_kasumi_encryption_test_case_5),
11170                 /** KASUMI decrypt only (UEA1) */
11171                 TEST_CASE_ST(ut_setup, ut_teardown,
11172                         test_kasumi_decryption_test_case_1),
11173                 TEST_CASE_ST(ut_setup, ut_teardown,
11174                         test_kasumi_decryption_test_case_2),
11175                 TEST_CASE_ST(ut_setup, ut_teardown,
11176                         test_kasumi_decryption_test_case_3),
11177                 TEST_CASE_ST(ut_setup, ut_teardown,
11178                         test_kasumi_decryption_test_case_4),
11179                 TEST_CASE_ST(ut_setup, ut_teardown,
11180                         test_kasumi_decryption_test_case_5),
11181
11182                 TEST_CASE_ST(ut_setup, ut_teardown,
11183                         test_kasumi_encryption_test_case_1_oop),
11184                 TEST_CASE_ST(ut_setup, ut_teardown,
11185                         test_kasumi_encryption_test_case_1_oop_sgl),
11186
11187
11188                 TEST_CASE_ST(ut_setup, ut_teardown,
11189                         test_kasumi_decryption_test_case_1_oop),
11190
11191                 /** KASUMI hash only (UIA1) */
11192                 TEST_CASE_ST(ut_setup, ut_teardown,
11193                         test_kasumi_hash_generate_test_case_1),
11194                 TEST_CASE_ST(ut_setup, ut_teardown,
11195                         test_kasumi_hash_generate_test_case_2),
11196                 TEST_CASE_ST(ut_setup, ut_teardown,
11197                         test_kasumi_hash_generate_test_case_3),
11198                 TEST_CASE_ST(ut_setup, ut_teardown,
11199                         test_kasumi_hash_generate_test_case_4),
11200                 TEST_CASE_ST(ut_setup, ut_teardown,
11201                         test_kasumi_hash_generate_test_case_5),
11202                 TEST_CASE_ST(ut_setup, ut_teardown,
11203                         test_kasumi_hash_generate_test_case_6),
11204                 TEST_CASE_ST(ut_setup, ut_teardown,
11205                         test_kasumi_hash_verify_test_case_1),
11206                 TEST_CASE_ST(ut_setup, ut_teardown,
11207                         test_kasumi_hash_verify_test_case_2),
11208                 TEST_CASE_ST(ut_setup, ut_teardown,
11209                         test_kasumi_hash_verify_test_case_3),
11210                 TEST_CASE_ST(ut_setup, ut_teardown,
11211                         test_kasumi_hash_verify_test_case_4),
11212                 TEST_CASE_ST(ut_setup, ut_teardown,
11213                         test_kasumi_hash_verify_test_case_5),
11214                 TEST_CASE_ST(ut_setup, ut_teardown,
11215                         test_kasumi_cipher_auth_test_case_1),
11216
11217                 /** KASUMI generate auth, then encrypt (F8) */
11218                 TEST_CASE_ST(ut_setup, ut_teardown,
11219                         test_kasumi_auth_cipher_test_case_1),
11220                 TEST_CASE_ST(ut_setup, ut_teardown,
11221                         test_kasumi_auth_cipher_test_case_2),
11222                 TEST_CASE_ST(ut_setup, ut_teardown,
11223                         test_kasumi_auth_cipher_test_case_2_oop),
11224                 TEST_CASE_ST(ut_setup, ut_teardown,
11225                         test_kasumi_auth_cipher_test_case_2_sgl),
11226                 TEST_CASE_ST(ut_setup, ut_teardown,
11227                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
11228
11229                 /** KASUMI decrypt (F8), then verify auth */
11230                 TEST_CASE_ST(ut_setup, ut_teardown,
11231                         test_kasumi_auth_cipher_verify_test_case_1),
11232                 TEST_CASE_ST(ut_setup, ut_teardown,
11233                         test_kasumi_auth_cipher_verify_test_case_2),
11234                 TEST_CASE_ST(ut_setup, ut_teardown,
11235                         test_kasumi_auth_cipher_verify_test_case_2_oop),
11236                 TEST_CASE_ST(ut_setup, ut_teardown,
11237                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
11238                 TEST_CASE_ST(ut_setup, ut_teardown,
11239                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
11240                 TEST_CASES_END() /**< NULL terminate unit test array */
11241         }
11242 };
11243 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
11244         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
11245         .setup = testsuite_setup,
11246         .teardown = testsuite_teardown,
11247         .unit_test_cases = {
11248                 /** SNOW 3G encrypt only (UEA2) */
11249                 TEST_CASE_ST(ut_setup, ut_teardown,
11250                         test_snow3g_encryption_test_case_1),
11251                 TEST_CASE_ST(ut_setup, ut_teardown,
11252                         test_snow3g_encryption_test_case_2),
11253                 TEST_CASE_ST(ut_setup, ut_teardown,
11254                         test_snow3g_encryption_test_case_3),
11255                 TEST_CASE_ST(ut_setup, ut_teardown,
11256                         test_snow3g_encryption_test_case_4),
11257                 TEST_CASE_ST(ut_setup, ut_teardown,
11258                         test_snow3g_encryption_test_case_5),
11259                 TEST_CASE_ST(ut_setup, ut_teardown,
11260                         test_snow3g_auth_cipher_with_digest_test_case_1),
11261
11262                 TEST_CASE_ST(ut_setup, ut_teardown,
11263                         test_snow3g_encryption_test_case_1_oop),
11264                 TEST_CASE_ST(ut_setup, ut_teardown,
11265                                 test_snow3g_encryption_test_case_1_oop_sgl),
11266                 TEST_CASE_ST(ut_setup, ut_teardown,
11267                         test_snow3g_decryption_test_case_1_oop),
11268
11269                 TEST_CASE_ST(ut_setup, ut_teardown,
11270                         test_snow3g_encryption_test_case_1_offset_oop),
11271
11272                 /** SNOW 3G decrypt only (UEA2) */
11273                 TEST_CASE_ST(ut_setup, ut_teardown,
11274                         test_snow3g_decryption_test_case_1),
11275                 TEST_CASE_ST(ut_setup, ut_teardown,
11276                         test_snow3g_decryption_test_case_2),
11277                 TEST_CASE_ST(ut_setup, ut_teardown,
11278                         test_snow3g_decryption_test_case_3),
11279                 TEST_CASE_ST(ut_setup, ut_teardown,
11280                         test_snow3g_decryption_test_case_4),
11281                 TEST_CASE_ST(ut_setup, ut_teardown,
11282                         test_snow3g_decryption_test_case_5),
11283                 TEST_CASE_ST(ut_setup, ut_teardown,
11284                         test_snow3g_decryption_with_digest_test_case_1),
11285                 TEST_CASE_ST(ut_setup, ut_teardown,
11286                         test_snow3g_hash_generate_test_case_1),
11287                 TEST_CASE_ST(ut_setup, ut_teardown,
11288                         test_snow3g_hash_generate_test_case_2),
11289                 TEST_CASE_ST(ut_setup, ut_teardown,
11290                         test_snow3g_hash_generate_test_case_3),
11291                 /* Tests with buffers which length is not byte-aligned */
11292                 TEST_CASE_ST(ut_setup, ut_teardown,
11293                         test_snow3g_hash_generate_test_case_4),
11294                 TEST_CASE_ST(ut_setup, ut_teardown,
11295                         test_snow3g_hash_generate_test_case_5),
11296                 TEST_CASE_ST(ut_setup, ut_teardown,
11297                         test_snow3g_hash_generate_test_case_6),
11298                 TEST_CASE_ST(ut_setup, ut_teardown,
11299                         test_snow3g_hash_verify_test_case_1),
11300                 TEST_CASE_ST(ut_setup, ut_teardown,
11301                         test_snow3g_hash_verify_test_case_2),
11302                 TEST_CASE_ST(ut_setup, ut_teardown,
11303                         test_snow3g_hash_verify_test_case_3),
11304                 /* Tests with buffers which length is not byte-aligned */
11305                 TEST_CASE_ST(ut_setup, ut_teardown,
11306                         test_snow3g_hash_verify_test_case_4),
11307                 TEST_CASE_ST(ut_setup, ut_teardown,
11308                         test_snow3g_hash_verify_test_case_5),
11309                 TEST_CASE_ST(ut_setup, ut_teardown,
11310                         test_snow3g_hash_verify_test_case_6),
11311                 TEST_CASE_ST(ut_setup, ut_teardown,
11312                         test_snow3g_cipher_auth_test_case_1),
11313
11314                 /** SNOW 3G generate auth, then encrypt (UEA2) */
11315                 TEST_CASE_ST(ut_setup, ut_teardown,
11316                         test_snow3g_auth_cipher_test_case_1),
11317                 TEST_CASE_ST(ut_setup, ut_teardown,
11318                         test_snow3g_auth_cipher_test_case_2),
11319                 TEST_CASE_ST(ut_setup, ut_teardown,
11320                         test_snow3g_auth_cipher_test_case_2_oop),
11321                 TEST_CASE_ST(ut_setup, ut_teardown,
11322                         test_snow3g_auth_cipher_part_digest_enc),
11323                 TEST_CASE_ST(ut_setup, ut_teardown,
11324                         test_snow3g_auth_cipher_part_digest_enc_oop),
11325                 TEST_CASE_ST(ut_setup, ut_teardown,
11326                         test_snow3g_auth_cipher_test_case_3_sgl),
11327                 TEST_CASE_ST(ut_setup, ut_teardown,
11328                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
11329                 TEST_CASE_ST(ut_setup, ut_teardown,
11330                         test_snow3g_auth_cipher_part_digest_enc_sgl),
11331                 TEST_CASE_ST(ut_setup, ut_teardown,
11332                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
11333
11334                 /** SNOW 3G decrypt (UEA2), then verify auth */
11335                 TEST_CASE_ST(ut_setup, ut_teardown,
11336                         test_snow3g_auth_cipher_verify_test_case_1),
11337                 TEST_CASE_ST(ut_setup, ut_teardown,
11338                         test_snow3g_auth_cipher_verify_test_case_2),
11339                 TEST_CASE_ST(ut_setup, ut_teardown,
11340                         test_snow3g_auth_cipher_verify_test_case_2_oop),
11341                 TEST_CASE_ST(ut_setup, ut_teardown,
11342                         test_snow3g_auth_cipher_verify_part_digest_enc),
11343                 TEST_CASE_ST(ut_setup, ut_teardown,
11344                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
11345                 TEST_CASE_ST(ut_setup, ut_teardown,
11346                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
11347                 TEST_CASE_ST(ut_setup, ut_teardown,
11348                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
11349                 TEST_CASE_ST(ut_setup, ut_teardown,
11350                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
11351                 TEST_CASE_ST(ut_setup, ut_teardown,
11352                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
11353
11354                 TEST_CASES_END() /**< NULL terminate unit test array */
11355         }
11356 };
11357
11358 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
11359         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
11360         .setup = testsuite_setup,
11361         .teardown = testsuite_teardown,
11362         .unit_test_cases = {
11363                 /** ZUC encrypt only (EEA3) */
11364                 TEST_CASE_ST(ut_setup, ut_teardown,
11365                         test_zuc_encryption_test_case_1),
11366                 TEST_CASE_ST(ut_setup, ut_teardown,
11367                         test_zuc_encryption_test_case_2),
11368                 TEST_CASE_ST(ut_setup, ut_teardown,
11369                         test_zuc_encryption_test_case_3),
11370                 TEST_CASE_ST(ut_setup, ut_teardown,
11371                         test_zuc_encryption_test_case_4),
11372                 TEST_CASE_ST(ut_setup, ut_teardown,
11373                         test_zuc_encryption_test_case_5),
11374                 TEST_CASE_ST(ut_setup, ut_teardown,
11375                         test_zuc_hash_generate_test_case_1),
11376                 TEST_CASE_ST(ut_setup, ut_teardown,
11377                         test_zuc_hash_generate_test_case_2),
11378                 TEST_CASE_ST(ut_setup, ut_teardown,
11379                         test_zuc_hash_generate_test_case_3),
11380                 TEST_CASE_ST(ut_setup, ut_teardown,
11381                         test_zuc_hash_generate_test_case_4),
11382                 TEST_CASE_ST(ut_setup, ut_teardown,
11383                         test_zuc_hash_generate_test_case_5),
11384                 TEST_CASE_ST(ut_setup, ut_teardown,
11385                         test_zuc_encryption_test_case_6_sgl),
11386                 TEST_CASES_END() /**< NULL terminate unit test array */
11387         }
11388 };
11389
11390 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
11391         .suite_name = "Crypto CAAM JR Unit Test Suite",
11392         .setup = testsuite_setup,
11393         .teardown = testsuite_teardown,
11394         .unit_test_cases = {
11395                 TEST_CASE_ST(ut_setup, ut_teardown,
11396                              test_device_configure_invalid_dev_id),
11397                 TEST_CASE_ST(ut_setup, ut_teardown,
11398                              test_multi_session),
11399
11400                 TEST_CASE_ST(ut_setup, ut_teardown,
11401                              test_AES_chain_caam_jr_all),
11402                 TEST_CASE_ST(ut_setup, ut_teardown,
11403                              test_3DES_chain_caam_jr_all),
11404                 TEST_CASE_ST(ut_setup, ut_teardown,
11405                              test_AES_cipheronly_caam_jr_all),
11406                 TEST_CASE_ST(ut_setup, ut_teardown,
11407                              test_3DES_cipheronly_caam_jr_all),
11408                 TEST_CASE_ST(ut_setup, ut_teardown,
11409                              test_authonly_caam_jr_all),
11410
11411                 TEST_CASES_END() /**< NULL terminate unit test array */
11412         }
11413 };
11414
11415 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
11416         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
11417         .setup = testsuite_setup,
11418         .teardown = testsuite_teardown,
11419         .unit_test_cases = {
11420                 TEST_CASE_ST(ut_setup, ut_teardown,
11421                              test_device_configure_invalid_dev_id),
11422                 TEST_CASE_ST(ut_setup, ut_teardown,
11423                              test_multi_session),
11424
11425                 TEST_CASE_ST(ut_setup, ut_teardown,
11426                              test_AES_chain_dpaa_sec_all),
11427                 TEST_CASE_ST(ut_setup, ut_teardown,
11428                              test_3DES_chain_dpaa_sec_all),
11429                 TEST_CASE_ST(ut_setup, ut_teardown,
11430                              test_AES_cipheronly_dpaa_sec_all),
11431                 TEST_CASE_ST(ut_setup, ut_teardown,
11432                              test_3DES_cipheronly_dpaa_sec_all),
11433                 TEST_CASE_ST(ut_setup, ut_teardown,
11434                              test_authonly_dpaa_sec_all),
11435
11436                 /** AES GCM Authenticated Encryption */
11437                 TEST_CASE_ST(ut_setup, ut_teardown,
11438                         test_AES_GCM_authenticated_encryption_test_case_1),
11439                 TEST_CASE_ST(ut_setup, ut_teardown,
11440                         test_AES_GCM_authenticated_encryption_test_case_2),
11441                 TEST_CASE_ST(ut_setup, ut_teardown,
11442                         test_AES_GCM_authenticated_encryption_test_case_3),
11443                 TEST_CASE_ST(ut_setup, ut_teardown,
11444                         test_AES_GCM_authenticated_encryption_test_case_4),
11445                 TEST_CASE_ST(ut_setup, ut_teardown,
11446                         test_AES_GCM_authenticated_encryption_test_case_5),
11447                 TEST_CASE_ST(ut_setup, ut_teardown,
11448                         test_AES_GCM_authenticated_encryption_test_case_6),
11449                 TEST_CASE_ST(ut_setup, ut_teardown,
11450                         test_AES_GCM_authenticated_encryption_test_case_7),
11451
11452                 /** AES GCM Authenticated Decryption */
11453                 TEST_CASE_ST(ut_setup, ut_teardown,
11454                         test_AES_GCM_authenticated_decryption_test_case_1),
11455                 TEST_CASE_ST(ut_setup, ut_teardown,
11456                         test_AES_GCM_authenticated_decryption_test_case_2),
11457                 TEST_CASE_ST(ut_setup, ut_teardown,
11458                         test_AES_GCM_authenticated_decryption_test_case_3),
11459                 TEST_CASE_ST(ut_setup, ut_teardown,
11460                         test_AES_GCM_authenticated_decryption_test_case_4),
11461                 TEST_CASE_ST(ut_setup, ut_teardown,
11462                         test_AES_GCM_authenticated_decryption_test_case_5),
11463                 TEST_CASE_ST(ut_setup, ut_teardown,
11464                         test_AES_GCM_authenticated_decryption_test_case_6),
11465                 TEST_CASE_ST(ut_setup, ut_teardown,
11466                         test_AES_GCM_authenticated_decryption_test_case_7),
11467
11468                 /** AES GCM Authenticated Encryption 256 bits key */
11469                 TEST_CASE_ST(ut_setup, ut_teardown,
11470                         test_AES_GCM_auth_encryption_test_case_256_1),
11471                 TEST_CASE_ST(ut_setup, ut_teardown,
11472                         test_AES_GCM_auth_encryption_test_case_256_2),
11473                 TEST_CASE_ST(ut_setup, ut_teardown,
11474                         test_AES_GCM_auth_encryption_test_case_256_3),
11475                 TEST_CASE_ST(ut_setup, ut_teardown,
11476                         test_AES_GCM_auth_encryption_test_case_256_4),
11477                 TEST_CASE_ST(ut_setup, ut_teardown,
11478                         test_AES_GCM_auth_encryption_test_case_256_5),
11479                 TEST_CASE_ST(ut_setup, ut_teardown,
11480                         test_AES_GCM_auth_encryption_test_case_256_6),
11481                 TEST_CASE_ST(ut_setup, ut_teardown,
11482                         test_AES_GCM_auth_encryption_test_case_256_7),
11483
11484                 /** AES GCM Authenticated Decryption 256 bits key */
11485                 TEST_CASE_ST(ut_setup, ut_teardown,
11486                         test_AES_GCM_auth_decryption_test_case_256_1),
11487                 TEST_CASE_ST(ut_setup, ut_teardown,
11488                         test_AES_GCM_auth_decryption_test_case_256_2),
11489                 TEST_CASE_ST(ut_setup, ut_teardown,
11490                         test_AES_GCM_auth_decryption_test_case_256_3),
11491                 TEST_CASE_ST(ut_setup, ut_teardown,
11492                         test_AES_GCM_auth_decryption_test_case_256_4),
11493                 TEST_CASE_ST(ut_setup, ut_teardown,
11494                         test_AES_GCM_auth_decryption_test_case_256_5),
11495                 TEST_CASE_ST(ut_setup, ut_teardown,
11496                         test_AES_GCM_auth_decryption_test_case_256_6),
11497                 TEST_CASE_ST(ut_setup, ut_teardown,
11498                         test_AES_GCM_auth_decryption_test_case_256_7),
11499
11500                 /** Out of place tests */
11501                 TEST_CASE_ST(ut_setup, ut_teardown,
11502                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
11503                 TEST_CASE_ST(ut_setup, ut_teardown,
11504                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
11505
11506                 /** Scatter-Gather */
11507                 TEST_CASE_ST(ut_setup, ut_teardown,
11508                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
11509                 TEST_CASE_ST(ut_setup, ut_teardown,
11510                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
11511                 TEST_CASE_ST(ut_setup, ut_teardown,
11512                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11513                 TEST_CASE_ST(ut_setup, ut_teardown,
11514                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
11515
11516                 TEST_CASES_END() /**< NULL terminate unit test array */
11517         }
11518 };
11519
11520 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
11521         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
11522         .setup = testsuite_setup,
11523         .teardown = testsuite_teardown,
11524         .unit_test_cases = {
11525                 TEST_CASE_ST(ut_setup, ut_teardown,
11526                         test_device_configure_invalid_dev_id),
11527                 TEST_CASE_ST(ut_setup, ut_teardown,
11528                         test_multi_session),
11529
11530                 TEST_CASE_ST(ut_setup, ut_teardown,
11531                         test_AES_chain_dpaa2_sec_all),
11532                 TEST_CASE_ST(ut_setup, ut_teardown,
11533                         test_3DES_chain_dpaa2_sec_all),
11534                 TEST_CASE_ST(ut_setup, ut_teardown,
11535                         test_AES_cipheronly_dpaa2_sec_all),
11536                 TEST_CASE_ST(ut_setup, ut_teardown,
11537                         test_3DES_cipheronly_dpaa2_sec_all),
11538                 TEST_CASE_ST(ut_setup, ut_teardown,
11539                         test_authonly_dpaa2_sec_all),
11540
11541                 /** AES GCM Authenticated Encryption */
11542                 TEST_CASE_ST(ut_setup, ut_teardown,
11543                         test_AES_GCM_authenticated_encryption_test_case_1),
11544                 TEST_CASE_ST(ut_setup, ut_teardown,
11545                         test_AES_GCM_authenticated_encryption_test_case_2),
11546                 TEST_CASE_ST(ut_setup, ut_teardown,
11547                         test_AES_GCM_authenticated_encryption_test_case_3),
11548                 TEST_CASE_ST(ut_setup, ut_teardown,
11549                         test_AES_GCM_authenticated_encryption_test_case_4),
11550                 TEST_CASE_ST(ut_setup, ut_teardown,
11551                         test_AES_GCM_authenticated_encryption_test_case_5),
11552                 TEST_CASE_ST(ut_setup, ut_teardown,
11553                         test_AES_GCM_authenticated_encryption_test_case_6),
11554                 TEST_CASE_ST(ut_setup, ut_teardown,
11555                         test_AES_GCM_authenticated_encryption_test_case_7),
11556
11557                 /** AES GCM Authenticated Decryption */
11558                 TEST_CASE_ST(ut_setup, ut_teardown,
11559                         test_AES_GCM_authenticated_decryption_test_case_1),
11560                 TEST_CASE_ST(ut_setup, ut_teardown,
11561                         test_AES_GCM_authenticated_decryption_test_case_2),
11562                 TEST_CASE_ST(ut_setup, ut_teardown,
11563                         test_AES_GCM_authenticated_decryption_test_case_3),
11564                 TEST_CASE_ST(ut_setup, ut_teardown,
11565                         test_AES_GCM_authenticated_decryption_test_case_4),
11566                 TEST_CASE_ST(ut_setup, ut_teardown,
11567                         test_AES_GCM_authenticated_decryption_test_case_5),
11568                 TEST_CASE_ST(ut_setup, ut_teardown,
11569                         test_AES_GCM_authenticated_decryption_test_case_6),
11570                 TEST_CASE_ST(ut_setup, ut_teardown,
11571                         test_AES_GCM_authenticated_decryption_test_case_7),
11572
11573                 /** AES GCM Authenticated Encryption 192 bits key */
11574                 TEST_CASE_ST(ut_setup, ut_teardown,
11575                         test_AES_GCM_auth_encryption_test_case_192_1),
11576                 TEST_CASE_ST(ut_setup, ut_teardown,
11577                         test_AES_GCM_auth_encryption_test_case_192_2),
11578                 TEST_CASE_ST(ut_setup, ut_teardown,
11579                         test_AES_GCM_auth_encryption_test_case_192_3),
11580                 TEST_CASE_ST(ut_setup, ut_teardown,
11581                         test_AES_GCM_auth_encryption_test_case_192_4),
11582                 TEST_CASE_ST(ut_setup, ut_teardown,
11583                         test_AES_GCM_auth_encryption_test_case_192_5),
11584                 TEST_CASE_ST(ut_setup, ut_teardown,
11585                         test_AES_GCM_auth_encryption_test_case_192_6),
11586                 TEST_CASE_ST(ut_setup, ut_teardown,
11587                         test_AES_GCM_auth_encryption_test_case_192_7),
11588
11589                 /** AES GCM Authenticated Decryption 192 bits key */
11590                 TEST_CASE_ST(ut_setup, ut_teardown,
11591                         test_AES_GCM_auth_decryption_test_case_192_1),
11592                 TEST_CASE_ST(ut_setup, ut_teardown,
11593                         test_AES_GCM_auth_decryption_test_case_192_2),
11594                 TEST_CASE_ST(ut_setup, ut_teardown,
11595                         test_AES_GCM_auth_decryption_test_case_192_3),
11596                 TEST_CASE_ST(ut_setup, ut_teardown,
11597                         test_AES_GCM_auth_decryption_test_case_192_4),
11598                 TEST_CASE_ST(ut_setup, ut_teardown,
11599                         test_AES_GCM_auth_decryption_test_case_192_5),
11600                 TEST_CASE_ST(ut_setup, ut_teardown,
11601                         test_AES_GCM_auth_decryption_test_case_192_6),
11602                 TEST_CASE_ST(ut_setup, ut_teardown,
11603                         test_AES_GCM_auth_decryption_test_case_192_7),
11604
11605                 /** AES GCM Authenticated Encryption 256 bits key */
11606                 TEST_CASE_ST(ut_setup, ut_teardown,
11607                         test_AES_GCM_auth_encryption_test_case_256_1),
11608                 TEST_CASE_ST(ut_setup, ut_teardown,
11609                         test_AES_GCM_auth_encryption_test_case_256_2),
11610                 TEST_CASE_ST(ut_setup, ut_teardown,
11611                         test_AES_GCM_auth_encryption_test_case_256_3),
11612                 TEST_CASE_ST(ut_setup, ut_teardown,
11613                         test_AES_GCM_auth_encryption_test_case_256_4),
11614                 TEST_CASE_ST(ut_setup, ut_teardown,
11615                         test_AES_GCM_auth_encryption_test_case_256_5),
11616                 TEST_CASE_ST(ut_setup, ut_teardown,
11617                         test_AES_GCM_auth_encryption_test_case_256_6),
11618                 TEST_CASE_ST(ut_setup, ut_teardown,
11619                         test_AES_GCM_auth_encryption_test_case_256_7),
11620
11621                 /** AES GCM Authenticated Decryption 256 bits key */
11622                 TEST_CASE_ST(ut_setup, ut_teardown,
11623                         test_AES_GCM_auth_decryption_test_case_256_1),
11624                 TEST_CASE_ST(ut_setup, ut_teardown,
11625                         test_AES_GCM_auth_decryption_test_case_256_2),
11626                 TEST_CASE_ST(ut_setup, ut_teardown,
11627                         test_AES_GCM_auth_decryption_test_case_256_3),
11628                 TEST_CASE_ST(ut_setup, ut_teardown,
11629                         test_AES_GCM_auth_decryption_test_case_256_4),
11630                 TEST_CASE_ST(ut_setup, ut_teardown,
11631                         test_AES_GCM_auth_decryption_test_case_256_5),
11632                 TEST_CASE_ST(ut_setup, ut_teardown,
11633                         test_AES_GCM_auth_decryption_test_case_256_6),
11634                 TEST_CASE_ST(ut_setup, ut_teardown,
11635                         test_AES_GCM_auth_decryption_test_case_256_7),
11636
11637                 /** Out of place tests */
11638                 TEST_CASE_ST(ut_setup, ut_teardown,
11639                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
11640                 TEST_CASE_ST(ut_setup, ut_teardown,
11641                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
11642
11643                 /** Scatter-Gather */
11644                 TEST_CASE_ST(ut_setup, ut_teardown,
11645                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
11646                 TEST_CASE_ST(ut_setup, ut_teardown,
11647                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
11648                 TEST_CASE_ST(ut_setup, ut_teardown,
11649                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11650                 TEST_CASE_ST(ut_setup, ut_teardown,
11651                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
11652
11653                 TEST_CASES_END() /**< NULL terminate unit test array */
11654         }
11655 };
11656
11657 static struct unit_test_suite cryptodev_null_testsuite  = {
11658         .suite_name = "Crypto Device NULL Unit Test Suite",
11659         .setup = testsuite_setup,
11660         .teardown = testsuite_teardown,
11661         .unit_test_cases = {
11662                 TEST_CASE_ST(ut_setup, ut_teardown,
11663                         test_null_invalid_operation),
11664                 TEST_CASE_ST(ut_setup, ut_teardown,
11665                         test_null_burst_operation),
11666                 TEST_CASE_ST(ut_setup, ut_teardown,
11667                         test_AES_chain_null_all),
11668                 TEST_CASE_ST(ut_setup, ut_teardown,
11669                         test_AES_cipheronly_null_all),
11670                 TEST_CASE_ST(ut_setup, ut_teardown,
11671                                 test_authonly_null_all),
11672
11673                 TEST_CASES_END() /**< NULL terminate unit test array */
11674         }
11675 };
11676
11677 static struct unit_test_suite cryptodev_armv8_testsuite  = {
11678         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
11679         .setup = testsuite_setup,
11680         .teardown = testsuite_teardown,
11681         .unit_test_cases = {
11682                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
11683
11684                 /** Negative tests */
11685                 TEST_CASE_ST(ut_setup, ut_teardown,
11686                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
11687                 TEST_CASE_ST(ut_setup, ut_teardown,
11688                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
11689
11690                 TEST_CASES_END() /**< NULL terminate unit test array */
11691         }
11692 };
11693
11694 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
11695         .suite_name = "Crypto Device Marvell Component Test Suite",
11696         .setup = testsuite_setup,
11697         .teardown = testsuite_teardown,
11698         .unit_test_cases = {
11699                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
11700                 TEST_CASE_ST(ut_setup, ut_teardown,
11701                                 test_multi_session_random_usage),
11702                 TEST_CASE_ST(ut_setup, ut_teardown,
11703                                 test_AES_chain_mrvl_all),
11704                 TEST_CASE_ST(ut_setup, ut_teardown,
11705                                 test_AES_cipheronly_mrvl_all),
11706                 TEST_CASE_ST(ut_setup, ut_teardown,
11707                                 test_authonly_mrvl_all),
11708                 TEST_CASE_ST(ut_setup, ut_teardown,
11709                                 test_3DES_chain_mrvl_all),
11710                 TEST_CASE_ST(ut_setup, ut_teardown,
11711                                 test_3DES_cipheronly_mrvl_all),
11712
11713                 /** Negative tests */
11714                 TEST_CASE_ST(ut_setup, ut_teardown,
11715                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
11716                 TEST_CASE_ST(ut_setup, ut_teardown,
11717                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
11718                 TEST_CASE_ST(ut_setup, ut_teardown,
11719                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
11720                 TEST_CASE_ST(ut_setup, ut_teardown,
11721                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
11722
11723                 TEST_CASES_END() /**< NULL terminate unit test array */
11724         }
11725 };
11726
11727 static struct unit_test_suite cryptodev_ccp_testsuite  = {
11728         .suite_name = "Crypto Device CCP Unit Test Suite",
11729         .setup = testsuite_setup,
11730         .teardown = testsuite_teardown,
11731         .unit_test_cases = {
11732                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
11733                 TEST_CASE_ST(ut_setup, ut_teardown,
11734                                 test_multi_session_random_usage),
11735                 TEST_CASE_ST(ut_setup, ut_teardown,
11736                                 test_AES_chain_ccp_all),
11737                 TEST_CASE_ST(ut_setup, ut_teardown,
11738                                 test_AES_cipheronly_ccp_all),
11739                 TEST_CASE_ST(ut_setup, ut_teardown,
11740                                 test_3DES_chain_ccp_all),
11741                 TEST_CASE_ST(ut_setup, ut_teardown,
11742                                 test_3DES_cipheronly_ccp_all),
11743                 TEST_CASE_ST(ut_setup, ut_teardown,
11744                                 test_authonly_ccp_all),
11745
11746                 /** Negative tests */
11747                 TEST_CASE_ST(ut_setup, ut_teardown,
11748                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
11749                 TEST_CASE_ST(ut_setup, ut_teardown,
11750                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
11751                 TEST_CASE_ST(ut_setup, ut_teardown,
11752                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
11753                 TEST_CASE_ST(ut_setup, ut_teardown,
11754                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
11755
11756                 TEST_CASES_END() /**< NULL terminate unit test array */
11757         }
11758 };
11759
11760 static struct unit_test_suite cryptodev_octeontx_testsuite  = {
11761         .suite_name = "Crypto Device OCTEONTX Unit Test Suite",
11762         .setup = testsuite_setup,
11763         .teardown = testsuite_teardown,
11764         .unit_test_cases = {
11765                 TEST_CASE_ST(ut_setup, ut_teardown,
11766                         test_AES_chain_octeontx_all),
11767                 TEST_CASE_ST(ut_setup, ut_teardown,
11768                         test_AES_cipheronly_octeontx_all),
11769                 TEST_CASE_ST(ut_setup, ut_teardown,
11770                         test_3DES_chain_octeontx_all),
11771                 TEST_CASE_ST(ut_setup, ut_teardown,
11772                         test_3DES_cipheronly_octeontx_all),
11773                 TEST_CASE_ST(ut_setup, ut_teardown,
11774                         test_authonly_octeontx_all),
11775
11776                 /** AES GCM Authenticated Encryption */
11777                 TEST_CASE_ST(ut_setup, ut_teardown,
11778                         test_AES_GCM_authenticated_encryption_test_case_1),
11779                 TEST_CASE_ST(ut_setup, ut_teardown,
11780                         test_AES_GCM_authenticated_encryption_test_case_2),
11781                 TEST_CASE_ST(ut_setup, ut_teardown,
11782                         test_AES_GCM_authenticated_encryption_test_case_3),
11783                 TEST_CASE_ST(ut_setup, ut_teardown,
11784                         test_AES_GCM_authenticated_encryption_test_case_4),
11785                 TEST_CASE_ST(ut_setup, ut_teardown,
11786                         test_AES_GCM_authenticated_encryption_test_case_5),
11787                 TEST_CASE_ST(ut_setup, ut_teardown,
11788                         test_AES_GCM_authenticated_encryption_test_case_6),
11789                 TEST_CASE_ST(ut_setup, ut_teardown,
11790                         test_AES_GCM_authenticated_encryption_test_case_7),
11791
11792                 /** AES GCM Authenticated Decryption */
11793                 TEST_CASE_ST(ut_setup, ut_teardown,
11794                         test_AES_GCM_authenticated_decryption_test_case_1),
11795                 TEST_CASE_ST(ut_setup, ut_teardown,
11796                         test_AES_GCM_authenticated_decryption_test_case_2),
11797                 TEST_CASE_ST(ut_setup, ut_teardown,
11798                         test_AES_GCM_authenticated_decryption_test_case_3),
11799                 TEST_CASE_ST(ut_setup, ut_teardown,
11800                         test_AES_GCM_authenticated_decryption_test_case_4),
11801                 TEST_CASE_ST(ut_setup, ut_teardown,
11802                         test_AES_GCM_authenticated_decryption_test_case_5),
11803                 TEST_CASE_ST(ut_setup, ut_teardown,
11804                         test_AES_GCM_authenticated_decryption_test_case_6),
11805                 TEST_CASE_ST(ut_setup, ut_teardown,
11806                         test_AES_GCM_authenticated_decryption_test_case_7),
11807                 /** AES GMAC Authentication */
11808                 TEST_CASE_ST(ut_setup, ut_teardown,
11809                         test_AES_GMAC_authentication_test_case_1),
11810                 TEST_CASE_ST(ut_setup, ut_teardown,
11811                         test_AES_GMAC_authentication_verify_test_case_1),
11812                 TEST_CASE_ST(ut_setup, ut_teardown,
11813                         test_AES_GMAC_authentication_test_case_2),
11814                 TEST_CASE_ST(ut_setup, ut_teardown,
11815                         test_AES_GMAC_authentication_verify_test_case_2),
11816                 TEST_CASE_ST(ut_setup, ut_teardown,
11817                         test_AES_GMAC_authentication_test_case_3),
11818                 TEST_CASE_ST(ut_setup, ut_teardown,
11819                         test_AES_GMAC_authentication_verify_test_case_3),
11820
11821                 /** SNOW 3G encrypt only (UEA2) */
11822                 TEST_CASE_ST(ut_setup, ut_teardown,
11823                         test_snow3g_encryption_test_case_1),
11824                 TEST_CASE_ST(ut_setup, ut_teardown,
11825                         test_snow3g_encryption_test_case_2),
11826                 TEST_CASE_ST(ut_setup, ut_teardown,
11827                         test_snow3g_encryption_test_case_3),
11828                 TEST_CASE_ST(ut_setup, ut_teardown,
11829                         test_snow3g_encryption_test_case_4),
11830                 TEST_CASE_ST(ut_setup, ut_teardown,
11831                         test_snow3g_encryption_test_case_5),
11832
11833                 TEST_CASE_ST(ut_setup, ut_teardown,
11834                         test_snow3g_encryption_test_case_1_oop),
11835                 TEST_CASE_ST(ut_setup, ut_teardown,
11836                         test_snow3g_decryption_test_case_1_oop),
11837                 TEST_CASE_ST(ut_setup, ut_teardown,
11838                         test_snow3g_encryption_test_case_1_oop_sgl),
11839
11840                 /** SNOW 3G decrypt only (UEA2) */
11841                 TEST_CASE_ST(ut_setup, ut_teardown,
11842                         test_snow3g_decryption_test_case_1),
11843                 TEST_CASE_ST(ut_setup, ut_teardown,
11844                         test_snow3g_decryption_test_case_2),
11845                 TEST_CASE_ST(ut_setup, ut_teardown,
11846                         test_snow3g_decryption_test_case_3),
11847                 TEST_CASE_ST(ut_setup, ut_teardown,
11848                         test_snow3g_decryption_test_case_4),
11849                 TEST_CASE_ST(ut_setup, ut_teardown,
11850                         test_snow3g_decryption_test_case_5),
11851
11852                 TEST_CASE_ST(ut_setup, ut_teardown,
11853                         test_snow3g_hash_generate_test_case_1),
11854                 TEST_CASE_ST(ut_setup, ut_teardown,
11855                         test_snow3g_hash_generate_test_case_2),
11856                 TEST_CASE_ST(ut_setup, ut_teardown,
11857                         test_snow3g_hash_generate_test_case_3),
11858                 TEST_CASE_ST(ut_setup, ut_teardown,
11859                         test_snow3g_hash_verify_test_case_1),
11860                 TEST_CASE_ST(ut_setup, ut_teardown,
11861                         test_snow3g_hash_verify_test_case_2),
11862                 TEST_CASE_ST(ut_setup, ut_teardown,
11863                         test_snow3g_hash_verify_test_case_3),
11864
11865                 /** ZUC encrypt only (EEA3) */
11866                 TEST_CASE_ST(ut_setup, ut_teardown,
11867                         test_zuc_encryption_test_case_1),
11868                 TEST_CASE_ST(ut_setup, ut_teardown,
11869                         test_zuc_encryption_test_case_2),
11870                 TEST_CASE_ST(ut_setup, ut_teardown,
11871                         test_zuc_encryption_test_case_3),
11872                 TEST_CASE_ST(ut_setup, ut_teardown,
11873                         test_zuc_encryption_test_case_4),
11874                 TEST_CASE_ST(ut_setup, ut_teardown,
11875                         test_zuc_encryption_test_case_5),
11876                 TEST_CASE_ST(ut_setup, ut_teardown,
11877                         test_zuc_hash_generate_test_case_1),
11878                 TEST_CASE_ST(ut_setup, ut_teardown,
11879                         test_zuc_hash_generate_test_case_2),
11880                 TEST_CASE_ST(ut_setup, ut_teardown,
11881                         test_zuc_hash_generate_test_case_3),
11882                 TEST_CASE_ST(ut_setup, ut_teardown,
11883                         test_zuc_hash_generate_test_case_4),
11884                 TEST_CASE_ST(ut_setup, ut_teardown,
11885                         test_zuc_hash_generate_test_case_5),
11886                 TEST_CASE_ST(ut_setup, ut_teardown,
11887                         test_zuc_encryption_test_case_6_sgl),
11888
11889                 /** KASUMI encrypt only (UEA1) */
11890                 TEST_CASE_ST(ut_setup, ut_teardown,
11891                         test_kasumi_encryption_test_case_1),
11892                 TEST_CASE_ST(ut_setup, ut_teardown,
11893                         test_kasumi_encryption_test_case_2),
11894                 TEST_CASE_ST(ut_setup, ut_teardown,
11895                         test_kasumi_encryption_test_case_3),
11896                 TEST_CASE_ST(ut_setup, ut_teardown,
11897                         test_kasumi_encryption_test_case_4),
11898                 TEST_CASE_ST(ut_setup, ut_teardown,
11899                         test_kasumi_encryption_test_case_5),
11900                 TEST_CASE_ST(ut_setup, ut_teardown,
11901                         test_kasumi_encryption_test_case_1_sgl),
11902                 TEST_CASE_ST(ut_setup, ut_teardown,
11903                         test_kasumi_encryption_test_case_1_oop_sgl),
11904                 /** KASUMI decrypt only (UEA1) */
11905                 TEST_CASE_ST(ut_setup, ut_teardown,
11906                         test_kasumi_decryption_test_case_1),
11907                 TEST_CASE_ST(ut_setup, ut_teardown,
11908                         test_kasumi_decryption_test_case_2),
11909                 TEST_CASE_ST(ut_setup, ut_teardown,
11910                         test_kasumi_decryption_test_case_3),
11911                 TEST_CASE_ST(ut_setup, ut_teardown,
11912                         test_kasumi_decryption_test_case_4),
11913                 TEST_CASE_ST(ut_setup, ut_teardown,
11914                         test_kasumi_decryption_test_case_5),
11915
11916                 TEST_CASE_ST(ut_setup, ut_teardown,
11917                         test_kasumi_encryption_test_case_1_oop),
11918                 TEST_CASE_ST(ut_setup, ut_teardown,
11919                         test_kasumi_decryption_test_case_1_oop),
11920
11921                 /** KASUMI hash only (UIA1) */
11922                 TEST_CASE_ST(ut_setup, ut_teardown,
11923                         test_kasumi_hash_generate_test_case_1),
11924                 TEST_CASE_ST(ut_setup, ut_teardown,
11925                         test_kasumi_hash_generate_test_case_2),
11926                 TEST_CASE_ST(ut_setup, ut_teardown,
11927                         test_kasumi_hash_generate_test_case_3),
11928                 TEST_CASE_ST(ut_setup, ut_teardown,
11929                         test_kasumi_hash_generate_test_case_4),
11930                 TEST_CASE_ST(ut_setup, ut_teardown,
11931                         test_kasumi_hash_generate_test_case_5),
11932                 TEST_CASE_ST(ut_setup, ut_teardown,
11933                         test_kasumi_hash_generate_test_case_6),
11934                 TEST_CASE_ST(ut_setup, ut_teardown,
11935                         test_kasumi_hash_verify_test_case_1),
11936                 TEST_CASE_ST(ut_setup, ut_teardown,
11937                         test_kasumi_hash_verify_test_case_2),
11938                 TEST_CASE_ST(ut_setup, ut_teardown,
11939                         test_kasumi_hash_verify_test_case_3),
11940                 TEST_CASE_ST(ut_setup, ut_teardown,
11941                         test_kasumi_hash_verify_test_case_4),
11942                 TEST_CASE_ST(ut_setup, ut_teardown,
11943                         test_kasumi_hash_verify_test_case_5),
11944
11945                 /** NULL tests */
11946                 TEST_CASE_ST(ut_setup, ut_teardown,
11947                         test_null_cipher_only_operation),
11948                 TEST_CASE_ST(ut_setup, ut_teardown,
11949                         test_null_auth_only_operation),
11950                 TEST_CASE_ST(ut_setup, ut_teardown,
11951                         test_null_cipher_auth_operation),
11952                 TEST_CASE_ST(ut_setup, ut_teardown,
11953                         test_null_auth_cipher_operation),
11954
11955                 /** Negative tests */
11956                 TEST_CASE_ST(ut_setup, ut_teardown,
11957                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
11958                 TEST_CASE_ST(ut_setup, ut_teardown,
11959                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
11960                 TEST_CASE_ST(ut_setup, ut_teardown,
11961                         authentication_verify_AES128_GMAC_fail_data_corrupt),
11962                 TEST_CASE_ST(ut_setup, ut_teardown,
11963                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
11964                 TEST_CASE_ST(ut_setup, ut_teardown,
11965                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
11966                 TEST_CASE_ST(ut_setup, ut_teardown,
11967                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
11968                 TEST_CASES_END() /**< NULL terminate unit test array */
11969         }
11970 };
11971
11972 static int
11973 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
11974 {
11975         gbl_driver_id = rte_cryptodev_driver_id_get(
11976                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
11977
11978         if (gbl_driver_id == -1) {
11979                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
11980                 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
11981                 "are enabled in config file to run this testsuite.\n");
11982                 return TEST_SKIPPED;
11983         }
11984
11985         return unit_test_suite_runner(&cryptodev_qat_testsuite);
11986 }
11987
11988 static int
11989 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
11990 {
11991         gbl_driver_id = rte_cryptodev_driver_id_get(
11992                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
11993
11994         if (gbl_driver_id == -1) {
11995                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
11996                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
11997                                 "in config file to run this testsuite.\n");
11998                 return TEST_FAILED;
11999         }
12000
12001         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
12002 }
12003
12004 static int
12005 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
12006 {
12007         gbl_driver_id = rte_cryptodev_driver_id_get(
12008                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12009
12010         if (gbl_driver_id == -1) {
12011                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
12012                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
12013                                 "in config file to run this testsuite.\n");
12014                 return TEST_SKIPPED;
12015         }
12016
12017         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
12018 }
12019
12020 static int
12021 test_cryptodev_openssl(void)
12022 {
12023         gbl_driver_id = rte_cryptodev_driver_id_get(
12024                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
12025
12026         if (gbl_driver_id == -1) {
12027                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
12028                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
12029                                 "in config file to run this testsuite.\n");
12030                 return TEST_SKIPPED;
12031         }
12032
12033         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
12034 }
12035
12036 static int
12037 test_cryptodev_aesni_gcm(void)
12038 {
12039         gbl_driver_id = rte_cryptodev_driver_id_get(
12040                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
12041
12042         if (gbl_driver_id == -1) {
12043                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
12044                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
12045                                 "in config file to run this testsuite.\n");
12046                 return TEST_SKIPPED;
12047         }
12048
12049         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
12050 }
12051
12052 static int
12053 test_cryptodev_null(void)
12054 {
12055         gbl_driver_id = rte_cryptodev_driver_id_get(
12056                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
12057
12058         if (gbl_driver_id == -1) {
12059                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
12060                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
12061                                 "in config file to run this testsuite.\n");
12062                 return TEST_SKIPPED;
12063         }
12064
12065         return unit_test_suite_runner(&cryptodev_null_testsuite);
12066 }
12067
12068 static int
12069 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
12070 {
12071         gbl_driver_id = rte_cryptodev_driver_id_get(
12072                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
12073
12074         if (gbl_driver_id == -1) {
12075                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
12076                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
12077                                 "in config file to run this testsuite.\n");
12078                 return TEST_SKIPPED;
12079         }
12080
12081         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
12082 }
12083
12084 static int
12085 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
12086 {
12087         gbl_driver_id = rte_cryptodev_driver_id_get(
12088                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
12089
12090         if (gbl_driver_id == -1) {
12091                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
12092                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
12093                                 "in config file to run this testsuite.\n");
12094                 return TEST_SKIPPED;
12095         }
12096
12097         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
12098 }
12099
12100 static int
12101 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
12102 {
12103         gbl_driver_id = rte_cryptodev_driver_id_get(
12104                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
12105
12106         if (gbl_driver_id == -1) {
12107                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
12108                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
12109                                 "in config file to run this testsuite.\n");
12110                 return TEST_SKIPPED;
12111         }
12112
12113         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
12114 }
12115
12116 static int
12117 test_cryptodev_armv8(void)
12118 {
12119         gbl_driver_id = rte_cryptodev_driver_id_get(
12120                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
12121
12122         if (gbl_driver_id == -1) {
12123                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
12124                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
12125                                 "in config file to run this testsuite.\n");
12126                 return TEST_SKIPPED;
12127         }
12128
12129         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
12130 }
12131
12132 static int
12133 test_cryptodev_mrvl(void)
12134 {
12135         gbl_driver_id = rte_cryptodev_driver_id_get(
12136                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
12137
12138         if (gbl_driver_id == -1) {
12139                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if "
12140                                 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled "
12141                                 "in config file to run this testsuite.\n");
12142                 return TEST_SKIPPED;
12143         }
12144
12145         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
12146 }
12147
12148 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
12149
12150 static int
12151 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
12152 {
12153         gbl_driver_id = rte_cryptodev_driver_id_get(
12154                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
12155
12156         if (gbl_driver_id == -1) {
12157                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
12158                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
12159                                 "in config file to run this testsuite.\n");
12160                 return TEST_SKIPPED;
12161         }
12162
12163         if (rte_cryptodev_driver_id_get(
12164                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
12165                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
12166                         " enabled in config file to run this testsuite.\n");
12167                 return TEST_SKIPPED;
12168 }
12169         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
12170 }
12171
12172 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
12173
12174 #endif
12175
12176 static int
12177 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
12178 {
12179         gbl_driver_id = rte_cryptodev_driver_id_get(
12180                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
12181
12182         if (gbl_driver_id == -1) {
12183                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
12184                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
12185                                 "in config file to run this testsuite.\n");
12186                 return TEST_SKIPPED;
12187         }
12188
12189         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
12190 }
12191
12192 static int
12193 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
12194 {
12195         gbl_driver_id = rte_cryptodev_driver_id_get(
12196                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
12197
12198         if (gbl_driver_id == -1) {
12199                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
12200                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
12201                                 "in config file to run this testsuite.\n");
12202                 return TEST_SKIPPED;
12203         }
12204
12205         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
12206 }
12207
12208 static int
12209 test_cryptodev_ccp(void)
12210 {
12211         gbl_driver_id = rte_cryptodev_driver_id_get(
12212                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
12213
12214         if (gbl_driver_id == -1) {
12215                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
12216                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
12217                                 "in config file to run this testsuite.\n");
12218                 return TEST_FAILED;
12219         }
12220
12221         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
12222 }
12223
12224 static int
12225 test_cryptodev_octeontx(void)
12226 {
12227         gbl_driver_id = rte_cryptodev_driver_id_get(
12228                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
12229         if (gbl_driver_id == -1) {
12230                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
12231                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
12232                                 "enabled in config file to run this "
12233                                 "testsuite.\n");
12234                 return TEST_FAILED;
12235         }
12236         return unit_test_suite_runner(&cryptodev_octeontx_testsuite);
12237 }
12238
12239 static int
12240 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
12241 {
12242         gbl_driver_id = rte_cryptodev_driver_id_get(
12243                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
12244
12245         if (gbl_driver_id == -1) {
12246                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded. Check if "
12247                                 "CONFIG_RTE_LIBRTE_PMD_CAAM_JR is enabled "
12248                                 "in config file to run this testsuite.\n");
12249                 return TEST_FAILED;
12250         }
12251
12252         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
12253 }
12254
12255 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
12256 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
12257 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
12258 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
12259 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
12260 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
12261 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
12262 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
12263 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
12264 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
12265 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
12266 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
12267 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
12268 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
12269 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
12270 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);