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