test/crypto: rename some tests
[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_256_1(void)
4959 {
4960         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_1);
4961 }
4962
4963 static int
4964 test_AES_GCM_auth_encryption_test_case_256_2(void)
4965 {
4966         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_2);
4967 }
4968
4969 static int
4970 test_AES_GCM_auth_encryption_test_case_256_3(void)
4971 {
4972         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_3);
4973 }
4974
4975 static int
4976 test_AES_GCM_auth_encryption_test_case_256_4(void)
4977 {
4978         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_4);
4979 }
4980
4981 static int
4982 test_AES_GCM_auth_encryption_test_case_256_5(void)
4983 {
4984         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_5);
4985 }
4986
4987 static int
4988 test_AES_GCM_auth_encryption_test_case_256_6(void)
4989 {
4990         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_6);
4991 }
4992
4993 static int
4994 test_AES_GCM_auth_encryption_test_case_256_7(void)
4995 {
4996         return test_AES_GCM_authenticated_encryption(&gcm_test_case_256_7);
4997 }
4998
4999 static int
5000 test_AES_GCM_auth_encryption_test_case_aad_1(void)
5001 {
5002         return test_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1);
5003 }
5004
5005 static int
5006 test_AES_GCM_auth_encryption_test_case_aad_2(void)
5007 {
5008         return test_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2);
5009 }
5010
5011 static int
5012 test_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
5013 {
5014         struct crypto_testsuite_params *ts_params = &testsuite_params;
5015         struct crypto_unittest_params *ut_params = &unittest_params;
5016
5017         int retval;
5018         uint8_t *plaintext;
5019         uint32_t i;
5020
5021         /* Create GCM session */
5022         retval = create_gcm_session(ts_params->valid_devs[0],
5023                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5024                         tdata->key.data, tdata->key.len,
5025                         tdata->aad.len, tdata->auth_tag.len,
5026                         tdata->iv.len);
5027         if (retval < 0)
5028                 return retval;
5029
5030         /* alloc mbuf and set payload */
5031         if (tdata->aad.len > MBUF_SIZE) {
5032                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5033                 /* Populate full size of add data */
5034                 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
5035                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5036         } else
5037                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5038
5039         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5040                         rte_pktmbuf_tailroom(ut_params->ibuf));
5041
5042         /* Create GCM operation */
5043         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5044         if (retval < 0)
5045                 return retval;
5046
5047         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5048
5049         ut_params->op->sym->m_src = ut_params->ibuf;
5050
5051         /* Process crypto operation */
5052         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5053                         ut_params->op), "failed to process sym crypto op");
5054
5055         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5056                         "crypto op processing failed");
5057
5058         if (ut_params->op->sym->m_dst)
5059                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5060                                 uint8_t *);
5061         else
5062                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5063                                 uint8_t *,
5064                                 ut_params->op->sym->cipher.data.offset);
5065
5066         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5067
5068         /* Validate obuf */
5069         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5070                         plaintext,
5071                         tdata->plaintext.data,
5072                         tdata->plaintext.len,
5073                         "GCM plaintext data not as expected");
5074
5075         TEST_ASSERT_EQUAL(ut_params->op->status,
5076                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5077                         "GCM authentication failed");
5078         return 0;
5079 }
5080
5081 static int
5082 test_AES_GCM_authenticated_decryption_test_case_1(void)
5083 {
5084         return test_AES_GCM_authenticated_decryption(&gcm_test_case_1);
5085 }
5086
5087 static int
5088 test_AES_GCM_authenticated_decryption_test_case_2(void)
5089 {
5090         return test_AES_GCM_authenticated_decryption(&gcm_test_case_2);
5091 }
5092
5093 static int
5094 test_AES_GCM_authenticated_decryption_test_case_3(void)
5095 {
5096         return test_AES_GCM_authenticated_decryption(&gcm_test_case_3);
5097 }
5098
5099 static int
5100 test_AES_GCM_authenticated_decryption_test_case_4(void)
5101 {
5102         return test_AES_GCM_authenticated_decryption(&gcm_test_case_4);
5103 }
5104
5105 static int
5106 test_AES_GCM_authenticated_decryption_test_case_5(void)
5107 {
5108         return test_AES_GCM_authenticated_decryption(&gcm_test_case_5);
5109 }
5110
5111 static int
5112 test_AES_GCM_authenticated_decryption_test_case_6(void)
5113 {
5114         return test_AES_GCM_authenticated_decryption(&gcm_test_case_6);
5115 }
5116
5117 static int
5118 test_AES_GCM_authenticated_decryption_test_case_7(void)
5119 {
5120         return test_AES_GCM_authenticated_decryption(&gcm_test_case_7);
5121 }
5122
5123 static int
5124 test_AES_GCM_auth_decryption_test_case_256_1(void)
5125 {
5126         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_1);
5127 }
5128
5129 static int
5130 test_AES_GCM_auth_decryption_test_case_256_2(void)
5131 {
5132         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_2);
5133 }
5134
5135 static int
5136 test_AES_GCM_auth_decryption_test_case_256_3(void)
5137 {
5138         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_3);
5139 }
5140
5141 static int
5142 test_AES_GCM_auth_decryption_test_case_256_4(void)
5143 {
5144         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_4);
5145 }
5146
5147 static int
5148 test_AES_GCM_auth_decryption_test_case_256_5(void)
5149 {
5150         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_5);
5151 }
5152
5153 static int
5154 test_AES_GCM_auth_decryption_test_case_256_6(void)
5155 {
5156         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_6);
5157 }
5158
5159 static int
5160 test_AES_GCM_auth_decryption_test_case_256_7(void)
5161 {
5162         return test_AES_GCM_authenticated_decryption(&gcm_test_case_256_7);
5163 }
5164
5165 static int
5166 test_AES_GCM_auth_decryption_test_case_aad_1(void)
5167 {
5168         return test_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1);
5169 }
5170
5171 static int
5172 test_AES_GCM_auth_decryption_test_case_aad_2(void)
5173 {
5174         return test_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2);
5175 }
5176
5177 static int
5178 test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata)
5179 {
5180         struct crypto_testsuite_params *ts_params = &testsuite_params;
5181         struct crypto_unittest_params *ut_params = &unittest_params;
5182
5183         int retval;
5184         uint8_t *ciphertext, *auth_tag;
5185         uint16_t plaintext_pad_len;
5186
5187         /* Create GCM session */
5188         retval = create_gcm_session(ts_params->valid_devs[0],
5189                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5190                         tdata->key.data, tdata->key.len,
5191                         tdata->aad.len, tdata->auth_tag.len,
5192                         tdata->iv.len);
5193         if (retval < 0)
5194                 return retval;
5195
5196         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5197         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5198
5199         /* clear mbuf payload */
5200         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5201                         rte_pktmbuf_tailroom(ut_params->ibuf));
5202         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5203                         rte_pktmbuf_tailroom(ut_params->obuf));
5204
5205         /* Create GCM operation */
5206         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5207         if (retval < 0)
5208                 return retval;
5209
5210         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5211
5212         ut_params->op->sym->m_src = ut_params->ibuf;
5213         ut_params->op->sym->m_dst = ut_params->obuf;
5214
5215         /* Process crypto operation */
5216         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5217                         ut_params->op), "failed to process sym crypto op");
5218
5219         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5220                         "crypto op processing failed");
5221
5222         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5223
5224         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5225                         ut_params->op->sym->cipher.data.offset);
5226         auth_tag = ciphertext + plaintext_pad_len;
5227
5228         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5229         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5230
5231         /* Validate obuf */
5232         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5233                         ciphertext,
5234                         tdata->ciphertext.data,
5235                         tdata->ciphertext.len,
5236                         "GCM Ciphertext data not as expected");
5237
5238         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5239                         auth_tag,
5240                         tdata->auth_tag.data,
5241                         tdata->auth_tag.len,
5242                         "GCM Generated auth tag not as expected");
5243
5244         return 0;
5245
5246 }
5247
5248 static int
5249 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
5250 {
5251         return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5);
5252 }
5253
5254 static int
5255 test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata)
5256 {
5257         struct crypto_testsuite_params *ts_params = &testsuite_params;
5258         struct crypto_unittest_params *ut_params = &unittest_params;
5259
5260         int retval;
5261         uint8_t *plaintext;
5262
5263         /* Create GCM session */
5264         retval = create_gcm_session(ts_params->valid_devs[0],
5265                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5266                         tdata->key.data, tdata->key.len,
5267                         tdata->aad.len, tdata->auth_tag.len,
5268                         tdata->iv.len);
5269         if (retval < 0)
5270                 return retval;
5271
5272         /* alloc mbuf and set payload */
5273         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5274         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5275
5276         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5277                         rte_pktmbuf_tailroom(ut_params->ibuf));
5278         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5279                         rte_pktmbuf_tailroom(ut_params->obuf));
5280
5281         /* Create GCM operation */
5282         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5283         if (retval < 0)
5284                 return retval;
5285
5286         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5287
5288         ut_params->op->sym->m_src = ut_params->ibuf;
5289         ut_params->op->sym->m_dst = ut_params->obuf;
5290
5291         /* Process crypto operation */
5292         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5293                         ut_params->op), "failed to process sym crypto op");
5294
5295         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5296                         "crypto op processing failed");
5297
5298         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5299                         ut_params->op->sym->cipher.data.offset);
5300
5301         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5302
5303         /* Validate obuf */
5304         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5305                         plaintext,
5306                         tdata->plaintext.data,
5307                         tdata->plaintext.len,
5308                         "GCM plaintext data not as expected");
5309
5310         TEST_ASSERT_EQUAL(ut_params->op->status,
5311                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5312                         "GCM authentication failed");
5313         return 0;
5314 }
5315
5316 static int
5317 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
5318 {
5319         return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5);
5320 }
5321
5322 static int
5323 test_AES_GCM_authenticated_encryption_sessionless(
5324                 const struct gcm_test_data *tdata)
5325 {
5326         struct crypto_testsuite_params *ts_params = &testsuite_params;
5327         struct crypto_unittest_params *ut_params = &unittest_params;
5328
5329         int retval;
5330         uint8_t *ciphertext, *auth_tag;
5331         uint16_t plaintext_pad_len;
5332         uint8_t key[tdata->key.len + 1];
5333
5334         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5335
5336         /* clear mbuf payload */
5337         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5338                         rte_pktmbuf_tailroom(ut_params->ibuf));
5339
5340         /* Create GCM operation */
5341         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
5342         if (retval < 0)
5343                 return retval;
5344
5345         /* Create GCM xforms */
5346         memcpy(key, tdata->key.data, tdata->key.len);
5347         retval = create_gcm_xforms(ut_params->op,
5348                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
5349                         key, tdata->key.len,
5350                         tdata->aad.len, tdata->auth_tag.len,
5351                         tdata->iv.len);
5352         if (retval < 0)
5353                 return retval;
5354
5355         ut_params->op->sym->m_src = ut_params->ibuf;
5356
5357         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
5358                         RTE_CRYPTO_OP_SESSIONLESS,
5359                         "crypto op session type not sessionless");
5360
5361         /* Process crypto operation */
5362         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5363                         ut_params->op), "failed to process sym crypto op");
5364
5365         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5366
5367         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5368                         "crypto op status not success");
5369
5370         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5371
5372         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5373                         ut_params->op->sym->cipher.data.offset);
5374         auth_tag = ciphertext + plaintext_pad_len;
5375
5376         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5377         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5378
5379         /* Validate obuf */
5380         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5381                         ciphertext,
5382                         tdata->ciphertext.data,
5383                         tdata->ciphertext.len,
5384                         "GCM Ciphertext data not as expected");
5385
5386         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5387                         auth_tag,
5388                         tdata->auth_tag.data,
5389                         tdata->auth_tag.len,
5390                         "GCM Generated auth tag not as expected");
5391
5392         return 0;
5393
5394 }
5395
5396 static int
5397 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
5398 {
5399         return test_AES_GCM_authenticated_encryption_sessionless(
5400                         &gcm_test_case_5);
5401 }
5402
5403 static int
5404 test_AES_GCM_authenticated_decryption_sessionless(
5405                 const struct gcm_test_data *tdata)
5406 {
5407         struct crypto_testsuite_params *ts_params = &testsuite_params;
5408         struct crypto_unittest_params *ut_params = &unittest_params;
5409
5410         int retval;
5411         uint8_t *plaintext;
5412         uint8_t key[tdata->key.len + 1];
5413
5414         /* alloc mbuf and set payload */
5415         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5416
5417         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5418                         rte_pktmbuf_tailroom(ut_params->ibuf));
5419
5420         /* Create GCM operation */
5421         retval = create_gcm_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
5422         if (retval < 0)
5423                 return retval;
5424
5425         /* Create GCM xforms */
5426         memcpy(key, tdata->key.data, tdata->key.len);
5427         retval = create_gcm_xforms(ut_params->op,
5428                         RTE_CRYPTO_AEAD_OP_DECRYPT,
5429                         key, tdata->key.len,
5430                         tdata->aad.len, tdata->auth_tag.len,
5431                         tdata->iv.len);
5432         if (retval < 0)
5433                 return retval;
5434
5435         ut_params->op->sym->m_src = ut_params->ibuf;
5436
5437         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
5438                         RTE_CRYPTO_OP_SESSIONLESS,
5439                         "crypto op session type not sessionless");
5440
5441         /* Process crypto operation */
5442         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5443                         ut_params->op), "failed to process sym crypto op");
5444
5445         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5446
5447         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5448                         "crypto op status not success");
5449
5450         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5451                         ut_params->op->sym->cipher.data.offset);
5452
5453         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5454
5455         /* Validate obuf */
5456         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5457                         plaintext,
5458                         tdata->plaintext.data,
5459                         tdata->plaintext.len,
5460                         "GCM plaintext data not as expected");
5461
5462         TEST_ASSERT_EQUAL(ut_params->op->status,
5463                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5464                         "GCM authentication failed");
5465         return 0;
5466 }
5467
5468 static int
5469 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
5470 {
5471         return test_AES_GCM_authenticated_decryption_sessionless(
5472                         &gcm_test_case_5);
5473 }
5474
5475 static int
5476 test_stats(void)
5477 {
5478         struct crypto_testsuite_params *ts_params = &testsuite_params;
5479         struct rte_cryptodev_stats stats;
5480         struct rte_cryptodev *dev;
5481         cryptodev_stats_get_t temp_pfn;
5482
5483         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5484         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
5485                         &stats) == -ENODEV),
5486                 "rte_cryptodev_stats_get invalid dev failed");
5487         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
5488                 "rte_cryptodev_stats_get invalid Param failed");
5489         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
5490         temp_pfn = dev->dev_ops->stats_get;
5491         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
5492         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
5493                         == -ENOTSUP),
5494                 "rte_cryptodev_stats_get invalid Param failed");
5495         dev->dev_ops->stats_get = temp_pfn;
5496
5497         /* Test expected values */
5498         ut_setup();
5499         test_AES_CBC_HMAC_SHA1_encrypt_digest();
5500         ut_teardown();
5501         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5502                         &stats),
5503                 "rte_cryptodev_stats_get failed");
5504         TEST_ASSERT((stats.enqueued_count == 1),
5505                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5506         TEST_ASSERT((stats.dequeued_count == 1),
5507                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5508         TEST_ASSERT((stats.enqueue_err_count == 0),
5509                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5510         TEST_ASSERT((stats.dequeue_err_count == 0),
5511                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5512
5513         /* invalid device but should ignore and not reset device stats*/
5514         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
5515         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5516                         &stats),
5517                 "rte_cryptodev_stats_get failed");
5518         TEST_ASSERT((stats.enqueued_count == 1),
5519                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5520
5521         /* check that a valid reset clears stats */
5522         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5523         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5524                         &stats),
5525                                           "rte_cryptodev_stats_get failed");
5526         TEST_ASSERT((stats.enqueued_count == 0),
5527                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5528         TEST_ASSERT((stats.dequeued_count == 0),
5529                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5530
5531         return TEST_SUCCESS;
5532 }
5533
5534 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
5535                                    struct crypto_unittest_params *ut_params,
5536                                    enum rte_crypto_auth_operation op,
5537                                    const struct HMAC_MD5_vector *test_case)
5538 {
5539         uint8_t key[64];
5540
5541         memcpy(key, test_case->key.data, test_case->key.len);
5542
5543         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5544         ut_params->auth_xform.next = NULL;
5545         ut_params->auth_xform.auth.op = op;
5546
5547         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
5548
5549         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
5550         ut_params->auth_xform.auth.key.length = test_case->key.len;
5551         ut_params->auth_xform.auth.key.data = key;
5552
5553         ut_params->sess = rte_cryptodev_sym_session_create(
5554                 ts_params->valid_devs[0], &ut_params->auth_xform);
5555
5556         if (ut_params->sess == NULL)
5557                 return TEST_FAILED;
5558
5559         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5560
5561         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5562                         rte_pktmbuf_tailroom(ut_params->ibuf));
5563
5564         return 0;
5565 }
5566
5567 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
5568                               const struct HMAC_MD5_vector *test_case,
5569                               uint8_t **plaintext)
5570 {
5571         uint16_t plaintext_pad_len;
5572
5573         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5574
5575         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5576                                 16);
5577
5578         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5579                         plaintext_pad_len);
5580         memcpy(*plaintext, test_case->plaintext.data,
5581                         test_case->plaintext.len);
5582
5583         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5584                         ut_params->ibuf, MD5_DIGEST_LEN);
5585         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5586                         "no room to append digest");
5587         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5588                         ut_params->ibuf, plaintext_pad_len);
5589
5590         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5591                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
5592                            test_case->auth_tag.len);
5593         }
5594
5595         sym_op->auth.data.offset = 0;
5596         sym_op->auth.data.length = test_case->plaintext.len;
5597
5598         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5599         ut_params->op->sym->m_src = ut_params->ibuf;
5600
5601         return 0;
5602 }
5603
5604 static int
5605 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
5606 {
5607         uint16_t plaintext_pad_len;
5608         uint8_t *plaintext, *auth_tag;
5609
5610         struct crypto_testsuite_params *ts_params = &testsuite_params;
5611         struct crypto_unittest_params *ut_params = &unittest_params;
5612
5613         if (MD5_HMAC_create_session(ts_params, ut_params,
5614                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
5615                 return TEST_FAILED;
5616
5617         /* Generate Crypto op data structure */
5618         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5619                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5620         TEST_ASSERT_NOT_NULL(ut_params->op,
5621                         "Failed to allocate symmetric crypto operation struct");
5622
5623         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5624                                 16);
5625
5626         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5627                 return TEST_FAILED;
5628
5629         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5630                         ut_params->op), "failed to process sym crypto op");
5631
5632         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5633                         "crypto op processing failed");
5634
5635         if (ut_params->op->sym->m_dst) {
5636                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5637                                 uint8_t *, plaintext_pad_len);
5638         } else {
5639                 auth_tag = plaintext + plaintext_pad_len;
5640         }
5641
5642         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5643                         auth_tag,
5644                         test_case->auth_tag.data,
5645                         test_case->auth_tag.len,
5646                         "HMAC_MD5 generated tag not as expected");
5647
5648         return TEST_SUCCESS;
5649 }
5650
5651 static int
5652 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
5653 {
5654         uint8_t *plaintext;
5655
5656         struct crypto_testsuite_params *ts_params = &testsuite_params;
5657         struct crypto_unittest_params *ut_params = &unittest_params;
5658
5659         if (MD5_HMAC_create_session(ts_params, ut_params,
5660                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
5661                 return TEST_FAILED;
5662         }
5663
5664         /* Generate Crypto op data structure */
5665         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5666                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5667         TEST_ASSERT_NOT_NULL(ut_params->op,
5668                         "Failed to allocate symmetric crypto operation struct");
5669
5670         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5671                 return TEST_FAILED;
5672
5673         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5674                         ut_params->op), "failed to process sym crypto op");
5675
5676         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5677                         "HMAC_MD5 crypto op processing failed");
5678
5679         return TEST_SUCCESS;
5680 }
5681
5682 static int
5683 test_MD5_HMAC_generate_case_1(void)
5684 {
5685         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
5686 }
5687
5688 static int
5689 test_MD5_HMAC_verify_case_1(void)
5690 {
5691         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
5692 }
5693
5694 static int
5695 test_MD5_HMAC_generate_case_2(void)
5696 {
5697         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
5698 }
5699
5700 static int
5701 test_MD5_HMAC_verify_case_2(void)
5702 {
5703         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
5704 }
5705
5706 static int
5707 test_multi_session(void)
5708 {
5709         struct crypto_testsuite_params *ts_params = &testsuite_params;
5710         struct crypto_unittest_params *ut_params = &unittest_params;
5711
5712         struct rte_cryptodev_info dev_info;
5713         struct rte_cryptodev_sym_session **sessions;
5714
5715         uint16_t i;
5716
5717         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
5718                         aes_cbc_key, hmac_sha512_key);
5719
5720
5721         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5722
5723         sessions = rte_malloc(NULL,
5724                         (sizeof(struct rte_cryptodev_sym_session *) *
5725                         dev_info.sym.max_nb_sessions) + 1, 0);
5726
5727         /* Create multiple crypto sessions*/
5728         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
5729                 sessions[i] = rte_cryptodev_sym_session_create(
5730                                 ts_params->valid_devs[0],
5731                         &ut_params->auth_xform);
5732                 TEST_ASSERT_NOT_NULL(sessions[i],
5733                                 "Session creation failed at session number %u",
5734                                 i);
5735
5736                 /* Attempt to send a request on each session */
5737                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
5738                         sessions[i],
5739                         ut_params,
5740                         ts_params,
5741                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
5742                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
5743                         aes_cbc_iv),
5744                         "Failed to perform decrypt on request number %u.", i);
5745                 /* free crypto operation structure */
5746                 if (ut_params->op)
5747                         rte_crypto_op_free(ut_params->op);
5748
5749                 /*
5750                  * free mbuf - both obuf and ibuf are usually the same,
5751                  * so check if they point at the same address is necessary,
5752                  * to avoid freeing the mbuf twice.
5753                  */
5754                 if (ut_params->obuf) {
5755                         rte_pktmbuf_free(ut_params->obuf);
5756                         if (ut_params->ibuf == ut_params->obuf)
5757                                 ut_params->ibuf = 0;
5758                         ut_params->obuf = 0;
5759                 }
5760                 if (ut_params->ibuf) {
5761                         rte_pktmbuf_free(ut_params->ibuf);
5762                         ut_params->ibuf = 0;
5763                 }
5764         }
5765
5766         /* Next session create should fail */
5767         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
5768                         &ut_params->auth_xform);
5769         TEST_ASSERT_NULL(sessions[i],
5770                         "Session creation succeeded unexpectedly!");
5771
5772         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
5773                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5774                                 sessions[i]);
5775
5776         rte_free(sessions);
5777
5778         return TEST_SUCCESS;
5779 }
5780
5781 struct multi_session_params {
5782         struct crypto_unittest_params ut_params;
5783         uint8_t *cipher_key;
5784         uint8_t *hmac_key;
5785         const uint8_t *cipher;
5786         const uint8_t *digest;
5787         uint8_t *iv;
5788 };
5789
5790 #define MB_SESSION_NUMBER 3
5791
5792 static int
5793 test_multi_session_random_usage(void)
5794 {
5795         struct crypto_testsuite_params *ts_params = &testsuite_params;
5796         struct rte_cryptodev_info dev_info;
5797         struct rte_cryptodev_sym_session **sessions;
5798         uint32_t i, j;
5799         struct multi_session_params ut_paramz[] = {
5800
5801                 {
5802                         .cipher_key = ms_aes_cbc_key0,
5803                         .hmac_key = ms_hmac_key0,
5804                         .cipher = ms_aes_cbc_cipher0,
5805                         .digest = ms_hmac_digest0,
5806                         .iv = ms_aes_cbc_iv0
5807                 },
5808                 {
5809                         .cipher_key = ms_aes_cbc_key1,
5810                         .hmac_key = ms_hmac_key1,
5811                         .cipher = ms_aes_cbc_cipher1,
5812                         .digest = ms_hmac_digest1,
5813                         .iv = ms_aes_cbc_iv1
5814                 },
5815                 {
5816                         .cipher_key = ms_aes_cbc_key2,
5817                         .hmac_key = ms_hmac_key2,
5818                         .cipher = ms_aes_cbc_cipher2,
5819                         .digest = ms_hmac_digest2,
5820                         .iv = ms_aes_cbc_iv2
5821                 },
5822
5823         };
5824
5825         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5826
5827         sessions = rte_malloc(NULL,
5828                         (sizeof(struct rte_cryptodev_sym_session *)
5829                                         * dev_info.sym.max_nb_sessions) + 1, 0);
5830
5831         for (i = 0; i < MB_SESSION_NUMBER; i++) {
5832                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
5833                                 sizeof(struct crypto_unittest_params));
5834
5835                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
5836                                 &ut_paramz[i].ut_params,
5837                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
5838
5839                 /* Create multiple crypto sessions*/
5840                 sessions[i] = rte_cryptodev_sym_session_create(
5841                                 ts_params->valid_devs[0],
5842                                 &ut_paramz[i].ut_params.auth_xform);
5843
5844                 TEST_ASSERT_NOT_NULL(sessions[i],
5845                                 "Session creation failed at session number %u",
5846                                 i);
5847
5848         }
5849
5850         srand(time(NULL));
5851         for (i = 0; i < 40000; i++) {
5852
5853                 j = rand() % MB_SESSION_NUMBER;
5854
5855                 TEST_ASSERT_SUCCESS(
5856                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
5857                                         sessions[j],
5858                                         &ut_paramz[j].ut_params,
5859                                         ts_params, ut_paramz[j].cipher,
5860                                         ut_paramz[j].digest,
5861                                         ut_paramz[j].iv),
5862                         "Failed to perform decrypt on request number %u.", i);
5863
5864                 if (ut_paramz[j].ut_params.op)
5865                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
5866
5867                 /*
5868                  * free mbuf - both obuf and ibuf are usually the same,
5869                  * so check if they point at the same address is necessary,
5870                  * to avoid freeing the mbuf twice.
5871                  */
5872                 if (ut_paramz[j].ut_params.obuf) {
5873                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
5874                         if (ut_paramz[j].ut_params.ibuf
5875                                         == ut_paramz[j].ut_params.obuf)
5876                                 ut_paramz[j].ut_params.ibuf = 0;
5877                         ut_paramz[j].ut_params.obuf = 0;
5878                 }
5879                 if (ut_paramz[j].ut_params.ibuf) {
5880                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
5881                         ut_paramz[j].ut_params.ibuf = 0;
5882                 }
5883         }
5884
5885         for (i = 0; i < MB_SESSION_NUMBER; i++)
5886                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5887                                 sessions[i]);
5888
5889         rte_free(sessions);
5890
5891         return TEST_SUCCESS;
5892 }
5893
5894 static int
5895 test_null_cipher_only_operation(void)
5896 {
5897         struct crypto_testsuite_params *ts_params = &testsuite_params;
5898         struct crypto_unittest_params *ut_params = &unittest_params;
5899
5900         /* Generate test mbuf data and space for digest */
5901         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5902                         catch_22_quote, QUOTE_512_BYTES, 0);
5903
5904         /* Setup Cipher Parameters */
5905         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5906         ut_params->cipher_xform.next = NULL;
5907
5908         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5909         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5910
5911         /* Create Crypto session*/
5912         ut_params->sess = rte_cryptodev_sym_session_create(
5913                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5914         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5915
5916         /* Generate Crypto op data structure */
5917         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5918                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5919         TEST_ASSERT_NOT_NULL(ut_params->op,
5920                         "Failed to allocate symmetric crypto operation struct");
5921
5922         /* Set crypto operation data parameters */
5923         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5924
5925         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5926
5927         /* set crypto operation source mbuf */
5928         sym_op->m_src = ut_params->ibuf;
5929
5930         sym_op->cipher.data.offset = 0;
5931         sym_op->cipher.data.length = QUOTE_512_BYTES;
5932
5933         /* Process crypto operation */
5934         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5935                         ut_params->op);
5936         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5937
5938         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5939                         "crypto operation processing failed");
5940
5941         /* Validate obuf */
5942         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5943                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5944                         catch_22_quote,
5945                         QUOTE_512_BYTES,
5946                         "Ciphertext data not as expected");
5947
5948         return TEST_SUCCESS;
5949 }
5950
5951 static int
5952 test_null_auth_only_operation(void)
5953 {
5954         struct crypto_testsuite_params *ts_params = &testsuite_params;
5955         struct crypto_unittest_params *ut_params = &unittest_params;
5956
5957         /* Generate test mbuf data and space for digest */
5958         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5959                         catch_22_quote, QUOTE_512_BYTES, 0);
5960
5961         /* Setup HMAC Parameters */
5962         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5963         ut_params->auth_xform.next = NULL;
5964
5965         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5966         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5967
5968         /* Create Crypto session*/
5969         ut_params->sess = rte_cryptodev_sym_session_create(
5970                         ts_params->valid_devs[0], &ut_params->auth_xform);
5971         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5972
5973         /* Generate Crypto op data structure */
5974         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5975                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5976         TEST_ASSERT_NOT_NULL(ut_params->op,
5977                         "Failed to allocate symmetric crypto operation struct");
5978
5979         /* Set crypto operation data parameters */
5980         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5981
5982         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5983
5984         sym_op->m_src = ut_params->ibuf;
5985
5986         sym_op->auth.data.offset = 0;
5987         sym_op->auth.data.length = QUOTE_512_BYTES;
5988
5989         /* Process crypto operation */
5990         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5991                         ut_params->op);
5992         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5993
5994         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5995                         "crypto operation processing failed");
5996
5997         return TEST_SUCCESS;
5998 }
5999
6000 static int
6001 test_null_cipher_auth_operation(void)
6002 {
6003         struct crypto_testsuite_params *ts_params = &testsuite_params;
6004         struct crypto_unittest_params *ut_params = &unittest_params;
6005
6006         /* Generate test mbuf data and space for digest */
6007         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6008                         catch_22_quote, QUOTE_512_BYTES, 0);
6009
6010         /* Setup Cipher Parameters */
6011         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6012         ut_params->cipher_xform.next = &ut_params->auth_xform;
6013
6014         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6015         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6016
6017         /* Setup HMAC Parameters */
6018         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6019         ut_params->auth_xform.next = NULL;
6020
6021         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6022         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6023
6024         /* Create Crypto session*/
6025         ut_params->sess = rte_cryptodev_sym_session_create(
6026                         ts_params->valid_devs[0], &ut_params->cipher_xform);
6027         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6028
6029         /* Generate Crypto op data structure */
6030         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6031                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6032         TEST_ASSERT_NOT_NULL(ut_params->op,
6033                         "Failed to allocate symmetric crypto operation struct");
6034
6035         /* Set crypto operation data parameters */
6036         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6037
6038         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6039
6040         sym_op->m_src = ut_params->ibuf;
6041
6042         sym_op->cipher.data.offset = 0;
6043         sym_op->cipher.data.length = QUOTE_512_BYTES;
6044
6045         sym_op->auth.data.offset = 0;
6046         sym_op->auth.data.length = QUOTE_512_BYTES;
6047
6048         /* Process crypto operation */
6049         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6050                         ut_params->op);
6051         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6052
6053         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6054                         "crypto operation processing failed");
6055
6056         /* Validate obuf */
6057         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6058                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6059                         catch_22_quote,
6060                         QUOTE_512_BYTES,
6061                         "Ciphertext data not as expected");
6062
6063         return TEST_SUCCESS;
6064 }
6065
6066 static int
6067 test_null_auth_cipher_operation(void)
6068 {
6069         struct crypto_testsuite_params *ts_params = &testsuite_params;
6070         struct crypto_unittest_params *ut_params = &unittest_params;
6071
6072         /* Generate test mbuf data and space for digest */
6073         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6074                         catch_22_quote, QUOTE_512_BYTES, 0);
6075
6076         /* Setup Cipher Parameters */
6077         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6078         ut_params->cipher_xform.next = NULL;
6079
6080         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6081         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6082
6083         /* Setup HMAC Parameters */
6084         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6085         ut_params->auth_xform.next = &ut_params->cipher_xform;
6086
6087         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6088         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6089
6090         /* Create Crypto session*/
6091         ut_params->sess = rte_cryptodev_sym_session_create(
6092                         ts_params->valid_devs[0], &ut_params->cipher_xform);
6093         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6094
6095         /* Generate Crypto op data structure */
6096         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6097                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6098         TEST_ASSERT_NOT_NULL(ut_params->op,
6099                         "Failed to allocate symmetric crypto operation struct");
6100
6101         /* Set crypto operation data parameters */
6102         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6103
6104         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6105
6106         sym_op->m_src = ut_params->ibuf;
6107
6108         sym_op->cipher.data.offset = 0;
6109         sym_op->cipher.data.length = QUOTE_512_BYTES;
6110
6111         sym_op->auth.data.offset = 0;
6112         sym_op->auth.data.length = QUOTE_512_BYTES;
6113
6114         /* Process crypto operation */
6115         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6116                         ut_params->op);
6117         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6118
6119         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6120                         "crypto operation processing failed");
6121
6122         /* Validate obuf */
6123         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6124                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6125                         catch_22_quote,
6126                         QUOTE_512_BYTES,
6127                         "Ciphertext data not as expected");
6128
6129         return TEST_SUCCESS;
6130 }
6131
6132
6133 static int
6134 test_null_invalid_operation(void)
6135 {
6136         struct crypto_testsuite_params *ts_params = &testsuite_params;
6137         struct crypto_unittest_params *ut_params = &unittest_params;
6138
6139         /* Setup Cipher Parameters */
6140         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6141         ut_params->cipher_xform.next = NULL;
6142
6143         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
6144         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6145
6146         /* Create Crypto session*/
6147         ut_params->sess = rte_cryptodev_sym_session_create(
6148                         ts_params->valid_devs[0], &ut_params->cipher_xform);
6149         TEST_ASSERT_NULL(ut_params->sess,
6150                         "Session creation succeeded unexpectedly");
6151
6152
6153         /* Setup HMAC Parameters */
6154         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6155         ut_params->auth_xform.next = NULL;
6156
6157         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
6158         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6159
6160         /* Create Crypto session*/
6161         ut_params->sess = rte_cryptodev_sym_session_create(
6162                         ts_params->valid_devs[0], &ut_params->auth_xform);
6163         TEST_ASSERT_NULL(ut_params->sess,
6164                         "Session creation succeeded unexpectedly");
6165
6166         return TEST_SUCCESS;
6167 }
6168
6169
6170 #define NULL_BURST_LENGTH (32)
6171
6172 static int
6173 test_null_burst_operation(void)
6174 {
6175         struct crypto_testsuite_params *ts_params = &testsuite_params;
6176         struct crypto_unittest_params *ut_params = &unittest_params;
6177
6178         unsigned i, burst_len = NULL_BURST_LENGTH;
6179
6180         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
6181         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
6182
6183         /* Setup Cipher Parameters */
6184         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6185         ut_params->cipher_xform.next = &ut_params->auth_xform;
6186
6187         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6188         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6189
6190         /* Setup HMAC Parameters */
6191         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6192         ut_params->auth_xform.next = NULL;
6193
6194         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6195         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6196
6197         /* Create Crypto session*/
6198         ut_params->sess = rte_cryptodev_sym_session_create(
6199                         ts_params->valid_devs[0], &ut_params->cipher_xform);
6200         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6201
6202         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
6203                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
6204                         burst_len, "failed to generate burst of crypto ops");
6205
6206         /* Generate an operation for each mbuf in burst */
6207         for (i = 0; i < burst_len; i++) {
6208                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6209
6210                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
6211
6212                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
6213                                 sizeof(unsigned));
6214                 *data = i;
6215
6216                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
6217
6218                 burst[i]->sym->m_src = m;
6219         }
6220
6221         /* Process crypto operation */
6222         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
6223                         0, burst, burst_len),
6224                         burst_len,
6225                         "Error enqueuing burst");
6226
6227         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
6228                         0, burst_dequeued, burst_len),
6229                         burst_len,
6230                         "Error dequeuing burst");
6231
6232
6233         for (i = 0; i < burst_len; i++) {
6234                 TEST_ASSERT_EQUAL(
6235                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
6236                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
6237                                         uint32_t *),
6238                         "data not as expected");
6239
6240                 rte_pktmbuf_free(burst[i]->sym->m_src);
6241                 rte_crypto_op_free(burst[i]);
6242         }
6243
6244         return TEST_SUCCESS;
6245 }
6246
6247 static void
6248 generate_gmac_large_plaintext(uint8_t *data)
6249 {
6250         uint16_t i;
6251
6252         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
6253                 memcpy(&data[i], &data[0], 32);
6254 }
6255
6256 static int
6257 create_gmac_operation(enum rte_crypto_auth_operation op,
6258                 const struct gmac_test_data *tdata)
6259 {
6260         struct crypto_testsuite_params *ts_params = &testsuite_params;
6261         struct crypto_unittest_params *ut_params = &unittest_params;
6262         struct rte_crypto_sym_op *sym_op;
6263
6264         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6265
6266         /* Generate Crypto op data structure */
6267         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6268                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6269         TEST_ASSERT_NOT_NULL(ut_params->op,
6270                         "Failed to allocate symmetric crypto operation struct");
6271
6272         sym_op = ut_params->op->sym;
6273
6274         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6275                         ut_params->ibuf, tdata->gmac_tag.len);
6276         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6277                         "no room to append digest");
6278
6279         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6280                         ut_params->ibuf, plaintext_pad_len);
6281
6282         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
6283                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
6284                                 tdata->gmac_tag.len);
6285                 TEST_HEXDUMP(stdout, "digest:",
6286                                 sym_op->auth.digest.data,
6287                                 tdata->gmac_tag.len);
6288         }
6289
6290         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6291                         uint8_t *, IV_OFFSET);
6292
6293         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
6294
6295         TEST_HEXDUMP(stdout, "iv:", iv_ptr, tdata->iv.len);
6296
6297         sym_op->cipher.data.length = 0;
6298         sym_op->cipher.data.offset = 0;
6299
6300         sym_op->auth.data.offset = 0;
6301         sym_op->auth.data.length = tdata->plaintext.len;
6302
6303         return 0;
6304 }
6305
6306 static int create_gmac_session(uint8_t dev_id,
6307                 const struct gmac_test_data *tdata,
6308                 enum rte_crypto_auth_operation auth_op)
6309 {
6310         uint8_t auth_key[tdata->key.len];
6311
6312         struct crypto_unittest_params *ut_params = &unittest_params;
6313
6314         memcpy(auth_key, tdata->key.data, tdata->key.len);
6315
6316         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6317         ut_params->auth_xform.next = NULL;
6318
6319         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
6320         ut_params->auth_xform.auth.op = auth_op;
6321         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
6322         ut_params->auth_xform.auth.key.length = tdata->key.len;
6323         ut_params->auth_xform.auth.key.data = auth_key;
6324         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
6325         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
6326
6327
6328         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6329                         &ut_params->auth_xform);
6330
6331         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6332
6333         return 0;
6334 }
6335
6336 static int
6337 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
6338 {
6339         struct crypto_testsuite_params *ts_params = &testsuite_params;
6340         struct crypto_unittest_params *ut_params = &unittest_params;
6341
6342         int retval;
6343
6344         uint8_t *auth_tag, *plaintext;
6345         uint16_t plaintext_pad_len;
6346
6347         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6348                               "No GMAC length in the source data");
6349
6350         retval = create_gmac_session(ts_params->valid_devs[0],
6351                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
6352
6353         if (retval < 0)
6354                 return retval;
6355
6356         if (tdata->plaintext.len > MBUF_SIZE)
6357                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6358         else
6359                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6360         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6361                         "Failed to allocate input buffer in mempool");
6362
6363         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6364                         rte_pktmbuf_tailroom(ut_params->ibuf));
6365
6366         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6367         /*
6368          * Runtime generate the large plain text instead of use hard code
6369          * plain text vector. It is done to avoid create huge source file
6370          * with the test vector.
6371          */
6372         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
6373                 generate_gmac_large_plaintext(tdata->plaintext.data);
6374
6375         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6376                                 plaintext_pad_len);
6377         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6378
6379         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6380         TEST_HEXDUMP(stdout, "plaintext:", plaintext,
6381                         tdata->plaintext.len);
6382
6383         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
6384                         tdata);
6385
6386         if (retval < 0)
6387                 return retval;
6388
6389         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6390
6391         ut_params->op->sym->m_src = ut_params->ibuf;
6392
6393         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6394                         ut_params->op), "failed to process sym crypto op");
6395
6396         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6397                         "crypto op processing failed");
6398
6399         if (ut_params->op->sym->m_dst) {
6400                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6401                                 uint8_t *, plaintext_pad_len);
6402         } else {
6403                 auth_tag = plaintext + plaintext_pad_len;
6404         }
6405
6406         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
6407
6408         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6409                         auth_tag,
6410                         tdata->gmac_tag.data,
6411                         tdata->gmac_tag.len,
6412                         "GMAC Generated auth tag not as expected");
6413
6414         return 0;
6415 }
6416
6417 static int
6418 test_AES_GMAC_authentication_test_case_1(void)
6419 {
6420         return test_AES_GMAC_authentication(&gmac_test_case_1);
6421 }
6422
6423 static int
6424 test_AES_GMAC_authentication_test_case_2(void)
6425 {
6426         return test_AES_GMAC_authentication(&gmac_test_case_2);
6427 }
6428
6429 static int
6430 test_AES_GMAC_authentication_test_case_3(void)
6431 {
6432         return test_AES_GMAC_authentication(&gmac_test_case_3);
6433 }
6434
6435 static int
6436 test_AES_GMAC_authentication_test_case_4(void)
6437 {
6438         return test_AES_GMAC_authentication(&gmac_test_case_4);
6439 }
6440
6441 static int
6442 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
6443 {
6444         struct crypto_testsuite_params *ts_params = &testsuite_params;
6445         struct crypto_unittest_params *ut_params = &unittest_params;
6446         int retval;
6447         uint32_t plaintext_pad_len;
6448         uint8_t *plaintext;
6449
6450         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6451                               "No GMAC length in the source data");
6452
6453         retval = create_gmac_session(ts_params->valid_devs[0],
6454                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
6455
6456         if (retval < 0)
6457                 return retval;
6458
6459         if (tdata->plaintext.len > MBUF_SIZE)
6460                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6461         else
6462                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6463         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6464                         "Failed to allocate input buffer in mempool");
6465
6466         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6467                         rte_pktmbuf_tailroom(ut_params->ibuf));
6468
6469         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6470
6471         /*
6472          * Runtime generate the large plain text instead of use hard code
6473          * plain text vector. It is done to avoid create huge source file
6474          * with the test vector.
6475          */
6476         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
6477                 generate_gmac_large_plaintext(tdata->plaintext.data);
6478
6479         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6480                                 plaintext_pad_len);
6481         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6482
6483         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6484         TEST_HEXDUMP(stdout, "plaintext:", plaintext,
6485                         tdata->plaintext.len);
6486
6487         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
6488                         tdata);
6489
6490         if (retval < 0)
6491                 return retval;
6492
6493         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6494
6495         ut_params->op->sym->m_src = ut_params->ibuf;
6496
6497         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6498                         ut_params->op), "failed to process sym crypto op");
6499
6500         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6501                         "crypto op processing failed");
6502
6503         return 0;
6504
6505 }
6506
6507 static int
6508 test_AES_GMAC_authentication_verify_test_case_1(void)
6509 {
6510         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
6511 }
6512
6513 static int
6514 test_AES_GMAC_authentication_verify_test_case_2(void)
6515 {
6516         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
6517 }
6518
6519 static int
6520 test_AES_GMAC_authentication_verify_test_case_3(void)
6521 {
6522         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
6523 }
6524
6525 static int
6526 test_AES_GMAC_authentication_verify_test_case_4(void)
6527 {
6528         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
6529 }
6530
6531 struct test_crypto_vector {
6532         enum rte_crypto_cipher_algorithm crypto_algo;
6533
6534         struct {
6535                 uint8_t data[64];
6536                 unsigned int len;
6537         } cipher_key;
6538
6539         struct {
6540                 uint8_t data[64];
6541                 unsigned int len;
6542         } iv;
6543
6544         struct {
6545                 const uint8_t *data;
6546                 unsigned int len;
6547         } plaintext;
6548
6549         struct {
6550                 const uint8_t *data;
6551                 unsigned int len;
6552         } ciphertext;
6553
6554         enum rte_crypto_auth_algorithm auth_algo;
6555
6556         struct {
6557                 uint8_t data[128];
6558                 unsigned int len;
6559         } auth_key;
6560
6561         struct {
6562                 const uint8_t *data;
6563                 unsigned int len;
6564         } aad;
6565
6566         struct {
6567                 uint8_t data[128];
6568                 unsigned int len;
6569         } digest;
6570 };
6571
6572 static const struct test_crypto_vector
6573 hmac_sha1_test_crypto_vector = {
6574         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6575         .plaintext = {
6576                 .data = plaintext_hash,
6577                 .len = 512
6578         },
6579         .auth_key = {
6580                 .data = {
6581                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6582                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6583                         0xDE, 0xF4, 0xDE, 0xAD
6584                 },
6585                 .len = 20
6586         },
6587         .digest = {
6588                 .data = {
6589                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
6590                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
6591                         0x3F, 0x91, 0x64, 0x59
6592                 },
6593                 .len = 20
6594         }
6595 };
6596
6597 static const struct test_crypto_vector
6598 aes128_gmac_test_vector = {
6599         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
6600         .plaintext = {
6601                 .data = plaintext_hash,
6602                 .len = 512
6603         },
6604         .iv = {
6605                 .data = {
6606                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6607                         0x08, 0x09, 0x0A, 0x0B
6608                 },
6609                 .len = 12
6610         },
6611         .auth_key = {
6612                 .data = {
6613                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6614                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
6615                 },
6616                 .len = 16
6617         },
6618         .digest = {
6619                 .data = {
6620                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
6621                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
6622                 },
6623                 .len = 16
6624         }
6625 };
6626
6627 static const struct test_crypto_vector
6628 aes128cbc_hmac_sha1_test_vector = {
6629         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
6630         .cipher_key = {
6631                 .data = {
6632                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
6633                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
6634                 },
6635                 .len = 16
6636         },
6637         .iv = {
6638                 .data = {
6639                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6640                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
6641                 },
6642                 .len = 16
6643         },
6644         .plaintext = {
6645                 .data = plaintext_hash,
6646                 .len = 512
6647         },
6648         .ciphertext = {
6649                 .data = ciphertext512_aes128cbc,
6650                 .len = 512
6651         },
6652         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6653         .auth_key = {
6654                 .data = {
6655                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6656                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6657                         0xDE, 0xF4, 0xDE, 0xAD
6658                 },
6659                 .len = 20
6660         },
6661         .digest = {
6662                 .data = {
6663                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
6664                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6665                         0x18, 0x8C, 0x1D, 0x32
6666                 },
6667                 .len = 20
6668         }
6669 };
6670
6671 static void
6672 data_corruption(uint8_t *data)
6673 {
6674         data[0] += 1;
6675 }
6676
6677 static void
6678 tag_corruption(uint8_t *data, unsigned int tag_offset)
6679 {
6680         data[tag_offset] += 1;
6681 }
6682
6683 static int
6684 create_auth_session(struct crypto_unittest_params *ut_params,
6685                 uint8_t dev_id,
6686                 const struct test_crypto_vector *reference,
6687                 enum rte_crypto_auth_operation auth_op)
6688 {
6689         uint8_t auth_key[reference->auth_key.len + 1];
6690
6691         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6692
6693         /* Setup Authentication Parameters */
6694         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6695         ut_params->auth_xform.auth.op = auth_op;
6696         ut_params->auth_xform.next = NULL;
6697         ut_params->auth_xform.auth.algo = reference->auth_algo;
6698         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6699         ut_params->auth_xform.auth.key.data = auth_key;
6700         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6701
6702         /* Create Crypto session*/
6703         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6704                                 &ut_params->auth_xform);
6705
6706         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6707
6708         return 0;
6709 }
6710
6711 static int
6712 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
6713                 uint8_t dev_id,
6714                 const struct test_crypto_vector *reference,
6715                 enum rte_crypto_auth_operation auth_op,
6716                 enum rte_crypto_cipher_operation cipher_op)
6717 {
6718         uint8_t cipher_key[reference->cipher_key.len + 1];
6719         uint8_t auth_key[reference->auth_key.len + 1];
6720
6721         memcpy(cipher_key, reference->cipher_key.data,
6722                         reference->cipher_key.len);
6723         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6724
6725         /* Setup Authentication Parameters */
6726         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6727         ut_params->auth_xform.auth.op = auth_op;
6728         ut_params->auth_xform.auth.algo = reference->auth_algo;
6729         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6730         ut_params->auth_xform.auth.key.data = auth_key;
6731         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6732
6733         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
6734                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
6735                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
6736         } else {
6737                 ut_params->auth_xform.next = &ut_params->cipher_xform;
6738
6739                 /* Setup Cipher Parameters */
6740                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6741                 ut_params->cipher_xform.next = NULL;
6742                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
6743                 ut_params->cipher_xform.cipher.op = cipher_op;
6744                 ut_params->cipher_xform.cipher.key.data = cipher_key;
6745                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
6746                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
6747                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
6748         }
6749
6750         /* Create Crypto session*/
6751         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6752                                 &ut_params->auth_xform);
6753
6754         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6755
6756         return 0;
6757 }
6758
6759 static int
6760 create_auth_operation(struct crypto_testsuite_params *ts_params,
6761                 struct crypto_unittest_params *ut_params,
6762                 const struct test_crypto_vector *reference,
6763                 unsigned int auth_generate)
6764 {
6765         /* Generate Crypto op data structure */
6766         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6767                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6768         TEST_ASSERT_NOT_NULL(ut_params->op,
6769                         "Failed to allocate pktmbuf offload");
6770
6771         /* Set crypto operation data parameters */
6772         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6773
6774         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6775
6776         /* set crypto operation source mbuf */
6777         sym_op->m_src = ut_params->ibuf;
6778
6779         /* digest */
6780         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6781                         ut_params->ibuf, reference->digest.len);
6782
6783         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6784                         "no room to append auth tag");
6785
6786         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6787                         ut_params->ibuf, reference->plaintext.len);
6788
6789         if (auth_generate)
6790                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6791         else
6792                 memcpy(sym_op->auth.digest.data,
6793                                 reference->digest.data,
6794                                 reference->digest.len);
6795
6796         TEST_HEXDUMP(stdout, "digest:",
6797                         sym_op->auth.digest.data,
6798                         reference->digest.len);
6799
6800         sym_op->auth.data.length = reference->plaintext.len;
6801         sym_op->auth.data.offset = 0;
6802
6803         return 0;
6804 }
6805
6806 static int
6807 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
6808                 struct crypto_unittest_params *ut_params,
6809                 const struct test_crypto_vector *reference,
6810                 unsigned int auth_generate)
6811 {
6812         /* Generate Crypto op data structure */
6813         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6814                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6815         TEST_ASSERT_NOT_NULL(ut_params->op,
6816                         "Failed to allocate pktmbuf offload");
6817
6818         /* Set crypto operation data parameters */
6819         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6820
6821         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6822
6823         /* set crypto operation source mbuf */
6824         sym_op->m_src = ut_params->ibuf;
6825
6826         /* digest */
6827         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6828                         ut_params->ibuf, reference->digest.len);
6829
6830         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6831                         "no room to append auth tag");
6832
6833         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6834                         ut_params->ibuf, reference->ciphertext.len);
6835
6836         if (auth_generate)
6837                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6838         else
6839                 memcpy(sym_op->auth.digest.data,
6840                                 reference->digest.data,
6841                                 reference->digest.len);
6842
6843         TEST_HEXDUMP(stdout, "digest:",
6844                         sym_op->auth.digest.data,
6845                         reference->digest.len);
6846
6847         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
6848                         reference->iv.data, reference->iv.len);
6849
6850         sym_op->cipher.data.length = 0;
6851         sym_op->cipher.data.offset = 0;
6852
6853         sym_op->auth.data.length = reference->plaintext.len;
6854         sym_op->auth.data.offset = 0;
6855
6856         return 0;
6857 }
6858
6859 static int
6860 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
6861                 struct crypto_unittest_params *ut_params,
6862                 const struct test_crypto_vector *reference,
6863                 unsigned int auth_generate)
6864 {
6865         /* Generate Crypto op data structure */
6866         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6867                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6868         TEST_ASSERT_NOT_NULL(ut_params->op,
6869                         "Failed to allocate pktmbuf offload");
6870
6871         /* Set crypto operation data parameters */
6872         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6873
6874         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6875
6876         /* set crypto operation source mbuf */
6877         sym_op->m_src = ut_params->ibuf;
6878
6879         /* digest */
6880         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6881                         ut_params->ibuf, reference->digest.len);
6882
6883         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6884                         "no room to append auth tag");
6885
6886         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6887                         ut_params->ibuf, reference->ciphertext.len);
6888
6889         if (auth_generate)
6890                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6891         else
6892                 memcpy(sym_op->auth.digest.data,
6893                                 reference->digest.data,
6894                                 reference->digest.len);
6895
6896         TEST_HEXDUMP(stdout, "digest:",
6897                         sym_op->auth.digest.data,
6898                         reference->digest.len);
6899
6900         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
6901                         reference->iv.data, reference->iv.len);
6902
6903         sym_op->cipher.data.length = reference->ciphertext.len;
6904         sym_op->cipher.data.offset = 0;
6905
6906         sym_op->auth.data.length = reference->ciphertext.len;
6907         sym_op->auth.data.offset = 0;
6908
6909         return 0;
6910 }
6911
6912 static int
6913 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6914                 struct crypto_unittest_params *ut_params,
6915                 const struct test_crypto_vector *reference)
6916 {
6917         return create_auth_operation(ts_params, ut_params, reference, 0);
6918 }
6919
6920 static int
6921 create_auth_verify_GMAC_operation(
6922                 struct crypto_testsuite_params *ts_params,
6923                 struct crypto_unittest_params *ut_params,
6924                 const struct test_crypto_vector *reference)
6925 {
6926         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
6927 }
6928
6929 static int
6930 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6931                 struct crypto_unittest_params *ut_params,
6932                 const struct test_crypto_vector *reference)
6933 {
6934         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
6935 }
6936
6937 static int
6938 test_authentication_verify_fail_when_data_corruption(
6939                 struct crypto_testsuite_params *ts_params,
6940                 struct crypto_unittest_params *ut_params,
6941                 const struct test_crypto_vector *reference,
6942                 unsigned int data_corrupted)
6943 {
6944         int retval;
6945
6946         uint8_t *plaintext;
6947
6948         /* Create session */
6949         retval = create_auth_session(ut_params,
6950                         ts_params->valid_devs[0],
6951                         reference,
6952                         RTE_CRYPTO_AUTH_OP_VERIFY);
6953         if (retval < 0)
6954                 return retval;
6955
6956         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6957         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6958                         "Failed to allocate input buffer in mempool");
6959
6960         /* clear mbuf payload */
6961         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6962                         rte_pktmbuf_tailroom(ut_params->ibuf));
6963
6964         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6965                         reference->plaintext.len);
6966         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6967         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
6968
6969         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
6970
6971         /* Create operation */
6972         retval = create_auth_verify_operation(ts_params, ut_params, reference);
6973
6974         if (retval < 0)
6975                 return retval;
6976
6977         if (data_corrupted)
6978                 data_corruption(plaintext);
6979         else
6980                 tag_corruption(plaintext, reference->plaintext.len);
6981
6982         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6983                         ut_params->op);
6984         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6985         TEST_ASSERT_EQUAL(ut_params->op->status,
6986                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6987                         "authentication not failed");
6988
6989         ut_params->obuf = ut_params->op->sym->m_src;
6990         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6991
6992         return 0;
6993 }
6994
6995 static int
6996 test_authentication_verify_GMAC_fail_when_corruption(
6997                 struct crypto_testsuite_params *ts_params,
6998                 struct crypto_unittest_params *ut_params,
6999                 const struct test_crypto_vector *reference,
7000                 unsigned int data_corrupted)
7001 {
7002         int retval;
7003         uint8_t *plaintext;
7004
7005         /* Create session */
7006         retval = create_auth_cipher_session(ut_params,
7007                         ts_params->valid_devs[0],
7008                         reference,
7009                         RTE_CRYPTO_AUTH_OP_VERIFY,
7010                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7011         if (retval < 0)
7012                 return retval;
7013
7014         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7015         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7016                         "Failed to allocate input buffer in mempool");
7017
7018         /* clear mbuf payload */
7019         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7020                         rte_pktmbuf_tailroom(ut_params->ibuf));
7021
7022         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7023                         reference->plaintext.len);
7024         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7025         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7026
7027         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
7028
7029         /* Create operation */
7030         retval = create_auth_verify_GMAC_operation(ts_params,
7031                         ut_params,
7032                         reference);
7033
7034         if (retval < 0)
7035                 return retval;
7036
7037         if (data_corrupted)
7038                 data_corruption(plaintext);
7039         else
7040                 tag_corruption(plaintext, reference->aad.len);
7041
7042         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7043                         ut_params->op);
7044         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7045         TEST_ASSERT_EQUAL(ut_params->op->status,
7046                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7047                         "authentication not failed");
7048
7049         ut_params->obuf = ut_params->op->sym->m_src;
7050         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7051
7052         return 0;
7053 }
7054
7055 static int
7056 test_authenticated_decryption_fail_when_corruption(
7057                 struct crypto_testsuite_params *ts_params,
7058                 struct crypto_unittest_params *ut_params,
7059                 const struct test_crypto_vector *reference,
7060                 unsigned int data_corrupted)
7061 {
7062         int retval;
7063
7064         uint8_t *ciphertext;
7065
7066         /* Create session */
7067         retval = create_auth_cipher_session(ut_params,
7068                         ts_params->valid_devs[0],
7069                         reference,
7070                         RTE_CRYPTO_AUTH_OP_VERIFY,
7071                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
7072         if (retval < 0)
7073                 return retval;
7074
7075         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7076         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7077                         "Failed to allocate input buffer in mempool");
7078
7079         /* clear mbuf payload */
7080         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7081                         rte_pktmbuf_tailroom(ut_params->ibuf));
7082
7083         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7084                         reference->ciphertext.len);
7085         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
7086         memcpy(ciphertext, reference->ciphertext.data,
7087                         reference->ciphertext.len);
7088
7089         /* Create operation */
7090         retval = create_cipher_auth_verify_operation(ts_params,
7091                         ut_params,
7092                         reference);
7093
7094         if (retval < 0)
7095                 return retval;
7096
7097         if (data_corrupted)
7098                 data_corruption(ciphertext);
7099         else
7100                 tag_corruption(ciphertext, reference->ciphertext.len);
7101
7102         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7103                         ut_params->op);
7104
7105         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7106         TEST_ASSERT_EQUAL(ut_params->op->status,
7107                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7108                         "authentication not failed");
7109
7110         ut_params->obuf = ut_params->op->sym->m_src;
7111         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7112
7113         return 0;
7114 }
7115
7116 static int
7117 create_gcm_operation_SGL(enum rte_crypto_aead_operation op,
7118                 const struct gcm_test_data *tdata,
7119                 void *digest_mem, uint64_t digest_phys)
7120 {
7121         struct crypto_testsuite_params *ts_params = &testsuite_params;
7122         struct crypto_unittest_params *ut_params = &unittest_params;
7123
7124         const unsigned int auth_tag_len = tdata->auth_tag.len;
7125         const unsigned int iv_len = tdata->iv.len;
7126         const unsigned int aad_len = tdata->aad.len;
7127
7128         /* Generate Crypto op data structure */
7129         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7130                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7131         TEST_ASSERT_NOT_NULL(ut_params->op,
7132                 "Failed to allocate symmetric crypto operation struct");
7133
7134         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7135
7136         sym_op->aead.digest.data = digest_mem;
7137
7138         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7139                         "no room to append digest");
7140
7141         sym_op->aead.digest.phys_addr = digest_phys;
7142
7143         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
7144                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7145                                 auth_tag_len);
7146                 TEST_HEXDUMP(stdout, "digest:",
7147                                 sym_op->aead.digest.data,
7148                                 auth_tag_len);
7149         }
7150
7151         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7152                         uint8_t *, IV_OFFSET);
7153
7154         rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
7155
7156         sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
7157                         ut_params->ibuf, aad_len);
7158         TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7159                         "no room to prepend aad");
7160         sym_op->aead.aad.phys_addr = rte_pktmbuf_mtophys(
7161                         ut_params->ibuf);
7162
7163         memset(sym_op->aead.aad.data, 0, aad_len);
7164         rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
7165
7166         TEST_HEXDUMP(stdout, "iv:", iv_ptr, iv_len);
7167         TEST_HEXDUMP(stdout, "aad:",
7168                         sym_op->aead.aad.data, aad_len);
7169
7170         sym_op->aead.data.length = tdata->plaintext.len;
7171         sym_op->aead.data.offset = aad_len;
7172
7173         return 0;
7174 }
7175
7176 #define SGL_MAX_NO      16
7177
7178 static int
7179 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
7180                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
7181 {
7182         struct crypto_testsuite_params *ts_params = &testsuite_params;
7183         struct crypto_unittest_params *ut_params = &unittest_params;
7184         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
7185         int retval;
7186         int to_trn = 0;
7187         int to_trn_tbl[SGL_MAX_NO];
7188         int segs = 1;
7189         unsigned int trn_data = 0;
7190         uint8_t *plaintext, *ciphertext, *auth_tag;
7191
7192         if (fragsz > tdata->plaintext.len)
7193                 fragsz = tdata->plaintext.len;
7194
7195         uint16_t plaintext_len = fragsz;
7196         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7197
7198         if (fragsz_oop > tdata->plaintext.len)
7199                 frag_size_oop = tdata->plaintext.len;
7200
7201         int ecx = 0;
7202         void *digest_mem = NULL;
7203
7204         uint32_t prepend_len = tdata->aad.len;
7205
7206         if (tdata->plaintext.len % fragsz != 0) {
7207                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
7208                         return 1;
7209         }       else {
7210                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
7211                         return 1;
7212         }
7213
7214         /*
7215          * For out-op-place we need to alloc another mbuf
7216          */
7217         if (oop) {
7218                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7219                 rte_pktmbuf_append(ut_params->obuf,
7220                                 frag_size_oop + prepend_len);
7221                 buf_oop = ut_params->obuf;
7222         }
7223
7224         /* Create GCM session */
7225         retval = create_gcm_session(ts_params->valid_devs[0],
7226                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7227                         tdata->key.data, tdata->key.len,
7228                         tdata->aad.len, tdata->auth_tag.len,
7229                         tdata->iv.len);
7230         if (retval < 0)
7231                 return retval;
7232
7233         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7234
7235         /* clear mbuf payload */
7236         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7237                         rte_pktmbuf_tailroom(ut_params->ibuf));
7238
7239         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7240                         plaintext_len);
7241
7242         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7243
7244         trn_data += plaintext_len;
7245
7246         buf = ut_params->ibuf;
7247
7248         /*
7249          * Loop until no more fragments
7250          */
7251
7252         while (trn_data < tdata->plaintext.len) {
7253                 ++segs;
7254                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
7255                                 (tdata->plaintext.len - trn_data) : fragsz;
7256
7257                 to_trn_tbl[ecx++] = to_trn;
7258
7259                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7260                 buf = buf->next;
7261
7262                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7263                                 rte_pktmbuf_tailroom(buf));
7264
7265                 /* OOP */
7266                 if (oop && !fragsz_oop) {
7267                         buf_last_oop = buf_oop->next =
7268                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7269                         buf_oop = buf_oop->next;
7270                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7271                                         0, rte_pktmbuf_tailroom(buf_oop));
7272                         rte_pktmbuf_append(buf_oop, to_trn);
7273                 }
7274
7275                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7276                                 to_trn);
7277
7278                 memcpy(plaintext, tdata->plaintext.data + trn_data,
7279                                 to_trn);
7280                 trn_data += to_trn;
7281                 if (trn_data  == tdata->plaintext.len) {
7282                         if (oop) {
7283                                 if (!fragsz_oop)
7284                                         digest_mem = rte_pktmbuf_append(buf_oop,
7285                                                 tdata->auth_tag.len);
7286                         } else
7287                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
7288                                         tdata->auth_tag.len);
7289                 }
7290         }
7291
7292         uint64_t digest_phys = 0;
7293
7294         ut_params->ibuf->nb_segs = segs;
7295
7296         segs = 1;
7297         if (fragsz_oop && oop) {
7298                 to_trn = 0;
7299                 ecx = 0;
7300
7301                 if (frag_size_oop == tdata->plaintext.len) {
7302                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
7303                                 tdata->auth_tag.len);
7304
7305                         digest_phys = rte_pktmbuf_mtophys_offset(
7306                                         ut_params->obuf,
7307                                         tdata->plaintext.len + prepend_len);
7308                 }
7309
7310                 trn_data = frag_size_oop;
7311                 while (trn_data < tdata->plaintext.len) {
7312                         ++segs;
7313                         to_trn =
7314                                 (tdata->plaintext.len - trn_data <
7315                                                 frag_size_oop) ?
7316                                 (tdata->plaintext.len - trn_data) :
7317                                                 frag_size_oop;
7318
7319                         to_trn_tbl[ecx++] = to_trn;
7320
7321                         buf_last_oop = buf_oop->next =
7322                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7323                         buf_oop = buf_oop->next;
7324                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7325                                         0, rte_pktmbuf_tailroom(buf_oop));
7326                         rte_pktmbuf_append(buf_oop, to_trn);
7327
7328                         trn_data += to_trn;
7329
7330                         if (trn_data  == tdata->plaintext.len) {
7331                                 digest_mem = rte_pktmbuf_append(buf_oop,
7332                                         tdata->auth_tag.len);
7333                         }
7334                 }
7335
7336                 ut_params->obuf->nb_segs = segs;
7337         }
7338
7339         /*
7340          * Place digest at the end of the last buffer
7341          */
7342         if (!digest_phys)
7343                 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
7344         if (oop && buf_last_oop)
7345                 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
7346
7347         if (!digest_mem && !oop) {
7348                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7349                                 + tdata->auth_tag.len);
7350                 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
7351                                 tdata->plaintext.len);
7352         }
7353
7354         /* Create GCM opertaion */
7355         retval = create_gcm_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
7356                         tdata, digest_mem, digest_phys);
7357
7358         if (retval < 0)
7359                 return retval;
7360
7361         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7362
7363         ut_params->op->sym->m_src = ut_params->ibuf;
7364         if (oop)
7365                 ut_params->op->sym->m_dst = ut_params->obuf;
7366
7367         /* Process crypto operation */
7368         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7369                         ut_params->op), "failed to process sym crypto op");
7370
7371         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7372                         "crypto op processing failed");
7373
7374
7375         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7376                         uint8_t *, prepend_len);
7377         if (oop) {
7378                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7379                                 uint8_t *, prepend_len);
7380         }
7381
7382         if (fragsz_oop)
7383                 fragsz = fragsz_oop;
7384
7385         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7386                         ciphertext,
7387                         tdata->ciphertext.data,
7388                         fragsz,
7389                         "GCM Ciphertext data not as expected");
7390
7391         buf = ut_params->op->sym->m_src->next;
7392         if (oop)
7393                 buf = ut_params->op->sym->m_dst->next;
7394
7395         unsigned int off = fragsz;
7396
7397         ecx = 0;
7398         while (buf) {
7399                 ciphertext = rte_pktmbuf_mtod(buf,
7400                                 uint8_t *);
7401
7402                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7403                                 ciphertext,
7404                                 tdata->ciphertext.data + off,
7405                                 to_trn_tbl[ecx],
7406                                 "GCM Ciphertext data not as expected");
7407
7408                 off += to_trn_tbl[ecx++];
7409                 buf = buf->next;
7410         }
7411
7412         auth_tag = digest_mem;
7413         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7414                         auth_tag,
7415                         tdata->auth_tag.data,
7416                         tdata->auth_tag.len,
7417                         "GCM Generated auth tag not as expected");
7418
7419         return 0;
7420 }
7421
7422 #define IN_PLACE        0
7423 #define OUT_OF_PLACE    1
7424
7425 static int
7426 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
7427 {
7428         return test_AES_GCM_authenticated_encryption_SGL(
7429                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
7430 }
7431
7432 static int
7433 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
7434 {
7435         return test_AES_GCM_authenticated_encryption_SGL(
7436                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
7437 }
7438
7439 static int
7440 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
7441 {
7442         return test_AES_GCM_authenticated_encryption_SGL(
7443                         &gcm_test_case_8, OUT_OF_PLACE, 400,
7444                         gcm_test_case_8.plaintext.len);
7445 }
7446
7447 static int
7448 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
7449 {
7450
7451         return test_AES_GCM_authenticated_encryption_SGL(
7452                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
7453 }
7454
7455 static int
7456 test_authentication_verify_fail_when_data_corrupted(
7457                 struct crypto_testsuite_params *ts_params,
7458                 struct crypto_unittest_params *ut_params,
7459                 const struct test_crypto_vector *reference)
7460 {
7461         return test_authentication_verify_fail_when_data_corruption(
7462                         ts_params, ut_params, reference, 1);
7463 }
7464
7465 static int
7466 test_authentication_verify_fail_when_tag_corrupted(
7467                 struct crypto_testsuite_params *ts_params,
7468                 struct crypto_unittest_params *ut_params,
7469                 const struct test_crypto_vector *reference)
7470 {
7471         return test_authentication_verify_fail_when_data_corruption(
7472                         ts_params, ut_params, reference, 0);
7473 }
7474
7475 static int
7476 test_authentication_verify_GMAC_fail_when_data_corrupted(
7477                 struct crypto_testsuite_params *ts_params,
7478                 struct crypto_unittest_params *ut_params,
7479                 const struct test_crypto_vector *reference)
7480 {
7481         return test_authentication_verify_GMAC_fail_when_corruption(
7482                         ts_params, ut_params, reference, 1);
7483 }
7484
7485 static int
7486 test_authentication_verify_GMAC_fail_when_tag_corrupted(
7487                 struct crypto_testsuite_params *ts_params,
7488                 struct crypto_unittest_params *ut_params,
7489                 const struct test_crypto_vector *reference)
7490 {
7491         return test_authentication_verify_GMAC_fail_when_corruption(
7492                         ts_params, ut_params, reference, 0);
7493 }
7494
7495 static int
7496 test_authenticated_decryption_fail_when_data_corrupted(
7497                 struct crypto_testsuite_params *ts_params,
7498                 struct crypto_unittest_params *ut_params,
7499                 const struct test_crypto_vector *reference)
7500 {
7501         return test_authenticated_decryption_fail_when_corruption(
7502                         ts_params, ut_params, reference, 1);
7503 }
7504
7505 static int
7506 test_authenticated_decryption_fail_when_tag_corrupted(
7507                 struct crypto_testsuite_params *ts_params,
7508                 struct crypto_unittest_params *ut_params,
7509                 const struct test_crypto_vector *reference)
7510 {
7511         return test_authenticated_decryption_fail_when_corruption(
7512                         ts_params, ut_params, reference, 0);
7513 }
7514
7515 static int
7516 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
7517 {
7518         return test_authentication_verify_fail_when_data_corrupted(
7519                         &testsuite_params, &unittest_params,
7520                         &hmac_sha1_test_crypto_vector);
7521 }
7522
7523 static int
7524 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
7525 {
7526         return test_authentication_verify_fail_when_tag_corrupted(
7527                         &testsuite_params, &unittest_params,
7528                         &hmac_sha1_test_crypto_vector);
7529 }
7530
7531 static int
7532 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
7533 {
7534         return test_authentication_verify_GMAC_fail_when_data_corrupted(
7535                         &testsuite_params, &unittest_params,
7536                         &aes128_gmac_test_vector);
7537 }
7538
7539 static int
7540 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
7541 {
7542         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
7543                         &testsuite_params, &unittest_params,
7544                         &aes128_gmac_test_vector);
7545 }
7546
7547 static int
7548 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
7549 {
7550         return test_authenticated_decryption_fail_when_data_corrupted(
7551                         &testsuite_params,
7552                         &unittest_params,
7553                         &aes128cbc_hmac_sha1_test_vector);
7554 }
7555
7556 static int
7557 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
7558 {
7559         return test_authenticated_decryption_fail_when_tag_corrupted(
7560                         &testsuite_params,
7561                         &unittest_params,
7562                         &aes128cbc_hmac_sha1_test_vector);
7563 }
7564
7565 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
7566
7567 /* global AESNI slave IDs for the scheduler test */
7568 uint8_t aesni_ids[2];
7569
7570 static int
7571 test_scheduler_attach_slave_op(void)
7572 {
7573         struct crypto_testsuite_params *ts_params = &testsuite_params;
7574         uint8_t sched_id = ts_params->valid_devs[0];
7575         uint32_t nb_devs, i, nb_devs_attached = 0;
7576         int ret;
7577         char vdev_name[32];
7578
7579         /* create 2 AESNI_MB if necessary */
7580         nb_devs = rte_cryptodev_count_devtype(
7581                         RTE_CRYPTODEV_AESNI_MB_PMD);
7582         if (nb_devs < 2) {
7583                 for (i = nb_devs; i < 2; i++) {
7584                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
7585                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
7586                                         i);
7587                         ret = rte_vdev_init(vdev_name, NULL);
7588
7589                         TEST_ASSERT(ret == 0,
7590                                 "Failed to create instance %u of"
7591                                 " pmd : %s",
7592                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7593                 }
7594         }
7595
7596         /* attach 2 AESNI_MB cdevs */
7597         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
7598                         i++) {
7599                 struct rte_cryptodev_info info;
7600
7601                 rte_cryptodev_info_get(i, &info);
7602                 if (info.dev_type != RTE_CRYPTODEV_AESNI_MB_PMD)
7603                         continue;
7604
7605                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
7606                                 (uint8_t)i);
7607
7608                 TEST_ASSERT(ret == 0,
7609                         "Failed to attach device %u of pmd : %s", i,
7610                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7611
7612                 aesni_ids[nb_devs_attached] = (uint8_t)i;
7613
7614                 nb_devs_attached++;
7615         }
7616
7617         return 0;
7618 }
7619
7620 static int
7621 test_scheduler_detach_slave_op(void)
7622 {
7623         struct crypto_testsuite_params *ts_params = &testsuite_params;
7624         uint8_t sched_id = ts_params->valid_devs[0];
7625         uint32_t i;
7626         int ret;
7627
7628         for (i = 0; i < 2; i++) {
7629                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
7630                                 aesni_ids[i]);
7631                 TEST_ASSERT(ret == 0,
7632                         "Failed to detach device %u", aesni_ids[i]);
7633         }
7634
7635         return 0;
7636 }
7637
7638 static int
7639 test_scheduler_mode_op(void)
7640 {
7641         struct crypto_testsuite_params *ts_params = &testsuite_params;
7642         uint8_t sched_id = ts_params->valid_devs[0];
7643         struct rte_cryptodev_scheduler_ops op = {0};
7644         struct rte_cryptodev_scheduler dummy_scheduler = {
7645                 .description = "dummy scheduler to test mode",
7646                 .name = "dummy scheduler",
7647                 .mode = CDEV_SCHED_MODE_USERDEFINED,
7648                 .ops = &op
7649         };
7650         int ret;
7651
7652         /* set user defined mode */
7653         ret = rte_cryptodev_scheduler_load_user_scheduler(sched_id,
7654                         &dummy_scheduler);
7655         TEST_ASSERT(ret == 0,
7656                 "Failed to set cdev %u to user defined mode", sched_id);
7657
7658         /* set round robin mode */
7659         ret = rte_cryptodev_scheduler_mode_set(sched_id,
7660                         CDEV_SCHED_MODE_ROUNDROBIN);
7661         TEST_ASSERT(ret == 0,
7662                 "Failed to set cdev %u to round-robin mode", sched_id);
7663         TEST_ASSERT(rte_cryptodev_scheduler_mode_get(sched_id) ==
7664                         CDEV_SCHED_MODE_ROUNDROBIN, "Scheduling Mode "
7665                                         "not match");
7666
7667         return 0;
7668 }
7669
7670 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
7671         .suite_name = "Crypto Device Scheduler Unit Test Suite",
7672         .setup = testsuite_setup,
7673         .teardown = testsuite_teardown,
7674         .unit_test_cases = {
7675                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
7676                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_op),
7677                 TEST_CASE_ST(ut_setup, ut_teardown,
7678                                 test_AES_chain_scheduler_all),
7679                 TEST_CASE_ST(ut_setup, ut_teardown,
7680                                 test_AES_cipheronly_scheduler_all),
7681                 TEST_CASE_ST(ut_setup, ut_teardown,
7682                                 test_authonly_scheduler_all),
7683                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
7684                 TEST_CASES_END() /**< NULL terminate unit test array */
7685         }
7686 };
7687
7688 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
7689
7690 static struct unit_test_suite cryptodev_qat_testsuite  = {
7691         .suite_name = "Crypto QAT Unit Test Suite",
7692         .setup = testsuite_setup,
7693         .teardown = testsuite_teardown,
7694         .unit_test_cases = {
7695                 TEST_CASE_ST(ut_setup, ut_teardown,
7696                                 test_device_configure_invalid_dev_id),
7697                 TEST_CASE_ST(ut_setup, ut_teardown,
7698                                 test_device_configure_invalid_queue_pair_ids),
7699                 TEST_CASE_ST(ut_setup, ut_teardown,
7700                                 test_queue_pair_descriptor_setup),
7701                 TEST_CASE_ST(ut_setup, ut_teardown,
7702                                 test_multi_session),
7703
7704                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
7705                 TEST_CASE_ST(ut_setup, ut_teardown,
7706                                                 test_AES_cipheronly_qat_all),
7707                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
7708                 TEST_CASE_ST(ut_setup, ut_teardown,
7709                                                 test_3DES_cipheronly_qat_all),
7710                 TEST_CASE_ST(ut_setup, ut_teardown,
7711                                                 test_DES_cipheronly_qat_all),
7712                 TEST_CASE_ST(ut_setup, ut_teardown,
7713                                                 test_AES_docsis_qat_all),
7714                 TEST_CASE_ST(ut_setup, ut_teardown,
7715                                                 test_DES_docsis_qat_all),
7716                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
7717
7718                 /** AES GCM Authenticated Encryption */
7719                 TEST_CASE_ST(ut_setup, ut_teardown,
7720                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
7721                 TEST_CASE_ST(ut_setup, ut_teardown,
7722                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
7723                 TEST_CASE_ST(ut_setup, ut_teardown,
7724                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
7725                 TEST_CASE_ST(ut_setup, ut_teardown,
7726                         test_AES_GCM_authenticated_encryption_test_case_1),
7727                 TEST_CASE_ST(ut_setup, ut_teardown,
7728                         test_AES_GCM_authenticated_encryption_test_case_2),
7729                 TEST_CASE_ST(ut_setup, ut_teardown,
7730                         test_AES_GCM_authenticated_encryption_test_case_3),
7731                 TEST_CASE_ST(ut_setup, ut_teardown,
7732                         test_AES_GCM_authenticated_encryption_test_case_4),
7733                 TEST_CASE_ST(ut_setup, ut_teardown,
7734                         test_AES_GCM_authenticated_encryption_test_case_5),
7735                 TEST_CASE_ST(ut_setup, ut_teardown,
7736                         test_AES_GCM_authenticated_encryption_test_case_6),
7737                 TEST_CASE_ST(ut_setup, ut_teardown,
7738                         test_AES_GCM_authenticated_encryption_test_case_7),
7739
7740                 /** AES GCM Authenticated Decryption */
7741                 TEST_CASE_ST(ut_setup, ut_teardown,
7742                         test_AES_GCM_authenticated_decryption_test_case_1),
7743                 TEST_CASE_ST(ut_setup, ut_teardown,
7744                         test_AES_GCM_authenticated_decryption_test_case_2),
7745                 TEST_CASE_ST(ut_setup, ut_teardown,
7746                         test_AES_GCM_authenticated_decryption_test_case_3),
7747                 TEST_CASE_ST(ut_setup, ut_teardown,
7748                         test_AES_GCM_authenticated_decryption_test_case_4),
7749                 TEST_CASE_ST(ut_setup, ut_teardown,
7750                         test_AES_GCM_authenticated_decryption_test_case_5),
7751                 TEST_CASE_ST(ut_setup, ut_teardown,
7752                         test_AES_GCM_authenticated_decryption_test_case_6),
7753                 TEST_CASE_ST(ut_setup, ut_teardown,
7754                         test_AES_GCM_authenticated_decryption_test_case_7),
7755
7756                 /** AES GMAC Authentication */
7757                 TEST_CASE_ST(ut_setup, ut_teardown,
7758                         test_AES_GMAC_authentication_test_case_1),
7759                 TEST_CASE_ST(ut_setup, ut_teardown,
7760                         test_AES_GMAC_authentication_verify_test_case_1),
7761                 TEST_CASE_ST(ut_setup, ut_teardown,
7762                         test_AES_GMAC_authentication_test_case_2),
7763                 TEST_CASE_ST(ut_setup, ut_teardown,
7764                         test_AES_GMAC_authentication_verify_test_case_2),
7765                 TEST_CASE_ST(ut_setup, ut_teardown,
7766                         test_AES_GMAC_authentication_test_case_3),
7767                 TEST_CASE_ST(ut_setup, ut_teardown,
7768                         test_AES_GMAC_authentication_verify_test_case_3),
7769
7770                 /** SNOW 3G encrypt only (UEA2) */
7771                 TEST_CASE_ST(ut_setup, ut_teardown,
7772                         test_snow3g_encryption_test_case_1),
7773                 TEST_CASE_ST(ut_setup, ut_teardown,
7774                         test_snow3g_encryption_test_case_2),
7775                 TEST_CASE_ST(ut_setup, ut_teardown,
7776                         test_snow3g_encryption_test_case_3),
7777                 TEST_CASE_ST(ut_setup, ut_teardown,
7778                         test_snow3g_encryption_test_case_4),
7779                 TEST_CASE_ST(ut_setup, ut_teardown,
7780                         test_snow3g_encryption_test_case_5),
7781
7782                 TEST_CASE_ST(ut_setup, ut_teardown,
7783                         test_snow3g_encryption_test_case_1_oop),
7784                 TEST_CASE_ST(ut_setup, ut_teardown,
7785                         test_snow3g_decryption_test_case_1_oop),
7786
7787                 /** SNOW 3G decrypt only (UEA2) */
7788                 TEST_CASE_ST(ut_setup, ut_teardown,
7789                         test_snow3g_decryption_test_case_1),
7790                 TEST_CASE_ST(ut_setup, ut_teardown,
7791                         test_snow3g_decryption_test_case_2),
7792                 TEST_CASE_ST(ut_setup, ut_teardown,
7793                         test_snow3g_decryption_test_case_3),
7794                 TEST_CASE_ST(ut_setup, ut_teardown,
7795                         test_snow3g_decryption_test_case_4),
7796                 TEST_CASE_ST(ut_setup, ut_teardown,
7797                         test_snow3g_decryption_test_case_5),
7798                 TEST_CASE_ST(ut_setup, ut_teardown,
7799                         test_snow3g_hash_generate_test_case_1),
7800                 TEST_CASE_ST(ut_setup, ut_teardown,
7801                         test_snow3g_hash_generate_test_case_2),
7802                 TEST_CASE_ST(ut_setup, ut_teardown,
7803                         test_snow3g_hash_generate_test_case_3),
7804                 TEST_CASE_ST(ut_setup, ut_teardown,
7805                         test_snow3g_hash_verify_test_case_1),
7806                 TEST_CASE_ST(ut_setup, ut_teardown,
7807                         test_snow3g_hash_verify_test_case_2),
7808                 TEST_CASE_ST(ut_setup, ut_teardown,
7809                         test_snow3g_hash_verify_test_case_3),
7810                 TEST_CASE_ST(ut_setup, ut_teardown,
7811                         test_snow3g_cipher_auth_test_case_1),
7812                 TEST_CASE_ST(ut_setup, ut_teardown,
7813                         test_snow3g_auth_cipher_test_case_1),
7814
7815                 /** ZUC encrypt only (EEA3) */
7816                 TEST_CASE_ST(ut_setup, ut_teardown,
7817                         test_zuc_encryption_test_case_1),
7818                 TEST_CASE_ST(ut_setup, ut_teardown,
7819                         test_zuc_encryption_test_case_2),
7820                 TEST_CASE_ST(ut_setup, ut_teardown,
7821                         test_zuc_encryption_test_case_3),
7822                 TEST_CASE_ST(ut_setup, ut_teardown,
7823                         test_zuc_encryption_test_case_4),
7824                 TEST_CASE_ST(ut_setup, ut_teardown,
7825                         test_zuc_encryption_test_case_5),
7826
7827                 /** ZUC authenticate (EIA3) */
7828                 TEST_CASE_ST(ut_setup, ut_teardown,
7829                         test_zuc_hash_generate_test_case_6),
7830                 TEST_CASE_ST(ut_setup, ut_teardown,
7831                         test_zuc_hash_generate_test_case_7),
7832                 TEST_CASE_ST(ut_setup, ut_teardown,
7833                         test_zuc_hash_generate_test_case_8),
7834
7835                 /** ZUC alg-chain (EEA3/EIA3) */
7836                 TEST_CASE_ST(ut_setup, ut_teardown,
7837                         test_zuc_cipher_auth_test_case_1),
7838                 TEST_CASE_ST(ut_setup, ut_teardown,
7839                         test_zuc_cipher_auth_test_case_2),
7840
7841                 /** HMAC_MD5 Authentication */
7842                 TEST_CASE_ST(ut_setup, ut_teardown,
7843                         test_MD5_HMAC_generate_case_1),
7844                 TEST_CASE_ST(ut_setup, ut_teardown,
7845                         test_MD5_HMAC_verify_case_1),
7846                 TEST_CASE_ST(ut_setup, ut_teardown,
7847                         test_MD5_HMAC_generate_case_2),
7848                 TEST_CASE_ST(ut_setup, ut_teardown,
7849                         test_MD5_HMAC_verify_case_2),
7850
7851                 /** NULL tests */
7852                 TEST_CASE_ST(ut_setup, ut_teardown,
7853                         test_null_auth_only_operation),
7854                 TEST_CASE_ST(ut_setup, ut_teardown,
7855                         test_null_cipher_only_operation),
7856                 TEST_CASE_ST(ut_setup, ut_teardown,
7857                         test_null_cipher_auth_operation),
7858                 TEST_CASE_ST(ut_setup, ut_teardown,
7859                         test_null_auth_cipher_operation),
7860
7861                 TEST_CASE_ST(ut_setup, ut_teardown,
7862                         test_kasumi_hash_generate_test_case_6),
7863
7864                 /** KASUMI tests */
7865                 TEST_CASE_ST(ut_setup, ut_teardown,
7866                         test_kasumi_encryption_test_case_1),
7867                 TEST_CASE_ST(ut_setup, ut_teardown,
7868                         test_kasumi_encryption_test_case_3),
7869                 TEST_CASE_ST(ut_setup, ut_teardown,
7870                         test_kasumi_auth_cipher_test_case_1),
7871                 TEST_CASE_ST(ut_setup, ut_teardown,
7872                         test_kasumi_cipher_auth_test_case_1),
7873
7874                 /** Negative tests */
7875                 TEST_CASE_ST(ut_setup, ut_teardown,
7876                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
7877                 TEST_CASE_ST(ut_setup, ut_teardown,
7878                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
7879                 TEST_CASE_ST(ut_setup, ut_teardown,
7880                         authentication_verify_AES128_GMAC_fail_data_corrupt),
7881                 TEST_CASE_ST(ut_setup, ut_teardown,
7882                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
7883                 TEST_CASE_ST(ut_setup, ut_teardown,
7884                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
7885                 TEST_CASE_ST(ut_setup, ut_teardown,
7886                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
7887
7888                 TEST_CASES_END() /**< NULL terminate unit test array */
7889         }
7890 };
7891
7892 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
7893         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
7894         .setup = testsuite_setup,
7895         .teardown = testsuite_teardown,
7896         .unit_test_cases = {
7897                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
7898                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
7899                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
7900                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
7901
7902                 TEST_CASES_END() /**< NULL terminate unit test array */
7903         }
7904 };
7905
7906 static struct unit_test_suite cryptodev_openssl_testsuite  = {
7907         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
7908         .setup = testsuite_setup,
7909         .teardown = testsuite_teardown,
7910         .unit_test_cases = {
7911                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
7912                 TEST_CASE_ST(ut_setup, ut_teardown,
7913                                 test_multi_session_random_usage),
7914                 TEST_CASE_ST(ut_setup, ut_teardown,
7915                                 test_AES_chain_openssl_all),
7916                 TEST_CASE_ST(ut_setup, ut_teardown,
7917                                 test_AES_cipheronly_openssl_all),
7918                 TEST_CASE_ST(ut_setup, ut_teardown,
7919                                 test_3DES_chain_openssl_all),
7920                 TEST_CASE_ST(ut_setup, ut_teardown,
7921                                 test_3DES_cipheronly_openssl_all),
7922                 TEST_CASE_ST(ut_setup, ut_teardown,
7923                                 test_DES_docsis_openssl_all),
7924                 TEST_CASE_ST(ut_setup, ut_teardown,
7925                                 test_authonly_openssl_all),
7926
7927                 /** AES GCM Authenticated Encryption */
7928                 TEST_CASE_ST(ut_setup, ut_teardown,
7929                         test_AES_GCM_authenticated_encryption_test_case_1),
7930                 TEST_CASE_ST(ut_setup, ut_teardown,
7931                         test_AES_GCM_authenticated_encryption_test_case_2),
7932                 TEST_CASE_ST(ut_setup, ut_teardown,
7933                         test_AES_GCM_authenticated_encryption_test_case_3),
7934                 TEST_CASE_ST(ut_setup, ut_teardown,
7935                         test_AES_GCM_authenticated_encryption_test_case_4),
7936                 TEST_CASE_ST(ut_setup, ut_teardown,
7937                         test_AES_GCM_authenticated_encryption_test_case_5),
7938                 TEST_CASE_ST(ut_setup, ut_teardown,
7939                         test_AES_GCM_authenticated_encryption_test_case_6),
7940                 TEST_CASE_ST(ut_setup, ut_teardown,
7941                         test_AES_GCM_authenticated_encryption_test_case_7),
7942
7943                 /** AES GCM Authenticated Decryption */
7944                 TEST_CASE_ST(ut_setup, ut_teardown,
7945                         test_AES_GCM_authenticated_decryption_test_case_1),
7946                 TEST_CASE_ST(ut_setup, ut_teardown,
7947                         test_AES_GCM_authenticated_decryption_test_case_2),
7948                 TEST_CASE_ST(ut_setup, ut_teardown,
7949                         test_AES_GCM_authenticated_decryption_test_case_3),
7950                 TEST_CASE_ST(ut_setup, ut_teardown,
7951                         test_AES_GCM_authenticated_decryption_test_case_4),
7952                 TEST_CASE_ST(ut_setup, ut_teardown,
7953                         test_AES_GCM_authenticated_decryption_test_case_5),
7954                 TEST_CASE_ST(ut_setup, ut_teardown,
7955                         test_AES_GCM_authenticated_decryption_test_case_6),
7956                 TEST_CASE_ST(ut_setup, ut_teardown,
7957                         test_AES_GCM_authenticated_decryption_test_case_7),
7958
7959                 /** AES GMAC Authentication */
7960                 TEST_CASE_ST(ut_setup, ut_teardown,
7961                         test_AES_GMAC_authentication_test_case_1),
7962                 TEST_CASE_ST(ut_setup, ut_teardown,
7963                         test_AES_GMAC_authentication_verify_test_case_1),
7964                 TEST_CASE_ST(ut_setup, ut_teardown,
7965                         test_AES_GMAC_authentication_test_case_2),
7966                 TEST_CASE_ST(ut_setup, ut_teardown,
7967                         test_AES_GMAC_authentication_verify_test_case_2),
7968                 TEST_CASE_ST(ut_setup, ut_teardown,
7969                         test_AES_GMAC_authentication_test_case_3),
7970                 TEST_CASE_ST(ut_setup, ut_teardown,
7971                         test_AES_GMAC_authentication_verify_test_case_3),
7972                 TEST_CASE_ST(ut_setup, ut_teardown,
7973                         test_AES_GMAC_authentication_test_case_4),
7974                 TEST_CASE_ST(ut_setup, ut_teardown,
7975                         test_AES_GMAC_authentication_verify_test_case_4),
7976
7977                 /** Scatter-Gather */
7978                 TEST_CASE_ST(ut_setup, ut_teardown,
7979                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
7980
7981                 /** Negative tests */
7982                 TEST_CASE_ST(ut_setup, ut_teardown,
7983                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
7984                 TEST_CASE_ST(ut_setup, ut_teardown,
7985                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
7986                 TEST_CASE_ST(ut_setup, ut_teardown,
7987                         authentication_verify_AES128_GMAC_fail_data_corrupt),
7988                 TEST_CASE_ST(ut_setup, ut_teardown,
7989                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
7990                 TEST_CASE_ST(ut_setup, ut_teardown,
7991                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
7992                 TEST_CASE_ST(ut_setup, ut_teardown,
7993                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
7994
7995                 TEST_CASES_END() /**< NULL terminate unit test array */
7996         }
7997 };
7998
7999 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
8000         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
8001         .setup = testsuite_setup,
8002         .teardown = testsuite_teardown,
8003         .unit_test_cases = {
8004                 /** AES GCM Authenticated Encryption */
8005                 TEST_CASE_ST(ut_setup, ut_teardown,
8006                         test_AES_GCM_authenticated_encryption_test_case_1),
8007                 TEST_CASE_ST(ut_setup, ut_teardown,
8008                         test_AES_GCM_authenticated_encryption_test_case_2),
8009                 TEST_CASE_ST(ut_setup, ut_teardown,
8010                         test_AES_GCM_authenticated_encryption_test_case_3),
8011                 TEST_CASE_ST(ut_setup, ut_teardown,
8012                         test_AES_GCM_authenticated_encryption_test_case_4),
8013                 TEST_CASE_ST(ut_setup, ut_teardown,
8014                         test_AES_GCM_authenticated_encryption_test_case_5),
8015                 TEST_CASE_ST(ut_setup, ut_teardown,
8016                         test_AES_GCM_authenticated_encryption_test_case_6),
8017                 TEST_CASE_ST(ut_setup, ut_teardown,
8018                         test_AES_GCM_authenticated_encryption_test_case_7),
8019
8020                 /** AES GCM Authenticated Decryption */
8021                 TEST_CASE_ST(ut_setup, ut_teardown,
8022                         test_AES_GCM_authenticated_decryption_test_case_1),
8023                 TEST_CASE_ST(ut_setup, ut_teardown,
8024                         test_AES_GCM_authenticated_decryption_test_case_2),
8025                 TEST_CASE_ST(ut_setup, ut_teardown,
8026                         test_AES_GCM_authenticated_decryption_test_case_3),
8027                 TEST_CASE_ST(ut_setup, ut_teardown,
8028                         test_AES_GCM_authenticated_decryption_test_case_4),
8029                 TEST_CASE_ST(ut_setup, ut_teardown,
8030                         test_AES_GCM_authenticated_decryption_test_case_5),
8031                 TEST_CASE_ST(ut_setup, ut_teardown,
8032                         test_AES_GCM_authenticated_decryption_test_case_6),
8033                 TEST_CASE_ST(ut_setup, ut_teardown,
8034                         test_AES_GCM_authenticated_decryption_test_case_7),
8035
8036                 /** AES GCM Authenticated Encryption 256 bits key */
8037                 TEST_CASE_ST(ut_setup, ut_teardown,
8038                         test_AES_GCM_auth_encryption_test_case_256_1),
8039                 TEST_CASE_ST(ut_setup, ut_teardown,
8040                         test_AES_GCM_auth_encryption_test_case_256_2),
8041                 TEST_CASE_ST(ut_setup, ut_teardown,
8042                         test_AES_GCM_auth_encryption_test_case_256_3),
8043                 TEST_CASE_ST(ut_setup, ut_teardown,
8044                         test_AES_GCM_auth_encryption_test_case_256_4),
8045                 TEST_CASE_ST(ut_setup, ut_teardown,
8046                         test_AES_GCM_auth_encryption_test_case_256_5),
8047                 TEST_CASE_ST(ut_setup, ut_teardown,
8048                         test_AES_GCM_auth_encryption_test_case_256_6),
8049                 TEST_CASE_ST(ut_setup, ut_teardown,
8050                         test_AES_GCM_auth_encryption_test_case_256_7),
8051
8052                 /** AES GCM Authenticated Decryption 256 bits key */
8053                 TEST_CASE_ST(ut_setup, ut_teardown,
8054                         test_AES_GCM_auth_decryption_test_case_256_1),
8055                 TEST_CASE_ST(ut_setup, ut_teardown,
8056                         test_AES_GCM_auth_decryption_test_case_256_2),
8057                 TEST_CASE_ST(ut_setup, ut_teardown,
8058                         test_AES_GCM_auth_decryption_test_case_256_3),
8059                 TEST_CASE_ST(ut_setup, ut_teardown,
8060                         test_AES_GCM_auth_decryption_test_case_256_4),
8061                 TEST_CASE_ST(ut_setup, ut_teardown,
8062                         test_AES_GCM_auth_decryption_test_case_256_5),
8063                 TEST_CASE_ST(ut_setup, ut_teardown,
8064                         test_AES_GCM_auth_decryption_test_case_256_6),
8065                 TEST_CASE_ST(ut_setup, ut_teardown,
8066                         test_AES_GCM_auth_decryption_test_case_256_7),
8067
8068                 /** AES GCM Authenticated Encryption big aad size */
8069                 TEST_CASE_ST(ut_setup, ut_teardown,
8070                         test_AES_GCM_auth_encryption_test_case_aad_1),
8071                 TEST_CASE_ST(ut_setup, ut_teardown,
8072                         test_AES_GCM_auth_encryption_test_case_aad_2),
8073
8074                 /** AES GCM Authenticated Decryption big aad size */
8075                 TEST_CASE_ST(ut_setup, ut_teardown,
8076                         test_AES_GCM_auth_decryption_test_case_aad_1),
8077                 TEST_CASE_ST(ut_setup, ut_teardown,
8078                         test_AES_GCM_auth_decryption_test_case_aad_2),
8079
8080                 /** AES GMAC Authentication */
8081                 TEST_CASE_ST(ut_setup, ut_teardown,
8082                         test_AES_GMAC_authentication_test_case_1),
8083                 TEST_CASE_ST(ut_setup, ut_teardown,
8084                         test_AES_GMAC_authentication_verify_test_case_1),
8085                 TEST_CASE_ST(ut_setup, ut_teardown,
8086                         test_AES_GMAC_authentication_test_case_3),
8087                 TEST_CASE_ST(ut_setup, ut_teardown,
8088                         test_AES_GMAC_authentication_verify_test_case_3),
8089                 TEST_CASE_ST(ut_setup, ut_teardown,
8090                         test_AES_GMAC_authentication_test_case_4),
8091                 TEST_CASE_ST(ut_setup, ut_teardown,
8092                         test_AES_GMAC_authentication_verify_test_case_4),
8093
8094                 /** Negative tests */
8095                 TEST_CASE_ST(ut_setup, ut_teardown,
8096                         authentication_verify_AES128_GMAC_fail_data_corrupt),
8097                 TEST_CASE_ST(ut_setup, ut_teardown,
8098                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
8099
8100                 /** Out of place tests */
8101                 TEST_CASE_ST(ut_setup, ut_teardown,
8102                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
8103                 TEST_CASE_ST(ut_setup, ut_teardown,
8104                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
8105
8106                 /** Session-less tests */
8107                 TEST_CASE_ST(ut_setup, ut_teardown,
8108                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
8109                 TEST_CASE_ST(ut_setup, ut_teardown,
8110                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
8111
8112                 /** Scatter-Gather */
8113                 TEST_CASE_ST(ut_setup, ut_teardown,
8114                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
8115
8116                 TEST_CASES_END() /**< NULL terminate unit test array */
8117         }
8118 };
8119
8120 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
8121         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
8122         .setup = testsuite_setup,
8123         .teardown = testsuite_teardown,
8124         .unit_test_cases = {
8125                 /** KASUMI encrypt only (UEA1) */
8126                 TEST_CASE_ST(ut_setup, ut_teardown,
8127                         test_kasumi_encryption_test_case_1),
8128                 TEST_CASE_ST(ut_setup, ut_teardown,
8129                         test_kasumi_encryption_test_case_1_sgl),
8130                 TEST_CASE_ST(ut_setup, ut_teardown,
8131                         test_kasumi_encryption_test_case_2),
8132                 TEST_CASE_ST(ut_setup, ut_teardown,
8133                         test_kasumi_encryption_test_case_3),
8134                 TEST_CASE_ST(ut_setup, ut_teardown,
8135                         test_kasumi_encryption_test_case_4),
8136                 TEST_CASE_ST(ut_setup, ut_teardown,
8137                         test_kasumi_encryption_test_case_5),
8138                 /** KASUMI decrypt only (UEA1) */
8139                 TEST_CASE_ST(ut_setup, ut_teardown,
8140                         test_kasumi_decryption_test_case_1),
8141                 TEST_CASE_ST(ut_setup, ut_teardown,
8142                         test_kasumi_decryption_test_case_2),
8143                 TEST_CASE_ST(ut_setup, ut_teardown,
8144                         test_kasumi_decryption_test_case_3),
8145                 TEST_CASE_ST(ut_setup, ut_teardown,
8146                         test_kasumi_decryption_test_case_4),
8147                 TEST_CASE_ST(ut_setup, ut_teardown,
8148                         test_kasumi_decryption_test_case_5),
8149
8150                 TEST_CASE_ST(ut_setup, ut_teardown,
8151                         test_kasumi_encryption_test_case_1_oop),
8152                 TEST_CASE_ST(ut_setup, ut_teardown,
8153                         test_kasumi_encryption_test_case_1_oop_sgl),
8154
8155
8156                 TEST_CASE_ST(ut_setup, ut_teardown,
8157                         test_kasumi_decryption_test_case_1_oop),
8158
8159                 /** KASUMI hash only (UIA1) */
8160                 TEST_CASE_ST(ut_setup, ut_teardown,
8161                         test_kasumi_hash_generate_test_case_1),
8162                 TEST_CASE_ST(ut_setup, ut_teardown,
8163                         test_kasumi_hash_generate_test_case_2),
8164                 TEST_CASE_ST(ut_setup, ut_teardown,
8165                         test_kasumi_hash_generate_test_case_3),
8166                 TEST_CASE_ST(ut_setup, ut_teardown,
8167                         test_kasumi_hash_generate_test_case_4),
8168                 TEST_CASE_ST(ut_setup, ut_teardown,
8169                         test_kasumi_hash_generate_test_case_5),
8170                 TEST_CASE_ST(ut_setup, ut_teardown,
8171                         test_kasumi_hash_generate_test_case_6),
8172                 TEST_CASE_ST(ut_setup, ut_teardown,
8173                         test_kasumi_hash_verify_test_case_1),
8174                 TEST_CASE_ST(ut_setup, ut_teardown,
8175                         test_kasumi_hash_verify_test_case_2),
8176                 TEST_CASE_ST(ut_setup, ut_teardown,
8177                         test_kasumi_hash_verify_test_case_3),
8178                 TEST_CASE_ST(ut_setup, ut_teardown,
8179                         test_kasumi_hash_verify_test_case_4),
8180                 TEST_CASE_ST(ut_setup, ut_teardown,
8181                         test_kasumi_hash_verify_test_case_5),
8182                 TEST_CASE_ST(ut_setup, ut_teardown,
8183                         test_kasumi_auth_cipher_test_case_1),
8184                 TEST_CASE_ST(ut_setup, ut_teardown,
8185                         test_kasumi_cipher_auth_test_case_1),
8186                 TEST_CASES_END() /**< NULL terminate unit test array */
8187         }
8188 };
8189 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
8190         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
8191         .setup = testsuite_setup,
8192         .teardown = testsuite_teardown,
8193         .unit_test_cases = {
8194                 /** SNOW 3G encrypt only (UEA2) */
8195                 TEST_CASE_ST(ut_setup, ut_teardown,
8196                         test_snow3g_encryption_test_case_1),
8197                 TEST_CASE_ST(ut_setup, ut_teardown,
8198                         test_snow3g_encryption_test_case_2),
8199                 TEST_CASE_ST(ut_setup, ut_teardown,
8200                         test_snow3g_encryption_test_case_3),
8201                 TEST_CASE_ST(ut_setup, ut_teardown,
8202                         test_snow3g_encryption_test_case_4),
8203                 TEST_CASE_ST(ut_setup, ut_teardown,
8204                         test_snow3g_encryption_test_case_5),
8205
8206                 TEST_CASE_ST(ut_setup, ut_teardown,
8207                         test_snow3g_encryption_test_case_1_oop),
8208                 TEST_CASE_ST(ut_setup, ut_teardown,
8209                                 test_snow3g_encryption_test_case_1_oop_sgl),
8210                 TEST_CASE_ST(ut_setup, ut_teardown,
8211                         test_snow3g_decryption_test_case_1_oop),
8212
8213                 TEST_CASE_ST(ut_setup, ut_teardown,
8214                         test_snow3g_encryption_test_case_1_offset_oop),
8215
8216                 /** SNOW 3G decrypt only (UEA2) */
8217                 TEST_CASE_ST(ut_setup, ut_teardown,
8218                         test_snow3g_decryption_test_case_1),
8219                 TEST_CASE_ST(ut_setup, ut_teardown,
8220                         test_snow3g_decryption_test_case_2),
8221                 TEST_CASE_ST(ut_setup, ut_teardown,
8222                         test_snow3g_decryption_test_case_3),
8223                 TEST_CASE_ST(ut_setup, ut_teardown,
8224                         test_snow3g_decryption_test_case_4),
8225                 TEST_CASE_ST(ut_setup, ut_teardown,
8226                         test_snow3g_decryption_test_case_5),
8227                 TEST_CASE_ST(ut_setup, ut_teardown,
8228                         test_snow3g_hash_generate_test_case_1),
8229                 TEST_CASE_ST(ut_setup, ut_teardown,
8230                         test_snow3g_hash_generate_test_case_2),
8231                 TEST_CASE_ST(ut_setup, ut_teardown,
8232                         test_snow3g_hash_generate_test_case_3),
8233                 /* Tests with buffers which length is not byte-aligned */
8234                 TEST_CASE_ST(ut_setup, ut_teardown,
8235                         test_snow3g_hash_generate_test_case_4),
8236                 TEST_CASE_ST(ut_setup, ut_teardown,
8237                         test_snow3g_hash_generate_test_case_5),
8238                 TEST_CASE_ST(ut_setup, ut_teardown,
8239                         test_snow3g_hash_generate_test_case_6),
8240                 TEST_CASE_ST(ut_setup, ut_teardown,
8241                         test_snow3g_hash_verify_test_case_1),
8242                 TEST_CASE_ST(ut_setup, ut_teardown,
8243                         test_snow3g_hash_verify_test_case_2),
8244                 TEST_CASE_ST(ut_setup, ut_teardown,
8245                         test_snow3g_hash_verify_test_case_3),
8246                 /* Tests with buffers which length is not byte-aligned */
8247                 TEST_CASE_ST(ut_setup, ut_teardown,
8248                         test_snow3g_hash_verify_test_case_4),
8249                 TEST_CASE_ST(ut_setup, ut_teardown,
8250                         test_snow3g_hash_verify_test_case_5),
8251                 TEST_CASE_ST(ut_setup, ut_teardown,
8252                         test_snow3g_hash_verify_test_case_6),
8253                 TEST_CASE_ST(ut_setup, ut_teardown,
8254                         test_snow3g_cipher_auth_test_case_1),
8255                 TEST_CASE_ST(ut_setup, ut_teardown,
8256                         test_snow3g_auth_cipher_test_case_1),
8257
8258                 TEST_CASES_END() /**< NULL terminate unit test array */
8259         }
8260 };
8261
8262 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
8263         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
8264         .setup = testsuite_setup,
8265         .teardown = testsuite_teardown,
8266         .unit_test_cases = {
8267                 /** ZUC encrypt only (EEA3) */
8268                 TEST_CASE_ST(ut_setup, ut_teardown,
8269                         test_zuc_encryption_test_case_1),
8270                 TEST_CASE_ST(ut_setup, ut_teardown,
8271                         test_zuc_encryption_test_case_2),
8272                 TEST_CASE_ST(ut_setup, ut_teardown,
8273                         test_zuc_encryption_test_case_3),
8274                 TEST_CASE_ST(ut_setup, ut_teardown,
8275                         test_zuc_encryption_test_case_4),
8276                 TEST_CASE_ST(ut_setup, ut_teardown,
8277                         test_zuc_encryption_test_case_5),
8278                 TEST_CASE_ST(ut_setup, ut_teardown,
8279                         test_zuc_hash_generate_test_case_1),
8280                 TEST_CASE_ST(ut_setup, ut_teardown,
8281                         test_zuc_hash_generate_test_case_2),
8282                 TEST_CASE_ST(ut_setup, ut_teardown,
8283                         test_zuc_hash_generate_test_case_3),
8284                 TEST_CASE_ST(ut_setup, ut_teardown,
8285                         test_zuc_hash_generate_test_case_4),
8286                 TEST_CASE_ST(ut_setup, ut_teardown,
8287                         test_zuc_hash_generate_test_case_5),
8288                 TEST_CASE_ST(ut_setup, ut_teardown,
8289                         test_zuc_encryption_test_case_6_sgl),
8290                 TEST_CASES_END() /**< NULL terminate unit test array */
8291         }
8292 };
8293
8294 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
8295         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
8296         .setup = testsuite_setup,
8297         .teardown = testsuite_teardown,
8298         .unit_test_cases = {
8299                 TEST_CASE_ST(ut_setup, ut_teardown,
8300                         test_device_configure_invalid_dev_id),
8301                 TEST_CASE_ST(ut_setup, ut_teardown,
8302                         test_multi_session),
8303
8304                 TEST_CASE_ST(ut_setup, ut_teardown,
8305                         test_AES_chain_dpaa2_sec_all),
8306                 TEST_CASE_ST(ut_setup, ut_teardown,
8307                         test_3DES_chain_dpaa2_sec_all),
8308                 TEST_CASE_ST(ut_setup, ut_teardown,
8309                         test_AES_cipheronly_dpaa2_sec_all),
8310                 TEST_CASE_ST(ut_setup, ut_teardown,
8311                         test_3DES_cipheronly_dpaa2_sec_all),
8312                 TEST_CASE_ST(ut_setup, ut_teardown,
8313                         test_authonly_dpaa2_sec_all),
8314
8315                 /** AES GCM Authenticated Encryption */
8316                 TEST_CASE_ST(ut_setup, ut_teardown,
8317                         test_AES_GCM_authenticated_encryption_test_case_1),
8318                 TEST_CASE_ST(ut_setup, ut_teardown,
8319                         test_AES_GCM_authenticated_encryption_test_case_2),
8320                 TEST_CASE_ST(ut_setup, ut_teardown,
8321                         test_AES_GCM_authenticated_encryption_test_case_3),
8322                 TEST_CASE_ST(ut_setup, ut_teardown,
8323                         test_AES_GCM_authenticated_encryption_test_case_4),
8324                 TEST_CASE_ST(ut_setup, ut_teardown,
8325                         test_AES_GCM_authenticated_encryption_test_case_5),
8326                 TEST_CASE_ST(ut_setup, ut_teardown,
8327                         test_AES_GCM_authenticated_encryption_test_case_6),
8328                 TEST_CASE_ST(ut_setup, ut_teardown,
8329                         test_AES_GCM_authenticated_encryption_test_case_7),
8330
8331                 /** AES GCM Authenticated Decryption */
8332                 TEST_CASE_ST(ut_setup, ut_teardown,
8333                         test_AES_GCM_authenticated_decryption_test_case_1),
8334                 TEST_CASE_ST(ut_setup, ut_teardown,
8335                         test_AES_GCM_authenticated_decryption_test_case_2),
8336                 TEST_CASE_ST(ut_setup, ut_teardown,
8337                         test_AES_GCM_authenticated_decryption_test_case_3),
8338                 TEST_CASE_ST(ut_setup, ut_teardown,
8339                         test_AES_GCM_authenticated_decryption_test_case_4),
8340                 TEST_CASE_ST(ut_setup, ut_teardown,
8341                         test_AES_GCM_authenticated_decryption_test_case_5),
8342                 TEST_CASE_ST(ut_setup, ut_teardown,
8343                         test_AES_GCM_authenticated_decryption_test_case_6),
8344                 TEST_CASE_ST(ut_setup, ut_teardown,
8345                         test_AES_GCM_authenticated_decryption_test_case_7),
8346
8347                 /** AES GCM Authenticated Encryption 256 bits key */
8348                 TEST_CASE_ST(ut_setup, ut_teardown,
8349                         test_AES_GCM_auth_encryption_test_case_256_1),
8350                 TEST_CASE_ST(ut_setup, ut_teardown,
8351                         test_AES_GCM_auth_encryption_test_case_256_2),
8352                 TEST_CASE_ST(ut_setup, ut_teardown,
8353                         test_AES_GCM_auth_encryption_test_case_256_3),
8354                 TEST_CASE_ST(ut_setup, ut_teardown,
8355                         test_AES_GCM_auth_encryption_test_case_256_4),
8356                 TEST_CASE_ST(ut_setup, ut_teardown,
8357                         test_AES_GCM_auth_encryption_test_case_256_5),
8358                 TEST_CASE_ST(ut_setup, ut_teardown,
8359                         test_AES_GCM_auth_encryption_test_case_256_6),
8360                 TEST_CASE_ST(ut_setup, ut_teardown,
8361                         test_AES_GCM_auth_encryption_test_case_256_7),
8362
8363                 /** AES GCM Authenticated Decryption 256 bits key */
8364                 TEST_CASE_ST(ut_setup, ut_teardown,
8365                         test_AES_GCM_auth_decryption_test_case_256_1),
8366                 TEST_CASE_ST(ut_setup, ut_teardown,
8367                         test_AES_GCM_auth_decryption_test_case_256_2),
8368                 TEST_CASE_ST(ut_setup, ut_teardown,
8369                         test_AES_GCM_auth_decryption_test_case_256_3),
8370                 TEST_CASE_ST(ut_setup, ut_teardown,
8371                         test_AES_GCM_auth_decryption_test_case_256_4),
8372                 TEST_CASE_ST(ut_setup, ut_teardown,
8373                         test_AES_GCM_auth_decryption_test_case_256_5),
8374                 TEST_CASE_ST(ut_setup, ut_teardown,
8375                         test_AES_GCM_auth_decryption_test_case_256_6),
8376                 TEST_CASE_ST(ut_setup, ut_teardown,
8377                         test_AES_GCM_auth_decryption_test_case_256_7),
8378
8379                 TEST_CASES_END() /**< NULL terminate unit test array */
8380         }
8381 };
8382
8383 static struct unit_test_suite cryptodev_null_testsuite  = {
8384         .suite_name = "Crypto Device NULL Unit Test Suite",
8385         .setup = testsuite_setup,
8386         .teardown = testsuite_teardown,
8387         .unit_test_cases = {
8388                 TEST_CASE_ST(ut_setup, ut_teardown,
8389                         test_null_auth_only_operation),
8390                 TEST_CASE_ST(ut_setup, ut_teardown,
8391                         test_null_cipher_only_operation),
8392                 TEST_CASE_ST(ut_setup, ut_teardown,
8393                         test_null_cipher_auth_operation),
8394                 TEST_CASE_ST(ut_setup, ut_teardown,
8395                         test_null_auth_cipher_operation),
8396                 TEST_CASE_ST(ut_setup, ut_teardown,
8397                         test_null_invalid_operation),
8398                 TEST_CASE_ST(ut_setup, ut_teardown,
8399                         test_null_burst_operation),
8400
8401                 TEST_CASES_END() /**< NULL terminate unit test array */
8402         }
8403 };
8404
8405 static struct unit_test_suite cryptodev_armv8_testsuite  = {
8406         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
8407         .setup = testsuite_setup,
8408         .teardown = testsuite_teardown,
8409         .unit_test_cases = {
8410                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
8411
8412                 /** Negative tests */
8413                 TEST_CASE_ST(ut_setup, ut_teardown,
8414                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8415                 TEST_CASE_ST(ut_setup, ut_teardown,
8416                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8417
8418                 TEST_CASES_END() /**< NULL terminate unit test array */
8419         }
8420 };
8421
8422 static int
8423 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
8424 {
8425         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
8426         return unit_test_suite_runner(&cryptodev_qat_testsuite);
8427 }
8428
8429 static int
8430 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
8431 {
8432         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
8433
8434         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
8435 }
8436
8437 static int
8438 test_cryptodev_openssl(void)
8439 {
8440         gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
8441
8442         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
8443 }
8444
8445 static int
8446 test_cryptodev_aesni_gcm(void)
8447 {
8448         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
8449
8450         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
8451 }
8452
8453 static int
8454 test_cryptodev_null(void)
8455 {
8456         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
8457
8458         return unit_test_suite_runner(&cryptodev_null_testsuite);
8459 }
8460
8461 static int
8462 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
8463 {
8464         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
8465
8466         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
8467 }
8468
8469 static int
8470 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
8471 {
8472         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
8473
8474         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
8475 }
8476
8477 static int
8478 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
8479 {
8480         gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
8481
8482         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
8483 }
8484
8485 static int
8486 test_cryptodev_armv8(void)
8487 {
8488         gbl_cryptodev_type = RTE_CRYPTODEV_ARMV8_PMD;
8489
8490         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
8491 }
8492
8493 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
8494
8495 static int
8496 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
8497 {
8498         gbl_cryptodev_type = RTE_CRYPTODEV_SCHEDULER_PMD;
8499         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
8500 }
8501
8502 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
8503
8504 #endif
8505
8506 static int
8507 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
8508 {
8509         gbl_cryptodev_type = RTE_CRYPTODEV_DPAA2_SEC_PMD;
8510         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
8511 }
8512
8513 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
8514 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
8515 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
8516 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
8517 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
8518 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
8519 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
8520 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
8521 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
8522 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);