crypto/aesni_mb: add single operation functionality
[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         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1740         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1741         sym_op->cipher.iv.length = iv_pad_len;
1742
1743         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1744         sym_op->cipher.data.length = cipher_len;
1745         sym_op->cipher.data.offset = cipher_offset;
1746         return 0;
1747 }
1748
1749 static int
1750 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1751                 enum rte_crypto_cipher_operation cipher_op,
1752                 enum rte_crypto_auth_operation auth_op,
1753                 enum rte_crypto_auth_algorithm auth_algo,
1754                 enum rte_crypto_cipher_algorithm cipher_algo,
1755                 const uint8_t *key, const uint8_t key_len,
1756                 const uint8_t aad_len, const uint8_t auth_len)
1757
1758 {
1759         uint8_t cipher_auth_key[key_len];
1760
1761         struct crypto_unittest_params *ut_params = &unittest_params;
1762
1763         memcpy(cipher_auth_key, key, key_len);
1764
1765         /* Setup Authentication Parameters */
1766         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1767         ut_params->auth_xform.next = NULL;
1768
1769         ut_params->auth_xform.auth.op = auth_op;
1770         ut_params->auth_xform.auth.algo = auth_algo;
1771         ut_params->auth_xform.auth.key.length = key_len;
1772         /* Hash key = cipher key */
1773         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1774         ut_params->auth_xform.auth.digest_length = auth_len;
1775         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1776
1777         /* Setup Cipher Parameters */
1778         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1779         ut_params->cipher_xform.next = &ut_params->auth_xform;
1780
1781         ut_params->cipher_xform.cipher.algo = cipher_algo;
1782         ut_params->cipher_xform.cipher.op = cipher_op;
1783         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1784         ut_params->cipher_xform.cipher.key.length = key_len;
1785
1786         TEST_HEXDUMP(stdout, "key:", key, key_len);
1787
1788         /* Create Crypto session*/
1789         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1790                                 &ut_params->cipher_xform);
1791
1792         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1793         return 0;
1794 }
1795
1796 static int
1797 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1798                 enum rte_crypto_cipher_operation cipher_op,
1799                 enum rte_crypto_auth_operation auth_op,
1800                 enum rte_crypto_auth_algorithm auth_algo,
1801                 enum rte_crypto_cipher_algorithm cipher_algo,
1802                 const uint8_t *key, const uint8_t key_len,
1803                 const uint8_t aad_len, const uint8_t auth_len)
1804 {
1805         uint8_t auth_cipher_key[key_len];
1806
1807         struct crypto_unittest_params *ut_params = &unittest_params;
1808
1809         memcpy(auth_cipher_key, key, key_len);
1810
1811         /* Setup Authentication Parameters */
1812         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1813         ut_params->auth_xform.auth.op = auth_op;
1814         ut_params->auth_xform.next = &ut_params->cipher_xform;
1815         ut_params->auth_xform.auth.algo = auth_algo;
1816         ut_params->auth_xform.auth.key.length = key_len;
1817         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1818         ut_params->auth_xform.auth.digest_length = auth_len;
1819         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1820
1821         /* Setup Cipher Parameters */
1822         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1823         ut_params->cipher_xform.next = NULL;
1824         ut_params->cipher_xform.cipher.algo = cipher_algo;
1825         ut_params->cipher_xform.cipher.op = cipher_op;
1826         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1827         ut_params->cipher_xform.cipher.key.length = key_len;
1828
1829         TEST_HEXDUMP(stdout, "key:", key, key_len);
1830
1831         /* Create Crypto session*/
1832         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1833                                 &ut_params->auth_xform);
1834
1835         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1836
1837         return 0;
1838 }
1839
1840 static int
1841 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
1842                 const unsigned auth_tag_len,
1843                 const uint8_t *aad, const unsigned aad_len,
1844                 unsigned data_pad_len,
1845                 enum rte_crypto_auth_operation op,
1846                 enum rte_crypto_auth_algorithm algo,
1847                 const unsigned auth_len, const unsigned auth_offset)
1848 {
1849         struct crypto_testsuite_params *ts_params = &testsuite_params;
1850
1851         struct crypto_unittest_params *ut_params = &unittest_params;
1852
1853         unsigned aad_buffer_len;
1854
1855         /* Generate Crypto op data structure */
1856         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1857                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1858         TEST_ASSERT_NOT_NULL(ut_params->op,
1859                 "Failed to allocate pktmbuf offload");
1860
1861         /* Set crypto operation data parameters */
1862         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1863
1864         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1865
1866         /* set crypto operation source mbuf */
1867         sym_op->m_src = ut_params->ibuf;
1868
1869         /* aad */
1870         /*
1871         * Always allocate the aad up to the block size.
1872         * The cryptodev API calls out -
1873         *  - the array must be big enough to hold the AAD, plus any
1874         *   space to round this up to the nearest multiple of the
1875         *   block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1876         */
1877         if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1878                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1879         else
1880                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1881         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1882                         ut_params->ibuf, aad_buffer_len);
1883         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1884                                         "no room to prepend aad");
1885         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1886                         ut_params->ibuf);
1887         sym_op->auth.aad.length = aad_len;
1888
1889         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1890         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1891
1892         TEST_HEXDUMP(stdout, "aad:",
1893                         sym_op->auth.aad.data, aad_len);
1894
1895         /* digest */
1896         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1897                                         ut_params->ibuf, auth_tag_len);
1898
1899         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1900                                 "no room to append auth tag");
1901         ut_params->digest = sym_op->auth.digest.data;
1902         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1903                         ut_params->ibuf, data_pad_len + aad_len);
1904         sym_op->auth.digest.length = auth_tag_len;
1905         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1906                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1907         else
1908                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1909
1910         TEST_HEXDUMP(stdout, "digest:",
1911                 sym_op->auth.digest.data,
1912                 sym_op->auth.digest.length);
1913
1914         sym_op->auth.data.length = auth_len;
1915         sym_op->auth.data.offset = auth_offset;
1916
1917         return 0;
1918 }
1919
1920 static int
1921 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
1922                 const unsigned auth_tag_len,
1923                 const uint8_t *aad, const uint8_t aad_len,
1924                 unsigned data_pad_len,
1925                 enum rte_crypto_auth_operation op,
1926                 enum rte_crypto_auth_algorithm auth_algo,
1927                 enum rte_crypto_cipher_algorithm cipher_algo,
1928                 const uint8_t *iv, const uint8_t iv_len,
1929                 const unsigned cipher_len, const unsigned cipher_offset,
1930                 const unsigned auth_len, const unsigned auth_offset)
1931 {
1932         struct crypto_testsuite_params *ts_params = &testsuite_params;
1933         struct crypto_unittest_params *ut_params = &unittest_params;
1934
1935         unsigned iv_pad_len = 0;
1936         unsigned aad_buffer_len;
1937
1938         /* Generate Crypto op data structure */
1939         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1940                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1941         TEST_ASSERT_NOT_NULL(ut_params->op,
1942                         "Failed to allocate pktmbuf offload");
1943         /* Set crypto operation data parameters */
1944         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1945
1946         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1947
1948         /* set crypto operation source mbuf */
1949         sym_op->m_src = ut_params->ibuf;
1950
1951         /* digest */
1952         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1953                         ut_params->ibuf, auth_tag_len);
1954
1955         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1956                         "no room to append auth tag");
1957         ut_params->digest = sym_op->auth.digest.data;
1958         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1959                         ut_params->ibuf, data_pad_len);
1960         sym_op->auth.digest.length = auth_tag_len;
1961         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1962                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1963         else
1964                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1965
1966         TEST_HEXDUMP(stdout, "digest:",
1967                 sym_op->auth.digest.data,
1968                 sym_op->auth.digest.length);
1969
1970         /* aad */
1971         /*
1972         * Always allocate the aad up to the block size.
1973         * The cryptodev API calls out -
1974         *  - the array must be big enough to hold the AAD, plus any
1975         *   space to round this up to the nearest multiple of the
1976         *   block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1977         */
1978         if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1979                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1980         else
1981                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1982         sym_op->auth.aad.data =
1983                 (uint8_t *)rte_pktmbuf_prepend(
1984                         ut_params->ibuf, aad_buffer_len);
1985         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1986                         "no room to prepend aad");
1987         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1988                         ut_params->ibuf);
1989         sym_op->auth.aad.length = aad_len;
1990         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1991         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1992         TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1993
1994         /* iv */
1995         if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1996                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1997         else
1998                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1999         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2000                 ut_params->ibuf, iv_pad_len);
2001
2002         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2003         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2004         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2005         sym_op->cipher.iv.length = iv_pad_len;
2006         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2007         sym_op->cipher.data.length = cipher_len;
2008         sym_op->cipher.data.offset = cipher_offset + auth_offset;
2009         sym_op->auth.data.length = auth_len;
2010         sym_op->auth.data.offset = auth_offset + cipher_offset;
2011
2012         return 0;
2013 }
2014
2015 static int
2016 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
2017                 const uint8_t *iv, const uint8_t iv_len,
2018                 const uint8_t *aad, const uint8_t aad_len,
2019                 unsigned data_pad_len,
2020                 const unsigned cipher_len, const unsigned cipher_offset,
2021                 const unsigned auth_len, const unsigned auth_offset,
2022                 enum rte_crypto_auth_algorithm auth_algo,
2023                 enum rte_crypto_cipher_algorithm cipher_algo)
2024 {
2025         struct crypto_testsuite_params *ts_params = &testsuite_params;
2026         struct crypto_unittest_params *ut_params = &unittest_params;
2027
2028         unsigned iv_pad_len = 0;
2029         unsigned aad_buffer_len = 0;
2030
2031         /* Generate Crypto op data structure */
2032         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2033                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2034         TEST_ASSERT_NOT_NULL(ut_params->op,
2035                         "Failed to allocate pktmbuf offload");
2036
2037         /* Set crypto operation data parameters */
2038         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2039
2040         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2041
2042         /* set crypto operation source mbuf */
2043         sym_op->m_src = ut_params->ibuf;
2044
2045         /* digest */
2046         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2047                         ut_params->ibuf, auth_tag_len);
2048
2049         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2050                         "no room to append auth tag");
2051
2052         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2053                         ut_params->ibuf, data_pad_len);
2054         sym_op->auth.digest.length = auth_tag_len;
2055
2056         memset(sym_op->auth.digest.data, 0, auth_tag_len);
2057
2058         TEST_HEXDUMP(stdout, "digest:",
2059                         sym_op->auth.digest.data,
2060                         sym_op->auth.digest.length);
2061
2062         /* aad */
2063         /*
2064         * Always allocate the aad up to the block size.
2065         * The cryptodev API calls out -
2066         *  - the array must be big enough to hold the AAD, plus any
2067         *   space to round this up to the nearest multiple of the
2068         *   block size (8 bytes for KASUMI 16 bytes).
2069         */
2070         if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2071                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2072         else
2073                 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2074         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2075         ut_params->ibuf, aad_buffer_len);
2076         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2077                                 "no room to prepend aad");
2078         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2079                                 ut_params->ibuf);
2080         sym_op->auth.aad.length = aad_len;
2081         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2082         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2083         TEST_HEXDUMP(stdout, "aad:",
2084                         sym_op->auth.aad.data, aad_len);
2085
2086         /* iv */
2087         if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2088                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2089         else
2090                 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2091
2092         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2093                 ut_params->ibuf, iv_pad_len);
2094         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2095
2096         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2097         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2098         sym_op->cipher.iv.length = iv_pad_len;
2099
2100         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2101
2102         sym_op->cipher.data.length = cipher_len;
2103         sym_op->cipher.data.offset = auth_offset + cipher_offset;
2104
2105         sym_op->auth.data.length = auth_len;
2106         sym_op->auth.data.offset = auth_offset + cipher_offset;
2107
2108         return 0;
2109 }
2110
2111 static int
2112 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2113 {
2114         struct crypto_testsuite_params *ts_params = &testsuite_params;
2115         struct crypto_unittest_params *ut_params = &unittest_params;
2116
2117         int retval;
2118         unsigned plaintext_pad_len;
2119         unsigned plaintext_len;
2120         uint8_t *plaintext;
2121
2122         /* Create SNOW 3G session */
2123         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2124                         tdata->key.data, tdata->key.len,
2125                         tdata->aad.len, tdata->digest.len,
2126                         RTE_CRYPTO_AUTH_OP_GENERATE,
2127                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2128         if (retval < 0)
2129                 return retval;
2130
2131         /* alloc mbuf and set payload */
2132         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2133
2134         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2135         rte_pktmbuf_tailroom(ut_params->ibuf));
2136
2137         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2138         /* Append data which is padded to a multiple of */
2139         /* the algorithms block size */
2140         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2141         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2142                                 plaintext_pad_len);
2143         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2144
2145         /* Create SNOW 3G operation */
2146         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2147                         tdata->aad.data, tdata->aad.len,
2148                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2149                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2150                         tdata->validAuthLenInBits.len,
2151                         tdata->validAuthOffsetLenInBits.len);
2152         if (retval < 0)
2153                 return retval;
2154
2155         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2156                                 ut_params->op);
2157         ut_params->obuf = ut_params->op->sym->m_src;
2158         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2159         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2160                         + plaintext_pad_len + tdata->aad.len;
2161
2162         /* Validate obuf */
2163         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2164         ut_params->digest,
2165         tdata->digest.data,
2166         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2167         "SNOW 3G Generated auth tag not as expected");
2168
2169         return 0;
2170 }
2171
2172 static int
2173 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2174 {
2175         struct crypto_testsuite_params *ts_params = &testsuite_params;
2176         struct crypto_unittest_params *ut_params = &unittest_params;
2177
2178         int retval;
2179         unsigned plaintext_pad_len;
2180         unsigned plaintext_len;
2181         uint8_t *plaintext;
2182
2183         /* Create SNOW 3G session */
2184         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2185                                 tdata->key.data, tdata->key.len,
2186                                 tdata->aad.len, tdata->digest.len,
2187                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2188                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2189         if (retval < 0)
2190                 return retval;
2191         /* alloc mbuf and set payload */
2192         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2193
2194         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2195         rte_pktmbuf_tailroom(ut_params->ibuf));
2196
2197         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2198         /* Append data which is padded to a multiple of */
2199         /* the algorithms block size */
2200         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2201         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2202                                 plaintext_pad_len);
2203         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2204
2205         /* Create SNOW 3G operation */
2206         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2207                         tdata->digest.len,
2208                         tdata->aad.data, tdata->aad.len,
2209                         plaintext_pad_len,
2210                         RTE_CRYPTO_AUTH_OP_VERIFY,
2211                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2212                         tdata->validAuthLenInBits.len,
2213                         tdata->validAuthOffsetLenInBits.len);
2214         if (retval < 0)
2215                 return retval;
2216
2217         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2218                                 ut_params->op);
2219         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2220         ut_params->obuf = ut_params->op->sym->m_src;
2221         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2222                                 + plaintext_pad_len + tdata->aad.len;
2223
2224         /* Validate obuf */
2225         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2226                 return 0;
2227         else
2228                 return -1;
2229
2230         return 0;
2231 }
2232
2233 static int
2234 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2235 {
2236         struct crypto_testsuite_params *ts_params = &testsuite_params;
2237         struct crypto_unittest_params *ut_params = &unittest_params;
2238
2239         int retval;
2240         unsigned plaintext_pad_len;
2241         unsigned plaintext_len;
2242         uint8_t *plaintext;
2243
2244         /* Create KASUMI session */
2245         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2246                         tdata->key.data, tdata->key.len,
2247                         tdata->aad.len, tdata->digest.len,
2248                         RTE_CRYPTO_AUTH_OP_GENERATE,
2249                         RTE_CRYPTO_AUTH_KASUMI_F9);
2250         if (retval < 0)
2251                 return retval;
2252
2253         /* alloc mbuf and set payload */
2254         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2255
2256         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2257         rte_pktmbuf_tailroom(ut_params->ibuf));
2258
2259         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2260         /* Append data which is padded to a multiple of */
2261         /* the algorithms block size */
2262         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2263         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2264                                 plaintext_pad_len);
2265         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2266
2267         /* Create KASUMI operation */
2268         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2269                         tdata->aad.data, tdata->aad.len,
2270                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2271                         RTE_CRYPTO_AUTH_KASUMI_F9,
2272                         tdata->validAuthLenInBits.len,
2273                         tdata->validAuthOffsetLenInBits.len);
2274         if (retval < 0)
2275                 return retval;
2276
2277         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2278                                 ut_params->op);
2279         ut_params->obuf = ut_params->op->sym->m_src;
2280         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2281         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2282                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
2283
2284         /* Validate obuf */
2285         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2286         ut_params->digest,
2287         tdata->digest.data,
2288         DIGEST_BYTE_LENGTH_KASUMI_F9,
2289         "KASUMI Generated auth tag not as expected");
2290
2291         return 0;
2292 }
2293
2294 static int
2295 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2296 {
2297         struct crypto_testsuite_params *ts_params = &testsuite_params;
2298         struct crypto_unittest_params *ut_params = &unittest_params;
2299
2300         int retval;
2301         unsigned plaintext_pad_len;
2302         unsigned plaintext_len;
2303         uint8_t *plaintext;
2304
2305         /* Create KASUMI session */
2306         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2307                                 tdata->key.data, tdata->key.len,
2308                                 tdata->aad.len, tdata->digest.len,
2309                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2310                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2311         if (retval < 0)
2312                 return retval;
2313         /* alloc mbuf and set payload */
2314         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2315
2316         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2317         rte_pktmbuf_tailroom(ut_params->ibuf));
2318
2319         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2320         /* Append data which is padded to a multiple */
2321         /* of the algorithms block size */
2322         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2323         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2324                                 plaintext_pad_len);
2325         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2326
2327         /* Create KASUMI operation */
2328         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2329                         tdata->digest.len,
2330                         tdata->aad.data, tdata->aad.len,
2331                         plaintext_pad_len,
2332                         RTE_CRYPTO_AUTH_OP_VERIFY,
2333                         RTE_CRYPTO_AUTH_KASUMI_F9,
2334                         tdata->validAuthLenInBits.len,
2335                         tdata->validAuthOffsetLenInBits.len);
2336         if (retval < 0)
2337                 return retval;
2338
2339         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2340                                 ut_params->op);
2341         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2342         ut_params->obuf = ut_params->op->sym->m_src;
2343         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2344                                 + plaintext_pad_len + tdata->aad.len;
2345
2346         /* Validate obuf */
2347         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2348                 return 0;
2349         else
2350                 return -1;
2351
2352         return 0;
2353 }
2354
2355 static int
2356 test_snow3g_hash_generate_test_case_1(void)
2357 {
2358         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2359 }
2360
2361 static int
2362 test_snow3g_hash_generate_test_case_2(void)
2363 {
2364         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2365 }
2366
2367 static int
2368 test_snow3g_hash_generate_test_case_3(void)
2369 {
2370         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2371 }
2372
2373 static int
2374 test_snow3g_hash_generate_test_case_4(void)
2375 {
2376         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2377 }
2378
2379 static int
2380 test_snow3g_hash_generate_test_case_5(void)
2381 {
2382         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2383 }
2384
2385 static int
2386 test_snow3g_hash_generate_test_case_6(void)
2387 {
2388         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2389 }
2390
2391 static int
2392 test_snow3g_hash_verify_test_case_1(void)
2393 {
2394         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2395
2396 }
2397
2398 static int
2399 test_snow3g_hash_verify_test_case_2(void)
2400 {
2401         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2402 }
2403
2404 static int
2405 test_snow3g_hash_verify_test_case_3(void)
2406 {
2407         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2408 }
2409
2410 static int
2411 test_snow3g_hash_verify_test_case_4(void)
2412 {
2413         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2414 }
2415
2416 static int
2417 test_snow3g_hash_verify_test_case_5(void)
2418 {
2419         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2420 }
2421
2422 static int
2423 test_snow3g_hash_verify_test_case_6(void)
2424 {
2425         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2426 }
2427
2428 static int
2429 test_kasumi_hash_generate_test_case_1(void)
2430 {
2431         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2432 }
2433
2434 static int
2435 test_kasumi_hash_generate_test_case_2(void)
2436 {
2437         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2438 }
2439
2440 static int
2441 test_kasumi_hash_generate_test_case_3(void)
2442 {
2443         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2444 }
2445
2446 static int
2447 test_kasumi_hash_generate_test_case_4(void)
2448 {
2449         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2450 }
2451
2452 static int
2453 test_kasumi_hash_generate_test_case_5(void)
2454 {
2455         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2456 }
2457
2458 static int
2459 test_kasumi_hash_generate_test_case_6(void)
2460 {
2461         return test_kasumi_authentication(&kasumi_hash_test_case_6);
2462 }
2463
2464 static int
2465 test_kasumi_hash_verify_test_case_1(void)
2466 {
2467         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2468 }
2469
2470 static int
2471 test_kasumi_hash_verify_test_case_2(void)
2472 {
2473         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2474 }
2475
2476 static int
2477 test_kasumi_hash_verify_test_case_3(void)
2478 {
2479         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2480 }
2481
2482 static int
2483 test_kasumi_hash_verify_test_case_4(void)
2484 {
2485         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2486 }
2487
2488 static int
2489 test_kasumi_hash_verify_test_case_5(void)
2490 {
2491         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2492 }
2493
2494 static int
2495 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2496 {
2497         struct crypto_testsuite_params *ts_params = &testsuite_params;
2498         struct crypto_unittest_params *ut_params = &unittest_params;
2499
2500         int retval;
2501         uint8_t *plaintext, *ciphertext;
2502         unsigned plaintext_pad_len;
2503         unsigned plaintext_len;
2504
2505         /* Create KASUMI session */
2506         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2507                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2508                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2509                                         tdata->key.data, tdata->key.len);
2510         if (retval < 0)
2511                 return retval;
2512
2513         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2514
2515         /* Clear mbuf payload */
2516         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2517                rte_pktmbuf_tailroom(ut_params->ibuf));
2518
2519         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2520         /* Append data which is padded to a multiple */
2521         /* of the algorithms block size */
2522         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2523         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2524                                 plaintext_pad_len);
2525         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2526
2527         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2528
2529         /* Create KASUMI operation */
2530         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2531                                         tdata->plaintext.len,
2532                                         tdata->validCipherOffsetLenInBits.len,
2533                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2534         if (retval < 0)
2535                 return retval;
2536
2537         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2538                                                 ut_params->op);
2539         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2540
2541         ut_params->obuf = ut_params->op->sym->m_dst;
2542         if (ut_params->obuf)
2543                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2544                                 + tdata->iv.len;
2545         else
2546                 ciphertext = plaintext;
2547
2548         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2549
2550         /* Validate obuf */
2551         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2552                 ciphertext,
2553                 tdata->ciphertext.data,
2554                 tdata->validCipherLenInBits.len,
2555                 "KASUMI Ciphertext data not as expected");
2556         return 0;
2557 }
2558
2559 static int
2560 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2561 {
2562         struct crypto_testsuite_params *ts_params = &testsuite_params;
2563         struct crypto_unittest_params *ut_params = &unittest_params;
2564
2565         int retval;
2566         uint8_t *plaintext, *ciphertext;
2567         unsigned plaintext_pad_len;
2568         unsigned plaintext_len;
2569
2570         /* Create KASUMI session */
2571         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2572                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2573                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2574                                         tdata->key.data, tdata->key.len);
2575         if (retval < 0)
2576                 return retval;
2577
2578         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2579         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2580
2581         /* Clear mbuf payload */
2582         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2583                rte_pktmbuf_tailroom(ut_params->ibuf));
2584
2585         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2586         /* Append data which is padded to a multiple */
2587         /* of the algorithms block size */
2588         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2589         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2590                                 plaintext_pad_len);
2591         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2592         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2593
2594         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2595
2596         /* Create KASUMI operation */
2597         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2598                                         tdata->iv.len,
2599                                         tdata->plaintext.len,
2600                                         tdata->validCipherOffsetLenInBits.len,
2601                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2602         if (retval < 0)
2603                 return retval;
2604
2605         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2606                                                 ut_params->op);
2607         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2608
2609         ut_params->obuf = ut_params->op->sym->m_dst;
2610         if (ut_params->obuf)
2611                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2612                                 + tdata->iv.len;
2613         else
2614                 ciphertext = plaintext;
2615
2616         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2617
2618         /* Validate obuf */
2619         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2620                 ciphertext,
2621                 tdata->ciphertext.data,
2622                 tdata->validCipherLenInBits.len,
2623                 "KASUMI Ciphertext data not as expected");
2624         return 0;
2625 }
2626
2627 static int
2628 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2629 {
2630         struct crypto_testsuite_params *ts_params = &testsuite_params;
2631         struct crypto_unittest_params *ut_params = &unittest_params;
2632
2633         int retval;
2634         uint8_t *ciphertext, *plaintext;
2635         unsigned ciphertext_pad_len;
2636         unsigned ciphertext_len;
2637
2638         /* Create KASUMI session */
2639         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2640                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2641                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2642                                         tdata->key.data, tdata->key.len);
2643         if (retval < 0)
2644                 return retval;
2645
2646         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2647         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2648
2649         /* Clear mbuf payload */
2650         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2651                rte_pktmbuf_tailroom(ut_params->ibuf));
2652
2653         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2654         /* Append data which is padded to a multiple */
2655         /* of the algorithms block size */
2656         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2657         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2658                                 ciphertext_pad_len);
2659         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2660         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2661
2662         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2663
2664         /* Create KASUMI operation */
2665         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2666                                         tdata->iv.len,
2667                                         tdata->ciphertext.len,
2668                                         tdata->validCipherOffsetLenInBits.len,
2669                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2670         if (retval < 0)
2671                 return retval;
2672
2673         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2674                                                 ut_params->op);
2675         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2676
2677         ut_params->obuf = ut_params->op->sym->m_dst;
2678         if (ut_params->obuf)
2679                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2680                                 + tdata->iv.len;
2681         else
2682                 plaintext = ciphertext;
2683
2684         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2685
2686         /* Validate obuf */
2687         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2688                 plaintext,
2689                 tdata->plaintext.data,
2690                 tdata->validCipherLenInBits.len,
2691                 "KASUMI Plaintext data not as expected");
2692         return 0;
2693 }
2694
2695 static int
2696 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2697 {
2698         struct crypto_testsuite_params *ts_params = &testsuite_params;
2699         struct crypto_unittest_params *ut_params = &unittest_params;
2700
2701         int retval;
2702         uint8_t *ciphertext, *plaintext;
2703         unsigned ciphertext_pad_len;
2704         unsigned ciphertext_len;
2705
2706         /* Create KASUMI session */
2707         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2708                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2709                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2710                                         tdata->key.data, tdata->key.len);
2711         if (retval < 0)
2712                 return retval;
2713
2714         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2715
2716         /* Clear mbuf payload */
2717         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2718                rte_pktmbuf_tailroom(ut_params->ibuf));
2719
2720         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2721         /* Append data which is padded to a multiple */
2722         /* of the algorithms block size */
2723         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2724         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2725                                 ciphertext_pad_len);
2726         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2727
2728         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2729
2730         /* Create KASUMI operation */
2731         retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2732                                         tdata->iv.len,
2733                                         tdata->ciphertext.len,
2734                                         tdata->validCipherOffsetLenInBits.len,
2735                                         RTE_CRYPTO_CIPHER_KASUMI_F8);
2736         if (retval < 0)
2737                 return retval;
2738
2739         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2740                                                 ut_params->op);
2741         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2742
2743         ut_params->obuf = ut_params->op->sym->m_dst;
2744         if (ut_params->obuf)
2745                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2746                                 + tdata->iv.len;
2747         else
2748                 plaintext = ciphertext;
2749
2750         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2751
2752         /* Validate obuf */
2753         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2754                 plaintext,
2755                 tdata->plaintext.data,
2756                 tdata->validCipherLenInBits.len,
2757                 "KASUMI Plaintext data not as expected");
2758         return 0;
2759 }
2760
2761 static int
2762 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2763 {
2764         struct crypto_testsuite_params *ts_params = &testsuite_params;
2765         struct crypto_unittest_params *ut_params = &unittest_params;
2766
2767         int retval;
2768         uint8_t *plaintext, *ciphertext;
2769         unsigned plaintext_pad_len;
2770         unsigned plaintext_len;
2771
2772         /* Create SNOW 3G session */
2773         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2774                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2775                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2776                                         tdata->key.data, tdata->key.len);
2777         if (retval < 0)
2778                 return retval;
2779
2780         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2781
2782         /* Clear mbuf payload */
2783         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2784                rte_pktmbuf_tailroom(ut_params->ibuf));
2785
2786         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2787         /* Append data which is padded to a multiple of */
2788         /* the algorithms block size */
2789         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2790         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2791                                 plaintext_pad_len);
2792         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2793
2794         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2795
2796         /* Create SNOW 3G operation */
2797         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2798                                         tdata->validCipherLenInBits.len,
2799                                         tdata->validCipherOffsetLenInBits.len,
2800                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2801         if (retval < 0)
2802                 return retval;
2803
2804         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2805                                                 ut_params->op);
2806         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2807
2808         ut_params->obuf = ut_params->op->sym->m_dst;
2809         if (ut_params->obuf)
2810                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2811                                 + tdata->iv.len;
2812         else
2813                 ciphertext = plaintext;
2814
2815         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2816
2817         /* Validate obuf */
2818         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2819                 ciphertext,
2820                 tdata->ciphertext.data,
2821                 tdata->validDataLenInBits.len,
2822                 "SNOW 3G Ciphertext data not as expected");
2823         return 0;
2824 }
2825
2826
2827 static int
2828 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2829 {
2830         struct crypto_testsuite_params *ts_params = &testsuite_params;
2831         struct crypto_unittest_params *ut_params = &unittest_params;
2832         uint8_t *plaintext, *ciphertext;
2833
2834         int retval;
2835         unsigned plaintext_pad_len;
2836         unsigned plaintext_len;
2837
2838         /* Create SNOW 3G session */
2839         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2840                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2841                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2842                                         tdata->key.data, tdata->key.len);
2843         if (retval < 0)
2844                 return retval;
2845
2846         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2847         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2848
2849         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2850                         "Failed to allocate input buffer in mempool");
2851         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2852                         "Failed to allocate output buffer in mempool");
2853
2854         /* Clear mbuf payload */
2855         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2856                rte_pktmbuf_tailroom(ut_params->ibuf));
2857
2858         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2859         /* Append data which is padded to a multiple of */
2860         /* the algorithms block size */
2861         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2862         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2863                                 plaintext_pad_len);
2864         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2865         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2866
2867         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2868
2869         /* Create SNOW 3G operation */
2870         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2871                                         tdata->iv.len,
2872                                         tdata->validCipherLenInBits.len,
2873                                         tdata->validCipherOffsetLenInBits.len,
2874                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2875         if (retval < 0)
2876                 return retval;
2877
2878         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2879                                                 ut_params->op);
2880         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2881
2882         ut_params->obuf = ut_params->op->sym->m_dst;
2883         if (ut_params->obuf)
2884                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2885                                 + tdata->iv.len;
2886         else
2887                 ciphertext = plaintext;
2888
2889         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2890
2891         /* Validate obuf */
2892         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2893                 ciphertext,
2894                 tdata->ciphertext.data,
2895                 tdata->validDataLenInBits.len,
2896                 "SNOW 3G Ciphertext data not as expected");
2897         return 0;
2898 }
2899
2900 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2901 static void
2902 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2903 {
2904         uint8_t curr_byte, prev_byte;
2905         uint32_t length_in_bytes = ceil_byte_length(length + offset);
2906         uint8_t lower_byte_mask = (1 << offset) - 1;
2907         unsigned i;
2908
2909         prev_byte = buffer[0];
2910         buffer[0] >>= offset;
2911
2912         for (i = 1; i < length_in_bytes; i++) {
2913                 curr_byte = buffer[i];
2914                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2915                                 (curr_byte >> offset);
2916                 prev_byte = curr_byte;
2917         }
2918 }
2919
2920 static int
2921 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2922 {
2923         struct crypto_testsuite_params *ts_params = &testsuite_params;
2924         struct crypto_unittest_params *ut_params = &unittest_params;
2925         uint8_t *plaintext, *ciphertext;
2926         int retval;
2927         uint32_t plaintext_len;
2928         uint32_t plaintext_pad_len;
2929         uint8_t extra_offset = 4;
2930         uint8_t *expected_ciphertext_shifted;
2931
2932         /* Create SNOW 3G session */
2933         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2934                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2935                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2936                                         tdata->key.data, tdata->key.len);
2937         if (retval < 0)
2938                 return retval;
2939
2940         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2941         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2942
2943         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2944                         "Failed to allocate input buffer in mempool");
2945         TEST_ASSERT_NOT_NULL(ut_params->obuf,
2946                         "Failed to allocate output buffer in mempool");
2947
2948         /* Clear mbuf payload */
2949         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2950                rte_pktmbuf_tailroom(ut_params->ibuf));
2951
2952         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2953         /*
2954          * Append data which is padded to a
2955          * multiple of the algorithms block size
2956          */
2957         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2958
2959         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2960                                                 plaintext_pad_len);
2961
2962         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2963
2964         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2965         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2966
2967 #ifdef RTE_APP_TEST_DEBUG
2968         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2969 #endif
2970         /* Create SNOW 3G operation */
2971         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2972                                         tdata->iv.len,
2973                                         tdata->validCipherLenInBits.len,
2974                                         tdata->validCipherOffsetLenInBits.len +
2975                                         extra_offset,
2976                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2977         if (retval < 0)
2978                 return retval;
2979
2980         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2981                                                 ut_params->op);
2982         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2983
2984         ut_params->obuf = ut_params->op->sym->m_dst;
2985         if (ut_params->obuf)
2986                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2987                                 + tdata->iv.len;
2988         else
2989                 ciphertext = plaintext;
2990
2991 #ifdef RTE_APP_TEST_DEBUG
2992         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2993 #endif
2994
2995         expected_ciphertext_shifted = rte_malloc(NULL,
2996                         ceil_byte_length(plaintext_len + extra_offset), 0);
2997
2998         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2999                         "failed to reserve memory for ciphertext shifted\n");
3000
3001         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3002                         ceil_byte_length(tdata->ciphertext.len));
3003         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3004                         extra_offset);
3005         /* Validate obuf */
3006         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3007                 ciphertext,
3008                 expected_ciphertext_shifted,
3009                 tdata->validDataLenInBits.len,
3010                 extra_offset,
3011                 "SNOW 3G Ciphertext data not as expected");
3012         return 0;
3013 }
3014
3015 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3016 {
3017         struct crypto_testsuite_params *ts_params = &testsuite_params;
3018         struct crypto_unittest_params *ut_params = &unittest_params;
3019
3020         int retval;
3021
3022         uint8_t *plaintext, *ciphertext;
3023         unsigned ciphertext_pad_len;
3024         unsigned ciphertext_len;
3025
3026         /* Create SNOW 3G session */
3027         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3028                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3029                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3030                                         tdata->key.data, tdata->key.len);
3031         if (retval < 0)
3032                 return retval;
3033
3034         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3035
3036         /* Clear mbuf payload */
3037         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3038                rte_pktmbuf_tailroom(ut_params->ibuf));
3039
3040         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3041         /* Append data which is padded to a multiple of */
3042         /* the algorithms block size */
3043         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3044         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3045                                 ciphertext_pad_len);
3046         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3047
3048         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3049
3050         /* Create SNOW 3G operation */
3051         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3052                                         tdata->validCipherLenInBits.len,
3053                                         tdata->validCipherOffsetLenInBits.len,
3054                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3055         if (retval < 0)
3056                 return retval;
3057
3058         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3059                                                 ut_params->op);
3060         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3061         ut_params->obuf = ut_params->op->sym->m_dst;
3062         if (ut_params->obuf)
3063                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3064                                 + tdata->iv.len;
3065         else
3066                 plaintext = ciphertext;
3067
3068         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3069
3070         /* Validate obuf */
3071         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3072                                 tdata->plaintext.data,
3073                                 tdata->validDataLenInBits.len,
3074                                 "SNOW 3G Plaintext data not as expected");
3075         return 0;
3076 }
3077
3078 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3079 {
3080         struct crypto_testsuite_params *ts_params = &testsuite_params;
3081         struct crypto_unittest_params *ut_params = &unittest_params;
3082
3083         int retval;
3084
3085         uint8_t *plaintext, *ciphertext;
3086         unsigned ciphertext_pad_len;
3087         unsigned ciphertext_len;
3088
3089         /* Create SNOW 3G session */
3090         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3091                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3092                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3093                                         tdata->key.data, tdata->key.len);
3094         if (retval < 0)
3095                 return retval;
3096
3097         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3098         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3099
3100         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3101                         "Failed to allocate input buffer");
3102         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3103                         "Failed to allocate output buffer");
3104
3105         /* Clear mbuf payload */
3106         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3107                rte_pktmbuf_tailroom(ut_params->ibuf));
3108
3109         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3110                        rte_pktmbuf_tailroom(ut_params->obuf));
3111
3112         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3113         /* Append data which is padded to a multiple of */
3114         /* the algorithms block size */
3115         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3116         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3117                                 ciphertext_pad_len);
3118         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3119         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3120
3121         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3122
3123         /* Create SNOW 3G operation */
3124         retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3125                                         tdata->iv.len,
3126                                         tdata->validCipherLenInBits.len,
3127                                         tdata->validCipherOffsetLenInBits.len,
3128                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3129         if (retval < 0)
3130                 return retval;
3131
3132         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3133                                                 ut_params->op);
3134         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3135         ut_params->obuf = ut_params->op->sym->m_dst;
3136         if (ut_params->obuf)
3137                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3138                                 + tdata->iv.len;
3139         else
3140                 plaintext = ciphertext;
3141
3142         TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3143
3144         /* Validate obuf */
3145         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3146                                 tdata->plaintext.data,
3147                                 tdata->validDataLenInBits.len,
3148                                 "SNOW 3G Plaintext data not as expected");
3149         return 0;
3150 }
3151
3152 static int
3153 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3154 {
3155         struct crypto_testsuite_params *ts_params = &testsuite_params;
3156         struct crypto_unittest_params *ut_params = &unittest_params;
3157
3158         int retval;
3159
3160         uint8_t *plaintext, *ciphertext;
3161         unsigned plaintext_pad_len;
3162         unsigned plaintext_len;
3163
3164         /* Create SNOW 3G session */
3165         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3166                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3167                         RTE_CRYPTO_AUTH_OP_GENERATE,
3168                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3169                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3170                         tdata->key.data, tdata->key.len,
3171                         tdata->aad.len, tdata->digest.len);
3172         if (retval < 0)
3173                 return retval;
3174         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3175
3176         /* clear mbuf payload */
3177         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3178                         rte_pktmbuf_tailroom(ut_params->ibuf));
3179
3180         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3181         /* Append data which is padded to a multiple of */
3182         /* the algorithms block size */
3183         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3184         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3185                                 plaintext_pad_len);
3186         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3187
3188         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3189
3190         /* Create SNOW 3G operation */
3191         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3192                         tdata->digest.len, tdata->aad.data,
3193                         tdata->aad.len, /*tdata->plaintext.len,*/
3194                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3195                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3196                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3197                         tdata->iv.data, tdata->iv.len,
3198                         tdata->validCipherLenInBits.len,
3199                         tdata->validCipherOffsetLenInBits.len,
3200                         tdata->validAuthLenInBits.len,
3201                         tdata->validAuthOffsetLenInBits.len
3202                         );
3203         if (retval < 0)
3204                 return retval;
3205
3206         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3207                         ut_params->op);
3208         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3209         ut_params->obuf = ut_params->op->sym->m_src;
3210         if (ut_params->obuf)
3211                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3212                                 + tdata->iv.len + tdata->aad.len;
3213         else
3214                 ciphertext = plaintext;
3215
3216         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3217         /* Validate obuf */
3218         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3219                         ciphertext,
3220                         tdata->ciphertext.data,
3221                         tdata->validDataLenInBits.len,
3222                         "SNOW 3G Ciphertext data not as expected");
3223
3224         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3225             + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3226
3227         /* Validate obuf */
3228         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3229                         ut_params->digest,
3230                         tdata->digest.data,
3231                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3232                         "SNOW 3G Generated auth tag not as expected");
3233         return 0;
3234 }
3235 static int
3236 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
3237 {
3238         struct crypto_testsuite_params *ts_params = &testsuite_params;
3239         struct crypto_unittest_params *ut_params = &unittest_params;
3240
3241         int retval;
3242
3243         uint8_t *plaintext, *ciphertext;
3244         unsigned plaintext_pad_len;
3245         unsigned plaintext_len;
3246
3247         /* Create SNOW 3G session */
3248         retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
3249                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3250                         RTE_CRYPTO_AUTH_OP_GENERATE,
3251                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3252                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3253                         tdata->key.data, tdata->key.len,
3254                         tdata->aad.len, tdata->digest.len);
3255         if (retval < 0)
3256                 return retval;
3257
3258         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3259
3260         /* clear mbuf payload */
3261         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3262                         rte_pktmbuf_tailroom(ut_params->ibuf));
3263
3264         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3265         /* Append data which is padded to a multiple of */
3266         /* the algorithms block size */
3267         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3268         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3269                                 plaintext_pad_len);
3270         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3271
3272         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3273
3274         /* Create SNOW 3G operation */
3275         retval = create_wireless_algo_auth_cipher_operation(
3276                 tdata->digest.len,
3277                 tdata->iv.data, tdata->iv.len,
3278                 tdata->aad.data, tdata->aad.len,
3279                 plaintext_pad_len,
3280                 tdata->validCipherLenInBits.len,
3281                 tdata->validCipherOffsetLenInBits.len,
3282                 tdata->validAuthLenInBits.len,
3283                 tdata->validAuthOffsetLenInBits.len,
3284                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3285                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
3286         );
3287
3288         if (retval < 0)
3289                 return retval;
3290
3291         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3292                         ut_params->op);
3293         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3294         ut_params->obuf = ut_params->op->sym->m_src;
3295         if (ut_params->obuf)
3296                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3297                                 + tdata->aad.len + tdata->iv.len;
3298         else
3299                 ciphertext = plaintext;
3300
3301         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3302                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3303         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3304
3305         /* Validate obuf */
3306         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3307                 ciphertext,
3308                 tdata->ciphertext.data,
3309                 tdata->validDataLenInBits.len,
3310                 "SNOW 3G Ciphertext data not as expected");
3311
3312         /* Validate obuf */
3313         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3314                 ut_params->digest,
3315                 tdata->digest.data,
3316                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3317                 "SNOW 3G Generated auth tag not as expected");
3318         return 0;
3319 }
3320
3321 static int
3322 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
3323 {
3324         struct crypto_testsuite_params *ts_params = &testsuite_params;
3325         struct crypto_unittest_params *ut_params = &unittest_params;
3326
3327         int retval;
3328
3329         uint8_t *plaintext, *ciphertext;
3330         unsigned plaintext_pad_len;
3331         unsigned plaintext_len;
3332
3333         /* Create KASUMI session */
3334         retval = create_wireless_algo_auth_cipher_session(
3335                         ts_params->valid_devs[0],
3336                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3337                         RTE_CRYPTO_AUTH_OP_GENERATE,
3338                         RTE_CRYPTO_AUTH_KASUMI_F9,
3339                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3340                         tdata->key.data, tdata->key.len,
3341                         tdata->aad.len, tdata->digest.len);
3342         if (retval < 0)
3343                 return retval;
3344         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3345
3346         /* clear mbuf payload */
3347         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3348                         rte_pktmbuf_tailroom(ut_params->ibuf));
3349
3350         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3351         /* Append data which is padded to a multiple of */
3352         /* the algorithms block size */
3353         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3354         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3355                                 plaintext_pad_len);
3356         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3357
3358         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3359
3360         /* Create KASUMI operation */
3361         retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
3362                                 tdata->iv.data, tdata->iv.len,
3363                                 tdata->aad.data, tdata->aad.len,
3364                                 plaintext_pad_len,
3365                                 tdata->validCipherLenInBits.len,
3366                                 tdata->validCipherOffsetLenInBits.len,
3367                                 tdata->validAuthLenInBits.len,
3368                                 tdata->validAuthOffsetLenInBits.len,
3369                                 RTE_CRYPTO_AUTH_KASUMI_F9,
3370                                 RTE_CRYPTO_CIPHER_KASUMI_F8
3371                                 );
3372
3373         if (retval < 0)
3374                 return retval;
3375
3376         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3377                         ut_params->op);
3378         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3379         ut_params->obuf = ut_params->op->sym->m_src;
3380         if (ut_params->obuf)
3381                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3382                                 + tdata->iv.len + tdata->aad.len;
3383         else
3384                 ciphertext = plaintext;
3385
3386         /* Validate obuf */
3387         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3388                         ciphertext,
3389                         tdata->ciphertext.data,
3390                         tdata->validCipherLenInBits.len,
3391                         "KASUMI Ciphertext data not as expected");
3392         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3393             + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3394
3395         /* Validate obuf */
3396         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3397                         ut_params->digest,
3398                         tdata->digest.data,
3399                         DIGEST_BYTE_LENGTH_KASUMI_F9,
3400                         "KASUMI Generated auth tag not as expected");
3401         return 0;
3402 }
3403
3404 static int
3405 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
3406 {
3407         struct crypto_testsuite_params *ts_params = &testsuite_params;
3408         struct crypto_unittest_params *ut_params = &unittest_params;
3409
3410         int retval;
3411
3412         uint8_t *plaintext, *ciphertext;
3413         unsigned plaintext_pad_len;
3414         unsigned plaintext_len;
3415
3416         /* Create KASUMI session */
3417         retval = create_wireless_algo_cipher_auth_session(
3418                         ts_params->valid_devs[0],
3419                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3420                         RTE_CRYPTO_AUTH_OP_GENERATE,
3421                         RTE_CRYPTO_AUTH_KASUMI_F9,
3422                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3423                         tdata->key.data, tdata->key.len,
3424                         tdata->aad.len, tdata->digest.len);
3425         if (retval < 0)
3426                 return retval;
3427
3428         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3429
3430         /* clear mbuf payload */
3431         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3432                         rte_pktmbuf_tailroom(ut_params->ibuf));
3433
3434         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3435         /* Append data which is padded to a multiple of */
3436         /* the algorithms block size */
3437         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3438         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3439                                 plaintext_pad_len);
3440         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3441
3442         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3443
3444         /* Create KASUMI operation */
3445         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3446                                 tdata->digest.len, tdata->aad.data,
3447                                 tdata->aad.len,
3448                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3449                                 RTE_CRYPTO_AUTH_KASUMI_F9,
3450                                 RTE_CRYPTO_CIPHER_KASUMI_F8,
3451                                 tdata->iv.data, tdata->iv.len,
3452                                 tdata->validCipherLenInBits.len,
3453                                 tdata->validCipherOffsetLenInBits.len,
3454                                 tdata->validAuthLenInBits.len,
3455                                 tdata->validAuthOffsetLenInBits.len
3456                                 );
3457         if (retval < 0)
3458                 return retval;
3459
3460         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3461                         ut_params->op);
3462         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3463         ut_params->obuf = ut_params->op->sym->m_src;
3464         if (ut_params->obuf)
3465                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3466                                 + tdata->aad.len + tdata->iv.len;
3467         else
3468                 ciphertext = plaintext;
3469
3470         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3471                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3472
3473         /* Validate obuf */
3474         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3475                 ciphertext,
3476                 tdata->ciphertext.data,
3477                 tdata->validCipherLenInBits.len,
3478                 "KASUMI Ciphertext data not as expected");
3479
3480         /* Validate obuf */
3481         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3482                 ut_params->digest,
3483                 tdata->digest.data,
3484                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3485                 "KASUMI Generated auth tag not as expected");
3486         return 0;
3487 }
3488
3489 static int
3490 test_zuc_encryption(const struct zuc_test_data *tdata)
3491 {
3492         struct crypto_testsuite_params *ts_params = &testsuite_params;
3493         struct crypto_unittest_params *ut_params = &unittest_params;
3494
3495         int retval;
3496         uint8_t *plaintext, *ciphertext;
3497         unsigned plaintext_pad_len;
3498         unsigned plaintext_len;
3499
3500         /* Create ZUC session */
3501         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3502                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3503                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
3504                                         tdata->key.data, tdata->key.len);
3505         if (retval < 0)
3506                 return retval;
3507
3508         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3509
3510         /* Clear mbuf payload */
3511         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3512                rte_pktmbuf_tailroom(ut_params->ibuf));
3513
3514         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3515         /* Append data which is padded to a multiple */
3516         /* of the algorithms block size */
3517         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3518         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3519                                 plaintext_pad_len);
3520         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3521
3522         TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3523
3524         /* Create ZUC operation */
3525         retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3526                                         tdata->plaintext.len,
3527                                         tdata->validCipherOffsetLenInBits.len,
3528                                         RTE_CRYPTO_CIPHER_ZUC_EEA3);
3529         if (retval < 0)
3530                 return retval;
3531
3532         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3533                                                 ut_params->op);
3534         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3535
3536         ut_params->obuf = ut_params->op->sym->m_dst;
3537         if (ut_params->obuf)
3538                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3539                                 + tdata->iv.len;
3540         else
3541                 ciphertext = plaintext;
3542
3543         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3544
3545         /* Validate obuf */
3546         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3547                 ciphertext,
3548                 tdata->ciphertext.data,
3549                 tdata->validCipherLenInBits.len,
3550                 "ZUC Ciphertext data not as expected");
3551         return 0;
3552 }
3553
3554 static int
3555 test_zuc_authentication(const struct zuc_hash_test_data *tdata)
3556 {
3557         struct crypto_testsuite_params *ts_params = &testsuite_params;
3558         struct crypto_unittest_params *ut_params = &unittest_params;
3559
3560         int retval;
3561         unsigned plaintext_pad_len;
3562         unsigned plaintext_len;
3563         uint8_t *plaintext;
3564
3565         /* Create ZUC session */
3566         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3567                         tdata->key.data, tdata->key.len,
3568                         tdata->aad.len, tdata->digest.len,
3569                         RTE_CRYPTO_AUTH_OP_GENERATE,
3570                         RTE_CRYPTO_AUTH_ZUC_EIA3);
3571         if (retval < 0)
3572                 return retval;
3573
3574         /* alloc mbuf and set payload */
3575         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3576
3577         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3578         rte_pktmbuf_tailroom(ut_params->ibuf));
3579
3580         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3581         /* Append data which is padded to a multiple of */
3582         /* the algorithms block size */
3583         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3584         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3585                                 plaintext_pad_len);
3586         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3587
3588         /* Create ZUC operation */
3589         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3590                         tdata->aad.data, tdata->aad.len,
3591                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3592                         RTE_CRYPTO_AUTH_ZUC_EIA3,
3593                         tdata->validAuthLenInBits.len,
3594                         tdata->validAuthOffsetLenInBits.len);
3595         if (retval < 0)
3596                 return retval;
3597
3598         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3599                                 ut_params->op);
3600         ut_params->obuf = ut_params->op->sym->m_src;
3601         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3602         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3603                         + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
3604
3605         /* Validate obuf */
3606         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3607         ut_params->digest,
3608         tdata->digest.data,
3609         DIGEST_BYTE_LENGTH_KASUMI_F9,
3610         "ZUC Generated auth tag not as expected");
3611
3612         return 0;
3613 }
3614
3615 static int
3616 test_kasumi_encryption_test_case_1(void)
3617 {
3618         return test_kasumi_encryption(&kasumi_test_case_1);
3619 }
3620
3621 static int
3622 test_kasumi_encryption_test_case_1_oop(void)
3623 {
3624         return test_kasumi_encryption_oop(&kasumi_test_case_1);
3625 }
3626
3627 static int
3628 test_kasumi_encryption_test_case_2(void)
3629 {
3630         return test_kasumi_encryption(&kasumi_test_case_2);
3631 }
3632
3633 static int
3634 test_kasumi_encryption_test_case_3(void)
3635 {
3636         return test_kasumi_encryption(&kasumi_test_case_3);
3637 }
3638
3639 static int
3640 test_kasumi_encryption_test_case_4(void)
3641 {
3642         return test_kasumi_encryption(&kasumi_test_case_4);
3643 }
3644
3645 static int
3646 test_kasumi_encryption_test_case_5(void)
3647 {
3648         return test_kasumi_encryption(&kasumi_test_case_5);
3649 }
3650
3651 static int
3652 test_kasumi_decryption_test_case_1(void)
3653 {
3654         return test_kasumi_decryption(&kasumi_test_case_1);
3655 }
3656
3657 static int
3658 test_kasumi_decryption_test_case_1_oop(void)
3659 {
3660         return test_kasumi_decryption_oop(&kasumi_test_case_1);
3661 }
3662
3663 static int
3664 test_kasumi_decryption_test_case_2(void)
3665 {
3666         return test_kasumi_decryption(&kasumi_test_case_2);
3667 }
3668
3669 static int
3670 test_kasumi_decryption_test_case_3(void)
3671 {
3672         return test_kasumi_decryption(&kasumi_test_case_3);
3673 }
3674
3675 static int
3676 test_kasumi_decryption_test_case_4(void)
3677 {
3678         return test_kasumi_decryption(&kasumi_test_case_4);
3679 }
3680
3681 static int
3682 test_kasumi_decryption_test_case_5(void)
3683 {
3684         return test_kasumi_decryption(&kasumi_test_case_5);
3685 }
3686 static int
3687 test_snow3g_encryption_test_case_1(void)
3688 {
3689         return test_snow3g_encryption(&snow3g_test_case_1);
3690 }
3691
3692 static int
3693 test_snow3g_encryption_test_case_1_oop(void)
3694 {
3695         return test_snow3g_encryption_oop(&snow3g_test_case_1);
3696 }
3697
3698 static int
3699 test_snow3g_encryption_test_case_1_offset_oop(void)
3700 {
3701         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3702 }
3703
3704 static int
3705 test_snow3g_encryption_test_case_2(void)
3706 {
3707         return test_snow3g_encryption(&snow3g_test_case_2);
3708 }
3709
3710 static int
3711 test_snow3g_encryption_test_case_3(void)
3712 {
3713         return test_snow3g_encryption(&snow3g_test_case_3);
3714 }
3715
3716 static int
3717 test_snow3g_encryption_test_case_4(void)
3718 {
3719         return test_snow3g_encryption(&snow3g_test_case_4);
3720 }
3721
3722 static int
3723 test_snow3g_encryption_test_case_5(void)
3724 {
3725         return test_snow3g_encryption(&snow3g_test_case_5);
3726 }
3727
3728 static int
3729 test_snow3g_decryption_test_case_1(void)
3730 {
3731         return test_snow3g_decryption(&snow3g_test_case_1);
3732 }
3733
3734 static int
3735 test_snow3g_decryption_test_case_1_oop(void)
3736 {
3737         return test_snow3g_decryption_oop(&snow3g_test_case_1);
3738 }
3739
3740 static int
3741 test_snow3g_decryption_test_case_2(void)
3742 {
3743         return test_snow3g_decryption(&snow3g_test_case_2);
3744 }
3745
3746 static int
3747 test_snow3g_decryption_test_case_3(void)
3748 {
3749         return test_snow3g_decryption(&snow3g_test_case_3);
3750 }
3751
3752 static int
3753 test_snow3g_decryption_test_case_4(void)
3754 {
3755         return test_snow3g_decryption(&snow3g_test_case_4);
3756 }
3757
3758 static int
3759 test_snow3g_decryption_test_case_5(void)
3760 {
3761         return test_snow3g_decryption(&snow3g_test_case_5);
3762 }
3763 static int
3764 test_snow3g_cipher_auth_test_case_1(void)
3765 {
3766         return test_snow3g_cipher_auth(&snow3g_test_case_3);
3767 }
3768
3769 static int
3770 test_snow3g_auth_cipher_test_case_1(void)
3771 {
3772         return test_snow3g_auth_cipher(&snow3g_test_case_6);
3773 }
3774
3775 static int
3776 test_kasumi_auth_cipher_test_case_1(void)
3777 {
3778         return test_kasumi_auth_cipher(&kasumi_test_case_3);
3779 }
3780
3781 static int
3782 test_kasumi_cipher_auth_test_case_1(void)
3783 {
3784         return test_kasumi_cipher_auth(&kasumi_test_case_6);
3785 }
3786
3787 static int
3788 test_zuc_encryption_test_case_1(void)
3789 {
3790         return test_zuc_encryption(&zuc_test_case_1);
3791 }
3792
3793 static int
3794 test_zuc_encryption_test_case_2(void)
3795 {
3796         return test_zuc_encryption(&zuc_test_case_2);
3797 }
3798
3799 static int
3800 test_zuc_encryption_test_case_3(void)
3801 {
3802         return test_zuc_encryption(&zuc_test_case_3);
3803 }
3804
3805 static int
3806 test_zuc_encryption_test_case_4(void)
3807 {
3808         return test_zuc_encryption(&zuc_test_case_4);
3809 }
3810
3811 static int
3812 test_zuc_encryption_test_case_5(void)
3813 {
3814         return test_zuc_encryption(&zuc_test_case_5);
3815 }
3816
3817 static int
3818 test_zuc_hash_generate_test_case_1(void)
3819 {
3820         return test_zuc_authentication(&zuc_hash_test_case_1);
3821 }
3822
3823 static int
3824 test_zuc_hash_generate_test_case_2(void)
3825 {
3826         return test_zuc_authentication(&zuc_hash_test_case_2);
3827 }
3828
3829 static int
3830 test_zuc_hash_generate_test_case_3(void)
3831 {
3832         return test_zuc_authentication(&zuc_hash_test_case_3);
3833 }
3834
3835 static int
3836 test_zuc_hash_generate_test_case_4(void)
3837 {
3838         return test_zuc_authentication(&zuc_hash_test_case_4);
3839 }
3840
3841 static int
3842 test_zuc_hash_generate_test_case_5(void)
3843 {
3844         return test_zuc_authentication(&zuc_hash_test_case_5);
3845 }
3846
3847 static int
3848 test_3DES_chain_qat_all(void)
3849 {
3850         struct crypto_testsuite_params *ts_params = &testsuite_params;
3851         int status;
3852
3853         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3854                 ts_params->op_mpool, ts_params->valid_devs[0],
3855                 RTE_CRYPTODEV_QAT_SYM_PMD,
3856                 BLKCIPHER_3DES_CHAIN_TYPE);
3857
3858         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3859
3860         return TEST_SUCCESS;
3861 }
3862
3863 static int
3864 test_DES_cipheronly_qat_all(void)
3865 {
3866         struct crypto_testsuite_params *ts_params = &testsuite_params;
3867         int status;
3868
3869         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3870                 ts_params->op_mpool, ts_params->valid_devs[0],
3871                 RTE_CRYPTODEV_QAT_SYM_PMD,
3872                 BLKCIPHER_DES_CIPHERONLY_TYPE);
3873
3874         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3875
3876         return TEST_SUCCESS;
3877 }
3878
3879 static int
3880 test_3DES_cipheronly_qat_all(void)
3881 {
3882         struct crypto_testsuite_params *ts_params = &testsuite_params;
3883         int status;
3884
3885         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3886                 ts_params->op_mpool, ts_params->valid_devs[0],
3887                 RTE_CRYPTODEV_QAT_SYM_PMD,
3888                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
3889
3890         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3891
3892         return TEST_SUCCESS;
3893 }
3894
3895 static int
3896 test_3DES_chain_openssl_all(void)
3897 {
3898         struct crypto_testsuite_params *ts_params = &testsuite_params;
3899         int status;
3900
3901         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3902                 ts_params->op_mpool, ts_params->valid_devs[0],
3903                 RTE_CRYPTODEV_OPENSSL_PMD,
3904                 BLKCIPHER_3DES_CHAIN_TYPE);
3905
3906         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3907
3908         return TEST_SUCCESS;
3909 }
3910
3911 static int
3912 test_3DES_cipheronly_openssl_all(void)
3913 {
3914         struct crypto_testsuite_params *ts_params = &testsuite_params;
3915         int status;
3916
3917         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
3918                 ts_params->op_mpool, ts_params->valid_devs[0],
3919                 RTE_CRYPTODEV_OPENSSL_PMD,
3920                 BLKCIPHER_3DES_CIPHERONLY_TYPE);
3921
3922         TEST_ASSERT_EQUAL(status, 0, "Test failed");
3923
3924         return TEST_SUCCESS;
3925 }
3926
3927 /* ***** AES-GCM Tests ***** */
3928
3929 static int
3930 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3931                 const uint8_t *key, const uint8_t key_len,
3932                 const uint8_t aad_len, const uint8_t auth_len,
3933                 enum rte_crypto_auth_operation auth_op)
3934 {
3935         uint8_t cipher_key[key_len];
3936
3937         struct crypto_unittest_params *ut_params = &unittest_params;
3938
3939         memcpy(cipher_key, key, key_len);
3940
3941         /* Setup Cipher Parameters */
3942         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3943         ut_params->cipher_xform.next = NULL;
3944
3945         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3946         ut_params->auth_xform.auth.op = auth_op;
3947         ut_params->cipher_xform.cipher.op = op;
3948         ut_params->cipher_xform.cipher.key.data = cipher_key;
3949         ut_params->cipher_xform.cipher.key.length = key_len;
3950
3951         TEST_HEXDUMP(stdout, "key:", key, key_len);
3952
3953         /* Setup Authentication Parameters */
3954         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3955         ut_params->auth_xform.next = NULL;
3956
3957         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3958
3959         ut_params->auth_xform.auth.digest_length = auth_len;
3960         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3961         ut_params->auth_xform.auth.key.length = 0;
3962         ut_params->auth_xform.auth.key.data = NULL;
3963
3964         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3965                 ut_params->cipher_xform.next = &ut_params->auth_xform;
3966
3967                 /* Create Crypto session*/
3968                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3969                                 &ut_params->cipher_xform);
3970         } else {/* Create Crypto session*/
3971                 ut_params->auth_xform.next = &ut_params->cipher_xform;
3972                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3973                                 &ut_params->auth_xform);
3974         }
3975
3976         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3977
3978         return 0;
3979 }
3980
3981 static int
3982 create_gcm_operation(enum rte_crypto_cipher_operation op,
3983                 const uint8_t *auth_tag, const unsigned auth_tag_len,
3984                 const uint8_t *iv, const unsigned iv_len,
3985                 const uint8_t *aad, const unsigned aad_len,
3986                 const unsigned data_len, unsigned data_pad_len)
3987 {
3988         struct crypto_testsuite_params *ts_params = &testsuite_params;
3989         struct crypto_unittest_params *ut_params = &unittest_params;
3990
3991         unsigned iv_pad_len = 0, aad_buffer_len;
3992
3993         /* Generate Crypto op data structure */
3994         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3995                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3996         TEST_ASSERT_NOT_NULL(ut_params->op,
3997                         "Failed to allocate symmetric crypto operation struct");
3998
3999         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4000
4001         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4002                         ut_params->ibuf, auth_tag_len);
4003         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4004                         "no room to append digest");
4005         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4006                         ut_params->ibuf, data_pad_len);
4007         sym_op->auth.digest.length = auth_tag_len;
4008
4009         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
4010                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
4011                 TEST_HEXDUMP(stdout, "digest:",
4012                                 sym_op->auth.digest.data,
4013                                 sym_op->auth.digest.length);
4014         }
4015
4016         /* iv */
4017         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
4018
4019         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4020                         ut_params->ibuf, iv_pad_len);
4021         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4022
4023         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4024         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4025         sym_op->cipher.iv.length = iv_len;
4026
4027         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
4028
4029         /*
4030          * Always allocate the aad up to the block size.
4031          * The cryptodev API calls out -
4032          *  - the array must be big enough to hold the AAD, plus any
4033          *   space to round this up to the nearest multiple of the
4034          *   block size (16 bytes).
4035          */
4036         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
4037
4038         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
4039                         ut_params->ibuf, aad_buffer_len);
4040         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4041                         "no room to prepend aad");
4042         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
4043                         ut_params->ibuf);
4044         sym_op->auth.aad.length = aad_len;
4045
4046         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
4047         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
4048
4049         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4050         TEST_HEXDUMP(stdout, "aad:",
4051                         sym_op->auth.aad.data, aad_len);
4052
4053         sym_op->cipher.data.length = data_len;
4054         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
4055
4056         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
4057         sym_op->auth.data.length = data_len;
4058
4059         return 0;
4060 }
4061
4062 static int
4063 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
4064 {
4065         struct crypto_testsuite_params *ts_params = &testsuite_params;
4066         struct crypto_unittest_params *ut_params = &unittest_params;
4067
4068         int retval;
4069
4070         uint8_t *plaintext, *ciphertext, *auth_tag;
4071         uint16_t plaintext_pad_len;
4072
4073         /* Create GCM session */
4074         retval = create_gcm_session(ts_params->valid_devs[0],
4075                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4076                         tdata->key.data, tdata->key.len,
4077                         tdata->aad.len, tdata->auth_tag.len,
4078                         RTE_CRYPTO_AUTH_OP_GENERATE);
4079         if (retval < 0)
4080                 return retval;
4081
4082
4083         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4084
4085         /* clear mbuf payload */
4086         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4087                         rte_pktmbuf_tailroom(ut_params->ibuf));
4088
4089         /*
4090          * Append data which is padded to a multiple
4091          * of the algorithms block size
4092          */
4093         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4094
4095         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4096                         plaintext_pad_len);
4097         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4098
4099         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4100
4101         /* Create GCM opertaion */
4102         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4103                         tdata->auth_tag.data, tdata->auth_tag.len,
4104                         tdata->iv.data, tdata->iv.len,
4105                         tdata->aad.data, tdata->aad.len,
4106                         tdata->plaintext.len, plaintext_pad_len);
4107         if (retval < 0)
4108                 return retval;
4109
4110         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4111
4112         ut_params->op->sym->m_src = ut_params->ibuf;
4113
4114         /* Process crypto operation */
4115         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4116                         ut_params->op), "failed to process sym crypto op");
4117
4118         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4119                         "crypto op processing failed");
4120
4121         if (ut_params->op->sym->m_dst) {
4122                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4123                                 uint8_t *);
4124                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4125                                 uint8_t *, plaintext_pad_len);
4126         } else {
4127                 ciphertext = plaintext;
4128                 auth_tag = plaintext + plaintext_pad_len;
4129         }
4130
4131         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4132         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4133
4134         /* Validate obuf */
4135         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4136                         ciphertext,
4137                         tdata->ciphertext.data,
4138                         tdata->ciphertext.len,
4139                         "GCM Ciphertext data not as expected");
4140
4141         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4142                         auth_tag,
4143                         tdata->auth_tag.data,
4144                         tdata->auth_tag.len,
4145                         "GCM Generated auth tag not as expected");
4146
4147         return 0;
4148
4149 }
4150
4151 static int
4152 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
4153 {
4154         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
4155 }
4156
4157 static int
4158 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
4159 {
4160         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
4161 }
4162
4163 static int
4164 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
4165 {
4166         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
4167 }
4168
4169 static int
4170 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
4171 {
4172         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
4173 }
4174
4175 static int
4176 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
4177 {
4178         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
4179 }
4180
4181 static int
4182 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
4183 {
4184         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
4185 }
4186
4187 static int
4188 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
4189 {
4190         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
4191 }
4192
4193 static int
4194 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
4195 {
4196         struct crypto_testsuite_params *ts_params = &testsuite_params;
4197         struct crypto_unittest_params *ut_params = &unittest_params;
4198
4199         int retval;
4200
4201         uint8_t *plaintext, *ciphertext;
4202         uint16_t ciphertext_pad_len;
4203
4204         /* Create GCM session */
4205         retval = create_gcm_session(ts_params->valid_devs[0],
4206                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4207                         tdata->key.data, tdata->key.len,
4208                         tdata->aad.len, tdata->auth_tag.len,
4209                         RTE_CRYPTO_AUTH_OP_VERIFY);
4210         if (retval < 0)
4211                 return retval;
4212
4213
4214         /* alloc mbuf and set payload */
4215         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4216
4217         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4218                         rte_pktmbuf_tailroom(ut_params->ibuf));
4219
4220         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4221
4222         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4223                         ciphertext_pad_len);
4224         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
4225
4226         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4227
4228         /* Create GCM opertaion */
4229         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
4230                         tdata->auth_tag.data, tdata->auth_tag.len,
4231                         tdata->iv.data, tdata->iv.len,
4232                         tdata->aad.data, tdata->aad.len,
4233                         tdata->ciphertext.len, ciphertext_pad_len);
4234         if (retval < 0)
4235                 return retval;
4236
4237
4238         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4239
4240         ut_params->op->sym->m_src = ut_params->ibuf;
4241
4242         /* Process crypto operation */
4243         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4244                         ut_params->op), "failed to process sym crypto op");
4245
4246         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4247                         "crypto op processing failed");
4248
4249         if (ut_params->op->sym->m_dst)
4250                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4251                                 uint8_t *);
4252         else
4253                 plaintext = ciphertext;
4254
4255         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
4256
4257         /* Validate obuf */
4258         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4259                         plaintext,
4260                         tdata->plaintext.data,
4261                         tdata->plaintext.len,
4262                         "GCM plaintext data not as expected");
4263
4264         TEST_ASSERT_EQUAL(ut_params->op->status,
4265                         RTE_CRYPTO_OP_STATUS_SUCCESS,
4266                         "GCM authentication failed");
4267         return 0;
4268 }
4269
4270 static int
4271 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
4272 {
4273         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
4274 }
4275
4276 static int
4277 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
4278 {
4279         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
4280 }
4281
4282 static int
4283 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
4284 {
4285         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
4286 }
4287
4288 static int
4289 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
4290 {
4291         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
4292 }
4293
4294 static int
4295 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
4296 {
4297         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
4298 }
4299
4300 static int
4301 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
4302 {
4303         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
4304 }
4305
4306 static int
4307 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
4308 {
4309         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
4310 }
4311
4312 static int
4313 test_stats(void)
4314 {
4315         struct crypto_testsuite_params *ts_params = &testsuite_params;
4316         struct rte_cryptodev_stats stats;
4317         struct rte_cryptodev *dev;
4318         cryptodev_stats_get_t temp_pfn;
4319
4320         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4321         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
4322                         &stats) == -ENODEV),
4323                 "rte_cryptodev_stats_get invalid dev failed");
4324         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
4325                 "rte_cryptodev_stats_get invalid Param failed");
4326         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
4327         temp_pfn = dev->dev_ops->stats_get;
4328         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
4329         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
4330                         == -ENOTSUP),
4331                 "rte_cryptodev_stats_get invalid Param failed");
4332         dev->dev_ops->stats_get = temp_pfn;
4333
4334         /* Test expected values */
4335         ut_setup();
4336         test_AES_CBC_HMAC_SHA1_encrypt_digest();
4337         ut_teardown();
4338         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4339                         &stats),
4340                 "rte_cryptodev_stats_get failed");
4341         TEST_ASSERT((stats.enqueued_count == 1),
4342                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4343         TEST_ASSERT((stats.dequeued_count == 1),
4344                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4345         TEST_ASSERT((stats.enqueue_err_count == 0),
4346                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4347         TEST_ASSERT((stats.dequeue_err_count == 0),
4348                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4349
4350         /* invalid device but should ignore and not reset device stats*/
4351         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
4352         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4353                         &stats),
4354                 "rte_cryptodev_stats_get failed");
4355         TEST_ASSERT((stats.enqueued_count == 1),
4356                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4357
4358         /* check that a valid reset clears stats */
4359         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4360         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4361                         &stats),
4362                                           "rte_cryptodev_stats_get failed");
4363         TEST_ASSERT((stats.enqueued_count == 0),
4364                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4365         TEST_ASSERT((stats.dequeued_count == 0),
4366                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4367
4368         return TEST_SUCCESS;
4369 }
4370
4371 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
4372                                    struct crypto_unittest_params *ut_params,
4373                                    enum rte_crypto_auth_operation op,
4374                                    const struct HMAC_MD5_vector *test_case)
4375 {
4376         uint8_t key[64];
4377
4378         memcpy(key, test_case->key.data, test_case->key.len);
4379
4380         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4381         ut_params->auth_xform.next = NULL;
4382         ut_params->auth_xform.auth.op = op;
4383
4384         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
4385
4386         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
4387         ut_params->auth_xform.auth.add_auth_data_length = 0;
4388         ut_params->auth_xform.auth.key.length = test_case->key.len;
4389         ut_params->auth_xform.auth.key.data = key;
4390
4391         ut_params->sess = rte_cryptodev_sym_session_create(
4392                 ts_params->valid_devs[0], &ut_params->auth_xform);
4393
4394         if (ut_params->sess == NULL)
4395                 return TEST_FAILED;
4396
4397         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4398
4399         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4400                         rte_pktmbuf_tailroom(ut_params->ibuf));
4401
4402         return 0;
4403 }
4404
4405 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
4406                               const struct HMAC_MD5_vector *test_case,
4407                               uint8_t **plaintext)
4408 {
4409         uint16_t plaintext_pad_len;
4410
4411         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4412
4413         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4414                                 16);
4415
4416         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4417                         plaintext_pad_len);
4418         memcpy(*plaintext, test_case->plaintext.data,
4419                         test_case->plaintext.len);
4420
4421         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4422                         ut_params->ibuf, MD5_DIGEST_LEN);
4423         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4424                         "no room to append digest");
4425         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4426                         ut_params->ibuf, plaintext_pad_len);
4427         sym_op->auth.digest.length = MD5_DIGEST_LEN;
4428
4429         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4430                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
4431                            test_case->auth_tag.len);
4432         }
4433
4434         sym_op->auth.data.offset = 0;
4435         sym_op->auth.data.length = test_case->plaintext.len;
4436
4437         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4438         ut_params->op->sym->m_src = ut_params->ibuf;
4439
4440         return 0;
4441 }
4442
4443 static int
4444 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
4445 {
4446         uint16_t plaintext_pad_len;
4447         uint8_t *plaintext, *auth_tag;
4448
4449         struct crypto_testsuite_params *ts_params = &testsuite_params;
4450         struct crypto_unittest_params *ut_params = &unittest_params;
4451
4452         if (MD5_HMAC_create_session(ts_params, ut_params,
4453                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
4454                 return TEST_FAILED;
4455
4456         /* Generate Crypto op data structure */
4457         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4458                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4459         TEST_ASSERT_NOT_NULL(ut_params->op,
4460                         "Failed to allocate symmetric crypto operation struct");
4461
4462         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4463                                 16);
4464
4465         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4466                 return TEST_FAILED;
4467
4468         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4469                         ut_params->op), "failed to process sym crypto op");
4470
4471         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4472                         "crypto op processing failed");
4473
4474         if (ut_params->op->sym->m_dst) {
4475                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4476                                 uint8_t *, plaintext_pad_len);
4477         } else {
4478                 auth_tag = plaintext + plaintext_pad_len;
4479         }
4480
4481         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4482                         auth_tag,
4483                         test_case->auth_tag.data,
4484                         test_case->auth_tag.len,
4485                         "HMAC_MD5 generated tag not as expected");
4486
4487         return TEST_SUCCESS;
4488 }
4489
4490 static int
4491 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
4492 {
4493         uint8_t *plaintext;
4494
4495         struct crypto_testsuite_params *ts_params = &testsuite_params;
4496         struct crypto_unittest_params *ut_params = &unittest_params;
4497
4498         if (MD5_HMAC_create_session(ts_params, ut_params,
4499                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
4500                 return TEST_FAILED;
4501         }
4502
4503         /* Generate Crypto op data structure */
4504         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4505                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4506         TEST_ASSERT_NOT_NULL(ut_params->op,
4507                         "Failed to allocate symmetric crypto operation struct");
4508
4509         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4510                 return TEST_FAILED;
4511
4512         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4513                         ut_params->op), "failed to process sym crypto op");
4514
4515         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4516                         "HMAC_MD5 crypto op processing failed");
4517
4518         return TEST_SUCCESS;
4519 }
4520
4521 static int
4522 test_MD5_HMAC_generate_case_1(void)
4523 {
4524         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
4525 }
4526
4527 static int
4528 test_MD5_HMAC_verify_case_1(void)
4529 {
4530         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
4531 }
4532
4533 static int
4534 test_MD5_HMAC_generate_case_2(void)
4535 {
4536         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
4537 }
4538
4539 static int
4540 test_MD5_HMAC_verify_case_2(void)
4541 {
4542         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
4543 }
4544
4545 static int
4546 test_multi_session(void)
4547 {
4548         struct crypto_testsuite_params *ts_params = &testsuite_params;
4549         struct crypto_unittest_params *ut_params = &unittest_params;
4550
4551         struct rte_cryptodev_info dev_info;
4552         struct rte_cryptodev_sym_session **sessions;
4553
4554         uint16_t i;
4555
4556         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
4557                         aes_cbc_key, hmac_sha512_key);
4558
4559
4560         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4561
4562         sessions = rte_malloc(NULL,
4563                         (sizeof(struct rte_cryptodev_sym_session *) *
4564                         dev_info.sym.max_nb_sessions) + 1, 0);
4565
4566         /* Create multiple crypto sessions*/
4567         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4568                 sessions[i] = rte_cryptodev_sym_session_create(
4569                                 ts_params->valid_devs[0],
4570                         &ut_params->auth_xform);
4571                 TEST_ASSERT_NOT_NULL(sessions[i],
4572                                 "Session creation failed at session number %u",
4573                                 i);
4574
4575                 /* Attempt to send a request on each session */
4576                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
4577                         sessions[i],
4578                         ut_params,
4579                         ts_params,
4580                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4581                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4582                         aes_cbc_iv),
4583                         "Failed to perform decrypt on request number %u.", i);
4584                 /* free crypto operation structure */
4585                 if (ut_params->op)
4586                         rte_crypto_op_free(ut_params->op);
4587
4588                 /*
4589                  * free mbuf - both obuf and ibuf are usually the same,
4590                  * so check if they point at the same address is necessary,
4591                  * to avoid freeing the mbuf twice.
4592                  */
4593                 if (ut_params->obuf) {
4594                         rte_pktmbuf_free(ut_params->obuf);
4595                         if (ut_params->ibuf == ut_params->obuf)
4596                                 ut_params->ibuf = 0;
4597                         ut_params->obuf = 0;
4598                 }
4599                 if (ut_params->ibuf) {
4600                         rte_pktmbuf_free(ut_params->ibuf);
4601                         ut_params->ibuf = 0;
4602                 }
4603         }
4604
4605         /* Next session create should fail */
4606         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4607                         &ut_params->auth_xform);
4608         TEST_ASSERT_NULL(sessions[i],
4609                         "Session creation succeeded unexpectedly!");
4610
4611         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4612                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4613                                 sessions[i]);
4614
4615         rte_free(sessions);
4616
4617         return TEST_SUCCESS;
4618 }
4619
4620 struct multi_session_params {
4621         struct crypto_unittest_params ut_params;
4622         uint8_t *cipher_key;
4623         uint8_t *hmac_key;
4624         const uint8_t *cipher;
4625         const uint8_t *digest;
4626         uint8_t *iv;
4627 };
4628
4629 #define MB_SESSION_NUMBER 3
4630
4631 static int
4632 test_multi_session_random_usage(void)
4633 {
4634         struct crypto_testsuite_params *ts_params = &testsuite_params;
4635         struct rte_cryptodev_info dev_info;
4636         struct rte_cryptodev_sym_session **sessions;
4637         uint32_t i, j;
4638         struct multi_session_params ut_paramz[] = {
4639
4640                 {
4641                         .cipher_key = ms_aes_cbc_key0,
4642                         .hmac_key = ms_hmac_key0,
4643                         .cipher = ms_aes_cbc_cipher0,
4644                         .digest = ms_hmac_digest0,
4645                         .iv = ms_aes_cbc_iv0
4646                 },
4647                 {
4648                         .cipher_key = ms_aes_cbc_key1,
4649                         .hmac_key = ms_hmac_key1,
4650                         .cipher = ms_aes_cbc_cipher1,
4651                         .digest = ms_hmac_digest1,
4652                         .iv = ms_aes_cbc_iv1
4653                 },
4654                 {
4655                         .cipher_key = ms_aes_cbc_key2,
4656                         .hmac_key = ms_hmac_key2,
4657                         .cipher = ms_aes_cbc_cipher2,
4658                         .digest = ms_hmac_digest2,
4659                         .iv = ms_aes_cbc_iv2
4660                 },
4661
4662         };
4663
4664         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4665
4666         sessions = rte_malloc(NULL,
4667                         (sizeof(struct rte_cryptodev_sym_session *)
4668                                         * dev_info.sym.max_nb_sessions) + 1, 0);
4669
4670         for (i = 0; i < MB_SESSION_NUMBER; i++) {
4671                 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
4672                                 sizeof(struct crypto_unittest_params));
4673
4674                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
4675                                 &ut_paramz[i].ut_params,
4676                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
4677
4678                 /* Create multiple crypto sessions*/
4679                 sessions[i] = rte_cryptodev_sym_session_create(
4680                                 ts_params->valid_devs[0],
4681                                 &ut_paramz[i].ut_params.auth_xform);
4682
4683                 TEST_ASSERT_NOT_NULL(sessions[i],
4684                                 "Session creation failed at session number %u",
4685                                 i);
4686
4687         }
4688
4689         srand(time(NULL));
4690         for (i = 0; i < 40000; i++) {
4691
4692                 j = rand() % MB_SESSION_NUMBER;
4693
4694                 TEST_ASSERT_SUCCESS(
4695                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
4696                                         sessions[j],
4697                                         &ut_paramz[j].ut_params,
4698                                         ts_params, ut_paramz[j].cipher,
4699                                         ut_paramz[j].digest,
4700                                         ut_paramz[j].iv),
4701                         "Failed to perform decrypt on request number %u.", i);
4702
4703                 if (ut_paramz[j].ut_params.op)
4704                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
4705
4706                 /*
4707                  * free mbuf - both obuf and ibuf are usually the same,
4708                  * so check if they point at the same address is necessary,
4709                  * to avoid freeing the mbuf twice.
4710                  */
4711                 if (ut_paramz[j].ut_params.obuf) {
4712                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
4713                         if (ut_paramz[j].ut_params.ibuf
4714                                         == ut_paramz[j].ut_params.obuf)
4715                                 ut_paramz[j].ut_params.ibuf = 0;
4716                         ut_paramz[j].ut_params.obuf = 0;
4717                 }
4718                 if (ut_paramz[j].ut_params.ibuf) {
4719                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
4720                         ut_paramz[j].ut_params.ibuf = 0;
4721                 }
4722         }
4723
4724         for (i = 0; i < MB_SESSION_NUMBER; i++)
4725                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4726                                 sessions[i]);
4727
4728         rte_free(sessions);
4729
4730         return TEST_SUCCESS;
4731 }
4732
4733 static int
4734 test_null_cipher_only_operation(void)
4735 {
4736         struct crypto_testsuite_params *ts_params = &testsuite_params;
4737         struct crypto_unittest_params *ut_params = &unittest_params;
4738
4739         /* Generate test mbuf data and space for digest */
4740         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4741                         catch_22_quote, QUOTE_512_BYTES, 0);
4742
4743         /* Setup Cipher Parameters */
4744         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4745         ut_params->cipher_xform.next = NULL;
4746
4747         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4748         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4749
4750         /* Create Crypto session*/
4751         ut_params->sess = rte_cryptodev_sym_session_create(
4752                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4753         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4754
4755         /* Generate Crypto op data structure */
4756         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4757                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4758         TEST_ASSERT_NOT_NULL(ut_params->op,
4759                         "Failed to allocate symmetric crypto operation struct");
4760
4761         /* Set crypto operation data parameters */
4762         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4763
4764         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4765
4766         /* set crypto operation source mbuf */
4767         sym_op->m_src = ut_params->ibuf;
4768
4769         sym_op->cipher.data.offset = 0;
4770         sym_op->cipher.data.length = QUOTE_512_BYTES;
4771
4772         /* Process crypto operation */
4773         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4774                         ut_params->op);
4775         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4776
4777         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4778                         "crypto operation processing failed");
4779
4780         /* Validate obuf */
4781         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4782                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4783                         catch_22_quote,
4784                         QUOTE_512_BYTES,
4785                         "Ciphertext data not as expected");
4786
4787         return TEST_SUCCESS;
4788 }
4789
4790 static int
4791 test_null_auth_only_operation(void)
4792 {
4793         struct crypto_testsuite_params *ts_params = &testsuite_params;
4794         struct crypto_unittest_params *ut_params = &unittest_params;
4795
4796         /* Generate test mbuf data and space for digest */
4797         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4798                         catch_22_quote, QUOTE_512_BYTES, 0);
4799
4800         /* Setup HMAC Parameters */
4801         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4802         ut_params->auth_xform.next = NULL;
4803
4804         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4805         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4806
4807         /* Create Crypto session*/
4808         ut_params->sess = rte_cryptodev_sym_session_create(
4809                         ts_params->valid_devs[0], &ut_params->auth_xform);
4810         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4811
4812         /* Generate Crypto op data structure */
4813         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4814                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4815         TEST_ASSERT_NOT_NULL(ut_params->op,
4816                         "Failed to allocate symmetric crypto operation struct");
4817
4818         /* Set crypto operation data parameters */
4819         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4820
4821         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4822
4823         sym_op->m_src = ut_params->ibuf;
4824
4825         sym_op->auth.data.offset = 0;
4826         sym_op->auth.data.length = QUOTE_512_BYTES;
4827
4828         /* Process crypto operation */
4829         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4830                         ut_params->op);
4831         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4832
4833         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4834                         "crypto operation processing failed");
4835
4836         return TEST_SUCCESS;
4837 }
4838
4839 static int
4840 test_null_cipher_auth_operation(void)
4841 {
4842         struct crypto_testsuite_params *ts_params = &testsuite_params;
4843         struct crypto_unittest_params *ut_params = &unittest_params;
4844
4845         /* Generate test mbuf data and space for digest */
4846         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4847                         catch_22_quote, QUOTE_512_BYTES, 0);
4848
4849         /* Setup Cipher Parameters */
4850         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4851         ut_params->cipher_xform.next = &ut_params->auth_xform;
4852
4853         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4854         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4855
4856         /* Setup HMAC Parameters */
4857         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4858         ut_params->auth_xform.next = NULL;
4859
4860         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4861         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4862
4863         /* Create Crypto session*/
4864         ut_params->sess = rte_cryptodev_sym_session_create(
4865                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4866         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4867
4868         /* Generate Crypto op data structure */
4869         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4870                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4871         TEST_ASSERT_NOT_NULL(ut_params->op,
4872                         "Failed to allocate symmetric crypto operation struct");
4873
4874         /* Set crypto operation data parameters */
4875         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4876
4877         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4878
4879         sym_op->m_src = ut_params->ibuf;
4880
4881         sym_op->cipher.data.offset = 0;
4882         sym_op->cipher.data.length = QUOTE_512_BYTES;
4883
4884         sym_op->auth.data.offset = 0;
4885         sym_op->auth.data.length = QUOTE_512_BYTES;
4886
4887         /* Process crypto operation */
4888         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4889                         ut_params->op);
4890         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4891
4892         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4893                         "crypto operation processing failed");
4894
4895         /* Validate obuf */
4896         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4897                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4898                         catch_22_quote,
4899                         QUOTE_512_BYTES,
4900                         "Ciphertext data not as expected");
4901
4902         return TEST_SUCCESS;
4903 }
4904
4905 static int
4906 test_null_auth_cipher_operation(void)
4907 {
4908         struct crypto_testsuite_params *ts_params = &testsuite_params;
4909         struct crypto_unittest_params *ut_params = &unittest_params;
4910
4911         /* Generate test mbuf data and space for digest */
4912         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4913                         catch_22_quote, QUOTE_512_BYTES, 0);
4914
4915         /* Setup Cipher Parameters */
4916         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4917         ut_params->cipher_xform.next = NULL;
4918
4919         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4920         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4921
4922         /* Setup HMAC Parameters */
4923         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4924         ut_params->auth_xform.next = &ut_params->cipher_xform;
4925
4926         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4927         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4928
4929         /* Create Crypto session*/
4930         ut_params->sess = rte_cryptodev_sym_session_create(
4931                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4932         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4933
4934         /* Generate Crypto op data structure */
4935         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4936                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4937         TEST_ASSERT_NOT_NULL(ut_params->op,
4938                         "Failed to allocate symmetric crypto operation struct");
4939
4940         /* Set crypto operation data parameters */
4941         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4942
4943         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4944
4945         sym_op->m_src = ut_params->ibuf;
4946
4947         sym_op->cipher.data.offset = 0;
4948         sym_op->cipher.data.length = QUOTE_512_BYTES;
4949
4950         sym_op->auth.data.offset = 0;
4951         sym_op->auth.data.length = QUOTE_512_BYTES;
4952
4953         /* Process crypto operation */
4954         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4955                         ut_params->op);
4956         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4957
4958         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4959                         "crypto operation processing failed");
4960
4961         /* Validate obuf */
4962         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4963                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4964                         catch_22_quote,
4965                         QUOTE_512_BYTES,
4966                         "Ciphertext data not as expected");
4967
4968         return TEST_SUCCESS;
4969 }
4970
4971
4972 static int
4973 test_null_invalid_operation(void)
4974 {
4975         struct crypto_testsuite_params *ts_params = &testsuite_params;
4976         struct crypto_unittest_params *ut_params = &unittest_params;
4977
4978         /* Setup Cipher Parameters */
4979         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4980         ut_params->cipher_xform.next = NULL;
4981
4982         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4983         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4984
4985         /* Create Crypto session*/
4986         ut_params->sess = rte_cryptodev_sym_session_create(
4987                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4988         TEST_ASSERT_NULL(ut_params->sess,
4989                         "Session creation succeeded unexpectedly");
4990
4991
4992         /* Setup HMAC Parameters */
4993         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4994         ut_params->auth_xform.next = NULL;
4995
4996         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4997         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4998
4999         /* Create Crypto session*/
5000         ut_params->sess = rte_cryptodev_sym_session_create(
5001                         ts_params->valid_devs[0], &ut_params->auth_xform);
5002         TEST_ASSERT_NULL(ut_params->sess,
5003                         "Session creation succeeded unexpectedly");
5004
5005         return TEST_SUCCESS;
5006 }
5007
5008
5009 #define NULL_BURST_LENGTH (32)
5010
5011 static int
5012 test_null_burst_operation(void)
5013 {
5014         struct crypto_testsuite_params *ts_params = &testsuite_params;
5015         struct crypto_unittest_params *ut_params = &unittest_params;
5016
5017         unsigned i, burst_len = NULL_BURST_LENGTH;
5018
5019         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
5020         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
5021
5022         /* Setup Cipher Parameters */
5023         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5024         ut_params->cipher_xform.next = &ut_params->auth_xform;
5025
5026         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5027         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5028
5029         /* Setup HMAC Parameters */
5030         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5031         ut_params->auth_xform.next = NULL;
5032
5033         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5034         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5035
5036         /* Create Crypto session*/
5037         ut_params->sess = rte_cryptodev_sym_session_create(
5038                         ts_params->valid_devs[0], &ut_params->cipher_xform);
5039         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5040
5041         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
5042                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
5043                         burst_len, "failed to generate burst of crypto ops");
5044
5045         /* Generate an operation for each mbuf in burst */
5046         for (i = 0; i < burst_len; i++) {
5047                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5048
5049                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
5050
5051                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
5052                                 sizeof(unsigned));
5053                 *data = i;
5054
5055                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
5056
5057                 burst[i]->sym->m_src = m;
5058         }
5059
5060         /* Process crypto operation */
5061         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
5062                         0, burst, burst_len),
5063                         burst_len,
5064                         "Error enqueuing burst");
5065
5066         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
5067                         0, burst_dequeued, burst_len),
5068                         burst_len,
5069                         "Error dequeuing burst");
5070
5071
5072         for (i = 0; i < burst_len; i++) {
5073                 TEST_ASSERT_EQUAL(
5074                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
5075                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
5076                                         uint32_t *),
5077                         "data not as expected");
5078
5079                 rte_pktmbuf_free(burst[i]->sym->m_src);
5080                 rte_crypto_op_free(burst[i]);
5081         }
5082
5083         return TEST_SUCCESS;
5084 }
5085
5086 static void
5087 generate_gmac_large_plaintext(uint8_t *data)
5088 {
5089         uint16_t i;
5090
5091         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
5092                 memcpy(&data[i], &data[0], 32);
5093 }
5094
5095 static int
5096 create_gmac_operation(enum rte_crypto_auth_operation op,
5097                 const struct gmac_test_data *tdata)
5098 {
5099         struct crypto_testsuite_params *ts_params = &testsuite_params;
5100         struct crypto_unittest_params *ut_params = &unittest_params;
5101         struct rte_crypto_sym_op *sym_op;
5102
5103         unsigned iv_pad_len;
5104         unsigned aad_pad_len;
5105
5106         iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
5107         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5108
5109         /*
5110          * Runtime generate the large plain text instead of use hard code
5111          * plain text vector. It is done to avoid create huge source file
5112          * with the test vector.
5113          */
5114         if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
5115                 generate_gmac_large_plaintext(tdata->aad.data);
5116
5117         /* Generate Crypto op data structure */
5118         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5119                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5120         TEST_ASSERT_NOT_NULL(ut_params->op,
5121                         "Failed to allocate symmetric crypto operation struct");
5122
5123         sym_op = ut_params->op->sym;
5124         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5125                         aad_pad_len);
5126         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
5127                         "no room to append aad");
5128
5129         sym_op->auth.aad.length = tdata->aad.len;
5130         sym_op->auth.aad.phys_addr =
5131                         rte_pktmbuf_mtophys(ut_params->ibuf);
5132         memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
5133
5134         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5135                         ut_params->ibuf, tdata->gmac_tag.len);
5136         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5137                         "no room to append digest");
5138
5139         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5140                         ut_params->ibuf, aad_pad_len);
5141         sym_op->auth.digest.length = tdata->gmac_tag.len;
5142
5143         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5144                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
5145                                 tdata->gmac_tag.len);
5146                 TEST_HEXDUMP(stdout, "digest:",
5147                                 sym_op->auth.digest.data,
5148                                 sym_op->auth.digest.length);
5149         }
5150
5151         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5152                         ut_params->ibuf, iv_pad_len);
5153         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5154
5155         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
5156         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5157         sym_op->cipher.iv.length = tdata->iv.len;
5158
5159         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
5160
5161         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
5162
5163         sym_op->cipher.data.length = 0;
5164         sym_op->cipher.data.offset = 0;
5165
5166         sym_op->auth.data.offset = 0;
5167         sym_op->auth.data.length = 0;
5168
5169         return 0;
5170 }
5171
5172 static int create_gmac_session(uint8_t dev_id,
5173                 enum rte_crypto_cipher_operation op,
5174                 const struct gmac_test_data *tdata,
5175                 enum rte_crypto_auth_operation auth_op)
5176 {
5177         uint8_t cipher_key[tdata->key.len];
5178
5179         struct crypto_unittest_params *ut_params = &unittest_params;
5180
5181         memcpy(cipher_key, tdata->key.data, tdata->key.len);
5182
5183         /* For GMAC we setup cipher parameters */
5184         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5185         ut_params->cipher_xform.next = NULL;
5186         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
5187         ut_params->cipher_xform.cipher.op = op;
5188         ut_params->cipher_xform.cipher.key.data = cipher_key;
5189         ut_params->cipher_xform.cipher.key.length = tdata->key.len;
5190
5191         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5192         ut_params->auth_xform.next = NULL;
5193
5194         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
5195         ut_params->auth_xform.auth.op = auth_op;
5196         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
5197         ut_params->auth_xform.auth.add_auth_data_length = 0;
5198         ut_params->auth_xform.auth.key.length = 0;
5199         ut_params->auth_xform.auth.key.data = NULL;
5200
5201         ut_params->cipher_xform.next = &ut_params->auth_xform;
5202
5203         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5204                         &ut_params->cipher_xform);
5205
5206         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5207
5208         return 0;
5209 }
5210
5211 static int
5212 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
5213 {
5214         struct crypto_testsuite_params *ts_params = &testsuite_params;
5215         struct crypto_unittest_params *ut_params = &unittest_params;
5216
5217         int retval;
5218
5219         uint8_t *auth_tag, *p;
5220         uint16_t aad_pad_len;
5221
5222         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5223                               "No GMAC length in the source data");
5224
5225         retval = create_gmac_session(ts_params->valid_devs[0],
5226                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5227                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
5228
5229         if (retval < 0)
5230                 return retval;
5231
5232         if (tdata->aad.len > MBUF_SIZE)
5233                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5234         else
5235                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5236         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5237                         "Failed to allocate input buffer in mempool");
5238
5239         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5240                         rte_pktmbuf_tailroom(ut_params->ibuf));
5241
5242         aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5243
5244         p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
5245
5246         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
5247                         tdata);
5248
5249         if (retval < 0)
5250                 return retval;
5251
5252         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5253
5254         ut_params->op->sym->m_src = ut_params->ibuf;
5255
5256         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5257                         ut_params->op), "failed to process sym crypto op");
5258
5259         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5260                         "crypto op processing failed");
5261
5262         if (ut_params->op->sym->m_dst) {
5263                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5264                                 uint8_t *, aad_pad_len);
5265         } else {
5266                 auth_tag = p + aad_pad_len;
5267         }
5268
5269         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
5270
5271         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5272                         auth_tag,
5273                         tdata->gmac_tag.data,
5274                         tdata->gmac_tag.len,
5275                         "GMAC Generated auth tag not as expected");
5276
5277         return 0;
5278 }
5279
5280 static int
5281 test_AES_GMAC_authentication_test_case_1(void)
5282 {
5283         return test_AES_GMAC_authentication(&gmac_test_case_1);
5284 }
5285
5286 static int
5287 test_AES_GMAC_authentication_test_case_2(void)
5288 {
5289         return test_AES_GMAC_authentication(&gmac_test_case_2);
5290 }
5291
5292 static int
5293 test_AES_GMAC_authentication_test_case_3(void)
5294 {
5295         return test_AES_GMAC_authentication(&gmac_test_case_3);
5296 }
5297
5298 static int
5299 test_AES_GMAC_authentication_test_case_4(void)
5300 {
5301         return test_AES_GMAC_authentication(&gmac_test_case_4);
5302 }
5303
5304 static int
5305 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
5306 {
5307         struct crypto_testsuite_params *ts_params = &testsuite_params;
5308         struct crypto_unittest_params *ut_params = &unittest_params;
5309         int retval;
5310
5311         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5312                               "No GMAC length in the source data");
5313
5314         retval = create_gmac_session(ts_params->valid_devs[0],
5315                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
5316                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
5317
5318         if (retval < 0)
5319                 return retval;
5320
5321         if (tdata->aad.len > MBUF_SIZE)
5322                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5323         else
5324                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5325         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5326                         "Failed to allocate input buffer in mempool");
5327
5328         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5329                         rte_pktmbuf_tailroom(ut_params->ibuf));
5330
5331         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
5332                         tdata);
5333
5334         if (retval < 0)
5335                 return retval;
5336
5337         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5338
5339         ut_params->op->sym->m_src = ut_params->ibuf;
5340
5341         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5342                         ut_params->op), "failed to process sym crypto op");
5343
5344         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5345                         "crypto op processing failed");
5346
5347         return 0;
5348
5349 }
5350
5351 static int
5352 test_AES_GMAC_authentication_verify_test_case_1(void)
5353 {
5354         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
5355 }
5356
5357 static int
5358 test_AES_GMAC_authentication_verify_test_case_2(void)
5359 {
5360         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
5361 }
5362
5363 static int
5364 test_AES_GMAC_authentication_verify_test_case_3(void)
5365 {
5366         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
5367 }
5368
5369 static int
5370 test_AES_GMAC_authentication_verify_test_case_4(void)
5371 {
5372         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
5373 }
5374
5375 struct test_crypto_vector {
5376         enum rte_crypto_cipher_algorithm crypto_algo;
5377
5378         struct {
5379                 uint8_t data[64];
5380                 unsigned int len;
5381         } cipher_key;
5382
5383         struct {
5384                 uint8_t data[64];
5385                 unsigned int len;
5386         } iv;
5387
5388         struct {
5389                 const uint8_t *data;
5390                 unsigned int len;
5391         } plaintext;
5392
5393         struct {
5394                 const uint8_t *data;
5395                 unsigned int len;
5396         } ciphertext;
5397
5398         enum rte_crypto_auth_algorithm auth_algo;
5399
5400         struct {
5401                 uint8_t data[128];
5402                 unsigned int len;
5403         } auth_key;
5404
5405         struct {
5406                 const uint8_t *data;
5407                 unsigned int len;
5408         } aad;
5409
5410         struct {
5411                 uint8_t data[128];
5412                 unsigned int len;
5413         } digest;
5414 };
5415
5416 static const struct test_crypto_vector
5417 hmac_sha1_test_crypto_vector = {
5418         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5419         .plaintext = {
5420                 .data = plaintext_hash,
5421                 .len = 512
5422         },
5423         .auth_key = {
5424                 .data = {
5425                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5426                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5427                         0xDE, 0xF4, 0xDE, 0xAD
5428                 },
5429                 .len = 20
5430         },
5431         .digest = {
5432                 .data = {
5433                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
5434                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
5435                         0x3F, 0x91, 0x64, 0x59
5436                 },
5437                 .len = 20
5438         }
5439 };
5440
5441 static const struct test_crypto_vector
5442 aes128_gmac_test_vector = {
5443         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
5444         .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
5445         .aad = {
5446                 .data = plaintext_hash,
5447                 .len = 512
5448         },
5449         .iv = {
5450                 .data = {
5451                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5452                         0x08, 0x09, 0x0A, 0x0B
5453                 },
5454                 .len = 12
5455         },
5456         .cipher_key = {
5457                 .data = {
5458                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5459                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
5460                 },
5461                 .len = 16
5462         },
5463         .digest = {
5464                 .data = {
5465                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
5466                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
5467                 },
5468                 .len = 16
5469         }
5470 };
5471
5472 static const struct test_crypto_vector
5473 aes128cbc_hmac_sha1_test_vector = {
5474         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
5475         .cipher_key = {
5476                 .data = {
5477                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
5478                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
5479                 },
5480                 .len = 16
5481         },
5482         .iv = {
5483                 .data = {
5484                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5485                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
5486                 },
5487                 .len = 16
5488         },
5489         .plaintext = {
5490                 .data = plaintext_hash,
5491                 .len = 512
5492         },
5493         .ciphertext = {
5494                 .data = ciphertext512_aes128cbc,
5495                 .len = 512
5496         },
5497         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5498         .auth_key = {
5499                 .data = {
5500                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5501                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5502                         0xDE, 0xF4, 0xDE, 0xAD
5503                 },
5504                 .len = 20
5505         },
5506         .digest = {
5507                 .data = {
5508                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
5509                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5510                         0x18, 0x8C, 0x1D, 0x32
5511                 },
5512                 .len = 20
5513         }
5514 };
5515
5516 static void
5517 data_corruption(uint8_t *data)
5518 {
5519         data[0] += 1;
5520 }
5521
5522 static void
5523 tag_corruption(uint8_t *data, unsigned int tag_offset)
5524 {
5525         data[tag_offset] += 1;
5526 }
5527
5528 static int
5529 create_auth_session(struct crypto_unittest_params *ut_params,
5530                 uint8_t dev_id,
5531                 const struct test_crypto_vector *reference,
5532                 enum rte_crypto_auth_operation auth_op)
5533 {
5534         uint8_t auth_key[reference->auth_key.len + 1];
5535
5536         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5537
5538         /* Setup Authentication Parameters */
5539         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5540         ut_params->auth_xform.auth.op = auth_op;
5541         ut_params->auth_xform.next = NULL;
5542         ut_params->auth_xform.auth.algo = reference->auth_algo;
5543         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5544         ut_params->auth_xform.auth.key.data = auth_key;
5545         ut_params->auth_xform.auth.digest_length = reference->digest.len;
5546         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5547
5548         /* Create Crypto session*/
5549         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5550                                 &ut_params->auth_xform);
5551
5552         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5553
5554         return 0;
5555 }
5556
5557 static int
5558 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
5559                 uint8_t dev_id,
5560                 const struct test_crypto_vector *reference,
5561                 enum rte_crypto_auth_operation auth_op,
5562                 enum rte_crypto_cipher_operation cipher_op)
5563 {
5564         uint8_t cipher_key[reference->cipher_key.len + 1];
5565         uint8_t auth_key[reference->auth_key.len + 1];
5566
5567         memcpy(cipher_key, reference->cipher_key.data,
5568                         reference->cipher_key.len);
5569         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5570
5571         /* Setup Authentication Parameters */
5572         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5573         ut_params->auth_xform.auth.op = auth_op;
5574         ut_params->auth_xform.next = &ut_params->cipher_xform;
5575         ut_params->auth_xform.auth.algo = reference->auth_algo;
5576         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5577         ut_params->auth_xform.auth.key.data = auth_key;
5578         ut_params->auth_xform.auth.digest_length = reference->digest.len;
5579         ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5580
5581         /* Setup Cipher Parameters */
5582         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5583         ut_params->cipher_xform.next = NULL;
5584         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
5585         ut_params->cipher_xform.cipher.op = cipher_op;
5586         ut_params->cipher_xform.cipher.key.data = cipher_key;
5587         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
5588
5589         /* Create Crypto session*/
5590         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5591                                 &ut_params->auth_xform);
5592
5593         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5594
5595         return 0;
5596 }
5597
5598 static int
5599 create_auth_operation(struct crypto_testsuite_params *ts_params,
5600                 struct crypto_unittest_params *ut_params,
5601                 const struct test_crypto_vector *reference,
5602                 unsigned int auth_generate)
5603 {
5604         /* Generate Crypto op data structure */
5605         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5606                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5607         TEST_ASSERT_NOT_NULL(ut_params->op,
5608                         "Failed to allocate pktmbuf offload");
5609
5610         /* Set crypto operation data parameters */
5611         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5612
5613         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5614
5615         /* set crypto operation source mbuf */
5616         sym_op->m_src = ut_params->ibuf;
5617
5618         /* digest */
5619         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5620                         ut_params->ibuf, reference->digest.len);
5621
5622         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5623                         "no room to append auth tag");
5624
5625         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5626                         ut_params->ibuf, reference->plaintext.len);
5627         sym_op->auth.digest.length = reference->digest.len;
5628
5629         if (auth_generate)
5630                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5631         else
5632                 memcpy(sym_op->auth.digest.data,
5633                                 reference->digest.data,
5634                                 reference->digest.len);
5635
5636         TEST_HEXDUMP(stdout, "digest:",
5637                         sym_op->auth.digest.data,
5638                         sym_op->auth.digest.length);
5639
5640         sym_op->auth.data.length = reference->plaintext.len;
5641         sym_op->auth.data.offset = 0;
5642
5643         return 0;
5644 }
5645
5646 static int
5647 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
5648                 struct crypto_unittest_params *ut_params,
5649                 const struct test_crypto_vector *reference,
5650                 unsigned int auth_generate)
5651 {
5652         /* Generate Crypto op data structure */
5653         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5654                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5655         TEST_ASSERT_NOT_NULL(ut_params->op,
5656                         "Failed to allocate pktmbuf offload");
5657
5658         /* Set crypto operation data parameters */
5659         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5660
5661         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5662
5663         /* set crypto operation source mbuf */
5664         sym_op->m_src = ut_params->ibuf;
5665
5666         /* aad */
5667         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5668                         reference->aad.len);
5669         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
5670         memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
5671
5672         TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
5673
5674         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5675         sym_op->auth.aad.length = reference->aad.len;
5676
5677         /* digest */
5678         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5679                         ut_params->ibuf, reference->digest.len);
5680
5681         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5682                         "no room to append auth tag");
5683
5684         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5685                         ut_params->ibuf, reference->ciphertext.len);
5686         sym_op->auth.digest.length = reference->digest.len;
5687
5688         if (auth_generate)
5689                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5690         else
5691                 memcpy(sym_op->auth.digest.data,
5692                                 reference->digest.data,
5693                                 reference->digest.len);
5694
5695         TEST_HEXDUMP(stdout, "digest:",
5696                         sym_op->auth.digest.data,
5697                         sym_op->auth.digest.length);
5698
5699         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5700                 ut_params->ibuf, reference->iv.len);
5701         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5702
5703         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5704         sym_op->cipher.iv.length = reference->iv.len;
5705
5706         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
5707
5708         sym_op->cipher.data.length = 0;
5709         sym_op->cipher.data.offset = 0;
5710
5711         sym_op->auth.data.length = 0;
5712         sym_op->auth.data.offset = 0;
5713
5714         return 0;
5715 }
5716
5717 static int
5718 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
5719                 struct crypto_unittest_params *ut_params,
5720                 const struct test_crypto_vector *reference,
5721                 unsigned int auth_generate)
5722 {
5723         /* Generate Crypto op data structure */
5724         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5725                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5726         TEST_ASSERT_NOT_NULL(ut_params->op,
5727                         "Failed to allocate pktmbuf offload");
5728
5729         /* Set crypto operation data parameters */
5730         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5731
5732         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5733
5734         /* set crypto operation source mbuf */
5735         sym_op->m_src = ut_params->ibuf;
5736
5737         /* digest */
5738         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5739                         ut_params->ibuf, reference->digest.len);
5740
5741         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5742                         "no room to append auth tag");
5743
5744         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5745                         ut_params->ibuf, reference->ciphertext.len);
5746         sym_op->auth.digest.length = reference->digest.len;
5747
5748         if (auth_generate)
5749                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5750         else
5751                 memcpy(sym_op->auth.digest.data,
5752                                 reference->digest.data,
5753                                 reference->digest.len);
5754
5755         TEST_HEXDUMP(stdout, "digest:",
5756                         sym_op->auth.digest.data,
5757                         sym_op->auth.digest.length);
5758
5759         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5760                 ut_params->ibuf, reference->iv.len);
5761         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5762
5763         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5764         sym_op->cipher.iv.length = reference->iv.len;
5765
5766         memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
5767
5768         sym_op->cipher.data.length = reference->ciphertext.len;
5769         sym_op->cipher.data.offset = reference->iv.len;
5770
5771         sym_op->auth.data.length = reference->ciphertext.len;
5772         sym_op->auth.data.offset = reference->iv.len;
5773
5774         return 0;
5775 }
5776
5777 static int
5778 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
5779                 struct crypto_unittest_params *ut_params,
5780                 const struct test_crypto_vector *reference)
5781 {
5782         return create_auth_operation(ts_params, ut_params, reference, 0);
5783 }
5784
5785 static int
5786 create_auth_verify_GMAC_operation(
5787                 struct crypto_testsuite_params *ts_params,
5788                 struct crypto_unittest_params *ut_params,
5789                 const struct test_crypto_vector *reference)
5790 {
5791         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
5792 }
5793
5794 static int
5795 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
5796                 struct crypto_unittest_params *ut_params,
5797                 const struct test_crypto_vector *reference)
5798 {
5799         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
5800 }
5801
5802 static int
5803 test_authentication_verify_fail_when_data_corruption(
5804                 struct crypto_testsuite_params *ts_params,
5805                 struct crypto_unittest_params *ut_params,
5806                 const struct test_crypto_vector *reference,
5807                 unsigned int data_corrupted)
5808 {
5809         int retval;
5810
5811         uint8_t *plaintext;
5812
5813         /* Create session */
5814         retval = create_auth_session(ut_params,
5815                         ts_params->valid_devs[0],
5816                         reference,
5817                         RTE_CRYPTO_AUTH_OP_VERIFY);
5818         if (retval < 0)
5819                 return retval;
5820
5821         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5822         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5823                         "Failed to allocate input buffer in mempool");
5824
5825         /* clear mbuf payload */
5826         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5827                         rte_pktmbuf_tailroom(ut_params->ibuf));
5828
5829         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5830                         reference->plaintext.len);
5831         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
5832         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
5833
5834         TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
5835
5836         /* Create operation */
5837         retval = create_auth_verify_operation(ts_params, ut_params, reference);
5838
5839         if (retval < 0)
5840                 return retval;
5841
5842         if (data_corrupted)
5843                 data_corruption(plaintext);
5844         else
5845                 tag_corruption(plaintext, reference->plaintext.len);
5846
5847         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5848                         ut_params->op);
5849         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5850         TEST_ASSERT_EQUAL(ut_params->op->status,
5851                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5852                         "authentication not failed");
5853
5854         ut_params->obuf = ut_params->op->sym->m_src;
5855         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5856
5857         return 0;
5858 }
5859
5860 static int
5861 test_authentication_verify_GMAC_fail_when_corruption(
5862                 struct crypto_testsuite_params *ts_params,
5863                 struct crypto_unittest_params *ut_params,
5864                 const struct test_crypto_vector *reference,
5865                 unsigned int data_corrupted)
5866 {
5867         int retval;
5868
5869         /* Create session */
5870         retval = create_auth_cipher_session(ut_params,
5871                         ts_params->valid_devs[0],
5872                         reference,
5873                         RTE_CRYPTO_AUTH_OP_VERIFY,
5874                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
5875         if (retval < 0)
5876                 return retval;
5877
5878         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5879         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5880                         "Failed to allocate input buffer in mempool");
5881
5882         /* clear mbuf payload */
5883         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5884                         rte_pktmbuf_tailroom(ut_params->ibuf));
5885
5886         /* Create operation */
5887         retval = create_auth_verify_GMAC_operation(ts_params,
5888                         ut_params,
5889                         reference);
5890
5891         if (retval < 0)
5892                 return retval;
5893
5894         if (data_corrupted)
5895                 data_corruption(ut_params->op->sym->auth.aad.data);
5896         else
5897                 tag_corruption(ut_params->op->sym->auth.aad.data,
5898                                 reference->aad.len);
5899
5900         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5901                         ut_params->op);
5902         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5903         TEST_ASSERT_EQUAL(ut_params->op->status,
5904                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5905                         "authentication not failed");
5906
5907         ut_params->obuf = ut_params->op->sym->m_src;
5908         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5909
5910         return 0;
5911 }
5912
5913 static int
5914 test_authenticated_decryption_fail_when_corruption(
5915                 struct crypto_testsuite_params *ts_params,
5916                 struct crypto_unittest_params *ut_params,
5917                 const struct test_crypto_vector *reference,
5918                 unsigned int data_corrupted)
5919 {
5920         int retval;
5921
5922         uint8_t *ciphertext;
5923
5924         /* Create session */
5925         retval = create_auth_cipher_session(ut_params,
5926                         ts_params->valid_devs[0],
5927                         reference,
5928                         RTE_CRYPTO_AUTH_OP_VERIFY,
5929                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
5930         if (retval < 0)
5931                 return retval;
5932
5933         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5934         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5935                         "Failed to allocate input buffer in mempool");
5936
5937         /* clear mbuf payload */
5938         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5939                         rte_pktmbuf_tailroom(ut_params->ibuf));
5940
5941         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5942                         reference->ciphertext.len);
5943         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
5944         memcpy(ciphertext, reference->ciphertext.data,
5945                         reference->ciphertext.len);
5946
5947         /* Create operation */
5948         retval = create_cipher_auth_verify_operation(ts_params,
5949                         ut_params,
5950                         reference);
5951
5952         if (retval < 0)
5953                 return retval;
5954
5955         if (data_corrupted)
5956                 data_corruption(ciphertext);
5957         else
5958                 tag_corruption(ciphertext, reference->ciphertext.len);
5959
5960         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5961                         ut_params->op);
5962
5963         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5964         TEST_ASSERT_EQUAL(ut_params->op->status,
5965                         RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
5966                         "authentication not failed");
5967
5968         ut_params->obuf = ut_params->op->sym->m_src;
5969         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
5970
5971         return 0;
5972 }
5973
5974 static int
5975 create_gcm_operation_SGL(enum rte_crypto_cipher_operation op,
5976                 const struct gcm_test_data *tdata,
5977                 void *digest_mem, uint64_t digest_phys)
5978 {
5979         struct crypto_testsuite_params *ts_params = &testsuite_params;
5980         struct crypto_unittest_params *ut_params = &unittest_params;
5981
5982         const unsigned int auth_tag_len = tdata->auth_tag.len;
5983         const unsigned int iv_len = tdata->iv.len;
5984         const unsigned int aad_len = tdata->aad.len;
5985
5986         unsigned int iv_pad_len = 0;
5987
5988         /* Generate Crypto op data structure */
5989         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5990                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5991         TEST_ASSERT_NOT_NULL(ut_params->op,
5992                 "Failed to allocate symmetric crypto operation struct");
5993
5994         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5995
5996         sym_op->auth.digest.data = digest_mem;
5997
5998         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5999                         "no room to append digest");
6000
6001         sym_op->auth.digest.phys_addr = digest_phys;
6002         sym_op->auth.digest.length = auth_tag_len;
6003
6004         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
6005                 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
6006                                 auth_tag_len);
6007                 TEST_HEXDUMP(stdout, "digest:",
6008                                 sym_op->auth.digest.data,
6009                                 sym_op->auth.digest.length);
6010         }
6011
6012         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
6013
6014         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6015                         ut_params->ibuf, iv_pad_len);
6016
6017         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
6018                         "no room to prepend iv");
6019
6020         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
6021         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6022         sym_op->cipher.iv.length = iv_len;
6023
6024         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, iv_pad_len);
6025
6026         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
6027                         ut_params->ibuf, aad_len);
6028         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
6029                         "no room to prepend aad");
6030         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
6031                         ut_params->ibuf);
6032         sym_op->auth.aad.length = aad_len;
6033
6034         memset(sym_op->auth.aad.data, 0, aad_len);
6035         rte_memcpy(sym_op->auth.aad.data, tdata->aad.data, aad_len);
6036
6037         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
6038         TEST_HEXDUMP(stdout, "aad:",
6039                         sym_op->auth.aad.data, aad_len);
6040
6041         sym_op->cipher.data.length = tdata->plaintext.len;
6042         sym_op->cipher.data.offset = aad_len + iv_pad_len;
6043
6044         sym_op->auth.data.offset = aad_len + iv_pad_len;
6045         sym_op->auth.data.length = tdata->plaintext.len;
6046
6047         return 0;
6048 }
6049
6050 #define SGL_MAX_NO      16
6051
6052 static int
6053 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
6054                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
6055 {
6056         struct crypto_testsuite_params *ts_params = &testsuite_params;
6057         struct crypto_unittest_params *ut_params = &unittest_params;
6058         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
6059         int retval;
6060         int to_trn = 0;
6061         int to_trn_tbl[SGL_MAX_NO];
6062         int segs = 1;
6063         unsigned int trn_data = 0;
6064         uint8_t *plaintext, *ciphertext, *auth_tag;
6065
6066         if (fragsz > tdata->plaintext.len)
6067                 fragsz = tdata->plaintext.len;
6068
6069         uint16_t plaintext_len = fragsz;
6070         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
6071
6072         if (fragsz_oop > tdata->plaintext.len)
6073                 frag_size_oop = tdata->plaintext.len;
6074
6075         int ecx = 0;
6076         void *digest_mem = NULL;
6077
6078         uint32_t prepend_len = ALIGN_POW2_ROUNDUP(tdata->iv.len, 16)
6079                         + tdata->aad.len;
6080
6081         if (tdata->plaintext.len % fragsz != 0) {
6082                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
6083                         return 1;
6084         }       else {
6085                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
6086                         return 1;
6087         }
6088
6089         /*
6090          * For out-op-place we need to alloc another mbuf
6091          */
6092         if (oop) {
6093                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6094                 rte_pktmbuf_append(ut_params->obuf,
6095                                 frag_size_oop + prepend_len);
6096                 buf_oop = ut_params->obuf;
6097         }
6098
6099         /* Create GCM session */
6100         retval = create_gcm_session(ts_params->valid_devs[0],
6101                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6102                         tdata->key.data, tdata->key.len,
6103                         tdata->aad.len, tdata->auth_tag.len,
6104                         RTE_CRYPTO_AUTH_OP_GENERATE);
6105         if (retval < 0)
6106                 return retval;
6107
6108         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6109
6110         /* clear mbuf payload */
6111         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6112                         rte_pktmbuf_tailroom(ut_params->ibuf));
6113
6114         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6115                         plaintext_len);
6116
6117         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6118
6119         trn_data += plaintext_len;
6120
6121         buf = ut_params->ibuf;
6122
6123         /*
6124          * Loop until no more fragments
6125          */
6126
6127         while (trn_data < tdata->plaintext.len) {
6128                 ++segs;
6129                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
6130                                 (tdata->plaintext.len - trn_data) : fragsz;
6131
6132                 to_trn_tbl[ecx++] = to_trn;
6133
6134                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6135                 buf = buf->next;
6136
6137                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
6138                                 rte_pktmbuf_tailroom(buf));
6139
6140                 /* OOP */
6141                 if (oop && !fragsz_oop) {
6142                         buf_last_oop = buf_oop->next =
6143                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
6144                         buf_oop = buf_oop->next;
6145                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
6146                                         0, rte_pktmbuf_tailroom(buf_oop));
6147                         rte_pktmbuf_append(buf_oop, to_trn);
6148                 }
6149
6150                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
6151                                 to_trn);
6152
6153                 memcpy(plaintext, tdata->plaintext.data + trn_data,
6154                                 to_trn);
6155                 trn_data += to_trn;
6156                 if (trn_data  == tdata->plaintext.len) {
6157                         if (oop) {
6158                                 if (!fragsz_oop)
6159                                         digest_mem = rte_pktmbuf_append(buf_oop,
6160                                                 tdata->auth_tag.len);
6161                         } else
6162                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
6163                                         tdata->auth_tag.len);
6164                 }
6165         }
6166
6167         uint64_t digest_phys = 0;
6168
6169         ut_params->ibuf->nb_segs = segs;
6170
6171         segs = 1;
6172         if (fragsz_oop && oop) {
6173                 to_trn = 0;
6174                 ecx = 0;
6175
6176                 if (frag_size_oop == tdata->plaintext.len) {
6177                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
6178                                 tdata->auth_tag.len);
6179
6180                         digest_phys = rte_pktmbuf_mtophys_offset(
6181                                         ut_params->obuf,
6182                                         tdata->plaintext.len + prepend_len);
6183                 }
6184
6185                 trn_data = frag_size_oop;
6186                 while (trn_data < tdata->plaintext.len) {
6187                         ++segs;
6188                         to_trn =
6189                                 (tdata->plaintext.len - trn_data <
6190                                                 frag_size_oop) ?
6191                                 (tdata->plaintext.len - trn_data) :
6192                                                 frag_size_oop;
6193
6194                         to_trn_tbl[ecx++] = to_trn;
6195
6196                         buf_last_oop = buf_oop->next =
6197                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
6198                         buf_oop = buf_oop->next;
6199                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
6200                                         0, rte_pktmbuf_tailroom(buf_oop));
6201                         rte_pktmbuf_append(buf_oop, to_trn);
6202
6203                         trn_data += to_trn;
6204
6205                         if (trn_data  == tdata->plaintext.len) {
6206                                 digest_mem = rte_pktmbuf_append(buf_oop,
6207                                         tdata->auth_tag.len);
6208                         }
6209                 }
6210
6211                 ut_params->obuf->nb_segs = segs;
6212         }
6213
6214         /*
6215          * Place digest at the end of the last buffer
6216          */
6217         if (!digest_phys)
6218                 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
6219         if (oop && buf_last_oop)
6220                 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
6221
6222         if (!digest_mem && !oop) {
6223                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6224                                 + tdata->auth_tag.len);
6225                 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
6226                                 tdata->plaintext.len);
6227         }
6228
6229         /* Create GCM opertaion */
6230         retval = create_gcm_operation_SGL(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6231                         tdata, digest_mem, digest_phys);
6232
6233         if (retval < 0)
6234                 return retval;
6235
6236         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6237
6238         ut_params->op->sym->m_src = ut_params->ibuf;
6239         if (oop)
6240                 ut_params->op->sym->m_dst = ut_params->obuf;
6241
6242         /* Process crypto operation */
6243         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6244                         ut_params->op), "failed to process sym crypto op");
6245
6246         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6247                         "crypto op processing failed");
6248
6249
6250         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
6251                         uint8_t *, prepend_len);
6252         if (oop) {
6253                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6254                                 uint8_t *, prepend_len);
6255         }
6256
6257         if (fragsz_oop)
6258                 fragsz = fragsz_oop;
6259
6260         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6261                         ciphertext,
6262                         tdata->ciphertext.data,
6263                         fragsz,
6264                         "GCM Ciphertext data not as expected");
6265
6266         buf = ut_params->op->sym->m_src->next;
6267         if (oop)
6268                 buf = ut_params->op->sym->m_dst->next;
6269
6270         unsigned int off = fragsz;
6271
6272         ecx = 0;
6273         while (buf) {
6274                 ciphertext = rte_pktmbuf_mtod(buf,
6275                                 uint8_t *);
6276
6277                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6278                                 ciphertext,
6279                                 tdata->ciphertext.data + off,
6280                                 to_trn_tbl[ecx],
6281                                 "GCM Ciphertext data not as expected");
6282
6283                 off += to_trn_tbl[ecx++];
6284                 buf = buf->next;
6285         }
6286
6287         auth_tag = digest_mem;
6288         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6289                         auth_tag,
6290                         tdata->auth_tag.data,
6291                         tdata->auth_tag.len,
6292                         "GCM Generated auth tag not as expected");
6293
6294         return 0;
6295 }
6296
6297 #define IN_PLACE        0
6298 #define OUT_OF_PLACE    1
6299
6300 static int
6301 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
6302 {
6303         return test_AES_GCM_authenticated_encryption_SGL(
6304                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
6305 }
6306
6307 static int
6308 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
6309 {
6310         return test_AES_GCM_authenticated_encryption_SGL(
6311                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
6312 }
6313
6314 static int
6315 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
6316 {
6317
6318         return test_AES_GCM_authenticated_encryption_SGL(
6319                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
6320 }
6321
6322 static int
6323 test_authentication_verify_fail_when_data_corrupted(
6324                 struct crypto_testsuite_params *ts_params,
6325                 struct crypto_unittest_params *ut_params,
6326                 const struct test_crypto_vector *reference)
6327 {
6328         return test_authentication_verify_fail_when_data_corruption(
6329                         ts_params, ut_params, reference, 1);
6330 }
6331
6332 static int
6333 test_authentication_verify_fail_when_tag_corrupted(
6334                 struct crypto_testsuite_params *ts_params,
6335                 struct crypto_unittest_params *ut_params,
6336                 const struct test_crypto_vector *reference)
6337 {
6338         return test_authentication_verify_fail_when_data_corruption(
6339                         ts_params, ut_params, reference, 0);
6340 }
6341
6342 static int
6343 test_authentication_verify_GMAC_fail_when_data_corrupted(
6344                 struct crypto_testsuite_params *ts_params,
6345                 struct crypto_unittest_params *ut_params,
6346                 const struct test_crypto_vector *reference)
6347 {
6348         return test_authentication_verify_GMAC_fail_when_corruption(
6349                         ts_params, ut_params, reference, 1);
6350 }
6351
6352 static int
6353 test_authentication_verify_GMAC_fail_when_tag_corrupted(
6354                 struct crypto_testsuite_params *ts_params,
6355                 struct crypto_unittest_params *ut_params,
6356                 const struct test_crypto_vector *reference)
6357 {
6358         return test_authentication_verify_GMAC_fail_when_corruption(
6359                         ts_params, ut_params, reference, 0);
6360 }
6361
6362 static int
6363 test_authenticated_decryption_fail_when_data_corrupted(
6364                 struct crypto_testsuite_params *ts_params,
6365                 struct crypto_unittest_params *ut_params,
6366                 const struct test_crypto_vector *reference)
6367 {
6368         return test_authenticated_decryption_fail_when_corruption(
6369                         ts_params, ut_params, reference, 1);
6370 }
6371
6372 static int
6373 test_authenticated_decryption_fail_when_tag_corrupted(
6374                 struct crypto_testsuite_params *ts_params,
6375                 struct crypto_unittest_params *ut_params,
6376                 const struct test_crypto_vector *reference)
6377 {
6378         return test_authenticated_decryption_fail_when_corruption(
6379                         ts_params, ut_params, reference, 0);
6380 }
6381
6382 static int
6383 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
6384 {
6385         return test_authentication_verify_fail_when_data_corrupted(
6386                         &testsuite_params, &unittest_params,
6387                         &hmac_sha1_test_crypto_vector);
6388 }
6389
6390 static int
6391 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
6392 {
6393         return test_authentication_verify_fail_when_tag_corrupted(
6394                         &testsuite_params, &unittest_params,
6395                         &hmac_sha1_test_crypto_vector);
6396 }
6397
6398 static int
6399 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
6400 {
6401         return test_authentication_verify_GMAC_fail_when_data_corrupted(
6402                         &testsuite_params, &unittest_params,
6403                         &aes128_gmac_test_vector);
6404 }
6405
6406 static int
6407 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
6408 {
6409         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
6410                         &testsuite_params, &unittest_params,
6411                         &aes128_gmac_test_vector);
6412 }
6413
6414 static int
6415 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
6416 {
6417         return test_authenticated_decryption_fail_when_data_corrupted(
6418                         &testsuite_params,
6419                         &unittest_params,
6420                         &aes128cbc_hmac_sha1_test_vector);
6421 }
6422
6423 static int
6424 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
6425 {
6426         return test_authenticated_decryption_fail_when_tag_corrupted(
6427                         &testsuite_params,
6428                         &unittest_params,
6429                         &aes128cbc_hmac_sha1_test_vector);
6430 }
6431
6432 static struct unit_test_suite cryptodev_qat_testsuite  = {
6433         .suite_name = "Crypto QAT Unit Test Suite",
6434         .setup = testsuite_setup,
6435         .teardown = testsuite_teardown,
6436         .unit_test_cases = {
6437                 TEST_CASE_ST(ut_setup, ut_teardown,
6438                                 test_device_configure_invalid_dev_id),
6439                 TEST_CASE_ST(ut_setup, ut_teardown,
6440                                 test_device_configure_invalid_queue_pair_ids),
6441                 TEST_CASE_ST(ut_setup, ut_teardown,
6442                                 test_queue_pair_descriptor_setup),
6443                 TEST_CASE_ST(ut_setup, ut_teardown,
6444                                 test_multi_session),
6445
6446                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
6447                 TEST_CASE_ST(ut_setup, ut_teardown,
6448                                                 test_AES_cipheronly_qat_all),
6449                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
6450                 TEST_CASE_ST(ut_setup, ut_teardown,
6451                                                 test_3DES_cipheronly_qat_all),
6452                 TEST_CASE_ST(ut_setup, ut_teardown,
6453                                                 test_DES_cipheronly_qat_all),
6454                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
6455
6456                 /** AES GCM Authenticated Encryption */
6457                 TEST_CASE_ST(ut_setup, ut_teardown,
6458                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
6459                 TEST_CASE_ST(ut_setup, ut_teardown,
6460                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
6461                 TEST_CASE_ST(ut_setup, ut_teardown,
6462                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
6463                 TEST_CASE_ST(ut_setup, ut_teardown,
6464                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6465                 TEST_CASE_ST(ut_setup, ut_teardown,
6466                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6467                 TEST_CASE_ST(ut_setup, ut_teardown,
6468                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6469                 TEST_CASE_ST(ut_setup, ut_teardown,
6470                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6471                 TEST_CASE_ST(ut_setup, ut_teardown,
6472                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6473                 TEST_CASE_ST(ut_setup, ut_teardown,
6474                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6475                 TEST_CASE_ST(ut_setup, ut_teardown,
6476                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6477
6478                 /** AES GCM Authenticated Decryption */
6479                 TEST_CASE_ST(ut_setup, ut_teardown,
6480                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6481                 TEST_CASE_ST(ut_setup, ut_teardown,
6482                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6483                 TEST_CASE_ST(ut_setup, ut_teardown,
6484                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6485                 TEST_CASE_ST(ut_setup, ut_teardown,
6486                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6487                 TEST_CASE_ST(ut_setup, ut_teardown,
6488                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6489                 TEST_CASE_ST(ut_setup, ut_teardown,
6490                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6491                 TEST_CASE_ST(ut_setup, ut_teardown,
6492                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6493
6494                 /** AES GMAC Authentication */
6495                 TEST_CASE_ST(ut_setup, ut_teardown,
6496                         test_AES_GMAC_authentication_test_case_1),
6497                 TEST_CASE_ST(ut_setup, ut_teardown,
6498                         test_AES_GMAC_authentication_verify_test_case_1),
6499                 TEST_CASE_ST(ut_setup, ut_teardown,
6500                         test_AES_GMAC_authentication_test_case_2),
6501                 TEST_CASE_ST(ut_setup, ut_teardown,
6502                         test_AES_GMAC_authentication_verify_test_case_2),
6503                 TEST_CASE_ST(ut_setup, ut_teardown,
6504                         test_AES_GMAC_authentication_test_case_3),
6505                 TEST_CASE_ST(ut_setup, ut_teardown,
6506                         test_AES_GMAC_authentication_verify_test_case_3),
6507
6508                 /** SNOW 3G encrypt only (UEA2) */
6509                 TEST_CASE_ST(ut_setup, ut_teardown,
6510                         test_snow3g_encryption_test_case_1),
6511                 TEST_CASE_ST(ut_setup, ut_teardown,
6512                         test_snow3g_encryption_test_case_2),
6513                 TEST_CASE_ST(ut_setup, ut_teardown,
6514                         test_snow3g_encryption_test_case_3),
6515                 TEST_CASE_ST(ut_setup, ut_teardown,
6516                         test_snow3g_encryption_test_case_4),
6517                 TEST_CASE_ST(ut_setup, ut_teardown,
6518                         test_snow3g_encryption_test_case_5),
6519
6520                 TEST_CASE_ST(ut_setup, ut_teardown,
6521                         test_snow3g_encryption_test_case_1_oop),
6522                 TEST_CASE_ST(ut_setup, ut_teardown,
6523                         test_snow3g_decryption_test_case_1_oop),
6524
6525                 /** SNOW 3G decrypt only (UEA2) */
6526                 TEST_CASE_ST(ut_setup, ut_teardown,
6527                         test_snow3g_decryption_test_case_1),
6528                 TEST_CASE_ST(ut_setup, ut_teardown,
6529                         test_snow3g_decryption_test_case_2),
6530                 TEST_CASE_ST(ut_setup, ut_teardown,
6531                         test_snow3g_decryption_test_case_3),
6532                 TEST_CASE_ST(ut_setup, ut_teardown,
6533                         test_snow3g_decryption_test_case_4),
6534                 TEST_CASE_ST(ut_setup, ut_teardown,
6535                         test_snow3g_decryption_test_case_5),
6536                 TEST_CASE_ST(ut_setup, ut_teardown,
6537                         test_snow3g_hash_generate_test_case_1),
6538                 TEST_CASE_ST(ut_setup, ut_teardown,
6539                         test_snow3g_hash_generate_test_case_2),
6540                 TEST_CASE_ST(ut_setup, ut_teardown,
6541                         test_snow3g_hash_generate_test_case_3),
6542                 TEST_CASE_ST(ut_setup, ut_teardown,
6543                         test_snow3g_hash_verify_test_case_1),
6544                 TEST_CASE_ST(ut_setup, ut_teardown,
6545                         test_snow3g_hash_verify_test_case_2),
6546                 TEST_CASE_ST(ut_setup, ut_teardown,
6547                         test_snow3g_hash_verify_test_case_3),
6548                 TEST_CASE_ST(ut_setup, ut_teardown,
6549                         test_snow3g_cipher_auth_test_case_1),
6550                 TEST_CASE_ST(ut_setup, ut_teardown,
6551                         test_snow3g_auth_cipher_test_case_1),
6552
6553                 /** HMAC_MD5 Authentication */
6554                 TEST_CASE_ST(ut_setup, ut_teardown,
6555                         test_MD5_HMAC_generate_case_1),
6556                 TEST_CASE_ST(ut_setup, ut_teardown,
6557                         test_MD5_HMAC_verify_case_1),
6558                 TEST_CASE_ST(ut_setup, ut_teardown,
6559                         test_MD5_HMAC_generate_case_2),
6560                 TEST_CASE_ST(ut_setup, ut_teardown,
6561                         test_MD5_HMAC_verify_case_2),
6562
6563                 /** NULL tests */
6564                 TEST_CASE_ST(ut_setup, ut_teardown,
6565                         test_null_auth_only_operation),
6566                 TEST_CASE_ST(ut_setup, ut_teardown,
6567                         test_null_cipher_only_operation),
6568                 TEST_CASE_ST(ut_setup, ut_teardown,
6569                         test_null_cipher_auth_operation),
6570                 TEST_CASE_ST(ut_setup, ut_teardown,
6571                         test_null_auth_cipher_operation),
6572
6573                 TEST_CASE_ST(ut_setup, ut_teardown,
6574                         test_kasumi_hash_generate_test_case_6),
6575
6576                 /** KASUMI tests */
6577                 TEST_CASE_ST(ut_setup, ut_teardown,
6578                         test_kasumi_encryption_test_case_1),
6579                 TEST_CASE_ST(ut_setup, ut_teardown,
6580                         test_kasumi_encryption_test_case_3),
6581                 TEST_CASE_ST(ut_setup, ut_teardown,
6582                         test_kasumi_auth_cipher_test_case_1),
6583                 TEST_CASE_ST(ut_setup, ut_teardown,
6584                         test_kasumi_cipher_auth_test_case_1),
6585
6586                 /** Negative tests */
6587                 TEST_CASE_ST(ut_setup, ut_teardown,
6588                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
6589                 TEST_CASE_ST(ut_setup, ut_teardown,
6590                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
6591                 TEST_CASE_ST(ut_setup, ut_teardown,
6592                         authentication_verify_AES128_GMAC_fail_data_corrupt),
6593                 TEST_CASE_ST(ut_setup, ut_teardown,
6594                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
6595                 TEST_CASE_ST(ut_setup, ut_teardown,
6596                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
6597                 TEST_CASE_ST(ut_setup, ut_teardown,
6598                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
6599
6600                 TEST_CASES_END() /**< NULL terminate unit test array */
6601         }
6602 };
6603
6604 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
6605         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
6606         .setup = testsuite_setup,
6607         .teardown = testsuite_teardown,
6608         .unit_test_cases = {
6609                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
6610                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
6611                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
6612
6613                 TEST_CASES_END() /**< NULL terminate unit test array */
6614         }
6615 };
6616
6617 static struct unit_test_suite cryptodev_openssl_testsuite  = {
6618         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
6619         .setup = testsuite_setup,
6620         .teardown = testsuite_teardown,
6621         .unit_test_cases = {
6622                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
6623                 TEST_CASE_ST(ut_setup, ut_teardown,
6624                                 test_multi_session_random_usage),
6625                 TEST_CASE_ST(ut_setup, ut_teardown,
6626                                 test_AES_chain_openssl_all),
6627                 TEST_CASE_ST(ut_setup, ut_teardown,
6628                                 test_AES_cipheronly_openssl_all),
6629                 TEST_CASE_ST(ut_setup, ut_teardown,
6630                                 test_3DES_chain_openssl_all),
6631                 TEST_CASE_ST(ut_setup, ut_teardown,
6632                                 test_3DES_cipheronly_openssl_all),
6633                 TEST_CASE_ST(ut_setup, ut_teardown,
6634                                 test_authonly_openssl_all),
6635
6636                 /** AES GCM Authenticated Encryption */
6637                 TEST_CASE_ST(ut_setup, ut_teardown,
6638                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6639                 TEST_CASE_ST(ut_setup, ut_teardown,
6640                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6641                 TEST_CASE_ST(ut_setup, ut_teardown,
6642                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6643                 TEST_CASE_ST(ut_setup, ut_teardown,
6644                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6645                 TEST_CASE_ST(ut_setup, ut_teardown,
6646                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6647                 TEST_CASE_ST(ut_setup, ut_teardown,
6648                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6649                 TEST_CASE_ST(ut_setup, ut_teardown,
6650                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6651
6652                 /** AES GCM Authenticated Decryption */
6653                 TEST_CASE_ST(ut_setup, ut_teardown,
6654                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6655                 TEST_CASE_ST(ut_setup, ut_teardown,
6656                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6657                 TEST_CASE_ST(ut_setup, ut_teardown,
6658                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6659                 TEST_CASE_ST(ut_setup, ut_teardown,
6660                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6661                 TEST_CASE_ST(ut_setup, ut_teardown,
6662                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6663                 TEST_CASE_ST(ut_setup, ut_teardown,
6664                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6665                 TEST_CASE_ST(ut_setup, ut_teardown,
6666                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6667
6668                 /** AES GMAC Authentication */
6669                 TEST_CASE_ST(ut_setup, ut_teardown,
6670                         test_AES_GMAC_authentication_test_case_1),
6671                 TEST_CASE_ST(ut_setup, ut_teardown,
6672                         test_AES_GMAC_authentication_verify_test_case_1),
6673                 TEST_CASE_ST(ut_setup, ut_teardown,
6674                         test_AES_GMAC_authentication_test_case_2),
6675                 TEST_CASE_ST(ut_setup, ut_teardown,
6676                         test_AES_GMAC_authentication_verify_test_case_2),
6677                 TEST_CASE_ST(ut_setup, ut_teardown,
6678                         test_AES_GMAC_authentication_test_case_3),
6679                 TEST_CASE_ST(ut_setup, ut_teardown,
6680                         test_AES_GMAC_authentication_verify_test_case_3),
6681                 TEST_CASE_ST(ut_setup, ut_teardown,
6682                         test_AES_GMAC_authentication_test_case_4),
6683                 TEST_CASE_ST(ut_setup, ut_teardown,
6684                         test_AES_GMAC_authentication_verify_test_case_4),
6685
6686                 /** Negative tests */
6687                 TEST_CASE_ST(ut_setup, ut_teardown,
6688                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
6689                 TEST_CASE_ST(ut_setup, ut_teardown,
6690                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
6691                 TEST_CASE_ST(ut_setup, ut_teardown,
6692                         authentication_verify_AES128_GMAC_fail_data_corrupt),
6693                 TEST_CASE_ST(ut_setup, ut_teardown,
6694                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
6695                 TEST_CASE_ST(ut_setup, ut_teardown,
6696                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
6697                 TEST_CASE_ST(ut_setup, ut_teardown,
6698                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
6699
6700                 TEST_CASES_END() /**< NULL terminate unit test array */
6701         }
6702 };
6703
6704 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
6705         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
6706         .setup = testsuite_setup,
6707         .teardown = testsuite_teardown,
6708         .unit_test_cases = {
6709                 /** AES GCM Authenticated Encryption */
6710                 TEST_CASE_ST(ut_setup, ut_teardown,
6711                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
6712                 TEST_CASE_ST(ut_setup, ut_teardown,
6713                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
6714                 TEST_CASE_ST(ut_setup, ut_teardown,
6715                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
6716                 TEST_CASE_ST(ut_setup, ut_teardown,
6717                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
6718                 TEST_CASE_ST(ut_setup, ut_teardown,
6719                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
6720                 TEST_CASE_ST(ut_setup, ut_teardown,
6721                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
6722                 TEST_CASE_ST(ut_setup, ut_teardown,
6723                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
6724
6725                 /** AES GCM Authenticated Decryption */
6726                 TEST_CASE_ST(ut_setup, ut_teardown,
6727                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
6728                 TEST_CASE_ST(ut_setup, ut_teardown,
6729                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
6730                 TEST_CASE_ST(ut_setup, ut_teardown,
6731                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
6732                 TEST_CASE_ST(ut_setup, ut_teardown,
6733                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
6734                 TEST_CASE_ST(ut_setup, ut_teardown,
6735                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
6736                 TEST_CASE_ST(ut_setup, ut_teardown,
6737                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
6738                 TEST_CASE_ST(ut_setup, ut_teardown,
6739                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
6740
6741                 TEST_CASES_END() /**< NULL terminate unit test array */
6742         }
6743 };
6744
6745 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
6746         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
6747         .setup = testsuite_setup,
6748         .teardown = testsuite_teardown,
6749         .unit_test_cases = {
6750                 /** KASUMI encrypt only (UEA1) */
6751                 TEST_CASE_ST(ut_setup, ut_teardown,
6752                         test_kasumi_encryption_test_case_1),
6753                 TEST_CASE_ST(ut_setup, ut_teardown,
6754                         test_kasumi_encryption_test_case_2),
6755                 TEST_CASE_ST(ut_setup, ut_teardown,
6756                         test_kasumi_encryption_test_case_3),
6757                 TEST_CASE_ST(ut_setup, ut_teardown,
6758                         test_kasumi_encryption_test_case_4),
6759                 TEST_CASE_ST(ut_setup, ut_teardown,
6760                         test_kasumi_encryption_test_case_5),
6761                 /** KASUMI decrypt only (UEA1) */
6762                 TEST_CASE_ST(ut_setup, ut_teardown,
6763                         test_kasumi_decryption_test_case_1),
6764                 TEST_CASE_ST(ut_setup, ut_teardown,
6765                         test_kasumi_decryption_test_case_2),
6766                 TEST_CASE_ST(ut_setup, ut_teardown,
6767                         test_kasumi_decryption_test_case_3),
6768                 TEST_CASE_ST(ut_setup, ut_teardown,
6769                         test_kasumi_decryption_test_case_4),
6770                 TEST_CASE_ST(ut_setup, ut_teardown,
6771                         test_kasumi_decryption_test_case_5),
6772
6773                 TEST_CASE_ST(ut_setup, ut_teardown,
6774                         test_kasumi_encryption_test_case_1_oop),
6775                 TEST_CASE_ST(ut_setup, ut_teardown,
6776                         test_kasumi_decryption_test_case_1_oop),
6777
6778                 /** KASUMI hash only (UIA1) */
6779                 TEST_CASE_ST(ut_setup, ut_teardown,
6780                         test_kasumi_hash_generate_test_case_1),
6781                 TEST_CASE_ST(ut_setup, ut_teardown,
6782                         test_kasumi_hash_generate_test_case_2),
6783                 TEST_CASE_ST(ut_setup, ut_teardown,
6784                         test_kasumi_hash_generate_test_case_3),
6785                 TEST_CASE_ST(ut_setup, ut_teardown,
6786                         test_kasumi_hash_generate_test_case_4),
6787                 TEST_CASE_ST(ut_setup, ut_teardown,
6788                         test_kasumi_hash_generate_test_case_5),
6789                 TEST_CASE_ST(ut_setup, ut_teardown,
6790                         test_kasumi_hash_generate_test_case_6),
6791                 TEST_CASE_ST(ut_setup, ut_teardown,
6792                         test_kasumi_hash_verify_test_case_1),
6793                 TEST_CASE_ST(ut_setup, ut_teardown,
6794                         test_kasumi_hash_verify_test_case_2),
6795                 TEST_CASE_ST(ut_setup, ut_teardown,
6796                         test_kasumi_hash_verify_test_case_3),
6797                 TEST_CASE_ST(ut_setup, ut_teardown,
6798                         test_kasumi_hash_verify_test_case_4),
6799                 TEST_CASE_ST(ut_setup, ut_teardown,
6800                         test_kasumi_hash_verify_test_case_5),
6801                 TEST_CASE_ST(ut_setup, ut_teardown,
6802                         test_kasumi_auth_cipher_test_case_1),
6803                 TEST_CASE_ST(ut_setup, ut_teardown,
6804                         test_kasumi_cipher_auth_test_case_1),
6805                 TEST_CASES_END() /**< NULL terminate unit test array */
6806         }
6807 };
6808 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
6809         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
6810         .setup = testsuite_setup,
6811         .teardown = testsuite_teardown,
6812         .unit_test_cases = {
6813                 /** SNOW 3G encrypt only (UEA2) */
6814                 TEST_CASE_ST(ut_setup, ut_teardown,
6815                         test_snow3g_encryption_test_case_1),
6816                 TEST_CASE_ST(ut_setup, ut_teardown,
6817                         test_snow3g_encryption_test_case_2),
6818                 TEST_CASE_ST(ut_setup, ut_teardown,
6819                         test_snow3g_encryption_test_case_3),
6820                 TEST_CASE_ST(ut_setup, ut_teardown,
6821                         test_snow3g_encryption_test_case_4),
6822                 TEST_CASE_ST(ut_setup, ut_teardown,
6823                         test_snow3g_encryption_test_case_5),
6824
6825                 TEST_CASE_ST(ut_setup, ut_teardown,
6826                         test_snow3g_encryption_test_case_1_oop),
6827                 TEST_CASE_ST(ut_setup, ut_teardown,
6828                         test_snow3g_decryption_test_case_1_oop),
6829
6830                 TEST_CASE_ST(ut_setup, ut_teardown,
6831                         test_snow3g_encryption_test_case_1_offset_oop),
6832
6833                 /** SNOW 3G decrypt only (UEA2) */
6834                 TEST_CASE_ST(ut_setup, ut_teardown,
6835                         test_snow3g_decryption_test_case_1),
6836                 TEST_CASE_ST(ut_setup, ut_teardown,
6837                         test_snow3g_decryption_test_case_2),
6838                 TEST_CASE_ST(ut_setup, ut_teardown,
6839                         test_snow3g_decryption_test_case_3),
6840                 TEST_CASE_ST(ut_setup, ut_teardown,
6841                         test_snow3g_decryption_test_case_4),
6842                 TEST_CASE_ST(ut_setup, ut_teardown,
6843                         test_snow3g_decryption_test_case_5),
6844                 TEST_CASE_ST(ut_setup, ut_teardown,
6845                         test_snow3g_hash_generate_test_case_1),
6846                 TEST_CASE_ST(ut_setup, ut_teardown,
6847                         test_snow3g_hash_generate_test_case_2),
6848                 TEST_CASE_ST(ut_setup, ut_teardown,
6849                         test_snow3g_hash_generate_test_case_3),
6850                 /* Tests with buffers which length is not byte-aligned */
6851                 TEST_CASE_ST(ut_setup, ut_teardown,
6852                         test_snow3g_hash_generate_test_case_4),
6853                 TEST_CASE_ST(ut_setup, ut_teardown,
6854                         test_snow3g_hash_generate_test_case_5),
6855                 TEST_CASE_ST(ut_setup, ut_teardown,
6856                         test_snow3g_hash_generate_test_case_6),
6857                 TEST_CASE_ST(ut_setup, ut_teardown,
6858                         test_snow3g_hash_verify_test_case_1),
6859                 TEST_CASE_ST(ut_setup, ut_teardown,
6860                         test_snow3g_hash_verify_test_case_2),
6861                 TEST_CASE_ST(ut_setup, ut_teardown,
6862                         test_snow3g_hash_verify_test_case_3),
6863                 /* Tests with buffers which length is not byte-aligned */
6864                 TEST_CASE_ST(ut_setup, ut_teardown,
6865                         test_snow3g_hash_verify_test_case_4),
6866                 TEST_CASE_ST(ut_setup, ut_teardown,
6867                         test_snow3g_hash_verify_test_case_5),
6868                 TEST_CASE_ST(ut_setup, ut_teardown,
6869                         test_snow3g_hash_verify_test_case_6),
6870                 TEST_CASE_ST(ut_setup, ut_teardown,
6871                         test_snow3g_cipher_auth_test_case_1),
6872                 TEST_CASE_ST(ut_setup, ut_teardown,
6873                         test_snow3g_auth_cipher_test_case_1),
6874
6875                 TEST_CASES_END() /**< NULL terminate unit test array */
6876         }
6877 };
6878
6879 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
6880         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
6881         .setup = testsuite_setup,
6882         .teardown = testsuite_teardown,
6883         .unit_test_cases = {
6884                 /** ZUC encrypt only (EEA3) */
6885                 TEST_CASE_ST(ut_setup, ut_teardown,
6886                         test_zuc_encryption_test_case_1),
6887                 TEST_CASE_ST(ut_setup, ut_teardown,
6888                         test_zuc_encryption_test_case_2),
6889                 TEST_CASE_ST(ut_setup, ut_teardown,
6890                         test_zuc_encryption_test_case_3),
6891                 TEST_CASE_ST(ut_setup, ut_teardown,
6892                         test_zuc_encryption_test_case_4),
6893                 TEST_CASE_ST(ut_setup, ut_teardown,
6894                         test_zuc_encryption_test_case_5),
6895                 TEST_CASE_ST(ut_setup, ut_teardown,
6896                         test_zuc_hash_generate_test_case_1),
6897                 TEST_CASE_ST(ut_setup, ut_teardown,
6898                         test_zuc_hash_generate_test_case_2),
6899                 TEST_CASE_ST(ut_setup, ut_teardown,
6900                         test_zuc_hash_generate_test_case_3),
6901                 TEST_CASE_ST(ut_setup, ut_teardown,
6902                         test_zuc_hash_generate_test_case_4),
6903                 TEST_CASE_ST(ut_setup, ut_teardown,
6904                         test_zuc_hash_generate_test_case_5),
6905                 TEST_CASES_END() /**< NULL terminate unit test array */
6906         }
6907 };
6908
6909 static struct unit_test_suite cryptodev_null_testsuite  = {
6910         .suite_name = "Crypto Device NULL Unit Test Suite",
6911         .setup = testsuite_setup,
6912         .teardown = testsuite_teardown,
6913         .unit_test_cases = {
6914                 TEST_CASE_ST(ut_setup, ut_teardown,
6915                         test_null_auth_only_operation),
6916                 TEST_CASE_ST(ut_setup, ut_teardown,
6917                         test_null_cipher_only_operation),
6918                 TEST_CASE_ST(ut_setup, ut_teardown,
6919                         test_null_cipher_auth_operation),
6920                 TEST_CASE_ST(ut_setup, ut_teardown,
6921                         test_null_auth_cipher_operation),
6922                 TEST_CASE_ST(ut_setup, ut_teardown,
6923                         test_null_invalid_operation),
6924                 TEST_CASE_ST(ut_setup, ut_teardown,
6925                         test_null_burst_operation),
6926
6927                 TEST_CASES_END() /**< NULL terminate unit test array */
6928         }
6929 };
6930
6931 static int
6932 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
6933 {
6934         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
6935         return unit_test_suite_runner(&cryptodev_qat_testsuite);
6936 }
6937
6938 static int
6939 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
6940 {
6941         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
6942
6943         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
6944 }
6945
6946 static int
6947 test_cryptodev_openssl(void)
6948 {
6949         gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
6950
6951         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
6952 }
6953
6954 static int
6955 test_cryptodev_aesni_gcm(void)
6956 {
6957         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
6958
6959         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
6960 }
6961
6962 static int
6963 test_cryptodev_null(void)
6964 {
6965         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
6966
6967         return unit_test_suite_runner(&cryptodev_null_testsuite);
6968 }
6969
6970 static int
6971 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
6972 {
6973         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
6974
6975         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
6976 }
6977
6978 static int
6979 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
6980 {
6981         gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
6982
6983         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
6984 }
6985
6986 static int
6987 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
6988 {
6989         gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
6990
6991         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
6992 }
6993
6994 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
6995 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
6996 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
6997 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
6998 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
6999 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
7000 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
7001 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);