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