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