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