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