cryptodev: replace mbuf scatter gather flag
[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
3164         uint64_t feat_flags = dev_info.feature_flags;
3165
3166         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3167                 printf("Device doesn't support in-place scatter-gather. "
3168                                 "Test Skipped.\n");
3169                 return 0;
3170         }
3171
3172         /* Create KASUMI session */
3173         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3174                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3175                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3176                                         tdata->key.data, tdata->key.len,
3177                                         tdata->cipher_iv.len);
3178         if (retval < 0)
3179                 return retval;
3180
3181         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3182
3183
3184         /* Append data which is padded to a multiple */
3185         /* of the algorithms block size */
3186         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3187
3188         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3189                         plaintext_pad_len, 10, 0);
3190
3191         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3192
3193         /* Create KASUMI operation */
3194         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3195                                 tdata->cipher_iv.len,
3196                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3197                                 tdata->validCipherOffsetInBits.len);
3198         if (retval < 0)
3199                 return retval;
3200
3201         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3202                                                 ut_params->op);
3203         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3204
3205         ut_params->obuf = ut_params->op->sym->m_dst;
3206
3207         if (ut_params->obuf)
3208                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3209                                 plaintext_len, buffer);
3210         else
3211                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3212                                 tdata->validCipherOffsetInBits.len >> 3,
3213                                 plaintext_len, buffer);
3214
3215         /* Validate obuf */
3216         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3217
3218         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3219                                 (tdata->validCipherOffsetInBits.len >> 3);
3220         /* Validate obuf */
3221         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3222                 ciphertext,
3223                 reference_ciphertext,
3224                 tdata->validCipherLenInBits.len,
3225                 "KASUMI Ciphertext data not as expected");
3226         return 0;
3227 }
3228
3229 static int
3230 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3231 {
3232         struct crypto_testsuite_params *ts_params = &testsuite_params;
3233         struct crypto_unittest_params *ut_params = &unittest_params;
3234
3235         int retval;
3236         uint8_t *plaintext, *ciphertext;
3237         unsigned plaintext_pad_len;
3238         unsigned plaintext_len;
3239
3240         /* Create KASUMI session */
3241         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3242                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3243                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3244                                         tdata->key.data, tdata->key.len,
3245                                         tdata->cipher_iv.len);
3246         if (retval < 0)
3247                 return retval;
3248
3249         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3250         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3251
3252         /* Clear mbuf payload */
3253         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3254                rte_pktmbuf_tailroom(ut_params->ibuf));
3255
3256         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3257         /* Append data which is padded to a multiple */
3258         /* of the algorithms block size */
3259         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3260         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3261                                 plaintext_pad_len);
3262         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3263         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3264
3265         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3266
3267         /* Create KASUMI operation */
3268         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3269                                 tdata->cipher_iv.len,
3270                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3271                                 tdata->validCipherOffsetInBits.len);
3272         if (retval < 0)
3273                 return retval;
3274
3275         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3276                                                 ut_params->op);
3277         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3278
3279         ut_params->obuf = ut_params->op->sym->m_dst;
3280         if (ut_params->obuf)
3281                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3282         else
3283                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3284
3285         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3286
3287         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3288                                 (tdata->validCipherOffsetInBits.len >> 3);
3289         /* Validate obuf */
3290         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3291                 ciphertext,
3292                 reference_ciphertext,
3293                 tdata->validCipherLenInBits.len,
3294                 "KASUMI Ciphertext data not as expected");
3295         return 0;
3296 }
3297
3298 static int
3299 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3300 {
3301         struct crypto_testsuite_params *ts_params = &testsuite_params;
3302         struct crypto_unittest_params *ut_params = &unittest_params;
3303
3304         int retval;
3305         unsigned int plaintext_pad_len;
3306         unsigned int plaintext_len;
3307
3308         const uint8_t *ciphertext;
3309         uint8_t buffer[2048];
3310
3311         struct rte_cryptodev_info dev_info;
3312
3313         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3314
3315         uint64_t feat_flags = dev_info.feature_flags;
3316         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3317                 printf("Device doesn't support out-of-place scatter-gather "
3318                                 "in both input and output mbufs. "
3319                                 "Test Skipped.\n");
3320                 return 0;
3321         }
3322
3323         /* Create KASUMI session */
3324         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3325                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3326                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3327                                         tdata->key.data, tdata->key.len,
3328                                         tdata->cipher_iv.len);
3329         if (retval < 0)
3330                 return retval;
3331
3332         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3333         /* Append data which is padded to a multiple */
3334         /* of the algorithms block size */
3335         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3336
3337         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3338                         plaintext_pad_len, 10, 0);
3339         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3340                         plaintext_pad_len, 3, 0);
3341
3342         /* Append data which is padded to a multiple */
3343         /* of the algorithms block size */
3344         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3345
3346         /* Create KASUMI operation */
3347         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3348                                 tdata->cipher_iv.len,
3349                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3350                                 tdata->validCipherOffsetInBits.len);
3351         if (retval < 0)
3352                 return retval;
3353
3354         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3355                                                 ut_params->op);
3356         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3357
3358         ut_params->obuf = ut_params->op->sym->m_dst;
3359         if (ut_params->obuf)
3360                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3361                                 plaintext_pad_len, buffer);
3362         else
3363                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3364                                 tdata->validCipherOffsetInBits.len >> 3,
3365                                 plaintext_pad_len, buffer);
3366
3367         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3368                                 (tdata->validCipherOffsetInBits.len >> 3);
3369         /* Validate obuf */
3370         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3371                 ciphertext,
3372                 reference_ciphertext,
3373                 tdata->validCipherLenInBits.len,
3374                 "KASUMI Ciphertext data not as expected");
3375         return 0;
3376 }
3377
3378
3379 static int
3380 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3381 {
3382         struct crypto_testsuite_params *ts_params = &testsuite_params;
3383         struct crypto_unittest_params *ut_params = &unittest_params;
3384
3385         int retval;
3386         uint8_t *ciphertext, *plaintext;
3387         unsigned ciphertext_pad_len;
3388         unsigned ciphertext_len;
3389
3390         /* Create KASUMI session */
3391         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3392                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3393                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3394                                         tdata->key.data, tdata->key.len,
3395                                         tdata->cipher_iv.len);
3396         if (retval < 0)
3397                 return retval;
3398
3399         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3400         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3401
3402         /* Clear mbuf payload */
3403         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3404                rte_pktmbuf_tailroom(ut_params->ibuf));
3405
3406         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3407         /* Append data which is padded to a multiple */
3408         /* of the algorithms block size */
3409         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3410         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3411                                 ciphertext_pad_len);
3412         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3413         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3414
3415         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3416
3417         /* Create KASUMI operation */
3418         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3419                                 tdata->cipher_iv.len,
3420                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3421                                 tdata->validCipherOffsetInBits.len);
3422         if (retval < 0)
3423                 return retval;
3424
3425         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3426                                                 ut_params->op);
3427         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3428
3429         ut_params->obuf = ut_params->op->sym->m_dst;
3430         if (ut_params->obuf)
3431                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3432         else
3433                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3434
3435         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3436
3437         const uint8_t *reference_plaintext = tdata->plaintext.data +
3438                                 (tdata->validCipherOffsetInBits.len >> 3);
3439         /* Validate obuf */
3440         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3441                 plaintext,
3442                 reference_plaintext,
3443                 tdata->validCipherLenInBits.len,
3444                 "KASUMI Plaintext data not as expected");
3445         return 0;
3446 }
3447
3448 static int
3449 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3450 {
3451         struct crypto_testsuite_params *ts_params = &testsuite_params;
3452         struct crypto_unittest_params *ut_params = &unittest_params;
3453
3454         int retval;
3455         uint8_t *ciphertext, *plaintext;
3456         unsigned ciphertext_pad_len;
3457         unsigned ciphertext_len;
3458
3459         /* Create KASUMI session */
3460         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3461                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3462                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3463                                         tdata->key.data, tdata->key.len,
3464                                         tdata->cipher_iv.len);
3465         if (retval < 0)
3466                 return retval;
3467
3468         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3469
3470         /* Clear mbuf payload */
3471         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3472                rte_pktmbuf_tailroom(ut_params->ibuf));
3473
3474         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3475         /* Append data which is padded to a multiple */
3476         /* of the algorithms block size */
3477         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3478         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3479                                 ciphertext_pad_len);
3480         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3481
3482         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3483
3484         /* Create KASUMI operation */
3485         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3486                                         tdata->cipher_iv.len,
3487                                         tdata->ciphertext.len,
3488                                         tdata->validCipherOffsetInBits.len);
3489         if (retval < 0)
3490                 return retval;
3491
3492         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3493                                                 ut_params->op);
3494         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3495
3496         ut_params->obuf = ut_params->op->sym->m_dst;
3497         if (ut_params->obuf)
3498                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3499         else
3500                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3501
3502         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3503
3504         const uint8_t *reference_plaintext = tdata->plaintext.data +
3505                                 (tdata->validCipherOffsetInBits.len >> 3);
3506         /* Validate obuf */
3507         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3508                 plaintext,
3509                 reference_plaintext,
3510                 tdata->validCipherLenInBits.len,
3511                 "KASUMI Plaintext data not as expected");
3512         return 0;
3513 }
3514
3515 static int
3516 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3517 {
3518         struct crypto_testsuite_params *ts_params = &testsuite_params;
3519         struct crypto_unittest_params *ut_params = &unittest_params;
3520
3521         int retval;
3522         uint8_t *plaintext, *ciphertext;
3523         unsigned plaintext_pad_len;
3524         unsigned plaintext_len;
3525
3526         /* Create SNOW 3G session */
3527         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3528                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3529                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3530                                         tdata->key.data, tdata->key.len,
3531                                         tdata->cipher_iv.len);
3532         if (retval < 0)
3533                 return retval;
3534
3535         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3536
3537         /* Clear mbuf payload */
3538         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3539                rte_pktmbuf_tailroom(ut_params->ibuf));
3540
3541         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3542         /* Append data which is padded to a multiple of */
3543         /* the algorithms block size */
3544         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3545         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3546                                 plaintext_pad_len);
3547         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3548
3549         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3550
3551         /* Create SNOW 3G operation */
3552         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3553                                         tdata->cipher_iv.len,
3554                                         tdata->validCipherLenInBits.len,
3555                                         0);
3556         if (retval < 0)
3557                 return retval;
3558
3559         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3560                                                 ut_params->op);
3561         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3562
3563         ut_params->obuf = ut_params->op->sym->m_dst;
3564         if (ut_params->obuf)
3565                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3566         else
3567                 ciphertext = plaintext;
3568
3569         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3570
3571         /* Validate obuf */
3572         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3573                 ciphertext,
3574                 tdata->ciphertext.data,
3575                 tdata->validDataLenInBits.len,
3576                 "SNOW 3G Ciphertext data not as expected");
3577         return 0;
3578 }
3579
3580
3581 static int
3582 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3583 {
3584         struct crypto_testsuite_params *ts_params = &testsuite_params;
3585         struct crypto_unittest_params *ut_params = &unittest_params;
3586         uint8_t *plaintext, *ciphertext;
3587
3588         int retval;
3589         unsigned plaintext_pad_len;
3590         unsigned plaintext_len;
3591
3592         /* Create SNOW 3G session */
3593         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3594                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3595                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3596                                         tdata->key.data, tdata->key.len,
3597                                         tdata->cipher_iv.len);
3598         if (retval < 0)
3599                 return retval;
3600
3601         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3602         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3603
3604         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3605                         "Failed to allocate input buffer in mempool");
3606         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3607                         "Failed to allocate output buffer in mempool");
3608
3609         /* Clear mbuf payload */
3610         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3611                rte_pktmbuf_tailroom(ut_params->ibuf));
3612
3613         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3614         /* Append data which is padded to a multiple of */
3615         /* the algorithms block size */
3616         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3617         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3618                                 plaintext_pad_len);
3619         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3620         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3621
3622         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3623
3624         /* Create SNOW 3G operation */
3625         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3626                                         tdata->cipher_iv.len,
3627                                         tdata->validCipherLenInBits.len,
3628                                         0);
3629         if (retval < 0)
3630                 return retval;
3631
3632         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3633                                                 ut_params->op);
3634         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3635
3636         ut_params->obuf = ut_params->op->sym->m_dst;
3637         if (ut_params->obuf)
3638                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3639         else
3640                 ciphertext = plaintext;
3641
3642         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3643
3644         /* Validate obuf */
3645         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3646                 ciphertext,
3647                 tdata->ciphertext.data,
3648                 tdata->validDataLenInBits.len,
3649                 "SNOW 3G Ciphertext data not as expected");
3650         return 0;
3651 }
3652
3653 static int
3654 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3655 {
3656         struct crypto_testsuite_params *ts_params = &testsuite_params;
3657         struct crypto_unittest_params *ut_params = &unittest_params;
3658
3659         int retval;
3660         unsigned int plaintext_pad_len;
3661         unsigned int plaintext_len;
3662         uint8_t buffer[10000];
3663         const uint8_t *ciphertext;
3664
3665         struct rte_cryptodev_info dev_info;
3666
3667         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3668
3669         uint64_t feat_flags = dev_info.feature_flags;
3670
3671         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3672                 printf("Device doesn't support out-of-place scatter-gather "
3673                                 "in both input and output mbufs. "
3674                                 "Test Skipped.\n");
3675                 return 0;
3676         }
3677
3678         /* Create SNOW 3G session */
3679         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3680                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3681                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3682                                         tdata->key.data, tdata->key.len,
3683                                         tdata->cipher_iv.len);
3684         if (retval < 0)
3685                 return retval;
3686
3687         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3688         /* Append data which is padded to a multiple of */
3689         /* the algorithms block size */
3690         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3691
3692         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3693                         plaintext_pad_len, 10, 0);
3694         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3695                         plaintext_pad_len, 3, 0);
3696
3697         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3698                         "Failed to allocate input buffer in mempool");
3699         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3700                         "Failed to allocate output buffer in mempool");
3701
3702         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3703
3704         /* Create SNOW 3G operation */
3705         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3706                                         tdata->cipher_iv.len,
3707                                         tdata->validCipherLenInBits.len,
3708                                         0);
3709         if (retval < 0)
3710                 return retval;
3711
3712         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3713                                                 ut_params->op);
3714         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3715
3716         ut_params->obuf = ut_params->op->sym->m_dst;
3717         if (ut_params->obuf)
3718                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3719                                 plaintext_len, buffer);
3720         else
3721                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3722                                 plaintext_len, buffer);
3723
3724         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3725
3726         /* Validate obuf */
3727         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3728                 ciphertext,
3729                 tdata->ciphertext.data,
3730                 tdata->validDataLenInBits.len,
3731                 "SNOW 3G Ciphertext data not as expected");
3732
3733         return 0;
3734 }
3735
3736 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3737 static void
3738 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3739 {
3740         uint8_t curr_byte, prev_byte;
3741         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3742         uint8_t lower_byte_mask = (1 << offset) - 1;
3743         unsigned i;
3744
3745         prev_byte = buffer[0];
3746         buffer[0] >>= offset;
3747
3748         for (i = 1; i < length_in_bytes; i++) {
3749                 curr_byte = buffer[i];
3750                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3751                                 (curr_byte >> offset);
3752                 prev_byte = curr_byte;
3753         }
3754 }
3755
3756 static int
3757 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3758 {
3759         struct crypto_testsuite_params *ts_params = &testsuite_params;
3760         struct crypto_unittest_params *ut_params = &unittest_params;
3761         uint8_t *plaintext, *ciphertext;
3762         int retval;
3763         uint32_t plaintext_len;
3764         uint32_t plaintext_pad_len;
3765         uint8_t extra_offset = 4;
3766         uint8_t *expected_ciphertext_shifted;
3767
3768         /* Create SNOW 3G session */
3769         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3770                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3771                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3772                                         tdata->key.data, tdata->key.len,
3773                                         tdata->cipher_iv.len);
3774         if (retval < 0)
3775                 return retval;
3776
3777         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3778         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3779
3780         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3781                         "Failed to allocate input buffer in mempool");
3782         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3783                         "Failed to allocate output buffer in mempool");
3784
3785         /* Clear mbuf payload */
3786         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3787                rte_pktmbuf_tailroom(ut_params->ibuf));
3788
3789         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3790         /*
3791          * Append data which is padded to a
3792          * multiple of the algorithms block size
3793          */
3794         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3795
3796         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3797                                                 plaintext_pad_len);
3798
3799         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3800
3801         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3802         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3803
3804 #ifdef RTE_APP_TEST_DEBUG
3805         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3806 #endif
3807         /* Create SNOW 3G operation */
3808         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3809                                         tdata->cipher_iv.len,
3810                                         tdata->validCipherLenInBits.len,
3811                                         extra_offset);
3812         if (retval < 0)
3813                 return retval;
3814
3815         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3816                                                 ut_params->op);
3817         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3818
3819         ut_params->obuf = ut_params->op->sym->m_dst;
3820         if (ut_params->obuf)
3821                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3822         else
3823                 ciphertext = plaintext;
3824
3825 #ifdef RTE_APP_TEST_DEBUG
3826         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3827 #endif
3828
3829         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
3830
3831         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3832                         "failed to reserve memory for ciphertext shifted\n");
3833
3834         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3835                         ceil_byte_length(tdata->ciphertext.len));
3836         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3837                         extra_offset);
3838         /* Validate obuf */
3839         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3840                 ciphertext,
3841                 expected_ciphertext_shifted,
3842                 tdata->validDataLenInBits.len,
3843                 extra_offset,
3844                 "SNOW 3G Ciphertext data not as expected");
3845         return 0;
3846 }
3847
3848 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3849 {
3850         struct crypto_testsuite_params *ts_params = &testsuite_params;
3851         struct crypto_unittest_params *ut_params = &unittest_params;
3852
3853         int retval;
3854
3855         uint8_t *plaintext, *ciphertext;
3856         unsigned ciphertext_pad_len;
3857         unsigned ciphertext_len;
3858
3859         /* Create SNOW 3G session */
3860         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3861                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3862                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3863                                         tdata->key.data, tdata->key.len,
3864                                         tdata->cipher_iv.len);
3865         if (retval < 0)
3866                 return retval;
3867
3868         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3869
3870         /* Clear mbuf payload */
3871         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3872                rte_pktmbuf_tailroom(ut_params->ibuf));
3873
3874         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3875         /* Append data which is padded to a multiple of */
3876         /* the algorithms block size */
3877         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3878         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3879                                 ciphertext_pad_len);
3880         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3881
3882         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3883
3884         /* Create SNOW 3G operation */
3885         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3886                                         tdata->cipher_iv.len,
3887                                         tdata->validCipherLenInBits.len,
3888                                         0);
3889         if (retval < 0)
3890                 return retval;
3891
3892         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3893                                                 ut_params->op);
3894         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3895         ut_params->obuf = ut_params->op->sym->m_dst;
3896         if (ut_params->obuf)
3897                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3898         else
3899                 plaintext = ciphertext;
3900
3901         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3902
3903         /* Validate obuf */
3904         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3905                                 tdata->plaintext.data,
3906                                 tdata->validDataLenInBits.len,
3907                                 "SNOW 3G Plaintext data not as expected");
3908         return 0;
3909 }
3910
3911 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3912 {
3913         struct crypto_testsuite_params *ts_params = &testsuite_params;
3914         struct crypto_unittest_params *ut_params = &unittest_params;
3915
3916         int retval;
3917
3918         uint8_t *plaintext, *ciphertext;
3919         unsigned ciphertext_pad_len;
3920         unsigned ciphertext_len;
3921
3922         /* Create SNOW 3G session */
3923         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3924                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3925                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3926                                         tdata->key.data, tdata->key.len,
3927                                         tdata->cipher_iv.len);
3928         if (retval < 0)
3929                 return retval;
3930
3931         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3932         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3933
3934         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3935                         "Failed to allocate input buffer");
3936         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3937                         "Failed to allocate output buffer");
3938
3939         /* Clear mbuf payload */
3940         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3941                rte_pktmbuf_tailroom(ut_params->ibuf));
3942
3943         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3944                        rte_pktmbuf_tailroom(ut_params->obuf));
3945
3946         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3947         /* Append data which is padded to a multiple of */
3948         /* the algorithms block size */
3949         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3950         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3951                                 ciphertext_pad_len);
3952         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3953         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3954
3955         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3956
3957         /* Create SNOW 3G operation */
3958         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3959                                         tdata->cipher_iv.len,
3960                                         tdata->validCipherLenInBits.len,
3961                                         0);
3962         if (retval < 0)
3963                 return retval;
3964
3965         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3966                                                 ut_params->op);
3967         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3968         ut_params->obuf = ut_params->op->sym->m_dst;
3969         if (ut_params->obuf)
3970                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3971         else
3972                 plaintext = ciphertext;
3973
3974         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3975
3976         /* Validate obuf */
3977         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3978                                 tdata->plaintext.data,
3979                                 tdata->validDataLenInBits.len,
3980                                 "SNOW 3G Plaintext data not as expected");
3981         return 0;
3982 }
3983
3984 static int
3985 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
3986 {
3987         struct crypto_testsuite_params *ts_params = &testsuite_params;
3988         struct crypto_unittest_params *ut_params = &unittest_params;
3989
3990         int retval;
3991
3992         uint8_t *plaintext, *ciphertext;
3993         unsigned int plaintext_pad_len;
3994         unsigned int plaintext_len;
3995
3996         struct rte_cryptodev_sym_capability_idx cap_idx;
3997
3998         /* Check if device supports ZUC EEA3 */
3999         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4000         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4001
4002         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4003                         &cap_idx) == NULL)
4004                 return -ENOTSUP;
4005
4006         /* Check if device supports ZUC EIA3 */
4007         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4008         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4009
4010         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4011                         &cap_idx) == NULL)
4012                 return -ENOTSUP;
4013
4014         /* Create ZUC session */
4015         retval = create_zuc_cipher_auth_encrypt_generate_session(
4016                         ts_params->valid_devs[0],
4017                         tdata);
4018         if (retval < 0)
4019                 return retval;
4020         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4021
4022         /* clear mbuf payload */
4023         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4024                         rte_pktmbuf_tailroom(ut_params->ibuf));
4025
4026         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4027         /* Append data which is padded to a multiple of */
4028         /* the algorithms block size */
4029         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4030         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4031                                 plaintext_pad_len);
4032         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4033
4034         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4035
4036         /* Create ZUC operation */
4037         retval = create_zuc_cipher_hash_generate_operation(tdata);
4038         if (retval < 0)
4039                 return retval;
4040
4041         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4042                         ut_params->op);
4043         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4044         ut_params->obuf = ut_params->op->sym->m_src;
4045         if (ut_params->obuf)
4046                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4047         else
4048                 ciphertext = plaintext;
4049
4050         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4051         /* Validate obuf */
4052         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4053                         ciphertext,
4054                         tdata->ciphertext.data,
4055                         tdata->validDataLenInBits.len,
4056                         "ZUC Ciphertext data not as expected");
4057
4058         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4059             + plaintext_pad_len;
4060
4061         /* Validate obuf */
4062         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4063                         ut_params->digest,
4064                         tdata->digest.data,
4065                         4,
4066                         "ZUC Generated auth tag not as expected");
4067         return 0;
4068 }
4069
4070 static int
4071 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4072 {
4073         struct crypto_testsuite_params *ts_params = &testsuite_params;
4074         struct crypto_unittest_params *ut_params = &unittest_params;
4075
4076         int retval;
4077
4078         uint8_t *plaintext, *ciphertext;
4079         unsigned plaintext_pad_len;
4080         unsigned plaintext_len;
4081
4082         /* Create SNOW 3G session */
4083         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4084                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4085                         RTE_CRYPTO_AUTH_OP_GENERATE,
4086                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4087                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4088                         tdata->key.data, tdata->key.len,
4089                         tdata->auth_iv.len, tdata->digest.len,
4090                         tdata->cipher_iv.len);
4091         if (retval < 0)
4092                 return retval;
4093         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4094
4095         /* clear mbuf payload */
4096         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4097                         rte_pktmbuf_tailroom(ut_params->ibuf));
4098
4099         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4100         /* Append data which is padded to a multiple of */
4101         /* the algorithms block size */
4102         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4103         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4104                                 plaintext_pad_len);
4105         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4106
4107         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4108
4109         /* Create SNOW 3G operation */
4110         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4111                         tdata->digest.len, tdata->auth_iv.data,
4112                         tdata->auth_iv.len,
4113                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4114                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4115                         tdata->validCipherLenInBits.len,
4116                         0,
4117                         tdata->validAuthLenInBits.len,
4118                         0
4119                         );
4120         if (retval < 0)
4121                 return retval;
4122
4123         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4124                         ut_params->op);
4125         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4126         ut_params->obuf = ut_params->op->sym->m_src;
4127         if (ut_params->obuf)
4128                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4129         else
4130                 ciphertext = plaintext;
4131
4132         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4133         /* Validate obuf */
4134         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4135                         ciphertext,
4136                         tdata->ciphertext.data,
4137                         tdata->validDataLenInBits.len,
4138                         "SNOW 3G Ciphertext data not as expected");
4139
4140         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4141             + plaintext_pad_len;
4142
4143         /* Validate obuf */
4144         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4145                         ut_params->digest,
4146                         tdata->digest.data,
4147                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4148                         "SNOW 3G Generated auth tag not as expected");
4149         return 0;
4150 }
4151 static int
4152 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
4153 {
4154         struct crypto_testsuite_params *ts_params = &testsuite_params;
4155         struct crypto_unittest_params *ut_params = &unittest_params;
4156
4157         int retval;
4158
4159         uint8_t *plaintext, *ciphertext;
4160         unsigned plaintext_pad_len;
4161         unsigned plaintext_len;
4162
4163         /* Create SNOW 3G session */
4164         retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
4165                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4166                         RTE_CRYPTO_AUTH_OP_GENERATE,
4167                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4168                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4169                         tdata->key.data, tdata->key.len,
4170                         tdata->auth_iv.len, tdata->digest.len,
4171                         tdata->cipher_iv.len);
4172         if (retval < 0)
4173                 return retval;
4174
4175         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4176
4177         /* clear mbuf payload */
4178         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4179                         rte_pktmbuf_tailroom(ut_params->ibuf));
4180
4181         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4182         /* Append data which is padded to a multiple of */
4183         /* the algorithms block size */
4184         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4185         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4186                                 plaintext_pad_len);
4187         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4188
4189         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4190
4191         /* Create SNOW 3G operation */
4192         retval = create_wireless_algo_auth_cipher_operation(
4193                 tdata->digest.len,
4194                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4195                 tdata->auth_iv.data, tdata->auth_iv.len,
4196                 plaintext_pad_len,
4197                 tdata->validCipherLenInBits.len,
4198                 0,
4199                 tdata->validAuthLenInBits.len,
4200                 0);
4201
4202         if (retval < 0)
4203                 return retval;
4204
4205         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4206                         ut_params->op);
4207         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4208         ut_params->obuf = ut_params->op->sym->m_src;
4209         if (ut_params->obuf)
4210                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4211         else
4212                 ciphertext = plaintext;
4213
4214         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4215                         + plaintext_pad_len;
4216         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4217
4218         /* Validate obuf */
4219         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4220                 ciphertext,
4221                 tdata->ciphertext.data,
4222                 tdata->validDataLenInBits.len,
4223                 "SNOW 3G Ciphertext data not as expected");
4224
4225         /* Validate obuf */
4226         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4227                 ut_params->digest,
4228                 tdata->digest.data,
4229                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4230                 "SNOW 3G Generated auth tag not as expected");
4231         return 0;
4232 }
4233
4234 static int
4235 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
4236 {
4237         struct crypto_testsuite_params *ts_params = &testsuite_params;
4238         struct crypto_unittest_params *ut_params = &unittest_params;
4239
4240         int retval;
4241
4242         uint8_t *plaintext, *ciphertext;
4243         unsigned plaintext_pad_len;
4244         unsigned plaintext_len;
4245
4246         /* Create KASUMI session */
4247         retval = create_wireless_algo_auth_cipher_session(
4248                         ts_params->valid_devs[0],
4249                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4250                         RTE_CRYPTO_AUTH_OP_GENERATE,
4251                         RTE_CRYPTO_AUTH_KASUMI_F9,
4252                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4253                         tdata->key.data, tdata->key.len,
4254                         0, tdata->digest.len,
4255                         tdata->cipher_iv.len);
4256         if (retval < 0)
4257                 return retval;
4258         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4259
4260         /* clear mbuf payload */
4261         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4262                         rte_pktmbuf_tailroom(ut_params->ibuf));
4263
4264         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4265         /* Append data which is padded to a multiple of */
4266         /* the algorithms block size */
4267         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4268         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4269                                 plaintext_pad_len);
4270         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4271
4272         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4273
4274         /* Create KASUMI operation */
4275         retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
4276                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4277                                 NULL, 0,
4278                                 plaintext_pad_len,
4279                                 tdata->validCipherLenInBits.len,
4280                                 tdata->validCipherOffsetInBits.len,
4281                                 tdata->validAuthLenInBits.len,
4282                                 0
4283                                 );
4284
4285         if (retval < 0)
4286                 return retval;
4287
4288         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4289                         ut_params->op);
4290         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4291         if (ut_params->op->sym->m_dst)
4292                 ut_params->obuf = ut_params->op->sym->m_dst;
4293         else
4294                 ut_params->obuf = ut_params->op->sym->m_src;
4295
4296         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4297                                 tdata->validCipherOffsetInBits.len >> 3);
4298
4299         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4300                                 (tdata->validCipherOffsetInBits.len >> 3);
4301         /* Validate obuf */
4302         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4303                         ciphertext,
4304                         reference_ciphertext,
4305                         tdata->validCipherLenInBits.len,
4306                         "KASUMI Ciphertext data not as expected");
4307         ut_params->digest = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *)
4308             + plaintext_pad_len;
4309
4310         /* Validate obuf */
4311         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4312                         ut_params->digest,
4313                         tdata->digest.data,
4314                         DIGEST_BYTE_LENGTH_KASUMI_F9,
4315                         "KASUMI Generated auth tag not as expected");
4316         return 0;
4317 }
4318
4319 static int
4320 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
4321 {
4322         struct crypto_testsuite_params *ts_params = &testsuite_params;
4323         struct crypto_unittest_params *ut_params = &unittest_params;
4324
4325         int retval;
4326
4327         uint8_t *plaintext, *ciphertext;
4328         unsigned plaintext_pad_len;
4329         unsigned plaintext_len;
4330
4331         /* Create KASUMI session */
4332         retval = create_wireless_algo_cipher_auth_session(
4333                         ts_params->valid_devs[0],
4334                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4335                         RTE_CRYPTO_AUTH_OP_GENERATE,
4336                         RTE_CRYPTO_AUTH_KASUMI_F9,
4337                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4338                         tdata->key.data, tdata->key.len,
4339                         0, tdata->digest.len,
4340                         tdata->cipher_iv.len);
4341         if (retval < 0)
4342                 return retval;
4343
4344         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4345
4346         /* clear mbuf payload */
4347         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4348                         rte_pktmbuf_tailroom(ut_params->ibuf));
4349
4350         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4351         /* Append data which is padded to a multiple of */
4352         /* the algorithms block size */
4353         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4354         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4355                                 plaintext_pad_len);
4356         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4357
4358         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4359
4360         /* Create KASUMI operation */
4361         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4362                                 tdata->digest.len, NULL, 0,
4363                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4364                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4365                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4366                                 tdata->validCipherOffsetInBits.len,
4367                                 tdata->validAuthLenInBits.len,
4368                                 0
4369                                 );
4370         if (retval < 0)
4371                 return retval;
4372
4373         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4374                         ut_params->op);
4375         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4376
4377         if (ut_params->op->sym->m_dst)
4378                 ut_params->obuf = ut_params->op->sym->m_dst;
4379         else
4380                 ut_params->obuf = ut_params->op->sym->m_src;
4381
4382         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4383                                 tdata->validCipherOffsetInBits.len >> 3);
4384
4385         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4386                         + plaintext_pad_len;
4387
4388         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4389                                 (tdata->validCipherOffsetInBits.len >> 3);
4390         /* Validate obuf */
4391         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4392                 ciphertext,
4393                 reference_ciphertext,
4394                 tdata->validCipherLenInBits.len,
4395                 "KASUMI Ciphertext data not as expected");
4396
4397         /* Validate obuf */
4398         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4399                 ut_params->digest,
4400                 tdata->digest.data,
4401                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4402                 "KASUMI Generated auth tag not as expected");
4403         return 0;
4404 }
4405
4406 static int
4407 test_zuc_encryption(const struct wireless_test_data *tdata)
4408 {
4409         struct crypto_testsuite_params *ts_params = &testsuite_params;
4410         struct crypto_unittest_params *ut_params = &unittest_params;
4411
4412         int retval;
4413         uint8_t *plaintext, *ciphertext;
4414         unsigned plaintext_pad_len;
4415         unsigned plaintext_len;
4416
4417         struct rte_cryptodev_sym_capability_idx cap_idx;
4418
4419         /* Check if device supports ZUC EEA3 */
4420         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4421         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4422
4423         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4424                         &cap_idx) == NULL)
4425                 return -ENOTSUP;
4426
4427         /* Create ZUC session */
4428         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4429                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4430                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4431                                         tdata->key.data, tdata->key.len,
4432                                         tdata->cipher_iv.len);
4433         if (retval < 0)
4434                 return retval;
4435
4436         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4437
4438         /* Clear mbuf payload */
4439         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4440                rte_pktmbuf_tailroom(ut_params->ibuf));
4441
4442         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4443         /* Append data which is padded to a multiple */
4444         /* of the algorithms block size */
4445         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4446         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4447                                 plaintext_pad_len);
4448         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4449
4450         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4451
4452         /* Create ZUC operation */
4453         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4454                                         tdata->cipher_iv.len,
4455                                         tdata->plaintext.len,
4456                                         0);
4457         if (retval < 0)
4458                 return retval;
4459
4460         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4461                                                 ut_params->op);
4462         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4463
4464         ut_params->obuf = ut_params->op->sym->m_dst;
4465         if (ut_params->obuf)
4466                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4467         else
4468                 ciphertext = plaintext;
4469
4470         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4471
4472         /* Validate obuf */
4473         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4474                 ciphertext,
4475                 tdata->ciphertext.data,
4476                 tdata->validCipherLenInBits.len,
4477                 "ZUC Ciphertext data not as expected");
4478         return 0;
4479 }
4480
4481 static int
4482 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
4483 {
4484         struct crypto_testsuite_params *ts_params = &testsuite_params;
4485         struct crypto_unittest_params *ut_params = &unittest_params;
4486
4487         int retval;
4488
4489         unsigned int plaintext_pad_len;
4490         unsigned int plaintext_len;
4491         const uint8_t *ciphertext;
4492         uint8_t ciphertext_buffer[2048];
4493         struct rte_cryptodev_info dev_info;
4494
4495         struct rte_cryptodev_sym_capability_idx cap_idx;
4496
4497         /* Check if device supports ZUC EEA3 */
4498         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4499         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4500
4501         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4502                         &cap_idx) == NULL)
4503                 return -ENOTSUP;
4504
4505         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4506
4507         uint64_t feat_flags = dev_info.feature_flags;
4508
4509         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4510                 printf("Device doesn't support in-place scatter-gather. "
4511                                 "Test Skipped.\n");
4512                 return 0;
4513         }
4514
4515         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4516
4517         /* Append data which is padded to a multiple */
4518         /* of the algorithms block size */
4519         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4520
4521         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4522                         plaintext_pad_len, 10, 0);
4523
4524         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4525                         tdata->plaintext.data);
4526
4527         /* Create ZUC session */
4528         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4529                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4530                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4531                         tdata->key.data, tdata->key.len,
4532                         tdata->cipher_iv.len);
4533         if (retval < 0)
4534                 return retval;
4535
4536         /* Clear mbuf payload */
4537
4538         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4539
4540         /* Create ZUC operation */
4541         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4542                         tdata->cipher_iv.len, tdata->plaintext.len,
4543                         0);
4544         if (retval < 0)
4545                 return retval;
4546
4547         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4548                                                 ut_params->op);
4549         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4550
4551         ut_params->obuf = ut_params->op->sym->m_dst;
4552         if (ut_params->obuf)
4553                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
4554                         0, plaintext_len, ciphertext_buffer);
4555         else
4556                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4557                         0, plaintext_len, ciphertext_buffer);
4558
4559         /* Validate obuf */
4560         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4561
4562         /* Validate obuf */
4563         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4564                 ciphertext,
4565                 tdata->ciphertext.data,
4566                 tdata->validCipherLenInBits.len,
4567                 "ZUC Ciphertext data not as expected");
4568
4569         return 0;
4570 }
4571
4572 static int
4573 test_zuc_authentication(const struct wireless_test_data *tdata)
4574 {
4575         struct crypto_testsuite_params *ts_params = &testsuite_params;
4576         struct crypto_unittest_params *ut_params = &unittest_params;
4577
4578         int retval;
4579         unsigned plaintext_pad_len;
4580         unsigned plaintext_len;
4581         uint8_t *plaintext;
4582
4583         struct rte_cryptodev_sym_capability_idx cap_idx;
4584
4585         /* Check if device supports ZUC EIA3 */
4586         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4587         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4588
4589         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4590                         &cap_idx) == NULL)
4591                 return -ENOTSUP;
4592
4593         /* Create ZUC session */
4594         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
4595                         tdata->key.data, tdata->key.len,
4596                         tdata->auth_iv.len, tdata->digest.len,
4597                         RTE_CRYPTO_AUTH_OP_GENERATE,
4598                         RTE_CRYPTO_AUTH_ZUC_EIA3);
4599         if (retval < 0)
4600                 return retval;
4601
4602         /* alloc mbuf and set payload */
4603         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4604
4605         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4606         rte_pktmbuf_tailroom(ut_params->ibuf));
4607
4608         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4609         /* Append data which is padded to a multiple of */
4610         /* the algorithms block size */
4611         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4612         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4613                                 plaintext_pad_len);
4614         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4615
4616         /* Create ZUC operation */
4617         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
4618                         tdata->auth_iv.data, tdata->auth_iv.len,
4619                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4620                         tdata->validAuthLenInBits.len,
4621                         0);
4622         if (retval < 0)
4623                 return retval;
4624
4625         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4626                                 ut_params->op);
4627         ut_params->obuf = ut_params->op->sym->m_src;
4628         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4629         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4630                         + plaintext_pad_len;
4631
4632         /* Validate obuf */
4633         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4634         ut_params->digest,
4635         tdata->digest.data,
4636         DIGEST_BYTE_LENGTH_KASUMI_F9,
4637         "ZUC Generated auth tag not as expected");
4638
4639         return 0;
4640 }
4641
4642 static int
4643 test_kasumi_encryption_test_case_1(void)
4644 {
4645         return test_kasumi_encryption(&kasumi_test_case_1);
4646 }
4647
4648 static int
4649 test_kasumi_encryption_test_case_1_sgl(void)
4650 {
4651         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
4652 }
4653
4654 static int
4655 test_kasumi_encryption_test_case_1_oop(void)
4656 {
4657         return test_kasumi_encryption_oop(&kasumi_test_case_1);
4658 }
4659
4660 static int
4661 test_kasumi_encryption_test_case_1_oop_sgl(void)
4662 {
4663         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
4664 }
4665
4666 static int
4667 test_kasumi_encryption_test_case_2(void)
4668 {
4669         return test_kasumi_encryption(&kasumi_test_case_2);
4670 }
4671
4672 static int
4673 test_kasumi_encryption_test_case_3(void)
4674 {
4675         return test_kasumi_encryption(&kasumi_test_case_3);
4676 }
4677
4678 static int
4679 test_kasumi_encryption_test_case_4(void)
4680 {
4681         return test_kasumi_encryption(&kasumi_test_case_4);
4682 }
4683
4684 static int
4685 test_kasumi_encryption_test_case_5(void)
4686 {
4687         return test_kasumi_encryption(&kasumi_test_case_5);
4688 }
4689
4690 static int
4691 test_kasumi_decryption_test_case_1(void)
4692 {
4693         return test_kasumi_decryption(&kasumi_test_case_1);
4694 }
4695
4696 static int
4697 test_kasumi_decryption_test_case_1_oop(void)
4698 {
4699         return test_kasumi_decryption_oop(&kasumi_test_case_1);
4700 }
4701
4702 static int
4703 test_kasumi_decryption_test_case_2(void)
4704 {
4705         return test_kasumi_decryption(&kasumi_test_case_2);
4706 }
4707
4708 static int
4709 test_kasumi_decryption_test_case_3(void)
4710 {
4711         return test_kasumi_decryption(&kasumi_test_case_3);
4712 }
4713
4714 static int
4715 test_kasumi_decryption_test_case_4(void)
4716 {
4717         return test_kasumi_decryption(&kasumi_test_case_4);
4718 }
4719
4720 static int
4721 test_kasumi_decryption_test_case_5(void)
4722 {
4723         return test_kasumi_decryption(&kasumi_test_case_5);
4724 }
4725 static int
4726 test_snow3g_encryption_test_case_1(void)
4727 {
4728         return test_snow3g_encryption(&snow3g_test_case_1);
4729 }
4730
4731 static int
4732 test_snow3g_encryption_test_case_1_oop(void)
4733 {
4734         return test_snow3g_encryption_oop(&snow3g_test_case_1);
4735 }
4736
4737 static int
4738 test_snow3g_encryption_test_case_1_oop_sgl(void)
4739 {
4740         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
4741 }
4742
4743
4744 static int
4745 test_snow3g_encryption_test_case_1_offset_oop(void)
4746 {
4747         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
4748 }
4749
4750 static int
4751 test_snow3g_encryption_test_case_2(void)
4752 {
4753         return test_snow3g_encryption(&snow3g_test_case_2);
4754 }
4755
4756 static int
4757 test_snow3g_encryption_test_case_3(void)
4758 {
4759         return test_snow3g_encryption(&snow3g_test_case_3);
4760 }
4761
4762 static int
4763 test_snow3g_encryption_test_case_4(void)
4764 {
4765         return test_snow3g_encryption(&snow3g_test_case_4);
4766 }
4767
4768 static int
4769 test_snow3g_encryption_test_case_5(void)
4770 {
4771         return test_snow3g_encryption(&snow3g_test_case_5);
4772 }
4773
4774 static int
4775 test_snow3g_decryption_test_case_1(void)
4776 {
4777         return test_snow3g_decryption(&snow3g_test_case_1);
4778 }
4779
4780 static int
4781 test_snow3g_decryption_test_case_1_oop(void)
4782 {
4783         return test_snow3g_decryption_oop(&snow3g_test_case_1);
4784 }
4785
4786 static int
4787 test_snow3g_decryption_test_case_2(void)
4788 {
4789         return test_snow3g_decryption(&snow3g_test_case_2);
4790 }
4791
4792 static int
4793 test_snow3g_decryption_test_case_3(void)
4794 {
4795         return test_snow3g_decryption(&snow3g_test_case_3);
4796 }
4797
4798 static int
4799 test_snow3g_decryption_test_case_4(void)
4800 {
4801         return test_snow3g_decryption(&snow3g_test_case_4);
4802 }
4803
4804 static int
4805 test_snow3g_decryption_test_case_5(void)
4806 {
4807         return test_snow3g_decryption(&snow3g_test_case_5);
4808 }
4809 static int
4810 test_snow3g_cipher_auth_test_case_1(void)
4811 {
4812         return test_snow3g_cipher_auth(&snow3g_test_case_3);
4813 }
4814
4815 static int
4816 test_snow3g_auth_cipher_test_case_1(void)
4817 {
4818         return test_snow3g_auth_cipher(&snow3g_test_case_6);
4819 }
4820
4821 static int
4822 test_kasumi_auth_cipher_test_case_1(void)
4823 {
4824         return test_kasumi_auth_cipher(&kasumi_test_case_3);
4825 }
4826
4827 static int
4828 test_kasumi_cipher_auth_test_case_1(void)
4829 {
4830         return test_kasumi_cipher_auth(&kasumi_test_case_6);
4831 }
4832
4833 static int
4834 test_zuc_encryption_test_case_1(void)
4835 {
4836         return test_zuc_encryption(&zuc_test_case_cipher_193b);
4837 }
4838
4839 static int
4840 test_zuc_encryption_test_case_2(void)
4841 {
4842         return test_zuc_encryption(&zuc_test_case_cipher_800b);
4843 }
4844
4845 static int
4846 test_zuc_encryption_test_case_3(void)
4847 {
4848         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
4849 }
4850
4851 static int
4852 test_zuc_encryption_test_case_4(void)
4853 {
4854         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
4855 }
4856
4857 static int
4858 test_zuc_encryption_test_case_5(void)
4859 {
4860         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
4861 }
4862
4863 static int
4864 test_zuc_encryption_test_case_6_sgl(void)
4865 {
4866         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
4867 }
4868
4869 static int
4870 test_zuc_hash_generate_test_case_1(void)
4871 {
4872         return test_zuc_authentication(&zuc_test_case_auth_1b);
4873 }
4874
4875 static int
4876 test_zuc_hash_generate_test_case_2(void)
4877 {
4878         return test_zuc_authentication(&zuc_test_case_auth_90b);
4879 }
4880
4881 static int
4882 test_zuc_hash_generate_test_case_3(void)
4883 {
4884         return test_zuc_authentication(&zuc_test_case_auth_577b);
4885 }
4886
4887 static int
4888 test_zuc_hash_generate_test_case_4(void)
4889 {
4890         return test_zuc_authentication(&zuc_test_case_auth_2079b);
4891 }
4892
4893 static int
4894 test_zuc_hash_generate_test_case_5(void)
4895 {
4896         return test_zuc_authentication(&zuc_test_auth_5670b);
4897 }
4898
4899 static int
4900 test_zuc_hash_generate_test_case_6(void)
4901 {
4902         return test_zuc_authentication(&zuc_test_case_auth_128b);
4903 }
4904
4905 static int
4906 test_zuc_hash_generate_test_case_7(void)
4907 {
4908         return test_zuc_authentication(&zuc_test_case_auth_2080b);
4909 }
4910
4911 static int
4912 test_zuc_hash_generate_test_case_8(void)
4913 {
4914         return test_zuc_authentication(&zuc_test_case_auth_584b);
4915 }
4916
4917 static int
4918 test_zuc_cipher_auth_test_case_1(void)
4919 {
4920         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
4921 }
4922
4923 static int
4924 test_zuc_cipher_auth_test_case_2(void)
4925 {
4926         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
4927 }
4928
4929 static int
4930 test_3DES_chain_qat_all(void)
4931 {
4932         struct crypto_testsuite_params *ts_params = &testsuite_params;
4933         int status;
4934
4935         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4936                 ts_params->op_mpool,
4937                 ts_params->session_mpool,
4938                 ts_params->valid_devs[0],
4939                 rte_cryptodev_driver_id_get(
4940                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
4941                 BLKCIPHER_3DES_CHAIN_TYPE);
4942
4943         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4944
4945         return TEST_SUCCESS;
4946 }
4947
4948 static int
4949 test_DES_cipheronly_qat_all(void)
4950 {
4951         struct crypto_testsuite_params *ts_params = &testsuite_params;
4952         int status;
4953
4954         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4955                 ts_params->op_mpool,
4956                 ts_params->session_mpool,
4957                 ts_params->valid_devs[0],
4958                 rte_cryptodev_driver_id_get(
4959                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
4960                 BLKCIPHER_DES_CIPHERONLY_TYPE);
4961
4962         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4963
4964         return TEST_SUCCESS;
4965 }
4966
4967 static int
4968 test_DES_cipheronly_openssl_all(void)
4969 {
4970         struct crypto_testsuite_params *ts_params = &testsuite_params;
4971         int status;
4972
4973         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4974                 ts_params->op_mpool,
4975                 ts_params->session_mpool,
4976                 ts_params->valid_devs[0],
4977                 rte_cryptodev_driver_id_get(
4978                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
4979                 BLKCIPHER_DES_CIPHERONLY_TYPE);
4980
4981         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4982
4983         return TEST_SUCCESS;
4984 }
4985
4986 static int
4987 test_DES_docsis_openssl_all(void)
4988 {
4989         struct crypto_testsuite_params *ts_params = &testsuite_params;
4990         int status;
4991
4992         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4993                 ts_params->op_mpool,
4994                 ts_params->session_mpool,
4995                 ts_params->valid_devs[0],
4996                 rte_cryptodev_driver_id_get(
4997                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
4998                 BLKCIPHER_DES_DOCSIS_TYPE);
4999
5000         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5001
5002         return TEST_SUCCESS;
5003 }
5004
5005 static int
5006 test_DES_cipheronly_mb_all(void)
5007 {
5008         struct crypto_testsuite_params *ts_params = &testsuite_params;
5009         int status;
5010
5011         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5012                 ts_params->op_mpool,
5013                 ts_params->session_mpool,
5014                 ts_params->valid_devs[0],
5015                 rte_cryptodev_driver_id_get(
5016                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
5017                 BLKCIPHER_DES_CIPHERONLY_TYPE);
5018
5019         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5020
5021         return TEST_SUCCESS;
5022 }
5023
5024 static int
5025 test_DES_docsis_mb_all(void)
5026 {
5027         struct crypto_testsuite_params *ts_params = &testsuite_params;
5028         int status;
5029
5030         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5031                 ts_params->op_mpool,
5032                 ts_params->session_mpool,
5033                 ts_params->valid_devs[0],
5034                 rte_cryptodev_driver_id_get(
5035                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
5036                 BLKCIPHER_DES_DOCSIS_TYPE);
5037
5038         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5039
5040         return TEST_SUCCESS;
5041 }
5042
5043 static int
5044 test_3DES_chain_dpaa_sec_all(void)
5045 {
5046         struct crypto_testsuite_params *ts_params = &testsuite_params;
5047         int status;
5048
5049         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5050                 ts_params->op_mpool,
5051                 ts_params->session_mpool,
5052                 ts_params->valid_devs[0],
5053                 rte_cryptodev_driver_id_get(
5054                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
5055                 BLKCIPHER_3DES_CHAIN_TYPE);
5056
5057         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5058
5059         return TEST_SUCCESS;
5060 }
5061
5062 static int
5063 test_3DES_cipheronly_dpaa_sec_all(void)
5064 {
5065         struct crypto_testsuite_params *ts_params = &testsuite_params;
5066         int status;
5067
5068         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5069                 ts_params->op_mpool,
5070                 ts_params->session_mpool,
5071                 ts_params->valid_devs[0],
5072                 rte_cryptodev_driver_id_get(
5073                 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)),
5074                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5075
5076         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5077
5078         return TEST_SUCCESS;
5079 }
5080
5081 static int
5082 test_3DES_chain_dpaa2_sec_all(void)
5083 {
5084         struct crypto_testsuite_params *ts_params = &testsuite_params;
5085         int status;
5086
5087         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5088                 ts_params->op_mpool,
5089                 ts_params->session_mpool,
5090                 ts_params->valid_devs[0],
5091                 rte_cryptodev_driver_id_get(
5092                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
5093                 BLKCIPHER_3DES_CHAIN_TYPE);
5094
5095         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5096
5097         return TEST_SUCCESS;
5098 }
5099
5100 static int
5101 test_3DES_cipheronly_dpaa2_sec_all(void)
5102 {
5103         struct crypto_testsuite_params *ts_params = &testsuite_params;
5104         int status;
5105
5106         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5107                 ts_params->op_mpool,
5108                 ts_params->session_mpool,
5109                 ts_params->valid_devs[0],
5110                 rte_cryptodev_driver_id_get(
5111                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
5112                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5113
5114         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5115
5116         return TEST_SUCCESS;
5117 }
5118
5119 static int
5120 test_3DES_chain_ccp_all(void)
5121 {
5122         struct crypto_testsuite_params *ts_params = &testsuite_params;
5123         int status;
5124
5125         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5126                 ts_params->op_mpool,
5127                 ts_params->session_mpool,
5128                 ts_params->valid_devs[0],
5129                 rte_cryptodev_driver_id_get(
5130                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
5131                 BLKCIPHER_3DES_CHAIN_TYPE);
5132
5133         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5134
5135         return TEST_SUCCESS;
5136 }
5137
5138 static int
5139 test_3DES_cipheronly_ccp_all(void)
5140 {
5141         struct crypto_testsuite_params *ts_params = &testsuite_params;
5142         int status;
5143
5144         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5145                 ts_params->op_mpool,
5146                 ts_params->session_mpool,
5147                 ts_params->valid_devs[0],
5148                 rte_cryptodev_driver_id_get(
5149                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)),
5150                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5151
5152         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5153
5154         return TEST_SUCCESS;
5155 }
5156
5157 static int
5158 test_3DES_cipheronly_qat_all(void)
5159 {
5160         struct crypto_testsuite_params *ts_params = &testsuite_params;
5161         int status;
5162
5163         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5164                 ts_params->op_mpool,
5165                 ts_params->session_mpool,
5166                 ts_params->valid_devs[0],
5167                 rte_cryptodev_driver_id_get(
5168                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
5169                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5170
5171         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5172
5173         return TEST_SUCCESS;
5174 }
5175
5176 static int
5177 test_3DES_chain_openssl_all(void)
5178 {
5179         struct crypto_testsuite_params *ts_params = &testsuite_params;
5180         int status;
5181
5182         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5183                 ts_params->op_mpool,
5184                 ts_params->session_mpool,
5185                 ts_params->valid_devs[0],
5186                 rte_cryptodev_driver_id_get(
5187                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
5188                 BLKCIPHER_3DES_CHAIN_TYPE);
5189
5190         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5191
5192         return TEST_SUCCESS;
5193 }
5194
5195 static int
5196 test_3DES_cipheronly_openssl_all(void)
5197 {
5198         struct crypto_testsuite_params *ts_params = &testsuite_params;
5199         int status;
5200
5201         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5202                 ts_params->op_mpool,
5203                 ts_params->session_mpool,
5204                 ts_params->valid_devs[0],
5205                 rte_cryptodev_driver_id_get(
5206                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
5207                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5208
5209         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5210
5211         return TEST_SUCCESS;
5212 }
5213
5214 /* ***** AEAD algorithm Tests ***** */
5215
5216 static int
5217 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
5218                 enum rte_crypto_aead_operation op,
5219                 const uint8_t *key, const uint8_t key_len,
5220                 const uint16_t aad_len, const uint8_t auth_len,
5221                 uint8_t iv_len)
5222 {
5223         uint8_t aead_key[key_len];
5224
5225         struct crypto_testsuite_params *ts_params = &testsuite_params;
5226         struct crypto_unittest_params *ut_params = &unittest_params;
5227
5228         memcpy(aead_key, key, key_len);
5229
5230         /* Setup AEAD Parameters */
5231         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
5232         ut_params->aead_xform.next = NULL;
5233         ut_params->aead_xform.aead.algo = algo;
5234         ut_params->aead_xform.aead.op = op;
5235         ut_params->aead_xform.aead.key.data = aead_key;
5236         ut_params->aead_xform.aead.key.length = key_len;
5237         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
5238         ut_params->aead_xform.aead.iv.length = iv_len;
5239         ut_params->aead_xform.aead.digest_length = auth_len;
5240         ut_params->aead_xform.aead.aad_length = aad_len;
5241
5242         debug_hexdump(stdout, "key:", key, key_len);
5243
5244         /* Create Crypto session*/
5245         ut_params->sess = rte_cryptodev_sym_session_create(
5246                         ts_params->session_mpool);
5247
5248         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
5249                         &ut_params->aead_xform, ts_params->session_mpool);
5250
5251         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5252
5253         return 0;
5254 }
5255
5256 static int
5257 create_aead_xform(struct rte_crypto_op *op,
5258                 enum rte_crypto_aead_algorithm algo,
5259                 enum rte_crypto_aead_operation aead_op,
5260                 uint8_t *key, const uint8_t key_len,
5261                 const uint8_t aad_len, const uint8_t auth_len,
5262                 uint8_t iv_len)
5263 {
5264         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
5265                         "failed to allocate space for crypto transform");
5266
5267         struct rte_crypto_sym_op *sym_op = op->sym;
5268
5269         /* Setup AEAD Parameters */
5270         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
5271         sym_op->xform->next = NULL;
5272         sym_op->xform->aead.algo = algo;
5273         sym_op->xform->aead.op = aead_op;
5274         sym_op->xform->aead.key.data = key;
5275         sym_op->xform->aead.key.length = key_len;
5276         sym_op->xform->aead.iv.offset = IV_OFFSET;
5277         sym_op->xform->aead.iv.length = iv_len;
5278         sym_op->xform->aead.digest_length = auth_len;
5279         sym_op->xform->aead.aad_length = aad_len;
5280
5281         debug_hexdump(stdout, "key:", key, key_len);
5282
5283         return 0;
5284 }
5285
5286 static int
5287 create_aead_operation(enum rte_crypto_aead_operation op,
5288                 const struct aead_test_data *tdata)
5289 {
5290         struct crypto_testsuite_params *ts_params = &testsuite_params;
5291         struct crypto_unittest_params *ut_params = &unittest_params;
5292
5293         uint8_t *plaintext, *ciphertext;
5294         unsigned int aad_pad_len, plaintext_pad_len;
5295
5296         /* Generate Crypto op data structure */
5297         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5298                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5299         TEST_ASSERT_NOT_NULL(ut_params->op,
5300                         "Failed to allocate symmetric crypto operation struct");
5301
5302         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5303
5304         /* Append aad data */
5305         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
5306                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
5307                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5308                                 aad_pad_len);
5309                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
5310                                 "no room to append aad");
5311
5312                 sym_op->aead.aad.phys_addr =
5313                                 rte_pktmbuf_iova(ut_params->ibuf);
5314                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
5315                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
5316                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
5317                         tdata->aad.len);
5318
5319                 /* Append IV at the end of the crypto operation*/
5320                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
5321                                 uint8_t *, IV_OFFSET);
5322
5323                 /* Copy IV 1 byte after the IV pointer, according to the API */
5324                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
5325                 debug_hexdump(stdout, "iv:", iv_ptr,
5326                         tdata->iv.len);
5327         } else {
5328                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5329                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5330                                 aad_pad_len);
5331                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
5332                                 "no room to append aad");
5333
5334                 sym_op->aead.aad.phys_addr =
5335                                 rte_pktmbuf_iova(ut_params->ibuf);
5336                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
5337                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
5338                         tdata->aad.len);
5339
5340                 /* Append IV at the end of the crypto operation*/
5341                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
5342                                 uint8_t *, IV_OFFSET);
5343
5344                 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
5345                 debug_hexdump(stdout, "iv:", iv_ptr,
5346                         tdata->iv.len);
5347         }
5348
5349         /* Append plaintext/ciphertext */
5350         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
5351                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5352                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5353                                 plaintext_pad_len);
5354                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
5355
5356                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
5357                 debug_hexdump(stdout, "plaintext:", plaintext,
5358                                 tdata->plaintext.len);
5359
5360                 if (ut_params->obuf) {
5361                         ciphertext = (uint8_t *)rte_pktmbuf_append(
5362                                         ut_params->obuf,
5363                                         plaintext_pad_len + aad_pad_len);
5364                         TEST_ASSERT_NOT_NULL(ciphertext,
5365                                         "no room to append ciphertext");
5366
5367                         memset(ciphertext + aad_pad_len, 0,
5368                                         tdata->ciphertext.len);
5369                 }
5370         } else {
5371                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
5372                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5373                                 plaintext_pad_len);
5374                 TEST_ASSERT_NOT_NULL(ciphertext,
5375                                 "no room to append ciphertext");
5376
5377                 memcpy(ciphertext, tdata->ciphertext.data,
5378                                 tdata->ciphertext.len);
5379                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5380                                 tdata->ciphertext.len);
5381
5382                 if (ut_params->obuf) {
5383                         plaintext = (uint8_t *)rte_pktmbuf_append(
5384                                         ut_params->obuf,
5385                                         plaintext_pad_len + aad_pad_len);
5386                         TEST_ASSERT_NOT_NULL(plaintext,
5387                                         "no room to append plaintext");
5388
5389                         memset(plaintext + aad_pad_len, 0,
5390                                         tdata->plaintext.len);
5391                 }
5392         }
5393
5394         /* Append digest data */
5395         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
5396                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
5397                                 ut_params->obuf ? ut_params->obuf :
5398                                                 ut_params->ibuf,
5399                                                 tdata->auth_tag.len);
5400                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
5401                                 "no room to append digest");
5402                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
5403                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
5404                                 ut_params->obuf ? ut_params->obuf :
5405                                                 ut_params->ibuf,
5406                                                 plaintext_pad_len +
5407                                                 aad_pad_len);
5408         } else {
5409                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
5410                                 ut_params->ibuf, tdata->auth_tag.len);
5411                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
5412                                 "no room to append digest");
5413                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
5414                                 ut_params->ibuf,
5415                                 plaintext_pad_len + aad_pad_len);
5416
5417                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
5418                         tdata->auth_tag.len);
5419                 debug_hexdump(stdout, "digest:",
5420                         sym_op->aead.digest.data,
5421                         tdata->auth_tag.len);
5422         }
5423
5424         sym_op->aead.data.length = tdata->plaintext.len;
5425         sym_op->aead.data.offset = aad_pad_len;
5426
5427         return 0;
5428 }
5429
5430 static int
5431 test_authenticated_encryption(const struct aead_test_data *tdata)
5432 {
5433         struct crypto_testsuite_params *ts_params = &testsuite_params;
5434         struct crypto_unittest_params *ut_params = &unittest_params;
5435
5436         int retval;
5437         uint8_t *ciphertext, *auth_tag;
5438         uint16_t plaintext_pad_len;
5439         uint32_t i;
5440
5441         /* Create AEAD session */
5442         retval = create_aead_session(ts_params->valid_devs[0],
5443                         tdata->algo,
5444                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5445                         tdata->key.data, tdata->key.len,
5446                         tdata->aad.len, tdata->auth_tag.len,
5447                         tdata->iv.len);
5448         if (retval < 0)
5449                 return retval;
5450
5451         if (tdata->aad.len > MBUF_SIZE) {
5452                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5453                 /* Populate full size of add data */
5454                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
5455                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5456         } else
5457                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5458
5459         /* clear mbuf payload */
5460         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5461                         rte_pktmbuf_tailroom(ut_params->ibuf));
5462
5463         /* Create AEAD operation */
5464         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5465         if (retval < 0)
5466                 return retval;
5467
5468         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5469
5470         ut_params->op->sym->m_src = ut_params->ibuf;
5471
5472         /* Process crypto operation */
5473         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5474                         ut_params->op), "failed to process sym crypto op");
5475
5476         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5477                         "crypto op processing failed");
5478
5479         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5480
5481         if (ut_params->op->sym->m_dst) {
5482                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5483                                 uint8_t *);
5484                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5485                                 uint8_t *, plaintext_pad_len);
5486         } else {
5487                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5488                                 uint8_t *,
5489                                 ut_params->op->sym->cipher.data.offset);
5490                 auth_tag = ciphertext + plaintext_pad_len;
5491         }
5492
5493         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5494         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5495
5496         /* Validate obuf */
5497         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5498                         ciphertext,
5499                         tdata->ciphertext.data,
5500                         tdata->ciphertext.len,
5501                         "Ciphertext data not as expected");
5502
5503         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5504                         auth_tag,
5505                         tdata->auth_tag.data,
5506                         tdata->auth_tag.len,
5507                         "Generated auth tag not as expected");
5508
5509         return 0;
5510
5511 }
5512
5513 static int
5514 test_AES_GCM_authenticated_encryption_test_case_1(void)
5515 {
5516         return test_authenticated_encryption(&gcm_test_case_1);
5517 }
5518
5519 static int
5520 test_AES_GCM_authenticated_encryption_test_case_2(void)
5521 {
5522         return test_authenticated_encryption(&gcm_test_case_2);
5523 }
5524
5525 static int
5526 test_AES_GCM_authenticated_encryption_test_case_3(void)
5527 {
5528         return test_authenticated_encryption(&gcm_test_case_3);
5529 }
5530
5531 static int
5532 test_AES_GCM_authenticated_encryption_test_case_4(void)
5533 {
5534         return test_authenticated_encryption(&gcm_test_case_4);
5535 }
5536
5537 static int
5538 test_AES_GCM_authenticated_encryption_test_case_5(void)
5539 {
5540         return test_authenticated_encryption(&gcm_test_case_5);
5541 }
5542
5543 static int
5544 test_AES_GCM_authenticated_encryption_test_case_6(void)
5545 {
5546         return test_authenticated_encryption(&gcm_test_case_6);
5547 }
5548
5549 static int
5550 test_AES_GCM_authenticated_encryption_test_case_7(void)
5551 {
5552         return test_authenticated_encryption(&gcm_test_case_7);
5553 }
5554
5555 static int
5556 test_AES_GCM_auth_encryption_test_case_192_1(void)
5557 {
5558         return test_authenticated_encryption(&gcm_test_case_192_1);
5559 }
5560
5561 static int
5562 test_AES_GCM_auth_encryption_test_case_192_2(void)
5563 {
5564         return test_authenticated_encryption(&gcm_test_case_192_2);
5565 }
5566
5567 static int
5568 test_AES_GCM_auth_encryption_test_case_192_3(void)
5569 {
5570         return test_authenticated_encryption(&gcm_test_case_192_3);
5571 }
5572
5573 static int
5574 test_AES_GCM_auth_encryption_test_case_192_4(void)
5575 {
5576         return test_authenticated_encryption(&gcm_test_case_192_4);
5577 }
5578
5579 static int
5580 test_AES_GCM_auth_encryption_test_case_192_5(void)
5581 {
5582         return test_authenticated_encryption(&gcm_test_case_192_5);
5583 }
5584
5585 static int
5586 test_AES_GCM_auth_encryption_test_case_192_6(void)
5587 {
5588         return test_authenticated_encryption(&gcm_test_case_192_6);
5589 }
5590
5591 static int
5592 test_AES_GCM_auth_encryption_test_case_192_7(void)
5593 {
5594         return test_authenticated_encryption(&gcm_test_case_192_7);
5595 }
5596
5597 static int
5598 test_AES_GCM_auth_encryption_test_case_256_1(void)
5599 {
5600         return test_authenticated_encryption(&gcm_test_case_256_1);
5601 }
5602
5603 static int
5604 test_AES_GCM_auth_encryption_test_case_256_2(void)
5605 {
5606         return test_authenticated_encryption(&gcm_test_case_256_2);
5607 }
5608
5609 static int
5610 test_AES_GCM_auth_encryption_test_case_256_3(void)
5611 {
5612         return test_authenticated_encryption(&gcm_test_case_256_3);
5613 }
5614
5615 static int
5616 test_AES_GCM_auth_encryption_test_case_256_4(void)
5617 {
5618         return test_authenticated_encryption(&gcm_test_case_256_4);
5619 }
5620
5621 static int
5622 test_AES_GCM_auth_encryption_test_case_256_5(void)
5623 {
5624         return test_authenticated_encryption(&gcm_test_case_256_5);
5625 }
5626
5627 static int
5628 test_AES_GCM_auth_encryption_test_case_256_6(void)
5629 {
5630         return test_authenticated_encryption(&gcm_test_case_256_6);
5631 }
5632
5633 static int
5634 test_AES_GCM_auth_encryption_test_case_256_7(void)
5635 {
5636         return test_authenticated_encryption(&gcm_test_case_256_7);
5637 }
5638
5639 static int
5640 test_AES_GCM_auth_encryption_test_case_aad_1(void)
5641 {
5642         return test_authenticated_encryption(&gcm_test_case_aad_1);
5643 }
5644
5645 static int
5646 test_AES_GCM_auth_encryption_test_case_aad_2(void)
5647 {
5648         return test_authenticated_encryption(&gcm_test_case_aad_2);
5649 }
5650
5651 static int
5652 test_authenticated_decryption(const struct aead_test_data *tdata)
5653 {
5654         struct crypto_testsuite_params *ts_params = &testsuite_params;
5655         struct crypto_unittest_params *ut_params = &unittest_params;
5656
5657         int retval;
5658         uint8_t *plaintext;
5659         uint32_t i;
5660
5661         /* Create AEAD session */
5662         retval = create_aead_session(ts_params->valid_devs[0],
5663                         tdata->algo,
5664                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5665                         tdata->key.data, tdata->key.len,
5666                         tdata->aad.len, tdata->auth_tag.len,
5667                         tdata->iv.len);
5668         if (retval < 0)
5669                 return retval;
5670
5671         /* alloc mbuf and set payload */
5672         if (tdata->aad.len > MBUF_SIZE) {
5673                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5674                 /* Populate full size of add data */
5675                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
5676                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5677         } else
5678                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5679
5680         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5681                         rte_pktmbuf_tailroom(ut_params->ibuf));
5682
5683         /* Create AEAD operation */
5684         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5685         if (retval < 0)
5686                 return retval;
5687
5688         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5689
5690         ut_params->op->sym->m_src = ut_params->ibuf;
5691
5692         /* Process crypto operation */
5693         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5694                         ut_params->op), "failed to process sym crypto op");
5695
5696         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5697                         "crypto op processing failed");
5698
5699         if (ut_params->op->sym->m_dst)
5700                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5701                                 uint8_t *);
5702         else
5703                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5704                                 uint8_t *,
5705                                 ut_params->op->sym->cipher.data.offset);
5706
5707         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5708
5709         /* Validate obuf */
5710         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5711                         plaintext,
5712                         tdata->plaintext.data,
5713                         tdata->plaintext.len,
5714                         "Plaintext data not as expected");
5715
5716         TEST_ASSERT_EQUAL(ut_params->op->status,
5717                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5718                         "Authentication failed");
5719         return 0;
5720 }
5721
5722 static int
5723 test_AES_GCM_authenticated_decryption_test_case_1(void)
5724 {
5725         return test_authenticated_decryption(&gcm_test_case_1);
5726 }
5727
5728 static int
5729 test_AES_GCM_authenticated_decryption_test_case_2(void)
5730 {
5731         return test_authenticated_decryption(&gcm_test_case_2);
5732 }
5733
5734 static int
5735 test_AES_GCM_authenticated_decryption_test_case_3(void)
5736 {
5737         return test_authenticated_decryption(&gcm_test_case_3);
5738 }
5739
5740 static int
5741 test_AES_GCM_authenticated_decryption_test_case_4(void)
5742 {
5743         return test_authenticated_decryption(&gcm_test_case_4);
5744 }
5745
5746 static int
5747 test_AES_GCM_authenticated_decryption_test_case_5(void)
5748 {
5749         return test_authenticated_decryption(&gcm_test_case_5);
5750 }
5751
5752 static int
5753 test_AES_GCM_authenticated_decryption_test_case_6(void)
5754 {
5755         return test_authenticated_decryption(&gcm_test_case_6);
5756 }
5757
5758 static int
5759 test_AES_GCM_authenticated_decryption_test_case_7(void)
5760 {
5761         return test_authenticated_decryption(&gcm_test_case_7);
5762 }
5763
5764 static int
5765 test_AES_GCM_auth_decryption_test_case_192_1(void)
5766 {
5767         return test_authenticated_decryption(&gcm_test_case_192_1);
5768 }
5769
5770 static int
5771 test_AES_GCM_auth_decryption_test_case_192_2(void)
5772 {
5773         return test_authenticated_decryption(&gcm_test_case_192_2);
5774 }
5775
5776 static int
5777 test_AES_GCM_auth_decryption_test_case_192_3(void)
5778 {
5779         return test_authenticated_decryption(&gcm_test_case_192_3);
5780 }
5781
5782 static int
5783 test_AES_GCM_auth_decryption_test_case_192_4(void)
5784 {
5785         return test_authenticated_decryption(&gcm_test_case_192_4);
5786 }
5787
5788 static int
5789 test_AES_GCM_auth_decryption_test_case_192_5(void)
5790 {
5791         return test_authenticated_decryption(&gcm_test_case_192_5);
5792 }
5793
5794 static int
5795 test_AES_GCM_auth_decryption_test_case_192_6(void)
5796 {
5797         return test_authenticated_decryption(&gcm_test_case_192_6);
5798 }
5799
5800 static int
5801 test_AES_GCM_auth_decryption_test_case_192_7(void)
5802 {
5803         return test_authenticated_decryption(&gcm_test_case_192_7);
5804 }
5805
5806 static int
5807 test_AES_GCM_auth_decryption_test_case_256_1(void)
5808 {
5809         return test_authenticated_decryption(&gcm_test_case_256_1);
5810 }
5811
5812 static int
5813 test_AES_GCM_auth_decryption_test_case_256_2(void)
5814 {
5815         return test_authenticated_decryption(&gcm_test_case_256_2);
5816 }
5817
5818 static int
5819 test_AES_GCM_auth_decryption_test_case_256_3(void)
5820 {
5821         return test_authenticated_decryption(&gcm_test_case_256_3);
5822 }
5823
5824 static int
5825 test_AES_GCM_auth_decryption_test_case_256_4(void)
5826 {
5827         return test_authenticated_decryption(&gcm_test_case_256_4);
5828 }
5829
5830 static int
5831 test_AES_GCM_auth_decryption_test_case_256_5(void)
5832 {
5833         return test_authenticated_decryption(&gcm_test_case_256_5);
5834 }
5835
5836 static int
5837 test_AES_GCM_auth_decryption_test_case_256_6(void)
5838 {
5839         return test_authenticated_decryption(&gcm_test_case_256_6);
5840 }
5841
5842 static int
5843 test_AES_GCM_auth_decryption_test_case_256_7(void)
5844 {
5845         return test_authenticated_decryption(&gcm_test_case_256_7);
5846 }
5847
5848 static int
5849 test_AES_GCM_auth_decryption_test_case_aad_1(void)
5850 {
5851         return test_authenticated_decryption(&gcm_test_case_aad_1);
5852 }
5853
5854 static int
5855 test_AES_GCM_auth_decryption_test_case_aad_2(void)
5856 {
5857         return test_authenticated_decryption(&gcm_test_case_aad_2);
5858 }
5859
5860 static int
5861 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
5862 {
5863         struct crypto_testsuite_params *ts_params = &testsuite_params;
5864         struct crypto_unittest_params *ut_params = &unittest_params;
5865
5866         int retval;
5867         uint8_t *ciphertext, *auth_tag;
5868         uint16_t plaintext_pad_len;
5869
5870         /* Create AEAD session */
5871         retval = create_aead_session(ts_params->valid_devs[0],
5872                         tdata->algo,
5873                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5874                         tdata->key.data, tdata->key.len,
5875                         tdata->aad.len, tdata->auth_tag.len,
5876                         tdata->iv.len);
5877         if (retval < 0)
5878                 return retval;
5879
5880         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5881         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5882
5883         /* clear mbuf payload */
5884         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5885                         rte_pktmbuf_tailroom(ut_params->ibuf));
5886         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5887                         rte_pktmbuf_tailroom(ut_params->obuf));
5888
5889         /* Create AEAD operation */
5890         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5891         if (retval < 0)
5892                 return retval;
5893
5894         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5895
5896         ut_params->op->sym->m_src = ut_params->ibuf;
5897         ut_params->op->sym->m_dst = ut_params->obuf;
5898
5899         /* Process crypto operation */
5900         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5901                         ut_params->op), "failed to process sym crypto op");
5902
5903         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5904                         "crypto op processing failed");
5905
5906         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5907
5908         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5909                         ut_params->op->sym->cipher.data.offset);
5910         auth_tag = ciphertext + plaintext_pad_len;
5911
5912         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5913         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5914
5915         /* Validate obuf */
5916         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5917                         ciphertext,
5918                         tdata->ciphertext.data,
5919                         tdata->ciphertext.len,
5920                         "Ciphertext data not as expected");
5921
5922         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5923                         auth_tag,
5924                         tdata->auth_tag.data,
5925                         tdata->auth_tag.len,
5926                         "Generated auth tag not as expected");
5927
5928         return 0;
5929
5930 }
5931
5932 static int
5933 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
5934 {
5935         return test_authenticated_encryption_oop(&gcm_test_case_5);
5936 }
5937
5938 static int
5939 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
5940 {
5941         struct crypto_testsuite_params *ts_params = &testsuite_params;
5942         struct crypto_unittest_params *ut_params = &unittest_params;
5943
5944         int retval;
5945         uint8_t *plaintext;
5946
5947         /* Create AEAD session */
5948         retval = create_aead_session(ts_params->valid_devs[0],
5949                         tdata->algo,
5950                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5951                         tdata->key.data, tdata->key.len,
5952                         tdata->aad.len, tdata->auth_tag.len,
5953                         tdata->iv.len);
5954         if (retval < 0)
5955                 return retval;
5956
5957         /* alloc mbuf and set payload */
5958         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5959         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5960
5961         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5962                         rte_pktmbuf_tailroom(ut_params->ibuf));
5963         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5964                         rte_pktmbuf_tailroom(ut_params->obuf));
5965
5966         /* Create AEAD operation */
5967         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5968         if (retval < 0)
5969                 return retval;
5970
5971         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5972
5973         ut_params->op->sym->m_src = ut_params->ibuf;
5974         ut_params->op->sym->m_dst = ut_params->obuf;
5975
5976         /* Process crypto operation */
5977         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5978                         ut_params->op), "failed to process sym crypto op");
5979
5980         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5981                         "crypto op processing failed");
5982
5983         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5984                         ut_params->op->sym->cipher.data.offset);
5985
5986         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5987
5988         /* Validate obuf */
5989         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5990                         plaintext,
5991                         tdata->plaintext.data,
5992                         tdata->plaintext.len,
5993                         "Plaintext data not as expected");
5994
5995         TEST_ASSERT_EQUAL(ut_params->op->status,
5996                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5997                         "Authentication failed");
5998         return 0;
5999 }
6000
6001 static int
6002 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
6003 {
6004         return test_authenticated_decryption_oop(&gcm_test_case_5);
6005 }
6006
6007 static int
6008 test_authenticated_encryption_sessionless(
6009                 const struct aead_test_data *tdata)
6010 {
6011         struct crypto_testsuite_params *ts_params = &testsuite_params;
6012         struct crypto_unittest_params *ut_params = &unittest_params;
6013
6014         int retval;
6015         uint8_t *ciphertext, *auth_tag;
6016         uint16_t plaintext_pad_len;
6017         uint8_t key[tdata->key.len + 1];
6018
6019         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6020
6021         /* clear mbuf payload */
6022         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6023                         rte_pktmbuf_tailroom(ut_params->ibuf));
6024
6025         /* Create AEAD operation */
6026         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
6027         if (retval < 0)
6028                 return retval;
6029
6030         /* Create GCM xform */
6031         memcpy(key, tdata->key.data, tdata->key.len);
6032         retval = create_aead_xform(ut_params->op,
6033                         tdata->algo,
6034                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
6035                         key, tdata->key.len,
6036                         tdata->aad.len, tdata->auth_tag.len,
6037                         tdata->iv.len);
6038         if (retval < 0)
6039                 return retval;
6040
6041         ut_params->op->sym->m_src = ut_params->ibuf;
6042
6043         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
6044                         RTE_CRYPTO_OP_SESSIONLESS,
6045                         "crypto op session type not sessionless");
6046
6047         /* Process crypto operation */
6048         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6049                         ut_params->op), "failed to process sym crypto op");
6050
6051         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6052
6053         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6054                         "crypto op status not success");
6055
6056         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6057
6058         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6059                         ut_params->op->sym->cipher.data.offset);
6060         auth_tag = ciphertext + plaintext_pad_len;
6061
6062         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
6063         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
6064
6065         /* Validate obuf */
6066         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6067                         ciphertext,
6068                         tdata->ciphertext.data,
6069                         tdata->ciphertext.len,
6070                         "Ciphertext data not as expected");
6071
6072         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6073                         auth_tag,
6074                         tdata->auth_tag.data,
6075                         tdata->auth_tag.len,
6076                         "Generated auth tag not as expected");
6077
6078         return 0;
6079
6080 }
6081
6082 static int
6083 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
6084 {
6085         return test_authenticated_encryption_sessionless(
6086                         &gcm_test_case_5);
6087 }
6088
6089 static int
6090 test_authenticated_decryption_sessionless(
6091                 const struct aead_test_data *tdata)
6092 {
6093         struct crypto_testsuite_params *ts_params = &testsuite_params;
6094         struct crypto_unittest_params *ut_params = &unittest_params;
6095
6096         int retval;
6097         uint8_t *plaintext;
6098         uint8_t key[tdata->key.len + 1];
6099
6100         /* alloc mbuf and set payload */
6101         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6102
6103         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6104                         rte_pktmbuf_tailroom(ut_params->ibuf));
6105
6106         /* Create AEAD operation */
6107         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
6108         if (retval < 0)
6109                 return retval;
6110
6111         /* Create AEAD xform */
6112         memcpy(key, tdata->key.data, tdata->key.len);
6113         retval = create_aead_xform(ut_params->op,
6114                         tdata->algo,
6115                         RTE_CRYPTO_AEAD_OP_DECRYPT,
6116                         key, tdata->key.len,
6117                         tdata->aad.len, tdata->auth_tag.len,
6118                         tdata->iv.len);
6119         if (retval < 0)
6120                 return retval;
6121
6122         ut_params->op->sym->m_src = ut_params->ibuf;
6123
6124         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
6125                         RTE_CRYPTO_OP_SESSIONLESS,
6126                         "crypto op session type not sessionless");
6127
6128         /* Process crypto operation */
6129         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6130                         ut_params->op), "failed to process sym crypto op");
6131
6132         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6133
6134         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6135                         "crypto op status not success");
6136
6137         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6138                         ut_params->op->sym->cipher.data.offset);
6139
6140         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
6141
6142         /* Validate obuf */
6143         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6144                         plaintext,
6145                         tdata->plaintext.data,
6146                         tdata->plaintext.len,
6147                         "Plaintext data not as expected");
6148
6149         TEST_ASSERT_EQUAL(ut_params->op->status,
6150                         RTE_CRYPTO_OP_STATUS_SUCCESS,
6151                         "Authentication failed");
6152         return 0;
6153 }
6154
6155 static int
6156 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
6157 {
6158         return test_authenticated_decryption_sessionless(
6159                         &gcm_test_case_5);
6160 }
6161
6162 static int
6163 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
6164 {
6165         return test_authenticated_encryption(&ccm_test_case_128_1);
6166 }
6167
6168 static int
6169 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
6170 {
6171         return test_authenticated_encryption(&ccm_test_case_128_2);
6172 }
6173
6174 static int
6175 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
6176 {
6177         return test_authenticated_encryption(&ccm_test_case_128_3);
6178 }
6179
6180 static int
6181 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
6182 {
6183         return test_authenticated_decryption(&ccm_test_case_128_1);
6184 }
6185
6186 static int
6187 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
6188 {
6189         return test_authenticated_decryption(&ccm_test_case_128_2);
6190 }
6191
6192 static int
6193 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
6194 {
6195         return test_authenticated_decryption(&ccm_test_case_128_3);
6196 }
6197
6198 static int
6199 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
6200 {
6201         return test_authenticated_encryption(&ccm_test_case_192_1);
6202 }
6203
6204 static int
6205 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
6206 {
6207         return test_authenticated_encryption(&ccm_test_case_192_2);
6208 }
6209
6210 static int
6211 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
6212 {
6213         return test_authenticated_encryption(&ccm_test_case_192_3);
6214 }
6215
6216 static int
6217 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
6218 {
6219         return test_authenticated_decryption(&ccm_test_case_192_1);
6220 }
6221
6222 static int
6223 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
6224 {
6225         return test_authenticated_decryption(&ccm_test_case_192_2);
6226 }
6227
6228 static int
6229 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
6230 {
6231         return test_authenticated_decryption(&ccm_test_case_192_3);
6232 }
6233
6234 static int
6235 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
6236 {
6237         return test_authenticated_encryption(&ccm_test_case_256_1);
6238 }
6239
6240 static int
6241 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
6242 {
6243         return test_authenticated_encryption(&ccm_test_case_256_2);
6244 }
6245
6246 static int
6247 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
6248 {
6249         return test_authenticated_encryption(&ccm_test_case_256_3);
6250 }
6251
6252 static int
6253 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
6254 {
6255         return test_authenticated_decryption(&ccm_test_case_256_1);
6256 }
6257
6258 static int
6259 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
6260 {
6261         return test_authenticated_decryption(&ccm_test_case_256_2);
6262 }
6263
6264 static int
6265 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
6266 {
6267         return test_authenticated_decryption(&ccm_test_case_256_3);
6268 }
6269
6270 static int
6271 test_stats(void)
6272 {
6273         struct crypto_testsuite_params *ts_params = &testsuite_params;
6274         struct rte_cryptodev_stats stats;
6275         struct rte_cryptodev *dev;
6276         cryptodev_stats_get_t temp_pfn;
6277
6278         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
6279         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
6280                         &stats) == -ENODEV),
6281                 "rte_cryptodev_stats_get invalid dev failed");
6282         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
6283                 "rte_cryptodev_stats_get invalid Param failed");
6284         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
6285         temp_pfn = dev->dev_ops->stats_get;
6286         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
6287         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
6288                         == -ENOTSUP),
6289                 "rte_cryptodev_stats_get invalid Param failed");
6290         dev->dev_ops->stats_get = temp_pfn;
6291
6292         /* Test expected values */
6293         ut_setup();
6294         test_AES_CBC_HMAC_SHA1_encrypt_digest();
6295         ut_teardown();
6296         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6297                         &stats),
6298                 "rte_cryptodev_stats_get failed");
6299         TEST_ASSERT((stats.enqueued_count == 1),
6300                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6301         TEST_ASSERT((stats.dequeued_count == 1),
6302                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6303         TEST_ASSERT((stats.enqueue_err_count == 0),
6304                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6305         TEST_ASSERT((stats.dequeue_err_count == 0),
6306                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6307
6308         /* invalid device but should ignore and not reset device stats*/
6309         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
6310         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6311                         &stats),
6312                 "rte_cryptodev_stats_get failed");
6313         TEST_ASSERT((stats.enqueued_count == 1),
6314                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6315
6316         /* check that a valid reset clears stats */
6317         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
6318         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6319                         &stats),
6320                                           "rte_cryptodev_stats_get failed");
6321         TEST_ASSERT((stats.enqueued_count == 0),
6322                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6323         TEST_ASSERT((stats.dequeued_count == 0),
6324                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6325
6326         return TEST_SUCCESS;
6327 }
6328
6329 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
6330                                    struct crypto_unittest_params *ut_params,
6331                                    enum rte_crypto_auth_operation op,
6332                                    const struct HMAC_MD5_vector *test_case)
6333 {
6334         uint8_t key[64];
6335
6336         memcpy(key, test_case->key.data, test_case->key.len);
6337
6338         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6339         ut_params->auth_xform.next = NULL;
6340         ut_params->auth_xform.auth.op = op;
6341
6342         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
6343
6344         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
6345         ut_params->auth_xform.auth.key.length = test_case->key.len;
6346         ut_params->auth_xform.auth.key.data = key;
6347
6348         ut_params->sess = rte_cryptodev_sym_session_create(
6349                         ts_params->session_mpool);
6350
6351         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6352                         ut_params->sess, &ut_params->auth_xform,
6353                         ts_params->session_mpool);
6354
6355         if (ut_params->sess == NULL)
6356                 return TEST_FAILED;
6357
6358         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6359
6360         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6361                         rte_pktmbuf_tailroom(ut_params->ibuf));
6362
6363         return 0;
6364 }
6365
6366 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
6367                               const struct HMAC_MD5_vector *test_case,
6368                               uint8_t **plaintext)
6369 {
6370         uint16_t plaintext_pad_len;
6371
6372         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6373
6374         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
6375                                 16);
6376
6377         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6378                         plaintext_pad_len);
6379         memcpy(*plaintext, test_case->plaintext.data,
6380                         test_case->plaintext.len);
6381
6382         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6383                         ut_params->ibuf, MD5_DIGEST_LEN);
6384         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6385                         "no room to append digest");
6386         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
6387                         ut_params->ibuf, plaintext_pad_len);
6388
6389         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
6390                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
6391                            test_case->auth_tag.len);
6392         }
6393
6394         sym_op->auth.data.offset = 0;
6395         sym_op->auth.data.length = test_case->plaintext.len;
6396
6397         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6398         ut_params->op->sym->m_src = ut_params->ibuf;
6399
6400         return 0;
6401 }
6402
6403 static int
6404 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
6405 {
6406         uint16_t plaintext_pad_len;
6407         uint8_t *plaintext, *auth_tag;
6408
6409         struct crypto_testsuite_params *ts_params = &testsuite_params;
6410         struct crypto_unittest_params *ut_params = &unittest_params;
6411
6412         if (MD5_HMAC_create_session(ts_params, ut_params,
6413                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
6414                 return TEST_FAILED;
6415
6416         /* Generate Crypto op data structure */
6417         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6418                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6419         TEST_ASSERT_NOT_NULL(ut_params->op,
6420                         "Failed to allocate symmetric crypto operation struct");
6421
6422         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
6423                                 16);
6424
6425         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
6426                 return TEST_FAILED;
6427
6428         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6429                         ut_params->op), "failed to process sym crypto op");
6430
6431         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6432                         "crypto op processing failed");
6433
6434         if (ut_params->op->sym->m_dst) {
6435                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6436                                 uint8_t *, plaintext_pad_len);
6437         } else {
6438                 auth_tag = plaintext + plaintext_pad_len;
6439         }
6440
6441         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6442                         auth_tag,
6443                         test_case->auth_tag.data,
6444                         test_case->auth_tag.len,
6445                         "HMAC_MD5 generated tag not as expected");
6446
6447         return TEST_SUCCESS;
6448 }
6449
6450 static int
6451 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
6452 {
6453         uint8_t *plaintext;
6454
6455         struct crypto_testsuite_params *ts_params = &testsuite_params;
6456         struct crypto_unittest_params *ut_params = &unittest_params;
6457
6458         if (MD5_HMAC_create_session(ts_params, ut_params,
6459                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
6460                 return TEST_FAILED;
6461         }
6462
6463         /* Generate Crypto op data structure */
6464         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6465                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6466         TEST_ASSERT_NOT_NULL(ut_params->op,
6467                         "Failed to allocate symmetric crypto operation struct");
6468
6469         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
6470                 return TEST_FAILED;
6471
6472         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6473                         ut_params->op), "failed to process sym crypto op");
6474
6475         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6476                         "HMAC_MD5 crypto op processing failed");
6477
6478         return TEST_SUCCESS;
6479 }
6480
6481 static int
6482 test_MD5_HMAC_generate_case_1(void)
6483 {
6484         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
6485 }
6486
6487 static int
6488 test_MD5_HMAC_verify_case_1(void)
6489 {
6490         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
6491 }
6492
6493 static int
6494 test_MD5_HMAC_generate_case_2(void)
6495 {
6496         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
6497 }
6498
6499 static int
6500 test_MD5_HMAC_verify_case_2(void)
6501 {
6502         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
6503 }
6504
6505 static int
6506 test_multi_session(void)
6507 {
6508         struct crypto_testsuite_params *ts_params = &testsuite_params;
6509         struct crypto_unittest_params *ut_params = &unittest_params;
6510
6511         struct rte_cryptodev_info dev_info;
6512         struct rte_cryptodev_sym_session **sessions;
6513
6514         uint16_t i;
6515
6516         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
6517                         aes_cbc_key, hmac_sha512_key);
6518
6519
6520         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6521
6522         sessions = rte_malloc(NULL,
6523                         (sizeof(struct rte_cryptodev_sym_session *) *
6524                         MAX_NB_SESSIONS) + 1, 0);
6525
6526         /* Create multiple crypto sessions*/
6527         for (i = 0; i < MAX_NB_SESSIONS; i++) {
6528
6529                 sessions[i] = rte_cryptodev_sym_session_create(
6530                                 ts_params->session_mpool);
6531
6532                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6533                                 sessions[i], &ut_params->auth_xform,
6534                                 ts_params->session_mpool);
6535                 TEST_ASSERT_NOT_NULL(sessions[i],
6536                                 "Session creation failed at session number %u",
6537                                 i);
6538
6539                 /* Attempt to send a request on each session */
6540                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
6541                         sessions[i],
6542                         ut_params,
6543                         ts_params,
6544                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
6545                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
6546                         aes_cbc_iv),
6547                         "Failed to perform decrypt on request number %u.", i);
6548                 /* free crypto operation structure */
6549                 if (ut_params->op)
6550                         rte_crypto_op_free(ut_params->op);
6551
6552                 /*
6553                  * free mbuf - both obuf and ibuf are usually the same,
6554                  * so check if they point at the same address is necessary,
6555                  * to avoid freeing the mbuf twice.
6556                  */
6557                 if (ut_params->obuf) {
6558                         rte_pktmbuf_free(ut_params->obuf);
6559                         if (ut_params->ibuf == ut_params->obuf)
6560                                 ut_params->ibuf = 0;
6561                         ut_params->obuf = 0;
6562                 }
6563                 if (ut_params->ibuf) {
6564                         rte_pktmbuf_free(ut_params->ibuf);
6565                         ut_params->ibuf = 0;
6566                 }
6567         }
6568
6569         /* Next session create should fail */
6570         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6571                         sessions[i], &ut_params->auth_xform,
6572                         ts_params->session_mpool);
6573         TEST_ASSERT_NULL(sessions[i],
6574                         "Session creation succeeded unexpectedly!");
6575
6576         for (i = 0; i < MAX_NB_SESSIONS; i++) {
6577                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
6578                                 sessions[i]);
6579                 rte_cryptodev_sym_session_free(sessions[i]);
6580         }
6581
6582         rte_free(sessions);
6583
6584         return TEST_SUCCESS;
6585 }
6586
6587 struct multi_session_params {
6588         struct crypto_unittest_params ut_params;
6589         uint8_t *cipher_key;
6590         uint8_t *hmac_key;
6591         const uint8_t *cipher;
6592         const uint8_t *digest;
6593         uint8_t *iv;
6594 };
6595
6596 #define MB_SESSION_NUMBER 3
6597
6598 static int
6599 test_multi_session_random_usage(void)
6600 {
6601         struct crypto_testsuite_params *ts_params = &testsuite_params;
6602         struct rte_cryptodev_info dev_info;
6603         struct rte_cryptodev_sym_session **sessions;
6604         uint32_t i, j;
6605         struct multi_session_params ut_paramz[] = {
6606
6607                 {
6608                         .cipher_key = ms_aes_cbc_key0,
6609                         .hmac_key = ms_hmac_key0,
6610                         .cipher = ms_aes_cbc_cipher0,
6611                         .digest = ms_hmac_digest0,
6612                         .iv = ms_aes_cbc_iv0
6613                 },
6614                 {
6615                         .cipher_key = ms_aes_cbc_key1,
6616                         .hmac_key = ms_hmac_key1,
6617                         .cipher = ms_aes_cbc_cipher1,
6618                         .digest = ms_hmac_digest1,
6619                         .iv = ms_aes_cbc_iv1
6620                 },
6621                 {
6622                         .cipher_key = ms_aes_cbc_key2,
6623                         .hmac_key = ms_hmac_key2,
6624                         .cipher = ms_aes_cbc_cipher2,
6625                         .digest = ms_hmac_digest2,
6626                         .iv = ms_aes_cbc_iv2
6627                 },
6628
6629         };
6630
6631         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6632
6633         sessions = rte_malloc(NULL,
6634                         (sizeof(struct rte_cryptodev_sym_session *)
6635                                         * MAX_NB_SESSIONS) + 1, 0);
6636
6637         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6638                 sessions[i] = rte_cryptodev_sym_session_create(
6639                                 ts_params->session_mpool);
6640
6641                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
6642                                 sizeof(struct crypto_unittest_params));
6643
6644                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
6645                                 &ut_paramz[i].ut_params,
6646                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
6647
6648                 /* Create multiple crypto sessions*/
6649                 rte_cryptodev_sym_session_init(
6650                                 ts_params->valid_devs[0],
6651                                 sessions[i],
6652                                 &ut_paramz[i].ut_params.auth_xform,
6653                                 ts_params->session_mpool);
6654
6655                 TEST_ASSERT_NOT_NULL(sessions[i],
6656                                 "Session creation failed at session number %u",
6657                                 i);
6658
6659         }
6660
6661         srand(time(NULL));
6662         for (i = 0; i < 40000; i++) {
6663
6664                 j = rand() % MB_SESSION_NUMBER;
6665
6666                 TEST_ASSERT_SUCCESS(
6667                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
6668                                         sessions[j],
6669                                         &ut_paramz[j].ut_params,
6670                                         ts_params, ut_paramz[j].cipher,
6671                                         ut_paramz[j].digest,
6672                                         ut_paramz[j].iv),
6673                         "Failed to perform decrypt on request number %u.", i);
6674
6675                 if (ut_paramz[j].ut_params.op)
6676                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
6677
6678                 /*
6679                  * free mbuf - both obuf and ibuf are usually the same,
6680                  * so check if they point at the same address is necessary,
6681                  * to avoid freeing the mbuf twice.
6682                  */
6683                 if (ut_paramz[j].ut_params.obuf) {
6684                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
6685                         if (ut_paramz[j].ut_params.ibuf
6686                                         == ut_paramz[j].ut_params.obuf)
6687                                 ut_paramz[j].ut_params.ibuf = 0;
6688                         ut_paramz[j].ut_params.obuf = 0;
6689                 }
6690                 if (ut_paramz[j].ut_params.ibuf) {
6691                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
6692                         ut_paramz[j].ut_params.ibuf = 0;
6693                 }
6694         }
6695
6696         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6697                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
6698                                 sessions[i]);
6699                 rte_cryptodev_sym_session_free(sessions[i]);
6700         }
6701
6702         rte_free(sessions);
6703
6704         return TEST_SUCCESS;
6705 }
6706
6707 static int
6708 test_null_cipher_only_operation(void)
6709 {
6710         struct crypto_testsuite_params *ts_params = &testsuite_params;
6711         struct crypto_unittest_params *ut_params = &unittest_params;
6712
6713         /* Generate test mbuf data and space for digest */
6714         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6715                         catch_22_quote, QUOTE_512_BYTES, 0);
6716
6717         /* Setup Cipher Parameters */
6718         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6719         ut_params->cipher_xform.next = NULL;
6720
6721         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6722         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6723
6724         ut_params->sess = rte_cryptodev_sym_session_create(
6725                         ts_params->session_mpool);
6726
6727         /* Create Crypto session*/
6728         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6729                                 ut_params->sess,
6730                                 &ut_params->cipher_xform,
6731                                 ts_params->session_mpool);
6732         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6733
6734         /* Generate Crypto op data structure */
6735         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6736                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6737         TEST_ASSERT_NOT_NULL(ut_params->op,
6738                         "Failed to allocate symmetric crypto operation struct");
6739
6740         /* Set crypto operation data parameters */
6741         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6742
6743         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6744
6745         /* set crypto operation source mbuf */
6746         sym_op->m_src = ut_params->ibuf;
6747
6748         sym_op->cipher.data.offset = 0;
6749         sym_op->cipher.data.length = QUOTE_512_BYTES;
6750
6751         /* Process crypto operation */
6752         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6753                         ut_params->op);
6754         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6755
6756         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6757                         "crypto operation processing failed");
6758
6759         /* Validate obuf */
6760         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6761                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6762                         catch_22_quote,
6763                         QUOTE_512_BYTES,
6764                         "Ciphertext data not as expected");
6765
6766         return TEST_SUCCESS;
6767 }
6768 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
6769                         0xab, 0xab, 0xab, 0xab,
6770                         0xab, 0xab, 0xab, 0xab,
6771                         0xab, 0xab, 0xab, 0xab};
6772 static int
6773 test_null_auth_only_operation(void)
6774 {
6775         struct crypto_testsuite_params *ts_params = &testsuite_params;
6776         struct crypto_unittest_params *ut_params = &unittest_params;
6777         uint8_t *digest;
6778
6779         /* Generate test mbuf data and space for digest */
6780         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6781                         catch_22_quote, QUOTE_512_BYTES, 0);
6782
6783         /* create a pointer for digest, but don't expect anything to be written
6784          * here in a NULL auth algo so no mbuf append done.
6785          */
6786         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6787                         QUOTE_512_BYTES);
6788         /* prefill the memory pointed to by digest */
6789         memcpy(digest, orig_data, sizeof(orig_data));
6790
6791         /* Setup HMAC Parameters */
6792         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6793         ut_params->auth_xform.next = NULL;
6794
6795         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6796         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6797
6798         ut_params->sess = rte_cryptodev_sym_session_create(
6799                         ts_params->session_mpool);
6800
6801         /* Create Crypto session*/
6802         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6803                         ut_params->sess, &ut_params->auth_xform,
6804                         ts_params->session_mpool);
6805         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6806
6807         /* Generate Crypto op data structure */
6808         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6809                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6810         TEST_ASSERT_NOT_NULL(ut_params->op,
6811                         "Failed to allocate symmetric crypto operation struct");
6812
6813         /* Set crypto operation data parameters */
6814         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6815
6816         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6817
6818         sym_op->m_src = ut_params->ibuf;
6819
6820         sym_op->auth.data.offset = 0;
6821         sym_op->auth.data.length = QUOTE_512_BYTES;
6822         sym_op->auth.digest.data = digest;
6823         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6824                         QUOTE_512_BYTES);
6825
6826         /* Process crypto operation */
6827         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6828                         ut_params->op);
6829         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6830
6831         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6832                         "crypto operation processing failed");
6833         /* Make sure memory pointed to by digest hasn't been overwritten */
6834         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6835                         orig_data,
6836                         digest,
6837                         sizeof(orig_data),
6838                         "Memory at digest ptr overwritten unexpectedly");
6839
6840         return TEST_SUCCESS;
6841 }
6842
6843
6844 static int
6845 test_null_cipher_auth_operation(void)
6846 {
6847         struct crypto_testsuite_params *ts_params = &testsuite_params;
6848         struct crypto_unittest_params *ut_params = &unittest_params;
6849         uint8_t *digest;
6850
6851         /* Generate test mbuf data and space for digest */
6852         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6853                         catch_22_quote, QUOTE_512_BYTES, 0);
6854
6855         /* create a pointer for digest, but don't expect anything to be written
6856          * here in a NULL auth algo so no mbuf append done.
6857          */
6858         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6859                         QUOTE_512_BYTES);
6860         /* prefill the memory pointed to by digest */
6861         memcpy(digest, orig_data, sizeof(orig_data));
6862
6863         /* Setup Cipher Parameters */
6864         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6865         ut_params->cipher_xform.next = &ut_params->auth_xform;
6866
6867         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6868         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6869
6870         /* Setup HMAC Parameters */
6871         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6872         ut_params->auth_xform.next = NULL;
6873
6874         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6875         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6876
6877         ut_params->sess = rte_cryptodev_sym_session_create(
6878                         ts_params->session_mpool);
6879
6880         /* Create Crypto session*/
6881         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6882                         ut_params->sess, &ut_params->cipher_xform,
6883                         ts_params->session_mpool);
6884         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6885
6886         /* Generate Crypto op data structure */
6887         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6888                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6889         TEST_ASSERT_NOT_NULL(ut_params->op,
6890                         "Failed to allocate symmetric crypto operation struct");
6891
6892         /* Set crypto operation data parameters */
6893         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6894
6895         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6896
6897         sym_op->m_src = ut_params->ibuf;
6898
6899         sym_op->cipher.data.offset = 0;
6900         sym_op->cipher.data.length = QUOTE_512_BYTES;
6901
6902         sym_op->auth.data.offset = 0;
6903         sym_op->auth.data.length = QUOTE_512_BYTES;
6904         sym_op->auth.digest.data = digest;
6905         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6906                         QUOTE_512_BYTES);
6907
6908         /* Process crypto operation */
6909         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6910                         ut_params->op);
6911         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6912
6913         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6914                         "crypto operation processing failed");
6915
6916         /* Validate obuf */
6917         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6918                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6919                         catch_22_quote,
6920                         QUOTE_512_BYTES,
6921                         "Ciphertext data not as expected");
6922         /* Make sure memory pointed to by digest hasn't been overwritten */
6923         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6924                         orig_data,
6925                         digest,
6926                         sizeof(orig_data),
6927                         "Memory at digest ptr overwritten unexpectedly");
6928
6929         return TEST_SUCCESS;
6930 }
6931
6932 static int
6933 test_null_auth_cipher_operation(void)
6934 {
6935         struct crypto_testsuite_params *ts_params = &testsuite_params;
6936         struct crypto_unittest_params *ut_params = &unittest_params;
6937         uint8_t *digest;
6938
6939         /* Generate test mbuf data */
6940         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6941                         catch_22_quote, QUOTE_512_BYTES, 0);
6942
6943         /* create a pointer for digest, but don't expect anything to be written
6944          * here in a NULL auth algo so no mbuf append done.
6945          */
6946         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6947                                 QUOTE_512_BYTES);
6948         /* prefill the memory pointed to by digest */
6949         memcpy(digest, orig_data, sizeof(orig_data));
6950
6951         /* Setup Cipher Parameters */
6952         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6953         ut_params->cipher_xform.next = NULL;
6954
6955         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6956         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6957
6958         /* Setup HMAC Parameters */
6959         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6960         ut_params->auth_xform.next = &ut_params->cipher_xform;
6961
6962         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6963         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6964
6965         ut_params->sess = rte_cryptodev_sym_session_create(
6966                         ts_params->session_mpool);
6967
6968         /* Create Crypto session*/
6969         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6970                         ut_params->sess, &ut_params->cipher_xform,
6971                         ts_params->session_mpool);
6972         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6973
6974         /* Generate Crypto op data structure */
6975         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6976                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6977         TEST_ASSERT_NOT_NULL(ut_params->op,
6978                         "Failed to allocate symmetric crypto operation struct");
6979
6980         /* Set crypto operation data parameters */
6981         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6982
6983         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6984
6985         sym_op->m_src = ut_params->ibuf;
6986
6987         sym_op->cipher.data.offset = 0;
6988         sym_op->cipher.data.length = QUOTE_512_BYTES;
6989
6990         sym_op->auth.data.offset = 0;
6991         sym_op->auth.data.length = QUOTE_512_BYTES;
6992         sym_op->auth.digest.data = digest;
6993         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6994                                         QUOTE_512_BYTES);
6995
6996         /* Process crypto operation */
6997         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6998                         ut_params->op);
6999         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
7000
7001         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7002                         "crypto operation processing failed");
7003
7004         /* Validate obuf */
7005         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7006                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
7007                         catch_22_quote,
7008                         QUOTE_512_BYTES,
7009                         "Ciphertext data not as expected");
7010         /* Make sure memory pointed to by digest hasn't been overwritten */
7011         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7012                         orig_data,
7013                         digest,
7014                         sizeof(orig_data),
7015                         "Memory at digest ptr overwritten unexpectedly");
7016
7017         return TEST_SUCCESS;
7018 }
7019
7020
7021 static int
7022 test_null_invalid_operation(void)
7023 {
7024         struct crypto_testsuite_params *ts_params = &testsuite_params;
7025         struct crypto_unittest_params *ut_params = &unittest_params;
7026         int ret;
7027
7028         /* Setup Cipher Parameters */
7029         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7030         ut_params->cipher_xform.next = NULL;
7031
7032         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
7033         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
7034
7035         ut_params->sess = rte_cryptodev_sym_session_create(
7036                         ts_params->session_mpool);
7037
7038         /* Create Crypto session*/
7039         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7040                         ut_params->sess, &ut_params->cipher_xform,
7041                         ts_params->session_mpool);
7042         TEST_ASSERT(ret < 0,
7043                         "Session creation succeeded unexpectedly");
7044
7045
7046         /* Setup HMAC Parameters */
7047         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7048         ut_params->auth_xform.next = NULL;
7049
7050         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
7051         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
7052
7053         ut_params->sess = rte_cryptodev_sym_session_create(
7054                         ts_params->session_mpool);
7055
7056         /* Create Crypto session*/
7057         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7058                         ut_params->sess, &ut_params->auth_xform,
7059                         ts_params->session_mpool);
7060         TEST_ASSERT(ret < 0,
7061                         "Session creation succeeded unexpectedly");
7062
7063         return TEST_SUCCESS;
7064 }
7065
7066
7067 #define NULL_BURST_LENGTH (32)
7068
7069 static int
7070 test_null_burst_operation(void)
7071 {
7072         struct crypto_testsuite_params *ts_params = &testsuite_params;
7073         struct crypto_unittest_params *ut_params = &unittest_params;
7074
7075         unsigned i, burst_len = NULL_BURST_LENGTH;
7076
7077         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
7078         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
7079
7080         /* Setup Cipher Parameters */
7081         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7082         ut_params->cipher_xform.next = &ut_params->auth_xform;
7083
7084         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
7085         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
7086
7087         /* Setup HMAC Parameters */
7088         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7089         ut_params->auth_xform.next = NULL;
7090
7091         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
7092         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
7093
7094         ut_params->sess = rte_cryptodev_sym_session_create(
7095                         ts_params->session_mpool);
7096
7097         /* Create Crypto session*/
7098         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7099                         ut_params->sess, &ut_params->cipher_xform,
7100                         ts_params->session_mpool);
7101         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7102
7103         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
7104                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
7105                         burst_len, "failed to generate burst of crypto ops");
7106
7107         /* Generate an operation for each mbuf in burst */
7108         for (i = 0; i < burst_len; i++) {
7109                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7110
7111                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
7112
7113                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
7114                                 sizeof(unsigned));
7115                 *data = i;
7116
7117                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
7118
7119                 burst[i]->sym->m_src = m;
7120         }
7121
7122         /* Process crypto operation */
7123         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
7124                         0, burst, burst_len),
7125                         burst_len,
7126                         "Error enqueuing burst");
7127
7128         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
7129                         0, burst_dequeued, burst_len),
7130                         burst_len,
7131                         "Error dequeuing burst");
7132
7133
7134         for (i = 0; i < burst_len; i++) {
7135                 TEST_ASSERT_EQUAL(
7136                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
7137                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
7138                                         uint32_t *),
7139                         "data not as expected");
7140
7141                 rte_pktmbuf_free(burst[i]->sym->m_src);
7142                 rte_crypto_op_free(burst[i]);
7143         }
7144
7145         return TEST_SUCCESS;
7146 }
7147
7148 static void
7149 generate_gmac_large_plaintext(uint8_t *data)
7150 {
7151         uint16_t i;
7152
7153         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
7154                 memcpy(&data[i], &data[0], 32);
7155 }
7156
7157 static int
7158 create_gmac_operation(enum rte_crypto_auth_operation op,
7159                 const struct gmac_test_data *tdata)
7160 {
7161         struct crypto_testsuite_params *ts_params = &testsuite_params;
7162         struct crypto_unittest_params *ut_params = &unittest_params;
7163         struct rte_crypto_sym_op *sym_op;
7164
7165         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7166
7167         /* Generate Crypto op data structure */
7168         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7169                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7170         TEST_ASSERT_NOT_NULL(ut_params->op,
7171                         "Failed to allocate symmetric crypto operation struct");
7172
7173         sym_op = ut_params->op->sym;
7174
7175         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7176                         ut_params->ibuf, tdata->gmac_tag.len);
7177         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7178                         "no room to append digest");
7179
7180         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7181                         ut_params->ibuf, plaintext_pad_len);
7182
7183         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
7184                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
7185                                 tdata->gmac_tag.len);
7186                 debug_hexdump(stdout, "digest:",
7187                                 sym_op->auth.digest.data,
7188                                 tdata->gmac_tag.len);
7189         }
7190
7191         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7192                         uint8_t *, IV_OFFSET);
7193
7194         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7195
7196         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
7197
7198         sym_op->cipher.data.length = 0;
7199         sym_op->cipher.data.offset = 0;
7200
7201         sym_op->auth.data.offset = 0;
7202         sym_op->auth.data.length = tdata->plaintext.len;
7203
7204         return 0;
7205 }
7206
7207 static int create_gmac_session(uint8_t dev_id,
7208                 const struct gmac_test_data *tdata,
7209                 enum rte_crypto_auth_operation auth_op)
7210 {
7211         uint8_t auth_key[tdata->key.len];
7212
7213         struct crypto_testsuite_params *ts_params = &testsuite_params;
7214         struct crypto_unittest_params *ut_params = &unittest_params;
7215
7216         memcpy(auth_key, tdata->key.data, tdata->key.len);
7217
7218         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7219         ut_params->auth_xform.next = NULL;
7220
7221         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
7222         ut_params->auth_xform.auth.op = auth_op;
7223         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
7224         ut_params->auth_xform.auth.key.length = tdata->key.len;
7225         ut_params->auth_xform.auth.key.data = auth_key;
7226         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
7227         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
7228
7229
7230         ut_params->sess = rte_cryptodev_sym_session_create(
7231                         ts_params->session_mpool);
7232
7233         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7234                         &ut_params->auth_xform,
7235                         ts_params->session_mpool);
7236
7237         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7238
7239         return 0;
7240 }
7241
7242 static int
7243 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
7244 {
7245         struct crypto_testsuite_params *ts_params = &testsuite_params;
7246         struct crypto_unittest_params *ut_params = &unittest_params;
7247
7248         int retval;
7249
7250         uint8_t *auth_tag, *plaintext;
7251         uint16_t plaintext_pad_len;
7252
7253         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
7254                               "No GMAC length in the source data");
7255
7256         retval = create_gmac_session(ts_params->valid_devs[0],
7257                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
7258
7259         if (retval < 0)
7260                 return retval;
7261
7262         if (tdata->plaintext.len > MBUF_SIZE)
7263                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7264         else
7265                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7266         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7267                         "Failed to allocate input buffer in mempool");
7268
7269         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7270                         rte_pktmbuf_tailroom(ut_params->ibuf));
7271
7272         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7273         /*
7274          * Runtime generate the large plain text instead of use hard code
7275          * plain text vector. It is done to avoid create huge source file
7276          * with the test vector.
7277          */
7278         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
7279                 generate_gmac_large_plaintext(tdata->plaintext.data);
7280
7281         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7282                                 plaintext_pad_len);
7283         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7284
7285         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7286         debug_hexdump(stdout, "plaintext:", plaintext,
7287                         tdata->plaintext.len);
7288
7289         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
7290                         tdata);
7291
7292         if (retval < 0)
7293                 return retval;
7294
7295         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7296
7297         ut_params->op->sym->m_src = ut_params->ibuf;
7298
7299         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7300                         ut_params->op), "failed to process sym crypto op");
7301
7302         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7303                         "crypto op processing failed");
7304
7305         if (ut_params->op->sym->m_dst) {
7306                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7307                                 uint8_t *, plaintext_pad_len);
7308         } else {
7309                 auth_tag = plaintext + plaintext_pad_len;
7310         }
7311
7312         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
7313
7314         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7315                         auth_tag,
7316                         tdata->gmac_tag.data,
7317                         tdata->gmac_tag.len,
7318                         "GMAC Generated auth tag not as expected");
7319
7320         return 0;
7321 }
7322
7323 static int
7324 test_AES_GMAC_authentication_test_case_1(void)
7325 {
7326         return test_AES_GMAC_authentication(&gmac_test_case_1);
7327 }
7328
7329 static int
7330 test_AES_GMAC_authentication_test_case_2(void)
7331 {
7332         return test_AES_GMAC_authentication(&gmac_test_case_2);
7333 }
7334
7335 static int
7336 test_AES_GMAC_authentication_test_case_3(void)
7337 {
7338         return test_AES_GMAC_authentication(&gmac_test_case_3);
7339 }
7340
7341 static int
7342 test_AES_GMAC_authentication_test_case_4(void)
7343 {
7344         return test_AES_GMAC_authentication(&gmac_test_case_4);
7345 }
7346
7347 static int
7348 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
7349 {
7350         struct crypto_testsuite_params *ts_params = &testsuite_params;
7351         struct crypto_unittest_params *ut_params = &unittest_params;
7352         int retval;
7353         uint32_t plaintext_pad_len;
7354         uint8_t *plaintext;
7355
7356         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
7357                               "No GMAC length in the source data");
7358
7359         retval = create_gmac_session(ts_params->valid_devs[0],
7360                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
7361
7362         if (retval < 0)
7363                 return retval;
7364
7365         if (tdata->plaintext.len > MBUF_SIZE)
7366                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7367         else
7368                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7369         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7370                         "Failed to allocate input buffer in mempool");
7371
7372         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7373                         rte_pktmbuf_tailroom(ut_params->ibuf));
7374
7375         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7376
7377         /*
7378          * Runtime generate the large plain text instead of use hard code
7379          * plain text vector. It is done to avoid create huge source file
7380          * with the test vector.
7381          */
7382         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
7383                 generate_gmac_large_plaintext(tdata->plaintext.data);
7384
7385         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7386                                 plaintext_pad_len);
7387         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7388
7389         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7390         debug_hexdump(stdout, "plaintext:", plaintext,
7391                         tdata->plaintext.len);
7392
7393         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
7394                         tdata);
7395
7396         if (retval < 0)
7397                 return retval;
7398
7399         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7400
7401         ut_params->op->sym->m_src = ut_params->ibuf;
7402
7403         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7404                         ut_params->op), "failed to process sym crypto op");
7405
7406         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7407                         "crypto op processing failed");
7408
7409         return 0;
7410
7411 }
7412
7413 static int
7414 test_AES_GMAC_authentication_verify_test_case_1(void)
7415 {
7416         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
7417 }
7418
7419 static int
7420 test_AES_GMAC_authentication_verify_test_case_2(void)
7421 {
7422         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
7423 }
7424
7425 static int
7426 test_AES_GMAC_authentication_verify_test_case_3(void)
7427 {
7428         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
7429 }
7430
7431 static int
7432 test_AES_GMAC_authentication_verify_test_case_4(void)
7433 {
7434         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
7435 }
7436
7437 struct test_crypto_vector {
7438         enum rte_crypto_cipher_algorithm crypto_algo;
7439
7440         struct {
7441                 uint8_t data[64];
7442                 unsigned int len;
7443         } cipher_key;
7444
7445         struct {
7446                 uint8_t data[64];
7447                 unsigned int len;
7448         } iv;
7449
7450         struct {
7451                 const uint8_t *data;
7452                 unsigned int len;
7453         } plaintext;
7454
7455         struct {
7456                 const uint8_t *data;
7457                 unsigned int len;
7458         } ciphertext;
7459
7460         enum rte_crypto_auth_algorithm auth_algo;
7461
7462         struct {
7463                 uint8_t data[128];
7464                 unsigned int len;
7465         } auth_key;
7466
7467         struct {
7468                 const uint8_t *data;
7469                 unsigned int len;
7470         } aad;
7471
7472         struct {
7473                 uint8_t data[128];
7474                 unsigned int len;
7475         } digest;
7476 };
7477
7478 static const struct test_crypto_vector
7479 hmac_sha1_test_crypto_vector = {
7480         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
7481         .plaintext = {
7482                 .data = plaintext_hash,
7483                 .len = 512
7484         },
7485         .auth_key = {
7486                 .data = {
7487                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
7488                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
7489                         0xDE, 0xF4, 0xDE, 0xAD
7490                 },
7491                 .len = 20
7492         },
7493         .digest = {
7494                 .data = {
7495                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
7496                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
7497                         0x3F, 0x91, 0x64, 0x59
7498                 },
7499                 .len = 20
7500         }
7501 };
7502
7503 static const struct test_crypto_vector
7504 aes128_gmac_test_vector = {
7505         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
7506         .plaintext = {
7507                 .data = plaintext_hash,
7508                 .len = 512
7509         },
7510         .iv = {
7511                 .data = {
7512                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
7513                         0x08, 0x09, 0x0A, 0x0B
7514                 },
7515                 .len = 12
7516         },
7517         .auth_key = {
7518                 .data = {
7519                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
7520                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
7521                 },
7522                 .len = 16
7523         },
7524         .digest = {
7525                 .data = {
7526                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
7527                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
7528                 },
7529                 .len = 16
7530         }
7531 };
7532
7533 static const struct test_crypto_vector
7534 aes128cbc_hmac_sha1_test_vector = {
7535         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
7536         .cipher_key = {
7537                 .data = {
7538                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
7539                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
7540                 },
7541                 .len = 16
7542         },
7543         .iv = {
7544                 .data = {
7545                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
7546                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
7547                 },
7548                 .len = 16
7549         },
7550         .plaintext = {
7551                 .data = plaintext_hash,
7552                 .len = 512
7553         },
7554         .ciphertext = {
7555                 .data = ciphertext512_aes128cbc,
7556                 .len = 512
7557         },
7558         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
7559         .auth_key = {
7560                 .data = {
7561                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
7562                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
7563                         0xDE, 0xF4, 0xDE, 0xAD
7564                 },
7565                 .len = 20
7566         },
7567         .digest = {
7568                 .data = {
7569                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
7570                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
7571                         0x18, 0x8C, 0x1D, 0x32
7572                 },
7573                 .len = 20
7574         }
7575 };
7576
7577 static void
7578 data_corruption(uint8_t *data)
7579 {
7580         data[0] += 1;
7581 }
7582
7583 static void
7584 tag_corruption(uint8_t *data, unsigned int tag_offset)
7585 {
7586         data[tag_offset] += 1;
7587 }
7588
7589 static int
7590 create_auth_session(struct crypto_unittest_params *ut_params,
7591                 uint8_t dev_id,
7592                 const struct test_crypto_vector *reference,
7593                 enum rte_crypto_auth_operation auth_op)
7594 {
7595         struct crypto_testsuite_params *ts_params = &testsuite_params;
7596         uint8_t auth_key[reference->auth_key.len + 1];
7597
7598         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
7599
7600         /* Setup Authentication Parameters */
7601         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7602         ut_params->auth_xform.auth.op = auth_op;
7603         ut_params->auth_xform.next = NULL;
7604         ut_params->auth_xform.auth.algo = reference->auth_algo;
7605         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
7606         ut_params->auth_xform.auth.key.data = auth_key;
7607         ut_params->auth_xform.auth.digest_length = reference->digest.len;
7608
7609         /* Create Crypto session*/
7610         ut_params->sess = rte_cryptodev_sym_session_create(
7611                         ts_params->session_mpool);
7612
7613         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7614                                 &ut_params->auth_xform,
7615                                 ts_params->session_mpool);
7616
7617         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7618
7619         return 0;
7620 }
7621
7622 static int
7623 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
7624                 uint8_t dev_id,
7625                 const struct test_crypto_vector *reference,
7626                 enum rte_crypto_auth_operation auth_op,
7627                 enum rte_crypto_cipher_operation cipher_op)
7628 {
7629         struct crypto_testsuite_params *ts_params = &testsuite_params;
7630         uint8_t cipher_key[reference->cipher_key.len + 1];
7631         uint8_t auth_key[reference->auth_key.len + 1];
7632
7633         memcpy(cipher_key, reference->cipher_key.data,
7634                         reference->cipher_key.len);
7635         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
7636
7637         /* Setup Authentication Parameters */
7638         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7639         ut_params->auth_xform.auth.op = auth_op;
7640         ut_params->auth_xform.auth.algo = reference->auth_algo;
7641         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
7642         ut_params->auth_xform.auth.key.data = auth_key;
7643         ut_params->auth_xform.auth.digest_length = reference->digest.len;
7644
7645         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
7646                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
7647                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
7648         } else {
7649                 ut_params->auth_xform.next = &ut_params->cipher_xform;
7650
7651                 /* Setup Cipher Parameters */
7652                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7653                 ut_params->cipher_xform.next = NULL;
7654                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
7655                 ut_params->cipher_xform.cipher.op = cipher_op;
7656                 ut_params->cipher_xform.cipher.key.data = cipher_key;
7657                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
7658                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7659                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
7660         }
7661
7662         /* Create Crypto session*/
7663         ut_params->sess = rte_cryptodev_sym_session_create(
7664                         ts_params->session_mpool);
7665
7666         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7667                                 &ut_params->auth_xform,
7668                                 ts_params->session_mpool);
7669
7670         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7671
7672         return 0;
7673 }
7674
7675 static int
7676 create_auth_operation(struct crypto_testsuite_params *ts_params,
7677                 struct crypto_unittest_params *ut_params,
7678                 const struct test_crypto_vector *reference,
7679                 unsigned int auth_generate)
7680 {
7681         /* Generate Crypto op data structure */
7682         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7683                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7684         TEST_ASSERT_NOT_NULL(ut_params->op,
7685                         "Failed to allocate pktmbuf offload");
7686
7687         /* Set crypto operation data parameters */
7688         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7689
7690         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7691
7692         /* set crypto operation source mbuf */
7693         sym_op->m_src = ut_params->ibuf;
7694
7695         /* digest */
7696         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7697                         ut_params->ibuf, reference->digest.len);
7698
7699         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7700                         "no room to append auth tag");
7701
7702         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7703                         ut_params->ibuf, reference->plaintext.len);
7704
7705         if (auth_generate)
7706                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7707         else
7708                 memcpy(sym_op->auth.digest.data,
7709                                 reference->digest.data,
7710                                 reference->digest.len);
7711
7712         debug_hexdump(stdout, "digest:",
7713                         sym_op->auth.digest.data,
7714                         reference->digest.len);
7715
7716         sym_op->auth.data.length = reference->plaintext.len;
7717         sym_op->auth.data.offset = 0;
7718
7719         return 0;
7720 }
7721
7722 static int
7723 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
7724                 struct crypto_unittest_params *ut_params,
7725                 const struct test_crypto_vector *reference,
7726                 unsigned int auth_generate)
7727 {
7728         /* Generate Crypto op data structure */
7729         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7730                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7731         TEST_ASSERT_NOT_NULL(ut_params->op,
7732                         "Failed to allocate pktmbuf offload");
7733
7734         /* Set crypto operation data parameters */
7735         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7736
7737         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7738
7739         /* set crypto operation source mbuf */
7740         sym_op->m_src = ut_params->ibuf;
7741
7742         /* digest */
7743         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7744                         ut_params->ibuf, reference->digest.len);
7745
7746         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7747                         "no room to append auth tag");
7748
7749         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7750                         ut_params->ibuf, reference->ciphertext.len);
7751
7752         if (auth_generate)
7753                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7754         else
7755                 memcpy(sym_op->auth.digest.data,
7756                                 reference->digest.data,
7757                                 reference->digest.len);
7758
7759         debug_hexdump(stdout, "digest:",
7760                         sym_op->auth.digest.data,
7761                         reference->digest.len);
7762
7763         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7764                         reference->iv.data, reference->iv.len);
7765
7766         sym_op->cipher.data.length = 0;
7767         sym_op->cipher.data.offset = 0;
7768
7769         sym_op->auth.data.length = reference->plaintext.len;
7770         sym_op->auth.data.offset = 0;
7771
7772         return 0;
7773 }
7774
7775 static int
7776 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
7777                 struct crypto_unittest_params *ut_params,
7778                 const struct test_crypto_vector *reference,
7779                 unsigned int auth_generate)
7780 {
7781         /* Generate Crypto op data structure */
7782         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7783                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7784         TEST_ASSERT_NOT_NULL(ut_params->op,
7785                         "Failed to allocate pktmbuf offload");
7786
7787         /* Set crypto operation data parameters */
7788         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7789
7790         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7791
7792         /* set crypto operation source mbuf */
7793         sym_op->m_src = ut_params->ibuf;
7794
7795         /* digest */
7796         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7797                         ut_params->ibuf, reference->digest.len);
7798
7799         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7800                         "no room to append auth tag");
7801
7802         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7803                         ut_params->ibuf, reference->ciphertext.len);
7804
7805         if (auth_generate)
7806                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7807         else
7808                 memcpy(sym_op->auth.digest.data,
7809                                 reference->digest.data,
7810                                 reference->digest.len);
7811
7812         debug_hexdump(stdout, "digest:",
7813                         sym_op->auth.digest.data,
7814                         reference->digest.len);
7815
7816         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7817                         reference->iv.data, reference->iv.len);
7818
7819         sym_op->cipher.data.length = reference->ciphertext.len;
7820         sym_op->cipher.data.offset = 0;
7821
7822         sym_op->auth.data.length = reference->ciphertext.len;
7823         sym_op->auth.data.offset = 0;
7824
7825         return 0;
7826 }
7827
7828 static int
7829 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7830                 struct crypto_unittest_params *ut_params,
7831                 const struct test_crypto_vector *reference)
7832 {
7833         return create_auth_operation(ts_params, ut_params, reference, 0);
7834 }
7835
7836 static int
7837 create_auth_verify_GMAC_operation(
7838                 struct crypto_testsuite_params *ts_params,
7839                 struct crypto_unittest_params *ut_params,
7840                 const struct test_crypto_vector *reference)
7841 {
7842         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
7843 }
7844
7845 static int
7846 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7847                 struct crypto_unittest_params *ut_params,
7848                 const struct test_crypto_vector *reference)
7849 {
7850         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
7851 }
7852
7853 static int
7854 test_authentication_verify_fail_when_data_corruption(
7855                 struct crypto_testsuite_params *ts_params,
7856                 struct crypto_unittest_params *ut_params,
7857                 const struct test_crypto_vector *reference,
7858                 unsigned int data_corrupted)
7859 {
7860         int retval;
7861
7862         uint8_t *plaintext;
7863
7864         /* Create session */
7865         retval = create_auth_session(ut_params,
7866                         ts_params->valid_devs[0],
7867                         reference,
7868                         RTE_CRYPTO_AUTH_OP_VERIFY);
7869         if (retval < 0)
7870                 return retval;
7871
7872         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7873         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7874                         "Failed to allocate input buffer in mempool");
7875
7876         /* clear mbuf payload */
7877         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7878                         rte_pktmbuf_tailroom(ut_params->ibuf));
7879
7880         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7881                         reference->plaintext.len);
7882         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7883         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7884
7885         debug_hexdump(stdout, "plaintext:", plaintext,
7886                 reference->plaintext.len);
7887
7888         /* Create operation */
7889         retval = create_auth_verify_operation(ts_params, ut_params, reference);
7890
7891         if (retval < 0)
7892                 return retval;
7893
7894         if (data_corrupted)
7895                 data_corruption(plaintext);
7896         else
7897                 tag_corruption(plaintext, reference->plaintext.len);
7898
7899         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7900                         ut_params->op);
7901         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7902         TEST_ASSERT_EQUAL(ut_params->op->status,
7903                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7904                         "authentication not failed");
7905
7906         ut_params->obuf = ut_params->op->sym->m_src;
7907         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7908
7909         return 0;
7910 }
7911
7912 static int
7913 test_authentication_verify_GMAC_fail_when_corruption(
7914                 struct crypto_testsuite_params *ts_params,
7915                 struct crypto_unittest_params *ut_params,
7916                 const struct test_crypto_vector *reference,
7917                 unsigned int data_corrupted)
7918 {
7919         int retval;
7920         uint8_t *plaintext;
7921
7922         /* Create session */
7923         retval = create_auth_cipher_session(ut_params,
7924                         ts_params->valid_devs[0],
7925                         reference,
7926                         RTE_CRYPTO_AUTH_OP_VERIFY,
7927                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7928         if (retval < 0)
7929                 return retval;
7930
7931         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7932         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7933                         "Failed to allocate input buffer in mempool");
7934
7935         /* clear mbuf payload */
7936         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7937                         rte_pktmbuf_tailroom(ut_params->ibuf));
7938
7939         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7940                         reference->plaintext.len);
7941         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7942         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7943
7944         debug_hexdump(stdout, "plaintext:", plaintext,
7945                 reference->plaintext.len);
7946
7947         /* Create operation */
7948         retval = create_auth_verify_GMAC_operation(ts_params,
7949                         ut_params,
7950                         reference);
7951
7952         if (retval < 0)
7953                 return retval;
7954
7955         if (data_corrupted)
7956                 data_corruption(plaintext);
7957         else
7958                 tag_corruption(plaintext, reference->aad.len);
7959
7960         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7961                         ut_params->op);
7962         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7963         TEST_ASSERT_EQUAL(ut_params->op->status,
7964                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7965                         "authentication not failed");
7966
7967         ut_params->obuf = ut_params->op->sym->m_src;
7968         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7969
7970         return 0;
7971 }
7972
7973 static int
7974 test_authenticated_decryption_fail_when_corruption(
7975                 struct crypto_testsuite_params *ts_params,
7976                 struct crypto_unittest_params *ut_params,
7977                 const struct test_crypto_vector *reference,
7978                 unsigned int data_corrupted)
7979 {
7980         int retval;
7981
7982         uint8_t *ciphertext;
7983
7984         /* Create session */
7985         retval = create_auth_cipher_session(ut_params,
7986                         ts_params->valid_devs[0],
7987                         reference,
7988                         RTE_CRYPTO_AUTH_OP_VERIFY,
7989                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7990         if (retval < 0)
7991                 return retval;
7992
7993         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7994         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7995                         "Failed to allocate input buffer in mempool");
7996
7997         /* clear mbuf payload */
7998         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7999                         rte_pktmbuf_tailroom(ut_params->ibuf));
8000
8001         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8002                         reference->ciphertext.len);
8003         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
8004         memcpy(ciphertext, reference->ciphertext.data,
8005                         reference->ciphertext.len);
8006
8007         /* Create operation */
8008         retval = create_cipher_auth_verify_operation(ts_params,
8009                         ut_params,
8010                         reference);
8011
8012         if (retval < 0)
8013                 return retval;
8014
8015         if (data_corrupted)
8016                 data_corruption(ciphertext);
8017         else
8018                 tag_corruption(ciphertext, reference->ciphertext.len);
8019
8020         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8021                         ut_params->op);
8022
8023         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8024         TEST_ASSERT_EQUAL(ut_params->op->status,
8025                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
8026                         "authentication not failed");
8027
8028         ut_params->obuf = ut_params->op->sym->m_src;
8029         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
8030
8031         return 0;
8032 }
8033
8034 static int
8035 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
8036                 const struct aead_test_data *tdata,
8037                 void *digest_mem, uint64_t digest_phys)
8038 {
8039         struct crypto_testsuite_params *ts_params = &testsuite_params;
8040         struct crypto_unittest_params *ut_params = &unittest_params;
8041
8042         const unsigned int auth_tag_len = tdata->auth_tag.len;
8043         const unsigned int iv_len = tdata->iv.len;
8044         unsigned int aad_len = tdata->aad.len;
8045
8046         /* Generate Crypto op data structure */
8047         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8048                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8049         TEST_ASSERT_NOT_NULL(ut_params->op,
8050                 "Failed to allocate symmetric crypto operation struct");
8051
8052         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8053
8054         sym_op->aead.digest.data = digest_mem;
8055
8056         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8057                         "no room to append digest");
8058
8059         sym_op->aead.digest.phys_addr = digest_phys;
8060
8061         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
8062                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8063                                 auth_tag_len);
8064                 debug_hexdump(stdout, "digest:",
8065                                 sym_op->aead.digest.data,
8066                                 auth_tag_len);
8067         }
8068
8069         /* Append aad data */
8070         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8071                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8072                                 uint8_t *, IV_OFFSET);
8073
8074                 /* Copy IV 1 byte after the IV pointer, according to the API */
8075                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
8076
8077                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
8078
8079                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
8080                                 ut_params->ibuf, aad_len);
8081                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8082                                 "no room to prepend aad");
8083                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
8084                                 ut_params->ibuf);
8085
8086                 memset(sym_op->aead.aad.data, 0, aad_len);
8087                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
8088                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
8089
8090                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
8091                 debug_hexdump(stdout, "aad:",
8092                                 sym_op->aead.aad.data, aad_len);
8093         } else {
8094                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8095                                 uint8_t *, IV_OFFSET);
8096
8097                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
8098
8099                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
8100                                 ut_params->ibuf, aad_len);
8101                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8102                                 "no room to prepend aad");
8103                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
8104                                 ut_params->ibuf);
8105
8106                 memset(sym_op->aead.aad.data, 0, aad_len);
8107                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
8108
8109                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
8110                 debug_hexdump(stdout, "aad:",
8111                                 sym_op->aead.aad.data, aad_len);
8112         }
8113
8114         sym_op->aead.data.length = tdata->plaintext.len;
8115         sym_op->aead.data.offset = aad_len;
8116
8117         return 0;
8118 }
8119
8120 #define SGL_MAX_NO      16
8121
8122 static int
8123 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
8124                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
8125 {
8126         struct crypto_testsuite_params *ts_params = &testsuite_params;
8127         struct crypto_unittest_params *ut_params = &unittest_params;
8128         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
8129         int retval;
8130         int to_trn = 0;
8131         int to_trn_tbl[SGL_MAX_NO];
8132         int segs = 1;
8133         unsigned int trn_data = 0;
8134         uint8_t *plaintext, *ciphertext, *auth_tag;
8135
8136         if (fragsz > tdata->plaintext.len)
8137                 fragsz = tdata->plaintext.len;
8138
8139         uint16_t plaintext_len = fragsz;
8140         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8141
8142         if (fragsz_oop > tdata->plaintext.len)
8143                 frag_size_oop = tdata->plaintext.len;
8144
8145         int ecx = 0;
8146         void *digest_mem = NULL;
8147
8148         uint32_t prepend_len = tdata->aad.len;
8149
8150         if (tdata->plaintext.len % fragsz != 0) {
8151                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
8152                         return 1;
8153         }       else {
8154                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
8155                         return 1;
8156         }
8157
8158         /*
8159          * For out-op-place we need to alloc another mbuf
8160          */
8161         if (oop) {
8162                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8163                 rte_pktmbuf_append(ut_params->obuf,
8164                                 frag_size_oop + prepend_len);
8165                 buf_oop = ut_params->obuf;
8166         }
8167
8168         /* Create AEAD session */
8169         retval = create_aead_session(ts_params->valid_devs[0],
8170                         tdata->algo,
8171                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8172                         tdata->key.data, tdata->key.len,
8173                         tdata->aad.len, tdata->auth_tag.len,
8174                         tdata->iv.len);
8175         if (retval < 0)
8176                 return retval;
8177
8178         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8179
8180         /* clear mbuf payload */
8181         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8182                         rte_pktmbuf_tailroom(ut_params->ibuf));
8183
8184         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8185                         plaintext_len);
8186
8187         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
8188
8189         trn_data += plaintext_len;
8190
8191         buf = ut_params->ibuf;
8192
8193         /*
8194          * Loop until no more fragments
8195          */
8196
8197         while (trn_data < tdata->plaintext.len) {
8198                 ++segs;
8199                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
8200                                 (tdata->plaintext.len - trn_data) : fragsz;
8201
8202                 to_trn_tbl[ecx++] = to_trn;
8203
8204                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8205                 buf = buf->next;
8206
8207                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8208                                 rte_pktmbuf_tailroom(buf));
8209
8210                 /* OOP */
8211                 if (oop && !fragsz_oop) {
8212                         buf_last_oop = buf_oop->next =
8213                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8214                         buf_oop = buf_oop->next;
8215                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8216                                         0, rte_pktmbuf_tailroom(buf_oop));
8217                         rte_pktmbuf_append(buf_oop, to_trn);
8218                 }
8219
8220                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8221                                 to_trn);
8222
8223                 memcpy(plaintext, tdata->plaintext.data + trn_data,
8224                                 to_trn);
8225                 trn_data += to_trn;
8226                 if (trn_data  == tdata->plaintext.len) {
8227                         if (oop) {
8228                                 if (!fragsz_oop)
8229                                         digest_mem = rte_pktmbuf_append(buf_oop,
8230                                                 tdata->auth_tag.len);
8231                         } else
8232                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
8233                                         tdata->auth_tag.len);
8234                 }
8235         }
8236
8237         uint64_t digest_phys = 0;
8238
8239         ut_params->ibuf->nb_segs = segs;
8240
8241         segs = 1;
8242         if (fragsz_oop && oop) {
8243                 to_trn = 0;
8244                 ecx = 0;
8245
8246                 if (frag_size_oop == tdata->plaintext.len) {
8247                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
8248                                 tdata->auth_tag.len);
8249
8250                         digest_phys = rte_pktmbuf_iova_offset(
8251                                         ut_params->obuf,
8252                                         tdata->plaintext.len + prepend_len);
8253                 }
8254
8255                 trn_data = frag_size_oop;
8256                 while (trn_data < tdata->plaintext.len) {
8257                         ++segs;
8258                         to_trn =
8259                                 (tdata->plaintext.len - trn_data <
8260                                                 frag_size_oop) ?
8261                                 (tdata->plaintext.len - trn_data) :
8262                                                 frag_size_oop;
8263
8264                         to_trn_tbl[ecx++] = to_trn;
8265
8266                         buf_last_oop = buf_oop->next =
8267                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8268                         buf_oop = buf_oop->next;
8269                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8270                                         0, rte_pktmbuf_tailroom(buf_oop));
8271                         rte_pktmbuf_append(buf_oop, to_trn);
8272
8273                         trn_data += to_trn;
8274
8275                         if (trn_data  == tdata->plaintext.len) {
8276                                 digest_mem = rte_pktmbuf_append(buf_oop,
8277                                         tdata->auth_tag.len);
8278                         }
8279                 }
8280
8281                 ut_params->obuf->nb_segs = segs;
8282         }
8283
8284         /*
8285          * Place digest at the end of the last buffer
8286          */
8287         if (!digest_phys)
8288                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
8289         if (oop && buf_last_oop)
8290                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
8291
8292         if (!digest_mem && !oop) {
8293                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8294                                 + tdata->auth_tag.len);
8295                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
8296                                 tdata->plaintext.len);
8297         }
8298
8299         /* Create AEAD operation */
8300         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
8301                         tdata, digest_mem, digest_phys);
8302
8303         if (retval < 0)
8304                 return retval;
8305
8306         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8307
8308         ut_params->op->sym->m_src = ut_params->ibuf;
8309         if (oop)
8310                 ut_params->op->sym->m_dst = ut_params->obuf;
8311
8312         /* Process crypto operation */
8313         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8314                         ut_params->op), "failed to process sym crypto op");
8315
8316         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8317                         "crypto op processing failed");
8318
8319
8320         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8321                         uint8_t *, prepend_len);
8322         if (oop) {
8323                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8324                                 uint8_t *, prepend_len);
8325         }
8326
8327         if (fragsz_oop)
8328                 fragsz = fragsz_oop;
8329
8330         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8331                         ciphertext,
8332                         tdata->ciphertext.data,
8333                         fragsz,
8334                         "Ciphertext data not as expected");
8335
8336         buf = ut_params->op->sym->m_src->next;
8337         if (oop)
8338                 buf = ut_params->op->sym->m_dst->next;
8339
8340         unsigned int off = fragsz;
8341
8342         ecx = 0;
8343         while (buf) {
8344                 ciphertext = rte_pktmbuf_mtod(buf,
8345                                 uint8_t *);
8346
8347                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
8348                                 ciphertext,
8349                                 tdata->ciphertext.data + off,
8350                                 to_trn_tbl[ecx],
8351                                 "Ciphertext data not as expected");
8352
8353                 off += to_trn_tbl[ecx++];
8354                 buf = buf->next;
8355         }
8356
8357         auth_tag = digest_mem;
8358         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8359                         auth_tag,
8360                         tdata->auth_tag.data,
8361                         tdata->auth_tag.len,
8362                         "Generated auth tag not as expected");
8363
8364         return 0;
8365 }
8366
8367 #define IN_PLACE        0
8368 #define OUT_OF_PLACE    1
8369
8370 static int
8371 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
8372 {
8373         return test_authenticated_encryption_SGL(
8374                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
8375 }
8376
8377 static int
8378 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
8379 {
8380         return test_authenticated_encryption_SGL(
8381                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
8382 }
8383
8384 static int
8385 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
8386 {
8387         return test_authenticated_encryption_SGL(
8388                         &gcm_test_case_8, OUT_OF_PLACE, 400,
8389                         gcm_test_case_8.plaintext.len);
8390 }
8391
8392 static int
8393 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
8394 {
8395
8396         return test_authenticated_encryption_SGL(
8397                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
8398 }
8399
8400 static int
8401 test_authentication_verify_fail_when_data_corrupted(
8402                 struct crypto_testsuite_params *ts_params,
8403                 struct crypto_unittest_params *ut_params,
8404                 const struct test_crypto_vector *reference)
8405 {
8406         return test_authentication_verify_fail_when_data_corruption(
8407                         ts_params, ut_params, reference, 1);
8408 }
8409
8410 static int
8411 test_authentication_verify_fail_when_tag_corrupted(
8412                 struct crypto_testsuite_params *ts_params,
8413                 struct crypto_unittest_params *ut_params,
8414                 const struct test_crypto_vector *reference)
8415 {
8416         return test_authentication_verify_fail_when_data_corruption(
8417                         ts_params, ut_params, reference, 0);
8418 }
8419
8420 static int
8421 test_authentication_verify_GMAC_fail_when_data_corrupted(
8422                 struct crypto_testsuite_params *ts_params,
8423                 struct crypto_unittest_params *ut_params,
8424                 const struct test_crypto_vector *reference)
8425 {
8426         return test_authentication_verify_GMAC_fail_when_corruption(
8427                         ts_params, ut_params, reference, 1);
8428 }
8429
8430 static int
8431 test_authentication_verify_GMAC_fail_when_tag_corrupted(
8432                 struct crypto_testsuite_params *ts_params,
8433                 struct crypto_unittest_params *ut_params,
8434                 const struct test_crypto_vector *reference)
8435 {
8436         return test_authentication_verify_GMAC_fail_when_corruption(
8437                         ts_params, ut_params, reference, 0);
8438 }
8439
8440 static int
8441 test_authenticated_decryption_fail_when_data_corrupted(
8442                 struct crypto_testsuite_params *ts_params,
8443                 struct crypto_unittest_params *ut_params,
8444                 const struct test_crypto_vector *reference)
8445 {
8446         return test_authenticated_decryption_fail_when_corruption(
8447                         ts_params, ut_params, reference, 1);
8448 }
8449
8450 static int
8451 test_authenticated_decryption_fail_when_tag_corrupted(
8452                 struct crypto_testsuite_params *ts_params,
8453                 struct crypto_unittest_params *ut_params,
8454                 const struct test_crypto_vector *reference)
8455 {
8456         return test_authenticated_decryption_fail_when_corruption(
8457                         ts_params, ut_params, reference, 0);
8458 }
8459
8460 static int
8461 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
8462 {
8463         return test_authentication_verify_fail_when_data_corrupted(
8464                         &testsuite_params, &unittest_params,
8465                         &hmac_sha1_test_crypto_vector);
8466 }
8467
8468 static int
8469 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
8470 {
8471         return test_authentication_verify_fail_when_tag_corrupted(
8472                         &testsuite_params, &unittest_params,
8473                         &hmac_sha1_test_crypto_vector);
8474 }
8475
8476 static int
8477 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
8478 {
8479         return test_authentication_verify_GMAC_fail_when_data_corrupted(
8480                         &testsuite_params, &unittest_params,
8481                         &aes128_gmac_test_vector);
8482 }
8483
8484 static int
8485 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
8486 {
8487         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
8488                         &testsuite_params, &unittest_params,
8489                         &aes128_gmac_test_vector);
8490 }
8491
8492 static int
8493 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
8494 {
8495         return test_authenticated_decryption_fail_when_data_corrupted(
8496                         &testsuite_params,
8497                         &unittest_params,
8498                         &aes128cbc_hmac_sha1_test_vector);
8499 }
8500
8501 static int
8502 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
8503 {
8504         return test_authenticated_decryption_fail_when_tag_corrupted(
8505                         &testsuite_params,
8506                         &unittest_params,
8507                         &aes128cbc_hmac_sha1_test_vector);
8508 }
8509
8510 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
8511
8512 /* global AESNI slave IDs for the scheduler test */
8513 uint8_t aesni_ids[2];
8514
8515 static int
8516 test_scheduler_attach_slave_op(void)
8517 {
8518         struct crypto_testsuite_params *ts_params = &testsuite_params;
8519         uint8_t sched_id = ts_params->valid_devs[0];
8520         uint32_t nb_devs, i, nb_devs_attached = 0;
8521         int ret;
8522         char vdev_name[32];
8523
8524         /* create 2 AESNI_MB if necessary */
8525         nb_devs = rte_cryptodev_device_count_by_driver(
8526                         rte_cryptodev_driver_id_get(
8527                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
8528         if (nb_devs < 2) {
8529                 for (i = nb_devs; i < 2; i++) {
8530                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
8531                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
8532                                         i);
8533                         ret = rte_vdev_init(vdev_name, NULL);
8534
8535                         TEST_ASSERT(ret == 0,
8536                                 "Failed to create instance %u of"
8537                                 " pmd : %s",
8538                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
8539                 }
8540         }
8541
8542         /* attach 2 AESNI_MB cdevs */
8543         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
8544                         i++) {
8545                 struct rte_cryptodev_info info;
8546
8547                 rte_cryptodev_info_get(i, &info);
8548                 if (info.driver_id != rte_cryptodev_driver_id_get(
8549                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
8550                         continue;
8551
8552                 /*
8553                  * Create the session mempool again, since now there are new devices
8554                  * to use the mempool.
8555                  */
8556                 if (ts_params->session_mpool) {
8557                         rte_mempool_free(ts_params->session_mpool);
8558                         ts_params->session_mpool = NULL;
8559                 }
8560                 unsigned int session_size =
8561                         rte_cryptodev_sym_get_private_session_size(i);
8562
8563                 if (info.sym.max_nb_sessions != 0 &&
8564                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
8565                         RTE_LOG(ERR, USER1,
8566                                         "Device does not support "
8567                                         "at least %u sessions\n",
8568                                         MAX_NB_SESSIONS);
8569                         return TEST_FAILED;
8570                 }
8571                 /*
8572                  * Create mempool with maximum number of sessions * 2,
8573                  * to include the session headers
8574                  */
8575                 if (ts_params->session_mpool == NULL) {
8576                         ts_params->session_mpool = rte_mempool_create(
8577                                         "test_sess_mp",
8578                                         MAX_NB_SESSIONS * 2,
8579                                         session_size,
8580                                         0, 0, NULL, NULL, NULL,
8581                                         NULL, SOCKET_ID_ANY,
8582                                         0);
8583
8584                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
8585                                         "session mempool allocation failed");
8586                 }
8587
8588                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
8589                                 (uint8_t)i);
8590
8591                 TEST_ASSERT(ret == 0,
8592                         "Failed to attach device %u of pmd : %s", i,
8593                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
8594
8595                 aesni_ids[nb_devs_attached] = (uint8_t)i;
8596
8597                 nb_devs_attached++;
8598         }
8599
8600         return 0;
8601 }
8602
8603 static int
8604 test_scheduler_detach_slave_op(void)
8605 {
8606         struct crypto_testsuite_params *ts_params = &testsuite_params;
8607         uint8_t sched_id = ts_params->valid_devs[0];
8608         uint32_t i;
8609         int ret;
8610
8611         for (i = 0; i < 2; i++) {
8612                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
8613                                 aesni_ids[i]);
8614                 TEST_ASSERT(ret == 0,
8615                         "Failed to detach device %u", aesni_ids[i]);
8616         }
8617
8618         return 0;
8619 }
8620
8621 static int
8622 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
8623 {
8624         struct crypto_testsuite_params *ts_params = &testsuite_params;
8625         uint8_t sched_id = ts_params->valid_devs[0];
8626         /* set mode */
8627         return rte_cryptodev_scheduler_mode_set(sched_id,
8628                 scheduler_mode);
8629 }
8630
8631 static int
8632 test_scheduler_mode_roundrobin_op(void)
8633 {
8634         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
8635                         0, "Failed to set roundrobin mode");
8636         return 0;
8637
8638 }
8639
8640 static int
8641 test_scheduler_mode_multicore_op(void)
8642 {
8643         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
8644                         0, "Failed to set multicore mode");
8645
8646         return 0;
8647 }
8648
8649 static int
8650 test_scheduler_mode_failover_op(void)
8651 {
8652         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
8653                         0, "Failed to set failover mode");
8654
8655         return 0;
8656 }
8657
8658 static int
8659 test_scheduler_mode_pkt_size_distr_op(void)
8660 {
8661         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
8662                         0, "Failed to set pktsize mode");
8663
8664         return 0;
8665 }
8666
8667 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
8668         .suite_name = "Crypto Device Scheduler Unit Test Suite",
8669         .setup = testsuite_setup,
8670         .teardown = testsuite_teardown,
8671         .unit_test_cases = {
8672                 /* Multi Core */
8673                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
8674                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
8675                 TEST_CASE_ST(ut_setup, ut_teardown,
8676                                         test_AES_chain_scheduler_all),
8677                 TEST_CASE_ST(ut_setup, ut_teardown,
8678                                         test_AES_cipheronly_scheduler_all),
8679                 TEST_CASE_ST(ut_setup, ut_teardown,
8680                                         test_authonly_scheduler_all),
8681                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
8682
8683                 /* Round Robin */
8684                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
8685                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
8686                 TEST_CASE_ST(ut_setup, ut_teardown,
8687                                 test_AES_chain_scheduler_all),
8688                 TEST_CASE_ST(ut_setup, ut_teardown,
8689                                 test_AES_cipheronly_scheduler_all),
8690                 TEST_CASE_ST(ut_setup, ut_teardown,
8691                                 test_authonly_scheduler_all),
8692                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
8693
8694                 /* Fail over */
8695                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
8696                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
8697                 TEST_CASE_ST(ut_setup, ut_teardown,
8698                                         test_AES_chain_scheduler_all),
8699                 TEST_CASE_ST(ut_setup, ut_teardown,
8700                                         test_AES_cipheronly_scheduler_all),
8701                 TEST_CASE_ST(ut_setup, ut_teardown,
8702                                         test_authonly_scheduler_all),
8703                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
8704
8705                 /* PKT SIZE */
8706                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
8707                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
8708                 TEST_CASE_ST(ut_setup, ut_teardown,
8709                                         test_AES_chain_scheduler_all),
8710                 TEST_CASE_ST(ut_setup, ut_teardown,
8711                                         test_AES_cipheronly_scheduler_all),
8712                 TEST_CASE_ST(ut_setup, ut_teardown,
8713                                         test_authonly_scheduler_all),
8714                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
8715
8716                 TEST_CASES_END() /**< NULL terminate unit test array */
8717         }
8718 };
8719
8720 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
8721
8722 static struct unit_test_suite cryptodev_qat_testsuite  = {
8723         .suite_name = "Crypto QAT Unit Test Suite",
8724         .setup = testsuite_setup,
8725         .teardown = testsuite_teardown,
8726         .unit_test_cases = {
8727                 TEST_CASE_ST(ut_setup, ut_teardown,
8728                                 test_device_configure_invalid_dev_id),
8729                 TEST_CASE_ST(ut_setup, ut_teardown,
8730                                 test_device_configure_invalid_queue_pair_ids),
8731                 TEST_CASE_ST(ut_setup, ut_teardown,
8732                                 test_queue_pair_descriptor_setup),
8733                 TEST_CASE_ST(ut_setup, ut_teardown,
8734                                 test_multi_session),
8735
8736                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
8737                 TEST_CASE_ST(ut_setup, ut_teardown,
8738                                                 test_AES_cipheronly_qat_all),
8739                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
8740                 TEST_CASE_ST(ut_setup, ut_teardown,
8741                                                 test_3DES_cipheronly_qat_all),
8742                 TEST_CASE_ST(ut_setup, ut_teardown,
8743                                                 test_DES_cipheronly_qat_all),
8744                 TEST_CASE_ST(ut_setup, ut_teardown,
8745                                                 test_AES_docsis_qat_all),
8746                 TEST_CASE_ST(ut_setup, ut_teardown,
8747                                                 test_DES_docsis_qat_all),
8748                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_qat_all),
8749                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
8750
8751                 /** AES CCM Authenticated Encryption 128 bits key */
8752                 TEST_CASE_ST(ut_setup, ut_teardown,
8753                         test_AES_CCM_authenticated_encryption_test_case_128_1),
8754                 TEST_CASE_ST(ut_setup, ut_teardown,
8755                         test_AES_CCM_authenticated_encryption_test_case_128_2),
8756                 TEST_CASE_ST(ut_setup, ut_teardown,
8757                         test_AES_CCM_authenticated_encryption_test_case_128_3),
8758
8759                 /** AES CCM Authenticated Decryption 128 bits key*/
8760                 TEST_CASE_ST(ut_setup, ut_teardown,
8761                         test_AES_CCM_authenticated_decryption_test_case_128_1),
8762                 TEST_CASE_ST(ut_setup, ut_teardown,
8763                         test_AES_CCM_authenticated_decryption_test_case_128_2),
8764                 TEST_CASE_ST(ut_setup, ut_teardown,
8765                         test_AES_CCM_authenticated_decryption_test_case_128_3),
8766
8767                 /** AES GCM Authenticated Encryption */
8768                 TEST_CASE_ST(ut_setup, ut_teardown,
8769                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
8770                 TEST_CASE_ST(ut_setup, ut_teardown,
8771                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
8772                 TEST_CASE_ST(ut_setup, ut_teardown,
8773                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
8774                 TEST_CASE_ST(ut_setup, ut_teardown,
8775                         test_AES_GCM_authenticated_encryption_test_case_1),
8776                 TEST_CASE_ST(ut_setup, ut_teardown,
8777                         test_AES_GCM_authenticated_encryption_test_case_2),
8778                 TEST_CASE_ST(ut_setup, ut_teardown,
8779                         test_AES_GCM_authenticated_encryption_test_case_3),
8780                 TEST_CASE_ST(ut_setup, ut_teardown,
8781                         test_AES_GCM_authenticated_encryption_test_case_4),
8782                 TEST_CASE_ST(ut_setup, ut_teardown,
8783                         test_AES_GCM_authenticated_encryption_test_case_5),
8784                 TEST_CASE_ST(ut_setup, ut_teardown,
8785                         test_AES_GCM_authenticated_encryption_test_case_6),
8786                 TEST_CASE_ST(ut_setup, ut_teardown,
8787                         test_AES_GCM_authenticated_encryption_test_case_7),
8788
8789                 /** AES GCM Authenticated Decryption */
8790                 TEST_CASE_ST(ut_setup, ut_teardown,
8791                         test_AES_GCM_authenticated_decryption_test_case_1),
8792                 TEST_CASE_ST(ut_setup, ut_teardown,
8793                         test_AES_GCM_authenticated_decryption_test_case_2),
8794                 TEST_CASE_ST(ut_setup, ut_teardown,
8795                         test_AES_GCM_authenticated_decryption_test_case_3),
8796                 TEST_CASE_ST(ut_setup, ut_teardown,
8797                         test_AES_GCM_authenticated_decryption_test_case_4),
8798                 TEST_CASE_ST(ut_setup, ut_teardown,
8799                         test_AES_GCM_authenticated_decryption_test_case_5),
8800                 TEST_CASE_ST(ut_setup, ut_teardown,
8801                         test_AES_GCM_authenticated_decryption_test_case_6),
8802                 TEST_CASE_ST(ut_setup, ut_teardown,
8803                         test_AES_GCM_authenticated_decryption_test_case_7),
8804
8805                 /** AES GCM Authenticated Encryption 192 bits key */
8806                 TEST_CASE_ST(ut_setup, ut_teardown,
8807                         test_AES_GCM_auth_encryption_test_case_192_1),
8808                 TEST_CASE_ST(ut_setup, ut_teardown,
8809                         test_AES_GCM_auth_encryption_test_case_192_2),
8810                 TEST_CASE_ST(ut_setup, ut_teardown,
8811                         test_AES_GCM_auth_encryption_test_case_192_3),
8812                 TEST_CASE_ST(ut_setup, ut_teardown,
8813                         test_AES_GCM_auth_encryption_test_case_192_4),
8814                 TEST_CASE_ST(ut_setup, ut_teardown,
8815                         test_AES_GCM_auth_encryption_test_case_192_5),
8816                 TEST_CASE_ST(ut_setup, ut_teardown,
8817                         test_AES_GCM_auth_encryption_test_case_192_6),
8818                 TEST_CASE_ST(ut_setup, ut_teardown,
8819                         test_AES_GCM_auth_encryption_test_case_192_7),
8820
8821                 /** AES GCM Authenticated Decryption 192 bits key */
8822                 TEST_CASE_ST(ut_setup, ut_teardown,
8823                         test_AES_GCM_auth_decryption_test_case_192_1),
8824                 TEST_CASE_ST(ut_setup, ut_teardown,
8825                         test_AES_GCM_auth_decryption_test_case_192_2),
8826                 TEST_CASE_ST(ut_setup, ut_teardown,
8827                         test_AES_GCM_auth_decryption_test_case_192_3),
8828                 TEST_CASE_ST(ut_setup, ut_teardown,
8829                         test_AES_GCM_auth_decryption_test_case_192_4),
8830                 TEST_CASE_ST(ut_setup, ut_teardown,
8831                         test_AES_GCM_auth_decryption_test_case_192_5),
8832                 TEST_CASE_ST(ut_setup, ut_teardown,
8833                         test_AES_GCM_auth_decryption_test_case_192_6),
8834                 TEST_CASE_ST(ut_setup, ut_teardown,
8835                         test_AES_GCM_auth_decryption_test_case_192_7),
8836
8837                 /** AES GCM Authenticated Encryption 256 bits key */
8838                 TEST_CASE_ST(ut_setup, ut_teardown,
8839                         test_AES_GCM_auth_encryption_test_case_256_1),
8840                 TEST_CASE_ST(ut_setup, ut_teardown,
8841                         test_AES_GCM_auth_encryption_test_case_256_2),
8842                 TEST_CASE_ST(ut_setup, ut_teardown,
8843                         test_AES_GCM_auth_encryption_test_case_256_3),
8844                 TEST_CASE_ST(ut_setup, ut_teardown,
8845                         test_AES_GCM_auth_encryption_test_case_256_4),
8846                 TEST_CASE_ST(ut_setup, ut_teardown,
8847                         test_AES_GCM_auth_encryption_test_case_256_5),
8848                 TEST_CASE_ST(ut_setup, ut_teardown,
8849                         test_AES_GCM_auth_encryption_test_case_256_6),
8850                 TEST_CASE_ST(ut_setup, ut_teardown,
8851                         test_AES_GCM_auth_encryption_test_case_256_7),
8852
8853                 /** AES GMAC Authentication */
8854                 TEST_CASE_ST(ut_setup, ut_teardown,
8855                         test_AES_GMAC_authentication_test_case_1),
8856                 TEST_CASE_ST(ut_setup, ut_teardown,
8857                         test_AES_GMAC_authentication_verify_test_case_1),
8858                 TEST_CASE_ST(ut_setup, ut_teardown,
8859                         test_AES_GMAC_authentication_test_case_2),
8860                 TEST_CASE_ST(ut_setup, ut_teardown,
8861                         test_AES_GMAC_authentication_verify_test_case_2),
8862                 TEST_CASE_ST(ut_setup, ut_teardown,
8863                         test_AES_GMAC_authentication_test_case_3),
8864                 TEST_CASE_ST(ut_setup, ut_teardown,
8865                         test_AES_GMAC_authentication_verify_test_case_3),
8866
8867                 /** SNOW 3G encrypt only (UEA2) */
8868                 TEST_CASE_ST(ut_setup, ut_teardown,
8869                         test_snow3g_encryption_test_case_1),
8870                 TEST_CASE_ST(ut_setup, ut_teardown,
8871                         test_snow3g_encryption_test_case_2),
8872                 TEST_CASE_ST(ut_setup, ut_teardown,
8873                         test_snow3g_encryption_test_case_3),
8874                 TEST_CASE_ST(ut_setup, ut_teardown,
8875                         test_snow3g_encryption_test_case_4),
8876                 TEST_CASE_ST(ut_setup, ut_teardown,
8877                         test_snow3g_encryption_test_case_5),
8878
8879                 TEST_CASE_ST(ut_setup, ut_teardown,
8880                         test_snow3g_encryption_test_case_1_oop),
8881                 TEST_CASE_ST(ut_setup, ut_teardown,
8882                         test_snow3g_decryption_test_case_1_oop),
8883
8884                 /** SNOW 3G decrypt only (UEA2) */
8885                 TEST_CASE_ST(ut_setup, ut_teardown,
8886                         test_snow3g_decryption_test_case_1),
8887                 TEST_CASE_ST(ut_setup, ut_teardown,
8888                         test_snow3g_decryption_test_case_2),
8889                 TEST_CASE_ST(ut_setup, ut_teardown,
8890                         test_snow3g_decryption_test_case_3),
8891                 TEST_CASE_ST(ut_setup, ut_teardown,
8892                         test_snow3g_decryption_test_case_4),
8893                 TEST_CASE_ST(ut_setup, ut_teardown,
8894                         test_snow3g_decryption_test_case_5),
8895                 TEST_CASE_ST(ut_setup, ut_teardown,
8896                         test_snow3g_hash_generate_test_case_1),
8897                 TEST_CASE_ST(ut_setup, ut_teardown,
8898                         test_snow3g_hash_generate_test_case_2),
8899                 TEST_CASE_ST(ut_setup, ut_teardown,
8900                         test_snow3g_hash_generate_test_case_3),
8901                 TEST_CASE_ST(ut_setup, ut_teardown,
8902                         test_snow3g_hash_verify_test_case_1),
8903                 TEST_CASE_ST(ut_setup, ut_teardown,
8904                         test_snow3g_hash_verify_test_case_2),
8905                 TEST_CASE_ST(ut_setup, ut_teardown,
8906                         test_snow3g_hash_verify_test_case_3),
8907                 TEST_CASE_ST(ut_setup, ut_teardown,
8908                         test_snow3g_cipher_auth_test_case_1),
8909                 TEST_CASE_ST(ut_setup, ut_teardown,
8910                         test_snow3g_auth_cipher_test_case_1),
8911
8912                 /** ZUC encrypt only (EEA3) */
8913                 TEST_CASE_ST(ut_setup, ut_teardown,
8914                         test_zuc_encryption_test_case_1),
8915                 TEST_CASE_ST(ut_setup, ut_teardown,
8916                         test_zuc_encryption_test_case_2),
8917                 TEST_CASE_ST(ut_setup, ut_teardown,
8918                         test_zuc_encryption_test_case_3),
8919                 TEST_CASE_ST(ut_setup, ut_teardown,
8920                         test_zuc_encryption_test_case_4),
8921                 TEST_CASE_ST(ut_setup, ut_teardown,
8922                         test_zuc_encryption_test_case_5),
8923
8924                 /** ZUC authenticate (EIA3) */
8925                 TEST_CASE_ST(ut_setup, ut_teardown,
8926                         test_zuc_hash_generate_test_case_6),
8927                 TEST_CASE_ST(ut_setup, ut_teardown,
8928                         test_zuc_hash_generate_test_case_7),
8929                 TEST_CASE_ST(ut_setup, ut_teardown,
8930                         test_zuc_hash_generate_test_case_8),
8931
8932                 /** ZUC alg-chain (EEA3/EIA3) */
8933                 TEST_CASE_ST(ut_setup, ut_teardown,
8934                         test_zuc_cipher_auth_test_case_1),
8935                 TEST_CASE_ST(ut_setup, ut_teardown,
8936                         test_zuc_cipher_auth_test_case_2),
8937
8938                 /** HMAC_MD5 Authentication */
8939                 TEST_CASE_ST(ut_setup, ut_teardown,
8940                         test_MD5_HMAC_generate_case_1),
8941                 TEST_CASE_ST(ut_setup, ut_teardown,
8942                         test_MD5_HMAC_verify_case_1),
8943                 TEST_CASE_ST(ut_setup, ut_teardown,
8944                         test_MD5_HMAC_generate_case_2),
8945                 TEST_CASE_ST(ut_setup, ut_teardown,
8946                         test_MD5_HMAC_verify_case_2),
8947
8948                 /** NULL tests */
8949                 TEST_CASE_ST(ut_setup, ut_teardown,
8950                         test_null_auth_only_operation),
8951                 TEST_CASE_ST(ut_setup, ut_teardown,
8952                         test_null_cipher_only_operation),
8953                 TEST_CASE_ST(ut_setup, ut_teardown,
8954                         test_null_cipher_auth_operation),
8955                 TEST_CASE_ST(ut_setup, ut_teardown,
8956                         test_null_auth_cipher_operation),
8957
8958                 /** KASUMI tests */
8959                 TEST_CASE_ST(ut_setup, ut_teardown,
8960                         test_kasumi_hash_generate_test_case_1),
8961                 TEST_CASE_ST(ut_setup, ut_teardown,
8962                         test_kasumi_hash_generate_test_case_2),
8963                 TEST_CASE_ST(ut_setup, ut_teardown,
8964                         test_kasumi_hash_generate_test_case_3),
8965                 TEST_CASE_ST(ut_setup, ut_teardown,
8966                         test_kasumi_hash_generate_test_case_4),
8967                 TEST_CASE_ST(ut_setup, ut_teardown,
8968                         test_kasumi_hash_generate_test_case_5),
8969                 TEST_CASE_ST(ut_setup, ut_teardown,
8970                         test_kasumi_hash_generate_test_case_6),
8971
8972                 TEST_CASE_ST(ut_setup, ut_teardown,
8973                         test_kasumi_hash_verify_test_case_1),
8974                 TEST_CASE_ST(ut_setup, ut_teardown,
8975                         test_kasumi_hash_verify_test_case_2),
8976                 TEST_CASE_ST(ut_setup, ut_teardown,
8977                         test_kasumi_hash_verify_test_case_3),
8978                 TEST_CASE_ST(ut_setup, ut_teardown,
8979                         test_kasumi_hash_verify_test_case_4),
8980                 TEST_CASE_ST(ut_setup, ut_teardown,
8981                         test_kasumi_hash_verify_test_case_5),
8982
8983                 TEST_CASE_ST(ut_setup, ut_teardown,
8984                         test_kasumi_encryption_test_case_1),
8985                 TEST_CASE_ST(ut_setup, ut_teardown,
8986                         test_kasumi_encryption_test_case_3),
8987                 TEST_CASE_ST(ut_setup, ut_teardown,
8988                         test_kasumi_auth_cipher_test_case_1),
8989                 TEST_CASE_ST(ut_setup, ut_teardown,
8990                         test_kasumi_cipher_auth_test_case_1),
8991
8992                 /** Negative tests */
8993                 TEST_CASE_ST(ut_setup, ut_teardown,
8994                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
8995                 TEST_CASE_ST(ut_setup, ut_teardown,
8996                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8997                 TEST_CASE_ST(ut_setup, ut_teardown,
8998                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8999                 TEST_CASE_ST(ut_setup, ut_teardown,
9000                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
9001                 TEST_CASE_ST(ut_setup, ut_teardown,
9002                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9003                 TEST_CASE_ST(ut_setup, ut_teardown,
9004                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9005
9006                 TEST_CASES_END() /**< NULL terminate unit test array */
9007         }
9008 };
9009
9010 static struct unit_test_suite cryptodev_virtio_testsuite = {
9011         .suite_name = "Crypto VIRTIO Unit Test Suite",
9012         .setup = testsuite_setup,
9013         .teardown = testsuite_teardown,
9014         .unit_test_cases = {
9015                 TEST_CASE_ST(ut_setup, ut_teardown,
9016                                 test_AES_cipheronly_virtio_all),
9017
9018                 TEST_CASES_END() /**< NULL terminate unit test array */
9019         }
9020 };
9021
9022 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
9023         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
9024         .setup = testsuite_setup,
9025         .teardown = testsuite_teardown,
9026         .unit_test_cases = {
9027                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
9028                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
9029                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
9030                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
9031                 TEST_CASE_ST(ut_setup, ut_teardown,
9032                                                 test_DES_cipheronly_mb_all),
9033                 TEST_CASE_ST(ut_setup, ut_teardown,
9034                                                 test_DES_docsis_mb_all),
9035                 TEST_CASE_ST(ut_setup, ut_teardown,
9036                         test_AES_CCM_authenticated_encryption_test_case_128_1),
9037                 TEST_CASE_ST(ut_setup, ut_teardown,
9038                         test_AES_CCM_authenticated_decryption_test_case_128_1),
9039                 TEST_CASE_ST(ut_setup, ut_teardown,
9040                         test_AES_CCM_authenticated_encryption_test_case_128_2),
9041                 TEST_CASE_ST(ut_setup, ut_teardown,
9042                         test_AES_CCM_authenticated_decryption_test_case_128_2),
9043                 TEST_CASE_ST(ut_setup, ut_teardown,
9044                         test_AES_CCM_authenticated_encryption_test_case_128_3),
9045                 TEST_CASE_ST(ut_setup, ut_teardown,
9046                         test_AES_CCM_authenticated_decryption_test_case_128_3),
9047
9048                 TEST_CASES_END() /**< NULL terminate unit test array */
9049         }
9050 };
9051
9052 static struct unit_test_suite cryptodev_openssl_testsuite  = {
9053         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
9054         .setup = testsuite_setup,
9055         .teardown = testsuite_teardown,
9056         .unit_test_cases = {
9057                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
9058                 TEST_CASE_ST(ut_setup, ut_teardown,
9059                                 test_multi_session_random_usage),
9060                 TEST_CASE_ST(ut_setup, ut_teardown,
9061                                 test_AES_chain_openssl_all),
9062                 TEST_CASE_ST(ut_setup, ut_teardown,
9063                                 test_AES_cipheronly_openssl_all),
9064                 TEST_CASE_ST(ut_setup, ut_teardown,
9065                                 test_3DES_chain_openssl_all),
9066                 TEST_CASE_ST(ut_setup, ut_teardown,
9067                                 test_3DES_cipheronly_openssl_all),
9068                 TEST_CASE_ST(ut_setup, ut_teardown,
9069                                 test_DES_cipheronly_openssl_all),
9070                 TEST_CASE_ST(ut_setup, ut_teardown,
9071                                 test_DES_docsis_openssl_all),
9072                 TEST_CASE_ST(ut_setup, ut_teardown,
9073                                 test_authonly_openssl_all),
9074
9075                 /** AES GCM Authenticated Encryption */
9076                 TEST_CASE_ST(ut_setup, ut_teardown,
9077                         test_AES_GCM_authenticated_encryption_test_case_1),
9078                 TEST_CASE_ST(ut_setup, ut_teardown,
9079                         test_AES_GCM_authenticated_encryption_test_case_2),
9080                 TEST_CASE_ST(ut_setup, ut_teardown,
9081                         test_AES_GCM_authenticated_encryption_test_case_3),
9082                 TEST_CASE_ST(ut_setup, ut_teardown,
9083                         test_AES_GCM_authenticated_encryption_test_case_4),
9084                 TEST_CASE_ST(ut_setup, ut_teardown,
9085                         test_AES_GCM_authenticated_encryption_test_case_5),
9086                 TEST_CASE_ST(ut_setup, ut_teardown,
9087                         test_AES_GCM_authenticated_encryption_test_case_6),
9088                 TEST_CASE_ST(ut_setup, ut_teardown,
9089                         test_AES_GCM_authenticated_encryption_test_case_7),
9090
9091                 /** AES GCM Authenticated Decryption */
9092                 TEST_CASE_ST(ut_setup, ut_teardown,
9093                         test_AES_GCM_authenticated_decryption_test_case_1),
9094                 TEST_CASE_ST(ut_setup, ut_teardown,
9095                         test_AES_GCM_authenticated_decryption_test_case_2),
9096                 TEST_CASE_ST(ut_setup, ut_teardown,
9097                         test_AES_GCM_authenticated_decryption_test_case_3),
9098                 TEST_CASE_ST(ut_setup, ut_teardown,
9099                         test_AES_GCM_authenticated_decryption_test_case_4),
9100                 TEST_CASE_ST(ut_setup, ut_teardown,
9101                         test_AES_GCM_authenticated_decryption_test_case_5),
9102                 TEST_CASE_ST(ut_setup, ut_teardown,
9103                         test_AES_GCM_authenticated_decryption_test_case_6),
9104                 TEST_CASE_ST(ut_setup, ut_teardown,
9105                         test_AES_GCM_authenticated_decryption_test_case_7),
9106
9107
9108                 /** AES GCM Authenticated Encryption 192 bits key */
9109                 TEST_CASE_ST(ut_setup, ut_teardown,
9110                         test_AES_GCM_auth_encryption_test_case_192_1),
9111                 TEST_CASE_ST(ut_setup, ut_teardown,
9112                         test_AES_GCM_auth_encryption_test_case_192_2),
9113                 TEST_CASE_ST(ut_setup, ut_teardown,
9114                         test_AES_GCM_auth_encryption_test_case_192_3),
9115                 TEST_CASE_ST(ut_setup, ut_teardown,
9116                         test_AES_GCM_auth_encryption_test_case_192_4),
9117                 TEST_CASE_ST(ut_setup, ut_teardown,
9118                         test_AES_GCM_auth_encryption_test_case_192_5),
9119                 TEST_CASE_ST(ut_setup, ut_teardown,
9120                         test_AES_GCM_auth_encryption_test_case_192_6),
9121                 TEST_CASE_ST(ut_setup, ut_teardown,
9122                         test_AES_GCM_auth_encryption_test_case_192_7),
9123
9124                 /** AES GCM Authenticated Decryption 192 bits key */
9125                 TEST_CASE_ST(ut_setup, ut_teardown,
9126                         test_AES_GCM_auth_decryption_test_case_192_1),
9127                 TEST_CASE_ST(ut_setup, ut_teardown,
9128                         test_AES_GCM_auth_decryption_test_case_192_2),
9129                 TEST_CASE_ST(ut_setup, ut_teardown,
9130                         test_AES_GCM_auth_decryption_test_case_192_3),
9131                 TEST_CASE_ST(ut_setup, ut_teardown,
9132                         test_AES_GCM_auth_decryption_test_case_192_4),
9133                 TEST_CASE_ST(ut_setup, ut_teardown,
9134                         test_AES_GCM_auth_decryption_test_case_192_5),
9135                 TEST_CASE_ST(ut_setup, ut_teardown,
9136                         test_AES_GCM_auth_decryption_test_case_192_6),
9137                 TEST_CASE_ST(ut_setup, ut_teardown,
9138                         test_AES_GCM_auth_decryption_test_case_192_7),
9139
9140                 /** AES GCM Authenticated Encryption 256 bits key */
9141                 TEST_CASE_ST(ut_setup, ut_teardown,
9142                         test_AES_GCM_auth_encryption_test_case_256_1),
9143                 TEST_CASE_ST(ut_setup, ut_teardown,
9144                         test_AES_GCM_auth_encryption_test_case_256_2),
9145                 TEST_CASE_ST(ut_setup, ut_teardown,
9146                         test_AES_GCM_auth_encryption_test_case_256_3),
9147                 TEST_CASE_ST(ut_setup, ut_teardown,
9148                         test_AES_GCM_auth_encryption_test_case_256_4),
9149                 TEST_CASE_ST(ut_setup, ut_teardown,
9150                         test_AES_GCM_auth_encryption_test_case_256_5),
9151                 TEST_CASE_ST(ut_setup, ut_teardown,
9152                         test_AES_GCM_auth_encryption_test_case_256_6),
9153                 TEST_CASE_ST(ut_setup, ut_teardown,
9154                         test_AES_GCM_auth_encryption_test_case_256_7),
9155
9156                 /** AES GCM Authenticated Decryption 256 bits key */
9157                 TEST_CASE_ST(ut_setup, ut_teardown,
9158                         test_AES_GCM_auth_decryption_test_case_256_1),
9159                 TEST_CASE_ST(ut_setup, ut_teardown,
9160                         test_AES_GCM_auth_decryption_test_case_256_2),
9161                 TEST_CASE_ST(ut_setup, ut_teardown,
9162                         test_AES_GCM_auth_decryption_test_case_256_3),
9163                 TEST_CASE_ST(ut_setup, ut_teardown,
9164                         test_AES_GCM_auth_decryption_test_case_256_4),
9165                 TEST_CASE_ST(ut_setup, ut_teardown,
9166                         test_AES_GCM_auth_decryption_test_case_256_5),
9167                 TEST_CASE_ST(ut_setup, ut_teardown,
9168                         test_AES_GCM_auth_decryption_test_case_256_6),
9169                 TEST_CASE_ST(ut_setup, ut_teardown,
9170                         test_AES_GCM_auth_decryption_test_case_256_7),
9171
9172                 /** AES GMAC Authentication */
9173                 TEST_CASE_ST(ut_setup, ut_teardown,
9174                         test_AES_GMAC_authentication_test_case_1),
9175                 TEST_CASE_ST(ut_setup, ut_teardown,
9176                         test_AES_GMAC_authentication_verify_test_case_1),
9177                 TEST_CASE_ST(ut_setup, ut_teardown,
9178                         test_AES_GMAC_authentication_test_case_2),
9179                 TEST_CASE_ST(ut_setup, ut_teardown,
9180                         test_AES_GMAC_authentication_verify_test_case_2),
9181                 TEST_CASE_ST(ut_setup, ut_teardown,
9182                         test_AES_GMAC_authentication_test_case_3),
9183                 TEST_CASE_ST(ut_setup, ut_teardown,
9184                         test_AES_GMAC_authentication_verify_test_case_3),
9185                 TEST_CASE_ST(ut_setup, ut_teardown,
9186                         test_AES_GMAC_authentication_test_case_4),
9187                 TEST_CASE_ST(ut_setup, ut_teardown,
9188                         test_AES_GMAC_authentication_verify_test_case_4),
9189
9190                 /** AES CCM Authenticated Encryption 128 bits key */
9191                 TEST_CASE_ST(ut_setup, ut_teardown,
9192                         test_AES_CCM_authenticated_encryption_test_case_128_1),
9193                 TEST_CASE_ST(ut_setup, ut_teardown,
9194                         test_AES_CCM_authenticated_encryption_test_case_128_2),
9195                 TEST_CASE_ST(ut_setup, ut_teardown,
9196                         test_AES_CCM_authenticated_encryption_test_case_128_3),
9197
9198                 /** AES CCM Authenticated Decryption 128 bits key*/
9199                 TEST_CASE_ST(ut_setup, ut_teardown,
9200                         test_AES_CCM_authenticated_decryption_test_case_128_1),
9201                 TEST_CASE_ST(ut_setup, ut_teardown,
9202                         test_AES_CCM_authenticated_decryption_test_case_128_2),
9203                 TEST_CASE_ST(ut_setup, ut_teardown,
9204                         test_AES_CCM_authenticated_decryption_test_case_128_3),
9205
9206                 /** AES CCM Authenticated Encryption 192 bits key */
9207                 TEST_CASE_ST(ut_setup, ut_teardown,
9208                         test_AES_CCM_authenticated_encryption_test_case_192_1),
9209                 TEST_CASE_ST(ut_setup, ut_teardown,
9210                         test_AES_CCM_authenticated_encryption_test_case_192_2),
9211                 TEST_CASE_ST(ut_setup, ut_teardown,
9212                         test_AES_CCM_authenticated_encryption_test_case_192_3),
9213
9214                 /** AES CCM Authenticated Decryption 192 bits key*/
9215                 TEST_CASE_ST(ut_setup, ut_teardown,
9216                         test_AES_CCM_authenticated_decryption_test_case_192_1),
9217                 TEST_CASE_ST(ut_setup, ut_teardown,
9218                         test_AES_CCM_authenticated_decryption_test_case_192_2),
9219                 TEST_CASE_ST(ut_setup, ut_teardown,
9220                         test_AES_CCM_authenticated_decryption_test_case_192_3),
9221
9222                 /** AES CCM Authenticated Encryption 256 bits key */
9223                 TEST_CASE_ST(ut_setup, ut_teardown,
9224                         test_AES_CCM_authenticated_encryption_test_case_256_1),
9225                 TEST_CASE_ST(ut_setup, ut_teardown,
9226                         test_AES_CCM_authenticated_encryption_test_case_256_2),
9227                 TEST_CASE_ST(ut_setup, ut_teardown,
9228                         test_AES_CCM_authenticated_encryption_test_case_256_3),
9229
9230                 /** AES CCM Authenticated Decryption 256 bits key*/
9231                 TEST_CASE_ST(ut_setup, ut_teardown,
9232                         test_AES_CCM_authenticated_decryption_test_case_256_1),
9233                 TEST_CASE_ST(ut_setup, ut_teardown,
9234                         test_AES_CCM_authenticated_decryption_test_case_256_2),
9235                 TEST_CASE_ST(ut_setup, ut_teardown,
9236                         test_AES_CCM_authenticated_decryption_test_case_256_3),
9237
9238                 /** Scatter-Gather */
9239                 TEST_CASE_ST(ut_setup, ut_teardown,
9240                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9241
9242                 /** Negative tests */
9243                 TEST_CASE_ST(ut_setup, ut_teardown,
9244                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9245                 TEST_CASE_ST(ut_setup, ut_teardown,
9246                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9247                 TEST_CASE_ST(ut_setup, ut_teardown,
9248                         authentication_verify_AES128_GMAC_fail_data_corrupt),
9249                 TEST_CASE_ST(ut_setup, ut_teardown,
9250                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
9251                 TEST_CASE_ST(ut_setup, ut_teardown,
9252                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9253                 TEST_CASE_ST(ut_setup, ut_teardown,
9254                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9255
9256                 TEST_CASES_END() /**< NULL terminate unit test array */
9257         }
9258 };
9259
9260 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
9261         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
9262         .setup = testsuite_setup,
9263         .teardown = testsuite_teardown,
9264         .unit_test_cases = {
9265                 /** AES GCM Authenticated Encryption */
9266                 TEST_CASE_ST(ut_setup, ut_teardown,
9267                         test_AES_GCM_authenticated_encryption_test_case_1),
9268                 TEST_CASE_ST(ut_setup, ut_teardown,
9269                         test_AES_GCM_authenticated_encryption_test_case_2),
9270                 TEST_CASE_ST(ut_setup, ut_teardown,
9271                         test_AES_GCM_authenticated_encryption_test_case_3),
9272                 TEST_CASE_ST(ut_setup, ut_teardown,
9273                         test_AES_GCM_authenticated_encryption_test_case_4),
9274                 TEST_CASE_ST(ut_setup, ut_teardown,
9275                         test_AES_GCM_authenticated_encryption_test_case_5),
9276                 TEST_CASE_ST(ut_setup, ut_teardown,
9277                         test_AES_GCM_authenticated_encryption_test_case_6),
9278                 TEST_CASE_ST(ut_setup, ut_teardown,
9279                         test_AES_GCM_authenticated_encryption_test_case_7),
9280
9281                 /** AES GCM Authenticated Decryption */
9282                 TEST_CASE_ST(ut_setup, ut_teardown,
9283                         test_AES_GCM_authenticated_decryption_test_case_1),
9284                 TEST_CASE_ST(ut_setup, ut_teardown,
9285                         test_AES_GCM_authenticated_decryption_test_case_2),
9286                 TEST_CASE_ST(ut_setup, ut_teardown,
9287                         test_AES_GCM_authenticated_decryption_test_case_3),
9288                 TEST_CASE_ST(ut_setup, ut_teardown,
9289                         test_AES_GCM_authenticated_decryption_test_case_4),
9290                 TEST_CASE_ST(ut_setup, ut_teardown,
9291                         test_AES_GCM_authenticated_decryption_test_case_5),
9292                 TEST_CASE_ST(ut_setup, ut_teardown,
9293                         test_AES_GCM_authenticated_decryption_test_case_6),
9294                 TEST_CASE_ST(ut_setup, ut_teardown,
9295                         test_AES_GCM_authenticated_decryption_test_case_7),
9296
9297                 /** AES GCM Authenticated Encryption 192 bits key */
9298                 TEST_CASE_ST(ut_setup, ut_teardown,
9299                         test_AES_GCM_auth_encryption_test_case_192_1),
9300                 TEST_CASE_ST(ut_setup, ut_teardown,
9301                         test_AES_GCM_auth_encryption_test_case_192_2),
9302                 TEST_CASE_ST(ut_setup, ut_teardown,
9303                         test_AES_GCM_auth_encryption_test_case_192_3),
9304                 TEST_CASE_ST(ut_setup, ut_teardown,
9305                         test_AES_GCM_auth_encryption_test_case_192_4),
9306                 TEST_CASE_ST(ut_setup, ut_teardown,
9307                         test_AES_GCM_auth_encryption_test_case_192_5),
9308                 TEST_CASE_ST(ut_setup, ut_teardown,
9309                         test_AES_GCM_auth_encryption_test_case_192_6),
9310                 TEST_CASE_ST(ut_setup, ut_teardown,
9311                         test_AES_GCM_auth_encryption_test_case_192_7),
9312
9313                 /** AES GCM Authenticated Decryption 192 bits key */
9314                 TEST_CASE_ST(ut_setup, ut_teardown,
9315                         test_AES_GCM_auth_decryption_test_case_192_1),
9316                 TEST_CASE_ST(ut_setup, ut_teardown,
9317                         test_AES_GCM_auth_decryption_test_case_192_2),
9318                 TEST_CASE_ST(ut_setup, ut_teardown,
9319                         test_AES_GCM_auth_decryption_test_case_192_3),
9320                 TEST_CASE_ST(ut_setup, ut_teardown,
9321                         test_AES_GCM_auth_decryption_test_case_192_4),
9322                 TEST_CASE_ST(ut_setup, ut_teardown,
9323                         test_AES_GCM_auth_decryption_test_case_192_5),
9324                 TEST_CASE_ST(ut_setup, ut_teardown,
9325                         test_AES_GCM_auth_decryption_test_case_192_6),
9326                 TEST_CASE_ST(ut_setup, ut_teardown,
9327                         test_AES_GCM_auth_decryption_test_case_192_7),
9328
9329                 /** AES GCM Authenticated Encryption 256 bits key */
9330                 TEST_CASE_ST(ut_setup, ut_teardown,
9331                         test_AES_GCM_auth_encryption_test_case_256_1),
9332                 TEST_CASE_ST(ut_setup, ut_teardown,
9333                         test_AES_GCM_auth_encryption_test_case_256_2),
9334                 TEST_CASE_ST(ut_setup, ut_teardown,
9335                         test_AES_GCM_auth_encryption_test_case_256_3),
9336                 TEST_CASE_ST(ut_setup, ut_teardown,
9337                         test_AES_GCM_auth_encryption_test_case_256_4),
9338                 TEST_CASE_ST(ut_setup, ut_teardown,
9339                         test_AES_GCM_auth_encryption_test_case_256_5),
9340                 TEST_CASE_ST(ut_setup, ut_teardown,
9341                         test_AES_GCM_auth_encryption_test_case_256_6),
9342                 TEST_CASE_ST(ut_setup, ut_teardown,
9343                         test_AES_GCM_auth_encryption_test_case_256_7),
9344
9345                 /** AES GCM Authenticated Decryption 256 bits key */
9346                 TEST_CASE_ST(ut_setup, ut_teardown,
9347                         test_AES_GCM_auth_decryption_test_case_256_1),
9348                 TEST_CASE_ST(ut_setup, ut_teardown,
9349                         test_AES_GCM_auth_decryption_test_case_256_2),
9350                 TEST_CASE_ST(ut_setup, ut_teardown,
9351                         test_AES_GCM_auth_decryption_test_case_256_3),
9352                 TEST_CASE_ST(ut_setup, ut_teardown,
9353                         test_AES_GCM_auth_decryption_test_case_256_4),
9354                 TEST_CASE_ST(ut_setup, ut_teardown,
9355                         test_AES_GCM_auth_decryption_test_case_256_5),
9356                 TEST_CASE_ST(ut_setup, ut_teardown,
9357                         test_AES_GCM_auth_decryption_test_case_256_6),
9358                 TEST_CASE_ST(ut_setup, ut_teardown,
9359                         test_AES_GCM_auth_decryption_test_case_256_7),
9360
9361                 /** AES GCM Authenticated Encryption big aad size */
9362                 TEST_CASE_ST(ut_setup, ut_teardown,
9363                         test_AES_GCM_auth_encryption_test_case_aad_1),
9364                 TEST_CASE_ST(ut_setup, ut_teardown,
9365                         test_AES_GCM_auth_encryption_test_case_aad_2),
9366
9367                 /** AES GCM Authenticated Decryption big aad size */
9368                 TEST_CASE_ST(ut_setup, ut_teardown,
9369                         test_AES_GCM_auth_decryption_test_case_aad_1),
9370                 TEST_CASE_ST(ut_setup, ut_teardown,
9371                         test_AES_GCM_auth_decryption_test_case_aad_2),
9372
9373                 /** AES GMAC Authentication */
9374                 TEST_CASE_ST(ut_setup, ut_teardown,
9375                         test_AES_GMAC_authentication_test_case_1),
9376                 TEST_CASE_ST(ut_setup, ut_teardown,
9377                         test_AES_GMAC_authentication_verify_test_case_1),
9378                 TEST_CASE_ST(ut_setup, ut_teardown,
9379                         test_AES_GMAC_authentication_test_case_3),
9380                 TEST_CASE_ST(ut_setup, ut_teardown,
9381                         test_AES_GMAC_authentication_verify_test_case_3),
9382                 TEST_CASE_ST(ut_setup, ut_teardown,
9383                         test_AES_GMAC_authentication_test_case_4),
9384                 TEST_CASE_ST(ut_setup, ut_teardown,
9385                         test_AES_GMAC_authentication_verify_test_case_4),
9386
9387                 /** Negative tests */
9388                 TEST_CASE_ST(ut_setup, ut_teardown,
9389                         authentication_verify_AES128_GMAC_fail_data_corrupt),
9390                 TEST_CASE_ST(ut_setup, ut_teardown,
9391                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
9392
9393                 /** Out of place tests */
9394                 TEST_CASE_ST(ut_setup, ut_teardown,
9395                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9396                 TEST_CASE_ST(ut_setup, ut_teardown,
9397                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9398
9399                 /** Session-less tests */
9400                 TEST_CASE_ST(ut_setup, ut_teardown,
9401                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
9402                 TEST_CASE_ST(ut_setup, ut_teardown,
9403                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
9404
9405                 /** Scatter-Gather */
9406                 TEST_CASE_ST(ut_setup, ut_teardown,
9407                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9408
9409                 TEST_CASES_END() /**< NULL terminate unit test array */
9410         }
9411 };
9412
9413 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
9414         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
9415         .setup = testsuite_setup,
9416         .teardown = testsuite_teardown,
9417         .unit_test_cases = {
9418                 /** KASUMI encrypt only (UEA1) */
9419                 TEST_CASE_ST(ut_setup, ut_teardown,
9420                         test_kasumi_encryption_test_case_1),
9421                 TEST_CASE_ST(ut_setup, ut_teardown,
9422                         test_kasumi_encryption_test_case_1_sgl),
9423                 TEST_CASE_ST(ut_setup, ut_teardown,
9424                         test_kasumi_encryption_test_case_2),
9425                 TEST_CASE_ST(ut_setup, ut_teardown,
9426                         test_kasumi_encryption_test_case_3),
9427                 TEST_CASE_ST(ut_setup, ut_teardown,
9428                         test_kasumi_encryption_test_case_4),
9429                 TEST_CASE_ST(ut_setup, ut_teardown,
9430                         test_kasumi_encryption_test_case_5),
9431                 /** KASUMI decrypt only (UEA1) */
9432                 TEST_CASE_ST(ut_setup, ut_teardown,
9433                         test_kasumi_decryption_test_case_1),
9434                 TEST_CASE_ST(ut_setup, ut_teardown,
9435                         test_kasumi_decryption_test_case_2),
9436                 TEST_CASE_ST(ut_setup, ut_teardown,
9437                         test_kasumi_decryption_test_case_3),
9438                 TEST_CASE_ST(ut_setup, ut_teardown,
9439                         test_kasumi_decryption_test_case_4),
9440                 TEST_CASE_ST(ut_setup, ut_teardown,
9441                         test_kasumi_decryption_test_case_5),
9442
9443                 TEST_CASE_ST(ut_setup, ut_teardown,
9444                         test_kasumi_encryption_test_case_1_oop),
9445                 TEST_CASE_ST(ut_setup, ut_teardown,
9446                         test_kasumi_encryption_test_case_1_oop_sgl),
9447
9448
9449                 TEST_CASE_ST(ut_setup, ut_teardown,
9450                         test_kasumi_decryption_test_case_1_oop),
9451
9452                 /** KASUMI hash only (UIA1) */
9453                 TEST_CASE_ST(ut_setup, ut_teardown,
9454                         test_kasumi_hash_generate_test_case_1),
9455                 TEST_CASE_ST(ut_setup, ut_teardown,
9456                         test_kasumi_hash_generate_test_case_2),
9457                 TEST_CASE_ST(ut_setup, ut_teardown,
9458                         test_kasumi_hash_generate_test_case_3),
9459                 TEST_CASE_ST(ut_setup, ut_teardown,
9460                         test_kasumi_hash_generate_test_case_4),
9461                 TEST_CASE_ST(ut_setup, ut_teardown,
9462                         test_kasumi_hash_generate_test_case_5),
9463                 TEST_CASE_ST(ut_setup, ut_teardown,
9464                         test_kasumi_hash_generate_test_case_6),
9465                 TEST_CASE_ST(ut_setup, ut_teardown,
9466                         test_kasumi_hash_verify_test_case_1),
9467                 TEST_CASE_ST(ut_setup, ut_teardown,
9468                         test_kasumi_hash_verify_test_case_2),
9469                 TEST_CASE_ST(ut_setup, ut_teardown,
9470                         test_kasumi_hash_verify_test_case_3),
9471                 TEST_CASE_ST(ut_setup, ut_teardown,
9472                         test_kasumi_hash_verify_test_case_4),
9473                 TEST_CASE_ST(ut_setup, ut_teardown,
9474                         test_kasumi_hash_verify_test_case_5),
9475                 TEST_CASE_ST(ut_setup, ut_teardown,
9476                         test_kasumi_auth_cipher_test_case_1),
9477                 TEST_CASE_ST(ut_setup, ut_teardown,
9478                         test_kasumi_cipher_auth_test_case_1),
9479                 TEST_CASES_END() /**< NULL terminate unit test array */
9480         }
9481 };
9482 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
9483         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
9484         .setup = testsuite_setup,
9485         .teardown = testsuite_teardown,
9486         .unit_test_cases = {
9487                 /** SNOW 3G encrypt only (UEA2) */
9488                 TEST_CASE_ST(ut_setup, ut_teardown,
9489                         test_snow3g_encryption_test_case_1),
9490                 TEST_CASE_ST(ut_setup, ut_teardown,
9491                         test_snow3g_encryption_test_case_2),
9492                 TEST_CASE_ST(ut_setup, ut_teardown,
9493                         test_snow3g_encryption_test_case_3),
9494                 TEST_CASE_ST(ut_setup, ut_teardown,
9495                         test_snow3g_encryption_test_case_4),
9496                 TEST_CASE_ST(ut_setup, ut_teardown,
9497                         test_snow3g_encryption_test_case_5),
9498
9499                 TEST_CASE_ST(ut_setup, ut_teardown,
9500                         test_snow3g_encryption_test_case_1_oop),
9501                 TEST_CASE_ST(ut_setup, ut_teardown,
9502                                 test_snow3g_encryption_test_case_1_oop_sgl),
9503                 TEST_CASE_ST(ut_setup, ut_teardown,
9504                         test_snow3g_decryption_test_case_1_oop),
9505
9506                 TEST_CASE_ST(ut_setup, ut_teardown,
9507                         test_snow3g_encryption_test_case_1_offset_oop),
9508
9509                 /** SNOW 3G decrypt only (UEA2) */
9510                 TEST_CASE_ST(ut_setup, ut_teardown,
9511                         test_snow3g_decryption_test_case_1),
9512                 TEST_CASE_ST(ut_setup, ut_teardown,
9513                         test_snow3g_decryption_test_case_2),
9514                 TEST_CASE_ST(ut_setup, ut_teardown,
9515                         test_snow3g_decryption_test_case_3),
9516                 TEST_CASE_ST(ut_setup, ut_teardown,
9517                         test_snow3g_decryption_test_case_4),
9518                 TEST_CASE_ST(ut_setup, ut_teardown,
9519                         test_snow3g_decryption_test_case_5),
9520                 TEST_CASE_ST(ut_setup, ut_teardown,
9521                         test_snow3g_hash_generate_test_case_1),
9522                 TEST_CASE_ST(ut_setup, ut_teardown,
9523                         test_snow3g_hash_generate_test_case_2),
9524                 TEST_CASE_ST(ut_setup, ut_teardown,
9525                         test_snow3g_hash_generate_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_generate_test_case_4),
9529                 TEST_CASE_ST(ut_setup, ut_teardown,
9530                         test_snow3g_hash_generate_test_case_5),
9531                 TEST_CASE_ST(ut_setup, ut_teardown,
9532                         test_snow3g_hash_generate_test_case_6),
9533                 TEST_CASE_ST(ut_setup, ut_teardown,
9534                         test_snow3g_hash_verify_test_case_1),
9535                 TEST_CASE_ST(ut_setup, ut_teardown,
9536                         test_snow3g_hash_verify_test_case_2),
9537                 TEST_CASE_ST(ut_setup, ut_teardown,
9538                         test_snow3g_hash_verify_test_case_3),
9539                 /* Tests with buffers which length is not byte-aligned */
9540                 TEST_CASE_ST(ut_setup, ut_teardown,
9541                         test_snow3g_hash_verify_test_case_4),
9542                 TEST_CASE_ST(ut_setup, ut_teardown,
9543                         test_snow3g_hash_verify_test_case_5),
9544                 TEST_CASE_ST(ut_setup, ut_teardown,
9545                         test_snow3g_hash_verify_test_case_6),
9546                 TEST_CASE_ST(ut_setup, ut_teardown,
9547                         test_snow3g_cipher_auth_test_case_1),
9548                 TEST_CASE_ST(ut_setup, ut_teardown,
9549                         test_snow3g_auth_cipher_test_case_1),
9550
9551                 TEST_CASES_END() /**< NULL terminate unit test array */
9552         }
9553 };
9554
9555 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
9556         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
9557         .setup = testsuite_setup,
9558         .teardown = testsuite_teardown,
9559         .unit_test_cases = {
9560                 /** ZUC encrypt only (EEA3) */
9561                 TEST_CASE_ST(ut_setup, ut_teardown,
9562                         test_zuc_encryption_test_case_1),
9563                 TEST_CASE_ST(ut_setup, ut_teardown,
9564                         test_zuc_encryption_test_case_2),
9565                 TEST_CASE_ST(ut_setup, ut_teardown,
9566                         test_zuc_encryption_test_case_3),
9567                 TEST_CASE_ST(ut_setup, ut_teardown,
9568                         test_zuc_encryption_test_case_4),
9569                 TEST_CASE_ST(ut_setup, ut_teardown,
9570                         test_zuc_encryption_test_case_5),
9571                 TEST_CASE_ST(ut_setup, ut_teardown,
9572                         test_zuc_hash_generate_test_case_1),
9573                 TEST_CASE_ST(ut_setup, ut_teardown,
9574                         test_zuc_hash_generate_test_case_2),
9575                 TEST_CASE_ST(ut_setup, ut_teardown,
9576                         test_zuc_hash_generate_test_case_3),
9577                 TEST_CASE_ST(ut_setup, ut_teardown,
9578                         test_zuc_hash_generate_test_case_4),
9579                 TEST_CASE_ST(ut_setup, ut_teardown,
9580                         test_zuc_hash_generate_test_case_5),
9581                 TEST_CASE_ST(ut_setup, ut_teardown,
9582                         test_zuc_encryption_test_case_6_sgl),
9583                 TEST_CASES_END() /**< NULL terminate unit test array */
9584         }
9585 };
9586
9587 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
9588         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
9589         .setup = testsuite_setup,
9590         .teardown = testsuite_teardown,
9591         .unit_test_cases = {
9592                 TEST_CASE_ST(ut_setup, ut_teardown,
9593                              test_device_configure_invalid_dev_id),
9594                 TEST_CASE_ST(ut_setup, ut_teardown,
9595                              test_multi_session),
9596
9597                 TEST_CASE_ST(ut_setup, ut_teardown,
9598                              test_AES_chain_dpaa_sec_all),
9599                 TEST_CASE_ST(ut_setup, ut_teardown,
9600                              test_3DES_chain_dpaa_sec_all),
9601                 TEST_CASE_ST(ut_setup, ut_teardown,
9602                              test_AES_cipheronly_dpaa_sec_all),
9603                 TEST_CASE_ST(ut_setup, ut_teardown,
9604                              test_3DES_cipheronly_dpaa_sec_all),
9605                 TEST_CASE_ST(ut_setup, ut_teardown,
9606                              test_authonly_dpaa_sec_all),
9607
9608                 /** AES GCM Authenticated Encryption */
9609                 TEST_CASE_ST(ut_setup, ut_teardown,
9610                         test_AES_GCM_authenticated_encryption_test_case_1),
9611                 TEST_CASE_ST(ut_setup, ut_teardown,
9612                         test_AES_GCM_authenticated_encryption_test_case_2),
9613                 TEST_CASE_ST(ut_setup, ut_teardown,
9614                         test_AES_GCM_authenticated_encryption_test_case_3),
9615                 TEST_CASE_ST(ut_setup, ut_teardown,
9616                         test_AES_GCM_authenticated_encryption_test_case_4),
9617                 TEST_CASE_ST(ut_setup, ut_teardown,
9618                         test_AES_GCM_authenticated_encryption_test_case_5),
9619                 TEST_CASE_ST(ut_setup, ut_teardown,
9620                         test_AES_GCM_authenticated_encryption_test_case_6),
9621                 TEST_CASE_ST(ut_setup, ut_teardown,
9622                         test_AES_GCM_authenticated_encryption_test_case_7),
9623
9624                 /** AES GCM Authenticated Decryption */
9625                 TEST_CASE_ST(ut_setup, ut_teardown,
9626                         test_AES_GCM_authenticated_decryption_test_case_1),
9627                 TEST_CASE_ST(ut_setup, ut_teardown,
9628                         test_AES_GCM_authenticated_decryption_test_case_2),
9629                 TEST_CASE_ST(ut_setup, ut_teardown,
9630                         test_AES_GCM_authenticated_decryption_test_case_3),
9631                 TEST_CASE_ST(ut_setup, ut_teardown,
9632                         test_AES_GCM_authenticated_decryption_test_case_4),
9633                 TEST_CASE_ST(ut_setup, ut_teardown,
9634                         test_AES_GCM_authenticated_decryption_test_case_5),
9635                 TEST_CASE_ST(ut_setup, ut_teardown,
9636                         test_AES_GCM_authenticated_decryption_test_case_6),
9637                 TEST_CASE_ST(ut_setup, ut_teardown,
9638                         test_AES_GCM_authenticated_decryption_test_case_7),
9639
9640                 /** AES GCM Authenticated Encryption 256 bits key */
9641                 TEST_CASE_ST(ut_setup, ut_teardown,
9642                         test_AES_GCM_auth_encryption_test_case_256_1),
9643                 TEST_CASE_ST(ut_setup, ut_teardown,
9644                         test_AES_GCM_auth_encryption_test_case_256_2),
9645                 TEST_CASE_ST(ut_setup, ut_teardown,
9646                         test_AES_GCM_auth_encryption_test_case_256_3),
9647                 TEST_CASE_ST(ut_setup, ut_teardown,
9648                         test_AES_GCM_auth_encryption_test_case_256_4),
9649                 TEST_CASE_ST(ut_setup, ut_teardown,
9650                         test_AES_GCM_auth_encryption_test_case_256_5),
9651                 TEST_CASE_ST(ut_setup, ut_teardown,
9652                         test_AES_GCM_auth_encryption_test_case_256_6),
9653                 TEST_CASE_ST(ut_setup, ut_teardown,
9654                         test_AES_GCM_auth_encryption_test_case_256_7),
9655
9656                 /** AES GCM Authenticated Decryption 256 bits key */
9657                 TEST_CASE_ST(ut_setup, ut_teardown,
9658                         test_AES_GCM_auth_decryption_test_case_256_1),
9659                 TEST_CASE_ST(ut_setup, ut_teardown,
9660                         test_AES_GCM_auth_decryption_test_case_256_2),
9661                 TEST_CASE_ST(ut_setup, ut_teardown,
9662                         test_AES_GCM_auth_decryption_test_case_256_3),
9663                 TEST_CASE_ST(ut_setup, ut_teardown,
9664                         test_AES_GCM_auth_decryption_test_case_256_4),
9665                 TEST_CASE_ST(ut_setup, ut_teardown,
9666                         test_AES_GCM_auth_decryption_test_case_256_5),
9667                 TEST_CASE_ST(ut_setup, ut_teardown,
9668                         test_AES_GCM_auth_decryption_test_case_256_6),
9669                 TEST_CASE_ST(ut_setup, ut_teardown,
9670                         test_AES_GCM_auth_decryption_test_case_256_7),
9671
9672                 /** Out of place tests */
9673                 TEST_CASE_ST(ut_setup, ut_teardown,
9674                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9675                 TEST_CASE_ST(ut_setup, ut_teardown,
9676                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9677
9678                 /** Scatter-Gather */
9679                 TEST_CASE_ST(ut_setup, ut_teardown,
9680                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
9681                 TEST_CASE_ST(ut_setup, ut_teardown,
9682                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
9683                 TEST_CASE_ST(ut_setup, ut_teardown,
9684                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9685                 TEST_CASE_ST(ut_setup, ut_teardown,
9686                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
9687
9688                 TEST_CASES_END() /**< NULL terminate unit test array */
9689         }
9690 };
9691
9692 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
9693         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
9694         .setup = testsuite_setup,
9695         .teardown = testsuite_teardown,
9696         .unit_test_cases = {
9697                 TEST_CASE_ST(ut_setup, ut_teardown,
9698                         test_device_configure_invalid_dev_id),
9699                 TEST_CASE_ST(ut_setup, ut_teardown,
9700                         test_multi_session),
9701
9702                 TEST_CASE_ST(ut_setup, ut_teardown,
9703                         test_AES_chain_dpaa2_sec_all),
9704                 TEST_CASE_ST(ut_setup, ut_teardown,
9705                         test_3DES_chain_dpaa2_sec_all),
9706                 TEST_CASE_ST(ut_setup, ut_teardown,
9707                         test_AES_cipheronly_dpaa2_sec_all),
9708                 TEST_CASE_ST(ut_setup, ut_teardown,
9709                         test_3DES_cipheronly_dpaa2_sec_all),
9710                 TEST_CASE_ST(ut_setup, ut_teardown,
9711                         test_authonly_dpaa2_sec_all),
9712
9713                 /** AES GCM Authenticated Encryption */
9714                 TEST_CASE_ST(ut_setup, ut_teardown,
9715                         test_AES_GCM_authenticated_encryption_test_case_1),
9716                 TEST_CASE_ST(ut_setup, ut_teardown,
9717                         test_AES_GCM_authenticated_encryption_test_case_2),
9718                 TEST_CASE_ST(ut_setup, ut_teardown,
9719                         test_AES_GCM_authenticated_encryption_test_case_3),
9720                 TEST_CASE_ST(ut_setup, ut_teardown,
9721                         test_AES_GCM_authenticated_encryption_test_case_4),
9722                 TEST_CASE_ST(ut_setup, ut_teardown,
9723                         test_AES_GCM_authenticated_encryption_test_case_5),
9724                 TEST_CASE_ST(ut_setup, ut_teardown,
9725                         test_AES_GCM_authenticated_encryption_test_case_6),
9726                 TEST_CASE_ST(ut_setup, ut_teardown,
9727                         test_AES_GCM_authenticated_encryption_test_case_7),
9728
9729                 /** AES GCM Authenticated Decryption */
9730                 TEST_CASE_ST(ut_setup, ut_teardown,
9731                         test_AES_GCM_authenticated_decryption_test_case_1),
9732                 TEST_CASE_ST(ut_setup, ut_teardown,
9733                         test_AES_GCM_authenticated_decryption_test_case_2),
9734                 TEST_CASE_ST(ut_setup, ut_teardown,
9735                         test_AES_GCM_authenticated_decryption_test_case_3),
9736                 TEST_CASE_ST(ut_setup, ut_teardown,
9737                         test_AES_GCM_authenticated_decryption_test_case_4),
9738                 TEST_CASE_ST(ut_setup, ut_teardown,
9739                         test_AES_GCM_authenticated_decryption_test_case_5),
9740                 TEST_CASE_ST(ut_setup, ut_teardown,
9741                         test_AES_GCM_authenticated_decryption_test_case_6),
9742                 TEST_CASE_ST(ut_setup, ut_teardown,
9743                         test_AES_GCM_authenticated_decryption_test_case_7),
9744
9745                 /** AES GCM Authenticated Encryption 192 bits key */
9746                 TEST_CASE_ST(ut_setup, ut_teardown,
9747                         test_AES_GCM_auth_encryption_test_case_192_1),
9748                 TEST_CASE_ST(ut_setup, ut_teardown,
9749                         test_AES_GCM_auth_encryption_test_case_192_2),
9750                 TEST_CASE_ST(ut_setup, ut_teardown,
9751                         test_AES_GCM_auth_encryption_test_case_192_3),
9752                 TEST_CASE_ST(ut_setup, ut_teardown,
9753                         test_AES_GCM_auth_encryption_test_case_192_4),
9754                 TEST_CASE_ST(ut_setup, ut_teardown,
9755                         test_AES_GCM_auth_encryption_test_case_192_5),
9756                 TEST_CASE_ST(ut_setup, ut_teardown,
9757                         test_AES_GCM_auth_encryption_test_case_192_6),
9758                 TEST_CASE_ST(ut_setup, ut_teardown,
9759                         test_AES_GCM_auth_encryption_test_case_192_7),
9760
9761                 /** AES GCM Authenticated Decryption 192 bits key */
9762                 TEST_CASE_ST(ut_setup, ut_teardown,
9763                         test_AES_GCM_auth_decryption_test_case_192_1),
9764                 TEST_CASE_ST(ut_setup, ut_teardown,
9765                         test_AES_GCM_auth_decryption_test_case_192_2),
9766                 TEST_CASE_ST(ut_setup, ut_teardown,
9767                         test_AES_GCM_auth_decryption_test_case_192_3),
9768                 TEST_CASE_ST(ut_setup, ut_teardown,
9769                         test_AES_GCM_auth_decryption_test_case_192_4),
9770                 TEST_CASE_ST(ut_setup, ut_teardown,
9771                         test_AES_GCM_auth_decryption_test_case_192_5),
9772                 TEST_CASE_ST(ut_setup, ut_teardown,
9773                         test_AES_GCM_auth_decryption_test_case_192_6),
9774                 TEST_CASE_ST(ut_setup, ut_teardown,
9775                         test_AES_GCM_auth_decryption_test_case_192_7),
9776
9777                 /** AES GCM Authenticated Encryption 256 bits key */
9778                 TEST_CASE_ST(ut_setup, ut_teardown,
9779                         test_AES_GCM_auth_encryption_test_case_256_1),
9780                 TEST_CASE_ST(ut_setup, ut_teardown,
9781                         test_AES_GCM_auth_encryption_test_case_256_2),
9782                 TEST_CASE_ST(ut_setup, ut_teardown,
9783                         test_AES_GCM_auth_encryption_test_case_256_3),
9784                 TEST_CASE_ST(ut_setup, ut_teardown,
9785                         test_AES_GCM_auth_encryption_test_case_256_4),
9786                 TEST_CASE_ST(ut_setup, ut_teardown,
9787                         test_AES_GCM_auth_encryption_test_case_256_5),
9788                 TEST_CASE_ST(ut_setup, ut_teardown,
9789                         test_AES_GCM_auth_encryption_test_case_256_6),
9790                 TEST_CASE_ST(ut_setup, ut_teardown,
9791                         test_AES_GCM_auth_encryption_test_case_256_7),
9792
9793                 /** AES GCM Authenticated Decryption 256 bits key */
9794                 TEST_CASE_ST(ut_setup, ut_teardown,
9795                         test_AES_GCM_auth_decryption_test_case_256_1),
9796                 TEST_CASE_ST(ut_setup, ut_teardown,
9797                         test_AES_GCM_auth_decryption_test_case_256_2),
9798                 TEST_CASE_ST(ut_setup, ut_teardown,
9799                         test_AES_GCM_auth_decryption_test_case_256_3),
9800                 TEST_CASE_ST(ut_setup, ut_teardown,
9801                         test_AES_GCM_auth_decryption_test_case_256_4),
9802                 TEST_CASE_ST(ut_setup, ut_teardown,
9803                         test_AES_GCM_auth_decryption_test_case_256_5),
9804                 TEST_CASE_ST(ut_setup, ut_teardown,
9805                         test_AES_GCM_auth_decryption_test_case_256_6),
9806                 TEST_CASE_ST(ut_setup, ut_teardown,
9807                         test_AES_GCM_auth_decryption_test_case_256_7),
9808
9809                 /** Out of place tests */
9810                 TEST_CASE_ST(ut_setup, ut_teardown,
9811                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9812                 TEST_CASE_ST(ut_setup, ut_teardown,
9813                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9814
9815                 /** Scatter-Gather */
9816                 TEST_CASE_ST(ut_setup, ut_teardown,
9817                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
9818                 TEST_CASE_ST(ut_setup, ut_teardown,
9819                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
9820                 TEST_CASE_ST(ut_setup, ut_teardown,
9821                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9822                 TEST_CASE_ST(ut_setup, ut_teardown,
9823                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
9824
9825                 TEST_CASES_END() /**< NULL terminate unit test array */
9826         }
9827 };
9828
9829 static struct unit_test_suite cryptodev_null_testsuite  = {
9830         .suite_name = "Crypto Device NULL Unit Test Suite",
9831         .setup = testsuite_setup,
9832         .teardown = testsuite_teardown,
9833         .unit_test_cases = {
9834                 TEST_CASE_ST(ut_setup, ut_teardown,
9835                         test_null_auth_only_operation),
9836                 TEST_CASE_ST(ut_setup, ut_teardown,
9837                         test_null_cipher_only_operation),
9838                 TEST_CASE_ST(ut_setup, ut_teardown,
9839                         test_null_cipher_auth_operation),
9840                 TEST_CASE_ST(ut_setup, ut_teardown,
9841                         test_null_auth_cipher_operation),
9842                 TEST_CASE_ST(ut_setup, ut_teardown,
9843                         test_null_invalid_operation),
9844                 TEST_CASE_ST(ut_setup, ut_teardown,
9845                         test_null_burst_operation),
9846
9847                 TEST_CASES_END() /**< NULL terminate unit test array */
9848         }
9849 };
9850
9851 static struct unit_test_suite cryptodev_armv8_testsuite  = {
9852         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
9853         .setup = testsuite_setup,
9854         .teardown = testsuite_teardown,
9855         .unit_test_cases = {
9856                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
9857
9858                 /** Negative tests */
9859                 TEST_CASE_ST(ut_setup, ut_teardown,
9860                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9861                 TEST_CASE_ST(ut_setup, ut_teardown,
9862                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9863
9864                 TEST_CASES_END() /**< NULL terminate unit test array */
9865         }
9866 };
9867
9868 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
9869         .suite_name = "Crypto Device Marvell Component Test Suite",
9870         .setup = testsuite_setup,
9871         .teardown = testsuite_teardown,
9872         .unit_test_cases = {
9873                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
9874                 TEST_CASE_ST(ut_setup, ut_teardown,
9875                                 test_multi_session_random_usage),
9876                 TEST_CASE_ST(ut_setup, ut_teardown,
9877                                 test_AES_chain_mrvl_all),
9878                 TEST_CASE_ST(ut_setup, ut_teardown,
9879                                 test_AES_cipheronly_mrvl_all),
9880                 TEST_CASE_ST(ut_setup, ut_teardown,
9881                                 test_authonly_mrvl_all),
9882                 TEST_CASE_ST(ut_setup, ut_teardown,
9883                                 test_3DES_chain_mrvl_all),
9884                 TEST_CASE_ST(ut_setup, ut_teardown,
9885                                 test_3DES_cipheronly_mrvl_all),
9886
9887                 /** Negative tests */
9888                 TEST_CASE_ST(ut_setup, ut_teardown,
9889                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9890                 TEST_CASE_ST(ut_setup, ut_teardown,
9891                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9892                 TEST_CASE_ST(ut_setup, ut_teardown,
9893                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9894                 TEST_CASE_ST(ut_setup, ut_teardown,
9895                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9896
9897                 TEST_CASES_END() /**< NULL terminate unit test array */
9898         }
9899 };
9900
9901 static struct unit_test_suite cryptodev_ccp_testsuite  = {
9902         .suite_name = "Crypto Device CCP Unit Test Suite",
9903         .setup = testsuite_setup,
9904         .teardown = testsuite_teardown,
9905         .unit_test_cases = {
9906                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
9907                 TEST_CASE_ST(ut_setup, ut_teardown,
9908                                 test_multi_session_random_usage),
9909                 TEST_CASE_ST(ut_setup, ut_teardown,
9910                                 test_AES_chain_ccp_all),
9911                 TEST_CASE_ST(ut_setup, ut_teardown,
9912                                 test_AES_cipheronly_ccp_all),
9913                 TEST_CASE_ST(ut_setup, ut_teardown,
9914                                 test_3DES_chain_ccp_all),
9915                 TEST_CASE_ST(ut_setup, ut_teardown,
9916                                 test_3DES_cipheronly_ccp_all),
9917                 TEST_CASE_ST(ut_setup, ut_teardown,
9918                                 test_authonly_ccp_all),
9919
9920                 /** Negative tests */
9921                 TEST_CASE_ST(ut_setup, ut_teardown,
9922                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9923                 TEST_CASE_ST(ut_setup, ut_teardown,
9924                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9925                 TEST_CASE_ST(ut_setup, ut_teardown,
9926                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9927                 TEST_CASE_ST(ut_setup, ut_teardown,
9928                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9929
9930                 TEST_CASES_END() /**< NULL terminate unit test array */
9931         }
9932 };
9933
9934 static int
9935 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
9936 {
9937         gbl_driver_id = rte_cryptodev_driver_id_get(
9938                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
9939
9940         if (gbl_driver_id == -1) {
9941                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
9942                                 "CONFIG_RTE_LIBRTE_PMD_QAT is enabled "
9943                                 "in config file to run this testsuite.\n");
9944                 return TEST_SKIPPED;
9945         }
9946
9947         return unit_test_suite_runner(&cryptodev_qat_testsuite);
9948 }
9949
9950 static int
9951 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
9952 {
9953         gbl_driver_id = rte_cryptodev_driver_id_get(
9954                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
9955
9956         if (gbl_driver_id == -1) {
9957                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
9958                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
9959                                 "in config file to run this testsuite.\n");
9960                 return TEST_FAILED;
9961         }
9962
9963         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
9964 }
9965
9966 static int
9967 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
9968 {
9969         gbl_driver_id = rte_cryptodev_driver_id_get(
9970                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
9971
9972         if (gbl_driver_id == -1) {
9973                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
9974                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
9975                                 "in config file to run this testsuite.\n");
9976                 return TEST_SKIPPED;
9977         }
9978
9979         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
9980 }
9981
9982 static int
9983 test_cryptodev_openssl(void)
9984 {
9985         gbl_driver_id = rte_cryptodev_driver_id_get(
9986                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
9987
9988         if (gbl_driver_id == -1) {
9989                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
9990                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
9991                                 "in config file to run this testsuite.\n");
9992                 return TEST_SKIPPED;
9993         }
9994
9995         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
9996 }
9997
9998 static int
9999 test_cryptodev_aesni_gcm(void)
10000 {
10001         gbl_driver_id = rte_cryptodev_driver_id_get(
10002                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
10003
10004         if (gbl_driver_id == -1) {
10005                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
10006                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
10007                                 "in config file to run this testsuite.\n");
10008                 return TEST_SKIPPED;
10009         }
10010
10011         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
10012 }
10013
10014 static int
10015 test_cryptodev_null(void)
10016 {
10017         gbl_driver_id = rte_cryptodev_driver_id_get(
10018                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
10019
10020         if (gbl_driver_id == -1) {
10021                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
10022                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
10023                                 "in config file to run this testsuite.\n");
10024                 return TEST_SKIPPED;
10025         }
10026
10027         return unit_test_suite_runner(&cryptodev_null_testsuite);
10028 }
10029
10030 static int
10031 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
10032 {
10033         gbl_driver_id = rte_cryptodev_driver_id_get(
10034                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
10035
10036         if (gbl_driver_id == -1) {
10037                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
10038                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
10039                                 "in config file to run this testsuite.\n");
10040                 return TEST_SKIPPED;
10041         }
10042
10043         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
10044 }
10045
10046 static int
10047 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
10048 {
10049         gbl_driver_id = rte_cryptodev_driver_id_get(
10050                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
10051
10052         if (gbl_driver_id == -1) {
10053                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
10054                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
10055                                 "in config file to run this testsuite.\n");
10056                 return TEST_SKIPPED;
10057         }
10058
10059         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
10060 }
10061
10062 static int
10063 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
10064 {
10065         gbl_driver_id = rte_cryptodev_driver_id_get(
10066                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
10067
10068         if (gbl_driver_id == -1) {
10069                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
10070                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
10071                                 "in config file to run this testsuite.\n");
10072                 return TEST_SKIPPED;
10073         }
10074
10075         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
10076 }
10077
10078 static int
10079 test_cryptodev_armv8(void)
10080 {
10081         gbl_driver_id = rte_cryptodev_driver_id_get(
10082                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
10083
10084         if (gbl_driver_id == -1) {
10085                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
10086                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
10087                                 "in config file to run this testsuite.\n");
10088                 return TEST_SKIPPED;
10089         }
10090
10091         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
10092 }
10093
10094 static int
10095 test_cryptodev_mrvl(void)
10096 {
10097         gbl_driver_id = rte_cryptodev_driver_id_get(
10098                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
10099
10100         if (gbl_driver_id == -1) {
10101                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if "
10102                                 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled "
10103                                 "in config file to run this testsuite.\n");
10104                 return TEST_SKIPPED;
10105         }
10106
10107         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
10108 }
10109
10110 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
10111
10112 static int
10113 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
10114 {
10115         gbl_driver_id = rte_cryptodev_driver_id_get(
10116                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
10117
10118         if (gbl_driver_id == -1) {
10119                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
10120                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
10121                                 "in config file to run this testsuite.\n");
10122                 return TEST_SKIPPED;
10123         }
10124
10125         if (rte_cryptodev_driver_id_get(
10126                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
10127                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
10128                         " enabled in config file to run this testsuite.\n");
10129                 return TEST_SKIPPED;
10130 }
10131         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
10132 }
10133
10134 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
10135
10136 #endif
10137
10138 static int
10139 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
10140 {
10141         gbl_driver_id = rte_cryptodev_driver_id_get(
10142                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
10143
10144         if (gbl_driver_id == -1) {
10145                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
10146                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
10147                                 "in config file to run this testsuite.\n");
10148                 return TEST_SKIPPED;
10149         }
10150
10151         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
10152 }
10153
10154 static int
10155 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
10156 {
10157         gbl_driver_id = rte_cryptodev_driver_id_get(
10158                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
10159
10160         if (gbl_driver_id == -1) {
10161                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
10162                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
10163                                 "in config file to run this testsuite.\n");
10164                 return TEST_SKIPPED;
10165         }
10166
10167         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
10168 }
10169
10170 static int
10171 test_cryptodev_ccp(void)
10172 {
10173         gbl_driver_id = rte_cryptodev_driver_id_get(
10174                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
10175
10176         if (gbl_driver_id == -1) {
10177                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
10178                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
10179                                 "in config file to run this testsuite.\n");
10180                 return TEST_FAILED;
10181         }
10182
10183         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
10184 }
10185
10186 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
10187 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
10188 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
10189 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
10190 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
10191 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
10192 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
10193 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
10194 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
10195 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
10196 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
10197 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
10198 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
10199 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);