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