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