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