app/test: add SNOW 3G UEA2 with offset
[dpdk.git] / app / test / test_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Intel Corporation nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
42
43 #include "test.h"
44 #include "test_cryptodev.h"
45
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_kasumi_test_vectors.h"
48 #include "test_cryptodev_kasumi_hash_test_vectors.h"
49 #include "test_cryptodev_snow3g_test_vectors.h"
50 #include "test_cryptodev_snow3g_hash_test_vectors.h"
51 #include "test_cryptodev_gcm_test_vectors.h"
52
53 static enum rte_cryptodev_type gbl_cryptodev_type;
54
55 struct crypto_testsuite_params {
56         struct rte_mempool *mbuf_pool;
57         struct rte_mempool *op_mpool;
58         struct rte_cryptodev_config conf;
59         struct rte_cryptodev_qp_conf qp_conf;
60
61         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
62         uint8_t valid_dev_count;
63 };
64
65 struct crypto_unittest_params {
66         struct rte_crypto_sym_xform cipher_xform;
67         struct rte_crypto_sym_xform auth_xform;
68
69         struct rte_cryptodev_sym_session *sess;
70
71         struct rte_crypto_op *op;
72
73         struct rte_mbuf *obuf, *ibuf;
74
75         uint8_t *digest;
76 };
77
78 #define ALIGN_POW2_ROUNDUP(num, align) \
79         (((num) + (align) - 1) & ~((align) - 1))
80
81 /*
82  * Forward declarations.
83  */
84 static int
85 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
86                 struct crypto_unittest_params *ut_params);
87
88 static int
89 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
90                 struct crypto_unittest_params *ut_params,
91                 struct crypto_testsuite_params *ts_param);
92
93 static struct rte_mbuf *
94 setup_test_string(struct rte_mempool *mpool,
95                 const char *string, size_t len, uint8_t blocksize)
96 {
97         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
98         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
99
100         memset(m->buf_addr, 0, m->buf_len);
101         if (m) {
102                 char *dst = rte_pktmbuf_append(m, t_len);
103
104                 if (!dst) {
105                         rte_pktmbuf_free(m);
106                         return NULL;
107                 }
108                 if (string != NULL)
109                         rte_memcpy(dst, string, t_len);
110                 else
111                         memset(dst, 0, t_len);
112         }
113
114         return m;
115 }
116
117 /* Get number of bytes in X bits (rounding up) */
118 static uint32_t
119 ceil_byte_length(uint32_t num_bits)
120 {
121         if (num_bits % 8)
122                 return ((num_bits >> 3) + 1);
123         else
124                 return (num_bits >> 3);
125 }
126
127 static struct rte_crypto_op *
128 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
129 {
130         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
131                 printf("Error sending packet for encryption");
132                 return NULL;
133         }
134
135         op = NULL;
136
137         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
138                 rte_pause();
139
140         return op;
141 }
142
143 static struct crypto_testsuite_params testsuite_params = { NULL };
144 static struct crypto_unittest_params unittest_params;
145
146 static int
147 testsuite_setup(void)
148 {
149         struct crypto_testsuite_params *ts_params = &testsuite_params;
150         struct rte_cryptodev_info info;
151         unsigned i, nb_devs, dev_id;
152         int ret;
153         uint16_t qp_id;
154
155         memset(ts_params, 0, sizeof(*ts_params));
156
157         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
158         if (ts_params->mbuf_pool == NULL) {
159                 /* Not already created so create */
160                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
161                                 "CRYPTO_MBUFPOOL",
162                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
163                                 rte_socket_id());
164                 if (ts_params->mbuf_pool == NULL) {
165                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
166                         return TEST_FAILED;
167                 }
168         }
169
170         ts_params->op_mpool = rte_crypto_op_pool_create(
171                         "MBUF_CRYPTO_SYM_OP_POOL",
172                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
173                         NUM_MBUFS, MBUF_CACHE_SIZE,
174                         DEFAULT_NUM_XFORMS *
175                         sizeof(struct rte_crypto_sym_xform),
176                         rte_socket_id());
177         if (ts_params->op_mpool == NULL) {
178                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
179                 return TEST_FAILED;
180         }
181
182         /* Create 2 AESNI MB devices if required */
183         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
184                 nb_devs = rte_cryptodev_count_devtype(
185                                 RTE_CRYPTODEV_AESNI_MB_PMD);
186                 if (nb_devs < 2) {
187                         for (i = nb_devs; i < 2; i++) {
188                                 ret = rte_eal_vdev_init(
189                                         CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
190
191                                 TEST_ASSERT(ret == 0,
192                                         "Failed to create instance %u of"
193                                         " pmd : %s",
194                                         i, CRYPTODEV_NAME_AESNI_MB_PMD);
195                         }
196                 }
197         }
198
199         /* Create 2 AESNI GCM devices if required */
200         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
201                 nb_devs = rte_cryptodev_count_devtype(
202                                 RTE_CRYPTODEV_AESNI_GCM_PMD);
203                 if (nb_devs < 2) {
204                         for (i = nb_devs; i < 2; i++) {
205                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
206                                         CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
207                                         "Failed to create instance %u of"
208                                         " pmd : %s",
209                                         i, CRYPTODEV_NAME_AESNI_GCM_PMD);
210                         }
211                 }
212         }
213
214         /* Create 2 Snow3G devices if required */
215         if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
216                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
217                 if (nb_devs < 2) {
218                         for (i = nb_devs; i < 2; i++) {
219                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
220                                         CRYPTODEV_NAME_SNOW3G_PMD, NULL),
221                                         "Failed to create instance %u of"
222                                         " pmd : %s",
223                                         i, CRYPTODEV_NAME_SNOW3G_PMD);
224                         }
225                 }
226         }
227
228         /* Create 2 KASUMI devices if required */
229         if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
230                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
231                 if (nb_devs < 2) {
232                         for (i = nb_devs; i < 2; i++) {
233                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
234                                         CRYPTODEV_NAME_KASUMI_PMD, NULL),
235                                         "Failed to create instance %u of"
236                                         " pmd : %s",
237                                         i, CRYPTODEV_NAME_KASUMI_PMD);
238                         }
239                 }
240         }
241
242         /* Create 2 NULL devices if required */
243         if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
244                 nb_devs = rte_cryptodev_count_devtype(
245                                 RTE_CRYPTODEV_NULL_PMD);
246                 if (nb_devs < 2) {
247                         for (i = nb_devs; i < 2; i++) {
248                                 int dev_id = rte_eal_vdev_init(
249                                         CRYPTODEV_NAME_NULL_PMD, NULL);
250
251                                 TEST_ASSERT(dev_id >= 0,
252                                         "Failed to create instance %u of"
253                                         " pmd : %s",
254                                         i, CRYPTODEV_NAME_NULL_PMD);
255                         }
256                 }
257         }
258
259         nb_devs = rte_cryptodev_count();
260         if (nb_devs < 1) {
261                 RTE_LOG(ERR, USER1, "No crypto devices found?");
262                 return TEST_FAILED;
263         }
264
265         /* Create list of valid crypto devs */
266         for (i = 0; i < nb_devs; i++) {
267                 rte_cryptodev_info_get(i, &info);
268                 if (info.dev_type == gbl_cryptodev_type)
269                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
270         }
271
272         if (ts_params->valid_dev_count < 1)
273                 return TEST_FAILED;
274
275         /* Set up all the qps on the first of the valid devices found */
276         for (i = 0; i < 1; i++) {
277                 dev_id = ts_params->valid_devs[i];
278
279                 rte_cryptodev_info_get(dev_id, &info);
280
281                 /*
282                  * Since we can't free and re-allocate queue memory always set
283                  * the queues on this device up to max size first so enough
284                  * memory is allocated for any later re-configures needed by
285                  * other tests
286                  */
287
288                 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
289                 ts_params->conf.socket_id = SOCKET_ID_ANY;
290                 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
291
292                 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
293                                 &ts_params->conf),
294                                 "Failed to configure cryptodev %u with %u qps",
295                                 dev_id, ts_params->conf.nb_queue_pairs);
296
297                 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
298
299                 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
300                         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
301                                         dev_id, qp_id, &ts_params->qp_conf,
302                                         rte_cryptodev_socket_id(dev_id)),
303                                         "Failed to setup queue pair %u on "
304                                         "cryptodev %u",
305                                         qp_id, dev_id);
306                 }
307         }
308
309         return TEST_SUCCESS;
310 }
311
312 static void
313 testsuite_teardown(void)
314 {
315         struct crypto_testsuite_params *ts_params = &testsuite_params;
316
317         if (ts_params->mbuf_pool != NULL) {
318                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
319                 rte_mempool_count(ts_params->mbuf_pool));
320         }
321
322         if (ts_params->op_mpool != NULL) {
323                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
324                 rte_mempool_count(ts_params->op_mpool));
325         }
326
327 }
328
329 static int
330 ut_setup(void)
331 {
332         struct crypto_testsuite_params *ts_params = &testsuite_params;
333         struct crypto_unittest_params *ut_params = &unittest_params;
334
335         uint16_t qp_id;
336
337         /* Clear unit test parameters before running test */
338         memset(ut_params, 0, sizeof(*ut_params));
339
340         /* Reconfigure device to default parameters */
341         ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
342         ts_params->conf.socket_id = SOCKET_ID_ANY;
343         ts_params->conf.session_mp.nb_objs =
344                         (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
345                                         DEFAULT_NUM_OPS_INFLIGHT :
346                                         DEFAULT_NUM_OPS_INFLIGHT;
347
348         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
349                         &ts_params->conf),
350                         "Failed to configure cryptodev %u",
351                         ts_params->valid_devs[0]);
352
353         /*
354          * Now reconfigure queues to size we actually want to use in this
355          * test suite.
356          */
357         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
358
359         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
360                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
361                         ts_params->valid_devs[0], qp_id,
362                         &ts_params->qp_conf,
363                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
364                         "Failed to setup queue pair %u on cryptodev %u",
365                         qp_id, ts_params->valid_devs[0]);
366         }
367
368
369         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
370
371         /* Start the device */
372         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
373                         "Failed to start cryptodev %u",
374                         ts_params->valid_devs[0]);
375
376         return TEST_SUCCESS;
377 }
378
379 static void
380 ut_teardown(void)
381 {
382         struct crypto_testsuite_params *ts_params = &testsuite_params;
383         struct crypto_unittest_params *ut_params = &unittest_params;
384         struct rte_cryptodev_stats stats;
385
386         /* free crypto session structure */
387         if (ut_params->sess) {
388                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
389                                 ut_params->sess);
390                 ut_params->sess = NULL;
391         }
392
393         /* free crypto operation structure */
394         if (ut_params->op)
395                 rte_crypto_op_free(ut_params->op);
396
397         /*
398          * free mbuf - both obuf and ibuf are usually the same,
399          * but rte copes even if we call free twice
400          */
401         if (ut_params->obuf) {
402                 rte_pktmbuf_free(ut_params->obuf);
403                 ut_params->obuf = 0;
404         }
405         if (ut_params->ibuf) {
406                 rte_pktmbuf_free(ut_params->ibuf);
407                 ut_params->ibuf = 0;
408         }
409
410         if (ts_params->mbuf_pool != NULL)
411                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
412                                 rte_mempool_count(ts_params->mbuf_pool));
413
414         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
415
416         /* Stop the device */
417         rte_cryptodev_stop(ts_params->valid_devs[0]);
418 }
419
420 static int
421 test_device_configure_invalid_dev_id(void)
422 {
423         struct crypto_testsuite_params *ts_params = &testsuite_params;
424         uint16_t dev_id, num_devs = 0;
425
426         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
427                         "Need at least %d devices for test", 1);
428
429         /* valid dev_id values */
430         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
431
432         /* Stop the device in case it's started so it can be configured */
433         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
434
435         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
436                         "Failed test for rte_cryptodev_configure: "
437                         "invalid dev_num %u", dev_id);
438
439         /* invalid dev_id values */
440         dev_id = num_devs;
441
442         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
443                         "Failed test for rte_cryptodev_configure: "
444                         "invalid dev_num %u", dev_id);
445
446         dev_id = 0xff;
447
448         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
449                         "Failed test for rte_cryptodev_configure:"
450                         "invalid dev_num %u", dev_id);
451
452         return TEST_SUCCESS;
453 }
454
455 static int
456 test_device_configure_invalid_queue_pair_ids(void)
457 {
458         struct crypto_testsuite_params *ts_params = &testsuite_params;
459
460         /* Stop the device in case it's started so it can be configured */
461         rte_cryptodev_stop(ts_params->valid_devs[0]);
462
463         /* valid - one queue pairs */
464         ts_params->conf.nb_queue_pairs = 1;
465
466         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
467                         &ts_params->conf),
468                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
469                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
470
471
472         /* valid - max value queue pairs */
473         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
474
475         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
476                         &ts_params->conf),
477                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
478                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
479
480
481         /* invalid - zero queue pairs */
482         ts_params->conf.nb_queue_pairs = 0;
483
484         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
485                         &ts_params->conf),
486                         "Failed test for rte_cryptodev_configure, dev_id %u,"
487                         " invalid qps: %u",
488                         ts_params->valid_devs[0],
489                         ts_params->conf.nb_queue_pairs);
490
491
492         /* invalid - max value supported by field queue pairs */
493         ts_params->conf.nb_queue_pairs = UINT16_MAX;
494
495         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
496                         &ts_params->conf),
497                         "Failed test for rte_cryptodev_configure, dev_id %u,"
498                         " invalid qps: %u",
499                         ts_params->valid_devs[0],
500                         ts_params->conf.nb_queue_pairs);
501
502
503         /* invalid - max value + 1 queue pairs */
504         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
505
506         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
507                         &ts_params->conf),
508                         "Failed test for rte_cryptodev_configure, dev_id %u,"
509                         " invalid qps: %u",
510                         ts_params->valid_devs[0],
511                         ts_params->conf.nb_queue_pairs);
512
513         return TEST_SUCCESS;
514 }
515
516 static int
517 test_queue_pair_descriptor_setup(void)
518 {
519         struct crypto_testsuite_params *ts_params = &testsuite_params;
520         struct rte_cryptodev_info dev_info;
521         struct rte_cryptodev_qp_conf qp_conf = {
522                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
523         };
524
525         uint16_t qp_id;
526
527         /* Stop the device in case it's started so it can be configured */
528         rte_cryptodev_stop(ts_params->valid_devs[0]);
529
530
531         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
532
533         ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
534
535         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
536                         &ts_params->conf), "Failed to configure cryptodev %u",
537                         ts_params->valid_devs[0]);
538
539
540         /*
541          * Test various ring sizes on this device. memzones can't be
542          * freed so are re-used if ring is released and re-created.
543          */
544         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
545
546         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
547                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
548                                 ts_params->valid_devs[0], qp_id, &qp_conf,
549                                 rte_cryptodev_socket_id(
550                                                 ts_params->valid_devs[0])),
551                                 "Failed test for "
552                                 "rte_cryptodev_queue_pair_setup: num_inflights "
553                                 "%u on qp %u on cryptodev %u",
554                                 qp_conf.nb_descriptors, qp_id,
555                                 ts_params->valid_devs[0]);
556         }
557
558         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
559
560         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
561                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
562                                 ts_params->valid_devs[0], qp_id, &qp_conf,
563                                 rte_cryptodev_socket_id(
564                                                 ts_params->valid_devs[0])),
565                                 "Failed test for"
566                                 " rte_cryptodev_queue_pair_setup: num_inflights"
567                                 " %u on qp %u on cryptodev %u",
568                                 qp_conf.nb_descriptors, qp_id,
569                                 ts_params->valid_devs[0]);
570         }
571
572         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
573
574         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
575                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
576                                 ts_params->valid_devs[0], qp_id, &qp_conf,
577                                 rte_cryptodev_socket_id(
578                                                 ts_params->valid_devs[0])),
579                                 "Failed test for "
580                                 "rte_cryptodev_queue_pair_setup: num_inflights"
581                                 " %u on qp %u on cryptodev %u",
582                                 qp_conf.nb_descriptors, qp_id,
583                                 ts_params->valid_devs[0]);
584         }
585
586         /* invalid number of descriptors - max supported + 2 */
587         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
588
589         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
590                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
591                                 ts_params->valid_devs[0], qp_id, &qp_conf,
592                                 rte_cryptodev_socket_id(
593                                                 ts_params->valid_devs[0])),
594                                 "Unexpectedly passed test for "
595                                 "rte_cryptodev_queue_pair_setup:"
596                                 "num_inflights %u on qp %u on cryptodev %u",
597                                 qp_conf.nb_descriptors, qp_id,
598                                 ts_params->valid_devs[0]);
599         }
600
601         /* invalid number of descriptors - max value of parameter */
602         qp_conf.nb_descriptors = UINT32_MAX-1;
603
604         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
605                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
606                                 ts_params->valid_devs[0], qp_id, &qp_conf,
607                                 rte_cryptodev_socket_id(
608                                                 ts_params->valid_devs[0])),
609                                 "Unexpectedly passed test for "
610                                 "rte_cryptodev_queue_pair_setup:"
611                                 "num_inflights %u on qp %u on cryptodev %u",
612                                 qp_conf.nb_descriptors, qp_id,
613                                 ts_params->valid_devs[0]);
614         }
615
616         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
617
618         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
619                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
620                                 ts_params->valid_devs[0], qp_id, &qp_conf,
621                                 rte_cryptodev_socket_id(
622                                                 ts_params->valid_devs[0])),
623                                 "Failed test for"
624                                 " rte_cryptodev_queue_pair_setup:"
625                                 "num_inflights %u on qp %u on cryptodev %u",
626                                 qp_conf.nb_descriptors, qp_id,
627                                 ts_params->valid_devs[0]);
628         }
629
630         /* invalid number of descriptors - max supported + 1 */
631         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
632
633         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
634                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
635                                 ts_params->valid_devs[0], qp_id, &qp_conf,
636                                 rte_cryptodev_socket_id(
637                                                 ts_params->valid_devs[0])),
638                                 "Unexpectedly passed test for "
639                                 "rte_cryptodev_queue_pair_setup:"
640                                 "num_inflights %u on qp %u on cryptodev %u",
641                                 qp_conf.nb_descriptors, qp_id,
642                                 ts_params->valid_devs[0]);
643         }
644
645         /* test invalid queue pair id */
646         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
647
648         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
649
650         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
651                         ts_params->valid_devs[0],
652                         qp_id, &qp_conf,
653                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
654                         "Failed test for rte_cryptodev_queue_pair_setup:"
655                         "invalid qp %u on cryptodev %u",
656                         qp_id, ts_params->valid_devs[0]);
657
658         qp_id = 0xffff; /*invalid*/
659
660         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
661                         ts_params->valid_devs[0],
662                         qp_id, &qp_conf,
663                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
664                         "Failed test for rte_cryptodev_queue_pair_setup:"
665                         "invalid qp %u on cryptodev %u",
666                         qp_id, ts_params->valid_devs[0]);
667
668         return TEST_SUCCESS;
669 }
670
671 /* ***** Plaintext data for tests ***** */
672
673 const char catch_22_quote_1[] =
674                 "There was only one catch and that was Catch-22, which "
675                 "specified that a concern for one's safety in the face of "
676                 "dangers that were real and immediate was the process of a "
677                 "rational mind. Orr was crazy and could be grounded. All he "
678                 "had to do was ask; and as soon as he did, he would no longer "
679                 "be crazy and would have to fly more missions. Orr would be "
680                 "crazy to fly more missions and sane if he didn't, but if he "
681                 "was sane he had to fly them. If he flew them he was crazy "
682                 "and didn't have to; but if he didn't want to he was sane and "
683                 "had to. Yossarian was moved very deeply by the absolute "
684                 "simplicity of this clause of Catch-22 and let out a "
685                 "respectful whistle. \"That's some catch, that Catch-22\", he "
686                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
687
688 const char catch_22_quote[] =
689                 "What a lousy earth! He wondered how many people were "
690                 "destitute that same night even in his own prosperous country, "
691                 "how many homes were shanties, how many husbands were drunk "
692                 "and wives socked, and how many children were bullied, abused, "
693                 "or abandoned. How many families hungered for food they could "
694                 "not afford to buy? How many hearts were broken? How many "
695                 "suicides would take place that same night, how many people "
696                 "would go insane? How many cockroaches and landlords would "
697                 "triumph? How many winners were losers, successes failures, "
698                 "and rich men poor men? How many wise guys were stupid? How "
699                 "many happy endings were unhappy endings? How many honest men "
700                 "were liars, brave men cowards, loyal men traitors, how many "
701                 "sainted men were corrupt, how many people in positions of "
702                 "trust had sold their souls to bodyguards, how many had never "
703                 "had souls? How many straight-and-narrow paths were crooked "
704                 "paths? How many best families were worst families and how "
705                 "many good people were bad people? When you added them all up "
706                 "and then subtracted, you might be left with only the children, "
707                 "and perhaps with Albert Einstein and an old violinist or "
708                 "sculptor somewhere.";
709
710 #define QUOTE_480_BYTES         (480)
711 #define QUOTE_512_BYTES         (512)
712 #define QUOTE_768_BYTES         (768)
713 #define QUOTE_1024_BYTES        (1024)
714
715
716
717 /* ***** SHA1 Hash Tests ***** */
718
719 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
720
721 static uint8_t hmac_sha1_key[] = {
722         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
723         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
724         0xDE, 0xF4, 0xDE, 0xAD };
725
726 /* ***** SHA224 Hash Tests ***** */
727
728 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
729
730
731 /* ***** AES-CBC Cipher Tests ***** */
732
733 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
734 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
735
736 static uint8_t aes_cbc_key[] = {
737         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
738         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
739
740 static uint8_t aes_cbc_iv[] = {
741         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
742         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
743
744
745 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
746
747 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
748         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
749         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
750         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
751         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
752         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
753         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
754         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
755         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
756         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
757         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
758         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
759         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
760         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
761         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
762         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
763         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
764         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
765         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
766         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
767         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
768         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
769         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
770         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
771         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
772         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
773         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
774         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
775         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
776         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
777         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
778         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
779         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
780         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
781         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
782         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
783         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
784         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
785         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
786         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
787         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
788         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
789         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
790         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
791         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
792         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
793         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
794         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
795         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
796         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
797         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
798         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
799         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
800         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
801         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
802         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
803         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
804         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
805         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
806         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
807         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
808         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
809         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
810         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
811         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
812 };
813
814 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
815         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
816         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
817         0x18, 0x8c, 0x1d, 0x32
818 };
819
820
821 static int
822 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
823 {
824         struct crypto_testsuite_params *ts_params = &testsuite_params;
825         struct crypto_unittest_params *ut_params = &unittest_params;
826
827         /* Generate test mbuf data and space for digest */
828         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
829                         catch_22_quote, QUOTE_512_BYTES, 0);
830
831         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
832                         DIGEST_BYTE_LENGTH_SHA1);
833         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
834
835         /* Setup Cipher Parameters */
836         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
837         ut_params->cipher_xform.next = &ut_params->auth_xform;
838
839         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
840         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
841         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
842         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
843
844         /* Setup HMAC Parameters */
845         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
846
847         ut_params->auth_xform.next = NULL;
848
849         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
850         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
851         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
852         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
853         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
854
855         /* Create crypto session*/
856         ut_params->sess = rte_cryptodev_sym_session_create(
857                         ts_params->valid_devs[0],
858                         &ut_params->cipher_xform);
859         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
860
861         /* Generate crypto op data structure */
862         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
863                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
864         TEST_ASSERT_NOT_NULL(ut_params->op,
865                         "Failed to allocate symmetric crypto operation struct");
866
867         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
868
869         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
870
871         /* set crypto operation source mbuf */
872         sym_op->m_src = ut_params->ibuf;
873
874         /* Set crypto operation authentication parameters */
875         sym_op->auth.digest.data = ut_params->digest;
876         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
877                         ut_params->ibuf, QUOTE_512_BYTES);
878         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
879
880         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
881         sym_op->auth.data.length = QUOTE_512_BYTES;
882
883         /* Set crypto operation cipher parameters */
884         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
885                         CIPHER_IV_LENGTH_AES_CBC);
886         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
887         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
888
889         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
890                         CIPHER_IV_LENGTH_AES_CBC);
891
892         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
893         sym_op->cipher.data.length = QUOTE_512_BYTES;
894
895         /* Process crypto operation */
896         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
897                         ut_params->op), "failed to process sym crypto op");
898
899         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
900                         "crypto op processing failed");
901
902         /* Validate obuf */
903         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
904                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
905
906         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
907                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
908                         QUOTE_512_BYTES,
909                         "ciphertext data not as expected");
910
911         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
912
913         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
914                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
915                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
916                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
917                                         DIGEST_BYTE_LENGTH_SHA1,
918                         "Generated digest data not as expected");
919
920         return TEST_SUCCESS;
921 }
922
923 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
924
925 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
926
927 static uint8_t hmac_sha512_key[] = {
928         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
929         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
930         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
931         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
932         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
933         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
934         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
935         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
936
937 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
938         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
939         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
940         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
941         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
942         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
943         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
944         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
945         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
946
947
948
949 static int
950 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
951                 struct crypto_unittest_params *ut_params);
952
953 static int
954 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
955                 struct crypto_unittest_params *ut_params,
956                 struct crypto_testsuite_params *ts_params);
957
958
959 static int
960 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
961                 struct crypto_unittest_params *ut_params)
962 {
963
964         /* Setup Cipher Parameters */
965         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
966         ut_params->cipher_xform.next = NULL;
967
968         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
969         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
970         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
971         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
972
973         /* Setup HMAC Parameters */
974         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
975         ut_params->auth_xform.next = &ut_params->cipher_xform;
976
977         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
978         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
979         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
980         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
981         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
982
983         return TEST_SUCCESS;
984 }
985
986
987 static int
988 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
989                 struct crypto_unittest_params *ut_params,
990                 struct crypto_testsuite_params *ts_params)
991 {
992         /* Generate test mbuf data and digest */
993         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
994                         (const char *)
995                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
996                         QUOTE_512_BYTES, 0);
997
998         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
999                         DIGEST_BYTE_LENGTH_SHA512);
1000         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1001
1002         rte_memcpy(ut_params->digest,
1003                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1004                         DIGEST_BYTE_LENGTH_SHA512);
1005
1006         /* Generate Crypto op data structure */
1007         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1008                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1009         TEST_ASSERT_NOT_NULL(ut_params->op,
1010                         "Failed to allocate symmetric crypto operation struct");
1011
1012         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1013
1014         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1015
1016         /* set crypto operation source mbuf */
1017         sym_op->m_src = ut_params->ibuf;
1018
1019         sym_op->auth.digest.data = ut_params->digest;
1020         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1021                         ut_params->ibuf, QUOTE_512_BYTES);
1022         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1023
1024         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1025         sym_op->auth.data.length = QUOTE_512_BYTES;
1026
1027         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1028                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1029         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1030                         ut_params->ibuf, 0);
1031         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1032
1033         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1034                         CIPHER_IV_LENGTH_AES_CBC);
1035
1036         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1037         sym_op->cipher.data.length = QUOTE_512_BYTES;
1038
1039         /* Process crypto operation */
1040         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1041                         ut_params->op), "failed to process sym crypto op");
1042
1043         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1044                         "crypto op processing failed");
1045
1046         ut_params->obuf = ut_params->op->sym->m_src;
1047
1048         /* Validate obuf */
1049         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1050                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1051                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1052                         QUOTE_512_BYTES,
1053                         "Plaintext data not as expected");
1054
1055         /* Validate obuf */
1056         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1057                         "Digest verification failed");
1058
1059         return TEST_SUCCESS;
1060 }
1061
1062 static int
1063 test_AES_mb_all(void)
1064 {
1065         struct crypto_testsuite_params *ts_params = &testsuite_params;
1066         int status;
1067
1068         status = test_AES_all_tests(ts_params->mbuf_pool,
1069                 ts_params->op_mpool, ts_params->valid_devs[0],
1070                 RTE_CRYPTODEV_AESNI_MB_PMD);
1071
1072         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1073
1074         return TEST_SUCCESS;
1075 }
1076
1077 static int
1078 test_AES_qat_all(void)
1079 {
1080         struct crypto_testsuite_params *ts_params = &testsuite_params;
1081         int status;
1082
1083         status = test_AES_all_tests(ts_params->mbuf_pool,
1084                 ts_params->op_mpool, ts_params->valid_devs[0],
1085                 RTE_CRYPTODEV_QAT_SYM_PMD);
1086
1087         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1088
1089         return TEST_SUCCESS;
1090 }
1091
1092 /* ***** Snow3G Tests ***** */
1093 static int
1094 create_snow3g_hash_session(uint8_t dev_id,
1095         const uint8_t *key, const uint8_t key_len,
1096         const uint8_t aad_len, const uint8_t auth_len,
1097         enum rte_crypto_auth_operation op)
1098 {
1099         uint8_t hash_key[key_len];
1100
1101         struct crypto_unittest_params *ut_params = &unittest_params;
1102
1103         memcpy(hash_key, key, key_len);
1104
1105         TEST_HEXDUMP(stdout, "key:", key, key_len);
1106
1107         /* Setup Authentication Parameters */
1108         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1109         ut_params->auth_xform.next = NULL;
1110
1111         ut_params->auth_xform.auth.op = op;
1112         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1113         ut_params->auth_xform.auth.key.length = key_len;
1114         ut_params->auth_xform.auth.key.data = hash_key;
1115         ut_params->auth_xform.auth.digest_length = auth_len;
1116         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1117         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1118                                 &ut_params->auth_xform);
1119         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1120         return 0;
1121 }
1122
1123 static int
1124 create_kasumi_hash_session(uint8_t dev_id,
1125         const uint8_t *key, const uint8_t key_len,
1126         const uint8_t aad_len, const uint8_t auth_len,
1127         enum rte_crypto_auth_operation op)
1128 {
1129         uint8_t hash_key[key_len];
1130
1131         struct crypto_unittest_params *ut_params = &unittest_params;
1132
1133         memcpy(hash_key, key, key_len);
1134         TEST_HEXDUMP(stdout, "key:", key, key_len);
1135         /* Setup Authentication Parameters */
1136         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1137         ut_params->auth_xform.next = NULL;
1138
1139         ut_params->auth_xform.auth.op = op;
1140         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_KASUMI_F9;
1141         ut_params->auth_xform.auth.key.length = key_len;
1142         ut_params->auth_xform.auth.key.data = hash_key;
1143         ut_params->auth_xform.auth.digest_length = auth_len;
1144         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1145         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1146                                 &ut_params->auth_xform);
1147         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1148         return 0;
1149 }
1150
1151 static int
1152 create_kasumi_cipher_session(uint8_t dev_id,
1153                         enum rte_crypto_cipher_operation op,
1154                         const uint8_t *key, const uint8_t key_len)
1155 {
1156         uint8_t cipher_key[key_len];
1157
1158         struct crypto_unittest_params *ut_params = &unittest_params;
1159
1160         memcpy(cipher_key, key, key_len);
1161
1162         /* Setup Cipher Parameters */
1163         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1164         ut_params->cipher_xform.next = NULL;
1165
1166         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_KASUMI_F8;
1167         ut_params->cipher_xform.cipher.op = op;
1168         ut_params->cipher_xform.cipher.key.data = cipher_key;
1169         ut_params->cipher_xform.cipher.key.length = key_len;
1170
1171         TEST_HEXDUMP(stdout, "key:", key, key_len);
1172
1173         /* Create Crypto session */
1174         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1175                                                 &ut_params->
1176                                                 cipher_xform);
1177         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1178         return 0;
1179 }
1180
1181 static int
1182 create_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1183                         const unsigned cipher_len,
1184                         const unsigned cipher_offset)
1185 {
1186         struct crypto_testsuite_params *ts_params = &testsuite_params;
1187         struct crypto_unittest_params *ut_params = &unittest_params;
1188         unsigned iv_pad_len = 0;
1189
1190         /* Generate Crypto op data structure */
1191         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1192                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1193         TEST_ASSERT_NOT_NULL(ut_params->op,
1194                                 "Failed to allocate pktmbuf offload");
1195
1196         /* Set crypto operation data parameters */
1197         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1198
1199         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1200
1201         /* set crypto operation source mbuf */
1202         sym_op->m_src = ut_params->ibuf;
1203
1204         /* iv */
1205         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1206         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1207                         , iv_pad_len);
1208
1209         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1210
1211         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1212         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1213         sym_op->cipher.iv.length = iv_pad_len;
1214
1215         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1216         sym_op->cipher.data.length = cipher_len;
1217         sym_op->cipher.data.offset = cipher_offset;
1218         return 0;
1219 }
1220
1221 static int
1222 create_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1223                         const unsigned cipher_len,
1224                         const unsigned cipher_offset)
1225 {
1226         struct crypto_testsuite_params *ts_params = &testsuite_params;
1227         struct crypto_unittest_params *ut_params = &unittest_params;
1228         unsigned iv_pad_len = 0;
1229
1230         /* Generate Crypto op data structure */
1231         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1232                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1233         TEST_ASSERT_NOT_NULL(ut_params->op,
1234                                 "Failed to allocate pktmbuf offload");
1235
1236         /* Set crypto operation data parameters */
1237         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1238
1239         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1240
1241         /* set crypto operation source mbuf */
1242         sym_op->m_src = ut_params->ibuf;
1243         sym_op->m_dst = ut_params->obuf;
1244
1245         /* iv */
1246         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1247         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1248                                         iv_pad_len);
1249
1250         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1251
1252         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1253         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1254         sym_op->cipher.iv.length = iv_pad_len;
1255
1256         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1257         sym_op->cipher.data.length = cipher_len;
1258         sym_op->cipher.data.offset = cipher_offset;
1259         return 0;
1260 }
1261
1262 static int
1263 create_snow3g_cipher_session(uint8_t dev_id,
1264                         enum rte_crypto_cipher_operation op,
1265                         const uint8_t *key, const uint8_t key_len)
1266 {
1267         uint8_t cipher_key[key_len];
1268
1269         struct crypto_unittest_params *ut_params = &unittest_params;
1270
1271         memcpy(cipher_key, key, key_len);
1272
1273         /* Setup Cipher Parameters */
1274         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1275         ut_params->cipher_xform.next = NULL;
1276
1277         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1278         ut_params->cipher_xform.cipher.op = op;
1279         ut_params->cipher_xform.cipher.key.data = cipher_key;
1280         ut_params->cipher_xform.cipher.key.length = key_len;
1281
1282         TEST_HEXDUMP(stdout, "key:", key, key_len);
1283
1284         /* Create Crypto session */
1285         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1286                                                 &ut_params->
1287                                                 cipher_xform);
1288         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1289         return 0;
1290 }
1291
1292 static int
1293 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1294                         const unsigned cipher_len,
1295                         const unsigned cipher_offset)
1296 {
1297         struct crypto_testsuite_params *ts_params = &testsuite_params;
1298         struct crypto_unittest_params *ut_params = &unittest_params;
1299         unsigned iv_pad_len = 0;
1300
1301         /* Generate Crypto op data structure */
1302         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1303                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1304         TEST_ASSERT_NOT_NULL(ut_params->op,
1305                                 "Failed to allocate pktmbuf offload");
1306
1307         /* Set crypto operation data parameters */
1308         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1309
1310         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1311
1312         /* set crypto operation source mbuf */
1313         sym_op->m_src = ut_params->ibuf;
1314
1315         /* iv */
1316         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1317         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1318                         , iv_pad_len);
1319
1320         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1321
1322         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1323         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1324         sym_op->cipher.iv.length = iv_pad_len;
1325
1326         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1327         sym_op->cipher.data.length = cipher_len;
1328         sym_op->cipher.data.offset = cipher_offset;
1329         return 0;
1330 }
1331
1332 static int
1333 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1334                         const unsigned cipher_len,
1335                         const unsigned cipher_offset)
1336 {
1337         struct crypto_testsuite_params *ts_params = &testsuite_params;
1338         struct crypto_unittest_params *ut_params = &unittest_params;
1339         unsigned iv_pad_len = 0;
1340
1341         /* Generate Crypto op data structure */
1342         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1343                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1344         TEST_ASSERT_NOT_NULL(ut_params->op,
1345                                 "Failed to allocate pktmbuf offload");
1346
1347         /* Set crypto operation data parameters */
1348         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1349
1350         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1351
1352         /* set crypto operation source mbuf */
1353         sym_op->m_src = ut_params->ibuf;
1354         sym_op->m_dst = ut_params->obuf;
1355
1356         /* iv */
1357         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1358         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1359                         , iv_pad_len);
1360
1361         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1362
1363         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1364         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1365         sym_op->cipher.iv.length = iv_pad_len;
1366
1367         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1368         sym_op->cipher.data.length = cipher_len;
1369         sym_op->cipher.data.offset = cipher_offset;
1370         return 0;
1371 }
1372
1373 static int
1374 create_snow3g_cipher_auth_session(uint8_t dev_id,
1375                 enum rte_crypto_cipher_operation cipher_op,
1376                 enum rte_crypto_auth_operation auth_op,
1377                 const uint8_t *key, const uint8_t key_len,
1378                 const uint8_t aad_len, const uint8_t auth_len)
1379 {
1380         uint8_t cipher_auth_key[key_len];
1381
1382         struct crypto_unittest_params *ut_params = &unittest_params;
1383
1384         memcpy(cipher_auth_key, key, key_len);
1385
1386         /* Setup Authentication Parameters */
1387         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1388         ut_params->auth_xform.next = NULL;
1389
1390         ut_params->auth_xform.auth.op = auth_op;
1391         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1392         ut_params->auth_xform.auth.key.length = key_len;
1393         /* Hash key = cipher key */
1394         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1395         ut_params->auth_xform.auth.digest_length = auth_len;
1396         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1397
1398         /* Setup Cipher Parameters */
1399         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1400         ut_params->cipher_xform.next = &ut_params->auth_xform;
1401
1402         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1403         ut_params->cipher_xform.cipher.op = cipher_op;
1404         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1405         ut_params->cipher_xform.cipher.key.length = key_len;
1406
1407         TEST_HEXDUMP(stdout, "key:", key, key_len);
1408
1409         /* Create Crypto session*/
1410         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1411                                 &ut_params->cipher_xform);
1412
1413         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1414         return 0;
1415 }
1416
1417 static int
1418 create_snow3g_auth_cipher_session(uint8_t dev_id,
1419                 enum rte_crypto_cipher_operation cipher_op,
1420                 enum rte_crypto_auth_operation auth_op,
1421                 const uint8_t *key, const uint8_t key_len,
1422                 const uint8_t aad_len, const uint8_t auth_len)
1423         {
1424         uint8_t auth_cipher_key[key_len];
1425
1426         struct crypto_unittest_params *ut_params = &unittest_params;
1427
1428         memcpy(auth_cipher_key, key, key_len);
1429
1430         /* Setup Authentication Parameters */
1431         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1432         ut_params->auth_xform.auth.op = auth_op;
1433         ut_params->auth_xform.next = &ut_params->cipher_xform;
1434         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1435         ut_params->auth_xform.auth.key.length = key_len;
1436         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1437         ut_params->auth_xform.auth.digest_length = auth_len;
1438         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1439
1440         /* Setup Cipher Parameters */
1441         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1442         ut_params->cipher_xform.next = NULL;
1443         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1444         ut_params->cipher_xform.cipher.op = cipher_op;
1445         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1446         ut_params->cipher_xform.cipher.key.length = key_len;
1447
1448         TEST_HEXDUMP(stdout, "key:", key, key_len);
1449
1450         /* Create Crypto session*/
1451         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1452                                 &ut_params->auth_xform);
1453
1454         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1455
1456         return 0;
1457 }
1458
1459 static int
1460 create_snow3g_hash_operation(const uint8_t *auth_tag,
1461                 const unsigned auth_tag_len,
1462                 const uint8_t *aad, const unsigned aad_len,
1463                 unsigned data_pad_len,
1464                 enum rte_crypto_auth_operation op,
1465                 const unsigned auth_len, const unsigned auth_offset)
1466 {
1467         struct crypto_testsuite_params *ts_params = &testsuite_params;
1468
1469         struct crypto_unittest_params *ut_params = &unittest_params;
1470
1471         unsigned aad_buffer_len;
1472
1473         /* Generate Crypto op data structure */
1474         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1475                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1476         TEST_ASSERT_NOT_NULL(ut_params->op,
1477                 "Failed to allocate pktmbuf offload");
1478
1479         /* Set crypto operation data parameters */
1480         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1481
1482         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1483
1484         /* set crypto operation source mbuf */
1485         sym_op->m_src = ut_params->ibuf;
1486
1487         /* aad */
1488         /*
1489         * Always allocate the aad up to the block size.
1490         * The cryptodev API calls out -
1491         *  - the array must be big enough to hold the AAD, plus any
1492         *   space to round this up to the nearest multiple of the
1493         *   block size (16 bytes).
1494         */
1495         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1496         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1497                         ut_params->ibuf, aad_buffer_len);
1498         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1499                                         "no room to prepend aad");
1500         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1501                         ut_params->ibuf);
1502         sym_op->auth.aad.length = aad_len;
1503
1504         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1505         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1506
1507         TEST_HEXDUMP(stdout, "aad:",
1508                         sym_op->auth.aad.data, aad_len);
1509
1510         /* digest */
1511         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1512                                         ut_params->ibuf, auth_tag_len);
1513
1514         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1515                                 "no room to append auth tag");
1516         ut_params->digest = sym_op->auth.digest.data;
1517         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1518                         ut_params->ibuf, data_pad_len + aad_len);
1519         sym_op->auth.digest.length = auth_tag_len;
1520         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1521                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1522         else
1523                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1524
1525         TEST_HEXDUMP(stdout, "digest:",
1526                 sym_op->auth.digest.data,
1527                 sym_op->auth.digest.length);
1528
1529         sym_op->auth.data.length = auth_len;
1530         sym_op->auth.data.offset = auth_offset;
1531
1532         return 0;
1533 }
1534
1535 static int
1536 create_kasumi_hash_operation(const uint8_t *auth_tag,
1537                 const unsigned auth_tag_len,
1538                 const uint8_t *aad, const unsigned aad_len,
1539                 unsigned data_pad_len,
1540                 enum rte_crypto_auth_operation op,
1541                 const unsigned auth_len, const unsigned auth_offset)
1542 {
1543         struct crypto_testsuite_params *ts_params = &testsuite_params;
1544
1545         struct crypto_unittest_params *ut_params = &unittest_params;
1546
1547         unsigned aad_buffer_len;
1548
1549         /* Generate Crypto op data structure */
1550         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1551                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1552         TEST_ASSERT_NOT_NULL(ut_params->op,
1553                 "Failed to allocate pktmbuf offload");
1554
1555         /* Set crypto operation data parameters */
1556         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1557
1558         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1559
1560         /* set crypto operation source mbuf */
1561         sym_op->m_src = ut_params->ibuf;
1562
1563         /* aad */
1564         /*
1565         * Always allocate the aad up to the block size.
1566         * The cryptodev API calls out -
1567         *  - the array must be big enough to hold the AAD, plus any
1568         *   space to round this up to the nearest multiple of the
1569         *   block size (16 bytes).
1570         */
1571         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1572         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1573                         ut_params->ibuf, aad_buffer_len);
1574         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1575                                         "no room to prepend aad");
1576         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1577                         ut_params->ibuf);
1578         sym_op->auth.aad.length = aad_len;
1579
1580         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1581         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1582
1583         TEST_HEXDUMP(stdout, "aad:",
1584                         sym_op->auth.aad.data, aad_len);
1585
1586         /* digest */
1587         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1588                                         ut_params->ibuf, auth_tag_len);
1589
1590         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1591                                 "no room to append auth tag");
1592         ut_params->digest = sym_op->auth.digest.data;
1593         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1594                         ut_params->ibuf, data_pad_len + aad_len);
1595         sym_op->auth.digest.length = auth_tag_len;
1596         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1597                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1598         else
1599                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1600
1601         TEST_HEXDUMP(stdout, "digest:",
1602                 sym_op->auth.digest.data,
1603                 sym_op->auth.digest.length);
1604
1605         sym_op->auth.data.length = auth_len;
1606         sym_op->auth.data.offset = auth_offset;
1607
1608         return 0;
1609 }
1610 static int
1611 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1612                 const unsigned auth_tag_len,
1613                 const uint8_t *aad, const uint8_t aad_len,
1614                 unsigned data_pad_len,
1615                 enum rte_crypto_auth_operation op,
1616                 const uint8_t *iv, const uint8_t iv_len,
1617                 const unsigned cipher_len, const unsigned cipher_offset,
1618                 const unsigned auth_len, const unsigned auth_offset)
1619 {
1620         struct crypto_testsuite_params *ts_params = &testsuite_params;
1621         struct crypto_unittest_params *ut_params = &unittest_params;
1622
1623         unsigned iv_pad_len = 0;
1624         unsigned aad_buffer_len;
1625
1626         /* Generate Crypto op data structure */
1627         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1628                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1629         TEST_ASSERT_NOT_NULL(ut_params->op,
1630                         "Failed to allocate pktmbuf offload");
1631         /* Set crypto operation data parameters */
1632         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1633
1634         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1635
1636         /* set crypto operation source mbuf */
1637         sym_op->m_src = ut_params->ibuf;
1638
1639
1640         /* iv */
1641         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1642
1643         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1644                 ut_params->ibuf, iv_pad_len);
1645         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1646
1647         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1648         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1649         sym_op->cipher.iv.length = iv_pad_len;
1650
1651         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1652
1653         sym_op->cipher.data.length = cipher_len;
1654         sym_op->cipher.data.offset = cipher_offset;
1655
1656         /* aad */
1657         /*
1658         * Always allocate the aad up to the block size.
1659         * The cryptodev API calls out -
1660         *  - the array must be big enough to hold the AAD, plus any
1661         *   space to round this up to the nearest multiple of the
1662         *   block size (16 bytes).
1663         */
1664         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1665
1666         sym_op->auth.aad.data =
1667                         (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1668         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1669                         "no room to prepend aad");
1670         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1671                         ut_params->ibuf);
1672         sym_op->auth.aad.length = aad_len;
1673
1674         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1675         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1676
1677         TEST_HEXDUMP(stdout, "aad:",
1678                         sym_op->auth.aad.data, aad_len);
1679
1680         /* digest */
1681         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1682                         ut_params->ibuf, auth_tag_len);
1683
1684         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1685                         "no room to append auth tag");
1686         ut_params->digest = sym_op->auth.digest.data;
1687         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1688                         ut_params->ibuf, data_pad_len + aad_len);
1689         sym_op->auth.digest.length = auth_tag_len;
1690         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1691                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1692         else
1693                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1694
1695         TEST_HEXDUMP(stdout, "digest:",
1696                 sym_op->auth.digest.data,
1697                 sym_op->auth.digest.length);
1698
1699         sym_op->auth.data.length = auth_len;
1700         sym_op->auth.data.offset = auth_offset;
1701
1702         return 0;
1703 }
1704
1705 static int
1706 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1707                 const uint8_t *iv, const uint8_t iv_len,
1708                 const uint8_t *aad, const uint8_t aad_len,
1709                 unsigned data_pad_len,
1710                 const unsigned cipher_len, const unsigned cipher_offset,
1711                 const unsigned auth_len, const unsigned auth_offset)
1712 {
1713         struct crypto_testsuite_params *ts_params = &testsuite_params;
1714         struct crypto_unittest_params *ut_params = &unittest_params;
1715
1716         unsigned iv_pad_len = 0;
1717         unsigned aad_buffer_len = 0;
1718
1719         /* Generate Crypto op data structure */
1720         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1721                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1722         TEST_ASSERT_NOT_NULL(ut_params->op,
1723                         "Failed to allocate pktmbuf offload");
1724
1725         /* Set crypto operation data parameters */
1726         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1727
1728         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1729
1730         /* set crypto operation source mbuf */
1731         sym_op->m_src = ut_params->ibuf;
1732
1733         /* digest */
1734         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1735                         ut_params->ibuf, auth_tag_len);
1736
1737         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1738                         "no room to append auth tag");
1739
1740         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1741                         ut_params->ibuf, data_pad_len);
1742         sym_op->auth.digest.length = auth_tag_len;
1743
1744         memset(sym_op->auth.digest.data, 0, auth_tag_len);
1745
1746         TEST_HEXDUMP(stdout, "digest:",
1747                         sym_op->auth.digest.data,
1748                         sym_op->auth.digest.length);
1749
1750         /* iv */
1751         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1752
1753         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1754                 ut_params->ibuf, iv_pad_len);
1755         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1756
1757         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1758         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1759         sym_op->cipher.iv.length = iv_pad_len;
1760
1761         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1762
1763         /* aad */
1764         /*
1765         * Always allocate the aad up to the block size.
1766         * The cryptodev API calls out -
1767         *  - the array must be big enough to hold the AAD, plus any
1768         *   space to round this up to the nearest multiple of the
1769         *   block size (16 bytes).
1770         */
1771         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1772
1773         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1774         ut_params->ibuf, aad_buffer_len);
1775         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1776                                 "no room to prepend aad");
1777         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1778                                 ut_params->ibuf);
1779         sym_op->auth.aad.length = aad_len;
1780
1781         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1782         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1783
1784         TEST_HEXDUMP(stdout, "aad:",
1785                         sym_op->auth.aad.data, aad_len);
1786
1787         sym_op->cipher.data.length = cipher_len;
1788         sym_op->cipher.data.offset = auth_offset + cipher_offset;
1789
1790         sym_op->auth.data.length = auth_len;
1791         sym_op->auth.data.offset = auth_offset + cipher_offset;
1792
1793         return 0;
1794 }
1795
1796 static int
1797 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1798 {
1799         struct crypto_testsuite_params *ts_params = &testsuite_params;
1800         struct crypto_unittest_params *ut_params = &unittest_params;
1801
1802         int retval;
1803         unsigned plaintext_pad_len;
1804         unsigned plaintext_len;
1805         uint8_t *plaintext;
1806
1807         /* Create SNOW3G session */
1808         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1809                         tdata->key.data, tdata->key.len,
1810                         tdata->aad.len, tdata->digest.len,
1811                         RTE_CRYPTO_AUTH_OP_GENERATE);
1812         if (retval < 0)
1813                 return retval;
1814
1815         /* alloc mbuf and set payload */
1816         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1817
1818         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1819         rte_pktmbuf_tailroom(ut_params->ibuf));
1820
1821         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1822         /* Append data which is padded to a multiple of */
1823         /* the algorithms block size */
1824         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1825         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1826                                 plaintext_pad_len);
1827         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1828
1829         /* Create SNOW3G opertaion */
1830         retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1831                         tdata->aad.data, tdata->aad.len,
1832                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1833                         tdata->validAuthLenInBits.len,
1834                         tdata->validAuthOffsetLenInBits.len);
1835         if (retval < 0)
1836                 return retval;
1837
1838         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1839                                 ut_params->op);
1840         ut_params->obuf = ut_params->op->sym->m_src;
1841         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1842         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1843                         + plaintext_pad_len + tdata->aad.len;
1844
1845         /* Validate obuf */
1846         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1847         ut_params->digest,
1848         tdata->digest.data,
1849         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1850         "Snow3G Generated auth tag not as expected");
1851
1852         return 0;
1853 }
1854
1855 static int
1856 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1857 {
1858         struct crypto_testsuite_params *ts_params = &testsuite_params;
1859         struct crypto_unittest_params *ut_params = &unittest_params;
1860
1861         int retval;
1862         unsigned plaintext_pad_len;
1863         unsigned plaintext_len;
1864         uint8_t *plaintext;
1865
1866         /* Create SNOW3G session */
1867         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1868                                 tdata->key.data, tdata->key.len,
1869                                 tdata->aad.len, tdata->digest.len,
1870                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1871         if (retval < 0)
1872                 return retval;
1873         /* alloc mbuf and set payload */
1874         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1875
1876         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1877         rte_pktmbuf_tailroom(ut_params->ibuf));
1878
1879         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1880         /* Append data which is padded to a multiple of */
1881         /* the algorithms block size */
1882         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1883         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1884                                 plaintext_pad_len);
1885         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1886
1887         /* Create SNOW3G operation */
1888         retval = create_snow3g_hash_operation(tdata->digest.data,
1889                         tdata->digest.len,
1890                         tdata->aad.data, tdata->aad.len,
1891                         plaintext_pad_len,
1892                         RTE_CRYPTO_AUTH_OP_VERIFY,
1893                         tdata->validAuthLenInBits.len,
1894                         tdata->validAuthOffsetLenInBits.len);
1895         if (retval < 0)
1896                 return retval;
1897
1898         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1899                                 ut_params->op);
1900         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1901         ut_params->obuf = ut_params->op->sym->m_src;
1902         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1903                                 + plaintext_pad_len + tdata->aad.len;
1904
1905         /* Validate obuf */
1906         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1907                 return 0;
1908         else
1909                 return -1;
1910
1911         return 0;
1912 }
1913
1914 static int
1915 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1916 {
1917         struct crypto_testsuite_params *ts_params = &testsuite_params;
1918         struct crypto_unittest_params *ut_params = &unittest_params;
1919
1920         int retval;
1921         unsigned plaintext_pad_len;
1922         unsigned plaintext_len;
1923         uint8_t *plaintext;
1924
1925         /* Create KASUMI session */
1926         retval = create_kasumi_hash_session(ts_params->valid_devs[0],
1927                         tdata->key.data, tdata->key.len,
1928                         tdata->aad.len, tdata->digest.len,
1929                         RTE_CRYPTO_AUTH_OP_GENERATE);
1930         if (retval < 0)
1931                 return retval;
1932
1933         /* alloc mbuf and set payload */
1934         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1935
1936         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1937         rte_pktmbuf_tailroom(ut_params->ibuf));
1938
1939         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1940         /* Append data which is padded to a multiple of */
1941         /* the algorithms block size */
1942         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1943         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1944                                 plaintext_pad_len);
1945         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1946
1947         /* Create KASUMI operation */
1948         retval = create_kasumi_hash_operation(NULL, tdata->digest.len,
1949                         tdata->aad.data, tdata->aad.len,
1950                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1951                         tdata->validAuthLenInBits.len,
1952                         tdata->validAuthOffsetLenInBits.len);
1953         if (retval < 0)
1954                 return retval;
1955
1956         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1957                                 ut_params->op);
1958         ut_params->obuf = ut_params->op->sym->m_src;
1959         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1960         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1961                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1962
1963         /* Validate obuf */
1964         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1965         ut_params->digest,
1966         tdata->digest.data,
1967         DIGEST_BYTE_LENGTH_KASUMI_F9,
1968         "KASUMI Generated auth tag not as expected");
1969
1970         return 0;
1971 }
1972
1973 static int
1974 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1975 {
1976         struct crypto_testsuite_params *ts_params = &testsuite_params;
1977         struct crypto_unittest_params *ut_params = &unittest_params;
1978
1979         int retval;
1980         unsigned plaintext_pad_len;
1981         unsigned plaintext_len;
1982         uint8_t *plaintext;
1983
1984         /* Create KASUMI session */
1985         retval = create_kasumi_hash_session(ts_params->valid_devs[0],
1986                                 tdata->key.data, tdata->key.len,
1987                                 tdata->aad.len, tdata->digest.len,
1988                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1989         if (retval < 0)
1990                 return retval;
1991         /* alloc mbuf and set payload */
1992         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1993
1994         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1995         rte_pktmbuf_tailroom(ut_params->ibuf));
1996
1997         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1998         /* Append data which is padded to a multiple */
1999         /* of the algorithms block size */
2000         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2001         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2002                                 plaintext_pad_len);
2003         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2004
2005         /* Create KASUMI operation */
2006         retval = create_kasumi_hash_operation(tdata->digest.data,
2007                         tdata->digest.len,
2008                         tdata->aad.data, tdata->aad.len,
2009                         plaintext_pad_len,
2010                         RTE_CRYPTO_AUTH_OP_VERIFY,
2011                         tdata->validAuthLenInBits.len,
2012                         tdata->validAuthOffsetLenInBits.len);
2013         if (retval < 0)
2014                 return retval;
2015
2016         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2017                                 ut_params->op);
2018         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2019         ut_params->obuf = ut_params->op->sym->m_src;
2020         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2021                                 + plaintext_pad_len + tdata->aad.len;
2022
2023         /* Validate obuf */
2024         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2025                 return 0;
2026         else
2027                 return -1;
2028
2029         return 0;
2030 }
2031
2032 static int
2033 test_snow3g_hash_generate_test_case_1(void)
2034 {
2035         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2036 }
2037
2038 static int
2039 test_snow3g_hash_generate_test_case_2(void)
2040 {
2041         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2042 }
2043
2044 static int
2045 test_snow3g_hash_generate_test_case_3(void)
2046 {
2047         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2048 }
2049
2050 static int
2051 test_snow3g_hash_generate_test_case_4(void)
2052 {
2053         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2054 }
2055
2056 static int
2057 test_snow3g_hash_generate_test_case_5(void)
2058 {
2059         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2060 }
2061
2062 static int
2063 test_snow3g_hash_generate_test_case_6(void)
2064 {
2065         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2066 }
2067
2068 static int
2069 test_snow3g_hash_verify_test_case_1(void)
2070 {
2071         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2072
2073 }
2074
2075 static int
2076 test_snow3g_hash_verify_test_case_2(void)
2077 {
2078         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2079 }
2080
2081 static int
2082 test_snow3g_hash_verify_test_case_3(void)
2083 {
2084         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2085 }
2086
2087 static int
2088 test_snow3g_hash_verify_test_case_4(void)
2089 {
2090         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2091 }
2092
2093 static int
2094 test_snow3g_hash_verify_test_case_5(void)
2095 {
2096         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2097 }
2098
2099 static int
2100 test_snow3g_hash_verify_test_case_6(void)
2101 {
2102         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2103 }
2104
2105 static int
2106 test_kasumi_hash_generate_test_case_1(void)
2107 {
2108         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2109 }
2110
2111 static int
2112 test_kasumi_hash_generate_test_case_2(void)
2113 {
2114         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2115 }
2116
2117 static int
2118 test_kasumi_hash_generate_test_case_3(void)
2119 {
2120         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2121 }
2122
2123 static int
2124 test_kasumi_hash_generate_test_case_4(void)
2125 {
2126         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2127 }
2128
2129 static int
2130 test_kasumi_hash_generate_test_case_5(void)
2131 {
2132         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2133 }
2134
2135 static int
2136 test_kasumi_hash_verify_test_case_1(void)
2137 {
2138         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2139 }
2140
2141 static int
2142 test_kasumi_hash_verify_test_case_2(void)
2143 {
2144         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2145 }
2146
2147 static int
2148 test_kasumi_hash_verify_test_case_3(void)
2149 {
2150         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2151 }
2152
2153 static int
2154 test_kasumi_hash_verify_test_case_4(void)
2155 {
2156         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2157 }
2158
2159 static int
2160 test_kasumi_hash_verify_test_case_5(void)
2161 {
2162         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2163 }
2164
2165 static int
2166 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2167 {
2168         struct crypto_testsuite_params *ts_params = &testsuite_params;
2169         struct crypto_unittest_params *ut_params = &unittest_params;
2170
2171         int retval;
2172         uint8_t *plaintext, *ciphertext;
2173         unsigned plaintext_pad_len;
2174         unsigned plaintext_len;
2175
2176         /* Create KASUMI session */
2177         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2178                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2179                                         tdata->key.data, tdata->key.len);
2180         if (retval < 0)
2181                 return retval;
2182
2183         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2184
2185         /* Clear mbuf payload */
2186         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2187                rte_pktmbuf_tailroom(ut_params->ibuf));
2188
2189         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2190         /* Append data which is padded to a multiple */
2191         /* of the algorithms block size */
2192         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2193         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2194                                 plaintext_pad_len);
2195         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2196
2197         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2198
2199         /* Create KASUMI operation */
2200         retval = create_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2201                                         tdata->plaintext.len,
2202                                         tdata->validCipherOffsetLenInBits.len);
2203         if (retval < 0)
2204                 return retval;
2205
2206         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2207                                                 ut_params->op);
2208         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2209
2210         ut_params->obuf = ut_params->op->sym->m_dst;
2211         if (ut_params->obuf)
2212                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2213                                 + tdata->iv.len;
2214         else
2215                 ciphertext = plaintext;
2216
2217         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2218
2219         /* Validate obuf */
2220         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2221                 ciphertext,
2222                 tdata->ciphertext.data,
2223                 tdata->validCipherLenInBits.len,
2224                 "KASUMI Ciphertext data not as expected");
2225         return 0;
2226 }
2227
2228 static int
2229 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2230 {
2231         struct crypto_testsuite_params *ts_params = &testsuite_params;
2232         struct crypto_unittest_params *ut_params = &unittest_params;
2233
2234         int retval;
2235         uint8_t *plaintext, *ciphertext;
2236         unsigned plaintext_pad_len;
2237         unsigned plaintext_len;
2238
2239         /* Create KASUMI session */
2240         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2241                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2242                                         tdata->key.data, tdata->key.len);
2243         if (retval < 0)
2244                 return retval;
2245
2246         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2247         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2248
2249         /* Clear mbuf payload */
2250         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2251                rte_pktmbuf_tailroom(ut_params->ibuf));
2252
2253         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2254         /* Append data which is padded to a multiple */
2255         /* of the algorithms block size */
2256         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2257         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2258                                 plaintext_pad_len);
2259         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2260         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2261
2262         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2263
2264         /* Create KASUMI operation */
2265         retval = create_kasumi_cipher_operation_oop(tdata->iv.data, tdata->iv.len,
2266                                         tdata->plaintext.len,
2267                                         tdata->validCipherOffsetLenInBits.len);
2268         if (retval < 0)
2269                 return retval;
2270
2271         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2272                                                 ut_params->op);
2273         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2274
2275         ut_params->obuf = ut_params->op->sym->m_dst;
2276         if (ut_params->obuf)
2277                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2278                                 + tdata->iv.len;
2279         else
2280                 ciphertext = plaintext;
2281
2282         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2283
2284         /* Validate obuf */
2285         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2286                 ciphertext,
2287                 tdata->ciphertext.data,
2288                 tdata->validCipherLenInBits.len,
2289                 "KASUMI Ciphertext data not as expected");
2290         return 0;
2291 }
2292
2293 static int
2294 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2295 {
2296         struct crypto_testsuite_params *ts_params = &testsuite_params;
2297         struct crypto_unittest_params *ut_params = &unittest_params;
2298
2299         int retval;
2300         uint8_t *ciphertext, *plaintext;
2301         unsigned ciphertext_pad_len;
2302         unsigned ciphertext_len;
2303
2304         /* Create KASUMI session */
2305         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2306                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2307                                         tdata->key.data, tdata->key.len);
2308         if (retval < 0)
2309                 return retval;
2310
2311         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2312         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2313
2314         /* Clear mbuf payload */
2315         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2316                rte_pktmbuf_tailroom(ut_params->ibuf));
2317
2318         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2319         /* Append data which is padded to a multiple */
2320         /* of the algorithms block size */
2321         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2322         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2323                                 ciphertext_pad_len);
2324         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2325         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2326
2327         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2328
2329         /* Create KASUMI operation */
2330         retval = create_kasumi_cipher_operation_oop(tdata->iv.data, tdata->iv.len,
2331                                         tdata->ciphertext.len,
2332                                         tdata->validCipherOffsetLenInBits.len);
2333         if (retval < 0)
2334                 return retval;
2335
2336         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2337                                                 ut_params->op);
2338         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2339
2340         ut_params->obuf = ut_params->op->sym->m_dst;
2341         if (ut_params->obuf)
2342                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2343                                 + tdata->iv.len;
2344         else
2345                 plaintext = ciphertext;
2346
2347         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2348
2349         /* Validate obuf */
2350         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2351                 plaintext,
2352                 tdata->plaintext.data,
2353                 tdata->validCipherLenInBits.len,
2354                 "KASUMI Plaintext data not as expected");
2355         return 0;
2356 }
2357
2358 static int
2359 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2360 {
2361         struct crypto_testsuite_params *ts_params = &testsuite_params;
2362         struct crypto_unittest_params *ut_params = &unittest_params;
2363
2364         int retval;
2365         uint8_t *ciphertext, *plaintext;
2366         unsigned ciphertext_pad_len;
2367         unsigned ciphertext_len;
2368
2369         /* Create KASUMI session */
2370         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2371                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2372                                         tdata->key.data, tdata->key.len);
2373         if (retval < 0)
2374                 return retval;
2375
2376         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2377
2378         /* Clear mbuf payload */
2379         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2380                rte_pktmbuf_tailroom(ut_params->ibuf));
2381
2382         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2383         /* Append data which is padded to a multiple */
2384         /* of the algorithms block size */
2385         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2386         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2387                                 ciphertext_pad_len);
2388         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2389
2390         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2391
2392         /* Create KASUMI operation */
2393         retval = create_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2394                                         tdata->ciphertext.len,
2395                                         tdata->validCipherOffsetLenInBits.len);
2396         if (retval < 0)
2397                 return retval;
2398
2399         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2400                                                 ut_params->op);
2401         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2402
2403         ut_params->obuf = ut_params->op->sym->m_dst;
2404         if (ut_params->obuf)
2405                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2406                                 + tdata->iv.len;
2407         else
2408                 plaintext = ciphertext;
2409
2410         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2411
2412         /* Validate obuf */
2413         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2414                 plaintext,
2415                 tdata->plaintext.data,
2416                 tdata->validCipherLenInBits.len,
2417                 "KASUMI Plaintext data not as expected");
2418         return 0;
2419 }
2420
2421 static int
2422 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2423 {
2424         struct crypto_testsuite_params *ts_params = &testsuite_params;
2425         struct crypto_unittest_params *ut_params = &unittest_params;
2426
2427         int retval;
2428         uint8_t *plaintext, *ciphertext;
2429         unsigned plaintext_pad_len;
2430         unsigned plaintext_len;
2431
2432         /* Create SNOW3G session */
2433         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2434                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2435                                         tdata->key.data, tdata->key.len);
2436         if (retval < 0)
2437                 return retval;
2438
2439         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2440
2441         /* Clear mbuf payload */
2442         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2443                rte_pktmbuf_tailroom(ut_params->ibuf));
2444
2445         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2446         /* Append data which is padded to a multiple of */
2447         /* the algorithms block size */
2448         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2449         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2450                                 plaintext_pad_len);
2451         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2452
2453         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2454
2455         /* Create SNOW3G operation */
2456         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2457                                         tdata->validCipherLenInBits.len,
2458                                         tdata->validCipherOffsetLenInBits.len);
2459         if (retval < 0)
2460                 return retval;
2461
2462         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2463                                                 ut_params->op);
2464         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2465
2466         ut_params->obuf = ut_params->op->sym->m_dst;
2467         if (ut_params->obuf)
2468                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2469                                 + tdata->iv.len;
2470         else
2471                 ciphertext = plaintext;
2472
2473         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2474
2475         /* Validate obuf */
2476         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2477                 ciphertext,
2478                 tdata->ciphertext.data,
2479                 tdata->validDataLenInBits.len,
2480                 "Snow3G Ciphertext data not as expected");
2481         return 0;
2482 }
2483
2484
2485 static int
2486 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2487 {
2488         struct crypto_testsuite_params *ts_params = &testsuite_params;
2489         struct crypto_unittest_params *ut_params = &unittest_params;
2490         uint8_t *plaintext, *ciphertext;
2491
2492         int retval;
2493         unsigned plaintext_pad_len;
2494         unsigned plaintext_len;
2495
2496         /* Create SNOW3G session */
2497         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2498                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2499                                         tdata->key.data, tdata->key.len);
2500         if (retval < 0)
2501                 return retval;
2502
2503         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2504         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2505
2506         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2507                         "Failed to allocate input buffer in mempool");
2508         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2509                         "Failed to allocate output buffer in mempool");
2510
2511         /* Clear mbuf payload */
2512         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2513                rte_pktmbuf_tailroom(ut_params->ibuf));
2514
2515         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2516         /* Append data which is padded to a multiple of */
2517         /* the algorithms block size */
2518         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2519         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2520                                 plaintext_pad_len);
2521         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2522         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2523
2524         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2525
2526         /* Create SNOW3G operation */
2527         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2528                                         tdata->iv.len,
2529                                         tdata->validCipherLenInBits.len,
2530                                         tdata->validCipherOffsetLenInBits.len);
2531         if (retval < 0)
2532                 return retval;
2533
2534         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2535                                                 ut_params->op);
2536         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2537
2538         ut_params->obuf = ut_params->op->sym->m_dst;
2539         if (ut_params->obuf)
2540                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2541                                 + tdata->iv.len;
2542         else
2543                 ciphertext = plaintext;
2544
2545         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2546
2547         /* Validate obuf */
2548         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2549                 ciphertext,
2550                 tdata->ciphertext.data,
2551                 tdata->validDataLenInBits.len,
2552                 "Snow3G Ciphertext data not as expected");
2553         return 0;
2554 }
2555
2556 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2557 static void
2558 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2559 {
2560         uint8_t curr_byte, prev_byte;
2561         uint32_t length_in_bytes = ceil_byte_length(length + offset);
2562         uint8_t lower_byte_mask = (1 << offset) - 1;
2563         unsigned i;
2564
2565         prev_byte = buffer[0];
2566         buffer[0] >>= offset;
2567
2568         for (i = 1; i < length_in_bytes; i++) {
2569                 curr_byte = buffer[i];
2570                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2571                                 (curr_byte >> offset);
2572                 prev_byte = curr_byte;
2573         }
2574 }
2575
2576 static int
2577 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2578 {
2579         struct crypto_testsuite_params *ts_params = &testsuite_params;
2580         struct crypto_unittest_params *ut_params = &unittest_params;
2581         uint8_t *plaintext, *ciphertext;
2582         int retval;
2583         uint32_t plaintext_len;
2584         uint32_t plaintext_pad_len;
2585         uint8_t extra_offset = 4;
2586         uint8_t *expected_ciphertext_shifted;
2587
2588         /* Create SNOW3G session */
2589         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2590                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2591                                         tdata->key.data, tdata->key.len);
2592         if (retval < 0)
2593                 return retval;
2594
2595         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2596         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2597
2598         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2599                         "Failed to allocate input buffer in mempool");
2600         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2601                         "Failed to allocate output buffer in mempool");
2602
2603         /* Clear mbuf payload */
2604         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2605                rte_pktmbuf_tailroom(ut_params->ibuf));
2606
2607         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2608         /*
2609          * Append data which is padded to a
2610          * multiple of the algorithms block size
2611          */
2612         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2613
2614         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2615                                                 plaintext_pad_len);
2616
2617         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2618
2619         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2620         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2621
2622 #ifdef RTE_APP_TEST_DEBUG
2623         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2624 #endif
2625         /* Create SNOW3G operation */
2626         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2627                                         tdata->iv.len,
2628                                         tdata->validCipherLenInBits.len,
2629                                         tdata->validCipherOffsetLenInBits.len +
2630                                         extra_offset);
2631         if (retval < 0)
2632                 return retval;
2633
2634         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2635                                                 ut_params->op);
2636         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2637
2638         ut_params->obuf = ut_params->op->sym->m_dst;
2639         if (ut_params->obuf)
2640                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2641                                 + tdata->iv.len;
2642         else
2643                 ciphertext = plaintext;
2644
2645 #ifdef RTE_APP_TEST_DEBUG
2646         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2647 #endif
2648
2649         expected_ciphertext_shifted = rte_malloc(NULL,
2650                         ceil_byte_length(plaintext_len + extra_offset), 0);
2651
2652         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2653                         "failed to reserve memory for ciphertext shifted\n");
2654
2655         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2656                         ceil_byte_length(tdata->ciphertext.len));
2657         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2658                         extra_offset);
2659         /* Validate obuf */
2660         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2661                 ciphertext,
2662                 expected_ciphertext_shifted,
2663                 tdata->validDataLenInBits.len,
2664                 extra_offset,
2665                 "Snow3G Ciphertext data not as expected");
2666         return 0;
2667 }
2668
2669 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2670 {
2671         struct crypto_testsuite_params *ts_params = &testsuite_params;
2672         struct crypto_unittest_params *ut_params = &unittest_params;
2673
2674         int retval;
2675
2676         uint8_t *plaintext, *ciphertext;
2677         unsigned ciphertext_pad_len;
2678         unsigned ciphertext_len;
2679
2680         /* Create SNOW3G session */
2681         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2682                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2683                                         tdata->key.data, tdata->key.len);
2684         if (retval < 0)
2685                 return retval;
2686
2687         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2688
2689         /* Clear mbuf payload */
2690         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2691                rte_pktmbuf_tailroom(ut_params->ibuf));
2692
2693         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2694         /* Append data which is padded to a multiple of */
2695         /* the algorithms block size */
2696         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2697         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2698                                 ciphertext_pad_len);
2699         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2700
2701         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2702
2703         /* Create SNOW3G operation */
2704         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2705                                         tdata->validCipherLenInBits.len,
2706                                         tdata->validCipherOffsetLenInBits.len);
2707         if (retval < 0)
2708                 return retval;
2709
2710         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2711                                                 ut_params->op);
2712         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
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, tdata->plaintext.len);
2721
2722         /* Validate obuf */
2723         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2724                                 tdata->plaintext.data,
2725                                 tdata->validDataLenInBits.len,
2726                                 "Snow3G Plaintext data not as expected");
2727         return 0;
2728 }
2729
2730 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2731 {
2732         struct crypto_testsuite_params *ts_params = &testsuite_params;
2733         struct crypto_unittest_params *ut_params = &unittest_params;
2734
2735         int retval;
2736
2737         uint8_t *plaintext, *ciphertext;
2738         unsigned ciphertext_pad_len;
2739         unsigned ciphertext_len;
2740
2741         /* Create SNOW3G session */
2742         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2743                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2744                                         tdata->key.data, tdata->key.len);
2745         if (retval < 0)
2746                 return retval;
2747
2748         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2749         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2750
2751         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2752                         "Failed to allocate input buffer");
2753         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2754                         "Failed to allocate output buffer");
2755
2756         /* Clear mbuf payload */
2757         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2758                rte_pktmbuf_tailroom(ut_params->ibuf));
2759
2760         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2761                        rte_pktmbuf_tailroom(ut_params->obuf));
2762
2763         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2764         /* Append data which is padded to a multiple of */
2765         /* the algorithms block size */
2766         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2767         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2768                                 ciphertext_pad_len);
2769         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2770         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2771
2772         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2773
2774         /* Create SNOW3G operation */
2775         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2776                                         tdata->iv.len,
2777                                         tdata->validCipherLenInBits.len,
2778                                         tdata->validCipherOffsetLenInBits.len);
2779         if (retval < 0)
2780                 return retval;
2781
2782         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2783                                                 ut_params->op);
2784         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2785         ut_params->obuf = ut_params->op->sym->m_dst;
2786         if (ut_params->obuf)
2787                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2788                                 + tdata->iv.len;
2789         else
2790                 plaintext = ciphertext;
2791
2792         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2793
2794         /* Validate obuf */
2795         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2796                                 tdata->plaintext.data,
2797                                 tdata->validDataLenInBits.len,
2798                                 "Snow3G Plaintext data not as expected");
2799         return 0;
2800 }
2801
2802 static int
2803 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2804 {
2805         struct crypto_testsuite_params *ts_params = &testsuite_params;
2806         struct crypto_unittest_params *ut_params = &unittest_params;
2807
2808         int retval;
2809
2810         uint8_t *plaintext, *ciphertext;
2811         unsigned plaintext_pad_len;
2812         unsigned plaintext_len;
2813
2814         /* Create SNOW3G session */
2815         retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2816                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2817                         RTE_CRYPTO_AUTH_OP_GENERATE,
2818                         tdata->key.data, tdata->key.len,
2819                         tdata->aad.len, tdata->digest.len);
2820         if (retval < 0)
2821                 return retval;
2822         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
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         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2835
2836         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2837
2838         /* Create SNOW3G operation */
2839         retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2840                         tdata->digest.len, tdata->aad.data,
2841                         tdata->aad.len, /*tdata->plaintext.len,*/
2842                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2843                         tdata->iv.data, tdata->iv.len,
2844                         tdata->validCipherLenInBits.len,
2845                         tdata->validCipherOffsetLenInBits.len,
2846                         tdata->validAuthLenInBits.len,
2847                         tdata->validAuthOffsetLenInBits.len);
2848         if (retval < 0)
2849                 return retval;
2850
2851         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2852                         ut_params->op);
2853         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2854         ut_params->obuf = ut_params->op->sym->m_src;
2855         if (ut_params->obuf)
2856                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2857                                 + tdata->iv.len;
2858         else
2859                 ciphertext = plaintext;
2860
2861         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2862
2863         /* Validate obuf */
2864         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2865                         ciphertext,
2866                         tdata->ciphertext.data,
2867                         tdata->validDataLenInBits.len,
2868                         "Snow3G Ciphertext data not as expected");
2869
2870         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2871             + plaintext_pad_len + tdata->aad.len;
2872
2873         /* Validate obuf */
2874         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2875                         ut_params->digest,
2876                         tdata->digest.data,
2877                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2878                         "Snow3G Generated auth tag not as expected");
2879         return 0;
2880 }
2881 static int
2882 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2883 {
2884         struct crypto_testsuite_params *ts_params = &testsuite_params;
2885         struct crypto_unittest_params *ut_params = &unittest_params;
2886
2887         int retval;
2888
2889         uint8_t *plaintext, *ciphertext;
2890         unsigned plaintext_pad_len;
2891         unsigned plaintext_len;
2892
2893         /* Create SNOW3G session */
2894         retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2895                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2896                         RTE_CRYPTO_AUTH_OP_GENERATE,
2897                         tdata->key.data, tdata->key.len,
2898                         tdata->aad.len, tdata->digest.len);
2899         if (retval < 0)
2900                 return retval;
2901
2902         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2903
2904         /* clear mbuf payload */
2905         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2906                         rte_pktmbuf_tailroom(ut_params->ibuf));
2907
2908         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2909         /* Append data which is padded to a multiple of */
2910         /* the algorithms block size */
2911         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2912         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2913                                 plaintext_pad_len);
2914         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2915
2916         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2917
2918         /* Create SNOW3G operation */
2919         retval = create_snow3g_auth_cipher_operation(
2920                 tdata->digest.len,
2921                 tdata->iv.data, tdata->iv.len,
2922                 tdata->aad.data, tdata->aad.len,
2923                 plaintext_pad_len,
2924                 tdata->validCipherLenInBits.len,
2925                 tdata->validCipherOffsetLenInBits.len,
2926                 tdata->validAuthLenInBits.len,
2927                 tdata->validAuthOffsetLenInBits.len
2928         );
2929
2930         if (retval < 0)
2931                 return retval;
2932
2933         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2934                         ut_params->op);
2935         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2936         ut_params->obuf = ut_params->op->sym->m_src;
2937         if (ut_params->obuf)
2938                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2939                                 + tdata->aad.len + tdata->iv.len;
2940         else
2941                 ciphertext = plaintext;
2942
2943         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2944                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2945         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2946
2947         /* Validate obuf */
2948         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2949                 ciphertext,
2950                 tdata->ciphertext.data,
2951                 tdata->validDataLenInBits.len,
2952                 "Snow3G Ciphertext data not as expected");
2953
2954         /* Validate obuf */
2955         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2956                 ut_params->digest,
2957                 tdata->digest.data,
2958                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2959                 "Snow3G Generated auth tag not as expected");
2960         return 0;
2961 }
2962
2963 static int
2964 test_kasumi_encryption_test_case_1(void)
2965 {
2966         return test_kasumi_encryption(&kasumi_test_case_1);
2967 }
2968
2969 static int
2970 test_kasumi_encryption_test_case_1_oop(void)
2971 {
2972         return test_kasumi_encryption_oop(&kasumi_test_case_1);
2973 }
2974
2975 static int
2976 test_kasumi_encryption_test_case_2(void)
2977 {
2978         return test_kasumi_encryption(&kasumi_test_case_2);
2979 }
2980
2981 static int
2982 test_kasumi_encryption_test_case_3(void)
2983 {
2984         return test_kasumi_encryption(&kasumi_test_case_3);
2985 }
2986
2987 static int
2988 test_kasumi_encryption_test_case_4(void)
2989 {
2990         return test_kasumi_encryption(&kasumi_test_case_4);
2991 }
2992
2993 static int
2994 test_kasumi_encryption_test_case_5(void)
2995 {
2996         return test_kasumi_encryption(&kasumi_test_case_5);
2997 }
2998
2999 static int
3000 test_kasumi_decryption_test_case_1(void)
3001 {
3002         return test_kasumi_decryption(&kasumi_test_case_1);
3003 }
3004
3005 static int
3006 test_kasumi_decryption_test_case_1_oop(void)
3007 {
3008         return test_kasumi_decryption_oop(&kasumi_test_case_1);
3009 }
3010
3011 static int
3012 test_kasumi_decryption_test_case_2(void)
3013 {
3014         return test_kasumi_decryption(&kasumi_test_case_2);
3015 }
3016
3017 static int
3018 test_kasumi_decryption_test_case_3(void)
3019 {
3020         return test_kasumi_decryption(&kasumi_test_case_3);
3021 }
3022
3023 static int
3024 test_kasumi_decryption_test_case_4(void)
3025 {
3026         return test_kasumi_decryption(&kasumi_test_case_4);
3027 }
3028
3029 static int
3030 test_kasumi_decryption_test_case_5(void)
3031 {
3032         return test_kasumi_decryption(&kasumi_test_case_5);
3033 }
3034 static int
3035 test_snow3g_encryption_test_case_1(void)
3036 {
3037         return test_snow3g_encryption(&snow3g_test_case_1);
3038 }
3039
3040 static int
3041 test_snow3g_encryption_test_case_1_oop(void)
3042 {
3043         return test_snow3g_encryption_oop(&snow3g_test_case_1);
3044 }
3045
3046 static int
3047 test_snow3g_encryption_test_case_1_offset_oop(void)
3048 {
3049         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3050 }
3051
3052 static int
3053 test_snow3g_encryption_test_case_2(void)
3054 {
3055         return test_snow3g_encryption(&snow3g_test_case_2);
3056 }
3057
3058 static int
3059 test_snow3g_encryption_test_case_3(void)
3060 {
3061         return test_snow3g_encryption(&snow3g_test_case_3);
3062 }
3063
3064 static int
3065 test_snow3g_encryption_test_case_4(void)
3066 {
3067         return test_snow3g_encryption(&snow3g_test_case_4);
3068 }
3069
3070 static int
3071 test_snow3g_encryption_test_case_5(void)
3072 {
3073         return test_snow3g_encryption(&snow3g_test_case_5);
3074 }
3075
3076 static int
3077 test_snow3g_decryption_test_case_1(void)
3078 {
3079         return test_snow3g_decryption(&snow3g_test_case_1);
3080 }
3081
3082 static int
3083 test_snow3g_decryption_test_case_1_oop(void)
3084 {
3085         return test_snow3g_decryption_oop(&snow3g_test_case_1);
3086 }
3087
3088 static int
3089 test_snow3g_decryption_test_case_2(void)
3090 {
3091         return test_snow3g_decryption(&snow3g_test_case_2);
3092 }
3093
3094 static int
3095 test_snow3g_decryption_test_case_3(void)
3096 {
3097         return test_snow3g_decryption(&snow3g_test_case_3);
3098 }
3099
3100 static int
3101 test_snow3g_decryption_test_case_4(void)
3102 {
3103         return test_snow3g_decryption(&snow3g_test_case_4);
3104 }
3105
3106 static int
3107 test_snow3g_decryption_test_case_5(void)
3108 {
3109         return test_snow3g_decryption(&snow3g_test_case_5);
3110 }
3111 static int
3112 test_snow3g_authenticated_encryption_test_case_1(void)
3113 {
3114         return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
3115 }
3116
3117 static int
3118 test_snow3g_encrypted_authentication_test_case_1(void)
3119 {
3120         return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
3121 }
3122
3123 /* ***** AES-GCM Tests ***** */
3124
3125 static int
3126 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3127                 const uint8_t *key, const uint8_t key_len,
3128                 const uint8_t aad_len, const uint8_t auth_len)
3129 {
3130         uint8_t cipher_key[key_len];
3131
3132         struct crypto_unittest_params *ut_params = &unittest_params;
3133
3134
3135         memcpy(cipher_key, key, key_len);
3136
3137         /* Setup Cipher Parameters */
3138         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3139         ut_params->cipher_xform.next = NULL;
3140
3141         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3142         ut_params->cipher_xform.cipher.op = op;
3143         ut_params->cipher_xform.cipher.key.data = cipher_key;
3144         ut_params->cipher_xform.cipher.key.length = key_len;
3145
3146         TEST_HEXDUMP(stdout, "key:", key, key_len);
3147
3148         /* Setup Authentication Parameters */
3149         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3150         ut_params->auth_xform.next = NULL;
3151
3152         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3153
3154         ut_params->auth_xform.auth.digest_length = auth_len;
3155         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3156         ut_params->auth_xform.auth.key.length = 0;
3157         ut_params->auth_xform.auth.key.data = NULL;
3158
3159         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3160                 ut_params->cipher_xform.next = &ut_params->auth_xform;
3161
3162                 /* Create Crypto session*/
3163                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3164                                 &ut_params->cipher_xform);
3165         } else {/* Create Crypto session*/
3166                 ut_params->auth_xform.next = &ut_params->cipher_xform;
3167                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3168                                 &ut_params->auth_xform);
3169         }
3170
3171         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3172
3173         return 0;
3174 }
3175
3176 static int
3177 create_gcm_operation(enum rte_crypto_cipher_operation op,
3178                 const uint8_t *auth_tag, const unsigned auth_tag_len,
3179                 const uint8_t *iv, const unsigned iv_len,
3180                 const uint8_t *aad, const unsigned aad_len,
3181                 const unsigned data_len, unsigned data_pad_len)
3182 {
3183         struct crypto_testsuite_params *ts_params = &testsuite_params;
3184         struct crypto_unittest_params *ut_params = &unittest_params;
3185
3186         unsigned iv_pad_len = 0, aad_buffer_len;
3187
3188         /* Generate Crypto op data structure */
3189         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3190                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3191         TEST_ASSERT_NOT_NULL(ut_params->op,
3192                         "Failed to allocate symmetric crypto operation struct");
3193
3194         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3195
3196
3197
3198         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3199                         ut_params->ibuf, auth_tag_len);
3200         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3201                         "no room to append digest");
3202         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3203                         ut_params->ibuf, data_pad_len);
3204         sym_op->auth.digest.length = auth_tag_len;
3205
3206         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3207                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3208                 TEST_HEXDUMP(stdout, "digest:",
3209                                 sym_op->auth.digest.data,
3210                                 sym_op->auth.digest.length);
3211         }
3212
3213         /* iv */
3214         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3215
3216         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3217                         ut_params->ibuf, iv_pad_len);
3218         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3219
3220         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3221         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3222         sym_op->cipher.iv.length = iv_pad_len;
3223
3224         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3225
3226         /* CalcY0 */
3227         if (iv_len != 16)
3228                 sym_op->cipher.iv.data[15] = 1;
3229
3230         /*
3231          * Always allocate the aad up to the block size.
3232          * The cryptodev API calls out -
3233          *  - the array must be big enough to hold the AAD, plus any
3234          *   space to round this up to the nearest multiple of the
3235          *   block size (16 bytes).
3236          */
3237         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3238
3239         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3240                         ut_params->ibuf, aad_buffer_len);
3241         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3242                         "no room to prepend aad");
3243         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3244                         ut_params->ibuf);
3245         sym_op->auth.aad.length = aad_len;
3246
3247         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3248         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3249
3250         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3251         TEST_HEXDUMP(stdout, "aad:",
3252                         sym_op->auth.aad.data, aad_len);
3253
3254         sym_op->cipher.data.length = data_len;
3255         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3256
3257         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3258         sym_op->auth.data.length = data_len;
3259
3260         return 0;
3261 }
3262
3263 static int
3264 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3265 {
3266         struct crypto_testsuite_params *ts_params = &testsuite_params;
3267         struct crypto_unittest_params *ut_params = &unittest_params;
3268
3269         int retval;
3270
3271         uint8_t *plaintext, *ciphertext, *auth_tag;
3272         uint16_t plaintext_pad_len;
3273
3274         /* Create GCM session */
3275         retval = create_gcm_session(ts_params->valid_devs[0],
3276                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3277                         tdata->key.data, tdata->key.len,
3278                         tdata->aad.len, tdata->auth_tag.len);
3279         if (retval < 0)
3280                 return retval;
3281
3282
3283         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3284
3285         /* clear mbuf payload */
3286         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3287                         rte_pktmbuf_tailroom(ut_params->ibuf));
3288
3289         /*
3290          * Append data which is padded to a multiple
3291          * of the algorithms block size
3292          */
3293         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3294
3295         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3296                         plaintext_pad_len);
3297         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3298
3299         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3300
3301         /* Create GCM opertaion */
3302         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3303                         tdata->auth_tag.data, tdata->auth_tag.len,
3304                         tdata->iv.data, tdata->iv.len,
3305                         tdata->aad.data, tdata->aad.len,
3306                         tdata->plaintext.len, plaintext_pad_len);
3307         if (retval < 0)
3308                 return retval;
3309
3310         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3311
3312         ut_params->op->sym->m_src = ut_params->ibuf;
3313
3314         /* Process crypto operation */
3315         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3316                         ut_params->op), "failed to process sym crypto op");
3317
3318         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3319                         "crypto op processing failed");
3320
3321         if (ut_params->op->sym->m_dst) {
3322                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3323                                 uint8_t *);
3324                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3325                                 uint8_t *, plaintext_pad_len);
3326         } else {
3327                 ciphertext = plaintext;
3328                 auth_tag = plaintext + plaintext_pad_len;
3329         }
3330
3331         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3332         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3333
3334         /* Validate obuf */
3335         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3336                         ciphertext,
3337                         tdata->ciphertext.data,
3338                         tdata->ciphertext.len,
3339                         "GCM Ciphertext data not as expected");
3340
3341         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3342                         auth_tag,
3343                         tdata->auth_tag.data,
3344                         tdata->auth_tag.len,
3345                         "GCM Generated auth tag not as expected");
3346
3347         return 0;
3348
3349 }
3350
3351 static int
3352 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3353 {
3354         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3355 }
3356
3357 static int
3358 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3359 {
3360         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3361 }
3362
3363 static int
3364 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3365 {
3366         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3367 }
3368
3369 static int
3370 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3371 {
3372         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3373 }
3374
3375 static int
3376 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3377 {
3378         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3379 }
3380
3381 static int
3382 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3383 {
3384         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3385 }
3386
3387 static int
3388 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3389 {
3390         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3391 }
3392
3393 static int
3394 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3395 {
3396         struct crypto_testsuite_params *ts_params = &testsuite_params;
3397         struct crypto_unittest_params *ut_params = &unittest_params;
3398
3399         int retval;
3400
3401         uint8_t *plaintext, *ciphertext;
3402         uint16_t ciphertext_pad_len;
3403
3404         /* Create GCM session */
3405         retval = create_gcm_session(ts_params->valid_devs[0],
3406                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3407                         tdata->key.data, tdata->key.len,
3408                         tdata->aad.len, tdata->auth_tag.len);
3409         if (retval < 0)
3410                 return retval;
3411
3412
3413         /* alloc mbuf and set payload */
3414         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3415
3416         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3417                         rte_pktmbuf_tailroom(ut_params->ibuf));
3418
3419         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3420
3421         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3422                         ciphertext_pad_len);
3423         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3424
3425         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3426
3427         /* Create GCM opertaion */
3428         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3429                         tdata->auth_tag.data, tdata->auth_tag.len,
3430                         tdata->iv.data, tdata->iv.len,
3431                         tdata->aad.data, tdata->aad.len,
3432                         tdata->ciphertext.len, ciphertext_pad_len);
3433         if (retval < 0)
3434                 return retval;
3435
3436
3437         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3438
3439         ut_params->op->sym->m_src = ut_params->ibuf;
3440
3441         /* Process crypto operation */
3442         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3443                         ut_params->op), "failed to process sym crypto op");
3444
3445         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3446                         "crypto op processing failed");
3447
3448         if (ut_params->op->sym->m_dst)
3449                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3450                                 uint8_t *);
3451         else
3452                 plaintext = ciphertext;
3453
3454         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3455
3456         /* Validate obuf */
3457         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3458                         plaintext,
3459                         tdata->plaintext.data,
3460                         tdata->plaintext.len,
3461                         "GCM plaintext data not as expected");
3462
3463         TEST_ASSERT_EQUAL(ut_params->op->status,
3464                         RTE_CRYPTO_OP_STATUS_SUCCESS,
3465                         "GCM authentication failed");
3466         return 0;
3467 }
3468
3469 static int
3470 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3471 {
3472         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3473 }
3474
3475 static int
3476 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3477 {
3478         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3479 }
3480
3481 static int
3482 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3483 {
3484         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3485 }
3486
3487 static int
3488 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3489 {
3490         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3491 }
3492
3493 static int
3494 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3495 {
3496         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3497 }
3498
3499 static int
3500 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3501 {
3502         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3503 }
3504
3505 static int
3506 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3507 {
3508         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3509 }
3510
3511 static int
3512 test_stats(void)
3513 {
3514         struct crypto_testsuite_params *ts_params = &testsuite_params;
3515         struct rte_cryptodev_stats stats;
3516         struct rte_cryptodev *dev;
3517         cryptodev_stats_get_t temp_pfn;
3518
3519         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3520         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3521                         &stats) == -ENODEV),
3522                 "rte_cryptodev_stats_get invalid dev failed");
3523         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3524                 "rte_cryptodev_stats_get invalid Param failed");
3525         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3526         temp_pfn = dev->dev_ops->stats_get;
3527         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3528         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3529                         == -ENOTSUP),
3530                 "rte_cryptodev_stats_get invalid Param failed");
3531         dev->dev_ops->stats_get = temp_pfn;
3532
3533         /* Test expected values */
3534         ut_setup();
3535         test_AES_CBC_HMAC_SHA1_encrypt_digest();
3536         ut_teardown();
3537         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3538                         &stats),
3539                 "rte_cryptodev_stats_get failed");
3540         TEST_ASSERT((stats.enqueued_count == 1),
3541                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3542         TEST_ASSERT((stats.dequeued_count == 1),
3543                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3544         TEST_ASSERT((stats.enqueue_err_count == 0),
3545                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3546         TEST_ASSERT((stats.dequeue_err_count == 0),
3547                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3548
3549         /* invalid device but should ignore and not reset device stats*/
3550         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3551         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3552                         &stats),
3553                 "rte_cryptodev_stats_get failed");
3554         TEST_ASSERT((stats.enqueued_count == 1),
3555                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3556
3557         /* check that a valid reset clears stats */
3558         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3559         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3560                         &stats),
3561                                           "rte_cryptodev_stats_get failed");
3562         TEST_ASSERT((stats.enqueued_count == 0),
3563                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3564         TEST_ASSERT((stats.dequeued_count == 0),
3565                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3566
3567         return TEST_SUCCESS;
3568 }
3569
3570
3571 static int
3572 test_multi_session(void)
3573 {
3574         struct crypto_testsuite_params *ts_params = &testsuite_params;
3575         struct crypto_unittest_params *ut_params = &unittest_params;
3576
3577         struct rte_cryptodev_info dev_info;
3578         struct rte_cryptodev_sym_session **sessions;
3579
3580         uint16_t i;
3581
3582         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3583
3584
3585         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3586
3587         sessions = rte_malloc(NULL,
3588                         (sizeof(struct rte_cryptodev_sym_session *) *
3589                         dev_info.sym.max_nb_sessions) + 1, 0);
3590
3591         /* Create multiple crypto sessions*/
3592         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3593                 sessions[i] = rte_cryptodev_sym_session_create(
3594                                 ts_params->valid_devs[0],
3595                         &ut_params->auth_xform);
3596                 TEST_ASSERT_NOT_NULL(sessions[i],
3597                                 "Session creation failed at session number %u",
3598                                 i);
3599
3600                 /* Attempt to send a request on each session */
3601                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3602                                 sessions[i], ut_params, ts_params),
3603                                 "Failed to perform decrypt on request "
3604                                 "number %u.", i);
3605                 /* free crypto operation structure */
3606                 if (ut_params->op)
3607                         rte_crypto_op_free(ut_params->op);
3608
3609                 /*
3610                  * free mbuf - both obuf and ibuf are usually the same,
3611                  * but rte copes even if we call free twice
3612                  */
3613                 if (ut_params->obuf) {
3614                         rte_pktmbuf_free(ut_params->obuf);
3615                         ut_params->obuf = 0;
3616                 }
3617         }
3618
3619         /* Next session create should fail */
3620         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3621                         &ut_params->auth_xform);
3622         TEST_ASSERT_NULL(sessions[i],
3623                         "Session creation succeeded unexpectedly!");
3624
3625         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3626                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3627                                 sessions[i]);
3628
3629         rte_free(sessions);
3630
3631         return TEST_SUCCESS;
3632 }
3633
3634 static int
3635 test_null_cipher_only_operation(void)
3636 {
3637         struct crypto_testsuite_params *ts_params = &testsuite_params;
3638         struct crypto_unittest_params *ut_params = &unittest_params;
3639
3640         /* Generate test mbuf data and space for digest */
3641         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3642                         catch_22_quote, QUOTE_512_BYTES, 0);
3643
3644         /* Setup Cipher Parameters */
3645         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3646         ut_params->cipher_xform.next = NULL;
3647
3648         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3649         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3650
3651         /* Create Crypto session*/
3652         ut_params->sess = rte_cryptodev_sym_session_create(
3653                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3654         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3655
3656         /* Generate Crypto op data structure */
3657         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3658                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3659         TEST_ASSERT_NOT_NULL(ut_params->op,
3660                         "Failed to allocate symmetric crypto operation struct");
3661
3662         /* Set crypto operation data parameters */
3663         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3664
3665         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3666
3667         /* set crypto operation source mbuf */
3668         sym_op->m_src = ut_params->ibuf;
3669
3670         sym_op->cipher.data.offset = 0;
3671         sym_op->cipher.data.length = QUOTE_512_BYTES;
3672
3673         /* Process crypto operation */
3674         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3675                         ut_params->op);
3676         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3677
3678         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3679                         "crypto operation processing failed");
3680
3681         /* Validate obuf */
3682         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3683                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3684                         catch_22_quote,
3685                         QUOTE_512_BYTES,
3686                         "Ciphertext data not as expected");
3687
3688         return TEST_SUCCESS;
3689 }
3690
3691 static int
3692 test_null_auth_only_operation(void)
3693 {
3694         struct crypto_testsuite_params *ts_params = &testsuite_params;
3695         struct crypto_unittest_params *ut_params = &unittest_params;
3696
3697         /* Generate test mbuf data and space for digest */
3698         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3699                         catch_22_quote, QUOTE_512_BYTES, 0);
3700
3701         /* Setup HMAC Parameters */
3702         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3703         ut_params->auth_xform.next = NULL;
3704
3705         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3706         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3707
3708         /* Create Crypto session*/
3709         ut_params->sess = rte_cryptodev_sym_session_create(
3710                         ts_params->valid_devs[0], &ut_params->auth_xform);
3711         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3712
3713         /* Generate Crypto op data structure */
3714         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3715                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3716         TEST_ASSERT_NOT_NULL(ut_params->op,
3717                         "Failed to allocate symmetric crypto operation struct");
3718
3719         /* Set crypto operation data parameters */
3720         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3721
3722         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3723
3724         sym_op->m_src = ut_params->ibuf;
3725
3726         sym_op->auth.data.offset = 0;
3727         sym_op->auth.data.length = QUOTE_512_BYTES;
3728
3729         /* Process crypto operation */
3730         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3731                         ut_params->op);
3732         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3733
3734         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3735                         "crypto operation processing failed");
3736
3737         return TEST_SUCCESS;
3738 }
3739
3740 static int
3741 test_null_cipher_auth_operation(void)
3742 {
3743         struct crypto_testsuite_params *ts_params = &testsuite_params;
3744         struct crypto_unittest_params *ut_params = &unittest_params;
3745
3746         /* Generate test mbuf data and space for digest */
3747         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3748                         catch_22_quote, QUOTE_512_BYTES, 0);
3749
3750         /* Setup Cipher Parameters */
3751         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3752         ut_params->cipher_xform.next = &ut_params->auth_xform;
3753
3754         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3755         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3756
3757         /* Setup HMAC Parameters */
3758         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3759         ut_params->auth_xform.next = NULL;
3760
3761         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3762         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3763
3764         /* Create Crypto session*/
3765         ut_params->sess = rte_cryptodev_sym_session_create(
3766                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3767         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3768
3769         /* Generate Crypto op data structure */
3770         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3771                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3772         TEST_ASSERT_NOT_NULL(ut_params->op,
3773                         "Failed to allocate symmetric crypto operation struct");
3774
3775         /* Set crypto operation data parameters */
3776         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3777
3778         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3779
3780         sym_op->m_src = ut_params->ibuf;
3781
3782         sym_op->cipher.data.offset = 0;
3783         sym_op->cipher.data.length = QUOTE_512_BYTES;
3784
3785         sym_op->auth.data.offset = 0;
3786         sym_op->auth.data.length = QUOTE_512_BYTES;
3787
3788         /* Process crypto operation */
3789         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3790                         ut_params->op);
3791         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3792
3793         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3794                         "crypto operation processing failed");
3795
3796         /* Validate obuf */
3797         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3798                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3799                         catch_22_quote,
3800                         QUOTE_512_BYTES,
3801                         "Ciphertext data not as expected");
3802
3803         return TEST_SUCCESS;
3804 }
3805
3806 static int
3807 test_null_auth_cipher_operation(void)
3808 {
3809         struct crypto_testsuite_params *ts_params = &testsuite_params;
3810         struct crypto_unittest_params *ut_params = &unittest_params;
3811
3812         /* Generate test mbuf data and space for digest */
3813         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3814                         catch_22_quote, QUOTE_512_BYTES, 0);
3815
3816         /* Setup Cipher Parameters */
3817         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3818         ut_params->cipher_xform.next = NULL;
3819
3820         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3821         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3822
3823         /* Setup HMAC Parameters */
3824         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3825         ut_params->auth_xform.next = &ut_params->cipher_xform;
3826
3827         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3828         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3829
3830         /* Create Crypto session*/
3831         ut_params->sess = rte_cryptodev_sym_session_create(
3832                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3833         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3834
3835         /* Generate Crypto op data structure */
3836         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3837                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3838         TEST_ASSERT_NOT_NULL(ut_params->op,
3839                         "Failed to allocate symmetric crypto operation struct");
3840
3841         /* Set crypto operation data parameters */
3842         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3843
3844         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3845
3846         sym_op->m_src = ut_params->ibuf;
3847
3848         sym_op->cipher.data.offset = 0;
3849         sym_op->cipher.data.length = QUOTE_512_BYTES;
3850
3851         sym_op->auth.data.offset = 0;
3852         sym_op->auth.data.length = QUOTE_512_BYTES;
3853
3854         /* Process crypto operation */
3855         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3856                         ut_params->op);
3857         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3858
3859         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3860                         "crypto operation processing failed");
3861
3862         /* Validate obuf */
3863         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3864                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3865                         catch_22_quote,
3866                         QUOTE_512_BYTES,
3867                         "Ciphertext data not as expected");
3868
3869         return TEST_SUCCESS;
3870 }
3871
3872
3873 static int
3874 test_null_invalid_operation(void)
3875 {
3876         struct crypto_testsuite_params *ts_params = &testsuite_params;
3877         struct crypto_unittest_params *ut_params = &unittest_params;
3878
3879         /* Setup Cipher Parameters */
3880         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3881         ut_params->cipher_xform.next = NULL;
3882
3883         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3884         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3885
3886         /* Create Crypto session*/
3887         ut_params->sess = rte_cryptodev_sym_session_create(
3888                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3889         TEST_ASSERT_NULL(ut_params->sess,
3890                         "Session creation succeeded unexpectedly");
3891
3892
3893         /* Setup HMAC Parameters */
3894         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3895         ut_params->auth_xform.next = NULL;
3896
3897         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3898         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3899
3900         /* Create Crypto session*/
3901         ut_params->sess = rte_cryptodev_sym_session_create(
3902                         ts_params->valid_devs[0], &ut_params->auth_xform);
3903         TEST_ASSERT_NULL(ut_params->sess,
3904                         "Session creation succeeded unexpectedly");
3905
3906         return TEST_SUCCESS;
3907 }
3908
3909
3910 #define NULL_BURST_LENGTH (32)
3911
3912 static int
3913 test_null_burst_operation(void)
3914 {
3915         struct crypto_testsuite_params *ts_params = &testsuite_params;
3916         struct crypto_unittest_params *ut_params = &unittest_params;
3917
3918         unsigned i, burst_len = NULL_BURST_LENGTH;
3919
3920         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3921         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3922
3923         /* Setup Cipher Parameters */
3924         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3925         ut_params->cipher_xform.next = &ut_params->auth_xform;
3926
3927         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3928         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3929
3930         /* Setup HMAC Parameters */
3931         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3932         ut_params->auth_xform.next = NULL;
3933
3934         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3935         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3936
3937         /* Create Crypto session*/
3938         ut_params->sess = rte_cryptodev_sym_session_create(
3939                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3940         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3941
3942         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3943                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3944                         burst_len, "failed to generate burst of crypto ops");
3945
3946         /* Generate an operation for each mbuf in burst */
3947         for (i = 0; i < burst_len; i++) {
3948                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3949
3950                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3951
3952                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3953                                 sizeof(unsigned));
3954                 *data = i;
3955
3956                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3957
3958                 burst[i]->sym->m_src = m;
3959         }
3960
3961         /* Process crypto operation */
3962         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3963                         0, burst, burst_len),
3964                         burst_len,
3965                         "Error enqueuing burst");
3966
3967         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3968                         0, burst_dequeued, burst_len),
3969                         burst_len,
3970                         "Error dequeuing burst");
3971
3972
3973         for (i = 0; i < burst_len; i++) {
3974                 TEST_ASSERT_EQUAL(
3975                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3976                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3977                                         uint32_t *),
3978                         "data not as expected");
3979
3980                 rte_pktmbuf_free(burst[i]->sym->m_src);
3981                 rte_crypto_op_free(burst[i]);
3982         }
3983
3984         return TEST_SUCCESS;
3985 }
3986
3987
3988
3989
3990 static struct unit_test_suite cryptodev_qat_testsuite  = {
3991         .suite_name = "Crypto QAT Unit Test Suite",
3992         .setup = testsuite_setup,
3993         .teardown = testsuite_teardown,
3994         .unit_test_cases = {
3995                 TEST_CASE_ST(ut_setup, ut_teardown,
3996                                 test_device_configure_invalid_dev_id),
3997                 TEST_CASE_ST(ut_setup, ut_teardown,
3998                                 test_device_configure_invalid_queue_pair_ids),
3999                 TEST_CASE_ST(ut_setup, ut_teardown,
4000                                 test_queue_pair_descriptor_setup),
4001                 TEST_CASE_ST(ut_setup, ut_teardown,
4002                                 test_multi_session),
4003
4004                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
4005                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4006
4007                 /** AES GCM Authenticated Encryption */
4008                 TEST_CASE_ST(ut_setup, ut_teardown,
4009                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
4010                 TEST_CASE_ST(ut_setup, ut_teardown,
4011                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
4012                 TEST_CASE_ST(ut_setup, ut_teardown,
4013                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
4014                 TEST_CASE_ST(ut_setup, ut_teardown,
4015                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
4016                 TEST_CASE_ST(ut_setup, ut_teardown,
4017                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
4018                 TEST_CASE_ST(ut_setup, ut_teardown,
4019                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
4020                 TEST_CASE_ST(ut_setup, ut_teardown,
4021                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
4022
4023                 /** AES GCM Authenticated Decryption */
4024                 TEST_CASE_ST(ut_setup, ut_teardown,
4025                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
4026                 TEST_CASE_ST(ut_setup, ut_teardown,
4027                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
4028                 TEST_CASE_ST(ut_setup, ut_teardown,
4029                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
4030                 TEST_CASE_ST(ut_setup, ut_teardown,
4031                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
4032                 TEST_CASE_ST(ut_setup, ut_teardown,
4033                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
4034                 TEST_CASE_ST(ut_setup, ut_teardown,
4035                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
4036                 TEST_CASE_ST(ut_setup, ut_teardown,
4037                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
4038
4039                 /** Snow3G encrypt only (UEA2) */
4040                 TEST_CASE_ST(ut_setup, ut_teardown,
4041                         test_snow3g_encryption_test_case_1),
4042                 TEST_CASE_ST(ut_setup, ut_teardown,
4043                         test_snow3g_encryption_test_case_2),
4044                 TEST_CASE_ST(ut_setup, ut_teardown,
4045                         test_snow3g_encryption_test_case_3),
4046                 TEST_CASE_ST(ut_setup, ut_teardown,
4047                         test_snow3g_encryption_test_case_4),
4048                 TEST_CASE_ST(ut_setup, ut_teardown,
4049                         test_snow3g_encryption_test_case_5),
4050
4051                 TEST_CASE_ST(ut_setup, ut_teardown,
4052                         test_snow3g_encryption_test_case_1_oop),
4053                 TEST_CASE_ST(ut_setup, ut_teardown,
4054                         test_snow3g_decryption_test_case_1_oop),
4055
4056                 /** Snow3G decrypt only (UEA2) */
4057                 TEST_CASE_ST(ut_setup, ut_teardown,
4058                         test_snow3g_decryption_test_case_1),
4059                 TEST_CASE_ST(ut_setup, ut_teardown,
4060                         test_snow3g_decryption_test_case_2),
4061                 TEST_CASE_ST(ut_setup, ut_teardown,
4062                         test_snow3g_decryption_test_case_3),
4063                 TEST_CASE_ST(ut_setup, ut_teardown,
4064                         test_snow3g_decryption_test_case_4),
4065                 TEST_CASE_ST(ut_setup, ut_teardown,
4066                         test_snow3g_decryption_test_case_5),
4067                 TEST_CASE_ST(ut_setup, ut_teardown,
4068                         test_snow3g_hash_generate_test_case_1),
4069                 TEST_CASE_ST(ut_setup, ut_teardown,
4070                         test_snow3g_hash_generate_test_case_2),
4071                 TEST_CASE_ST(ut_setup, ut_teardown,
4072                         test_snow3g_hash_generate_test_case_3),
4073                 TEST_CASE_ST(ut_setup, ut_teardown,
4074                         test_snow3g_hash_verify_test_case_1),
4075                 TEST_CASE_ST(ut_setup, ut_teardown,
4076                         test_snow3g_hash_verify_test_case_2),
4077                 TEST_CASE_ST(ut_setup, ut_teardown,
4078                         test_snow3g_hash_verify_test_case_3),
4079                 TEST_CASE_ST(ut_setup, ut_teardown,
4080                         test_snow3g_authenticated_encryption_test_case_1),
4081                 TEST_CASE_ST(ut_setup, ut_teardown,
4082                         test_snow3g_encrypted_authentication_test_case_1),
4083                 TEST_CASES_END() /**< NULL terminate unit test array */
4084         }
4085 };
4086
4087 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
4088         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4089         .setup = testsuite_setup,
4090         .teardown = testsuite_teardown,
4091         .unit_test_cases = {
4092                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
4093
4094                 TEST_CASES_END() /**< NULL terminate unit test array */
4095         }
4096 };
4097
4098 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
4099         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4100         .setup = testsuite_setup,
4101         .teardown = testsuite_teardown,
4102         .unit_test_cases = {
4103                 /** AES GCM Authenticated Encryption */
4104                 TEST_CASE_ST(ut_setup, ut_teardown,
4105                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
4106                 TEST_CASE_ST(ut_setup, ut_teardown,
4107                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
4108                 TEST_CASE_ST(ut_setup, ut_teardown,
4109                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
4110                 TEST_CASE_ST(ut_setup, ut_teardown,
4111                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
4112                 TEST_CASE_ST(ut_setup, ut_teardown,
4113                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
4114                 TEST_CASE_ST(ut_setup, ut_teardown,
4115                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
4116                 TEST_CASE_ST(ut_setup, ut_teardown,
4117                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
4118
4119                 /** AES GCM Authenticated Decryption */
4120                 TEST_CASE_ST(ut_setup, ut_teardown,
4121                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
4122                 TEST_CASE_ST(ut_setup, ut_teardown,
4123                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
4124                 TEST_CASE_ST(ut_setup, ut_teardown,
4125                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
4126                 TEST_CASE_ST(ut_setup, ut_teardown,
4127                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
4128                 TEST_CASE_ST(ut_setup, ut_teardown,
4129                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
4130                 TEST_CASE_ST(ut_setup, ut_teardown,
4131                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
4132                 TEST_CASE_ST(ut_setup, ut_teardown,
4133                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
4134
4135                 TEST_CASES_END() /**< NULL terminate unit test array */
4136         }
4137 };
4138
4139 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
4140         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4141         .setup = testsuite_setup,
4142         .teardown = testsuite_teardown,
4143         .unit_test_cases = {
4144                 /** KASUMI encrypt only (UEA1) */
4145                 TEST_CASE_ST(ut_setup, ut_teardown,
4146                         test_kasumi_encryption_test_case_1),
4147                 TEST_CASE_ST(ut_setup, ut_teardown,
4148                         test_kasumi_encryption_test_case_2),
4149                 TEST_CASE_ST(ut_setup, ut_teardown,
4150                         test_kasumi_encryption_test_case_3),
4151                 TEST_CASE_ST(ut_setup, ut_teardown,
4152                         test_kasumi_encryption_test_case_4),
4153                 TEST_CASE_ST(ut_setup, ut_teardown,
4154                         test_kasumi_encryption_test_case_5),
4155                 /** KASUMI decrypt only (UEA1) */
4156                 TEST_CASE_ST(ut_setup, ut_teardown,
4157                         test_kasumi_decryption_test_case_1),
4158                 TEST_CASE_ST(ut_setup, ut_teardown,
4159                         test_kasumi_decryption_test_case_2),
4160                 TEST_CASE_ST(ut_setup, ut_teardown,
4161                         test_kasumi_decryption_test_case_3),
4162                 TEST_CASE_ST(ut_setup, ut_teardown,
4163                         test_kasumi_decryption_test_case_4),
4164                 TEST_CASE_ST(ut_setup, ut_teardown,
4165                         test_kasumi_decryption_test_case_5),
4166
4167                 TEST_CASE_ST(ut_setup, ut_teardown,
4168                         test_kasumi_encryption_test_case_1_oop),
4169                 TEST_CASE_ST(ut_setup, ut_teardown,
4170                         test_kasumi_decryption_test_case_1_oop),
4171
4172                 /** KASUMI hash only (UIA1) */
4173                 TEST_CASE_ST(ut_setup, ut_teardown,
4174                         test_kasumi_hash_generate_test_case_1),
4175                 TEST_CASE_ST(ut_setup, ut_teardown,
4176                         test_kasumi_hash_generate_test_case_2),
4177                 TEST_CASE_ST(ut_setup, ut_teardown,
4178                         test_kasumi_hash_generate_test_case_3),
4179                 TEST_CASE_ST(ut_setup, ut_teardown,
4180                         test_kasumi_hash_generate_test_case_4),
4181                 TEST_CASE_ST(ut_setup, ut_teardown,
4182                         test_kasumi_hash_generate_test_case_5),
4183                 TEST_CASE_ST(ut_setup, ut_teardown,
4184                         test_kasumi_hash_verify_test_case_1),
4185                 TEST_CASE_ST(ut_setup, ut_teardown,
4186                         test_kasumi_hash_verify_test_case_2),
4187                 TEST_CASE_ST(ut_setup, ut_teardown,
4188                         test_kasumi_hash_verify_test_case_3),
4189                 TEST_CASE_ST(ut_setup, ut_teardown,
4190                         test_kasumi_hash_verify_test_case_4),
4191                 TEST_CASE_ST(ut_setup, ut_teardown,
4192                         test_kasumi_hash_verify_test_case_5),
4193
4194                 TEST_CASES_END() /**< NULL terminate unit test array */
4195         }
4196 };
4197 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
4198         .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4199         .setup = testsuite_setup,
4200         .teardown = testsuite_teardown,
4201         .unit_test_cases = {
4202                 /** Snow3G encrypt only (UEA2) */
4203                 TEST_CASE_ST(ut_setup, ut_teardown,
4204                         test_snow3g_encryption_test_case_1),
4205                 TEST_CASE_ST(ut_setup, ut_teardown,
4206                         test_snow3g_encryption_test_case_2),
4207                 TEST_CASE_ST(ut_setup, ut_teardown,
4208                         test_snow3g_encryption_test_case_3),
4209                 TEST_CASE_ST(ut_setup, ut_teardown,
4210                         test_snow3g_encryption_test_case_4),
4211                 TEST_CASE_ST(ut_setup, ut_teardown,
4212                         test_snow3g_encryption_test_case_5),
4213
4214                 TEST_CASE_ST(ut_setup, ut_teardown,
4215                         test_snow3g_encryption_test_case_1_oop),
4216                 TEST_CASE_ST(ut_setup, ut_teardown,
4217                         test_snow3g_decryption_test_case_1_oop),
4218
4219                 TEST_CASE_ST(ut_setup, ut_teardown,
4220                         test_snow3g_encryption_test_case_1_offset_oop),
4221
4222                 /** Snow3G decrypt only (UEA2) */
4223                 TEST_CASE_ST(ut_setup, ut_teardown,
4224                         test_snow3g_decryption_test_case_1),
4225                 TEST_CASE_ST(ut_setup, ut_teardown,
4226                         test_snow3g_decryption_test_case_2),
4227                 TEST_CASE_ST(ut_setup, ut_teardown,
4228                         test_snow3g_decryption_test_case_3),
4229                 TEST_CASE_ST(ut_setup, ut_teardown,
4230                         test_snow3g_decryption_test_case_4),
4231                 TEST_CASE_ST(ut_setup, ut_teardown,
4232                         test_snow3g_decryption_test_case_5),
4233                 TEST_CASE_ST(ut_setup, ut_teardown,
4234                         test_snow3g_hash_generate_test_case_1),
4235                 TEST_CASE_ST(ut_setup, ut_teardown,
4236                         test_snow3g_hash_generate_test_case_2),
4237                 TEST_CASE_ST(ut_setup, ut_teardown,
4238                         test_snow3g_hash_generate_test_case_3),
4239                 /* Tests with buffers which length is not byte-aligned */
4240                 TEST_CASE_ST(ut_setup, ut_teardown,
4241                         test_snow3g_hash_generate_test_case_4),
4242                 TEST_CASE_ST(ut_setup, ut_teardown,
4243                         test_snow3g_hash_generate_test_case_5),
4244                 TEST_CASE_ST(ut_setup, ut_teardown,
4245                         test_snow3g_hash_generate_test_case_6),
4246                 TEST_CASE_ST(ut_setup, ut_teardown,
4247                         test_snow3g_hash_verify_test_case_1),
4248                 TEST_CASE_ST(ut_setup, ut_teardown,
4249                         test_snow3g_hash_verify_test_case_2),
4250                 TEST_CASE_ST(ut_setup, ut_teardown,
4251                         test_snow3g_hash_verify_test_case_3),
4252                 /* Tests with buffers which length is not byte-aligned */
4253                 TEST_CASE_ST(ut_setup, ut_teardown,
4254                         test_snow3g_hash_verify_test_case_4),
4255                 TEST_CASE_ST(ut_setup, ut_teardown,
4256                         test_snow3g_hash_verify_test_case_5),
4257                 TEST_CASE_ST(ut_setup, ut_teardown,
4258                         test_snow3g_hash_verify_test_case_6),
4259                 TEST_CASE_ST(ut_setup, ut_teardown,
4260                         test_snow3g_authenticated_encryption_test_case_1),
4261                 TEST_CASE_ST(ut_setup, ut_teardown,
4262                         test_snow3g_encrypted_authentication_test_case_1),
4263
4264                 TEST_CASES_END() /**< NULL terminate unit test array */
4265         }
4266 };
4267
4268 static struct unit_test_suite cryptodev_null_testsuite  = {
4269         .suite_name = "Crypto Device NULL Unit Test Suite",
4270         .setup = testsuite_setup,
4271         .teardown = testsuite_teardown,
4272         .unit_test_cases = {
4273                 TEST_CASE_ST(ut_setup, ut_teardown,
4274                         test_null_auth_only_operation),
4275                 TEST_CASE_ST(ut_setup, ut_teardown,
4276                         test_null_cipher_only_operation),
4277                 TEST_CASE_ST(ut_setup, ut_teardown,
4278                         test_null_cipher_auth_operation),
4279                 TEST_CASE_ST(ut_setup, ut_teardown,
4280                         test_null_auth_cipher_operation),
4281                 TEST_CASE_ST(ut_setup, ut_teardown,
4282                         test_null_invalid_operation),
4283                 TEST_CASE_ST(ut_setup, ut_teardown,
4284                         test_null_burst_operation),
4285
4286                 TEST_CASES_END() /**< NULL terminate unit test array */
4287         }
4288 };
4289
4290 static int
4291 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4292 {
4293         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4294         return unit_test_suite_runner(&cryptodev_qat_testsuite);
4295 }
4296 static struct test_command cryptodev_qat_cmd = {
4297         .command = "cryptodev_qat_autotest",
4298         .callback = test_cryptodev_qat,
4299 };
4300
4301 static int
4302 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4303 {
4304         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4305
4306         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4307 }
4308
4309 static struct test_command cryptodev_aesni_mb_cmd = {
4310         .command = "cryptodev_aesni_mb_autotest",
4311         .callback = test_cryptodev_aesni_mb,
4312 };
4313
4314 static int
4315 test_cryptodev_aesni_gcm(void)
4316 {
4317         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4318
4319         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4320 }
4321
4322 static struct test_command cryptodev_aesni_gcm_cmd = {
4323         .command = "cryptodev_aesni_gcm_autotest",
4324         .callback = test_cryptodev_aesni_gcm,
4325 };
4326
4327 static int
4328 test_cryptodev_null(void)
4329 {
4330         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4331
4332         return unit_test_suite_runner(&cryptodev_null_testsuite);
4333 }
4334
4335 static struct test_command cryptodev_null_cmd = {
4336         .command = "cryptodev_null_autotest",
4337         .callback = test_cryptodev_null,
4338 };
4339
4340 static int
4341 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4342 {
4343         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4344
4345         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4346 }
4347
4348 static struct test_command cryptodev_sw_snow3g_cmd = {
4349         .command = "cryptodev_sw_snow3g_autotest",
4350         .callback = test_cryptodev_sw_snow3g,
4351 };
4352
4353 static int
4354 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4355 {
4356         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4357
4358         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4359 }
4360
4361 static struct test_command cryptodev_sw_kasumi_cmd = {
4362         .command = "cryptodev_sw_kasumi_autotest",
4363         .callback = test_cryptodev_sw_kasumi,
4364 };
4365
4366 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4367 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4368 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4369 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4370 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);
4371 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_cmd);