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