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