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