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