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