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