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