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