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