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