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