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