745f2611aca2267dc005897eeda6b0ebdc538033
[dpdk.git] / test / test / test_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2017 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 #include <rte_pause.h>
39
40 #include <rte_crypto.h>
41 #include <rte_cryptodev.h>
42 #include <rte_cryptodev_pmd.h>
43
44 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
45 #include <rte_cryptodev_scheduler.h>
46 #include <rte_cryptodev_scheduler_operations.h>
47 #endif
48
49 #include "test.h"
50 #include "test_cryptodev.h"
51
52 #include "test_cryptodev_blockcipher.h"
53 #include "test_cryptodev_aes_test_vectors.h"
54 #include "test_cryptodev_des_test_vectors.h"
55 #include "test_cryptodev_hash_test_vectors.h"
56 #include "test_cryptodev_kasumi_test_vectors.h"
57 #include "test_cryptodev_kasumi_hash_test_vectors.h"
58 #include "test_cryptodev_snow3g_test_vectors.h"
59 #include "test_cryptodev_snow3g_hash_test_vectors.h"
60 #include "test_cryptodev_zuc_test_vectors.h"
61 #include "test_cryptodev_gcm_test_vectors.h"
62 #include "test_cryptodev_hmac_test_vectors.h"
63
64 static int gbl_driver_id;
65
66 struct crypto_testsuite_params {
67         struct rte_mempool *mbuf_pool;
68         struct rte_mempool *large_mbuf_pool;
69         struct rte_mempool *op_mpool;
70         struct rte_mempool *session_mpool;
71         struct rte_cryptodev_config conf;
72         struct rte_cryptodev_qp_conf qp_conf;
73
74         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
75         uint8_t valid_dev_count;
76 };
77
78 struct crypto_unittest_params {
79         struct rte_crypto_sym_xform cipher_xform;
80         struct rte_crypto_sym_xform auth_xform;
81         struct rte_crypto_sym_xform aead_xform;
82
83         struct rte_cryptodev_sym_session *sess;
84
85         struct rte_crypto_op *op;
86
87         struct rte_mbuf *obuf, *ibuf;
88
89         uint8_t *digest;
90 };
91
92 #define ALIGN_POW2_ROUNDUP(num, align) \
93         (((num) + (align) - 1) & ~((align) - 1))
94
95 /*
96  * Forward declarations.
97  */
98 static int
99 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
100                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
101                 uint8_t *hmac_key);
102
103 static int
104 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
105                 struct crypto_unittest_params *ut_params,
106                 struct crypto_testsuite_params *ts_param,
107                 const uint8_t *cipher,
108                 const uint8_t *digest,
109                 const uint8_t *iv);
110
111 static struct rte_mbuf *
112 setup_test_string(struct rte_mempool *mpool,
113                 const char *string, size_t len, uint8_t blocksize)
114 {
115         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
116         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
117
118         memset(m->buf_addr, 0, m->buf_len);
119         if (m) {
120                 char *dst = rte_pktmbuf_append(m, t_len);
121
122                 if (!dst) {
123                         rte_pktmbuf_free(m);
124                         return NULL;
125                 }
126                 if (string != NULL)
127                         rte_memcpy(dst, string, t_len);
128                 else
129                         memset(dst, 0, t_len);
130         }
131
132         return m;
133 }
134
135 /* Get number of bytes in X bits (rounding up) */
136 static uint32_t
137 ceil_byte_length(uint32_t num_bits)
138 {
139         if (num_bits % 8)
140                 return ((num_bits >> 3) + 1);
141         else
142                 return (num_bits >> 3);
143 }
144
145 static struct rte_crypto_op *
146 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
147 {
148         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
149                 printf("Error sending packet for encryption");
150                 return NULL;
151         }
152
153         op = NULL;
154
155         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
156                 rte_pause();
157
158         return op;
159 }
160
161 static struct crypto_testsuite_params testsuite_params = { NULL };
162 static struct crypto_unittest_params unittest_params;
163
164 static int
165 testsuite_setup(void)
166 {
167         struct crypto_testsuite_params *ts_params = &testsuite_params;
168         struct rte_cryptodev_info info;
169         uint32_t i = 0, nb_devs, dev_id;
170         int ret;
171         uint16_t qp_id;
172
173         memset(ts_params, 0, sizeof(*ts_params));
174
175         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
176         if (ts_params->mbuf_pool == NULL) {
177                 /* Not already created so create */
178                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
179                                 "CRYPTO_MBUFPOOL",
180                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
181                                 rte_socket_id());
182                 if (ts_params->mbuf_pool == NULL) {
183                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
184                         return TEST_FAILED;
185                 }
186         }
187
188         ts_params->large_mbuf_pool = rte_mempool_lookup(
189                         "CRYPTO_LARGE_MBUFPOOL");
190         if (ts_params->large_mbuf_pool == NULL) {
191                 /* Not already created so create */
192                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
193                                 "CRYPTO_LARGE_MBUFPOOL",
194                                 1, 0, 0, UINT16_MAX,
195                                 rte_socket_id());
196                 if (ts_params->large_mbuf_pool == NULL) {
197                         RTE_LOG(ERR, USER1,
198                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
199                         return TEST_FAILED;
200                 }
201         }
202
203         ts_params->op_mpool = rte_crypto_op_pool_create(
204                         "MBUF_CRYPTO_SYM_OP_POOL",
205                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
206                         NUM_MBUFS, MBUF_CACHE_SIZE,
207                         DEFAULT_NUM_XFORMS *
208                         sizeof(struct rte_crypto_sym_xform) +
209                         MAXIMUM_IV_LENGTH,
210                         rte_socket_id());
211         if (ts_params->op_mpool == NULL) {
212                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
213                 return TEST_FAILED;
214         }
215
216         /* Create an AESNI MB device if required */
217         if (gbl_driver_id == rte_cryptodev_driver_id_get(
218                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
219                 nb_devs = rte_cryptodev_device_count_by_driver(
220                                 rte_cryptodev_driver_id_get(
221                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
222                 if (nb_devs < 1) {
223                         ret = rte_vdev_init(
224                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
225
226                         TEST_ASSERT(ret == 0,
227                                 "Failed to create instance of"
228                                 " pmd : %s",
229                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
230                 }
231         }
232
233         /* Create an AESNI GCM device if required */
234         if (gbl_driver_id == rte_cryptodev_driver_id_get(
235                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
236                 nb_devs = rte_cryptodev_device_count_by_driver(
237                                 rte_cryptodev_driver_id_get(
238                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
239                 if (nb_devs < 1) {
240                         TEST_ASSERT_SUCCESS(rte_vdev_init(
241                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
242                                 "Failed to create instance of"
243                                 " pmd : %s",
244                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
245                 }
246         }
247
248         /* Create a SNOW 3G device if required */
249         if (gbl_driver_id == rte_cryptodev_driver_id_get(
250                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
251                 nb_devs = rte_cryptodev_device_count_by_driver(
252                                 rte_cryptodev_driver_id_get(
253                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
254                 if (nb_devs < 1) {
255                         TEST_ASSERT_SUCCESS(rte_vdev_init(
256                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
257                                 "Failed to create instance of"
258                                 " pmd : %s",
259                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
260                 }
261         }
262
263         /* Create a KASUMI device if required */
264         if (gbl_driver_id == rte_cryptodev_driver_id_get(
265                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
266                 nb_devs = rte_cryptodev_device_count_by_driver(
267                                 rte_cryptodev_driver_id_get(
268                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
269                 if (nb_devs < 1) {
270                         TEST_ASSERT_SUCCESS(rte_vdev_init(
271                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
272                                 "Failed to create instance of"
273                                 " pmd : %s",
274                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
275                 }
276         }
277
278         /* Create a ZUC device if required */
279         if (gbl_driver_id == rte_cryptodev_driver_id_get(
280                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
281                 nb_devs = rte_cryptodev_device_count_by_driver(
282                                 rte_cryptodev_driver_id_get(
283                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
284                 if (nb_devs < 1) {
285                         TEST_ASSERT_SUCCESS(rte_vdev_init(
286                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
287                                 "Failed to create instance of"
288                                 " pmd : %s",
289                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
290                 }
291         }
292
293         /* Create a NULL device if required */
294         if (gbl_driver_id == rte_cryptodev_driver_id_get(
295                         RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
296                 nb_devs = rte_cryptodev_device_count_by_driver(
297                                 rte_cryptodev_driver_id_get(
298                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
299                 if (nb_devs < 1) {
300                         ret = rte_vdev_init(
301                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
302
303                         TEST_ASSERT(ret == 0,
304                                 "Failed to create instance of"
305                                 " pmd : %s",
306                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
307                 }
308         }
309
310         /* Create an OPENSSL device if required */
311         if (gbl_driver_id == rte_cryptodev_driver_id_get(
312                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
313                 nb_devs = rte_cryptodev_device_count_by_driver(
314                                 rte_cryptodev_driver_id_get(
315                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
316                 if (nb_devs < 1) {
317                         ret = rte_vdev_init(
318                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
319                                 NULL);
320
321                         TEST_ASSERT(ret == 0, "Failed to create "
322                                 "instance of pmd : %s",
323                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
324                 }
325         }
326
327         /* Create a ARMv8 device if required */
328         if (gbl_driver_id == rte_cryptodev_driver_id_get(
329                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
330                 nb_devs = rte_cryptodev_device_count_by_driver(
331                                 rte_cryptodev_driver_id_get(
332                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
333                 if (nb_devs < 1) {
334                         ret = rte_vdev_init(
335                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
336                                 NULL);
337
338                         TEST_ASSERT(ret == 0, "Failed to create "
339                                 "instance of pmd : %s",
340                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
341                 }
342         }
343
344 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
345         if (gbl_driver_id == rte_cryptodev_driver_id_get(
346                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
347
348                 nb_devs = rte_cryptodev_device_count_by_driver(
349                                 rte_cryptodev_driver_id_get(
350                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
351                 if (nb_devs < 1) {
352                         ret = rte_vdev_init(
353                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
354                                 NULL);
355
356                         TEST_ASSERT(ret == 0,
357                                 "Failed to create instance %u of"
358                                 " pmd : %s",
359                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
360                 }
361         }
362 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
363
364         nb_devs = rte_cryptodev_count();
365         if (nb_devs < 1) {
366                 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
367                 return TEST_FAILED;
368         }
369
370         /* Create list of valid crypto devs */
371         for (i = 0; i < nb_devs; i++) {
372                 rte_cryptodev_info_get(i, &info);
373                 if (info.driver_id == gbl_driver_id)
374                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
375         }
376
377         if (ts_params->valid_dev_count < 1)
378                 return TEST_FAILED;
379
380         /* Set up all the qps on the first of the valid devices found */
381
382         dev_id = ts_params->valid_devs[0];
383
384         rte_cryptodev_info_get(dev_id, &info);
385
386         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
387         ts_params->conf.socket_id = SOCKET_ID_ANY;
388
389         unsigned int session_size = rte_cryptodev_get_private_session_size(dev_id);
390
391         /*
392          * Create mempool with maximum number of sessions * 2,
393          * to include the session headers
394          */
395         ts_params->session_mpool = rte_mempool_create(
396                                 "test_sess_mp",
397                                 info.sym.max_nb_sessions * 2,
398                                 session_size,
399                                 0, 0, NULL, NULL, NULL,
400                                 NULL, SOCKET_ID_ANY,
401                                 0);
402
403         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
404                         "session mempool allocation failed");
405
406         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
407                         &ts_params->conf, ts_params->session_mpool),
408                         "Failed to configure cryptodev %u with %u qps",
409                         dev_id, ts_params->conf.nb_queue_pairs);
410
411         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
412
413         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
414                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
415                         dev_id, qp_id, &ts_params->qp_conf,
416                         rte_cryptodev_socket_id(dev_id)),
417                         "Failed to setup queue pair %u on cryptodev %u",
418                         qp_id, dev_id);
419         }
420
421         return TEST_SUCCESS;
422 }
423
424 static void
425 testsuite_teardown(void)
426 {
427         struct crypto_testsuite_params *ts_params = &testsuite_params;
428
429         if (ts_params->mbuf_pool != NULL) {
430                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
431                 rte_mempool_avail_count(ts_params->mbuf_pool));
432         }
433
434         if (ts_params->op_mpool != NULL) {
435                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
436                 rte_mempool_avail_count(ts_params->op_mpool));
437         }
438
439         /* Free session mempools */
440         if (ts_params->session_mpool != NULL) {
441                 rte_mempool_free(ts_params->session_mpool);
442                 ts_params->session_mpool = NULL;
443         }
444 }
445
446 static int
447 ut_setup(void)
448 {
449         struct crypto_testsuite_params *ts_params = &testsuite_params;
450         struct crypto_unittest_params *ut_params = &unittest_params;
451
452         uint16_t qp_id;
453
454         /* Clear unit test parameters before running test */
455         memset(ut_params, 0, sizeof(*ut_params));
456
457         /* Reconfigure device to default parameters */
458         ts_params->conf.socket_id = SOCKET_ID_ANY;
459
460         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
461                         &ts_params->conf, ts_params->session_mpool),
462                         "Failed to configure cryptodev %u",
463                         ts_params->valid_devs[0]);
464
465         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
466                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
467                         ts_params->valid_devs[0], qp_id,
468                         &ts_params->qp_conf,
469                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
470                         "Failed to setup queue pair %u on cryptodev %u",
471                         qp_id, ts_params->valid_devs[0]);
472         }
473
474
475         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
476
477         /* Start the device */
478         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
479                         "Failed to start cryptodev %u",
480                         ts_params->valid_devs[0]);
481
482         return TEST_SUCCESS;
483 }
484
485 static void
486 ut_teardown(void)
487 {
488         struct crypto_testsuite_params *ts_params = &testsuite_params;
489         struct crypto_unittest_params *ut_params = &unittest_params;
490         struct rte_cryptodev_stats stats;
491
492         /* free crypto session structure */
493         if (ut_params->sess) {
494                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
495                                 ut_params->sess);
496                 rte_cryptodev_sym_session_free(ut_params->sess);
497                 ut_params->sess = NULL;
498         }
499
500         /* free crypto operation structure */
501         if (ut_params->op)
502                 rte_crypto_op_free(ut_params->op);
503
504         /*
505          * free mbuf - both obuf and ibuf are usually the same,
506          * so check if they point at the same address is necessary,
507          * to avoid freeing the mbuf twice.
508          */
509         if (ut_params->obuf) {
510                 rte_pktmbuf_free(ut_params->obuf);
511                 if (ut_params->ibuf == ut_params->obuf)
512                         ut_params->ibuf = 0;
513                 ut_params->obuf = 0;
514         }
515         if (ut_params->ibuf) {
516                 rte_pktmbuf_free(ut_params->ibuf);
517                 ut_params->ibuf = 0;
518         }
519
520         if (ts_params->mbuf_pool != NULL)
521                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
522                         rte_mempool_avail_count(ts_params->mbuf_pool));
523
524         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
525
526         /* Stop the device */
527         rte_cryptodev_stop(ts_params->valid_devs[0]);
528 }
529
530 static int
531 test_device_configure_invalid_dev_id(void)
532 {
533         struct crypto_testsuite_params *ts_params = &testsuite_params;
534         uint16_t dev_id, num_devs = 0;
535
536         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
537                         "Need at least %d devices for test", 1);
538
539         /* valid dev_id values */
540         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
541
542         /* Stop the device in case it's started so it can be configured */
543         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
544
545         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf,
546                                 ts_params->session_mpool),
547                         "Failed test for rte_cryptodev_configure: "
548                         "invalid dev_num %u", dev_id);
549
550         /* invalid dev_id values */
551         dev_id = num_devs;
552
553         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf,
554                                 ts_params->session_mpool),
555                         "Failed test for rte_cryptodev_configure: "
556                         "invalid dev_num %u", dev_id);
557
558         dev_id = 0xff;
559
560         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf,
561                                 ts_params->session_mpool),
562                         "Failed test for rte_cryptodev_configure:"
563                         "invalid dev_num %u", dev_id);
564
565         return TEST_SUCCESS;
566 }
567
568 static int
569 test_device_configure_invalid_queue_pair_ids(void)
570 {
571         struct crypto_testsuite_params *ts_params = &testsuite_params;
572         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
573
574         /* Stop the device in case it's started so it can be configured */
575         rte_cryptodev_stop(ts_params->valid_devs[0]);
576
577         /* valid - one queue pairs */
578         ts_params->conf.nb_queue_pairs = 1;
579
580         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
581                         &ts_params->conf, ts_params->session_mpool),
582                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
583                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
584
585
586         /* valid - max value queue pairs */
587         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
588
589         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
590                         &ts_params->conf, ts_params->session_mpool),
591                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
592                         ts_params->valid_devs[0],
593                         ts_params->conf.nb_queue_pairs);
594
595
596         /* invalid - zero queue pairs */
597         ts_params->conf.nb_queue_pairs = 0;
598
599         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
600                         &ts_params->conf, ts_params->session_mpool),
601                         "Failed test for rte_cryptodev_configure, dev_id %u,"
602                         " invalid qps: %u",
603                         ts_params->valid_devs[0],
604                         ts_params->conf.nb_queue_pairs);
605
606
607         /* invalid - max value supported by field queue pairs */
608         ts_params->conf.nb_queue_pairs = UINT16_MAX;
609
610         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
611                         &ts_params->conf, ts_params->session_mpool),
612                         "Failed test for rte_cryptodev_configure, dev_id %u,"
613                         " invalid qps: %u",
614                         ts_params->valid_devs[0],
615                         ts_params->conf.nb_queue_pairs);
616
617
618         /* invalid - max value + 1 queue pairs */
619         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
620
621         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
622                         &ts_params->conf, ts_params->session_mpool),
623                         "Failed test for rte_cryptodev_configure, dev_id %u,"
624                         " invalid qps: %u",
625                         ts_params->valid_devs[0],
626                         ts_params->conf.nb_queue_pairs);
627
628         /* revert to original testsuite value */
629         ts_params->conf.nb_queue_pairs = orig_nb_qps;
630
631         return TEST_SUCCESS;
632 }
633
634 static int
635 test_queue_pair_descriptor_setup(void)
636 {
637         struct crypto_testsuite_params *ts_params = &testsuite_params;
638         struct rte_cryptodev_info dev_info;
639         struct rte_cryptodev_qp_conf qp_conf = {
640                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
641         };
642
643         uint16_t qp_id;
644
645         /* Stop the device in case it's started so it can be configured */
646         rte_cryptodev_stop(ts_params->valid_devs[0]);
647
648
649         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
650
651         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
652                         &ts_params->conf, ts_params->session_mpool),
653                         "Failed to configure cryptodev %u",
654                         ts_params->valid_devs[0]);
655
656         /*
657          * Test various ring sizes on this device. memzones can't be
658          * freed so are re-used if ring is released and re-created.
659          */
660         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
661
662         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
663                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
664                                 ts_params->valid_devs[0], qp_id, &qp_conf,
665                                 rte_cryptodev_socket_id(
666                                                 ts_params->valid_devs[0])),
667                                 "Failed test for "
668                                 "rte_cryptodev_queue_pair_setup: num_inflights "
669                                 "%u on qp %u on cryptodev %u",
670                                 qp_conf.nb_descriptors, qp_id,
671                                 ts_params->valid_devs[0]);
672         }
673
674         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
675
676         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
677                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
678                                 ts_params->valid_devs[0], qp_id, &qp_conf,
679                                 rte_cryptodev_socket_id(
680                                                 ts_params->valid_devs[0])),
681                                 "Failed test for"
682                                 " rte_cryptodev_queue_pair_setup: num_inflights"
683                                 " %u on qp %u on cryptodev %u",
684                                 qp_conf.nb_descriptors, qp_id,
685                                 ts_params->valid_devs[0]);
686         }
687
688         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
689
690         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
691                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
692                                 ts_params->valid_devs[0], qp_id, &qp_conf,
693                                 rte_cryptodev_socket_id(
694                                                 ts_params->valid_devs[0])),
695                                 "Failed test for "
696                                 "rte_cryptodev_queue_pair_setup: num_inflights"
697                                 " %u on qp %u on cryptodev %u",
698                                 qp_conf.nb_descriptors, qp_id,
699                                 ts_params->valid_devs[0]);
700         }
701
702         /* invalid number of descriptors - max supported + 2 */
703         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
704
705         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
706                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
707                                 ts_params->valid_devs[0], qp_id, &qp_conf,
708                                 rte_cryptodev_socket_id(
709                                                 ts_params->valid_devs[0])),
710                                 "Unexpectedly passed test for "
711                                 "rte_cryptodev_queue_pair_setup:"
712                                 "num_inflights %u on qp %u on cryptodev %u",
713                                 qp_conf.nb_descriptors, qp_id,
714                                 ts_params->valid_devs[0]);
715         }
716
717         /* invalid number of descriptors - max value of parameter */
718         qp_conf.nb_descriptors = UINT32_MAX-1;
719
720         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
721                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
722                                 ts_params->valid_devs[0], qp_id, &qp_conf,
723                                 rte_cryptodev_socket_id(
724                                                 ts_params->valid_devs[0])),
725                                 "Unexpectedly passed test for "
726                                 "rte_cryptodev_queue_pair_setup:"
727                                 "num_inflights %u on qp %u on cryptodev %u",
728                                 qp_conf.nb_descriptors, qp_id,
729                                 ts_params->valid_devs[0]);
730         }
731
732         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
733
734         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
735                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
736                                 ts_params->valid_devs[0], qp_id, &qp_conf,
737                                 rte_cryptodev_socket_id(
738                                                 ts_params->valid_devs[0])),
739                                 "Failed test for"
740                                 " rte_cryptodev_queue_pair_setup:"
741                                 "num_inflights %u on qp %u on cryptodev %u",
742                                 qp_conf.nb_descriptors, qp_id,
743                                 ts_params->valid_devs[0]);
744         }
745
746         /* invalid number of descriptors - max supported + 1 */
747         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
748
749         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
750                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
751                                 ts_params->valid_devs[0], qp_id, &qp_conf,
752                                 rte_cryptodev_socket_id(
753                                                 ts_params->valid_devs[0])),
754                                 "Unexpectedly passed test for "
755                                 "rte_cryptodev_queue_pair_setup:"
756                                 "num_inflights %u on qp %u on cryptodev %u",
757                                 qp_conf.nb_descriptors, qp_id,
758                                 ts_params->valid_devs[0]);
759         }
760
761         /* test invalid queue pair id */
762         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
763
764         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
765
766         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
767                         ts_params->valid_devs[0],
768                         qp_id, &qp_conf,
769                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
770                         "Failed test for rte_cryptodev_queue_pair_setup:"
771                         "invalid qp %u on cryptodev %u",
772                         qp_id, ts_params->valid_devs[0]);
773
774         qp_id = 0xffff; /*invalid*/
775
776         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
777                         ts_params->valid_devs[0],
778                         qp_id, &qp_conf,
779                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
780                         "Failed test for rte_cryptodev_queue_pair_setup:"
781                         "invalid qp %u on cryptodev %u",
782                         qp_id, ts_params->valid_devs[0]);
783
784         return TEST_SUCCESS;
785 }
786
787 /* ***** Plaintext data for tests ***** */
788
789 const char catch_22_quote_1[] =
790                 "There was only one catch and that was Catch-22, which "
791                 "specified that a concern for one's safety in the face of "
792                 "dangers that were real and immediate was the process of a "
793                 "rational mind. Orr was crazy and could be grounded. All he "
794                 "had to do was ask; and as soon as he did, he would no longer "
795                 "be crazy and would have to fly more missions. Orr would be "
796                 "crazy to fly more missions and sane if he didn't, but if he "
797                 "was sane he had to fly them. If he flew them he was crazy "
798                 "and didn't have to; but if he didn't want to he was sane and "
799                 "had to. Yossarian was moved very deeply by the absolute "
800                 "simplicity of this clause of Catch-22 and let out a "
801                 "respectful whistle. \"That's some catch, that Catch-22\", he "
802                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
803
804 const char catch_22_quote[] =
805                 "What a lousy earth! He wondered how many people were "
806                 "destitute that same night even in his own prosperous country, "
807                 "how many homes were shanties, how many husbands were drunk "
808                 "and wives socked, and how many children were bullied, abused, "
809                 "or abandoned. How many families hungered for food they could "
810                 "not afford to buy? How many hearts were broken? How many "
811                 "suicides would take place that same night, how many people "
812                 "would go insane? How many cockroaches and landlords would "
813                 "triumph? How many winners were losers, successes failures, "
814                 "and rich men poor men? How many wise guys were stupid? How "
815                 "many happy endings were unhappy endings? How many honest men "
816                 "were liars, brave men cowards, loyal men traitors, how many "
817                 "sainted men were corrupt, how many people in positions of "
818                 "trust had sold their souls to bodyguards, how many had never "
819                 "had souls? How many straight-and-narrow paths were crooked "
820                 "paths? How many best families were worst families and how "
821                 "many good people were bad people? When you added them all up "
822                 "and then subtracted, you might be left with only the children, "
823                 "and perhaps with Albert Einstein and an old violinist or "
824                 "sculptor somewhere.";
825
826 #define QUOTE_480_BYTES         (480)
827 #define QUOTE_512_BYTES         (512)
828 #define QUOTE_768_BYTES         (768)
829 #define QUOTE_1024_BYTES        (1024)
830
831
832
833 /* ***** SHA1 Hash Tests ***** */
834
835 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
836
837 static uint8_t hmac_sha1_key[] = {
838         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
839         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
840         0xDE, 0xF4, 0xDE, 0xAD };
841
842 /* ***** SHA224 Hash Tests ***** */
843
844 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
845
846
847 /* ***** AES-CBC Cipher Tests ***** */
848
849 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
850 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
851
852 static uint8_t aes_cbc_key[] = {
853         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
854         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
855
856 static uint8_t aes_cbc_iv[] = {
857         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
858         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
859
860
861 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
862
863 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
864         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
865         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
866         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
867         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
868         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
869         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
870         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
871         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
872         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
873         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
874         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
875         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
876         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
877         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
878         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
879         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
880         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
881         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
882         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
883         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
884         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
885         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
886         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
887         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
888         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
889         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
890         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
891         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
892         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
893         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
894         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
895         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
896         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
897         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
898         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
899         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
900         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
901         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
902         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
903         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
904         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
905         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
906         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
907         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
908         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
909         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
910         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
911         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
912         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
913         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
914         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
915         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
916         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
917         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
918         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
919         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
920         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
921         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
922         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
923         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
924         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
925         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
926         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
927         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
928 };
929
930 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
931         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
932         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
933         0x18, 0x8c, 0x1d, 0x32
934 };
935
936
937 /* Multisession Vector context Test */
938 /*Begin Session 0 */
939 static uint8_t ms_aes_cbc_key0[] = {
940         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
941         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
942 };
943
944 static uint8_t ms_aes_cbc_iv0[] = {
945         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
946         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
947 };
948
949 static const uint8_t ms_aes_cbc_cipher0[] = {
950                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
951                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
952                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
953                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
954                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
955                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
956                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
957                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
958                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
959                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
960                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
961                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
962                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
963                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
964                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
965                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
966                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
967                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
968                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
969                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
970                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
971                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
972                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
973                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
974                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
975                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
976                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
977                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
978                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
979                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
980                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
981                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
982                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
983                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
984                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
985                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
986                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
987                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
988                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
989                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
990                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
991                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
992                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
993                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
994                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
995                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
996                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
997                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
998                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
999                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1000                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1001                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1002                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1003                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1004                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1005                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1006                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1007                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1008                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1009                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1010                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1011                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1012                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1013                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1014 };
1015
1016
1017 static  uint8_t ms_hmac_key0[] = {
1018                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1019                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1020                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1021                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1022                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1023                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1024                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1025                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1026 };
1027
1028 static const uint8_t ms_hmac_digest0[] = {
1029                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1030                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1031                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1032                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1033                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1034                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1035                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1036                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1037                 };
1038
1039 /* End Session 0 */
1040 /* Begin session 1 */
1041
1042 static  uint8_t ms_aes_cbc_key1[] = {
1043                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1044                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1045 };
1046
1047 static  uint8_t ms_aes_cbc_iv1[] = {
1048         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1049         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1050 };
1051
1052 static const uint8_t ms_aes_cbc_cipher1[] = {
1053                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1054                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1055                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1056                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1057                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1058                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1059                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1060                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1061                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1062                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1063                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1064                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1065                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1066                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1067                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1068                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1069                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1070                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1071                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1072                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1073                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1074                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1075                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1076                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1077                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1078                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1079                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1080                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1081                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1082                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1083                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1084                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1085                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1086                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1087                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1088                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1089                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1090                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1091                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1092                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1093                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1094                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1095                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1096                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1097                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1098                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1099                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1100                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1101                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1102                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1103                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1104                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1105                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1106                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1107                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1108                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1109                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1110                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1111                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1112                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1113                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1114                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1115                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1116                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1117
1118 };
1119
1120 static uint8_t ms_hmac_key1[] = {
1121                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1122                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1123                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1124                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1125                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1126                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1127                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1128                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1129 };
1130
1131 static const uint8_t ms_hmac_digest1[] = {
1132                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1133                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1134                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1135                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1136                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1137                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1138                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1139                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1140 };
1141 /* End Session 1  */
1142 /* Begin Session 2 */
1143 static  uint8_t ms_aes_cbc_key2[] = {
1144                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1145                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1146 };
1147
1148 static  uint8_t ms_aes_cbc_iv2[] = {
1149                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1150                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1151 };
1152
1153 static const uint8_t ms_aes_cbc_cipher2[] = {
1154                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1155                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1156                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1157                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1158                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1159                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1160                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1161                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1162                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1163                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1164                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1165                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1166                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1167                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1168                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1169                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1170                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1171                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1172                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1173                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1174                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1175                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1176                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1177                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1178                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1179                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1180                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1181                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1182                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1183                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1184                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1185                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1186                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1187                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1188                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1189                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1190                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1191                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1192                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1193                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1194                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1195                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1196                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1197                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1198                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1199                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1200                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1201                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1202                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1203                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1204                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1205                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1206                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1207                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1208                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1209                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1210                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1211                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1212                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1213                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1214                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1215                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1216                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1217                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1218 };
1219
1220 static  uint8_t ms_hmac_key2[] = {
1221                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1222                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1223                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1224                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1225                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1226                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1227                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1228                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1229 };
1230
1231 static const uint8_t ms_hmac_digest2[] = {
1232                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1233                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1234                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1235                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1236                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1237                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1238                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1239                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1240 };
1241
1242 /* End Session 2 */
1243
1244
1245 static int
1246 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1247 {
1248         struct crypto_testsuite_params *ts_params = &testsuite_params;
1249         struct crypto_unittest_params *ut_params = &unittest_params;
1250
1251         /* Generate test mbuf data and space for digest */
1252         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1253                         catch_22_quote, QUOTE_512_BYTES, 0);
1254
1255         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1256                         DIGEST_BYTE_LENGTH_SHA1);
1257         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1258
1259         /* Setup Cipher Parameters */
1260         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1261         ut_params->cipher_xform.next = &ut_params->auth_xform;
1262
1263         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1264         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1265         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1266         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1267         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1268         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1269
1270         /* Setup HMAC Parameters */
1271         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1272
1273         ut_params->auth_xform.next = NULL;
1274
1275         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1276         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1277         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1278         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1279         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1280
1281         ut_params->sess = rte_cryptodev_sym_session_create(
1282                         ts_params->session_mpool);
1283
1284         /* Create crypto session*/
1285         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1286                         ut_params->sess, &ut_params->cipher_xform,
1287                         ts_params->session_mpool);
1288         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1289
1290         /* Generate crypto op data structure */
1291         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1292                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1293         TEST_ASSERT_NOT_NULL(ut_params->op,
1294                         "Failed to allocate symmetric crypto operation struct");
1295
1296         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1297
1298         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1299
1300         /* set crypto operation source mbuf */
1301         sym_op->m_src = ut_params->ibuf;
1302
1303         /* Set crypto operation authentication parameters */
1304         sym_op->auth.digest.data = ut_params->digest;
1305         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1306                         ut_params->ibuf, QUOTE_512_BYTES);
1307
1308         sym_op->auth.data.offset = 0;
1309         sym_op->auth.data.length = QUOTE_512_BYTES;
1310
1311         /* Copy IV at the end of the crypto operation */
1312         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1313                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1314
1315         /* Set crypto operation cipher parameters */
1316         sym_op->cipher.data.offset = 0;
1317         sym_op->cipher.data.length = QUOTE_512_BYTES;
1318
1319         /* Process crypto operation */
1320         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1321                         ut_params->op), "failed to process sym crypto op");
1322
1323         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1324                         "crypto op processing failed");
1325
1326         /* Validate obuf */
1327         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1328                         uint8_t *);
1329
1330         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1331                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1332                         QUOTE_512_BYTES,
1333                         "ciphertext data not as expected");
1334
1335         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1336
1337         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1338                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1339                         gbl_driver_id == rte_cryptodev_driver_id_get(
1340                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1341                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1342                                         DIGEST_BYTE_LENGTH_SHA1,
1343                         "Generated digest data not as expected");
1344
1345         return TEST_SUCCESS;
1346 }
1347
1348 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1349
1350 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1351
1352 static uint8_t hmac_sha512_key[] = {
1353         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1354         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1355         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1356         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1357         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1358         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1359         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1360         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1361
1362 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1363         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1364         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1365         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1366         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1367         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1368         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1369         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1370         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1371
1372
1373
1374 static int
1375 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1376                 struct crypto_unittest_params *ut_params,
1377                 uint8_t *cipher_key,
1378                 uint8_t *hmac_key);
1379
1380 static int
1381 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1382                 struct crypto_unittest_params *ut_params,
1383                 struct crypto_testsuite_params *ts_params,
1384                 const uint8_t *cipher,
1385                 const uint8_t *digest,
1386                 const uint8_t *iv);
1387
1388
1389 static int
1390 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1391                 struct crypto_unittest_params *ut_params,
1392                 uint8_t *cipher_key,
1393                 uint8_t *hmac_key)
1394 {
1395
1396         /* Setup Cipher Parameters */
1397         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1398         ut_params->cipher_xform.next = NULL;
1399
1400         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1401         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1402         ut_params->cipher_xform.cipher.key.data = cipher_key;
1403         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1404         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1405         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1406
1407         /* Setup HMAC Parameters */
1408         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1409         ut_params->auth_xform.next = &ut_params->cipher_xform;
1410
1411         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1412         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1413         ut_params->auth_xform.auth.key.data = hmac_key;
1414         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1415         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1416
1417         return TEST_SUCCESS;
1418 }
1419
1420
1421 static int
1422 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1423                 struct crypto_unittest_params *ut_params,
1424                 struct crypto_testsuite_params *ts_params,
1425                 const uint8_t *cipher,
1426                 const uint8_t *digest,
1427                 const uint8_t *iv)
1428 {
1429         /* Generate test mbuf data and digest */
1430         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1431                         (const char *)
1432                         cipher,
1433                         QUOTE_512_BYTES, 0);
1434
1435         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1436                         DIGEST_BYTE_LENGTH_SHA512);
1437         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1438
1439         rte_memcpy(ut_params->digest,
1440                         digest,
1441                         DIGEST_BYTE_LENGTH_SHA512);
1442
1443         /* Generate Crypto op data structure */
1444         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1445                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1446         TEST_ASSERT_NOT_NULL(ut_params->op,
1447                         "Failed to allocate symmetric crypto operation struct");
1448
1449         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1450
1451         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1452
1453         /* set crypto operation source mbuf */
1454         sym_op->m_src = ut_params->ibuf;
1455
1456         sym_op->auth.digest.data = ut_params->digest;
1457         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1458                         ut_params->ibuf, QUOTE_512_BYTES);
1459
1460         sym_op->auth.data.offset = 0;
1461         sym_op->auth.data.length = QUOTE_512_BYTES;
1462
1463         /* Copy IV at the end of the crypto operation */
1464         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1465                         iv, CIPHER_IV_LENGTH_AES_CBC);
1466
1467         sym_op->cipher.data.offset = 0;
1468         sym_op->cipher.data.length = QUOTE_512_BYTES;
1469
1470         /* Process crypto operation */
1471         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1472                         ut_params->op), "failed to process sym crypto op");
1473
1474         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1475                         "crypto op processing failed");
1476
1477         ut_params->obuf = ut_params->op->sym->m_src;
1478
1479         /* Validate obuf */
1480         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1481                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1482                         catch_22_quote,
1483                         QUOTE_512_BYTES,
1484                         "Plaintext data not as expected");
1485
1486         /* Validate obuf */
1487         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1488                         "Digest verification failed");
1489
1490         return TEST_SUCCESS;
1491 }
1492
1493 static int
1494 test_AES_cipheronly_mb_all(void)
1495 {
1496         struct crypto_testsuite_params *ts_params = &testsuite_params;
1497         int status;
1498
1499         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1500                 ts_params->op_mpool,
1501                 ts_params->session_mpool,
1502                 ts_params->valid_devs[0],
1503                 rte_cryptodev_driver_id_get(
1504                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1505                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1506
1507         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1508
1509         return TEST_SUCCESS;
1510 }
1511
1512 static int
1513 test_AES_docsis_mb_all(void)
1514 {
1515         struct crypto_testsuite_params *ts_params = &testsuite_params;
1516         int status;
1517
1518         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1519                 ts_params->op_mpool,
1520                 ts_params->session_mpool,
1521                 ts_params->valid_devs[0],
1522                 rte_cryptodev_driver_id_get(
1523                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1524                 BLKCIPHER_AES_DOCSIS_TYPE);
1525
1526         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1527
1528         return TEST_SUCCESS;
1529 }
1530
1531 static int
1532 test_AES_docsis_qat_all(void)
1533 {
1534         struct crypto_testsuite_params *ts_params = &testsuite_params;
1535         int status;
1536
1537         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1538                 ts_params->op_mpool,
1539                 ts_params->session_mpool,
1540                 ts_params->valid_devs[0],
1541                 rte_cryptodev_driver_id_get(
1542                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1543                 BLKCIPHER_AES_DOCSIS_TYPE);
1544
1545         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1546
1547         return TEST_SUCCESS;
1548 }
1549
1550 static int
1551 test_DES_docsis_qat_all(void)
1552 {
1553         struct crypto_testsuite_params *ts_params = &testsuite_params;
1554         int status;
1555
1556         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1557                 ts_params->op_mpool,
1558                 ts_params->session_mpool,
1559                 ts_params->valid_devs[0],
1560                 rte_cryptodev_driver_id_get(
1561                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1562                 BLKCIPHER_DES_DOCSIS_TYPE);
1563
1564         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1565
1566         return TEST_SUCCESS;
1567 }
1568
1569 static int
1570 test_authonly_mb_all(void)
1571 {
1572         struct crypto_testsuite_params *ts_params = &testsuite_params;
1573         int status;
1574
1575         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1576                 ts_params->op_mpool,
1577                 ts_params->session_mpool,
1578                 ts_params->valid_devs[0],
1579                 rte_cryptodev_driver_id_get(
1580                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1581                 BLKCIPHER_AUTHONLY_TYPE);
1582
1583         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1584
1585         return TEST_SUCCESS;
1586 }
1587
1588 static int
1589 test_AES_chain_mb_all(void)
1590 {
1591         struct crypto_testsuite_params *ts_params = &testsuite_params;
1592         int status;
1593
1594         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1595                 ts_params->op_mpool,
1596                 ts_params->session_mpool,
1597                 ts_params->valid_devs[0],
1598                 rte_cryptodev_driver_id_get(
1599                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)),
1600                 BLKCIPHER_AES_CHAIN_TYPE);
1601
1602         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1603
1604         return TEST_SUCCESS;
1605 }
1606
1607 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
1608
1609 static int
1610 test_AES_cipheronly_scheduler_all(void)
1611 {
1612         struct crypto_testsuite_params *ts_params = &testsuite_params;
1613         int status;
1614
1615         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1616                 ts_params->op_mpool,
1617                 ts_params->session_mpool,
1618                 ts_params->valid_devs[0],
1619                 rte_cryptodev_driver_id_get(
1620                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1621                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1622
1623         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1624
1625         return TEST_SUCCESS;
1626 }
1627
1628 static int
1629 test_AES_chain_scheduler_all(void)
1630 {
1631         struct crypto_testsuite_params *ts_params = &testsuite_params;
1632         int status;
1633
1634         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1635                 ts_params->op_mpool,
1636                 ts_params->session_mpool,
1637                 ts_params->valid_devs[0],
1638                 rte_cryptodev_driver_id_get(
1639                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1640                 BLKCIPHER_AES_CHAIN_TYPE);
1641
1642         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1643
1644         return TEST_SUCCESS;
1645 }
1646
1647 static int
1648 test_authonly_scheduler_all(void)
1649 {
1650         struct crypto_testsuite_params *ts_params = &testsuite_params;
1651         int status;
1652
1653         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1654                 ts_params->op_mpool,
1655                 ts_params->session_mpool,
1656                 ts_params->valid_devs[0],
1657                 rte_cryptodev_driver_id_get(
1658                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)),
1659                 BLKCIPHER_AUTHONLY_TYPE);
1660
1661         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1662
1663         return TEST_SUCCESS;
1664 }
1665
1666 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
1667
1668 static int
1669 test_AES_chain_openssl_all(void)
1670 {
1671         struct crypto_testsuite_params *ts_params = &testsuite_params;
1672         int status;
1673
1674         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1675                 ts_params->op_mpool,
1676                 ts_params->session_mpool,
1677                 ts_params->valid_devs[0],
1678                 rte_cryptodev_driver_id_get(
1679                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
1680                 BLKCIPHER_AES_CHAIN_TYPE);
1681
1682         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1683
1684         return TEST_SUCCESS;
1685 }
1686
1687 static int
1688 test_AES_cipheronly_openssl_all(void)
1689 {
1690         struct crypto_testsuite_params *ts_params = &testsuite_params;
1691         int status;
1692
1693         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1694                 ts_params->op_mpool,
1695                 ts_params->session_mpool,
1696                 ts_params->valid_devs[0],
1697                 rte_cryptodev_driver_id_get(
1698                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
1699                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1700
1701         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1702
1703         return TEST_SUCCESS;
1704 }
1705
1706 static int
1707 test_AES_chain_qat_all(void)
1708 {
1709         struct crypto_testsuite_params *ts_params = &testsuite_params;
1710         int status;
1711
1712         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1713                 ts_params->op_mpool,
1714                 ts_params->session_mpool,
1715                 ts_params->valid_devs[0],
1716                 rte_cryptodev_driver_id_get(
1717                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1718                 BLKCIPHER_AES_CHAIN_TYPE);
1719
1720         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1721
1722         return TEST_SUCCESS;
1723 }
1724
1725 static int
1726 test_AES_cipheronly_qat_all(void)
1727 {
1728         struct crypto_testsuite_params *ts_params = &testsuite_params;
1729         int status;
1730
1731         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1732                 ts_params->op_mpool,
1733                 ts_params->session_mpool,
1734                 ts_params->valid_devs[0],
1735                 rte_cryptodev_driver_id_get(
1736                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
1737                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1738
1739         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1740
1741         return TEST_SUCCESS;
1742 }
1743
1744 static int
1745 test_AES_chain_dpaa2_sec_all(void)
1746 {
1747         struct crypto_testsuite_params *ts_params = &testsuite_params;
1748         int status;
1749
1750         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1751                 ts_params->op_mpool,
1752                 ts_params->session_mpool,
1753                 ts_params->valid_devs[0],
1754                 rte_cryptodev_driver_id_get(
1755                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
1756                 BLKCIPHER_AES_CHAIN_TYPE);
1757
1758         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1759
1760         return TEST_SUCCESS;
1761 }
1762
1763 static int
1764 test_AES_cipheronly_dpaa2_sec_all(void)
1765 {
1766         struct crypto_testsuite_params *ts_params = &testsuite_params;
1767         int status;
1768
1769         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1770                 ts_params->op_mpool,
1771                 ts_params->session_mpool,
1772                 ts_params->valid_devs[0],
1773                 rte_cryptodev_driver_id_get(
1774                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
1775                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1776
1777         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1778
1779         return TEST_SUCCESS;
1780 }
1781
1782 static int
1783 test_authonly_dpaa2_sec_all(void)
1784 {
1785         struct crypto_testsuite_params *ts_params = &testsuite_params;
1786         int status;
1787
1788         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1789                 ts_params->op_mpool,
1790                 ts_params->session_mpool,
1791                 ts_params->valid_devs[0],
1792                 rte_cryptodev_driver_id_get(
1793                 RTE_STR(RTE_CRYPTODEV_DPAA2_SEC_PMD)),
1794                 BLKCIPHER_AUTHONLY_TYPE);
1795
1796         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1797
1798         return TEST_SUCCESS;
1799 }
1800
1801 static int
1802 test_authonly_openssl_all(void)
1803 {
1804         struct crypto_testsuite_params *ts_params = &testsuite_params;
1805         int status;
1806
1807         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1808                 ts_params->op_mpool,
1809                 ts_params->session_mpool,
1810                 ts_params->valid_devs[0],
1811                 rte_cryptodev_driver_id_get(
1812                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
1813                 BLKCIPHER_AUTHONLY_TYPE);
1814
1815         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1816
1817         return TEST_SUCCESS;
1818 }
1819
1820 static int
1821 test_AES_chain_armv8_all(void)
1822 {
1823         struct crypto_testsuite_params *ts_params = &testsuite_params;
1824         int status;
1825
1826         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1827                 ts_params->op_mpool,
1828                 ts_params->session_mpool,
1829                 ts_params->valid_devs[0],
1830                 rte_cryptodev_driver_id_get(
1831                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)),
1832                 BLKCIPHER_AES_CHAIN_TYPE);
1833
1834         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1835
1836         return TEST_SUCCESS;
1837 }
1838
1839 /* ***** SNOW 3G Tests ***** */
1840 static int
1841 create_wireless_algo_hash_session(uint8_t dev_id,
1842         const uint8_t *key, const uint8_t key_len,
1843         const uint8_t iv_len, const uint8_t auth_len,
1844         enum rte_crypto_auth_operation op,
1845         enum rte_crypto_auth_algorithm algo)
1846 {
1847         uint8_t hash_key[key_len];
1848
1849         struct crypto_testsuite_params *ts_params = &testsuite_params;
1850         struct crypto_unittest_params *ut_params = &unittest_params;
1851
1852         memcpy(hash_key, key, key_len);
1853
1854         TEST_HEXDUMP(stdout, "key:", key, key_len);
1855
1856         /* Setup Authentication Parameters */
1857         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1858         ut_params->auth_xform.next = NULL;
1859
1860         ut_params->auth_xform.auth.op = op;
1861         ut_params->auth_xform.auth.algo = algo;
1862         ut_params->auth_xform.auth.key.length = key_len;
1863         ut_params->auth_xform.auth.key.data = hash_key;
1864         ut_params->auth_xform.auth.digest_length = auth_len;
1865         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
1866         ut_params->auth_xform.auth.iv.length = iv_len;
1867         ut_params->sess = rte_cryptodev_sym_session_create(
1868                         ts_params->session_mpool);
1869
1870         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1871                         &ut_params->auth_xform, ts_params->session_mpool);
1872         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1873         return 0;
1874 }
1875
1876 static int
1877 create_wireless_algo_cipher_session(uint8_t dev_id,
1878                         enum rte_crypto_cipher_operation op,
1879                         enum rte_crypto_cipher_algorithm algo,
1880                         const uint8_t *key, const uint8_t key_len,
1881                         uint8_t iv_len)
1882 {
1883         uint8_t cipher_key[key_len];
1884
1885         struct crypto_testsuite_params *ts_params = &testsuite_params;
1886         struct crypto_unittest_params *ut_params = &unittest_params;
1887
1888         memcpy(cipher_key, key, key_len);
1889
1890         /* Setup Cipher Parameters */
1891         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1892         ut_params->cipher_xform.next = NULL;
1893
1894         ut_params->cipher_xform.cipher.algo = algo;
1895         ut_params->cipher_xform.cipher.op = op;
1896         ut_params->cipher_xform.cipher.key.data = cipher_key;
1897         ut_params->cipher_xform.cipher.key.length = key_len;
1898         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1899         ut_params->cipher_xform.cipher.iv.length = iv_len;
1900
1901         TEST_HEXDUMP(stdout, "key:", key, key_len);
1902
1903         /* Create Crypto session */
1904         ut_params->sess = rte_cryptodev_sym_session_create(
1905                         ts_params->session_mpool);
1906
1907         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1908                         &ut_params->cipher_xform, ts_params->session_mpool);
1909         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1910         return 0;
1911 }
1912
1913 static int
1914 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
1915                         unsigned int cipher_len,
1916                         unsigned int cipher_offset)
1917 {
1918         struct crypto_testsuite_params *ts_params = &testsuite_params;
1919         struct crypto_unittest_params *ut_params = &unittest_params;
1920
1921         /* Generate Crypto op data structure */
1922         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1923                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1924         TEST_ASSERT_NOT_NULL(ut_params->op,
1925                                 "Failed to allocate pktmbuf offload");
1926
1927         /* Set crypto operation data parameters */
1928         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1929
1930         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1931
1932         /* set crypto operation source mbuf */
1933         sym_op->m_src = ut_params->ibuf;
1934
1935         /* iv */
1936         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1937                         iv, iv_len);
1938         sym_op->cipher.data.length = cipher_len;
1939         sym_op->cipher.data.offset = cipher_offset;
1940         return 0;
1941 }
1942
1943 static int
1944 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
1945                         unsigned int cipher_len,
1946                         unsigned int cipher_offset)
1947 {
1948         struct crypto_testsuite_params *ts_params = &testsuite_params;
1949         struct crypto_unittest_params *ut_params = &unittest_params;
1950
1951         /* Generate Crypto op data structure */
1952         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1953                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1954         TEST_ASSERT_NOT_NULL(ut_params->op,
1955                                 "Failed to allocate pktmbuf offload");
1956
1957         /* Set crypto operation data parameters */
1958         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1959
1960         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1961
1962         /* set crypto operation source mbuf */
1963         sym_op->m_src = ut_params->ibuf;
1964         sym_op->m_dst = ut_params->obuf;
1965
1966         /* iv */
1967         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1968                         iv, iv_len);
1969         sym_op->cipher.data.length = cipher_len;
1970         sym_op->cipher.data.offset = cipher_offset;
1971         return 0;
1972 }
1973
1974 static int
1975 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1976                 enum rte_crypto_cipher_operation cipher_op,
1977                 enum rte_crypto_auth_operation auth_op,
1978                 enum rte_crypto_auth_algorithm auth_algo,
1979                 enum rte_crypto_cipher_algorithm cipher_algo,
1980                 const uint8_t *key, uint8_t key_len,
1981                 uint8_t auth_iv_len, uint8_t auth_len,
1982                 uint8_t cipher_iv_len)
1983
1984 {
1985         uint8_t cipher_auth_key[key_len];
1986
1987         struct crypto_testsuite_params *ts_params = &testsuite_params;
1988         struct crypto_unittest_params *ut_params = &unittest_params;
1989
1990         memcpy(cipher_auth_key, key, key_len);
1991
1992         /* Setup Authentication Parameters */
1993         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1994         ut_params->auth_xform.next = NULL;
1995
1996         ut_params->auth_xform.auth.op = auth_op;
1997         ut_params->auth_xform.auth.algo = auth_algo;
1998         ut_params->auth_xform.auth.key.length = key_len;
1999         /* Hash key = cipher key */
2000         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2001         ut_params->auth_xform.auth.digest_length = auth_len;
2002         /* Auth IV will be after cipher IV */
2003         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2004         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2005
2006         /* Setup Cipher Parameters */
2007         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2008         ut_params->cipher_xform.next = &ut_params->auth_xform;
2009
2010         ut_params->cipher_xform.cipher.algo = cipher_algo;
2011         ut_params->cipher_xform.cipher.op = cipher_op;
2012         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2013         ut_params->cipher_xform.cipher.key.length = key_len;
2014         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2015         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2016
2017         TEST_HEXDUMP(stdout, "key:", key, key_len);
2018
2019         /* Create Crypto session*/
2020         ut_params->sess = rte_cryptodev_sym_session_create(
2021                         ts_params->session_mpool);
2022
2023         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2024                         &ut_params->cipher_xform, ts_params->session_mpool);
2025
2026         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2027         return 0;
2028 }
2029
2030 static int
2031 create_wireless_cipher_auth_session(uint8_t dev_id,
2032                 enum rte_crypto_cipher_operation cipher_op,
2033                 enum rte_crypto_auth_operation auth_op,
2034                 enum rte_crypto_auth_algorithm auth_algo,
2035                 enum rte_crypto_cipher_algorithm cipher_algo,
2036                 const struct wireless_test_data *tdata)
2037 {
2038         const uint8_t key_len = tdata->key.len;
2039         uint8_t cipher_auth_key[key_len];
2040
2041         struct crypto_testsuite_params *ts_params = &testsuite_params;
2042         struct crypto_unittest_params *ut_params = &unittest_params;
2043         const uint8_t *key = tdata->key.data;
2044         const uint8_t auth_len = tdata->digest.len;
2045         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2046         uint8_t auth_iv_len = tdata->auth_iv.len;
2047
2048         memcpy(cipher_auth_key, key, key_len);
2049
2050         /* Setup Authentication Parameters */
2051         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2052         ut_params->auth_xform.next = NULL;
2053
2054         ut_params->auth_xform.auth.op = auth_op;
2055         ut_params->auth_xform.auth.algo = auth_algo;
2056         ut_params->auth_xform.auth.key.length = key_len;
2057         /* Hash key = cipher key */
2058         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2059         ut_params->auth_xform.auth.digest_length = auth_len;
2060         /* Auth IV will be after cipher IV */
2061         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2062         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2063
2064         /* Setup Cipher Parameters */
2065         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2066         ut_params->cipher_xform.next = &ut_params->auth_xform;
2067
2068         ut_params->cipher_xform.cipher.algo = cipher_algo;
2069         ut_params->cipher_xform.cipher.op = cipher_op;
2070         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2071         ut_params->cipher_xform.cipher.key.length = key_len;
2072         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2073         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2074
2075
2076         TEST_HEXDUMP(stdout, "key:", key, key_len);
2077
2078         /* Create Crypto session*/
2079         ut_params->sess = rte_cryptodev_sym_session_create(
2080                         ts_params->session_mpool);
2081
2082         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2083                         &ut_params->cipher_xform, ts_params->session_mpool);
2084
2085         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2086         return 0;
2087 }
2088
2089 static int
2090 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2091                 const struct wireless_test_data *tdata)
2092 {
2093         return create_wireless_cipher_auth_session(dev_id,
2094                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2095                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2096                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2097 }
2098
2099 static int
2100 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2101                 enum rte_crypto_cipher_operation cipher_op,
2102                 enum rte_crypto_auth_operation auth_op,
2103                 enum rte_crypto_auth_algorithm auth_algo,
2104                 enum rte_crypto_cipher_algorithm cipher_algo,
2105                 const uint8_t *key, const uint8_t key_len,
2106                 uint8_t auth_iv_len, uint8_t auth_len,
2107                 uint8_t cipher_iv_len)
2108 {
2109         uint8_t auth_cipher_key[key_len];
2110
2111         struct crypto_testsuite_params *ts_params = &testsuite_params;
2112         struct crypto_unittest_params *ut_params = &unittest_params;
2113
2114         memcpy(auth_cipher_key, key, key_len);
2115
2116         /* Setup Authentication Parameters */
2117         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2118         ut_params->auth_xform.auth.op = auth_op;
2119         ut_params->auth_xform.next = &ut_params->cipher_xform;
2120         ut_params->auth_xform.auth.algo = auth_algo;
2121         ut_params->auth_xform.auth.key.length = key_len;
2122         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2123         ut_params->auth_xform.auth.digest_length = auth_len;
2124         /* Auth IV will be after cipher IV */
2125         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2126         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2127
2128         /* Setup Cipher Parameters */
2129         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2130         ut_params->cipher_xform.next = NULL;
2131         ut_params->cipher_xform.cipher.algo = cipher_algo;
2132         ut_params->cipher_xform.cipher.op = cipher_op;
2133         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2134         ut_params->cipher_xform.cipher.key.length = key_len;
2135         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2136         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2137
2138         TEST_HEXDUMP(stdout, "key:", key, key_len);
2139
2140         /* Create Crypto session*/
2141         ut_params->sess = rte_cryptodev_sym_session_create(
2142                         ts_params->session_mpool);
2143
2144         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2145                         &ut_params->auth_xform, ts_params->session_mpool);
2146
2147         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2148
2149         return 0;
2150 }
2151
2152 static int
2153 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2154                 unsigned int auth_tag_len,
2155                 const uint8_t *iv, unsigned int iv_len,
2156                 unsigned int data_pad_len,
2157                 enum rte_crypto_auth_operation op,
2158                 unsigned int auth_len, unsigned int auth_offset)
2159 {
2160         struct crypto_testsuite_params *ts_params = &testsuite_params;
2161
2162         struct crypto_unittest_params *ut_params = &unittest_params;
2163
2164         /* Generate Crypto op data structure */
2165         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2166                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2167         TEST_ASSERT_NOT_NULL(ut_params->op,
2168                 "Failed to allocate pktmbuf offload");
2169
2170         /* Set crypto operation data parameters */
2171         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2172
2173         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2174
2175         /* set crypto operation source mbuf */
2176         sym_op->m_src = ut_params->ibuf;
2177
2178         /* iv */
2179         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2180                         iv, iv_len);
2181         /* digest */
2182         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2183                                         ut_params->ibuf, auth_tag_len);
2184
2185         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2186                                 "no room to append auth tag");
2187         ut_params->digest = sym_op->auth.digest.data;
2188         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2189                         ut_params->ibuf, data_pad_len);
2190         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2191                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2192         else
2193                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2194
2195         TEST_HEXDUMP(stdout, "digest:",
2196                 sym_op->auth.digest.data,
2197                 auth_tag_len);
2198
2199         sym_op->auth.data.length = auth_len;
2200         sym_op->auth.data.offset = auth_offset;
2201
2202         return 0;
2203 }
2204
2205 static int
2206 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2207         enum rte_crypto_auth_operation op)
2208 {
2209         struct crypto_testsuite_params *ts_params = &testsuite_params;
2210         struct crypto_unittest_params *ut_params = &unittest_params;
2211
2212         const uint8_t *auth_tag = tdata->digest.data;
2213         const unsigned int auth_tag_len = tdata->digest.len;
2214         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2215         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2216
2217         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2218         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2219         const uint8_t *auth_iv = tdata->auth_iv.data;
2220         const uint8_t auth_iv_len = tdata->auth_iv.len;
2221         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2222         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2223
2224         /* Generate Crypto op data structure */
2225         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2226                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2227         TEST_ASSERT_NOT_NULL(ut_params->op,
2228                         "Failed to allocate pktmbuf offload");
2229         /* Set crypto operation data parameters */
2230         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2231
2232         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2233
2234         /* set crypto operation source mbuf */
2235         sym_op->m_src = ut_params->ibuf;
2236
2237         /* digest */
2238         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2239                         ut_params->ibuf, auth_tag_len);
2240
2241         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2242                         "no room to append auth tag");
2243         ut_params->digest = sym_op->auth.digest.data;
2244         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2245                         ut_params->ibuf, data_pad_len);
2246         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2247                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2248         else
2249                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2250
2251         TEST_HEXDUMP(stdout, "digest:",
2252                 sym_op->auth.digest.data,
2253                 auth_tag_len);
2254
2255         /* Copy cipher and auth IVs at the end of the crypto operation */
2256         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2257                                                 IV_OFFSET);
2258         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2259         iv_ptr += cipher_iv_len;
2260         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2261
2262         sym_op->cipher.data.length = cipher_len;
2263         sym_op->cipher.data.offset = 0;
2264         sym_op->auth.data.length = auth_len;
2265         sym_op->auth.data.offset = 0;
2266
2267         return 0;
2268 }
2269
2270 static int
2271 create_zuc_cipher_hash_generate_operation(
2272                 const struct wireless_test_data *tdata)
2273 {
2274         return create_wireless_cipher_hash_operation(tdata,
2275                 RTE_CRYPTO_AUTH_OP_GENERATE);
2276 }
2277
2278 static int
2279 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2280                 const unsigned auth_tag_len,
2281                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2282                 unsigned data_pad_len,
2283                 enum rte_crypto_auth_operation op,
2284                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2285                 const unsigned cipher_len, const unsigned cipher_offset,
2286                 const unsigned auth_len, const unsigned auth_offset)
2287 {
2288         struct crypto_testsuite_params *ts_params = &testsuite_params;
2289         struct crypto_unittest_params *ut_params = &unittest_params;
2290
2291         /* Generate Crypto op data structure */
2292         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2293                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2294         TEST_ASSERT_NOT_NULL(ut_params->op,
2295                         "Failed to allocate pktmbuf offload");
2296         /* Set crypto operation data parameters */
2297         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2298
2299         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2300
2301         /* set crypto operation source mbuf */
2302         sym_op->m_src = ut_params->ibuf;
2303
2304         /* digest */
2305         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2306                         ut_params->ibuf, auth_tag_len);
2307
2308         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2309                         "no room to append auth tag");
2310         ut_params->digest = sym_op->auth.digest.data;
2311         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2312                         ut_params->ibuf, data_pad_len);
2313         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2314                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2315         else
2316                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2317
2318         TEST_HEXDUMP(stdout, "digest:",
2319                 sym_op->auth.digest.data,
2320                 auth_tag_len);
2321
2322         /* Copy cipher and auth IVs at the end of the crypto operation */
2323         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2324                                                 IV_OFFSET);
2325         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2326         iv_ptr += cipher_iv_len;
2327         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2328
2329         sym_op->cipher.data.length = cipher_len;
2330         sym_op->cipher.data.offset = cipher_offset + auth_offset;
2331         sym_op->auth.data.length = auth_len;
2332         sym_op->auth.data.offset = auth_offset + cipher_offset;
2333
2334         return 0;
2335 }
2336
2337 static int
2338 create_wireless_algo_auth_cipher_operation(unsigned int auth_tag_len,
2339                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2340                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2341                 unsigned int data_pad_len,
2342                 unsigned int cipher_len, unsigned int cipher_offset,
2343                 unsigned int auth_len, unsigned int auth_offset)
2344 {
2345         struct crypto_testsuite_params *ts_params = &testsuite_params;
2346         struct crypto_unittest_params *ut_params = &unittest_params;
2347
2348         /* Generate Crypto op data structure */
2349         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2350                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2351         TEST_ASSERT_NOT_NULL(ut_params->op,
2352                         "Failed to allocate pktmbuf offload");
2353
2354         /* Set crypto operation data parameters */
2355         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2356
2357         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2358
2359         /* set crypto operation source mbuf */
2360         sym_op->m_src = ut_params->ibuf;
2361
2362         /* digest */
2363         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2364                         ut_params->ibuf, auth_tag_len);
2365
2366         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2367                         "no room to append auth tag");
2368
2369         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2370                         ut_params->ibuf, data_pad_len);
2371
2372         memset(sym_op->auth.digest.data, 0, auth_tag_len);
2373
2374         TEST_HEXDUMP(stdout, "digest:",
2375                         sym_op->auth.digest.data,
2376                         auth_tag_len);
2377
2378         /* Copy cipher and auth IVs at the end of the crypto operation */
2379         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2380                                                 IV_OFFSET);
2381         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2382         iv_ptr += cipher_iv_len;
2383         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2384
2385         sym_op->cipher.data.length = cipher_len;
2386         sym_op->cipher.data.offset = auth_offset + cipher_offset;
2387
2388         sym_op->auth.data.length = auth_len;
2389         sym_op->auth.data.offset = auth_offset + cipher_offset;
2390
2391         return 0;
2392 }
2393
2394 static int
2395 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2396 {
2397         struct crypto_testsuite_params *ts_params = &testsuite_params;
2398         struct crypto_unittest_params *ut_params = &unittest_params;
2399
2400         int retval;
2401         unsigned plaintext_pad_len;
2402         unsigned plaintext_len;
2403         uint8_t *plaintext;
2404
2405         /* Create SNOW 3G session */
2406         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2407                         tdata->key.data, tdata->key.len,
2408                         tdata->auth_iv.len, tdata->digest.len,
2409                         RTE_CRYPTO_AUTH_OP_GENERATE,
2410                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2411         if (retval < 0)
2412                 return retval;
2413
2414         /* alloc mbuf and set payload */
2415         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2416
2417         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2418         rte_pktmbuf_tailroom(ut_params->ibuf));
2419
2420         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2421         /* Append data which is padded to a multiple of */
2422         /* the algorithms block size */
2423         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2424         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2425                                 plaintext_pad_len);
2426         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2427
2428         /* Create SNOW 3G operation */
2429         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2430                         tdata->auth_iv.data, tdata->auth_iv.len,
2431                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2432                         tdata->validAuthLenInBits.len,
2433                         0);
2434         if (retval < 0)
2435                 return retval;
2436
2437         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2438                                 ut_params->op);
2439         ut_params->obuf = ut_params->op->sym->m_src;
2440         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2441         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2442                         + plaintext_pad_len;
2443
2444         /* Validate obuf */
2445         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2446         ut_params->digest,
2447         tdata->digest.data,
2448         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2449         "SNOW 3G Generated auth tag not as expected");
2450
2451         return 0;
2452 }
2453
2454 static int
2455 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2456 {
2457         struct crypto_testsuite_params *ts_params = &testsuite_params;
2458         struct crypto_unittest_params *ut_params = &unittest_params;
2459
2460         int retval;
2461         unsigned plaintext_pad_len;
2462         unsigned plaintext_len;
2463         uint8_t *plaintext;
2464
2465         /* Create SNOW 3G session */
2466         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2467                                 tdata->key.data, tdata->key.len,
2468                                 tdata->auth_iv.len, tdata->digest.len,
2469                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2470                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2471         if (retval < 0)
2472                 return retval;
2473         /* alloc mbuf and set payload */
2474         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2475
2476         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2477         rte_pktmbuf_tailroom(ut_params->ibuf));
2478
2479         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2480         /* Append data which is padded to a multiple of */
2481         /* the algorithms block size */
2482         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2483         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2484                                 plaintext_pad_len);
2485         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2486
2487         /* Create SNOW 3G operation */
2488         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2489                         tdata->digest.len,
2490                         tdata->auth_iv.data, tdata->auth_iv.len,
2491                         plaintext_pad_len,
2492                         RTE_CRYPTO_AUTH_OP_VERIFY,
2493                         tdata->validAuthLenInBits.len,
2494                         0);
2495         if (retval < 0)
2496                 return retval;
2497
2498         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2499                                 ut_params->op);
2500         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2501         ut_params->obuf = ut_params->op->sym->m_src;
2502         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2503                                 + plaintext_pad_len;
2504
2505         /* Validate obuf */
2506         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2507                 return 0;
2508         else
2509                 return -1;
2510
2511         return 0;
2512 }
2513
2514 static int
2515 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2516 {
2517         struct crypto_testsuite_params *ts_params = &testsuite_params;
2518         struct crypto_unittest_params *ut_params = &unittest_params;
2519
2520         int retval;
2521         unsigned plaintext_pad_len;
2522         unsigned plaintext_len;
2523         uint8_t *plaintext;
2524
2525         /* Create KASUMI session */
2526         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2527                         tdata->key.data, tdata->key.len,
2528                         tdata->auth_iv.len, tdata->digest.len,
2529                         RTE_CRYPTO_AUTH_OP_GENERATE,
2530                         RTE_CRYPTO_AUTH_KASUMI_F9);
2531         if (retval < 0)
2532                 return retval;
2533
2534         /* alloc mbuf and set payload */
2535         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2536
2537         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2538         rte_pktmbuf_tailroom(ut_params->ibuf));
2539
2540         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2541         /* Append data which is padded to a multiple of */
2542         /* the algorithms block size */
2543         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2544         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2545                                 plaintext_pad_len);
2546         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2547
2548         /* Create KASUMI operation */
2549         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2550                         tdata->auth_iv.data, tdata->auth_iv.len,
2551                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2552                         tdata->validAuthLenInBits.len,
2553                         0);
2554         if (retval < 0)
2555                 return retval;
2556
2557         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2558                                 ut_params->op);
2559         ut_params->obuf = ut_params->op->sym->m_src;
2560         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2561         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2562                         + plaintext_pad_len;
2563
2564         /* Validate obuf */
2565         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2566         ut_params->digest,
2567         tdata->digest.data,
2568         DIGEST_BYTE_LENGTH_KASUMI_F9,
2569         "KASUMI Generated auth tag not as expected");
2570
2571         return 0;
2572 }
2573
2574 static int
2575 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2576 {
2577         struct crypto_testsuite_params *ts_params = &testsuite_params;
2578         struct crypto_unittest_params *ut_params = &unittest_params;
2579
2580         int retval;
2581         unsigned plaintext_pad_len;
2582         unsigned plaintext_len;
2583         uint8_t *plaintext;
2584
2585         /* Create KASUMI session */
2586         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2587                                 tdata->key.data, tdata->key.len,
2588                                 tdata->auth_iv.len, tdata->digest.len,
2589                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2590                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2591         if (retval < 0)
2592                 return retval;
2593         /* alloc mbuf and set payload */
2594         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2595
2596         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2597         rte_pktmbuf_tailroom(ut_params->ibuf));
2598
2599         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2600         /* Append data which is padded to a multiple */
2601         /* of the algorithms block size */
2602         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2603         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2604                                 plaintext_pad_len);
2605         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2606
2607         /* Create KASUMI operation */
2608         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2609                         tdata->digest.len,
2610                         tdata->auth_iv.data, tdata->auth_iv.len,
2611                         plaintext_pad_len,
2612                         RTE_CRYPTO_AUTH_OP_VERIFY,
2613                         tdata->validAuthLenInBits.len,
2614                         0);
2615         if (retval < 0)
2616                 return retval;
2617
2618         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2619                                 ut_params->op);
2620         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2621         ut_params->obuf = ut_params->op->sym->m_src;
2622         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2623                                 + plaintext_pad_len;
2624
2625         /* Validate obuf */
2626         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2627                 return 0;
2628         else
2629                 return -1;
2630
2631         return 0;
2632 }
2633
2634 static int
2635 test_snow3g_hash_generate_test_case_1(void)
2636 {
2637         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2638 }
2639
2640 static int
2641 test_snow3g_hash_generate_test_case_2(void)
2642 {
2643         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2644 }
2645
2646 static int
2647 test_snow3g_hash_generate_test_case_3(void)
2648 {
2649         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2650 }
2651
2652 static int
2653 test_snow3g_hash_generate_test_case_4(void)
2654 {
2655         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2656 }
2657
2658 static int
2659 test_snow3g_hash_generate_test_case_5(void)
2660 {
2661         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2662 }
2663
2664 static int
2665 test_snow3g_hash_generate_test_case_6(void)
2666 {
2667         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2668 }
2669
2670 static int
2671 test_snow3g_hash_verify_test_case_1(void)
2672 {
2673         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2674
2675 }
2676
2677 static int
2678 test_snow3g_hash_verify_test_case_2(void)
2679 {
2680         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2681 }
2682
2683 static int
2684 test_snow3g_hash_verify_test_case_3(void)
2685 {
2686         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2687 }
2688
2689 static int
2690 test_snow3g_hash_verify_test_case_4(void)
2691 {
2692         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2693 }
2694
2695 static int
2696 test_snow3g_hash_verify_test_case_5(void)
2697 {
2698         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2699 }
2700
2701 static int
2702 test_snow3g_hash_verify_test_case_6(void)
2703 {
2704         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2705 }
2706
2707 static int
2708 test_kasumi_hash_generate_test_case_1(void)
2709 {
2710         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2711 }
2712
2713 static int
2714 test_kasumi_hash_generate_test_case_2(void)
2715 {
2716         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2717 }
2718
2719 static int
2720 test_kasumi_hash_generate_test_case_3(void)
2721 {
2722         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2723 }
2724
2725 static int
2726 test_kasumi_hash_generate_test_case_4(void)
2727 {
2728         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2729 }
2730
2731 static int
2732 test_kasumi_hash_generate_test_case_5(void)
2733 {
2734         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2735 }
2736
2737 static int
2738 test_kasumi_hash_generate_test_case_6(void)
2739 {
2740         return test_kasumi_authentication(&kasumi_hash_test_case_6);
2741 }
2742
2743 static int
2744 test_kasumi_hash_verify_test_case_1(void)
2745 {
2746         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2747 }
2748
2749 static int
2750 test_kasumi_hash_verify_test_case_2(void)
2751 {
2752         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2753 }
2754
2755 static int
2756 test_kasumi_hash_verify_test_case_3(void)
2757 {
2758         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2759 }
2760
2761 static int
2762 test_kasumi_hash_verify_test_case_4(void)
2763 {
2764         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2765 }
2766
2767 static int
2768 test_kasumi_hash_verify_test_case_5(void)
2769 {
2770         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2771 }
2772
2773 static int
2774 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2775 {
2776         struct crypto_testsuite_params *ts_params = &testsuite_params;
2777         struct crypto_unittest_params *ut_params = &unittest_params;
2778
2779         int retval;
2780         uint8_t *plaintext, *ciphertext;
2781         unsigned plaintext_pad_len;
2782         unsigned plaintext_len;
2783
2784         /* Create KASUMI session */
2785         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2786                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2787                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2788                                         tdata->key.data, tdata->key.len,
2789                                         tdata->cipher_iv.len);
2790         if (retval < 0)
2791                 return retval;
2792
2793         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2794
2795         /* Clear mbuf payload */
2796         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2797                rte_pktmbuf_tailroom(ut_params->ibuf));
2798
2799         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2800         /* Append data which is padded to a multiple */
2801         /* of the algorithms block size */
2802         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2803         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2804                                 plaintext_pad_len);
2805         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2806
2807         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2808
2809         /* Create KASUMI operation */
2810         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
2811                                         tdata->cipher_iv.len,
2812                                         tdata->plaintext.len,
2813                                         0);
2814         if (retval < 0)
2815                 return retval;
2816
2817         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2818                                                 ut_params->op);
2819         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2820
2821         ut_params->obuf = ut_params->op->sym->m_dst;
2822         if (ut_params->obuf)
2823                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
2824         else
2825                 ciphertext = plaintext;
2826
2827         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2828
2829         /* Validate obuf */
2830         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2831                 ciphertext,
2832                 tdata->ciphertext.data,
2833                 tdata->validCipherLenInBits.len,
2834                 "KASUMI Ciphertext data not as expected");
2835         return 0;
2836 }
2837
2838 static int
2839 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
2840 {
2841         struct crypto_testsuite_params *ts_params = &testsuite_params;
2842         struct crypto_unittest_params *ut_params = &unittest_params;
2843
2844         int retval;
2845
2846         unsigned int plaintext_pad_len;
2847         unsigned int plaintext_len;
2848
2849         uint8_t buffer[10000];
2850         const uint8_t *ciphertext;
2851
2852         struct rte_cryptodev_info dev_info;
2853
2854         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2855         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
2856                 printf("Device doesn't support scatter-gather. "
2857                                 "Test Skipped.\n");
2858                 return 0;
2859         }
2860
2861         /* Create KASUMI session */
2862         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2863                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2864                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2865                                         tdata->key.data, tdata->key.len,
2866                                         tdata->cipher_iv.len);
2867         if (retval < 0)
2868                 return retval;
2869
2870         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2871
2872
2873         /* Append data which is padded to a multiple */
2874         /* of the algorithms block size */
2875         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2876
2877         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
2878                         plaintext_pad_len, 10, 0);
2879
2880         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
2881
2882         /* Create KASUMI operation */
2883         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
2884                                         tdata->cipher_iv.len,
2885                                         tdata->plaintext.len,
2886                                         0);
2887         if (retval < 0)
2888                 return retval;
2889
2890         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2891                                                 ut_params->op);
2892         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2893
2894         ut_params->obuf = ut_params->op->sym->m_dst;
2895
2896         if (ut_params->obuf)
2897                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
2898                                 plaintext_len, buffer);
2899         else
2900                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
2901                                 plaintext_len, buffer);
2902
2903         /* Validate obuf */
2904         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2905
2906                 /* Validate obuf */
2907                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2908                         ciphertext,
2909                         tdata->ciphertext.data,
2910                         tdata->validCipherLenInBits.len,
2911                         "KASUMI Ciphertext data not as expected");
2912                 return 0;
2913 }
2914
2915 static int
2916 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2917 {
2918         struct crypto_testsuite_params *ts_params = &testsuite_params;
2919         struct crypto_unittest_params *ut_params = &unittest_params;
2920
2921         int retval;
2922         uint8_t *plaintext, *ciphertext;
2923         unsigned plaintext_pad_len;
2924         unsigned plaintext_len;
2925
2926         /* Create KASUMI session */
2927         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2928                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2929                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2930                                         tdata->key.data, tdata->key.len,
2931                                         tdata->cipher_iv.len);
2932         if (retval < 0)
2933                 return retval;
2934
2935         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2936         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2937
2938         /* Clear mbuf payload */
2939         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2940                rte_pktmbuf_tailroom(ut_params->ibuf));
2941
2942         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2943         /* Append data which is padded to a multiple */
2944         /* of the algorithms block size */
2945         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2946         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2947                                 plaintext_pad_len);
2948         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2949         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2950
2951         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2952
2953         /* Create KASUMI operation */
2954         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
2955                                         tdata->cipher_iv.len,
2956                                         tdata->plaintext.len,
2957                                         0);
2958         if (retval < 0)
2959                 return retval;
2960
2961         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2962                                                 ut_params->op);
2963         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2964
2965         ut_params->obuf = ut_params->op->sym->m_dst;
2966         if (ut_params->obuf)
2967                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
2968         else
2969                 ciphertext = plaintext;
2970
2971         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2972
2973         /* Validate obuf */
2974         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2975                 ciphertext,
2976                 tdata->ciphertext.data,
2977                 tdata->validCipherLenInBits.len,
2978                 "KASUMI Ciphertext data not as expected");
2979         return 0;
2980 }
2981
2982 static int
2983 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
2984 {
2985         struct crypto_testsuite_params *ts_params = &testsuite_params;
2986         struct crypto_unittest_params *ut_params = &unittest_params;
2987
2988         int retval;
2989         unsigned int plaintext_pad_len;
2990         unsigned int plaintext_len;
2991
2992         const uint8_t *ciphertext;
2993         uint8_t buffer[2048];
2994
2995         struct rte_cryptodev_info dev_info;
2996
2997         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2998         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
2999                 printf("Device doesn't support scatter-gather. "
3000                                 "Test Skipped.\n");
3001                 return 0;
3002         }
3003
3004         /* Create KASUMI session */
3005         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3006                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3007                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3008                                         tdata->key.data, tdata->key.len,
3009                                         tdata->cipher_iv.len);
3010         if (retval < 0)
3011                 return retval;
3012
3013         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3014         /* Append data which is padded to a multiple */
3015         /* of the algorithms block size */
3016         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3017
3018         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3019                         plaintext_pad_len, 10, 0);
3020         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3021                         plaintext_pad_len, 3, 0);
3022
3023         /* Append data which is padded to a multiple */
3024         /* of the algorithms block size */
3025         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3026
3027         /* Create KASUMI operation */
3028         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3029                                         tdata->cipher_iv.len,
3030                                         tdata->plaintext.len,
3031                                         0);
3032         if (retval < 0)
3033                 return retval;
3034
3035         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3036                                                 ut_params->op);
3037         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3038
3039         ut_params->obuf = ut_params->op->sym->m_dst;
3040         if (ut_params->obuf)
3041                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3042                                 plaintext_pad_len, buffer);
3043         else
3044                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3045                                 plaintext_pad_len, buffer);
3046
3047         /* Validate obuf */
3048         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3049                 ciphertext,
3050                 tdata->ciphertext.data,
3051                 tdata->validCipherLenInBits.len,
3052                 "KASUMI Ciphertext data not as expected");
3053         return 0;
3054 }
3055
3056
3057 static int
3058 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3059 {
3060         struct crypto_testsuite_params *ts_params = &testsuite_params;
3061         struct crypto_unittest_params *ut_params = &unittest_params;
3062
3063         int retval;
3064         uint8_t *ciphertext, *plaintext;
3065         unsigned ciphertext_pad_len;
3066         unsigned ciphertext_len;
3067
3068         /* Create KASUMI session */
3069         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3070                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3071                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3072                                         tdata->key.data, tdata->key.len,
3073                                         tdata->cipher_iv.len);
3074         if (retval < 0)
3075                 return retval;
3076
3077         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3078         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3079
3080         /* Clear mbuf payload */
3081         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3082                rte_pktmbuf_tailroom(ut_params->ibuf));
3083
3084         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3085         /* Append data which is padded to a multiple */
3086         /* of the algorithms block size */
3087         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3088         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3089                                 ciphertext_pad_len);
3090         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3091         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3092
3093         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3094
3095         /* Create KASUMI operation */
3096         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3097                                         tdata->cipher_iv.len,
3098                                         tdata->ciphertext.len,
3099                                         0);
3100         if (retval < 0)
3101                 return retval;
3102
3103         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3104                                                 ut_params->op);
3105         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3106
3107         ut_params->obuf = ut_params->op->sym->m_dst;
3108         if (ut_params->obuf)
3109                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3110         else
3111                 plaintext = ciphertext;
3112
3113         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3114
3115         /* Validate obuf */
3116         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3117                 plaintext,
3118                 tdata->plaintext.data,
3119                 tdata->validCipherLenInBits.len,
3120                 "KASUMI Plaintext data not as expected");
3121         return 0;
3122 }
3123
3124 static int
3125 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3126 {
3127         struct crypto_testsuite_params *ts_params = &testsuite_params;
3128         struct crypto_unittest_params *ut_params = &unittest_params;
3129
3130         int retval;
3131         uint8_t *ciphertext, *plaintext;
3132         unsigned ciphertext_pad_len;
3133         unsigned ciphertext_len;
3134
3135         /* Create KASUMI session */
3136         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3137                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3138                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3139                                         tdata->key.data, tdata->key.len,
3140                                         tdata->cipher_iv.len);
3141         if (retval < 0)
3142                 return retval;
3143
3144         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3145
3146         /* Clear mbuf payload */
3147         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3148                rte_pktmbuf_tailroom(ut_params->ibuf));
3149
3150         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3151         /* Append data which is padded to a multiple */
3152         /* of the algorithms block size */
3153         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3154         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3155                                 ciphertext_pad_len);
3156         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3157
3158         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3159
3160         /* Create KASUMI operation */
3161         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3162                                         tdata->cipher_iv.len,
3163                                         tdata->ciphertext.len,
3164                                         0);
3165         if (retval < 0)
3166                 return retval;
3167
3168         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3169                                                 ut_params->op);
3170         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3171
3172         ut_params->obuf = ut_params->op->sym->m_dst;
3173         if (ut_params->obuf)
3174                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3175         else
3176                 plaintext = ciphertext;
3177
3178         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3179
3180         /* Validate obuf */
3181         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3182                 plaintext,
3183                 tdata->plaintext.data,
3184                 tdata->validCipherLenInBits.len,
3185                 "KASUMI Plaintext data not as expected");
3186         return 0;
3187 }
3188
3189 static int
3190 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3191 {
3192         struct crypto_testsuite_params *ts_params = &testsuite_params;
3193         struct crypto_unittest_params *ut_params = &unittest_params;
3194
3195         int retval;
3196         uint8_t *plaintext, *ciphertext;
3197         unsigned plaintext_pad_len;
3198         unsigned plaintext_len;
3199
3200         /* Create SNOW 3G session */
3201         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3202                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3203                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3204                                         tdata->key.data, tdata->key.len,
3205                                         tdata->cipher_iv.len);
3206         if (retval < 0)
3207                 return retval;
3208
3209         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3210
3211         /* Clear mbuf payload */
3212         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3213                rte_pktmbuf_tailroom(ut_params->ibuf));
3214
3215         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3216         /* Append data which is padded to a multiple of */
3217         /* the algorithms block size */
3218         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3219         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3220                                 plaintext_pad_len);
3221         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3222
3223         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3224
3225         /* Create SNOW 3G operation */
3226         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3227                                         tdata->cipher_iv.len,
3228                                         tdata->validCipherLenInBits.len,
3229                                         0);
3230         if (retval < 0)
3231                 return retval;
3232
3233         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3234                                                 ut_params->op);
3235         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3236
3237         ut_params->obuf = ut_params->op->sym->m_dst;
3238         if (ut_params->obuf)
3239                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3240         else
3241                 ciphertext = plaintext;
3242
3243         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3244
3245         /* Validate obuf */
3246         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3247                 ciphertext,
3248                 tdata->ciphertext.data,
3249                 tdata->validDataLenInBits.len,
3250                 "SNOW 3G Ciphertext data not as expected");
3251         return 0;
3252 }
3253
3254
3255 static int
3256 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3257 {
3258         struct crypto_testsuite_params *ts_params = &testsuite_params;
3259         struct crypto_unittest_params *ut_params = &unittest_params;
3260         uint8_t *plaintext, *ciphertext;
3261
3262         int retval;
3263         unsigned plaintext_pad_len;
3264         unsigned plaintext_len;
3265
3266         /* Create SNOW 3G session */
3267         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3268                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3269                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3270                                         tdata->key.data, tdata->key.len,
3271                                         tdata->cipher_iv.len);
3272         if (retval < 0)
3273                 return retval;
3274
3275         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3276         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3277
3278         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3279                         "Failed to allocate input buffer in mempool");
3280         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3281                         "Failed to allocate output buffer in mempool");
3282
3283         /* Clear mbuf payload */
3284         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3285                rte_pktmbuf_tailroom(ut_params->ibuf));
3286
3287         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3288         /* Append data which is padded to a multiple of */
3289         /* the algorithms block size */
3290         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3291         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3292                                 plaintext_pad_len);
3293         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3294         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3295
3296         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3297
3298         /* Create SNOW 3G operation */
3299         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3300                                         tdata->cipher_iv.len,
3301                                         tdata->validCipherLenInBits.len,
3302                                         0);
3303         if (retval < 0)
3304                 return retval;
3305
3306         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3307                                                 ut_params->op);
3308         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3309
3310         ut_params->obuf = ut_params->op->sym->m_dst;
3311         if (ut_params->obuf)
3312                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3313         else
3314                 ciphertext = plaintext;
3315
3316         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3317
3318         /* Validate obuf */
3319         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3320                 ciphertext,
3321                 tdata->ciphertext.data,
3322                 tdata->validDataLenInBits.len,
3323                 "SNOW 3G Ciphertext data not as expected");
3324         return 0;
3325 }
3326
3327 static int
3328 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3329 {
3330         struct crypto_testsuite_params *ts_params = &testsuite_params;
3331         struct crypto_unittest_params *ut_params = &unittest_params;
3332
3333         int retval;
3334         unsigned int plaintext_pad_len;
3335         unsigned int plaintext_len;
3336         uint8_t buffer[10000];
3337         const uint8_t *ciphertext;
3338
3339         struct rte_cryptodev_info dev_info;
3340
3341         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3342         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3343                 printf("Device doesn't support scatter-gather. "
3344                                 "Test Skipped.\n");
3345                 return 0;
3346         }
3347
3348         /* Create SNOW 3G session */
3349         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3350                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3351                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3352                                         tdata->key.data, tdata->key.len,
3353                                         tdata->cipher_iv.len);
3354         if (retval < 0)
3355                 return retval;
3356
3357         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3358         /* Append data which is padded to a multiple of */
3359         /* the algorithms block size */
3360         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3361
3362         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3363                         plaintext_pad_len, 10, 0);
3364         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3365                         plaintext_pad_len, 3, 0);
3366
3367         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3368                         "Failed to allocate input buffer in mempool");
3369         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3370                         "Failed to allocate output buffer in mempool");
3371
3372         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3373
3374         /* Create SNOW 3G operation */
3375         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3376                                         tdata->cipher_iv.len,
3377                                         tdata->validCipherLenInBits.len,
3378                                         0);
3379         if (retval < 0)
3380                 return retval;
3381
3382         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3383                                                 ut_params->op);
3384         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3385
3386         ut_params->obuf = ut_params->op->sym->m_dst;
3387         if (ut_params->obuf)
3388                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3389                                 plaintext_len, buffer);
3390         else
3391                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3392                                 plaintext_len, buffer);
3393
3394         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3395
3396         /* Validate obuf */
3397         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3398                 ciphertext,
3399                 tdata->ciphertext.data,
3400                 tdata->validDataLenInBits.len,
3401                 "SNOW 3G Ciphertext data not as expected");
3402
3403         return 0;
3404 }
3405
3406 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3407 static void
3408 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3409 {
3410         uint8_t curr_byte, prev_byte;
3411         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3412         uint8_t lower_byte_mask = (1 << offset) - 1;
3413         unsigned i;
3414
3415         prev_byte = buffer[0];
3416         buffer[0] >>= offset;
3417
3418         for (i = 1; i < length_in_bytes; i++) {
3419                 curr_byte = buffer[i];
3420                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3421                                 (curr_byte >> offset);
3422                 prev_byte = curr_byte;
3423         }
3424 }
3425
3426 static int
3427 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3428 {
3429         struct crypto_testsuite_params *ts_params = &testsuite_params;
3430         struct crypto_unittest_params *ut_params = &unittest_params;
3431         uint8_t *plaintext, *ciphertext;
3432         int retval;
3433         uint32_t plaintext_len;
3434         uint32_t plaintext_pad_len;
3435         uint8_t extra_offset = 4;
3436         uint8_t *expected_ciphertext_shifted;
3437
3438         /* Create SNOW 3G session */
3439         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3440                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3441                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3442                                         tdata->key.data, tdata->key.len,
3443                                         tdata->cipher_iv.len);
3444         if (retval < 0)
3445                 return retval;
3446
3447         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3448         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3449
3450         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3451                         "Failed to allocate input buffer in mempool");
3452         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3453                         "Failed to allocate output buffer in mempool");
3454
3455         /* Clear mbuf payload */
3456         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3457                rte_pktmbuf_tailroom(ut_params->ibuf));
3458
3459         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3460         /*
3461          * Append data which is padded to a
3462          * multiple of the algorithms block size
3463          */
3464         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3465
3466         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3467                                                 plaintext_pad_len);
3468
3469         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3470
3471         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3472         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3473
3474 #ifdef RTE_APP_TEST_DEBUG
3475         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3476 #endif
3477         /* Create SNOW 3G operation */
3478         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3479                                         tdata->cipher_iv.len,
3480                                         tdata->validCipherLenInBits.len,
3481                                         extra_offset);
3482         if (retval < 0)
3483                 return retval;
3484
3485         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3486                                                 ut_params->op);
3487         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3488
3489         ut_params->obuf = ut_params->op->sym->m_dst;
3490         if (ut_params->obuf)
3491                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3492         else
3493                 ciphertext = plaintext;
3494
3495 #ifdef RTE_APP_TEST_DEBUG
3496         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3497 #endif
3498
3499         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
3500
3501         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3502                         "failed to reserve memory for ciphertext shifted\n");
3503
3504         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3505                         ceil_byte_length(tdata->ciphertext.len));
3506         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3507                         extra_offset);
3508         /* Validate obuf */
3509         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3510                 ciphertext,
3511                 expected_ciphertext_shifted,
3512                 tdata->validDataLenInBits.len,
3513                 extra_offset,
3514                 "SNOW 3G Ciphertext data not as expected");
3515         return 0;
3516 }
3517
3518 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3519 {
3520         struct crypto_testsuite_params *ts_params = &testsuite_params;
3521         struct crypto_unittest_params *ut_params = &unittest_params;
3522
3523         int retval;
3524
3525         uint8_t *plaintext, *ciphertext;
3526         unsigned ciphertext_pad_len;
3527         unsigned ciphertext_len;
3528
3529         /* Create SNOW 3G session */
3530         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3531                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3532                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3533                                         tdata->key.data, tdata->key.len,
3534                                         tdata->cipher_iv.len);
3535         if (retval < 0)
3536                 return retval;
3537
3538         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3539
3540         /* Clear mbuf payload */
3541         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3542                rte_pktmbuf_tailroom(ut_params->ibuf));
3543
3544         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3545         /* Append data which is padded to a multiple of */
3546         /* the algorithms block size */
3547         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3548         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3549                                 ciphertext_pad_len);
3550         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3551
3552         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3553
3554         /* Create SNOW 3G operation */
3555         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3556                                         tdata->cipher_iv.len,
3557                                         tdata->validCipherLenInBits.len,
3558                                         0);
3559         if (retval < 0)
3560                 return retval;
3561
3562         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3563                                                 ut_params->op);
3564         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3565         ut_params->obuf = ut_params->op->sym->m_dst;
3566         if (ut_params->obuf)
3567                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3568         else
3569                 plaintext = ciphertext;
3570
3571         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3572
3573         /* Validate obuf */
3574         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3575                                 tdata->plaintext.data,
3576                                 tdata->validDataLenInBits.len,
3577                                 "SNOW 3G Plaintext data not as expected");
3578         return 0;
3579 }
3580
3581 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3582 {
3583         struct crypto_testsuite_params *ts_params = &testsuite_params;
3584         struct crypto_unittest_params *ut_params = &unittest_params;
3585
3586         int retval;
3587
3588         uint8_t *plaintext, *ciphertext;
3589         unsigned ciphertext_pad_len;
3590         unsigned ciphertext_len;
3591
3592         /* Create SNOW 3G session */
3593         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3594                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3595                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3596                                         tdata->key.data, tdata->key.len,
3597                                         tdata->cipher_iv.len);
3598         if (retval < 0)
3599                 return retval;
3600
3601         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3602         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3603
3604         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3605                         "Failed to allocate input buffer");
3606         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3607                         "Failed to allocate output buffer");
3608
3609         /* Clear mbuf payload */
3610         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3611                rte_pktmbuf_tailroom(ut_params->ibuf));
3612
3613         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3614                        rte_pktmbuf_tailroom(ut_params->obuf));
3615
3616         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3617         /* Append data which is padded to a multiple of */
3618         /* the algorithms block size */
3619         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3620         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3621                                 ciphertext_pad_len);
3622         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3623         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3624
3625         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3626
3627         /* Create SNOW 3G operation */
3628         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3629                                         tdata->cipher_iv.len,
3630                                         tdata->validCipherLenInBits.len,
3631                                         0);
3632         if (retval < 0)
3633                 return retval;
3634
3635         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3636                                                 ut_params->op);
3637         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3638         ut_params->obuf = ut_params->op->sym->m_dst;
3639         if (ut_params->obuf)
3640                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3641         else
3642                 plaintext = ciphertext;
3643
3644         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3645
3646         /* Validate obuf */
3647         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3648                                 tdata->plaintext.data,
3649                                 tdata->validDataLenInBits.len,
3650                                 "SNOW 3G Plaintext data not as expected");
3651         return 0;
3652 }
3653
3654 static int
3655 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
3656 {
3657         struct crypto_testsuite_params *ts_params = &testsuite_params;
3658         struct crypto_unittest_params *ut_params = &unittest_params;
3659
3660         int retval;
3661
3662         uint8_t *plaintext, *ciphertext;
3663         unsigned int plaintext_pad_len;
3664         unsigned int plaintext_len;
3665
3666         struct rte_cryptodev_sym_capability_idx cap_idx;
3667
3668         /* Check if device supports ZUC EEA3 */
3669         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3670         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
3671
3672         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3673                         &cap_idx) == NULL)
3674                 return -ENOTSUP;
3675
3676         /* Check if device supports ZUC EIA3 */
3677         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3678         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
3679
3680         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3681                         &cap_idx) == NULL)
3682                 return -ENOTSUP;
3683
3684         /* Create ZUC session */
3685         retval = create_zuc_cipher_auth_encrypt_generate_session(
3686                         ts_params->valid_devs[0],
3687                         tdata);
3688         if (retval < 0)
3689                 return retval;
3690         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3691
3692         /* clear mbuf payload */
3693         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3694                         rte_pktmbuf_tailroom(ut_params->ibuf));
3695
3696         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3697         /* Append data which is padded to a multiple of */
3698         /* the algorithms block size */
3699         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3700         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3701                                 plaintext_pad_len);
3702         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3703
3704         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3705
3706         /* Create ZUC operation */
3707         retval = create_zuc_cipher_hash_generate_operation(tdata);
3708         if (retval < 0)
3709                 return retval;
3710
3711         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3712                         ut_params->op);
3713         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3714         ut_params->obuf = ut_params->op->sym->m_src;
3715         if (ut_params->obuf)
3716                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3717         else
3718                 ciphertext = plaintext;
3719
3720         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3721         /* Validate obuf */
3722         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3723                         ciphertext,
3724                         tdata->ciphertext.data,
3725                         tdata->validDataLenInBits.len,
3726                         "ZUC Ciphertext data not as expected");
3727
3728         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3729             + plaintext_pad_len;
3730
3731         /* Validate obuf */
3732         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3733                         ut_params->digest,
3734                         tdata->digest.data,
3735                         4,
3736                         "ZUC Generated auth tag not as expected");
3737         return 0;
3738 }
3739
3740 static int
3741 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3742 {
3743         struct crypto_testsuite_params *ts_params = &testsuite_params;
3744         struct crypto_unittest_params *ut_params = &unittest_params;
3745
3746         int retval;
3747
3748         uint8_t *plaintext, *ciphertext;
3749         unsigned plaintext_pad_len;
3750         unsigned plaintext_len;
3751
3752         /* Create SNOW 3G session */
3753         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3754                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3755                         RTE_CRYPTO_AUTH_OP_GENERATE,
3756                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3757                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3758                         tdata->key.data, tdata->key.len,
3759                         tdata->auth_iv.len, tdata->digest.len,
3760                         tdata->cipher_iv.len);
3761         if (retval < 0)
3762                 return retval;
3763         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3764
3765         /* clear mbuf payload */
3766         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3767                         rte_pktmbuf_tailroom(ut_params->ibuf));
3768
3769         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3770         /* Append data which is padded to a multiple of */
3771         /* the algorithms block size */
3772         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3773         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3774                                 plaintext_pad_len);
3775         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3776
3777         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3778
3779         /* Create SNOW 3G operation */
3780         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3781                         tdata->digest.len, tdata->auth_iv.data,
3782                         tdata->auth_iv.len,
3783                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3784                         tdata->cipher_iv.data, tdata->cipher_iv.len,
3785                         tdata->validCipherLenInBits.len,
3786                         0,
3787                         tdata->validAuthLenInBits.len,
3788                         0
3789                         );
3790         if (retval < 0)
3791                 return retval;
3792
3793         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3794                         ut_params->op);
3795         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3796         ut_params->obuf = ut_params->op->sym->m_src;
3797         if (ut_params->obuf)
3798                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3799         else
3800                 ciphertext = plaintext;
3801
3802         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3803         /* Validate obuf */
3804         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3805                         ciphertext,
3806                         tdata->ciphertext.data,
3807                         tdata->validDataLenInBits.len,
3808                         "SNOW 3G Ciphertext data not as expected");
3809
3810         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3811             + plaintext_pad_len;
3812
3813         /* Validate obuf */
3814         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3815                         ut_params->digest,
3816                         tdata->digest.data,
3817                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3818                         "SNOW 3G Generated auth tag not as expected");
3819         return 0;
3820 }
3821 static int
3822 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
3823 {
3824         struct crypto_testsuite_params *ts_params = &testsuite_params;
3825         struct crypto_unittest_params *ut_params = &unittest_params;
3826
3827         int retval;
3828
3829         uint8_t *plaintext, *ciphertext;
3830         unsigned plaintext_pad_len;
3831         unsigned plaintext_len;
3832
3833         /* Create SNOW 3G session */
3834         retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
3835                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3836                         RTE_CRYPTO_AUTH_OP_GENERATE,
3837                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3838                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3839                         tdata->key.data, tdata->key.len,
3840                         tdata->auth_iv.len, tdata->digest.len,
3841                         tdata->cipher_iv.len);
3842         if (retval < 0)
3843                 return retval;
3844
3845         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3846
3847         /* clear mbuf payload */
3848         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3849                         rte_pktmbuf_tailroom(ut_params->ibuf));
3850
3851         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3852         /* Append data which is padded to a multiple of */
3853         /* the algorithms block size */
3854         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3855         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3856                                 plaintext_pad_len);
3857         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3858
3859         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3860
3861         /* Create SNOW 3G operation */
3862         retval = create_wireless_algo_auth_cipher_operation(
3863                 tdata->digest.len,
3864                 tdata->cipher_iv.data, tdata->cipher_iv.len,
3865                 tdata->auth_iv.data, tdata->auth_iv.len,
3866                 plaintext_pad_len,
3867                 tdata->validCipherLenInBits.len,
3868                 0,
3869                 tdata->validAuthLenInBits.len,
3870                 0);
3871
3872         if (retval < 0)
3873                 return retval;
3874
3875         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3876                         ut_params->op);
3877         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3878         ut_params->obuf = ut_params->op->sym->m_src;
3879         if (ut_params->obuf)
3880                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3881         else
3882                 ciphertext = plaintext;
3883
3884         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3885                         + plaintext_pad_len;
3886         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3887
3888         /* Validate obuf */
3889         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3890                 ciphertext,
3891                 tdata->ciphertext.data,
3892                 tdata->validDataLenInBits.len,
3893                 "SNOW 3G Ciphertext data not as expected");
3894
3895         /* Validate obuf */
3896         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3897                 ut_params->digest,
3898                 tdata->digest.data,
3899                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3900                 "SNOW 3G Generated auth tag not as expected");
3901         return 0;
3902 }
3903
3904 static int
3905 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
3906 {
3907         struct crypto_testsuite_params *ts_params = &testsuite_params;
3908         struct crypto_unittest_params *ut_params = &unittest_params;
3909
3910         int retval;
3911
3912         uint8_t *plaintext, *ciphertext;
3913         unsigned plaintext_pad_len;
3914         unsigned plaintext_len;
3915
3916         /* Create KASUMI session */
3917         retval = create_wireless_algo_auth_cipher_session(
3918                         ts_params->valid_devs[0],
3919                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3920                         RTE_CRYPTO_AUTH_OP_GENERATE,
3921                         RTE_CRYPTO_AUTH_KASUMI_F9,
3922                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3923                         tdata->key.data, tdata->key.len,
3924                         tdata->auth_iv.len, tdata->digest.len,
3925                         tdata->cipher_iv.len);
3926         if (retval < 0)
3927                 return retval;
3928         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3929
3930         /* clear mbuf payload */
3931         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3932                         rte_pktmbuf_tailroom(ut_params->ibuf));
3933
3934         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3935         /* Append data which is padded to a multiple of */
3936         /* the algorithms block size */
3937         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3938         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3939                                 plaintext_pad_len);
3940         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3941
3942         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3943
3944         /* Create KASUMI operation */
3945         retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
3946                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
3947                                 tdata->auth_iv.data, tdata->auth_iv.len,
3948                                 plaintext_pad_len,
3949                                 tdata->validCipherLenInBits.len,
3950                                 0,
3951                                 tdata->validAuthLenInBits.len,
3952                                 0
3953                                 );
3954
3955         if (retval < 0)
3956                 return retval;
3957
3958         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3959                         ut_params->op);
3960         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3961         ut_params->obuf = ut_params->op->sym->m_src;
3962         if (ut_params->obuf)
3963                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3964         else
3965                 ciphertext = plaintext;
3966
3967         /* Validate obuf */
3968         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3969                         ciphertext,
3970                         tdata->ciphertext.data,
3971                         tdata->validCipherLenInBits.len,
3972                         "KASUMI Ciphertext data not as expected");
3973         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3974             + plaintext_pad_len;
3975
3976         /* Validate obuf */
3977         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3978                         ut_params->digest,
3979                         tdata->digest.data,
3980                         DIGEST_BYTE_LENGTH_KASUMI_F9,
3981                         "KASUMI Generated auth tag not as expected");
3982         return 0;
3983 }
3984
3985 static int
3986 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
3987 {
3988         struct crypto_testsuite_params *ts_params = &testsuite_params;
3989         struct crypto_unittest_params *ut_params = &unittest_params;
3990
3991         int retval;
3992
3993         uint8_t *plaintext, *ciphertext;
3994         unsigned plaintext_pad_len;
3995         unsigned plaintext_len;
3996
3997         /* Create KASUMI session */
3998         retval = create_wireless_algo_cipher_auth_session(
3999                         ts_params->valid_devs[0],
4000                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4001                         RTE_CRYPTO_AUTH_OP_GENERATE,
4002                         RTE_CRYPTO_AUTH_KASUMI_F9,
4003                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4004                         tdata->key.data, tdata->key.len,
4005                         tdata->auth_iv.len, tdata->digest.len,
4006                         tdata->cipher_iv.len);
4007         if (retval < 0)
4008                 return retval;
4009
4010         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4011
4012         /* clear mbuf payload */
4013         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4014                         rte_pktmbuf_tailroom(ut_params->ibuf));
4015
4016         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4017         /* Append data which is padded to a multiple of */
4018         /* the algorithms block size */
4019         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4020         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4021                                 plaintext_pad_len);
4022         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4023
4024         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
4025
4026         /* Create KASUMI operation */
4027         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4028                                 tdata->digest.len, tdata->auth_iv.data,
4029                                 tdata->auth_iv.len,
4030                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4031                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4032                                 tdata->validCipherLenInBits.len,
4033                                 0,
4034                                 tdata->validAuthLenInBits.len,
4035                                 0
4036                                 );
4037         if (retval < 0)
4038                 return retval;
4039
4040         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4041                         ut_params->op);
4042         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4043         ut_params->obuf = ut_params->op->sym->m_src;
4044         if (ut_params->obuf)
4045                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4046         else
4047                 ciphertext = plaintext;
4048
4049         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4050                         + plaintext_pad_len;
4051
4052         /* Validate obuf */
4053         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4054                 ciphertext,
4055                 tdata->ciphertext.data,
4056                 tdata->validCipherLenInBits.len,
4057                 "KASUMI Ciphertext data not as expected");
4058
4059         /* Validate obuf */
4060         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4061                 ut_params->digest,
4062                 tdata->digest.data,
4063                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4064                 "KASUMI Generated auth tag not as expected");
4065         return 0;
4066 }
4067
4068 static int
4069 test_zuc_encryption(const struct wireless_test_data *tdata)
4070 {
4071         struct crypto_testsuite_params *ts_params = &testsuite_params;
4072         struct crypto_unittest_params *ut_params = &unittest_params;
4073
4074         int retval;
4075         uint8_t *plaintext, *ciphertext;
4076         unsigned plaintext_pad_len;
4077         unsigned plaintext_len;
4078
4079         struct rte_cryptodev_sym_capability_idx cap_idx;
4080
4081         /* Check if device supports ZUC EEA3 */
4082         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4083         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4084
4085         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4086                         &cap_idx) == NULL)
4087                 return -ENOTSUP;
4088
4089         /* Create ZUC session */
4090         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4091                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4092                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4093                                         tdata->key.data, tdata->key.len,
4094                                         tdata->cipher_iv.len);
4095         if (retval < 0)
4096                 return retval;
4097
4098         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4099
4100         /* Clear mbuf payload */
4101         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4102                rte_pktmbuf_tailroom(ut_params->ibuf));
4103
4104         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4105         /* Append data which is padded to a multiple */
4106         /* of the algorithms block size */
4107         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4108         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4109                                 plaintext_pad_len);
4110         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4111
4112         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
4113
4114         /* Create ZUC operation */
4115         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4116                                         tdata->cipher_iv.len,
4117                                         tdata->plaintext.len,
4118                                         0);
4119         if (retval < 0)
4120                 return retval;
4121
4122         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4123                                                 ut_params->op);
4124         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4125
4126         ut_params->obuf = ut_params->op->sym->m_dst;
4127         if (ut_params->obuf)
4128                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4129         else
4130                 ciphertext = plaintext;
4131
4132         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
4133
4134         /* Validate obuf */
4135         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4136                 ciphertext,
4137                 tdata->ciphertext.data,
4138                 tdata->validCipherLenInBits.len,
4139                 "ZUC Ciphertext data not as expected");
4140         return 0;
4141 }
4142
4143 static int
4144 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
4145 {
4146         struct crypto_testsuite_params *ts_params = &testsuite_params;
4147         struct crypto_unittest_params *ut_params = &unittest_params;
4148
4149         int retval;
4150
4151         unsigned int plaintext_pad_len;
4152         unsigned int plaintext_len;
4153         const uint8_t *ciphertext;
4154         uint8_t ciphertext_buffer[2048];
4155         struct rte_cryptodev_info dev_info;
4156
4157         struct rte_cryptodev_sym_capability_idx cap_idx;
4158
4159         /* Check if device supports ZUC EEA3 */
4160         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4161         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4162
4163         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4164                         &cap_idx) == NULL)
4165                 return -ENOTSUP;
4166
4167         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4168         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
4169                 printf("Device doesn't support scatter-gather. "
4170                                 "Test Skipped.\n");
4171                 return -ENOTSUP;
4172         }
4173
4174         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4175
4176         /* Append data which is padded to a multiple */
4177         /* of the algorithms block size */
4178         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4179
4180         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4181                         plaintext_pad_len, 10, 0);
4182
4183         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4184                         tdata->plaintext.data);
4185
4186         /* Create ZUC session */
4187         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4188                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4189                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4190                         tdata->key.data, tdata->key.len,
4191                         tdata->cipher_iv.len);
4192         if (retval < 0)
4193                 return retval;
4194
4195         /* Clear mbuf payload */
4196
4197         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4198
4199         /* Create ZUC operation */
4200         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4201                         tdata->cipher_iv.len, tdata->plaintext.len,
4202                         0);
4203         if (retval < 0)
4204                 return retval;
4205
4206         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4207                                                 ut_params->op);
4208         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4209
4210         ut_params->obuf = ut_params->op->sym->m_dst;
4211         if (ut_params->obuf)
4212                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
4213                         0, plaintext_len, ciphertext_buffer);
4214         else
4215                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4216                         0, plaintext_len, ciphertext_buffer);
4217
4218         /* Validate obuf */
4219         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
4220
4221         /* Validate obuf */
4222         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4223                 ciphertext,
4224                 tdata->ciphertext.data,
4225                 tdata->validCipherLenInBits.len,
4226                 "ZUC Ciphertext data not as expected");
4227
4228         return 0;
4229 }
4230
4231 static int
4232 test_zuc_authentication(const struct wireless_test_data *tdata)
4233 {
4234         struct crypto_testsuite_params *ts_params = &testsuite_params;
4235         struct crypto_unittest_params *ut_params = &unittest_params;
4236
4237         int retval;
4238         unsigned plaintext_pad_len;
4239         unsigned plaintext_len;
4240         uint8_t *plaintext;
4241
4242         struct rte_cryptodev_sym_capability_idx cap_idx;
4243
4244         /* Check if device supports ZUC EIA3 */
4245         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4246         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4247
4248         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4249                         &cap_idx) == NULL)
4250                 return -ENOTSUP;
4251
4252         /* Create ZUC session */
4253         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
4254                         tdata->key.data, tdata->key.len,
4255                         tdata->auth_iv.len, tdata->digest.len,
4256                         RTE_CRYPTO_AUTH_OP_GENERATE,
4257                         RTE_CRYPTO_AUTH_ZUC_EIA3);
4258         if (retval < 0)
4259                 return retval;
4260
4261         /* alloc mbuf and set payload */
4262         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4263
4264         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4265         rte_pktmbuf_tailroom(ut_params->ibuf));
4266
4267         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4268         /* Append data which is padded to a multiple of */
4269         /* the algorithms block size */
4270         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4271         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4272                                 plaintext_pad_len);
4273         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4274
4275         /* Create ZUC operation */
4276         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
4277                         tdata->auth_iv.data, tdata->auth_iv.len,
4278                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4279                         tdata->validAuthLenInBits.len,
4280                         0);
4281         if (retval < 0)
4282                 return retval;
4283
4284         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4285                                 ut_params->op);
4286         ut_params->obuf = ut_params->op->sym->m_src;
4287         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4288         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4289                         + plaintext_pad_len;
4290
4291         /* Validate obuf */
4292         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4293         ut_params->digest,
4294         tdata->digest.data,
4295         DIGEST_BYTE_LENGTH_KASUMI_F9,
4296         "ZUC Generated auth tag not as expected");
4297
4298         return 0;
4299 }
4300
4301 static int
4302 test_kasumi_encryption_test_case_1(void)
4303 {
4304         return test_kasumi_encryption(&kasumi_test_case_1);
4305 }
4306
4307 static int
4308 test_kasumi_encryption_test_case_1_sgl(void)
4309 {
4310         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
4311 }
4312
4313 static int
4314 test_kasumi_encryption_test_case_1_oop(void)
4315 {
4316         return test_kasumi_encryption_oop(&kasumi_test_case_1);
4317 }
4318
4319 static int
4320 test_kasumi_encryption_test_case_1_oop_sgl(void)
4321 {
4322         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
4323 }
4324
4325 static int
4326 test_kasumi_encryption_test_case_2(void)
4327 {
4328         return test_kasumi_encryption(&kasumi_test_case_2);
4329 }
4330
4331 static int
4332 test_kasumi_encryption_test_case_3(void)
4333 {
4334         return test_kasumi_encryption(&kasumi_test_case_3);
4335 }
4336
4337 static int
4338 test_kasumi_encryption_test_case_4(void)
4339 {
4340         return test_kasumi_encryption(&kasumi_test_case_4);
4341 }
4342
4343 static int
4344 test_kasumi_encryption_test_case_5(void)
4345 {
4346         return test_kasumi_encryption(&kasumi_test_case_5);
4347 }
4348
4349 static int
4350 test_kasumi_decryption_test_case_1(void)
4351 {
4352         return test_kasumi_decryption(&kasumi_test_case_1);
4353 }
4354
4355 static int
4356 test_kasumi_decryption_test_case_1_oop(void)
4357 {
4358         return test_kasumi_decryption_oop(&kasumi_test_case_1);
4359 }
4360
4361 static int
4362 test_kasumi_decryption_test_case_2(void)
4363 {
4364         return test_kasumi_decryption(&kasumi_test_case_2);
4365 }
4366
4367 static int
4368 test_kasumi_decryption_test_case_3(void)
4369 {
4370         return test_kasumi_decryption(&kasumi_test_case_3);
4371 }
4372
4373 static int
4374 test_kasumi_decryption_test_case_4(void)
4375 {
4376         return test_kasumi_decryption(&kasumi_test_case_4);
4377 }
4378
4379 static int
4380 test_kasumi_decryption_test_case_5(void)
4381 {
4382         return test_kasumi_decryption(&kasumi_test_case_5);
4383 }
4384 static int
4385 test_snow3g_encryption_test_case_1(void)
4386 {
4387         return test_snow3g_encryption(&snow3g_test_case_1);
4388 }
4389
4390 static int
4391 test_snow3g_encryption_test_case_1_oop(void)
4392 {
4393         return test_snow3g_encryption_oop(&snow3g_test_case_1);
4394 }
4395
4396 static int
4397 test_snow3g_encryption_test_case_1_oop_sgl(void)
4398 {
4399         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
4400 }
4401
4402
4403 static int
4404 test_snow3g_encryption_test_case_1_offset_oop(void)
4405 {
4406         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
4407 }
4408
4409 static int
4410 test_snow3g_encryption_test_case_2(void)
4411 {
4412         return test_snow3g_encryption(&snow3g_test_case_2);
4413 }
4414
4415 static int
4416 test_snow3g_encryption_test_case_3(void)
4417 {
4418         return test_snow3g_encryption(&snow3g_test_case_3);
4419 }
4420
4421 static int
4422 test_snow3g_encryption_test_case_4(void)
4423 {
4424         return test_snow3g_encryption(&snow3g_test_case_4);
4425 }
4426
4427 static int
4428 test_snow3g_encryption_test_case_5(void)
4429 {
4430         return test_snow3g_encryption(&snow3g_test_case_5);
4431 }
4432
4433 static int
4434 test_snow3g_decryption_test_case_1(void)
4435 {
4436         return test_snow3g_decryption(&snow3g_test_case_1);
4437 }
4438
4439 static int
4440 test_snow3g_decryption_test_case_1_oop(void)
4441 {
4442         return test_snow3g_decryption_oop(&snow3g_test_case_1);
4443 }
4444
4445 static int
4446 test_snow3g_decryption_test_case_2(void)
4447 {
4448         return test_snow3g_decryption(&snow3g_test_case_2);
4449 }
4450
4451 static int
4452 test_snow3g_decryption_test_case_3(void)
4453 {
4454         return test_snow3g_decryption(&snow3g_test_case_3);
4455 }
4456
4457 static int
4458 test_snow3g_decryption_test_case_4(void)
4459 {
4460         return test_snow3g_decryption(&snow3g_test_case_4);
4461 }
4462
4463 static int
4464 test_snow3g_decryption_test_case_5(void)
4465 {
4466         return test_snow3g_decryption(&snow3g_test_case_5);
4467 }
4468 static int
4469 test_snow3g_cipher_auth_test_case_1(void)
4470 {
4471         return test_snow3g_cipher_auth(&snow3g_test_case_3);
4472 }
4473
4474 static int
4475 test_snow3g_auth_cipher_test_case_1(void)
4476 {
4477         return test_snow3g_auth_cipher(&snow3g_test_case_6);
4478 }
4479
4480 static int
4481 test_kasumi_auth_cipher_test_case_1(void)
4482 {
4483         return test_kasumi_auth_cipher(&kasumi_test_case_3);
4484 }
4485
4486 static int
4487 test_kasumi_cipher_auth_test_case_1(void)
4488 {
4489         return test_kasumi_cipher_auth(&kasumi_test_case_6);
4490 }
4491
4492 static int
4493 test_zuc_encryption_test_case_1(void)
4494 {
4495         return test_zuc_encryption(&zuc_test_case_cipher_193b);
4496 }
4497
4498 static int
4499 test_zuc_encryption_test_case_2(void)
4500 {
4501         return test_zuc_encryption(&zuc_test_case_cipher_800b);
4502 }
4503
4504 static int
4505 test_zuc_encryption_test_case_3(void)
4506 {
4507         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
4508 }
4509
4510 static int
4511 test_zuc_encryption_test_case_4(void)
4512 {
4513         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
4514 }
4515
4516 static int
4517 test_zuc_encryption_test_case_5(void)
4518 {
4519         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
4520 }
4521
4522 static int
4523 test_zuc_encryption_test_case_6_sgl(void)
4524 {
4525         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
4526 }
4527
4528 static int
4529 test_zuc_hash_generate_test_case_1(void)
4530 {
4531         return test_zuc_authentication(&zuc_test_case_auth_1b);
4532 }
4533
4534 static int
4535 test_zuc_hash_generate_test_case_2(void)
4536 {
4537         return test_zuc_authentication(&zuc_test_case_auth_90b);
4538 }
4539
4540 static int
4541 test_zuc_hash_generate_test_case_3(void)
4542 {
4543         return test_zuc_authentication(&zuc_test_case_auth_577b);
4544 }
4545
4546 static int
4547 test_zuc_hash_generate_test_case_4(void)
4548 {
4549         return test_zuc_authentication(&zuc_test_case_auth_2079b);
4550 }
4551
4552 static int
4553 test_zuc_hash_generate_test_case_5(void)
4554 {
4555         return test_zuc_authentication(&zuc_test_auth_5670b);
4556 }
4557
4558 static int
4559 test_zuc_hash_generate_test_case_6(void)
4560 {
4561         return test_zuc_authentication(&zuc_test_case_auth_128b);
4562 }
4563
4564 static int
4565 test_zuc_hash_generate_test_case_7(void)
4566 {
4567         return test_zuc_authentication(&zuc_test_case_auth_2080b);
4568 }
4569
4570 static int
4571 test_zuc_hash_generate_test_case_8(void)
4572 {
4573         return test_zuc_authentication(&zuc_test_case_auth_584b);
4574 }
4575
4576 static int
4577 test_zuc_cipher_auth_test_case_1(void)
4578 {
4579         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
4580 }
4581
4582 static int
4583 test_zuc_cipher_auth_test_case_2(void)
4584 {
4585         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
4586 }
4587
4588 static int
4589 test_3DES_chain_qat_all(void)
4590 {
4591         struct crypto_testsuite_params *ts_params = &testsuite_params;
4592         int status;
4593
4594         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4595                 ts_params->op_mpool,
4596                 ts_params->session_mpool,
4597                 ts_params->valid_devs[0],
4598                 rte_cryptodev_driver_id_get(
4599                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
4600                 BLKCIPHER_3DES_CHAIN_TYPE);
4601
4602         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4603
4604         return TEST_SUCCESS;
4605 }
4606
4607 static int
4608 test_DES_cipheronly_qat_all(void)
4609 {
4610         struct crypto_testsuite_params *ts_params = &testsuite_params;
4611         int status;
4612
4613         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4614                 ts_params->op_mpool,
4615                 ts_params->session_mpool,
4616                 ts_params->valid_devs[0],
4617                 rte_cryptodev_driver_id_get(
4618                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
4619                 BLKCIPHER_DES_CIPHERONLY_TYPE);
4620
4621         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4622
4623         return TEST_SUCCESS;
4624 }
4625
4626 static int
4627 test_DES_docsis_openssl_all(void)
4628 {
4629         struct crypto_testsuite_params *ts_params = &testsuite_params;
4630         int status;
4631
4632         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4633                 ts_params->op_mpool,
4634                 ts_params->session_mpool,
4635                 ts_params->valid_devs[0],
4636                 rte_cryptodev_driver_id_get(
4637                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
4638                 BLKCIPHER_DES_DOCSIS_TYPE);
4639
4640         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4641
4642         return TEST_SUCCESS;
4643 }
4644
4645 static int
4646 test_3DES_chain_dpaa2_sec_all(void)
4647 {
4648         struct crypto_testsuite_params *ts_params = &testsuite_params;
4649         int status;
4650
4651         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4652                 ts_params->op_mpool,
4653                 ts_params->session_mpool,
4654                 ts_params->valid_devs[0],
4655                 rte_cryptodev_driver_id_get(
4656                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
4657                 BLKCIPHER_3DES_CHAIN_TYPE);
4658
4659         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4660
4661         return TEST_SUCCESS;
4662 }
4663
4664 static int
4665 test_3DES_cipheronly_dpaa2_sec_all(void)
4666 {
4667         struct crypto_testsuite_params *ts_params = &testsuite_params;
4668         int status;
4669
4670         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4671                 ts_params->op_mpool,
4672                 ts_params->session_mpool,
4673                 ts_params->valid_devs[0],
4674                 rte_cryptodev_driver_id_get(
4675                 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)),
4676                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4677
4678         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4679
4680         return TEST_SUCCESS;
4681 }
4682
4683 static int
4684 test_3DES_cipheronly_qat_all(void)
4685 {
4686         struct crypto_testsuite_params *ts_params = &testsuite_params;
4687         int status;
4688
4689         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4690                 ts_params->op_mpool,
4691                 ts_params->session_mpool,
4692                 ts_params->valid_devs[0],
4693                 rte_cryptodev_driver_id_get(
4694                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)),
4695                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4696
4697         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4698
4699         return TEST_SUCCESS;
4700 }
4701
4702 static int
4703 test_3DES_chain_openssl_all(void)
4704 {
4705         struct crypto_testsuite_params *ts_params = &testsuite_params;
4706         int status;
4707
4708         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4709                 ts_params->op_mpool,
4710                 ts_params->session_mpool,
4711                 ts_params->valid_devs[0],
4712                 rte_cryptodev_driver_id_get(
4713                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
4714                 BLKCIPHER_3DES_CHAIN_TYPE);
4715
4716         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4717
4718         return TEST_SUCCESS;
4719 }
4720
4721 static int
4722 test_3DES_cipheronly_openssl_all(void)
4723 {
4724         struct crypto_testsuite_params *ts_params = &testsuite_params;
4725         int status;
4726
4727         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4728                 ts_params->op_mpool,
4729                 ts_params->session_mpool,
4730                 ts_params->valid_devs[0],
4731                 rte_cryptodev_driver_id_get(
4732                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
4733                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4734
4735         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4736
4737         return TEST_SUCCESS;
4738 }
4739
4740 /* ***** AES-GCM Tests ***** */
4741
4742 static int
4743 create_gcm_session(uint8_t dev_id, enum rte_crypto_aead_operation op,
4744                 const uint8_t *key, const uint8_t key_len,
4745                 const uint16_t aad_len, const uint8_t auth_len,
4746                 uint8_t iv_len)
4747 {
4748         uint8_t aead_key[key_len];
4749
4750         struct crypto_testsuite_params *ts_params = &testsuite_params;
4751         struct crypto_unittest_params *ut_params = &unittest_params;
4752
4753         memcpy(aead_key, key, key_len);
4754
4755         /* Setup AEAD Parameters */
4756         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
4757         ut_params->aead_xform.next = NULL;
4758         ut_params->aead_xform.aead.algo = RTE_CRYPTO_AEAD_AES_GCM;
4759         ut_params->aead_xform.aead.op = op;
4760         ut_params->aead_xform.aead.key.data = aead_key;
4761         ut_params->aead_xform.aead.key.length = key_len;
4762         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
4763         ut_params->aead_xform.aead.iv.length = iv_len;
4764         ut_params->aead_xform.aead.digest_length = auth_len;
4765         ut_params->aead_xform.aead.add_auth_data_length = aad_len;
4766
4767         TEST_HEXDUMP(stdout, "key:", key, key_len);
4768
4769         /* Create Crypto session*/
4770         ut_params->sess = rte_cryptodev_sym_session_create(
4771                         ts_params->session_mpool);
4772
4773         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
4774                         &ut_params->aead_xform, ts_params->session_mpool);
4775
4776         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4777
4778         return 0;
4779 }
4780
4781 static int
4782 create_gcm_xforms(struct rte_crypto_op *op,
4783                 enum rte_crypto_aead_operation aead_op,
4784                 uint8_t *key, const uint8_t key_len,
4785                 const uint8_t aad_len, const uint8_t auth_len,
4786                 uint8_t iv_len)
4787 {
4788         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
4789                         "failed to allocate space for crypto transform");
4790
4791         struct rte_crypto_sym_op *sym_op = op->sym;
4792
4793         /* Setup AEAD Parameters */
4794         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
4795         sym_op->xform->next = NULL;
4796         sym_op->xform->aead.algo = RTE_CRYPTO_AEAD_AES_GCM;
4797         sym_op->xform->aead.op = aead_op;
4798         sym_op->xform->aead.key.data = key;
4799         sym_op->xform->aead.key.length = key_len;
4800         sym_op->xform->aead.iv.offset = IV_OFFSET;
4801         sym_op->xform->aead.iv.length = iv_len;
4802         sym_op->xform->aead.digest_length = auth_len;
4803         sym_op->xform->aead.add_auth_data_length = aad_len;
4804
4805         TEST_HEXDUMP(stdout, "key:", key, key_len);
4806
4807         return 0;
4808 }
4809
4810 static int
4811 create_gcm_operation(enum rte_crypto_aead_operation op,
4812                 const struct gcm_test_data *tdata)
4813 {
4814         struct crypto_testsuite_params *ts_params = &testsuite_params;
4815         struct crypto_unittest_params *ut_params = &unittest_params;
4816
4817         uint8_t *plaintext, *ciphertext;
4818         unsigned int aad_pad_len, plaintext_pad_len;
4819
4820         /* Generate Crypto op data structure */
4821         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4822                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4823         TEST_ASSERT_NOT_NULL(ut_params->op,
4824                         "Failed to allocate symmetric crypto operation struct");
4825
4826         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4827
4828         /* Append aad data */
4829         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4830         sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4831                         aad_pad_len);
4832         TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
4833                         "no room to append aad");
4834
4835         sym_op->aead.aad.phys_addr =
4836                         rte_pktmbuf_mtophys(ut_params->ibuf);
4837         memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
4838         TEST_HEXDUMP(stdout, "aad:", sym_op->aead.aad.data,
4839                 tdata->aad.len);
4840
4841         /* Append IV at the end of the crypto operation*/
4842         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
4843                         uint8_t *, IV_OFFSET);
4844
4845         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
4846         TEST_HEXDUMP(stdout, "iv:", iv_ptr,
4847                 tdata->iv.len);
4848
4849         /* Append plaintext/ciphertext */
4850         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
4851                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4852                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4853                                 plaintext_pad_len);
4854                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
4855
4856                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4857                 TEST_HEXDUMP(stdout, "plaintext:", plaintext,
4858                                 tdata->plaintext.len);
4859
4860                 if (ut_params->obuf) {
4861                         ciphertext = (uint8_t *)rte_pktmbuf_append(
4862                                         ut_params->obuf,
4863                                         plaintext_pad_len + aad_pad_len);
4864                         TEST_ASSERT_NOT_NULL(ciphertext,
4865                                         "no room to append ciphertext");
4866
4867                         memset(ciphertext + aad_pad_len, 0,
4868                                         tdata->ciphertext.len);
4869                 }
4870         } else {
4871                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4872                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4873                                 plaintext_pad_len);
4874                 TEST_ASSERT_NOT_NULL(ciphertext,
4875                                 "no room to append ciphertext");
4876
4877                 memcpy(ciphertext, tdata->ciphertext.data,
4878                                 tdata->ciphertext.len);
4879                 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext,
4880                                 tdata->ciphertext.len);
4881
4882                 if (ut_params->obuf) {
4883                         plaintext = (uint8_t *)rte_pktmbuf_append(
4884                                         ut_params->obuf,
4885                                         plaintext_pad_len + aad_pad_len);
4886                         TEST_ASSERT_NOT_NULL(plaintext,
4887                                         "no room to append plaintext");
4888
4889                         memset(plaintext + aad_pad_len, 0,
4890                                         tdata->plaintext.len);
4891                 }
4892         }
4893
4894         /* Append digest data */
4895         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
4896                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
4897                                 ut_params->obuf ? ut_params->obuf :
4898                                                 ut_params->ibuf,
4899                                                 tdata->auth_tag.len);
4900                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
4901                                 "no room to append digest");
4902                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
4903                 sym_op->aead.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4904                                 ut_params->obuf ? ut_params->obuf :
4905                                                 ut_params->ibuf,
4906                                                 plaintext_pad_len +
4907                                                 aad_pad_len);
4908         } else {
4909                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
4910                                 ut_params->ibuf, tdata->auth_tag.len);
4911                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
4912                                 "no room to append digest");
4913                 sym_op->aead.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4914                                 ut_params->ibuf,
4915                                 plaintext_pad_len + aad_pad_len);
4916
4917                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
4918                         tdata->auth_tag.len);
4919                 TEST_HEXDUMP(stdout, "digest:",
4920                         sym_op->aead.digest.data,
4921                         tdata->auth_tag.len);
4922         }
4923
4924         sym_op->aead.data.length = tdata->plaintext.len;
4925         sym_op->aead.data.offset = aad_pad_len;
4926
4927         return 0;
4928 }
4929
4930 static int
4931 test_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
4932 {
4933         struct crypto_testsuite_params *ts_params = &testsuite_params;
4934         struct crypto_unittest_params *ut_params = &unittest_params;
4935
4936         int retval;
4937         uint8_t *ciphertext, *auth_tag;
4938         uint16_t plaintext_pad_len;
4939         uint32_t i;
4940
4941         /* Create GCM session */
4942         retval = create_gcm_session(ts_params->valid_devs[0],
4943                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
4944                         tdata->key.data, tdata->key.len,
4945                         tdata->aad.len, tdata->auth_tag.len,
4946                         tdata->iv.len);
4947         if (retval < 0)
4948                 return retval;
4949
4950         if (tdata->aad.len > MBUF_SIZE) {
4951                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
4952                 /* Populate full size of add data */
4953                 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
4954                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
4955         } else
4956                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4957
4958         /* clear mbuf payload */
4959         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4960                         rte_pktmbuf_tailroom(ut_params->ibuf));
4961
4962         /* Create GCM operation */
4963         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
4964         if (retval < 0)
4965                 return retval;
4966
4967         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4968
4969         ut_params->op->sym->m_src = ut_params->ibuf;
4970
4971         /* Process crypto operation */
4972         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4973                         ut_params->op), "failed to process sym crypto op");
4974
4975         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4976                         "crypto op processing failed");
4977
4978         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4979
4980         if (ut_params->op->sym->m_dst) {
4981                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4982                                 uint8_t *);
4983                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4984                                 uint8_t *, plaintext_pad_len);
4985         } else {
4986                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
4987                                 uint8_t *,
4988                                 ut_params->op->sym->cipher.data.offset);
4989                 auth_tag = ciphertext + plaintext_pad_len;
4990         }
4991
4992         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4993         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4994
4995         /* Validate obuf */
4996         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4997                         ciphertext,
4998                         tdata->ciphertext.data,
4999                         tdata->ciphertext.len,
5000                         "GCM Ciphertext data not as expected");
5001
5002         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5003                         auth_tag,
5004                         tdata->auth_tag.data,
5005                         tdata->auth_tag.len,
5006                         "GCM Generated auth tag not as expected");
5007
5008         return 0;
5009
5010 }
5011
5012 static int
5013 test_AES_GCM_authenticated_encryption_test_case_1(void)
5014 {
5015         return test_AES_GCM_authenticated_encryption(&gcm_test_case_1);
5016 }
5017
5018 static int
5019 test_AES_GCM_authenticated_encryption_test_case_2(void)
5020 {
5021         return test_AES_GCM_authenticated_encryption(&gcm_test_case_2);
5022 }
5023
5024 static int
5025 test_AES_GCM_authenticated_encryption_test_case_3(void)
5026 {
5027         return test_AES_GCM_authenticated_encryption(&gcm_test_case_3);
5028 }
5029
5030 static int
5031 test_AES_GCM_authenticated_encryption_test_case_4(void)
5032 {
5033         return test_AES_GCM_authenticated_encryption(&gcm_test_case_4);
5034 }
5035
5036 static int
5037 test_AES_GCM_authenticated_encryption_test_case_5(void)
5038 {
5039         return test_AES_GCM_authenticated_encryption(&gcm_test_case_5);
5040 }
5041
5042 static int
5043 test_AES_GCM_authenticated_encryption_test_case_6(void)
5044 {
5045         return test_AES_GCM_authenticated_encryption(&gcm_test_case_6);
5046 }
5047
5048 static int
5049 test_AES_GCM_authenticated_encryption_test_case_7(void)
5050 {
5051         return test_AES_GCM_authenticated_encryption(&gcm_test_case_7);
5052 }
5053
5054 static int
5055 test_AES_GCM_auth_encryption_test_case_192_1(void)
5056 {
5057         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_1);
5058 }
5059
5060 static int
5061 test_AES_GCM_auth_encryption_test_case_192_2(void)
5062 {
5063         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_2);
5064 }
5065
5066 static int
5067 test_AES_GCM_auth_encryption_test_case_192_3(void)
5068 {
5069         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_3);
5070 }
5071
5072 static int
5073 test_AES_GCM_auth_encryption_test_case_192_4(void)
5074 {
5075         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_4);
5076 }
5077
5078 static int
5079 test_AES_GCM_auth_encryption_test_case_192_5(void)
5080 {
5081         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_5);
5082 }
5083
5084 static int
5085 test_AES_GCM_auth_encryption_test_case_192_6(void)
5086 {
5087         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_6);
5088 }
5089
5090 static int
5091 test_AES_GCM_auth_encryption_test_case_192_7(void)
5092 {
5093         return test_AES_GCM_authenticated_encryption(&gcm_test_case_192_7);
5094 }
5095
5096 static int
5097 test_AES_GCM_auth_encryption_test_case_256_1(void)
5098 {
5099         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_1);
5100 }
5101
5102 static int
5103 test_AES_GCM_auth_encryption_test_case_256_2(void)
5104 {
5105         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_2);
5106 }
5107
5108 static int
5109 test_AES_GCM_auth_encryption_test_case_256_3(void)
5110 {
5111         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_3);
5112 }
5113
5114 static int
5115 test_AES_GCM_auth_encryption_test_case_256_4(void)
5116 {
5117         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_4);
5118 }
5119
5120 static int
5121 test_AES_GCM_auth_encryption_test_case_256_5(void)
5122 {
5123         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_5);
5124 }
5125
5126 static int
5127 test_AES_GCM_auth_encryption_test_case_256_6(void)
5128 {
5129         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_6);
5130 }
5131
5132 static int
5133 test_AES_GCM_auth_encryption_test_case_256_7(void)
5134 {
5135         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_7);
5136 }
5137
5138 static int
5139 test_AES_GCM_auth_encryption_test_case_aad_1(void)
5140 {
5141         return test_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1);
5142 }
5143
5144 static int
5145 test_AES_GCM_auth_encryption_test_case_aad_2(void)
5146 {
5147         return test_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2);
5148 }
5149
5150 static int
5151 test_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
5152 {
5153         struct crypto_testsuite_params *ts_params = &testsuite_params;
5154         struct crypto_unittest_params *ut_params = &unittest_params;
5155
5156         int retval;
5157         uint8_t *plaintext;
5158         uint32_t i;
5159
5160         /* Create GCM session */
5161         retval = create_gcm_session(ts_params->valid_devs[0],
5162                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5163                         tdata->key.data, tdata->key.len,
5164                         tdata->aad.len, tdata->auth_tag.len,
5165                         tdata->iv.len);
5166         if (retval < 0)
5167                 return retval;
5168
5169         /* alloc mbuf and set payload */
5170         if (tdata->aad.len > MBUF_SIZE) {
5171                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5172                 /* Populate full size of add data */
5173                 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
5174                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5175         } else
5176                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5177
5178         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5179                         rte_pktmbuf_tailroom(ut_params->ibuf));
5180
5181         /* Create GCM operation */
5182         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5183         if (retval < 0)
5184                 return retval;
5185
5186         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5187
5188         ut_params->op->sym->m_src = ut_params->ibuf;
5189
5190         /* Process crypto operation */
5191         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5192                         ut_params->op), "failed to process sym crypto op");
5193
5194         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5195                         "crypto op processing failed");
5196
5197         if (ut_params->op->sym->m_dst)
5198                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5199                                 uint8_t *);
5200         else
5201                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5202                                 uint8_t *,
5203                                 ut_params->op->sym->cipher.data.offset);
5204
5205         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5206
5207         /* Validate obuf */
5208         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5209                         plaintext,
5210                         tdata->plaintext.data,
5211                         tdata->plaintext.len,
5212                         "GCM plaintext data not as expected");
5213
5214         TEST_ASSERT_EQUAL(ut_params->op->status,
5215                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5216                         "GCM authentication failed");
5217         return 0;
5218 }
5219
5220 static int
5221 test_AES_GCM_authenticated_decryption_test_case_1(void)
5222 {
5223         return test_AES_GCM_authenticated_decryption(&gcm_test_case_1);
5224 }
5225
5226 static int
5227 test_AES_GCM_authenticated_decryption_test_case_2(void)
5228 {
5229         return test_AES_GCM_authenticated_decryption(&gcm_test_case_2);
5230 }
5231
5232 static int
5233 test_AES_GCM_authenticated_decryption_test_case_3(void)
5234 {
5235         return test_AES_GCM_authenticated_decryption(&gcm_test_case_3);
5236 }
5237
5238 static int
5239 test_AES_GCM_authenticated_decryption_test_case_4(void)
5240 {
5241         return test_AES_GCM_authenticated_decryption(&gcm_test_case_4);
5242 }
5243
5244 static int
5245 test_AES_GCM_authenticated_decryption_test_case_5(void)
5246 {
5247         return test_AES_GCM_authenticated_decryption(&gcm_test_case_5);
5248 }
5249
5250 static int
5251 test_AES_GCM_authenticated_decryption_test_case_6(void)
5252 {
5253         return test_AES_GCM_authenticated_decryption(&gcm_test_case_6);
5254 }
5255
5256 static int
5257 test_AES_GCM_authenticated_decryption_test_case_7(void)
5258 {
5259         return test_AES_GCM_authenticated_decryption(&gcm_test_case_7);
5260 }
5261
5262 static int
5263 test_AES_GCM_auth_decryption_test_case_192_1(void)
5264 {
5265         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_1);
5266 }
5267
5268 static int
5269 test_AES_GCM_auth_decryption_test_case_192_2(void)
5270 {
5271         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_2);
5272 }
5273
5274 static int
5275 test_AES_GCM_auth_decryption_test_case_192_3(void)
5276 {
5277         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_3);
5278 }
5279
5280 static int
5281 test_AES_GCM_auth_decryption_test_case_192_4(void)
5282 {
5283         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_4);
5284 }
5285
5286 static int
5287 test_AES_GCM_auth_decryption_test_case_192_5(void)
5288 {
5289         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_5);
5290 }
5291
5292 static int
5293 test_AES_GCM_auth_decryption_test_case_192_6(void)
5294 {
5295         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_6);
5296 }
5297
5298 static int
5299 test_AES_GCM_auth_decryption_test_case_192_7(void)
5300 {
5301         return test_AES_GCM_authenticated_decryption(&gcm_test_case_192_7);
5302 }
5303
5304 static int
5305 test_AES_GCM_auth_decryption_test_case_256_1(void)
5306 {
5307         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_1);
5308 }
5309
5310 static int
5311 test_AES_GCM_auth_decryption_test_case_256_2(void)
5312 {
5313         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_2);
5314 }
5315
5316 static int
5317 test_AES_GCM_auth_decryption_test_case_256_3(void)
5318 {
5319         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_3);
5320 }
5321
5322 static int
5323 test_AES_GCM_auth_decryption_test_case_256_4(void)
5324 {
5325         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_4);
5326 }
5327
5328 static int
5329 test_AES_GCM_auth_decryption_test_case_256_5(void)
5330 {
5331         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_5);
5332 }
5333
5334 static int
5335 test_AES_GCM_auth_decryption_test_case_256_6(void)
5336 {
5337         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_6);
5338 }
5339
5340 static int
5341 test_AES_GCM_auth_decryption_test_case_256_7(void)
5342 {
5343         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_7);
5344 }
5345
5346 static int
5347 test_AES_GCM_auth_decryption_test_case_aad_1(void)
5348 {
5349         return test_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1);
5350 }
5351
5352 static int
5353 test_AES_GCM_auth_decryption_test_case_aad_2(void)
5354 {
5355         return test_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2);
5356 }
5357
5358 static int
5359 test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata)
5360 {
5361         struct crypto_testsuite_params *ts_params = &testsuite_params;
5362         struct crypto_unittest_params *ut_params = &unittest_params;
5363
5364         int retval;
5365         uint8_t *ciphertext, *auth_tag;
5366         uint16_t plaintext_pad_len;
5367
5368         /* Create GCM session */
5369         retval = create_gcm_session(ts_params->valid_devs[0],
5370                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5371                         tdata->key.data, tdata->key.len,
5372                         tdata->aad.len, tdata->auth_tag.len,
5373                         tdata->iv.len);
5374         if (retval < 0)
5375                 return retval;
5376
5377         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5378         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5379
5380         /* clear mbuf payload */
5381         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5382                         rte_pktmbuf_tailroom(ut_params->ibuf));
5383         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5384                         rte_pktmbuf_tailroom(ut_params->obuf));
5385
5386         /* Create GCM operation */
5387         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5388         if (retval < 0)
5389                 return retval;
5390
5391         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5392
5393         ut_params->op->sym->m_src = ut_params->ibuf;
5394         ut_params->op->sym->m_dst = ut_params->obuf;
5395
5396         /* Process crypto operation */
5397         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5398                         ut_params->op), "failed to process sym crypto op");
5399
5400         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5401                         "crypto op processing failed");
5402
5403         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5404
5405         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5406                         ut_params->op->sym->cipher.data.offset);
5407         auth_tag = ciphertext + plaintext_pad_len;
5408
5409         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5410         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5411
5412         /* Validate obuf */
5413         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5414                         ciphertext,
5415                         tdata->ciphertext.data,
5416                         tdata->ciphertext.len,
5417                         "GCM Ciphertext data not as expected");
5418
5419         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5420                         auth_tag,
5421                         tdata->auth_tag.data,
5422                         tdata->auth_tag.len,
5423                         "GCM Generated auth tag not as expected");
5424
5425         return 0;
5426
5427 }
5428
5429 static int
5430 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
5431 {
5432         return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5);
5433 }
5434
5435 static int
5436 test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata)
5437 {
5438         struct crypto_testsuite_params *ts_params = &testsuite_params;
5439         struct crypto_unittest_params *ut_params = &unittest_params;
5440
5441         int retval;
5442         uint8_t *plaintext;
5443
5444         /* Create GCM session */
5445         retval = create_gcm_session(ts_params->valid_devs[0],
5446                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5447                         tdata->key.data, tdata->key.len,
5448                         tdata->aad.len, tdata->auth_tag.len,
5449                         tdata->iv.len);
5450         if (retval < 0)
5451                 return retval;
5452
5453         /* alloc mbuf and set payload */
5454         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5455         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5456
5457         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5458                         rte_pktmbuf_tailroom(ut_params->ibuf));
5459         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5460                         rte_pktmbuf_tailroom(ut_params->obuf));
5461
5462         /* Create GCM operation */
5463         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5464         if (retval < 0)
5465                 return retval;
5466
5467         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5468
5469         ut_params->op->sym->m_src = ut_params->ibuf;
5470         ut_params->op->sym->m_dst = ut_params->obuf;
5471
5472         /* Process crypto operation */
5473         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5474                         ut_params->op), "failed to process sym crypto op");
5475
5476         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5477                         "crypto op processing failed");
5478
5479         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5480                         ut_params->op->sym->cipher.data.offset);
5481
5482         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5483
5484         /* Validate obuf */
5485         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5486                         plaintext,
5487                         tdata->plaintext.data,
5488                         tdata->plaintext.len,
5489                         "GCM plaintext data not as expected");
5490
5491         TEST_ASSERT_EQUAL(ut_params->op->status,
5492                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5493                         "GCM authentication failed");
5494         return 0;
5495 }
5496
5497 static int
5498 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
5499 {
5500         return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5);
5501 }
5502
5503 static int
5504 test_AES_GCM_authenticated_encryption_sessionless(
5505                 const struct gcm_test_data *tdata)
5506 {
5507         struct crypto_testsuite_params *ts_params = &testsuite_params;
5508         struct crypto_unittest_params *ut_params = &unittest_params;
5509
5510         int retval;
5511         uint8_t *ciphertext, *auth_tag;
5512         uint16_t plaintext_pad_len;
5513         uint8_t key[tdata->key.len + 1];
5514
5515         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5516
5517         /* clear mbuf payload */
5518         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5519                         rte_pktmbuf_tailroom(ut_params->ibuf));
5520
5521         /* Create GCM operation */
5522         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5523         if (retval < 0)
5524                 return retval;
5525
5526         /* Create GCM xforms */
5527         memcpy(key, tdata->key.data, tdata->key.len);
5528         retval = create_gcm_xforms(ut_params->op,
5529                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5530                         key, tdata->key.len,
5531                         tdata->aad.len, tdata->auth_tag.len,
5532                         tdata->iv.len);
5533         if (retval < 0)
5534                 return retval;
5535
5536         ut_params->op->sym->m_src = ut_params->ibuf;
5537
5538         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
5539                         RTE_CRYPTO_OP_SESSIONLESS,
5540                         "crypto op session type not sessionless");
5541
5542         /* Process crypto operation */
5543         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5544                         ut_params->op), "failed to process sym crypto op");
5545
5546         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5547
5548         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5549                         "crypto op status not success");
5550
5551         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5552
5553         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5554                         ut_params->op->sym->cipher.data.offset);
5555         auth_tag = ciphertext + plaintext_pad_len;
5556
5557         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5558         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5559
5560         /* Validate obuf */
5561         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5562                         ciphertext,
5563                         tdata->ciphertext.data,
5564                         tdata->ciphertext.len,
5565                         "GCM Ciphertext data not as expected");
5566
5567         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5568                         auth_tag,
5569                         tdata->auth_tag.data,
5570                         tdata->auth_tag.len,
5571                         "GCM Generated auth tag not as expected");
5572
5573         return 0;
5574
5575 }
5576
5577 static int
5578 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
5579 {
5580         return test_AES_GCM_authenticated_encryption_sessionless(
5581                         &gcm_test_case_5);
5582 }
5583
5584 static int
5585 test_AES_GCM_authenticated_decryption_sessionless(
5586                 const struct gcm_test_data *tdata)
5587 {
5588         struct crypto_testsuite_params *ts_params = &testsuite_params;
5589         struct crypto_unittest_params *ut_params = &unittest_params;
5590
5591         int retval;
5592         uint8_t *plaintext;
5593         uint8_t key[tdata->key.len + 1];
5594
5595         /* alloc mbuf and set payload */
5596         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5597
5598         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5599                         rte_pktmbuf_tailroom(ut_params->ibuf));
5600
5601         /* Create GCM operation */
5602         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5603         if (retval < 0)
5604                 return retval;
5605
5606         /* Create GCM xforms */
5607         memcpy(key, tdata->key.data, tdata->key.len);
5608         retval = create_gcm_xforms(ut_params->op,
5609                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5610                         key, tdata->key.len,
5611                         tdata->aad.len, tdata->auth_tag.len,
5612                         tdata->iv.len);
5613         if (retval < 0)
5614                 return retval;
5615
5616         ut_params->op->sym->m_src = ut_params->ibuf;
5617
5618         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
5619                         RTE_CRYPTO_OP_SESSIONLESS,
5620                         "crypto op session type not sessionless");
5621
5622         /* Process crypto operation */
5623         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5624                         ut_params->op), "failed to process sym crypto op");
5625
5626         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5627
5628         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5629                         "crypto op status not success");
5630
5631         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5632                         ut_params->op->sym->cipher.data.offset);
5633
5634         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5635
5636         /* Validate obuf */
5637         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5638                         plaintext,
5639                         tdata->plaintext.data,
5640                         tdata->plaintext.len,
5641                         "GCM plaintext data not as expected");
5642
5643         TEST_ASSERT_EQUAL(ut_params->op->status,
5644                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5645                         "GCM authentication failed");
5646         return 0;
5647 }
5648
5649 static int
5650 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
5651 {
5652         return test_AES_GCM_authenticated_decryption_sessionless(
5653                         &gcm_test_case_5);
5654 }
5655
5656 static int
5657 test_stats(void)
5658 {
5659         struct crypto_testsuite_params *ts_params = &testsuite_params;
5660         struct rte_cryptodev_stats stats;
5661         struct rte_cryptodev *dev;
5662         cryptodev_stats_get_t temp_pfn;
5663
5664         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5665         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
5666                         &stats) == -ENODEV),
5667                 "rte_cryptodev_stats_get invalid dev failed");
5668         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
5669                 "rte_cryptodev_stats_get invalid Param failed");
5670         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
5671         temp_pfn = dev->dev_ops->stats_get;
5672         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
5673         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
5674                         == -ENOTSUP),
5675                 "rte_cryptodev_stats_get invalid Param failed");
5676         dev->dev_ops->stats_get = temp_pfn;
5677
5678         /* Test expected values */
5679         ut_setup();
5680         test_AES_CBC_HMAC_SHA1_encrypt_digest();
5681         ut_teardown();
5682         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5683                         &stats),
5684                 "rte_cryptodev_stats_get failed");
5685         TEST_ASSERT((stats.enqueued_count == 1),
5686                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5687         TEST_ASSERT((stats.dequeued_count == 1),
5688                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5689         TEST_ASSERT((stats.enqueue_err_count == 0),
5690                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5691         TEST_ASSERT((stats.dequeue_err_count == 0),
5692                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5693
5694         /* invalid device but should ignore and not reset device stats*/
5695         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
5696         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5697                         &stats),
5698                 "rte_cryptodev_stats_get failed");
5699         TEST_ASSERT((stats.enqueued_count == 1),
5700                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5701
5702         /* check that a valid reset clears stats */
5703         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5704         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5705                         &stats),
5706                                           "rte_cryptodev_stats_get failed");
5707         TEST_ASSERT((stats.enqueued_count == 0),
5708                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5709         TEST_ASSERT((stats.dequeued_count == 0),
5710                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5711
5712         return TEST_SUCCESS;
5713 }
5714
5715 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
5716                                    struct crypto_unittest_params *ut_params,
5717                                    enum rte_crypto_auth_operation op,
5718                                    const struct HMAC_MD5_vector *test_case)
5719 {
5720         uint8_t key[64];
5721
5722         memcpy(key, test_case->key.data, test_case->key.len);
5723
5724         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5725         ut_params->auth_xform.next = NULL;
5726         ut_params->auth_xform.auth.op = op;
5727
5728         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
5729
5730         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
5731         ut_params->auth_xform.auth.key.length = test_case->key.len;
5732         ut_params->auth_xform.auth.key.data = key;
5733
5734         ut_params->sess = rte_cryptodev_sym_session_create(
5735                         ts_params->session_mpool);
5736
5737         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
5738                         ut_params->sess, &ut_params->auth_xform,
5739                         ts_params->session_mpool);
5740
5741         if (ut_params->sess == NULL)
5742                 return TEST_FAILED;
5743
5744         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5745
5746         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5747                         rte_pktmbuf_tailroom(ut_params->ibuf));
5748
5749         return 0;
5750 }
5751
5752 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
5753                               const struct HMAC_MD5_vector *test_case,
5754                               uint8_t **plaintext)
5755 {
5756         uint16_t plaintext_pad_len;
5757
5758         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5759
5760         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5761                                 16);
5762
5763         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5764                         plaintext_pad_len);
5765         memcpy(*plaintext, test_case->plaintext.data,
5766                         test_case->plaintext.len);
5767
5768         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5769                         ut_params->ibuf, MD5_DIGEST_LEN);
5770         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5771                         "no room to append digest");
5772         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5773                         ut_params->ibuf, plaintext_pad_len);
5774
5775         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5776                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
5777                            test_case->auth_tag.len);
5778         }
5779
5780         sym_op->auth.data.offset = 0;
5781         sym_op->auth.data.length = test_case->plaintext.len;
5782
5783         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5784         ut_params->op->sym->m_src = ut_params->ibuf;
5785
5786         return 0;
5787 }
5788
5789 static int
5790 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
5791 {
5792         uint16_t plaintext_pad_len;
5793         uint8_t *plaintext, *auth_tag;
5794
5795         struct crypto_testsuite_params *ts_params = &testsuite_params;
5796         struct crypto_unittest_params *ut_params = &unittest_params;
5797
5798         if (MD5_HMAC_create_session(ts_params, ut_params,
5799                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
5800                 return TEST_FAILED;
5801
5802         /* Generate Crypto op data structure */
5803         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5804                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5805         TEST_ASSERT_NOT_NULL(ut_params->op,
5806                         "Failed to allocate symmetric crypto operation struct");
5807
5808         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5809                                 16);
5810
5811         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5812                 return TEST_FAILED;
5813
5814         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5815                         ut_params->op), "failed to process sym crypto op");
5816
5817         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5818                         "crypto op processing failed");
5819
5820         if (ut_params->op->sym->m_dst) {
5821                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5822                                 uint8_t *, plaintext_pad_len);
5823         } else {
5824                 auth_tag = plaintext + plaintext_pad_len;
5825         }
5826
5827         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5828                         auth_tag,
5829                         test_case->auth_tag.data,
5830                         test_case->auth_tag.len,
5831                         "HMAC_MD5 generated tag not as expected");
5832
5833         return TEST_SUCCESS;
5834 }
5835
5836 static int
5837 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
5838 {
5839         uint8_t *plaintext;
5840
5841         struct crypto_testsuite_params *ts_params = &testsuite_params;
5842         struct crypto_unittest_params *ut_params = &unittest_params;
5843
5844         if (MD5_HMAC_create_session(ts_params, ut_params,
5845                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
5846                 return TEST_FAILED;
5847         }
5848
5849         /* Generate Crypto op data structure */
5850         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5851                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5852         TEST_ASSERT_NOT_NULL(ut_params->op,
5853                         "Failed to allocate symmetric crypto operation struct");
5854
5855         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5856                 return TEST_FAILED;
5857
5858         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5859                         ut_params->op), "failed to process sym crypto op");
5860
5861         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5862                         "HMAC_MD5 crypto op processing failed");
5863
5864         return TEST_SUCCESS;
5865 }
5866
5867 static int
5868 test_MD5_HMAC_generate_case_1(void)
5869 {
5870         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
5871 }
5872
5873 static int
5874 test_MD5_HMAC_verify_case_1(void)
5875 {
5876         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
5877 }
5878
5879 static int
5880 test_MD5_HMAC_generate_case_2(void)
5881 {
5882         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
5883 }
5884
5885 static int
5886 test_MD5_HMAC_verify_case_2(void)
5887 {
5888         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
5889 }
5890
5891 static int
5892 test_multi_session(void)
5893 {
5894         struct crypto_testsuite_params *ts_params = &testsuite_params;
5895         struct crypto_unittest_params *ut_params = &unittest_params;
5896
5897         struct rte_cryptodev_info dev_info;
5898         struct rte_cryptodev_sym_session **sessions;
5899
5900         uint16_t i;
5901
5902         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
5903                         aes_cbc_key, hmac_sha512_key);
5904
5905
5906         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5907
5908         sessions = rte_malloc(NULL,
5909                         (sizeof(struct rte_cryptodev_sym_session *) *
5910                         dev_info.sym.max_nb_sessions) + 1, 0);
5911
5912         /* Create multiple crypto sessions*/
5913         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
5914
5915                 sessions[i] = rte_cryptodev_sym_session_create(
5916                                 ts_params->session_mpool);
5917
5918                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
5919                                 sessions[i], &ut_params->auth_xform,
5920                                 ts_params->session_mpool);
5921                 TEST_ASSERT_NOT_NULL(sessions[i],
5922                                 "Session creation failed at session number %u",
5923                                 i);
5924
5925                 /* Attempt to send a request on each session */
5926                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
5927                         sessions[i],
5928                         ut_params,
5929                         ts_params,
5930                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
5931                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
5932                         aes_cbc_iv),
5933                         "Failed to perform decrypt on request number %u.", i);
5934                 /* free crypto operation structure */
5935                 if (ut_params->op)
5936                         rte_crypto_op_free(ut_params->op);
5937
5938                 /*
5939                  * free mbuf - both obuf and ibuf are usually the same,
5940                  * so check if they point at the same address is necessary,
5941                  * to avoid freeing the mbuf twice.
5942                  */
5943                 if (ut_params->obuf) {
5944                         rte_pktmbuf_free(ut_params->obuf);
5945                         if (ut_params->ibuf == ut_params->obuf)
5946                                 ut_params->ibuf = 0;
5947                         ut_params->obuf = 0;
5948                 }
5949                 if (ut_params->ibuf) {
5950                         rte_pktmbuf_free(ut_params->ibuf);
5951                         ut_params->ibuf = 0;
5952                 }
5953         }
5954
5955         /* Next session create should fail */
5956         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
5957                         sessions[i], &ut_params->auth_xform,
5958                         ts_params->session_mpool);
5959         TEST_ASSERT_NULL(sessions[i],
5960                         "Session creation succeeded unexpectedly!");
5961
5962         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
5963                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
5964                                 sessions[i]);
5965                 rte_cryptodev_sym_session_free(sessions[i]);
5966         }
5967
5968         rte_free(sessions);
5969
5970         return TEST_SUCCESS;
5971 }
5972
5973 struct multi_session_params {
5974         struct crypto_unittest_params ut_params;
5975         uint8_t *cipher_key;
5976         uint8_t *hmac_key;
5977         const uint8_t *cipher;
5978         const uint8_t *digest;
5979         uint8_t *iv;
5980 };
5981
5982 #define MB_SESSION_NUMBER 3
5983
5984 static int
5985 test_multi_session_random_usage(void)
5986 {
5987         struct crypto_testsuite_params *ts_params = &testsuite_params;
5988         struct rte_cryptodev_info dev_info;
5989         struct rte_cryptodev_sym_session **sessions;
5990         uint32_t i, j;
5991         struct multi_session_params ut_paramz[] = {
5992
5993                 {
5994                         .cipher_key = ms_aes_cbc_key0,
5995                         .hmac_key = ms_hmac_key0,
5996                         .cipher = ms_aes_cbc_cipher0,
5997                         .digest = ms_hmac_digest0,
5998                         .iv = ms_aes_cbc_iv0
5999                 },
6000                 {
6001                         .cipher_key = ms_aes_cbc_key1,
6002                         .hmac_key = ms_hmac_key1,
6003                         .cipher = ms_aes_cbc_cipher1,
6004                         .digest = ms_hmac_digest1,
6005                         .iv = ms_aes_cbc_iv1
6006                 },
6007                 {
6008                         .cipher_key = ms_aes_cbc_key2,
6009                         .hmac_key = ms_hmac_key2,
6010                         .cipher = ms_aes_cbc_cipher2,
6011                         .digest = ms_hmac_digest2,
6012                         .iv = ms_aes_cbc_iv2
6013                 },
6014
6015         };
6016
6017         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6018
6019         sessions = rte_malloc(NULL,
6020                         (sizeof(struct rte_cryptodev_sym_session *)
6021                                         * dev_info.sym.max_nb_sessions) + 1, 0);
6022
6023         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6024                 sessions[i] = rte_cryptodev_sym_session_create(
6025                                 ts_params->session_mpool);
6026
6027                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
6028                                 sizeof(struct crypto_unittest_params));
6029
6030                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
6031                                 &ut_paramz[i].ut_params,
6032                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
6033
6034                 /* Create multiple crypto sessions*/
6035                 rte_cryptodev_sym_session_init(
6036                                 ts_params->valid_devs[0],
6037                                 sessions[i],
6038                                 &ut_paramz[i].ut_params.auth_xform,
6039                                 ts_params->session_mpool);
6040
6041                 TEST_ASSERT_NOT_NULL(sessions[i],
6042                                 "Session creation failed at session number %u",
6043                                 i);
6044
6045         }
6046
6047         srand(time(NULL));
6048         for (i = 0; i < 40000; i++) {
6049
6050                 j = rand() % MB_SESSION_NUMBER;
6051
6052                 TEST_ASSERT_SUCCESS(
6053                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
6054                                         sessions[j],
6055                                         &ut_paramz[j].ut_params,
6056                                         ts_params, ut_paramz[j].cipher,
6057                                         ut_paramz[j].digest,
6058                                         ut_paramz[j].iv),
6059                         "Failed to perform decrypt on request number %u.", i);
6060
6061                 if (ut_paramz[j].ut_params.op)
6062                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
6063
6064                 /*
6065                  * free mbuf - both obuf and ibuf are usually the same,
6066                  * so check if they point at the same address is necessary,
6067                  * to avoid freeing the mbuf twice.
6068                  */
6069                 if (ut_paramz[j].ut_params.obuf) {
6070                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
6071                         if (ut_paramz[j].ut_params.ibuf
6072                                         == ut_paramz[j].ut_params.obuf)
6073                                 ut_paramz[j].ut_params.ibuf = 0;
6074                         ut_paramz[j].ut_params.obuf = 0;
6075                 }
6076                 if (ut_paramz[j].ut_params.ibuf) {
6077                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
6078                         ut_paramz[j].ut_params.ibuf = 0;
6079                 }
6080         }
6081
6082         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6083                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
6084                                 sessions[i]);
6085                 rte_cryptodev_sym_session_free(sessions[i]);
6086         }
6087
6088         rte_free(sessions);
6089
6090         return TEST_SUCCESS;
6091 }
6092
6093 static int
6094 test_null_cipher_only_operation(void)
6095 {
6096         struct crypto_testsuite_params *ts_params = &testsuite_params;
6097         struct crypto_unittest_params *ut_params = &unittest_params;
6098
6099         /* Generate test mbuf data and space for digest */
6100         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6101                         catch_22_quote, QUOTE_512_BYTES, 0);
6102
6103         /* Setup Cipher Parameters */
6104         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6105         ut_params->cipher_xform.next = NULL;
6106
6107         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6108         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6109
6110         ut_params->sess = rte_cryptodev_sym_session_create(
6111                         ts_params->session_mpool);
6112
6113         /* Create Crypto session*/
6114         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6115                                 ut_params->sess,
6116                                 &ut_params->cipher_xform,
6117                                 ts_params->session_mpool);
6118         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6119
6120         /* Generate Crypto op data structure */
6121         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6122                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6123         TEST_ASSERT_NOT_NULL(ut_params->op,
6124                         "Failed to allocate symmetric crypto operation struct");
6125
6126         /* Set crypto operation data parameters */
6127         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6128
6129         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6130
6131         /* set crypto operation source mbuf */
6132         sym_op->m_src = ut_params->ibuf;
6133
6134         sym_op->cipher.data.offset = 0;
6135         sym_op->cipher.data.length = QUOTE_512_BYTES;
6136
6137         /* Process crypto operation */
6138         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6139                         ut_params->op);
6140         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6141
6142         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6143                         "crypto operation processing failed");
6144
6145         /* Validate obuf */
6146         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6147                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6148                         catch_22_quote,
6149                         QUOTE_512_BYTES,
6150                         "Ciphertext data not as expected");
6151
6152         return TEST_SUCCESS;
6153 }
6154
6155 static int
6156 test_null_auth_only_operation(void)
6157 {
6158         struct crypto_testsuite_params *ts_params = &testsuite_params;
6159         struct crypto_unittest_params *ut_params = &unittest_params;
6160
6161         /* Generate test mbuf data and space for digest */
6162         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6163                         catch_22_quote, QUOTE_512_BYTES, 0);
6164
6165         /* Setup HMAC Parameters */
6166         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6167         ut_params->auth_xform.next = NULL;
6168
6169         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6170         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6171
6172         ut_params->sess = rte_cryptodev_sym_session_create(
6173                         ts_params->session_mpool);
6174
6175         /* Create Crypto session*/
6176         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6177                         ut_params->sess, &ut_params->auth_xform,
6178                         ts_params->session_mpool);
6179         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6180
6181         /* Generate Crypto op data structure */
6182         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6183                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6184         TEST_ASSERT_NOT_NULL(ut_params->op,
6185                         "Failed to allocate symmetric crypto operation struct");
6186
6187         /* Set crypto operation data parameters */
6188         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6189
6190         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6191
6192         sym_op->m_src = ut_params->ibuf;
6193
6194         sym_op->auth.data.offset = 0;
6195         sym_op->auth.data.length = QUOTE_512_BYTES;
6196
6197         /* Process crypto operation */
6198         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6199                         ut_params->op);
6200         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6201
6202         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6203                         "crypto operation processing failed");
6204
6205         return TEST_SUCCESS;
6206 }
6207
6208 static int
6209 test_null_cipher_auth_operation(void)
6210 {
6211         struct crypto_testsuite_params *ts_params = &testsuite_params;
6212         struct crypto_unittest_params *ut_params = &unittest_params;
6213
6214         /* Generate test mbuf data and space for digest */
6215         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6216                         catch_22_quote, QUOTE_512_BYTES, 0);
6217
6218         /* Setup Cipher Parameters */
6219         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6220         ut_params->cipher_xform.next = &ut_params->auth_xform;
6221
6222         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6223         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6224
6225         /* Setup HMAC Parameters */
6226         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6227         ut_params->auth_xform.next = NULL;
6228
6229         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6230         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6231
6232         ut_params->sess = rte_cryptodev_sym_session_create(
6233                         ts_params->session_mpool);
6234
6235         /* Create Crypto session*/
6236         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6237                         ut_params->sess, &ut_params->cipher_xform,
6238                         ts_params->session_mpool);
6239         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6240
6241         /* Generate Crypto op data structure */
6242         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6243                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6244         TEST_ASSERT_NOT_NULL(ut_params->op,
6245                         "Failed to allocate symmetric crypto operation struct");
6246
6247         /* Set crypto operation data parameters */
6248         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6249
6250         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6251
6252         sym_op->m_src = ut_params->ibuf;
6253
6254         sym_op->cipher.data.offset = 0;
6255         sym_op->cipher.data.length = QUOTE_512_BYTES;
6256
6257         sym_op->auth.data.offset = 0;
6258         sym_op->auth.data.length = QUOTE_512_BYTES;
6259
6260         /* Process crypto operation */
6261         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6262                         ut_params->op);
6263         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6264
6265         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6266                         "crypto operation processing failed");
6267
6268         /* Validate obuf */
6269         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6270                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6271                         catch_22_quote,
6272                         QUOTE_512_BYTES,
6273                         "Ciphertext data not as expected");
6274
6275         return TEST_SUCCESS;
6276 }
6277
6278 static int
6279 test_null_auth_cipher_operation(void)
6280 {
6281         struct crypto_testsuite_params *ts_params = &testsuite_params;
6282         struct crypto_unittest_params *ut_params = &unittest_params;
6283
6284         /* Generate test mbuf data and space for digest */
6285         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6286                         catch_22_quote, QUOTE_512_BYTES, 0);
6287
6288         /* Setup Cipher Parameters */
6289         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6290         ut_params->cipher_xform.next = NULL;
6291
6292         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6293         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6294
6295         /* Setup HMAC Parameters */
6296         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6297         ut_params->auth_xform.next = &ut_params->cipher_xform;
6298
6299         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6300         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6301
6302         ut_params->sess = rte_cryptodev_sym_session_create(
6303                         ts_params->session_mpool);
6304
6305         /* Create Crypto session*/
6306         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6307                         ut_params->sess, &ut_params->cipher_xform,
6308                         ts_params->session_mpool);
6309         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6310
6311         /* Generate Crypto op data structure */
6312         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6313                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6314         TEST_ASSERT_NOT_NULL(ut_params->op,
6315                         "Failed to allocate symmetric crypto operation struct");
6316
6317         /* Set crypto operation data parameters */
6318         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6319
6320         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6321
6322         sym_op->m_src = ut_params->ibuf;
6323
6324         sym_op->cipher.data.offset = 0;
6325         sym_op->cipher.data.length = QUOTE_512_BYTES;
6326
6327         sym_op->auth.data.offset = 0;
6328         sym_op->auth.data.length = QUOTE_512_BYTES;
6329
6330         /* Process crypto operation */
6331         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6332                         ut_params->op);
6333         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6334
6335         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6336                         "crypto operation processing failed");
6337
6338         /* Validate obuf */
6339         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6340                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6341                         catch_22_quote,
6342                         QUOTE_512_BYTES,
6343                         "Ciphertext data not as expected");
6344
6345         return TEST_SUCCESS;
6346 }
6347
6348
6349 static int
6350 test_null_invalid_operation(void)
6351 {
6352         struct crypto_testsuite_params *ts_params = &testsuite_params;
6353         struct crypto_unittest_params *ut_params = &unittest_params;
6354         int ret;
6355
6356         /* Setup Cipher Parameters */
6357         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6358         ut_params->cipher_xform.next = NULL;
6359
6360         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
6361         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6362
6363         ut_params->sess = rte_cryptodev_sym_session_create(
6364                         ts_params->session_mpool);
6365
6366         /* Create Crypto session*/
6367         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6368                         ut_params->sess, &ut_params->cipher_xform,
6369                         ts_params->session_mpool);
6370         TEST_ASSERT(ret == -1,
6371                         "Session creation succeeded unexpectedly");
6372
6373
6374         /* Setup HMAC Parameters */
6375         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6376         ut_params->auth_xform.next = NULL;
6377
6378         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
6379         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6380
6381         ut_params->sess = rte_cryptodev_sym_session_create(
6382                         ts_params->session_mpool);
6383
6384         /* Create Crypto session*/
6385         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6386                         ut_params->sess, &ut_params->auth_xform,
6387                         ts_params->session_mpool);
6388         TEST_ASSERT(ret == -1,
6389                         "Session creation succeeded unexpectedly");
6390
6391         return TEST_SUCCESS;
6392 }
6393
6394
6395 #define NULL_BURST_LENGTH (32)
6396
6397 static int
6398 test_null_burst_operation(void)
6399 {
6400         struct crypto_testsuite_params *ts_params = &testsuite_params;
6401         struct crypto_unittest_params *ut_params = &unittest_params;
6402
6403         unsigned i, burst_len = NULL_BURST_LENGTH;
6404
6405         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
6406         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
6407
6408         /* Setup Cipher Parameters */
6409         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6410         ut_params->cipher_xform.next = &ut_params->auth_xform;
6411
6412         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6413         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6414
6415         /* Setup HMAC Parameters */
6416         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6417         ut_params->auth_xform.next = NULL;
6418
6419         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6420         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6421
6422         ut_params->sess = rte_cryptodev_sym_session_create(
6423                         ts_params->session_mpool);
6424
6425         /* Create Crypto session*/
6426         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6427                         ut_params->sess, &ut_params->cipher_xform,
6428                         ts_params->session_mpool);
6429         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6430
6431         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
6432                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
6433                         burst_len, "failed to generate burst of crypto ops");
6434
6435         /* Generate an operation for each mbuf in burst */
6436         for (i = 0; i < burst_len; i++) {
6437                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6438
6439                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
6440
6441                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
6442                                 sizeof(unsigned));
6443                 *data = i;
6444
6445                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
6446
6447                 burst[i]->sym->m_src = m;
6448         }
6449
6450         /* Process crypto operation */
6451         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
6452                         0, burst, burst_len),
6453                         burst_len,
6454                         "Error enqueuing burst");
6455
6456         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
6457                         0, burst_dequeued, burst_len),
6458                         burst_len,
6459                         "Error dequeuing burst");
6460
6461
6462         for (i = 0; i < burst_len; i++) {
6463                 TEST_ASSERT_EQUAL(
6464                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
6465                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
6466                                         uint32_t *),
6467                         "data not as expected");
6468
6469                 rte_pktmbuf_free(burst[i]->sym->m_src);
6470                 rte_crypto_op_free(burst[i]);
6471         }
6472
6473         return TEST_SUCCESS;
6474 }
6475
6476 static void
6477 generate_gmac_large_plaintext(uint8_t *data)
6478 {
6479         uint16_t i;
6480
6481         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
6482                 memcpy(&data[i], &data[0], 32);
6483 }
6484
6485 static int
6486 create_gmac_operation(enum rte_crypto_auth_operation op,
6487                 const struct gmac_test_data *tdata)
6488 {
6489         struct crypto_testsuite_params *ts_params = &testsuite_params;
6490         struct crypto_unittest_params *ut_params = &unittest_params;
6491         struct rte_crypto_sym_op *sym_op;
6492
6493         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6494
6495         /* Generate Crypto op data structure */
6496         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6497                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6498         TEST_ASSERT_NOT_NULL(ut_params->op,
6499                         "Failed to allocate symmetric crypto operation struct");
6500
6501         sym_op = ut_params->op->sym;
6502
6503         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6504                         ut_params->ibuf, tdata->gmac_tag.len);
6505         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6506                         "no room to append digest");
6507
6508         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6509                         ut_params->ibuf, plaintext_pad_len);
6510
6511         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
6512                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
6513                                 tdata->gmac_tag.len);
6514                 TEST_HEXDUMP(stdout, "digest:",
6515                                 sym_op->auth.digest.data,
6516                                 tdata->gmac_tag.len);
6517         }
6518
6519         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6520                         uint8_t *, IV_OFFSET);
6521
6522         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
6523
6524         TEST_HEXDUMP(stdout, "iv:", iv_ptr, tdata->iv.len);
6525
6526         sym_op->cipher.data.length = 0;
6527         sym_op->cipher.data.offset = 0;
6528
6529         sym_op->auth.data.offset = 0;
6530         sym_op->auth.data.length = tdata->plaintext.len;
6531
6532         return 0;
6533 }
6534
6535 static int create_gmac_session(uint8_t dev_id,
6536                 const struct gmac_test_data *tdata,
6537                 enum rte_crypto_auth_operation auth_op)
6538 {
6539         uint8_t auth_key[tdata->key.len];
6540
6541         struct crypto_testsuite_params *ts_params = &testsuite_params;
6542         struct crypto_unittest_params *ut_params = &unittest_params;
6543
6544         memcpy(auth_key, tdata->key.data, tdata->key.len);
6545
6546         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6547         ut_params->auth_xform.next = NULL;
6548
6549         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
6550         ut_params->auth_xform.auth.op = auth_op;
6551         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
6552         ut_params->auth_xform.auth.key.length = tdata->key.len;
6553         ut_params->auth_xform.auth.key.data = auth_key;
6554         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
6555         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
6556
6557
6558         ut_params->sess = rte_cryptodev_sym_session_create(
6559                         ts_params->session_mpool);
6560
6561         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6562                         &ut_params->auth_xform,
6563                         ts_params->session_mpool);
6564
6565         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6566
6567         return 0;
6568 }
6569
6570 static int
6571 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
6572 {
6573         struct crypto_testsuite_params *ts_params = &testsuite_params;
6574         struct crypto_unittest_params *ut_params = &unittest_params;
6575
6576         int retval;
6577
6578         uint8_t *auth_tag, *plaintext;
6579         uint16_t plaintext_pad_len;
6580
6581         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6582                               "No GMAC length in the source data");
6583
6584         retval = create_gmac_session(ts_params->valid_devs[0],
6585                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
6586
6587         if (retval < 0)
6588                 return retval;
6589
6590         if (tdata->plaintext.len > MBUF_SIZE)
6591                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6592         else
6593                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6594         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6595                         "Failed to allocate input buffer in mempool");
6596
6597         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6598                         rte_pktmbuf_tailroom(ut_params->ibuf));
6599
6600         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6601         /*
6602          * Runtime generate the large plain text instead of use hard code
6603          * plain text vector. It is done to avoid create huge source file
6604          * with the test vector.
6605          */
6606         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
6607                 generate_gmac_large_plaintext(tdata->plaintext.data);
6608
6609         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6610                                 plaintext_pad_len);
6611         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6612
6613         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6614         TEST_HEXDUMP(stdout, "plaintext:", plaintext,
6615                         tdata->plaintext.len);
6616
6617         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
6618                         tdata);
6619
6620         if (retval < 0)
6621                 return retval;
6622
6623         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6624
6625         ut_params->op->sym->m_src = ut_params->ibuf;
6626
6627         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6628                         ut_params->op), "failed to process sym crypto op");
6629
6630         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6631                         "crypto op processing failed");
6632
6633         if (ut_params->op->sym->m_dst) {
6634                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6635                                 uint8_t *, plaintext_pad_len);
6636         } else {
6637                 auth_tag = plaintext + plaintext_pad_len;
6638         }
6639
6640         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
6641
6642         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6643                         auth_tag,
6644                         tdata->gmac_tag.data,
6645                         tdata->gmac_tag.len,
6646                         "GMAC Generated auth tag not as expected");
6647
6648         return 0;
6649 }
6650
6651 static int
6652 test_AES_GMAC_authentication_test_case_1(void)
6653 {
6654         return test_AES_GMAC_authentication(&gmac_test_case_1);
6655 }
6656
6657 static int
6658 test_AES_GMAC_authentication_test_case_2(void)
6659 {
6660         return test_AES_GMAC_authentication(&gmac_test_case_2);
6661 }
6662
6663 static int
6664 test_AES_GMAC_authentication_test_case_3(void)
6665 {
6666         return test_AES_GMAC_authentication(&gmac_test_case_3);
6667 }
6668
6669 static int
6670 test_AES_GMAC_authentication_test_case_4(void)
6671 {
6672         return test_AES_GMAC_authentication(&gmac_test_case_4);
6673 }
6674
6675 static int
6676 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
6677 {
6678         struct crypto_testsuite_params *ts_params = &testsuite_params;
6679         struct crypto_unittest_params *ut_params = &unittest_params;
6680         int retval;
6681         uint32_t plaintext_pad_len;
6682         uint8_t *plaintext;
6683
6684         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6685                               "No GMAC length in the source data");
6686
6687         retval = create_gmac_session(ts_params->valid_devs[0],
6688                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
6689
6690         if (retval < 0)
6691                 return retval;
6692
6693         if (tdata->plaintext.len > MBUF_SIZE)
6694                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6695         else
6696                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6697         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6698                         "Failed to allocate input buffer in mempool");
6699
6700         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6701                         rte_pktmbuf_tailroom(ut_params->ibuf));
6702
6703         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6704
6705         /*
6706          * Runtime generate the large plain text instead of use hard code
6707          * plain text vector. It is done to avoid create huge source file
6708          * with the test vector.
6709          */
6710         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
6711                 generate_gmac_large_plaintext(tdata->plaintext.data);
6712
6713         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6714                                 plaintext_pad_len);
6715         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6716
6717         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6718         TEST_HEXDUMP(stdout, "plaintext:", plaintext,
6719                         tdata->plaintext.len);
6720
6721         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
6722                         tdata);
6723
6724         if (retval < 0)
6725                 return retval;
6726
6727         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6728
6729         ut_params->op->sym->m_src = ut_params->ibuf;
6730
6731         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6732                         ut_params->op), "failed to process sym crypto op");
6733
6734         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6735                         "crypto op processing failed");
6736
6737         return 0;
6738
6739 }
6740
6741 static int
6742 test_AES_GMAC_authentication_verify_test_case_1(void)
6743 {
6744         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
6745 }
6746
6747 static int
6748 test_AES_GMAC_authentication_verify_test_case_2(void)
6749 {
6750         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
6751 }
6752
6753 static int
6754 test_AES_GMAC_authentication_verify_test_case_3(void)
6755 {
6756         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
6757 }
6758
6759 static int
6760 test_AES_GMAC_authentication_verify_test_case_4(void)
6761 {
6762         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
6763 }
6764
6765 struct test_crypto_vector {
6766         enum rte_crypto_cipher_algorithm crypto_algo;
6767
6768         struct {
6769                 uint8_t data[64];
6770                 unsigned int len;
6771         } cipher_key;
6772
6773         struct {
6774                 uint8_t data[64];
6775                 unsigned int len;
6776         } iv;
6777
6778         struct {
6779                 const uint8_t *data;
6780                 unsigned int len;
6781         } plaintext;
6782
6783         struct {
6784                 const uint8_t *data;
6785                 unsigned int len;
6786         } ciphertext;
6787
6788         enum rte_crypto_auth_algorithm auth_algo;
6789
6790         struct {
6791                 uint8_t data[128];
6792                 unsigned int len;
6793         } auth_key;
6794
6795         struct {
6796                 const uint8_t *data;
6797                 unsigned int len;
6798         } aad;
6799
6800         struct {
6801                 uint8_t data[128];
6802                 unsigned int len;
6803         } digest;
6804 };
6805
6806 static const struct test_crypto_vector
6807 hmac_sha1_test_crypto_vector = {
6808         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6809         .plaintext = {
6810                 .data = plaintext_hash,
6811                 .len = 512
6812         },
6813         .auth_key = {
6814                 .data = {
6815                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6816                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6817                         0xDE, 0xF4, 0xDE, 0xAD
6818                 },
6819                 .len = 20
6820         },
6821         .digest = {
6822                 .data = {
6823                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
6824                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
6825                         0x3F, 0x91, 0x64, 0x59
6826                 },
6827                 .len = 20
6828         }
6829 };
6830
6831 static const struct test_crypto_vector
6832 aes128_gmac_test_vector = {
6833         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
6834         .plaintext = {
6835                 .data = plaintext_hash,
6836                 .len = 512
6837         },
6838         .iv = {
6839                 .data = {
6840                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6841                         0x08, 0x09, 0x0A, 0x0B
6842                 },
6843                 .len = 12
6844         },
6845         .auth_key = {
6846                 .data = {
6847                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6848                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
6849                 },
6850                 .len = 16
6851         },
6852         .digest = {
6853                 .data = {
6854                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
6855                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
6856                 },
6857                 .len = 16
6858         }
6859 };
6860
6861 static const struct test_crypto_vector
6862 aes128cbc_hmac_sha1_test_vector = {
6863         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
6864         .cipher_key = {
6865                 .data = {
6866                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
6867                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
6868                 },
6869                 .len = 16
6870         },
6871         .iv = {
6872                 .data = {
6873                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6874                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
6875                 },
6876                 .len = 16
6877         },
6878         .plaintext = {
6879                 .data = plaintext_hash,
6880                 .len = 512
6881         },
6882         .ciphertext = {
6883                 .data = ciphertext512_aes128cbc,
6884                 .len = 512
6885         },
6886         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6887         .auth_key = {
6888                 .data = {
6889                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6890                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6891                         0xDE, 0xF4, 0xDE, 0xAD
6892                 },
6893                 .len = 20
6894         },
6895         .digest = {
6896                 .data = {
6897                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
6898                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6899                         0x18, 0x8C, 0x1D, 0x32
6900                 },
6901                 .len = 20
6902         }
6903 };
6904
6905 static void
6906 data_corruption(uint8_t *data)
6907 {
6908         data[0] += 1;
6909 }
6910
6911 static void
6912 tag_corruption(uint8_t *data, unsigned int tag_offset)
6913 {
6914         data[tag_offset] += 1;
6915 }
6916
6917 static int
6918 create_auth_session(struct crypto_unittest_params *ut_params,
6919                 uint8_t dev_id,
6920                 const struct test_crypto_vector *reference,
6921                 enum rte_crypto_auth_operation auth_op)
6922 {
6923         struct crypto_testsuite_params *ts_params = &testsuite_params;
6924         uint8_t auth_key[reference->auth_key.len + 1];
6925
6926         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6927
6928         /* Setup Authentication Parameters */
6929         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6930         ut_params->auth_xform.auth.op = auth_op;
6931         ut_params->auth_xform.next = NULL;
6932         ut_params->auth_xform.auth.algo = reference->auth_algo;
6933         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6934         ut_params->auth_xform.auth.key.data = auth_key;
6935         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6936
6937         /* Create Crypto session*/
6938         ut_params->sess = rte_cryptodev_sym_session_create(
6939                         ts_params->session_mpool);
6940
6941         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6942                                 &ut_params->auth_xform,
6943                                 ts_params->session_mpool);
6944
6945         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6946
6947         return 0;
6948 }
6949
6950 static int
6951 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
6952                 uint8_t dev_id,
6953                 const struct test_crypto_vector *reference,
6954                 enum rte_crypto_auth_operation auth_op,
6955                 enum rte_crypto_cipher_operation cipher_op)
6956 {
6957         struct crypto_testsuite_params *ts_params = &testsuite_params;
6958         uint8_t cipher_key[reference->cipher_key.len + 1];
6959         uint8_t auth_key[reference->auth_key.len + 1];
6960
6961         memcpy(cipher_key, reference->cipher_key.data,
6962                         reference->cipher_key.len);
6963         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6964
6965         /* Setup Authentication Parameters */
6966         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6967         ut_params->auth_xform.auth.op = auth_op;
6968         ut_params->auth_xform.auth.algo = reference->auth_algo;
6969         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6970         ut_params->auth_xform.auth.key.data = auth_key;
6971         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6972
6973         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
6974                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
6975                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
6976         } else {
6977                 ut_params->auth_xform.next = &ut_params->cipher_xform;
6978
6979                 /* Setup Cipher Parameters */
6980                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6981                 ut_params->cipher_xform.next = NULL;
6982                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
6983                 ut_params->cipher_xform.cipher.op = cipher_op;
6984                 ut_params->cipher_xform.cipher.key.data = cipher_key;
6985                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
6986                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
6987                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
6988         }
6989
6990         /* Create Crypto session*/
6991         ut_params->sess = rte_cryptodev_sym_session_create(
6992                         ts_params->session_mpool);
6993
6994         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6995                                 &ut_params->auth_xform,
6996                                 ts_params->session_mpool);
6997
6998         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6999
7000         return 0;
7001 }
7002
7003 static int
7004 create_auth_operation(struct crypto_testsuite_params *ts_params,
7005                 struct crypto_unittest_params *ut_params,
7006                 const struct test_crypto_vector *reference,
7007                 unsigned int auth_generate)
7008 {
7009         /* Generate Crypto op data structure */
7010         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7011                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7012         TEST_ASSERT_NOT_NULL(ut_params->op,
7013                         "Failed to allocate pktmbuf offload");
7014
7015         /* Set crypto operation data parameters */
7016         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7017
7018         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7019
7020         /* set crypto operation source mbuf */
7021         sym_op->m_src = ut_params->ibuf;
7022
7023         /* digest */
7024         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7025                         ut_params->ibuf, reference->digest.len);
7026
7027         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7028                         "no room to append auth tag");
7029
7030         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
7031                         ut_params->ibuf, reference->plaintext.len);
7032
7033         if (auth_generate)
7034                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7035         else
7036                 memcpy(sym_op->auth.digest.data,
7037                                 reference->digest.data,
7038                                 reference->digest.len);
7039
7040         TEST_HEXDUMP(stdout, "digest:",
7041                         sym_op->auth.digest.data,
7042                         reference->digest.len);
7043
7044         sym_op->auth.data.length = reference->plaintext.len;
7045         sym_op->auth.data.offset = 0;
7046
7047         return 0;
7048 }
7049
7050 static int
7051 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
7052                 struct crypto_unittest_params *ut_params,
7053                 const struct test_crypto_vector *reference,
7054                 unsigned int auth_generate)
7055 {
7056         /* Generate Crypto op data structure */
7057         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7058                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7059         TEST_ASSERT_NOT_NULL(ut_params->op,
7060                         "Failed to allocate pktmbuf offload");
7061
7062         /* Set crypto operation data parameters */
7063         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7064
7065         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7066
7067         /* set crypto operation source mbuf */
7068         sym_op->m_src = ut_params->ibuf;
7069
7070         /* digest */
7071         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7072                         ut_params->ibuf, reference->digest.len);
7073
7074         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7075                         "no room to append auth tag");
7076
7077         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
7078                         ut_params->ibuf, reference->ciphertext.len);
7079
7080         if (auth_generate)
7081                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7082         else
7083                 memcpy(sym_op->auth.digest.data,
7084                                 reference->digest.data,
7085                                 reference->digest.len);
7086
7087         TEST_HEXDUMP(stdout, "digest:",
7088                         sym_op->auth.digest.data,
7089                         reference->digest.len);
7090
7091         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7092                         reference->iv.data, reference->iv.len);
7093
7094         sym_op->cipher.data.length = 0;
7095         sym_op->cipher.data.offset = 0;
7096
7097         sym_op->auth.data.length = reference->plaintext.len;
7098         sym_op->auth.data.offset = 0;
7099
7100         return 0;
7101 }
7102
7103 static int
7104 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
7105                 struct crypto_unittest_params *ut_params,
7106                 const struct test_crypto_vector *reference,
7107                 unsigned int auth_generate)
7108 {
7109         /* Generate Crypto op data structure */
7110         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7111                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7112         TEST_ASSERT_NOT_NULL(ut_params->op,
7113                         "Failed to allocate pktmbuf offload");
7114
7115         /* Set crypto operation data parameters */
7116         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7117
7118         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7119
7120         /* set crypto operation source mbuf */
7121         sym_op->m_src = ut_params->ibuf;
7122
7123         /* digest */
7124         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7125                         ut_params->ibuf, reference->digest.len);
7126
7127         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7128                         "no room to append auth tag");
7129
7130         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
7131                         ut_params->ibuf, reference->ciphertext.len);
7132
7133         if (auth_generate)
7134                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7135         else
7136                 memcpy(sym_op->auth.digest.data,
7137                                 reference->digest.data,
7138                                 reference->digest.len);
7139
7140         TEST_HEXDUMP(stdout, "digest:",
7141                         sym_op->auth.digest.data,
7142                         reference->digest.len);
7143
7144         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7145                         reference->iv.data, reference->iv.len);
7146
7147         sym_op->cipher.data.length = reference->ciphertext.len;
7148         sym_op->cipher.data.offset = 0;
7149
7150         sym_op->auth.data.length = reference->ciphertext.len;
7151         sym_op->auth.data.offset = 0;
7152
7153         return 0;
7154 }
7155
7156 static int
7157 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7158                 struct crypto_unittest_params *ut_params,
7159                 const struct test_crypto_vector *reference)
7160 {
7161         return create_auth_operation(ts_params, ut_params, reference, 0);
7162 }
7163
7164 static int
7165 create_auth_verify_GMAC_operation(
7166                 struct crypto_testsuite_params *ts_params,
7167                 struct crypto_unittest_params *ut_params,
7168                 const struct test_crypto_vector *reference)
7169 {
7170         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
7171 }
7172
7173 static int
7174 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7175                 struct crypto_unittest_params *ut_params,
7176                 const struct test_crypto_vector *reference)
7177 {
7178         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
7179 }
7180
7181 static int
7182 test_authentication_verify_fail_when_data_corruption(
7183                 struct crypto_testsuite_params *ts_params,
7184                 struct crypto_unittest_params *ut_params,
7185                 const struct test_crypto_vector *reference,
7186                 unsigned int data_corrupted)
7187 {
7188         int retval;
7189
7190         uint8_t *plaintext;
7191
7192         /* Create session */
7193         retval = create_auth_session(ut_params,
7194                         ts_params->valid_devs[0],
7195                         reference,
7196                         RTE_CRYPTO_AUTH_OP_VERIFY);
7197         if (retval < 0)
7198                 return retval;
7199
7200         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7201         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7202                         "Failed to allocate input buffer in mempool");
7203
7204         /* clear mbuf payload */
7205         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7206                         rte_pktmbuf_tailroom(ut_params->ibuf));
7207
7208         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7209                         reference->plaintext.len);
7210         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7211         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7212
7213         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
7214
7215         /* Create operation */
7216         retval = create_auth_verify_operation(ts_params, ut_params, reference);
7217
7218         if (retval < 0)
7219                 return retval;
7220
7221         if (data_corrupted)
7222                 data_corruption(plaintext);
7223         else
7224                 tag_corruption(plaintext, reference->plaintext.len);
7225
7226         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7227                         ut_params->op);
7228         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7229         TEST_ASSERT_EQUAL(ut_params->op->status,
7230                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7231                         "authentication not failed");
7232
7233         ut_params->obuf = ut_params->op->sym->m_src;
7234         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7235
7236         return 0;
7237 }
7238
7239 static int
7240 test_authentication_verify_GMAC_fail_when_corruption(
7241                 struct crypto_testsuite_params *ts_params,
7242                 struct crypto_unittest_params *ut_params,
7243                 const struct test_crypto_vector *reference,
7244                 unsigned int data_corrupted)
7245 {
7246         int retval;
7247         uint8_t *plaintext;
7248
7249         /* Create session */
7250         retval = create_auth_cipher_session(ut_params,
7251                         ts_params->valid_devs[0],
7252                         reference,
7253                         RTE_CRYPTO_AUTH_OP_VERIFY,
7254                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7255         if (retval < 0)
7256                 return retval;
7257
7258         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7259         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7260                         "Failed to allocate input buffer in mempool");
7261
7262         /* clear mbuf payload */
7263         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7264                         rte_pktmbuf_tailroom(ut_params->ibuf));
7265
7266         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7267                         reference->plaintext.len);
7268         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7269         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7270
7271         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
7272
7273         /* Create operation */
7274         retval = create_auth_verify_GMAC_operation(ts_params,
7275                         ut_params,
7276                         reference);
7277
7278         if (retval < 0)
7279                 return retval;
7280
7281         if (data_corrupted)
7282                 data_corruption(plaintext);
7283         else
7284                 tag_corruption(plaintext, reference->aad.len);
7285
7286         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7287                         ut_params->op);
7288         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7289         TEST_ASSERT_EQUAL(ut_params->op->status,
7290                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7291                         "authentication not failed");
7292
7293         ut_params->obuf = ut_params->op->sym->m_src;
7294         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7295
7296         return 0;
7297 }
7298
7299 static int
7300 test_authenticated_decryption_fail_when_corruption(
7301                 struct crypto_testsuite_params *ts_params,
7302                 struct crypto_unittest_params *ut_params,
7303                 const struct test_crypto_vector *reference,
7304                 unsigned int data_corrupted)
7305 {
7306         int retval;
7307
7308         uint8_t *ciphertext;
7309
7310         /* Create session */
7311         retval = create_auth_cipher_session(ut_params,
7312                         ts_params->valid_devs[0],
7313                         reference,
7314                         RTE_CRYPTO_AUTH_OP_VERIFY,
7315                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7316         if (retval < 0)
7317                 return retval;
7318
7319         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7320         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7321                         "Failed to allocate input buffer in mempool");
7322
7323         /* clear mbuf payload */
7324         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7325                         rte_pktmbuf_tailroom(ut_params->ibuf));
7326
7327         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7328                         reference->ciphertext.len);
7329         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
7330         memcpy(ciphertext, reference->ciphertext.data,
7331                         reference->ciphertext.len);
7332
7333         /* Create operation */
7334         retval = create_cipher_auth_verify_operation(ts_params,
7335                         ut_params,
7336                         reference);
7337
7338         if (retval < 0)
7339                 return retval;
7340
7341         if (data_corrupted)
7342                 data_corruption(ciphertext);
7343         else
7344                 tag_corruption(ciphertext, reference->ciphertext.len);
7345
7346         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7347                         ut_params->op);
7348
7349         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7350         TEST_ASSERT_EQUAL(ut_params->op->status,
7351                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7352                         "authentication not failed");
7353
7354         ut_params->obuf = ut_params->op->sym->m_src;
7355         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7356
7357         return 0;
7358 }
7359
7360 static int
7361 create_gcm_operation_SGL(enum rte_crypto_aead_operation op,
7362                 const struct gcm_test_data *tdata,
7363                 void *digest_mem, uint64_t digest_phys)
7364 {
7365         struct crypto_testsuite_params *ts_params = &testsuite_params;
7366         struct crypto_unittest_params *ut_params = &unittest_params;
7367
7368         const unsigned int auth_tag_len = tdata->auth_tag.len;
7369         const unsigned int iv_len = tdata->iv.len;
7370         const unsigned int aad_len = tdata->aad.len;
7371
7372         /* Generate Crypto op data structure */
7373         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7374                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7375         TEST_ASSERT_NOT_NULL(ut_params->op,
7376                 "Failed to allocate symmetric crypto operation struct");
7377
7378         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7379
7380         sym_op->aead.digest.data = digest_mem;
7381
7382         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7383                         "no room to append digest");
7384
7385         sym_op->aead.digest.phys_addr = digest_phys;
7386
7387         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
7388                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7389                                 auth_tag_len);
7390                 TEST_HEXDUMP(stdout, "digest:",
7391                                 sym_op->aead.digest.data,
7392                                 auth_tag_len);
7393         }
7394
7395         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7396                         uint8_t *, IV_OFFSET);
7397
7398         rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
7399
7400         sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
7401                         ut_params->ibuf, aad_len);
7402         TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7403                         "no room to prepend aad");
7404         sym_op->aead.aad.phys_addr = rte_pktmbuf_mtophys(
7405                         ut_params->ibuf);
7406
7407         memset(sym_op->aead.aad.data, 0, aad_len);
7408         rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
7409
7410         TEST_HEXDUMP(stdout, "iv:", iv_ptr, iv_len);
7411         TEST_HEXDUMP(stdout, "aad:",
7412                         sym_op->aead.aad.data, aad_len);
7413
7414         sym_op->aead.data.length = tdata->plaintext.len;
7415         sym_op->aead.data.offset = aad_len;
7416
7417         return 0;
7418 }
7419
7420 #define SGL_MAX_NO      16
7421
7422 static int
7423 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
7424                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
7425 {
7426         struct crypto_testsuite_params *ts_params = &testsuite_params;
7427         struct crypto_unittest_params *ut_params = &unittest_params;
7428         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
7429         int retval;
7430         int to_trn = 0;
7431         int to_trn_tbl[SGL_MAX_NO];
7432         int segs = 1;
7433         unsigned int trn_data = 0;
7434         uint8_t *plaintext, *ciphertext, *auth_tag;
7435
7436         if (fragsz > tdata->plaintext.len)
7437                 fragsz = tdata->plaintext.len;
7438
7439         uint16_t plaintext_len = fragsz;
7440         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7441
7442         if (fragsz_oop > tdata->plaintext.len)
7443                 frag_size_oop = tdata->plaintext.len;
7444
7445         int ecx = 0;
7446         void *digest_mem = NULL;
7447
7448         uint32_t prepend_len = tdata->aad.len;
7449
7450         if (tdata->plaintext.len % fragsz != 0) {
7451                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
7452                         return 1;
7453         }       else {
7454                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
7455                         return 1;
7456         }
7457
7458         /*
7459          * For out-op-place we need to alloc another mbuf
7460          */
7461         if (oop) {
7462                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7463                 rte_pktmbuf_append(ut_params->obuf,
7464                                 frag_size_oop + prepend_len);
7465                 buf_oop = ut_params->obuf;
7466         }
7467
7468         /* Create GCM session */
7469         retval = create_gcm_session(ts_params->valid_devs[0],
7470                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7471                         tdata->key.data, tdata->key.len,
7472                         tdata->aad.len, tdata->auth_tag.len,
7473                         tdata->iv.len);
7474         if (retval < 0)
7475                 return retval;
7476
7477         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7478
7479         /* clear mbuf payload */
7480         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7481                         rte_pktmbuf_tailroom(ut_params->ibuf));
7482
7483         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7484                         plaintext_len);
7485
7486         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7487
7488         trn_data += plaintext_len;
7489
7490         buf = ut_params->ibuf;
7491
7492         /*
7493          * Loop until no more fragments
7494          */
7495
7496         while (trn_data < tdata->plaintext.len) {
7497                 ++segs;
7498                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
7499                                 (tdata->plaintext.len - trn_data) : fragsz;
7500
7501                 to_trn_tbl[ecx++] = to_trn;
7502
7503                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7504                 buf = buf->next;
7505
7506                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7507                                 rte_pktmbuf_tailroom(buf));
7508
7509                 /* OOP */
7510                 if (oop && !fragsz_oop) {
7511                         buf_last_oop = buf_oop->next =
7512                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7513                         buf_oop = buf_oop->next;
7514                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7515                                         0, rte_pktmbuf_tailroom(buf_oop));
7516                         rte_pktmbuf_append(buf_oop, to_trn);
7517                 }
7518
7519                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7520                                 to_trn);
7521
7522                 memcpy(plaintext, tdata->plaintext.data + trn_data,
7523                                 to_trn);
7524                 trn_data += to_trn;
7525                 if (trn_data  == tdata->plaintext.len) {
7526                         if (oop) {
7527                                 if (!fragsz_oop)
7528                                         digest_mem = rte_pktmbuf_append(buf_oop,
7529                                                 tdata->auth_tag.len);
7530                         } else
7531                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
7532                                         tdata->auth_tag.len);
7533                 }
7534         }
7535
7536         uint64_t digest_phys = 0;
7537
7538         ut_params->ibuf->nb_segs = segs;
7539
7540         segs = 1;
7541         if (fragsz_oop && oop) {
7542                 to_trn = 0;
7543                 ecx = 0;
7544
7545                 if (frag_size_oop == tdata->plaintext.len) {
7546                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
7547                                 tdata->auth_tag.len);
7548
7549                         digest_phys = rte_pktmbuf_mtophys_offset(
7550                                         ut_params->obuf,
7551                                         tdata->plaintext.len + prepend_len);
7552                 }
7553
7554                 trn_data = frag_size_oop;
7555                 while (trn_data < tdata->plaintext.len) {
7556                         ++segs;
7557                         to_trn =
7558                                 (tdata->plaintext.len - trn_data <
7559                                                 frag_size_oop) ?
7560                                 (tdata->plaintext.len - trn_data) :
7561                                                 frag_size_oop;
7562
7563                         to_trn_tbl[ecx++] = to_trn;
7564
7565                         buf_last_oop = buf_oop->next =
7566                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7567                         buf_oop = buf_oop->next;
7568                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7569                                         0, rte_pktmbuf_tailroom(buf_oop));
7570                         rte_pktmbuf_append(buf_oop, to_trn);
7571
7572                         trn_data += to_trn;
7573
7574                         if (trn_data  == tdata->plaintext.len) {
7575                                 digest_mem = rte_pktmbuf_append(buf_oop,
7576                                         tdata->auth_tag.len);
7577                         }
7578                 }
7579
7580                 ut_params->obuf->nb_segs = segs;
7581         }
7582
7583         /*
7584          * Place digest at the end of the last buffer
7585          */
7586         if (!digest_phys)
7587                 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
7588         if (oop && buf_last_oop)
7589                 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
7590
7591         if (!digest_mem && !oop) {
7592                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7593                                 + tdata->auth_tag.len);
7594                 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
7595                                 tdata->plaintext.len);
7596         }
7597
7598         /* Create GCM opertaion */
7599         retval = create_gcm_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
7600                         tdata, digest_mem, digest_phys);
7601
7602         if (retval < 0)
7603                 return retval;
7604
7605         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7606
7607         ut_params->op->sym->m_src = ut_params->ibuf;
7608         if (oop)
7609                 ut_params->op->sym->m_dst = ut_params->obuf;
7610
7611         /* Process crypto operation */
7612         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7613                         ut_params->op), "failed to process sym crypto op");
7614
7615         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7616                         "crypto op processing failed");
7617
7618
7619         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7620                         uint8_t *, prepend_len);
7621         if (oop) {
7622                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7623                                 uint8_t *, prepend_len);
7624         }
7625
7626         if (fragsz_oop)
7627                 fragsz = fragsz_oop;
7628
7629         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7630                         ciphertext,
7631                         tdata->ciphertext.data,
7632                         fragsz,
7633                         "GCM Ciphertext data not as expected");
7634
7635         buf = ut_params->op->sym->m_src->next;
7636         if (oop)
7637                 buf = ut_params->op->sym->m_dst->next;
7638
7639         unsigned int off = fragsz;
7640
7641         ecx = 0;
7642         while (buf) {
7643                 ciphertext = rte_pktmbuf_mtod(buf,
7644                                 uint8_t *);
7645
7646                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7647                                 ciphertext,
7648                                 tdata->ciphertext.data + off,
7649                                 to_trn_tbl[ecx],
7650                                 "GCM Ciphertext data not as expected");
7651
7652                 off += to_trn_tbl[ecx++];
7653                 buf = buf->next;
7654         }
7655
7656         auth_tag = digest_mem;
7657         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7658                         auth_tag,
7659                         tdata->auth_tag.data,
7660                         tdata->auth_tag.len,
7661                         "GCM Generated auth tag not as expected");
7662
7663         return 0;
7664 }
7665
7666 #define IN_PLACE        0
7667 #define OUT_OF_PLACE    1
7668
7669 static int
7670 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
7671 {
7672         return test_AES_GCM_authenticated_encryption_SGL(
7673                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
7674 }
7675
7676 static int
7677 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
7678 {
7679         return test_AES_GCM_authenticated_encryption_SGL(
7680                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
7681 }
7682
7683 static int
7684 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
7685 {
7686         return test_AES_GCM_authenticated_encryption_SGL(
7687                         &gcm_test_case_8, OUT_OF_PLACE, 400,
7688                         gcm_test_case_8.plaintext.len);
7689 }
7690
7691 static int
7692 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
7693 {
7694
7695         return test_AES_GCM_authenticated_encryption_SGL(
7696                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
7697 }
7698
7699 static int
7700 test_authentication_verify_fail_when_data_corrupted(
7701                 struct crypto_testsuite_params *ts_params,
7702                 struct crypto_unittest_params *ut_params,
7703                 const struct test_crypto_vector *reference)
7704 {
7705         return test_authentication_verify_fail_when_data_corruption(
7706                         ts_params, ut_params, reference, 1);
7707 }
7708
7709 static int
7710 test_authentication_verify_fail_when_tag_corrupted(
7711                 struct crypto_testsuite_params *ts_params,
7712                 struct crypto_unittest_params *ut_params,
7713                 const struct test_crypto_vector *reference)
7714 {
7715         return test_authentication_verify_fail_when_data_corruption(
7716                         ts_params, ut_params, reference, 0);
7717 }
7718
7719 static int
7720 test_authentication_verify_GMAC_fail_when_data_corrupted(
7721                 struct crypto_testsuite_params *ts_params,
7722                 struct crypto_unittest_params *ut_params,
7723                 const struct test_crypto_vector *reference)
7724 {
7725         return test_authentication_verify_GMAC_fail_when_corruption(
7726                         ts_params, ut_params, reference, 1);
7727 }
7728
7729 static int
7730 test_authentication_verify_GMAC_fail_when_tag_corrupted(
7731                 struct crypto_testsuite_params *ts_params,
7732                 struct crypto_unittest_params *ut_params,
7733                 const struct test_crypto_vector *reference)
7734 {
7735         return test_authentication_verify_GMAC_fail_when_corruption(
7736                         ts_params, ut_params, reference, 0);
7737 }
7738
7739 static int
7740 test_authenticated_decryption_fail_when_data_corrupted(
7741                 struct crypto_testsuite_params *ts_params,
7742                 struct crypto_unittest_params *ut_params,
7743                 const struct test_crypto_vector *reference)
7744 {
7745         return test_authenticated_decryption_fail_when_corruption(
7746                         ts_params, ut_params, reference, 1);
7747 }
7748
7749 static int
7750 test_authenticated_decryption_fail_when_tag_corrupted(
7751                 struct crypto_testsuite_params *ts_params,
7752                 struct crypto_unittest_params *ut_params,
7753                 const struct test_crypto_vector *reference)
7754 {
7755         return test_authenticated_decryption_fail_when_corruption(
7756                         ts_params, ut_params, reference, 0);
7757 }
7758
7759 static int
7760 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
7761 {
7762         return test_authentication_verify_fail_when_data_corrupted(
7763                         &testsuite_params, &unittest_params,
7764                         &hmac_sha1_test_crypto_vector);
7765 }
7766
7767 static int
7768 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
7769 {
7770         return test_authentication_verify_fail_when_tag_corrupted(
7771                         &testsuite_params, &unittest_params,
7772                         &hmac_sha1_test_crypto_vector);
7773 }
7774
7775 static int
7776 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
7777 {
7778         return test_authentication_verify_GMAC_fail_when_data_corrupted(
7779                         &testsuite_params, &unittest_params,
7780                         &aes128_gmac_test_vector);
7781 }
7782
7783 static int
7784 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
7785 {
7786         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
7787                         &testsuite_params, &unittest_params,
7788                         &aes128_gmac_test_vector);
7789 }
7790
7791 static int
7792 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
7793 {
7794         return test_authenticated_decryption_fail_when_data_corrupted(
7795                         &testsuite_params,
7796                         &unittest_params,
7797                         &aes128cbc_hmac_sha1_test_vector);
7798 }
7799
7800 static int
7801 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
7802 {
7803         return test_authenticated_decryption_fail_when_tag_corrupted(
7804                         &testsuite_params,
7805                         &unittest_params,
7806                         &aes128cbc_hmac_sha1_test_vector);
7807 }
7808
7809 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
7810
7811 /* global AESNI slave IDs for the scheduler test */
7812 uint8_t aesni_ids[2];
7813
7814 static int
7815 test_scheduler_attach_slave_op(void)
7816 {
7817         struct crypto_testsuite_params *ts_params = &testsuite_params;
7818         uint8_t sched_id = ts_params->valid_devs[0];
7819         uint32_t nb_devs, i, nb_devs_attached = 0;
7820         int ret;
7821         char vdev_name[32];
7822
7823         /* create 2 AESNI_MB if necessary */
7824         nb_devs = rte_cryptodev_device_count_by_driver(
7825                         rte_cryptodev_driver_id_get(
7826                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
7827         if (nb_devs < 2) {
7828                 for (i = nb_devs; i < 2; i++) {
7829                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
7830                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
7831                                         i);
7832                         ret = rte_vdev_init(vdev_name, NULL);
7833
7834                         TEST_ASSERT(ret == 0,
7835                                 "Failed to create instance %u of"
7836                                 " pmd : %s",
7837                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7838                 }
7839         }
7840
7841         /* attach 2 AESNI_MB cdevs */
7842         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
7843                         i++) {
7844                 struct rte_cryptodev_info info;
7845
7846                 rte_cryptodev_info_get(i, &info);
7847                 if (info.driver_id != rte_cryptodev_driver_id_get(
7848                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
7849                         continue;
7850
7851                 /*
7852                  * Create the session mempool again, since now there are new devices
7853                  * to use the mempool.
7854                  */
7855                 if (ts_params->session_mpool) {
7856                         rte_mempool_free(ts_params->session_mpool);
7857                         ts_params->session_mpool = NULL;
7858                 }
7859                 unsigned int session_size = rte_cryptodev_get_private_session_size(i);
7860
7861                 /*
7862                  * Create mempool with maximum number of sessions * 2,
7863                  * to include the session headers
7864                  */
7865                 if (ts_params->session_mpool == NULL) {
7866                         ts_params->session_mpool = rte_mempool_create(
7867                                         "test_sess_mp",
7868                                         info.sym.max_nb_sessions * 2,
7869                                         session_size,
7870                                         0, 0, NULL, NULL, NULL,
7871                                         NULL, SOCKET_ID_ANY,
7872                                         0);
7873
7874                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
7875                                         "session mempool allocation failed");
7876                 }
7877
7878                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
7879                                 (uint8_t)i);
7880
7881                 TEST_ASSERT(ret == 0,
7882                         "Failed to attach device %u of pmd : %s", i,
7883                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7884
7885                 aesni_ids[nb_devs_attached] = (uint8_t)i;
7886
7887                 nb_devs_attached++;
7888         }
7889
7890         return 0;
7891 }
7892
7893 static int
7894 test_scheduler_detach_slave_op(void)
7895 {
7896         struct crypto_testsuite_params *ts_params = &testsuite_params;
7897         uint8_t sched_id = ts_params->valid_devs[0];
7898         uint32_t i;
7899         int ret;
7900
7901         for (i = 0; i < 2; i++) {
7902                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
7903                                 aesni_ids[i]);
7904                 TEST_ASSERT(ret == 0,
7905                         "Failed to detach device %u", aesni_ids[i]);
7906         }
7907
7908         return 0;
7909 }
7910
7911 static int
7912 test_scheduler_mode_op(void)
7913 {
7914         struct crypto_testsuite_params *ts_params = &testsuite_params;
7915         uint8_t sched_id = ts_params->valid_devs[0];
7916         struct rte_cryptodev_scheduler_ops op = {0};
7917         struct rte_cryptodev_scheduler dummy_scheduler = {
7918                 .description = "dummy scheduler to test mode",
7919                 .name = "dummy scheduler",
7920                 .mode = CDEV_SCHED_MODE_USERDEFINED,
7921                 .ops = &op
7922         };
7923         int ret;
7924
7925         /* set user defined mode */
7926         ret = rte_cryptodev_scheduler_load_user_scheduler(sched_id,
7927                         &dummy_scheduler);
7928         TEST_ASSERT(ret == 0,
7929                 "Failed to set cdev %u to user defined mode", sched_id);
7930
7931         /* set round robin mode */
7932         ret = rte_cryptodev_scheduler_mode_set(sched_id,
7933                         CDEV_SCHED_MODE_ROUNDROBIN);
7934         TEST_ASSERT(ret == 0,
7935                 "Failed to set cdev %u to round-robin mode", sched_id);
7936         TEST_ASSERT(rte_cryptodev_scheduler_mode_get(sched_id) ==
7937                         CDEV_SCHED_MODE_ROUNDROBIN, "Scheduling Mode "
7938                                         "not match");
7939
7940         return 0;
7941 }
7942
7943 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
7944         .suite_name = "Crypto Device Scheduler Unit Test Suite",
7945         .setup = testsuite_setup,
7946         .teardown = testsuite_teardown,
7947         .unit_test_cases = {
7948                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
7949                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_op),
7950                 TEST_CASE_ST(ut_setup, ut_teardown,
7951                                 test_AES_chain_scheduler_all),
7952                 TEST_CASE_ST(ut_setup, ut_teardown,
7953                                 test_AES_cipheronly_scheduler_all),
7954                 TEST_CASE_ST(ut_setup, ut_teardown,
7955                                 test_authonly_scheduler_all),
7956                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
7957                 TEST_CASES_END() /**< NULL terminate unit test array */
7958         }
7959 };
7960
7961 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
7962
7963 static struct unit_test_suite cryptodev_qat_testsuite  = {
7964         .suite_name = "Crypto QAT Unit Test Suite",
7965         .setup = testsuite_setup,
7966         .teardown = testsuite_teardown,
7967         .unit_test_cases = {
7968                 TEST_CASE_ST(ut_setup, ut_teardown,
7969                                 test_device_configure_invalid_dev_id),
7970                 TEST_CASE_ST(ut_setup, ut_teardown,
7971                                 test_device_configure_invalid_queue_pair_ids),
7972                 TEST_CASE_ST(ut_setup, ut_teardown,
7973                                 test_queue_pair_descriptor_setup),
7974                 TEST_CASE_ST(ut_setup, ut_teardown,
7975                                 test_multi_session),
7976
7977                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
7978                 TEST_CASE_ST(ut_setup, ut_teardown,
7979                                                 test_AES_cipheronly_qat_all),
7980                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
7981                 TEST_CASE_ST(ut_setup, ut_teardown,
7982                                                 test_3DES_cipheronly_qat_all),
7983                 TEST_CASE_ST(ut_setup, ut_teardown,
7984                                                 test_DES_cipheronly_qat_all),
7985                 TEST_CASE_ST(ut_setup, ut_teardown,
7986                                                 test_AES_docsis_qat_all),
7987                 TEST_CASE_ST(ut_setup, ut_teardown,
7988                                                 test_DES_docsis_qat_all),
7989                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
7990
7991                 /** AES GCM Authenticated Encryption */
7992                 TEST_CASE_ST(ut_setup, ut_teardown,
7993                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
7994                 TEST_CASE_ST(ut_setup, ut_teardown,
7995                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
7996                 TEST_CASE_ST(ut_setup, ut_teardown,
7997                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
7998                 TEST_CASE_ST(ut_setup, ut_teardown,
7999                         test_AES_GCM_authenticated_encryption_test_case_1),
8000                 TEST_CASE_ST(ut_setup, ut_teardown,
8001                         test_AES_GCM_authenticated_encryption_test_case_2),
8002                 TEST_CASE_ST(ut_setup, ut_teardown,
8003                         test_AES_GCM_authenticated_encryption_test_case_3),
8004                 TEST_CASE_ST(ut_setup, ut_teardown,
8005                         test_AES_GCM_authenticated_encryption_test_case_4),
8006                 TEST_CASE_ST(ut_setup, ut_teardown,
8007                         test_AES_GCM_authenticated_encryption_test_case_5),
8008                 TEST_CASE_ST(ut_setup, ut_teardown,
8009                         test_AES_GCM_authenticated_encryption_test_case_6),
8010                 TEST_CASE_ST(ut_setup, ut_teardown,
8011                         test_AES_GCM_authenticated_encryption_test_case_7),
8012
8013                 /** AES GCM Authenticated Decryption */
8014                 TEST_CASE_ST(ut_setup, ut_teardown,
8015                         test_AES_GCM_authenticated_decryption_test_case_1),
8016                 TEST_CASE_ST(ut_setup, ut_teardown,
8017                         test_AES_GCM_authenticated_decryption_test_case_2),
8018                 TEST_CASE_ST(ut_setup, ut_teardown,
8019                         test_AES_GCM_authenticated_decryption_test_case_3),
8020                 TEST_CASE_ST(ut_setup, ut_teardown,
8021                         test_AES_GCM_authenticated_decryption_test_case_4),
8022                 TEST_CASE_ST(ut_setup, ut_teardown,
8023                         test_AES_GCM_authenticated_decryption_test_case_5),
8024                 TEST_CASE_ST(ut_setup, ut_teardown,
8025                         test_AES_GCM_authenticated_decryption_test_case_6),
8026                 TEST_CASE_ST(ut_setup, ut_teardown,
8027                         test_AES_GCM_authenticated_decryption_test_case_7),
8028
8029                 /** AES GCM Authenticated Encryption 192 bits key */
8030                 TEST_CASE_ST(ut_setup, ut_teardown,
8031                         test_AES_GCM_auth_encryption_test_case_192_1),
8032                 TEST_CASE_ST(ut_setup, ut_teardown,
8033                         test_AES_GCM_auth_encryption_test_case_192_2),
8034                 TEST_CASE_ST(ut_setup, ut_teardown,
8035                         test_AES_GCM_auth_encryption_test_case_192_3),
8036                 TEST_CASE_ST(ut_setup, ut_teardown,
8037                         test_AES_GCM_auth_encryption_test_case_192_4),
8038                 TEST_CASE_ST(ut_setup, ut_teardown,
8039                         test_AES_GCM_auth_encryption_test_case_192_5),
8040                 TEST_CASE_ST(ut_setup, ut_teardown,
8041                         test_AES_GCM_auth_encryption_test_case_192_6),
8042                 TEST_CASE_ST(ut_setup, ut_teardown,
8043                         test_AES_GCM_auth_encryption_test_case_192_7),
8044
8045                 /** AES GCM Authenticated Decryption 192 bits key */
8046                 TEST_CASE_ST(ut_setup, ut_teardown,
8047                         test_AES_GCM_auth_decryption_test_case_192_1),
8048                 TEST_CASE_ST(ut_setup, ut_teardown,
8049                         test_AES_GCM_auth_decryption_test_case_192_2),
8050                 TEST_CASE_ST(ut_setup, ut_teardown,
8051                         test_AES_GCM_auth_decryption_test_case_192_3),
8052                 TEST_CASE_ST(ut_setup, ut_teardown,
8053                         test_AES_GCM_auth_decryption_test_case_192_4),
8054                 TEST_CASE_ST(ut_setup, ut_teardown,
8055                         test_AES_GCM_auth_decryption_test_case_192_5),
8056                 TEST_CASE_ST(ut_setup, ut_teardown,
8057                         test_AES_GCM_auth_decryption_test_case_192_6),
8058                 TEST_CASE_ST(ut_setup, ut_teardown,
8059                         test_AES_GCM_auth_decryption_test_case_192_7),
8060
8061                 /** AES GCM Authenticated Encryption 256 bits key */
8062                 TEST_CASE_ST(ut_setup, ut_teardown,
8063                         test_AES_GCM_auth_encryption_test_case_256_1),
8064                 TEST_CASE_ST(ut_setup, ut_teardown,
8065                         test_AES_GCM_auth_encryption_test_case_256_2),
8066                 TEST_CASE_ST(ut_setup, ut_teardown,
8067                         test_AES_GCM_auth_encryption_test_case_256_3),
8068                 TEST_CASE_ST(ut_setup, ut_teardown,
8069                         test_AES_GCM_auth_encryption_test_case_256_4),
8070                 TEST_CASE_ST(ut_setup, ut_teardown,
8071                         test_AES_GCM_auth_encryption_test_case_256_5),
8072                 TEST_CASE_ST(ut_setup, ut_teardown,
8073                         test_AES_GCM_auth_encryption_test_case_256_6),
8074                 TEST_CASE_ST(ut_setup, ut_teardown,
8075                         test_AES_GCM_auth_encryption_test_case_256_7),
8076
8077                 /** AES GMAC Authentication */
8078                 TEST_CASE_ST(ut_setup, ut_teardown,
8079                         test_AES_GMAC_authentication_test_case_1),
8080                 TEST_CASE_ST(ut_setup, ut_teardown,
8081                         test_AES_GMAC_authentication_verify_test_case_1),
8082                 TEST_CASE_ST(ut_setup, ut_teardown,
8083                         test_AES_GMAC_authentication_test_case_2),
8084                 TEST_CASE_ST(ut_setup, ut_teardown,
8085                         test_AES_GMAC_authentication_verify_test_case_2),
8086                 TEST_CASE_ST(ut_setup, ut_teardown,
8087                         test_AES_GMAC_authentication_test_case_3),
8088                 TEST_CASE_ST(ut_setup, ut_teardown,
8089                         test_AES_GMAC_authentication_verify_test_case_3),
8090
8091                 /** SNOW 3G encrypt only (UEA2) */
8092                 TEST_CASE_ST(ut_setup, ut_teardown,
8093                         test_snow3g_encryption_test_case_1),
8094                 TEST_CASE_ST(ut_setup, ut_teardown,
8095                         test_snow3g_encryption_test_case_2),
8096                 TEST_CASE_ST(ut_setup, ut_teardown,
8097                         test_snow3g_encryption_test_case_3),
8098                 TEST_CASE_ST(ut_setup, ut_teardown,
8099                         test_snow3g_encryption_test_case_4),
8100                 TEST_CASE_ST(ut_setup, ut_teardown,
8101                         test_snow3g_encryption_test_case_5),
8102
8103                 TEST_CASE_ST(ut_setup, ut_teardown,
8104                         test_snow3g_encryption_test_case_1_oop),
8105                 TEST_CASE_ST(ut_setup, ut_teardown,
8106                         test_snow3g_decryption_test_case_1_oop),
8107
8108                 /** SNOW 3G decrypt only (UEA2) */
8109                 TEST_CASE_ST(ut_setup, ut_teardown,
8110                         test_snow3g_decryption_test_case_1),
8111                 TEST_CASE_ST(ut_setup, ut_teardown,
8112                         test_snow3g_decryption_test_case_2),
8113                 TEST_CASE_ST(ut_setup, ut_teardown,
8114                         test_snow3g_decryption_test_case_3),
8115                 TEST_CASE_ST(ut_setup, ut_teardown,
8116                         test_snow3g_decryption_test_case_4),
8117                 TEST_CASE_ST(ut_setup, ut_teardown,
8118                         test_snow3g_decryption_test_case_5),
8119                 TEST_CASE_ST(ut_setup, ut_teardown,
8120                         test_snow3g_hash_generate_test_case_1),
8121                 TEST_CASE_ST(ut_setup, ut_teardown,
8122                         test_snow3g_hash_generate_test_case_2),
8123                 TEST_CASE_ST(ut_setup, ut_teardown,
8124                         test_snow3g_hash_generate_test_case_3),
8125                 TEST_CASE_ST(ut_setup, ut_teardown,
8126                         test_snow3g_hash_verify_test_case_1),
8127                 TEST_CASE_ST(ut_setup, ut_teardown,
8128                         test_snow3g_hash_verify_test_case_2),
8129                 TEST_CASE_ST(ut_setup, ut_teardown,
8130                         test_snow3g_hash_verify_test_case_3),
8131                 TEST_CASE_ST(ut_setup, ut_teardown,
8132                         test_snow3g_cipher_auth_test_case_1),
8133                 TEST_CASE_ST(ut_setup, ut_teardown,
8134                         test_snow3g_auth_cipher_test_case_1),
8135
8136                 /** ZUC encrypt only (EEA3) */
8137                 TEST_CASE_ST(ut_setup, ut_teardown,
8138                         test_zuc_encryption_test_case_1),
8139                 TEST_CASE_ST(ut_setup, ut_teardown,
8140                         test_zuc_encryption_test_case_2),
8141                 TEST_CASE_ST(ut_setup, ut_teardown,
8142                         test_zuc_encryption_test_case_3),
8143                 TEST_CASE_ST(ut_setup, ut_teardown,
8144                         test_zuc_encryption_test_case_4),
8145                 TEST_CASE_ST(ut_setup, ut_teardown,
8146                         test_zuc_encryption_test_case_5),
8147
8148                 /** ZUC authenticate (EIA3) */
8149                 TEST_CASE_ST(ut_setup, ut_teardown,
8150                         test_zuc_hash_generate_test_case_6),
8151                 TEST_CASE_ST(ut_setup, ut_teardown,
8152                         test_zuc_hash_generate_test_case_7),
8153                 TEST_CASE_ST(ut_setup, ut_teardown,
8154                         test_zuc_hash_generate_test_case_8),
8155
8156                 /** ZUC alg-chain (EEA3/EIA3) */
8157                 TEST_CASE_ST(ut_setup, ut_teardown,
8158                         test_zuc_cipher_auth_test_case_1),
8159                 TEST_CASE_ST(ut_setup, ut_teardown,
8160                         test_zuc_cipher_auth_test_case_2),
8161
8162                 /** HMAC_MD5 Authentication */
8163                 TEST_CASE_ST(ut_setup, ut_teardown,
8164                         test_MD5_HMAC_generate_case_1),
8165                 TEST_CASE_ST(ut_setup, ut_teardown,
8166                         test_MD5_HMAC_verify_case_1),
8167                 TEST_CASE_ST(ut_setup, ut_teardown,
8168                         test_MD5_HMAC_generate_case_2),
8169                 TEST_CASE_ST(ut_setup, ut_teardown,
8170                         test_MD5_HMAC_verify_case_2),
8171
8172                 /** NULL tests */
8173                 TEST_CASE_ST(ut_setup, ut_teardown,
8174                         test_null_auth_only_operation),
8175                 TEST_CASE_ST(ut_setup, ut_teardown,
8176                         test_null_cipher_only_operation),
8177                 TEST_CASE_ST(ut_setup, ut_teardown,
8178                         test_null_cipher_auth_operation),
8179                 TEST_CASE_ST(ut_setup, ut_teardown,
8180                         test_null_auth_cipher_operation),
8181
8182                 TEST_CASE_ST(ut_setup, ut_teardown,
8183                         test_kasumi_hash_generate_test_case_6),
8184
8185                 /** KASUMI tests */
8186                 TEST_CASE_ST(ut_setup, ut_teardown,
8187                         test_kasumi_encryption_test_case_1),
8188                 TEST_CASE_ST(ut_setup, ut_teardown,
8189                         test_kasumi_encryption_test_case_3),
8190                 TEST_CASE_ST(ut_setup, ut_teardown,
8191                         test_kasumi_auth_cipher_test_case_1),
8192                 TEST_CASE_ST(ut_setup, ut_teardown,
8193                         test_kasumi_cipher_auth_test_case_1),
8194
8195                 /** Negative tests */
8196                 TEST_CASE_ST(ut_setup, ut_teardown,
8197                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
8198                 TEST_CASE_ST(ut_setup, ut_teardown,
8199                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8200                 TEST_CASE_ST(ut_setup, ut_teardown,
8201                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8202                 TEST_CASE_ST(ut_setup, ut_teardown,
8203                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
8204                 TEST_CASE_ST(ut_setup, ut_teardown,
8205                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8206                 TEST_CASE_ST(ut_setup, ut_teardown,
8207                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8208
8209                 TEST_CASES_END() /**< NULL terminate unit test array */
8210         }
8211 };
8212
8213 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
8214         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
8215         .setup = testsuite_setup,
8216         .teardown = testsuite_teardown,
8217         .unit_test_cases = {
8218                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
8219                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
8220                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
8221                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
8222
8223                 TEST_CASES_END() /**< NULL terminate unit test array */
8224         }
8225 };
8226
8227 static struct unit_test_suite cryptodev_openssl_testsuite  = {
8228         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
8229         .setup = testsuite_setup,
8230         .teardown = testsuite_teardown,
8231         .unit_test_cases = {
8232                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
8233                 TEST_CASE_ST(ut_setup, ut_teardown,
8234                                 test_multi_session_random_usage),
8235                 TEST_CASE_ST(ut_setup, ut_teardown,
8236                                 test_AES_chain_openssl_all),
8237                 TEST_CASE_ST(ut_setup, ut_teardown,
8238                                 test_AES_cipheronly_openssl_all),
8239                 TEST_CASE_ST(ut_setup, ut_teardown,
8240                                 test_3DES_chain_openssl_all),
8241                 TEST_CASE_ST(ut_setup, ut_teardown,
8242                                 test_3DES_cipheronly_openssl_all),
8243                 TEST_CASE_ST(ut_setup, ut_teardown,
8244                                 test_DES_docsis_openssl_all),
8245                 TEST_CASE_ST(ut_setup, ut_teardown,
8246                                 test_authonly_openssl_all),
8247
8248                 /** AES GCM Authenticated Encryption */
8249                 TEST_CASE_ST(ut_setup, ut_teardown,
8250                         test_AES_GCM_authenticated_encryption_test_case_1),
8251                 TEST_CASE_ST(ut_setup, ut_teardown,
8252                         test_AES_GCM_authenticated_encryption_test_case_2),
8253                 TEST_CASE_ST(ut_setup, ut_teardown,
8254                         test_AES_GCM_authenticated_encryption_test_case_3),
8255                 TEST_CASE_ST(ut_setup, ut_teardown,
8256                         test_AES_GCM_authenticated_encryption_test_case_4),
8257                 TEST_CASE_ST(ut_setup, ut_teardown,
8258                         test_AES_GCM_authenticated_encryption_test_case_5),
8259                 TEST_CASE_ST(ut_setup, ut_teardown,
8260                         test_AES_GCM_authenticated_encryption_test_case_6),
8261                 TEST_CASE_ST(ut_setup, ut_teardown,
8262                         test_AES_GCM_authenticated_encryption_test_case_7),
8263
8264                 /** AES GCM Authenticated Decryption */
8265                 TEST_CASE_ST(ut_setup, ut_teardown,
8266                         test_AES_GCM_authenticated_decryption_test_case_1),
8267                 TEST_CASE_ST(ut_setup, ut_teardown,
8268                         test_AES_GCM_authenticated_decryption_test_case_2),
8269                 TEST_CASE_ST(ut_setup, ut_teardown,
8270                         test_AES_GCM_authenticated_decryption_test_case_3),
8271                 TEST_CASE_ST(ut_setup, ut_teardown,
8272                         test_AES_GCM_authenticated_decryption_test_case_4),
8273                 TEST_CASE_ST(ut_setup, ut_teardown,
8274                         test_AES_GCM_authenticated_decryption_test_case_5),
8275                 TEST_CASE_ST(ut_setup, ut_teardown,
8276                         test_AES_GCM_authenticated_decryption_test_case_6),
8277                 TEST_CASE_ST(ut_setup, ut_teardown,
8278                         test_AES_GCM_authenticated_decryption_test_case_7),
8279
8280
8281                 /** AES GCM Authenticated Encryption 192 bits key */
8282                 TEST_CASE_ST(ut_setup, ut_teardown,
8283                         test_AES_GCM_auth_encryption_test_case_192_1),
8284                 TEST_CASE_ST(ut_setup, ut_teardown,
8285                         test_AES_GCM_auth_encryption_test_case_192_2),
8286                 TEST_CASE_ST(ut_setup, ut_teardown,
8287                         test_AES_GCM_auth_encryption_test_case_192_3),
8288                 TEST_CASE_ST(ut_setup, ut_teardown,
8289                         test_AES_GCM_auth_encryption_test_case_192_4),
8290                 TEST_CASE_ST(ut_setup, ut_teardown,
8291                         test_AES_GCM_auth_encryption_test_case_192_5),
8292                 TEST_CASE_ST(ut_setup, ut_teardown,
8293                         test_AES_GCM_auth_encryption_test_case_192_6),
8294                 TEST_CASE_ST(ut_setup, ut_teardown,
8295                         test_AES_GCM_auth_encryption_test_case_192_7),
8296
8297                 /** AES GCM Authenticated Decryption 192 bits key */
8298                 TEST_CASE_ST(ut_setup, ut_teardown,
8299                         test_AES_GCM_auth_decryption_test_case_192_1),
8300                 TEST_CASE_ST(ut_setup, ut_teardown,
8301                         test_AES_GCM_auth_decryption_test_case_192_2),
8302                 TEST_CASE_ST(ut_setup, ut_teardown,
8303                         test_AES_GCM_auth_decryption_test_case_192_3),
8304                 TEST_CASE_ST(ut_setup, ut_teardown,
8305                         test_AES_GCM_auth_decryption_test_case_192_4),
8306                 TEST_CASE_ST(ut_setup, ut_teardown,
8307                         test_AES_GCM_auth_decryption_test_case_192_5),
8308                 TEST_CASE_ST(ut_setup, ut_teardown,
8309                         test_AES_GCM_auth_decryption_test_case_192_6),
8310                 TEST_CASE_ST(ut_setup, ut_teardown,
8311                         test_AES_GCM_auth_decryption_test_case_192_7),
8312
8313                 /** AES GCM Authenticated Encryption 256 bits key */
8314                 TEST_CASE_ST(ut_setup, ut_teardown,
8315                         test_AES_GCM_auth_encryption_test_case_256_1),
8316                 TEST_CASE_ST(ut_setup, ut_teardown,
8317                         test_AES_GCM_auth_encryption_test_case_256_2),
8318                 TEST_CASE_ST(ut_setup, ut_teardown,
8319                         test_AES_GCM_auth_encryption_test_case_256_3),
8320                 TEST_CASE_ST(ut_setup, ut_teardown,
8321                         test_AES_GCM_auth_encryption_test_case_256_4),
8322                 TEST_CASE_ST(ut_setup, ut_teardown,
8323                         test_AES_GCM_auth_encryption_test_case_256_5),
8324                 TEST_CASE_ST(ut_setup, ut_teardown,
8325                         test_AES_GCM_auth_encryption_test_case_256_6),
8326                 TEST_CASE_ST(ut_setup, ut_teardown,
8327                         test_AES_GCM_auth_encryption_test_case_256_7),
8328
8329                 /** AES GCM Authenticated Decryption 256 bits key */
8330                 TEST_CASE_ST(ut_setup, ut_teardown,
8331                         test_AES_GCM_auth_decryption_test_case_256_1),
8332                 TEST_CASE_ST(ut_setup, ut_teardown,
8333                         test_AES_GCM_auth_decryption_test_case_256_2),
8334                 TEST_CASE_ST(ut_setup, ut_teardown,
8335                         test_AES_GCM_auth_decryption_test_case_256_3),
8336                 TEST_CASE_ST(ut_setup, ut_teardown,
8337                         test_AES_GCM_auth_decryption_test_case_256_4),
8338                 TEST_CASE_ST(ut_setup, ut_teardown,
8339                         test_AES_GCM_auth_decryption_test_case_256_5),
8340                 TEST_CASE_ST(ut_setup, ut_teardown,
8341                         test_AES_GCM_auth_decryption_test_case_256_6),
8342                 TEST_CASE_ST(ut_setup, ut_teardown,
8343                         test_AES_GCM_auth_decryption_test_case_256_7),
8344
8345                 /** AES GMAC Authentication */
8346                 TEST_CASE_ST(ut_setup, ut_teardown,
8347                         test_AES_GMAC_authentication_test_case_1),
8348                 TEST_CASE_ST(ut_setup, ut_teardown,
8349                         test_AES_GMAC_authentication_verify_test_case_1),
8350                 TEST_CASE_ST(ut_setup, ut_teardown,
8351                         test_AES_GMAC_authentication_test_case_2),
8352                 TEST_CASE_ST(ut_setup, ut_teardown,
8353                         test_AES_GMAC_authentication_verify_test_case_2),
8354                 TEST_CASE_ST(ut_setup, ut_teardown,
8355                         test_AES_GMAC_authentication_test_case_3),
8356                 TEST_CASE_ST(ut_setup, ut_teardown,
8357                         test_AES_GMAC_authentication_verify_test_case_3),
8358                 TEST_CASE_ST(ut_setup, ut_teardown,
8359                         test_AES_GMAC_authentication_test_case_4),
8360                 TEST_CASE_ST(ut_setup, ut_teardown,
8361                         test_AES_GMAC_authentication_verify_test_case_4),
8362
8363                 /** Scatter-Gather */
8364                 TEST_CASE_ST(ut_setup, ut_teardown,
8365                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
8366
8367                 /** Negative tests */
8368                 TEST_CASE_ST(ut_setup, ut_teardown,
8369                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
8370                 TEST_CASE_ST(ut_setup, ut_teardown,
8371                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8372                 TEST_CASE_ST(ut_setup, ut_teardown,
8373                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8374                 TEST_CASE_ST(ut_setup, ut_teardown,
8375                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
8376                 TEST_CASE_ST(ut_setup, ut_teardown,
8377                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8378                 TEST_CASE_ST(ut_setup, ut_teardown,
8379                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8380
8381                 TEST_CASES_END() /**< NULL terminate unit test array */
8382         }
8383 };
8384
8385 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
8386         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
8387         .setup = testsuite_setup,
8388         .teardown = testsuite_teardown,
8389         .unit_test_cases = {
8390                 /** AES GCM Authenticated Encryption */
8391                 TEST_CASE_ST(ut_setup, ut_teardown,
8392                         test_AES_GCM_authenticated_encryption_test_case_1),
8393                 TEST_CASE_ST(ut_setup, ut_teardown,
8394                         test_AES_GCM_authenticated_encryption_test_case_2),
8395                 TEST_CASE_ST(ut_setup, ut_teardown,
8396                         test_AES_GCM_authenticated_encryption_test_case_3),
8397                 TEST_CASE_ST(ut_setup, ut_teardown,
8398                         test_AES_GCM_authenticated_encryption_test_case_4),
8399                 TEST_CASE_ST(ut_setup, ut_teardown,
8400                         test_AES_GCM_authenticated_encryption_test_case_5),
8401                 TEST_CASE_ST(ut_setup, ut_teardown,
8402                         test_AES_GCM_authenticated_encryption_test_case_6),
8403                 TEST_CASE_ST(ut_setup, ut_teardown,
8404                         test_AES_GCM_authenticated_encryption_test_case_7),
8405
8406                 /** AES GCM Authenticated Decryption */
8407                 TEST_CASE_ST(ut_setup, ut_teardown,
8408                         test_AES_GCM_authenticated_decryption_test_case_1),
8409                 TEST_CASE_ST(ut_setup, ut_teardown,
8410                         test_AES_GCM_authenticated_decryption_test_case_2),
8411                 TEST_CASE_ST(ut_setup, ut_teardown,
8412                         test_AES_GCM_authenticated_decryption_test_case_3),
8413                 TEST_CASE_ST(ut_setup, ut_teardown,
8414                         test_AES_GCM_authenticated_decryption_test_case_4),
8415                 TEST_CASE_ST(ut_setup, ut_teardown,
8416                         test_AES_GCM_authenticated_decryption_test_case_5),
8417                 TEST_CASE_ST(ut_setup, ut_teardown,
8418                         test_AES_GCM_authenticated_decryption_test_case_6),
8419                 TEST_CASE_ST(ut_setup, ut_teardown,
8420                         test_AES_GCM_authenticated_decryption_test_case_7),
8421
8422                 /** AES GCM Authenticated Encryption 192 bits key */
8423                 TEST_CASE_ST(ut_setup, ut_teardown,
8424                         test_AES_GCM_auth_encryption_test_case_192_1),
8425                 TEST_CASE_ST(ut_setup, ut_teardown,
8426                         test_AES_GCM_auth_encryption_test_case_192_2),
8427                 TEST_CASE_ST(ut_setup, ut_teardown,
8428                         test_AES_GCM_auth_encryption_test_case_192_3),
8429                 TEST_CASE_ST(ut_setup, ut_teardown,
8430                         test_AES_GCM_auth_encryption_test_case_192_4),
8431                 TEST_CASE_ST(ut_setup, ut_teardown,
8432                         test_AES_GCM_auth_encryption_test_case_192_5),
8433                 TEST_CASE_ST(ut_setup, ut_teardown,
8434                         test_AES_GCM_auth_encryption_test_case_192_6),
8435                 TEST_CASE_ST(ut_setup, ut_teardown,
8436                         test_AES_GCM_auth_encryption_test_case_192_7),
8437
8438                 /** AES GCM Authenticated Decryption 192 bits key */
8439                 TEST_CASE_ST(ut_setup, ut_teardown,
8440                         test_AES_GCM_auth_decryption_test_case_192_1),
8441                 TEST_CASE_ST(ut_setup, ut_teardown,
8442                         test_AES_GCM_auth_decryption_test_case_192_2),
8443                 TEST_CASE_ST(ut_setup, ut_teardown,
8444                         test_AES_GCM_auth_decryption_test_case_192_3),
8445                 TEST_CASE_ST(ut_setup, ut_teardown,
8446                         test_AES_GCM_auth_decryption_test_case_192_4),
8447                 TEST_CASE_ST(ut_setup, ut_teardown,
8448                         test_AES_GCM_auth_decryption_test_case_192_5),
8449                 TEST_CASE_ST(ut_setup, ut_teardown,
8450                         test_AES_GCM_auth_decryption_test_case_192_6),
8451                 TEST_CASE_ST(ut_setup, ut_teardown,
8452                         test_AES_GCM_auth_decryption_test_case_192_7),
8453
8454                 /** AES GCM Authenticated Encryption 256 bits key */
8455                 TEST_CASE_ST(ut_setup, ut_teardown,
8456                         test_AES_GCM_auth_encryption_test_case_256_1),
8457                 TEST_CASE_ST(ut_setup, ut_teardown,
8458                         test_AES_GCM_auth_encryption_test_case_256_2),
8459                 TEST_CASE_ST(ut_setup, ut_teardown,
8460                         test_AES_GCM_auth_encryption_test_case_256_3),
8461                 TEST_CASE_ST(ut_setup, ut_teardown,
8462                         test_AES_GCM_auth_encryption_test_case_256_4),
8463                 TEST_CASE_ST(ut_setup, ut_teardown,
8464                         test_AES_GCM_auth_encryption_test_case_256_5),
8465                 TEST_CASE_ST(ut_setup, ut_teardown,
8466                         test_AES_GCM_auth_encryption_test_case_256_6),
8467                 TEST_CASE_ST(ut_setup, ut_teardown,
8468                         test_AES_GCM_auth_encryption_test_case_256_7),
8469
8470                 /** AES GCM Authenticated Decryption 256 bits key */
8471                 TEST_CASE_ST(ut_setup, ut_teardown,
8472                         test_AES_GCM_auth_decryption_test_case_256_1),
8473                 TEST_CASE_ST(ut_setup, ut_teardown,
8474                         test_AES_GCM_auth_decryption_test_case_256_2),
8475                 TEST_CASE_ST(ut_setup, ut_teardown,
8476                         test_AES_GCM_auth_decryption_test_case_256_3),
8477                 TEST_CASE_ST(ut_setup, ut_teardown,
8478                         test_AES_GCM_auth_decryption_test_case_256_4),
8479                 TEST_CASE_ST(ut_setup, ut_teardown,
8480                         test_AES_GCM_auth_decryption_test_case_256_5),
8481                 TEST_CASE_ST(ut_setup, ut_teardown,
8482                         test_AES_GCM_auth_decryption_test_case_256_6),
8483                 TEST_CASE_ST(ut_setup, ut_teardown,
8484                         test_AES_GCM_auth_decryption_test_case_256_7),
8485
8486                 /** AES GCM Authenticated Encryption big aad size */
8487                 TEST_CASE_ST(ut_setup, ut_teardown,
8488                         test_AES_GCM_auth_encryption_test_case_aad_1),
8489                 TEST_CASE_ST(ut_setup, ut_teardown,
8490                         test_AES_GCM_auth_encryption_test_case_aad_2),
8491
8492                 /** AES GCM Authenticated Decryption big aad size */
8493                 TEST_CASE_ST(ut_setup, ut_teardown,
8494                         test_AES_GCM_auth_decryption_test_case_aad_1),
8495                 TEST_CASE_ST(ut_setup, ut_teardown,
8496                         test_AES_GCM_auth_decryption_test_case_aad_2),
8497
8498                 /** AES GMAC Authentication */
8499                 TEST_CASE_ST(ut_setup, ut_teardown,
8500                         test_AES_GMAC_authentication_test_case_1),
8501                 TEST_CASE_ST(ut_setup, ut_teardown,
8502                         test_AES_GMAC_authentication_verify_test_case_1),
8503                 TEST_CASE_ST(ut_setup, ut_teardown,
8504                         test_AES_GMAC_authentication_test_case_3),
8505                 TEST_CASE_ST(ut_setup, ut_teardown,
8506                         test_AES_GMAC_authentication_verify_test_case_3),
8507                 TEST_CASE_ST(ut_setup, ut_teardown,
8508                         test_AES_GMAC_authentication_test_case_4),
8509                 TEST_CASE_ST(ut_setup, ut_teardown,
8510                         test_AES_GMAC_authentication_verify_test_case_4),
8511
8512                 /** Negative tests */
8513                 TEST_CASE_ST(ut_setup, ut_teardown,
8514                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8515                 TEST_CASE_ST(ut_setup, ut_teardown,
8516                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
8517
8518                 /** Out of place tests */
8519                 TEST_CASE_ST(ut_setup, ut_teardown,
8520                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
8521                 TEST_CASE_ST(ut_setup, ut_teardown,
8522                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
8523
8524                 /** Session-less tests */
8525                 TEST_CASE_ST(ut_setup, ut_teardown,
8526                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
8527                 TEST_CASE_ST(ut_setup, ut_teardown,
8528                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
8529
8530                 /** Scatter-Gather */
8531                 TEST_CASE_ST(ut_setup, ut_teardown,
8532                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
8533
8534                 TEST_CASES_END() /**< NULL terminate unit test array */
8535         }
8536 };
8537
8538 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
8539         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
8540         .setup = testsuite_setup,
8541         .teardown = testsuite_teardown,
8542         .unit_test_cases = {
8543                 /** KASUMI encrypt only (UEA1) */
8544                 TEST_CASE_ST(ut_setup, ut_teardown,
8545                         test_kasumi_encryption_test_case_1),
8546                 TEST_CASE_ST(ut_setup, ut_teardown,
8547                         test_kasumi_encryption_test_case_1_sgl),
8548                 TEST_CASE_ST(ut_setup, ut_teardown,
8549                         test_kasumi_encryption_test_case_2),
8550                 TEST_CASE_ST(ut_setup, ut_teardown,
8551                         test_kasumi_encryption_test_case_3),
8552                 TEST_CASE_ST(ut_setup, ut_teardown,
8553                         test_kasumi_encryption_test_case_4),
8554                 TEST_CASE_ST(ut_setup, ut_teardown,
8555                         test_kasumi_encryption_test_case_5),
8556                 /** KASUMI decrypt only (UEA1) */
8557                 TEST_CASE_ST(ut_setup, ut_teardown,
8558                         test_kasumi_decryption_test_case_1),
8559                 TEST_CASE_ST(ut_setup, ut_teardown,
8560                         test_kasumi_decryption_test_case_2),
8561                 TEST_CASE_ST(ut_setup, ut_teardown,
8562                         test_kasumi_decryption_test_case_3),
8563                 TEST_CASE_ST(ut_setup, ut_teardown,
8564                         test_kasumi_decryption_test_case_4),
8565                 TEST_CASE_ST(ut_setup, ut_teardown,
8566                         test_kasumi_decryption_test_case_5),
8567
8568                 TEST_CASE_ST(ut_setup, ut_teardown,
8569                         test_kasumi_encryption_test_case_1_oop),
8570                 TEST_CASE_ST(ut_setup, ut_teardown,
8571                         test_kasumi_encryption_test_case_1_oop_sgl),
8572
8573
8574                 TEST_CASE_ST(ut_setup, ut_teardown,
8575                         test_kasumi_decryption_test_case_1_oop),
8576
8577                 /** KASUMI hash only (UIA1) */
8578                 TEST_CASE_ST(ut_setup, ut_teardown,
8579                         test_kasumi_hash_generate_test_case_1),
8580                 TEST_CASE_ST(ut_setup, ut_teardown,
8581                         test_kasumi_hash_generate_test_case_2),
8582                 TEST_CASE_ST(ut_setup, ut_teardown,
8583                         test_kasumi_hash_generate_test_case_3),
8584                 TEST_CASE_ST(ut_setup, ut_teardown,
8585                         test_kasumi_hash_generate_test_case_4),
8586                 TEST_CASE_ST(ut_setup, ut_teardown,
8587                         test_kasumi_hash_generate_test_case_5),
8588                 TEST_CASE_ST(ut_setup, ut_teardown,
8589                         test_kasumi_hash_generate_test_case_6),
8590                 TEST_CASE_ST(ut_setup, ut_teardown,
8591                         test_kasumi_hash_verify_test_case_1),
8592                 TEST_CASE_ST(ut_setup, ut_teardown,
8593                         test_kasumi_hash_verify_test_case_2),
8594                 TEST_CASE_ST(ut_setup, ut_teardown,
8595                         test_kasumi_hash_verify_test_case_3),
8596                 TEST_CASE_ST(ut_setup, ut_teardown,
8597                         test_kasumi_hash_verify_test_case_4),
8598                 TEST_CASE_ST(ut_setup, ut_teardown,
8599                         test_kasumi_hash_verify_test_case_5),
8600                 TEST_CASE_ST(ut_setup, ut_teardown,
8601                         test_kasumi_auth_cipher_test_case_1),
8602                 TEST_CASE_ST(ut_setup, ut_teardown,
8603                         test_kasumi_cipher_auth_test_case_1),
8604                 TEST_CASES_END() /**< NULL terminate unit test array */
8605         }
8606 };
8607 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
8608         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
8609         .setup = testsuite_setup,
8610         .teardown = testsuite_teardown,
8611         .unit_test_cases = {
8612                 /** SNOW 3G encrypt only (UEA2) */
8613                 TEST_CASE_ST(ut_setup, ut_teardown,
8614                         test_snow3g_encryption_test_case_1),
8615                 TEST_CASE_ST(ut_setup, ut_teardown,
8616                         test_snow3g_encryption_test_case_2),
8617                 TEST_CASE_ST(ut_setup, ut_teardown,
8618                         test_snow3g_encryption_test_case_3),
8619                 TEST_CASE_ST(ut_setup, ut_teardown,
8620                         test_snow3g_encryption_test_case_4),
8621                 TEST_CASE_ST(ut_setup, ut_teardown,
8622                         test_snow3g_encryption_test_case_5),
8623
8624                 TEST_CASE_ST(ut_setup, ut_teardown,
8625                         test_snow3g_encryption_test_case_1_oop),
8626                 TEST_CASE_ST(ut_setup, ut_teardown,
8627                                 test_snow3g_encryption_test_case_1_oop_sgl),
8628                 TEST_CASE_ST(ut_setup, ut_teardown,
8629                         test_snow3g_decryption_test_case_1_oop),
8630
8631                 TEST_CASE_ST(ut_setup, ut_teardown,
8632                         test_snow3g_encryption_test_case_1_offset_oop),
8633
8634                 /** SNOW 3G decrypt only (UEA2) */
8635                 TEST_CASE_ST(ut_setup, ut_teardown,
8636                         test_snow3g_decryption_test_case_1),
8637                 TEST_CASE_ST(ut_setup, ut_teardown,
8638                         test_snow3g_decryption_test_case_2),
8639                 TEST_CASE_ST(ut_setup, ut_teardown,
8640                         test_snow3g_decryption_test_case_3),
8641                 TEST_CASE_ST(ut_setup, ut_teardown,
8642                         test_snow3g_decryption_test_case_4),
8643                 TEST_CASE_ST(ut_setup, ut_teardown,
8644                         test_snow3g_decryption_test_case_5),
8645                 TEST_CASE_ST(ut_setup, ut_teardown,
8646                         test_snow3g_hash_generate_test_case_1),
8647                 TEST_CASE_ST(ut_setup, ut_teardown,
8648                         test_snow3g_hash_generate_test_case_2),
8649                 TEST_CASE_ST(ut_setup, ut_teardown,
8650                         test_snow3g_hash_generate_test_case_3),
8651                 /* Tests with buffers which length is not byte-aligned */
8652                 TEST_CASE_ST(ut_setup, ut_teardown,
8653                         test_snow3g_hash_generate_test_case_4),
8654                 TEST_CASE_ST(ut_setup, ut_teardown,
8655                         test_snow3g_hash_generate_test_case_5),
8656                 TEST_CASE_ST(ut_setup, ut_teardown,
8657                         test_snow3g_hash_generate_test_case_6),
8658                 TEST_CASE_ST(ut_setup, ut_teardown,
8659                         test_snow3g_hash_verify_test_case_1),
8660                 TEST_CASE_ST(ut_setup, ut_teardown,
8661                         test_snow3g_hash_verify_test_case_2),
8662                 TEST_CASE_ST(ut_setup, ut_teardown,
8663                         test_snow3g_hash_verify_test_case_3),
8664                 /* Tests with buffers which length is not byte-aligned */
8665                 TEST_CASE_ST(ut_setup, ut_teardown,
8666                         test_snow3g_hash_verify_test_case_4),
8667                 TEST_CASE_ST(ut_setup, ut_teardown,
8668                         test_snow3g_hash_verify_test_case_5),
8669                 TEST_CASE_ST(ut_setup, ut_teardown,
8670                         test_snow3g_hash_verify_test_case_6),
8671                 TEST_CASE_ST(ut_setup, ut_teardown,
8672                         test_snow3g_cipher_auth_test_case_1),
8673                 TEST_CASE_ST(ut_setup, ut_teardown,
8674                         test_snow3g_auth_cipher_test_case_1),
8675
8676                 TEST_CASES_END() /**< NULL terminate unit test array */
8677         }
8678 };
8679
8680 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
8681         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
8682         .setup = testsuite_setup,
8683         .teardown = testsuite_teardown,
8684         .unit_test_cases = {
8685                 /** ZUC encrypt only (EEA3) */
8686                 TEST_CASE_ST(ut_setup, ut_teardown,
8687                         test_zuc_encryption_test_case_1),
8688                 TEST_CASE_ST(ut_setup, ut_teardown,
8689                         test_zuc_encryption_test_case_2),
8690                 TEST_CASE_ST(ut_setup, ut_teardown,
8691                         test_zuc_encryption_test_case_3),
8692                 TEST_CASE_ST(ut_setup, ut_teardown,
8693                         test_zuc_encryption_test_case_4),
8694                 TEST_CASE_ST(ut_setup, ut_teardown,
8695                         test_zuc_encryption_test_case_5),
8696                 TEST_CASE_ST(ut_setup, ut_teardown,
8697                         test_zuc_hash_generate_test_case_1),
8698                 TEST_CASE_ST(ut_setup, ut_teardown,
8699                         test_zuc_hash_generate_test_case_2),
8700                 TEST_CASE_ST(ut_setup, ut_teardown,
8701                         test_zuc_hash_generate_test_case_3),
8702                 TEST_CASE_ST(ut_setup, ut_teardown,
8703                         test_zuc_hash_generate_test_case_4),
8704                 TEST_CASE_ST(ut_setup, ut_teardown,
8705                         test_zuc_hash_generate_test_case_5),
8706                 TEST_CASE_ST(ut_setup, ut_teardown,
8707                         test_zuc_encryption_test_case_6_sgl),
8708                 TEST_CASES_END() /**< NULL terminate unit test array */
8709         }
8710 };
8711
8712 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
8713         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
8714         .setup = testsuite_setup,
8715         .teardown = testsuite_teardown,
8716         .unit_test_cases = {
8717                 TEST_CASE_ST(ut_setup, ut_teardown,
8718                         test_device_configure_invalid_dev_id),
8719                 TEST_CASE_ST(ut_setup, ut_teardown,
8720                         test_multi_session),
8721
8722                 TEST_CASE_ST(ut_setup, ut_teardown,
8723                         test_AES_chain_dpaa2_sec_all),
8724                 TEST_CASE_ST(ut_setup, ut_teardown,
8725                         test_3DES_chain_dpaa2_sec_all),
8726                 TEST_CASE_ST(ut_setup, ut_teardown,
8727                         test_AES_cipheronly_dpaa2_sec_all),
8728                 TEST_CASE_ST(ut_setup, ut_teardown,
8729                         test_3DES_cipheronly_dpaa2_sec_all),
8730                 TEST_CASE_ST(ut_setup, ut_teardown,
8731                         test_authonly_dpaa2_sec_all),
8732
8733                 /** AES GCM Authenticated Encryption */
8734                 TEST_CASE_ST(ut_setup, ut_teardown,
8735                         test_AES_GCM_authenticated_encryption_test_case_1),
8736                 TEST_CASE_ST(ut_setup, ut_teardown,
8737                         test_AES_GCM_authenticated_encryption_test_case_2),
8738                 TEST_CASE_ST(ut_setup, ut_teardown,
8739                         test_AES_GCM_authenticated_encryption_test_case_3),
8740                 TEST_CASE_ST(ut_setup, ut_teardown,
8741                         test_AES_GCM_authenticated_encryption_test_case_4),
8742                 TEST_CASE_ST(ut_setup, ut_teardown,
8743                         test_AES_GCM_authenticated_encryption_test_case_5),
8744                 TEST_CASE_ST(ut_setup, ut_teardown,
8745                         test_AES_GCM_authenticated_encryption_test_case_6),
8746                 TEST_CASE_ST(ut_setup, ut_teardown,
8747                         test_AES_GCM_authenticated_encryption_test_case_7),
8748
8749                 /** AES GCM Authenticated Decryption */
8750                 TEST_CASE_ST(ut_setup, ut_teardown,
8751                         test_AES_GCM_authenticated_decryption_test_case_1),
8752                 TEST_CASE_ST(ut_setup, ut_teardown,
8753                         test_AES_GCM_authenticated_decryption_test_case_2),
8754                 TEST_CASE_ST(ut_setup, ut_teardown,
8755                         test_AES_GCM_authenticated_decryption_test_case_3),
8756                 TEST_CASE_ST(ut_setup, ut_teardown,
8757                         test_AES_GCM_authenticated_decryption_test_case_4),
8758                 TEST_CASE_ST(ut_setup, ut_teardown,
8759                         test_AES_GCM_authenticated_decryption_test_case_5),
8760                 TEST_CASE_ST(ut_setup, ut_teardown,
8761                         test_AES_GCM_authenticated_decryption_test_case_6),
8762                 TEST_CASE_ST(ut_setup, ut_teardown,
8763                         test_AES_GCM_authenticated_decryption_test_case_7),
8764
8765                 /** AES GCM Authenticated Encryption 192 bits key */
8766                 TEST_CASE_ST(ut_setup, ut_teardown,
8767                         test_AES_GCM_auth_encryption_test_case_192_1),
8768                 TEST_CASE_ST(ut_setup, ut_teardown,
8769                         test_AES_GCM_auth_encryption_test_case_192_2),
8770                 TEST_CASE_ST(ut_setup, ut_teardown,
8771                         test_AES_GCM_auth_encryption_test_case_192_3),
8772                 TEST_CASE_ST(ut_setup, ut_teardown,
8773                         test_AES_GCM_auth_encryption_test_case_192_4),
8774                 TEST_CASE_ST(ut_setup, ut_teardown,
8775                         test_AES_GCM_auth_encryption_test_case_192_5),
8776                 TEST_CASE_ST(ut_setup, ut_teardown,
8777                         test_AES_GCM_auth_encryption_test_case_192_6),
8778                 TEST_CASE_ST(ut_setup, ut_teardown,
8779                         test_AES_GCM_auth_encryption_test_case_192_7),
8780
8781                 /** AES GCM Authenticated Decryption 192 bits key */
8782                 TEST_CASE_ST(ut_setup, ut_teardown,
8783                         test_AES_GCM_auth_decryption_test_case_192_1),
8784                 TEST_CASE_ST(ut_setup, ut_teardown,
8785                         test_AES_GCM_auth_decryption_test_case_192_2),
8786                 TEST_CASE_ST(ut_setup, ut_teardown,
8787                         test_AES_GCM_auth_decryption_test_case_192_3),
8788                 TEST_CASE_ST(ut_setup, ut_teardown,
8789                         test_AES_GCM_auth_decryption_test_case_192_4),
8790                 TEST_CASE_ST(ut_setup, ut_teardown,
8791                         test_AES_GCM_auth_decryption_test_case_192_5),
8792                 TEST_CASE_ST(ut_setup, ut_teardown,
8793                         test_AES_GCM_auth_decryption_test_case_192_6),
8794                 TEST_CASE_ST(ut_setup, ut_teardown,
8795                         test_AES_GCM_auth_decryption_test_case_192_7),
8796
8797                 /** AES GCM Authenticated Encryption 256 bits key */
8798                 TEST_CASE_ST(ut_setup, ut_teardown,
8799                         test_AES_GCM_auth_encryption_test_case_256_1),
8800                 TEST_CASE_ST(ut_setup, ut_teardown,
8801                         test_AES_GCM_auth_encryption_test_case_256_2),
8802                 TEST_CASE_ST(ut_setup, ut_teardown,
8803                         test_AES_GCM_auth_encryption_test_case_256_3),
8804                 TEST_CASE_ST(ut_setup, ut_teardown,
8805                         test_AES_GCM_auth_encryption_test_case_256_4),
8806                 TEST_CASE_ST(ut_setup, ut_teardown,
8807                         test_AES_GCM_auth_encryption_test_case_256_5),
8808                 TEST_CASE_ST(ut_setup, ut_teardown,
8809                         test_AES_GCM_auth_encryption_test_case_256_6),
8810                 TEST_CASE_ST(ut_setup, ut_teardown,
8811                         test_AES_GCM_auth_encryption_test_case_256_7),
8812
8813                 /** AES GCM Authenticated Decryption 256 bits key */
8814                 TEST_CASE_ST(ut_setup, ut_teardown,
8815                         test_AES_GCM_auth_decryption_test_case_256_1),
8816                 TEST_CASE_ST(ut_setup, ut_teardown,
8817                         test_AES_GCM_auth_decryption_test_case_256_2),
8818                 TEST_CASE_ST(ut_setup, ut_teardown,
8819                         test_AES_GCM_auth_decryption_test_case_256_3),
8820                 TEST_CASE_ST(ut_setup, ut_teardown,
8821                         test_AES_GCM_auth_decryption_test_case_256_4),
8822                 TEST_CASE_ST(ut_setup, ut_teardown,
8823                         test_AES_GCM_auth_decryption_test_case_256_5),
8824                 TEST_CASE_ST(ut_setup, ut_teardown,
8825                         test_AES_GCM_auth_decryption_test_case_256_6),
8826                 TEST_CASE_ST(ut_setup, ut_teardown,
8827                         test_AES_GCM_auth_decryption_test_case_256_7),
8828
8829                 TEST_CASES_END() /**< NULL terminate unit test array */
8830         }
8831 };
8832
8833 static struct unit_test_suite cryptodev_null_testsuite  = {
8834         .suite_name = "Crypto Device NULL Unit Test Suite",
8835         .setup = testsuite_setup,
8836         .teardown = testsuite_teardown,
8837         .unit_test_cases = {
8838                 TEST_CASE_ST(ut_setup, ut_teardown,
8839                         test_null_auth_only_operation),
8840                 TEST_CASE_ST(ut_setup, ut_teardown,
8841                         test_null_cipher_only_operation),
8842                 TEST_CASE_ST(ut_setup, ut_teardown,
8843                         test_null_cipher_auth_operation),
8844                 TEST_CASE_ST(ut_setup, ut_teardown,
8845                         test_null_auth_cipher_operation),
8846                 TEST_CASE_ST(ut_setup, ut_teardown,
8847                         test_null_invalid_operation),
8848                 TEST_CASE_ST(ut_setup, ut_teardown,
8849                         test_null_burst_operation),
8850
8851                 TEST_CASES_END() /**< NULL terminate unit test array */
8852         }
8853 };
8854
8855 static struct unit_test_suite cryptodev_armv8_testsuite  = {
8856         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
8857         .setup = testsuite_setup,
8858         .teardown = testsuite_teardown,
8859         .unit_test_cases = {
8860                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
8861
8862                 /** Negative tests */
8863                 TEST_CASE_ST(ut_setup, ut_teardown,
8864                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8865                 TEST_CASE_ST(ut_setup, ut_teardown,
8866                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8867
8868                 TEST_CASES_END() /**< NULL terminate unit test array */
8869         }
8870 };
8871
8872 static int
8873 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
8874 {
8875         gbl_driver_id = rte_cryptodev_driver_id_get(
8876                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
8877
8878         if (gbl_driver_id == -1) {
8879                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
8880                                 "CONFIG_RTE_LIBRTE_PMD_QAT is enabled "
8881                                 "in config file to run this testsuite.\n");
8882                 return TEST_FAILED;
8883         }
8884
8885         return unit_test_suite_runner(&cryptodev_qat_testsuite);
8886 }
8887
8888 static int
8889 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
8890 {
8891         gbl_driver_id = rte_cryptodev_driver_id_get(
8892                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
8893
8894         if (gbl_driver_id == -1) {
8895                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
8896                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
8897                                 "in config file to run this testsuite.\n");
8898                 return TEST_FAILED;
8899         }
8900
8901         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
8902 }
8903
8904 static int
8905 test_cryptodev_openssl(void)
8906 {
8907         gbl_driver_id = rte_cryptodev_driver_id_get(
8908                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
8909
8910         if (gbl_driver_id == -1) {
8911                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
8912                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
8913                                 "in config file to run this testsuite.\n");
8914                 return TEST_FAILED;
8915         }
8916
8917         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
8918 }
8919
8920 static int
8921 test_cryptodev_aesni_gcm(void)
8922 {
8923         gbl_driver_id = rte_cryptodev_driver_id_get(
8924                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
8925
8926         if (gbl_driver_id == -1) {
8927                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
8928                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
8929                                 "in config file to run this testsuite.\n");
8930                 return TEST_FAILED;
8931         }
8932
8933         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
8934 }
8935
8936 static int
8937 test_cryptodev_null(void)
8938 {
8939         gbl_driver_id = rte_cryptodev_driver_id_get(
8940                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
8941
8942         if (gbl_driver_id == -1) {
8943                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
8944                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
8945                                 "in config file to run this testsuite.\n");
8946                 return TEST_FAILED;
8947         }
8948
8949         return unit_test_suite_runner(&cryptodev_null_testsuite);
8950 }
8951
8952 static int
8953 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
8954 {
8955         gbl_driver_id = rte_cryptodev_driver_id_get(
8956                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
8957
8958         if (gbl_driver_id == -1) {
8959                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
8960                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
8961                                 "in config file to run this testsuite.\n");
8962                 return TEST_FAILED;
8963         }
8964
8965         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
8966 }
8967
8968 static int
8969 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
8970 {
8971         gbl_driver_id = rte_cryptodev_driver_id_get(
8972                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
8973
8974         if (gbl_driver_id == -1) {
8975                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
8976                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
8977                                 "in config file to run this testsuite.\n");
8978                 return TEST_FAILED;
8979         }
8980
8981         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
8982 }
8983
8984 static int
8985 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
8986 {
8987         gbl_driver_id = rte_cryptodev_driver_id_get(
8988                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
8989
8990         if (gbl_driver_id == -1) {
8991                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
8992                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
8993                                 "in config file to run this testsuite.\n");
8994                 return TEST_FAILED;
8995         }
8996
8997         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
8998 }
8999
9000 static int
9001 test_cryptodev_armv8(void)
9002 {
9003         gbl_driver_id = rte_cryptodev_driver_id_get(
9004                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
9005
9006         if (gbl_driver_id == -1) {
9007                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
9008                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
9009                                 "in config file to run this testsuite.\n");
9010                 return TEST_FAILED;
9011         }
9012
9013         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
9014 }
9015
9016 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
9017
9018 static int
9019 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
9020 {
9021         gbl_driver_id = rte_cryptodev_driver_id_get(
9022                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
9023
9024         if (gbl_driver_id == -1) {
9025                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
9026                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
9027                                 "in config file to run this testsuite.\n");
9028                 return TEST_FAILED;
9029         }
9030
9031         if (rte_cryptodev_driver_id_get(
9032                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
9033                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
9034                         " enabled in config file to run this testsuite.\n");
9035                 return TEST_FAILED;
9036 }
9037         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
9038 }
9039
9040 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
9041
9042 #endif
9043
9044 static int
9045 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
9046 {
9047         gbl_driver_id = rte_cryptodev_driver_id_get(
9048                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
9049
9050         if (gbl_driver_id == -1) {
9051                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
9052                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
9053                                 "in config file to run this testsuite.\n");
9054                 return TEST_FAILED;
9055         }
9056
9057         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
9058 }
9059
9060 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
9061 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
9062 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
9063 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
9064 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
9065 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
9066 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
9067 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
9068 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
9069 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);