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