test/crypto: add tests for virtio-crypto
[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_cipheronly_virtio_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_VIRTIO_PMD)),
1834                 BLKCIPHER_AES_CIPHERONLY_TYPE);
1835
1836         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1837
1838         return TEST_SUCCESS;
1839 }
1840
1841 static int
1842 test_AES_chain_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_CHAIN_TYPE);
1854
1855         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1856
1857         return TEST_SUCCESS;
1858 }
1859
1860 static int
1861 test_AES_cipheronly_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_AES_CIPHERONLY_TYPE);
1873
1874         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1875
1876         return TEST_SUCCESS;
1877 }
1878
1879 static int
1880 test_authonly_dpaa_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_DPAA_SEC_PMD)),
1891                 BLKCIPHER_AUTHONLY_TYPE);
1892
1893         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1894
1895         return TEST_SUCCESS;
1896 }
1897
1898 static int
1899 test_AES_chain_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_CHAIN_TYPE);
1911
1912         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1913
1914         return TEST_SUCCESS;
1915 }
1916
1917 static int
1918 test_AES_cipheronly_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_AES_CIPHERONLY_TYPE);
1930
1931         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1932
1933         return TEST_SUCCESS;
1934 }
1935
1936 static int
1937 test_authonly_dpaa2_sec_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_DPAA2_SEC_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_openssl_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_OPENSSL_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_authonly_ccp_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_CCP_PMD)),
1986                 BLKCIPHER_AUTHONLY_TYPE);
1987
1988         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1989
1990         return TEST_SUCCESS;
1991 }
1992
1993 static int
1994 test_AES_chain_armv8_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_ARMV8_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_chain_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_CHAIN_TYPE);
2025
2026         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2027
2028         return TEST_SUCCESS;
2029 }
2030
2031 static int
2032 test_AES_cipheronly_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_AES_CIPHERONLY_TYPE);
2044
2045         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2046
2047         return TEST_SUCCESS;
2048 }
2049
2050 static int
2051 test_authonly_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_AUTHONLY_TYPE);
2063
2064         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2065
2066         return TEST_SUCCESS;
2067 }
2068
2069 static int
2070 test_3DES_chain_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_CHAIN_TYPE);
2082
2083         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2084
2085         return TEST_SUCCESS;
2086 }
2087
2088 static int
2089 test_3DES_cipheronly_mrvl_all(void)
2090 {
2091         struct crypto_testsuite_params *ts_params = &testsuite_params;
2092         int status;
2093
2094         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2095                 ts_params->op_mpool,
2096                 ts_params->session_mpool,
2097                 ts_params->valid_devs[0],
2098                 rte_cryptodev_driver_id_get(
2099                 RTE_STR(CRYPTODEV_NAME_MRVL_PMD)),
2100                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
2101
2102         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2103
2104         return TEST_SUCCESS;
2105 }
2106
2107 /* ***** SNOW 3G Tests ***** */
2108 static int
2109 create_wireless_algo_hash_session(uint8_t dev_id,
2110         const uint8_t *key, const uint8_t key_len,
2111         const uint8_t iv_len, const uint8_t auth_len,
2112         enum rte_crypto_auth_operation op,
2113         enum rte_crypto_auth_algorithm algo)
2114 {
2115         uint8_t hash_key[key_len];
2116
2117         struct crypto_testsuite_params *ts_params = &testsuite_params;
2118         struct crypto_unittest_params *ut_params = &unittest_params;
2119
2120         memcpy(hash_key, key, key_len);
2121
2122         debug_hexdump(stdout, "key:", key, key_len);
2123
2124         /* Setup Authentication Parameters */
2125         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2126         ut_params->auth_xform.next = NULL;
2127
2128         ut_params->auth_xform.auth.op = op;
2129         ut_params->auth_xform.auth.algo = algo;
2130         ut_params->auth_xform.auth.key.length = key_len;
2131         ut_params->auth_xform.auth.key.data = hash_key;
2132         ut_params->auth_xform.auth.digest_length = auth_len;
2133         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2134         ut_params->auth_xform.auth.iv.length = iv_len;
2135         ut_params->sess = rte_cryptodev_sym_session_create(
2136                         ts_params->session_mpool);
2137
2138         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2139                         &ut_params->auth_xform, ts_params->session_mpool);
2140         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2141         return 0;
2142 }
2143
2144 static int
2145 create_wireless_algo_cipher_session(uint8_t dev_id,
2146                         enum rte_crypto_cipher_operation op,
2147                         enum rte_crypto_cipher_algorithm algo,
2148                         const uint8_t *key, const uint8_t key_len,
2149                         uint8_t iv_len)
2150 {
2151         uint8_t cipher_key[key_len];
2152
2153         struct crypto_testsuite_params *ts_params = &testsuite_params;
2154         struct crypto_unittest_params *ut_params = &unittest_params;
2155
2156         memcpy(cipher_key, key, key_len);
2157
2158         /* Setup Cipher Parameters */
2159         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2160         ut_params->cipher_xform.next = NULL;
2161
2162         ut_params->cipher_xform.cipher.algo = algo;
2163         ut_params->cipher_xform.cipher.op = op;
2164         ut_params->cipher_xform.cipher.key.data = cipher_key;
2165         ut_params->cipher_xform.cipher.key.length = key_len;
2166         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2167         ut_params->cipher_xform.cipher.iv.length = iv_len;
2168
2169         debug_hexdump(stdout, "key:", key, key_len);
2170
2171         /* Create Crypto session */
2172         ut_params->sess = rte_cryptodev_sym_session_create(
2173                         ts_params->session_mpool);
2174
2175         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2176                         &ut_params->cipher_xform, ts_params->session_mpool);
2177         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2178         return 0;
2179 }
2180
2181 static int
2182 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2183                         unsigned int cipher_len,
2184                         unsigned int cipher_offset)
2185 {
2186         struct crypto_testsuite_params *ts_params = &testsuite_params;
2187         struct crypto_unittest_params *ut_params = &unittest_params;
2188
2189         /* Generate Crypto op data structure */
2190         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2191                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2192         TEST_ASSERT_NOT_NULL(ut_params->op,
2193                                 "Failed to allocate pktmbuf offload");
2194
2195         /* Set crypto operation data parameters */
2196         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2197
2198         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2199
2200         /* set crypto operation source mbuf */
2201         sym_op->m_src = ut_params->ibuf;
2202
2203         /* iv */
2204         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2205                         iv, iv_len);
2206         sym_op->cipher.data.length = cipher_len;
2207         sym_op->cipher.data.offset = cipher_offset;
2208         return 0;
2209 }
2210
2211 static int
2212 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2213                         unsigned int cipher_len,
2214                         unsigned int cipher_offset)
2215 {
2216         struct crypto_testsuite_params *ts_params = &testsuite_params;
2217         struct crypto_unittest_params *ut_params = &unittest_params;
2218
2219         /* Generate Crypto op data structure */
2220         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2221                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2222         TEST_ASSERT_NOT_NULL(ut_params->op,
2223                                 "Failed to allocate pktmbuf offload");
2224
2225         /* Set crypto operation data parameters */
2226         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2227
2228         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2229
2230         /* set crypto operation source mbuf */
2231         sym_op->m_src = ut_params->ibuf;
2232         sym_op->m_dst = ut_params->obuf;
2233
2234         /* iv */
2235         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2236                         iv, iv_len);
2237         sym_op->cipher.data.length = cipher_len;
2238         sym_op->cipher.data.offset = cipher_offset;
2239         return 0;
2240 }
2241
2242 static int
2243 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2244                 enum rte_crypto_cipher_operation cipher_op,
2245                 enum rte_crypto_auth_operation auth_op,
2246                 enum rte_crypto_auth_algorithm auth_algo,
2247                 enum rte_crypto_cipher_algorithm cipher_algo,
2248                 const uint8_t *key, uint8_t key_len,
2249                 uint8_t auth_iv_len, uint8_t auth_len,
2250                 uint8_t cipher_iv_len)
2251
2252 {
2253         uint8_t cipher_auth_key[key_len];
2254
2255         struct crypto_testsuite_params *ts_params = &testsuite_params;
2256         struct crypto_unittest_params *ut_params = &unittest_params;
2257
2258         memcpy(cipher_auth_key, key, key_len);
2259
2260         /* Setup Authentication Parameters */
2261         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2262         ut_params->auth_xform.next = NULL;
2263
2264         ut_params->auth_xform.auth.op = auth_op;
2265         ut_params->auth_xform.auth.algo = auth_algo;
2266         ut_params->auth_xform.auth.key.length = key_len;
2267         /* Hash key = cipher key */
2268         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2269         ut_params->auth_xform.auth.digest_length = auth_len;
2270         /* Auth IV will be after cipher IV */
2271         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2272         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2273
2274         /* Setup Cipher Parameters */
2275         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2276         ut_params->cipher_xform.next = &ut_params->auth_xform;
2277
2278         ut_params->cipher_xform.cipher.algo = cipher_algo;
2279         ut_params->cipher_xform.cipher.op = cipher_op;
2280         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2281         ut_params->cipher_xform.cipher.key.length = key_len;
2282         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2283         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2284
2285         debug_hexdump(stdout, "key:", key, key_len);
2286
2287         /* Create Crypto session*/
2288         ut_params->sess = rte_cryptodev_sym_session_create(
2289                         ts_params->session_mpool);
2290
2291         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2292                         &ut_params->cipher_xform, ts_params->session_mpool);
2293
2294         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2295         return 0;
2296 }
2297
2298 static int
2299 create_wireless_cipher_auth_session(uint8_t dev_id,
2300                 enum rte_crypto_cipher_operation cipher_op,
2301                 enum rte_crypto_auth_operation auth_op,
2302                 enum rte_crypto_auth_algorithm auth_algo,
2303                 enum rte_crypto_cipher_algorithm cipher_algo,
2304                 const struct wireless_test_data *tdata)
2305 {
2306         const uint8_t key_len = tdata->key.len;
2307         uint8_t cipher_auth_key[key_len];
2308
2309         struct crypto_testsuite_params *ts_params = &testsuite_params;
2310         struct crypto_unittest_params *ut_params = &unittest_params;
2311         const uint8_t *key = tdata->key.data;
2312         const uint8_t auth_len = tdata->digest.len;
2313         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2314         uint8_t auth_iv_len = tdata->auth_iv.len;
2315
2316         memcpy(cipher_auth_key, key, key_len);
2317
2318         /* Setup Authentication Parameters */
2319         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2320         ut_params->auth_xform.next = NULL;
2321
2322         ut_params->auth_xform.auth.op = auth_op;
2323         ut_params->auth_xform.auth.algo = auth_algo;
2324         ut_params->auth_xform.auth.key.length = key_len;
2325         /* Hash key = cipher key */
2326         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2327         ut_params->auth_xform.auth.digest_length = auth_len;
2328         /* Auth IV will be after cipher IV */
2329         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2330         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2331
2332         /* Setup Cipher Parameters */
2333         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2334         ut_params->cipher_xform.next = &ut_params->auth_xform;
2335
2336         ut_params->cipher_xform.cipher.algo = cipher_algo;
2337         ut_params->cipher_xform.cipher.op = cipher_op;
2338         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2339         ut_params->cipher_xform.cipher.key.length = key_len;
2340         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2341         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2342
2343
2344         debug_hexdump(stdout, "key:", key, key_len);
2345
2346         /* Create Crypto session*/
2347         ut_params->sess = rte_cryptodev_sym_session_create(
2348                         ts_params->session_mpool);
2349
2350         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2351                         &ut_params->cipher_xform, ts_params->session_mpool);
2352
2353         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2354         return 0;
2355 }
2356
2357 static int
2358 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2359                 const struct wireless_test_data *tdata)
2360 {
2361         return create_wireless_cipher_auth_session(dev_id,
2362                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2363                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2364                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2365 }
2366
2367 static int
2368 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2369                 enum rte_crypto_cipher_operation cipher_op,
2370                 enum rte_crypto_auth_operation auth_op,
2371                 enum rte_crypto_auth_algorithm auth_algo,
2372                 enum rte_crypto_cipher_algorithm cipher_algo,
2373                 const uint8_t *key, const uint8_t key_len,
2374                 uint8_t auth_iv_len, uint8_t auth_len,
2375                 uint8_t cipher_iv_len)
2376 {
2377         uint8_t auth_cipher_key[key_len];
2378
2379         struct crypto_testsuite_params *ts_params = &testsuite_params;
2380         struct crypto_unittest_params *ut_params = &unittest_params;
2381
2382         memcpy(auth_cipher_key, key, key_len);
2383
2384         /* Setup Authentication Parameters */
2385         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2386         ut_params->auth_xform.auth.op = auth_op;
2387         ut_params->auth_xform.next = &ut_params->cipher_xform;
2388         ut_params->auth_xform.auth.algo = auth_algo;
2389         ut_params->auth_xform.auth.key.length = key_len;
2390         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2391         ut_params->auth_xform.auth.digest_length = auth_len;
2392         /* Auth IV will be after cipher IV */
2393         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2394         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2395
2396         /* Setup Cipher Parameters */
2397         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2398         ut_params->cipher_xform.next = NULL;
2399         ut_params->cipher_xform.cipher.algo = cipher_algo;
2400         ut_params->cipher_xform.cipher.op = cipher_op;
2401         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2402         ut_params->cipher_xform.cipher.key.length = key_len;
2403         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2404         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2405
2406         debug_hexdump(stdout, "key:", key, key_len);
2407
2408         /* Create Crypto session*/
2409         ut_params->sess = rte_cryptodev_sym_session_create(
2410                         ts_params->session_mpool);
2411
2412         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2413                         &ut_params->auth_xform, ts_params->session_mpool);
2414
2415         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2416
2417         return 0;
2418 }
2419
2420 static int
2421 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2422                 unsigned int auth_tag_len,
2423                 const uint8_t *iv, unsigned int iv_len,
2424                 unsigned int data_pad_len,
2425                 enum rte_crypto_auth_operation op,
2426                 unsigned int auth_len, unsigned int auth_offset)
2427 {
2428         struct crypto_testsuite_params *ts_params = &testsuite_params;
2429
2430         struct crypto_unittest_params *ut_params = &unittest_params;
2431
2432         /* Generate Crypto op data structure */
2433         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2434                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2435         TEST_ASSERT_NOT_NULL(ut_params->op,
2436                 "Failed to allocate pktmbuf offload");
2437
2438         /* Set crypto operation data parameters */
2439         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2440
2441         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2442
2443         /* set crypto operation source mbuf */
2444         sym_op->m_src = ut_params->ibuf;
2445
2446         /* iv */
2447         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2448                         iv, iv_len);
2449         /* digest */
2450         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2451                                         ut_params->ibuf, auth_tag_len);
2452
2453         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2454                                 "no room to append auth tag");
2455         ut_params->digest = sym_op->auth.digest.data;
2456         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2457                         ut_params->ibuf, data_pad_len);
2458         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2459                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2460         else
2461                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2462
2463         debug_hexdump(stdout, "digest:",
2464                 sym_op->auth.digest.data,
2465                 auth_tag_len);
2466
2467         sym_op->auth.data.length = auth_len;
2468         sym_op->auth.data.offset = auth_offset;
2469
2470         return 0;
2471 }
2472
2473 static int
2474 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2475         enum rte_crypto_auth_operation op)
2476 {
2477         struct crypto_testsuite_params *ts_params = &testsuite_params;
2478         struct crypto_unittest_params *ut_params = &unittest_params;
2479
2480         const uint8_t *auth_tag = tdata->digest.data;
2481         const unsigned int auth_tag_len = tdata->digest.len;
2482         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2483         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2484
2485         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2486         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2487         const uint8_t *auth_iv = tdata->auth_iv.data;
2488         const uint8_t auth_iv_len = tdata->auth_iv.len;
2489         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2490         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2491
2492         /* Generate Crypto op data structure */
2493         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2494                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2495         TEST_ASSERT_NOT_NULL(ut_params->op,
2496                         "Failed to allocate pktmbuf offload");
2497         /* Set crypto operation data parameters */
2498         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2499
2500         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2501
2502         /* set crypto operation source mbuf */
2503         sym_op->m_src = ut_params->ibuf;
2504
2505         /* digest */
2506         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2507                         ut_params->ibuf, auth_tag_len);
2508
2509         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2510                         "no room to append auth tag");
2511         ut_params->digest = sym_op->auth.digest.data;
2512         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2513                         ut_params->ibuf, data_pad_len);
2514         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2515                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2516         else
2517                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2518
2519         debug_hexdump(stdout, "digest:",
2520                 sym_op->auth.digest.data,
2521                 auth_tag_len);
2522
2523         /* Copy cipher and auth IVs at the end of the crypto operation */
2524         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2525                                                 IV_OFFSET);
2526         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2527         iv_ptr += cipher_iv_len;
2528         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2529
2530         sym_op->cipher.data.length = cipher_len;
2531         sym_op->cipher.data.offset = 0;
2532         sym_op->auth.data.length = auth_len;
2533         sym_op->auth.data.offset = 0;
2534
2535         return 0;
2536 }
2537
2538 static int
2539 create_zuc_cipher_hash_generate_operation(
2540                 const struct wireless_test_data *tdata)
2541 {
2542         return create_wireless_cipher_hash_operation(tdata,
2543                 RTE_CRYPTO_AUTH_OP_GENERATE);
2544 }
2545
2546 static int
2547 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2548                 const unsigned auth_tag_len,
2549                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2550                 unsigned data_pad_len,
2551                 enum rte_crypto_auth_operation op,
2552                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2553                 const unsigned cipher_len, const unsigned cipher_offset,
2554                 const unsigned auth_len, const unsigned auth_offset)
2555 {
2556         struct crypto_testsuite_params *ts_params = &testsuite_params;
2557         struct crypto_unittest_params *ut_params = &unittest_params;
2558
2559         /* Generate Crypto op data structure */
2560         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2561                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2562         TEST_ASSERT_NOT_NULL(ut_params->op,
2563                         "Failed to allocate pktmbuf offload");
2564         /* Set crypto operation data parameters */
2565         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2566
2567         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2568
2569         /* set crypto operation source mbuf */
2570         sym_op->m_src = ut_params->ibuf;
2571
2572         /* digest */
2573         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2574                         ut_params->ibuf, auth_tag_len);
2575
2576         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2577                         "no room to append auth tag");
2578         ut_params->digest = sym_op->auth.digest.data;
2579         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2580                         ut_params->ibuf, data_pad_len);
2581         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2582                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2583         else
2584                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2585
2586         debug_hexdump(stdout, "digest:",
2587                 sym_op->auth.digest.data,
2588                 auth_tag_len);
2589
2590         /* Copy cipher and auth IVs at the end of the crypto operation */
2591         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2592                                                 IV_OFFSET);
2593         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2594         iv_ptr += cipher_iv_len;
2595         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2596
2597         sym_op->cipher.data.length = cipher_len;
2598         sym_op->cipher.data.offset = cipher_offset;
2599         sym_op->auth.data.length = auth_len;
2600         sym_op->auth.data.offset = auth_offset;
2601
2602         return 0;
2603 }
2604
2605 static int
2606 create_wireless_algo_auth_cipher_operation(unsigned int auth_tag_len,
2607                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2608                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2609                 unsigned int data_pad_len,
2610                 unsigned int cipher_len, unsigned int cipher_offset,
2611                 unsigned int auth_len, unsigned int auth_offset)
2612 {
2613         struct crypto_testsuite_params *ts_params = &testsuite_params;
2614         struct crypto_unittest_params *ut_params = &unittest_params;
2615
2616         /* Generate Crypto op data structure */
2617         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2618                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2619         TEST_ASSERT_NOT_NULL(ut_params->op,
2620                         "Failed to allocate pktmbuf offload");
2621
2622         /* Set crypto operation data parameters */
2623         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2624
2625         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2626
2627         /* set crypto operation source mbuf */
2628         sym_op->m_src = ut_params->ibuf;
2629
2630         /* digest */
2631         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2632                         ut_params->ibuf, auth_tag_len);
2633
2634         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2635                         "no room to append auth tag");
2636
2637         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2638                         ut_params->ibuf, data_pad_len);
2639
2640         memset(sym_op->auth.digest.data, 0, auth_tag_len);
2641
2642         debug_hexdump(stdout, "digest:",
2643                         sym_op->auth.digest.data,
2644                         auth_tag_len);
2645
2646         /* Copy cipher and auth IVs at the end of the crypto operation */
2647         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2648                                                 IV_OFFSET);
2649         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2650         iv_ptr += cipher_iv_len;
2651         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2652
2653         sym_op->cipher.data.length = cipher_len;
2654         sym_op->cipher.data.offset = cipher_offset;
2655
2656         sym_op->auth.data.length = auth_len;
2657         sym_op->auth.data.offset = auth_offset;
2658
2659         return 0;
2660 }
2661
2662 static int
2663 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2664 {
2665         struct crypto_testsuite_params *ts_params = &testsuite_params;
2666         struct crypto_unittest_params *ut_params = &unittest_params;
2667
2668         int retval;
2669         unsigned plaintext_pad_len;
2670         unsigned plaintext_len;
2671         uint8_t *plaintext;
2672
2673         /* Create SNOW 3G session */
2674         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2675                         tdata->key.data, tdata->key.len,
2676                         tdata->auth_iv.len, tdata->digest.len,
2677                         RTE_CRYPTO_AUTH_OP_GENERATE,
2678                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2679         if (retval < 0)
2680                 return retval;
2681
2682         /* alloc mbuf and set payload */
2683         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2684
2685         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2686         rte_pktmbuf_tailroom(ut_params->ibuf));
2687
2688         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2689         /* Append data which is padded to a multiple of */
2690         /* the algorithms block size */
2691         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2692         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2693                                 plaintext_pad_len);
2694         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2695
2696         /* Create SNOW 3G operation */
2697         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2698                         tdata->auth_iv.data, tdata->auth_iv.len,
2699                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2700                         tdata->validAuthLenInBits.len,
2701                         0);
2702         if (retval < 0)
2703                 return retval;
2704
2705         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2706                                 ut_params->op);
2707         ut_params->obuf = ut_params->op->sym->m_src;
2708         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2709         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2710                         + plaintext_pad_len;
2711
2712         /* Validate obuf */
2713         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2714         ut_params->digest,
2715         tdata->digest.data,
2716         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2717         "SNOW 3G Generated auth tag not as expected");
2718
2719         return 0;
2720 }
2721
2722 static int
2723 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2724 {
2725         struct crypto_testsuite_params *ts_params = &testsuite_params;
2726         struct crypto_unittest_params *ut_params = &unittest_params;
2727
2728         int retval;
2729         unsigned plaintext_pad_len;
2730         unsigned plaintext_len;
2731         uint8_t *plaintext;
2732
2733         /* Create SNOW 3G session */
2734         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2735                                 tdata->key.data, tdata->key.len,
2736                                 tdata->auth_iv.len, tdata->digest.len,
2737                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2738                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2739         if (retval < 0)
2740                 return retval;
2741         /* alloc mbuf and set payload */
2742         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2743
2744         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2745         rte_pktmbuf_tailroom(ut_params->ibuf));
2746
2747         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2748         /* Append data which is padded to a multiple of */
2749         /* the algorithms block size */
2750         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2751         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2752                                 plaintext_pad_len);
2753         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2754
2755         /* Create SNOW 3G operation */
2756         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2757                         tdata->digest.len,
2758                         tdata->auth_iv.data, tdata->auth_iv.len,
2759                         plaintext_pad_len,
2760                         RTE_CRYPTO_AUTH_OP_VERIFY,
2761                         tdata->validAuthLenInBits.len,
2762                         0);
2763         if (retval < 0)
2764                 return retval;
2765
2766         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2767                                 ut_params->op);
2768         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2769         ut_params->obuf = ut_params->op->sym->m_src;
2770         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2771                                 + plaintext_pad_len;
2772
2773         /* Validate obuf */
2774         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2775                 return 0;
2776         else
2777                 return -1;
2778
2779         return 0;
2780 }
2781
2782 static int
2783 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2784 {
2785         struct crypto_testsuite_params *ts_params = &testsuite_params;
2786         struct crypto_unittest_params *ut_params = &unittest_params;
2787
2788         int retval;
2789         unsigned plaintext_pad_len;
2790         unsigned plaintext_len;
2791         uint8_t *plaintext;
2792
2793         /* Create KASUMI session */
2794         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2795                         tdata->key.data, tdata->key.len,
2796                         0, tdata->digest.len,
2797                         RTE_CRYPTO_AUTH_OP_GENERATE,
2798                         RTE_CRYPTO_AUTH_KASUMI_F9);
2799         if (retval < 0)
2800                 return retval;
2801
2802         /* alloc mbuf and set payload */
2803         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2804
2805         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2806         rte_pktmbuf_tailroom(ut_params->ibuf));
2807
2808         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2809         /* Append data which is padded to a multiple of */
2810         /* the algorithms block size */
2811         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2812         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2813                                 plaintext_pad_len);
2814         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2815
2816         /* Create KASUMI operation */
2817         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2818                         NULL, 0,
2819                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2820                         tdata->plaintext.len,
2821                         0);
2822         if (retval < 0)
2823                 return retval;
2824
2825         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2826                                 ut_params->op);
2827         ut_params->obuf = ut_params->op->sym->m_src;
2828         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2829         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2830                         + plaintext_pad_len;
2831
2832         /* Validate obuf */
2833         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2834         ut_params->digest,
2835         tdata->digest.data,
2836         DIGEST_BYTE_LENGTH_KASUMI_F9,
2837         "KASUMI Generated auth tag not as expected");
2838
2839         return 0;
2840 }
2841
2842 static int
2843 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2844 {
2845         struct crypto_testsuite_params *ts_params = &testsuite_params;
2846         struct crypto_unittest_params *ut_params = &unittest_params;
2847
2848         int retval;
2849         unsigned plaintext_pad_len;
2850         unsigned plaintext_len;
2851         uint8_t *plaintext;
2852
2853         /* Create KASUMI session */
2854         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2855                                 tdata->key.data, tdata->key.len,
2856                                 0, tdata->digest.len,
2857                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2858                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2859         if (retval < 0)
2860                 return retval;
2861         /* alloc mbuf and set payload */
2862         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2863
2864         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2865         rte_pktmbuf_tailroom(ut_params->ibuf));
2866
2867         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2868         /* Append data which is padded to a multiple */
2869         /* of the algorithms block size */
2870         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2871         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2872                                 plaintext_pad_len);
2873         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2874
2875         /* Create KASUMI operation */
2876         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2877                         tdata->digest.len,
2878                         NULL, 0,
2879                         plaintext_pad_len,
2880                         RTE_CRYPTO_AUTH_OP_VERIFY,
2881                         tdata->plaintext.len,
2882                         0);
2883         if (retval < 0)
2884                 return retval;
2885
2886         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2887                                 ut_params->op);
2888         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2889         ut_params->obuf = ut_params->op->sym->m_src;
2890         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2891                                 + plaintext_pad_len;
2892
2893         /* Validate obuf */
2894         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2895                 return 0;
2896         else
2897                 return -1;
2898
2899         return 0;
2900 }
2901
2902 static int
2903 test_snow3g_hash_generate_test_case_1(void)
2904 {
2905         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2906 }
2907
2908 static int
2909 test_snow3g_hash_generate_test_case_2(void)
2910 {
2911         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2912 }
2913
2914 static int
2915 test_snow3g_hash_generate_test_case_3(void)
2916 {
2917         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2918 }
2919
2920 static int
2921 test_snow3g_hash_generate_test_case_4(void)
2922 {
2923         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2924 }
2925
2926 static int
2927 test_snow3g_hash_generate_test_case_5(void)
2928 {
2929         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2930 }
2931
2932 static int
2933 test_snow3g_hash_generate_test_case_6(void)
2934 {
2935         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2936 }
2937
2938 static int
2939 test_snow3g_hash_verify_test_case_1(void)
2940 {
2941         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2942
2943 }
2944
2945 static int
2946 test_snow3g_hash_verify_test_case_2(void)
2947 {
2948         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2949 }
2950
2951 static int
2952 test_snow3g_hash_verify_test_case_3(void)
2953 {
2954         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2955 }
2956
2957 static int
2958 test_snow3g_hash_verify_test_case_4(void)
2959 {
2960         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2961 }
2962
2963 static int
2964 test_snow3g_hash_verify_test_case_5(void)
2965 {
2966         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2967 }
2968
2969 static int
2970 test_snow3g_hash_verify_test_case_6(void)
2971 {
2972         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2973 }
2974
2975 static int
2976 test_kasumi_hash_generate_test_case_1(void)
2977 {
2978         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2979 }
2980
2981 static int
2982 test_kasumi_hash_generate_test_case_2(void)
2983 {
2984         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2985 }
2986
2987 static int
2988 test_kasumi_hash_generate_test_case_3(void)
2989 {
2990         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2991 }
2992
2993 static int
2994 test_kasumi_hash_generate_test_case_4(void)
2995 {
2996         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2997 }
2998
2999 static int
3000 test_kasumi_hash_generate_test_case_5(void)
3001 {
3002         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3003 }
3004
3005 static int
3006 test_kasumi_hash_generate_test_case_6(void)
3007 {
3008         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3009 }
3010
3011 static int
3012 test_kasumi_hash_verify_test_case_1(void)
3013 {
3014         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3015 }
3016
3017 static int
3018 test_kasumi_hash_verify_test_case_2(void)
3019 {
3020         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3021 }
3022
3023 static int
3024 test_kasumi_hash_verify_test_case_3(void)
3025 {
3026         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3027 }
3028
3029 static int
3030 test_kasumi_hash_verify_test_case_4(void)
3031 {
3032         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3033 }
3034
3035 static int
3036 test_kasumi_hash_verify_test_case_5(void)
3037 {
3038         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3039 }
3040
3041 static int
3042 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3043 {
3044         struct crypto_testsuite_params *ts_params = &testsuite_params;
3045         struct crypto_unittest_params *ut_params = &unittest_params;
3046
3047         int retval;
3048         uint8_t *plaintext, *ciphertext;
3049         unsigned plaintext_pad_len;
3050         unsigned plaintext_len;
3051
3052         /* Create KASUMI session */
3053         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3054                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3055                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3056                                         tdata->key.data, tdata->key.len,
3057                                         tdata->cipher_iv.len);
3058         if (retval < 0)
3059                 return retval;
3060
3061         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3062
3063         /* Clear mbuf payload */
3064         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3065                rte_pktmbuf_tailroom(ut_params->ibuf));
3066
3067         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3068         /* Append data which is padded to a multiple */
3069         /* of the algorithms block size */
3070         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3071         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3072                                 plaintext_pad_len);
3073         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3074
3075         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3076
3077         /* Create KASUMI operation */
3078         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3079                                 tdata->cipher_iv.len,
3080                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3081                                 tdata->validCipherOffsetInBits.len);
3082         if (retval < 0)
3083                 return retval;
3084
3085         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3086                                                 ut_params->op);
3087         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3088
3089         ut_params->obuf = ut_params->op->sym->m_dst;
3090         if (ut_params->obuf)
3091                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3092         else
3093                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3094
3095         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3096
3097         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3098                                 (tdata->validCipherOffsetInBits.len >> 3);
3099         /* Validate obuf */
3100         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3101                 ciphertext,
3102                 reference_ciphertext,
3103                 tdata->validCipherLenInBits.len,
3104                 "KASUMI Ciphertext data not as expected");
3105         return 0;
3106 }
3107
3108 static int
3109 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3110 {
3111         struct crypto_testsuite_params *ts_params = &testsuite_params;
3112         struct crypto_unittest_params *ut_params = &unittest_params;
3113
3114         int retval;
3115
3116         unsigned int plaintext_pad_len;
3117         unsigned int plaintext_len;
3118
3119         uint8_t buffer[10000];
3120         const uint8_t *ciphertext;
3121
3122         struct rte_cryptodev_info dev_info;
3123
3124         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3125         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3126                 printf("Device doesn't support scatter-gather. "
3127                                 "Test Skipped.\n");
3128                 return 0;
3129         }
3130
3131         /* Create KASUMI session */
3132         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3133                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3134                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3135                                         tdata->key.data, tdata->key.len,
3136                                         tdata->cipher_iv.len);
3137         if (retval < 0)
3138                 return retval;
3139
3140         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3141
3142
3143         /* Append data which is padded to a multiple */
3144         /* of the algorithms block size */
3145         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3146
3147         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3148                         plaintext_pad_len, 10, 0);
3149
3150         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3151
3152         /* Create KASUMI operation */
3153         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3154                                 tdata->cipher_iv.len,
3155                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3156                                 tdata->validCipherOffsetInBits.len);
3157         if (retval < 0)
3158                 return retval;
3159
3160         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3161                                                 ut_params->op);
3162         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3163
3164         ut_params->obuf = ut_params->op->sym->m_dst;
3165
3166         if (ut_params->obuf)
3167                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3168                                 plaintext_len, buffer);
3169         else
3170                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3171                                 tdata->validCipherOffsetInBits.len >> 3,
3172                                 plaintext_len, buffer);
3173
3174         /* Validate obuf */
3175         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3176
3177         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3178                                 (tdata->validCipherOffsetInBits.len >> 3);
3179         /* Validate obuf */
3180         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3181                 ciphertext,
3182                 reference_ciphertext,
3183                 tdata->validCipherLenInBits.len,
3184                 "KASUMI Ciphertext data not as expected");
3185         return 0;
3186 }
3187
3188 static int
3189 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3190 {
3191         struct crypto_testsuite_params *ts_params = &testsuite_params;
3192         struct crypto_unittest_params *ut_params = &unittest_params;
3193
3194         int retval;
3195         uint8_t *plaintext, *ciphertext;
3196         unsigned plaintext_pad_len;
3197         unsigned plaintext_len;
3198
3199         /* Create KASUMI session */
3200         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3201                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3202                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3203                                         tdata->key.data, tdata->key.len,
3204                                         tdata->cipher_iv.len);
3205         if (retval < 0)
3206                 return retval;
3207
3208         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3209         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3210
3211         /* Clear mbuf payload */
3212         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3213                rte_pktmbuf_tailroom(ut_params->ibuf));
3214
3215         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3216         /* Append data which is padded to a multiple */
3217         /* of the algorithms block size */
3218         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3219         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3220                                 plaintext_pad_len);
3221         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3222         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3223
3224         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3225
3226         /* Create KASUMI operation */
3227         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3228                                 tdata->cipher_iv.len,
3229                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3230                                 tdata->validCipherOffsetInBits.len);
3231         if (retval < 0)
3232                 return retval;
3233
3234         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3235                                                 ut_params->op);
3236         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3237
3238         ut_params->obuf = ut_params->op->sym->m_dst;
3239         if (ut_params->obuf)
3240                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3241         else
3242                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3243
3244         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3245
3246         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3247                                 (tdata->validCipherOffsetInBits.len >> 3);
3248         /* Validate obuf */
3249         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3250                 ciphertext,
3251                 reference_ciphertext,
3252                 tdata->validCipherLenInBits.len,
3253                 "KASUMI Ciphertext data not as expected");
3254         return 0;
3255 }
3256
3257 static int
3258 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3259 {
3260         struct crypto_testsuite_params *ts_params = &testsuite_params;
3261         struct crypto_unittest_params *ut_params = &unittest_params;
3262
3263         int retval;
3264         unsigned int plaintext_pad_len;
3265         unsigned int plaintext_len;
3266
3267         const uint8_t *ciphertext;
3268         uint8_t buffer[2048];
3269
3270         struct rte_cryptodev_info dev_info;
3271
3272         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3273         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3274                 printf("Device doesn't support scatter-gather. "
3275                                 "Test Skipped.\n");
3276                 return 0;
3277         }
3278
3279         /* Create KASUMI session */
3280         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3281                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3282                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3283                                         tdata->key.data, tdata->key.len,
3284                                         tdata->cipher_iv.len);
3285         if (retval < 0)
3286                 return retval;
3287
3288         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3289         /* Append data which is padded to a multiple */
3290         /* of the algorithms block size */
3291         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3292
3293         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3294                         plaintext_pad_len, 10, 0);
3295         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3296                         plaintext_pad_len, 3, 0);
3297
3298         /* Append data which is padded to a multiple */
3299         /* of the algorithms block size */
3300         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3301
3302         /* Create KASUMI operation */
3303         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3304                                 tdata->cipher_iv.len,
3305                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3306                                 tdata->validCipherOffsetInBits.len);
3307         if (retval < 0)
3308                 return retval;
3309
3310         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3311                                                 ut_params->op);
3312         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3313
3314         ut_params->obuf = ut_params->op->sym->m_dst;
3315         if (ut_params->obuf)
3316                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3317                                 plaintext_pad_len, buffer);
3318         else
3319                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3320                                 tdata->validCipherOffsetInBits.len >> 3,
3321                                 plaintext_pad_len, buffer);
3322
3323         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3324                                 (tdata->validCipherOffsetInBits.len >> 3);
3325         /* Validate obuf */
3326         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3327                 ciphertext,
3328                 reference_ciphertext,
3329                 tdata->validCipherLenInBits.len,
3330                 "KASUMI Ciphertext data not as expected");
3331         return 0;
3332 }
3333
3334
3335 static int
3336 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3337 {
3338         struct crypto_testsuite_params *ts_params = &testsuite_params;
3339         struct crypto_unittest_params *ut_params = &unittest_params;
3340
3341         int retval;
3342         uint8_t *ciphertext, *plaintext;
3343         unsigned ciphertext_pad_len;
3344         unsigned ciphertext_len;
3345
3346         /* Create KASUMI session */
3347         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3348                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3349                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3350                                         tdata->key.data, tdata->key.len,
3351                                         tdata->cipher_iv.len);
3352         if (retval < 0)
3353                 return retval;
3354
3355         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3356         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3357
3358         /* Clear mbuf payload */
3359         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3360                rte_pktmbuf_tailroom(ut_params->ibuf));
3361
3362         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3363         /* Append data which is padded to a multiple */
3364         /* of the algorithms block size */
3365         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3366         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3367                                 ciphertext_pad_len);
3368         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3369         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3370
3371         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3372
3373         /* Create KASUMI operation */
3374         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3375                                 tdata->cipher_iv.len,
3376                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3377                                 tdata->validCipherOffsetInBits.len);
3378         if (retval < 0)
3379                 return retval;
3380
3381         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3382                                                 ut_params->op);
3383         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3384
3385         ut_params->obuf = ut_params->op->sym->m_dst;
3386         if (ut_params->obuf)
3387                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3388         else
3389                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3390
3391         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3392
3393         const uint8_t *reference_plaintext = tdata->plaintext.data +
3394                                 (tdata->validCipherOffsetInBits.len >> 3);
3395         /* Validate obuf */
3396         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3397                 plaintext,
3398                 reference_plaintext,
3399                 tdata->validCipherLenInBits.len,
3400                 "KASUMI Plaintext data not as expected");
3401         return 0;
3402 }
3403
3404 static int
3405 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3406 {
3407         struct crypto_testsuite_params *ts_params = &testsuite_params;
3408         struct crypto_unittest_params *ut_params = &unittest_params;
3409
3410         int retval;
3411         uint8_t *ciphertext, *plaintext;
3412         unsigned ciphertext_pad_len;
3413         unsigned ciphertext_len;
3414
3415         /* Create KASUMI session */
3416         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3417                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3418                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3419                                         tdata->key.data, tdata->key.len,
3420                                         tdata->cipher_iv.len);
3421         if (retval < 0)
3422                 return retval;
3423
3424         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3425
3426         /* Clear mbuf payload */
3427         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3428                rte_pktmbuf_tailroom(ut_params->ibuf));
3429
3430         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3431         /* Append data which is padded to a multiple */
3432         /* of the algorithms block size */
3433         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3434         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3435                                 ciphertext_pad_len);
3436         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3437
3438         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3439
3440         /* Create KASUMI operation */
3441         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3442                                         tdata->cipher_iv.len,
3443                                         tdata->ciphertext.len,
3444                                         tdata->validCipherOffsetInBits.len);
3445         if (retval < 0)
3446                 return retval;
3447
3448         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3449                                                 ut_params->op);
3450         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3451
3452         ut_params->obuf = ut_params->op->sym->m_dst;
3453         if (ut_params->obuf)
3454                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3455         else
3456                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3457
3458         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3459
3460         const uint8_t *reference_plaintext = tdata->plaintext.data +
3461                                 (tdata->validCipherOffsetInBits.len >> 3);
3462         /* Validate obuf */
3463         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3464                 plaintext,
3465                 reference_plaintext,
3466                 tdata->validCipherLenInBits.len,
3467                 "KASUMI Plaintext data not as expected");
3468         return 0;
3469 }
3470
3471 static int
3472 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3473 {
3474         struct crypto_testsuite_params *ts_params = &testsuite_params;
3475         struct crypto_unittest_params *ut_params = &unittest_params;
3476
3477         int retval;
3478         uint8_t *plaintext, *ciphertext;
3479         unsigned plaintext_pad_len;
3480         unsigned plaintext_len;
3481
3482         /* Create SNOW 3G session */
3483         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3484                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3485                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3486                                         tdata->key.data, tdata->key.len,
3487                                         tdata->cipher_iv.len);
3488         if (retval < 0)
3489                 return retval;
3490
3491         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3492
3493         /* Clear mbuf payload */
3494         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3495                rte_pktmbuf_tailroom(ut_params->ibuf));
3496
3497         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3498         /* Append data which is padded to a multiple of */
3499         /* the algorithms block size */
3500         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3501         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3502                                 plaintext_pad_len);
3503         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3504
3505         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3506
3507         /* Create SNOW 3G operation */
3508         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3509                                         tdata->cipher_iv.len,
3510                                         tdata->validCipherLenInBits.len,
3511                                         0);
3512         if (retval < 0)
3513                 return retval;
3514
3515         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3516                                                 ut_params->op);
3517         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3518
3519         ut_params->obuf = ut_params->op->sym->m_dst;
3520         if (ut_params->obuf)
3521                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3522         else
3523                 ciphertext = plaintext;
3524
3525         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3526
3527         /* Validate obuf */
3528         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3529                 ciphertext,
3530                 tdata->ciphertext.data,
3531                 tdata->validDataLenInBits.len,
3532                 "SNOW 3G Ciphertext data not as expected");
3533         return 0;
3534 }
3535
3536
3537 static int
3538 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3539 {
3540         struct crypto_testsuite_params *ts_params = &testsuite_params;
3541         struct crypto_unittest_params *ut_params = &unittest_params;
3542         uint8_t *plaintext, *ciphertext;
3543
3544         int retval;
3545         unsigned plaintext_pad_len;
3546         unsigned plaintext_len;
3547
3548         /* Create SNOW 3G session */
3549         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3550                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3551                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3552                                         tdata->key.data, tdata->key.len,
3553                                         tdata->cipher_iv.len);
3554         if (retval < 0)
3555                 return retval;
3556
3557         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3558         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3559
3560         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3561                         "Failed to allocate input buffer in mempool");
3562         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3563                         "Failed to allocate output buffer in mempool");
3564
3565         /* Clear mbuf payload */
3566         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3567                rte_pktmbuf_tailroom(ut_params->ibuf));
3568
3569         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3570         /* Append data which is padded to a multiple of */
3571         /* the algorithms block size */
3572         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3573         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3574                                 plaintext_pad_len);
3575         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3576         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3577
3578         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3579
3580         /* Create SNOW 3G operation */
3581         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3582                                         tdata->cipher_iv.len,
3583                                         tdata->validCipherLenInBits.len,
3584                                         0);
3585         if (retval < 0)
3586                 return retval;
3587
3588         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3589                                                 ut_params->op);
3590         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3591
3592         ut_params->obuf = ut_params->op->sym->m_dst;
3593         if (ut_params->obuf)
3594                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3595         else
3596                 ciphertext = plaintext;
3597
3598         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3599
3600         /* Validate obuf */
3601         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3602                 ciphertext,
3603                 tdata->ciphertext.data,
3604                 tdata->validDataLenInBits.len,
3605                 "SNOW 3G Ciphertext data not as expected");
3606         return 0;
3607 }
3608
3609 static int
3610 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3611 {
3612         struct crypto_testsuite_params *ts_params = &testsuite_params;
3613         struct crypto_unittest_params *ut_params = &unittest_params;
3614
3615         int retval;
3616         unsigned int plaintext_pad_len;
3617         unsigned int plaintext_len;
3618         uint8_t buffer[10000];
3619         const uint8_t *ciphertext;
3620
3621         struct rte_cryptodev_info dev_info;
3622
3623         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3624         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3625                 printf("Device doesn't support scatter-gather. "
3626                                 "Test Skipped.\n");
3627                 return 0;
3628         }
3629
3630         /* Create SNOW 3G session */
3631         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3632                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3633                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3634                                         tdata->key.data, tdata->key.len,
3635                                         tdata->cipher_iv.len);
3636         if (retval < 0)
3637                 return retval;
3638
3639         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3640         /* Append data which is padded to a multiple of */
3641         /* the algorithms block size */
3642         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3643
3644         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3645                         plaintext_pad_len, 10, 0);
3646         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3647                         plaintext_pad_len, 3, 0);
3648
3649         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3650                         "Failed to allocate input buffer in mempool");
3651         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3652                         "Failed to allocate output buffer in mempool");
3653
3654         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3655
3656         /* Create SNOW 3G operation */
3657         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3658                                         tdata->cipher_iv.len,
3659                                         tdata->validCipherLenInBits.len,
3660                                         0);
3661         if (retval < 0)
3662                 return retval;
3663
3664         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3665                                                 ut_params->op);
3666         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3667
3668         ut_params->obuf = ut_params->op->sym->m_dst;
3669         if (ut_params->obuf)
3670                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3671                                 plaintext_len, buffer);
3672         else
3673                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3674                                 plaintext_len, buffer);
3675
3676         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3677
3678         /* Validate obuf */
3679         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3680                 ciphertext,
3681                 tdata->ciphertext.data,
3682                 tdata->validDataLenInBits.len,
3683                 "SNOW 3G Ciphertext data not as expected");
3684
3685         return 0;
3686 }
3687
3688 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3689 static void
3690 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3691 {
3692         uint8_t curr_byte, prev_byte;
3693         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3694         uint8_t lower_byte_mask = (1 << offset) - 1;
3695         unsigned i;
3696
3697         prev_byte = buffer[0];
3698         buffer[0] >>= offset;
3699
3700         for (i = 1; i < length_in_bytes; i++) {
3701                 curr_byte = buffer[i];
3702                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3703                                 (curr_byte >> offset);
3704                 prev_byte = curr_byte;
3705         }
3706 }
3707
3708 static int
3709 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3710 {
3711         struct crypto_testsuite_params *ts_params = &testsuite_params;
3712         struct crypto_unittest_params *ut_params = &unittest_params;
3713         uint8_t *plaintext, *ciphertext;
3714         int retval;
3715         uint32_t plaintext_len;
3716         uint32_t plaintext_pad_len;
3717         uint8_t extra_offset = 4;
3718         uint8_t *expected_ciphertext_shifted;
3719
3720         /* Create SNOW 3G session */
3721         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3722                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3723                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3724                                         tdata->key.data, tdata->key.len,
3725                                         tdata->cipher_iv.len);
3726         if (retval < 0)
3727                 return retval;
3728
3729         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3730         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3731
3732         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3733                         "Failed to allocate input buffer in mempool");
3734         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3735                         "Failed to allocate output buffer in mempool");
3736
3737         /* Clear mbuf payload */
3738         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3739                rte_pktmbuf_tailroom(ut_params->ibuf));
3740
3741         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3742         /*
3743          * Append data which is padded to a
3744          * multiple of the algorithms block size
3745          */
3746         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3747
3748         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3749                                                 plaintext_pad_len);
3750
3751         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3752
3753         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3754         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3755
3756 #ifdef RTE_APP_TEST_DEBUG
3757         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3758 #endif
3759         /* Create SNOW 3G operation */
3760         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3761                                         tdata->cipher_iv.len,
3762                                         tdata->validCipherLenInBits.len,
3763                                         extra_offset);
3764         if (retval < 0)
3765                 return retval;
3766
3767         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3768                                                 ut_params->op);
3769         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3770
3771         ut_params->obuf = ut_params->op->sym->m_dst;
3772         if (ut_params->obuf)
3773                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3774         else
3775                 ciphertext = plaintext;
3776
3777 #ifdef RTE_APP_TEST_DEBUG
3778         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3779 #endif
3780
3781         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
3782
3783         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3784                         "failed to reserve memory for ciphertext shifted\n");
3785
3786         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3787                         ceil_byte_length(tdata->ciphertext.len));
3788         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3789                         extra_offset);
3790         /* Validate obuf */
3791         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3792                 ciphertext,
3793                 expected_ciphertext_shifted,
3794                 tdata->validDataLenInBits.len,
3795                 extra_offset,
3796                 "SNOW 3G Ciphertext data not as expected");
3797         return 0;
3798 }
3799
3800 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3801 {
3802         struct crypto_testsuite_params *ts_params = &testsuite_params;
3803         struct crypto_unittest_params *ut_params = &unittest_params;
3804
3805         int retval;
3806
3807         uint8_t *plaintext, *ciphertext;
3808         unsigned ciphertext_pad_len;
3809         unsigned ciphertext_len;
3810
3811         /* Create SNOW 3G session */
3812         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3813                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3814                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3815                                         tdata->key.data, tdata->key.len,
3816                                         tdata->cipher_iv.len);
3817         if (retval < 0)
3818                 return retval;
3819
3820         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3821
3822         /* Clear mbuf payload */
3823         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3824                rte_pktmbuf_tailroom(ut_params->ibuf));
3825
3826         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3827         /* Append data which is padded to a multiple of */
3828         /* the algorithms block size */
3829         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3830         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3831                                 ciphertext_pad_len);
3832         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3833
3834         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3835
3836         /* Create SNOW 3G operation */
3837         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3838                                         tdata->cipher_iv.len,
3839                                         tdata->validCipherLenInBits.len,
3840                                         0);
3841         if (retval < 0)
3842                 return retval;
3843
3844         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3845                                                 ut_params->op);
3846         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3847         ut_params->obuf = ut_params->op->sym->m_dst;
3848         if (ut_params->obuf)
3849                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3850         else
3851                 plaintext = ciphertext;
3852
3853         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3854
3855         /* Validate obuf */
3856         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3857                                 tdata->plaintext.data,
3858                                 tdata->validDataLenInBits.len,
3859                                 "SNOW 3G Plaintext data not as expected");
3860         return 0;
3861 }
3862
3863 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3864 {
3865         struct crypto_testsuite_params *ts_params = &testsuite_params;
3866         struct crypto_unittest_params *ut_params = &unittest_params;
3867
3868         int retval;
3869
3870         uint8_t *plaintext, *ciphertext;
3871         unsigned ciphertext_pad_len;
3872         unsigned ciphertext_len;
3873
3874         /* Create SNOW 3G session */
3875         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3876                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3877                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3878                                         tdata->key.data, tdata->key.len,
3879                                         tdata->cipher_iv.len);
3880         if (retval < 0)
3881                 return retval;
3882
3883         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3884         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3885
3886         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3887                         "Failed to allocate input buffer");
3888         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3889                         "Failed to allocate output buffer");
3890
3891         /* Clear mbuf payload */
3892         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3893                rte_pktmbuf_tailroom(ut_params->ibuf));
3894
3895         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3896                        rte_pktmbuf_tailroom(ut_params->obuf));
3897
3898         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3899         /* Append data which is padded to a multiple of */
3900         /* the algorithms block size */
3901         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3902         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3903                                 ciphertext_pad_len);
3904         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3905         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3906
3907         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3908
3909         /* Create SNOW 3G operation */
3910         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3911                                         tdata->cipher_iv.len,
3912                                         tdata->validCipherLenInBits.len,
3913                                         0);
3914         if (retval < 0)
3915                 return retval;
3916
3917         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3918                                                 ut_params->op);
3919         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3920         ut_params->obuf = ut_params->op->sym->m_dst;
3921         if (ut_params->obuf)
3922                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3923         else
3924                 plaintext = ciphertext;
3925
3926         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3927
3928         /* Validate obuf */
3929         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3930                                 tdata->plaintext.data,
3931                                 tdata->validDataLenInBits.len,
3932                                 "SNOW 3G Plaintext data not as expected");
3933         return 0;
3934 }
3935
3936 static int
3937 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
3938 {
3939         struct crypto_testsuite_params *ts_params = &testsuite_params;
3940         struct crypto_unittest_params *ut_params = &unittest_params;
3941
3942         int retval;
3943
3944         uint8_t *plaintext, *ciphertext;
3945         unsigned int plaintext_pad_len;
3946         unsigned int plaintext_len;
3947
3948         struct rte_cryptodev_sym_capability_idx cap_idx;
3949
3950         /* Check if device supports ZUC EEA3 */
3951         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3952         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
3953
3954         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3955                         &cap_idx) == NULL)
3956                 return -ENOTSUP;
3957
3958         /* Check if device supports ZUC EIA3 */
3959         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3960         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
3961
3962         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3963                         &cap_idx) == NULL)
3964                 return -ENOTSUP;
3965
3966         /* Create ZUC session */
3967         retval = create_zuc_cipher_auth_encrypt_generate_session(
3968                         ts_params->valid_devs[0],
3969                         tdata);
3970         if (retval < 0)
3971                 return retval;
3972         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3973
3974         /* clear mbuf payload */
3975         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3976                         rte_pktmbuf_tailroom(ut_params->ibuf));
3977
3978         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3979         /* Append data which is padded to a multiple of */
3980         /* the algorithms block size */
3981         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3982         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3983                                 plaintext_pad_len);
3984         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3985
3986         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3987
3988         /* Create ZUC operation */
3989         retval = create_zuc_cipher_hash_generate_operation(tdata);
3990         if (retval < 0)
3991                 return retval;
3992
3993         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3994                         ut_params->op);
3995         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3996         ut_params->obuf = ut_params->op->sym->m_src;
3997         if (ut_params->obuf)
3998                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3999         else
4000                 ciphertext = plaintext;
4001
4002         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4003         /* Validate obuf */
4004         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4005                         ciphertext,
4006                         tdata->ciphertext.data,
4007                         tdata->validDataLenInBits.len,
4008                         "ZUC Ciphertext data not as expected");
4009
4010         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4011             + plaintext_pad_len;
4012
4013         /* Validate obuf */
4014         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4015                         ut_params->digest,
4016                         tdata->digest.data,
4017                         4,
4018                         "ZUC Generated auth tag not as expected");
4019         return 0;
4020 }
4021
4022 static int
4023 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4024 {
4025         struct crypto_testsuite_params *ts_params = &testsuite_params;
4026         struct crypto_unittest_params *ut_params = &unittest_params;
4027
4028         int retval;
4029
4030         uint8_t *plaintext, *ciphertext;
4031         unsigned plaintext_pad_len;
4032         unsigned plaintext_len;
4033
4034         /* Create SNOW 3G session */
4035         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4036                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4037                         RTE_CRYPTO_AUTH_OP_GENERATE,
4038                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4039                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4040                         tdata->key.data, tdata->key.len,
4041                         tdata->auth_iv.len, tdata->digest.len,
4042                         tdata->cipher_iv.len);
4043         if (retval < 0)
4044                 return retval;
4045         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4046
4047         /* clear mbuf payload */
4048         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4049                         rte_pktmbuf_tailroom(ut_params->ibuf));
4050
4051         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4052         /* Append data which is padded to a multiple of */
4053         /* the algorithms block size */
4054         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4055         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4056                                 plaintext_pad_len);
4057         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4058
4059         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4060
4061         /* Create SNOW 3G operation */
4062         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4063                         tdata->digest.len, tdata->auth_iv.data,
4064                         tdata->auth_iv.len,
4065                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4066                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4067                         tdata->validCipherLenInBits.len,
4068                         0,
4069                         tdata->validAuthLenInBits.len,
4070                         0
4071                         );
4072         if (retval < 0)
4073                 return retval;
4074
4075         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4076                         ut_params->op);
4077         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4078         ut_params->obuf = ut_params->op->sym->m_src;
4079         if (ut_params->obuf)
4080                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4081         else
4082                 ciphertext = plaintext;
4083
4084         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4085         /* Validate obuf */
4086         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4087                         ciphertext,
4088                         tdata->ciphertext.data,
4089                         tdata->validDataLenInBits.len,
4090                         "SNOW 3G Ciphertext data not as expected");
4091
4092         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4093             + plaintext_pad_len;
4094
4095         /* Validate obuf */
4096         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4097                         ut_params->digest,
4098                         tdata->digest.data,
4099                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4100                         "SNOW 3G Generated auth tag not as expected");
4101         return 0;
4102 }
4103 static int
4104 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
4105 {
4106         struct crypto_testsuite_params *ts_params = &testsuite_params;
4107         struct crypto_unittest_params *ut_params = &unittest_params;
4108
4109         int retval;
4110
4111         uint8_t *plaintext, *ciphertext;
4112         unsigned plaintext_pad_len;
4113         unsigned plaintext_len;
4114
4115         /* Create SNOW 3G session */
4116         retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
4117                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4118                         RTE_CRYPTO_AUTH_OP_GENERATE,
4119                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4120                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4121                         tdata->key.data, tdata->key.len,
4122                         tdata->auth_iv.len, tdata->digest.len,
4123                         tdata->cipher_iv.len);
4124         if (retval < 0)
4125                 return retval;
4126
4127         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4128
4129         /* clear mbuf payload */
4130         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4131                         rte_pktmbuf_tailroom(ut_params->ibuf));
4132
4133         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4134         /* Append data which is padded to a multiple of */
4135         /* the algorithms block size */
4136         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4137         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4138                                 plaintext_pad_len);
4139         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4140
4141         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4142
4143         /* Create SNOW 3G operation */
4144         retval = create_wireless_algo_auth_cipher_operation(
4145                 tdata->digest.len,
4146                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4147                 tdata->auth_iv.data, tdata->auth_iv.len,
4148                 plaintext_pad_len,
4149                 tdata->validCipherLenInBits.len,
4150                 0,
4151                 tdata->validAuthLenInBits.len,
4152                 0);
4153
4154         if (retval < 0)
4155                 return retval;
4156
4157         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4158                         ut_params->op);
4159         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4160         ut_params->obuf = ut_params->op->sym->m_src;
4161         if (ut_params->obuf)
4162                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4163         else
4164                 ciphertext = plaintext;
4165
4166         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4167                         + plaintext_pad_len;
4168         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4169
4170         /* Validate obuf */
4171         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4172                 ciphertext,
4173                 tdata->ciphertext.data,
4174                 tdata->validDataLenInBits.len,
4175                 "SNOW 3G Ciphertext data not as expected");
4176
4177         /* Validate obuf */
4178         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4179                 ut_params->digest,
4180                 tdata->digest.data,
4181                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4182                 "SNOW 3G Generated auth tag not as expected");
4183         return 0;
4184 }
4185
4186 static int
4187 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
4188 {
4189         struct crypto_testsuite_params *ts_params = &testsuite_params;
4190         struct crypto_unittest_params *ut_params = &unittest_params;
4191
4192         int retval;
4193
4194         uint8_t *plaintext, *ciphertext;
4195         unsigned plaintext_pad_len;
4196         unsigned plaintext_len;
4197
4198         /* Create KASUMI session */
4199         retval = create_wireless_algo_auth_cipher_session(
4200                         ts_params->valid_devs[0],
4201                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4202                         RTE_CRYPTO_AUTH_OP_GENERATE,
4203                         RTE_CRYPTO_AUTH_KASUMI_F9,
4204                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4205                         tdata->key.data, tdata->key.len,
4206                         0, tdata->digest.len,
4207                         tdata->cipher_iv.len);
4208         if (retval < 0)
4209                 return retval;
4210         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4211
4212         /* clear mbuf payload */
4213         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4214                         rte_pktmbuf_tailroom(ut_params->ibuf));
4215
4216         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4217         /* Append data which is padded to a multiple of */
4218         /* the algorithms block size */
4219         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4220         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4221                                 plaintext_pad_len);
4222         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4223
4224         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4225
4226         /* Create KASUMI operation */
4227         retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
4228                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4229                                 NULL, 0,
4230                                 plaintext_pad_len,
4231                                 tdata->validCipherLenInBits.len,
4232                                 tdata->validCipherOffsetInBits.len,
4233                                 tdata->validAuthLenInBits.len,
4234                                 0
4235                                 );
4236
4237         if (retval < 0)
4238                 return retval;
4239
4240         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4241                         ut_params->op);
4242         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4243         if (ut_params->op->sym->m_dst)
4244                 ut_params->obuf = ut_params->op->sym->m_dst;
4245         else
4246                 ut_params->obuf = ut_params->op->sym->m_src;
4247
4248         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4249                                 tdata->validCipherOffsetInBits.len >> 3);
4250
4251         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4252                                 (tdata->validCipherOffsetInBits.len >> 3);
4253         /* Validate obuf */
4254         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4255                         ciphertext,
4256                         reference_ciphertext,
4257                         tdata->validCipherLenInBits.len,
4258                         "KASUMI Ciphertext data not as expected");
4259         ut_params->digest = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *)
4260             + plaintext_pad_len;
4261
4262         /* Validate obuf */
4263         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4264                         ut_params->digest,
4265                         tdata->digest.data,
4266                         DIGEST_BYTE_LENGTH_KASUMI_F9,
4267                         "KASUMI Generated auth tag not as expected");
4268         return 0;
4269 }
4270
4271 static int
4272 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
4273 {
4274         struct crypto_testsuite_params *ts_params = &testsuite_params;
4275         struct crypto_unittest_params *ut_params = &unittest_params;
4276
4277         int retval;
4278
4279         uint8_t *plaintext, *ciphertext;
4280         unsigned plaintext_pad_len;
4281         unsigned plaintext_len;
4282
4283         /* Create KASUMI session */
4284         retval = create_wireless_algo_cipher_auth_session(
4285                         ts_params->valid_devs[0],
4286                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4287                         RTE_CRYPTO_AUTH_OP_GENERATE,
4288                         RTE_CRYPTO_AUTH_KASUMI_F9,
4289                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4290                         tdata->key.data, tdata->key.len,
4291                         0, tdata->digest.len,
4292                         tdata->cipher_iv.len);
4293         if (retval < 0)
4294                 return retval;
4295
4296         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4297
4298         /* clear mbuf payload */
4299         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4300                         rte_pktmbuf_tailroom(ut_params->ibuf));
4301
4302         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4303         /* Append data which is padded to a multiple of */
4304         /* the algorithms block size */
4305         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4306         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4307                                 plaintext_pad_len);
4308         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4309
4310         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4311
4312         /* Create KASUMI operation */
4313         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4314                                 tdata->digest.len, NULL, 0,
4315                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4316                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4317                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4318                                 tdata->validCipherOffsetInBits.len,
4319                                 tdata->validAuthLenInBits.len,
4320                                 0
4321                                 );
4322         if (retval < 0)
4323                 return retval;
4324
4325         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4326                         ut_params->op);
4327         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4328
4329         if (ut_params->op->sym->m_dst)
4330                 ut_params->obuf = ut_params->op->sym->m_dst;
4331         else
4332                 ut_params->obuf = ut_params->op->sym->m_src;
4333
4334         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4335                                 tdata->validCipherOffsetInBits.len >> 3);
4336
4337         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4338                         + plaintext_pad_len;
4339
4340         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4341                                 (tdata->validCipherOffsetInBits.len >> 3);
4342         /* Validate obuf */
4343         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4344                 ciphertext,
4345                 reference_ciphertext,
4346                 tdata->validCipherLenInBits.len,
4347                 "KASUMI Ciphertext data not as expected");
4348
4349         /* Validate obuf */
4350         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4351                 ut_params->digest,
4352                 tdata->digest.data,
4353                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4354                 "KASUMI Generated auth tag not as expected");
4355         return 0;
4356 }
4357
4358 static int
4359 test_zuc_encryption(const struct wireless_test_data *tdata)
4360 {
4361         struct crypto_testsuite_params *ts_params = &testsuite_params;
4362         struct crypto_unittest_params *ut_params = &unittest_params;
4363
4364         int retval;
4365         uint8_t *plaintext, *ciphertext;
4366         unsigned plaintext_pad_len;
4367         unsigned plaintext_len;
4368
4369         struct rte_cryptodev_sym_capability_idx cap_idx;
4370
4371         /* Check if device supports ZUC EEA3 */
4372         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4373         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4374
4375         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4376                         &cap_idx) == NULL)
4377                 return -ENOTSUP;
4378
4379         /* Create ZUC session */
4380         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4381                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4382                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4383                                         tdata->key.data, tdata->key.len,
4384                                         tdata->cipher_iv.len);
4385         if (retval < 0)
4386                 return retval;
4387
4388         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4389
4390         /* Clear mbuf payload */
4391         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4392                rte_pktmbuf_tailroom(ut_params->ibuf));
4393
4394         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4395         /* Append data which is padded to a multiple */
4396         /* of the algorithms block size */
4397         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4398         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4399                                 plaintext_pad_len);
4400         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4401
4402         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4403
4404         /* Create ZUC operation */
4405         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4406                                         tdata->cipher_iv.len,
4407                                         tdata->plaintext.len,
4408                                         0);
4409         if (retval < 0)
4410                 return retval;
4411
4412         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4413                                                 ut_params->op);
4414         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4415
4416         ut_params->obuf = ut_params->op->sym->m_dst;
4417         if (ut_params->obuf)
4418                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4419         else
4420                 ciphertext = plaintext;
4421
4422         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4423
4424         /* Validate obuf */
4425         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4426                 ciphertext,
4427                 tdata->ciphertext.data,
4428                 tdata->validCipherLenInBits.len,
4429                 "ZUC Ciphertext data not as expected");
4430         return 0;
4431 }
4432
4433 static int
4434 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
4435 {
4436         struct crypto_testsuite_params *ts_params = &testsuite_params;
4437         struct crypto_unittest_params *ut_params = &unittest_params;
4438
4439         int retval;
4440
4441         unsigned int plaintext_pad_len;
4442         unsigned int plaintext_len;
4443         const uint8_t *ciphertext;
4444         uint8_t ciphertext_buffer[2048];
4445         struct rte_cryptodev_info dev_info;
4446
4447         struct rte_cryptodev_sym_capability_idx cap_idx;
4448
4449         /* Check if device supports ZUC EEA3 */
4450         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4451         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4452
4453         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4454                         &cap_idx) == NULL)
4455                 return -ENOTSUP;
4456
4457         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4458         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
4459                 printf("Device doesn't support scatter-gather. "
4460                                 "Test Skipped.\n");
4461                 return -ENOTSUP;
4462         }
4463
4464         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4465
4466         /* Append data which is padded to a multiple */
4467         /* of the algorithms block size */
4468         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4469
4470         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4471                         plaintext_pad_len, 10, 0);
4472
4473         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4474                         tdata->plaintext.data);
4475
4476         /* Create ZUC session */
4477         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4478                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4479                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4480                         tdata->key.data, tdata->key.len,
4481                         tdata->cipher_iv.len);
4482         if (retval < 0)
4483                 return retval;
4484
4485         /* Clear mbuf payload */
4486
4487         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4488
4489         /* Create ZUC operation */
4490         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4491                         tdata->cipher_iv.len, tdata->plaintext.len,
4492                         0);
4493         if (retval < 0)
4494                 return retval;
4495
4496         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4497                                                 ut_params->op);
4498         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4499
4500         ut_params->obuf = ut_params->op->sym->m_dst;
4501         if (ut_params->obuf)
4502                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
4503                         0, plaintext_len, ciphertext_buffer);
4504         else
4505                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4506                         0, plaintext_len, ciphertext_buffer);
4507
4508         /* Validate obuf */
4509         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4510
4511         /* Validate obuf */
4512         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4513                 ciphertext,
4514                 tdata->ciphertext.data,
4515                 tdata->validCipherLenInBits.len,
4516                 "ZUC Ciphertext data not as expected");
4517
4518         return 0;
4519 }
4520
4521 static int
4522 test_zuc_authentication(const struct wireless_test_data *tdata)
4523 {
4524         struct crypto_testsuite_params *ts_params = &testsuite_params;
4525         struct crypto_unittest_params *ut_params = &unittest_params;
4526
4527         int retval;
4528         unsigned plaintext_pad_len;
4529         unsigned plaintext_len;
4530         uint8_t *plaintext;
4531
4532         struct rte_cryptodev_sym_capability_idx cap_idx;
4533
4534         /* Check if device supports ZUC EIA3 */
4535         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4536         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4537
4538         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4539                         &cap_idx) == NULL)
4540                 return -ENOTSUP;
4541
4542         /* Create ZUC session */
4543         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
4544                         tdata->key.data, tdata->key.len,
4545                         tdata->auth_iv.len, tdata->digest.len,
4546                         RTE_CRYPTO_AUTH_OP_GENERATE,
4547                         RTE_CRYPTO_AUTH_ZUC_EIA3);
4548         if (retval < 0)
4549                 return retval;
4550
4551         /* alloc mbuf and set payload */
4552         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4553
4554         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4555         rte_pktmbuf_tailroom(ut_params->ibuf));
4556
4557         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4558         /* Append data which is padded to a multiple of */
4559         /* the algorithms block size */
4560         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4561         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4562                                 plaintext_pad_len);
4563         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4564
4565         /* Create ZUC operation */
4566         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
4567                         tdata->auth_iv.data, tdata->auth_iv.len,
4568                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4569                         tdata->validAuthLenInBits.len,
4570                         0);
4571         if (retval < 0)
4572                 return retval;
4573
4574         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4575                                 ut_params->op);
4576         ut_params->obuf = ut_params->op->sym->m_src;
4577         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4578         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4579                         + plaintext_pad_len;
4580
4581         /* Validate obuf */
4582         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4583         ut_params->digest,
4584         tdata->digest.data,
4585         DIGEST_BYTE_LENGTH_KASUMI_F9,
4586         "ZUC Generated auth tag not as expected");
4587
4588         return 0;
4589 }
4590
4591 static int
4592 test_kasumi_encryption_test_case_1(void)
4593 {
4594         return test_kasumi_encryption(&kasumi_test_case_1);
4595 }
4596
4597 static int
4598 test_kasumi_encryption_test_case_1_sgl(void)
4599 {
4600         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
4601 }
4602
4603 static int
4604 test_kasumi_encryption_test_case_1_oop(void)
4605 {
4606         return test_kasumi_encryption_oop(&kasumi_test_case_1);
4607 }
4608
4609 static int
4610 test_kasumi_encryption_test_case_1_oop_sgl(void)
4611 {
4612         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
4613 }
4614
4615 static int
4616 test_kasumi_encryption_test_case_2(void)
4617 {
4618         return test_kasumi_encryption(&kasumi_test_case_2);
4619 }
4620
4621 static int
4622 test_kasumi_encryption_test_case_3(void)
4623 {
4624         return test_kasumi_encryption(&kasumi_test_case_3);
4625 }
4626
4627 static int
4628 test_kasumi_encryption_test_case_4(void)
4629 {
4630         return test_kasumi_encryption(&kasumi_test_case_4);
4631 }
4632
4633 static int
4634 test_kasumi_encryption_test_case_5(void)
4635 {
4636         return test_kasumi_encryption(&kasumi_test_case_5);
4637 }
4638
4639 static int
4640 test_kasumi_decryption_test_case_1(void)
4641 {
4642         return test_kasumi_decryption(&kasumi_test_case_1);
4643 }
4644
4645 static int
4646 test_kasumi_decryption_test_case_1_oop(void)
4647 {
4648         return test_kasumi_decryption_oop(&kasumi_test_case_1);
4649 }
4650
4651 static int
4652 test_kasumi_decryption_test_case_2(void)
4653 {
4654         return test_kasumi_decryption(&kasumi_test_case_2);
4655 }
4656
4657 static int
4658 test_kasumi_decryption_test_case_3(void)
4659 {
4660         return test_kasumi_decryption(&kasumi_test_case_3);
4661 }
4662
4663 static int
4664 test_kasumi_decryption_test_case_4(void)
4665 {
4666         return test_kasumi_decryption(&kasumi_test_case_4);
4667 }
4668
4669 static int
4670 test_kasumi_decryption_test_case_5(void)
4671 {
4672         return test_kasumi_decryption(&kasumi_test_case_5);
4673 }
4674 static int
4675 test_snow3g_encryption_test_case_1(void)
4676 {
4677         return test_snow3g_encryption(&snow3g_test_case_1);
4678 }
4679
4680 static int
4681 test_snow3g_encryption_test_case_1_oop(void)
4682 {
4683         return test_snow3g_encryption_oop(&snow3g_test_case_1);
4684 }
4685
4686 static int
4687 test_snow3g_encryption_test_case_1_oop_sgl(void)
4688 {
4689         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
4690 }
4691
4692
4693 static int
4694 test_snow3g_encryption_test_case_1_offset_oop(void)
4695 {
4696         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
4697 }
4698
4699 static int
4700 test_snow3g_encryption_test_case_2(void)
4701 {
4702         return test_snow3g_encryption(&snow3g_test_case_2);
4703 }
4704
4705 static int
4706 test_snow3g_encryption_test_case_3(void)
4707 {
4708         return test_snow3g_encryption(&snow3g_test_case_3);
4709 }
4710
4711 static int
4712 test_snow3g_encryption_test_case_4(void)
4713 {
4714         return test_snow3g_encryption(&snow3g_test_case_4);
4715 }
4716
4717 static int
4718 test_snow3g_encryption_test_case_5(void)
4719 {
4720         return test_snow3g_encryption(&snow3g_test_case_5);
4721 }
4722
4723 static int
4724 test_snow3g_decryption_test_case_1(void)
4725 {
4726         return test_snow3g_decryption(&snow3g_test_case_1);
4727 }
4728
4729 static int
4730 test_snow3g_decryption_test_case_1_oop(void)
4731 {
4732         return test_snow3g_decryption_oop(&snow3g_test_case_1);
4733 }
4734
4735 static int
4736 test_snow3g_decryption_test_case_2(void)
4737 {
4738         return test_snow3g_decryption(&snow3g_test_case_2);
4739 }
4740
4741 static int
4742 test_snow3g_decryption_test_case_3(void)
4743 {
4744         return test_snow3g_decryption(&snow3g_test_case_3);
4745 }
4746
4747 static int
4748 test_snow3g_decryption_test_case_4(void)
4749 {
4750         return test_snow3g_decryption(&snow3g_test_case_4);
4751 }
4752
4753 static int
4754 test_snow3g_decryption_test_case_5(void)
4755 {
4756         return test_snow3g_decryption(&snow3g_test_case_5);
4757 }
4758 static int
4759 test_snow3g_cipher_auth_test_case_1(void)
4760 {
4761         return test_snow3g_cipher_auth(&snow3g_test_case_3);
4762 }
4763
4764 static int
4765 test_snow3g_auth_cipher_test_case_1(void)
4766 {
4767         return test_snow3g_auth_cipher(&snow3g_test_case_6);
4768 }
4769
4770 static int
4771 test_kasumi_auth_cipher_test_case_1(void)
4772 {
4773         return test_kasumi_auth_cipher(&kasumi_test_case_3);
4774 }
4775
4776 static int
4777 test_kasumi_cipher_auth_test_case_1(void)
4778 {
4779         return test_kasumi_cipher_auth(&kasumi_test_case_6);
4780 }
4781
4782 static int
4783 test_zuc_encryption_test_case_1(void)
4784 {
4785         return test_zuc_encryption(&zuc_test_case_cipher_193b);
4786 }
4787
4788 static int
4789 test_zuc_encryption_test_case_2(void)
4790 {
4791         return test_zuc_encryption(&zuc_test_case_cipher_800b);
4792 }
4793
4794 static int
4795 test_zuc_encryption_test_case_3(void)
4796 {
4797         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
4798 }
4799
4800 static int
4801 test_zuc_encryption_test_case_4(void)
4802 {
4803         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
4804 }
4805
4806 static int
4807 test_zuc_encryption_test_case_5(void)
4808 {
4809         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
4810 }
4811
4812 static int
4813 test_zuc_encryption_test_case_6_sgl(void)
4814 {
4815         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
4816 }
4817
4818 static int
4819 test_zuc_hash_generate_test_case_1(void)
4820 {
4821         return test_zuc_authentication(&zuc_test_case_auth_1b);
4822 }
4823
4824 static int
4825 test_zuc_hash_generate_test_case_2(void)
4826 {
4827         return test_zuc_authentication(&zuc_test_case_auth_90b);
4828 }
4829
4830 static int
4831 test_zuc_hash_generate_test_case_3(void)
4832 {
4833         return test_zuc_authentication(&zuc_test_case_auth_577b);
4834 }
4835
4836 static int
4837 test_zuc_hash_generate_test_case_4(void)
4838 {
4839         return test_zuc_authentication(&zuc_test_case_auth_2079b);
4840 }
4841
4842 static int
4843 test_zuc_hash_generate_test_case_5(void)
4844 {
4845         return test_zuc_authentication(&zuc_test_auth_5670b);
4846 }
4847
4848 static int
4849 test_zuc_hash_generate_test_case_6(void)
4850 {
4851         return test_zuc_authentication(&zuc_test_case_auth_128b);
4852 }
4853
4854 static int
4855 test_zuc_hash_generate_test_case_7(void)
4856 {
4857         return test_zuc_authentication(&zuc_test_case_auth_2080b);
4858 }
4859
4860 static int
4861 test_zuc_hash_generate_test_case_8(void)
4862 {
4863         return test_zuc_authentication(&zuc_test_case_auth_584b);
4864 }
4865
4866 static int
4867 test_zuc_cipher_auth_test_case_1(void)
4868 {
4869         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
4870 }
4871
4872 static int
4873 test_zuc_cipher_auth_test_case_2(void)
4874 {
4875         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
4876 }
4877
4878 static int
4879 test_3DES_chain_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_3DES_CHAIN_TYPE);
4891
4892         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4893
4894         return TEST_SUCCESS;
4895 }
4896
4897 static int
4898 test_DES_cipheronly_qat_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_QAT_SYM_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_cipheronly_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_CIPHERONLY_TYPE);
4929
4930         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4931
4932         return TEST_SUCCESS;
4933 }
4934
4935 static int
4936 test_DES_docsis_openssl_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_OPENSSL_PMD)),
4947                 BLKCIPHER_DES_DOCSIS_TYPE);
4948
4949         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4950
4951         return TEST_SUCCESS;
4952 }
4953
4954 static int
4955 test_DES_cipheronly_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_CIPHERONLY_TYPE);
4967
4968         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4969
4970         return TEST_SUCCESS;
4971 }
4972
4973 static int
4974 test_DES_docsis_mb_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_AESNI_MB_PMD)),
4985                 BLKCIPHER_DES_DOCSIS_TYPE);
4986
4987         TEST_ASSERT_EQUAL(status, 0, "Test failed");
4988
4989         return TEST_SUCCESS;
4990 }
4991
4992 static int
4993 test_3DES_chain_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_CHAIN_TYPE);
5005
5006         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5007
5008         return TEST_SUCCESS;
5009 }
5010
5011 static int
5012 test_3DES_cipheronly_dpaa_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_DPAA_SEC_PMD)),
5023                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5024
5025         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5026
5027         return TEST_SUCCESS;
5028 }
5029
5030 static int
5031 test_3DES_chain_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_CHAIN_TYPE);
5043
5044         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5045
5046         return TEST_SUCCESS;
5047 }
5048
5049 static int
5050 test_3DES_cipheronly_dpaa2_sec_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_DPAA2_SEC_PMD)),
5061                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5062
5063         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5064
5065         return TEST_SUCCESS;
5066 }
5067
5068 static int
5069 test_3DES_chain_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_CHAIN_TYPE);
5081
5082         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5083
5084         return TEST_SUCCESS;
5085 }
5086
5087 static int
5088 test_3DES_cipheronly_ccp_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_CCP_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_cipheronly_qat_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_QAT_SYM_PMD)),
5118                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5119
5120         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5121
5122         return TEST_SUCCESS;
5123 }
5124
5125 static int
5126 test_3DES_chain_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_CHAIN_TYPE);
5138
5139         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5140
5141         return TEST_SUCCESS;
5142 }
5143
5144 static int
5145 test_3DES_cipheronly_openssl_all(void)
5146 {
5147         struct crypto_testsuite_params *ts_params = &testsuite_params;
5148         int status;
5149
5150         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
5151                 ts_params->op_mpool,
5152                 ts_params->session_mpool,
5153                 ts_params->valid_devs[0],
5154                 rte_cryptodev_driver_id_get(
5155                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)),
5156                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
5157
5158         TEST_ASSERT_EQUAL(status, 0, "Test failed");
5159
5160         return TEST_SUCCESS;
5161 }
5162
5163 /* ***** AEAD algorithm Tests ***** */
5164
5165 static int
5166 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
5167                 enum rte_crypto_aead_operation op,
5168                 const uint8_t *key, const uint8_t key_len,
5169                 const uint16_t aad_len, const uint8_t auth_len,
5170                 uint8_t iv_len)
5171 {
5172         uint8_t aead_key[key_len];
5173
5174         struct crypto_testsuite_params *ts_params = &testsuite_params;
5175         struct crypto_unittest_params *ut_params = &unittest_params;
5176
5177         memcpy(aead_key, key, key_len);
5178
5179         /* Setup AEAD Parameters */
5180         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
5181         ut_params->aead_xform.next = NULL;
5182         ut_params->aead_xform.aead.algo = algo;
5183         ut_params->aead_xform.aead.op = op;
5184         ut_params->aead_xform.aead.key.data = aead_key;
5185         ut_params->aead_xform.aead.key.length = key_len;
5186         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
5187         ut_params->aead_xform.aead.iv.length = iv_len;
5188         ut_params->aead_xform.aead.digest_length = auth_len;
5189         ut_params->aead_xform.aead.aad_length = aad_len;
5190
5191         debug_hexdump(stdout, "key:", key, key_len);
5192
5193         /* Create Crypto session*/
5194         ut_params->sess = rte_cryptodev_sym_session_create(
5195                         ts_params->session_mpool);
5196
5197         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
5198                         &ut_params->aead_xform, ts_params->session_mpool);
5199
5200         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5201
5202         return 0;
5203 }
5204
5205 static int
5206 create_aead_xform(struct rte_crypto_op *op,
5207                 enum rte_crypto_aead_algorithm algo,
5208                 enum rte_crypto_aead_operation aead_op,
5209                 uint8_t *key, const uint8_t key_len,
5210                 const uint8_t aad_len, const uint8_t auth_len,
5211                 uint8_t iv_len)
5212 {
5213         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
5214                         "failed to allocate space for crypto transform");
5215
5216         struct rte_crypto_sym_op *sym_op = op->sym;
5217
5218         /* Setup AEAD Parameters */
5219         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
5220         sym_op->xform->next = NULL;
5221         sym_op->xform->aead.algo = algo;
5222         sym_op->xform->aead.op = aead_op;
5223         sym_op->xform->aead.key.data = key;
5224         sym_op->xform->aead.key.length = key_len;
5225         sym_op->xform->aead.iv.offset = IV_OFFSET;
5226         sym_op->xform->aead.iv.length = iv_len;
5227         sym_op->xform->aead.digest_length = auth_len;
5228         sym_op->xform->aead.aad_length = aad_len;
5229
5230         debug_hexdump(stdout, "key:", key, key_len);
5231
5232         return 0;
5233 }
5234
5235 static int
5236 create_aead_operation(enum rte_crypto_aead_operation op,
5237                 const struct aead_test_data *tdata)
5238 {
5239         struct crypto_testsuite_params *ts_params = &testsuite_params;
5240         struct crypto_unittest_params *ut_params = &unittest_params;
5241
5242         uint8_t *plaintext, *ciphertext;
5243         unsigned int aad_pad_len, plaintext_pad_len;
5244
5245         /* Generate Crypto op data structure */
5246         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5247                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5248         TEST_ASSERT_NOT_NULL(ut_params->op,
5249                         "Failed to allocate symmetric crypto operation struct");
5250
5251         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5252
5253         /* Append aad data */
5254         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
5255                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
5256                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5257                                 aad_pad_len);
5258                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
5259                                 "no room to append aad");
5260
5261                 sym_op->aead.aad.phys_addr =
5262                                 rte_pktmbuf_iova(ut_params->ibuf);
5263                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
5264                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
5265                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
5266                         tdata->aad.len);
5267
5268                 /* Append IV at the end of the crypto operation*/
5269                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
5270                                 uint8_t *, IV_OFFSET);
5271
5272                 /* Copy IV 1 byte after the IV pointer, according to the API */
5273                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
5274                 debug_hexdump(stdout, "iv:", iv_ptr,
5275                         tdata->iv.len);
5276         } else {
5277                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5278                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5279                                 aad_pad_len);
5280                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
5281                                 "no room to append aad");
5282
5283                 sym_op->aead.aad.phys_addr =
5284                                 rte_pktmbuf_iova(ut_params->ibuf);
5285                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
5286                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
5287                         tdata->aad.len);
5288
5289                 /* Append IV at the end of the crypto operation*/
5290                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
5291                                 uint8_t *, IV_OFFSET);
5292
5293                 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
5294                 debug_hexdump(stdout, "iv:", iv_ptr,
5295                         tdata->iv.len);
5296         }
5297
5298         /* Append plaintext/ciphertext */
5299         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
5300                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5301                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5302                                 plaintext_pad_len);
5303                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
5304
5305                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
5306                 debug_hexdump(stdout, "plaintext:", plaintext,
5307                                 tdata->plaintext.len);
5308
5309                 if (ut_params->obuf) {
5310                         ciphertext = (uint8_t *)rte_pktmbuf_append(
5311                                         ut_params->obuf,
5312                                         plaintext_pad_len + aad_pad_len);
5313                         TEST_ASSERT_NOT_NULL(ciphertext,
5314                                         "no room to append ciphertext");
5315
5316                         memset(ciphertext + aad_pad_len, 0,
5317                                         tdata->ciphertext.len);
5318                 }
5319         } else {
5320                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
5321                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5322                                 plaintext_pad_len);
5323                 TEST_ASSERT_NOT_NULL(ciphertext,
5324                                 "no room to append ciphertext");
5325
5326                 memcpy(ciphertext, tdata->ciphertext.data,
5327                                 tdata->ciphertext.len);
5328                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5329                                 tdata->ciphertext.len);
5330
5331                 if (ut_params->obuf) {
5332                         plaintext = (uint8_t *)rte_pktmbuf_append(
5333                                         ut_params->obuf,
5334                                         plaintext_pad_len + aad_pad_len);
5335                         TEST_ASSERT_NOT_NULL(plaintext,
5336                                         "no room to append plaintext");
5337
5338                         memset(plaintext + aad_pad_len, 0,
5339                                         tdata->plaintext.len);
5340                 }
5341         }
5342
5343         /* Append digest data */
5344         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
5345                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
5346                                 ut_params->obuf ? ut_params->obuf :
5347                                                 ut_params->ibuf,
5348                                                 tdata->auth_tag.len);
5349                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
5350                                 "no room to append digest");
5351                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
5352                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
5353                                 ut_params->obuf ? ut_params->obuf :
5354                                                 ut_params->ibuf,
5355                                                 plaintext_pad_len +
5356                                                 aad_pad_len);
5357         } else {
5358                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
5359                                 ut_params->ibuf, tdata->auth_tag.len);
5360                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
5361                                 "no room to append digest");
5362                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
5363                                 ut_params->ibuf,
5364                                 plaintext_pad_len + aad_pad_len);
5365
5366                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
5367                         tdata->auth_tag.len);
5368                 debug_hexdump(stdout, "digest:",
5369                         sym_op->aead.digest.data,
5370                         tdata->auth_tag.len);
5371         }
5372
5373         sym_op->aead.data.length = tdata->plaintext.len;
5374         sym_op->aead.data.offset = aad_pad_len;
5375
5376         return 0;
5377 }
5378
5379 static int
5380 test_authenticated_encryption(const struct aead_test_data *tdata)
5381 {
5382         struct crypto_testsuite_params *ts_params = &testsuite_params;
5383         struct crypto_unittest_params *ut_params = &unittest_params;
5384
5385         int retval;
5386         uint8_t *ciphertext, *auth_tag;
5387         uint16_t plaintext_pad_len;
5388         uint32_t i;
5389
5390         /* Create AEAD session */
5391         retval = create_aead_session(ts_params->valid_devs[0],
5392                         tdata->algo,
5393                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5394                         tdata->key.data, tdata->key.len,
5395                         tdata->aad.len, tdata->auth_tag.len,
5396                         tdata->iv.len);
5397         if (retval < 0)
5398                 return retval;
5399
5400         if (tdata->aad.len > MBUF_SIZE) {
5401                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5402                 /* Populate full size of add data */
5403                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
5404                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5405         } else
5406                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5407
5408         /* clear mbuf payload */
5409         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5410                         rte_pktmbuf_tailroom(ut_params->ibuf));
5411
5412         /* Create AEAD operation */
5413         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5414         if (retval < 0)
5415                 return retval;
5416
5417         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5418
5419         ut_params->op->sym->m_src = ut_params->ibuf;
5420
5421         /* Process crypto operation */
5422         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5423                         ut_params->op), "failed to process sym crypto op");
5424
5425         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5426                         "crypto op processing failed");
5427
5428         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5429
5430         if (ut_params->op->sym->m_dst) {
5431                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5432                                 uint8_t *);
5433                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5434                                 uint8_t *, plaintext_pad_len);
5435         } else {
5436                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5437                                 uint8_t *,
5438                                 ut_params->op->sym->cipher.data.offset);
5439                 auth_tag = ciphertext + plaintext_pad_len;
5440         }
5441
5442         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5443         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5444
5445         /* Validate obuf */
5446         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5447                         ciphertext,
5448                         tdata->ciphertext.data,
5449                         tdata->ciphertext.len,
5450                         "Ciphertext data not as expected");
5451
5452         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5453                         auth_tag,
5454                         tdata->auth_tag.data,
5455                         tdata->auth_tag.len,
5456                         "Generated auth tag not as expected");
5457
5458         return 0;
5459
5460 }
5461
5462 static int
5463 test_AES_GCM_authenticated_encryption_test_case_1(void)
5464 {
5465         return test_authenticated_encryption(&gcm_test_case_1);
5466 }
5467
5468 static int
5469 test_AES_GCM_authenticated_encryption_test_case_2(void)
5470 {
5471         return test_authenticated_encryption(&gcm_test_case_2);
5472 }
5473
5474 static int
5475 test_AES_GCM_authenticated_encryption_test_case_3(void)
5476 {
5477         return test_authenticated_encryption(&gcm_test_case_3);
5478 }
5479
5480 static int
5481 test_AES_GCM_authenticated_encryption_test_case_4(void)
5482 {
5483         return test_authenticated_encryption(&gcm_test_case_4);
5484 }
5485
5486 static int
5487 test_AES_GCM_authenticated_encryption_test_case_5(void)
5488 {
5489         return test_authenticated_encryption(&gcm_test_case_5);
5490 }
5491
5492 static int
5493 test_AES_GCM_authenticated_encryption_test_case_6(void)
5494 {
5495         return test_authenticated_encryption(&gcm_test_case_6);
5496 }
5497
5498 static int
5499 test_AES_GCM_authenticated_encryption_test_case_7(void)
5500 {
5501         return test_authenticated_encryption(&gcm_test_case_7);
5502 }
5503
5504 static int
5505 test_AES_GCM_auth_encryption_test_case_192_1(void)
5506 {
5507         return test_authenticated_encryption(&gcm_test_case_192_1);
5508 }
5509
5510 static int
5511 test_AES_GCM_auth_encryption_test_case_192_2(void)
5512 {
5513         return test_authenticated_encryption(&gcm_test_case_192_2);
5514 }
5515
5516 static int
5517 test_AES_GCM_auth_encryption_test_case_192_3(void)
5518 {
5519         return test_authenticated_encryption(&gcm_test_case_192_3);
5520 }
5521
5522 static int
5523 test_AES_GCM_auth_encryption_test_case_192_4(void)
5524 {
5525         return test_authenticated_encryption(&gcm_test_case_192_4);
5526 }
5527
5528 static int
5529 test_AES_GCM_auth_encryption_test_case_192_5(void)
5530 {
5531         return test_authenticated_encryption(&gcm_test_case_192_5);
5532 }
5533
5534 static int
5535 test_AES_GCM_auth_encryption_test_case_192_6(void)
5536 {
5537         return test_authenticated_encryption(&gcm_test_case_192_6);
5538 }
5539
5540 static int
5541 test_AES_GCM_auth_encryption_test_case_192_7(void)
5542 {
5543         return test_authenticated_encryption(&gcm_test_case_192_7);
5544 }
5545
5546 static int
5547 test_AES_GCM_auth_encryption_test_case_256_1(void)
5548 {
5549         return test_authenticated_encryption(&gcm_test_case_256_1);
5550 }
5551
5552 static int
5553 test_AES_GCM_auth_encryption_test_case_256_2(void)
5554 {
5555         return test_authenticated_encryption(&gcm_test_case_256_2);
5556 }
5557
5558 static int
5559 test_AES_GCM_auth_encryption_test_case_256_3(void)
5560 {
5561         return test_authenticated_encryption(&gcm_test_case_256_3);
5562 }
5563
5564 static int
5565 test_AES_GCM_auth_encryption_test_case_256_4(void)
5566 {
5567         return test_authenticated_encryption(&gcm_test_case_256_4);
5568 }
5569
5570 static int
5571 test_AES_GCM_auth_encryption_test_case_256_5(void)
5572 {
5573         return test_authenticated_encryption(&gcm_test_case_256_5);
5574 }
5575
5576 static int
5577 test_AES_GCM_auth_encryption_test_case_256_6(void)
5578 {
5579         return test_authenticated_encryption(&gcm_test_case_256_6);
5580 }
5581
5582 static int
5583 test_AES_GCM_auth_encryption_test_case_256_7(void)
5584 {
5585         return test_authenticated_encryption(&gcm_test_case_256_7);
5586 }
5587
5588 static int
5589 test_AES_GCM_auth_encryption_test_case_aad_1(void)
5590 {
5591         return test_authenticated_encryption(&gcm_test_case_aad_1);
5592 }
5593
5594 static int
5595 test_AES_GCM_auth_encryption_test_case_aad_2(void)
5596 {
5597         return test_authenticated_encryption(&gcm_test_case_aad_2);
5598 }
5599
5600 static int
5601 test_authenticated_decryption(const struct aead_test_data *tdata)
5602 {
5603         struct crypto_testsuite_params *ts_params = &testsuite_params;
5604         struct crypto_unittest_params *ut_params = &unittest_params;
5605
5606         int retval;
5607         uint8_t *plaintext;
5608         uint32_t i;
5609
5610         /* Create AEAD session */
5611         retval = create_aead_session(ts_params->valid_devs[0],
5612                         tdata->algo,
5613                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5614                         tdata->key.data, tdata->key.len,
5615                         tdata->aad.len, tdata->auth_tag.len,
5616                         tdata->iv.len);
5617         if (retval < 0)
5618                 return retval;
5619
5620         /* alloc mbuf and set payload */
5621         if (tdata->aad.len > MBUF_SIZE) {
5622                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5623                 /* Populate full size of add data */
5624                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
5625                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5626         } else
5627                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5628
5629         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5630                         rte_pktmbuf_tailroom(ut_params->ibuf));
5631
5632         /* Create AEAD operation */
5633         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5634         if (retval < 0)
5635                 return retval;
5636
5637         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5638
5639         ut_params->op->sym->m_src = ut_params->ibuf;
5640
5641         /* Process crypto operation */
5642         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5643                         ut_params->op), "failed to process sym crypto op");
5644
5645         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5646                         "crypto op processing failed");
5647
5648         if (ut_params->op->sym->m_dst)
5649                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5650                                 uint8_t *);
5651         else
5652                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5653                                 uint8_t *,
5654                                 ut_params->op->sym->cipher.data.offset);
5655
5656         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5657
5658         /* Validate obuf */
5659         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5660                         plaintext,
5661                         tdata->plaintext.data,
5662                         tdata->plaintext.len,
5663                         "Plaintext data not as expected");
5664
5665         TEST_ASSERT_EQUAL(ut_params->op->status,
5666                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5667                         "Authentication failed");
5668         return 0;
5669 }
5670
5671 static int
5672 test_AES_GCM_authenticated_decryption_test_case_1(void)
5673 {
5674         return test_authenticated_decryption(&gcm_test_case_1);
5675 }
5676
5677 static int
5678 test_AES_GCM_authenticated_decryption_test_case_2(void)
5679 {
5680         return test_authenticated_decryption(&gcm_test_case_2);
5681 }
5682
5683 static int
5684 test_AES_GCM_authenticated_decryption_test_case_3(void)
5685 {
5686         return test_authenticated_decryption(&gcm_test_case_3);
5687 }
5688
5689 static int
5690 test_AES_GCM_authenticated_decryption_test_case_4(void)
5691 {
5692         return test_authenticated_decryption(&gcm_test_case_4);
5693 }
5694
5695 static int
5696 test_AES_GCM_authenticated_decryption_test_case_5(void)
5697 {
5698         return test_authenticated_decryption(&gcm_test_case_5);
5699 }
5700
5701 static int
5702 test_AES_GCM_authenticated_decryption_test_case_6(void)
5703 {
5704         return test_authenticated_decryption(&gcm_test_case_6);
5705 }
5706
5707 static int
5708 test_AES_GCM_authenticated_decryption_test_case_7(void)
5709 {
5710         return test_authenticated_decryption(&gcm_test_case_7);
5711 }
5712
5713 static int
5714 test_AES_GCM_auth_decryption_test_case_192_1(void)
5715 {
5716         return test_authenticated_decryption(&gcm_test_case_192_1);
5717 }
5718
5719 static int
5720 test_AES_GCM_auth_decryption_test_case_192_2(void)
5721 {
5722         return test_authenticated_decryption(&gcm_test_case_192_2);
5723 }
5724
5725 static int
5726 test_AES_GCM_auth_decryption_test_case_192_3(void)
5727 {
5728         return test_authenticated_decryption(&gcm_test_case_192_3);
5729 }
5730
5731 static int
5732 test_AES_GCM_auth_decryption_test_case_192_4(void)
5733 {
5734         return test_authenticated_decryption(&gcm_test_case_192_4);
5735 }
5736
5737 static int
5738 test_AES_GCM_auth_decryption_test_case_192_5(void)
5739 {
5740         return test_authenticated_decryption(&gcm_test_case_192_5);
5741 }
5742
5743 static int
5744 test_AES_GCM_auth_decryption_test_case_192_6(void)
5745 {
5746         return test_authenticated_decryption(&gcm_test_case_192_6);
5747 }
5748
5749 static int
5750 test_AES_GCM_auth_decryption_test_case_192_7(void)
5751 {
5752         return test_authenticated_decryption(&gcm_test_case_192_7);
5753 }
5754
5755 static int
5756 test_AES_GCM_auth_decryption_test_case_256_1(void)
5757 {
5758         return test_authenticated_decryption(&gcm_test_case_256_1);
5759 }
5760
5761 static int
5762 test_AES_GCM_auth_decryption_test_case_256_2(void)
5763 {
5764         return test_authenticated_decryption(&gcm_test_case_256_2);
5765 }
5766
5767 static int
5768 test_AES_GCM_auth_decryption_test_case_256_3(void)
5769 {
5770         return test_authenticated_decryption(&gcm_test_case_256_3);
5771 }
5772
5773 static int
5774 test_AES_GCM_auth_decryption_test_case_256_4(void)
5775 {
5776         return test_authenticated_decryption(&gcm_test_case_256_4);
5777 }
5778
5779 static int
5780 test_AES_GCM_auth_decryption_test_case_256_5(void)
5781 {
5782         return test_authenticated_decryption(&gcm_test_case_256_5);
5783 }
5784
5785 static int
5786 test_AES_GCM_auth_decryption_test_case_256_6(void)
5787 {
5788         return test_authenticated_decryption(&gcm_test_case_256_6);
5789 }
5790
5791 static int
5792 test_AES_GCM_auth_decryption_test_case_256_7(void)
5793 {
5794         return test_authenticated_decryption(&gcm_test_case_256_7);
5795 }
5796
5797 static int
5798 test_AES_GCM_auth_decryption_test_case_aad_1(void)
5799 {
5800         return test_authenticated_decryption(&gcm_test_case_aad_1);
5801 }
5802
5803 static int
5804 test_AES_GCM_auth_decryption_test_case_aad_2(void)
5805 {
5806         return test_authenticated_decryption(&gcm_test_case_aad_2);
5807 }
5808
5809 static int
5810 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
5811 {
5812         struct crypto_testsuite_params *ts_params = &testsuite_params;
5813         struct crypto_unittest_params *ut_params = &unittest_params;
5814
5815         int retval;
5816         uint8_t *ciphertext, *auth_tag;
5817         uint16_t plaintext_pad_len;
5818
5819         /* Create AEAD session */
5820         retval = create_aead_session(ts_params->valid_devs[0],
5821                         tdata->algo,
5822                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5823                         tdata->key.data, tdata->key.len,
5824                         tdata->aad.len, tdata->auth_tag.len,
5825                         tdata->iv.len);
5826         if (retval < 0)
5827                 return retval;
5828
5829         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5830         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5831
5832         /* clear mbuf payload */
5833         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5834                         rte_pktmbuf_tailroom(ut_params->ibuf));
5835         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5836                         rte_pktmbuf_tailroom(ut_params->obuf));
5837
5838         /* Create AEAD operation */
5839         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5840         if (retval < 0)
5841                 return retval;
5842
5843         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5844
5845         ut_params->op->sym->m_src = ut_params->ibuf;
5846         ut_params->op->sym->m_dst = ut_params->obuf;
5847
5848         /* Process crypto operation */
5849         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5850                         ut_params->op), "failed to process sym crypto op");
5851
5852         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5853                         "crypto op processing failed");
5854
5855         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5856
5857         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5858                         ut_params->op->sym->cipher.data.offset);
5859         auth_tag = ciphertext + plaintext_pad_len;
5860
5861         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5862         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5863
5864         /* Validate obuf */
5865         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5866                         ciphertext,
5867                         tdata->ciphertext.data,
5868                         tdata->ciphertext.len,
5869                         "Ciphertext data not as expected");
5870
5871         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5872                         auth_tag,
5873                         tdata->auth_tag.data,
5874                         tdata->auth_tag.len,
5875                         "Generated auth tag not as expected");
5876
5877         return 0;
5878
5879 }
5880
5881 static int
5882 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
5883 {
5884         return test_authenticated_encryption_oop(&gcm_test_case_5);
5885 }
5886
5887 static int
5888 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
5889 {
5890         struct crypto_testsuite_params *ts_params = &testsuite_params;
5891         struct crypto_unittest_params *ut_params = &unittest_params;
5892
5893         int retval;
5894         uint8_t *plaintext;
5895
5896         /* Create AEAD session */
5897         retval = create_aead_session(ts_params->valid_devs[0],
5898                         tdata->algo,
5899                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5900                         tdata->key.data, tdata->key.len,
5901                         tdata->aad.len, tdata->auth_tag.len,
5902                         tdata->iv.len);
5903         if (retval < 0)
5904                 return retval;
5905
5906         /* alloc mbuf and set payload */
5907         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5908         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5909
5910         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5911                         rte_pktmbuf_tailroom(ut_params->ibuf));
5912         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5913                         rte_pktmbuf_tailroom(ut_params->obuf));
5914
5915         /* Create AEAD operation */
5916         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5917         if (retval < 0)
5918                 return retval;
5919
5920         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5921
5922         ut_params->op->sym->m_src = ut_params->ibuf;
5923         ut_params->op->sym->m_dst = ut_params->obuf;
5924
5925         /* Process crypto operation */
5926         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5927                         ut_params->op), "failed to process sym crypto op");
5928
5929         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5930                         "crypto op processing failed");
5931
5932         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5933                         ut_params->op->sym->cipher.data.offset);
5934
5935         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5936
5937         /* Validate obuf */
5938         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5939                         plaintext,
5940                         tdata->plaintext.data,
5941                         tdata->plaintext.len,
5942                         "Plaintext data not as expected");
5943
5944         TEST_ASSERT_EQUAL(ut_params->op->status,
5945                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5946                         "Authentication failed");
5947         return 0;
5948 }
5949
5950 static int
5951 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
5952 {
5953         return test_authenticated_decryption_oop(&gcm_test_case_5);
5954 }
5955
5956 static int
5957 test_authenticated_encryption_sessionless(
5958                 const struct aead_test_data *tdata)
5959 {
5960         struct crypto_testsuite_params *ts_params = &testsuite_params;
5961         struct crypto_unittest_params *ut_params = &unittest_params;
5962
5963         int retval;
5964         uint8_t *ciphertext, *auth_tag;
5965         uint16_t plaintext_pad_len;
5966         uint8_t key[tdata->key.len + 1];
5967
5968         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5969
5970         /* clear mbuf payload */
5971         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5972                         rte_pktmbuf_tailroom(ut_params->ibuf));
5973
5974         /* Create AEAD operation */
5975         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5976         if (retval < 0)
5977                 return retval;
5978
5979         /* Create GCM xform */
5980         memcpy(key, tdata->key.data, tdata->key.len);
5981         retval = create_aead_xform(ut_params->op,
5982                         tdata->algo,
5983                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5984                         key, tdata->key.len,
5985                         tdata->aad.len, tdata->auth_tag.len,
5986                         tdata->iv.len);
5987         if (retval < 0)
5988                 return retval;
5989
5990         ut_params->op->sym->m_src = ut_params->ibuf;
5991
5992         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
5993                         RTE_CRYPTO_OP_SESSIONLESS,
5994                         "crypto op session type not sessionless");
5995
5996         /* Process crypto operation */
5997         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5998                         ut_params->op), "failed to process sym crypto op");
5999
6000         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6001
6002         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6003                         "crypto op status not success");
6004
6005         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6006
6007         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6008                         ut_params->op->sym->cipher.data.offset);
6009         auth_tag = ciphertext + plaintext_pad_len;
6010
6011         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
6012         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
6013
6014         /* Validate obuf */
6015         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6016                         ciphertext,
6017                         tdata->ciphertext.data,
6018                         tdata->ciphertext.len,
6019                         "Ciphertext data not as expected");
6020
6021         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6022                         auth_tag,
6023                         tdata->auth_tag.data,
6024                         tdata->auth_tag.len,
6025                         "Generated auth tag not as expected");
6026
6027         return 0;
6028
6029 }
6030
6031 static int
6032 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
6033 {
6034         return test_authenticated_encryption_sessionless(
6035                         &gcm_test_case_5);
6036 }
6037
6038 static int
6039 test_authenticated_decryption_sessionless(
6040                 const struct aead_test_data *tdata)
6041 {
6042         struct crypto_testsuite_params *ts_params = &testsuite_params;
6043         struct crypto_unittest_params *ut_params = &unittest_params;
6044
6045         int retval;
6046         uint8_t *plaintext;
6047         uint8_t key[tdata->key.len + 1];
6048
6049         /* alloc mbuf and set payload */
6050         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6051
6052         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6053                         rte_pktmbuf_tailroom(ut_params->ibuf));
6054
6055         /* Create AEAD operation */
6056         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
6057         if (retval < 0)
6058                 return retval;
6059
6060         /* Create AEAD xform */
6061         memcpy(key, tdata->key.data, tdata->key.len);
6062         retval = create_aead_xform(ut_params->op,
6063                         tdata->algo,
6064                         RTE_CRYPTO_AEAD_OP_DECRYPT,
6065                         key, tdata->key.len,
6066                         tdata->aad.len, tdata->auth_tag.len,
6067                         tdata->iv.len);
6068         if (retval < 0)
6069                 return retval;
6070
6071         ut_params->op->sym->m_src = ut_params->ibuf;
6072
6073         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
6074                         RTE_CRYPTO_OP_SESSIONLESS,
6075                         "crypto op session type not sessionless");
6076
6077         /* Process crypto operation */
6078         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6079                         ut_params->op), "failed to process sym crypto op");
6080
6081         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6082
6083         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6084                         "crypto op status not success");
6085
6086         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6087                         ut_params->op->sym->cipher.data.offset);
6088
6089         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
6090
6091         /* Validate obuf */
6092         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6093                         plaintext,
6094                         tdata->plaintext.data,
6095                         tdata->plaintext.len,
6096                         "Plaintext data not as expected");
6097
6098         TEST_ASSERT_EQUAL(ut_params->op->status,
6099                         RTE_CRYPTO_OP_STATUS_SUCCESS,
6100                         "Authentication failed");
6101         return 0;
6102 }
6103
6104 static int
6105 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
6106 {
6107         return test_authenticated_decryption_sessionless(
6108                         &gcm_test_case_5);
6109 }
6110
6111 static int
6112 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
6113 {
6114         return test_authenticated_encryption(&ccm_test_case_128_1);
6115 }
6116
6117 static int
6118 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
6119 {
6120         return test_authenticated_encryption(&ccm_test_case_128_2);
6121 }
6122
6123 static int
6124 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
6125 {
6126         return test_authenticated_encryption(&ccm_test_case_128_3);
6127 }
6128
6129 static int
6130 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
6131 {
6132         return test_authenticated_decryption(&ccm_test_case_128_1);
6133 }
6134
6135 static int
6136 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
6137 {
6138         return test_authenticated_decryption(&ccm_test_case_128_2);
6139 }
6140
6141 static int
6142 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
6143 {
6144         return test_authenticated_decryption(&ccm_test_case_128_3);
6145 }
6146
6147 static int
6148 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
6149 {
6150         return test_authenticated_encryption(&ccm_test_case_192_1);
6151 }
6152
6153 static int
6154 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
6155 {
6156         return test_authenticated_encryption(&ccm_test_case_192_2);
6157 }
6158
6159 static int
6160 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
6161 {
6162         return test_authenticated_encryption(&ccm_test_case_192_3);
6163 }
6164
6165 static int
6166 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
6167 {
6168         return test_authenticated_decryption(&ccm_test_case_192_1);
6169 }
6170
6171 static int
6172 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
6173 {
6174         return test_authenticated_decryption(&ccm_test_case_192_2);
6175 }
6176
6177 static int
6178 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
6179 {
6180         return test_authenticated_decryption(&ccm_test_case_192_3);
6181 }
6182
6183 static int
6184 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
6185 {
6186         return test_authenticated_encryption(&ccm_test_case_256_1);
6187 }
6188
6189 static int
6190 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
6191 {
6192         return test_authenticated_encryption(&ccm_test_case_256_2);
6193 }
6194
6195 static int
6196 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
6197 {
6198         return test_authenticated_encryption(&ccm_test_case_256_3);
6199 }
6200
6201 static int
6202 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
6203 {
6204         return test_authenticated_decryption(&ccm_test_case_256_1);
6205 }
6206
6207 static int
6208 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
6209 {
6210         return test_authenticated_decryption(&ccm_test_case_256_2);
6211 }
6212
6213 static int
6214 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
6215 {
6216         return test_authenticated_decryption(&ccm_test_case_256_3);
6217 }
6218
6219 static int
6220 test_stats(void)
6221 {
6222         struct crypto_testsuite_params *ts_params = &testsuite_params;
6223         struct rte_cryptodev_stats stats;
6224         struct rte_cryptodev *dev;
6225         cryptodev_stats_get_t temp_pfn;
6226
6227         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
6228         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
6229                         &stats) == -ENODEV),
6230                 "rte_cryptodev_stats_get invalid dev failed");
6231         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
6232                 "rte_cryptodev_stats_get invalid Param failed");
6233         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
6234         temp_pfn = dev->dev_ops->stats_get;
6235         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
6236         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
6237                         == -ENOTSUP),
6238                 "rte_cryptodev_stats_get invalid Param failed");
6239         dev->dev_ops->stats_get = temp_pfn;
6240
6241         /* Test expected values */
6242         ut_setup();
6243         test_AES_CBC_HMAC_SHA1_encrypt_digest();
6244         ut_teardown();
6245         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6246                         &stats),
6247                 "rte_cryptodev_stats_get failed");
6248         TEST_ASSERT((stats.enqueued_count == 1),
6249                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6250         TEST_ASSERT((stats.dequeued_count == 1),
6251                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6252         TEST_ASSERT((stats.enqueue_err_count == 0),
6253                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6254         TEST_ASSERT((stats.dequeue_err_count == 0),
6255                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6256
6257         /* invalid device but should ignore and not reset device stats*/
6258         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
6259         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6260                         &stats),
6261                 "rte_cryptodev_stats_get failed");
6262         TEST_ASSERT((stats.enqueued_count == 1),
6263                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6264
6265         /* check that a valid reset clears stats */
6266         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
6267         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
6268                         &stats),
6269                                           "rte_cryptodev_stats_get failed");
6270         TEST_ASSERT((stats.enqueued_count == 0),
6271                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6272         TEST_ASSERT((stats.dequeued_count == 0),
6273                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
6274
6275         return TEST_SUCCESS;
6276 }
6277
6278 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
6279                                    struct crypto_unittest_params *ut_params,
6280                                    enum rte_crypto_auth_operation op,
6281                                    const struct HMAC_MD5_vector *test_case)
6282 {
6283         uint8_t key[64];
6284
6285         memcpy(key, test_case->key.data, test_case->key.len);
6286
6287         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6288         ut_params->auth_xform.next = NULL;
6289         ut_params->auth_xform.auth.op = op;
6290
6291         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
6292
6293         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
6294         ut_params->auth_xform.auth.key.length = test_case->key.len;
6295         ut_params->auth_xform.auth.key.data = key;
6296
6297         ut_params->sess = rte_cryptodev_sym_session_create(
6298                         ts_params->session_mpool);
6299
6300         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6301                         ut_params->sess, &ut_params->auth_xform,
6302                         ts_params->session_mpool);
6303
6304         if (ut_params->sess == NULL)
6305                 return TEST_FAILED;
6306
6307         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6308
6309         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6310                         rte_pktmbuf_tailroom(ut_params->ibuf));
6311
6312         return 0;
6313 }
6314
6315 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
6316                               const struct HMAC_MD5_vector *test_case,
6317                               uint8_t **plaintext)
6318 {
6319         uint16_t plaintext_pad_len;
6320
6321         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6322
6323         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
6324                                 16);
6325
6326         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6327                         plaintext_pad_len);
6328         memcpy(*plaintext, test_case->plaintext.data,
6329                         test_case->plaintext.len);
6330
6331         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6332                         ut_params->ibuf, MD5_DIGEST_LEN);
6333         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6334                         "no room to append digest");
6335         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
6336                         ut_params->ibuf, plaintext_pad_len);
6337
6338         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
6339                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
6340                            test_case->auth_tag.len);
6341         }
6342
6343         sym_op->auth.data.offset = 0;
6344         sym_op->auth.data.length = test_case->plaintext.len;
6345
6346         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6347         ut_params->op->sym->m_src = ut_params->ibuf;
6348
6349         return 0;
6350 }
6351
6352 static int
6353 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
6354 {
6355         uint16_t plaintext_pad_len;
6356         uint8_t *plaintext, *auth_tag;
6357
6358         struct crypto_testsuite_params *ts_params = &testsuite_params;
6359         struct crypto_unittest_params *ut_params = &unittest_params;
6360
6361         if (MD5_HMAC_create_session(ts_params, ut_params,
6362                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
6363                 return TEST_FAILED;
6364
6365         /* Generate Crypto op data structure */
6366         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6367                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6368         TEST_ASSERT_NOT_NULL(ut_params->op,
6369                         "Failed to allocate symmetric crypto operation struct");
6370
6371         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
6372                                 16);
6373
6374         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
6375                 return TEST_FAILED;
6376
6377         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6378                         ut_params->op), "failed to process sym crypto op");
6379
6380         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6381                         "crypto op processing failed");
6382
6383         if (ut_params->op->sym->m_dst) {
6384                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6385                                 uint8_t *, plaintext_pad_len);
6386         } else {
6387                 auth_tag = plaintext + plaintext_pad_len;
6388         }
6389
6390         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6391                         auth_tag,
6392                         test_case->auth_tag.data,
6393                         test_case->auth_tag.len,
6394                         "HMAC_MD5 generated tag not as expected");
6395
6396         return TEST_SUCCESS;
6397 }
6398
6399 static int
6400 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
6401 {
6402         uint8_t *plaintext;
6403
6404         struct crypto_testsuite_params *ts_params = &testsuite_params;
6405         struct crypto_unittest_params *ut_params = &unittest_params;
6406
6407         if (MD5_HMAC_create_session(ts_params, ut_params,
6408                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
6409                 return TEST_FAILED;
6410         }
6411
6412         /* Generate Crypto op data structure */
6413         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6414                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6415         TEST_ASSERT_NOT_NULL(ut_params->op,
6416                         "Failed to allocate symmetric crypto operation struct");
6417
6418         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
6419                 return TEST_FAILED;
6420
6421         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6422                         ut_params->op), "failed to process sym crypto op");
6423
6424         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6425                         "HMAC_MD5 crypto op processing failed");
6426
6427         return TEST_SUCCESS;
6428 }
6429
6430 static int
6431 test_MD5_HMAC_generate_case_1(void)
6432 {
6433         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
6434 }
6435
6436 static int
6437 test_MD5_HMAC_verify_case_1(void)
6438 {
6439         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
6440 }
6441
6442 static int
6443 test_MD5_HMAC_generate_case_2(void)
6444 {
6445         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
6446 }
6447
6448 static int
6449 test_MD5_HMAC_verify_case_2(void)
6450 {
6451         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
6452 }
6453
6454 static int
6455 test_multi_session(void)
6456 {
6457         struct crypto_testsuite_params *ts_params = &testsuite_params;
6458         struct crypto_unittest_params *ut_params = &unittest_params;
6459
6460         struct rte_cryptodev_info dev_info;
6461         struct rte_cryptodev_sym_session **sessions;
6462
6463         uint16_t i;
6464
6465         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
6466                         aes_cbc_key, hmac_sha512_key);
6467
6468
6469         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6470
6471         sessions = rte_malloc(NULL,
6472                         (sizeof(struct rte_cryptodev_sym_session *) *
6473                         dev_info.sym.max_nb_sessions) + 1, 0);
6474
6475         /* Create multiple crypto sessions*/
6476         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
6477
6478                 sessions[i] = rte_cryptodev_sym_session_create(
6479                                 ts_params->session_mpool);
6480
6481                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6482                                 sessions[i], &ut_params->auth_xform,
6483                                 ts_params->session_mpool);
6484                 TEST_ASSERT_NOT_NULL(sessions[i],
6485                                 "Session creation failed at session number %u",
6486                                 i);
6487
6488                 /* Attempt to send a request on each session */
6489                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
6490                         sessions[i],
6491                         ut_params,
6492                         ts_params,
6493                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
6494                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
6495                         aes_cbc_iv),
6496                         "Failed to perform decrypt on request number %u.", i);
6497                 /* free crypto operation structure */
6498                 if (ut_params->op)
6499                         rte_crypto_op_free(ut_params->op);
6500
6501                 /*
6502                  * free mbuf - both obuf and ibuf are usually the same,
6503                  * so check if they point at the same address is necessary,
6504                  * to avoid freeing the mbuf twice.
6505                  */
6506                 if (ut_params->obuf) {
6507                         rte_pktmbuf_free(ut_params->obuf);
6508                         if (ut_params->ibuf == ut_params->obuf)
6509                                 ut_params->ibuf = 0;
6510                         ut_params->obuf = 0;
6511                 }
6512                 if (ut_params->ibuf) {
6513                         rte_pktmbuf_free(ut_params->ibuf);
6514                         ut_params->ibuf = 0;
6515                 }
6516         }
6517
6518         /* Next session create should fail */
6519         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6520                         sessions[i], &ut_params->auth_xform,
6521                         ts_params->session_mpool);
6522         TEST_ASSERT_NULL(sessions[i],
6523                         "Session creation succeeded unexpectedly!");
6524
6525         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
6526                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
6527                                 sessions[i]);
6528                 rte_cryptodev_sym_session_free(sessions[i]);
6529         }
6530
6531         rte_free(sessions);
6532
6533         return TEST_SUCCESS;
6534 }
6535
6536 struct multi_session_params {
6537         struct crypto_unittest_params ut_params;
6538         uint8_t *cipher_key;
6539         uint8_t *hmac_key;
6540         const uint8_t *cipher;
6541         const uint8_t *digest;
6542         uint8_t *iv;
6543 };
6544
6545 #define MB_SESSION_NUMBER 3
6546
6547 static int
6548 test_multi_session_random_usage(void)
6549 {
6550         struct crypto_testsuite_params *ts_params = &testsuite_params;
6551         struct rte_cryptodev_info dev_info;
6552         struct rte_cryptodev_sym_session **sessions;
6553         uint32_t i, j;
6554         struct multi_session_params ut_paramz[] = {
6555
6556                 {
6557                         .cipher_key = ms_aes_cbc_key0,
6558                         .hmac_key = ms_hmac_key0,
6559                         .cipher = ms_aes_cbc_cipher0,
6560                         .digest = ms_hmac_digest0,
6561                         .iv = ms_aes_cbc_iv0
6562                 },
6563                 {
6564                         .cipher_key = ms_aes_cbc_key1,
6565                         .hmac_key = ms_hmac_key1,
6566                         .cipher = ms_aes_cbc_cipher1,
6567                         .digest = ms_hmac_digest1,
6568                         .iv = ms_aes_cbc_iv1
6569                 },
6570                 {
6571                         .cipher_key = ms_aes_cbc_key2,
6572                         .hmac_key = ms_hmac_key2,
6573                         .cipher = ms_aes_cbc_cipher2,
6574                         .digest = ms_hmac_digest2,
6575                         .iv = ms_aes_cbc_iv2
6576                 },
6577
6578         };
6579
6580         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6581
6582         sessions = rte_malloc(NULL,
6583                         (sizeof(struct rte_cryptodev_sym_session *)
6584                                         * dev_info.sym.max_nb_sessions) + 1, 0);
6585
6586         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6587                 sessions[i] = rte_cryptodev_sym_session_create(
6588                                 ts_params->session_mpool);
6589
6590                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
6591                                 sizeof(struct crypto_unittest_params));
6592
6593                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
6594                                 &ut_paramz[i].ut_params,
6595                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
6596
6597                 /* Create multiple crypto sessions*/
6598                 rte_cryptodev_sym_session_init(
6599                                 ts_params->valid_devs[0],
6600                                 sessions[i],
6601                                 &ut_paramz[i].ut_params.auth_xform,
6602                                 ts_params->session_mpool);
6603
6604                 TEST_ASSERT_NOT_NULL(sessions[i],
6605                                 "Session creation failed at session number %u",
6606                                 i);
6607
6608         }
6609
6610         srand(time(NULL));
6611         for (i = 0; i < 40000; i++) {
6612
6613                 j = rand() % MB_SESSION_NUMBER;
6614
6615                 TEST_ASSERT_SUCCESS(
6616                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
6617                                         sessions[j],
6618                                         &ut_paramz[j].ut_params,
6619                                         ts_params, ut_paramz[j].cipher,
6620                                         ut_paramz[j].digest,
6621                                         ut_paramz[j].iv),
6622                         "Failed to perform decrypt on request number %u.", i);
6623
6624                 if (ut_paramz[j].ut_params.op)
6625                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
6626
6627                 /*
6628                  * free mbuf - both obuf and ibuf are usually the same,
6629                  * so check if they point at the same address is necessary,
6630                  * to avoid freeing the mbuf twice.
6631                  */
6632                 if (ut_paramz[j].ut_params.obuf) {
6633                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
6634                         if (ut_paramz[j].ut_params.ibuf
6635                                         == ut_paramz[j].ut_params.obuf)
6636                                 ut_paramz[j].ut_params.ibuf = 0;
6637                         ut_paramz[j].ut_params.obuf = 0;
6638                 }
6639                 if (ut_paramz[j].ut_params.ibuf) {
6640                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
6641                         ut_paramz[j].ut_params.ibuf = 0;
6642                 }
6643         }
6644
6645         for (i = 0; i < MB_SESSION_NUMBER; i++) {
6646                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
6647                                 sessions[i]);
6648                 rte_cryptodev_sym_session_free(sessions[i]);
6649         }
6650
6651         rte_free(sessions);
6652
6653         return TEST_SUCCESS;
6654 }
6655
6656 static int
6657 test_null_cipher_only_operation(void)
6658 {
6659         struct crypto_testsuite_params *ts_params = &testsuite_params;
6660         struct crypto_unittest_params *ut_params = &unittest_params;
6661
6662         /* Generate test mbuf data and space for digest */
6663         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6664                         catch_22_quote, QUOTE_512_BYTES, 0);
6665
6666         /* Setup Cipher Parameters */
6667         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6668         ut_params->cipher_xform.next = NULL;
6669
6670         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6671         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6672
6673         ut_params->sess = rte_cryptodev_sym_session_create(
6674                         ts_params->session_mpool);
6675
6676         /* Create Crypto session*/
6677         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6678                                 ut_params->sess,
6679                                 &ut_params->cipher_xform,
6680                                 ts_params->session_mpool);
6681         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6682
6683         /* Generate Crypto op data structure */
6684         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6685                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6686         TEST_ASSERT_NOT_NULL(ut_params->op,
6687                         "Failed to allocate symmetric crypto operation struct");
6688
6689         /* Set crypto operation data parameters */
6690         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6691
6692         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6693
6694         /* set crypto operation source mbuf */
6695         sym_op->m_src = ut_params->ibuf;
6696
6697         sym_op->cipher.data.offset = 0;
6698         sym_op->cipher.data.length = QUOTE_512_BYTES;
6699
6700         /* Process crypto operation */
6701         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6702                         ut_params->op);
6703         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6704
6705         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6706                         "crypto operation processing failed");
6707
6708         /* Validate obuf */
6709         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6710                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6711                         catch_22_quote,
6712                         QUOTE_512_BYTES,
6713                         "Ciphertext data not as expected");
6714
6715         return TEST_SUCCESS;
6716 }
6717 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
6718                         0xab, 0xab, 0xab, 0xab,
6719                         0xab, 0xab, 0xab, 0xab,
6720                         0xab, 0xab, 0xab, 0xab};
6721 static int
6722 test_null_auth_only_operation(void)
6723 {
6724         struct crypto_testsuite_params *ts_params = &testsuite_params;
6725         struct crypto_unittest_params *ut_params = &unittest_params;
6726         uint8_t *digest;
6727
6728         /* Generate test mbuf data and space for digest */
6729         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6730                         catch_22_quote, QUOTE_512_BYTES, 0);
6731
6732         /* create a pointer for digest, but don't expect anything to be written
6733          * here in a NULL auth algo so no mbuf append done.
6734          */
6735         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6736                         QUOTE_512_BYTES);
6737         /* prefill the memory pointed to by digest */
6738         memcpy(digest, orig_data, sizeof(orig_data));
6739
6740         /* Setup HMAC Parameters */
6741         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6742         ut_params->auth_xform.next = NULL;
6743
6744         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6745         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6746
6747         ut_params->sess = rte_cryptodev_sym_session_create(
6748                         ts_params->session_mpool);
6749
6750         /* Create Crypto session*/
6751         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6752                         ut_params->sess, &ut_params->auth_xform,
6753                         ts_params->session_mpool);
6754         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6755
6756         /* Generate Crypto op data structure */
6757         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6758                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6759         TEST_ASSERT_NOT_NULL(ut_params->op,
6760                         "Failed to allocate symmetric crypto operation struct");
6761
6762         /* Set crypto operation data parameters */
6763         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6764
6765         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6766
6767         sym_op->m_src = ut_params->ibuf;
6768
6769         sym_op->auth.data.offset = 0;
6770         sym_op->auth.data.length = QUOTE_512_BYTES;
6771         sym_op->auth.digest.data = digest;
6772         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6773                         QUOTE_512_BYTES);
6774
6775         /* Process crypto operation */
6776         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6777                         ut_params->op);
6778         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6779
6780         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6781                         "crypto operation processing failed");
6782         /* Make sure memory pointed to by digest hasn't been overwritten */
6783         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6784                         orig_data,
6785                         digest,
6786                         sizeof(orig_data),
6787                         "Memory at digest ptr overwritten unexpectedly");
6788
6789         return TEST_SUCCESS;
6790 }
6791
6792
6793 static int
6794 test_null_cipher_auth_operation(void)
6795 {
6796         struct crypto_testsuite_params *ts_params = &testsuite_params;
6797         struct crypto_unittest_params *ut_params = &unittest_params;
6798         uint8_t *digest;
6799
6800         /* Generate test mbuf data and space for digest */
6801         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6802                         catch_22_quote, QUOTE_512_BYTES, 0);
6803
6804         /* create a pointer for digest, but don't expect anything to be written
6805          * here in a NULL auth algo so no mbuf append done.
6806          */
6807         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6808                         QUOTE_512_BYTES);
6809         /* prefill the memory pointed to by digest */
6810         memcpy(digest, orig_data, sizeof(orig_data));
6811
6812         /* Setup Cipher Parameters */
6813         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6814         ut_params->cipher_xform.next = &ut_params->auth_xform;
6815
6816         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6817         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6818
6819         /* Setup HMAC Parameters */
6820         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6821         ut_params->auth_xform.next = NULL;
6822
6823         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6824         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6825
6826         ut_params->sess = rte_cryptodev_sym_session_create(
6827                         ts_params->session_mpool);
6828
6829         /* Create Crypto session*/
6830         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6831                         ut_params->sess, &ut_params->cipher_xform,
6832                         ts_params->session_mpool);
6833         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6834
6835         /* Generate Crypto op data structure */
6836         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6837                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6838         TEST_ASSERT_NOT_NULL(ut_params->op,
6839                         "Failed to allocate symmetric crypto operation struct");
6840
6841         /* Set crypto operation data parameters */
6842         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6843
6844         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6845
6846         sym_op->m_src = ut_params->ibuf;
6847
6848         sym_op->cipher.data.offset = 0;
6849         sym_op->cipher.data.length = QUOTE_512_BYTES;
6850
6851         sym_op->auth.data.offset = 0;
6852         sym_op->auth.data.length = QUOTE_512_BYTES;
6853         sym_op->auth.digest.data = digest;
6854         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6855                         QUOTE_512_BYTES);
6856
6857         /* Process crypto operation */
6858         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6859                         ut_params->op);
6860         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6861
6862         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6863                         "crypto operation processing failed");
6864
6865         /* Validate obuf */
6866         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6867                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6868                         catch_22_quote,
6869                         QUOTE_512_BYTES,
6870                         "Ciphertext data not as expected");
6871         /* Make sure memory pointed to by digest hasn't been overwritten */
6872         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6873                         orig_data,
6874                         digest,
6875                         sizeof(orig_data),
6876                         "Memory at digest ptr overwritten unexpectedly");
6877
6878         return TEST_SUCCESS;
6879 }
6880
6881 static int
6882 test_null_auth_cipher_operation(void)
6883 {
6884         struct crypto_testsuite_params *ts_params = &testsuite_params;
6885         struct crypto_unittest_params *ut_params = &unittest_params;
6886         uint8_t *digest;
6887
6888         /* Generate test mbuf data */
6889         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6890                         catch_22_quote, QUOTE_512_BYTES, 0);
6891
6892         /* create a pointer for digest, but don't expect anything to be written
6893          * here in a NULL auth algo so no mbuf append done.
6894          */
6895         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
6896                                 QUOTE_512_BYTES);
6897         /* prefill the memory pointed to by digest */
6898         memcpy(digest, orig_data, sizeof(orig_data));
6899
6900         /* Setup Cipher Parameters */
6901         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6902         ut_params->cipher_xform.next = NULL;
6903
6904         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6905         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6906
6907         /* Setup HMAC Parameters */
6908         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6909         ut_params->auth_xform.next = &ut_params->cipher_xform;
6910
6911         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6912         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6913
6914         ut_params->sess = rte_cryptodev_sym_session_create(
6915                         ts_params->session_mpool);
6916
6917         /* Create Crypto session*/
6918         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6919                         ut_params->sess, &ut_params->cipher_xform,
6920                         ts_params->session_mpool);
6921         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6922
6923         /* Generate Crypto op data structure */
6924         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6925                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6926         TEST_ASSERT_NOT_NULL(ut_params->op,
6927                         "Failed to allocate symmetric crypto operation struct");
6928
6929         /* Set crypto operation data parameters */
6930         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6931
6932         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6933
6934         sym_op->m_src = ut_params->ibuf;
6935
6936         sym_op->cipher.data.offset = 0;
6937         sym_op->cipher.data.length = QUOTE_512_BYTES;
6938
6939         sym_op->auth.data.offset = 0;
6940         sym_op->auth.data.length = QUOTE_512_BYTES;
6941         sym_op->auth.digest.data = digest;
6942         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
6943                                         QUOTE_512_BYTES);
6944
6945         /* Process crypto operation */
6946         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6947                         ut_params->op);
6948         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6949
6950         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6951                         "crypto operation processing failed");
6952
6953         /* Validate obuf */
6954         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6955                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6956                         catch_22_quote,
6957                         QUOTE_512_BYTES,
6958                         "Ciphertext data not as expected");
6959         /* Make sure memory pointed to by digest hasn't been overwritten */
6960         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6961                         orig_data,
6962                         digest,
6963                         sizeof(orig_data),
6964                         "Memory at digest ptr overwritten unexpectedly");
6965
6966         return TEST_SUCCESS;
6967 }
6968
6969
6970 static int
6971 test_null_invalid_operation(void)
6972 {
6973         struct crypto_testsuite_params *ts_params = &testsuite_params;
6974         struct crypto_unittest_params *ut_params = &unittest_params;
6975         int ret;
6976
6977         /* Setup Cipher Parameters */
6978         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6979         ut_params->cipher_xform.next = NULL;
6980
6981         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
6982         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6983
6984         ut_params->sess = rte_cryptodev_sym_session_create(
6985                         ts_params->session_mpool);
6986
6987         /* Create Crypto session*/
6988         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
6989                         ut_params->sess, &ut_params->cipher_xform,
6990                         ts_params->session_mpool);
6991         TEST_ASSERT(ret < 0,
6992                         "Session creation succeeded unexpectedly");
6993
6994
6995         /* Setup HMAC Parameters */
6996         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6997         ut_params->auth_xform.next = NULL;
6998
6999         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
7000         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
7001
7002         ut_params->sess = rte_cryptodev_sym_session_create(
7003                         ts_params->session_mpool);
7004
7005         /* Create Crypto session*/
7006         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7007                         ut_params->sess, &ut_params->auth_xform,
7008                         ts_params->session_mpool);
7009         TEST_ASSERT(ret < 0,
7010                         "Session creation succeeded unexpectedly");
7011
7012         return TEST_SUCCESS;
7013 }
7014
7015
7016 #define NULL_BURST_LENGTH (32)
7017
7018 static int
7019 test_null_burst_operation(void)
7020 {
7021         struct crypto_testsuite_params *ts_params = &testsuite_params;
7022         struct crypto_unittest_params *ut_params = &unittest_params;
7023
7024         unsigned i, burst_len = NULL_BURST_LENGTH;
7025
7026         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
7027         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
7028
7029         /* Setup Cipher Parameters */
7030         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7031         ut_params->cipher_xform.next = &ut_params->auth_xform;
7032
7033         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
7034         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
7035
7036         /* Setup HMAC Parameters */
7037         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7038         ut_params->auth_xform.next = NULL;
7039
7040         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
7041         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
7042
7043         ut_params->sess = rte_cryptodev_sym_session_create(
7044                         ts_params->session_mpool);
7045
7046         /* Create Crypto session*/
7047         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
7048                         ut_params->sess, &ut_params->cipher_xform,
7049                         ts_params->session_mpool);
7050         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7051
7052         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
7053                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
7054                         burst_len, "failed to generate burst of crypto ops");
7055
7056         /* Generate an operation for each mbuf in burst */
7057         for (i = 0; i < burst_len; i++) {
7058                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7059
7060                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
7061
7062                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
7063                                 sizeof(unsigned));
7064                 *data = i;
7065
7066                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
7067
7068                 burst[i]->sym->m_src = m;
7069         }
7070
7071         /* Process crypto operation */
7072         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
7073                         0, burst, burst_len),
7074                         burst_len,
7075                         "Error enqueuing burst");
7076
7077         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
7078                         0, burst_dequeued, burst_len),
7079                         burst_len,
7080                         "Error dequeuing burst");
7081
7082
7083         for (i = 0; i < burst_len; i++) {
7084                 TEST_ASSERT_EQUAL(
7085                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
7086                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
7087                                         uint32_t *),
7088                         "data not as expected");
7089
7090                 rte_pktmbuf_free(burst[i]->sym->m_src);
7091                 rte_crypto_op_free(burst[i]);
7092         }
7093
7094         return TEST_SUCCESS;
7095 }
7096
7097 static void
7098 generate_gmac_large_plaintext(uint8_t *data)
7099 {
7100         uint16_t i;
7101
7102         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
7103                 memcpy(&data[i], &data[0], 32);
7104 }
7105
7106 static int
7107 create_gmac_operation(enum rte_crypto_auth_operation op,
7108                 const struct gmac_test_data *tdata)
7109 {
7110         struct crypto_testsuite_params *ts_params = &testsuite_params;
7111         struct crypto_unittest_params *ut_params = &unittest_params;
7112         struct rte_crypto_sym_op *sym_op;
7113
7114         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7115
7116         /* Generate Crypto op data structure */
7117         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7118                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7119         TEST_ASSERT_NOT_NULL(ut_params->op,
7120                         "Failed to allocate symmetric crypto operation struct");
7121
7122         sym_op = ut_params->op->sym;
7123
7124         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7125                         ut_params->ibuf, tdata->gmac_tag.len);
7126         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7127                         "no room to append digest");
7128
7129         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7130                         ut_params->ibuf, plaintext_pad_len);
7131
7132         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
7133                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
7134                                 tdata->gmac_tag.len);
7135                 debug_hexdump(stdout, "digest:",
7136                                 sym_op->auth.digest.data,
7137                                 tdata->gmac_tag.len);
7138         }
7139
7140         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7141                         uint8_t *, IV_OFFSET);
7142
7143         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7144
7145         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
7146
7147         sym_op->cipher.data.length = 0;
7148         sym_op->cipher.data.offset = 0;
7149
7150         sym_op->auth.data.offset = 0;
7151         sym_op->auth.data.length = tdata->plaintext.len;
7152
7153         return 0;
7154 }
7155
7156 static int create_gmac_session(uint8_t dev_id,
7157                 const struct gmac_test_data *tdata,
7158                 enum rte_crypto_auth_operation auth_op)
7159 {
7160         uint8_t auth_key[tdata->key.len];
7161
7162         struct crypto_testsuite_params *ts_params = &testsuite_params;
7163         struct crypto_unittest_params *ut_params = &unittest_params;
7164
7165         memcpy(auth_key, tdata->key.data, tdata->key.len);
7166
7167         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7168         ut_params->auth_xform.next = NULL;
7169
7170         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
7171         ut_params->auth_xform.auth.op = auth_op;
7172         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
7173         ut_params->auth_xform.auth.key.length = tdata->key.len;
7174         ut_params->auth_xform.auth.key.data = auth_key;
7175         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
7176         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
7177
7178
7179         ut_params->sess = rte_cryptodev_sym_session_create(
7180                         ts_params->session_mpool);
7181
7182         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7183                         &ut_params->auth_xform,
7184                         ts_params->session_mpool);
7185
7186         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7187
7188         return 0;
7189 }
7190
7191 static int
7192 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
7193 {
7194         struct crypto_testsuite_params *ts_params = &testsuite_params;
7195         struct crypto_unittest_params *ut_params = &unittest_params;
7196
7197         int retval;
7198
7199         uint8_t *auth_tag, *plaintext;
7200         uint16_t plaintext_pad_len;
7201
7202         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
7203                               "No GMAC length in the source data");
7204
7205         retval = create_gmac_session(ts_params->valid_devs[0],
7206                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
7207
7208         if (retval < 0)
7209                 return retval;
7210
7211         if (tdata->plaintext.len > MBUF_SIZE)
7212                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7213         else
7214                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7215         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7216                         "Failed to allocate input buffer in mempool");
7217
7218         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7219                         rte_pktmbuf_tailroom(ut_params->ibuf));
7220
7221         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7222         /*
7223          * Runtime generate the large plain text instead of use hard code
7224          * plain text vector. It is done to avoid create huge source file
7225          * with the test vector.
7226          */
7227         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
7228                 generate_gmac_large_plaintext(tdata->plaintext.data);
7229
7230         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7231                                 plaintext_pad_len);
7232         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7233
7234         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7235         debug_hexdump(stdout, "plaintext:", plaintext,
7236                         tdata->plaintext.len);
7237
7238         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
7239                         tdata);
7240
7241         if (retval < 0)
7242                 return retval;
7243
7244         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7245
7246         ut_params->op->sym->m_src = ut_params->ibuf;
7247
7248         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7249                         ut_params->op), "failed to process sym crypto op");
7250
7251         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7252                         "crypto op processing failed");
7253
7254         if (ut_params->op->sym->m_dst) {
7255                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7256                                 uint8_t *, plaintext_pad_len);
7257         } else {
7258                 auth_tag = plaintext + plaintext_pad_len;
7259         }
7260
7261         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
7262
7263         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7264                         auth_tag,
7265                         tdata->gmac_tag.data,
7266                         tdata->gmac_tag.len,
7267                         "GMAC Generated auth tag not as expected");
7268
7269         return 0;
7270 }
7271
7272 static int
7273 test_AES_GMAC_authentication_test_case_1(void)
7274 {
7275         return test_AES_GMAC_authentication(&gmac_test_case_1);
7276 }
7277
7278 static int
7279 test_AES_GMAC_authentication_test_case_2(void)
7280 {
7281         return test_AES_GMAC_authentication(&gmac_test_case_2);
7282 }
7283
7284 static int
7285 test_AES_GMAC_authentication_test_case_3(void)
7286 {
7287         return test_AES_GMAC_authentication(&gmac_test_case_3);
7288 }
7289
7290 static int
7291 test_AES_GMAC_authentication_test_case_4(void)
7292 {
7293         return test_AES_GMAC_authentication(&gmac_test_case_4);
7294 }
7295
7296 static int
7297 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
7298 {
7299         struct crypto_testsuite_params *ts_params = &testsuite_params;
7300         struct crypto_unittest_params *ut_params = &unittest_params;
7301         int retval;
7302         uint32_t plaintext_pad_len;
7303         uint8_t *plaintext;
7304
7305         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
7306                               "No GMAC length in the source data");
7307
7308         retval = create_gmac_session(ts_params->valid_devs[0],
7309                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
7310
7311         if (retval < 0)
7312                 return retval;
7313
7314         if (tdata->plaintext.len > MBUF_SIZE)
7315                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7316         else
7317                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7318         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7319                         "Failed to allocate input buffer in mempool");
7320
7321         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7322                         rte_pktmbuf_tailroom(ut_params->ibuf));
7323
7324         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7325
7326         /*
7327          * Runtime generate the large plain text instead of use hard code
7328          * plain text vector. It is done to avoid create huge source file
7329          * with the test vector.
7330          */
7331         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
7332                 generate_gmac_large_plaintext(tdata->plaintext.data);
7333
7334         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7335                                 plaintext_pad_len);
7336         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7337
7338         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7339         debug_hexdump(stdout, "plaintext:", plaintext,
7340                         tdata->plaintext.len);
7341
7342         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
7343                         tdata);
7344
7345         if (retval < 0)
7346                 return retval;
7347
7348         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7349
7350         ut_params->op->sym->m_src = ut_params->ibuf;
7351
7352         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7353                         ut_params->op), "failed to process sym crypto op");
7354
7355         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7356                         "crypto op processing failed");
7357
7358         return 0;
7359
7360 }
7361
7362 static int
7363 test_AES_GMAC_authentication_verify_test_case_1(void)
7364 {
7365         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
7366 }
7367
7368 static int
7369 test_AES_GMAC_authentication_verify_test_case_2(void)
7370 {
7371         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
7372 }
7373
7374 static int
7375 test_AES_GMAC_authentication_verify_test_case_3(void)
7376 {
7377         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
7378 }
7379
7380 static int
7381 test_AES_GMAC_authentication_verify_test_case_4(void)
7382 {
7383         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
7384 }
7385
7386 struct test_crypto_vector {
7387         enum rte_crypto_cipher_algorithm crypto_algo;
7388
7389         struct {
7390                 uint8_t data[64];
7391                 unsigned int len;
7392         } cipher_key;
7393
7394         struct {
7395                 uint8_t data[64];
7396                 unsigned int len;
7397         } iv;
7398
7399         struct {
7400                 const uint8_t *data;
7401                 unsigned int len;
7402         } plaintext;
7403
7404         struct {
7405                 const uint8_t *data;
7406                 unsigned int len;
7407         } ciphertext;
7408
7409         enum rte_crypto_auth_algorithm auth_algo;
7410
7411         struct {
7412                 uint8_t data[128];
7413                 unsigned int len;
7414         } auth_key;
7415
7416         struct {
7417                 const uint8_t *data;
7418                 unsigned int len;
7419         } aad;
7420
7421         struct {
7422                 uint8_t data[128];
7423                 unsigned int len;
7424         } digest;
7425 };
7426
7427 static const struct test_crypto_vector
7428 hmac_sha1_test_crypto_vector = {
7429         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
7430         .plaintext = {
7431                 .data = plaintext_hash,
7432                 .len = 512
7433         },
7434         .auth_key = {
7435                 .data = {
7436                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
7437                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
7438                         0xDE, 0xF4, 0xDE, 0xAD
7439                 },
7440                 .len = 20
7441         },
7442         .digest = {
7443                 .data = {
7444                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
7445                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
7446                         0x3F, 0x91, 0x64, 0x59
7447                 },
7448                 .len = 20
7449         }
7450 };
7451
7452 static const struct test_crypto_vector
7453 aes128_gmac_test_vector = {
7454         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
7455         .plaintext = {
7456                 .data = plaintext_hash,
7457                 .len = 512
7458         },
7459         .iv = {
7460                 .data = {
7461                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
7462                         0x08, 0x09, 0x0A, 0x0B
7463                 },
7464                 .len = 12
7465         },
7466         .auth_key = {
7467                 .data = {
7468                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
7469                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
7470                 },
7471                 .len = 16
7472         },
7473         .digest = {
7474                 .data = {
7475                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
7476                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
7477                 },
7478                 .len = 16
7479         }
7480 };
7481
7482 static const struct test_crypto_vector
7483 aes128cbc_hmac_sha1_test_vector = {
7484         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
7485         .cipher_key = {
7486                 .data = {
7487                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
7488                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
7489                 },
7490                 .len = 16
7491         },
7492         .iv = {
7493                 .data = {
7494                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
7495                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
7496                 },
7497                 .len = 16
7498         },
7499         .plaintext = {
7500                 .data = plaintext_hash,
7501                 .len = 512
7502         },
7503         .ciphertext = {
7504                 .data = ciphertext512_aes128cbc,
7505                 .len = 512
7506         },
7507         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
7508         .auth_key = {
7509                 .data = {
7510                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
7511                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
7512                         0xDE, 0xF4, 0xDE, 0xAD
7513                 },
7514                 .len = 20
7515         },
7516         .digest = {
7517                 .data = {
7518                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
7519                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
7520                         0x18, 0x8C, 0x1D, 0x32
7521                 },
7522                 .len = 20
7523         }
7524 };
7525
7526 static void
7527 data_corruption(uint8_t *data)
7528 {
7529         data[0] += 1;
7530 }
7531
7532 static void
7533 tag_corruption(uint8_t *data, unsigned int tag_offset)
7534 {
7535         data[tag_offset] += 1;
7536 }
7537
7538 static int
7539 create_auth_session(struct crypto_unittest_params *ut_params,
7540                 uint8_t dev_id,
7541                 const struct test_crypto_vector *reference,
7542                 enum rte_crypto_auth_operation auth_op)
7543 {
7544         struct crypto_testsuite_params *ts_params = &testsuite_params;
7545         uint8_t auth_key[reference->auth_key.len + 1];
7546
7547         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
7548
7549         /* Setup Authentication Parameters */
7550         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7551         ut_params->auth_xform.auth.op = auth_op;
7552         ut_params->auth_xform.next = NULL;
7553         ut_params->auth_xform.auth.algo = reference->auth_algo;
7554         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
7555         ut_params->auth_xform.auth.key.data = auth_key;
7556         ut_params->auth_xform.auth.digest_length = reference->digest.len;
7557
7558         /* Create Crypto session*/
7559         ut_params->sess = rte_cryptodev_sym_session_create(
7560                         ts_params->session_mpool);
7561
7562         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7563                                 &ut_params->auth_xform,
7564                                 ts_params->session_mpool);
7565
7566         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7567
7568         return 0;
7569 }
7570
7571 static int
7572 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
7573                 uint8_t dev_id,
7574                 const struct test_crypto_vector *reference,
7575                 enum rte_crypto_auth_operation auth_op,
7576                 enum rte_crypto_cipher_operation cipher_op)
7577 {
7578         struct crypto_testsuite_params *ts_params = &testsuite_params;
7579         uint8_t cipher_key[reference->cipher_key.len + 1];
7580         uint8_t auth_key[reference->auth_key.len + 1];
7581
7582         memcpy(cipher_key, reference->cipher_key.data,
7583                         reference->cipher_key.len);
7584         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
7585
7586         /* Setup Authentication Parameters */
7587         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7588         ut_params->auth_xform.auth.op = auth_op;
7589         ut_params->auth_xform.auth.algo = reference->auth_algo;
7590         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
7591         ut_params->auth_xform.auth.key.data = auth_key;
7592         ut_params->auth_xform.auth.digest_length = reference->digest.len;
7593
7594         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
7595                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
7596                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
7597         } else {
7598                 ut_params->auth_xform.next = &ut_params->cipher_xform;
7599
7600                 /* Setup Cipher Parameters */
7601                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7602                 ut_params->cipher_xform.next = NULL;
7603                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
7604                 ut_params->cipher_xform.cipher.op = cipher_op;
7605                 ut_params->cipher_xform.cipher.key.data = cipher_key;
7606                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
7607                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7608                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
7609         }
7610
7611         /* Create Crypto session*/
7612         ut_params->sess = rte_cryptodev_sym_session_create(
7613                         ts_params->session_mpool);
7614
7615         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7616                                 &ut_params->auth_xform,
7617                                 ts_params->session_mpool);
7618
7619         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7620
7621         return 0;
7622 }
7623
7624 static int
7625 create_auth_operation(struct crypto_testsuite_params *ts_params,
7626                 struct crypto_unittest_params *ut_params,
7627                 const struct test_crypto_vector *reference,
7628                 unsigned int auth_generate)
7629 {
7630         /* Generate Crypto op data structure */
7631         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7632                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7633         TEST_ASSERT_NOT_NULL(ut_params->op,
7634                         "Failed to allocate pktmbuf offload");
7635
7636         /* Set crypto operation data parameters */
7637         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7638
7639         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7640
7641         /* set crypto operation source mbuf */
7642         sym_op->m_src = ut_params->ibuf;
7643
7644         /* digest */
7645         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7646                         ut_params->ibuf, reference->digest.len);
7647
7648         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7649                         "no room to append auth tag");
7650
7651         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7652                         ut_params->ibuf, reference->plaintext.len);
7653
7654         if (auth_generate)
7655                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7656         else
7657                 memcpy(sym_op->auth.digest.data,
7658                                 reference->digest.data,
7659                                 reference->digest.len);
7660
7661         debug_hexdump(stdout, "digest:",
7662                         sym_op->auth.digest.data,
7663                         reference->digest.len);
7664
7665         sym_op->auth.data.length = reference->plaintext.len;
7666         sym_op->auth.data.offset = 0;
7667
7668         return 0;
7669 }
7670
7671 static int
7672 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
7673                 struct crypto_unittest_params *ut_params,
7674                 const struct test_crypto_vector *reference,
7675                 unsigned int auth_generate)
7676 {
7677         /* Generate Crypto op data structure */
7678         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7679                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7680         TEST_ASSERT_NOT_NULL(ut_params->op,
7681                         "Failed to allocate pktmbuf offload");
7682
7683         /* Set crypto operation data parameters */
7684         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7685
7686         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7687
7688         /* set crypto operation source mbuf */
7689         sym_op->m_src = ut_params->ibuf;
7690
7691         /* digest */
7692         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7693                         ut_params->ibuf, reference->digest.len);
7694
7695         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7696                         "no room to append auth tag");
7697
7698         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7699                         ut_params->ibuf, reference->ciphertext.len);
7700
7701         if (auth_generate)
7702                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7703         else
7704                 memcpy(sym_op->auth.digest.data,
7705                                 reference->digest.data,
7706                                 reference->digest.len);
7707
7708         debug_hexdump(stdout, "digest:",
7709                         sym_op->auth.digest.data,
7710                         reference->digest.len);
7711
7712         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7713                         reference->iv.data, reference->iv.len);
7714
7715         sym_op->cipher.data.length = 0;
7716         sym_op->cipher.data.offset = 0;
7717
7718         sym_op->auth.data.length = reference->plaintext.len;
7719         sym_op->auth.data.offset = 0;
7720
7721         return 0;
7722 }
7723
7724 static int
7725 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
7726                 struct crypto_unittest_params *ut_params,
7727                 const struct test_crypto_vector *reference,
7728                 unsigned int auth_generate)
7729 {
7730         /* Generate Crypto op data structure */
7731         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7732                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7733         TEST_ASSERT_NOT_NULL(ut_params->op,
7734                         "Failed to allocate pktmbuf offload");
7735
7736         /* Set crypto operation data parameters */
7737         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7738
7739         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7740
7741         /* set crypto operation source mbuf */
7742         sym_op->m_src = ut_params->ibuf;
7743
7744         /* digest */
7745         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7746                         ut_params->ibuf, reference->digest.len);
7747
7748         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7749                         "no room to append auth tag");
7750
7751         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
7752                         ut_params->ibuf, reference->ciphertext.len);
7753
7754         if (auth_generate)
7755                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7756         else
7757                 memcpy(sym_op->auth.digest.data,
7758                                 reference->digest.data,
7759                                 reference->digest.len);
7760
7761         debug_hexdump(stdout, "digest:",
7762                         sym_op->auth.digest.data,
7763                         reference->digest.len);
7764
7765         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
7766                         reference->iv.data, reference->iv.len);
7767
7768         sym_op->cipher.data.length = reference->ciphertext.len;
7769         sym_op->cipher.data.offset = 0;
7770
7771         sym_op->auth.data.length = reference->ciphertext.len;
7772         sym_op->auth.data.offset = 0;
7773
7774         return 0;
7775 }
7776
7777 static int
7778 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7779                 struct crypto_unittest_params *ut_params,
7780                 const struct test_crypto_vector *reference)
7781 {
7782         return create_auth_operation(ts_params, ut_params, reference, 0);
7783 }
7784
7785 static int
7786 create_auth_verify_GMAC_operation(
7787                 struct crypto_testsuite_params *ts_params,
7788                 struct crypto_unittest_params *ut_params,
7789                 const struct test_crypto_vector *reference)
7790 {
7791         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
7792 }
7793
7794 static int
7795 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7796                 struct crypto_unittest_params *ut_params,
7797                 const struct test_crypto_vector *reference)
7798 {
7799         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
7800 }
7801
7802 static int
7803 test_authentication_verify_fail_when_data_corruption(
7804                 struct crypto_testsuite_params *ts_params,
7805                 struct crypto_unittest_params *ut_params,
7806                 const struct test_crypto_vector *reference,
7807                 unsigned int data_corrupted)
7808 {
7809         int retval;
7810
7811         uint8_t *plaintext;
7812
7813         /* Create session */
7814         retval = create_auth_session(ut_params,
7815                         ts_params->valid_devs[0],
7816                         reference,
7817                         RTE_CRYPTO_AUTH_OP_VERIFY);
7818         if (retval < 0)
7819                 return retval;
7820
7821         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7822         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7823                         "Failed to allocate input buffer in mempool");
7824
7825         /* clear mbuf payload */
7826         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7827                         rte_pktmbuf_tailroom(ut_params->ibuf));
7828
7829         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7830                         reference->plaintext.len);
7831         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7832         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7833
7834         debug_hexdump(stdout, "plaintext:", plaintext,
7835                 reference->plaintext.len);
7836
7837         /* Create operation */
7838         retval = create_auth_verify_operation(ts_params, ut_params, reference);
7839
7840         if (retval < 0)
7841                 return retval;
7842
7843         if (data_corrupted)
7844                 data_corruption(plaintext);
7845         else
7846                 tag_corruption(plaintext, reference->plaintext.len);
7847
7848         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7849                         ut_params->op);
7850         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7851         TEST_ASSERT_EQUAL(ut_params->op->status,
7852                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7853                         "authentication not failed");
7854
7855         ut_params->obuf = ut_params->op->sym->m_src;
7856         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7857
7858         return 0;
7859 }
7860
7861 static int
7862 test_authentication_verify_GMAC_fail_when_corruption(
7863                 struct crypto_testsuite_params *ts_params,
7864                 struct crypto_unittest_params *ut_params,
7865                 const struct test_crypto_vector *reference,
7866                 unsigned int data_corrupted)
7867 {
7868         int retval;
7869         uint8_t *plaintext;
7870
7871         /* Create session */
7872         retval = create_auth_cipher_session(ut_params,
7873                         ts_params->valid_devs[0],
7874                         reference,
7875                         RTE_CRYPTO_AUTH_OP_VERIFY,
7876                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7877         if (retval < 0)
7878                 return retval;
7879
7880         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7881         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7882                         "Failed to allocate input buffer in mempool");
7883
7884         /* clear mbuf payload */
7885         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7886                         rte_pktmbuf_tailroom(ut_params->ibuf));
7887
7888         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7889                         reference->plaintext.len);
7890         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7891         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7892
7893         debug_hexdump(stdout, "plaintext:", plaintext,
7894                 reference->plaintext.len);
7895
7896         /* Create operation */
7897         retval = create_auth_verify_GMAC_operation(ts_params,
7898                         ut_params,
7899                         reference);
7900
7901         if (retval < 0)
7902                 return retval;
7903
7904         if (data_corrupted)
7905                 data_corruption(plaintext);
7906         else
7907                 tag_corruption(plaintext, reference->aad.len);
7908
7909         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7910                         ut_params->op);
7911         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7912         TEST_ASSERT_EQUAL(ut_params->op->status,
7913                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7914                         "authentication not failed");
7915
7916         ut_params->obuf = ut_params->op->sym->m_src;
7917         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7918
7919         return 0;
7920 }
7921
7922 static int
7923 test_authenticated_decryption_fail_when_corruption(
7924                 struct crypto_testsuite_params *ts_params,
7925                 struct crypto_unittest_params *ut_params,
7926                 const struct test_crypto_vector *reference,
7927                 unsigned int data_corrupted)
7928 {
7929         int retval;
7930
7931         uint8_t *ciphertext;
7932
7933         /* Create session */
7934         retval = create_auth_cipher_session(ut_params,
7935                         ts_params->valid_devs[0],
7936                         reference,
7937                         RTE_CRYPTO_AUTH_OP_VERIFY,
7938                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7939         if (retval < 0)
7940                 return retval;
7941
7942         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7943         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7944                         "Failed to allocate input buffer in mempool");
7945
7946         /* clear mbuf payload */
7947         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7948                         rte_pktmbuf_tailroom(ut_params->ibuf));
7949
7950         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7951                         reference->ciphertext.len);
7952         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
7953         memcpy(ciphertext, reference->ciphertext.data,
7954                         reference->ciphertext.len);
7955
7956         /* Create operation */
7957         retval = create_cipher_auth_verify_operation(ts_params,
7958                         ut_params,
7959                         reference);
7960
7961         if (retval < 0)
7962                 return retval;
7963
7964         if (data_corrupted)
7965                 data_corruption(ciphertext);
7966         else
7967                 tag_corruption(ciphertext, reference->ciphertext.len);
7968
7969         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7970                         ut_params->op);
7971
7972         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7973         TEST_ASSERT_EQUAL(ut_params->op->status,
7974                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7975                         "authentication not failed");
7976
7977         ut_params->obuf = ut_params->op->sym->m_src;
7978         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7979
7980         return 0;
7981 }
7982
7983 static int
7984 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
7985                 const struct aead_test_data *tdata,
7986                 void *digest_mem, uint64_t digest_phys)
7987 {
7988         struct crypto_testsuite_params *ts_params = &testsuite_params;
7989         struct crypto_unittest_params *ut_params = &unittest_params;
7990
7991         const unsigned int auth_tag_len = tdata->auth_tag.len;
7992         const unsigned int iv_len = tdata->iv.len;
7993         unsigned int aad_len = tdata->aad.len;
7994
7995         /* Generate Crypto op data structure */
7996         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7997                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7998         TEST_ASSERT_NOT_NULL(ut_params->op,
7999                 "Failed to allocate symmetric crypto operation struct");
8000
8001         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8002
8003         sym_op->aead.digest.data = digest_mem;
8004
8005         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8006                         "no room to append digest");
8007
8008         sym_op->aead.digest.phys_addr = digest_phys;
8009
8010         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
8011                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8012                                 auth_tag_len);
8013                 debug_hexdump(stdout, "digest:",
8014                                 sym_op->aead.digest.data,
8015                                 auth_tag_len);
8016         }
8017
8018         /* Append aad data */
8019         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8020                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8021                                 uint8_t *, IV_OFFSET);
8022
8023                 /* Copy IV 1 byte after the IV pointer, according to the API */
8024                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
8025
8026                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
8027
8028                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
8029                                 ut_params->ibuf, aad_len);
8030                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8031                                 "no room to prepend aad");
8032                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
8033                                 ut_params->ibuf);
8034
8035                 memset(sym_op->aead.aad.data, 0, aad_len);
8036                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
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         } else {
8043                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8044                                 uint8_t *, IV_OFFSET);
8045
8046                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
8047
8048                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
8049                                 ut_params->ibuf, aad_len);
8050                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8051                                 "no room to prepend aad");
8052                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
8053                                 ut_params->ibuf);
8054
8055                 memset(sym_op->aead.aad.data, 0, aad_len);
8056                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
8057
8058                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
8059                 debug_hexdump(stdout, "aad:",
8060                                 sym_op->aead.aad.data, aad_len);
8061         }
8062
8063         sym_op->aead.data.length = tdata->plaintext.len;
8064         sym_op->aead.data.offset = aad_len;
8065
8066         return 0;
8067 }
8068
8069 #define SGL_MAX_NO      16
8070
8071 static int
8072 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
8073                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
8074 {
8075         struct crypto_testsuite_params *ts_params = &testsuite_params;
8076         struct crypto_unittest_params *ut_params = &unittest_params;
8077         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
8078         int retval;
8079         int to_trn = 0;
8080         int to_trn_tbl[SGL_MAX_NO];
8081         int segs = 1;
8082         unsigned int trn_data = 0;
8083         uint8_t *plaintext, *ciphertext, *auth_tag;
8084
8085         if (fragsz > tdata->plaintext.len)
8086                 fragsz = tdata->plaintext.len;
8087
8088         uint16_t plaintext_len = fragsz;
8089         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8090
8091         if (fragsz_oop > tdata->plaintext.len)
8092                 frag_size_oop = tdata->plaintext.len;
8093
8094         int ecx = 0;
8095         void *digest_mem = NULL;
8096
8097         uint32_t prepend_len = tdata->aad.len;
8098
8099         if (tdata->plaintext.len % fragsz != 0) {
8100                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
8101                         return 1;
8102         }       else {
8103                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
8104                         return 1;
8105         }
8106
8107         /*
8108          * For out-op-place we need to alloc another mbuf
8109          */
8110         if (oop) {
8111                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8112                 rte_pktmbuf_append(ut_params->obuf,
8113                                 frag_size_oop + prepend_len);
8114                 buf_oop = ut_params->obuf;
8115         }
8116
8117         /* Create AEAD session */
8118         retval = create_aead_session(ts_params->valid_devs[0],
8119                         tdata->algo,
8120                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8121                         tdata->key.data, tdata->key.len,
8122                         tdata->aad.len, tdata->auth_tag.len,
8123                         tdata->iv.len);
8124         if (retval < 0)
8125                 return retval;
8126
8127         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8128
8129         /* clear mbuf payload */
8130         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8131                         rte_pktmbuf_tailroom(ut_params->ibuf));
8132
8133         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8134                         plaintext_len);
8135
8136         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
8137
8138         trn_data += plaintext_len;
8139
8140         buf = ut_params->ibuf;
8141
8142         /*
8143          * Loop until no more fragments
8144          */
8145
8146         while (trn_data < tdata->plaintext.len) {
8147                 ++segs;
8148                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
8149                                 (tdata->plaintext.len - trn_data) : fragsz;
8150
8151                 to_trn_tbl[ecx++] = to_trn;
8152
8153                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8154                 buf = buf->next;
8155
8156                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8157                                 rte_pktmbuf_tailroom(buf));
8158
8159                 /* OOP */
8160                 if (oop && !fragsz_oop) {
8161                         buf_last_oop = buf_oop->next =
8162                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8163                         buf_oop = buf_oop->next;
8164                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8165                                         0, rte_pktmbuf_tailroom(buf_oop));
8166                         rte_pktmbuf_append(buf_oop, to_trn);
8167                 }
8168
8169                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8170                                 to_trn);
8171
8172                 memcpy(plaintext, tdata->plaintext.data + trn_data,
8173                                 to_trn);
8174                 trn_data += to_trn;
8175                 if (trn_data  == tdata->plaintext.len) {
8176                         if (oop) {
8177                                 if (!fragsz_oop)
8178                                         digest_mem = rte_pktmbuf_append(buf_oop,
8179                                                 tdata->auth_tag.len);
8180                         } else
8181                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
8182                                         tdata->auth_tag.len);
8183                 }
8184         }
8185
8186         uint64_t digest_phys = 0;
8187
8188         ut_params->ibuf->nb_segs = segs;
8189
8190         segs = 1;
8191         if (fragsz_oop && oop) {
8192                 to_trn = 0;
8193                 ecx = 0;
8194
8195                 if (frag_size_oop == tdata->plaintext.len) {
8196                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
8197                                 tdata->auth_tag.len);
8198
8199                         digest_phys = rte_pktmbuf_iova_offset(
8200                                         ut_params->obuf,
8201                                         tdata->plaintext.len + prepend_len);
8202                 }
8203
8204                 trn_data = frag_size_oop;
8205                 while (trn_data < tdata->plaintext.len) {
8206                         ++segs;
8207                         to_trn =
8208                                 (tdata->plaintext.len - trn_data <
8209                                                 frag_size_oop) ?
8210                                 (tdata->plaintext.len - trn_data) :
8211                                                 frag_size_oop;
8212
8213                         to_trn_tbl[ecx++] = to_trn;
8214
8215                         buf_last_oop = buf_oop->next =
8216                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8217                         buf_oop = buf_oop->next;
8218                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8219                                         0, rte_pktmbuf_tailroom(buf_oop));
8220                         rte_pktmbuf_append(buf_oop, to_trn);
8221
8222                         trn_data += to_trn;
8223
8224                         if (trn_data  == tdata->plaintext.len) {
8225                                 digest_mem = rte_pktmbuf_append(buf_oop,
8226                                         tdata->auth_tag.len);
8227                         }
8228                 }
8229
8230                 ut_params->obuf->nb_segs = segs;
8231         }
8232
8233         /*
8234          * Place digest at the end of the last buffer
8235          */
8236         if (!digest_phys)
8237                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
8238         if (oop && buf_last_oop)
8239                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
8240
8241         if (!digest_mem && !oop) {
8242                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8243                                 + tdata->auth_tag.len);
8244                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
8245                                 tdata->plaintext.len);
8246         }
8247
8248         /* Create AEAD operation */
8249         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
8250                         tdata, digest_mem, digest_phys);
8251
8252         if (retval < 0)
8253                 return retval;
8254
8255         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8256
8257         ut_params->op->sym->m_src = ut_params->ibuf;
8258         if (oop)
8259                 ut_params->op->sym->m_dst = ut_params->obuf;
8260
8261         /* Process crypto operation */
8262         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8263                         ut_params->op), "failed to process sym crypto op");
8264
8265         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8266                         "crypto op processing failed");
8267
8268
8269         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8270                         uint8_t *, prepend_len);
8271         if (oop) {
8272                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8273                                 uint8_t *, prepend_len);
8274         }
8275
8276         if (fragsz_oop)
8277                 fragsz = fragsz_oop;
8278
8279         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8280                         ciphertext,
8281                         tdata->ciphertext.data,
8282                         fragsz,
8283                         "Ciphertext data not as expected");
8284
8285         buf = ut_params->op->sym->m_src->next;
8286         if (oop)
8287                 buf = ut_params->op->sym->m_dst->next;
8288
8289         unsigned int off = fragsz;
8290
8291         ecx = 0;
8292         while (buf) {
8293                 ciphertext = rte_pktmbuf_mtod(buf,
8294                                 uint8_t *);
8295
8296                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
8297                                 ciphertext,
8298                                 tdata->ciphertext.data + off,
8299                                 to_trn_tbl[ecx],
8300                                 "Ciphertext data not as expected");
8301
8302                 off += to_trn_tbl[ecx++];
8303                 buf = buf->next;
8304         }
8305
8306         auth_tag = digest_mem;
8307         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8308                         auth_tag,
8309                         tdata->auth_tag.data,
8310                         tdata->auth_tag.len,
8311                         "Generated auth tag not as expected");
8312
8313         return 0;
8314 }
8315
8316 #define IN_PLACE        0
8317 #define OUT_OF_PLACE    1
8318
8319 static int
8320 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
8321 {
8322         return test_authenticated_encryption_SGL(
8323                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
8324 }
8325
8326 static int
8327 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
8328 {
8329         return test_authenticated_encryption_SGL(
8330                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
8331 }
8332
8333 static int
8334 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
8335 {
8336         return test_authenticated_encryption_SGL(
8337                         &gcm_test_case_8, OUT_OF_PLACE, 400,
8338                         gcm_test_case_8.plaintext.len);
8339 }
8340
8341 static int
8342 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
8343 {
8344
8345         return test_authenticated_encryption_SGL(
8346                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
8347 }
8348
8349 static int
8350 test_authentication_verify_fail_when_data_corrupted(
8351                 struct crypto_testsuite_params *ts_params,
8352                 struct crypto_unittest_params *ut_params,
8353                 const struct test_crypto_vector *reference)
8354 {
8355         return test_authentication_verify_fail_when_data_corruption(
8356                         ts_params, ut_params, reference, 1);
8357 }
8358
8359 static int
8360 test_authentication_verify_fail_when_tag_corrupted(
8361                 struct crypto_testsuite_params *ts_params,
8362                 struct crypto_unittest_params *ut_params,
8363                 const struct test_crypto_vector *reference)
8364 {
8365         return test_authentication_verify_fail_when_data_corruption(
8366                         ts_params, ut_params, reference, 0);
8367 }
8368
8369 static int
8370 test_authentication_verify_GMAC_fail_when_data_corrupted(
8371                 struct crypto_testsuite_params *ts_params,
8372                 struct crypto_unittest_params *ut_params,
8373                 const struct test_crypto_vector *reference)
8374 {
8375         return test_authentication_verify_GMAC_fail_when_corruption(
8376                         ts_params, ut_params, reference, 1);
8377 }
8378
8379 static int
8380 test_authentication_verify_GMAC_fail_when_tag_corrupted(
8381                 struct crypto_testsuite_params *ts_params,
8382                 struct crypto_unittest_params *ut_params,
8383                 const struct test_crypto_vector *reference)
8384 {
8385         return test_authentication_verify_GMAC_fail_when_corruption(
8386                         ts_params, ut_params, reference, 0);
8387 }
8388
8389 static int
8390 test_authenticated_decryption_fail_when_data_corrupted(
8391                 struct crypto_testsuite_params *ts_params,
8392                 struct crypto_unittest_params *ut_params,
8393                 const struct test_crypto_vector *reference)
8394 {
8395         return test_authenticated_decryption_fail_when_corruption(
8396                         ts_params, ut_params, reference, 1);
8397 }
8398
8399 static int
8400 test_authenticated_decryption_fail_when_tag_corrupted(
8401                 struct crypto_testsuite_params *ts_params,
8402                 struct crypto_unittest_params *ut_params,
8403                 const struct test_crypto_vector *reference)
8404 {
8405         return test_authenticated_decryption_fail_when_corruption(
8406                         ts_params, ut_params, reference, 0);
8407 }
8408
8409 static int
8410 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
8411 {
8412         return test_authentication_verify_fail_when_data_corrupted(
8413                         &testsuite_params, &unittest_params,
8414                         &hmac_sha1_test_crypto_vector);
8415 }
8416
8417 static int
8418 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
8419 {
8420         return test_authentication_verify_fail_when_tag_corrupted(
8421                         &testsuite_params, &unittest_params,
8422                         &hmac_sha1_test_crypto_vector);
8423 }
8424
8425 static int
8426 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
8427 {
8428         return test_authentication_verify_GMAC_fail_when_data_corrupted(
8429                         &testsuite_params, &unittest_params,
8430                         &aes128_gmac_test_vector);
8431 }
8432
8433 static int
8434 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
8435 {
8436         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
8437                         &testsuite_params, &unittest_params,
8438                         &aes128_gmac_test_vector);
8439 }
8440
8441 static int
8442 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
8443 {
8444         return test_authenticated_decryption_fail_when_data_corrupted(
8445                         &testsuite_params,
8446                         &unittest_params,
8447                         &aes128cbc_hmac_sha1_test_vector);
8448 }
8449
8450 static int
8451 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
8452 {
8453         return test_authenticated_decryption_fail_when_tag_corrupted(
8454                         &testsuite_params,
8455                         &unittest_params,
8456                         &aes128cbc_hmac_sha1_test_vector);
8457 }
8458
8459 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
8460
8461 /* global AESNI slave IDs for the scheduler test */
8462 uint8_t aesni_ids[2];
8463
8464 static int
8465 test_scheduler_attach_slave_op(void)
8466 {
8467         struct crypto_testsuite_params *ts_params = &testsuite_params;
8468         uint8_t sched_id = ts_params->valid_devs[0];
8469         uint32_t nb_devs, i, nb_devs_attached = 0;
8470         int ret;
8471         char vdev_name[32];
8472
8473         /* create 2 AESNI_MB if necessary */
8474         nb_devs = rte_cryptodev_device_count_by_driver(
8475                         rte_cryptodev_driver_id_get(
8476                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
8477         if (nb_devs < 2) {
8478                 for (i = nb_devs; i < 2; i++) {
8479                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
8480                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
8481                                         i);
8482                         ret = rte_vdev_init(vdev_name, NULL);
8483
8484                         TEST_ASSERT(ret == 0,
8485                                 "Failed to create instance %u of"
8486                                 " pmd : %s",
8487                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
8488                 }
8489         }
8490
8491         /* attach 2 AESNI_MB cdevs */
8492         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
8493                         i++) {
8494                 struct rte_cryptodev_info info;
8495
8496                 rte_cryptodev_info_get(i, &info);
8497                 if (info.driver_id != rte_cryptodev_driver_id_get(
8498                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
8499                         continue;
8500
8501                 /*
8502                  * Create the session mempool again, since now there are new devices
8503                  * to use the mempool.
8504                  */
8505                 if (ts_params->session_mpool) {
8506                         rte_mempool_free(ts_params->session_mpool);
8507                         ts_params->session_mpool = NULL;
8508                 }
8509                 unsigned int session_size = rte_cryptodev_get_private_session_size(i);
8510
8511                 /*
8512                  * Create mempool with maximum number of sessions * 2,
8513                  * to include the session headers
8514                  */
8515                 if (ts_params->session_mpool == NULL) {
8516                         ts_params->session_mpool = rte_mempool_create(
8517                                         "test_sess_mp",
8518                                         info.sym.max_nb_sessions * 2,
8519                                         session_size,
8520                                         0, 0, NULL, NULL, NULL,
8521                                         NULL, SOCKET_ID_ANY,
8522                                         0);
8523
8524                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
8525                                         "session mempool allocation failed");
8526                 }
8527
8528                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
8529                                 (uint8_t)i);
8530
8531                 TEST_ASSERT(ret == 0,
8532                         "Failed to attach device %u of pmd : %s", i,
8533                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
8534
8535                 aesni_ids[nb_devs_attached] = (uint8_t)i;
8536
8537                 nb_devs_attached++;
8538         }
8539
8540         return 0;
8541 }
8542
8543 static int
8544 test_scheduler_detach_slave_op(void)
8545 {
8546         struct crypto_testsuite_params *ts_params = &testsuite_params;
8547         uint8_t sched_id = ts_params->valid_devs[0];
8548         uint32_t i;
8549         int ret;
8550
8551         for (i = 0; i < 2; i++) {
8552                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
8553                                 aesni_ids[i]);
8554                 TEST_ASSERT(ret == 0,
8555                         "Failed to detach device %u", aesni_ids[i]);
8556         }
8557
8558         return 0;
8559 }
8560
8561 static int
8562 test_scheduler_mode_op(void)
8563 {
8564         struct crypto_testsuite_params *ts_params = &testsuite_params;
8565         uint8_t sched_id = ts_params->valid_devs[0];
8566         struct rte_cryptodev_scheduler_ops op = {0};
8567         struct rte_cryptodev_scheduler dummy_scheduler = {
8568                 .description = "dummy scheduler to test mode",
8569                 .name = "dummy scheduler",
8570                 .mode = CDEV_SCHED_MODE_USERDEFINED,
8571                 .ops = &op
8572         };
8573         int ret;
8574
8575         /* set user defined mode */
8576         ret = rte_cryptodev_scheduler_load_user_scheduler(sched_id,
8577                         &dummy_scheduler);
8578         TEST_ASSERT(ret == 0,
8579                 "Failed to set cdev %u to user defined mode", sched_id);
8580
8581         /* set round robin mode */
8582         ret = rte_cryptodev_scheduler_mode_set(sched_id,
8583                         CDEV_SCHED_MODE_ROUNDROBIN);
8584         TEST_ASSERT(ret == 0,
8585                 "Failed to set cdev %u to round-robin mode", sched_id);
8586         TEST_ASSERT(rte_cryptodev_scheduler_mode_get(sched_id) ==
8587                         CDEV_SCHED_MODE_ROUNDROBIN, "Scheduling Mode "
8588                                         "not match");
8589
8590         return 0;
8591 }
8592
8593 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
8594         .suite_name = "Crypto Device Scheduler Unit Test Suite",
8595         .setup = testsuite_setup,
8596         .teardown = testsuite_teardown,
8597         .unit_test_cases = {
8598                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
8599                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_op),
8600                 TEST_CASE_ST(ut_setup, ut_teardown,
8601                                 test_AES_chain_scheduler_all),
8602                 TEST_CASE_ST(ut_setup, ut_teardown,
8603                                 test_AES_cipheronly_scheduler_all),
8604                 TEST_CASE_ST(ut_setup, ut_teardown,
8605                                 test_authonly_scheduler_all),
8606                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
8607                 TEST_CASES_END() /**< NULL terminate unit test array */
8608         }
8609 };
8610
8611 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
8612
8613 static struct unit_test_suite cryptodev_qat_testsuite  = {
8614         .suite_name = "Crypto QAT Unit Test Suite",
8615         .setup = testsuite_setup,
8616         .teardown = testsuite_teardown,
8617         .unit_test_cases = {
8618                 TEST_CASE_ST(ut_setup, ut_teardown,
8619                                 test_device_configure_invalid_dev_id),
8620                 TEST_CASE_ST(ut_setup, ut_teardown,
8621                                 test_device_configure_invalid_queue_pair_ids),
8622                 TEST_CASE_ST(ut_setup, ut_teardown,
8623                                 test_queue_pair_descriptor_setup),
8624                 TEST_CASE_ST(ut_setup, ut_teardown,
8625                                 test_multi_session),
8626
8627                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
8628                 TEST_CASE_ST(ut_setup, ut_teardown,
8629                                                 test_AES_cipheronly_qat_all),
8630                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
8631                 TEST_CASE_ST(ut_setup, ut_teardown,
8632                                                 test_3DES_cipheronly_qat_all),
8633                 TEST_CASE_ST(ut_setup, ut_teardown,
8634                                                 test_DES_cipheronly_qat_all),
8635                 TEST_CASE_ST(ut_setup, ut_teardown,
8636                                                 test_AES_docsis_qat_all),
8637                 TEST_CASE_ST(ut_setup, ut_teardown,
8638                                                 test_DES_docsis_qat_all),
8639                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_qat_all),
8640                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
8641
8642                 /** AES CCM Authenticated Encryption 128 bits key */
8643                 TEST_CASE_ST(ut_setup, ut_teardown,
8644                         test_AES_CCM_authenticated_encryption_test_case_128_1),
8645                 TEST_CASE_ST(ut_setup, ut_teardown,
8646                         test_AES_CCM_authenticated_encryption_test_case_128_2),
8647                 TEST_CASE_ST(ut_setup, ut_teardown,
8648                         test_AES_CCM_authenticated_encryption_test_case_128_3),
8649
8650                 /** AES CCM Authenticated Decryption 128 bits key*/
8651                 TEST_CASE_ST(ut_setup, ut_teardown,
8652                         test_AES_CCM_authenticated_decryption_test_case_128_1),
8653                 TEST_CASE_ST(ut_setup, ut_teardown,
8654                         test_AES_CCM_authenticated_decryption_test_case_128_2),
8655                 TEST_CASE_ST(ut_setup, ut_teardown,
8656                         test_AES_CCM_authenticated_decryption_test_case_128_3),
8657
8658                 /** AES GCM Authenticated Encryption */
8659                 TEST_CASE_ST(ut_setup, ut_teardown,
8660                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
8661                 TEST_CASE_ST(ut_setup, ut_teardown,
8662                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
8663                 TEST_CASE_ST(ut_setup, ut_teardown,
8664                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
8665                 TEST_CASE_ST(ut_setup, ut_teardown,
8666                         test_AES_GCM_authenticated_encryption_test_case_1),
8667                 TEST_CASE_ST(ut_setup, ut_teardown,
8668                         test_AES_GCM_authenticated_encryption_test_case_2),
8669                 TEST_CASE_ST(ut_setup, ut_teardown,
8670                         test_AES_GCM_authenticated_encryption_test_case_3),
8671                 TEST_CASE_ST(ut_setup, ut_teardown,
8672                         test_AES_GCM_authenticated_encryption_test_case_4),
8673                 TEST_CASE_ST(ut_setup, ut_teardown,
8674                         test_AES_GCM_authenticated_encryption_test_case_5),
8675                 TEST_CASE_ST(ut_setup, ut_teardown,
8676                         test_AES_GCM_authenticated_encryption_test_case_6),
8677                 TEST_CASE_ST(ut_setup, ut_teardown,
8678                         test_AES_GCM_authenticated_encryption_test_case_7),
8679
8680                 /** AES GCM Authenticated Decryption */
8681                 TEST_CASE_ST(ut_setup, ut_teardown,
8682                         test_AES_GCM_authenticated_decryption_test_case_1),
8683                 TEST_CASE_ST(ut_setup, ut_teardown,
8684                         test_AES_GCM_authenticated_decryption_test_case_2),
8685                 TEST_CASE_ST(ut_setup, ut_teardown,
8686                         test_AES_GCM_authenticated_decryption_test_case_3),
8687                 TEST_CASE_ST(ut_setup, ut_teardown,
8688                         test_AES_GCM_authenticated_decryption_test_case_4),
8689                 TEST_CASE_ST(ut_setup, ut_teardown,
8690                         test_AES_GCM_authenticated_decryption_test_case_5),
8691                 TEST_CASE_ST(ut_setup, ut_teardown,
8692                         test_AES_GCM_authenticated_decryption_test_case_6),
8693                 TEST_CASE_ST(ut_setup, ut_teardown,
8694                         test_AES_GCM_authenticated_decryption_test_case_7),
8695
8696                 /** AES GCM Authenticated Encryption 192 bits key */
8697                 TEST_CASE_ST(ut_setup, ut_teardown,
8698                         test_AES_GCM_auth_encryption_test_case_192_1),
8699                 TEST_CASE_ST(ut_setup, ut_teardown,
8700                         test_AES_GCM_auth_encryption_test_case_192_2),
8701                 TEST_CASE_ST(ut_setup, ut_teardown,
8702                         test_AES_GCM_auth_encryption_test_case_192_3),
8703                 TEST_CASE_ST(ut_setup, ut_teardown,
8704                         test_AES_GCM_auth_encryption_test_case_192_4),
8705                 TEST_CASE_ST(ut_setup, ut_teardown,
8706                         test_AES_GCM_auth_encryption_test_case_192_5),
8707                 TEST_CASE_ST(ut_setup, ut_teardown,
8708                         test_AES_GCM_auth_encryption_test_case_192_6),
8709                 TEST_CASE_ST(ut_setup, ut_teardown,
8710                         test_AES_GCM_auth_encryption_test_case_192_7),
8711
8712                 /** AES GCM Authenticated Decryption 192 bits key */
8713                 TEST_CASE_ST(ut_setup, ut_teardown,
8714                         test_AES_GCM_auth_decryption_test_case_192_1),
8715                 TEST_CASE_ST(ut_setup, ut_teardown,
8716                         test_AES_GCM_auth_decryption_test_case_192_2),
8717                 TEST_CASE_ST(ut_setup, ut_teardown,
8718                         test_AES_GCM_auth_decryption_test_case_192_3),
8719                 TEST_CASE_ST(ut_setup, ut_teardown,
8720                         test_AES_GCM_auth_decryption_test_case_192_4),
8721                 TEST_CASE_ST(ut_setup, ut_teardown,
8722                         test_AES_GCM_auth_decryption_test_case_192_5),
8723                 TEST_CASE_ST(ut_setup, ut_teardown,
8724                         test_AES_GCM_auth_decryption_test_case_192_6),
8725                 TEST_CASE_ST(ut_setup, ut_teardown,
8726                         test_AES_GCM_auth_decryption_test_case_192_7),
8727
8728                 /** AES GCM Authenticated Encryption 256 bits key */
8729                 TEST_CASE_ST(ut_setup, ut_teardown,
8730                         test_AES_GCM_auth_encryption_test_case_256_1),
8731                 TEST_CASE_ST(ut_setup, ut_teardown,
8732                         test_AES_GCM_auth_encryption_test_case_256_2),
8733                 TEST_CASE_ST(ut_setup, ut_teardown,
8734                         test_AES_GCM_auth_encryption_test_case_256_3),
8735                 TEST_CASE_ST(ut_setup, ut_teardown,
8736                         test_AES_GCM_auth_encryption_test_case_256_4),
8737                 TEST_CASE_ST(ut_setup, ut_teardown,
8738                         test_AES_GCM_auth_encryption_test_case_256_5),
8739                 TEST_CASE_ST(ut_setup, ut_teardown,
8740                         test_AES_GCM_auth_encryption_test_case_256_6),
8741                 TEST_CASE_ST(ut_setup, ut_teardown,
8742                         test_AES_GCM_auth_encryption_test_case_256_7),
8743
8744                 /** AES GMAC Authentication */
8745                 TEST_CASE_ST(ut_setup, ut_teardown,
8746                         test_AES_GMAC_authentication_test_case_1),
8747                 TEST_CASE_ST(ut_setup, ut_teardown,
8748                         test_AES_GMAC_authentication_verify_test_case_1),
8749                 TEST_CASE_ST(ut_setup, ut_teardown,
8750                         test_AES_GMAC_authentication_test_case_2),
8751                 TEST_CASE_ST(ut_setup, ut_teardown,
8752                         test_AES_GMAC_authentication_verify_test_case_2),
8753                 TEST_CASE_ST(ut_setup, ut_teardown,
8754                         test_AES_GMAC_authentication_test_case_3),
8755                 TEST_CASE_ST(ut_setup, ut_teardown,
8756                         test_AES_GMAC_authentication_verify_test_case_3),
8757
8758                 /** SNOW 3G encrypt only (UEA2) */
8759                 TEST_CASE_ST(ut_setup, ut_teardown,
8760                         test_snow3g_encryption_test_case_1),
8761                 TEST_CASE_ST(ut_setup, ut_teardown,
8762                         test_snow3g_encryption_test_case_2),
8763                 TEST_CASE_ST(ut_setup, ut_teardown,
8764                         test_snow3g_encryption_test_case_3),
8765                 TEST_CASE_ST(ut_setup, ut_teardown,
8766                         test_snow3g_encryption_test_case_4),
8767                 TEST_CASE_ST(ut_setup, ut_teardown,
8768                         test_snow3g_encryption_test_case_5),
8769
8770                 TEST_CASE_ST(ut_setup, ut_teardown,
8771                         test_snow3g_encryption_test_case_1_oop),
8772                 TEST_CASE_ST(ut_setup, ut_teardown,
8773                         test_snow3g_decryption_test_case_1_oop),
8774
8775                 /** SNOW 3G decrypt only (UEA2) */
8776                 TEST_CASE_ST(ut_setup, ut_teardown,
8777                         test_snow3g_decryption_test_case_1),
8778                 TEST_CASE_ST(ut_setup, ut_teardown,
8779                         test_snow3g_decryption_test_case_2),
8780                 TEST_CASE_ST(ut_setup, ut_teardown,
8781                         test_snow3g_decryption_test_case_3),
8782                 TEST_CASE_ST(ut_setup, ut_teardown,
8783                         test_snow3g_decryption_test_case_4),
8784                 TEST_CASE_ST(ut_setup, ut_teardown,
8785                         test_snow3g_decryption_test_case_5),
8786                 TEST_CASE_ST(ut_setup, ut_teardown,
8787                         test_snow3g_hash_generate_test_case_1),
8788                 TEST_CASE_ST(ut_setup, ut_teardown,
8789                         test_snow3g_hash_generate_test_case_2),
8790                 TEST_CASE_ST(ut_setup, ut_teardown,
8791                         test_snow3g_hash_generate_test_case_3),
8792                 TEST_CASE_ST(ut_setup, ut_teardown,
8793                         test_snow3g_hash_verify_test_case_1),
8794                 TEST_CASE_ST(ut_setup, ut_teardown,
8795                         test_snow3g_hash_verify_test_case_2),
8796                 TEST_CASE_ST(ut_setup, ut_teardown,
8797                         test_snow3g_hash_verify_test_case_3),
8798                 TEST_CASE_ST(ut_setup, ut_teardown,
8799                         test_snow3g_cipher_auth_test_case_1),
8800                 TEST_CASE_ST(ut_setup, ut_teardown,
8801                         test_snow3g_auth_cipher_test_case_1),
8802
8803                 /** ZUC encrypt only (EEA3) */
8804                 TEST_CASE_ST(ut_setup, ut_teardown,
8805                         test_zuc_encryption_test_case_1),
8806                 TEST_CASE_ST(ut_setup, ut_teardown,
8807                         test_zuc_encryption_test_case_2),
8808                 TEST_CASE_ST(ut_setup, ut_teardown,
8809                         test_zuc_encryption_test_case_3),
8810                 TEST_CASE_ST(ut_setup, ut_teardown,
8811                         test_zuc_encryption_test_case_4),
8812                 TEST_CASE_ST(ut_setup, ut_teardown,
8813                         test_zuc_encryption_test_case_5),
8814
8815                 /** ZUC authenticate (EIA3) */
8816                 TEST_CASE_ST(ut_setup, ut_teardown,
8817                         test_zuc_hash_generate_test_case_6),
8818                 TEST_CASE_ST(ut_setup, ut_teardown,
8819                         test_zuc_hash_generate_test_case_7),
8820                 TEST_CASE_ST(ut_setup, ut_teardown,
8821                         test_zuc_hash_generate_test_case_8),
8822
8823                 /** ZUC alg-chain (EEA3/EIA3) */
8824                 TEST_CASE_ST(ut_setup, ut_teardown,
8825                         test_zuc_cipher_auth_test_case_1),
8826                 TEST_CASE_ST(ut_setup, ut_teardown,
8827                         test_zuc_cipher_auth_test_case_2),
8828
8829                 /** HMAC_MD5 Authentication */
8830                 TEST_CASE_ST(ut_setup, ut_teardown,
8831                         test_MD5_HMAC_generate_case_1),
8832                 TEST_CASE_ST(ut_setup, ut_teardown,
8833                         test_MD5_HMAC_verify_case_1),
8834                 TEST_CASE_ST(ut_setup, ut_teardown,
8835                         test_MD5_HMAC_generate_case_2),
8836                 TEST_CASE_ST(ut_setup, ut_teardown,
8837                         test_MD5_HMAC_verify_case_2),
8838
8839                 /** NULL tests */
8840                 TEST_CASE_ST(ut_setup, ut_teardown,
8841                         test_null_auth_only_operation),
8842                 TEST_CASE_ST(ut_setup, ut_teardown,
8843                         test_null_cipher_only_operation),
8844                 TEST_CASE_ST(ut_setup, ut_teardown,
8845                         test_null_cipher_auth_operation),
8846                 TEST_CASE_ST(ut_setup, ut_teardown,
8847                         test_null_auth_cipher_operation),
8848
8849                 /** KASUMI tests */
8850                 TEST_CASE_ST(ut_setup, ut_teardown,
8851                         test_kasumi_hash_generate_test_case_1),
8852                 TEST_CASE_ST(ut_setup, ut_teardown,
8853                         test_kasumi_hash_generate_test_case_2),
8854                 TEST_CASE_ST(ut_setup, ut_teardown,
8855                         test_kasumi_hash_generate_test_case_3),
8856                 TEST_CASE_ST(ut_setup, ut_teardown,
8857                         test_kasumi_hash_generate_test_case_4),
8858                 TEST_CASE_ST(ut_setup, ut_teardown,
8859                         test_kasumi_hash_generate_test_case_5),
8860                 TEST_CASE_ST(ut_setup, ut_teardown,
8861                         test_kasumi_hash_generate_test_case_6),
8862
8863                 TEST_CASE_ST(ut_setup, ut_teardown,
8864                         test_kasumi_hash_verify_test_case_1),
8865                 TEST_CASE_ST(ut_setup, ut_teardown,
8866                         test_kasumi_hash_verify_test_case_2),
8867                 TEST_CASE_ST(ut_setup, ut_teardown,
8868                         test_kasumi_hash_verify_test_case_3),
8869                 TEST_CASE_ST(ut_setup, ut_teardown,
8870                         test_kasumi_hash_verify_test_case_4),
8871                 TEST_CASE_ST(ut_setup, ut_teardown,
8872                         test_kasumi_hash_verify_test_case_5),
8873
8874                 TEST_CASE_ST(ut_setup, ut_teardown,
8875                         test_kasumi_encryption_test_case_1),
8876                 TEST_CASE_ST(ut_setup, ut_teardown,
8877                         test_kasumi_encryption_test_case_3),
8878                 TEST_CASE_ST(ut_setup, ut_teardown,
8879                         test_kasumi_auth_cipher_test_case_1),
8880                 TEST_CASE_ST(ut_setup, ut_teardown,
8881                         test_kasumi_cipher_auth_test_case_1),
8882
8883                 /** Negative tests */
8884                 TEST_CASE_ST(ut_setup, ut_teardown,
8885                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
8886                 TEST_CASE_ST(ut_setup, ut_teardown,
8887                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8888                 TEST_CASE_ST(ut_setup, ut_teardown,
8889                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8890                 TEST_CASE_ST(ut_setup, ut_teardown,
8891                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
8892                 TEST_CASE_ST(ut_setup, ut_teardown,
8893                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8894                 TEST_CASE_ST(ut_setup, ut_teardown,
8895                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8896
8897                 TEST_CASES_END() /**< NULL terminate unit test array */
8898         }
8899 };
8900
8901 static struct unit_test_suite cryptodev_virtio_testsuite = {
8902         .suite_name = "Crypto VIRTIO Unit Test Suite",
8903         .setup = testsuite_setup,
8904         .teardown = testsuite_teardown,
8905         .unit_test_cases = {
8906                 TEST_CASE_ST(ut_setup, ut_teardown,
8907                                 test_AES_cipheronly_virtio_all),
8908
8909                 TEST_CASES_END() /**< NULL terminate unit test array */
8910         }
8911 };
8912
8913 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
8914         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
8915         .setup = testsuite_setup,
8916         .teardown = testsuite_teardown,
8917         .unit_test_cases = {
8918                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
8919                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
8920                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
8921                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
8922                 TEST_CASE_ST(ut_setup, ut_teardown,
8923                                                 test_DES_cipheronly_mb_all),
8924                 TEST_CASE_ST(ut_setup, ut_teardown,
8925                                                 test_DES_docsis_mb_all),
8926                 TEST_CASE_ST(ut_setup, ut_teardown,
8927                         test_AES_CCM_authenticated_encryption_test_case_128_1),
8928                 TEST_CASE_ST(ut_setup, ut_teardown,
8929                         test_AES_CCM_authenticated_decryption_test_case_128_1),
8930                 TEST_CASE_ST(ut_setup, ut_teardown,
8931                         test_AES_CCM_authenticated_encryption_test_case_128_2),
8932                 TEST_CASE_ST(ut_setup, ut_teardown,
8933                         test_AES_CCM_authenticated_decryption_test_case_128_2),
8934                 TEST_CASE_ST(ut_setup, ut_teardown,
8935                         test_AES_CCM_authenticated_encryption_test_case_128_3),
8936                 TEST_CASE_ST(ut_setup, ut_teardown,
8937                         test_AES_CCM_authenticated_decryption_test_case_128_3),
8938
8939                 TEST_CASES_END() /**< NULL terminate unit test array */
8940         }
8941 };
8942
8943 static struct unit_test_suite cryptodev_openssl_testsuite  = {
8944         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
8945         .setup = testsuite_setup,
8946         .teardown = testsuite_teardown,
8947         .unit_test_cases = {
8948                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
8949                 TEST_CASE_ST(ut_setup, ut_teardown,
8950                                 test_multi_session_random_usage),
8951                 TEST_CASE_ST(ut_setup, ut_teardown,
8952                                 test_AES_chain_openssl_all),
8953                 TEST_CASE_ST(ut_setup, ut_teardown,
8954                                 test_AES_cipheronly_openssl_all),
8955                 TEST_CASE_ST(ut_setup, ut_teardown,
8956                                 test_3DES_chain_openssl_all),
8957                 TEST_CASE_ST(ut_setup, ut_teardown,
8958                                 test_3DES_cipheronly_openssl_all),
8959                 TEST_CASE_ST(ut_setup, ut_teardown,
8960                                 test_DES_cipheronly_openssl_all),
8961                 TEST_CASE_ST(ut_setup, ut_teardown,
8962                                 test_DES_docsis_openssl_all),
8963                 TEST_CASE_ST(ut_setup, ut_teardown,
8964                                 test_authonly_openssl_all),
8965
8966                 /** AES GCM Authenticated Encryption */
8967                 TEST_CASE_ST(ut_setup, ut_teardown,
8968                         test_AES_GCM_authenticated_encryption_test_case_1),
8969                 TEST_CASE_ST(ut_setup, ut_teardown,
8970                         test_AES_GCM_authenticated_encryption_test_case_2),
8971                 TEST_CASE_ST(ut_setup, ut_teardown,
8972                         test_AES_GCM_authenticated_encryption_test_case_3),
8973                 TEST_CASE_ST(ut_setup, ut_teardown,
8974                         test_AES_GCM_authenticated_encryption_test_case_4),
8975                 TEST_CASE_ST(ut_setup, ut_teardown,
8976                         test_AES_GCM_authenticated_encryption_test_case_5),
8977                 TEST_CASE_ST(ut_setup, ut_teardown,
8978                         test_AES_GCM_authenticated_encryption_test_case_6),
8979                 TEST_CASE_ST(ut_setup, ut_teardown,
8980                         test_AES_GCM_authenticated_encryption_test_case_7),
8981
8982                 /** AES GCM Authenticated Decryption */
8983                 TEST_CASE_ST(ut_setup, ut_teardown,
8984                         test_AES_GCM_authenticated_decryption_test_case_1),
8985                 TEST_CASE_ST(ut_setup, ut_teardown,
8986                         test_AES_GCM_authenticated_decryption_test_case_2),
8987                 TEST_CASE_ST(ut_setup, ut_teardown,
8988                         test_AES_GCM_authenticated_decryption_test_case_3),
8989                 TEST_CASE_ST(ut_setup, ut_teardown,
8990                         test_AES_GCM_authenticated_decryption_test_case_4),
8991                 TEST_CASE_ST(ut_setup, ut_teardown,
8992                         test_AES_GCM_authenticated_decryption_test_case_5),
8993                 TEST_CASE_ST(ut_setup, ut_teardown,
8994                         test_AES_GCM_authenticated_decryption_test_case_6),
8995                 TEST_CASE_ST(ut_setup, ut_teardown,
8996                         test_AES_GCM_authenticated_decryption_test_case_7),
8997
8998
8999                 /** AES GCM Authenticated Encryption 192 bits key */
9000                 TEST_CASE_ST(ut_setup, ut_teardown,
9001                         test_AES_GCM_auth_encryption_test_case_192_1),
9002                 TEST_CASE_ST(ut_setup, ut_teardown,
9003                         test_AES_GCM_auth_encryption_test_case_192_2),
9004                 TEST_CASE_ST(ut_setup, ut_teardown,
9005                         test_AES_GCM_auth_encryption_test_case_192_3),
9006                 TEST_CASE_ST(ut_setup, ut_teardown,
9007                         test_AES_GCM_auth_encryption_test_case_192_4),
9008                 TEST_CASE_ST(ut_setup, ut_teardown,
9009                         test_AES_GCM_auth_encryption_test_case_192_5),
9010                 TEST_CASE_ST(ut_setup, ut_teardown,
9011                         test_AES_GCM_auth_encryption_test_case_192_6),
9012                 TEST_CASE_ST(ut_setup, ut_teardown,
9013                         test_AES_GCM_auth_encryption_test_case_192_7),
9014
9015                 /** AES GCM Authenticated Decryption 192 bits key */
9016                 TEST_CASE_ST(ut_setup, ut_teardown,
9017                         test_AES_GCM_auth_decryption_test_case_192_1),
9018                 TEST_CASE_ST(ut_setup, ut_teardown,
9019                         test_AES_GCM_auth_decryption_test_case_192_2),
9020                 TEST_CASE_ST(ut_setup, ut_teardown,
9021                         test_AES_GCM_auth_decryption_test_case_192_3),
9022                 TEST_CASE_ST(ut_setup, ut_teardown,
9023                         test_AES_GCM_auth_decryption_test_case_192_4),
9024                 TEST_CASE_ST(ut_setup, ut_teardown,
9025                         test_AES_GCM_auth_decryption_test_case_192_5),
9026                 TEST_CASE_ST(ut_setup, ut_teardown,
9027                         test_AES_GCM_auth_decryption_test_case_192_6),
9028                 TEST_CASE_ST(ut_setup, ut_teardown,
9029                         test_AES_GCM_auth_decryption_test_case_192_7),
9030
9031                 /** AES GCM Authenticated Encryption 256 bits key */
9032                 TEST_CASE_ST(ut_setup, ut_teardown,
9033                         test_AES_GCM_auth_encryption_test_case_256_1),
9034                 TEST_CASE_ST(ut_setup, ut_teardown,
9035                         test_AES_GCM_auth_encryption_test_case_256_2),
9036                 TEST_CASE_ST(ut_setup, ut_teardown,
9037                         test_AES_GCM_auth_encryption_test_case_256_3),
9038                 TEST_CASE_ST(ut_setup, ut_teardown,
9039                         test_AES_GCM_auth_encryption_test_case_256_4),
9040                 TEST_CASE_ST(ut_setup, ut_teardown,
9041                         test_AES_GCM_auth_encryption_test_case_256_5),
9042                 TEST_CASE_ST(ut_setup, ut_teardown,
9043                         test_AES_GCM_auth_encryption_test_case_256_6),
9044                 TEST_CASE_ST(ut_setup, ut_teardown,
9045                         test_AES_GCM_auth_encryption_test_case_256_7),
9046
9047                 /** AES GCM Authenticated Decryption 256 bits key */
9048                 TEST_CASE_ST(ut_setup, ut_teardown,
9049                         test_AES_GCM_auth_decryption_test_case_256_1),
9050                 TEST_CASE_ST(ut_setup, ut_teardown,
9051                         test_AES_GCM_auth_decryption_test_case_256_2),
9052                 TEST_CASE_ST(ut_setup, ut_teardown,
9053                         test_AES_GCM_auth_decryption_test_case_256_3),
9054                 TEST_CASE_ST(ut_setup, ut_teardown,
9055                         test_AES_GCM_auth_decryption_test_case_256_4),
9056                 TEST_CASE_ST(ut_setup, ut_teardown,
9057                         test_AES_GCM_auth_decryption_test_case_256_5),
9058                 TEST_CASE_ST(ut_setup, ut_teardown,
9059                         test_AES_GCM_auth_decryption_test_case_256_6),
9060                 TEST_CASE_ST(ut_setup, ut_teardown,
9061                         test_AES_GCM_auth_decryption_test_case_256_7),
9062
9063                 /** AES GMAC Authentication */
9064                 TEST_CASE_ST(ut_setup, ut_teardown,
9065                         test_AES_GMAC_authentication_test_case_1),
9066                 TEST_CASE_ST(ut_setup, ut_teardown,
9067                         test_AES_GMAC_authentication_verify_test_case_1),
9068                 TEST_CASE_ST(ut_setup, ut_teardown,
9069                         test_AES_GMAC_authentication_test_case_2),
9070                 TEST_CASE_ST(ut_setup, ut_teardown,
9071                         test_AES_GMAC_authentication_verify_test_case_2),
9072                 TEST_CASE_ST(ut_setup, ut_teardown,
9073                         test_AES_GMAC_authentication_test_case_3),
9074                 TEST_CASE_ST(ut_setup, ut_teardown,
9075                         test_AES_GMAC_authentication_verify_test_case_3),
9076                 TEST_CASE_ST(ut_setup, ut_teardown,
9077                         test_AES_GMAC_authentication_test_case_4),
9078                 TEST_CASE_ST(ut_setup, ut_teardown,
9079                         test_AES_GMAC_authentication_verify_test_case_4),
9080
9081                 /** AES CCM Authenticated Encryption 128 bits key */
9082                 TEST_CASE_ST(ut_setup, ut_teardown,
9083                         test_AES_CCM_authenticated_encryption_test_case_128_1),
9084                 TEST_CASE_ST(ut_setup, ut_teardown,
9085                         test_AES_CCM_authenticated_encryption_test_case_128_2),
9086                 TEST_CASE_ST(ut_setup, ut_teardown,
9087                         test_AES_CCM_authenticated_encryption_test_case_128_3),
9088
9089                 /** AES CCM Authenticated Decryption 128 bits key*/
9090                 TEST_CASE_ST(ut_setup, ut_teardown,
9091                         test_AES_CCM_authenticated_decryption_test_case_128_1),
9092                 TEST_CASE_ST(ut_setup, ut_teardown,
9093                         test_AES_CCM_authenticated_decryption_test_case_128_2),
9094                 TEST_CASE_ST(ut_setup, ut_teardown,
9095                         test_AES_CCM_authenticated_decryption_test_case_128_3),
9096
9097                 /** AES CCM Authenticated Encryption 192 bits key */
9098                 TEST_CASE_ST(ut_setup, ut_teardown,
9099                         test_AES_CCM_authenticated_encryption_test_case_192_1),
9100                 TEST_CASE_ST(ut_setup, ut_teardown,
9101                         test_AES_CCM_authenticated_encryption_test_case_192_2),
9102                 TEST_CASE_ST(ut_setup, ut_teardown,
9103                         test_AES_CCM_authenticated_encryption_test_case_192_3),
9104
9105                 /** AES CCM Authenticated Decryption 192 bits key*/
9106                 TEST_CASE_ST(ut_setup, ut_teardown,
9107                         test_AES_CCM_authenticated_decryption_test_case_192_1),
9108                 TEST_CASE_ST(ut_setup, ut_teardown,
9109                         test_AES_CCM_authenticated_decryption_test_case_192_2),
9110                 TEST_CASE_ST(ut_setup, ut_teardown,
9111                         test_AES_CCM_authenticated_decryption_test_case_192_3),
9112
9113                 /** AES CCM Authenticated Encryption 256 bits key */
9114                 TEST_CASE_ST(ut_setup, ut_teardown,
9115                         test_AES_CCM_authenticated_encryption_test_case_256_1),
9116                 TEST_CASE_ST(ut_setup, ut_teardown,
9117                         test_AES_CCM_authenticated_encryption_test_case_256_2),
9118                 TEST_CASE_ST(ut_setup, ut_teardown,
9119                         test_AES_CCM_authenticated_encryption_test_case_256_3),
9120
9121                 /** AES CCM Authenticated Decryption 256 bits key*/
9122                 TEST_CASE_ST(ut_setup, ut_teardown,
9123                         test_AES_CCM_authenticated_decryption_test_case_256_1),
9124                 TEST_CASE_ST(ut_setup, ut_teardown,
9125                         test_AES_CCM_authenticated_decryption_test_case_256_2),
9126                 TEST_CASE_ST(ut_setup, ut_teardown,
9127                         test_AES_CCM_authenticated_decryption_test_case_256_3),
9128
9129                 /** Scatter-Gather */
9130                 TEST_CASE_ST(ut_setup, ut_teardown,
9131                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9132
9133                 /** Negative tests */
9134                 TEST_CASE_ST(ut_setup, ut_teardown,
9135                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9136                 TEST_CASE_ST(ut_setup, ut_teardown,
9137                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9138                 TEST_CASE_ST(ut_setup, ut_teardown,
9139                         authentication_verify_AES128_GMAC_fail_data_corrupt),
9140                 TEST_CASE_ST(ut_setup, ut_teardown,
9141                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
9142                 TEST_CASE_ST(ut_setup, ut_teardown,
9143                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9144                 TEST_CASE_ST(ut_setup, ut_teardown,
9145                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9146
9147                 TEST_CASES_END() /**< NULL terminate unit test array */
9148         }
9149 };
9150
9151 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
9152         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
9153         .setup = testsuite_setup,
9154         .teardown = testsuite_teardown,
9155         .unit_test_cases = {
9156                 /** AES GCM Authenticated Encryption */
9157                 TEST_CASE_ST(ut_setup, ut_teardown,
9158                         test_AES_GCM_authenticated_encryption_test_case_1),
9159                 TEST_CASE_ST(ut_setup, ut_teardown,
9160                         test_AES_GCM_authenticated_encryption_test_case_2),
9161                 TEST_CASE_ST(ut_setup, ut_teardown,
9162                         test_AES_GCM_authenticated_encryption_test_case_3),
9163                 TEST_CASE_ST(ut_setup, ut_teardown,
9164                         test_AES_GCM_authenticated_encryption_test_case_4),
9165                 TEST_CASE_ST(ut_setup, ut_teardown,
9166                         test_AES_GCM_authenticated_encryption_test_case_5),
9167                 TEST_CASE_ST(ut_setup, ut_teardown,
9168                         test_AES_GCM_authenticated_encryption_test_case_6),
9169                 TEST_CASE_ST(ut_setup, ut_teardown,
9170                         test_AES_GCM_authenticated_encryption_test_case_7),
9171
9172                 /** AES GCM Authenticated Decryption */
9173                 TEST_CASE_ST(ut_setup, ut_teardown,
9174                         test_AES_GCM_authenticated_decryption_test_case_1),
9175                 TEST_CASE_ST(ut_setup, ut_teardown,
9176                         test_AES_GCM_authenticated_decryption_test_case_2),
9177                 TEST_CASE_ST(ut_setup, ut_teardown,
9178                         test_AES_GCM_authenticated_decryption_test_case_3),
9179                 TEST_CASE_ST(ut_setup, ut_teardown,
9180                         test_AES_GCM_authenticated_decryption_test_case_4),
9181                 TEST_CASE_ST(ut_setup, ut_teardown,
9182                         test_AES_GCM_authenticated_decryption_test_case_5),
9183                 TEST_CASE_ST(ut_setup, ut_teardown,
9184                         test_AES_GCM_authenticated_decryption_test_case_6),
9185                 TEST_CASE_ST(ut_setup, ut_teardown,
9186                         test_AES_GCM_authenticated_decryption_test_case_7),
9187
9188                 /** AES GCM Authenticated Encryption 192 bits key */
9189                 TEST_CASE_ST(ut_setup, ut_teardown,
9190                         test_AES_GCM_auth_encryption_test_case_192_1),
9191                 TEST_CASE_ST(ut_setup, ut_teardown,
9192                         test_AES_GCM_auth_encryption_test_case_192_2),
9193                 TEST_CASE_ST(ut_setup, ut_teardown,
9194                         test_AES_GCM_auth_encryption_test_case_192_3),
9195                 TEST_CASE_ST(ut_setup, ut_teardown,
9196                         test_AES_GCM_auth_encryption_test_case_192_4),
9197                 TEST_CASE_ST(ut_setup, ut_teardown,
9198                         test_AES_GCM_auth_encryption_test_case_192_5),
9199                 TEST_CASE_ST(ut_setup, ut_teardown,
9200                         test_AES_GCM_auth_encryption_test_case_192_6),
9201                 TEST_CASE_ST(ut_setup, ut_teardown,
9202                         test_AES_GCM_auth_encryption_test_case_192_7),
9203
9204                 /** AES GCM Authenticated Decryption 192 bits key */
9205                 TEST_CASE_ST(ut_setup, ut_teardown,
9206                         test_AES_GCM_auth_decryption_test_case_192_1),
9207                 TEST_CASE_ST(ut_setup, ut_teardown,
9208                         test_AES_GCM_auth_decryption_test_case_192_2),
9209                 TEST_CASE_ST(ut_setup, ut_teardown,
9210                         test_AES_GCM_auth_decryption_test_case_192_3),
9211                 TEST_CASE_ST(ut_setup, ut_teardown,
9212                         test_AES_GCM_auth_decryption_test_case_192_4),
9213                 TEST_CASE_ST(ut_setup, ut_teardown,
9214                         test_AES_GCM_auth_decryption_test_case_192_5),
9215                 TEST_CASE_ST(ut_setup, ut_teardown,
9216                         test_AES_GCM_auth_decryption_test_case_192_6),
9217                 TEST_CASE_ST(ut_setup, ut_teardown,
9218                         test_AES_GCM_auth_decryption_test_case_192_7),
9219
9220                 /** AES GCM Authenticated Encryption 256 bits key */
9221                 TEST_CASE_ST(ut_setup, ut_teardown,
9222                         test_AES_GCM_auth_encryption_test_case_256_1),
9223                 TEST_CASE_ST(ut_setup, ut_teardown,
9224                         test_AES_GCM_auth_encryption_test_case_256_2),
9225                 TEST_CASE_ST(ut_setup, ut_teardown,
9226                         test_AES_GCM_auth_encryption_test_case_256_3),
9227                 TEST_CASE_ST(ut_setup, ut_teardown,
9228                         test_AES_GCM_auth_encryption_test_case_256_4),
9229                 TEST_CASE_ST(ut_setup, ut_teardown,
9230                         test_AES_GCM_auth_encryption_test_case_256_5),
9231                 TEST_CASE_ST(ut_setup, ut_teardown,
9232                         test_AES_GCM_auth_encryption_test_case_256_6),
9233                 TEST_CASE_ST(ut_setup, ut_teardown,
9234                         test_AES_GCM_auth_encryption_test_case_256_7),
9235
9236                 /** AES GCM Authenticated Decryption 256 bits key */
9237                 TEST_CASE_ST(ut_setup, ut_teardown,
9238                         test_AES_GCM_auth_decryption_test_case_256_1),
9239                 TEST_CASE_ST(ut_setup, ut_teardown,
9240                         test_AES_GCM_auth_decryption_test_case_256_2),
9241                 TEST_CASE_ST(ut_setup, ut_teardown,
9242                         test_AES_GCM_auth_decryption_test_case_256_3),
9243                 TEST_CASE_ST(ut_setup, ut_teardown,
9244                         test_AES_GCM_auth_decryption_test_case_256_4),
9245                 TEST_CASE_ST(ut_setup, ut_teardown,
9246                         test_AES_GCM_auth_decryption_test_case_256_5),
9247                 TEST_CASE_ST(ut_setup, ut_teardown,
9248                         test_AES_GCM_auth_decryption_test_case_256_6),
9249                 TEST_CASE_ST(ut_setup, ut_teardown,
9250                         test_AES_GCM_auth_decryption_test_case_256_7),
9251
9252                 /** AES GCM Authenticated Encryption big aad size */
9253                 TEST_CASE_ST(ut_setup, ut_teardown,
9254                         test_AES_GCM_auth_encryption_test_case_aad_1),
9255                 TEST_CASE_ST(ut_setup, ut_teardown,
9256                         test_AES_GCM_auth_encryption_test_case_aad_2),
9257
9258                 /** AES GCM Authenticated Decryption big aad size */
9259                 TEST_CASE_ST(ut_setup, ut_teardown,
9260                         test_AES_GCM_auth_decryption_test_case_aad_1),
9261                 TEST_CASE_ST(ut_setup, ut_teardown,
9262                         test_AES_GCM_auth_decryption_test_case_aad_2),
9263
9264                 /** AES GMAC Authentication */
9265                 TEST_CASE_ST(ut_setup, ut_teardown,
9266                         test_AES_GMAC_authentication_test_case_1),
9267                 TEST_CASE_ST(ut_setup, ut_teardown,
9268                         test_AES_GMAC_authentication_verify_test_case_1),
9269                 TEST_CASE_ST(ut_setup, ut_teardown,
9270                         test_AES_GMAC_authentication_test_case_3),
9271                 TEST_CASE_ST(ut_setup, ut_teardown,
9272                         test_AES_GMAC_authentication_verify_test_case_3),
9273                 TEST_CASE_ST(ut_setup, ut_teardown,
9274                         test_AES_GMAC_authentication_test_case_4),
9275                 TEST_CASE_ST(ut_setup, ut_teardown,
9276                         test_AES_GMAC_authentication_verify_test_case_4),
9277
9278                 /** Negative tests */
9279                 TEST_CASE_ST(ut_setup, ut_teardown,
9280                         authentication_verify_AES128_GMAC_fail_data_corrupt),
9281                 TEST_CASE_ST(ut_setup, ut_teardown,
9282                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
9283
9284                 /** Out of place tests */
9285                 TEST_CASE_ST(ut_setup, ut_teardown,
9286                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9287                 TEST_CASE_ST(ut_setup, ut_teardown,
9288                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9289
9290                 /** Session-less tests */
9291                 TEST_CASE_ST(ut_setup, ut_teardown,
9292                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
9293                 TEST_CASE_ST(ut_setup, ut_teardown,
9294                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
9295
9296                 /** Scatter-Gather */
9297                 TEST_CASE_ST(ut_setup, ut_teardown,
9298                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9299
9300                 TEST_CASES_END() /**< NULL terminate unit test array */
9301         }
9302 };
9303
9304 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
9305         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
9306         .setup = testsuite_setup,
9307         .teardown = testsuite_teardown,
9308         .unit_test_cases = {
9309                 /** KASUMI encrypt only (UEA1) */
9310                 TEST_CASE_ST(ut_setup, ut_teardown,
9311                         test_kasumi_encryption_test_case_1),
9312                 TEST_CASE_ST(ut_setup, ut_teardown,
9313                         test_kasumi_encryption_test_case_1_sgl),
9314                 TEST_CASE_ST(ut_setup, ut_teardown,
9315                         test_kasumi_encryption_test_case_2),
9316                 TEST_CASE_ST(ut_setup, ut_teardown,
9317                         test_kasumi_encryption_test_case_3),
9318                 TEST_CASE_ST(ut_setup, ut_teardown,
9319                         test_kasumi_encryption_test_case_4),
9320                 TEST_CASE_ST(ut_setup, ut_teardown,
9321                         test_kasumi_encryption_test_case_5),
9322                 /** KASUMI decrypt only (UEA1) */
9323                 TEST_CASE_ST(ut_setup, ut_teardown,
9324                         test_kasumi_decryption_test_case_1),
9325                 TEST_CASE_ST(ut_setup, ut_teardown,
9326                         test_kasumi_decryption_test_case_2),
9327                 TEST_CASE_ST(ut_setup, ut_teardown,
9328                         test_kasumi_decryption_test_case_3),
9329                 TEST_CASE_ST(ut_setup, ut_teardown,
9330                         test_kasumi_decryption_test_case_4),
9331                 TEST_CASE_ST(ut_setup, ut_teardown,
9332                         test_kasumi_decryption_test_case_5),
9333
9334                 TEST_CASE_ST(ut_setup, ut_teardown,
9335                         test_kasumi_encryption_test_case_1_oop),
9336                 TEST_CASE_ST(ut_setup, ut_teardown,
9337                         test_kasumi_encryption_test_case_1_oop_sgl),
9338
9339
9340                 TEST_CASE_ST(ut_setup, ut_teardown,
9341                         test_kasumi_decryption_test_case_1_oop),
9342
9343                 /** KASUMI hash only (UIA1) */
9344                 TEST_CASE_ST(ut_setup, ut_teardown,
9345                         test_kasumi_hash_generate_test_case_1),
9346                 TEST_CASE_ST(ut_setup, ut_teardown,
9347                         test_kasumi_hash_generate_test_case_2),
9348                 TEST_CASE_ST(ut_setup, ut_teardown,
9349                         test_kasumi_hash_generate_test_case_3),
9350                 TEST_CASE_ST(ut_setup, ut_teardown,
9351                         test_kasumi_hash_generate_test_case_4),
9352                 TEST_CASE_ST(ut_setup, ut_teardown,
9353                         test_kasumi_hash_generate_test_case_5),
9354                 TEST_CASE_ST(ut_setup, ut_teardown,
9355                         test_kasumi_hash_generate_test_case_6),
9356                 TEST_CASE_ST(ut_setup, ut_teardown,
9357                         test_kasumi_hash_verify_test_case_1),
9358                 TEST_CASE_ST(ut_setup, ut_teardown,
9359                         test_kasumi_hash_verify_test_case_2),
9360                 TEST_CASE_ST(ut_setup, ut_teardown,
9361                         test_kasumi_hash_verify_test_case_3),
9362                 TEST_CASE_ST(ut_setup, ut_teardown,
9363                         test_kasumi_hash_verify_test_case_4),
9364                 TEST_CASE_ST(ut_setup, ut_teardown,
9365                         test_kasumi_hash_verify_test_case_5),
9366                 TEST_CASE_ST(ut_setup, ut_teardown,
9367                         test_kasumi_auth_cipher_test_case_1),
9368                 TEST_CASE_ST(ut_setup, ut_teardown,
9369                         test_kasumi_cipher_auth_test_case_1),
9370                 TEST_CASES_END() /**< NULL terminate unit test array */
9371         }
9372 };
9373 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
9374         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
9375         .setup = testsuite_setup,
9376         .teardown = testsuite_teardown,
9377         .unit_test_cases = {
9378                 /** SNOW 3G encrypt only (UEA2) */
9379                 TEST_CASE_ST(ut_setup, ut_teardown,
9380                         test_snow3g_encryption_test_case_1),
9381                 TEST_CASE_ST(ut_setup, ut_teardown,
9382                         test_snow3g_encryption_test_case_2),
9383                 TEST_CASE_ST(ut_setup, ut_teardown,
9384                         test_snow3g_encryption_test_case_3),
9385                 TEST_CASE_ST(ut_setup, ut_teardown,
9386                         test_snow3g_encryption_test_case_4),
9387                 TEST_CASE_ST(ut_setup, ut_teardown,
9388                         test_snow3g_encryption_test_case_5),
9389
9390                 TEST_CASE_ST(ut_setup, ut_teardown,
9391                         test_snow3g_encryption_test_case_1_oop),
9392                 TEST_CASE_ST(ut_setup, ut_teardown,
9393                                 test_snow3g_encryption_test_case_1_oop_sgl),
9394                 TEST_CASE_ST(ut_setup, ut_teardown,
9395                         test_snow3g_decryption_test_case_1_oop),
9396
9397                 TEST_CASE_ST(ut_setup, ut_teardown,
9398                         test_snow3g_encryption_test_case_1_offset_oop),
9399
9400                 /** SNOW 3G decrypt only (UEA2) */
9401                 TEST_CASE_ST(ut_setup, ut_teardown,
9402                         test_snow3g_decryption_test_case_1),
9403                 TEST_CASE_ST(ut_setup, ut_teardown,
9404                         test_snow3g_decryption_test_case_2),
9405                 TEST_CASE_ST(ut_setup, ut_teardown,
9406                         test_snow3g_decryption_test_case_3),
9407                 TEST_CASE_ST(ut_setup, ut_teardown,
9408                         test_snow3g_decryption_test_case_4),
9409                 TEST_CASE_ST(ut_setup, ut_teardown,
9410                         test_snow3g_decryption_test_case_5),
9411                 TEST_CASE_ST(ut_setup, ut_teardown,
9412                         test_snow3g_hash_generate_test_case_1),
9413                 TEST_CASE_ST(ut_setup, ut_teardown,
9414                         test_snow3g_hash_generate_test_case_2),
9415                 TEST_CASE_ST(ut_setup, ut_teardown,
9416                         test_snow3g_hash_generate_test_case_3),
9417                 /* Tests with buffers which length is not byte-aligned */
9418                 TEST_CASE_ST(ut_setup, ut_teardown,
9419                         test_snow3g_hash_generate_test_case_4),
9420                 TEST_CASE_ST(ut_setup, ut_teardown,
9421                         test_snow3g_hash_generate_test_case_5),
9422                 TEST_CASE_ST(ut_setup, ut_teardown,
9423                         test_snow3g_hash_generate_test_case_6),
9424                 TEST_CASE_ST(ut_setup, ut_teardown,
9425                         test_snow3g_hash_verify_test_case_1),
9426                 TEST_CASE_ST(ut_setup, ut_teardown,
9427                         test_snow3g_hash_verify_test_case_2),
9428                 TEST_CASE_ST(ut_setup, ut_teardown,
9429                         test_snow3g_hash_verify_test_case_3),
9430                 /* Tests with buffers which length is not byte-aligned */
9431                 TEST_CASE_ST(ut_setup, ut_teardown,
9432                         test_snow3g_hash_verify_test_case_4),
9433                 TEST_CASE_ST(ut_setup, ut_teardown,
9434                         test_snow3g_hash_verify_test_case_5),
9435                 TEST_CASE_ST(ut_setup, ut_teardown,
9436                         test_snow3g_hash_verify_test_case_6),
9437                 TEST_CASE_ST(ut_setup, ut_teardown,
9438                         test_snow3g_cipher_auth_test_case_1),
9439                 TEST_CASE_ST(ut_setup, ut_teardown,
9440                         test_snow3g_auth_cipher_test_case_1),
9441
9442                 TEST_CASES_END() /**< NULL terminate unit test array */
9443         }
9444 };
9445
9446 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
9447         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
9448         .setup = testsuite_setup,
9449         .teardown = testsuite_teardown,
9450         .unit_test_cases = {
9451                 /** ZUC encrypt only (EEA3) */
9452                 TEST_CASE_ST(ut_setup, ut_teardown,
9453                         test_zuc_encryption_test_case_1),
9454                 TEST_CASE_ST(ut_setup, ut_teardown,
9455                         test_zuc_encryption_test_case_2),
9456                 TEST_CASE_ST(ut_setup, ut_teardown,
9457                         test_zuc_encryption_test_case_3),
9458                 TEST_CASE_ST(ut_setup, ut_teardown,
9459                         test_zuc_encryption_test_case_4),
9460                 TEST_CASE_ST(ut_setup, ut_teardown,
9461                         test_zuc_encryption_test_case_5),
9462                 TEST_CASE_ST(ut_setup, ut_teardown,
9463                         test_zuc_hash_generate_test_case_1),
9464                 TEST_CASE_ST(ut_setup, ut_teardown,
9465                         test_zuc_hash_generate_test_case_2),
9466                 TEST_CASE_ST(ut_setup, ut_teardown,
9467                         test_zuc_hash_generate_test_case_3),
9468                 TEST_CASE_ST(ut_setup, ut_teardown,
9469                         test_zuc_hash_generate_test_case_4),
9470                 TEST_CASE_ST(ut_setup, ut_teardown,
9471                         test_zuc_hash_generate_test_case_5),
9472                 TEST_CASE_ST(ut_setup, ut_teardown,
9473                         test_zuc_encryption_test_case_6_sgl),
9474                 TEST_CASES_END() /**< NULL terminate unit test array */
9475         }
9476 };
9477
9478 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
9479         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
9480         .setup = testsuite_setup,
9481         .teardown = testsuite_teardown,
9482         .unit_test_cases = {
9483                 TEST_CASE_ST(ut_setup, ut_teardown,
9484                              test_device_configure_invalid_dev_id),
9485                 TEST_CASE_ST(ut_setup, ut_teardown,
9486                              test_multi_session),
9487
9488                 TEST_CASE_ST(ut_setup, ut_teardown,
9489                              test_AES_chain_dpaa_sec_all),
9490                 TEST_CASE_ST(ut_setup, ut_teardown,
9491                              test_3DES_chain_dpaa_sec_all),
9492                 TEST_CASE_ST(ut_setup, ut_teardown,
9493                              test_AES_cipheronly_dpaa_sec_all),
9494                 TEST_CASE_ST(ut_setup, ut_teardown,
9495                              test_3DES_cipheronly_dpaa_sec_all),
9496                 TEST_CASE_ST(ut_setup, ut_teardown,
9497                              test_authonly_dpaa_sec_all),
9498
9499                 /** AES GCM Authenticated Encryption */
9500                 TEST_CASE_ST(ut_setup, ut_teardown,
9501                         test_AES_GCM_authenticated_encryption_test_case_1),
9502                 TEST_CASE_ST(ut_setup, ut_teardown,
9503                         test_AES_GCM_authenticated_encryption_test_case_2),
9504                 TEST_CASE_ST(ut_setup, ut_teardown,
9505                         test_AES_GCM_authenticated_encryption_test_case_3),
9506                 TEST_CASE_ST(ut_setup, ut_teardown,
9507                         test_AES_GCM_authenticated_encryption_test_case_4),
9508                 TEST_CASE_ST(ut_setup, ut_teardown,
9509                         test_AES_GCM_authenticated_encryption_test_case_5),
9510                 TEST_CASE_ST(ut_setup, ut_teardown,
9511                         test_AES_GCM_authenticated_encryption_test_case_6),
9512                 TEST_CASE_ST(ut_setup, ut_teardown,
9513                         test_AES_GCM_authenticated_encryption_test_case_7),
9514
9515                 /** AES GCM Authenticated Decryption */
9516                 TEST_CASE_ST(ut_setup, ut_teardown,
9517                         test_AES_GCM_authenticated_decryption_test_case_1),
9518                 TEST_CASE_ST(ut_setup, ut_teardown,
9519                         test_AES_GCM_authenticated_decryption_test_case_2),
9520                 TEST_CASE_ST(ut_setup, ut_teardown,
9521                         test_AES_GCM_authenticated_decryption_test_case_3),
9522                 TEST_CASE_ST(ut_setup, ut_teardown,
9523                         test_AES_GCM_authenticated_decryption_test_case_4),
9524                 TEST_CASE_ST(ut_setup, ut_teardown,
9525                         test_AES_GCM_authenticated_decryption_test_case_5),
9526                 TEST_CASE_ST(ut_setup, ut_teardown,
9527                         test_AES_GCM_authenticated_decryption_test_case_6),
9528                 TEST_CASE_ST(ut_setup, ut_teardown,
9529                         test_AES_GCM_authenticated_decryption_test_case_7),
9530
9531                 /** AES GCM Authenticated Encryption 256 bits key */
9532                 TEST_CASE_ST(ut_setup, ut_teardown,
9533                         test_AES_GCM_auth_encryption_test_case_256_1),
9534                 TEST_CASE_ST(ut_setup, ut_teardown,
9535                         test_AES_GCM_auth_encryption_test_case_256_2),
9536                 TEST_CASE_ST(ut_setup, ut_teardown,
9537                         test_AES_GCM_auth_encryption_test_case_256_3),
9538                 TEST_CASE_ST(ut_setup, ut_teardown,
9539                         test_AES_GCM_auth_encryption_test_case_256_4),
9540                 TEST_CASE_ST(ut_setup, ut_teardown,
9541                         test_AES_GCM_auth_encryption_test_case_256_5),
9542                 TEST_CASE_ST(ut_setup, ut_teardown,
9543                         test_AES_GCM_auth_encryption_test_case_256_6),
9544                 TEST_CASE_ST(ut_setup, ut_teardown,
9545                         test_AES_GCM_auth_encryption_test_case_256_7),
9546
9547                 /** AES GCM Authenticated Decryption 256 bits key */
9548                 TEST_CASE_ST(ut_setup, ut_teardown,
9549                         test_AES_GCM_auth_decryption_test_case_256_1),
9550                 TEST_CASE_ST(ut_setup, ut_teardown,
9551                         test_AES_GCM_auth_decryption_test_case_256_2),
9552                 TEST_CASE_ST(ut_setup, ut_teardown,
9553                         test_AES_GCM_auth_decryption_test_case_256_3),
9554                 TEST_CASE_ST(ut_setup, ut_teardown,
9555                         test_AES_GCM_auth_decryption_test_case_256_4),
9556                 TEST_CASE_ST(ut_setup, ut_teardown,
9557                         test_AES_GCM_auth_decryption_test_case_256_5),
9558                 TEST_CASE_ST(ut_setup, ut_teardown,
9559                         test_AES_GCM_auth_decryption_test_case_256_6),
9560                 TEST_CASE_ST(ut_setup, ut_teardown,
9561                         test_AES_GCM_auth_decryption_test_case_256_7),
9562
9563                 /** Out of place tests */
9564                 TEST_CASE_ST(ut_setup, ut_teardown,
9565                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9566                 TEST_CASE_ST(ut_setup, ut_teardown,
9567                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9568
9569                 /** Scatter-Gather */
9570                 TEST_CASE_ST(ut_setup, ut_teardown,
9571                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
9572                 TEST_CASE_ST(ut_setup, ut_teardown,
9573                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
9574                 TEST_CASE_ST(ut_setup, ut_teardown,
9575                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9576                 TEST_CASE_ST(ut_setup, ut_teardown,
9577                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
9578
9579                 TEST_CASES_END() /**< NULL terminate unit test array */
9580         }
9581 };
9582
9583 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
9584         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
9585         .setup = testsuite_setup,
9586         .teardown = testsuite_teardown,
9587         .unit_test_cases = {
9588                 TEST_CASE_ST(ut_setup, ut_teardown,
9589                         test_device_configure_invalid_dev_id),
9590                 TEST_CASE_ST(ut_setup, ut_teardown,
9591                         test_multi_session),
9592
9593                 TEST_CASE_ST(ut_setup, ut_teardown,
9594                         test_AES_chain_dpaa2_sec_all),
9595                 TEST_CASE_ST(ut_setup, ut_teardown,
9596                         test_3DES_chain_dpaa2_sec_all),
9597                 TEST_CASE_ST(ut_setup, ut_teardown,
9598                         test_AES_cipheronly_dpaa2_sec_all),
9599                 TEST_CASE_ST(ut_setup, ut_teardown,
9600                         test_3DES_cipheronly_dpaa2_sec_all),
9601                 TEST_CASE_ST(ut_setup, ut_teardown,
9602                         test_authonly_dpaa2_sec_all),
9603
9604                 /** AES GCM Authenticated Encryption */
9605                 TEST_CASE_ST(ut_setup, ut_teardown,
9606                         test_AES_GCM_authenticated_encryption_test_case_1),
9607                 TEST_CASE_ST(ut_setup, ut_teardown,
9608                         test_AES_GCM_authenticated_encryption_test_case_2),
9609                 TEST_CASE_ST(ut_setup, ut_teardown,
9610                         test_AES_GCM_authenticated_encryption_test_case_3),
9611                 TEST_CASE_ST(ut_setup, ut_teardown,
9612                         test_AES_GCM_authenticated_encryption_test_case_4),
9613                 TEST_CASE_ST(ut_setup, ut_teardown,
9614                         test_AES_GCM_authenticated_encryption_test_case_5),
9615                 TEST_CASE_ST(ut_setup, ut_teardown,
9616                         test_AES_GCM_authenticated_encryption_test_case_6),
9617                 TEST_CASE_ST(ut_setup, ut_teardown,
9618                         test_AES_GCM_authenticated_encryption_test_case_7),
9619
9620                 /** AES GCM Authenticated Decryption */
9621                 TEST_CASE_ST(ut_setup, ut_teardown,
9622                         test_AES_GCM_authenticated_decryption_test_case_1),
9623                 TEST_CASE_ST(ut_setup, ut_teardown,
9624                         test_AES_GCM_authenticated_decryption_test_case_2),
9625                 TEST_CASE_ST(ut_setup, ut_teardown,
9626                         test_AES_GCM_authenticated_decryption_test_case_3),
9627                 TEST_CASE_ST(ut_setup, ut_teardown,
9628                         test_AES_GCM_authenticated_decryption_test_case_4),
9629                 TEST_CASE_ST(ut_setup, ut_teardown,
9630                         test_AES_GCM_authenticated_decryption_test_case_5),
9631                 TEST_CASE_ST(ut_setup, ut_teardown,
9632                         test_AES_GCM_authenticated_decryption_test_case_6),
9633                 TEST_CASE_ST(ut_setup, ut_teardown,
9634                         test_AES_GCM_authenticated_decryption_test_case_7),
9635
9636                 /** AES GCM Authenticated Encryption 192 bits key */
9637                 TEST_CASE_ST(ut_setup, ut_teardown,
9638                         test_AES_GCM_auth_encryption_test_case_192_1),
9639                 TEST_CASE_ST(ut_setup, ut_teardown,
9640                         test_AES_GCM_auth_encryption_test_case_192_2),
9641                 TEST_CASE_ST(ut_setup, ut_teardown,
9642                         test_AES_GCM_auth_encryption_test_case_192_3),
9643                 TEST_CASE_ST(ut_setup, ut_teardown,
9644                         test_AES_GCM_auth_encryption_test_case_192_4),
9645                 TEST_CASE_ST(ut_setup, ut_teardown,
9646                         test_AES_GCM_auth_encryption_test_case_192_5),
9647                 TEST_CASE_ST(ut_setup, ut_teardown,
9648                         test_AES_GCM_auth_encryption_test_case_192_6),
9649                 TEST_CASE_ST(ut_setup, ut_teardown,
9650                         test_AES_GCM_auth_encryption_test_case_192_7),
9651
9652                 /** AES GCM Authenticated Decryption 192 bits key */
9653                 TEST_CASE_ST(ut_setup, ut_teardown,
9654                         test_AES_GCM_auth_decryption_test_case_192_1),
9655                 TEST_CASE_ST(ut_setup, ut_teardown,
9656                         test_AES_GCM_auth_decryption_test_case_192_2),
9657                 TEST_CASE_ST(ut_setup, ut_teardown,
9658                         test_AES_GCM_auth_decryption_test_case_192_3),
9659                 TEST_CASE_ST(ut_setup, ut_teardown,
9660                         test_AES_GCM_auth_decryption_test_case_192_4),
9661                 TEST_CASE_ST(ut_setup, ut_teardown,
9662                         test_AES_GCM_auth_decryption_test_case_192_5),
9663                 TEST_CASE_ST(ut_setup, ut_teardown,
9664                         test_AES_GCM_auth_decryption_test_case_192_6),
9665                 TEST_CASE_ST(ut_setup, ut_teardown,
9666                         test_AES_GCM_auth_decryption_test_case_192_7),
9667
9668                 /** AES GCM Authenticated Encryption 256 bits key */
9669                 TEST_CASE_ST(ut_setup, ut_teardown,
9670                         test_AES_GCM_auth_encryption_test_case_256_1),
9671                 TEST_CASE_ST(ut_setup, ut_teardown,
9672                         test_AES_GCM_auth_encryption_test_case_256_2),
9673                 TEST_CASE_ST(ut_setup, ut_teardown,
9674                         test_AES_GCM_auth_encryption_test_case_256_3),
9675                 TEST_CASE_ST(ut_setup, ut_teardown,
9676                         test_AES_GCM_auth_encryption_test_case_256_4),
9677                 TEST_CASE_ST(ut_setup, ut_teardown,
9678                         test_AES_GCM_auth_encryption_test_case_256_5),
9679                 TEST_CASE_ST(ut_setup, ut_teardown,
9680                         test_AES_GCM_auth_encryption_test_case_256_6),
9681                 TEST_CASE_ST(ut_setup, ut_teardown,
9682                         test_AES_GCM_auth_encryption_test_case_256_7),
9683
9684                 /** AES GCM Authenticated Decryption 256 bits key */
9685                 TEST_CASE_ST(ut_setup, ut_teardown,
9686                         test_AES_GCM_auth_decryption_test_case_256_1),
9687                 TEST_CASE_ST(ut_setup, ut_teardown,
9688                         test_AES_GCM_auth_decryption_test_case_256_2),
9689                 TEST_CASE_ST(ut_setup, ut_teardown,
9690                         test_AES_GCM_auth_decryption_test_case_256_3),
9691                 TEST_CASE_ST(ut_setup, ut_teardown,
9692                         test_AES_GCM_auth_decryption_test_case_256_4),
9693                 TEST_CASE_ST(ut_setup, ut_teardown,
9694                         test_AES_GCM_auth_decryption_test_case_256_5),
9695                 TEST_CASE_ST(ut_setup, ut_teardown,
9696                         test_AES_GCM_auth_decryption_test_case_256_6),
9697                 TEST_CASE_ST(ut_setup, ut_teardown,
9698                         test_AES_GCM_auth_decryption_test_case_256_7),
9699
9700                 /** Out of place tests */
9701                 TEST_CASE_ST(ut_setup, ut_teardown,
9702                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
9703                 TEST_CASE_ST(ut_setup, ut_teardown,
9704                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
9705
9706                 /** Scatter-Gather */
9707                 TEST_CASE_ST(ut_setup, ut_teardown,
9708                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
9709                 TEST_CASE_ST(ut_setup, ut_teardown,
9710                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
9711                 TEST_CASE_ST(ut_setup, ut_teardown,
9712                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
9713                 TEST_CASE_ST(ut_setup, ut_teardown,
9714                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
9715
9716                 TEST_CASES_END() /**< NULL terminate unit test array */
9717         }
9718 };
9719
9720 static struct unit_test_suite cryptodev_null_testsuite  = {
9721         .suite_name = "Crypto Device NULL Unit Test Suite",
9722         .setup = testsuite_setup,
9723         .teardown = testsuite_teardown,
9724         .unit_test_cases = {
9725                 TEST_CASE_ST(ut_setup, ut_teardown,
9726                         test_null_auth_only_operation),
9727                 TEST_CASE_ST(ut_setup, ut_teardown,
9728                         test_null_cipher_only_operation),
9729                 TEST_CASE_ST(ut_setup, ut_teardown,
9730                         test_null_cipher_auth_operation),
9731                 TEST_CASE_ST(ut_setup, ut_teardown,
9732                         test_null_auth_cipher_operation),
9733                 TEST_CASE_ST(ut_setup, ut_teardown,
9734                         test_null_invalid_operation),
9735                 TEST_CASE_ST(ut_setup, ut_teardown,
9736                         test_null_burst_operation),
9737
9738                 TEST_CASES_END() /**< NULL terminate unit test array */
9739         }
9740 };
9741
9742 static struct unit_test_suite cryptodev_armv8_testsuite  = {
9743         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
9744         .setup = testsuite_setup,
9745         .teardown = testsuite_teardown,
9746         .unit_test_cases = {
9747                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
9748
9749                 /** Negative tests */
9750                 TEST_CASE_ST(ut_setup, ut_teardown,
9751                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9752                 TEST_CASE_ST(ut_setup, ut_teardown,
9753                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9754
9755                 TEST_CASES_END() /**< NULL terminate unit test array */
9756         }
9757 };
9758
9759 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
9760         .suite_name = "Crypto Device Marvell Component Test Suite",
9761         .setup = testsuite_setup,
9762         .teardown = testsuite_teardown,
9763         .unit_test_cases = {
9764                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
9765                 TEST_CASE_ST(ut_setup, ut_teardown,
9766                                 test_multi_session_random_usage),
9767                 TEST_CASE_ST(ut_setup, ut_teardown,
9768                                 test_AES_chain_mrvl_all),
9769                 TEST_CASE_ST(ut_setup, ut_teardown,
9770                                 test_AES_cipheronly_mrvl_all),
9771                 TEST_CASE_ST(ut_setup, ut_teardown,
9772                                 test_authonly_mrvl_all),
9773                 TEST_CASE_ST(ut_setup, ut_teardown,
9774                                 test_3DES_chain_mrvl_all),
9775                 TEST_CASE_ST(ut_setup, ut_teardown,
9776                                 test_3DES_cipheronly_mrvl_all),
9777
9778                 /** Negative tests */
9779                 TEST_CASE_ST(ut_setup, ut_teardown,
9780                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9781                 TEST_CASE_ST(ut_setup, ut_teardown,
9782                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9783                 TEST_CASE_ST(ut_setup, ut_teardown,
9784                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9785                 TEST_CASE_ST(ut_setup, ut_teardown,
9786                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9787
9788                 TEST_CASES_END() /**< NULL terminate unit test array */
9789         }
9790 };
9791
9792 static struct unit_test_suite cryptodev_ccp_testsuite  = {
9793         .suite_name = "Crypto Device CCP Unit Test Suite",
9794         .setup = testsuite_setup,
9795         .teardown = testsuite_teardown,
9796         .unit_test_cases = {
9797                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
9798                 TEST_CASE_ST(ut_setup, ut_teardown,
9799                                 test_multi_session_random_usage),
9800                 TEST_CASE_ST(ut_setup, ut_teardown,
9801                                 test_AES_chain_ccp_all),
9802                 TEST_CASE_ST(ut_setup, ut_teardown,
9803                                 test_AES_cipheronly_ccp_all),
9804                 TEST_CASE_ST(ut_setup, ut_teardown,
9805                                 test_3DES_chain_ccp_all),
9806                 TEST_CASE_ST(ut_setup, ut_teardown,
9807                                 test_3DES_cipheronly_ccp_all),
9808                 TEST_CASE_ST(ut_setup, ut_teardown,
9809                                 test_authonly_ccp_all),
9810
9811                 /** Negative tests */
9812                 TEST_CASE_ST(ut_setup, ut_teardown,
9813                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
9814                 TEST_CASE_ST(ut_setup, ut_teardown,
9815                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
9816                 TEST_CASE_ST(ut_setup, ut_teardown,
9817                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
9818                 TEST_CASE_ST(ut_setup, ut_teardown,
9819                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
9820
9821                 TEST_CASES_END() /**< NULL terminate unit test array */
9822         }
9823 };
9824
9825 static int
9826 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
9827 {
9828         gbl_driver_id = rte_cryptodev_driver_id_get(
9829                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
9830
9831         if (gbl_driver_id == -1) {
9832                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
9833                                 "CONFIG_RTE_LIBRTE_PMD_QAT is enabled "
9834                                 "in config file to run this testsuite.\n");
9835                 return TEST_SKIPPED;
9836         }
9837
9838         return unit_test_suite_runner(&cryptodev_qat_testsuite);
9839 }
9840
9841 static int
9842 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
9843 {
9844         gbl_driver_id = rte_cryptodev_driver_id_get(
9845                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
9846
9847         if (gbl_driver_id == -1) {
9848                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
9849                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
9850                                 "in config file to run this testsuite.\n");
9851                 return TEST_FAILED;
9852         }
9853
9854         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
9855 }
9856
9857 static int
9858 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
9859 {
9860         gbl_driver_id = rte_cryptodev_driver_id_get(
9861                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
9862
9863         if (gbl_driver_id == -1) {
9864                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
9865                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
9866                                 "in config file to run this testsuite.\n");
9867                 return TEST_SKIPPED;
9868         }
9869
9870         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
9871 }
9872
9873 static int
9874 test_cryptodev_openssl(void)
9875 {
9876         gbl_driver_id = rte_cryptodev_driver_id_get(
9877                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
9878
9879         if (gbl_driver_id == -1) {
9880                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
9881                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
9882                                 "in config file to run this testsuite.\n");
9883                 return TEST_SKIPPED;
9884         }
9885
9886         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
9887 }
9888
9889 static int
9890 test_cryptodev_aesni_gcm(void)
9891 {
9892         gbl_driver_id = rte_cryptodev_driver_id_get(
9893                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
9894
9895         if (gbl_driver_id == -1) {
9896                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
9897                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
9898                                 "in config file to run this testsuite.\n");
9899                 return TEST_SKIPPED;
9900         }
9901
9902         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
9903 }
9904
9905 static int
9906 test_cryptodev_null(void)
9907 {
9908         gbl_driver_id = rte_cryptodev_driver_id_get(
9909                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
9910
9911         if (gbl_driver_id == -1) {
9912                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
9913                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
9914                                 "in config file to run this testsuite.\n");
9915                 return TEST_SKIPPED;
9916         }
9917
9918         return unit_test_suite_runner(&cryptodev_null_testsuite);
9919 }
9920
9921 static int
9922 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
9923 {
9924         gbl_driver_id = rte_cryptodev_driver_id_get(
9925                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
9926
9927         if (gbl_driver_id == -1) {
9928                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
9929                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
9930                                 "in config file to run this testsuite.\n");
9931                 return TEST_SKIPPED;
9932         }
9933
9934         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
9935 }
9936
9937 static int
9938 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
9939 {
9940         gbl_driver_id = rte_cryptodev_driver_id_get(
9941                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
9942
9943         if (gbl_driver_id == -1) {
9944                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
9945                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
9946                                 "in config file to run this testsuite.\n");
9947                 return TEST_SKIPPED;
9948         }
9949
9950         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
9951 }
9952
9953 static int
9954 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
9955 {
9956         gbl_driver_id = rte_cryptodev_driver_id_get(
9957                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
9958
9959         if (gbl_driver_id == -1) {
9960                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
9961                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
9962                                 "in config file to run this testsuite.\n");
9963                 return TEST_SKIPPED;
9964         }
9965
9966         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
9967 }
9968
9969 static int
9970 test_cryptodev_armv8(void)
9971 {
9972         gbl_driver_id = rte_cryptodev_driver_id_get(
9973                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
9974
9975         if (gbl_driver_id == -1) {
9976                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
9977                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
9978                                 "in config file to run this testsuite.\n");
9979                 return TEST_SKIPPED;
9980         }
9981
9982         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
9983 }
9984
9985 static int
9986 test_cryptodev_mrvl(void)
9987 {
9988         gbl_driver_id = rte_cryptodev_driver_id_get(
9989                         RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
9990
9991         if (gbl_driver_id == -1) {
9992                 RTE_LOG(ERR, USER1, "MRVL PMD must be loaded. Check if "
9993                                 "CONFIG_RTE_LIBRTE_PMD_MRVL_CRYPTO is enabled "
9994                                 "in config file to run this testsuite.\n");
9995                 return TEST_SKIPPED;
9996         }
9997
9998         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
9999 }
10000
10001 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
10002
10003 static int
10004 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
10005 {
10006         gbl_driver_id = rte_cryptodev_driver_id_get(
10007                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
10008
10009         if (gbl_driver_id == -1) {
10010                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
10011                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
10012                                 "in config file to run this testsuite.\n");
10013                 return TEST_SKIPPED;
10014         }
10015
10016         if (rte_cryptodev_driver_id_get(
10017                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
10018                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
10019                         " enabled in config file to run this testsuite.\n");
10020                 return TEST_SKIPPED;
10021 }
10022         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
10023 }
10024
10025 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
10026
10027 #endif
10028
10029 static int
10030 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
10031 {
10032         gbl_driver_id = rte_cryptodev_driver_id_get(
10033                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
10034
10035         if (gbl_driver_id == -1) {
10036                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
10037                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
10038                                 "in config file to run this testsuite.\n");
10039                 return TEST_SKIPPED;
10040         }
10041
10042         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
10043 }
10044
10045 static int
10046 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
10047 {
10048         gbl_driver_id = rte_cryptodev_driver_id_get(
10049                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
10050
10051         if (gbl_driver_id == -1) {
10052                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
10053                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
10054                                 "in config file to run this testsuite.\n");
10055                 return TEST_SKIPPED;
10056         }
10057
10058         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
10059 }
10060
10061 static int
10062 test_cryptodev_ccp(void)
10063 {
10064         gbl_driver_id = rte_cryptodev_driver_id_get(
10065                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
10066
10067         if (gbl_driver_id == -1) {
10068                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
10069                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
10070                                 "in config file to run this testsuite.\n");
10071                 return TEST_FAILED;
10072         }
10073
10074         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
10075 }
10076
10077 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
10078 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
10079 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
10080 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
10081 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
10082 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
10083 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
10084 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
10085 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
10086 REGISTER_TEST_COMMAND(cryptodev_sw_mrvl_autotest, test_cryptodev_mrvl);
10087 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
10088 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
10089 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
10090 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);