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