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