app/test: use new bit-level memcmp macro
[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         uint8_t *plaintext;
1805
1806         /* Create SNOW3G session */
1807         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1808                         tdata->key.data, tdata->key.len,
1809                         tdata->aad.len, tdata->digest.len,
1810                         RTE_CRYPTO_AUTH_OP_GENERATE);
1811         if (retval < 0)
1812                 return retval;
1813
1814         /* alloc mbuf and set payload */
1815         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1816
1817         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1818         rte_pktmbuf_tailroom(ut_params->ibuf));
1819
1820         /* Append data which is padded to a multiple of */
1821         /* the algorithms block size */
1822         plaintext_pad_len = tdata->plaintext.len >> 3;
1823         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1824                                 plaintext_pad_len);
1825         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1826
1827         /* Create SNOW3G opertaion */
1828         retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1829                         tdata->aad.data, tdata->aad.len,
1830                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1831                         tdata->validAuthLenInBits.len,
1832                         tdata->validAuthOffsetLenInBits.len);
1833         if (retval < 0)
1834                 return retval;
1835
1836         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1837                                 ut_params->op);
1838         ut_params->obuf = ut_params->op->sym->m_src;
1839         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1840         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1841                         + plaintext_pad_len + tdata->aad.len;
1842
1843         /* Validate obuf */
1844         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1845         ut_params->digest,
1846         tdata->digest.data,
1847         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1848         "Snow3G Generated auth tag not as expected");
1849
1850         return 0;
1851 }
1852
1853 static int
1854 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1855 {
1856         struct crypto_testsuite_params *ts_params = &testsuite_params;
1857         struct crypto_unittest_params *ut_params = &unittest_params;
1858
1859         int retval;
1860         unsigned plaintext_pad_len;
1861         uint8_t *plaintext;
1862
1863         /* Create SNOW3G session */
1864         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1865                                 tdata->key.data, tdata->key.len,
1866                                 tdata->aad.len, tdata->digest.len,
1867                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1868         if (retval < 0)
1869                 return retval;
1870         /* alloc mbuf and set payload */
1871         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1872
1873         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1874         rte_pktmbuf_tailroom(ut_params->ibuf));
1875
1876         /* Append data which is padded to a multiple */
1877         /* of the algorithms block size */
1878         plaintext_pad_len = tdata->plaintext.len >> 3;
1879         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1880                                         plaintext_pad_len);
1881         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1882
1883         /* Create SNOW3G operation */
1884         retval = create_snow3g_hash_operation(tdata->digest.data,
1885                         tdata->digest.len,
1886                         tdata->aad.data, tdata->aad.len,
1887                         plaintext_pad_len,
1888                         RTE_CRYPTO_AUTH_OP_VERIFY,
1889                         tdata->validAuthLenInBits.len,
1890                         tdata->validAuthOffsetLenInBits.len);
1891         if (retval < 0)
1892                 return retval;
1893
1894         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1895                                 ut_params->op);
1896         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1897         ut_params->obuf = ut_params->op->sym->m_src;
1898         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1899                                 + plaintext_pad_len + tdata->aad.len;
1900
1901         /* Validate obuf */
1902         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1903                 return 0;
1904         else
1905                 return -1;
1906
1907         return 0;
1908 }
1909
1910 static int
1911 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1912 {
1913         struct crypto_testsuite_params *ts_params = &testsuite_params;
1914         struct crypto_unittest_params *ut_params = &unittest_params;
1915
1916         int retval;
1917         unsigned plaintext_pad_len;
1918         unsigned plaintext_len;
1919         uint8_t *plaintext;
1920
1921         /* Create KASUMI session */
1922         retval = create_kasumi_hash_session(ts_params->valid_devs[0],
1923                         tdata->key.data, tdata->key.len,
1924                         tdata->aad.len, tdata->digest.len,
1925                         RTE_CRYPTO_AUTH_OP_GENERATE);
1926         if (retval < 0)
1927                 return retval;
1928
1929         /* alloc mbuf and set payload */
1930         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1931
1932         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1933         rte_pktmbuf_tailroom(ut_params->ibuf));
1934
1935         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1936         /* Append data which is padded to a multiple of */
1937         /* the algorithms block size */
1938         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1939         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1940                                 plaintext_pad_len);
1941         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1942
1943         /* Create KASUMI operation */
1944         retval = create_kasumi_hash_operation(NULL, tdata->digest.len,
1945                         tdata->aad.data, tdata->aad.len,
1946                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1947                         tdata->validAuthLenInBits.len,
1948                         tdata->validAuthOffsetLenInBits.len);
1949         if (retval < 0)
1950                 return retval;
1951
1952         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1953                                 ut_params->op);
1954         ut_params->obuf = ut_params->op->sym->m_src;
1955         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1956         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1957                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1958
1959         /* Validate obuf */
1960         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1961         ut_params->digest,
1962         tdata->digest.data,
1963         DIGEST_BYTE_LENGTH_KASUMI_F9,
1964         "KASUMI Generated auth tag not as expected");
1965
1966         return 0;
1967 }
1968
1969 static int
1970 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1971 {
1972         struct crypto_testsuite_params *ts_params = &testsuite_params;
1973         struct crypto_unittest_params *ut_params = &unittest_params;
1974
1975         int retval;
1976         unsigned plaintext_pad_len;
1977         unsigned plaintext_len;
1978         uint8_t *plaintext;
1979
1980         /* Create KASUMI session */
1981         retval = create_kasumi_hash_session(ts_params->valid_devs[0],
1982                                 tdata->key.data, tdata->key.len,
1983                                 tdata->aad.len, tdata->digest.len,
1984                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1985         if (retval < 0)
1986                 return retval;
1987         /* alloc mbuf and set payload */
1988         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1989
1990         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1991         rte_pktmbuf_tailroom(ut_params->ibuf));
1992
1993         plaintext_len = ceil_byte_length(tdata->plaintext.len);
1994         /* Append data which is padded to a multiple */
1995         /* of the algorithms block size */
1996         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1997         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1998                                 plaintext_pad_len);
1999         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2000
2001         /* Create KASUMI operation */
2002         retval = create_kasumi_hash_operation(tdata->digest.data,
2003                         tdata->digest.len,
2004                         tdata->aad.data, tdata->aad.len,
2005                         plaintext_pad_len,
2006                         RTE_CRYPTO_AUTH_OP_VERIFY,
2007                         tdata->validAuthLenInBits.len,
2008                         tdata->validAuthOffsetLenInBits.len);
2009         if (retval < 0)
2010                 return retval;
2011
2012         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2013                                 ut_params->op);
2014         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2015         ut_params->obuf = ut_params->op->sym->m_src;
2016         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2017                                 + plaintext_pad_len + tdata->aad.len;
2018
2019         /* Validate obuf */
2020         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2021                 return 0;
2022         else
2023                 return -1;
2024
2025         return 0;
2026 }
2027
2028 static int
2029 test_snow3g_hash_generate_test_case_1(void)
2030 {
2031         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2032 }
2033
2034 static int
2035 test_snow3g_hash_generate_test_case_2(void)
2036 {
2037         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2038 }
2039
2040 static int
2041 test_snow3g_hash_generate_test_case_3(void)
2042 {
2043         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2044 }
2045
2046 static int
2047 test_snow3g_hash_verify_test_case_1(void)
2048 {
2049         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2050
2051 }
2052
2053 static int
2054 test_snow3g_hash_verify_test_case_2(void)
2055 {
2056         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2057 }
2058
2059 static int
2060 test_snow3g_hash_verify_test_case_3(void)
2061 {
2062         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2063 }
2064
2065 static int
2066 test_kasumi_hash_generate_test_case_1(void)
2067 {
2068         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2069 }
2070
2071 static int
2072 test_kasumi_hash_generate_test_case_2(void)
2073 {
2074         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2075 }
2076
2077 static int
2078 test_kasumi_hash_generate_test_case_3(void)
2079 {
2080         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2081 }
2082
2083 static int
2084 test_kasumi_hash_generate_test_case_4(void)
2085 {
2086         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2087 }
2088
2089 static int
2090 test_kasumi_hash_generate_test_case_5(void)
2091 {
2092         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2093 }
2094
2095 static int
2096 test_kasumi_hash_verify_test_case_1(void)
2097 {
2098         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2099 }
2100
2101 static int
2102 test_kasumi_hash_verify_test_case_2(void)
2103 {
2104         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2105 }
2106
2107 static int
2108 test_kasumi_hash_verify_test_case_3(void)
2109 {
2110         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2111 }
2112
2113 static int
2114 test_kasumi_hash_verify_test_case_4(void)
2115 {
2116         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2117 }
2118
2119 static int
2120 test_kasumi_hash_verify_test_case_5(void)
2121 {
2122         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2123 }
2124
2125 static int
2126 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2127 {
2128         struct crypto_testsuite_params *ts_params = &testsuite_params;
2129         struct crypto_unittest_params *ut_params = &unittest_params;
2130
2131         int retval;
2132         uint8_t *plaintext, *ciphertext;
2133         unsigned plaintext_pad_len;
2134         unsigned plaintext_len;
2135
2136         /* Create KASUMI session */
2137         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2138                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2139                                         tdata->key.data, tdata->key.len);
2140         if (retval < 0)
2141                 return retval;
2142
2143         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2144
2145         /* Clear mbuf payload */
2146         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2147                rte_pktmbuf_tailroom(ut_params->ibuf));
2148
2149         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2150         /* Append data which is padded to a multiple */
2151         /* of the algorithms block size */
2152         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2153         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2154                                 plaintext_pad_len);
2155         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2156
2157         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2158
2159         /* Create KASUMI operation */
2160         retval = create_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2161                                         tdata->plaintext.len,
2162                                         tdata->validCipherOffsetLenInBits.len);
2163         if (retval < 0)
2164                 return retval;
2165
2166         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2167                                                 ut_params->op);
2168         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2169
2170         ut_params->obuf = ut_params->op->sym->m_dst;
2171         if (ut_params->obuf)
2172                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2173                                 + tdata->iv.len;
2174         else
2175                 ciphertext = plaintext;
2176
2177         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2178
2179         /* Validate obuf */
2180         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2181                 ciphertext,
2182                 tdata->ciphertext.data,
2183                 tdata->validCipherLenInBits.len,
2184                 "KASUMI Ciphertext data not as expected");
2185         return 0;
2186 }
2187
2188 static int
2189 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2190 {
2191         struct crypto_testsuite_params *ts_params = &testsuite_params;
2192         struct crypto_unittest_params *ut_params = &unittest_params;
2193
2194         int retval;
2195         uint8_t *plaintext, *ciphertext;
2196         unsigned plaintext_pad_len;
2197         unsigned plaintext_len;
2198
2199         /* Create KASUMI session */
2200         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2201                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2202                                         tdata->key.data, tdata->key.len);
2203         if (retval < 0)
2204                 return retval;
2205
2206         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2207         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2208
2209         /* Clear mbuf payload */
2210         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2211                rte_pktmbuf_tailroom(ut_params->ibuf));
2212
2213         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2214         /* Append data which is padded to a multiple */
2215         /* of the algorithms block size */
2216         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2217         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2218                                 plaintext_pad_len);
2219         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2220         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2221
2222         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2223
2224         /* Create KASUMI operation */
2225         retval = create_kasumi_cipher_operation_oop(tdata->iv.data, tdata->iv.len,
2226                                         tdata->plaintext.len,
2227                                         tdata->validCipherOffsetLenInBits.len);
2228         if (retval < 0)
2229                 return retval;
2230
2231         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2232                                                 ut_params->op);
2233         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2234
2235         ut_params->obuf = ut_params->op->sym->m_dst;
2236         if (ut_params->obuf)
2237                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2238                                 + tdata->iv.len;
2239         else
2240                 ciphertext = plaintext;
2241
2242         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2243
2244         /* Validate obuf */
2245         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2246                 ciphertext,
2247                 tdata->ciphertext.data,
2248                 tdata->validCipherLenInBits.len,
2249                 "KASUMI Ciphertext data not as expected");
2250         return 0;
2251 }
2252
2253 static int
2254 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2255 {
2256         struct crypto_testsuite_params *ts_params = &testsuite_params;
2257         struct crypto_unittest_params *ut_params = &unittest_params;
2258
2259         int retval;
2260         uint8_t *ciphertext, *plaintext;
2261         unsigned ciphertext_pad_len;
2262         unsigned ciphertext_len;
2263
2264         /* Create KASUMI session */
2265         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2266                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2267                                         tdata->key.data, tdata->key.len);
2268         if (retval < 0)
2269                 return retval;
2270
2271         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2272         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2273
2274         /* Clear mbuf payload */
2275         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2276                rte_pktmbuf_tailroom(ut_params->ibuf));
2277
2278         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2279         /* Append data which is padded to a multiple */
2280         /* of the algorithms block size */
2281         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2282         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2283                                 ciphertext_pad_len);
2284         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2285         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2286
2287         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2288
2289         /* Create KASUMI operation */
2290         retval = create_kasumi_cipher_operation_oop(tdata->iv.data, tdata->iv.len,
2291                                         tdata->ciphertext.len,
2292                                         tdata->validCipherOffsetLenInBits.len);
2293         if (retval < 0)
2294                 return retval;
2295
2296         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2297                                                 ut_params->op);
2298         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2299
2300         ut_params->obuf = ut_params->op->sym->m_dst;
2301         if (ut_params->obuf)
2302                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2303                                 + tdata->iv.len;
2304         else
2305                 plaintext = ciphertext;
2306
2307         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2308
2309         /* Validate obuf */
2310         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2311                 plaintext,
2312                 tdata->plaintext.data,
2313                 tdata->validCipherLenInBits.len,
2314                 "KASUMI Plaintext data not as expected");
2315         return 0;
2316 }
2317
2318 static int
2319 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2320 {
2321         struct crypto_testsuite_params *ts_params = &testsuite_params;
2322         struct crypto_unittest_params *ut_params = &unittest_params;
2323
2324         int retval;
2325         uint8_t *ciphertext, *plaintext;
2326         unsigned ciphertext_pad_len;
2327         unsigned ciphertext_len;
2328
2329         /* Create KASUMI session */
2330         retval = create_kasumi_cipher_session(ts_params->valid_devs[0],
2331                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2332                                         tdata->key.data, tdata->key.len);
2333         if (retval < 0)
2334                 return retval;
2335
2336         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2337
2338         /* Clear mbuf payload */
2339         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2340                rte_pktmbuf_tailroom(ut_params->ibuf));
2341
2342         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2343         /* Append data which is padded to a multiple */
2344         /* of the algorithms block size */
2345         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2346         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2347                                 ciphertext_pad_len);
2348         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2349
2350         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2351
2352         /* Create KASUMI operation */
2353         retval = create_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2354                                         tdata->ciphertext.len,
2355                                         tdata->validCipherOffsetLenInBits.len);
2356         if (retval < 0)
2357                 return retval;
2358
2359         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2360                                                 ut_params->op);
2361         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2362
2363         ut_params->obuf = ut_params->op->sym->m_dst;
2364         if (ut_params->obuf)
2365                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2366                                 + tdata->iv.len;
2367         else
2368                 plaintext = ciphertext;
2369
2370         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2371
2372         /* Validate obuf */
2373         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2374                 plaintext,
2375                 tdata->plaintext.data,
2376                 tdata->validCipherLenInBits.len,
2377                 "KASUMI Plaintext data not as expected");
2378         return 0;
2379 }
2380
2381 static int
2382 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2383 {
2384         struct crypto_testsuite_params *ts_params = &testsuite_params;
2385         struct crypto_unittest_params *ut_params = &unittest_params;
2386
2387         int retval;
2388         uint8_t *plaintext, *ciphertext;
2389         uint8_t plaintext_pad_len;
2390
2391         /* Create SNOW3G session */
2392         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2393                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2394                                         tdata->key.data, tdata->key.len);
2395         if (retval < 0)
2396                 return retval;
2397
2398         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2399
2400         /* Clear mbuf payload */
2401         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2402                rte_pktmbuf_tailroom(ut_params->ibuf));
2403
2404         /*
2405          * Append data which is padded to a
2406          * multiple of the algorithms block size
2407          */
2408         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2409         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2410
2411         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2412                                                 plaintext_pad_len);
2413         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2414
2415         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2416
2417         /* Create SNOW3G operation */
2418         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2419                                         tdata->validCipherLenInBits.len,
2420                                         tdata->validCipherOffsetLenInBits.len);
2421         if (retval < 0)
2422                 return retval;
2423
2424         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2425                                                 ut_params->op);
2426         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2427
2428         ut_params->obuf = ut_params->op->sym->m_dst;
2429         if (ut_params->obuf)
2430                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2431                                 + tdata->iv.len;
2432         else
2433                 ciphertext = plaintext;
2434
2435         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2436
2437         /* Validate obuf */
2438         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2439                 ciphertext,
2440                 tdata->ciphertext.data,
2441                 tdata->validDataLenInBits.len,
2442                 "Snow3G Ciphertext data not as expected");
2443         return 0;
2444 }
2445
2446
2447 static int
2448 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2449 {
2450         struct crypto_testsuite_params *ts_params = &testsuite_params;
2451         struct crypto_unittest_params *ut_params = &unittest_params;
2452         uint8_t *plaintext, *ciphertext;
2453
2454         int retval;
2455         uint8_t plaintext_pad_len;
2456
2457         /* Create SNOW3G session */
2458         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2459                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2460                                         tdata->key.data, tdata->key.len);
2461         if (retval < 0)
2462                 return retval;
2463
2464         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2465         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2466
2467         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2468                         "Failed to allocate input buffer in mempool");
2469         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2470                         "Failed to allocate output buffer in mempool");
2471
2472         /* Clear mbuf payload */
2473         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2474                rte_pktmbuf_tailroom(ut_params->ibuf));
2475
2476         /*
2477          * Append data which is padded to a
2478          * multiple of the algorithms block size
2479          */
2480         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2481         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2482
2483         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2484                                                 plaintext_pad_len);
2485
2486         rte_pktmbuf_append(ut_params->obuf,
2487                                                 plaintext_pad_len);
2488
2489         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2490
2491         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2492
2493         /* Create SNOW3G operation */
2494         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2495                                         tdata->iv.len,
2496                                         tdata->validCipherLenInBits.len,
2497                                         tdata->validCipherOffsetLenInBits.len);
2498         if (retval < 0)
2499                 return retval;
2500
2501         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2502                                                 ut_params->op);
2503         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2504
2505         ut_params->obuf = ut_params->op->sym->m_dst;
2506         if (ut_params->obuf)
2507                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2508                                 + tdata->iv.len;
2509         else
2510                 ciphertext = plaintext;
2511
2512         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2513
2514         /* Validate obuf */
2515         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2516                 ciphertext,
2517                 tdata->ciphertext.data,
2518                 tdata->validDataLenInBits.len,
2519                 "Snow3G Ciphertext data not as expected");
2520         return 0;
2521 }
2522
2523
2524 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2525 {
2526         struct crypto_testsuite_params *ts_params = &testsuite_params;
2527         struct crypto_unittest_params *ut_params = &unittest_params;
2528
2529         int retval;
2530
2531         uint8_t *plaintext, *ciphertext;
2532         uint8_t ciphertext_pad_len;
2533
2534         /* Create SNOW3G session */
2535         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2536                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2537                                         tdata->key.data, tdata->key.len);
2538         if (retval < 0)
2539                 return retval;
2540
2541         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2542
2543         /* Clear mbuf payload */
2544         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2545                rte_pktmbuf_tailroom(ut_params->ibuf));
2546
2547         /*
2548          * Append data which is padded to a
2549          * multiple of the algorithms block size
2550          */
2551         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2552
2553         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2554                                                 ciphertext_pad_len);
2555         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2556
2557         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2558
2559         /* Create SNOW3G operation */
2560         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2561                                         tdata->validCipherLenInBits.len,
2562                                         tdata->validCipherOffsetLenInBits.len);
2563         if (retval < 0)
2564                 return retval;
2565
2566         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2567                                                 ut_params->op);
2568         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2569         ut_params->obuf = ut_params->op->sym->m_src;
2570         if (ut_params->obuf)
2571                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2572                                 + tdata->iv.len;
2573         else
2574                 plaintext = ciphertext;
2575
2576         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2577
2578         /* Validate obuf */
2579         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2580                                 tdata->plaintext.data,
2581                                 tdata->validDataLenInBits.len,
2582                                 "Snow3G Plaintext data not as expected");
2583         return 0;
2584 }
2585
2586 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2587 {
2588         struct crypto_testsuite_params *ts_params = &testsuite_params;
2589         struct crypto_unittest_params *ut_params = &unittest_params;
2590
2591         int retval;
2592
2593         uint8_t *plaintext, *ciphertext;
2594         uint8_t ciphertext_pad_len;
2595
2596         /* Create SNOW3G session */
2597         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2598                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2599                                         tdata->key.data, tdata->key.len);
2600         if (retval < 0)
2601                 return retval;
2602
2603         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2604         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2605
2606         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2607                         "Failed to allocate input buffer");
2608         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2609                         "Failed to allocate output buffer");
2610
2611         /* Clear mbuf payload */
2612         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2613                rte_pktmbuf_tailroom(ut_params->ibuf));
2614
2615         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2616                        rte_pktmbuf_tailroom(ut_params->obuf));
2617
2618         /*
2619          * Append data which is padded to a
2620          * multiple of the algorithms block size
2621          */
2622         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2623
2624         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2625                                                 ciphertext_pad_len);
2626
2627         rte_pktmbuf_append(ut_params->obuf,
2628                                                 ciphertext_pad_len);
2629
2630         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2631
2632         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2633
2634         /* Create SNOW3G operation */
2635         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2636                                         tdata->iv.len,
2637                                         tdata->validCipherLenInBits.len,
2638                                         tdata->validCipherOffsetLenInBits.len);
2639         if (retval < 0)
2640                 return retval;
2641
2642         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2643                                                 ut_params->op);
2644         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2645         ut_params->obuf = ut_params->op->sym->m_dst;
2646         if (ut_params->obuf)
2647                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2648                                 + tdata->iv.len;
2649         else
2650                 plaintext = ciphertext;
2651
2652         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2653
2654         /* Validate obuf */
2655         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2656                                 tdata->plaintext.data,
2657                                 tdata->validDataLenInBits.len,
2658                                 "Snow3G Plaintext data not as expected");
2659         return 0;
2660 }
2661
2662 static int
2663 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2664 {
2665         struct crypto_testsuite_params *ts_params = &testsuite_params;
2666         struct crypto_unittest_params *ut_params = &unittest_params;
2667
2668         int retval;
2669
2670         uint8_t *plaintext, *ciphertext;
2671         uint8_t plaintext_pad_len;
2672
2673         /* Create SNOW3G session */
2674         retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2675                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2676                         RTE_CRYPTO_AUTH_OP_GENERATE,
2677                         tdata->key.data, tdata->key.len,
2678                         tdata->aad.len, tdata->digest.len);
2679         if (retval < 0)
2680                 return retval;
2681         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2682
2683         /* clear mbuf payload */
2684         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2685                         rte_pktmbuf_tailroom(ut_params->ibuf));
2686
2687         /* Append data which is padded to a multiple */
2688         /*  of the algorithms block size */
2689         plaintext_pad_len = tdata->plaintext.len >> 3;
2690
2691         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2692                         plaintext_pad_len);
2693         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2694
2695         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2696
2697         /* Create SNOW3G operation */
2698         retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2699                         tdata->digest.len, tdata->aad.data,
2700                         tdata->aad.len, /*tdata->plaintext.len,*/
2701                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2702                         tdata->iv.data, tdata->iv.len,
2703                         tdata->validCipherLenInBits.len,
2704                         tdata->validCipherOffsetLenInBits.len,
2705                         tdata->validAuthLenInBits.len,
2706                         tdata->validAuthOffsetLenInBits.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_src;
2714         if (ut_params->obuf)
2715                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2716                                 + tdata->iv.len;
2717         else
2718                 ciphertext = plaintext;
2719
2720         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2721
2722         /* Validate obuf */
2723         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2724                         ciphertext,
2725                         tdata->ciphertext.data,
2726                         tdata->validDataLenInBits.len,
2727                         "Snow3G Ciphertext data not as expected");
2728
2729         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2730             + plaintext_pad_len + tdata->aad.len;
2731
2732         /* Validate obuf */
2733         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2734                         ut_params->digest,
2735                         tdata->digest.data,
2736                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2737                         "Snow3G Generated auth tag not as expected");
2738         return 0;
2739 }
2740 static int
2741 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2742 {
2743         struct crypto_testsuite_params *ts_params = &testsuite_params;
2744         struct crypto_unittest_params *ut_params = &unittest_params;
2745
2746         int retval;
2747
2748         uint8_t *plaintext, *ciphertext;
2749         uint8_t plaintext_pad_len;
2750
2751         /* Create SNOW3G session */
2752         retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2753                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2754                         RTE_CRYPTO_AUTH_OP_GENERATE,
2755                         tdata->key.data, tdata->key.len,
2756                         tdata->aad.len, tdata->digest.len);
2757         if (retval < 0)
2758                 return retval;
2759
2760         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2761
2762         /* clear mbuf payload */
2763         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2764                         rte_pktmbuf_tailroom(ut_params->ibuf));
2765
2766         /* Append data which is padded to a multiple */
2767         /* of the algorithms block size */
2768         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2769
2770         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2771                         plaintext_pad_len);
2772         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2773
2774         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2775
2776         /* Create SNOW3G operation */
2777         retval = create_snow3g_auth_cipher_operation(
2778                 tdata->digest.len,
2779                 tdata->iv.data, tdata->iv.len,
2780                 tdata->aad.data, tdata->aad.len,
2781                 plaintext_pad_len,
2782                 tdata->validCipherLenInBits.len,
2783                 tdata->validCipherOffsetLenInBits.len,
2784                 tdata->validAuthLenInBits.len,
2785                 tdata->validAuthOffsetLenInBits.len
2786         );
2787
2788         if (retval < 0)
2789                 return retval;
2790
2791         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2792                         ut_params->op);
2793         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2794         ut_params->obuf = ut_params->op->sym->m_src;
2795         if (ut_params->obuf)
2796                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2797                                 + tdata->aad.len + tdata->iv.len;
2798         else
2799                 ciphertext = plaintext;
2800
2801         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2802                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2803         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2804
2805         /* Validate obuf */
2806         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2807                 ciphertext,
2808                 tdata->ciphertext.data,
2809                 tdata->validDataLenInBits.len,
2810                 "Snow3G Ciphertext data not as expected");
2811
2812         /* Validate obuf */
2813         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2814                 ut_params->digest,
2815                 tdata->digest.data,
2816                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2817                 "Snow3G Generated auth tag not as expected");
2818         return 0;
2819 }
2820
2821 static int
2822 test_kasumi_encryption_test_case_1(void)
2823 {
2824         return test_kasumi_encryption(&kasumi_test_case_1);
2825 }
2826
2827 static int
2828 test_kasumi_encryption_test_case_1_oop(void)
2829 {
2830         return test_kasumi_encryption_oop(&kasumi_test_case_1);
2831 }
2832
2833 static int
2834 test_kasumi_encryption_test_case_2(void)
2835 {
2836         return test_kasumi_encryption(&kasumi_test_case_2);
2837 }
2838
2839 static int
2840 test_kasumi_encryption_test_case_3(void)
2841 {
2842         return test_kasumi_encryption(&kasumi_test_case_3);
2843 }
2844
2845 static int
2846 test_kasumi_encryption_test_case_4(void)
2847 {
2848         return test_kasumi_encryption(&kasumi_test_case_4);
2849 }
2850
2851 static int
2852 test_kasumi_encryption_test_case_5(void)
2853 {
2854         return test_kasumi_encryption(&kasumi_test_case_5);
2855 }
2856
2857 static int
2858 test_kasumi_decryption_test_case_1(void)
2859 {
2860         return test_kasumi_decryption(&kasumi_test_case_1);
2861 }
2862
2863 static int
2864 test_kasumi_decryption_test_case_1_oop(void)
2865 {
2866         return test_kasumi_decryption_oop(&kasumi_test_case_1);
2867 }
2868
2869 static int
2870 test_kasumi_decryption_test_case_2(void)
2871 {
2872         return test_kasumi_decryption(&kasumi_test_case_2);
2873 }
2874
2875 static int
2876 test_kasumi_decryption_test_case_3(void)
2877 {
2878         return test_kasumi_decryption(&kasumi_test_case_3);
2879 }
2880
2881 static int
2882 test_kasumi_decryption_test_case_4(void)
2883 {
2884         return test_kasumi_decryption(&kasumi_test_case_4);
2885 }
2886
2887 static int
2888 test_kasumi_decryption_test_case_5(void)
2889 {
2890         return test_kasumi_decryption(&kasumi_test_case_5);
2891 }
2892 static int
2893 test_snow3g_encryption_test_case_1(void)
2894 {
2895         return test_snow3g_encryption(&snow3g_test_case_1);
2896 }
2897
2898 static int
2899 test_snow3g_encryption_test_case_1_oop(void)
2900 {
2901         return test_snow3g_encryption_oop(&snow3g_test_case_1);
2902 }
2903
2904 static int
2905 test_snow3g_encryption_test_case_2(void)
2906 {
2907         return test_snow3g_encryption(&snow3g_test_case_2);
2908 }
2909
2910 static int
2911 test_snow3g_encryption_test_case_3(void)
2912 {
2913         return test_snow3g_encryption(&snow3g_test_case_3);
2914 }
2915
2916 static int
2917 test_snow3g_encryption_test_case_4(void)
2918 {
2919         return test_snow3g_encryption(&snow3g_test_case_4);
2920 }
2921
2922 static int
2923 test_snow3g_encryption_test_case_5(void)
2924 {
2925         return test_snow3g_encryption(&snow3g_test_case_5);
2926 }
2927
2928 static int
2929 test_snow3g_decryption_test_case_1(void)
2930 {
2931         return test_snow3g_decryption(&snow3g_test_case_1);
2932 }
2933
2934 static int
2935 test_snow3g_decryption_test_case_1_oop(void)
2936 {
2937         return test_snow3g_decryption_oop(&snow3g_test_case_1);
2938 }
2939
2940 static int
2941 test_snow3g_decryption_test_case_2(void)
2942 {
2943         return test_snow3g_decryption(&snow3g_test_case_2);
2944 }
2945
2946 static int
2947 test_snow3g_decryption_test_case_3(void)
2948 {
2949         return test_snow3g_decryption(&snow3g_test_case_3);
2950 }
2951
2952 static int
2953 test_snow3g_decryption_test_case_4(void)
2954 {
2955         return test_snow3g_decryption(&snow3g_test_case_4);
2956 }
2957
2958 static int
2959 test_snow3g_decryption_test_case_5(void)
2960 {
2961         return test_snow3g_decryption(&snow3g_test_case_5);
2962 }
2963 static int
2964 test_snow3g_authenticated_encryption_test_case_1(void)
2965 {
2966         return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2967 }
2968
2969 static int
2970 test_snow3g_encrypted_authentication_test_case_1(void)
2971 {
2972         return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2973 }
2974
2975 /* ***** AES-GCM Tests ***** */
2976
2977 static int
2978 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2979                 const uint8_t *key, const uint8_t key_len,
2980                 const uint8_t aad_len, const uint8_t auth_len)
2981 {
2982         uint8_t cipher_key[key_len];
2983
2984         struct crypto_unittest_params *ut_params = &unittest_params;
2985
2986
2987         memcpy(cipher_key, key, key_len);
2988
2989         /* Setup Cipher Parameters */
2990         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2991         ut_params->cipher_xform.next = NULL;
2992
2993         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2994         ut_params->cipher_xform.cipher.op = op;
2995         ut_params->cipher_xform.cipher.key.data = cipher_key;
2996         ut_params->cipher_xform.cipher.key.length = key_len;
2997
2998         TEST_HEXDUMP(stdout, "key:", key, key_len);
2999
3000         /* Setup Authentication Parameters */
3001         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3002         ut_params->auth_xform.next = NULL;
3003
3004         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3005
3006         ut_params->auth_xform.auth.digest_length = auth_len;
3007         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3008         ut_params->auth_xform.auth.key.length = 0;
3009         ut_params->auth_xform.auth.key.data = NULL;
3010
3011         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3012                 ut_params->cipher_xform.next = &ut_params->auth_xform;
3013
3014                 /* Create Crypto session*/
3015                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3016                                 &ut_params->cipher_xform);
3017         } else {/* Create Crypto session*/
3018                 ut_params->auth_xform.next = &ut_params->cipher_xform;
3019                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3020                                 &ut_params->auth_xform);
3021         }
3022
3023         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3024
3025         return 0;
3026 }
3027
3028 static int
3029 create_gcm_operation(enum rte_crypto_cipher_operation op,
3030                 const uint8_t *auth_tag, const unsigned auth_tag_len,
3031                 const uint8_t *iv, const unsigned iv_len,
3032                 const uint8_t *aad, const unsigned aad_len,
3033                 const unsigned data_len, unsigned data_pad_len)
3034 {
3035         struct crypto_testsuite_params *ts_params = &testsuite_params;
3036         struct crypto_unittest_params *ut_params = &unittest_params;
3037
3038         unsigned iv_pad_len = 0, aad_buffer_len;
3039
3040         /* Generate Crypto op data structure */
3041         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3042                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3043         TEST_ASSERT_NOT_NULL(ut_params->op,
3044                         "Failed to allocate symmetric crypto operation struct");
3045
3046         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3047
3048
3049
3050         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3051                         ut_params->ibuf, auth_tag_len);
3052         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3053                         "no room to append digest");
3054         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3055                         ut_params->ibuf, data_pad_len);
3056         sym_op->auth.digest.length = auth_tag_len;
3057
3058         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3059                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3060                 TEST_HEXDUMP(stdout, "digest:",
3061                                 sym_op->auth.digest.data,
3062                                 sym_op->auth.digest.length);
3063         }
3064
3065         /* iv */
3066         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3067
3068         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3069                         ut_params->ibuf, iv_pad_len);
3070         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3071
3072         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3073         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3074         sym_op->cipher.iv.length = iv_pad_len;
3075
3076         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3077
3078         /* CalcY0 */
3079         if (iv_len != 16)
3080                 sym_op->cipher.iv.data[15] = 1;
3081
3082         /*
3083          * Always allocate the aad up to the block size.
3084          * The cryptodev API calls out -
3085          *  - the array must be big enough to hold the AAD, plus any
3086          *   space to round this up to the nearest multiple of the
3087          *   block size (16 bytes).
3088          */
3089         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3090
3091         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3092                         ut_params->ibuf, aad_buffer_len);
3093         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3094                         "no room to prepend aad");
3095         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3096                         ut_params->ibuf);
3097         sym_op->auth.aad.length = aad_len;
3098
3099         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3100         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3101
3102         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3103         TEST_HEXDUMP(stdout, "aad:",
3104                         sym_op->auth.aad.data, aad_len);
3105
3106         sym_op->cipher.data.length = data_len;
3107         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3108
3109         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3110         sym_op->auth.data.length = data_len;
3111
3112         return 0;
3113 }
3114
3115 static int
3116 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3117 {
3118         struct crypto_testsuite_params *ts_params = &testsuite_params;
3119         struct crypto_unittest_params *ut_params = &unittest_params;
3120
3121         int retval;
3122
3123         uint8_t *plaintext, *ciphertext, *auth_tag;
3124         uint16_t plaintext_pad_len;
3125
3126         /* Create GCM session */
3127         retval = create_gcm_session(ts_params->valid_devs[0],
3128                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3129                         tdata->key.data, tdata->key.len,
3130                         tdata->aad.len, tdata->auth_tag.len);
3131         if (retval < 0)
3132                 return retval;
3133
3134
3135         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3136
3137         /* clear mbuf payload */
3138         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3139                         rte_pktmbuf_tailroom(ut_params->ibuf));
3140
3141         /*
3142          * Append data which is padded to a multiple
3143          * of the algorithms block size
3144          */
3145         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3146
3147         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3148                         plaintext_pad_len);
3149         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3150
3151         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3152
3153         /* Create GCM opertaion */
3154         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3155                         tdata->auth_tag.data, tdata->auth_tag.len,
3156                         tdata->iv.data, tdata->iv.len,
3157                         tdata->aad.data, tdata->aad.len,
3158                         tdata->plaintext.len, plaintext_pad_len);
3159         if (retval < 0)
3160                 return retval;
3161
3162         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3163
3164         ut_params->op->sym->m_src = ut_params->ibuf;
3165
3166         /* Process crypto operation */
3167         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3168                         ut_params->op), "failed to process sym crypto op");
3169
3170         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3171                         "crypto op processing failed");
3172
3173         if (ut_params->op->sym->m_dst) {
3174                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3175                                 uint8_t *);
3176                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3177                                 uint8_t *, plaintext_pad_len);
3178         } else {
3179                 ciphertext = plaintext;
3180                 auth_tag = plaintext + plaintext_pad_len;
3181         }
3182
3183         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3184         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3185
3186         /* Validate obuf */
3187         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3188                         ciphertext,
3189                         tdata->ciphertext.data,
3190                         tdata->ciphertext.len,
3191                         "GCM Ciphertext data not as expected");
3192
3193         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3194                         auth_tag,
3195                         tdata->auth_tag.data,
3196                         tdata->auth_tag.len,
3197                         "GCM Generated auth tag not as expected");
3198
3199         return 0;
3200
3201 }
3202
3203 static int
3204 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3205 {
3206         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3207 }
3208
3209 static int
3210 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3211 {
3212         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3213 }
3214
3215 static int
3216 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3217 {
3218         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3219 }
3220
3221 static int
3222 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3223 {
3224         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3225 }
3226
3227 static int
3228 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3229 {
3230         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3231 }
3232
3233 static int
3234 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3235 {
3236         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3237 }
3238
3239 static int
3240 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3241 {
3242         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3243 }
3244
3245 static int
3246 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3247 {
3248         struct crypto_testsuite_params *ts_params = &testsuite_params;
3249         struct crypto_unittest_params *ut_params = &unittest_params;
3250
3251         int retval;
3252
3253         uint8_t *plaintext, *ciphertext;
3254         uint16_t ciphertext_pad_len;
3255
3256         /* Create GCM session */
3257         retval = create_gcm_session(ts_params->valid_devs[0],
3258                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3259                         tdata->key.data, tdata->key.len,
3260                         tdata->aad.len, tdata->auth_tag.len);
3261         if (retval < 0)
3262                 return retval;
3263
3264
3265         /* alloc mbuf and set payload */
3266         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3267
3268         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3269                         rte_pktmbuf_tailroom(ut_params->ibuf));
3270
3271         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3272
3273         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3274                         ciphertext_pad_len);
3275         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3276
3277         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3278
3279         /* Create GCM opertaion */
3280         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3281                         tdata->auth_tag.data, tdata->auth_tag.len,
3282                         tdata->iv.data, tdata->iv.len,
3283                         tdata->aad.data, tdata->aad.len,
3284                         tdata->ciphertext.len, ciphertext_pad_len);
3285         if (retval < 0)
3286                 return retval;
3287
3288
3289         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3290
3291         ut_params->op->sym->m_src = ut_params->ibuf;
3292
3293         /* Process crypto operation */
3294         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3295                         ut_params->op), "failed to process sym crypto op");
3296
3297         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3298                         "crypto op processing failed");
3299
3300         if (ut_params->op->sym->m_dst)
3301                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3302                                 uint8_t *);
3303         else
3304                 plaintext = ciphertext;
3305
3306         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3307
3308         /* Validate obuf */
3309         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3310                         plaintext,
3311                         tdata->plaintext.data,
3312                         tdata->plaintext.len,
3313                         "GCM plaintext data not as expected");
3314
3315         TEST_ASSERT_EQUAL(ut_params->op->status,
3316                         RTE_CRYPTO_OP_STATUS_SUCCESS,
3317                         "GCM authentication failed");
3318         return 0;
3319 }
3320
3321 static int
3322 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3323 {
3324         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3325 }
3326
3327 static int
3328 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3329 {
3330         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3331 }
3332
3333 static int
3334 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3335 {
3336         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3337 }
3338
3339 static int
3340 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3341 {
3342         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3343 }
3344
3345 static int
3346 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3347 {
3348         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3349 }
3350
3351 static int
3352 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3353 {
3354         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3355 }
3356
3357 static int
3358 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3359 {
3360         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3361 }
3362
3363 static int
3364 test_stats(void)
3365 {
3366         struct crypto_testsuite_params *ts_params = &testsuite_params;
3367         struct rte_cryptodev_stats stats;
3368         struct rte_cryptodev *dev;
3369         cryptodev_stats_get_t temp_pfn;
3370
3371         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3372         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3373                         &stats) == -ENODEV),
3374                 "rte_cryptodev_stats_get invalid dev failed");
3375         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3376                 "rte_cryptodev_stats_get invalid Param failed");
3377         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3378         temp_pfn = dev->dev_ops->stats_get;
3379         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3380         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3381                         == -ENOTSUP),
3382                 "rte_cryptodev_stats_get invalid Param failed");
3383         dev->dev_ops->stats_get = temp_pfn;
3384
3385         /* Test expected values */
3386         ut_setup();
3387         test_AES_CBC_HMAC_SHA1_encrypt_digest();
3388         ut_teardown();
3389         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3390                         &stats),
3391                 "rte_cryptodev_stats_get failed");
3392         TEST_ASSERT((stats.enqueued_count == 1),
3393                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3394         TEST_ASSERT((stats.dequeued_count == 1),
3395                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3396         TEST_ASSERT((stats.enqueue_err_count == 0),
3397                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3398         TEST_ASSERT((stats.dequeue_err_count == 0),
3399                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3400
3401         /* invalid device but should ignore and not reset device stats*/
3402         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3403         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3404                         &stats),
3405                 "rte_cryptodev_stats_get failed");
3406         TEST_ASSERT((stats.enqueued_count == 1),
3407                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3408
3409         /* check that a valid reset clears stats */
3410         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3411         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3412                         &stats),
3413                                           "rte_cryptodev_stats_get failed");
3414         TEST_ASSERT((stats.enqueued_count == 0),
3415                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3416         TEST_ASSERT((stats.dequeued_count == 0),
3417                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3418
3419         return TEST_SUCCESS;
3420 }
3421
3422
3423 static int
3424 test_multi_session(void)
3425 {
3426         struct crypto_testsuite_params *ts_params = &testsuite_params;
3427         struct crypto_unittest_params *ut_params = &unittest_params;
3428
3429         struct rte_cryptodev_info dev_info;
3430         struct rte_cryptodev_sym_session **sessions;
3431
3432         uint16_t i;
3433
3434         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3435
3436
3437         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3438
3439         sessions = rte_malloc(NULL,
3440                         (sizeof(struct rte_cryptodev_sym_session *) *
3441                         dev_info.sym.max_nb_sessions) + 1, 0);
3442
3443         /* Create multiple crypto sessions*/
3444         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3445                 sessions[i] = rte_cryptodev_sym_session_create(
3446                                 ts_params->valid_devs[0],
3447                         &ut_params->auth_xform);
3448                 TEST_ASSERT_NOT_NULL(sessions[i],
3449                                 "Session creation failed at session number %u",
3450                                 i);
3451
3452                 /* Attempt to send a request on each session */
3453                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3454                                 sessions[i], ut_params, ts_params),
3455                                 "Failed to perform decrypt on request "
3456                                 "number %u.", i);
3457                 /* free crypto operation structure */
3458                 if (ut_params->op)
3459                         rte_crypto_op_free(ut_params->op);
3460
3461                 /*
3462                  * free mbuf - both obuf and ibuf are usually the same,
3463                  * but rte copes even if we call free twice
3464                  */
3465                 if (ut_params->obuf) {
3466                         rte_pktmbuf_free(ut_params->obuf);
3467                         ut_params->obuf = 0;
3468                 }
3469         }
3470
3471         /* Next session create should fail */
3472         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3473                         &ut_params->auth_xform);
3474         TEST_ASSERT_NULL(sessions[i],
3475                         "Session creation succeeded unexpectedly!");
3476
3477         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3478                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3479                                 sessions[i]);
3480
3481         rte_free(sessions);
3482
3483         return TEST_SUCCESS;
3484 }
3485
3486 static int
3487 test_null_cipher_only_operation(void)
3488 {
3489         struct crypto_testsuite_params *ts_params = &testsuite_params;
3490         struct crypto_unittest_params *ut_params = &unittest_params;
3491
3492         /* Generate test mbuf data and space for digest */
3493         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3494                         catch_22_quote, QUOTE_512_BYTES, 0);
3495
3496         /* Setup Cipher Parameters */
3497         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3498         ut_params->cipher_xform.next = NULL;
3499
3500         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3501         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3502
3503         /* Create Crypto session*/
3504         ut_params->sess = rte_cryptodev_sym_session_create(
3505                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3506         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3507
3508         /* Generate Crypto op data structure */
3509         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3510                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3511         TEST_ASSERT_NOT_NULL(ut_params->op,
3512                         "Failed to allocate symmetric crypto operation struct");
3513
3514         /* Set crypto operation data parameters */
3515         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3516
3517         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3518
3519         /* set crypto operation source mbuf */
3520         sym_op->m_src = ut_params->ibuf;
3521
3522         sym_op->cipher.data.offset = 0;
3523         sym_op->cipher.data.length = QUOTE_512_BYTES;
3524
3525         /* Process crypto operation */
3526         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3527                         ut_params->op);
3528         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3529
3530         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3531                         "crypto operation processing failed");
3532
3533         /* Validate obuf */
3534         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3535                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3536                         catch_22_quote,
3537                         QUOTE_512_BYTES,
3538                         "Ciphertext data not as expected");
3539
3540         return TEST_SUCCESS;
3541 }
3542
3543 static int
3544 test_null_auth_only_operation(void)
3545 {
3546         struct crypto_testsuite_params *ts_params = &testsuite_params;
3547         struct crypto_unittest_params *ut_params = &unittest_params;
3548
3549         /* Generate test mbuf data and space for digest */
3550         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3551                         catch_22_quote, QUOTE_512_BYTES, 0);
3552
3553         /* Setup HMAC Parameters */
3554         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3555         ut_params->auth_xform.next = NULL;
3556
3557         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3558         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3559
3560         /* Create Crypto session*/
3561         ut_params->sess = rte_cryptodev_sym_session_create(
3562                         ts_params->valid_devs[0], &ut_params->auth_xform);
3563         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3564
3565         /* Generate Crypto op data structure */
3566         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3567                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3568         TEST_ASSERT_NOT_NULL(ut_params->op,
3569                         "Failed to allocate symmetric crypto operation struct");
3570
3571         /* Set crypto operation data parameters */
3572         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3573
3574         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3575
3576         sym_op->m_src = ut_params->ibuf;
3577
3578         sym_op->auth.data.offset = 0;
3579         sym_op->auth.data.length = QUOTE_512_BYTES;
3580
3581         /* Process crypto operation */
3582         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3583                         ut_params->op);
3584         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3585
3586         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3587                         "crypto operation processing failed");
3588
3589         return TEST_SUCCESS;
3590 }
3591
3592 static int
3593 test_null_cipher_auth_operation(void)
3594 {
3595         struct crypto_testsuite_params *ts_params = &testsuite_params;
3596         struct crypto_unittest_params *ut_params = &unittest_params;
3597
3598         /* Generate test mbuf data and space for digest */
3599         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3600                         catch_22_quote, QUOTE_512_BYTES, 0);
3601
3602         /* Setup Cipher Parameters */
3603         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3604         ut_params->cipher_xform.next = &ut_params->auth_xform;
3605
3606         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3607         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3608
3609         /* Setup HMAC Parameters */
3610         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3611         ut_params->auth_xform.next = NULL;
3612
3613         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3614         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3615
3616         /* Create Crypto session*/
3617         ut_params->sess = rte_cryptodev_sym_session_create(
3618                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3619         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3620
3621         /* Generate Crypto op data structure */
3622         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3623                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3624         TEST_ASSERT_NOT_NULL(ut_params->op,
3625                         "Failed to allocate symmetric crypto operation struct");
3626
3627         /* Set crypto operation data parameters */
3628         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3629
3630         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3631
3632         sym_op->m_src = ut_params->ibuf;
3633
3634         sym_op->cipher.data.offset = 0;
3635         sym_op->cipher.data.length = QUOTE_512_BYTES;
3636
3637         sym_op->auth.data.offset = 0;
3638         sym_op->auth.data.length = QUOTE_512_BYTES;
3639
3640         /* Process crypto operation */
3641         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3642                         ut_params->op);
3643         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3644
3645         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3646                         "crypto operation processing failed");
3647
3648         /* Validate obuf */
3649         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3650                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3651                         catch_22_quote,
3652                         QUOTE_512_BYTES,
3653                         "Ciphertext data not as expected");
3654
3655         return TEST_SUCCESS;
3656 }
3657
3658 static int
3659 test_null_auth_cipher_operation(void)
3660 {
3661         struct crypto_testsuite_params *ts_params = &testsuite_params;
3662         struct crypto_unittest_params *ut_params = &unittest_params;
3663
3664         /* Generate test mbuf data and space for digest */
3665         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3666                         catch_22_quote, QUOTE_512_BYTES, 0);
3667
3668         /* Setup Cipher Parameters */
3669         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3670         ut_params->cipher_xform.next = NULL;
3671
3672         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3673         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3674
3675         /* Setup HMAC Parameters */
3676         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3677         ut_params->auth_xform.next = &ut_params->cipher_xform;
3678
3679         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3680         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3681
3682         /* Create Crypto session*/
3683         ut_params->sess = rte_cryptodev_sym_session_create(
3684                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3685         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3686
3687         /* Generate Crypto op data structure */
3688         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3689                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3690         TEST_ASSERT_NOT_NULL(ut_params->op,
3691                         "Failed to allocate symmetric crypto operation struct");
3692
3693         /* Set crypto operation data parameters */
3694         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3695
3696         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3697
3698         sym_op->m_src = ut_params->ibuf;
3699
3700         sym_op->cipher.data.offset = 0;
3701         sym_op->cipher.data.length = QUOTE_512_BYTES;
3702
3703         sym_op->auth.data.offset = 0;
3704         sym_op->auth.data.length = QUOTE_512_BYTES;
3705
3706         /* Process crypto operation */
3707         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3708                         ut_params->op);
3709         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3710
3711         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3712                         "crypto operation processing failed");
3713
3714         /* Validate obuf */
3715         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3716                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3717                         catch_22_quote,
3718                         QUOTE_512_BYTES,
3719                         "Ciphertext data not as expected");
3720
3721         return TEST_SUCCESS;
3722 }
3723
3724
3725 static int
3726 test_null_invalid_operation(void)
3727 {
3728         struct crypto_testsuite_params *ts_params = &testsuite_params;
3729         struct crypto_unittest_params *ut_params = &unittest_params;
3730
3731         /* Setup Cipher Parameters */
3732         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3733         ut_params->cipher_xform.next = NULL;
3734
3735         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3736         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3737
3738         /* Create Crypto session*/
3739         ut_params->sess = rte_cryptodev_sym_session_create(
3740                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3741         TEST_ASSERT_NULL(ut_params->sess,
3742                         "Session creation succeeded unexpectedly");
3743
3744
3745         /* Setup HMAC Parameters */
3746         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3747         ut_params->auth_xform.next = NULL;
3748
3749         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3750         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3751
3752         /* Create Crypto session*/
3753         ut_params->sess = rte_cryptodev_sym_session_create(
3754                         ts_params->valid_devs[0], &ut_params->auth_xform);
3755         TEST_ASSERT_NULL(ut_params->sess,
3756                         "Session creation succeeded unexpectedly");
3757
3758         return TEST_SUCCESS;
3759 }
3760
3761
3762 #define NULL_BURST_LENGTH (32)
3763
3764 static int
3765 test_null_burst_operation(void)
3766 {
3767         struct crypto_testsuite_params *ts_params = &testsuite_params;
3768         struct crypto_unittest_params *ut_params = &unittest_params;
3769
3770         unsigned i, burst_len = NULL_BURST_LENGTH;
3771
3772         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3773         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3774
3775         /* Setup Cipher Parameters */
3776         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3777         ut_params->cipher_xform.next = &ut_params->auth_xform;
3778
3779         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3780         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3781
3782         /* Setup HMAC Parameters */
3783         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3784         ut_params->auth_xform.next = NULL;
3785
3786         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3787         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3788
3789         /* Create Crypto session*/
3790         ut_params->sess = rte_cryptodev_sym_session_create(
3791                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3792         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3793
3794         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3795                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3796                         burst_len, "failed to generate burst of crypto ops");
3797
3798         /* Generate an operation for each mbuf in burst */
3799         for (i = 0; i < burst_len; i++) {
3800                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3801
3802                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3803
3804                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3805                                 sizeof(unsigned));
3806                 *data = i;
3807
3808                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3809
3810                 burst[i]->sym->m_src = m;
3811         }
3812
3813         /* Process crypto operation */
3814         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3815                         0, burst, burst_len),
3816                         burst_len,
3817                         "Error enqueuing burst");
3818
3819         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3820                         0, burst_dequeued, burst_len),
3821                         burst_len,
3822                         "Error dequeuing burst");
3823
3824
3825         for (i = 0; i < burst_len; i++) {
3826                 TEST_ASSERT_EQUAL(
3827                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3828                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3829                                         uint32_t *),
3830                         "data not as expected");
3831
3832                 rte_pktmbuf_free(burst[i]->sym->m_src);
3833                 rte_crypto_op_free(burst[i]);
3834         }
3835
3836         return TEST_SUCCESS;
3837 }
3838
3839
3840
3841
3842 static struct unit_test_suite cryptodev_qat_testsuite  = {
3843         .suite_name = "Crypto QAT Unit Test Suite",
3844         .setup = testsuite_setup,
3845         .teardown = testsuite_teardown,
3846         .unit_test_cases = {
3847                 TEST_CASE_ST(ut_setup, ut_teardown,
3848                                 test_device_configure_invalid_dev_id),
3849                 TEST_CASE_ST(ut_setup, ut_teardown,
3850                                 test_device_configure_invalid_queue_pair_ids),
3851                 TEST_CASE_ST(ut_setup, ut_teardown,
3852                                 test_queue_pair_descriptor_setup),
3853                 TEST_CASE_ST(ut_setup, ut_teardown,
3854                                 test_multi_session),
3855
3856                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3857                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3858
3859                 /** AES GCM Authenticated Encryption */
3860                 TEST_CASE_ST(ut_setup, ut_teardown,
3861                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3862                 TEST_CASE_ST(ut_setup, ut_teardown,
3863                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3864                 TEST_CASE_ST(ut_setup, ut_teardown,
3865                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3866                 TEST_CASE_ST(ut_setup, ut_teardown,
3867                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3868                 TEST_CASE_ST(ut_setup, ut_teardown,
3869                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3870                 TEST_CASE_ST(ut_setup, ut_teardown,
3871                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3872                 TEST_CASE_ST(ut_setup, ut_teardown,
3873                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3874
3875                 /** AES GCM Authenticated Decryption */
3876                 TEST_CASE_ST(ut_setup, ut_teardown,
3877                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3878                 TEST_CASE_ST(ut_setup, ut_teardown,
3879                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3880                 TEST_CASE_ST(ut_setup, ut_teardown,
3881                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3882                 TEST_CASE_ST(ut_setup, ut_teardown,
3883                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3884                 TEST_CASE_ST(ut_setup, ut_teardown,
3885                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3886                 TEST_CASE_ST(ut_setup, ut_teardown,
3887                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3888                 TEST_CASE_ST(ut_setup, ut_teardown,
3889                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3890
3891                 /** Snow3G encrypt only (UEA2) */
3892                 TEST_CASE_ST(ut_setup, ut_teardown,
3893                         test_snow3g_encryption_test_case_1),
3894                 TEST_CASE_ST(ut_setup, ut_teardown,
3895                         test_snow3g_encryption_test_case_2),
3896                 TEST_CASE_ST(ut_setup, ut_teardown,
3897                         test_snow3g_encryption_test_case_3),
3898                 TEST_CASE_ST(ut_setup, ut_teardown,
3899                         test_snow3g_encryption_test_case_4),
3900                 TEST_CASE_ST(ut_setup, ut_teardown,
3901                         test_snow3g_encryption_test_case_5),
3902
3903                 TEST_CASE_ST(ut_setup, ut_teardown,
3904                         test_snow3g_encryption_test_case_1_oop),
3905                 TEST_CASE_ST(ut_setup, ut_teardown,
3906                         test_snow3g_decryption_test_case_1_oop),
3907
3908                 /** Snow3G decrypt only (UEA2) */
3909                 TEST_CASE_ST(ut_setup, ut_teardown,
3910                         test_snow3g_decryption_test_case_1),
3911                 TEST_CASE_ST(ut_setup, ut_teardown,
3912                         test_snow3g_decryption_test_case_2),
3913                 TEST_CASE_ST(ut_setup, ut_teardown,
3914                         test_snow3g_decryption_test_case_3),
3915                 TEST_CASE_ST(ut_setup, ut_teardown,
3916                         test_snow3g_decryption_test_case_4),
3917                 TEST_CASE_ST(ut_setup, ut_teardown,
3918                         test_snow3g_decryption_test_case_5),
3919                 TEST_CASE_ST(ut_setup, ut_teardown,
3920                         test_snow3g_hash_generate_test_case_1),
3921                 TEST_CASE_ST(ut_setup, ut_teardown,
3922                         test_snow3g_hash_generate_test_case_2),
3923                 TEST_CASE_ST(ut_setup, ut_teardown,
3924                         test_snow3g_hash_generate_test_case_3),
3925                 TEST_CASE_ST(ut_setup, ut_teardown,
3926                         test_snow3g_hash_verify_test_case_1),
3927                 TEST_CASE_ST(ut_setup, ut_teardown,
3928                         test_snow3g_hash_verify_test_case_2),
3929                 TEST_CASE_ST(ut_setup, ut_teardown,
3930                         test_snow3g_hash_verify_test_case_3),
3931                 TEST_CASE_ST(ut_setup, ut_teardown,
3932                         test_snow3g_authenticated_encryption_test_case_1),
3933                 TEST_CASE_ST(ut_setup, ut_teardown,
3934                         test_snow3g_encrypted_authentication_test_case_1),
3935                 TEST_CASES_END() /**< NULL terminate unit test array */
3936         }
3937 };
3938
3939 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
3940         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3941         .setup = testsuite_setup,
3942         .teardown = testsuite_teardown,
3943         .unit_test_cases = {
3944                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3945
3946                 TEST_CASES_END() /**< NULL terminate unit test array */
3947         }
3948 };
3949
3950 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
3951         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3952         .setup = testsuite_setup,
3953         .teardown = testsuite_teardown,
3954         .unit_test_cases = {
3955                 /** AES GCM Authenticated Encryption */
3956                 TEST_CASE_ST(ut_setup, ut_teardown,
3957                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3958                 TEST_CASE_ST(ut_setup, ut_teardown,
3959                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3960                 TEST_CASE_ST(ut_setup, ut_teardown,
3961                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3962                 TEST_CASE_ST(ut_setup, ut_teardown,
3963                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3964                 TEST_CASE_ST(ut_setup, ut_teardown,
3965                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3966                 TEST_CASE_ST(ut_setup, ut_teardown,
3967                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3968                 TEST_CASE_ST(ut_setup, ut_teardown,
3969                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3970
3971                 /** AES GCM Authenticated Decryption */
3972                 TEST_CASE_ST(ut_setup, ut_teardown,
3973                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3974                 TEST_CASE_ST(ut_setup, ut_teardown,
3975                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3976                 TEST_CASE_ST(ut_setup, ut_teardown,
3977                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3978                 TEST_CASE_ST(ut_setup, ut_teardown,
3979                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3980                 TEST_CASE_ST(ut_setup, ut_teardown,
3981                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3982                 TEST_CASE_ST(ut_setup, ut_teardown,
3983                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3984                 TEST_CASE_ST(ut_setup, ut_teardown,
3985                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3986
3987                 TEST_CASES_END() /**< NULL terminate unit test array */
3988         }
3989 };
3990
3991 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
3992         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
3993         .setup = testsuite_setup,
3994         .teardown = testsuite_teardown,
3995         .unit_test_cases = {
3996                 /** KASUMI encrypt only (UEA1) */
3997                 TEST_CASE_ST(ut_setup, ut_teardown,
3998                         test_kasumi_encryption_test_case_1),
3999                 TEST_CASE_ST(ut_setup, ut_teardown,
4000                         test_kasumi_encryption_test_case_2),
4001                 TEST_CASE_ST(ut_setup, ut_teardown,
4002                         test_kasumi_encryption_test_case_3),
4003                 TEST_CASE_ST(ut_setup, ut_teardown,
4004                         test_kasumi_encryption_test_case_4),
4005                 TEST_CASE_ST(ut_setup, ut_teardown,
4006                         test_kasumi_encryption_test_case_5),
4007                 /** KASUMI decrypt only (UEA1) */
4008                 TEST_CASE_ST(ut_setup, ut_teardown,
4009                         test_kasumi_decryption_test_case_1),
4010                 TEST_CASE_ST(ut_setup, ut_teardown,
4011                         test_kasumi_decryption_test_case_2),
4012                 TEST_CASE_ST(ut_setup, ut_teardown,
4013                         test_kasumi_decryption_test_case_3),
4014                 TEST_CASE_ST(ut_setup, ut_teardown,
4015                         test_kasumi_decryption_test_case_4),
4016                 TEST_CASE_ST(ut_setup, ut_teardown,
4017                         test_kasumi_decryption_test_case_5),
4018
4019                 TEST_CASE_ST(ut_setup, ut_teardown,
4020                         test_kasumi_encryption_test_case_1_oop),
4021                 TEST_CASE_ST(ut_setup, ut_teardown,
4022                         test_kasumi_decryption_test_case_1_oop),
4023
4024                 /** KASUMI hash only (UIA1) */
4025                 TEST_CASE_ST(ut_setup, ut_teardown,
4026                         test_kasumi_hash_generate_test_case_1),
4027                 TEST_CASE_ST(ut_setup, ut_teardown,
4028                         test_kasumi_hash_generate_test_case_2),
4029                 TEST_CASE_ST(ut_setup, ut_teardown,
4030                         test_kasumi_hash_generate_test_case_3),
4031                 TEST_CASE_ST(ut_setup, ut_teardown,
4032                         test_kasumi_hash_generate_test_case_4),
4033                 TEST_CASE_ST(ut_setup, ut_teardown,
4034                         test_kasumi_hash_generate_test_case_5),
4035                 TEST_CASE_ST(ut_setup, ut_teardown,
4036                         test_kasumi_hash_verify_test_case_1),
4037                 TEST_CASE_ST(ut_setup, ut_teardown,
4038                         test_kasumi_hash_verify_test_case_2),
4039                 TEST_CASE_ST(ut_setup, ut_teardown,
4040                         test_kasumi_hash_verify_test_case_3),
4041                 TEST_CASE_ST(ut_setup, ut_teardown,
4042                         test_kasumi_hash_verify_test_case_4),
4043                 TEST_CASE_ST(ut_setup, ut_teardown,
4044                         test_kasumi_hash_verify_test_case_5),
4045
4046                 TEST_CASES_END() /**< NULL terminate unit test array */
4047         }
4048 };
4049 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
4050         .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4051         .setup = testsuite_setup,
4052         .teardown = testsuite_teardown,
4053         .unit_test_cases = {
4054                 /** Snow3G encrypt only (UEA2) */
4055                 TEST_CASE_ST(ut_setup, ut_teardown,
4056                         test_snow3g_encryption_test_case_1),
4057                 TEST_CASE_ST(ut_setup, ut_teardown,
4058                         test_snow3g_encryption_test_case_2),
4059                 TEST_CASE_ST(ut_setup, ut_teardown,
4060                         test_snow3g_encryption_test_case_3),
4061                 TEST_CASE_ST(ut_setup, ut_teardown,
4062                         test_snow3g_encryption_test_case_4),
4063                 TEST_CASE_ST(ut_setup, ut_teardown,
4064                         test_snow3g_encryption_test_case_5),
4065
4066
4067                 /** Snow3G decrypt only (UEA2) */
4068                 TEST_CASE_ST(ut_setup, ut_teardown,
4069                         test_snow3g_decryption_test_case_1),
4070                 TEST_CASE_ST(ut_setup, ut_teardown,
4071                         test_snow3g_decryption_test_case_2),
4072                 TEST_CASE_ST(ut_setup, ut_teardown,
4073                         test_snow3g_decryption_test_case_3),
4074                 TEST_CASE_ST(ut_setup, ut_teardown,
4075                         test_snow3g_decryption_test_case_4),
4076                 TEST_CASE_ST(ut_setup, ut_teardown,
4077                         test_snow3g_decryption_test_case_5),
4078                 TEST_CASE_ST(ut_setup, ut_teardown,
4079                         test_snow3g_hash_generate_test_case_1),
4080                 TEST_CASE_ST(ut_setup, ut_teardown,
4081                         test_snow3g_hash_generate_test_case_2),
4082                 TEST_CASE_ST(ut_setup, ut_teardown,
4083                         test_snow3g_hash_generate_test_case_3),
4084                 TEST_CASE_ST(ut_setup, ut_teardown,
4085                         test_snow3g_hash_verify_test_case_1),
4086                 TEST_CASE_ST(ut_setup, ut_teardown,
4087                         test_snow3g_hash_verify_test_case_2),
4088                 TEST_CASE_ST(ut_setup, ut_teardown,
4089                         test_snow3g_hash_verify_test_case_3),
4090                 TEST_CASE_ST(ut_setup, ut_teardown,
4091                         test_snow3g_authenticated_encryption_test_case_1),
4092                 TEST_CASE_ST(ut_setup, ut_teardown,
4093                         test_snow3g_encrypted_authentication_test_case_1),
4094
4095                 TEST_CASES_END() /**< NULL terminate unit test array */
4096         }
4097 };
4098
4099 static struct unit_test_suite cryptodev_null_testsuite  = {
4100         .suite_name = "Crypto Device NULL Unit Test Suite",
4101         .setup = testsuite_setup,
4102         .teardown = testsuite_teardown,
4103         .unit_test_cases = {
4104                 TEST_CASE_ST(ut_setup, ut_teardown,
4105                         test_null_auth_only_operation),
4106                 TEST_CASE_ST(ut_setup, ut_teardown,
4107                         test_null_cipher_only_operation),
4108                 TEST_CASE_ST(ut_setup, ut_teardown,
4109                         test_null_cipher_auth_operation),
4110                 TEST_CASE_ST(ut_setup, ut_teardown,
4111                         test_null_auth_cipher_operation),
4112                 TEST_CASE_ST(ut_setup, ut_teardown,
4113                         test_null_invalid_operation),
4114                 TEST_CASE_ST(ut_setup, ut_teardown,
4115                         test_null_burst_operation),
4116
4117                 TEST_CASES_END() /**< NULL terminate unit test array */
4118         }
4119 };
4120
4121 static int
4122 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4123 {
4124         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4125         return unit_test_suite_runner(&cryptodev_qat_testsuite);
4126 }
4127 static struct test_command cryptodev_qat_cmd = {
4128         .command = "cryptodev_qat_autotest",
4129         .callback = test_cryptodev_qat,
4130 };
4131
4132 static int
4133 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4134 {
4135         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4136
4137         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4138 }
4139
4140 static struct test_command cryptodev_aesni_mb_cmd = {
4141         .command = "cryptodev_aesni_mb_autotest",
4142         .callback = test_cryptodev_aesni_mb,
4143 };
4144
4145 static int
4146 test_cryptodev_aesni_gcm(void)
4147 {
4148         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4149
4150         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4151 }
4152
4153 static struct test_command cryptodev_aesni_gcm_cmd = {
4154         .command = "cryptodev_aesni_gcm_autotest",
4155         .callback = test_cryptodev_aesni_gcm,
4156 };
4157
4158 static int
4159 test_cryptodev_null(void)
4160 {
4161         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4162
4163         return unit_test_suite_runner(&cryptodev_null_testsuite);
4164 }
4165
4166 static struct test_command cryptodev_null_cmd = {
4167         .command = "cryptodev_null_autotest",
4168         .callback = test_cryptodev_null,
4169 };
4170
4171 static int
4172 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4173 {
4174         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4175
4176         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4177 }
4178
4179 static struct test_command cryptodev_sw_snow3g_cmd = {
4180         .command = "cryptodev_sw_snow3g_autotest",
4181         .callback = test_cryptodev_sw_snow3g,
4182 };
4183
4184 static int
4185 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4186 {
4187         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4188
4189         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4190 }
4191
4192 static struct test_command cryptodev_sw_kasumi_cmd = {
4193         .command = "cryptodev_sw_kasumi_autotest",
4194         .callback = test_cryptodev_sw_kasumi,
4195 };
4196
4197 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4198 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4199 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4200 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4201 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);
4202 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_cmd);