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