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