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