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