New upstream version 16.11.3
[deb_dpdk.git] / app / test / test_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 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
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
42
43 #include "test.h"
44 #include "test_cryptodev.h"
45
46 #include "test_cryptodev_blockcipher.h"
47 #include "test_cryptodev_aes_test_vectors.h"
48 #include "test_cryptodev_des_test_vectors.h"
49 #include "test_cryptodev_hash_test_vectors.h"
50 #include "test_cryptodev_kasumi_test_vectors.h"
51 #include "test_cryptodev_kasumi_hash_test_vectors.h"
52 #include "test_cryptodev_snow3g_test_vectors.h"
53 #include "test_cryptodev_snow3g_hash_test_vectors.h"
54 #include "test_cryptodev_zuc_test_vectors.h"
55 #include "test_cryptodev_zuc_hash_test_vectors.h"
56 #include "test_cryptodev_gcm_test_vectors.h"
57 #include "test_cryptodev_hmac_test_vectors.h"
58
59 static enum rte_cryptodev_type gbl_cryptodev_type;
60
61 struct crypto_testsuite_params {
62         struct rte_mempool *mbuf_pool;
63         struct rte_mempool *large_mbuf_pool;
64         struct rte_mempool *op_mpool;
65         struct rte_cryptodev_config conf;
66         struct rte_cryptodev_qp_conf qp_conf;
67
68         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
69         uint8_t valid_dev_count;
70 };
71
72 struct crypto_unittest_params {
73         struct rte_crypto_sym_xform cipher_xform;
74         struct rte_crypto_sym_xform auth_xform;
75
76         struct rte_cryptodev_sym_session *sess;
77
78         struct rte_crypto_op *op;
79
80         struct rte_mbuf *obuf, *ibuf;
81
82         uint8_t *digest;
83 };
84
85 #define ALIGN_POW2_ROUNDUP(num, align) \
86         (((num) + (align) - 1) & ~((align) - 1))
87
88 /*
89  * Forward declarations.
90  */
91 static int
92 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
93                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
94                 uint8_t *hmac_key);
95
96 static int
97 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
98                 struct crypto_unittest_params *ut_params,
99                 struct crypto_testsuite_params *ts_param,
100                 const uint8_t *cipher,
101                 const uint8_t *digest,
102                 const uint8_t *iv);
103
104 static struct rte_mbuf *
105 setup_test_string(struct rte_mempool *mpool,
106                 const char *string, size_t len, uint8_t blocksize)
107 {
108         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
109         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
110
111         memset(m->buf_addr, 0, m->buf_len);
112         if (m) {
113                 char *dst = rte_pktmbuf_append(m, t_len);
114
115                 if (!dst) {
116                         rte_pktmbuf_free(m);
117                         return NULL;
118                 }
119                 if (string != NULL)
120                         rte_memcpy(dst, string, t_len);
121                 else
122                         memset(dst, 0, t_len);
123         }
124
125         return m;
126 }
127
128 /* Get number of bytes in X bits (rounding up) */
129 static uint32_t
130 ceil_byte_length(uint32_t num_bits)
131 {
132         if (num_bits % 8)
133                 return ((num_bits >> 3) + 1);
134         else
135                 return (num_bits >> 3);
136 }
137
138 static struct rte_crypto_op *
139 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
140 {
141         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
142                 printf("Error sending packet for encryption");
143                 return NULL;
144         }
145
146         op = NULL;
147
148         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
149                 rte_pause();
150
151         return op;
152 }
153
154 static struct crypto_testsuite_params testsuite_params = { NULL };
155 static struct crypto_unittest_params unittest_params;
156
157 static int
158 testsuite_setup(void)
159 {
160         struct crypto_testsuite_params *ts_params = &testsuite_params;
161         struct rte_cryptodev_info info;
162         unsigned i, nb_devs, dev_id;
163         int ret;
164         uint16_t qp_id;
165
166         memset(ts_params, 0, sizeof(*ts_params));
167
168         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
169         if (ts_params->mbuf_pool == NULL) {
170                 /* Not already created so create */
171                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
172                                 "CRYPTO_MBUFPOOL",
173                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
174                                 rte_socket_id());
175                 if (ts_params->mbuf_pool == NULL) {
176                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
177                         return TEST_FAILED;
178                 }
179         }
180
181         ts_params->large_mbuf_pool = rte_mempool_lookup(
182                         "CRYPTO_LARGE_MBUFPOOL");
183         if (ts_params->large_mbuf_pool == NULL) {
184                 /* Not already created so create */
185                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
186                                 "CRYPTO_LARGE_MBUFPOOL",
187                                 1, 0, 0, UINT16_MAX,
188                                 rte_socket_id());
189                 if (ts_params->large_mbuf_pool == NULL) {
190                         RTE_LOG(ERR, USER1,
191                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
192                         return TEST_FAILED;
193                 }
194         }
195
196         ts_params->op_mpool = rte_crypto_op_pool_create(
197                         "MBUF_CRYPTO_SYM_OP_POOL",
198                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
199                         NUM_MBUFS, MBUF_CACHE_SIZE,
200                         DEFAULT_NUM_XFORMS *
201                         sizeof(struct rte_crypto_sym_xform),
202                         rte_socket_id());
203         if (ts_params->op_mpool == NULL) {
204                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
205                 return TEST_FAILED;
206         }
207
208         /* Create 2 AESNI MB devices if required */
209         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
210 #ifndef RTE_LIBRTE_PMD_AESNI_MB
211                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
212                         " enabled in config file to run this testsuite.\n");
213                 return TEST_FAILED;
214 #endif
215                 nb_devs = rte_cryptodev_count_devtype(
216                                 RTE_CRYPTODEV_AESNI_MB_PMD);
217                 if (nb_devs < 2) {
218                         for (i = nb_devs; i < 2; i++) {
219                                 ret = rte_eal_vdev_init(
220                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
221
222                                 TEST_ASSERT(ret == 0,
223                                         "Failed to create instance %u of"
224                                         " pmd : %s",
225                                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
226                         }
227                 }
228         }
229
230         /* Create 2 AESNI GCM devices if required */
231         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
232 #ifndef RTE_LIBRTE_PMD_AESNI_GCM
233                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be"
234                         " enabled in config file to run this testsuite.\n");
235                 return TEST_FAILED;
236 #endif
237                 nb_devs = rte_cryptodev_count_devtype(
238                                 RTE_CRYPTODEV_AESNI_GCM_PMD);
239                 if (nb_devs < 2) {
240                         for (i = nb_devs; i < 2; i++) {
241                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
242                                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
243                                         "Failed to create instance %u of"
244                                         " pmd : %s",
245                                         i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
246                         }
247                 }
248         }
249
250         /* Create 2 SNOW 3G devices if required */
251         if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
252 #ifndef RTE_LIBRTE_PMD_SNOW3G
253                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be"
254                         " enabled in config file to run this testsuite.\n");
255                 return TEST_FAILED;
256 #endif
257                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
258                 if (nb_devs < 2) {
259                         for (i = nb_devs; i < 2; i++) {
260                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
261                                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
262                                         "Failed to create instance %u of"
263                                         " pmd : %s",
264                                         i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
265                         }
266                 }
267         }
268
269         /* Create 2 KASUMI devices if required */
270         if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
271 #ifndef RTE_LIBRTE_PMD_KASUMI
272                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be"
273                         " enabled in config file to run this testsuite.\n");
274                 return TEST_FAILED;
275 #endif
276                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
277                 if (nb_devs < 2) {
278                         for (i = nb_devs; i < 2; i++) {
279                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
280                                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
281                                         "Failed to create instance %u of"
282                                         " pmd : %s",
283                                         i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
284                         }
285                 }
286         }
287
288         /* Create 2 ZUC devices if required */
289         if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
290 #ifndef RTE_LIBRTE_PMD_ZUC
291                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be"
292                         " enabled in config file to run this testsuite.\n");
293                 return TEST_FAILED;
294 #endif
295                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
296                 if (nb_devs < 2) {
297                         for (i = nb_devs; i < 2; i++) {
298                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
299                                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
300                                         "Failed to create instance %u of"
301                                         " pmd : %s",
302                                         i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
303                         }
304                 }
305         }
306
307         /* Create 2 NULL devices if required */
308         if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
309 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO
310                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be"
311                         " enabled in config file to run this testsuite.\n");
312                 return TEST_FAILED;
313 #endif
314                 nb_devs = rte_cryptodev_count_devtype(
315                                 RTE_CRYPTODEV_NULL_PMD);
316                 if (nb_devs < 2) {
317                         for (i = nb_devs; i < 2; i++) {
318                                 int dev_id = rte_eal_vdev_init(
319                                         RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
320
321                                 TEST_ASSERT(dev_id >= 0,
322                                         "Failed to create instance %u of"
323                                         " pmd : %s",
324                                         i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
325                         }
326                 }
327         }
328
329         /* Create 2 OPENSSL devices if required */
330         if (gbl_cryptodev_type == RTE_CRYPTODEV_OPENSSL_PMD) {
331 #ifndef RTE_LIBRTE_PMD_OPENSSL
332                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_OPENSSL must be"
333                         " enabled in config file to run this testsuite.\n");
334                 return TEST_FAILED;
335 #endif
336                 nb_devs = rte_cryptodev_count_devtype(
337                                 RTE_CRYPTODEV_OPENSSL_PMD);
338                 if (nb_devs < 2) {
339                         for (i = nb_devs; i < 2; i++) {
340                                 ret = rte_eal_vdev_init(
341                                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
342                                         NULL);
343
344                                 TEST_ASSERT(ret == 0, "Failed to create "
345                                         "instance %u of pmd : %s", i,
346                                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
347                         }
348                 }
349         }
350
351 #ifndef RTE_LIBRTE_PMD_QAT
352         if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) {
353                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled "
354                                 "in config file to run this testsuite.\n");
355                 return TEST_FAILED;
356         }
357 #endif
358
359         nb_devs = rte_cryptodev_count();
360         if (nb_devs < 1) {
361                 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
362                 return TEST_FAILED;
363         }
364
365         /* Create list of valid crypto devs */
366         for (i = 0; i < nb_devs; i++) {
367                 rte_cryptodev_info_get(i, &info);
368                 if (info.dev_type == gbl_cryptodev_type)
369                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
370         }
371
372         if (ts_params->valid_dev_count < 1)
373                 return TEST_FAILED;
374
375         /* Set up all the qps on the first of the valid devices found */
376
377         dev_id = ts_params->valid_devs[0];
378
379         rte_cryptodev_info_get(dev_id, &info);
380
381         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
382         ts_params->conf.socket_id = SOCKET_ID_ANY;
383         ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
384
385         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
386                         &ts_params->conf),
387                         "Failed to configure cryptodev %u with %u qps",
388                         dev_id, ts_params->conf.nb_queue_pairs);
389
390         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
391
392         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
393                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
394                         dev_id, qp_id, &ts_params->qp_conf,
395                         rte_cryptodev_socket_id(dev_id)),
396                         "Failed to setup queue pair %u on cryptodev %u",
397                         qp_id, dev_id);
398         }
399
400         return TEST_SUCCESS;
401 }
402
403 static void
404 testsuite_teardown(void)
405 {
406         struct crypto_testsuite_params *ts_params = &testsuite_params;
407
408         if (ts_params->mbuf_pool != NULL) {
409                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
410                 rte_mempool_avail_count(ts_params->mbuf_pool));
411         }
412
413         if (ts_params->op_mpool != NULL) {
414                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
415                 rte_mempool_avail_count(ts_params->op_mpool));
416         }
417
418 }
419
420 static int
421 ut_setup(void)
422 {
423         struct crypto_testsuite_params *ts_params = &testsuite_params;
424         struct crypto_unittest_params *ut_params = &unittest_params;
425
426         uint16_t qp_id;
427
428         /* Clear unit test parameters before running test */
429         memset(ut_params, 0, sizeof(*ut_params));
430
431         /* Reconfigure device to default parameters */
432         ts_params->conf.socket_id = SOCKET_ID_ANY;
433         ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
434
435         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
436                         &ts_params->conf),
437                         "Failed to configure cryptodev %u",
438                         ts_params->valid_devs[0]);
439
440         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
441                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
442                         ts_params->valid_devs[0], qp_id,
443                         &ts_params->qp_conf,
444                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
445                         "Failed to setup queue pair %u on cryptodev %u",
446                         qp_id, ts_params->valid_devs[0]);
447         }
448
449
450         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
451
452         /* Start the device */
453         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
454                         "Failed to start cryptodev %u",
455                         ts_params->valid_devs[0]);
456
457         return TEST_SUCCESS;
458 }
459
460 static void
461 ut_teardown(void)
462 {
463         struct crypto_testsuite_params *ts_params = &testsuite_params;
464         struct crypto_unittest_params *ut_params = &unittest_params;
465         struct rte_cryptodev_stats stats;
466
467         /* free crypto session structure */
468         if (ut_params->sess) {
469                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
470                                 ut_params->sess);
471                 ut_params->sess = NULL;
472         }
473
474         /* free crypto operation structure */
475         if (ut_params->op)
476                 rte_crypto_op_free(ut_params->op);
477
478         /*
479          * free mbuf - both obuf and ibuf are usually the same,
480          * so check if they point at the same address is necessary,
481          * to avoid freeing the mbuf twice.
482          */
483         if (ut_params->obuf) {
484                 rte_pktmbuf_free(ut_params->obuf);
485                 if (ut_params->ibuf == ut_params->obuf)
486                         ut_params->ibuf = 0;
487                 ut_params->obuf = 0;
488         }
489         if (ut_params->ibuf) {
490                 rte_pktmbuf_free(ut_params->ibuf);
491                 ut_params->ibuf = 0;
492         }
493
494         if (ts_params->mbuf_pool != NULL)
495                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
496                         rte_mempool_avail_count(ts_params->mbuf_pool));
497
498         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
499
500         /* Stop the device */
501         rte_cryptodev_stop(ts_params->valid_devs[0]);
502 }
503
504 static int
505 test_device_configure_invalid_dev_id(void)
506 {
507         struct crypto_testsuite_params *ts_params = &testsuite_params;
508         uint16_t dev_id, num_devs = 0;
509
510         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
511                         "Need at least %d devices for test", 1);
512
513         /* valid dev_id values */
514         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
515
516         /* Stop the device in case it's started so it can be configured */
517         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
518
519         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
520                         "Failed test for rte_cryptodev_configure: "
521                         "invalid dev_num %u", dev_id);
522
523         /* invalid dev_id values */
524         dev_id = num_devs;
525
526         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
527                         "Failed test for rte_cryptodev_configure: "
528                         "invalid dev_num %u", dev_id);
529
530         dev_id = 0xff;
531
532         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
533                         "Failed test for rte_cryptodev_configure:"
534                         "invalid dev_num %u", dev_id);
535
536         return TEST_SUCCESS;
537 }
538
539 static int
540 test_device_configure_invalid_queue_pair_ids(void)
541 {
542         struct crypto_testsuite_params *ts_params = &testsuite_params;
543         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
544
545         /* Stop the device in case it's started so it can be configured */
546         rte_cryptodev_stop(ts_params->valid_devs[0]);
547
548         /* valid - one queue pairs */
549         ts_params->conf.nb_queue_pairs = 1;
550
551         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
552                         &ts_params->conf),
553                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
554                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
555
556
557         /* valid - max value queue pairs */
558         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
559
560         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
561                         &ts_params->conf),
562                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
563                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
564
565
566         /* invalid - zero queue pairs */
567         ts_params->conf.nb_queue_pairs = 0;
568
569         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
570                         &ts_params->conf),
571                         "Failed test for rte_cryptodev_configure, dev_id %u,"
572                         " invalid qps: %u",
573                         ts_params->valid_devs[0],
574                         ts_params->conf.nb_queue_pairs);
575
576
577         /* invalid - max value supported by field queue pairs */
578         ts_params->conf.nb_queue_pairs = UINT16_MAX;
579
580         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
581                         &ts_params->conf),
582                         "Failed test for rte_cryptodev_configure, dev_id %u,"
583                         " invalid qps: %u",
584                         ts_params->valid_devs[0],
585                         ts_params->conf.nb_queue_pairs);
586
587
588         /* invalid - max value + 1 queue pairs */
589         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
590
591         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
592                         &ts_params->conf),
593                         "Failed test for rte_cryptodev_configure, dev_id %u,"
594                         " invalid qps: %u",
595                         ts_params->valid_devs[0],
596                         ts_params->conf.nb_queue_pairs);
597
598         /* revert to original testsuite value */
599         ts_params->conf.nb_queue_pairs = orig_nb_qps;
600
601         return TEST_SUCCESS;
602 }
603
604 static int
605 test_queue_pair_descriptor_setup(void)
606 {
607         struct crypto_testsuite_params *ts_params = &testsuite_params;
608         struct rte_cryptodev_info dev_info;
609         struct rte_cryptodev_qp_conf qp_conf = {
610                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
611         };
612
613         uint16_t qp_id;
614
615         /* Stop the device in case it's started so it can be configured */
616         rte_cryptodev_stop(ts_params->valid_devs[0]);
617
618
619         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
620
621         ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
622
623         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
624                         &ts_params->conf), "Failed to configure cryptodev %u",
625                         ts_params->valid_devs[0]);
626
627
628         /*
629          * Test various ring sizes on this device. memzones can't be
630          * freed so are re-used if ring is released and re-created.
631          */
632         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
633
634         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
635                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
636                                 ts_params->valid_devs[0], qp_id, &qp_conf,
637                                 rte_cryptodev_socket_id(
638                                                 ts_params->valid_devs[0])),
639                                 "Failed test for "
640                                 "rte_cryptodev_queue_pair_setup: num_inflights "
641                                 "%u on qp %u on cryptodev %u",
642                                 qp_conf.nb_descriptors, qp_id,
643                                 ts_params->valid_devs[0]);
644         }
645
646         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
647
648         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
649                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
650                                 ts_params->valid_devs[0], qp_id, &qp_conf,
651                                 rte_cryptodev_socket_id(
652                                                 ts_params->valid_devs[0])),
653                                 "Failed test for"
654                                 " rte_cryptodev_queue_pair_setup: num_inflights"
655                                 " %u on qp %u on cryptodev %u",
656                                 qp_conf.nb_descriptors, qp_id,
657                                 ts_params->valid_devs[0]);
658         }
659
660         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
661
662         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
663                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
664                                 ts_params->valid_devs[0], qp_id, &qp_conf,
665                                 rte_cryptodev_socket_id(
666                                                 ts_params->valid_devs[0])),
667                                 "Failed test for "
668                                 "rte_cryptodev_queue_pair_setup: num_inflights"
669                                 " %u on qp %u on cryptodev %u",
670                                 qp_conf.nb_descriptors, qp_id,
671                                 ts_params->valid_devs[0]);
672         }
673
674         /* invalid number of descriptors - max supported + 2 */
675         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
676
677         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
678                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
679                                 ts_params->valid_devs[0], qp_id, &qp_conf,
680                                 rte_cryptodev_socket_id(
681                                                 ts_params->valid_devs[0])),
682                                 "Unexpectedly passed test for "
683                                 "rte_cryptodev_queue_pair_setup:"
684                                 "num_inflights %u on qp %u on cryptodev %u",
685                                 qp_conf.nb_descriptors, qp_id,
686                                 ts_params->valid_devs[0]);
687         }
688
689         /* invalid number of descriptors - max value of parameter */
690         qp_conf.nb_descriptors = UINT32_MAX-1;
691
692         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
693                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
694                                 ts_params->valid_devs[0], qp_id, &qp_conf,
695                                 rte_cryptodev_socket_id(
696                                                 ts_params->valid_devs[0])),
697                                 "Unexpectedly passed test for "
698                                 "rte_cryptodev_queue_pair_setup:"
699                                 "num_inflights %u on qp %u on cryptodev %u",
700                                 qp_conf.nb_descriptors, qp_id,
701                                 ts_params->valid_devs[0]);
702         }
703
704         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
705
706         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
707                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
708                                 ts_params->valid_devs[0], qp_id, &qp_conf,
709                                 rte_cryptodev_socket_id(
710                                                 ts_params->valid_devs[0])),
711                                 "Failed test for"
712                                 " rte_cryptodev_queue_pair_setup:"
713                                 "num_inflights %u on qp %u on cryptodev %u",
714                                 qp_conf.nb_descriptors, qp_id,
715                                 ts_params->valid_devs[0]);
716         }
717
718         /* invalid number of descriptors - max supported + 1 */
719         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
720
721         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
722                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
723                                 ts_params->valid_devs[0], qp_id, &qp_conf,
724                                 rte_cryptodev_socket_id(
725                                                 ts_params->valid_devs[0])),
726                                 "Unexpectedly passed test for "
727                                 "rte_cryptodev_queue_pair_setup:"
728                                 "num_inflights %u on qp %u on cryptodev %u",
729                                 qp_conf.nb_descriptors, qp_id,
730                                 ts_params->valid_devs[0]);
731         }
732
733         /* test invalid queue pair id */
734         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
735
736         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
737
738         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
739                         ts_params->valid_devs[0],
740                         qp_id, &qp_conf,
741                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
742                         "Failed test for rte_cryptodev_queue_pair_setup:"
743                         "invalid qp %u on cryptodev %u",
744                         qp_id, ts_params->valid_devs[0]);
745
746         qp_id = 0xffff; /*invalid*/
747
748         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
749                         ts_params->valid_devs[0],
750                         qp_id, &qp_conf,
751                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
752                         "Failed test for rte_cryptodev_queue_pair_setup:"
753                         "invalid qp %u on cryptodev %u",
754                         qp_id, ts_params->valid_devs[0]);
755
756         return TEST_SUCCESS;
757 }
758
759 /* ***** Plaintext data for tests ***** */
760
761 const char catch_22_quote_1[] =
762                 "There was only one catch and that was Catch-22, which "
763                 "specified that a concern for one's safety in the face of "
764                 "dangers that were real and immediate was the process of a "
765                 "rational mind. Orr was crazy and could be grounded. All he "
766                 "had to do was ask; and as soon as he did, he would no longer "
767                 "be crazy and would have to fly more missions. Orr would be "
768                 "crazy to fly more missions and sane if he didn't, but if he "
769                 "was sane he had to fly them. If he flew them he was crazy "
770                 "and didn't have to; but if he didn't want to he was sane and "
771                 "had to. Yossarian was moved very deeply by the absolute "
772                 "simplicity of this clause of Catch-22 and let out a "
773                 "respectful whistle. \"That's some catch, that Catch-22\", he "
774                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
775
776 const char catch_22_quote[] =
777                 "What a lousy earth! He wondered how many people were "
778                 "destitute that same night even in his own prosperous country, "
779                 "how many homes were shanties, how many husbands were drunk "
780                 "and wives socked, and how many children were bullied, abused, "
781                 "or abandoned. How many families hungered for food they could "
782                 "not afford to buy? How many hearts were broken? How many "
783                 "suicides would take place that same night, how many people "
784                 "would go insane? How many cockroaches and landlords would "
785                 "triumph? How many winners were losers, successes failures, "
786                 "and rich men poor men? How many wise guys were stupid? How "
787                 "many happy endings were unhappy endings? How many honest men "
788                 "were liars, brave men cowards, loyal men traitors, how many "
789                 "sainted men were corrupt, how many people in positions of "
790                 "trust had sold their souls to bodyguards, how many had never "
791                 "had souls? How many straight-and-narrow paths were crooked "
792                 "paths? How many best families were worst families and how "
793                 "many good people were bad people? When you added them all up "
794                 "and then subtracted, you might be left with only the children, "
795                 "and perhaps with Albert Einstein and an old violinist or "
796                 "sculptor somewhere.";
797
798 #define QUOTE_480_BYTES         (480)
799 #define QUOTE_512_BYTES         (512)
800 #define QUOTE_768_BYTES         (768)
801 #define QUOTE_1024_BYTES        (1024)
802
803
804
805 /* ***** SHA1 Hash Tests ***** */
806
807 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
808
809 static uint8_t hmac_sha1_key[] = {
810         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
811         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
812         0xDE, 0xF4, 0xDE, 0xAD };
813
814 /* ***** SHA224 Hash Tests ***** */
815
816 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
817
818
819 /* ***** AES-CBC Cipher Tests ***** */
820
821 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
822 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
823
824 static uint8_t aes_cbc_key[] = {
825         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
826         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
827
828 static uint8_t aes_cbc_iv[] = {
829         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
830         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
831
832
833 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
834
835 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
836         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
837         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
838         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
839         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
840         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
841         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
842         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
843         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
844         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
845         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
846         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
847         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
848         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
849         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
850         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
851         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
852         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
853         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
854         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
855         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
856         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
857         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
858         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
859         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
860         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
861         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
862         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
863         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
864         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
865         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
866         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
867         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
868         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
869         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
870         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
871         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
872         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
873         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
874         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
875         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
876         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
877         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
878         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
879         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
880         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
881         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
882         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
883         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
884         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
885         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
886         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
887         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
888         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
889         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
890         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
891         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
892         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
893         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
894         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
895         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
896         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
897         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
898         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
899         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
900 };
901
902 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
903         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
904         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
905         0x18, 0x8c, 0x1d, 0x32
906 };
907
908
909 /* Multisession Vector context Test */
910 /*Begin Session 0 */
911 static uint8_t ms_aes_cbc_key0[] = {
912         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
913         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
914 };
915
916 static uint8_t ms_aes_cbc_iv0[] = {
917         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
918         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
919 };
920
921 static const uint8_t ms_aes_cbc_cipher0[] = {
922                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
923                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
924                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
925                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
926                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
927                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
928                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
929                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
930                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
931                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
932                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
933                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
934                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
935                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
936                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
937                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
938                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
939                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
940                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
941                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
942                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
943                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
944                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
945                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
946                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
947                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
948                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
949                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
950                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
951                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
952                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
953                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
954                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
955                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
956                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
957                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
958                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
959                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
960                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
961                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
962                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
963                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
964                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
965                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
966                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
967                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
968                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
969                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
970                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
971                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
972                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
973                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
974                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
975                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
976                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
977                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
978                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
979                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
980                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
981                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
982                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
983                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
984                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
985                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
986 };
987
988
989 static  uint8_t ms_hmac_key0[] = {
990                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
991                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
992                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
993                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
994                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
995                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
996                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
997                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
998 };
999
1000 static const uint8_t ms_hmac_digest0[] = {
1001                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1002                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1003                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1004                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1005                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1006                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1007                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1008                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1009                 };
1010
1011 /* End Session 0 */
1012 /* Begin session 1 */
1013
1014 static  uint8_t ms_aes_cbc_key1[] = {
1015                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1016                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1017 };
1018
1019 static  uint8_t ms_aes_cbc_iv1[] = {
1020         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1021         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1022 };
1023
1024 static const uint8_t ms_aes_cbc_cipher1[] = {
1025                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1026                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1027                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1028                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1029                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1030                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1031                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1032                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1033                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1034                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1035                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1036                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1037                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1038                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1039                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1040                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1041                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1042                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1043                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1044                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1045                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1046                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1047                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1048                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1049                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1050                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1051                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1052                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1053                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1054                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1055                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1056                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1057                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1058                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1059                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1060                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1061                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1062                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1063                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1064                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1065                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1066                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1067                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1068                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1069                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1070                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1071                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1072                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1073                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1074                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1075                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1076                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1077                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1078                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1079                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1080                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1081                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1082                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1083                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1084                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1085                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1086                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1087                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1088                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1089
1090 };
1091
1092 static uint8_t ms_hmac_key1[] = {
1093                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1094                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1095                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1096                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1097                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1098                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1099                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1100                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1101 };
1102
1103 static const uint8_t ms_hmac_digest1[] = {
1104                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1105                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1106                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1107                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1108                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1109                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1110                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1111                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1112 };
1113 /* End Session 1  */
1114 /* Begin Session 2 */
1115 static  uint8_t ms_aes_cbc_key2[] = {
1116                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1117                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1118 };
1119
1120 static  uint8_t ms_aes_cbc_iv2[] = {
1121                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1122                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1123 };
1124
1125 static const uint8_t ms_aes_cbc_cipher2[] = {
1126                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1127                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1128                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1129                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1130                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1131                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1132                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1133                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1134                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1135                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1136                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1137                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1138                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1139                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1140                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1141                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1142                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1143                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1144                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1145                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1146                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1147                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1148                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1149                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1150                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1151                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1152                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1153                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1154                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1155                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1156                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1157                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1158                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1159                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1160                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1161                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1162                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1163                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1164                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1165                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1166                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1167                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1168                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1169                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1170                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1171                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1172                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1173                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1174                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1175                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1176                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1177                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1178                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1179                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1180                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1181                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1182                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1183                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1184                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1185                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1186                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1187                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1188                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1189                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1190 };
1191
1192 static  uint8_t ms_hmac_key2[] = {
1193                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1194                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1195                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1196                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1197                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1198                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1199                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1200                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1201 };
1202
1203 static const uint8_t ms_hmac_digest2[] = {
1204                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1205                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1206                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1207                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1208                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1209                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1210                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1211                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1212 };
1213
1214 /* End Session 2 */
1215
1216
1217 static int
1218 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1219 {
1220         struct crypto_testsuite_params *ts_params = &testsuite_params;
1221         struct crypto_unittest_params *ut_params = &unittest_params;
1222
1223         /* Generate test mbuf data and space for digest */
1224         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1225                         catch_22_quote, QUOTE_512_BYTES, 0);
1226
1227         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1228                         DIGEST_BYTE_LENGTH_SHA1);
1229         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1230
1231         /* Setup Cipher Parameters */
1232         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1233         ut_params->cipher_xform.next = &ut_params->auth_xform;
1234
1235         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1236         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1237         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1238         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1239
1240         /* Setup HMAC Parameters */
1241         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1242
1243         ut_params->auth_xform.next = NULL;
1244
1245         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1246         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1247         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1248         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1249         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1250
1251         /* Create crypto session*/
1252         ut_params->sess = rte_cryptodev_sym_session_create(
1253                         ts_params->valid_devs[0],
1254                         &ut_params->cipher_xform);
1255         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1256
1257         /* Generate crypto op data structure */
1258         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1259                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1260         TEST_ASSERT_NOT_NULL(ut_params->op,
1261                         "Failed to allocate symmetric crypto operation struct");
1262
1263         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1264
1265         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1266
1267         /* set crypto operation source mbuf */
1268         sym_op->m_src = ut_params->ibuf;
1269
1270         /* Set crypto operation authentication parameters */
1271         sym_op->auth.digest.data = ut_params->digest;
1272         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1273                         ut_params->ibuf, QUOTE_512_BYTES);
1274         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1275
1276         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1277         sym_op->auth.data.length = QUOTE_512_BYTES;
1278
1279         /* Set crypto operation cipher parameters */
1280         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1281                         CIPHER_IV_LENGTH_AES_CBC);
1282         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1283         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1284
1285         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1286                         CIPHER_IV_LENGTH_AES_CBC);
1287
1288         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1289         sym_op->cipher.data.length = QUOTE_512_BYTES;
1290
1291         /* Process crypto operation */
1292         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1293                         ut_params->op), "failed to process sym crypto op");
1294
1295         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1296                         "crypto op processing failed");
1297
1298         /* Validate obuf */
1299         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1300                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1301
1302         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1303                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1304                         QUOTE_512_BYTES,
1305                         "ciphertext data not as expected");
1306
1307         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1308
1309         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1310                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1311                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1312                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1313                                         DIGEST_BYTE_LENGTH_SHA1,
1314                         "Generated digest data not as expected");
1315
1316         return TEST_SUCCESS;
1317 }
1318
1319 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1320
1321 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1322
1323 static uint8_t hmac_sha512_key[] = {
1324         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1325         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1326         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1327         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1328         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1329         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1330         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1331         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1332
1333 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1334         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1335         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1336         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1337         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1338         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1339         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1340         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1341         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1342
1343
1344
1345 static int
1346 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1347                 struct crypto_unittest_params *ut_params,
1348                 uint8_t *cipher_key,
1349                 uint8_t *hmac_key);
1350
1351 static int
1352 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1353                 struct crypto_unittest_params *ut_params,
1354                 struct crypto_testsuite_params *ts_params,
1355                 const uint8_t *cipher,
1356                 const uint8_t *digest,
1357                 const uint8_t *iv);
1358
1359
1360 static int
1361 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1362                 struct crypto_unittest_params *ut_params,
1363                 uint8_t *cipher_key,
1364                 uint8_t *hmac_key)
1365 {
1366
1367         /* Setup Cipher Parameters */
1368         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1369         ut_params->cipher_xform.next = NULL;
1370
1371         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1372         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1373         ut_params->cipher_xform.cipher.key.data = cipher_key;
1374         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1375
1376         /* Setup HMAC Parameters */
1377         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1378         ut_params->auth_xform.next = &ut_params->cipher_xform;
1379
1380         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1381         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1382         ut_params->auth_xform.auth.key.data = hmac_key;
1383         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1384         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1385
1386         return TEST_SUCCESS;
1387 }
1388
1389
1390 static int
1391 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1392                 struct crypto_unittest_params *ut_params,
1393                 struct crypto_testsuite_params *ts_params,
1394                 const uint8_t *cipher,
1395                 const uint8_t *digest,
1396                 const uint8_t *iv)
1397 {
1398         /* Generate test mbuf data and digest */
1399         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1400                         (const char *)
1401                         cipher,
1402                         QUOTE_512_BYTES, 0);
1403
1404         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1405                         DIGEST_BYTE_LENGTH_SHA512);
1406         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1407
1408         rte_memcpy(ut_params->digest,
1409                         digest,
1410                         DIGEST_BYTE_LENGTH_SHA512);
1411
1412         /* Generate Crypto op data structure */
1413         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1414                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1415         TEST_ASSERT_NOT_NULL(ut_params->op,
1416                         "Failed to allocate symmetric crypto operation struct");
1417
1418         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1419
1420         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1421
1422         /* set crypto operation source mbuf */
1423         sym_op->m_src = ut_params->ibuf;
1424
1425         sym_op->auth.digest.data = ut_params->digest;
1426         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1427                         ut_params->ibuf, QUOTE_512_BYTES);
1428         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1429
1430         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1431         sym_op->auth.data.length = QUOTE_512_BYTES;
1432
1433         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1434                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1435         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1436                         ut_params->ibuf, 0);
1437         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1438
1439         rte_memcpy(sym_op->cipher.iv.data, iv,
1440                         CIPHER_IV_LENGTH_AES_CBC);
1441
1442         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1443         sym_op->cipher.data.length = QUOTE_512_BYTES;
1444
1445         /* Process crypto operation */
1446         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1447                         ut_params->op), "failed to process sym crypto op");
1448
1449         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1450                         "crypto op processing failed");
1451
1452         ut_params->obuf = ut_params->op->sym->m_src;
1453
1454         /* Validate obuf */
1455         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1456                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1457                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1458                         QUOTE_512_BYTES,
1459                         "Plaintext data not as expected");
1460
1461         /* Validate obuf */
1462         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1463                         "Digest verification failed");
1464
1465         return TEST_SUCCESS;
1466 }
1467
1468 static int
1469 test_AES_chain_mb_all(void)
1470 {
1471         struct crypto_testsuite_params *ts_params = &testsuite_params;
1472         int status;
1473
1474         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1475                 ts_params->op_mpool, ts_params->valid_devs[0],
1476                 RTE_CRYPTODEV_AESNI_MB_PMD,
1477                 BLKCIPHER_AES_CHAIN_TYPE);
1478
1479         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1480
1481         return TEST_SUCCESS;
1482 }
1483
1484 static int
1485 test_AES_chain_openssl_all(void)
1486 {
1487         struct crypto_testsuite_params *ts_params = &testsuite_params;
1488         int status;
1489
1490         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1491                 ts_params->op_mpool, ts_params->valid_devs[0],
1492                 RTE_CRYPTODEV_OPENSSL_PMD,
1493                 BLKCIPHER_AES_CHAIN_TYPE);
1494
1495         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1496
1497         return TEST_SUCCESS;
1498 }
1499
1500 static int
1501 test_AES_cipheronly_openssl_all(void)
1502 {
1503         struct crypto_testsuite_params *ts_params = &testsuite_params;
1504         int status;
1505
1506         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1507                 ts_params->op_mpool, ts_params->valid_devs[0],
1508                 RTE_CRYPTODEV_OPENSSL_PMD,
1509                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1510
1511         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1512
1513         return TEST_SUCCESS;
1514 }
1515
1516 static int
1517 test_AES_chain_qat_all(void)
1518 {
1519         struct crypto_testsuite_params *ts_params = &testsuite_params;
1520         int status;
1521
1522         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1523                 ts_params->op_mpool, ts_params->valid_devs[0],
1524                 RTE_CRYPTODEV_QAT_SYM_PMD,
1525                 BLKCIPHER_AES_CHAIN_TYPE);
1526
1527         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1528
1529         return TEST_SUCCESS;
1530 }
1531
1532 static int
1533 test_authonly_openssl_all(void)
1534 {
1535         struct crypto_testsuite_params *ts_params = &testsuite_params;
1536         int status;
1537
1538         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1539                 ts_params->op_mpool, ts_params->valid_devs[0],
1540                 RTE_CRYPTODEV_OPENSSL_PMD,
1541                 BLKCIPHER_AUTHONLY_TYPE);
1542
1543         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1544
1545         return TEST_SUCCESS;
1546 }
1547
1548 static int
1549 test_authonly_qat_all(void)
1550 {
1551         struct crypto_testsuite_params *ts_params = &testsuite_params;
1552         int status;
1553
1554         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1555                 ts_params->op_mpool, ts_params->valid_devs[0],
1556                 RTE_CRYPTODEV_QAT_SYM_PMD,
1557                 BLKCIPHER_AUTHONLY_TYPE);
1558
1559         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1560
1561         return TEST_SUCCESS;
1562 }
1563
1564 /* ***** SNOW 3G Tests ***** */
1565 static int
1566 create_wireless_algo_hash_session(uint8_t dev_id,
1567         const uint8_t *key, const uint8_t key_len,
1568         const uint8_t aad_len, const uint8_t auth_len,
1569         enum rte_crypto_auth_operation op,
1570         enum rte_crypto_auth_algorithm algo)
1571 {
1572         uint8_t hash_key[key_len];
1573
1574         struct crypto_unittest_params *ut_params = &unittest_params;
1575
1576         memcpy(hash_key, key, key_len);
1577
1578         TEST_HEXDUMP(stdout, "key:", key, key_len);
1579
1580         /* Setup Authentication Parameters */
1581         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1582         ut_params->auth_xform.next = NULL;
1583
1584         ut_params->auth_xform.auth.op = op;
1585         ut_params->auth_xform.auth.algo = algo;
1586         ut_params->auth_xform.auth.key.length = key_len;
1587         ut_params->auth_xform.auth.key.data = hash_key;
1588         ut_params->auth_xform.auth.digest_length = auth_len;
1589         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1590         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1591                                 &ut_params->auth_xform);
1592         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1593         return 0;
1594 }
1595
1596 static int
1597 create_wireless_algo_cipher_session(uint8_t dev_id,
1598                         enum rte_crypto_cipher_operation op,
1599                         enum rte_crypto_cipher_algorithm algo,
1600                         const uint8_t *key, const uint8_t key_len)
1601 {
1602         uint8_t cipher_key[key_len];
1603
1604         struct crypto_unittest_params *ut_params = &unittest_params;
1605
1606         memcpy(cipher_key, key, key_len);
1607
1608         /* Setup Cipher Parameters */
1609         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1610         ut_params->cipher_xform.next = NULL;
1611
1612         ut_params->cipher_xform.cipher.algo = algo;
1613         ut_params->cipher_xform.cipher.op = op;
1614         ut_params->cipher_xform.cipher.key.data = cipher_key;
1615         ut_params->cipher_xform.cipher.key.length = key_len;
1616
1617         TEST_HEXDUMP(stdout, "key:", key, key_len);
1618
1619         /* Create Crypto session */
1620         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1621                                                 &ut_params->
1622                                                 cipher_xform);
1623         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1624         return 0;
1625 }
1626
1627 static int
1628 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1629                         const unsigned cipher_len,
1630                         const unsigned cipher_offset,
1631                         enum rte_crypto_cipher_algorithm algo)
1632 {
1633         struct crypto_testsuite_params *ts_params = &testsuite_params;
1634         struct crypto_unittest_params *ut_params = &unittest_params;
1635         unsigned iv_pad_len = 0;
1636
1637         /* Generate Crypto op data structure */
1638         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1639                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1640         TEST_ASSERT_NOT_NULL(ut_params->op,
1641                                 "Failed to allocate pktmbuf offload");
1642
1643         /* Set crypto operation data parameters */
1644         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1645
1646         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1647
1648         /* set crypto operation source mbuf */
1649         sym_op->m_src = ut_params->ibuf;
1650
1651         /* iv */
1652         if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1653                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1654         else
1655                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1656
1657         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1658                         , iv_pad_len);
1659
1660         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1661
1662         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1663         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1664         sym_op->cipher.iv.length = iv_pad_len;
1665
1666         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1667         sym_op->cipher.data.length = cipher_len;
1668         sym_op->cipher.data.offset = cipher_offset;
1669         return 0;
1670 }
1671
1672 static int
1673 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1674                         const unsigned cipher_len,
1675                         const unsigned cipher_offset,
1676                         enum rte_crypto_cipher_algorithm algo)
1677 {
1678         struct crypto_testsuite_params *ts_params = &testsuite_params;
1679         struct crypto_unittest_params *ut_params = &unittest_params;
1680         unsigned iv_pad_len = 0;
1681
1682         /* Generate Crypto op data structure */
1683         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1684                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1685         TEST_ASSERT_NOT_NULL(ut_params->op,
1686                                 "Failed to allocate pktmbuf offload");
1687
1688         /* Set crypto operation data parameters */
1689         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1690
1691         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1692
1693         /* set crypto operation source mbuf */
1694         sym_op->m_src = ut_params->ibuf;
1695         sym_op->m_dst = ut_params->obuf;
1696
1697         /* iv */
1698         if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1699                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1700         else
1701                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1702         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1703                                         iv_pad_len);
1704
1705         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1706
1707         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1708         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1709         sym_op->cipher.iv.length = iv_pad_len;
1710
1711         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1712         sym_op->cipher.data.length = cipher_len;
1713         sym_op->cipher.data.offset = cipher_offset;
1714         return 0;
1715 }
1716
1717 static int
1718 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1719                 enum rte_crypto_cipher_operation cipher_op,
1720                 enum rte_crypto_auth_operation auth_op,
1721                 enum rte_crypto_auth_algorithm auth_algo,
1722                 enum rte_crypto_cipher_algorithm cipher_algo,
1723                 const uint8_t *key, const uint8_t key_len,
1724                 const uint8_t aad_len, const uint8_t auth_len)
1725
1726 {
1727         uint8_t cipher_auth_key[key_len];
1728
1729         struct crypto_unittest_params *ut_params = &unittest_params;
1730
1731         memcpy(cipher_auth_key, key, key_len);
1732
1733         /* Setup Authentication Parameters */
1734         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1735         ut_params->auth_xform.next = NULL;
1736
1737         ut_params->auth_xform.auth.op = auth_op;
1738         ut_params->auth_xform.auth.algo = auth_algo;
1739         ut_params->auth_xform.auth.key.length = key_len;
1740         /* Hash key = cipher key */
1741         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1742         ut_params->auth_xform.auth.digest_length = auth_len;
1743         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1744
1745         /* Setup Cipher Parameters */
1746         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1747         ut_params->cipher_xform.next = &ut_params->auth_xform;
1748
1749         ut_params->cipher_xform.cipher.algo = cipher_algo;
1750         ut_params->cipher_xform.cipher.op = cipher_op;
1751         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1752         ut_params->cipher_xform.cipher.key.length = key_len;
1753
1754         TEST_HEXDUMP(stdout, "key:", key, key_len);
1755
1756         /* Create Crypto session*/
1757         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1758                                 &ut_params->cipher_xform);
1759
1760         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1761         return 0;
1762 }
1763
1764 static int
1765 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1766                 enum rte_crypto_cipher_operation cipher_op,
1767                 enum rte_crypto_auth_operation auth_op,
1768                 enum rte_crypto_auth_algorithm auth_algo,
1769                 enum rte_crypto_cipher_algorithm cipher_algo,
1770                 const uint8_t *key, const uint8_t key_len,
1771                 const uint8_t aad_len, const uint8_t auth_len)
1772 {
1773         uint8_t auth_cipher_key[key_len];
1774
1775         struct crypto_unittest_params *ut_params = &unittest_params;
1776
1777         memcpy(auth_cipher_key, key, key_len);
1778
1779         /* Setup Authentication Parameters */
1780         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1781         ut_params->auth_xform.auth.op = auth_op;
1782         ut_params->auth_xform.next = &ut_params->cipher_xform;
1783         ut_params->auth_xform.auth.algo = auth_algo;
1784         ut_params->auth_xform.auth.key.length = key_len;
1785         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1786         ut_params->auth_xform.auth.digest_length = auth_len;
1787         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1788
1789         /* Setup Cipher Parameters */
1790         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1791         ut_params->cipher_xform.next = NULL;
1792         ut_params->cipher_xform.cipher.algo = cipher_algo;
1793         ut_params->cipher_xform.cipher.op = cipher_op;
1794         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1795         ut_params->cipher_xform.cipher.key.length = key_len;
1796
1797         TEST_HEXDUMP(stdout, "key:", key, key_len);
1798
1799         /* Create Crypto session*/
1800         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1801                                 &ut_params->auth_xform);
1802
1803         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1804
1805         return 0;
1806 }
1807
1808 static int
1809 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
1810                 const unsigned auth_tag_len,
1811                 const uint8_t *aad, const unsigned aad_len,
1812                 unsigned data_pad_len,
1813                 enum rte_crypto_auth_operation op,
1814                 enum rte_crypto_auth_algorithm algo,
1815                 const unsigned auth_len, const unsigned auth_offset)
1816 {
1817         struct crypto_testsuite_params *ts_params = &testsuite_params;
1818
1819         struct crypto_unittest_params *ut_params = &unittest_params;
1820
1821         unsigned aad_buffer_len;
1822
1823         /* Generate Crypto op data structure */
1824         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1825                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1826         TEST_ASSERT_NOT_NULL(ut_params->op,
1827                 "Failed to allocate pktmbuf offload");
1828
1829         /* Set crypto operation data parameters */
1830         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1831
1832         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1833
1834         /* set crypto operation source mbuf */
1835         sym_op->m_src = ut_params->ibuf;
1836
1837         /* aad */
1838         /*
1839         * Always allocate the aad up to the block size.
1840         * The cryptodev API calls out -
1841         *  - the array must be big enough to hold the AAD, plus any
1842         *   space to round this up to the nearest multiple of the
1843         *   block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1844         */
1845         if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1846                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1847         else
1848                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1849         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1850                         ut_params->ibuf, aad_buffer_len);
1851         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1852                                         "no room to prepend aad");
1853         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1854                         ut_params->ibuf);
1855         sym_op->auth.aad.length = aad_len;
1856
1857         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1858         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1859
1860         TEST_HEXDUMP(stdout, "aad:",
1861                         sym_op->auth.aad.data, aad_len);
1862
1863         /* digest */
1864         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1865                                         ut_params->ibuf, auth_tag_len);
1866
1867         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1868                                 "no room to append auth tag");
1869         ut_params->digest = sym_op->auth.digest.data;
1870         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1871                         ut_params->ibuf, data_pad_len + aad_len);
1872         sym_op->auth.digest.length = auth_tag_len;
1873         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1874                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1875         else
1876                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1877
1878         TEST_HEXDUMP(stdout, "digest:",
1879                 sym_op->auth.digest.data,
1880                 sym_op->auth.digest.length);
1881
1882         sym_op->auth.data.length = auth_len;
1883         sym_op->auth.data.offset = auth_offset;
1884
1885         return 0;
1886 }
1887
1888 static int
1889 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
1890                 const unsigned auth_tag_len,
1891                 const uint8_t *aad, const uint8_t aad_len,
1892                 unsigned data_pad_len,
1893                 enum rte_crypto_auth_operation op,
1894                 enum rte_crypto_auth_algorithm auth_algo,
1895                 enum rte_crypto_cipher_algorithm cipher_algo,
1896                 const uint8_t *iv, const uint8_t iv_len,
1897                 const unsigned cipher_len, const unsigned cipher_offset,
1898                 const unsigned auth_len, const unsigned auth_offset)
1899 {
1900         struct crypto_testsuite_params *ts_params = &testsuite_params;
1901         struct crypto_unittest_params *ut_params = &unittest_params;
1902
1903         unsigned iv_pad_len = 0;
1904         unsigned aad_buffer_len;
1905
1906         /* Generate Crypto op data structure */
1907         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1908                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1909         TEST_ASSERT_NOT_NULL(ut_params->op,
1910                         "Failed to allocate pktmbuf offload");
1911         /* Set crypto operation data parameters */
1912         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1913
1914         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1915
1916         /* set crypto operation source mbuf */
1917         sym_op->m_src = ut_params->ibuf;
1918
1919         /* digest */
1920         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1921                         ut_params->ibuf, auth_tag_len);
1922
1923         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1924                         "no room to append auth tag");
1925         ut_params->digest = sym_op->auth.digest.data;
1926         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1927                         ut_params->ibuf, data_pad_len);
1928         sym_op->auth.digest.length = auth_tag_len;
1929         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1930                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1931         else
1932                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1933
1934         TEST_HEXDUMP(stdout, "digest:",
1935                 sym_op->auth.digest.data,
1936                 sym_op->auth.digest.length);
1937
1938         /* aad */
1939         /*
1940         * Always allocate the aad up to the block size.
1941         * The cryptodev API calls out -
1942         *  - the array must be big enough to hold the AAD, plus any
1943         *   space to round this up to the nearest multiple of the
1944         *   block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1945         */
1946         if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1947                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1948         else
1949                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1950         sym_op->auth.aad.data =
1951                 (uint8_t *)rte_pktmbuf_prepend(
1952                         ut_params->ibuf, aad_buffer_len);
1953         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1954                         "no room to prepend aad");
1955         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1956                         ut_params->ibuf);
1957         sym_op->auth.aad.length = aad_len;
1958         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1959         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1960         TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1961
1962         /* iv */
1963         if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1964                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1965         else
1966                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1967         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1968                 ut_params->ibuf, iv_pad_len);
1969
1970         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1971         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1972         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1973         sym_op->cipher.iv.length = iv_pad_len;
1974         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1975         sym_op->cipher.data.length = cipher_len;
1976         sym_op->cipher.data.offset = cipher_offset + auth_offset;
1977         sym_op->auth.data.length = auth_len;
1978         sym_op->auth.data.offset = auth_offset + cipher_offset;
1979
1980         return 0;
1981 }
1982
1983 static int
1984 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
1985                 const uint8_t *iv, const uint8_t iv_len,
1986                 const uint8_t *aad, const uint8_t aad_len,
1987                 unsigned data_pad_len,
1988                 const unsigned cipher_len, const unsigned cipher_offset,
1989                 const unsigned auth_len, const unsigned auth_offset,
1990                 enum rte_crypto_auth_algorithm auth_algo,
1991                 enum rte_crypto_cipher_algorithm cipher_algo)
1992 {
1993         struct crypto_testsuite_params *ts_params = &testsuite_params;
1994         struct crypto_unittest_params *ut_params = &unittest_params;
1995
1996         unsigned iv_pad_len = 0;
1997         unsigned aad_buffer_len = 0;
1998
1999         /* Generate Crypto op data structure */
2000         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2001                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2002         TEST_ASSERT_NOT_NULL(ut_params->op,
2003                         "Failed to allocate pktmbuf offload");
2004
2005         /* Set crypto operation data parameters */
2006         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2007
2008         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2009
2010         /* set crypto operation source mbuf */
2011         sym_op->m_src = ut_params->ibuf;
2012
2013         /* digest */
2014         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2015                         ut_params->ibuf, auth_tag_len);
2016
2017         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2018                         "no room to append auth tag");
2019
2020         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2021                         ut_params->ibuf, data_pad_len);
2022         sym_op->auth.digest.length = auth_tag_len;
2023
2024         memset(sym_op->auth.digest.data, 0, auth_tag_len);
2025
2026         TEST_HEXDUMP(stdout, "digest:",
2027                         sym_op->auth.digest.data,
2028                         sym_op->auth.digest.length);
2029
2030         /* aad */
2031         /*
2032         * Always allocate the aad up to the block size.
2033         * The cryptodev API calls out -
2034         *  - the array must be big enough to hold the AAD, plus any
2035         *   space to round this up to the nearest multiple of the
2036         *   block size (8 bytes for KASUMI 16 bytes).
2037         */
2038         if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2039                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2040         else
2041                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2042         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2043         ut_params->ibuf, aad_buffer_len);
2044         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2045                                 "no room to prepend aad");
2046         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2047                                 ut_params->ibuf);
2048         sym_op->auth.aad.length = aad_len;
2049         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2050         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2051         TEST_HEXDUMP(stdout, "aad:",
2052                         sym_op->auth.aad.data, aad_len);
2053
2054         /* iv */
2055         if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2056                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2057         else
2058                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2059
2060         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2061                 ut_params->ibuf, iv_pad_len);
2062         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2063
2064         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2065         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2066         sym_op->cipher.iv.length = iv_pad_len;
2067
2068         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2069
2070         sym_op->cipher.data.length = cipher_len;
2071         sym_op->cipher.data.offset = auth_offset + cipher_offset;
2072
2073         sym_op->auth.data.length = auth_len;
2074         sym_op->auth.data.offset = auth_offset + cipher_offset;
2075
2076         return 0;
2077 }
2078
2079 static int
2080 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2081 {
2082         struct crypto_testsuite_params *ts_params = &testsuite_params;
2083         struct crypto_unittest_params *ut_params = &unittest_params;
2084
2085         int retval;
2086         unsigned plaintext_pad_len;
2087         unsigned plaintext_len;
2088         uint8_t *plaintext;
2089
2090         /* Create SNOW 3G session */
2091         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2092                         tdata->key.data, tdata->key.len,
2093                         tdata->aad.len, tdata->digest.len,
2094                         RTE_CRYPTO_AUTH_OP_GENERATE,
2095                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2096         if (retval < 0)
2097                 return retval;
2098
2099         /* alloc mbuf and set payload */
2100         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2101
2102         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2103         rte_pktmbuf_tailroom(ut_params->ibuf));
2104
2105         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2106         /* Append data which is padded to a multiple of */
2107         /* the algorithms block size */
2108         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2109         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2110                                 plaintext_pad_len);
2111         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2112
2113         /* Create SNOW 3G operation */
2114         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2115                         tdata->aad.data, tdata->aad.len,
2116                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2117                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2118                         tdata->validAuthLenInBits.len,
2119                         tdata->validAuthOffsetLenInBits.len);
2120         if (retval < 0)
2121                 return retval;
2122
2123         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2124                                 ut_params->op);
2125         ut_params->obuf = ut_params->op->sym->m_src;
2126         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2127         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2128                         + plaintext_pad_len + tdata->aad.len;
2129
2130         /* Validate obuf */
2131         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2132         ut_params->digest,
2133         tdata->digest.data,
2134         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2135         "SNOW 3G Generated auth tag not as expected");
2136
2137         return 0;
2138 }
2139
2140 static int
2141 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2142 {
2143         struct crypto_testsuite_params *ts_params = &testsuite_params;
2144         struct crypto_unittest_params *ut_params = &unittest_params;
2145
2146         int retval;
2147         unsigned plaintext_pad_len;
2148         unsigned plaintext_len;
2149         uint8_t *plaintext;
2150
2151         /* Create SNOW 3G session */
2152         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2153                                 tdata->key.data, tdata->key.len,
2154                                 tdata->aad.len, tdata->digest.len,
2155                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2156                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2157         if (retval < 0)
2158                 return retval;
2159         /* alloc mbuf and set payload */
2160         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2161
2162         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2163         rte_pktmbuf_tailroom(ut_params->ibuf));
2164
2165         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2166         /* Append data which is padded to a multiple of */
2167         /* the algorithms block size */
2168         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2169         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2170                                 plaintext_pad_len);
2171         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2172
2173         /* Create SNOW 3G operation */
2174         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2175                         tdata->digest.len,
2176                         tdata->aad.data, tdata->aad.len,
2177                         plaintext_pad_len,
2178                         RTE_CRYPTO_AUTH_OP_VERIFY,
2179                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2180                         tdata->validAuthLenInBits.len,
2181                         tdata->validAuthOffsetLenInBits.len);
2182         if (retval < 0)
2183                 return retval;
2184
2185         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2186                                 ut_params->op);
2187         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2188         ut_params->obuf = ut_params->op->sym->m_src;
2189         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2190                                 + plaintext_pad_len + tdata->aad.len;
2191
2192         /* Validate obuf */
2193         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2194                 return 0;
2195         else
2196                 return -1;
2197
2198         return 0;
2199 }
2200
2201 static int
2202 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2203 {
2204         struct crypto_testsuite_params *ts_params = &testsuite_params;
2205         struct crypto_unittest_params *ut_params = &unittest_params;
2206
2207         int retval;
2208         unsigned plaintext_pad_len;
2209         unsigned plaintext_len;
2210         uint8_t *plaintext;
2211
2212         /* Create KASUMI session */
2213         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2214                         tdata->key.data, tdata->key.len,
2215                         tdata->aad.len, tdata->digest.len,
2216                         RTE_CRYPTO_AUTH_OP_GENERATE,
2217                         RTE_CRYPTO_AUTH_KASUMI_F9);
2218         if (retval < 0)
2219                 return retval;
2220
2221         /* alloc mbuf and set payload */
2222         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2223
2224         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2225         rte_pktmbuf_tailroom(ut_params->ibuf));
2226
2227         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2228         /* Append data which is padded to a multiple of */
2229         /* the algorithms block size */
2230         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2231         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2232                                 plaintext_pad_len);
2233         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2234
2235         /* Create KASUMI operation */
2236         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2237                         tdata->aad.data, tdata->aad.len,
2238                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2239                         RTE_CRYPTO_AUTH_KASUMI_F9,
2240                         tdata->validAuthLenInBits.len,
2241                         tdata->validAuthOffsetLenInBits.len);
2242         if (retval < 0)
2243                 return retval;
2244
2245         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2246                                 ut_params->op);
2247         ut_params->obuf = ut_params->op->sym->m_src;
2248         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2249         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2250                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
2251
2252         /* Validate obuf */
2253         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2254         ut_params->digest,
2255         tdata->digest.data,
2256         DIGEST_BYTE_LENGTH_KASUMI_F9,
2257         "KASUMI Generated auth tag not as expected");
2258
2259         return 0;
2260 }
2261
2262 static int
2263 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2264 {
2265         struct crypto_testsuite_params *ts_params = &testsuite_params;
2266         struct crypto_unittest_params *ut_params = &unittest_params;
2267
2268         int retval;
2269         unsigned plaintext_pad_len;
2270         unsigned plaintext_len;
2271         uint8_t *plaintext;
2272
2273         /* Create KASUMI session */
2274         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2275                                 tdata->key.data, tdata->key.len,
2276                                 tdata->aad.len, tdata->digest.len,
2277                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2278                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2279         if (retval < 0)
2280                 return retval;
2281         /* alloc mbuf and set payload */
2282         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2283
2284         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2285         rte_pktmbuf_tailroom(ut_params->ibuf));
2286
2287         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2288         /* Append data which is padded to a multiple */
2289         /* of the algorithms block size */
2290         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2291         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2292                                 plaintext_pad_len);
2293         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2294
2295         /* Create KASUMI operation */
2296         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2297                         tdata->digest.len,
2298                         tdata->aad.data, tdata->aad.len,
2299                         plaintext_pad_len,
2300                         RTE_CRYPTO_AUTH_OP_VERIFY,
2301                         RTE_CRYPTO_AUTH_KASUMI_F9,
2302                         tdata->validAuthLenInBits.len,
2303                         tdata->validAuthOffsetLenInBits.len);
2304         if (retval < 0)
2305                 return retval;
2306
2307         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2308                                 ut_params->op);
2309         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2310         ut_params->obuf = ut_params->op->sym->m_src;
2311         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2312                                 + plaintext_pad_len + tdata->aad.len;
2313
2314         /* Validate obuf */
2315         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2316                 return 0;
2317         else
2318                 return -1;
2319
2320         return 0;
2321 }
2322
2323 static int
2324 test_snow3g_hash_generate_test_case_1(void)
2325 {
2326         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2327 }
2328
2329 static int
2330 test_snow3g_hash_generate_test_case_2(void)
2331 {
2332         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2333 }
2334
2335 static int
2336 test_snow3g_hash_generate_test_case_3(void)
2337 {
2338         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2339 }
2340
2341 static int
2342 test_snow3g_hash_generate_test_case_4(void)
2343 {
2344         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2345 }
2346
2347 static int
2348 test_snow3g_hash_generate_test_case_5(void)
2349 {
2350         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2351 }
2352
2353 static int
2354 test_snow3g_hash_generate_test_case_6(void)
2355 {
2356         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2357 }
2358
2359 static int
2360 test_snow3g_hash_verify_test_case_1(void)
2361 {
2362         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2363
2364 }
2365
2366 static int
2367 test_snow3g_hash_verify_test_case_2(void)
2368 {
2369         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2370 }
2371
2372 static int
2373 test_snow3g_hash_verify_test_case_3(void)
2374 {
2375         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2376 }
2377
2378 static int
2379 test_snow3g_hash_verify_test_case_4(void)
2380 {
2381         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2382 }
2383
2384 static int
2385 test_snow3g_hash_verify_test_case_5(void)
2386 {
2387         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2388 }
2389
2390 static int
2391 test_snow3g_hash_verify_test_case_6(void)
2392 {
2393         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2394 }
2395
2396 static int
2397 test_kasumi_hash_generate_test_case_1(void)
2398 {
2399         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2400 }
2401
2402 static int
2403 test_kasumi_hash_generate_test_case_2(void)
2404 {
2405         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2406 }
2407
2408 static int
2409 test_kasumi_hash_generate_test_case_3(void)
2410 {
2411         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2412 }
2413
2414 static int
2415 test_kasumi_hash_generate_test_case_4(void)
2416 {
2417         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2418 }
2419
2420 static int
2421 test_kasumi_hash_generate_test_case_5(void)
2422 {
2423         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2424 }
2425
2426 static int
2427 test_kasumi_hash_generate_test_case_6(void)
2428 {
2429         return test_kasumi_authentication(&kasumi_hash_test_case_6);
2430 }
2431
2432 static int
2433 test_kasumi_hash_verify_test_case_1(void)
2434 {
2435         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2436 }
2437
2438 static int
2439 test_kasumi_hash_verify_test_case_2(void)
2440 {
2441         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2442 }
2443
2444 static int
2445 test_kasumi_hash_verify_test_case_3(void)
2446 {
2447         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2448 }
2449
2450 static int
2451 test_kasumi_hash_verify_test_case_4(void)
2452 {
2453         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2454 }
2455
2456 static int
2457 test_kasumi_hash_verify_test_case_5(void)
2458 {
2459         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2460 }
2461
2462 static int
2463 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2464 {
2465         struct crypto_testsuite_params *ts_params = &testsuite_params;
2466         struct crypto_unittest_params *ut_params = &unittest_params;
2467
2468         int retval;
2469         uint8_t *plaintext, *ciphertext;
2470         unsigned plaintext_pad_len;
2471         unsigned plaintext_len;
2472
2473         /* Create KASUMI session */
2474         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2475                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2476                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2477                                         tdata->key.data, tdata->key.len);
2478         if (retval < 0)
2479                 return retval;
2480
2481         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2482
2483         /* Clear mbuf payload */
2484         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2485                rte_pktmbuf_tailroom(ut_params->ibuf));
2486
2487         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2488         /* Append data which is padded to a multiple */
2489         /* of the algorithms block size */
2490         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2491         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2492                                 plaintext_pad_len);
2493         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2494
2495         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2496
2497         /* Create KASUMI operation */
2498         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2499                                         tdata->plaintext.len,
2500                                         tdata->validCipherOffsetLenInBits.len,
2501                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2502         if (retval < 0)
2503                 return retval;
2504
2505         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2506                                                 ut_params->op);
2507         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2508
2509         ut_params->obuf = ut_params->op->sym->m_dst;
2510         if (ut_params->obuf)
2511                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2512                                 + tdata->iv.len;
2513         else
2514                 ciphertext = plaintext;
2515
2516         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2517
2518         /* Validate obuf */
2519         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2520                 ciphertext,
2521                 tdata->ciphertext.data,
2522                 tdata->validCipherLenInBits.len,
2523                 "KASUMI Ciphertext data not as expected");
2524         return 0;
2525 }
2526
2527 static int
2528 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2529 {
2530         struct crypto_testsuite_params *ts_params = &testsuite_params;
2531         struct crypto_unittest_params *ut_params = &unittest_params;
2532
2533         int retval;
2534         uint8_t *plaintext, *ciphertext;
2535         unsigned plaintext_pad_len;
2536         unsigned plaintext_len;
2537
2538         /* Create KASUMI session */
2539         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2540                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2541                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2542                                         tdata->key.data, tdata->key.len);
2543         if (retval < 0)
2544                 return retval;
2545
2546         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2547         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2548
2549         /* Clear mbuf payload */
2550         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2551                rte_pktmbuf_tailroom(ut_params->ibuf));
2552
2553         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2554         /* Append data which is padded to a multiple */
2555         /* of the algorithms block size */
2556         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2557         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2558                                 plaintext_pad_len);
2559         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2560         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2561
2562         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2563
2564         /* Create KASUMI operation */
2565         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2566                                         tdata->iv.len,
2567                                         tdata->plaintext.len,
2568                                         tdata->validCipherOffsetLenInBits.len,
2569                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2570         if (retval < 0)
2571                 return retval;
2572
2573         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2574                                                 ut_params->op);
2575         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2576
2577         ut_params->obuf = ut_params->op->sym->m_dst;
2578         if (ut_params->obuf)
2579                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2580                                 + tdata->iv.len;
2581         else
2582                 ciphertext = plaintext;
2583
2584         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2585
2586         /* Validate obuf */
2587         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2588                 ciphertext,
2589                 tdata->ciphertext.data,
2590                 tdata->validCipherLenInBits.len,
2591                 "KASUMI Ciphertext data not as expected");
2592         return 0;
2593 }
2594
2595 static int
2596 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2597 {
2598         struct crypto_testsuite_params *ts_params = &testsuite_params;
2599         struct crypto_unittest_params *ut_params = &unittest_params;
2600
2601         int retval;
2602         uint8_t *ciphertext, *plaintext;
2603         unsigned ciphertext_pad_len;
2604         unsigned ciphertext_len;
2605
2606         /* Create KASUMI session */
2607         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2608                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2609                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2610                                         tdata->key.data, tdata->key.len);
2611         if (retval < 0)
2612                 return retval;
2613
2614         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2615         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2616
2617         /* Clear mbuf payload */
2618         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2619                rte_pktmbuf_tailroom(ut_params->ibuf));
2620
2621         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2622         /* Append data which is padded to a multiple */
2623         /* of the algorithms block size */
2624         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2625         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2626                                 ciphertext_pad_len);
2627         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2628         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2629
2630         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2631
2632         /* Create KASUMI operation */
2633         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2634                                         tdata->iv.len,
2635                                         tdata->ciphertext.len,
2636                                         tdata->validCipherOffsetLenInBits.len,
2637                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2638         if (retval < 0)
2639                 return retval;
2640
2641         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2642                                                 ut_params->op);
2643         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2644
2645         ut_params->obuf = ut_params->op->sym->m_dst;
2646         if (ut_params->obuf)
2647                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2648                                 + tdata->iv.len;
2649         else
2650                 plaintext = ciphertext;
2651
2652         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2653
2654         /* Validate obuf */
2655         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2656                 plaintext,
2657                 tdata->plaintext.data,
2658                 tdata->validCipherLenInBits.len,
2659                 "KASUMI Plaintext data not as expected");
2660         return 0;
2661 }
2662
2663 static int
2664 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2665 {
2666         struct crypto_testsuite_params *ts_params = &testsuite_params;
2667         struct crypto_unittest_params *ut_params = &unittest_params;
2668
2669         int retval;
2670         uint8_t *ciphertext, *plaintext;
2671         unsigned ciphertext_pad_len;
2672         unsigned ciphertext_len;
2673
2674         /* Create KASUMI session */
2675         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2676                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2677                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2678                                         tdata->key.data, tdata->key.len);
2679         if (retval < 0)
2680                 return retval;
2681
2682         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2683
2684         /* Clear mbuf payload */
2685         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2686                rte_pktmbuf_tailroom(ut_params->ibuf));
2687
2688         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2689         /* Append data which is padded to a multiple */
2690         /* of the algorithms block size */
2691         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2692         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2693                                 ciphertext_pad_len);
2694         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2695
2696         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2697
2698         /* Create KASUMI operation */
2699         retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2700                                         tdata->iv.len,
2701                                         tdata->ciphertext.len,
2702                                         tdata->validCipherOffsetLenInBits.len,
2703                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2704         if (retval < 0)
2705                 return retval;
2706
2707         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2708                                                 ut_params->op);
2709         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2710
2711         ut_params->obuf = ut_params->op->sym->m_dst;
2712         if (ut_params->obuf)
2713                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2714                                 + tdata->iv.len;
2715         else
2716                 plaintext = ciphertext;
2717
2718         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2719
2720         /* Validate obuf */
2721         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2722                 plaintext,
2723                 tdata->plaintext.data,
2724                 tdata->validCipherLenInBits.len,
2725                 "KASUMI Plaintext data not as expected");
2726         return 0;
2727 }
2728
2729 static int
2730 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2731 {
2732         struct crypto_testsuite_params *ts_params = &testsuite_params;
2733         struct crypto_unittest_params *ut_params = &unittest_params;
2734
2735         int retval;
2736         uint8_t *plaintext, *ciphertext;
2737         unsigned plaintext_pad_len;
2738         unsigned plaintext_len;
2739
2740         /* Create SNOW 3G session */
2741         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2742                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2743                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2744                                         tdata->key.data, tdata->key.len);
2745         if (retval < 0)
2746                 return retval;
2747
2748         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2749
2750         /* Clear mbuf payload */
2751         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2752                rte_pktmbuf_tailroom(ut_params->ibuf));
2753
2754         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2755         /* Append data which is padded to a multiple of */
2756         /* the algorithms block size */
2757         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2758         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2759                                 plaintext_pad_len);
2760         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2761
2762         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2763
2764         /* Create SNOW 3G operation */
2765         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2766                                         tdata->validCipherLenInBits.len,
2767                                         tdata->validCipherOffsetLenInBits.len,
2768                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2769         if (retval < 0)
2770                 return retval;
2771
2772         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2773                                                 ut_params->op);
2774         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2775
2776         ut_params->obuf = ut_params->op->sym->m_dst;
2777         if (ut_params->obuf)
2778                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2779                                 + tdata->iv.len;
2780         else
2781                 ciphertext = plaintext;
2782
2783         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2784
2785         /* Validate obuf */
2786         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2787                 ciphertext,
2788                 tdata->ciphertext.data,
2789                 tdata->validDataLenInBits.len,
2790                 "SNOW 3G Ciphertext data not as expected");
2791         return 0;
2792 }
2793
2794
2795 static int
2796 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2797 {
2798         struct crypto_testsuite_params *ts_params = &testsuite_params;
2799         struct crypto_unittest_params *ut_params = &unittest_params;
2800         uint8_t *plaintext, *ciphertext;
2801
2802         int retval;
2803         unsigned plaintext_pad_len;
2804         unsigned plaintext_len;
2805
2806         /* Create SNOW 3G session */
2807         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2808                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2809                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2810                                         tdata->key.data, tdata->key.len);
2811         if (retval < 0)
2812                 return retval;
2813
2814         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2815         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2816
2817         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2818                         "Failed to allocate input buffer in mempool");
2819         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2820                         "Failed to allocate output buffer in mempool");
2821
2822         /* Clear mbuf payload */
2823         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2824                rte_pktmbuf_tailroom(ut_params->ibuf));
2825
2826         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2827         /* Append data which is padded to a multiple of */
2828         /* the algorithms block size */
2829         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2830         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2831                                 plaintext_pad_len);
2832         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2833         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2834
2835         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2836
2837         /* Create SNOW 3G operation */
2838         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2839                                         tdata->iv.len,
2840                                         tdata->validCipherLenInBits.len,
2841                                         tdata->validCipherOffsetLenInBits.len,
2842                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2843         if (retval < 0)
2844                 return retval;
2845
2846         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2847                                                 ut_params->op);
2848         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2849
2850         ut_params->obuf = ut_params->op->sym->m_dst;
2851         if (ut_params->obuf)
2852                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2853                                 + tdata->iv.len;
2854         else
2855                 ciphertext = plaintext;
2856
2857         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2858
2859         /* Validate obuf */
2860         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2861                 ciphertext,
2862                 tdata->ciphertext.data,
2863                 tdata->validDataLenInBits.len,
2864                 "SNOW 3G Ciphertext data not as expected");
2865         return 0;
2866 }
2867
2868 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2869 static void
2870 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2871 {
2872         uint8_t curr_byte, prev_byte;
2873         uint32_t length_in_bytes = ceil_byte_length(length + offset);
2874         uint8_t lower_byte_mask = (1 << offset) - 1;
2875         unsigned i;
2876
2877         prev_byte = buffer[0];
2878         buffer[0] >>= offset;
2879
2880         for (i = 1; i < length_in_bytes; i++) {
2881                 curr_byte = buffer[i];
2882                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2883                                 (curr_byte >> offset);
2884                 prev_byte = curr_byte;
2885         }
2886 }
2887
2888 static int
2889 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2890 {
2891         struct crypto_testsuite_params *ts_params = &testsuite_params;
2892         struct crypto_unittest_params *ut_params = &unittest_params;
2893         uint8_t *plaintext, *ciphertext;
2894         int retval;
2895         uint32_t plaintext_len;
2896         uint32_t plaintext_pad_len;
2897         uint8_t extra_offset = 4;
2898         uint8_t *expected_ciphertext_shifted;
2899
2900         /* Create SNOW 3G session */
2901         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2902                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2903                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2904                                         tdata->key.data, tdata->key.len);
2905         if (retval < 0)
2906                 return retval;
2907
2908         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2909         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2910
2911         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2912                         "Failed to allocate input buffer in mempool");
2913         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2914                         "Failed to allocate output buffer in mempool");
2915
2916         /* Clear mbuf payload */
2917         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2918                rte_pktmbuf_tailroom(ut_params->ibuf));
2919
2920         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2921         /*
2922          * Append data which is padded to a
2923          * multiple of the algorithms block size
2924          */
2925         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2926
2927         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2928                                                 plaintext_pad_len);
2929
2930         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2931
2932         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2933         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2934
2935 #ifdef RTE_APP_TEST_DEBUG
2936         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2937 #endif
2938         /* Create SNOW 3G operation */
2939         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2940                                         tdata->iv.len,
2941                                         tdata->validCipherLenInBits.len,
2942                                         tdata->validCipherOffsetLenInBits.len +
2943                                         extra_offset,
2944                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2945         if (retval < 0)
2946                 return retval;
2947
2948         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2949                                                 ut_params->op);
2950         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2951
2952         ut_params->obuf = ut_params->op->sym->m_dst;
2953         if (ut_params->obuf)
2954                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2955                                 + tdata->iv.len;
2956         else
2957                 ciphertext = plaintext;
2958
2959 #ifdef RTE_APP_TEST_DEBUG
2960         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2961 #endif
2962
2963         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
2964
2965         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2966                         "failed to reserve memory for ciphertext shifted\n");
2967
2968         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2969                         ceil_byte_length(tdata->ciphertext.len));
2970         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2971                         extra_offset);
2972         /* Validate obuf */
2973         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2974                 ciphertext,
2975                 expected_ciphertext_shifted,
2976                 tdata->validDataLenInBits.len,
2977                 extra_offset,
2978                 "SNOW 3G Ciphertext data not as expected");
2979         return 0;
2980 }
2981
2982 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2983 {
2984         struct crypto_testsuite_params *ts_params = &testsuite_params;
2985         struct crypto_unittest_params *ut_params = &unittest_params;
2986
2987         int retval;
2988
2989         uint8_t *plaintext, *ciphertext;
2990         unsigned ciphertext_pad_len;
2991         unsigned ciphertext_len;
2992
2993         /* Create SNOW 3G session */
2994         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2995                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2996                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2997                                         tdata->key.data, tdata->key.len);
2998         if (retval < 0)
2999                 return retval;
3000
3001         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3002
3003         /* Clear mbuf payload */
3004         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3005                rte_pktmbuf_tailroom(ut_params->ibuf));
3006
3007         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3008         /* Append data which is padded to a multiple of */
3009         /* the algorithms block size */
3010         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3011         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3012                                 ciphertext_pad_len);
3013         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3014
3015         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3016
3017         /* Create SNOW 3G operation */
3018         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3019                                         tdata->validCipherLenInBits.len,
3020                                         tdata->validCipherOffsetLenInBits.len,
3021                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3022         if (retval < 0)
3023                 return retval;
3024
3025         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3026                                                 ut_params->op);
3027         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3028         ut_params->obuf = ut_params->op->sym->m_dst;
3029         if (ut_params->obuf)
3030                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3031                                 + tdata->iv.len;
3032         else
3033                 plaintext = ciphertext;
3034
3035         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3036
3037         /* Validate obuf */
3038         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3039                                 tdata->plaintext.data,
3040                                 tdata->validDataLenInBits.len,
3041                                 "SNOW 3G Plaintext data not as expected");
3042         return 0;
3043 }
3044
3045 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3046 {
3047         struct crypto_testsuite_params *ts_params = &testsuite_params;
3048         struct crypto_unittest_params *ut_params = &unittest_params;
3049
3050         int retval;
3051
3052         uint8_t *plaintext, *ciphertext;
3053         unsigned ciphertext_pad_len;
3054         unsigned ciphertext_len;
3055
3056         /* Create SNOW 3G session */
3057         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3058                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3059                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3060                                         tdata->key.data, tdata->key.len);
3061         if (retval < 0)
3062                 return retval;
3063
3064         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3065         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3066
3067         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3068                         "Failed to allocate input buffer");
3069         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3070                         "Failed to allocate output buffer");
3071
3072         /* Clear mbuf payload */
3073         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3074                rte_pktmbuf_tailroom(ut_params->ibuf));
3075
3076         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3077                        rte_pktmbuf_tailroom(ut_params->obuf));
3078
3079         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3080         /* Append data which is padded to a multiple of */
3081         /* the algorithms block size */
3082         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3083         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3084                                 ciphertext_pad_len);
3085         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3086         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3087
3088         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3089
3090         /* Create SNOW 3G operation */
3091         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3092                                         tdata->iv.len,
3093                                         tdata->validCipherLenInBits.len,
3094                                         tdata->validCipherOffsetLenInBits.len,
3095                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3096         if (retval < 0)
3097                 return retval;
3098
3099         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3100                                                 ut_params->op);
3101         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3102         ut_params->obuf = ut_params->op->sym->m_dst;
3103         if (ut_params->obuf)
3104                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3105                                 + tdata->iv.len;
3106         else
3107                 plaintext = ciphertext;
3108
3109         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3110
3111         /* Validate obuf */
3112         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3113                                 tdata->plaintext.data,
3114                                 tdata->validDataLenInBits.len,
3115                                 "SNOW 3G Plaintext data not as expected");
3116         return 0;
3117 }
3118
3119 static int
3120 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3121 {
3122         struct crypto_testsuite_params *ts_params = &testsuite_params;
3123         struct crypto_unittest_params *ut_params = &unittest_params;
3124
3125         int retval;
3126
3127         uint8_t *plaintext, *ciphertext;
3128         unsigned plaintext_pad_len;
3129         unsigned plaintext_len;
3130
3131         /* Create SNOW 3G session */
3132         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3133                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3134                         RTE_CRYPTO_AUTH_OP_GENERATE,
3135                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3136                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3137                         tdata->key.data, tdata->key.len,
3138                         tdata->aad.len, tdata->digest.len);
3139         if (retval < 0)
3140                 return retval;
3141         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3142
3143         /* clear mbuf payload */
3144         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3145                         rte_pktmbuf_tailroom(ut_params->ibuf));
3146
3147         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3148         /* Append data which is padded to a multiple of */
3149         /* the algorithms block size */
3150         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3151         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3152                                 plaintext_pad_len);
3153         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3154
3155         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3156
3157         /* Create SNOW 3G operation */
3158         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3159                         tdata->digest.len, tdata->aad.data,
3160                         tdata->aad.len, /*tdata->plaintext.len,*/
3161                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3162                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3163                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3164                         tdata->iv.data, tdata->iv.len,
3165                         tdata->validCipherLenInBits.len,
3166                         tdata->validCipherOffsetLenInBits.len,
3167                         tdata->validAuthLenInBits.len,
3168                         tdata->validAuthOffsetLenInBits.len
3169                         );
3170         if (retval < 0)
3171                 return retval;
3172
3173         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3174                         ut_params->op);
3175         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3176         ut_params->obuf = ut_params->op->sym->m_src;
3177         if (ut_params->obuf)
3178                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3179                                 + tdata->iv.len + tdata->aad.len;
3180         else
3181                 ciphertext = plaintext;
3182
3183         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3184         /* Validate obuf */
3185         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3186                         ciphertext,
3187                         tdata->ciphertext.data,
3188                         tdata->validDataLenInBits.len,
3189                         "SNOW 3G Ciphertext data not as expected");
3190
3191         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3192             + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3193
3194         /* Validate obuf */
3195         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3196                         ut_params->digest,
3197                         tdata->digest.data,
3198                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3199                         "SNOW 3G Generated auth tag not as expected");
3200         return 0;
3201 }
3202 static int
3203 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
3204 {
3205         struct crypto_testsuite_params *ts_params = &testsuite_params;
3206         struct crypto_unittest_params *ut_params = &unittest_params;
3207
3208         int retval;
3209
3210         uint8_t *plaintext, *ciphertext;
3211         unsigned plaintext_pad_len;
3212         unsigned plaintext_len;
3213
3214         /* Create SNOW 3G session */
3215         retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
3216                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3217                         RTE_CRYPTO_AUTH_OP_GENERATE,
3218                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3219                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3220                         tdata->key.data, tdata->key.len,
3221                         tdata->aad.len, tdata->digest.len);
3222         if (retval < 0)
3223                 return retval;
3224
3225         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3226
3227         /* clear mbuf payload */
3228         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3229                         rte_pktmbuf_tailroom(ut_params->ibuf));
3230
3231         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3232         /* Append data which is padded to a multiple of */
3233         /* the algorithms block size */
3234         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3235         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3236                                 plaintext_pad_len);
3237         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3238
3239         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3240
3241         /* Create SNOW 3G operation */
3242         retval = create_wireless_algo_auth_cipher_operation(
3243                 tdata->digest.len,
3244                 tdata->iv.data, tdata->iv.len,
3245                 tdata->aad.data, tdata->aad.len,
3246                 plaintext_pad_len,
3247                 tdata->validCipherLenInBits.len,
3248                 tdata->validCipherOffsetLenInBits.len,
3249                 tdata->validAuthLenInBits.len,
3250                 tdata->validAuthOffsetLenInBits.len,
3251                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3252                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
3253         );
3254
3255         if (retval < 0)
3256                 return retval;
3257
3258         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3259                         ut_params->op);
3260         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3261         ut_params->obuf = ut_params->op->sym->m_src;
3262         if (ut_params->obuf)
3263                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3264                                 + tdata->aad.len + tdata->iv.len;
3265         else
3266                 ciphertext = plaintext;
3267
3268         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3269                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3270         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3271
3272         /* Validate obuf */
3273         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3274                 ciphertext,
3275                 tdata->ciphertext.data,
3276                 tdata->validDataLenInBits.len,
3277                 "SNOW 3G Ciphertext data not as expected");
3278
3279         /* Validate obuf */
3280         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3281                 ut_params->digest,
3282                 tdata->digest.data,
3283                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3284                 "SNOW 3G Generated auth tag not as expected");
3285         return 0;
3286 }
3287
3288 static int
3289 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
3290 {
3291         struct crypto_testsuite_params *ts_params = &testsuite_params;
3292         struct crypto_unittest_params *ut_params = &unittest_params;
3293
3294         int retval;
3295
3296         uint8_t *plaintext, *ciphertext;
3297         unsigned plaintext_pad_len;
3298         unsigned plaintext_len;
3299
3300         /* Create KASUMI session */
3301         retval = create_wireless_algo_auth_cipher_session(
3302                         ts_params->valid_devs[0],
3303                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3304                         RTE_CRYPTO_AUTH_OP_GENERATE,
3305                         RTE_CRYPTO_AUTH_KASUMI_F9,
3306                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3307                         tdata->key.data, tdata->key.len,
3308                         tdata->aad.len, tdata->digest.len);
3309         if (retval < 0)
3310                 return retval;
3311         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3312
3313         /* clear mbuf payload */
3314         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3315                         rte_pktmbuf_tailroom(ut_params->ibuf));
3316
3317         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3318         /* Append data which is padded to a multiple of */
3319         /* the algorithms block size */
3320         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3321         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3322                                 plaintext_pad_len);
3323         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3324
3325         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3326
3327         /* Create KASUMI operation */
3328         retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
3329                                 tdata->iv.data, tdata->iv.len,
3330                                 tdata->aad.data, tdata->aad.len,
3331                                 plaintext_pad_len,
3332                                 tdata->validCipherLenInBits.len,
3333                                 tdata->validCipherOffsetLenInBits.len,
3334                                 tdata->validAuthLenInBits.len,
3335                                 tdata->validAuthOffsetLenInBits.len,
3336                                 RTE_CRYPTO_AUTH_KASUMI_F9,
3337                                 RTE_CRYPTO_CIPHER_KASUMI_F8
3338                                 );
3339
3340         if (retval < 0)
3341                 return retval;
3342
3343         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3344                         ut_params->op);
3345         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3346         ut_params->obuf = ut_params->op->sym->m_src;
3347         if (ut_params->obuf)
3348                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3349                                 + tdata->iv.len + tdata->aad.len;
3350         else
3351                 ciphertext = plaintext;
3352
3353         /* Validate obuf */
3354         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3355                         ciphertext,
3356                         tdata->ciphertext.data,
3357                         tdata->validCipherLenInBits.len,
3358                         "KASUMI Ciphertext data not as expected");
3359         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3360             + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3361
3362         /* Validate obuf */
3363         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3364                         ut_params->digest,
3365                         tdata->digest.data,
3366                         DIGEST_BYTE_LENGTH_KASUMI_F9,
3367                         "KASUMI Generated auth tag not as expected");
3368         return 0;
3369 }
3370
3371 static int
3372 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
3373 {
3374         struct crypto_testsuite_params *ts_params = &testsuite_params;
3375         struct crypto_unittest_params *ut_params = &unittest_params;
3376
3377         int retval;
3378
3379         uint8_t *plaintext, *ciphertext;
3380         unsigned plaintext_pad_len;
3381         unsigned plaintext_len;
3382
3383         /* Create KASUMI session */
3384         retval = create_wireless_algo_cipher_auth_session(
3385                         ts_params->valid_devs[0],
3386                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3387                         RTE_CRYPTO_AUTH_OP_GENERATE,
3388                         RTE_CRYPTO_AUTH_KASUMI_F9,
3389                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3390                         tdata->key.data, tdata->key.len,
3391                         tdata->aad.len, tdata->digest.len);
3392         if (retval < 0)
3393                 return retval;
3394
3395         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3396
3397         /* clear mbuf payload */
3398         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3399                         rte_pktmbuf_tailroom(ut_params->ibuf));
3400
3401         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3402         /* Append data which is padded to a multiple of */
3403         /* the algorithms block size */
3404         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3405         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3406                                 plaintext_pad_len);
3407         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3408
3409         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3410
3411         /* Create KASUMI operation */
3412         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3413                                 tdata->digest.len, tdata->aad.data,
3414                                 tdata->aad.len,
3415                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3416                                 RTE_CRYPTO_AUTH_KASUMI_F9,
3417                                 RTE_CRYPTO_CIPHER_KASUMI_F8,
3418                                 tdata->iv.data, tdata->iv.len,
3419                                 tdata->validCipherLenInBits.len,
3420                                 tdata->validCipherOffsetLenInBits.len,
3421                                 tdata->validAuthLenInBits.len,
3422                                 tdata->validAuthOffsetLenInBits.len
3423                                 );
3424         if (retval < 0)
3425                 return retval;
3426
3427         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3428                         ut_params->op);
3429         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3430         ut_params->obuf = ut_params->op->sym->m_src;
3431         if (ut_params->obuf)
3432                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3433                                 + tdata->aad.len + tdata->iv.len;
3434         else
3435                 ciphertext = plaintext;
3436
3437         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3438                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3439
3440         /* Validate obuf */
3441         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3442                 ciphertext,
3443                 tdata->ciphertext.data,
3444                 tdata->validCipherLenInBits.len,
3445                 "KASUMI Ciphertext data not as expected");
3446
3447         /* Validate obuf */
3448         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3449                 ut_params->digest,
3450                 tdata->digest.data,
3451                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3452                 "KASUMI Generated auth tag not as expected");
3453         return 0;
3454 }
3455
3456 static int
3457 test_zuc_encryption(const struct zuc_test_data *tdata)
3458 {
3459         struct crypto_testsuite_params *ts_params = &testsuite_params;
3460         struct crypto_unittest_params *ut_params = &unittest_params;
3461
3462         int retval;
3463         uint8_t *plaintext, *ciphertext;
3464         unsigned plaintext_pad_len;
3465         unsigned plaintext_len;
3466
3467         /* Create ZUC session */
3468         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3469                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3470                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
3471                                         tdata->key.data, tdata->key.len);
3472         if (retval < 0)
3473                 return retval;
3474
3475         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3476
3477         /* Clear mbuf payload */
3478         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3479                rte_pktmbuf_tailroom(ut_params->ibuf));
3480
3481         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3482         /* Append data which is padded to a multiple */
3483         /* of the algorithms block size */
3484         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3485         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3486                                 plaintext_pad_len);
3487         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3488
3489         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3490
3491         /* Create ZUC operation */
3492         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3493                                         tdata->plaintext.len,
3494                                         tdata->validCipherOffsetLenInBits.len,
3495                                         RTE_CRYPTO_CIPHER_ZUC_EEA3);
3496         if (retval < 0)
3497                 return retval;
3498
3499         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3500                                                 ut_params->op);
3501         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3502
3503         ut_params->obuf = ut_params->op->sym->m_dst;
3504         if (ut_params->obuf)
3505                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3506                                 + tdata->iv.len;
3507         else
3508                 ciphertext = plaintext;
3509
3510         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3511
3512         /* Validate obuf */
3513         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3514                 ciphertext,
3515                 tdata->ciphertext.data,
3516                 tdata->validCipherLenInBits.len,
3517                 "ZUC Ciphertext data not as expected");
3518         return 0;
3519 }
3520
3521 static int
3522 test_zuc_authentication(const struct zuc_hash_test_data *tdata)
3523 {
3524         struct crypto_testsuite_params *ts_params = &testsuite_params;
3525         struct crypto_unittest_params *ut_params = &unittest_params;
3526
3527         int retval;
3528         unsigned plaintext_pad_len;
3529         unsigned plaintext_len;
3530         uint8_t *plaintext;
3531
3532         /* Create ZUC session */
3533         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3534                         tdata->key.data, tdata->key.len,
3535                         tdata->aad.len, tdata->digest.len,
3536                         RTE_CRYPTO_AUTH_OP_GENERATE,
3537                         RTE_CRYPTO_AUTH_ZUC_EIA3);
3538         if (retval < 0)
3539                 return retval;
3540
3541         /* alloc mbuf and set payload */
3542         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3543
3544         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3545         rte_pktmbuf_tailroom(ut_params->ibuf));
3546
3547         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3548         /* Append data which is padded to a multiple of */
3549         /* the algorithms block size */
3550         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3551         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3552                                 plaintext_pad_len);
3553         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3554
3555         /* Create ZUC operation */
3556         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3557                         tdata->aad.data, tdata->aad.len,
3558                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3559                         RTE_CRYPTO_AUTH_ZUC_EIA3,
3560                         tdata->validAuthLenInBits.len,
3561                         tdata->validAuthOffsetLenInBits.len);
3562         if (retval < 0)
3563                 return retval;
3564
3565         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3566                                 ut_params->op);
3567         ut_params->obuf = ut_params->op->sym->m_src;
3568         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3569         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3570                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
3571
3572         /* Validate obuf */
3573         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3574         ut_params->digest,
3575         tdata->digest.data,
3576         DIGEST_BYTE_LENGTH_KASUMI_F9,
3577         "ZUC Generated auth tag not as expected");
3578
3579         return 0;
3580 }
3581
3582 static int
3583 test_kasumi_encryption_test_case_1(void)
3584 {
3585         return test_kasumi_encryption(&kasumi_test_case_1);
3586 }
3587
3588 static int
3589 test_kasumi_encryption_test_case_1_oop(void)
3590 {
3591         return test_kasumi_encryption_oop(&kasumi_test_case_1);
3592 }
3593
3594 static int
3595 test_kasumi_encryption_test_case_2(void)
3596 {
3597         return test_kasumi_encryption(&kasumi_test_case_2);
3598 }
3599
3600 static int
3601 test_kasumi_encryption_test_case_3(void)
3602 {
3603         return test_kasumi_encryption(&kasumi_test_case_3);
3604 }
3605
3606 static int
3607 test_kasumi_encryption_test_case_4(void)
3608 {
3609         return test_kasumi_encryption(&kasumi_test_case_4);
3610 }
3611
3612 static int
3613 test_kasumi_encryption_test_case_5(void)
3614 {
3615         return test_kasumi_encryption(&kasumi_test_case_5);
3616 }
3617
3618 static int
3619 test_kasumi_decryption_test_case_1(void)
3620 {
3621         return test_kasumi_decryption(&kasumi_test_case_1);
3622 }
3623
3624 static int
3625 test_kasumi_decryption_test_case_1_oop(void)
3626 {
3627         return test_kasumi_decryption_oop(&kasumi_test_case_1);
3628 }
3629
3630 static int
3631 test_kasumi_decryption_test_case_2(void)
3632 {
3633         return test_kasumi_decryption(&kasumi_test_case_2);
3634 }
3635
3636 static int
3637 test_kasumi_decryption_test_case_3(void)
3638 {
3639         return test_kasumi_decryption(&kasumi_test_case_3);
3640 }
3641
3642 static int
3643 test_kasumi_decryption_test_case_4(void)
3644 {
3645         return test_kasumi_decryption(&kasumi_test_case_4);
3646 }
3647
3648 static int
3649 test_kasumi_decryption_test_case_5(void)
3650 {
3651         return test_kasumi_decryption(&kasumi_test_case_5);
3652 }
3653 static int
3654 test_snow3g_encryption_test_case_1(void)
3655 {
3656         return test_snow3g_encryption(&snow3g_test_case_1);
3657 }
3658
3659 static int
3660 test_snow3g_encryption_test_case_1_oop(void)
3661 {
3662         return test_snow3g_encryption_oop(&snow3g_test_case_1);
3663 }
3664
3665 static int
3666 test_snow3g_encryption_test_case_1_offset_oop(void)
3667 {
3668         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3669 }
3670
3671 static int
3672 test_snow3g_encryption_test_case_2(void)
3673 {
3674         return test_snow3g_encryption(&snow3g_test_case_2);
3675 }
3676
3677 static int
3678 test_snow3g_encryption_test_case_3(void)
3679 {
3680         return test_snow3g_encryption(&snow3g_test_case_3);
3681 }
3682
3683 static int
3684 test_snow3g_encryption_test_case_4(void)
3685 {
3686         return test_snow3g_encryption(&snow3g_test_case_4);
3687 }
3688
3689 static int
3690 test_snow3g_encryption_test_case_5(void)
3691 {
3692         return test_snow3g_encryption(&snow3g_test_case_5);
3693 }
3694
3695 static int
3696 test_snow3g_decryption_test_case_1(void)
3697 {
3698         return test_snow3g_decryption(&snow3g_test_case_1);
3699 }
3700
3701 static int
3702 test_snow3g_decryption_test_case_1_oop(void)
3703 {
3704         return test_snow3g_decryption_oop(&snow3g_test_case_1);
3705 }
3706
3707 static int
3708 test_snow3g_decryption_test_case_2(void)
3709 {
3710         return test_snow3g_decryption(&snow3g_test_case_2);
3711 }
3712
3713 static int
3714 test_snow3g_decryption_test_case_3(void)
3715 {
3716         return test_snow3g_decryption(&snow3g_test_case_3);
3717 }
3718
3719 static int
3720 test_snow3g_decryption_test_case_4(void)
3721 {
3722         return test_snow3g_decryption(&snow3g_test_case_4);
3723 }
3724
3725 static int
3726 test_snow3g_decryption_test_case_5(void)
3727 {
3728         return test_snow3g_decryption(&snow3g_test_case_5);
3729 }
3730 static int
3731 test_snow3g_cipher_auth_test_case_1(void)
3732 {
3733         return test_snow3g_cipher_auth(&snow3g_test_case_3);
3734 }
3735
3736 static int
3737 test_snow3g_auth_cipher_test_case_1(void)
3738 {
3739         return test_snow3g_auth_cipher(&snow3g_test_case_6);
3740 }
3741
3742 static int
3743 test_kasumi_auth_cipher_test_case_1(void)
3744 {
3745         return test_kasumi_auth_cipher(&kasumi_test_case_3);
3746 }
3747
3748 static int
3749 test_kasumi_cipher_auth_test_case_1(void)
3750 {
3751         return test_kasumi_cipher_auth(&kasumi_test_case_6);
3752 }
3753
3754 static int
3755 test_zuc_encryption_test_case_1(void)
3756 {
3757         return test_zuc_encryption(&zuc_test_case_1);
3758 }
3759
3760 static int
3761 test_zuc_encryption_test_case_2(void)
3762 {
3763         return test_zuc_encryption(&zuc_test_case_2);
3764 }
3765
3766 static int
3767 test_zuc_encryption_test_case_3(void)
3768 {
3769         return test_zuc_encryption(&zuc_test_case_3);
3770 }
3771
3772 static int
3773 test_zuc_encryption_test_case_4(void)
3774 {
3775         return test_zuc_encryption(&zuc_test_case_4);
3776 }
3777
3778 static int
3779 test_zuc_encryption_test_case_5(void)
3780 {
3781         return test_zuc_encryption(&zuc_test_case_5);
3782 }
3783
3784 static int
3785 test_zuc_hash_generate_test_case_1(void)
3786 {
3787         return test_zuc_authentication(&zuc_hash_test_case_1);
3788 }
3789
3790 static int
3791 test_zuc_hash_generate_test_case_2(void)
3792 {
3793         return test_zuc_authentication(&zuc_hash_test_case_2);
3794 }
3795
3796 static int
3797 test_zuc_hash_generate_test_case_3(void)
3798 {
3799         return test_zuc_authentication(&zuc_hash_test_case_3);
3800 }
3801
3802 static int
3803 test_zuc_hash_generate_test_case_4(void)
3804 {
3805         return test_zuc_authentication(&zuc_hash_test_case_4);
3806 }
3807
3808 static int
3809 test_zuc_hash_generate_test_case_5(void)
3810 {
3811         return test_zuc_authentication(&zuc_hash_test_case_5);
3812 }
3813
3814 static int
3815 test_3DES_chain_qat_all(void)
3816 {
3817         struct crypto_testsuite_params *ts_params = &testsuite_params;
3818         int status;
3819
3820         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3821                 ts_params->op_mpool, ts_params->valid_devs[0],
3822                 RTE_CRYPTODEV_QAT_SYM_PMD,
3823                 BLKCIPHER_3DES_CHAIN_TYPE);
3824
3825         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3826
3827         return TEST_SUCCESS;
3828 }
3829
3830 static int
3831 test_3DES_cipheronly_qat_all(void)
3832 {
3833         struct crypto_testsuite_params *ts_params = &testsuite_params;
3834         int status;
3835
3836         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3837                 ts_params->op_mpool, ts_params->valid_devs[0],
3838                 RTE_CRYPTODEV_QAT_SYM_PMD,
3839                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
3840
3841         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3842
3843         return TEST_SUCCESS;
3844 }
3845
3846 static int
3847 test_3DES_chain_openssl_all(void)
3848 {
3849         struct crypto_testsuite_params *ts_params = &testsuite_params;
3850         int status;
3851
3852         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3853                 ts_params->op_mpool, ts_params->valid_devs[0],
3854                 RTE_CRYPTODEV_OPENSSL_PMD,
3855                 BLKCIPHER_3DES_CHAIN_TYPE);
3856
3857         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3858
3859         return TEST_SUCCESS;
3860 }
3861
3862 static int
3863 test_3DES_cipheronly_openssl_all(void)
3864 {
3865         struct crypto_testsuite_params *ts_params = &testsuite_params;
3866         int status;
3867
3868         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3869                 ts_params->op_mpool, ts_params->valid_devs[0],
3870                 RTE_CRYPTODEV_OPENSSL_PMD,
3871                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
3872
3873         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3874
3875         return TEST_SUCCESS;
3876 }
3877
3878 /* ***** AES-GCM Tests ***** */
3879
3880 static int
3881 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3882                 const uint8_t *key, const uint8_t key_len,
3883                 const uint8_t aad_len, const uint8_t auth_len,
3884                 enum rte_crypto_auth_operation auth_op)
3885 {
3886         uint8_t cipher_key[key_len];
3887
3888         struct crypto_unittest_params *ut_params = &unittest_params;
3889
3890         memcpy(cipher_key, key, key_len);
3891
3892         /* Setup Cipher Parameters */
3893         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3894         ut_params->cipher_xform.next = NULL;
3895
3896         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3897         ut_params->auth_xform.auth.op = auth_op;
3898         ut_params->cipher_xform.cipher.op = op;
3899         ut_params->cipher_xform.cipher.key.data = cipher_key;
3900         ut_params->cipher_xform.cipher.key.length = key_len;
3901
3902         TEST_HEXDUMP(stdout, "key:", key, key_len);
3903
3904         /* Setup Authentication Parameters */
3905         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3906         ut_params->auth_xform.next = NULL;
3907
3908         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3909
3910         ut_params->auth_xform.auth.digest_length = auth_len;
3911         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3912         ut_params->auth_xform.auth.key.length = 0;
3913         ut_params->auth_xform.auth.key.data = NULL;
3914
3915         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3916                 ut_params->cipher_xform.next = &ut_params->auth_xform;
3917
3918                 /* Create Crypto session*/
3919                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3920                                 &ut_params->cipher_xform);
3921         } else {/* Create Crypto session*/
3922                 ut_params->auth_xform.next = &ut_params->cipher_xform;
3923                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3924                                 &ut_params->auth_xform);
3925         }
3926
3927         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3928
3929         return 0;
3930 }
3931
3932 static int
3933 create_gcm_operation(enum rte_crypto_cipher_operation op,
3934                 const uint8_t *auth_tag, const unsigned auth_tag_len,
3935                 const uint8_t *iv, const unsigned iv_len,
3936                 const uint8_t *aad, const unsigned aad_len,
3937                 const unsigned data_len, unsigned data_pad_len)
3938 {
3939         struct crypto_testsuite_params *ts_params = &testsuite_params;
3940         struct crypto_unittest_params *ut_params = &unittest_params;
3941
3942         unsigned iv_pad_len = 0, aad_buffer_len;
3943
3944         /* Generate Crypto op data structure */
3945         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3946                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3947         TEST_ASSERT_NOT_NULL(ut_params->op,
3948                         "Failed to allocate symmetric crypto operation struct");
3949
3950         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3951
3952         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3953                         ut_params->ibuf, auth_tag_len);
3954         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3955                         "no room to append digest");
3956         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3957                         ut_params->ibuf, data_pad_len);
3958         sym_op->auth.digest.length = auth_tag_len;
3959
3960         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3961                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3962                 TEST_HEXDUMP(stdout, "digest:",
3963                                 sym_op->auth.digest.data,
3964                                 sym_op->auth.digest.length);
3965         }
3966
3967         /* iv */
3968         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3969
3970         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3971                         ut_params->ibuf, iv_pad_len);
3972         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3973
3974         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3975         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3976         sym_op->cipher.iv.length = iv_len;
3977
3978         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3979
3980         /*
3981          * Always allocate the aad up to the block size.
3982          * The cryptodev API calls out -
3983          *  - the array must be big enough to hold the AAD, plus any
3984          *   space to round this up to the nearest multiple of the
3985          *   block size (16 bytes).
3986          */
3987         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3988
3989         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3990                         ut_params->ibuf, aad_buffer_len);
3991         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3992                         "no room to prepend aad");
3993         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3994                         ut_params->ibuf);
3995         sym_op->auth.aad.length = aad_len;
3996
3997         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3998         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3999
4000         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4001         TEST_HEXDUMP(stdout, "aad:",
4002                         sym_op->auth.aad.data, aad_len);
4003
4004         sym_op->cipher.data.length = data_len;
4005         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
4006
4007         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
4008         sym_op->auth.data.length = data_len;
4009
4010         return 0;
4011 }
4012
4013 static int
4014 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
4015 {
4016         struct crypto_testsuite_params *ts_params = &testsuite_params;
4017         struct crypto_unittest_params *ut_params = &unittest_params;
4018
4019         int retval;
4020
4021         uint8_t *plaintext, *ciphertext, *auth_tag;
4022         uint16_t plaintext_pad_len;
4023
4024         /* Create GCM session */
4025         retval = create_gcm_session(ts_params->valid_devs[0],
4026                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4027                         tdata->key.data, tdata->key.len,
4028                         tdata->aad.len, tdata->auth_tag.len,
4029                         RTE_CRYPTO_AUTH_OP_GENERATE);
4030         if (retval < 0)
4031                 return retval;
4032
4033
4034         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4035
4036         /* clear mbuf payload */
4037         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4038                         rte_pktmbuf_tailroom(ut_params->ibuf));
4039
4040         /*
4041          * Append data which is padded to a multiple
4042          * of the algorithms block size
4043          */
4044         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4045
4046         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4047                         plaintext_pad_len);
4048         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4049
4050         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4051
4052         /* Create GCM opertaion */
4053         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4054                         tdata->auth_tag.data, tdata->auth_tag.len,
4055                         tdata->iv.data, tdata->iv.len,
4056                         tdata->aad.data, tdata->aad.len,
4057                         tdata->plaintext.len, plaintext_pad_len);
4058         if (retval < 0)
4059                 return retval;
4060
4061         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4062
4063         ut_params->op->sym->m_src = ut_params->ibuf;
4064
4065         /* Process crypto operation */
4066         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4067                         ut_params->op), "failed to process sym crypto op");
4068
4069         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4070                         "crypto op processing failed");
4071
4072         if (ut_params->op->sym->m_dst) {
4073                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4074                                 uint8_t *);
4075                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4076                                 uint8_t *, plaintext_pad_len);
4077         } else {
4078                 ciphertext = plaintext;
4079                 auth_tag = plaintext + plaintext_pad_len;
4080         }
4081
4082         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4083         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4084
4085         /* Validate obuf */
4086         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4087                         ciphertext,
4088                         tdata->ciphertext.data,
4089                         tdata->ciphertext.len,
4090                         "GCM Ciphertext data not as expected");
4091
4092         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4093                         auth_tag,
4094                         tdata->auth_tag.data,
4095                         tdata->auth_tag.len,
4096                         "GCM Generated auth tag not as expected");
4097
4098         return 0;
4099
4100 }
4101
4102 static int
4103 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
4104 {
4105         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
4106 }
4107
4108 static int
4109 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
4110 {
4111         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
4112 }
4113
4114 static int
4115 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
4116 {
4117         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
4118 }
4119
4120 static int
4121 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
4122 {
4123         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
4124 }
4125
4126 static int
4127 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
4128 {
4129         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
4130 }
4131
4132 static int
4133 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
4134 {
4135         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
4136 }
4137
4138 static int
4139 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
4140 {
4141         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
4142 }
4143
4144 static int
4145 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
4146 {
4147         struct crypto_testsuite_params *ts_params = &testsuite_params;
4148         struct crypto_unittest_params *ut_params = &unittest_params;
4149
4150         int retval;
4151
4152         uint8_t *plaintext, *ciphertext;
4153         uint16_t ciphertext_pad_len;
4154
4155         /* Create GCM session */
4156         retval = create_gcm_session(ts_params->valid_devs[0],
4157                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4158                         tdata->key.data, tdata->key.len,
4159                         tdata->aad.len, tdata->auth_tag.len,
4160                         RTE_CRYPTO_AUTH_OP_VERIFY);
4161         if (retval < 0)
4162                 return retval;
4163
4164
4165         /* alloc mbuf and set payload */
4166         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4167
4168         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4169                         rte_pktmbuf_tailroom(ut_params->ibuf));
4170
4171         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4172
4173         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4174                         ciphertext_pad_len);
4175         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
4176
4177         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4178
4179         /* Create GCM opertaion */
4180         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
4181                         tdata->auth_tag.data, tdata->auth_tag.len,
4182                         tdata->iv.data, tdata->iv.len,
4183                         tdata->aad.data, tdata->aad.len,
4184                         tdata->ciphertext.len, ciphertext_pad_len);
4185         if (retval < 0)
4186                 return retval;
4187
4188
4189         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4190
4191         ut_params->op->sym->m_src = ut_params->ibuf;
4192
4193         /* Process crypto operation */
4194         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4195                         ut_params->op), "failed to process sym crypto op");
4196
4197         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4198                         "crypto op processing failed");
4199
4200         if (ut_params->op->sym->m_dst)
4201                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4202                                 uint8_t *);
4203         else
4204                 plaintext = ciphertext;
4205
4206         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
4207
4208         /* Validate obuf */
4209         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4210                         plaintext,
4211                         tdata->plaintext.data,
4212                         tdata->plaintext.len,
4213                         "GCM plaintext data not as expected");
4214
4215         TEST_ASSERT_EQUAL(ut_params->op->status,
4216                         RTE_CRYPTO_OP_STATUS_SUCCESS,
4217                         "GCM authentication failed");
4218         return 0;
4219 }
4220
4221 static int
4222 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
4223 {
4224         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
4225 }
4226
4227 static int
4228 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
4229 {
4230         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
4231 }
4232
4233 static int
4234 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
4235 {
4236         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
4237 }
4238
4239 static int
4240 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
4241 {
4242         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
4243 }
4244
4245 static int
4246 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
4247 {
4248         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
4249 }
4250
4251 static int
4252 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
4253 {
4254         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
4255 }
4256
4257 static int
4258 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
4259 {
4260         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
4261 }
4262
4263 static int
4264 test_stats(void)
4265 {
4266         struct crypto_testsuite_params *ts_params = &testsuite_params;
4267         struct rte_cryptodev_stats stats;
4268         struct rte_cryptodev *dev;
4269         cryptodev_stats_get_t temp_pfn;
4270
4271         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4272         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
4273                         &stats) == -ENODEV),
4274                 "rte_cryptodev_stats_get invalid dev failed");
4275         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
4276                 "rte_cryptodev_stats_get invalid Param failed");
4277         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
4278         temp_pfn = dev->dev_ops->stats_get;
4279         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
4280         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
4281                         == -ENOTSUP),
4282                 "rte_cryptodev_stats_get invalid Param failed");
4283         dev->dev_ops->stats_get = temp_pfn;
4284
4285         /* Test expected values */
4286         ut_setup();
4287         test_AES_CBC_HMAC_SHA1_encrypt_digest();
4288         ut_teardown();
4289         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4290                         &stats),
4291                 "rte_cryptodev_stats_get failed");
4292         TEST_ASSERT((stats.enqueued_count == 1),
4293                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4294         TEST_ASSERT((stats.dequeued_count == 1),
4295                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4296         TEST_ASSERT((stats.enqueue_err_count == 0),
4297                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4298         TEST_ASSERT((stats.dequeue_err_count == 0),
4299                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4300
4301         /* invalid device but should ignore and not reset device stats*/
4302         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
4303         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4304                         &stats),
4305                 "rte_cryptodev_stats_get failed");
4306         TEST_ASSERT((stats.enqueued_count == 1),
4307                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4308
4309         /* check that a valid reset clears stats */
4310         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4311         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4312                         &stats),
4313                                           "rte_cryptodev_stats_get failed");
4314         TEST_ASSERT((stats.enqueued_count == 0),
4315                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4316         TEST_ASSERT((stats.dequeued_count == 0),
4317                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4318
4319         return TEST_SUCCESS;
4320 }
4321
4322 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
4323                                    struct crypto_unittest_params *ut_params,
4324                                    enum rte_crypto_auth_operation op,
4325                                    const struct HMAC_MD5_vector *test_case)
4326 {
4327         uint8_t key[64];
4328
4329         memcpy(key, test_case->key.data, test_case->key.len);
4330
4331         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4332         ut_params->auth_xform.next = NULL;
4333         ut_params->auth_xform.auth.op = op;
4334
4335         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
4336
4337         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
4338         ut_params->auth_xform.auth.add_auth_data_length = 0;
4339         ut_params->auth_xform.auth.key.length = test_case->key.len;
4340         ut_params->auth_xform.auth.key.data = key;
4341
4342         ut_params->sess = rte_cryptodev_sym_session_create(
4343                 ts_params->valid_devs[0], &ut_params->auth_xform);
4344
4345         if (ut_params->sess == NULL)
4346                 return TEST_FAILED;
4347
4348         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4349
4350         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4351                         rte_pktmbuf_tailroom(ut_params->ibuf));
4352
4353         return 0;
4354 }
4355
4356 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
4357                               const struct HMAC_MD5_vector *test_case,
4358                               uint8_t **plaintext)
4359 {
4360         uint16_t plaintext_pad_len;
4361
4362         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4363
4364         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4365                                 16);
4366
4367         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4368                         plaintext_pad_len);
4369         memcpy(*plaintext, test_case->plaintext.data,
4370                         test_case->plaintext.len);
4371
4372         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4373                         ut_params->ibuf, MD5_DIGEST_LEN);
4374         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4375                         "no room to append digest");
4376         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4377                         ut_params->ibuf, plaintext_pad_len);
4378         sym_op->auth.digest.length = MD5_DIGEST_LEN;
4379
4380         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4381                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
4382                            test_case->auth_tag.len);
4383         }
4384
4385         sym_op->auth.data.offset = 0;
4386         sym_op->auth.data.length = test_case->plaintext.len;
4387
4388         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4389         ut_params->op->sym->m_src = ut_params->ibuf;
4390
4391         return 0;
4392 }
4393
4394 static int
4395 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
4396 {
4397         uint16_t plaintext_pad_len;
4398         uint8_t *plaintext, *auth_tag;
4399
4400         struct crypto_testsuite_params *ts_params = &testsuite_params;
4401         struct crypto_unittest_params *ut_params = &unittest_params;
4402
4403         if (MD5_HMAC_create_session(ts_params, ut_params,
4404                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
4405                 return TEST_FAILED;
4406
4407         /* Generate Crypto op data structure */
4408         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4409                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4410         TEST_ASSERT_NOT_NULL(ut_params->op,
4411                         "Failed to allocate symmetric crypto operation struct");
4412
4413         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4414                                 16);
4415
4416         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4417                 return TEST_FAILED;
4418
4419         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4420                         ut_params->op), "failed to process sym crypto op");
4421
4422         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4423                         "crypto op processing failed");
4424
4425         if (ut_params->op->sym->m_dst) {
4426                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4427                                 uint8_t *, plaintext_pad_len);
4428         } else {
4429                 auth_tag = plaintext + plaintext_pad_len;
4430         }
4431
4432         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4433                         auth_tag,
4434                         test_case->auth_tag.data,
4435                         test_case->auth_tag.len,
4436                         "HMAC_MD5 generated tag not as expected");
4437
4438         return TEST_SUCCESS;
4439 }
4440
4441 static int
4442 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
4443 {
4444         uint8_t *plaintext;
4445
4446         struct crypto_testsuite_params *ts_params = &testsuite_params;
4447         struct crypto_unittest_params *ut_params = &unittest_params;
4448
4449         if (MD5_HMAC_create_session(ts_params, ut_params,
4450                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
4451                 return TEST_FAILED;
4452         }
4453
4454         /* Generate Crypto op data structure */
4455         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4456                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4457         TEST_ASSERT_NOT_NULL(ut_params->op,
4458                         "Failed to allocate symmetric crypto operation struct");
4459
4460         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4461                 return TEST_FAILED;
4462
4463         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4464                         ut_params->op), "failed to process sym crypto op");
4465
4466         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4467                         "HMAC_MD5 crypto op processing failed");
4468
4469         return TEST_SUCCESS;
4470 }
4471
4472 static int
4473 test_MD5_HMAC_generate_case_1(void)
4474 {
4475         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
4476 }
4477
4478 static int
4479 test_MD5_HMAC_verify_case_1(void)
4480 {
4481         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
4482 }
4483
4484 static int
4485 test_MD5_HMAC_generate_case_2(void)
4486 {
4487         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
4488 }
4489
4490 static int
4491 test_MD5_HMAC_verify_case_2(void)
4492 {
4493         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
4494 }
4495
4496 static int
4497 test_multi_session(void)
4498 {
4499         struct crypto_testsuite_params *ts_params = &testsuite_params;
4500         struct crypto_unittest_params *ut_params = &unittest_params;
4501
4502         struct rte_cryptodev_info dev_info;
4503         struct rte_cryptodev_sym_session **sessions;
4504
4505         uint16_t i;
4506
4507         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
4508                         aes_cbc_key, hmac_sha512_key);
4509
4510
4511         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4512
4513         sessions = rte_malloc(NULL,
4514                         (sizeof(struct rte_cryptodev_sym_session *) *
4515                         dev_info.sym.max_nb_sessions) + 1, 0);
4516
4517         /* Create multiple crypto sessions*/
4518         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4519                 sessions[i] = rte_cryptodev_sym_session_create(
4520                                 ts_params->valid_devs[0],
4521                         &ut_params->auth_xform);
4522                 TEST_ASSERT_NOT_NULL(sessions[i],
4523                                 "Session creation failed at session number %u",
4524                                 i);
4525
4526                 /* Attempt to send a request on each session */
4527                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
4528                         sessions[i],
4529                         ut_params,
4530                         ts_params,
4531                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4532                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4533                         aes_cbc_iv),
4534                         "Failed to perform decrypt on request number %u.", i);
4535                 /* free crypto operation structure */
4536                 if (ut_params->op)
4537                         rte_crypto_op_free(ut_params->op);
4538
4539                 /*
4540                  * free mbuf - both obuf and ibuf are usually the same,
4541                  * so check if they point at the same address is necessary,
4542                  * to avoid freeing the mbuf twice.
4543                  */
4544                 if (ut_params->obuf) {
4545                         rte_pktmbuf_free(ut_params->obuf);
4546                         if (ut_params->ibuf == ut_params->obuf)
4547                                 ut_params->ibuf = 0;
4548                         ut_params->obuf = 0;
4549                 }
4550                 if (ut_params->ibuf) {
4551                         rte_pktmbuf_free(ut_params->ibuf);
4552                         ut_params->ibuf = 0;
4553                 }
4554         }
4555
4556         /* Next session create should fail */
4557         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4558                         &ut_params->auth_xform);
4559         TEST_ASSERT_NULL(sessions[i],
4560                         "Session creation succeeded unexpectedly!");
4561
4562         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4563                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4564                                 sessions[i]);
4565
4566         rte_free(sessions);
4567
4568         return TEST_SUCCESS;
4569 }
4570
4571 struct multi_session_params {
4572         struct crypto_unittest_params ut_params;
4573         uint8_t *cipher_key;
4574         uint8_t *hmac_key;
4575         const uint8_t *cipher;
4576         const uint8_t *digest;
4577         uint8_t *iv;
4578 };
4579
4580 #define MB_SESSION_NUMBER 3
4581
4582 static int
4583 test_multi_session_random_usage(void)
4584 {
4585         struct crypto_testsuite_params *ts_params = &testsuite_params;
4586         struct rte_cryptodev_info dev_info;
4587         struct rte_cryptodev_sym_session **sessions;
4588         uint32_t i, j;
4589         struct multi_session_params ut_paramz[] = {
4590
4591                 {
4592                         .cipher_key = ms_aes_cbc_key0,
4593                         .hmac_key = ms_hmac_key0,
4594                         .cipher = ms_aes_cbc_cipher0,
4595                         .digest = ms_hmac_digest0,
4596                         .iv = ms_aes_cbc_iv0
4597                 },
4598                 {
4599                         .cipher_key = ms_aes_cbc_key1,
4600                         .hmac_key = ms_hmac_key1,
4601                         .cipher = ms_aes_cbc_cipher1,
4602                         .digest = ms_hmac_digest1,
4603                         .iv = ms_aes_cbc_iv1
4604                 },
4605                 {
4606                         .cipher_key = ms_aes_cbc_key2,
4607                         .hmac_key = ms_hmac_key2,
4608                         .cipher = ms_aes_cbc_cipher2,
4609                         .digest = ms_hmac_digest2,
4610                         .iv = ms_aes_cbc_iv2
4611                 },
4612
4613         };
4614
4615         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4616
4617         sessions = rte_malloc(NULL,
4618                         (sizeof(struct rte_cryptodev_sym_session *)
4619                                         * dev_info.sym.max_nb_sessions) + 1, 0);
4620
4621         for (i = 0; i < MB_SESSION_NUMBER; i++) {
4622                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
4623                                 sizeof(struct crypto_unittest_params));
4624
4625                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
4626                                 &ut_paramz[i].ut_params,
4627                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
4628
4629                 /* Create multiple crypto sessions*/
4630                 sessions[i] = rte_cryptodev_sym_session_create(
4631                                 ts_params->valid_devs[0],
4632                                 &ut_paramz[i].ut_params.auth_xform);
4633
4634                 TEST_ASSERT_NOT_NULL(sessions[i],
4635                                 "Session creation failed at session number %u",
4636                                 i);
4637
4638         }
4639
4640         srand(time(NULL));
4641         for (i = 0; i < 40000; i++) {
4642
4643                 j = rand() % MB_SESSION_NUMBER;
4644
4645                 TEST_ASSERT_SUCCESS(
4646                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
4647                                         sessions[j],
4648                                         &ut_paramz[j].ut_params,
4649                                         ts_params, ut_paramz[j].cipher,
4650                                         ut_paramz[j].digest,
4651                                         ut_paramz[j].iv),
4652                         "Failed to perform decrypt on request number %u.", i);
4653
4654                 if (ut_paramz[j].ut_params.op)
4655                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
4656
4657                 /*
4658                  * free mbuf - both obuf and ibuf are usually the same,
4659                  * so check if they point at the same address is necessary,
4660                  * to avoid freeing the mbuf twice.
4661                  */
4662                 if (ut_paramz[j].ut_params.obuf) {
4663                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
4664                         if (ut_paramz[j].ut_params.ibuf
4665                                         == ut_paramz[j].ut_params.obuf)
4666                                 ut_paramz[j].ut_params.ibuf = 0;
4667                         ut_paramz[j].ut_params.obuf = 0;
4668                 }
4669                 if (ut_paramz[j].ut_params.ibuf) {
4670                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
4671                         ut_paramz[j].ut_params.ibuf = 0;
4672                 }
4673         }
4674
4675         for (i = 0; i < MB_SESSION_NUMBER; i++)
4676                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4677                                 sessions[i]);
4678
4679         rte_free(sessions);
4680
4681         return TEST_SUCCESS;
4682 }
4683
4684 static int
4685 test_null_cipher_only_operation(void)
4686 {
4687         struct crypto_testsuite_params *ts_params = &testsuite_params;
4688         struct crypto_unittest_params *ut_params = &unittest_params;
4689
4690         /* Generate test mbuf data and space for digest */
4691         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4692                         catch_22_quote, QUOTE_512_BYTES, 0);
4693
4694         /* Setup Cipher Parameters */
4695         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4696         ut_params->cipher_xform.next = NULL;
4697
4698         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4699         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4700
4701         /* Create Crypto session*/
4702         ut_params->sess = rte_cryptodev_sym_session_create(
4703                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4704         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4705
4706         /* Generate Crypto op data structure */
4707         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4708                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4709         TEST_ASSERT_NOT_NULL(ut_params->op,
4710                         "Failed to allocate symmetric crypto operation struct");
4711
4712         /* Set crypto operation data parameters */
4713         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4714
4715         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4716
4717         /* set crypto operation source mbuf */
4718         sym_op->m_src = ut_params->ibuf;
4719
4720         sym_op->cipher.data.offset = 0;
4721         sym_op->cipher.data.length = QUOTE_512_BYTES;
4722
4723         /* Process crypto operation */
4724         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4725                         ut_params->op);
4726         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4727
4728         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4729                         "crypto operation processing failed");
4730
4731         /* Validate obuf */
4732         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4733                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4734                         catch_22_quote,
4735                         QUOTE_512_BYTES,
4736                         "Ciphertext data not as expected");
4737
4738         return TEST_SUCCESS;
4739 }
4740
4741 static int
4742 test_null_auth_only_operation(void)
4743 {
4744         struct crypto_testsuite_params *ts_params = &testsuite_params;
4745         struct crypto_unittest_params *ut_params = &unittest_params;
4746
4747         /* Generate test mbuf data and space for digest */
4748         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4749                         catch_22_quote, QUOTE_512_BYTES, 0);
4750
4751         /* Setup HMAC Parameters */
4752         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4753         ut_params->auth_xform.next = NULL;
4754
4755         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4756         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4757
4758         /* Create Crypto session*/
4759         ut_params->sess = rte_cryptodev_sym_session_create(
4760                         ts_params->valid_devs[0], &ut_params->auth_xform);
4761         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4762
4763         /* Generate Crypto op data structure */
4764         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4765                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4766         TEST_ASSERT_NOT_NULL(ut_params->op,
4767                         "Failed to allocate symmetric crypto operation struct");
4768
4769         /* Set crypto operation data parameters */
4770         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4771
4772         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4773
4774         sym_op->m_src = ut_params->ibuf;
4775
4776         sym_op->auth.data.offset = 0;
4777         sym_op->auth.data.length = QUOTE_512_BYTES;
4778
4779         /* Process crypto operation */
4780         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4781                         ut_params->op);
4782         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4783
4784         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4785                         "crypto operation processing failed");
4786
4787         return TEST_SUCCESS;
4788 }
4789
4790 static int
4791 test_null_cipher_auth_operation(void)
4792 {
4793         struct crypto_testsuite_params *ts_params = &testsuite_params;
4794         struct crypto_unittest_params *ut_params = &unittest_params;
4795
4796         /* Generate test mbuf data and space for digest */
4797         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4798                         catch_22_quote, QUOTE_512_BYTES, 0);
4799
4800         /* Setup Cipher Parameters */
4801         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4802         ut_params->cipher_xform.next = &ut_params->auth_xform;
4803
4804         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4805         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4806
4807         /* Setup HMAC Parameters */
4808         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4809         ut_params->auth_xform.next = NULL;
4810
4811         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4812         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4813
4814         /* Create Crypto session*/
4815         ut_params->sess = rte_cryptodev_sym_session_create(
4816                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4817         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4818
4819         /* Generate Crypto op data structure */
4820         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4821                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4822         TEST_ASSERT_NOT_NULL(ut_params->op,
4823                         "Failed to allocate symmetric crypto operation struct");
4824
4825         /* Set crypto operation data parameters */
4826         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4827
4828         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4829
4830         sym_op->m_src = ut_params->ibuf;
4831
4832         sym_op->cipher.data.offset = 0;
4833         sym_op->cipher.data.length = QUOTE_512_BYTES;
4834
4835         sym_op->auth.data.offset = 0;
4836         sym_op->auth.data.length = QUOTE_512_BYTES;
4837
4838         /* Process crypto operation */
4839         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4840                         ut_params->op);
4841         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4842
4843         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4844                         "crypto operation processing failed");
4845
4846         /* Validate obuf */
4847         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4848                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4849                         catch_22_quote,
4850                         QUOTE_512_BYTES,
4851                         "Ciphertext data not as expected");
4852
4853         return TEST_SUCCESS;
4854 }
4855
4856 static int
4857 test_null_auth_cipher_operation(void)
4858 {
4859         struct crypto_testsuite_params *ts_params = &testsuite_params;
4860         struct crypto_unittest_params *ut_params = &unittest_params;
4861
4862         /* Generate test mbuf data and space for digest */
4863         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4864                         catch_22_quote, QUOTE_512_BYTES, 0);
4865
4866         /* Setup Cipher Parameters */
4867         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4868         ut_params->cipher_xform.next = NULL;
4869
4870         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4871         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4872
4873         /* Setup HMAC Parameters */
4874         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4875         ut_params->auth_xform.next = &ut_params->cipher_xform;
4876
4877         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4878         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4879
4880         /* Create Crypto session*/
4881         ut_params->sess = rte_cryptodev_sym_session_create(
4882                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4883         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4884
4885         /* Generate Crypto op data structure */
4886         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4887                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4888         TEST_ASSERT_NOT_NULL(ut_params->op,
4889                         "Failed to allocate symmetric crypto operation struct");
4890
4891         /* Set crypto operation data parameters */
4892         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4893
4894         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4895
4896         sym_op->m_src = ut_params->ibuf;
4897
4898         sym_op->cipher.data.offset = 0;
4899         sym_op->cipher.data.length = QUOTE_512_BYTES;
4900
4901         sym_op->auth.data.offset = 0;
4902         sym_op->auth.data.length = QUOTE_512_BYTES;
4903
4904         /* Process crypto operation */
4905         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4906                         ut_params->op);
4907         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4908
4909         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4910                         "crypto operation processing failed");
4911
4912         /* Validate obuf */
4913         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4914                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4915                         catch_22_quote,
4916                         QUOTE_512_BYTES,
4917                         "Ciphertext data not as expected");
4918
4919         return TEST_SUCCESS;
4920 }
4921
4922
4923 static int
4924 test_null_invalid_operation(void)
4925 {
4926         struct crypto_testsuite_params *ts_params = &testsuite_params;
4927         struct crypto_unittest_params *ut_params = &unittest_params;
4928
4929         /* Setup Cipher Parameters */
4930         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4931         ut_params->cipher_xform.next = NULL;
4932
4933         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4934         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4935
4936         /* Create Crypto session*/
4937         ut_params->sess = rte_cryptodev_sym_session_create(
4938                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4939         TEST_ASSERT_NULL(ut_params->sess,
4940                         "Session creation succeeded unexpectedly");
4941
4942
4943         /* Setup HMAC Parameters */
4944         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4945         ut_params->auth_xform.next = NULL;
4946
4947         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4948         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4949
4950         /* Create Crypto session*/
4951         ut_params->sess = rte_cryptodev_sym_session_create(
4952                         ts_params->valid_devs[0], &ut_params->auth_xform);
4953         TEST_ASSERT_NULL(ut_params->sess,
4954                         "Session creation succeeded unexpectedly");
4955
4956         return TEST_SUCCESS;
4957 }
4958
4959
4960 #define NULL_BURST_LENGTH (32)
4961
4962 static int
4963 test_null_burst_operation(void)
4964 {
4965         struct crypto_testsuite_params *ts_params = &testsuite_params;
4966         struct crypto_unittest_params *ut_params = &unittest_params;
4967
4968         unsigned i, burst_len = NULL_BURST_LENGTH;
4969
4970         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4971         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4972
4973         /* Setup Cipher Parameters */
4974         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4975         ut_params->cipher_xform.next = &ut_params->auth_xform;
4976
4977         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4978         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4979
4980         /* Setup HMAC Parameters */
4981         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4982         ut_params->auth_xform.next = NULL;
4983
4984         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4985         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4986
4987         /* Create Crypto session*/
4988         ut_params->sess = rte_cryptodev_sym_session_create(
4989                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4990         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4991
4992         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4993                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4994                         burst_len, "failed to generate burst of crypto ops");
4995
4996         /* Generate an operation for each mbuf in burst */
4997         for (i = 0; i < burst_len; i++) {
4998                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4999
5000                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
5001
5002                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
5003                                 sizeof(unsigned));
5004                 *data = i;
5005
5006                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
5007
5008                 burst[i]->sym->m_src = m;
5009         }
5010
5011         /* Process crypto operation */
5012         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
5013                         0, burst, burst_len),
5014                         burst_len,
5015                         "Error enqueuing burst");
5016
5017         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
5018                         0, burst_dequeued, burst_len),
5019                         burst_len,
5020                         "Error dequeuing burst");
5021
5022
5023         for (i = 0; i < burst_len; i++) {
5024                 TEST_ASSERT_EQUAL(
5025                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
5026                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
5027                                         uint32_t *),
5028                         "data not as expected");
5029
5030                 rte_pktmbuf_free(burst[i]->sym->m_src);
5031                 rte_crypto_op_free(burst[i]);
5032         }
5033
5034         return TEST_SUCCESS;
5035 }
5036
5037 static void
5038 generate_gmac_large_plaintext(uint8_t *data)
5039 {
5040         uint16_t i;
5041
5042         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
5043                 memcpy(&data[i], &data[0], 32);
5044 }
5045
5046 static int
5047 create_gmac_operation(enum rte_crypto_auth_operation op,
5048                 const struct gmac_test_data *tdata)
5049 {
5050         struct crypto_testsuite_params *ts_params = &testsuite_params;
5051         struct crypto_unittest_params *ut_params = &unittest_params;
5052         struct rte_crypto_sym_op *sym_op;
5053
5054         unsigned iv_pad_len;
5055         unsigned aad_pad_len;
5056
5057         iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
5058         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5059
5060         /*
5061          * Runtime generate the large plain text instead of use hard code
5062          * plain text vector. It is done to avoid create huge source file
5063          * with the test vector.
5064          */
5065         if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
5066                 generate_gmac_large_plaintext(tdata->aad.data);
5067
5068         /* Generate Crypto op data structure */
5069         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5070                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5071         TEST_ASSERT_NOT_NULL(ut_params->op,
5072                         "Failed to allocate symmetric crypto operation struct");
5073
5074         sym_op = ut_params->op->sym;
5075         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5076                         aad_pad_len);
5077         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
5078                         "no room to append aad");
5079
5080         sym_op->auth.aad.length = tdata->aad.len;
5081         sym_op->auth.aad.phys_addr =
5082                         rte_pktmbuf_mtophys(ut_params->ibuf);
5083         memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
5084
5085         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5086                         ut_params->ibuf, tdata->gmac_tag.len);
5087         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5088                         "no room to append digest");
5089
5090         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5091                         ut_params->ibuf, aad_pad_len);
5092         sym_op->auth.digest.length = tdata->gmac_tag.len;
5093
5094         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5095                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
5096                                 tdata->gmac_tag.len);
5097                 TEST_HEXDUMP(stdout, "digest:",
5098                                 sym_op->auth.digest.data,
5099                                 sym_op->auth.digest.length);
5100         }
5101
5102         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5103                         ut_params->ibuf, iv_pad_len);
5104         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5105
5106         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
5107         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5108         sym_op->cipher.iv.length = tdata->iv.len;
5109
5110         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
5111
5112         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
5113
5114         sym_op->cipher.data.length = 0;
5115         sym_op->cipher.data.offset = 0;
5116
5117         sym_op->auth.data.offset = 0;
5118         sym_op->auth.data.length = 0;
5119
5120         return 0;
5121 }
5122
5123 static int create_gmac_session(uint8_t dev_id,
5124                 enum rte_crypto_cipher_operation op,
5125                 const struct gmac_test_data *tdata,
5126                 enum rte_crypto_auth_operation auth_op)
5127 {
5128         uint8_t cipher_key[tdata->key.len];
5129
5130         struct crypto_unittest_params *ut_params = &unittest_params;
5131
5132         memcpy(cipher_key, tdata->key.data, tdata->key.len);
5133
5134         /* For GMAC we setup cipher parameters */
5135         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5136         ut_params->cipher_xform.next = NULL;
5137         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
5138         ut_params->cipher_xform.cipher.op = op;
5139         ut_params->cipher_xform.cipher.key.data = cipher_key;
5140         ut_params->cipher_xform.cipher.key.length = tdata->key.len;
5141
5142         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5143         ut_params->auth_xform.next = NULL;
5144
5145         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
5146         ut_params->auth_xform.auth.op = auth_op;
5147         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
5148         ut_params->auth_xform.auth.add_auth_data_length = 0;
5149         ut_params->auth_xform.auth.key.length = 0;
5150         ut_params->auth_xform.auth.key.data = NULL;
5151
5152         ut_params->cipher_xform.next = &ut_params->auth_xform;
5153
5154         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5155                         &ut_params->cipher_xform);
5156
5157         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5158
5159         return 0;
5160 }
5161
5162 static int
5163 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
5164 {
5165         struct crypto_testsuite_params *ts_params = &testsuite_params;
5166         struct crypto_unittest_params *ut_params = &unittest_params;
5167
5168         int retval;
5169
5170         uint8_t *auth_tag, *p;
5171         uint16_t aad_pad_len;
5172
5173         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5174                               "No GMAC length in the source data");
5175
5176         retval = create_gmac_session(ts_params->valid_devs[0],
5177                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5178                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
5179
5180         if (retval < 0)
5181                 return retval;
5182
5183         if (tdata->aad.len > MBUF_SIZE)
5184                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5185         else
5186                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5187         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5188                         "Failed to allocate input buffer in mempool");
5189
5190         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5191                         rte_pktmbuf_tailroom(ut_params->ibuf));
5192
5193         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5194
5195         p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
5196
5197         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
5198                         tdata);
5199
5200         if (retval < 0)
5201                 return retval;
5202
5203         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5204
5205         ut_params->op->sym->m_src = ut_params->ibuf;
5206
5207         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5208                         ut_params->op), "failed to process sym crypto op");
5209
5210         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5211                         "crypto op processing failed");
5212
5213         if (ut_params->op->sym->m_dst) {
5214                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5215                                 uint8_t *, aad_pad_len);
5216         } else {
5217                 auth_tag = p + aad_pad_len;
5218         }
5219
5220         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
5221
5222         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5223                         auth_tag,
5224                         tdata->gmac_tag.data,
5225                         tdata->gmac_tag.len,
5226                         "GMAC Generated auth tag not as expected");
5227
5228         return 0;
5229 }
5230
5231 static int
5232 test_AES_GMAC_authentication_test_case_1(void)
5233 {
5234         return test_AES_GMAC_authentication(&gmac_test_case_1);
5235 }
5236
5237 static int
5238 test_AES_GMAC_authentication_test_case_2(void)
5239 {
5240         return test_AES_GMAC_authentication(&gmac_test_case_2);
5241 }
5242
5243 static int
5244 test_AES_GMAC_authentication_test_case_3(void)
5245 {
5246         return test_AES_GMAC_authentication(&gmac_test_case_3);
5247 }
5248
5249 static int
5250 test_AES_GMAC_authentication_test_case_4(void)
5251 {
5252         return test_AES_GMAC_authentication(&gmac_test_case_4);
5253 }
5254
5255 static int
5256 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
5257 {
5258         struct crypto_testsuite_params *ts_params = &testsuite_params;
5259         struct crypto_unittest_params *ut_params = &unittest_params;
5260         int retval;
5261
5262         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5263                               "No GMAC length in the source data");
5264
5265         retval = create_gmac_session(ts_params->valid_devs[0],
5266                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
5267                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
5268
5269         if (retval < 0)
5270                 return retval;
5271
5272         if (tdata->aad.len > MBUF_SIZE)
5273                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5274         else
5275                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5276         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5277                         "Failed to allocate input buffer in mempool");
5278
5279         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5280                         rte_pktmbuf_tailroom(ut_params->ibuf));
5281
5282         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
5283                         tdata);
5284
5285         if (retval < 0)
5286                 return retval;
5287
5288         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5289
5290         ut_params->op->sym->m_src = ut_params->ibuf;
5291
5292         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5293                         ut_params->op), "failed to process sym crypto op");
5294
5295         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5296                         "crypto op processing failed");
5297
5298         return 0;
5299
5300 }
5301
5302 static int
5303 test_AES_GMAC_authentication_verify_test_case_1(void)
5304 {
5305         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
5306 }
5307
5308 static int
5309 test_AES_GMAC_authentication_verify_test_case_2(void)
5310 {
5311         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
5312 }
5313
5314 static int
5315 test_AES_GMAC_authentication_verify_test_case_3(void)
5316 {
5317         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
5318 }
5319
5320 static int
5321 test_AES_GMAC_authentication_verify_test_case_4(void)
5322 {
5323         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
5324 }
5325
5326 struct test_crypto_vector {
5327         enum rte_crypto_cipher_algorithm crypto_algo;
5328
5329         struct {
5330                 uint8_t data[64];
5331                 unsigned int len;
5332         } cipher_key;
5333
5334         struct {
5335                 uint8_t data[64];
5336                 unsigned int len;
5337         } iv;
5338
5339         struct {
5340                 const uint8_t *data;
5341                 unsigned int len;
5342         } plaintext;
5343
5344         struct {
5345                 const uint8_t *data;
5346                 unsigned int len;
5347         } ciphertext;
5348
5349         enum rte_crypto_auth_algorithm auth_algo;
5350
5351         struct {
5352                 uint8_t data[128];
5353                 unsigned int len;
5354         } auth_key;
5355
5356         struct {
5357                 const uint8_t *data;
5358                 unsigned int len;
5359         } aad;
5360
5361         struct {
5362                 uint8_t data[128];
5363                 unsigned int len;
5364         } digest;
5365 };
5366
5367 static const struct test_crypto_vector
5368 hmac_sha1_test_crypto_vector = {
5369         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5370         .plaintext = {
5371                 .data = plaintext_hash,
5372                 .len = 512
5373         },
5374         .auth_key = {
5375                 .data = {
5376                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5377                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5378                         0xDE, 0xF4, 0xDE, 0xAD
5379                 },
5380                 .len = 20
5381         },
5382         .digest = {
5383                 .data = {
5384                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
5385                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
5386                         0x3F, 0x91, 0x64, 0x59
5387                 },
5388                 .len = 20
5389         }
5390 };
5391
5392 static const struct test_crypto_vector
5393 aes128_gmac_test_vector = {
5394         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
5395         .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
5396         .aad = {
5397                 .data = plaintext_hash,
5398                 .len = 512
5399         },
5400         .iv = {
5401                 .data = {
5402                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5403                         0x08, 0x09, 0x0A, 0x0B
5404                 },
5405                 .len = 12
5406         },
5407         .cipher_key = {
5408                 .data = {
5409                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5410                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
5411                 },
5412                 .len = 16
5413         },
5414         .digest = {
5415                 .data = {
5416                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
5417                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
5418                 },
5419                 .len = 16
5420         }
5421 };
5422
5423 static const struct test_crypto_vector
5424 aes128cbc_hmac_sha1_test_vector = {
5425         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
5426         .cipher_key = {
5427                 .data = {
5428                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
5429                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
5430                 },
5431                 .len = 16
5432         },
5433         .iv = {
5434                 .data = {
5435                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5436                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
5437                 },
5438                 .len = 16
5439         },
5440         .plaintext = {
5441                 .data = plaintext_hash,
5442                 .len = 512
5443         },
5444         .ciphertext = {
5445                 .data = ciphertext512_aes128cbc,
5446                 .len = 512
5447         },
5448         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5449         .auth_key = {
5450                 .data = {
5451                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5452                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5453                         0xDE, 0xF4, 0xDE, 0xAD
5454                 },
5455                 .len = 20
5456         },
5457         .digest = {
5458                 .data = {
5459                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
5460                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5461                         0x18, 0x8C, 0x1D, 0x32
5462                 },
5463                 .len = 20
5464         }
5465 };
5466
5467 static void
5468 data_corruption(uint8_t *data)
5469 {
5470         data[0] += 1;
5471 }
5472
5473 static void
5474 tag_corruption(uint8_t *data, unsigned int tag_offset)
5475 {
5476         data[tag_offset] += 1;
5477 }
5478
5479 static int
5480 create_auth_session(struct crypto_unittest_params *ut_params,
5481                 uint8_t dev_id,
5482                 const struct test_crypto_vector *reference,
5483                 enum rte_crypto_auth_operation auth_op)
5484 {
5485         uint8_t auth_key[reference->auth_key.len + 1];
5486
5487         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5488
5489         /* Setup Authentication Parameters */
5490         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5491         ut_params->auth_xform.auth.op = auth_op;
5492         ut_params->auth_xform.next = NULL;
5493         ut_params->auth_xform.auth.algo = reference->auth_algo;
5494         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5495         ut_params->auth_xform.auth.key.data = auth_key;
5496         ut_params->auth_xform.auth.digest_length = reference->digest.len;
5497         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5498
5499         /* Create Crypto session*/
5500         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5501                                 &ut_params->auth_xform);
5502
5503         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5504
5505         return 0;
5506 }
5507
5508 static int
5509 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
5510                 uint8_t dev_id,
5511                 const struct test_crypto_vector *reference,
5512                 enum rte_crypto_auth_operation auth_op,
5513                 enum rte_crypto_cipher_operation cipher_op)
5514 {
5515         uint8_t cipher_key[reference->cipher_key.len + 1];
5516         uint8_t auth_key[reference->auth_key.len + 1];
5517
5518         memcpy(cipher_key, reference->cipher_key.data,
5519                         reference->cipher_key.len);
5520         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5521
5522         /* Setup Authentication Parameters */
5523         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5524         ut_params->auth_xform.auth.op = auth_op;
5525         ut_params->auth_xform.next = &ut_params->cipher_xform;
5526         ut_params->auth_xform.auth.algo = reference->auth_algo;
5527         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5528         ut_params->auth_xform.auth.key.data = auth_key;
5529         ut_params->auth_xform.auth.digest_length = reference->digest.len;
5530         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5531
5532         /* Setup Cipher Parameters */
5533         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5534         ut_params->cipher_xform.next = NULL;
5535         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
5536         ut_params->cipher_xform.cipher.op = cipher_op;
5537         ut_params->cipher_xform.cipher.key.data = cipher_key;
5538         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
5539
5540         /* Create Crypto session*/
5541         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5542                                 &ut_params->auth_xform);
5543
5544         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5545
5546         return 0;
5547 }
5548
5549 static int
5550 create_auth_operation(struct crypto_testsuite_params *ts_params,
5551                 struct crypto_unittest_params *ut_params,
5552                 const struct test_crypto_vector *reference,
5553                 unsigned int auth_generate)
5554 {
5555         /* Generate Crypto op data structure */
5556         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5557                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5558         TEST_ASSERT_NOT_NULL(ut_params->op,
5559                         "Failed to allocate pktmbuf offload");
5560
5561         /* Set crypto operation data parameters */
5562         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5563
5564         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5565
5566         /* set crypto operation source mbuf */
5567         sym_op->m_src = ut_params->ibuf;
5568
5569         /* digest */
5570         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5571                         ut_params->ibuf, reference->digest.len);
5572
5573         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5574                         "no room to append auth tag");
5575
5576         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5577                         ut_params->ibuf, reference->plaintext.len);
5578         sym_op->auth.digest.length = reference->digest.len;
5579
5580         if (auth_generate)
5581                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5582         else
5583                 memcpy(sym_op->auth.digest.data,
5584                                 reference->digest.data,
5585                                 reference->digest.len);
5586
5587         TEST_HEXDUMP(stdout, "digest:",
5588                         sym_op->auth.digest.data,
5589                         sym_op->auth.digest.length);
5590
5591         sym_op->auth.data.length = reference->plaintext.len;
5592         sym_op->auth.data.offset = 0;
5593
5594         return 0;
5595 }
5596
5597 static int
5598 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
5599                 struct crypto_unittest_params *ut_params,
5600                 const struct test_crypto_vector *reference,
5601                 unsigned int auth_generate)
5602 {
5603         /* Generate Crypto op data structure */
5604         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5605                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5606         TEST_ASSERT_NOT_NULL(ut_params->op,
5607                         "Failed to allocate pktmbuf offload");
5608
5609         /* Set crypto operation data parameters */
5610         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5611
5612         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5613
5614         /* set crypto operation source mbuf */
5615         sym_op->m_src = ut_params->ibuf;
5616
5617         /* aad */
5618         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5619                         reference->aad.len);
5620         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
5621         memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
5622
5623         TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
5624
5625         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5626         sym_op->auth.aad.length = reference->aad.len;
5627
5628         /* digest */
5629         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5630                         ut_params->ibuf, reference->digest.len);
5631
5632         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5633                         "no room to append auth tag");
5634
5635         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5636                         ut_params->ibuf, reference->ciphertext.len);
5637         sym_op->auth.digest.length = reference->digest.len;
5638
5639         if (auth_generate)
5640                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5641         else
5642                 memcpy(sym_op->auth.digest.data,
5643                                 reference->digest.data,
5644                                 reference->digest.len);
5645
5646         TEST_HEXDUMP(stdout, "digest:",
5647                         sym_op->auth.digest.data,
5648                         sym_op->auth.digest.length);
5649
5650         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5651                 ut_params->ibuf, reference->iv.len);
5652         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5653
5654         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5655         sym_op->cipher.iv.length = reference->iv.len;
5656
5657         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
5658
5659         sym_op->cipher.data.length = 0;
5660         sym_op->cipher.data.offset = 0;
5661
5662         sym_op->auth.data.length = 0;
5663         sym_op->auth.data.offset = 0;
5664
5665         return 0;
5666 }
5667
5668 static int
5669 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
5670                 struct crypto_unittest_params *ut_params,
5671                 const struct test_crypto_vector *reference,
5672                 unsigned int auth_generate)
5673 {
5674         /* Generate Crypto op data structure */
5675         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5676                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5677         TEST_ASSERT_NOT_NULL(ut_params->op,
5678                         "Failed to allocate pktmbuf offload");
5679
5680         /* Set crypto operation data parameters */
5681         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5682
5683         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5684
5685         /* set crypto operation source mbuf */
5686         sym_op->m_src = ut_params->ibuf;
5687
5688         /* digest */
5689         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5690                         ut_params->ibuf, reference->digest.len);
5691
5692         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5693                         "no room to append auth tag");
5694
5695         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5696                         ut_params->ibuf, reference->ciphertext.len);
5697         sym_op->auth.digest.length = reference->digest.len;
5698
5699         if (auth_generate)
5700                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5701         else
5702                 memcpy(sym_op->auth.digest.data,
5703                                 reference->digest.data,
5704                                 reference->digest.len);
5705
5706         TEST_HEXDUMP(stdout, "digest:",
5707                         sym_op->auth.digest.data,
5708                         sym_op->auth.digest.length);
5709
5710         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5711                 ut_params->ibuf, reference->iv.len);
5712         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5713
5714         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5715         sym_op->cipher.iv.length = reference->iv.len;
5716
5717         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
5718
5719         sym_op->cipher.data.length = reference->ciphertext.len;
5720         sym_op->cipher.data.offset = reference->iv.len;
5721
5722         sym_op->auth.data.length = reference->ciphertext.len;
5723         sym_op->auth.data.offset = reference->iv.len;
5724
5725         return 0;
5726 }
5727
5728 static int
5729 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
5730                 struct crypto_unittest_params *ut_params,
5731                 const struct test_crypto_vector *reference)
5732 {
5733         return create_auth_operation(ts_params, ut_params, reference, 0);
5734 }
5735
5736 static int
5737 create_auth_verify_GMAC_operation(
5738                 struct crypto_testsuite_params *ts_params,
5739                 struct crypto_unittest_params *ut_params,
5740                 const struct test_crypto_vector *reference)
5741 {
5742         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
5743 }
5744
5745 static int
5746 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
5747                 struct crypto_unittest_params *ut_params,
5748                 const struct test_crypto_vector *reference)
5749 {
5750         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
5751 }
5752
5753 static int
5754 test_authentication_verify_fail_when_data_corruption(
5755                 struct crypto_testsuite_params *ts_params,
5756                 struct crypto_unittest_params *ut_params,
5757                 const struct test_crypto_vector *reference,
5758                 unsigned int data_corrupted)
5759 {
5760         int retval;
5761
5762         uint8_t *plaintext;
5763
5764         /* Create session */
5765         retval = create_auth_session(ut_params,
5766                         ts_params->valid_devs[0],
5767                         reference,
5768                         RTE_CRYPTO_AUTH_OP_VERIFY);
5769         if (retval < 0)
5770                 return retval;
5771
5772         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5773         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5774                         "Failed to allocate input buffer in mempool");
5775
5776         /* clear mbuf payload */
5777         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5778                         rte_pktmbuf_tailroom(ut_params->ibuf));
5779
5780         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5781                         reference->plaintext.len);
5782         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
5783         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
5784
5785         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
5786
5787         /* Create operation */
5788         retval = create_auth_verify_operation(ts_params, ut_params, reference);
5789
5790         if (retval < 0)
5791                 return retval;
5792
5793         if (data_corrupted)
5794                 data_corruption(plaintext);
5795         else
5796                 tag_corruption(plaintext, reference->plaintext.len);
5797
5798         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5799                         ut_params->op);
5800         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5801         TEST_ASSERT_EQUAL(ut_params->op->status,
5802                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5803                         "authentication not failed");
5804
5805         ut_params->obuf = ut_params->op->sym->m_src;
5806         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5807
5808         return 0;
5809 }
5810
5811 static int
5812 test_authentication_verify_GMAC_fail_when_corruption(
5813                 struct crypto_testsuite_params *ts_params,
5814                 struct crypto_unittest_params *ut_params,
5815                 const struct test_crypto_vector *reference,
5816                 unsigned int data_corrupted)
5817 {
5818         int retval;
5819
5820         /* Create session */
5821         retval = create_auth_cipher_session(ut_params,
5822                         ts_params->valid_devs[0],
5823                         reference,
5824                         RTE_CRYPTO_AUTH_OP_VERIFY,
5825                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
5826         if (retval < 0)
5827                 return retval;
5828
5829         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5830         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5831                         "Failed to allocate input buffer in mempool");
5832
5833         /* clear mbuf payload */
5834         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5835                         rte_pktmbuf_tailroom(ut_params->ibuf));
5836
5837         /* Create operation */
5838         retval = create_auth_verify_GMAC_operation(ts_params,
5839                         ut_params,
5840                         reference);
5841
5842         if (retval < 0)
5843                 return retval;
5844
5845         if (data_corrupted)
5846                 data_corruption(ut_params->op->sym->auth.aad.data);
5847         else
5848                 tag_corruption(ut_params->op->sym->auth.aad.data,
5849                                 reference->aad.len);
5850
5851         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5852                         ut_params->op);
5853         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5854         TEST_ASSERT_EQUAL(ut_params->op->status,
5855                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5856                         "authentication not failed");
5857
5858         ut_params->obuf = ut_params->op->sym->m_src;
5859         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5860
5861         return 0;
5862 }
5863
5864 static int
5865 test_authenticated_decryption_fail_when_corruption(
5866                 struct crypto_testsuite_params *ts_params,
5867                 struct crypto_unittest_params *ut_params,
5868                 const struct test_crypto_vector *reference,
5869                 unsigned int data_corrupted)
5870 {
5871         int retval;
5872
5873         uint8_t *ciphertext;
5874
5875         /* Create session */
5876         retval = create_auth_cipher_session(ut_params,
5877                         ts_params->valid_devs[0],
5878                         reference,
5879                         RTE_CRYPTO_AUTH_OP_VERIFY,
5880                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
5881         if (retval < 0)
5882                 return retval;
5883
5884         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5885         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5886                         "Failed to allocate input buffer in mempool");
5887
5888         /* clear mbuf payload */
5889         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5890                         rte_pktmbuf_tailroom(ut_params->ibuf));
5891
5892         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5893                         reference->ciphertext.len);
5894         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
5895         memcpy(ciphertext, reference->ciphertext.data,
5896                         reference->ciphertext.len);
5897
5898         /* Create operation */
5899         retval = create_cipher_auth_verify_operation(ts_params,
5900                         ut_params,
5901                         reference);
5902
5903         if (retval < 0)
5904                 return retval;
5905
5906         if (data_corrupted)
5907                 data_corruption(ciphertext);
5908         else
5909                 tag_corruption(ciphertext, reference->ciphertext.len);
5910
5911         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5912                         ut_params->op);
5913
5914         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5915         TEST_ASSERT_EQUAL(ut_params->op->status,
5916                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5917                         "authentication not failed");
5918
5919         ut_params->obuf = ut_params->op->sym->m_src;
5920         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5921
5922         return 0;
5923 }
5924
5925 static int
5926 test_authentication_verify_fail_when_data_corrupted(
5927                 struct crypto_testsuite_params *ts_params,
5928                 struct crypto_unittest_params *ut_params,
5929                 const struct test_crypto_vector *reference)
5930 {
5931         return test_authentication_verify_fail_when_data_corruption(
5932                         ts_params, ut_params, reference, 1);
5933 }
5934
5935 static int
5936 test_authentication_verify_fail_when_tag_corrupted(
5937                 struct crypto_testsuite_params *ts_params,
5938                 struct crypto_unittest_params *ut_params,
5939                 const struct test_crypto_vector *reference)
5940 {
5941         return test_authentication_verify_fail_when_data_corruption(
5942                         ts_params, ut_params, reference, 0);
5943 }
5944
5945 static int
5946 test_authentication_verify_GMAC_fail_when_data_corrupted(
5947                 struct crypto_testsuite_params *ts_params,
5948                 struct crypto_unittest_params *ut_params,
5949                 const struct test_crypto_vector *reference)
5950 {
5951         return test_authentication_verify_GMAC_fail_when_corruption(
5952                         ts_params, ut_params, reference, 1);
5953 }
5954
5955 static int
5956 test_authentication_verify_GMAC_fail_when_tag_corrupted(
5957                 struct crypto_testsuite_params *ts_params,
5958                 struct crypto_unittest_params *ut_params,
5959                 const struct test_crypto_vector *reference)
5960 {
5961         return test_authentication_verify_GMAC_fail_when_corruption(
5962                         ts_params, ut_params, reference, 0);
5963 }
5964
5965 static int
5966 test_authenticated_decryption_fail_when_data_corrupted(
5967                 struct crypto_testsuite_params *ts_params,
5968                 struct crypto_unittest_params *ut_params,
5969                 const struct test_crypto_vector *reference)
5970 {
5971         return test_authenticated_decryption_fail_when_corruption(
5972                         ts_params, ut_params, reference, 1);
5973 }
5974
5975 static int
5976 test_authenticated_decryption_fail_when_tag_corrupted(
5977                 struct crypto_testsuite_params *ts_params,
5978                 struct crypto_unittest_params *ut_params,
5979                 const struct test_crypto_vector *reference)
5980 {
5981         return test_authenticated_decryption_fail_when_corruption(
5982                         ts_params, ut_params, reference, 0);
5983 }
5984
5985 static int
5986 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
5987 {
5988         return test_authentication_verify_fail_when_data_corrupted(
5989                         &testsuite_params, &unittest_params,
5990                         &hmac_sha1_test_crypto_vector);
5991 }
5992
5993 static int
5994 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
5995 {
5996         return test_authentication_verify_fail_when_tag_corrupted(
5997                         &testsuite_params, &unittest_params,
5998                         &hmac_sha1_test_crypto_vector);
5999 }
6000
6001 static int
6002 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
6003 {
6004         return test_authentication_verify_GMAC_fail_when_data_corrupted(
6005                         &testsuite_params, &unittest_params,
6006                         &aes128_gmac_test_vector);
6007 }
6008
6009 static int
6010 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
6011 {
6012         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
6013                         &testsuite_params, &unittest_params,
6014                         &aes128_gmac_test_vector);
6015 }
6016
6017 static int
6018 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
6019 {
6020         return test_authenticated_decryption_fail_when_data_corrupted(
6021                         &testsuite_params,
6022                         &unittest_params,
6023                         &aes128cbc_hmac_sha1_test_vector);
6024 }
6025
6026 static int
6027 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
6028 {
6029         return test_authenticated_decryption_fail_when_tag_corrupted(
6030                         &testsuite_params,
6031                         &unittest_params,
6032                         &aes128cbc_hmac_sha1_test_vector);
6033 }
6034
6035 static struct unit_test_suite cryptodev_qat_testsuite  = {
6036         .suite_name = "Crypto QAT Unit Test Suite",
6037         .setup = testsuite_setup,
6038         .teardown = testsuite_teardown,
6039         .unit_test_cases = {
6040                 TEST_CASE_ST(ut_setup, ut_teardown,
6041                                 test_device_configure_invalid_dev_id),
6042                 TEST_CASE_ST(ut_setup, ut_teardown,
6043                                 test_device_configure_invalid_queue_pair_ids),
6044                 TEST_CASE_ST(ut_setup, ut_teardown,
6045                                 test_queue_pair_descriptor_setup),
6046                 TEST_CASE_ST(ut_setup, ut_teardown,
6047                                 test_multi_session),
6048
6049                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
6050                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
6051                 TEST_CASE_ST(ut_setup, ut_teardown,
6052                                                 test_3DES_cipheronly_qat_all),
6053                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_qat_all),
6054                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
6055
6056                 /** AES GCM Authenticated Encryption */
6057                 TEST_CASE_ST(ut_setup, ut_teardown,
6058                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6059                 TEST_CASE_ST(ut_setup, ut_teardown,
6060                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6061                 TEST_CASE_ST(ut_setup, ut_teardown,
6062                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6063                 TEST_CASE_ST(ut_setup, ut_teardown,
6064                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6065                 TEST_CASE_ST(ut_setup, ut_teardown,
6066                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6067                 TEST_CASE_ST(ut_setup, ut_teardown,
6068                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6069                 TEST_CASE_ST(ut_setup, ut_teardown,
6070                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6071
6072                 /** AES GCM Authenticated Decryption */
6073                 TEST_CASE_ST(ut_setup, ut_teardown,
6074                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6075                 TEST_CASE_ST(ut_setup, ut_teardown,
6076                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6077                 TEST_CASE_ST(ut_setup, ut_teardown,
6078                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6079                 TEST_CASE_ST(ut_setup, ut_teardown,
6080                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6081                 TEST_CASE_ST(ut_setup, ut_teardown,
6082                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6083                 TEST_CASE_ST(ut_setup, ut_teardown,
6084                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6085                 TEST_CASE_ST(ut_setup, ut_teardown,
6086                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6087
6088                 /** AES GMAC Authentication */
6089                 TEST_CASE_ST(ut_setup, ut_teardown,
6090                         test_AES_GMAC_authentication_test_case_1),
6091                 TEST_CASE_ST(ut_setup, ut_teardown,
6092                         test_AES_GMAC_authentication_verify_test_case_1),
6093                 TEST_CASE_ST(ut_setup, ut_teardown,
6094                         test_AES_GMAC_authentication_test_case_2),
6095                 TEST_CASE_ST(ut_setup, ut_teardown,
6096                         test_AES_GMAC_authentication_verify_test_case_2),
6097                 TEST_CASE_ST(ut_setup, ut_teardown,
6098                         test_AES_GMAC_authentication_test_case_3),
6099                 TEST_CASE_ST(ut_setup, ut_teardown,
6100                         test_AES_GMAC_authentication_verify_test_case_3),
6101
6102                 /** SNOW 3G encrypt only (UEA2) */
6103                 TEST_CASE_ST(ut_setup, ut_teardown,
6104                         test_snow3g_encryption_test_case_1),
6105                 TEST_CASE_ST(ut_setup, ut_teardown,
6106                         test_snow3g_encryption_test_case_2),
6107                 TEST_CASE_ST(ut_setup, ut_teardown,
6108                         test_snow3g_encryption_test_case_3),
6109                 TEST_CASE_ST(ut_setup, ut_teardown,
6110                         test_snow3g_encryption_test_case_4),
6111                 TEST_CASE_ST(ut_setup, ut_teardown,
6112                         test_snow3g_encryption_test_case_5),
6113
6114                 TEST_CASE_ST(ut_setup, ut_teardown,
6115                         test_snow3g_encryption_test_case_1_oop),
6116                 TEST_CASE_ST(ut_setup, ut_teardown,
6117                         test_snow3g_decryption_test_case_1_oop),
6118
6119                 /** SNOW 3G decrypt only (UEA2) */
6120                 TEST_CASE_ST(ut_setup, ut_teardown,
6121                         test_snow3g_decryption_test_case_1),
6122                 TEST_CASE_ST(ut_setup, ut_teardown,
6123                         test_snow3g_decryption_test_case_2),
6124                 TEST_CASE_ST(ut_setup, ut_teardown,
6125                         test_snow3g_decryption_test_case_3),
6126                 TEST_CASE_ST(ut_setup, ut_teardown,
6127                         test_snow3g_decryption_test_case_4),
6128                 TEST_CASE_ST(ut_setup, ut_teardown,
6129                         test_snow3g_decryption_test_case_5),
6130                 TEST_CASE_ST(ut_setup, ut_teardown,
6131                         test_snow3g_hash_generate_test_case_1),
6132                 TEST_CASE_ST(ut_setup, ut_teardown,
6133                         test_snow3g_hash_generate_test_case_2),
6134                 TEST_CASE_ST(ut_setup, ut_teardown,
6135                         test_snow3g_hash_generate_test_case_3),
6136                 TEST_CASE_ST(ut_setup, ut_teardown,
6137                         test_snow3g_hash_verify_test_case_1),
6138                 TEST_CASE_ST(ut_setup, ut_teardown,
6139                         test_snow3g_hash_verify_test_case_2),
6140                 TEST_CASE_ST(ut_setup, ut_teardown,
6141                         test_snow3g_hash_verify_test_case_3),
6142                 TEST_CASE_ST(ut_setup, ut_teardown,
6143                         test_snow3g_cipher_auth_test_case_1),
6144                 TEST_CASE_ST(ut_setup, ut_teardown,
6145                         test_snow3g_auth_cipher_test_case_1),
6146
6147                 /** HMAC_MD5 Authentication */
6148                 TEST_CASE_ST(ut_setup, ut_teardown,
6149                         test_MD5_HMAC_generate_case_1),
6150                 TEST_CASE_ST(ut_setup, ut_teardown,
6151                         test_MD5_HMAC_verify_case_1),
6152                 TEST_CASE_ST(ut_setup, ut_teardown,
6153                         test_MD5_HMAC_generate_case_2),
6154                 TEST_CASE_ST(ut_setup, ut_teardown,
6155                         test_MD5_HMAC_verify_case_2),
6156
6157                 /** NULL tests */
6158                 TEST_CASE_ST(ut_setup, ut_teardown,
6159                         test_null_auth_only_operation),
6160                 TEST_CASE_ST(ut_setup, ut_teardown,
6161                         test_null_cipher_only_operation),
6162                 TEST_CASE_ST(ut_setup, ut_teardown,
6163                         test_null_cipher_auth_operation),
6164                 TEST_CASE_ST(ut_setup, ut_teardown,
6165                         test_null_auth_cipher_operation),
6166
6167                 TEST_CASE_ST(ut_setup, ut_teardown,
6168                         test_kasumi_hash_generate_test_case_6),
6169
6170                 /** KASUMI tests */
6171                 TEST_CASE_ST(ut_setup, ut_teardown,
6172                         test_kasumi_encryption_test_case_1),
6173                 TEST_CASE_ST(ut_setup, ut_teardown,
6174                         test_kasumi_encryption_test_case_3),
6175                 TEST_CASE_ST(ut_setup, ut_teardown,
6176                         test_kasumi_auth_cipher_test_case_1),
6177                 TEST_CASE_ST(ut_setup, ut_teardown,
6178                         test_kasumi_cipher_auth_test_case_1),
6179
6180                 /** Negative tests */
6181                 TEST_CASE_ST(ut_setup, ut_teardown,
6182                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
6183                 TEST_CASE_ST(ut_setup, ut_teardown,
6184                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
6185                 TEST_CASE_ST(ut_setup, ut_teardown,
6186                         authentication_verify_AES128_GMAC_fail_data_corrupt),
6187                 TEST_CASE_ST(ut_setup, ut_teardown,
6188                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
6189                 TEST_CASE_ST(ut_setup, ut_teardown,
6190                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
6191                 TEST_CASE_ST(ut_setup, ut_teardown,
6192                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
6193
6194                 TEST_CASES_END() /**< NULL terminate unit test array */
6195         }
6196 };
6197
6198 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
6199         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
6200         .setup = testsuite_setup,
6201         .teardown = testsuite_teardown,
6202         .unit_test_cases = {
6203                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
6204
6205                 TEST_CASES_END() /**< NULL terminate unit test array */
6206         }
6207 };
6208
6209 static struct unit_test_suite cryptodev_openssl_testsuite  = {
6210         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
6211         .setup = testsuite_setup,
6212         .teardown = testsuite_teardown,
6213         .unit_test_cases = {
6214                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
6215                 TEST_CASE_ST(ut_setup, ut_teardown,
6216                                 test_multi_session_random_usage),
6217                 TEST_CASE_ST(ut_setup, ut_teardown,
6218                                 test_AES_chain_openssl_all),
6219                 TEST_CASE_ST(ut_setup, ut_teardown,
6220                                 test_AES_cipheronly_openssl_all),
6221                 TEST_CASE_ST(ut_setup, ut_teardown,
6222                                 test_3DES_chain_openssl_all),
6223                 TEST_CASE_ST(ut_setup, ut_teardown,
6224                                 test_3DES_cipheronly_openssl_all),
6225                 TEST_CASE_ST(ut_setup, ut_teardown,
6226                                 test_authonly_openssl_all),
6227
6228                 /** AES GCM Authenticated Encryption */
6229                 TEST_CASE_ST(ut_setup, ut_teardown,
6230                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6231                 TEST_CASE_ST(ut_setup, ut_teardown,
6232                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6233                 TEST_CASE_ST(ut_setup, ut_teardown,
6234                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6235                 TEST_CASE_ST(ut_setup, ut_teardown,
6236                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6237                 TEST_CASE_ST(ut_setup, ut_teardown,
6238                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6239                 TEST_CASE_ST(ut_setup, ut_teardown,
6240                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6241                 TEST_CASE_ST(ut_setup, ut_teardown,
6242                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6243
6244                 /** AES GCM Authenticated Decryption */
6245                 TEST_CASE_ST(ut_setup, ut_teardown,
6246                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6247                 TEST_CASE_ST(ut_setup, ut_teardown,
6248                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6249                 TEST_CASE_ST(ut_setup, ut_teardown,
6250                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6251                 TEST_CASE_ST(ut_setup, ut_teardown,
6252                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6253                 TEST_CASE_ST(ut_setup, ut_teardown,
6254                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6255                 TEST_CASE_ST(ut_setup, ut_teardown,
6256                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6257                 TEST_CASE_ST(ut_setup, ut_teardown,
6258                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6259
6260                 /** AES GMAC Authentication */
6261                 TEST_CASE_ST(ut_setup, ut_teardown,
6262                         test_AES_GMAC_authentication_test_case_1),
6263                 TEST_CASE_ST(ut_setup, ut_teardown,
6264                         test_AES_GMAC_authentication_verify_test_case_1),
6265                 TEST_CASE_ST(ut_setup, ut_teardown,
6266                         test_AES_GMAC_authentication_test_case_2),
6267                 TEST_CASE_ST(ut_setup, ut_teardown,
6268                         test_AES_GMAC_authentication_verify_test_case_2),
6269                 TEST_CASE_ST(ut_setup, ut_teardown,
6270                         test_AES_GMAC_authentication_test_case_3),
6271                 TEST_CASE_ST(ut_setup, ut_teardown,
6272                         test_AES_GMAC_authentication_verify_test_case_3),
6273                 TEST_CASE_ST(ut_setup, ut_teardown,
6274                         test_AES_GMAC_authentication_test_case_4),
6275                 TEST_CASE_ST(ut_setup, ut_teardown,
6276                         test_AES_GMAC_authentication_verify_test_case_4),
6277
6278                 /** Negative tests */
6279                 TEST_CASE_ST(ut_setup, ut_teardown,
6280                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
6281                 TEST_CASE_ST(ut_setup, ut_teardown,
6282                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
6283                 TEST_CASE_ST(ut_setup, ut_teardown,
6284                         authentication_verify_AES128_GMAC_fail_data_corrupt),
6285                 TEST_CASE_ST(ut_setup, ut_teardown,
6286                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
6287                 TEST_CASE_ST(ut_setup, ut_teardown,
6288                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
6289                 TEST_CASE_ST(ut_setup, ut_teardown,
6290                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
6291
6292                 TEST_CASES_END() /**< NULL terminate unit test array */
6293         }
6294 };
6295
6296 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
6297         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
6298         .setup = testsuite_setup,
6299         .teardown = testsuite_teardown,
6300         .unit_test_cases = {
6301                 /** AES GCM Authenticated Encryption */
6302                 TEST_CASE_ST(ut_setup, ut_teardown,
6303                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6304                 TEST_CASE_ST(ut_setup, ut_teardown,
6305                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6306                 TEST_CASE_ST(ut_setup, ut_teardown,
6307                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6308                 TEST_CASE_ST(ut_setup, ut_teardown,
6309                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6310                 TEST_CASE_ST(ut_setup, ut_teardown,
6311                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6312                 TEST_CASE_ST(ut_setup, ut_teardown,
6313                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6314                 TEST_CASE_ST(ut_setup, ut_teardown,
6315                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6316
6317                 /** AES GCM Authenticated Decryption */
6318                 TEST_CASE_ST(ut_setup, ut_teardown,
6319                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6320                 TEST_CASE_ST(ut_setup, ut_teardown,
6321                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6322                 TEST_CASE_ST(ut_setup, ut_teardown,
6323                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6324                 TEST_CASE_ST(ut_setup, ut_teardown,
6325                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6326                 TEST_CASE_ST(ut_setup, ut_teardown,
6327                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6328                 TEST_CASE_ST(ut_setup, ut_teardown,
6329                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6330                 TEST_CASE_ST(ut_setup, ut_teardown,
6331                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6332
6333                 TEST_CASES_END() /**< NULL terminate unit test array */
6334         }
6335 };
6336
6337 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
6338         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
6339         .setup = testsuite_setup,
6340         .teardown = testsuite_teardown,
6341         .unit_test_cases = {
6342                 /** KASUMI encrypt only (UEA1) */
6343                 TEST_CASE_ST(ut_setup, ut_teardown,
6344                         test_kasumi_encryption_test_case_1),
6345                 TEST_CASE_ST(ut_setup, ut_teardown,
6346                         test_kasumi_encryption_test_case_2),
6347                 TEST_CASE_ST(ut_setup, ut_teardown,
6348                         test_kasumi_encryption_test_case_3),
6349                 TEST_CASE_ST(ut_setup, ut_teardown,
6350                         test_kasumi_encryption_test_case_4),
6351                 TEST_CASE_ST(ut_setup, ut_teardown,
6352                         test_kasumi_encryption_test_case_5),
6353                 /** KASUMI decrypt only (UEA1) */
6354                 TEST_CASE_ST(ut_setup, ut_teardown,
6355                         test_kasumi_decryption_test_case_1),
6356                 TEST_CASE_ST(ut_setup, ut_teardown,
6357                         test_kasumi_decryption_test_case_2),
6358                 TEST_CASE_ST(ut_setup, ut_teardown,
6359                         test_kasumi_decryption_test_case_3),
6360                 TEST_CASE_ST(ut_setup, ut_teardown,
6361                         test_kasumi_decryption_test_case_4),
6362                 TEST_CASE_ST(ut_setup, ut_teardown,
6363                         test_kasumi_decryption_test_case_5),
6364
6365                 TEST_CASE_ST(ut_setup, ut_teardown,
6366                         test_kasumi_encryption_test_case_1_oop),
6367                 TEST_CASE_ST(ut_setup, ut_teardown,
6368                         test_kasumi_decryption_test_case_1_oop),
6369
6370                 /** KASUMI hash only (UIA1) */
6371                 TEST_CASE_ST(ut_setup, ut_teardown,
6372                         test_kasumi_hash_generate_test_case_1),
6373                 TEST_CASE_ST(ut_setup, ut_teardown,
6374                         test_kasumi_hash_generate_test_case_2),
6375                 TEST_CASE_ST(ut_setup, ut_teardown,
6376                         test_kasumi_hash_generate_test_case_3),
6377                 TEST_CASE_ST(ut_setup, ut_teardown,
6378                         test_kasumi_hash_generate_test_case_4),
6379                 TEST_CASE_ST(ut_setup, ut_teardown,
6380                         test_kasumi_hash_generate_test_case_5),
6381                 TEST_CASE_ST(ut_setup, ut_teardown,
6382                         test_kasumi_hash_generate_test_case_6),
6383                 TEST_CASE_ST(ut_setup, ut_teardown,
6384                         test_kasumi_hash_verify_test_case_1),
6385                 TEST_CASE_ST(ut_setup, ut_teardown,
6386                         test_kasumi_hash_verify_test_case_2),
6387                 TEST_CASE_ST(ut_setup, ut_teardown,
6388                         test_kasumi_hash_verify_test_case_3),
6389                 TEST_CASE_ST(ut_setup, ut_teardown,
6390                         test_kasumi_hash_verify_test_case_4),
6391                 TEST_CASE_ST(ut_setup, ut_teardown,
6392                         test_kasumi_hash_verify_test_case_5),
6393                 TEST_CASE_ST(ut_setup, ut_teardown,
6394                         test_kasumi_auth_cipher_test_case_1),
6395                 TEST_CASE_ST(ut_setup, ut_teardown,
6396                         test_kasumi_cipher_auth_test_case_1),
6397                 TEST_CASES_END() /**< NULL terminate unit test array */
6398         }
6399 };
6400 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
6401         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
6402         .setup = testsuite_setup,
6403         .teardown = testsuite_teardown,
6404         .unit_test_cases = {
6405                 /** SNOW 3G encrypt only (UEA2) */
6406                 TEST_CASE_ST(ut_setup, ut_teardown,
6407                         test_snow3g_encryption_test_case_1),
6408                 TEST_CASE_ST(ut_setup, ut_teardown,
6409                         test_snow3g_encryption_test_case_2),
6410                 TEST_CASE_ST(ut_setup, ut_teardown,
6411                         test_snow3g_encryption_test_case_3),
6412                 TEST_CASE_ST(ut_setup, ut_teardown,
6413                         test_snow3g_encryption_test_case_4),
6414                 TEST_CASE_ST(ut_setup, ut_teardown,
6415                         test_snow3g_encryption_test_case_5),
6416
6417                 TEST_CASE_ST(ut_setup, ut_teardown,
6418                         test_snow3g_encryption_test_case_1_oop),
6419                 TEST_CASE_ST(ut_setup, ut_teardown,
6420                         test_snow3g_decryption_test_case_1_oop),
6421
6422                 TEST_CASE_ST(ut_setup, ut_teardown,
6423                         test_snow3g_encryption_test_case_1_offset_oop),
6424
6425                 /** SNOW 3G decrypt only (UEA2) */
6426                 TEST_CASE_ST(ut_setup, ut_teardown,
6427                         test_snow3g_decryption_test_case_1),
6428                 TEST_CASE_ST(ut_setup, ut_teardown,
6429                         test_snow3g_decryption_test_case_2),
6430                 TEST_CASE_ST(ut_setup, ut_teardown,
6431                         test_snow3g_decryption_test_case_3),
6432                 TEST_CASE_ST(ut_setup, ut_teardown,
6433                         test_snow3g_decryption_test_case_4),
6434                 TEST_CASE_ST(ut_setup, ut_teardown,
6435                         test_snow3g_decryption_test_case_5),
6436                 TEST_CASE_ST(ut_setup, ut_teardown,
6437                         test_snow3g_hash_generate_test_case_1),
6438                 TEST_CASE_ST(ut_setup, ut_teardown,
6439                         test_snow3g_hash_generate_test_case_2),
6440                 TEST_CASE_ST(ut_setup, ut_teardown,
6441                         test_snow3g_hash_generate_test_case_3),
6442                 /* Tests with buffers which length is not byte-aligned */
6443                 TEST_CASE_ST(ut_setup, ut_teardown,
6444                         test_snow3g_hash_generate_test_case_4),
6445                 TEST_CASE_ST(ut_setup, ut_teardown,
6446                         test_snow3g_hash_generate_test_case_5),
6447                 TEST_CASE_ST(ut_setup, ut_teardown,
6448                         test_snow3g_hash_generate_test_case_6),
6449                 TEST_CASE_ST(ut_setup, ut_teardown,
6450                         test_snow3g_hash_verify_test_case_1),
6451                 TEST_CASE_ST(ut_setup, ut_teardown,
6452                         test_snow3g_hash_verify_test_case_2),
6453                 TEST_CASE_ST(ut_setup, ut_teardown,
6454                         test_snow3g_hash_verify_test_case_3),
6455                 /* Tests with buffers which length is not byte-aligned */
6456                 TEST_CASE_ST(ut_setup, ut_teardown,
6457                         test_snow3g_hash_verify_test_case_4),
6458                 TEST_CASE_ST(ut_setup, ut_teardown,
6459                         test_snow3g_hash_verify_test_case_5),
6460                 TEST_CASE_ST(ut_setup, ut_teardown,
6461                         test_snow3g_hash_verify_test_case_6),
6462                 TEST_CASE_ST(ut_setup, ut_teardown,
6463                         test_snow3g_cipher_auth_test_case_1),
6464                 TEST_CASE_ST(ut_setup, ut_teardown,
6465                         test_snow3g_auth_cipher_test_case_1),
6466
6467                 TEST_CASES_END() /**< NULL terminate unit test array */
6468         }
6469 };
6470
6471 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
6472         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
6473         .setup = testsuite_setup,
6474         .teardown = testsuite_teardown,
6475         .unit_test_cases = {
6476                 /** ZUC encrypt only (EEA3) */
6477                 TEST_CASE_ST(ut_setup, ut_teardown,
6478                         test_zuc_encryption_test_case_1),
6479                 TEST_CASE_ST(ut_setup, ut_teardown,
6480                         test_zuc_encryption_test_case_2),
6481                 TEST_CASE_ST(ut_setup, ut_teardown,
6482                         test_zuc_encryption_test_case_3),
6483                 TEST_CASE_ST(ut_setup, ut_teardown,
6484                         test_zuc_encryption_test_case_4),
6485                 TEST_CASE_ST(ut_setup, ut_teardown,
6486                         test_zuc_encryption_test_case_5),
6487                 TEST_CASE_ST(ut_setup, ut_teardown,
6488                         test_zuc_hash_generate_test_case_1),
6489                 TEST_CASE_ST(ut_setup, ut_teardown,
6490                         test_zuc_hash_generate_test_case_2),
6491                 TEST_CASE_ST(ut_setup, ut_teardown,
6492                         test_zuc_hash_generate_test_case_3),
6493                 TEST_CASE_ST(ut_setup, ut_teardown,
6494                         test_zuc_hash_generate_test_case_4),
6495                 TEST_CASE_ST(ut_setup, ut_teardown,
6496                         test_zuc_hash_generate_test_case_5),
6497                 TEST_CASES_END() /**< NULL terminate unit test array */
6498         }
6499 };
6500
6501 static struct unit_test_suite cryptodev_null_testsuite  = {
6502         .suite_name = "Crypto Device NULL Unit Test Suite",
6503         .setup = testsuite_setup,
6504         .teardown = testsuite_teardown,
6505         .unit_test_cases = {
6506                 TEST_CASE_ST(ut_setup, ut_teardown,
6507                         test_null_auth_only_operation),
6508                 TEST_CASE_ST(ut_setup, ut_teardown,
6509                         test_null_cipher_only_operation),
6510                 TEST_CASE_ST(ut_setup, ut_teardown,
6511                         test_null_cipher_auth_operation),
6512                 TEST_CASE_ST(ut_setup, ut_teardown,
6513                         test_null_auth_cipher_operation),
6514                 TEST_CASE_ST(ut_setup, ut_teardown,
6515                         test_null_invalid_operation),
6516                 TEST_CASE_ST(ut_setup, ut_teardown,
6517                         test_null_burst_operation),
6518
6519                 TEST_CASES_END() /**< NULL terminate unit test array */
6520         }
6521 };
6522
6523 static int
6524 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
6525 {
6526         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
6527         return unit_test_suite_runner(&cryptodev_qat_testsuite);
6528 }
6529
6530 static int
6531 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
6532 {
6533         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
6534
6535         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
6536 }
6537
6538 static int
6539 test_cryptodev_openssl(void)
6540 {
6541         gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
6542
6543         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
6544 }
6545
6546 static int
6547 test_cryptodev_aesni_gcm(void)
6548 {
6549         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
6550
6551         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
6552 }
6553
6554 static int
6555 test_cryptodev_null(void)
6556 {
6557         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
6558
6559         return unit_test_suite_runner(&cryptodev_null_testsuite);
6560 }
6561
6562 static int
6563 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
6564 {
6565         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
6566
6567         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
6568 }
6569
6570 static int
6571 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
6572 {
6573         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
6574
6575         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
6576 }
6577
6578 static int
6579 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
6580 {
6581         gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
6582
6583         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
6584 }
6585
6586 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
6587 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
6588 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
6589 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
6590 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
6591 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
6592 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
6593 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);