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