crypto/aesni_gcm: test new features
[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_xforms(struct rte_crypto_op *op,
4321                 enum rte_crypto_cipher_operation cipher_op,
4322                 uint8_t *key, const uint8_t key_len,
4323                 const uint8_t aad_len, const uint8_t auth_len,
4324                 enum rte_crypto_auth_operation auth_op)
4325 {
4326         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 2),
4327                         "failed to allocate space for crypto transforms");
4328
4329         struct rte_crypto_sym_op *sym_op = op->sym;
4330
4331         /* Setup Cipher Parameters */
4332         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4333         sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4334         sym_op->xform->cipher.op = cipher_op;
4335         sym_op->xform->cipher.key.data = key;
4336         sym_op->xform->cipher.key.length = key_len;
4337
4338         TEST_HEXDUMP(stdout, "key:", key, key_len);
4339
4340         /* Setup Authentication Parameters */
4341         sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4342         sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
4343         sym_op->xform->next->auth.op = auth_op;
4344         sym_op->xform->next->auth.digest_length = auth_len;
4345         sym_op->xform->next->auth.add_auth_data_length = aad_len;
4346         sym_op->xform->next->auth.key.length = 0;
4347         sym_op->xform->next->auth.key.data = NULL;
4348         sym_op->xform->next->next = NULL;
4349
4350         return 0;
4351 }
4352
4353 static int
4354 create_gcm_operation(enum rte_crypto_cipher_operation op,
4355                 const struct gcm_test_data *tdata)
4356 {
4357         struct crypto_testsuite_params *ts_params = &testsuite_params;
4358         struct crypto_unittest_params *ut_params = &unittest_params;
4359
4360         uint8_t *plaintext, *ciphertext;
4361         unsigned int iv_pad_len, aad_pad_len, plaintext_pad_len;
4362
4363         /* Generate Crypto op data structure */
4364         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4365                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4366         TEST_ASSERT_NOT_NULL(ut_params->op,
4367                         "Failed to allocate symmetric crypto operation struct");
4368
4369         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4370
4371         /* Append aad data */
4372         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4373         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4374                         aad_pad_len);
4375         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4376                         "no room to append aad");
4377
4378         sym_op->auth.aad.length = tdata->aad.len;
4379         sym_op->auth.aad.phys_addr =
4380                         rte_pktmbuf_mtophys(ut_params->ibuf);
4381         memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
4382         TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data,
4383                 sym_op->auth.aad.length);
4384
4385         /* Prepend iv */
4386         iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
4387         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4388                         ut_params->ibuf, iv_pad_len);
4389         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4390
4391         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4392         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4393         sym_op->cipher.iv.length = tdata->iv.len;
4394
4395         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
4396         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data,
4397                 sym_op->cipher.iv.length);
4398
4399         /* Append plaintext/ciphertext */
4400         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4401                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4402                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4403                                 plaintext_pad_len);
4404                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
4405
4406                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4407                 TEST_HEXDUMP(stdout, "plaintext:", plaintext,
4408                                 tdata->plaintext.len);
4409
4410                 if (ut_params->obuf) {
4411                         ciphertext = (uint8_t *)rte_pktmbuf_append(
4412                                         ut_params->obuf,
4413                                         plaintext_pad_len + aad_pad_len +
4414                                         iv_pad_len);
4415                         TEST_ASSERT_NOT_NULL(ciphertext,
4416                                         "no room to append ciphertext");
4417
4418                         memset(ciphertext + aad_pad_len + iv_pad_len, 0,
4419                                         tdata->ciphertext.len);
4420                 }
4421         } else {
4422                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4423                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4424                                 plaintext_pad_len);
4425                 TEST_ASSERT_NOT_NULL(ciphertext,
4426                                 "no room to append ciphertext");
4427
4428                 memcpy(ciphertext, tdata->ciphertext.data,
4429                                 tdata->ciphertext.len);
4430                 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext,
4431                                 tdata->ciphertext.len);
4432
4433                 if (ut_params->obuf) {
4434                         plaintext = (uint8_t *)rte_pktmbuf_append(
4435                                         ut_params->obuf,
4436                                         plaintext_pad_len + aad_pad_len +
4437                                         iv_pad_len);
4438                         TEST_ASSERT_NOT_NULL(plaintext,
4439                                         "no room to append plaintext");
4440
4441                         memset(plaintext + aad_pad_len + iv_pad_len, 0,
4442                                         tdata->plaintext.len);
4443                 }
4444         }
4445
4446         /* Append digest data */
4447         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4448                 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4449                                 ut_params->obuf ? ut_params->obuf :
4450                                                 ut_params->ibuf,
4451                                                 tdata->auth_tag.len);
4452                 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4453                                 "no room to append digest");
4454                 memset(sym_op->auth.digest.data, 0, tdata->auth_tag.len);
4455                 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4456                                 ut_params->obuf ? ut_params->obuf :
4457                                                 ut_params->ibuf,
4458                                                 plaintext_pad_len +
4459                                                 aad_pad_len + iv_pad_len);
4460                 sym_op->auth.digest.length = tdata->auth_tag.len;
4461         } else {
4462                 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4463                                 ut_params->ibuf, tdata->auth_tag.len);
4464                 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4465                                 "no room to append digest");
4466                 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4467                                 ut_params->ibuf,
4468                                 plaintext_pad_len + aad_pad_len + iv_pad_len);
4469                 sym_op->auth.digest.length = tdata->auth_tag.len;
4470
4471                 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
4472                         tdata->auth_tag.len);
4473                 TEST_HEXDUMP(stdout, "digest:",
4474                         sym_op->auth.digest.data,
4475                         sym_op->auth.digest.length);
4476         }
4477
4478         sym_op->cipher.data.length = tdata->plaintext.len;
4479         sym_op->cipher.data.offset = aad_pad_len + iv_pad_len;
4480
4481         sym_op->auth.data.length = tdata->plaintext.len;
4482         sym_op->auth.data.offset = aad_pad_len + iv_pad_len;
4483
4484         return 0;
4485 }
4486
4487 static int
4488 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
4489 {
4490         struct crypto_testsuite_params *ts_params = &testsuite_params;
4491         struct crypto_unittest_params *ut_params = &unittest_params;
4492
4493         int retval;
4494         uint8_t *ciphertext, *auth_tag;
4495         uint16_t plaintext_pad_len;
4496         uint32_t i;
4497
4498         /* Create GCM session */
4499         retval = create_gcm_session(ts_params->valid_devs[0],
4500                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4501                         tdata->key.data, tdata->key.len,
4502                         tdata->aad.len, tdata->auth_tag.len,
4503                         RTE_CRYPTO_AUTH_OP_GENERATE);
4504         if (retval < 0)
4505                 return retval;
4506
4507         if (tdata->aad.len > MBUF_SIZE) {
4508                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
4509                 /* Populate full size of add data */
4510                 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
4511                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
4512         } else
4513                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4514
4515         /* clear mbuf payload */
4516         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4517                         rte_pktmbuf_tailroom(ut_params->ibuf));
4518
4519         /* Create GCM operation */
4520         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
4521         if (retval < 0)
4522                 return retval;
4523
4524         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4525
4526         ut_params->op->sym->m_src = ut_params->ibuf;
4527
4528         /* Process crypto operation */
4529         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4530                         ut_params->op), "failed to process sym crypto op");
4531
4532         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4533                         "crypto op processing failed");
4534
4535         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4536
4537         if (ut_params->op->sym->m_dst) {
4538                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4539                                 uint8_t *);
4540                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4541                                 uint8_t *, plaintext_pad_len);
4542         } else {
4543                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
4544                                 uint8_t *,
4545                                 ut_params->op->sym->cipher.data.offset);
4546                 auth_tag = ciphertext + plaintext_pad_len;
4547         }
4548
4549         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4550         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4551
4552         /* Validate obuf */
4553         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4554                         ciphertext,
4555                         tdata->ciphertext.data,
4556                         tdata->ciphertext.len,
4557                         "GCM Ciphertext data not as expected");
4558
4559         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4560                         auth_tag,
4561                         tdata->auth_tag.data,
4562                         tdata->auth_tag.len,
4563                         "GCM Generated auth tag not as expected");
4564
4565         return 0;
4566
4567 }
4568
4569 static int
4570 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
4571 {
4572         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
4573 }
4574
4575 static int
4576 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
4577 {
4578         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
4579 }
4580
4581 static int
4582 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
4583 {
4584         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
4585 }
4586
4587 static int
4588 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
4589 {
4590         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
4591 }
4592
4593 static int
4594 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
4595 {
4596         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
4597 }
4598
4599 static int
4600 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
4601 {
4602         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
4603 }
4604
4605 static int
4606 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
4607 {
4608         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
4609 }
4610
4611 static int
4612 test_mb_AES_GCM_auth_encryption_test_case_256_1(void)
4613 {
4614         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_1);
4615 }
4616
4617 static int
4618 test_mb_AES_GCM_auth_encryption_test_case_256_2(void)
4619 {
4620         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_2);
4621 }
4622
4623 static int
4624 test_mb_AES_GCM_auth_encryption_test_case_256_3(void)
4625 {
4626         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_3);
4627 }
4628
4629 static int
4630 test_mb_AES_GCM_auth_encryption_test_case_256_4(void)
4631 {
4632         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_4);
4633 }
4634
4635 static int
4636 test_mb_AES_GCM_auth_encryption_test_case_256_5(void)
4637 {
4638         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_5);
4639 }
4640
4641 static int
4642 test_mb_AES_GCM_auth_encryption_test_case_256_6(void)
4643 {
4644         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_6);
4645 }
4646
4647 static int
4648 test_mb_AES_GCM_auth_encryption_test_case_256_7(void)
4649 {
4650         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_7);
4651 }
4652
4653 static int
4654 test_mb_AES_GCM_auth_encryption_test_case_aad_1(void)
4655 {
4656         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1);
4657 }
4658
4659 static int
4660 test_mb_AES_GCM_auth_encryption_test_case_aad_2(void)
4661 {
4662         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2);
4663 }
4664
4665 static int
4666 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
4667 {
4668         struct crypto_testsuite_params *ts_params = &testsuite_params;
4669         struct crypto_unittest_params *ut_params = &unittest_params;
4670
4671         int retval;
4672         uint8_t *plaintext;
4673         uint32_t i;
4674
4675         /* Create GCM session */
4676         retval = create_gcm_session(ts_params->valid_devs[0],
4677                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4678                         tdata->key.data, tdata->key.len,
4679                         tdata->aad.len, tdata->auth_tag.len,
4680                         RTE_CRYPTO_AUTH_OP_VERIFY);
4681         if (retval < 0)
4682                 return retval;
4683
4684         /* alloc mbuf and set payload */
4685         if (tdata->aad.len > MBUF_SIZE) {
4686                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
4687                 /* Populate full size of add data */
4688                 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
4689                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
4690         } else
4691                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4692
4693         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4694                         rte_pktmbuf_tailroom(ut_params->ibuf));
4695
4696         /* Create GCM operation */
4697         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
4698         if (retval < 0)
4699                 return retval;
4700
4701         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4702
4703         ut_params->op->sym->m_src = ut_params->ibuf;
4704
4705         /* Process crypto operation */
4706         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4707                         ut_params->op), "failed to process sym crypto op");
4708
4709         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4710                         "crypto op processing failed");
4711
4712         if (ut_params->op->sym->m_dst)
4713                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4714                                 uint8_t *);
4715         else
4716                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
4717                                 uint8_t *,
4718                                 ut_params->op->sym->cipher.data.offset);
4719
4720         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
4721
4722         /* Validate obuf */
4723         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4724                         plaintext,
4725                         tdata->plaintext.data,
4726                         tdata->plaintext.len,
4727                         "GCM plaintext data not as expected");
4728
4729         TEST_ASSERT_EQUAL(ut_params->op->status,
4730                         RTE_CRYPTO_OP_STATUS_SUCCESS,
4731                         "GCM authentication failed");
4732         return 0;
4733 }
4734
4735 static int
4736 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
4737 {
4738         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
4739 }
4740
4741 static int
4742 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
4743 {
4744         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
4745 }
4746
4747 static int
4748 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
4749 {
4750         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
4751 }
4752
4753 static int
4754 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
4755 {
4756         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
4757 }
4758
4759 static int
4760 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
4761 {
4762         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
4763 }
4764
4765 static int
4766 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
4767 {
4768         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
4769 }
4770
4771 static int
4772 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
4773 {
4774         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
4775 }
4776
4777 static int
4778 test_mb_AES_GCM_auth_decryption_test_case_256_1(void)
4779 {
4780         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_1);
4781 }
4782
4783 static int
4784 test_mb_AES_GCM_auth_decryption_test_case_256_2(void)
4785 {
4786         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_2);
4787 }
4788
4789 static int
4790 test_mb_AES_GCM_auth_decryption_test_case_256_3(void)
4791 {
4792         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_3);
4793 }
4794
4795 static int
4796 test_mb_AES_GCM_auth_decryption_test_case_256_4(void)
4797 {
4798         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_4);
4799 }
4800
4801 static int
4802 test_mb_AES_GCM_auth_decryption_test_case_256_5(void)
4803 {
4804         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_5);
4805 }
4806
4807 static int
4808 test_mb_AES_GCM_auth_decryption_test_case_256_6(void)
4809 {
4810         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_6);
4811 }
4812
4813 static int
4814 test_mb_AES_GCM_auth_decryption_test_case_256_7(void)
4815 {
4816         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_7);
4817 }
4818
4819 static int
4820 test_mb_AES_GCM_auth_decryption_test_case_aad_1(void)
4821 {
4822         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1);
4823 }
4824
4825 static int
4826 test_mb_AES_GCM_auth_decryption_test_case_aad_2(void)
4827 {
4828         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2);
4829 }
4830
4831 static int
4832 test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata)
4833 {
4834         struct crypto_testsuite_params *ts_params = &testsuite_params;
4835         struct crypto_unittest_params *ut_params = &unittest_params;
4836
4837         int retval;
4838         uint8_t *ciphertext, *auth_tag;
4839         uint16_t plaintext_pad_len;
4840
4841         /* Create GCM session */
4842         retval = create_gcm_session(ts_params->valid_devs[0],
4843                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4844                         tdata->key.data, tdata->key.len,
4845                         tdata->aad.len, tdata->auth_tag.len,
4846                         RTE_CRYPTO_AUTH_OP_GENERATE);
4847         if (retval < 0)
4848                 return retval;
4849
4850         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4851         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4852
4853         /* clear mbuf payload */
4854         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4855                         rte_pktmbuf_tailroom(ut_params->ibuf));
4856         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4857                         rte_pktmbuf_tailroom(ut_params->obuf));
4858
4859         /* Create GCM operation */
4860         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
4861         if (retval < 0)
4862                 return retval;
4863
4864         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4865
4866         ut_params->op->sym->m_src = ut_params->ibuf;
4867         ut_params->op->sym->m_dst = ut_params->obuf;
4868
4869         /* Process crypto operation */
4870         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4871                         ut_params->op), "failed to process sym crypto op");
4872
4873         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4874                         "crypto op processing failed");
4875
4876         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4877
4878         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4879                         ut_params->op->sym->cipher.data.offset);
4880         auth_tag = ciphertext + plaintext_pad_len;
4881
4882         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4883         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4884
4885         /* Validate obuf */
4886         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4887                         ciphertext,
4888                         tdata->ciphertext.data,
4889                         tdata->ciphertext.len,
4890                         "GCM Ciphertext data not as expected");
4891
4892         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4893                         auth_tag,
4894                         tdata->auth_tag.data,
4895                         tdata->auth_tag.len,
4896                         "GCM Generated auth tag not as expected");
4897
4898         return 0;
4899
4900 }
4901
4902 static int
4903 test_mb_AES_GCM_authenticated_encryption_oop(void)
4904 {
4905         return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5);
4906 }
4907
4908 static int
4909 test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata)
4910 {
4911         struct crypto_testsuite_params *ts_params = &testsuite_params;
4912         struct crypto_unittest_params *ut_params = &unittest_params;
4913
4914         int retval;
4915         uint8_t *plaintext;
4916
4917         /* Create GCM session */
4918         retval = create_gcm_session(ts_params->valid_devs[0],
4919                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4920                         tdata->key.data, tdata->key.len,
4921                         tdata->aad.len, tdata->auth_tag.len,
4922                         RTE_CRYPTO_AUTH_OP_VERIFY);
4923         if (retval < 0)
4924                 return retval;
4925
4926         /* alloc mbuf and set payload */
4927         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4928         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4929
4930         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4931                         rte_pktmbuf_tailroom(ut_params->ibuf));
4932         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4933                         rte_pktmbuf_tailroom(ut_params->obuf));
4934
4935         /* Create GCM operation */
4936         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
4937         if (retval < 0)
4938                 return retval;
4939
4940         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4941
4942         ut_params->op->sym->m_src = ut_params->ibuf;
4943         ut_params->op->sym->m_dst = ut_params->obuf;
4944
4945         /* Process crypto operation */
4946         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4947                         ut_params->op), "failed to process sym crypto op");
4948
4949         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4950                         "crypto op processing failed");
4951
4952         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4953                         ut_params->op->sym->cipher.data.offset);
4954
4955         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
4956
4957         /* Validate obuf */
4958         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4959                         plaintext,
4960                         tdata->plaintext.data,
4961                         tdata->plaintext.len,
4962                         "GCM plaintext data not as expected");
4963
4964         TEST_ASSERT_EQUAL(ut_params->op->status,
4965                         RTE_CRYPTO_OP_STATUS_SUCCESS,
4966                         "GCM authentication failed");
4967         return 0;
4968 }
4969
4970 static int
4971 test_mb_AES_GCM_authenticated_decryption_oop(void)
4972 {
4973         return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5);
4974 }
4975
4976 static int
4977 test_AES_GCM_authenticated_encryption_sessionless(
4978                 const struct gcm_test_data *tdata)
4979 {
4980         struct crypto_testsuite_params *ts_params = &testsuite_params;
4981         struct crypto_unittest_params *ut_params = &unittest_params;
4982
4983         int retval;
4984         uint8_t *ciphertext, *auth_tag;
4985         uint16_t plaintext_pad_len;
4986         uint8_t key[tdata->key.len + 1];
4987
4988         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4989
4990         /* clear mbuf payload */
4991         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4992                         rte_pktmbuf_tailroom(ut_params->ibuf));
4993
4994         /* Create GCM operation */
4995         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
4996         if (retval < 0)
4997                 return retval;
4998
4999         /* Create GCM xforms */
5000         memcpy(key, tdata->key.data, tdata->key.len);
5001         retval = create_gcm_xforms(ut_params->op,
5002                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5003                         key, tdata->key.len,
5004                         tdata->aad.len, tdata->auth_tag.len,
5005                         RTE_CRYPTO_AUTH_OP_GENERATE);
5006         if (retval < 0)
5007                 return retval;
5008
5009         ut_params->op->sym->m_src = ut_params->ibuf;
5010
5011         TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
5012                         RTE_CRYPTO_SYM_OP_SESSIONLESS,
5013                         "crypto op session type not sessionless");
5014
5015         /* Process crypto operation */
5016         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5017                         ut_params->op), "failed to process sym crypto op");
5018
5019         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5020
5021         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5022                         "crypto op status not success");
5023
5024         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5025
5026         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5027                         ut_params->op->sym->cipher.data.offset);
5028         auth_tag = ciphertext + plaintext_pad_len;
5029
5030         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5031         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5032
5033         /* Validate obuf */
5034         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5035                         ciphertext,
5036                         tdata->ciphertext.data,
5037                         tdata->ciphertext.len,
5038                         "GCM Ciphertext data not as expected");
5039
5040         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5041                         auth_tag,
5042                         tdata->auth_tag.data,
5043                         tdata->auth_tag.len,
5044                         "GCM Generated auth tag not as expected");
5045
5046         return 0;
5047
5048 }
5049
5050 static int
5051 test_mb_AES_GCM_authenticated_encryption_sessionless(void)
5052 {
5053         return test_AES_GCM_authenticated_encryption_sessionless(
5054                         &gcm_test_case_5);
5055 }
5056
5057 static int
5058 test_AES_GCM_authenticated_decryption_sessionless(
5059                 const struct gcm_test_data *tdata)
5060 {
5061         struct crypto_testsuite_params *ts_params = &testsuite_params;
5062         struct crypto_unittest_params *ut_params = &unittest_params;
5063
5064         int retval;
5065         uint8_t *plaintext;
5066         uint8_t key[tdata->key.len + 1];
5067
5068         /* alloc mbuf and set payload */
5069         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5070
5071         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5072                         rte_pktmbuf_tailroom(ut_params->ibuf));
5073
5074         /* Create GCM operation */
5075         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
5076         if (retval < 0)
5077                 return retval;
5078
5079         /* Create GCM xforms */
5080         memcpy(key, tdata->key.data, tdata->key.len);
5081         retval = create_gcm_xforms(ut_params->op,
5082                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
5083                         key, tdata->key.len,
5084                         tdata->aad.len, tdata->auth_tag.len,
5085                         RTE_CRYPTO_AUTH_OP_VERIFY);
5086         if (retval < 0)
5087                 return retval;
5088
5089         ut_params->op->sym->m_src = ut_params->ibuf;
5090
5091         TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
5092                         RTE_CRYPTO_SYM_OP_SESSIONLESS,
5093                         "crypto op session type not sessionless");
5094
5095         /* Process crypto operation */
5096         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5097                         ut_params->op), "failed to process sym crypto op");
5098
5099         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5100
5101         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5102                         "crypto op status not success");
5103
5104         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5105                         ut_params->op->sym->cipher.data.offset);
5106
5107         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5108
5109         /* Validate obuf */
5110         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5111                         plaintext,
5112                         tdata->plaintext.data,
5113                         tdata->plaintext.len,
5114                         "GCM plaintext data not as expected");
5115
5116         TEST_ASSERT_EQUAL(ut_params->op->status,
5117                         RTE_CRYPTO_OP_STATUS_SUCCESS,
5118                         "GCM authentication failed");
5119         return 0;
5120 }
5121
5122 static int
5123 test_mb_AES_GCM_authenticated_decryption_sessionless(void)
5124 {
5125         return test_AES_GCM_authenticated_decryption_sessionless(
5126                         &gcm_test_case_5);
5127 }
5128
5129 static int
5130 test_stats(void)
5131 {
5132         struct crypto_testsuite_params *ts_params = &testsuite_params;
5133         struct rte_cryptodev_stats stats;
5134         struct rte_cryptodev *dev;
5135         cryptodev_stats_get_t temp_pfn;
5136
5137         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5138         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
5139                         &stats) == -ENODEV),
5140                 "rte_cryptodev_stats_get invalid dev failed");
5141         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
5142                 "rte_cryptodev_stats_get invalid Param failed");
5143         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
5144         temp_pfn = dev->dev_ops->stats_get;
5145         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
5146         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
5147                         == -ENOTSUP),
5148                 "rte_cryptodev_stats_get invalid Param failed");
5149         dev->dev_ops->stats_get = temp_pfn;
5150
5151         /* Test expected values */
5152         ut_setup();
5153         test_AES_CBC_HMAC_SHA1_encrypt_digest();
5154         ut_teardown();
5155         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5156                         &stats),
5157                 "rte_cryptodev_stats_get failed");
5158         TEST_ASSERT((stats.enqueued_count == 1),
5159                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5160         TEST_ASSERT((stats.dequeued_count == 1),
5161                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5162         TEST_ASSERT((stats.enqueue_err_count == 0),
5163                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5164         TEST_ASSERT((stats.dequeue_err_count == 0),
5165                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5166
5167         /* invalid device but should ignore and not reset device stats*/
5168         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
5169         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5170                         &stats),
5171                 "rte_cryptodev_stats_get failed");
5172         TEST_ASSERT((stats.enqueued_count == 1),
5173                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5174
5175         /* check that a valid reset clears stats */
5176         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5177         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5178                         &stats),
5179                                           "rte_cryptodev_stats_get failed");
5180         TEST_ASSERT((stats.enqueued_count == 0),
5181                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5182         TEST_ASSERT((stats.dequeued_count == 0),
5183                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5184
5185         return TEST_SUCCESS;
5186 }
5187
5188 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
5189                                    struct crypto_unittest_params *ut_params,
5190                                    enum rte_crypto_auth_operation op,
5191                                    const struct HMAC_MD5_vector *test_case)
5192 {
5193         uint8_t key[64];
5194
5195         memcpy(key, test_case->key.data, test_case->key.len);
5196
5197         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5198         ut_params->auth_xform.next = NULL;
5199         ut_params->auth_xform.auth.op = op;
5200
5201         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
5202
5203         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
5204         ut_params->auth_xform.auth.add_auth_data_length = 0;
5205         ut_params->auth_xform.auth.key.length = test_case->key.len;
5206         ut_params->auth_xform.auth.key.data = key;
5207
5208         ut_params->sess = rte_cryptodev_sym_session_create(
5209                 ts_params->valid_devs[0], &ut_params->auth_xform);
5210
5211         if (ut_params->sess == NULL)
5212                 return TEST_FAILED;
5213
5214         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5215
5216         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5217                         rte_pktmbuf_tailroom(ut_params->ibuf));
5218
5219         return 0;
5220 }
5221
5222 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
5223                               const struct HMAC_MD5_vector *test_case,
5224                               uint8_t **plaintext)
5225 {
5226         uint16_t plaintext_pad_len;
5227
5228         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5229
5230         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5231                                 16);
5232
5233         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5234                         plaintext_pad_len);
5235         memcpy(*plaintext, test_case->plaintext.data,
5236                         test_case->plaintext.len);
5237
5238         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5239                         ut_params->ibuf, MD5_DIGEST_LEN);
5240         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5241                         "no room to append digest");
5242         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5243                         ut_params->ibuf, plaintext_pad_len);
5244         sym_op->auth.digest.length = MD5_DIGEST_LEN;
5245
5246         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5247                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
5248                            test_case->auth_tag.len);
5249         }
5250
5251         sym_op->auth.data.offset = 0;
5252         sym_op->auth.data.length = test_case->plaintext.len;
5253
5254         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5255         ut_params->op->sym->m_src = ut_params->ibuf;
5256
5257         return 0;
5258 }
5259
5260 static int
5261 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
5262 {
5263         uint16_t plaintext_pad_len;
5264         uint8_t *plaintext, *auth_tag;
5265
5266         struct crypto_testsuite_params *ts_params = &testsuite_params;
5267         struct crypto_unittest_params *ut_params = &unittest_params;
5268
5269         if (MD5_HMAC_create_session(ts_params, ut_params,
5270                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
5271                 return TEST_FAILED;
5272
5273         /* Generate Crypto op data structure */
5274         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5275                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5276         TEST_ASSERT_NOT_NULL(ut_params->op,
5277                         "Failed to allocate symmetric crypto operation struct");
5278
5279         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5280                                 16);
5281
5282         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5283                 return TEST_FAILED;
5284
5285         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5286                         ut_params->op), "failed to process sym crypto op");
5287
5288         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5289                         "crypto op processing failed");
5290
5291         if (ut_params->op->sym->m_dst) {
5292                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5293                                 uint8_t *, plaintext_pad_len);
5294         } else {
5295                 auth_tag = plaintext + plaintext_pad_len;
5296         }
5297
5298         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5299                         auth_tag,
5300                         test_case->auth_tag.data,
5301                         test_case->auth_tag.len,
5302                         "HMAC_MD5 generated tag not as expected");
5303
5304         return TEST_SUCCESS;
5305 }
5306
5307 static int
5308 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
5309 {
5310         uint8_t *plaintext;
5311
5312         struct crypto_testsuite_params *ts_params = &testsuite_params;
5313         struct crypto_unittest_params *ut_params = &unittest_params;
5314
5315         if (MD5_HMAC_create_session(ts_params, ut_params,
5316                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
5317                 return TEST_FAILED;
5318         }
5319
5320         /* Generate Crypto op data structure */
5321         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5322                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5323         TEST_ASSERT_NOT_NULL(ut_params->op,
5324                         "Failed to allocate symmetric crypto operation struct");
5325
5326         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5327                 return TEST_FAILED;
5328
5329         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5330                         ut_params->op), "failed to process sym crypto op");
5331
5332         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5333                         "HMAC_MD5 crypto op processing failed");
5334
5335         return TEST_SUCCESS;
5336 }
5337
5338 static int
5339 test_MD5_HMAC_generate_case_1(void)
5340 {
5341         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
5342 }
5343
5344 static int
5345 test_MD5_HMAC_verify_case_1(void)
5346 {
5347         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
5348 }
5349
5350 static int
5351 test_MD5_HMAC_generate_case_2(void)
5352 {
5353         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
5354 }
5355
5356 static int
5357 test_MD5_HMAC_verify_case_2(void)
5358 {
5359         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
5360 }
5361
5362 static int
5363 test_multi_session(void)
5364 {
5365         struct crypto_testsuite_params *ts_params = &testsuite_params;
5366         struct crypto_unittest_params *ut_params = &unittest_params;
5367
5368         struct rte_cryptodev_info dev_info;
5369         struct rte_cryptodev_sym_session **sessions;
5370
5371         uint16_t i;
5372
5373         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
5374                         aes_cbc_key, hmac_sha512_key);
5375
5376
5377         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5378
5379         sessions = rte_malloc(NULL,
5380                         (sizeof(struct rte_cryptodev_sym_session *) *
5381                         dev_info.sym.max_nb_sessions) + 1, 0);
5382
5383         /* Create multiple crypto sessions*/
5384         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
5385                 sessions[i] = rte_cryptodev_sym_session_create(
5386                                 ts_params->valid_devs[0],
5387                         &ut_params->auth_xform);
5388                 TEST_ASSERT_NOT_NULL(sessions[i],
5389                                 "Session creation failed at session number %u",
5390                                 i);
5391
5392                 /* Attempt to send a request on each session */
5393                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
5394                         sessions[i],
5395                         ut_params,
5396                         ts_params,
5397                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
5398                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
5399                         aes_cbc_iv),
5400                         "Failed to perform decrypt on request number %u.", i);
5401                 /* free crypto operation structure */
5402                 if (ut_params->op)
5403                         rte_crypto_op_free(ut_params->op);
5404
5405                 /*
5406                  * free mbuf - both obuf and ibuf are usually the same,
5407                  * so check if they point at the same address is necessary,
5408                  * to avoid freeing the mbuf twice.
5409                  */
5410                 if (ut_params->obuf) {
5411                         rte_pktmbuf_free(ut_params->obuf);
5412                         if (ut_params->ibuf == ut_params->obuf)
5413                                 ut_params->ibuf = 0;
5414                         ut_params->obuf = 0;
5415                 }
5416                 if (ut_params->ibuf) {
5417                         rte_pktmbuf_free(ut_params->ibuf);
5418                         ut_params->ibuf = 0;
5419                 }
5420         }
5421
5422         /* Next session create should fail */
5423         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
5424                         &ut_params->auth_xform);
5425         TEST_ASSERT_NULL(sessions[i],
5426                         "Session creation succeeded unexpectedly!");
5427
5428         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
5429                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5430                                 sessions[i]);
5431
5432         rte_free(sessions);
5433
5434         return TEST_SUCCESS;
5435 }
5436
5437 struct multi_session_params {
5438         struct crypto_unittest_params ut_params;
5439         uint8_t *cipher_key;
5440         uint8_t *hmac_key;
5441         const uint8_t *cipher;
5442         const uint8_t *digest;
5443         uint8_t *iv;
5444 };
5445
5446 #define MB_SESSION_NUMBER 3
5447
5448 static int
5449 test_multi_session_random_usage(void)
5450 {
5451         struct crypto_testsuite_params *ts_params = &testsuite_params;
5452         struct rte_cryptodev_info dev_info;
5453         struct rte_cryptodev_sym_session **sessions;
5454         uint32_t i, j;
5455         struct multi_session_params ut_paramz[] = {
5456
5457                 {
5458                         .cipher_key = ms_aes_cbc_key0,
5459                         .hmac_key = ms_hmac_key0,
5460                         .cipher = ms_aes_cbc_cipher0,
5461                         .digest = ms_hmac_digest0,
5462                         .iv = ms_aes_cbc_iv0
5463                 },
5464                 {
5465                         .cipher_key = ms_aes_cbc_key1,
5466                         .hmac_key = ms_hmac_key1,
5467                         .cipher = ms_aes_cbc_cipher1,
5468                         .digest = ms_hmac_digest1,
5469                         .iv = ms_aes_cbc_iv1
5470                 },
5471                 {
5472                         .cipher_key = ms_aes_cbc_key2,
5473                         .hmac_key = ms_hmac_key2,
5474                         .cipher = ms_aes_cbc_cipher2,
5475                         .digest = ms_hmac_digest2,
5476                         .iv = ms_aes_cbc_iv2
5477                 },
5478
5479         };
5480
5481         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5482
5483         sessions = rte_malloc(NULL,
5484                         (sizeof(struct rte_cryptodev_sym_session *)
5485                                         * dev_info.sym.max_nb_sessions) + 1, 0);
5486
5487         for (i = 0; i < MB_SESSION_NUMBER; i++) {
5488                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
5489                                 sizeof(struct crypto_unittest_params));
5490
5491                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
5492                                 &ut_paramz[i].ut_params,
5493                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
5494
5495                 /* Create multiple crypto sessions*/
5496                 sessions[i] = rte_cryptodev_sym_session_create(
5497                                 ts_params->valid_devs[0],
5498                                 &ut_paramz[i].ut_params.auth_xform);
5499
5500                 TEST_ASSERT_NOT_NULL(sessions[i],
5501                                 "Session creation failed at session number %u",
5502                                 i);
5503
5504         }
5505
5506         srand(time(NULL));
5507         for (i = 0; i < 40000; i++) {
5508
5509                 j = rand() % MB_SESSION_NUMBER;
5510
5511                 TEST_ASSERT_SUCCESS(
5512                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
5513                                         sessions[j],
5514                                         &ut_paramz[j].ut_params,
5515                                         ts_params, ut_paramz[j].cipher,
5516                                         ut_paramz[j].digest,
5517                                         ut_paramz[j].iv),
5518                         "Failed to perform decrypt on request number %u.", i);
5519
5520                 if (ut_paramz[j].ut_params.op)
5521                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
5522
5523                 /*
5524                  * free mbuf - both obuf and ibuf are usually the same,
5525                  * so check if they point at the same address is necessary,
5526                  * to avoid freeing the mbuf twice.
5527                  */
5528                 if (ut_paramz[j].ut_params.obuf) {
5529                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
5530                         if (ut_paramz[j].ut_params.ibuf
5531                                         == ut_paramz[j].ut_params.obuf)
5532                                 ut_paramz[j].ut_params.ibuf = 0;
5533                         ut_paramz[j].ut_params.obuf = 0;
5534                 }
5535                 if (ut_paramz[j].ut_params.ibuf) {
5536                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
5537                         ut_paramz[j].ut_params.ibuf = 0;
5538                 }
5539         }
5540
5541         for (i = 0; i < MB_SESSION_NUMBER; i++)
5542                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5543                                 sessions[i]);
5544
5545         rte_free(sessions);
5546
5547         return TEST_SUCCESS;
5548 }
5549
5550 static int
5551 test_null_cipher_only_operation(void)
5552 {
5553         struct crypto_testsuite_params *ts_params = &testsuite_params;
5554         struct crypto_unittest_params *ut_params = &unittest_params;
5555
5556         /* Generate test mbuf data and space for digest */
5557         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5558                         catch_22_quote, QUOTE_512_BYTES, 0);
5559
5560         /* Setup Cipher Parameters */
5561         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5562         ut_params->cipher_xform.next = NULL;
5563
5564         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5565         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5566
5567         /* Create Crypto session*/
5568         ut_params->sess = rte_cryptodev_sym_session_create(
5569                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5570         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5571
5572         /* Generate Crypto op data structure */
5573         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5574                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5575         TEST_ASSERT_NOT_NULL(ut_params->op,
5576                         "Failed to allocate symmetric crypto operation struct");
5577
5578         /* Set crypto operation data parameters */
5579         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5580
5581         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5582
5583         /* set crypto operation source mbuf */
5584         sym_op->m_src = ut_params->ibuf;
5585
5586         sym_op->cipher.data.offset = 0;
5587         sym_op->cipher.data.length = QUOTE_512_BYTES;
5588
5589         /* Process crypto operation */
5590         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5591                         ut_params->op);
5592         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5593
5594         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5595                         "crypto operation processing failed");
5596
5597         /* Validate obuf */
5598         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5599                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5600                         catch_22_quote,
5601                         QUOTE_512_BYTES,
5602                         "Ciphertext data not as expected");
5603
5604         return TEST_SUCCESS;
5605 }
5606
5607 static int
5608 test_null_auth_only_operation(void)
5609 {
5610         struct crypto_testsuite_params *ts_params = &testsuite_params;
5611         struct crypto_unittest_params *ut_params = &unittest_params;
5612
5613         /* Generate test mbuf data and space for digest */
5614         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5615                         catch_22_quote, QUOTE_512_BYTES, 0);
5616
5617         /* Setup HMAC Parameters */
5618         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5619         ut_params->auth_xform.next = NULL;
5620
5621         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5622         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5623
5624         /* Create Crypto session*/
5625         ut_params->sess = rte_cryptodev_sym_session_create(
5626                         ts_params->valid_devs[0], &ut_params->auth_xform);
5627         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5628
5629         /* Generate Crypto op data structure */
5630         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5631                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5632         TEST_ASSERT_NOT_NULL(ut_params->op,
5633                         "Failed to allocate symmetric crypto operation struct");
5634
5635         /* Set crypto operation data parameters */
5636         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5637
5638         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5639
5640         sym_op->m_src = ut_params->ibuf;
5641
5642         sym_op->auth.data.offset = 0;
5643         sym_op->auth.data.length = QUOTE_512_BYTES;
5644
5645         /* Process crypto operation */
5646         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5647                         ut_params->op);
5648         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5649
5650         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5651                         "crypto operation processing failed");
5652
5653         return TEST_SUCCESS;
5654 }
5655
5656 static int
5657 test_null_cipher_auth_operation(void)
5658 {
5659         struct crypto_testsuite_params *ts_params = &testsuite_params;
5660         struct crypto_unittest_params *ut_params = &unittest_params;
5661
5662         /* Generate test mbuf data and space for digest */
5663         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5664                         catch_22_quote, QUOTE_512_BYTES, 0);
5665
5666         /* Setup Cipher Parameters */
5667         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5668         ut_params->cipher_xform.next = &ut_params->auth_xform;
5669
5670         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5671         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5672
5673         /* Setup HMAC Parameters */
5674         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5675         ut_params->auth_xform.next = NULL;
5676
5677         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5678         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5679
5680         /* Create Crypto session*/
5681         ut_params->sess = rte_cryptodev_sym_session_create(
5682                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5683         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5684
5685         /* Generate Crypto op data structure */
5686         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5687                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5688         TEST_ASSERT_NOT_NULL(ut_params->op,
5689                         "Failed to allocate symmetric crypto operation struct");
5690
5691         /* Set crypto operation data parameters */
5692         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5693
5694         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5695
5696         sym_op->m_src = ut_params->ibuf;
5697
5698         sym_op->cipher.data.offset = 0;
5699         sym_op->cipher.data.length = QUOTE_512_BYTES;
5700
5701         sym_op->auth.data.offset = 0;
5702         sym_op->auth.data.length = QUOTE_512_BYTES;
5703
5704         /* Process crypto operation */
5705         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5706                         ut_params->op);
5707         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5708
5709         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5710                         "crypto operation processing failed");
5711
5712         /* Validate obuf */
5713         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5714                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5715                         catch_22_quote,
5716                         QUOTE_512_BYTES,
5717                         "Ciphertext data not as expected");
5718
5719         return TEST_SUCCESS;
5720 }
5721
5722 static int
5723 test_null_auth_cipher_operation(void)
5724 {
5725         struct crypto_testsuite_params *ts_params = &testsuite_params;
5726         struct crypto_unittest_params *ut_params = &unittest_params;
5727
5728         /* Generate test mbuf data and space for digest */
5729         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5730                         catch_22_quote, QUOTE_512_BYTES, 0);
5731
5732         /* Setup Cipher Parameters */
5733         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5734         ut_params->cipher_xform.next = NULL;
5735
5736         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5737         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5738
5739         /* Setup HMAC Parameters */
5740         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5741         ut_params->auth_xform.next = &ut_params->cipher_xform;
5742
5743         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5744         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5745
5746         /* Create Crypto session*/
5747         ut_params->sess = rte_cryptodev_sym_session_create(
5748                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5749         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5750
5751         /* Generate Crypto op data structure */
5752         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5753                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5754         TEST_ASSERT_NOT_NULL(ut_params->op,
5755                         "Failed to allocate symmetric crypto operation struct");
5756
5757         /* Set crypto operation data parameters */
5758         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5759
5760         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5761
5762         sym_op->m_src = ut_params->ibuf;
5763
5764         sym_op->cipher.data.offset = 0;
5765         sym_op->cipher.data.length = QUOTE_512_BYTES;
5766
5767         sym_op->auth.data.offset = 0;
5768         sym_op->auth.data.length = QUOTE_512_BYTES;
5769
5770         /* Process crypto operation */
5771         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5772                         ut_params->op);
5773         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5774
5775         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5776                         "crypto operation processing failed");
5777
5778         /* Validate obuf */
5779         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5780                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5781                         catch_22_quote,
5782                         QUOTE_512_BYTES,
5783                         "Ciphertext data not as expected");
5784
5785         return TEST_SUCCESS;
5786 }
5787
5788
5789 static int
5790 test_null_invalid_operation(void)
5791 {
5792         struct crypto_testsuite_params *ts_params = &testsuite_params;
5793         struct crypto_unittest_params *ut_params = &unittest_params;
5794
5795         /* Setup Cipher Parameters */
5796         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5797         ut_params->cipher_xform.next = NULL;
5798
5799         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
5800         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5801
5802         /* Create Crypto session*/
5803         ut_params->sess = rte_cryptodev_sym_session_create(
5804                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5805         TEST_ASSERT_NULL(ut_params->sess,
5806                         "Session creation succeeded unexpectedly");
5807
5808
5809         /* Setup HMAC Parameters */
5810         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5811         ut_params->auth_xform.next = NULL;
5812
5813         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
5814         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5815
5816         /* Create Crypto session*/
5817         ut_params->sess = rte_cryptodev_sym_session_create(
5818                         ts_params->valid_devs[0], &ut_params->auth_xform);
5819         TEST_ASSERT_NULL(ut_params->sess,
5820                         "Session creation succeeded unexpectedly");
5821
5822         return TEST_SUCCESS;
5823 }
5824
5825
5826 #define NULL_BURST_LENGTH (32)
5827
5828 static int
5829 test_null_burst_operation(void)
5830 {
5831         struct crypto_testsuite_params *ts_params = &testsuite_params;
5832         struct crypto_unittest_params *ut_params = &unittest_params;
5833
5834         unsigned i, burst_len = NULL_BURST_LENGTH;
5835
5836         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
5837         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
5838
5839         /* Setup Cipher Parameters */
5840         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5841         ut_params->cipher_xform.next = &ut_params->auth_xform;
5842
5843         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5844         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5845
5846         /* Setup HMAC Parameters */
5847         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5848         ut_params->auth_xform.next = NULL;
5849
5850         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5851         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5852
5853         /* Create Crypto session*/
5854         ut_params->sess = rte_cryptodev_sym_session_create(
5855                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5856         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5857
5858         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
5859                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
5860                         burst_len, "failed to generate burst of crypto ops");
5861
5862         /* Generate an operation for each mbuf in burst */
5863         for (i = 0; i < burst_len; i++) {
5864                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5865
5866                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
5867
5868                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
5869                                 sizeof(unsigned));
5870                 *data = i;
5871
5872                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
5873
5874                 burst[i]->sym->m_src = m;
5875         }
5876
5877         /* Process crypto operation */
5878         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
5879                         0, burst, burst_len),
5880                         burst_len,
5881                         "Error enqueuing burst");
5882
5883         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
5884                         0, burst_dequeued, burst_len),
5885                         burst_len,
5886                         "Error dequeuing burst");
5887
5888
5889         for (i = 0; i < burst_len; i++) {
5890                 TEST_ASSERT_EQUAL(
5891                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
5892                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
5893                                         uint32_t *),
5894                         "data not as expected");
5895
5896                 rte_pktmbuf_free(burst[i]->sym->m_src);
5897                 rte_crypto_op_free(burst[i]);
5898         }
5899
5900         return TEST_SUCCESS;
5901 }
5902
5903 static void
5904 generate_gmac_large_plaintext(uint8_t *data)
5905 {
5906         uint16_t i;
5907
5908         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
5909                 memcpy(&data[i], &data[0], 32);
5910 }
5911
5912 static int
5913 create_gmac_operation(enum rte_crypto_auth_operation op,
5914                 const struct gmac_test_data *tdata)
5915 {
5916         struct crypto_testsuite_params *ts_params = &testsuite_params;
5917         struct crypto_unittest_params *ut_params = &unittest_params;
5918         struct rte_crypto_sym_op *sym_op;
5919
5920         unsigned iv_pad_len;
5921         unsigned aad_pad_len;
5922
5923         iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
5924         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5925
5926         /*
5927          * Runtime generate the large plain text instead of use hard code
5928          * plain text vector. It is done to avoid create huge source file
5929          * with the test vector.
5930          */
5931         if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
5932                 generate_gmac_large_plaintext(tdata->aad.data);
5933
5934         /* Generate Crypto op data structure */
5935         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5936                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5937         TEST_ASSERT_NOT_NULL(ut_params->op,
5938                         "Failed to allocate symmetric crypto operation struct");
5939
5940         sym_op = ut_params->op->sym;
5941         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5942                         aad_pad_len);
5943         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
5944                         "no room to append aad");
5945
5946         sym_op->auth.aad.length = tdata->aad.len;
5947         sym_op->auth.aad.phys_addr =
5948                         rte_pktmbuf_mtophys(ut_params->ibuf);
5949         memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
5950
5951         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5952                         ut_params->ibuf, tdata->gmac_tag.len);
5953         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5954                         "no room to append digest");
5955
5956         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5957                         ut_params->ibuf, aad_pad_len);
5958         sym_op->auth.digest.length = tdata->gmac_tag.len;
5959
5960         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5961                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
5962                                 tdata->gmac_tag.len);
5963                 TEST_HEXDUMP(stdout, "digest:",
5964                                 sym_op->auth.digest.data,
5965                                 sym_op->auth.digest.length);
5966         }
5967
5968         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5969                         ut_params->ibuf, iv_pad_len);
5970         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5971
5972         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
5973         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5974         sym_op->cipher.iv.length = tdata->iv.len;
5975
5976         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
5977
5978         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
5979
5980         sym_op->cipher.data.length = 0;
5981         sym_op->cipher.data.offset = 0;
5982
5983         sym_op->auth.data.offset = 0;
5984         sym_op->auth.data.length = 0;
5985
5986         return 0;
5987 }
5988
5989 static int create_gmac_session(uint8_t dev_id,
5990                 enum rte_crypto_cipher_operation op,
5991                 const struct gmac_test_data *tdata,
5992                 enum rte_crypto_auth_operation auth_op)
5993 {
5994         uint8_t cipher_key[tdata->key.len];
5995
5996         struct crypto_unittest_params *ut_params = &unittest_params;
5997
5998         memcpy(cipher_key, tdata->key.data, tdata->key.len);
5999
6000         /* For GMAC we setup cipher parameters */
6001         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6002         ut_params->cipher_xform.next = NULL;
6003         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
6004         ut_params->cipher_xform.cipher.op = op;
6005         ut_params->cipher_xform.cipher.key.data = cipher_key;
6006         ut_params->cipher_xform.cipher.key.length = tdata->key.len;
6007
6008         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6009         ut_params->auth_xform.next = NULL;
6010
6011         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
6012         ut_params->auth_xform.auth.op = auth_op;
6013         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
6014         ut_params->auth_xform.auth.add_auth_data_length = 0;
6015         ut_params->auth_xform.auth.key.length = 0;
6016         ut_params->auth_xform.auth.key.data = NULL;
6017
6018         ut_params->cipher_xform.next = &ut_params->auth_xform;
6019
6020         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6021                         &ut_params->cipher_xform);
6022
6023         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6024
6025         return 0;
6026 }
6027
6028 static int
6029 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
6030 {
6031         struct crypto_testsuite_params *ts_params = &testsuite_params;
6032         struct crypto_unittest_params *ut_params = &unittest_params;
6033
6034         int retval;
6035
6036         uint8_t *auth_tag, *p;
6037         uint16_t aad_pad_len;
6038
6039         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6040                               "No GMAC length in the source data");
6041
6042         retval = create_gmac_session(ts_params->valid_devs[0],
6043                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6044                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
6045
6046         if (retval < 0)
6047                 return retval;
6048
6049         if (tdata->aad.len > MBUF_SIZE)
6050                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6051         else
6052                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6053         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6054                         "Failed to allocate input buffer in mempool");
6055
6056         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6057                         rte_pktmbuf_tailroom(ut_params->ibuf));
6058
6059         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6060
6061         p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
6062
6063         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
6064                         tdata);
6065
6066         if (retval < 0)
6067                 return retval;
6068
6069         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6070
6071         ut_params->op->sym->m_src = ut_params->ibuf;
6072
6073         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6074                         ut_params->op), "failed to process sym crypto op");
6075
6076         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6077                         "crypto op processing failed");
6078
6079         if (ut_params->op->sym->m_dst) {
6080                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6081                                 uint8_t *, aad_pad_len);
6082         } else {
6083                 auth_tag = p + aad_pad_len;
6084         }
6085
6086         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
6087
6088         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6089                         auth_tag,
6090                         tdata->gmac_tag.data,
6091                         tdata->gmac_tag.len,
6092                         "GMAC Generated auth tag not as expected");
6093
6094         return 0;
6095 }
6096
6097 static int
6098 test_AES_GMAC_authentication_test_case_1(void)
6099 {
6100         return test_AES_GMAC_authentication(&gmac_test_case_1);
6101 }
6102
6103 static int
6104 test_AES_GMAC_authentication_test_case_2(void)
6105 {
6106         return test_AES_GMAC_authentication(&gmac_test_case_2);
6107 }
6108
6109 static int
6110 test_AES_GMAC_authentication_test_case_3(void)
6111 {
6112         return test_AES_GMAC_authentication(&gmac_test_case_3);
6113 }
6114
6115 static int
6116 test_AES_GMAC_authentication_test_case_4(void)
6117 {
6118         return test_AES_GMAC_authentication(&gmac_test_case_4);
6119 }
6120
6121 static int
6122 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
6123 {
6124         struct crypto_testsuite_params *ts_params = &testsuite_params;
6125         struct crypto_unittest_params *ut_params = &unittest_params;
6126         int retval;
6127
6128         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6129                               "No GMAC length in the source data");
6130
6131         retval = create_gmac_session(ts_params->valid_devs[0],
6132                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
6133                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
6134
6135         if (retval < 0)
6136                 return retval;
6137
6138         if (tdata->aad.len > MBUF_SIZE)
6139                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6140         else
6141                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6142         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6143                         "Failed to allocate input buffer in mempool");
6144
6145         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6146                         rte_pktmbuf_tailroom(ut_params->ibuf));
6147
6148         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
6149                         tdata);
6150
6151         if (retval < 0)
6152                 return retval;
6153
6154         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6155
6156         ut_params->op->sym->m_src = ut_params->ibuf;
6157
6158         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6159                         ut_params->op), "failed to process sym crypto op");
6160
6161         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6162                         "crypto op processing failed");
6163
6164         return 0;
6165
6166 }
6167
6168 static int
6169 test_AES_GMAC_authentication_verify_test_case_1(void)
6170 {
6171         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
6172 }
6173
6174 static int
6175 test_AES_GMAC_authentication_verify_test_case_2(void)
6176 {
6177         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
6178 }
6179
6180 static int
6181 test_AES_GMAC_authentication_verify_test_case_3(void)
6182 {
6183         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
6184 }
6185
6186 static int
6187 test_AES_GMAC_authentication_verify_test_case_4(void)
6188 {
6189         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
6190 }
6191
6192 struct test_crypto_vector {
6193         enum rte_crypto_cipher_algorithm crypto_algo;
6194
6195         struct {
6196                 uint8_t data[64];
6197                 unsigned int len;
6198         } cipher_key;
6199
6200         struct {
6201                 uint8_t data[64];
6202                 unsigned int len;
6203         } iv;
6204
6205         struct {
6206                 const uint8_t *data;
6207                 unsigned int len;
6208         } plaintext;
6209
6210         struct {
6211                 const uint8_t *data;
6212                 unsigned int len;
6213         } ciphertext;
6214
6215         enum rte_crypto_auth_algorithm auth_algo;
6216
6217         struct {
6218                 uint8_t data[128];
6219                 unsigned int len;
6220         } auth_key;
6221
6222         struct {
6223                 const uint8_t *data;
6224                 unsigned int len;
6225         } aad;
6226
6227         struct {
6228                 uint8_t data[128];
6229                 unsigned int len;
6230         } digest;
6231 };
6232
6233 static const struct test_crypto_vector
6234 hmac_sha1_test_crypto_vector = {
6235         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6236         .plaintext = {
6237                 .data = plaintext_hash,
6238                 .len = 512
6239         },
6240         .auth_key = {
6241                 .data = {
6242                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6243                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6244                         0xDE, 0xF4, 0xDE, 0xAD
6245                 },
6246                 .len = 20
6247         },
6248         .digest = {
6249                 .data = {
6250                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
6251                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
6252                         0x3F, 0x91, 0x64, 0x59
6253                 },
6254                 .len = 20
6255         }
6256 };
6257
6258 static const struct test_crypto_vector
6259 aes128_gmac_test_vector = {
6260         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
6261         .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
6262         .aad = {
6263                 .data = plaintext_hash,
6264                 .len = 512
6265         },
6266         .iv = {
6267                 .data = {
6268                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6269                         0x08, 0x09, 0x0A, 0x0B
6270                 },
6271                 .len = 12
6272         },
6273         .cipher_key = {
6274                 .data = {
6275                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6276                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
6277                 },
6278                 .len = 16
6279         },
6280         .digest = {
6281                 .data = {
6282                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
6283                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
6284                 },
6285                 .len = 16
6286         }
6287 };
6288
6289 static const struct test_crypto_vector
6290 aes128cbc_hmac_sha1_test_vector = {
6291         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
6292         .cipher_key = {
6293                 .data = {
6294                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
6295                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
6296                 },
6297                 .len = 16
6298         },
6299         .iv = {
6300                 .data = {
6301                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6302                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
6303                 },
6304                 .len = 16
6305         },
6306         .plaintext = {
6307                 .data = plaintext_hash,
6308                 .len = 512
6309         },
6310         .ciphertext = {
6311                 .data = ciphertext512_aes128cbc,
6312                 .len = 512
6313         },
6314         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6315         .auth_key = {
6316                 .data = {
6317                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6318                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6319                         0xDE, 0xF4, 0xDE, 0xAD
6320                 },
6321                 .len = 20
6322         },
6323         .digest = {
6324                 .data = {
6325                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
6326                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6327                         0x18, 0x8C, 0x1D, 0x32
6328                 },
6329                 .len = 20
6330         }
6331 };
6332
6333 static void
6334 data_corruption(uint8_t *data)
6335 {
6336         data[0] += 1;
6337 }
6338
6339 static void
6340 tag_corruption(uint8_t *data, unsigned int tag_offset)
6341 {
6342         data[tag_offset] += 1;
6343 }
6344
6345 static int
6346 create_auth_session(struct crypto_unittest_params *ut_params,
6347                 uint8_t dev_id,
6348                 const struct test_crypto_vector *reference,
6349                 enum rte_crypto_auth_operation auth_op)
6350 {
6351         uint8_t auth_key[reference->auth_key.len + 1];
6352
6353         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6354
6355         /* Setup Authentication Parameters */
6356         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6357         ut_params->auth_xform.auth.op = auth_op;
6358         ut_params->auth_xform.next = NULL;
6359         ut_params->auth_xform.auth.algo = reference->auth_algo;
6360         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6361         ut_params->auth_xform.auth.key.data = auth_key;
6362         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6363         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
6364
6365         /* Create Crypto session*/
6366         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6367                                 &ut_params->auth_xform);
6368
6369         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6370
6371         return 0;
6372 }
6373
6374 static int
6375 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
6376                 uint8_t dev_id,
6377                 const struct test_crypto_vector *reference,
6378                 enum rte_crypto_auth_operation auth_op,
6379                 enum rte_crypto_cipher_operation cipher_op)
6380 {
6381         uint8_t cipher_key[reference->cipher_key.len + 1];
6382         uint8_t auth_key[reference->auth_key.len + 1];
6383
6384         memcpy(cipher_key, reference->cipher_key.data,
6385                         reference->cipher_key.len);
6386         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6387
6388         /* Setup Authentication Parameters */
6389         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6390         ut_params->auth_xform.auth.op = auth_op;
6391         ut_params->auth_xform.next = &ut_params->cipher_xform;
6392         ut_params->auth_xform.auth.algo = reference->auth_algo;
6393         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6394         ut_params->auth_xform.auth.key.data = auth_key;
6395         ut_params->auth_xform.auth.digest_length = reference->digest.len;
6396         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
6397
6398         /* Setup Cipher Parameters */
6399         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6400         ut_params->cipher_xform.next = NULL;
6401         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
6402         ut_params->cipher_xform.cipher.op = cipher_op;
6403         ut_params->cipher_xform.cipher.key.data = cipher_key;
6404         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
6405
6406         /* Create Crypto session*/
6407         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6408                                 &ut_params->auth_xform);
6409
6410         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6411
6412         return 0;
6413 }
6414
6415 static int
6416 create_auth_operation(struct crypto_testsuite_params *ts_params,
6417                 struct crypto_unittest_params *ut_params,
6418                 const struct test_crypto_vector *reference,
6419                 unsigned int auth_generate)
6420 {
6421         /* Generate Crypto op data structure */
6422         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6423                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6424         TEST_ASSERT_NOT_NULL(ut_params->op,
6425                         "Failed to allocate pktmbuf offload");
6426
6427         /* Set crypto operation data parameters */
6428         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6429
6430         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6431
6432         /* set crypto operation source mbuf */
6433         sym_op->m_src = ut_params->ibuf;
6434
6435         /* digest */
6436         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6437                         ut_params->ibuf, reference->digest.len);
6438
6439         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6440                         "no room to append auth tag");
6441
6442         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6443                         ut_params->ibuf, reference->plaintext.len);
6444         sym_op->auth.digest.length = reference->digest.len;
6445
6446         if (auth_generate)
6447                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6448         else
6449                 memcpy(sym_op->auth.digest.data,
6450                                 reference->digest.data,
6451                                 reference->digest.len);
6452
6453         TEST_HEXDUMP(stdout, "digest:",
6454                         sym_op->auth.digest.data,
6455                         sym_op->auth.digest.length);
6456
6457         sym_op->auth.data.length = reference->plaintext.len;
6458         sym_op->auth.data.offset = 0;
6459
6460         return 0;
6461 }
6462
6463 static int
6464 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
6465                 struct crypto_unittest_params *ut_params,
6466                 const struct test_crypto_vector *reference,
6467                 unsigned int auth_generate)
6468 {
6469         /* Generate Crypto op data structure */
6470         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6471                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6472         TEST_ASSERT_NOT_NULL(ut_params->op,
6473                         "Failed to allocate pktmbuf offload");
6474
6475         /* Set crypto operation data parameters */
6476         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6477
6478         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6479
6480         /* set crypto operation source mbuf */
6481         sym_op->m_src = ut_params->ibuf;
6482
6483         /* aad */
6484         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6485                         reference->aad.len);
6486         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
6487         memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
6488
6489         TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
6490
6491         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6492         sym_op->auth.aad.length = reference->aad.len;
6493
6494         /* digest */
6495         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6496                         ut_params->ibuf, reference->digest.len);
6497
6498         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6499                         "no room to append auth tag");
6500
6501         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6502                         ut_params->ibuf, reference->ciphertext.len);
6503         sym_op->auth.digest.length = reference->digest.len;
6504
6505         if (auth_generate)
6506                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6507         else
6508                 memcpy(sym_op->auth.digest.data,
6509                                 reference->digest.data,
6510                                 reference->digest.len);
6511
6512         TEST_HEXDUMP(stdout, "digest:",
6513                         sym_op->auth.digest.data,
6514                         sym_op->auth.digest.length);
6515
6516         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6517                 ut_params->ibuf, reference->iv.len);
6518         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
6519
6520         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6521         sym_op->cipher.iv.length = reference->iv.len;
6522
6523         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
6524
6525         sym_op->cipher.data.length = 0;
6526         sym_op->cipher.data.offset = 0;
6527
6528         sym_op->auth.data.length = 0;
6529         sym_op->auth.data.offset = 0;
6530
6531         return 0;
6532 }
6533
6534 static int
6535 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
6536                 struct crypto_unittest_params *ut_params,
6537                 const struct test_crypto_vector *reference,
6538                 unsigned int auth_generate)
6539 {
6540         /* Generate Crypto op data structure */
6541         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6542                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6543         TEST_ASSERT_NOT_NULL(ut_params->op,
6544                         "Failed to allocate pktmbuf offload");
6545
6546         /* Set crypto operation data parameters */
6547         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6548
6549         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6550
6551         /* set crypto operation source mbuf */
6552         sym_op->m_src = ut_params->ibuf;
6553
6554         /* digest */
6555         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6556                         ut_params->ibuf, reference->digest.len);
6557
6558         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6559                         "no room to append auth tag");
6560
6561         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6562                         ut_params->ibuf, reference->ciphertext.len);
6563         sym_op->auth.digest.length = reference->digest.len;
6564
6565         if (auth_generate)
6566                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6567         else
6568                 memcpy(sym_op->auth.digest.data,
6569                                 reference->digest.data,
6570                                 reference->digest.len);
6571
6572         TEST_HEXDUMP(stdout, "digest:",
6573                         sym_op->auth.digest.data,
6574                         sym_op->auth.digest.length);
6575
6576         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6577                 ut_params->ibuf, reference->iv.len);
6578         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
6579
6580         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6581         sym_op->cipher.iv.length = reference->iv.len;
6582
6583         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
6584
6585         sym_op->cipher.data.length = reference->ciphertext.len;
6586         sym_op->cipher.data.offset = reference->iv.len;
6587
6588         sym_op->auth.data.length = reference->ciphertext.len;
6589         sym_op->auth.data.offset = reference->iv.len;
6590
6591         return 0;
6592 }
6593
6594 static int
6595 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6596                 struct crypto_unittest_params *ut_params,
6597                 const struct test_crypto_vector *reference)
6598 {
6599         return create_auth_operation(ts_params, ut_params, reference, 0);
6600 }
6601
6602 static int
6603 create_auth_verify_GMAC_operation(
6604                 struct crypto_testsuite_params *ts_params,
6605                 struct crypto_unittest_params *ut_params,
6606                 const struct test_crypto_vector *reference)
6607 {
6608         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
6609 }
6610
6611 static int
6612 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6613                 struct crypto_unittest_params *ut_params,
6614                 const struct test_crypto_vector *reference)
6615 {
6616         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
6617 }
6618
6619 static int
6620 test_authentication_verify_fail_when_data_corruption(
6621                 struct crypto_testsuite_params *ts_params,
6622                 struct crypto_unittest_params *ut_params,
6623                 const struct test_crypto_vector *reference,
6624                 unsigned int data_corrupted)
6625 {
6626         int retval;
6627
6628         uint8_t *plaintext;
6629
6630         /* Create session */
6631         retval = create_auth_session(ut_params,
6632                         ts_params->valid_devs[0],
6633                         reference,
6634                         RTE_CRYPTO_AUTH_OP_VERIFY);
6635         if (retval < 0)
6636                 return retval;
6637
6638         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6639         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6640                         "Failed to allocate input buffer in mempool");
6641
6642         /* clear mbuf payload */
6643         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6644                         rte_pktmbuf_tailroom(ut_params->ibuf));
6645
6646         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6647                         reference->plaintext.len);
6648         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6649         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
6650
6651         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
6652
6653         /* Create operation */
6654         retval = create_auth_verify_operation(ts_params, ut_params, reference);
6655
6656         if (retval < 0)
6657                 return retval;
6658
6659         if (data_corrupted)
6660                 data_corruption(plaintext);
6661         else
6662                 tag_corruption(plaintext, reference->plaintext.len);
6663
6664         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6665                         ut_params->op);
6666         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6667         TEST_ASSERT_EQUAL(ut_params->op->status,
6668                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6669                         "authentication not failed");
6670
6671         ut_params->obuf = ut_params->op->sym->m_src;
6672         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6673
6674         return 0;
6675 }
6676
6677 static int
6678 test_authentication_verify_GMAC_fail_when_corruption(
6679                 struct crypto_testsuite_params *ts_params,
6680                 struct crypto_unittest_params *ut_params,
6681                 const struct test_crypto_vector *reference,
6682                 unsigned int data_corrupted)
6683 {
6684         int retval;
6685
6686         /* Create session */
6687         retval = create_auth_cipher_session(ut_params,
6688                         ts_params->valid_devs[0],
6689                         reference,
6690                         RTE_CRYPTO_AUTH_OP_VERIFY,
6691                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
6692         if (retval < 0)
6693                 return retval;
6694
6695         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6696         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6697                         "Failed to allocate input buffer in mempool");
6698
6699         /* clear mbuf payload */
6700         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6701                         rte_pktmbuf_tailroom(ut_params->ibuf));
6702
6703         /* Create operation */
6704         retval = create_auth_verify_GMAC_operation(ts_params,
6705                         ut_params,
6706                         reference);
6707
6708         if (retval < 0)
6709                 return retval;
6710
6711         if (data_corrupted)
6712                 data_corruption(ut_params->op->sym->auth.aad.data);
6713         else
6714                 tag_corruption(ut_params->op->sym->auth.aad.data,
6715                                 reference->aad.len);
6716
6717         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6718                         ut_params->op);
6719         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6720         TEST_ASSERT_EQUAL(ut_params->op->status,
6721                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6722                         "authentication not failed");
6723
6724         ut_params->obuf = ut_params->op->sym->m_src;
6725         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6726
6727         return 0;
6728 }
6729
6730 static int
6731 test_authenticated_decryption_fail_when_corruption(
6732                 struct crypto_testsuite_params *ts_params,
6733                 struct crypto_unittest_params *ut_params,
6734                 const struct test_crypto_vector *reference,
6735                 unsigned int data_corrupted)
6736 {
6737         int retval;
6738
6739         uint8_t *ciphertext;
6740
6741         /* Create session */
6742         retval = create_auth_cipher_session(ut_params,
6743                         ts_params->valid_devs[0],
6744                         reference,
6745                         RTE_CRYPTO_AUTH_OP_VERIFY,
6746                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
6747         if (retval < 0)
6748                 return retval;
6749
6750         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6751         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6752                         "Failed to allocate input buffer in mempool");
6753
6754         /* clear mbuf payload */
6755         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6756                         rte_pktmbuf_tailroom(ut_params->ibuf));
6757
6758         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6759                         reference->ciphertext.len);
6760         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
6761         memcpy(ciphertext, reference->ciphertext.data,
6762                         reference->ciphertext.len);
6763
6764         /* Create operation */
6765         retval = create_cipher_auth_verify_operation(ts_params,
6766                         ut_params,
6767                         reference);
6768
6769         if (retval < 0)
6770                 return retval;
6771
6772         if (data_corrupted)
6773                 data_corruption(ciphertext);
6774         else
6775                 tag_corruption(ciphertext, reference->ciphertext.len);
6776
6777         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6778                         ut_params->op);
6779
6780         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6781         TEST_ASSERT_EQUAL(ut_params->op->status,
6782                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6783                         "authentication not failed");
6784
6785         ut_params->obuf = ut_params->op->sym->m_src;
6786         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6787
6788         return 0;
6789 }
6790
6791 static int
6792 create_gcm_operation_SGL(enum rte_crypto_cipher_operation op,
6793                 const struct gcm_test_data *tdata,
6794                 void *digest_mem, uint64_t digest_phys)
6795 {
6796         struct crypto_testsuite_params *ts_params = &testsuite_params;
6797         struct crypto_unittest_params *ut_params = &unittest_params;
6798
6799         const unsigned int auth_tag_len = tdata->auth_tag.len;
6800         const unsigned int iv_len = tdata->iv.len;
6801         const unsigned int aad_len = tdata->aad.len;
6802
6803         unsigned int iv_pad_len = 0;
6804
6805         /* Generate Crypto op data structure */
6806         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6807                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6808         TEST_ASSERT_NOT_NULL(ut_params->op,
6809                 "Failed to allocate symmetric crypto operation struct");
6810
6811         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6812
6813         sym_op->auth.digest.data = digest_mem;
6814
6815         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6816                         "no room to append digest");
6817
6818         sym_op->auth.digest.phys_addr = digest_phys;
6819         sym_op->auth.digest.length = auth_tag_len;
6820
6821         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
6822                 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
6823                                 auth_tag_len);
6824                 TEST_HEXDUMP(stdout, "digest:",
6825                                 sym_op->auth.digest.data,
6826                                 sym_op->auth.digest.length);
6827         }
6828
6829         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
6830
6831         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6832                         ut_params->ibuf, iv_pad_len);
6833
6834         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
6835                         "no room to prepend iv");
6836
6837         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
6838         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6839         sym_op->cipher.iv.length = iv_len;
6840
6841         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, iv_pad_len);
6842
6843         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
6844                         ut_params->ibuf, aad_len);
6845         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
6846                         "no room to prepend aad");
6847         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
6848                         ut_params->ibuf);
6849         sym_op->auth.aad.length = aad_len;
6850
6851         memset(sym_op->auth.aad.data, 0, aad_len);
6852         rte_memcpy(sym_op->auth.aad.data, tdata->aad.data, aad_len);
6853
6854         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
6855         TEST_HEXDUMP(stdout, "aad:",
6856                         sym_op->auth.aad.data, aad_len);
6857
6858         sym_op->cipher.data.length = tdata->plaintext.len;
6859         sym_op->cipher.data.offset = aad_len + iv_pad_len;
6860
6861         sym_op->auth.data.offset = aad_len + iv_pad_len;
6862         sym_op->auth.data.length = tdata->plaintext.len;
6863
6864         return 0;
6865 }
6866
6867 #define SGL_MAX_NO      16
6868
6869 static int
6870 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
6871                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
6872 {
6873         struct crypto_testsuite_params *ts_params = &testsuite_params;
6874         struct crypto_unittest_params *ut_params = &unittest_params;
6875         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
6876         int retval;
6877         int to_trn = 0;
6878         int to_trn_tbl[SGL_MAX_NO];
6879         int segs = 1;
6880         unsigned int trn_data = 0;
6881         uint8_t *plaintext, *ciphertext, *auth_tag;
6882
6883         if (fragsz > tdata->plaintext.len)
6884                 fragsz = tdata->plaintext.len;
6885
6886         uint16_t plaintext_len = fragsz;
6887         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
6888
6889         if (fragsz_oop > tdata->plaintext.len)
6890                 frag_size_oop = tdata->plaintext.len;
6891
6892         int ecx = 0;
6893         void *digest_mem = NULL;
6894
6895         uint32_t prepend_len = ALIGN_POW2_ROUNDUP(tdata->iv.len, 16)
6896                         + tdata->aad.len;
6897
6898         if (tdata->plaintext.len % fragsz != 0) {
6899                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
6900                         return 1;
6901         }       else {
6902                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
6903                         return 1;
6904         }
6905
6906         /*
6907          * For out-op-place we need to alloc another mbuf
6908          */
6909         if (oop) {
6910                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6911                 rte_pktmbuf_append(ut_params->obuf,
6912                                 frag_size_oop + prepend_len);
6913                 buf_oop = ut_params->obuf;
6914         }
6915
6916         /* Create GCM session */
6917         retval = create_gcm_session(ts_params->valid_devs[0],
6918                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6919                         tdata->key.data, tdata->key.len,
6920                         tdata->aad.len, tdata->auth_tag.len,
6921                         RTE_CRYPTO_AUTH_OP_GENERATE);
6922         if (retval < 0)
6923                 return retval;
6924
6925         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6926
6927         /* clear mbuf payload */
6928         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6929                         rte_pktmbuf_tailroom(ut_params->ibuf));
6930
6931         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6932                         plaintext_len);
6933
6934         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6935
6936         trn_data += plaintext_len;
6937
6938         buf = ut_params->ibuf;
6939
6940         /*
6941          * Loop until no more fragments
6942          */
6943
6944         while (trn_data < tdata->plaintext.len) {
6945                 ++segs;
6946                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
6947                                 (tdata->plaintext.len - trn_data) : fragsz;
6948
6949                 to_trn_tbl[ecx++] = to_trn;
6950
6951                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6952                 buf = buf->next;
6953
6954                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
6955                                 rte_pktmbuf_tailroom(buf));
6956
6957                 /* OOP */
6958                 if (oop && !fragsz_oop) {
6959                         buf_last_oop = buf_oop->next =
6960                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
6961                         buf_oop = buf_oop->next;
6962                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
6963                                         0, rte_pktmbuf_tailroom(buf_oop));
6964                         rte_pktmbuf_append(buf_oop, to_trn);
6965                 }
6966
6967                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
6968                                 to_trn);
6969
6970                 memcpy(plaintext, tdata->plaintext.data + trn_data,
6971                                 to_trn);
6972                 trn_data += to_trn;
6973                 if (trn_data  == tdata->plaintext.len) {
6974                         if (oop) {
6975                                 if (!fragsz_oop)
6976                                         digest_mem = rte_pktmbuf_append(buf_oop,
6977                                                 tdata->auth_tag.len);
6978                         } else
6979                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
6980                                         tdata->auth_tag.len);
6981                 }
6982         }
6983
6984         uint64_t digest_phys = 0;
6985
6986         ut_params->ibuf->nb_segs = segs;
6987
6988         segs = 1;
6989         if (fragsz_oop && oop) {
6990                 to_trn = 0;
6991                 ecx = 0;
6992
6993                 if (frag_size_oop == tdata->plaintext.len) {
6994                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
6995                                 tdata->auth_tag.len);
6996
6997                         digest_phys = rte_pktmbuf_mtophys_offset(
6998                                         ut_params->obuf,
6999                                         tdata->plaintext.len + prepend_len);
7000                 }
7001
7002                 trn_data = frag_size_oop;
7003                 while (trn_data < tdata->plaintext.len) {
7004                         ++segs;
7005                         to_trn =
7006                                 (tdata->plaintext.len - trn_data <
7007                                                 frag_size_oop) ?
7008                                 (tdata->plaintext.len - trn_data) :
7009                                                 frag_size_oop;
7010
7011                         to_trn_tbl[ecx++] = to_trn;
7012
7013                         buf_last_oop = buf_oop->next =
7014                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7015                         buf_oop = buf_oop->next;
7016                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7017                                         0, rte_pktmbuf_tailroom(buf_oop));
7018                         rte_pktmbuf_append(buf_oop, to_trn);
7019
7020                         trn_data += to_trn;
7021
7022                         if (trn_data  == tdata->plaintext.len) {
7023                                 digest_mem = rte_pktmbuf_append(buf_oop,
7024                                         tdata->auth_tag.len);
7025                         }
7026                 }
7027
7028                 ut_params->obuf->nb_segs = segs;
7029         }
7030
7031         /*
7032          * Place digest at the end of the last buffer
7033          */
7034         if (!digest_phys)
7035                 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
7036         if (oop && buf_last_oop)
7037                 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
7038
7039         if (!digest_mem && !oop) {
7040                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7041                                 + tdata->auth_tag.len);
7042                 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
7043                                 tdata->plaintext.len);
7044         }
7045
7046         /* Create GCM opertaion */
7047         retval = create_gcm_operation_SGL(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7048                         tdata, digest_mem, digest_phys);
7049
7050         if (retval < 0)
7051                 return retval;
7052
7053         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7054
7055         ut_params->op->sym->m_src = ut_params->ibuf;
7056         if (oop)
7057                 ut_params->op->sym->m_dst = ut_params->obuf;
7058
7059         /* Process crypto operation */
7060         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7061                         ut_params->op), "failed to process sym crypto op");
7062
7063         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7064                         "crypto op processing failed");
7065
7066
7067         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7068                         uint8_t *, prepend_len);
7069         if (oop) {
7070                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7071                                 uint8_t *, prepend_len);
7072         }
7073
7074         if (fragsz_oop)
7075                 fragsz = fragsz_oop;
7076
7077         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7078                         ciphertext,
7079                         tdata->ciphertext.data,
7080                         fragsz,
7081                         "GCM Ciphertext data not as expected");
7082
7083         buf = ut_params->op->sym->m_src->next;
7084         if (oop)
7085                 buf = ut_params->op->sym->m_dst->next;
7086
7087         unsigned int off = fragsz;
7088
7089         ecx = 0;
7090         while (buf) {
7091                 ciphertext = rte_pktmbuf_mtod(buf,
7092                                 uint8_t *);
7093
7094                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7095                                 ciphertext,
7096                                 tdata->ciphertext.data + off,
7097                                 to_trn_tbl[ecx],
7098                                 "GCM Ciphertext data not as expected");
7099
7100                 off += to_trn_tbl[ecx++];
7101                 buf = buf->next;
7102         }
7103
7104         auth_tag = digest_mem;
7105         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7106                         auth_tag,
7107                         tdata->auth_tag.data,
7108                         tdata->auth_tag.len,
7109                         "GCM Generated auth tag not as expected");
7110
7111         return 0;
7112 }
7113
7114 #define IN_PLACE        0
7115 #define OUT_OF_PLACE    1
7116
7117 static int
7118 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
7119 {
7120         return test_AES_GCM_authenticated_encryption_SGL(
7121                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
7122 }
7123
7124 static int
7125 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
7126 {
7127         return test_AES_GCM_authenticated_encryption_SGL(
7128                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
7129 }
7130
7131 static int
7132 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
7133 {
7134         return test_AES_GCM_authenticated_encryption_SGL(
7135                         &gcm_test_case_8, OUT_OF_PLACE, 400,
7136                         gcm_test_case_8.plaintext.len);
7137 }
7138
7139 static int
7140 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
7141 {
7142
7143         return test_AES_GCM_authenticated_encryption_SGL(
7144                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
7145 }
7146
7147 static int
7148 test_authentication_verify_fail_when_data_corrupted(
7149                 struct crypto_testsuite_params *ts_params,
7150                 struct crypto_unittest_params *ut_params,
7151                 const struct test_crypto_vector *reference)
7152 {
7153         return test_authentication_verify_fail_when_data_corruption(
7154                         ts_params, ut_params, reference, 1);
7155 }
7156
7157 static int
7158 test_authentication_verify_fail_when_tag_corrupted(
7159                 struct crypto_testsuite_params *ts_params,
7160                 struct crypto_unittest_params *ut_params,
7161                 const struct test_crypto_vector *reference)
7162 {
7163         return test_authentication_verify_fail_when_data_corruption(
7164                         ts_params, ut_params, reference, 0);
7165 }
7166
7167 static int
7168 test_authentication_verify_GMAC_fail_when_data_corrupted(
7169                 struct crypto_testsuite_params *ts_params,
7170                 struct crypto_unittest_params *ut_params,
7171                 const struct test_crypto_vector *reference)
7172 {
7173         return test_authentication_verify_GMAC_fail_when_corruption(
7174                         ts_params, ut_params, reference, 1);
7175 }
7176
7177 static int
7178 test_authentication_verify_GMAC_fail_when_tag_corrupted(
7179                 struct crypto_testsuite_params *ts_params,
7180                 struct crypto_unittest_params *ut_params,
7181                 const struct test_crypto_vector *reference)
7182 {
7183         return test_authentication_verify_GMAC_fail_when_corruption(
7184                         ts_params, ut_params, reference, 0);
7185 }
7186
7187 static int
7188 test_authenticated_decryption_fail_when_data_corrupted(
7189                 struct crypto_testsuite_params *ts_params,
7190                 struct crypto_unittest_params *ut_params,
7191                 const struct test_crypto_vector *reference)
7192 {
7193         return test_authenticated_decryption_fail_when_corruption(
7194                         ts_params, ut_params, reference, 1);
7195 }
7196
7197 static int
7198 test_authenticated_decryption_fail_when_tag_corrupted(
7199                 struct crypto_testsuite_params *ts_params,
7200                 struct crypto_unittest_params *ut_params,
7201                 const struct test_crypto_vector *reference)
7202 {
7203         return test_authenticated_decryption_fail_when_corruption(
7204                         ts_params, ut_params, reference, 0);
7205 }
7206
7207 static int
7208 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
7209 {
7210         return test_authentication_verify_fail_when_data_corrupted(
7211                         &testsuite_params, &unittest_params,
7212                         &hmac_sha1_test_crypto_vector);
7213 }
7214
7215 static int
7216 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
7217 {
7218         return test_authentication_verify_fail_when_tag_corrupted(
7219                         &testsuite_params, &unittest_params,
7220                         &hmac_sha1_test_crypto_vector);
7221 }
7222
7223 static int
7224 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
7225 {
7226         return test_authentication_verify_GMAC_fail_when_data_corrupted(
7227                         &testsuite_params, &unittest_params,
7228                         &aes128_gmac_test_vector);
7229 }
7230
7231 static int
7232 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
7233 {
7234         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
7235                         &testsuite_params, &unittest_params,
7236                         &aes128_gmac_test_vector);
7237 }
7238
7239 static int
7240 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
7241 {
7242         return test_authenticated_decryption_fail_when_data_corrupted(
7243                         &testsuite_params,
7244                         &unittest_params,
7245                         &aes128cbc_hmac_sha1_test_vector);
7246 }
7247
7248 static int
7249 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
7250 {
7251         return test_authenticated_decryption_fail_when_tag_corrupted(
7252                         &testsuite_params,
7253                         &unittest_params,
7254                         &aes128cbc_hmac_sha1_test_vector);
7255 }
7256
7257 static struct unit_test_suite cryptodev_qat_testsuite  = {
7258         .suite_name = "Crypto QAT Unit Test Suite",
7259         .setup = testsuite_setup,
7260         .teardown = testsuite_teardown,
7261         .unit_test_cases = {
7262                 TEST_CASE_ST(ut_setup, ut_teardown,
7263                                 test_device_configure_invalid_dev_id),
7264                 TEST_CASE_ST(ut_setup, ut_teardown,
7265                                 test_device_configure_invalid_queue_pair_ids),
7266                 TEST_CASE_ST(ut_setup, ut_teardown,
7267                                 test_queue_pair_descriptor_setup),
7268                 TEST_CASE_ST(ut_setup, ut_teardown,
7269                                 test_multi_session),
7270
7271                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
7272                 TEST_CASE_ST(ut_setup, ut_teardown,
7273                                                 test_AES_cipheronly_qat_all),
7274                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
7275                 TEST_CASE_ST(ut_setup, ut_teardown,
7276                                                 test_3DES_cipheronly_qat_all),
7277                 TEST_CASE_ST(ut_setup, ut_teardown,
7278                                                 test_DES_cipheronly_qat_all),
7279                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
7280
7281                 /** AES GCM Authenticated Encryption */
7282                 TEST_CASE_ST(ut_setup, ut_teardown,
7283                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
7284                 TEST_CASE_ST(ut_setup, ut_teardown,
7285                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
7286                 TEST_CASE_ST(ut_setup, ut_teardown,
7287                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
7288                 TEST_CASE_ST(ut_setup, ut_teardown,
7289                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
7290                 TEST_CASE_ST(ut_setup, ut_teardown,
7291                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
7292                 TEST_CASE_ST(ut_setup, ut_teardown,
7293                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
7294                 TEST_CASE_ST(ut_setup, ut_teardown,
7295                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
7296                 TEST_CASE_ST(ut_setup, ut_teardown,
7297                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
7298                 TEST_CASE_ST(ut_setup, ut_teardown,
7299                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
7300                 TEST_CASE_ST(ut_setup, ut_teardown,
7301                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
7302
7303                 /** AES GCM Authenticated Decryption */
7304                 TEST_CASE_ST(ut_setup, ut_teardown,
7305                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
7306                 TEST_CASE_ST(ut_setup, ut_teardown,
7307                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
7308                 TEST_CASE_ST(ut_setup, ut_teardown,
7309                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
7310                 TEST_CASE_ST(ut_setup, ut_teardown,
7311                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
7312                 TEST_CASE_ST(ut_setup, ut_teardown,
7313                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
7314                 TEST_CASE_ST(ut_setup, ut_teardown,
7315                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
7316                 TEST_CASE_ST(ut_setup, ut_teardown,
7317                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
7318
7319                 /** AES GMAC Authentication */
7320                 TEST_CASE_ST(ut_setup, ut_teardown,
7321                         test_AES_GMAC_authentication_test_case_1),
7322                 TEST_CASE_ST(ut_setup, ut_teardown,
7323                         test_AES_GMAC_authentication_verify_test_case_1),
7324                 TEST_CASE_ST(ut_setup, ut_teardown,
7325                         test_AES_GMAC_authentication_test_case_2),
7326                 TEST_CASE_ST(ut_setup, ut_teardown,
7327                         test_AES_GMAC_authentication_verify_test_case_2),
7328                 TEST_CASE_ST(ut_setup, ut_teardown,
7329                         test_AES_GMAC_authentication_test_case_3),
7330                 TEST_CASE_ST(ut_setup, ut_teardown,
7331                         test_AES_GMAC_authentication_verify_test_case_3),
7332
7333                 /** SNOW 3G encrypt only (UEA2) */
7334                 TEST_CASE_ST(ut_setup, ut_teardown,
7335                         test_snow3g_encryption_test_case_1),
7336                 TEST_CASE_ST(ut_setup, ut_teardown,
7337                         test_snow3g_encryption_test_case_2),
7338                 TEST_CASE_ST(ut_setup, ut_teardown,
7339                         test_snow3g_encryption_test_case_3),
7340                 TEST_CASE_ST(ut_setup, ut_teardown,
7341                         test_snow3g_encryption_test_case_4),
7342                 TEST_CASE_ST(ut_setup, ut_teardown,
7343                         test_snow3g_encryption_test_case_5),
7344
7345                 TEST_CASE_ST(ut_setup, ut_teardown,
7346                         test_snow3g_encryption_test_case_1_oop),
7347                 TEST_CASE_ST(ut_setup, ut_teardown,
7348                         test_snow3g_decryption_test_case_1_oop),
7349
7350                 /** SNOW 3G decrypt only (UEA2) */
7351                 TEST_CASE_ST(ut_setup, ut_teardown,
7352                         test_snow3g_decryption_test_case_1),
7353                 TEST_CASE_ST(ut_setup, ut_teardown,
7354                         test_snow3g_decryption_test_case_2),
7355                 TEST_CASE_ST(ut_setup, ut_teardown,
7356                         test_snow3g_decryption_test_case_3),
7357                 TEST_CASE_ST(ut_setup, ut_teardown,
7358                         test_snow3g_decryption_test_case_4),
7359                 TEST_CASE_ST(ut_setup, ut_teardown,
7360                         test_snow3g_decryption_test_case_5),
7361                 TEST_CASE_ST(ut_setup, ut_teardown,
7362                         test_snow3g_hash_generate_test_case_1),
7363                 TEST_CASE_ST(ut_setup, ut_teardown,
7364                         test_snow3g_hash_generate_test_case_2),
7365                 TEST_CASE_ST(ut_setup, ut_teardown,
7366                         test_snow3g_hash_generate_test_case_3),
7367                 TEST_CASE_ST(ut_setup, ut_teardown,
7368                         test_snow3g_hash_verify_test_case_1),
7369                 TEST_CASE_ST(ut_setup, ut_teardown,
7370                         test_snow3g_hash_verify_test_case_2),
7371                 TEST_CASE_ST(ut_setup, ut_teardown,
7372                         test_snow3g_hash_verify_test_case_3),
7373                 TEST_CASE_ST(ut_setup, ut_teardown,
7374                         test_snow3g_cipher_auth_test_case_1),
7375                 TEST_CASE_ST(ut_setup, ut_teardown,
7376                         test_snow3g_auth_cipher_test_case_1),
7377
7378                 /** HMAC_MD5 Authentication */
7379                 TEST_CASE_ST(ut_setup, ut_teardown,
7380                         test_MD5_HMAC_generate_case_1),
7381                 TEST_CASE_ST(ut_setup, ut_teardown,
7382                         test_MD5_HMAC_verify_case_1),
7383                 TEST_CASE_ST(ut_setup, ut_teardown,
7384                         test_MD5_HMAC_generate_case_2),
7385                 TEST_CASE_ST(ut_setup, ut_teardown,
7386                         test_MD5_HMAC_verify_case_2),
7387
7388                 /** NULL tests */
7389                 TEST_CASE_ST(ut_setup, ut_teardown,
7390                         test_null_auth_only_operation),
7391                 TEST_CASE_ST(ut_setup, ut_teardown,
7392                         test_null_cipher_only_operation),
7393                 TEST_CASE_ST(ut_setup, ut_teardown,
7394                         test_null_cipher_auth_operation),
7395                 TEST_CASE_ST(ut_setup, ut_teardown,
7396                         test_null_auth_cipher_operation),
7397
7398                 TEST_CASE_ST(ut_setup, ut_teardown,
7399                         test_kasumi_hash_generate_test_case_6),
7400
7401                 /** KASUMI tests */
7402                 TEST_CASE_ST(ut_setup, ut_teardown,
7403                         test_kasumi_encryption_test_case_1),
7404                 TEST_CASE_ST(ut_setup, ut_teardown,
7405                         test_kasumi_encryption_test_case_3),
7406                 TEST_CASE_ST(ut_setup, ut_teardown,
7407                         test_kasumi_auth_cipher_test_case_1),
7408                 TEST_CASE_ST(ut_setup, ut_teardown,
7409                         test_kasumi_cipher_auth_test_case_1),
7410
7411                 /** Negative tests */
7412                 TEST_CASE_ST(ut_setup, ut_teardown,
7413                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
7414                 TEST_CASE_ST(ut_setup, ut_teardown,
7415                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
7416                 TEST_CASE_ST(ut_setup, ut_teardown,
7417                         authentication_verify_AES128_GMAC_fail_data_corrupt),
7418                 TEST_CASE_ST(ut_setup, ut_teardown,
7419                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
7420                 TEST_CASE_ST(ut_setup, ut_teardown,
7421                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
7422                 TEST_CASE_ST(ut_setup, ut_teardown,
7423                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
7424
7425                 TEST_CASES_END() /**< NULL terminate unit test array */
7426         }
7427 };
7428
7429 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
7430         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
7431         .setup = testsuite_setup,
7432         .teardown = testsuite_teardown,
7433         .unit_test_cases = {
7434                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
7435                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
7436                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
7437
7438                 TEST_CASES_END() /**< NULL terminate unit test array */
7439         }
7440 };
7441
7442 static struct unit_test_suite cryptodev_openssl_testsuite  = {
7443         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
7444         .setup = testsuite_setup,
7445         .teardown = testsuite_teardown,
7446         .unit_test_cases = {
7447                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
7448                 TEST_CASE_ST(ut_setup, ut_teardown,
7449                                 test_multi_session_random_usage),
7450                 TEST_CASE_ST(ut_setup, ut_teardown,
7451                                 test_AES_chain_openssl_all),
7452                 TEST_CASE_ST(ut_setup, ut_teardown,
7453                                 test_AES_cipheronly_openssl_all),
7454                 TEST_CASE_ST(ut_setup, ut_teardown,
7455                                 test_3DES_chain_openssl_all),
7456                 TEST_CASE_ST(ut_setup, ut_teardown,
7457                                 test_3DES_cipheronly_openssl_all),
7458                 TEST_CASE_ST(ut_setup, ut_teardown,
7459                                 test_authonly_openssl_all),
7460
7461                 /** AES GCM Authenticated Encryption */
7462                 TEST_CASE_ST(ut_setup, ut_teardown,
7463                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
7464                 TEST_CASE_ST(ut_setup, ut_teardown,
7465                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
7466                 TEST_CASE_ST(ut_setup, ut_teardown,
7467                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
7468                 TEST_CASE_ST(ut_setup, ut_teardown,
7469                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
7470                 TEST_CASE_ST(ut_setup, ut_teardown,
7471                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
7472                 TEST_CASE_ST(ut_setup, ut_teardown,
7473                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
7474                 TEST_CASE_ST(ut_setup, ut_teardown,
7475                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
7476
7477                 /** AES GCM Authenticated Decryption */
7478                 TEST_CASE_ST(ut_setup, ut_teardown,
7479                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
7480                 TEST_CASE_ST(ut_setup, ut_teardown,
7481                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
7482                 TEST_CASE_ST(ut_setup, ut_teardown,
7483                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
7484                 TEST_CASE_ST(ut_setup, ut_teardown,
7485                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
7486                 TEST_CASE_ST(ut_setup, ut_teardown,
7487                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
7488                 TEST_CASE_ST(ut_setup, ut_teardown,
7489                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
7490                 TEST_CASE_ST(ut_setup, ut_teardown,
7491                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
7492
7493                 /** AES GMAC Authentication */
7494                 TEST_CASE_ST(ut_setup, ut_teardown,
7495                         test_AES_GMAC_authentication_test_case_1),
7496                 TEST_CASE_ST(ut_setup, ut_teardown,
7497                         test_AES_GMAC_authentication_verify_test_case_1),
7498                 TEST_CASE_ST(ut_setup, ut_teardown,
7499                         test_AES_GMAC_authentication_test_case_2),
7500                 TEST_CASE_ST(ut_setup, ut_teardown,
7501                         test_AES_GMAC_authentication_verify_test_case_2),
7502                 TEST_CASE_ST(ut_setup, ut_teardown,
7503                         test_AES_GMAC_authentication_test_case_3),
7504                 TEST_CASE_ST(ut_setup, ut_teardown,
7505                         test_AES_GMAC_authentication_verify_test_case_3),
7506                 TEST_CASE_ST(ut_setup, ut_teardown,
7507                         test_AES_GMAC_authentication_test_case_4),
7508                 TEST_CASE_ST(ut_setup, ut_teardown,
7509                         test_AES_GMAC_authentication_verify_test_case_4),
7510
7511                 /** Scatter-Gather */
7512                 TEST_CASE_ST(ut_setup, ut_teardown,
7513                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
7514
7515                 /** Negative tests */
7516                 TEST_CASE_ST(ut_setup, ut_teardown,
7517                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
7518                 TEST_CASE_ST(ut_setup, ut_teardown,
7519                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
7520                 TEST_CASE_ST(ut_setup, ut_teardown,
7521                         authentication_verify_AES128_GMAC_fail_data_corrupt),
7522                 TEST_CASE_ST(ut_setup, ut_teardown,
7523                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
7524                 TEST_CASE_ST(ut_setup, ut_teardown,
7525                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
7526                 TEST_CASE_ST(ut_setup, ut_teardown,
7527                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
7528
7529                 TEST_CASES_END() /**< NULL terminate unit test array */
7530         }
7531 };
7532
7533 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
7534         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
7535         .setup = testsuite_setup,
7536         .teardown = testsuite_teardown,
7537         .unit_test_cases = {
7538                 /** AES GCM Authenticated Encryption */
7539                 TEST_CASE_ST(ut_setup, ut_teardown,
7540                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
7541                 TEST_CASE_ST(ut_setup, ut_teardown,
7542                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
7543                 TEST_CASE_ST(ut_setup, ut_teardown,
7544                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
7545                 TEST_CASE_ST(ut_setup, ut_teardown,
7546                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
7547                 TEST_CASE_ST(ut_setup, ut_teardown,
7548                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
7549                 TEST_CASE_ST(ut_setup, ut_teardown,
7550                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
7551                 TEST_CASE_ST(ut_setup, ut_teardown,
7552                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
7553
7554                 /** AES GCM Authenticated Decryption */
7555                 TEST_CASE_ST(ut_setup, ut_teardown,
7556                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
7557                 TEST_CASE_ST(ut_setup, ut_teardown,
7558                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
7559                 TEST_CASE_ST(ut_setup, ut_teardown,
7560                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
7561                 TEST_CASE_ST(ut_setup, ut_teardown,
7562                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
7563                 TEST_CASE_ST(ut_setup, ut_teardown,
7564                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
7565                 TEST_CASE_ST(ut_setup, ut_teardown,
7566                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
7567                 TEST_CASE_ST(ut_setup, ut_teardown,
7568                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
7569
7570                 /** AES GCM Authenticated Encryption 256 bits key */
7571                 TEST_CASE_ST(ut_setup, ut_teardown,
7572                         test_mb_AES_GCM_auth_encryption_test_case_256_1),
7573                 TEST_CASE_ST(ut_setup, ut_teardown,
7574                         test_mb_AES_GCM_auth_encryption_test_case_256_2),
7575                 TEST_CASE_ST(ut_setup, ut_teardown,
7576                         test_mb_AES_GCM_auth_encryption_test_case_256_3),
7577                 TEST_CASE_ST(ut_setup, ut_teardown,
7578                         test_mb_AES_GCM_auth_encryption_test_case_256_4),
7579                 TEST_CASE_ST(ut_setup, ut_teardown,
7580                         test_mb_AES_GCM_auth_encryption_test_case_256_5),
7581                 TEST_CASE_ST(ut_setup, ut_teardown,
7582                         test_mb_AES_GCM_auth_encryption_test_case_256_6),
7583                 TEST_CASE_ST(ut_setup, ut_teardown,
7584                         test_mb_AES_GCM_auth_encryption_test_case_256_7),
7585
7586                 /** AES GCM Authenticated Decryption 256 bits key */
7587                 TEST_CASE_ST(ut_setup, ut_teardown,
7588                         test_mb_AES_GCM_auth_decryption_test_case_256_1),
7589                 TEST_CASE_ST(ut_setup, ut_teardown,
7590                         test_mb_AES_GCM_auth_decryption_test_case_256_2),
7591                 TEST_CASE_ST(ut_setup, ut_teardown,
7592                         test_mb_AES_GCM_auth_decryption_test_case_256_3),
7593                 TEST_CASE_ST(ut_setup, ut_teardown,
7594                         test_mb_AES_GCM_auth_decryption_test_case_256_4),
7595                 TEST_CASE_ST(ut_setup, ut_teardown,
7596                         test_mb_AES_GCM_auth_decryption_test_case_256_5),
7597                 TEST_CASE_ST(ut_setup, ut_teardown,
7598                         test_mb_AES_GCM_auth_decryption_test_case_256_6),
7599                 TEST_CASE_ST(ut_setup, ut_teardown,
7600                         test_mb_AES_GCM_auth_decryption_test_case_256_7),
7601
7602                 /** AES GCM Authenticated Encryption big aad size */
7603                 TEST_CASE_ST(ut_setup, ut_teardown,
7604                         test_mb_AES_GCM_auth_encryption_test_case_aad_1),
7605                 TEST_CASE_ST(ut_setup, ut_teardown,
7606                         test_mb_AES_GCM_auth_encryption_test_case_aad_2),
7607
7608                 /** AES GCM Authenticated Decryption big aad size */
7609                 TEST_CASE_ST(ut_setup, ut_teardown,
7610                         test_mb_AES_GCM_auth_decryption_test_case_aad_1),
7611                 TEST_CASE_ST(ut_setup, ut_teardown,
7612                         test_mb_AES_GCM_auth_decryption_test_case_aad_2),
7613
7614                 /** AES GMAC Authentication */
7615                 TEST_CASE_ST(ut_setup, ut_teardown,
7616                         test_AES_GMAC_authentication_test_case_1),
7617                 TEST_CASE_ST(ut_setup, ut_teardown,
7618                         test_AES_GMAC_authentication_verify_test_case_1),
7619                 TEST_CASE_ST(ut_setup, ut_teardown,
7620                         test_AES_GMAC_authentication_test_case_3),
7621                 TEST_CASE_ST(ut_setup, ut_teardown,
7622                         test_AES_GMAC_authentication_verify_test_case_3),
7623                 TEST_CASE_ST(ut_setup, ut_teardown,
7624                         test_AES_GMAC_authentication_test_case_4),
7625                 TEST_CASE_ST(ut_setup, ut_teardown,
7626                         test_AES_GMAC_authentication_verify_test_case_4),
7627
7628                 /** Negative tests */
7629                 TEST_CASE_ST(ut_setup, ut_teardown,
7630                         authentication_verify_AES128_GMAC_fail_data_corrupt),
7631                 TEST_CASE_ST(ut_setup, ut_teardown,
7632                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
7633
7634                 /** Out of place tests */
7635                 TEST_CASE_ST(ut_setup, ut_teardown,
7636                         test_mb_AES_GCM_authenticated_encryption_oop),
7637                 TEST_CASE_ST(ut_setup, ut_teardown,
7638                         test_mb_AES_GCM_authenticated_decryption_oop),
7639
7640                 /** Session-less tests */
7641                 TEST_CASE_ST(ut_setup, ut_teardown,
7642                         test_mb_AES_GCM_authenticated_encryption_sessionless),
7643                 TEST_CASE_ST(ut_setup, ut_teardown,
7644                         test_mb_AES_GCM_authenticated_decryption_sessionless),
7645
7646                 /** Scatter-Gather */
7647                 TEST_CASE_ST(ut_setup, ut_teardown,
7648                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
7649
7650                 TEST_CASES_END() /**< NULL terminate unit test array */
7651         }
7652 };
7653
7654 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
7655         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
7656         .setup = testsuite_setup,
7657         .teardown = testsuite_teardown,
7658         .unit_test_cases = {
7659                 /** KASUMI encrypt only (UEA1) */
7660                 TEST_CASE_ST(ut_setup, ut_teardown,
7661                         test_kasumi_encryption_test_case_1),
7662                 TEST_CASE_ST(ut_setup, ut_teardown,
7663                         test_kasumi_encryption_test_case_1_sgl),
7664                 TEST_CASE_ST(ut_setup, ut_teardown,
7665                         test_kasumi_encryption_test_case_2),
7666                 TEST_CASE_ST(ut_setup, ut_teardown,
7667                         test_kasumi_encryption_test_case_3),
7668                 TEST_CASE_ST(ut_setup, ut_teardown,
7669                         test_kasumi_encryption_test_case_4),
7670                 TEST_CASE_ST(ut_setup, ut_teardown,
7671                         test_kasumi_encryption_test_case_5),
7672                 /** KASUMI decrypt only (UEA1) */
7673                 TEST_CASE_ST(ut_setup, ut_teardown,
7674                         test_kasumi_decryption_test_case_1),
7675                 TEST_CASE_ST(ut_setup, ut_teardown,
7676                         test_kasumi_decryption_test_case_2),
7677                 TEST_CASE_ST(ut_setup, ut_teardown,
7678                         test_kasumi_decryption_test_case_3),
7679                 TEST_CASE_ST(ut_setup, ut_teardown,
7680                         test_kasumi_decryption_test_case_4),
7681                 TEST_CASE_ST(ut_setup, ut_teardown,
7682                         test_kasumi_decryption_test_case_5),
7683
7684                 TEST_CASE_ST(ut_setup, ut_teardown,
7685                         test_kasumi_encryption_test_case_1_oop),
7686                 TEST_CASE_ST(ut_setup, ut_teardown,
7687                         test_kasumi_encryption_test_case_1_oop_sgl),
7688
7689
7690                 TEST_CASE_ST(ut_setup, ut_teardown,
7691                         test_kasumi_decryption_test_case_1_oop),
7692
7693                 /** KASUMI hash only (UIA1) */
7694                 TEST_CASE_ST(ut_setup, ut_teardown,
7695                         test_kasumi_hash_generate_test_case_1),
7696                 TEST_CASE_ST(ut_setup, ut_teardown,
7697                         test_kasumi_hash_generate_test_case_2),
7698                 TEST_CASE_ST(ut_setup, ut_teardown,
7699                         test_kasumi_hash_generate_test_case_3),
7700                 TEST_CASE_ST(ut_setup, ut_teardown,
7701                         test_kasumi_hash_generate_test_case_4),
7702                 TEST_CASE_ST(ut_setup, ut_teardown,
7703                         test_kasumi_hash_generate_test_case_5),
7704                 TEST_CASE_ST(ut_setup, ut_teardown,
7705                         test_kasumi_hash_generate_test_case_6),
7706                 TEST_CASE_ST(ut_setup, ut_teardown,
7707                         test_kasumi_hash_verify_test_case_1),
7708                 TEST_CASE_ST(ut_setup, ut_teardown,
7709                         test_kasumi_hash_verify_test_case_2),
7710                 TEST_CASE_ST(ut_setup, ut_teardown,
7711                         test_kasumi_hash_verify_test_case_3),
7712                 TEST_CASE_ST(ut_setup, ut_teardown,
7713                         test_kasumi_hash_verify_test_case_4),
7714                 TEST_CASE_ST(ut_setup, ut_teardown,
7715                         test_kasumi_hash_verify_test_case_5),
7716                 TEST_CASE_ST(ut_setup, ut_teardown,
7717                         test_kasumi_auth_cipher_test_case_1),
7718                 TEST_CASE_ST(ut_setup, ut_teardown,
7719                         test_kasumi_cipher_auth_test_case_1),
7720                 TEST_CASES_END() /**< NULL terminate unit test array */
7721         }
7722 };
7723 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
7724         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
7725         .setup = testsuite_setup,
7726         .teardown = testsuite_teardown,
7727         .unit_test_cases = {
7728                 /** SNOW 3G encrypt only (UEA2) */
7729                 TEST_CASE_ST(ut_setup, ut_teardown,
7730                         test_snow3g_encryption_test_case_1),
7731                 TEST_CASE_ST(ut_setup, ut_teardown,
7732                         test_snow3g_encryption_test_case_2),
7733                 TEST_CASE_ST(ut_setup, ut_teardown,
7734                         test_snow3g_encryption_test_case_3),
7735                 TEST_CASE_ST(ut_setup, ut_teardown,
7736                         test_snow3g_encryption_test_case_4),
7737                 TEST_CASE_ST(ut_setup, ut_teardown,
7738                         test_snow3g_encryption_test_case_5),
7739
7740                 TEST_CASE_ST(ut_setup, ut_teardown,
7741                         test_snow3g_encryption_test_case_1_oop),
7742                 TEST_CASE_ST(ut_setup, ut_teardown,
7743                                 test_snow3g_encryption_test_case_1_oop_sgl),
7744                 TEST_CASE_ST(ut_setup, ut_teardown,
7745                         test_snow3g_decryption_test_case_1_oop),
7746
7747                 TEST_CASE_ST(ut_setup, ut_teardown,
7748                         test_snow3g_encryption_test_case_1_offset_oop),
7749
7750                 /** SNOW 3G decrypt only (UEA2) */
7751                 TEST_CASE_ST(ut_setup, ut_teardown,
7752                         test_snow3g_decryption_test_case_1),
7753                 TEST_CASE_ST(ut_setup, ut_teardown,
7754                         test_snow3g_decryption_test_case_2),
7755                 TEST_CASE_ST(ut_setup, ut_teardown,
7756                         test_snow3g_decryption_test_case_3),
7757                 TEST_CASE_ST(ut_setup, ut_teardown,
7758                         test_snow3g_decryption_test_case_4),
7759                 TEST_CASE_ST(ut_setup, ut_teardown,
7760                         test_snow3g_decryption_test_case_5),
7761                 TEST_CASE_ST(ut_setup, ut_teardown,
7762                         test_snow3g_hash_generate_test_case_1),
7763                 TEST_CASE_ST(ut_setup, ut_teardown,
7764                         test_snow3g_hash_generate_test_case_2),
7765                 TEST_CASE_ST(ut_setup, ut_teardown,
7766                         test_snow3g_hash_generate_test_case_3),
7767                 /* Tests with buffers which length is not byte-aligned */
7768                 TEST_CASE_ST(ut_setup, ut_teardown,
7769                         test_snow3g_hash_generate_test_case_4),
7770                 TEST_CASE_ST(ut_setup, ut_teardown,
7771                         test_snow3g_hash_generate_test_case_5),
7772                 TEST_CASE_ST(ut_setup, ut_teardown,
7773                         test_snow3g_hash_generate_test_case_6),
7774                 TEST_CASE_ST(ut_setup, ut_teardown,
7775                         test_snow3g_hash_verify_test_case_1),
7776                 TEST_CASE_ST(ut_setup, ut_teardown,
7777                         test_snow3g_hash_verify_test_case_2),
7778                 TEST_CASE_ST(ut_setup, ut_teardown,
7779                         test_snow3g_hash_verify_test_case_3),
7780                 /* Tests with buffers which length is not byte-aligned */
7781                 TEST_CASE_ST(ut_setup, ut_teardown,
7782                         test_snow3g_hash_verify_test_case_4),
7783                 TEST_CASE_ST(ut_setup, ut_teardown,
7784                         test_snow3g_hash_verify_test_case_5),
7785                 TEST_CASE_ST(ut_setup, ut_teardown,
7786                         test_snow3g_hash_verify_test_case_6),
7787                 TEST_CASE_ST(ut_setup, ut_teardown,
7788                         test_snow3g_cipher_auth_test_case_1),
7789                 TEST_CASE_ST(ut_setup, ut_teardown,
7790                         test_snow3g_auth_cipher_test_case_1),
7791
7792                 TEST_CASES_END() /**< NULL terminate unit test array */
7793         }
7794 };
7795
7796 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
7797         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
7798         .setup = testsuite_setup,
7799         .teardown = testsuite_teardown,
7800         .unit_test_cases = {
7801                 /** ZUC encrypt only (EEA3) */
7802                 TEST_CASE_ST(ut_setup, ut_teardown,
7803                         test_zuc_encryption_test_case_1),
7804                 TEST_CASE_ST(ut_setup, ut_teardown,
7805                         test_zuc_encryption_test_case_2),
7806                 TEST_CASE_ST(ut_setup, ut_teardown,
7807                         test_zuc_encryption_test_case_3),
7808                 TEST_CASE_ST(ut_setup, ut_teardown,
7809                         test_zuc_encryption_test_case_4),
7810                 TEST_CASE_ST(ut_setup, ut_teardown,
7811                         test_zuc_encryption_test_case_5),
7812                 TEST_CASE_ST(ut_setup, ut_teardown,
7813                         test_zuc_hash_generate_test_case_1),
7814                 TEST_CASE_ST(ut_setup, ut_teardown,
7815                         test_zuc_hash_generate_test_case_2),
7816                 TEST_CASE_ST(ut_setup, ut_teardown,
7817                         test_zuc_hash_generate_test_case_3),
7818                 TEST_CASE_ST(ut_setup, ut_teardown,
7819                         test_zuc_hash_generate_test_case_4),
7820                 TEST_CASE_ST(ut_setup, ut_teardown,
7821                         test_zuc_hash_generate_test_case_5),
7822                 TEST_CASE_ST(ut_setup, ut_teardown,
7823                         test_zuc_encryption_test_case_6_sgl),
7824                 TEST_CASES_END() /**< NULL terminate unit test array */
7825         }
7826 };
7827
7828 static struct unit_test_suite cryptodev_null_testsuite  = {
7829         .suite_name = "Crypto Device NULL Unit Test Suite",
7830         .setup = testsuite_setup,
7831         .teardown = testsuite_teardown,
7832         .unit_test_cases = {
7833                 TEST_CASE_ST(ut_setup, ut_teardown,
7834                         test_null_auth_only_operation),
7835                 TEST_CASE_ST(ut_setup, ut_teardown,
7836                         test_null_cipher_only_operation),
7837                 TEST_CASE_ST(ut_setup, ut_teardown,
7838                         test_null_cipher_auth_operation),
7839                 TEST_CASE_ST(ut_setup, ut_teardown,
7840                         test_null_auth_cipher_operation),
7841                 TEST_CASE_ST(ut_setup, ut_teardown,
7842                         test_null_invalid_operation),
7843                 TEST_CASE_ST(ut_setup, ut_teardown,
7844                         test_null_burst_operation),
7845
7846                 TEST_CASES_END() /**< NULL terminate unit test array */
7847         }
7848 };
7849
7850 static int
7851 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
7852 {
7853         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
7854         return unit_test_suite_runner(&cryptodev_qat_testsuite);
7855 }
7856
7857 static int
7858 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
7859 {
7860         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
7861
7862         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
7863 }
7864
7865 static int
7866 test_cryptodev_openssl(void)
7867 {
7868         gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
7869
7870         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
7871 }
7872
7873 static int
7874 test_cryptodev_aesni_gcm(void)
7875 {
7876         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
7877
7878         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
7879 }
7880
7881 static int
7882 test_cryptodev_null(void)
7883 {
7884         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
7885
7886         return unit_test_suite_runner(&cryptodev_null_testsuite);
7887 }
7888
7889 static int
7890 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
7891 {
7892         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
7893
7894         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
7895 }
7896
7897 static int
7898 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
7899 {
7900         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
7901
7902         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
7903 }
7904
7905 static int
7906 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
7907 {
7908         gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
7909
7910         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
7911 }
7912
7913 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
7914 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
7915 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
7916 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
7917 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
7918 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
7919 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
7920 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);