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