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