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