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