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