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