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