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