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