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