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