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