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