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