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