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