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