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