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