app/test: remove unnecessary hexdump
[dpdk.git] / app / test / test_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 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 #include "test.h"
44 #include "test_cryptodev.h"
45
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_snow3g_test_vectors.h"
48 #include "test_cryptodev_snow3g_hash_test_vectors.h"
49 #include "test_cryptodev_gcm_test_vectors.h"
50
51 static enum rte_cryptodev_type gbl_cryptodev_type;
52
53 struct crypto_testsuite_params {
54         struct rte_mempool *mbuf_pool;
55         struct rte_mempool *op_mpool;
56         struct rte_cryptodev_config conf;
57         struct rte_cryptodev_qp_conf qp_conf;
58
59         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
60         uint8_t valid_dev_count;
61 };
62
63 struct crypto_unittest_params {
64         struct rte_crypto_sym_xform cipher_xform;
65         struct rte_crypto_sym_xform auth_xform;
66
67         struct rte_cryptodev_sym_session *sess;
68
69         struct rte_crypto_op *op;
70
71         struct rte_mbuf *obuf, *ibuf;
72
73         uint8_t *digest;
74 };
75
76 #define ALIGN_POW2_ROUNDUP(num, align) \
77         (((num) + (align) - 1) & ~((align) - 1))
78
79 /*
80  * Forward declarations.
81  */
82 static int
83 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
84                 struct crypto_unittest_params *ut_params);
85
86 static int
87 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
88                 struct crypto_unittest_params *ut_params,
89                 struct crypto_testsuite_params *ts_param);
90
91 static struct rte_mbuf *
92 setup_test_string(struct rte_mempool *mpool,
93                 const char *string, size_t len, uint8_t blocksize)
94 {
95         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
96         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
97
98         memset(m->buf_addr, 0, m->buf_len);
99         if (m) {
100                 char *dst = rte_pktmbuf_append(m, t_len);
101
102                 if (!dst) {
103                         rte_pktmbuf_free(m);
104                         return NULL;
105                 }
106                 if (string != NULL)
107                         rte_memcpy(dst, string, t_len);
108                 else
109                         memset(dst, 0, t_len);
110         }
111
112         return m;
113 }
114
115 static struct rte_crypto_op *
116 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
117 {
118         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
119                 printf("Error sending packet for encryption");
120                 return NULL;
121         }
122
123         op = NULL;
124
125         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
126                 rte_pause();
127
128         return op;
129 }
130
131 static struct crypto_testsuite_params testsuite_params = { NULL };
132 static struct crypto_unittest_params unittest_params;
133
134 static int
135 testsuite_setup(void)
136 {
137         struct crypto_testsuite_params *ts_params = &testsuite_params;
138         struct rte_cryptodev_info info;
139         unsigned i, nb_devs, dev_id;
140         int ret;
141         uint16_t qp_id;
142
143         memset(ts_params, 0, sizeof(*ts_params));
144
145         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
146         if (ts_params->mbuf_pool == NULL) {
147                 /* Not already created so create */
148                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
149                                 "CRYPTO_MBUFPOOL",
150                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
151                                 rte_socket_id());
152                 if (ts_params->mbuf_pool == NULL) {
153                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
154                         return TEST_FAILED;
155                 }
156         }
157
158         ts_params->op_mpool = rte_crypto_op_pool_create(
159                         "MBUF_CRYPTO_SYM_OP_POOL",
160                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
161                         NUM_MBUFS, MBUF_CACHE_SIZE,
162                         DEFAULT_NUM_XFORMS *
163                         sizeof(struct rte_crypto_sym_xform),
164                         rte_socket_id());
165         if (ts_params->op_mpool == NULL) {
166                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
167                 return TEST_FAILED;
168         }
169
170         /* Create 2 AESNI MB devices if required */
171         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
172                 nb_devs = rte_cryptodev_count_devtype(
173                                 RTE_CRYPTODEV_AESNI_MB_PMD);
174                 if (nb_devs < 2) {
175                         for (i = nb_devs; i < 2; i++) {
176                                 ret = rte_eal_vdev_init(
177                                         CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
178
179                                 TEST_ASSERT(ret == 0,
180                                         "Failed to create instance %u of"
181                                         " pmd : %s",
182                                         i, CRYPTODEV_NAME_AESNI_MB_PMD);
183                         }
184                 }
185         }
186
187         /* Create 2 AESNI GCM devices if required */
188         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
189                 nb_devs = rte_cryptodev_count_devtype(
190                                 RTE_CRYPTODEV_AESNI_GCM_PMD);
191                 if (nb_devs < 2) {
192                         for (i = nb_devs; i < 2; i++) {
193                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
194                                         CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
195                                         "Failed to create instance %u of"
196                                         " pmd : %s",
197                                         i, CRYPTODEV_NAME_AESNI_GCM_PMD);
198                         }
199                 }
200         }
201
202         /* Create 2 Snow3G devices if required */
203         if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
204                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
205                 if (nb_devs < 2) {
206                         for (i = nb_devs; i < 2; i++) {
207                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
208                                         CRYPTODEV_NAME_SNOW3G_PMD, NULL),
209                                         "Failed to create instance %u of"
210                                         " pmd : %s",
211                                         i, CRYPTODEV_NAME_SNOW3G_PMD);
212                         }
213                 }
214         }
215
216         /* Create 2 NULL devices if required */
217         if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
218                 nb_devs = rte_cryptodev_count_devtype(
219                                 RTE_CRYPTODEV_NULL_PMD);
220                 if (nb_devs < 2) {
221                         for (i = nb_devs; i < 2; i++) {
222                                 int dev_id = rte_eal_vdev_init(
223                                         CRYPTODEV_NAME_NULL_PMD, NULL);
224
225                                 TEST_ASSERT(dev_id >= 0,
226                                         "Failed to create instance %u of"
227                                         " pmd : %s",
228                                         i, CRYPTODEV_NAME_NULL_PMD);
229                         }
230                 }
231         }
232
233         nb_devs = rte_cryptodev_count();
234         if (nb_devs < 1) {
235                 RTE_LOG(ERR, USER1, "No crypto devices found?");
236                 return TEST_FAILED;
237         }
238
239         /* Create list of valid crypto devs */
240         for (i = 0; i < nb_devs; i++) {
241                 rte_cryptodev_info_get(i, &info);
242                 if (info.dev_type == gbl_cryptodev_type)
243                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
244         }
245
246         if (ts_params->valid_dev_count < 1)
247                 return TEST_FAILED;
248
249         /* Set up all the qps on the first of the valid devices found */
250         for (i = 0; i < 1; i++) {
251                 dev_id = ts_params->valid_devs[i];
252
253                 rte_cryptodev_info_get(dev_id, &info);
254
255                 /*
256                  * Since we can't free and re-allocate queue memory always set
257                  * the queues on this device up to max size first so enough
258                  * memory is allocated for any later re-configures needed by
259                  * other tests
260                  */
261
262                 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
263                 ts_params->conf.socket_id = SOCKET_ID_ANY;
264                 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
265
266                 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
267                                 &ts_params->conf),
268                                 "Failed to configure cryptodev %u with %u qps",
269                                 dev_id, ts_params->conf.nb_queue_pairs);
270
271                 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
272
273                 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
274                         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
275                                         dev_id, qp_id, &ts_params->qp_conf,
276                                         rte_cryptodev_socket_id(dev_id)),
277                                         "Failed to setup queue pair %u on "
278                                         "cryptodev %u",
279                                         qp_id, dev_id);
280                 }
281         }
282
283         return TEST_SUCCESS;
284 }
285
286 static void
287 testsuite_teardown(void)
288 {
289         struct crypto_testsuite_params *ts_params = &testsuite_params;
290
291         if (ts_params->mbuf_pool != NULL) {
292                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
293                 rte_mempool_count(ts_params->mbuf_pool));
294         }
295
296         if (ts_params->op_mpool != NULL) {
297                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
298                 rte_mempool_count(ts_params->op_mpool));
299         }
300
301 }
302
303 static int
304 ut_setup(void)
305 {
306         struct crypto_testsuite_params *ts_params = &testsuite_params;
307         struct crypto_unittest_params *ut_params = &unittest_params;
308
309         uint16_t qp_id;
310
311         /* Clear unit test parameters before running test */
312         memset(ut_params, 0, sizeof(*ut_params));
313
314         /* Reconfigure device to default parameters */
315         ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
316         ts_params->conf.socket_id = SOCKET_ID_ANY;
317         ts_params->conf.session_mp.nb_objs =
318                         (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
319                                         DEFAULT_NUM_OPS_INFLIGHT :
320                                         DEFAULT_NUM_OPS_INFLIGHT;
321
322         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
323                         &ts_params->conf),
324                         "Failed to configure cryptodev %u",
325                         ts_params->valid_devs[0]);
326
327         /*
328          * Now reconfigure queues to size we actually want to use in this
329          * test suite.
330          */
331         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
332
333         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
334                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
335                         ts_params->valid_devs[0], qp_id,
336                         &ts_params->qp_conf,
337                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
338                         "Failed to setup queue pair %u on cryptodev %u",
339                         qp_id, ts_params->valid_devs[0]);
340         }
341
342
343         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
344
345         /* Start the device */
346         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
347                         "Failed to start cryptodev %u",
348                         ts_params->valid_devs[0]);
349
350         return TEST_SUCCESS;
351 }
352
353 static void
354 ut_teardown(void)
355 {
356         struct crypto_testsuite_params *ts_params = &testsuite_params;
357         struct crypto_unittest_params *ut_params = &unittest_params;
358         struct rte_cryptodev_stats stats;
359
360         /* free crypto session structure */
361         if (ut_params->sess) {
362                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
363                                 ut_params->sess);
364                 ut_params->sess = NULL;
365         }
366
367         /* free crypto operation structure */
368         if (ut_params->op)
369                 rte_crypto_op_free(ut_params->op);
370
371         /*
372          * free mbuf - both obuf and ibuf are usually the same,
373          * but rte copes even if we call free twice
374          */
375         if (ut_params->obuf) {
376                 rte_pktmbuf_free(ut_params->obuf);
377                 ut_params->obuf = 0;
378         }
379         if (ut_params->ibuf) {
380                 rte_pktmbuf_free(ut_params->ibuf);
381                 ut_params->ibuf = 0;
382         }
383
384         if (ts_params->mbuf_pool != NULL)
385                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
386                                 rte_mempool_count(ts_params->mbuf_pool));
387
388         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
389
390         /* Stop the device */
391         rte_cryptodev_stop(ts_params->valid_devs[0]);
392 }
393
394 static int
395 test_device_configure_invalid_dev_id(void)
396 {
397         struct crypto_testsuite_params *ts_params = &testsuite_params;
398         uint16_t dev_id, num_devs = 0;
399
400         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
401                         "Need at least %d devices for test", 1);
402
403         /* valid dev_id values */
404         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
405
406         /* Stop the device in case it's started so it can be configured */
407         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
408
409         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
410                         "Failed test for rte_cryptodev_configure: "
411                         "invalid dev_num %u", dev_id);
412
413         /* invalid dev_id values */
414         dev_id = num_devs;
415
416         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
417                         "Failed test for rte_cryptodev_configure: "
418                         "invalid dev_num %u", dev_id);
419
420         dev_id = 0xff;
421
422         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
423                         "Failed test for rte_cryptodev_configure:"
424                         "invalid dev_num %u", dev_id);
425
426         return TEST_SUCCESS;
427 }
428
429 static int
430 test_device_configure_invalid_queue_pair_ids(void)
431 {
432         struct crypto_testsuite_params *ts_params = &testsuite_params;
433
434         /* Stop the device in case it's started so it can be configured */
435         rte_cryptodev_stop(ts_params->valid_devs[0]);
436
437         /* valid - one queue pairs */
438         ts_params->conf.nb_queue_pairs = 1;
439
440         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
441                         &ts_params->conf),
442                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
443                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
444
445
446         /* valid - max value queue pairs */
447         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
448
449         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
450                         &ts_params->conf),
451                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
452                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
453
454
455         /* invalid - zero queue pairs */
456         ts_params->conf.nb_queue_pairs = 0;
457
458         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
459                         &ts_params->conf),
460                         "Failed test for rte_cryptodev_configure, dev_id %u,"
461                         " invalid qps: %u",
462                         ts_params->valid_devs[0],
463                         ts_params->conf.nb_queue_pairs);
464
465
466         /* invalid - max value supported by field queue pairs */
467         ts_params->conf.nb_queue_pairs = UINT16_MAX;
468
469         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
470                         &ts_params->conf),
471                         "Failed test for rte_cryptodev_configure, dev_id %u,"
472                         " invalid qps: %u",
473                         ts_params->valid_devs[0],
474                         ts_params->conf.nb_queue_pairs);
475
476
477         /* invalid - max value + 1 queue pairs */
478         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
479
480         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
481                         &ts_params->conf),
482                         "Failed test for rte_cryptodev_configure, dev_id %u,"
483                         " invalid qps: %u",
484                         ts_params->valid_devs[0],
485                         ts_params->conf.nb_queue_pairs);
486
487         return TEST_SUCCESS;
488 }
489
490 static int
491 test_queue_pair_descriptor_setup(void)
492 {
493         struct crypto_testsuite_params *ts_params = &testsuite_params;
494         struct rte_cryptodev_info dev_info;
495         struct rte_cryptodev_qp_conf qp_conf = {
496                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
497         };
498
499         uint16_t qp_id;
500
501         /* Stop the device in case it's started so it can be configured */
502         rte_cryptodev_stop(ts_params->valid_devs[0]);
503
504
505         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
506
507         ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
508
509         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
510                         &ts_params->conf), "Failed to configure cryptodev %u",
511                         ts_params->valid_devs[0]);
512
513
514         /*
515          * Test various ring sizes on this device. memzones can't be
516          * freed so are re-used if ring is released and re-created.
517          */
518         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
519
520         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
521                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
522                                 ts_params->valid_devs[0], qp_id, &qp_conf,
523                                 rte_cryptodev_socket_id(
524                                                 ts_params->valid_devs[0])),
525                                 "Failed test for "
526                                 "rte_cryptodev_queue_pair_setup: num_inflights "
527                                 "%u on qp %u on cryptodev %u",
528                                 qp_conf.nb_descriptors, qp_id,
529                                 ts_params->valid_devs[0]);
530         }
531
532         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
533
534         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
535                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
536                                 ts_params->valid_devs[0], qp_id, &qp_conf,
537                                 rte_cryptodev_socket_id(
538                                                 ts_params->valid_devs[0])),
539                                 "Failed test for"
540                                 " rte_cryptodev_queue_pair_setup: num_inflights"
541                                 " %u on qp %u on cryptodev %u",
542                                 qp_conf.nb_descriptors, qp_id,
543                                 ts_params->valid_devs[0]);
544         }
545
546         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
547
548         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
549                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
550                                 ts_params->valid_devs[0], qp_id, &qp_conf,
551                                 rte_cryptodev_socket_id(
552                                                 ts_params->valid_devs[0])),
553                                 "Failed test for "
554                                 "rte_cryptodev_queue_pair_setup: num_inflights"
555                                 " %u on qp %u on cryptodev %u",
556                                 qp_conf.nb_descriptors, qp_id,
557                                 ts_params->valid_devs[0]);
558         }
559
560         /* invalid number of descriptors - max supported + 2 */
561         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
562
563         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
564                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
565                                 ts_params->valid_devs[0], qp_id, &qp_conf,
566                                 rte_cryptodev_socket_id(
567                                                 ts_params->valid_devs[0])),
568                                 "Unexpectedly passed test for "
569                                 "rte_cryptodev_queue_pair_setup:"
570                                 "num_inflights %u on qp %u on cryptodev %u",
571                                 qp_conf.nb_descriptors, qp_id,
572                                 ts_params->valid_devs[0]);
573         }
574
575         /* invalid number of descriptors - max value of parameter */
576         qp_conf.nb_descriptors = UINT32_MAX-1;
577
578         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
579                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
580                                 ts_params->valid_devs[0], qp_id, &qp_conf,
581                                 rte_cryptodev_socket_id(
582                                                 ts_params->valid_devs[0])),
583                                 "Unexpectedly passed test for "
584                                 "rte_cryptodev_queue_pair_setup:"
585                                 "num_inflights %u on qp %u on cryptodev %u",
586                                 qp_conf.nb_descriptors, qp_id,
587                                 ts_params->valid_devs[0]);
588         }
589
590         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
591
592         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
593                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
594                                 ts_params->valid_devs[0], qp_id, &qp_conf,
595                                 rte_cryptodev_socket_id(
596                                                 ts_params->valid_devs[0])),
597                                 "Failed test for"
598                                 " rte_cryptodev_queue_pair_setup:"
599                                 "num_inflights %u on qp %u on cryptodev %u",
600                                 qp_conf.nb_descriptors, qp_id,
601                                 ts_params->valid_devs[0]);
602         }
603
604         /* invalid number of descriptors - max supported + 1 */
605         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
606
607         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
608                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
609                                 ts_params->valid_devs[0], qp_id, &qp_conf,
610                                 rte_cryptodev_socket_id(
611                                                 ts_params->valid_devs[0])),
612                                 "Unexpectedly passed test for "
613                                 "rte_cryptodev_queue_pair_setup:"
614                                 "num_inflights %u on qp %u on cryptodev %u",
615                                 qp_conf.nb_descriptors, qp_id,
616                                 ts_params->valid_devs[0]);
617         }
618
619         /* test invalid queue pair id */
620         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
621
622         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
623
624         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
625                         ts_params->valid_devs[0],
626                         qp_id, &qp_conf,
627                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
628                         "Failed test for rte_cryptodev_queue_pair_setup:"
629                         "invalid qp %u on cryptodev %u",
630                         qp_id, ts_params->valid_devs[0]);
631
632         qp_id = 0xffff; /*invalid*/
633
634         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
635                         ts_params->valid_devs[0],
636                         qp_id, &qp_conf,
637                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
638                         "Failed test for rte_cryptodev_queue_pair_setup:"
639                         "invalid qp %u on cryptodev %u",
640                         qp_id, ts_params->valid_devs[0]);
641
642         return TEST_SUCCESS;
643 }
644
645 /* ***** Plaintext data for tests ***** */
646
647 const char catch_22_quote_1[] =
648                 "There was only one catch and that was Catch-22, which "
649                 "specified that a concern for one's safety in the face of "
650                 "dangers that were real and immediate was the process of a "
651                 "rational mind. Orr was crazy and could be grounded. All he "
652                 "had to do was ask; and as soon as he did, he would no longer "
653                 "be crazy and would have to fly more missions. Orr would be "
654                 "crazy to fly more missions and sane if he didn't, but if he "
655                 "was sane he had to fly them. If he flew them he was crazy "
656                 "and didn't have to; but if he didn't want to he was sane and "
657                 "had to. Yossarian was moved very deeply by the absolute "
658                 "simplicity of this clause of Catch-22 and let out a "
659                 "respectful whistle. \"That's some catch, that Catch-22\", he "
660                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
661
662 const char catch_22_quote[] =
663                 "What a lousy earth! He wondered how many people were "
664                 "destitute that same night even in his own prosperous country, "
665                 "how many homes were shanties, how many husbands were drunk "
666                 "and wives socked, and how many children were bullied, abused, "
667                 "or abandoned. How many families hungered for food they could "
668                 "not afford to buy? How many hearts were broken? How many "
669                 "suicides would take place that same night, how many people "
670                 "would go insane? How many cockroaches and landlords would "
671                 "triumph? How many winners were losers, successes failures, "
672                 "and rich men poor men? How many wise guys were stupid? How "
673                 "many happy endings were unhappy endings? How many honest men "
674                 "were liars, brave men cowards, loyal men traitors, how many "
675                 "sainted men were corrupt, how many people in positions of "
676                 "trust had sold their souls to bodyguards, how many had never "
677                 "had souls? How many straight-and-narrow paths were crooked "
678                 "paths? How many best families were worst families and how "
679                 "many good people were bad people? When you added them all up "
680                 "and then subtracted, you might be left with only the children, "
681                 "and perhaps with Albert Einstein and an old violinist or "
682                 "sculptor somewhere.";
683
684 #define QUOTE_480_BYTES         (480)
685 #define QUOTE_512_BYTES         (512)
686 #define QUOTE_768_BYTES         (768)
687 #define QUOTE_1024_BYTES        (1024)
688
689
690
691 /* ***** SHA1 Hash Tests ***** */
692
693 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
694
695 static uint8_t hmac_sha1_key[] = {
696         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
697         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
698         0xDE, 0xF4, 0xDE, 0xAD };
699
700 /* ***** SHA224 Hash Tests ***** */
701
702 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
703
704
705 /* ***** AES-CBC Cipher Tests ***** */
706
707 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
708 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
709
710 static uint8_t aes_cbc_key[] = {
711         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
712         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
713
714 static uint8_t aes_cbc_iv[] = {
715         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
716         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
717
718
719 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
720
721 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
722         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
723         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
724         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
725         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
726         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
727         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
728         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
729         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
730         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
731         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
732         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
733         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
734         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
735         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
736         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
737         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
738         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
739         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
740         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
741         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
742         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
743         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
744         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
745         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
746         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
747         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
748         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
749         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
750         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
751         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
752         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
753         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
754         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
755         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
756         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
757         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
758         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
759         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
760         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
761         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
762         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
763         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
764         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
765         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
766         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
767         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
768         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
769         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
770         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
771         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
772         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
773         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
774         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
775         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
776         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
777         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
778         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
779         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
780         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
781         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
782         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
783         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
784         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
785         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
786 };
787
788 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
789         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
790         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
791         0x18, 0x8c, 0x1d, 0x32
792 };
793
794
795 static int
796 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
797 {
798         struct crypto_testsuite_params *ts_params = &testsuite_params;
799         struct crypto_unittest_params *ut_params = &unittest_params;
800
801         /* Generate test mbuf data and space for digest */
802         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
803                         catch_22_quote, QUOTE_512_BYTES, 0);
804
805         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
806                         DIGEST_BYTE_LENGTH_SHA1);
807         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
808
809         /* Setup Cipher Parameters */
810         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
811         ut_params->cipher_xform.next = &ut_params->auth_xform;
812
813         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
814         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
815         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
816         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
817
818         /* Setup HMAC Parameters */
819         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
820
821         ut_params->auth_xform.next = NULL;
822
823         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
824         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
825         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
826         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
827         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
828
829         /* Create crypto session*/
830         ut_params->sess = rte_cryptodev_sym_session_create(
831                         ts_params->valid_devs[0],
832                         &ut_params->cipher_xform);
833         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
834
835         /* Generate crypto op data structure */
836         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
837                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
838         TEST_ASSERT_NOT_NULL(ut_params->op,
839                         "Failed to allocate symmetric crypto operation struct");
840
841         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
842
843         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
844
845         /* set crypto operation source mbuf */
846         sym_op->m_src = ut_params->ibuf;
847
848         /* Set crypto operation authentication parameters */
849         sym_op->auth.digest.data = ut_params->digest;
850         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
851                         ut_params->ibuf, QUOTE_512_BYTES);
852         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
853
854         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
855         sym_op->auth.data.length = QUOTE_512_BYTES;
856
857         /* Set crypto operation cipher parameters */
858         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
859                         CIPHER_IV_LENGTH_AES_CBC);
860         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
861         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
862
863         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
864                         CIPHER_IV_LENGTH_AES_CBC);
865
866         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
867         sym_op->cipher.data.length = QUOTE_512_BYTES;
868
869         /* Process crypto operation */
870         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
871                         ut_params->op), "failed to process sym crypto op");
872
873         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
874                         "crypto op processing failed");
875
876         /* Validate obuf */
877         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
878                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
879
880         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
881                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
882                         QUOTE_512_BYTES,
883                         "ciphertext data not as expected");
884
885         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
886
887         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
888                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
889                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
890                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
891                                         DIGEST_BYTE_LENGTH_SHA1,
892                         "Generated digest data not as expected");
893
894         return TEST_SUCCESS;
895 }
896
897 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
898
899 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
900
901 static uint8_t hmac_sha512_key[] = {
902         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
903         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
904         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
905         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
906         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
907         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
908         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
909         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
910
911 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
912         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
913         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
914         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
915         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
916         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
917         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
918         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
919         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
920
921
922
923 static int
924 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
925                 struct crypto_unittest_params *ut_params);
926
927 static int
928 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
929                 struct crypto_unittest_params *ut_params,
930                 struct crypto_testsuite_params *ts_params);
931
932
933 static int
934 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
935                 struct crypto_unittest_params *ut_params)
936 {
937
938         /* Setup Cipher Parameters */
939         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
940         ut_params->cipher_xform.next = NULL;
941
942         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
943         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
944         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
945         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
946
947         /* Setup HMAC Parameters */
948         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
949         ut_params->auth_xform.next = &ut_params->cipher_xform;
950
951         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
952         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
953         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
954         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
955         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
956
957         return TEST_SUCCESS;
958 }
959
960
961 static int
962 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
963                 struct crypto_unittest_params *ut_params,
964                 struct crypto_testsuite_params *ts_params)
965 {
966         /* Generate test mbuf data and digest */
967         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
968                         (const char *)
969                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
970                         QUOTE_512_BYTES, 0);
971
972         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
973                         DIGEST_BYTE_LENGTH_SHA512);
974         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
975
976         rte_memcpy(ut_params->digest,
977                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
978                         DIGEST_BYTE_LENGTH_SHA512);
979
980         /* Generate Crypto op data structure */
981         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
982                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
983         TEST_ASSERT_NOT_NULL(ut_params->op,
984                         "Failed to allocate symmetric crypto operation struct");
985
986         rte_crypto_op_attach_sym_session(ut_params->op, sess);
987
988         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
989
990         /* set crypto operation source mbuf */
991         sym_op->m_src = ut_params->ibuf;
992
993         sym_op->auth.digest.data = ut_params->digest;
994         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
995                         ut_params->ibuf, QUOTE_512_BYTES);
996         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
997
998         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
999         sym_op->auth.data.length = QUOTE_512_BYTES;
1000
1001         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1002                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1003         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1004                         ut_params->ibuf, 0);
1005         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1006
1007         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1008                         CIPHER_IV_LENGTH_AES_CBC);
1009
1010         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1011         sym_op->cipher.data.length = QUOTE_512_BYTES;
1012
1013         /* Process crypto operation */
1014         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1015                         ut_params->op), "failed to process sym crypto op");
1016
1017         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1018                         "crypto op processing failed");
1019
1020         ut_params->obuf = ut_params->op->sym->m_src;
1021
1022         /* Validate obuf */
1023         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1024                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1025                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1026                         QUOTE_512_BYTES,
1027                         "Plaintext data not as expected");
1028
1029         /* Validate obuf */
1030         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1031                         "Digest verification failed");
1032
1033         return TEST_SUCCESS;
1034 }
1035
1036 static int
1037 test_AES_mb_all(void)
1038 {
1039         struct crypto_testsuite_params *ts_params = &testsuite_params;
1040         int status;
1041
1042         status = test_AES_all_tests(ts_params->mbuf_pool,
1043                 ts_params->op_mpool, ts_params->valid_devs[0],
1044                 RTE_CRYPTODEV_AESNI_MB_PMD);
1045
1046         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1047
1048         return TEST_SUCCESS;
1049 }
1050
1051 static int
1052 test_AES_qat_all(void)
1053 {
1054         struct crypto_testsuite_params *ts_params = &testsuite_params;
1055         int status;
1056
1057         status = test_AES_all_tests(ts_params->mbuf_pool,
1058                 ts_params->op_mpool, ts_params->valid_devs[0],
1059                 RTE_CRYPTODEV_QAT_SYM_PMD);
1060
1061         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1062
1063         return TEST_SUCCESS;
1064 }
1065
1066 /* ***** Snow3G Tests ***** */
1067 static int
1068 create_snow3g_hash_session(uint8_t dev_id,
1069         const uint8_t *key, const uint8_t key_len,
1070         const uint8_t aad_len, const uint8_t auth_len,
1071         enum rte_crypto_auth_operation op)
1072 {
1073         uint8_t hash_key[key_len];
1074
1075         struct crypto_unittest_params *ut_params = &unittest_params;
1076
1077         memcpy(hash_key, key, key_len);
1078 #ifdef RTE_APP_TEST_DEBUG
1079         rte_hexdump(stdout, "key:", key, key_len);
1080 #endif
1081         /* Setup Authentication Parameters */
1082         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1083         ut_params->auth_xform.next = NULL;
1084
1085         ut_params->auth_xform.auth.op = op;
1086         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1087         ut_params->auth_xform.auth.key.length = key_len;
1088         ut_params->auth_xform.auth.key.data = hash_key;
1089         ut_params->auth_xform.auth.digest_length = auth_len;
1090         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1091         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1092                                 &ut_params->auth_xform);
1093         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1094         return 0;
1095 }
1096 static int
1097 create_snow3g_cipher_session(uint8_t dev_id,
1098                         enum rte_crypto_cipher_operation op,
1099                         const uint8_t *key, const uint8_t key_len)
1100 {
1101         uint8_t cipher_key[key_len];
1102
1103         struct crypto_unittest_params *ut_params = &unittest_params;
1104
1105         memcpy(cipher_key, key, key_len);
1106
1107         /* Setup Cipher Parameters */
1108         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1109         ut_params->cipher_xform.next = NULL;
1110
1111         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1112         ut_params->cipher_xform.cipher.op = op;
1113         ut_params->cipher_xform.cipher.key.data = cipher_key;
1114         ut_params->cipher_xform.cipher.key.length = key_len;
1115
1116 #ifdef RTE_APP_TEST_DEBUG
1117         rte_hexdump(stdout, "key:", key, key_len);
1118 #endif
1119         /* Create Crypto session */
1120         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1121                                                 &ut_params->
1122                                                 cipher_xform);
1123         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1124         return 0;
1125 }
1126
1127 static int
1128 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1129                         const unsigned cipher_len,
1130                         const unsigned cipher_offset)
1131 {
1132         struct crypto_testsuite_params *ts_params = &testsuite_params;
1133         struct crypto_unittest_params *ut_params = &unittest_params;
1134         unsigned iv_pad_len = 0;
1135
1136         /* Generate Crypto op data structure */
1137         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1138                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1139         TEST_ASSERT_NOT_NULL(ut_params->op,
1140                                 "Failed to allocate pktmbuf offload");
1141
1142         /* Set crypto operation data parameters */
1143         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1144
1145         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1146
1147         /* set crypto operation source mbuf */
1148         sym_op->m_src = ut_params->ibuf;
1149
1150         /* iv */
1151         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1152         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1153                         , iv_pad_len);
1154
1155         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1156
1157         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1158         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1159         sym_op->cipher.iv.length = iv_pad_len;
1160
1161         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1162         sym_op->cipher.data.length = cipher_len;
1163         sym_op->cipher.data.offset = cipher_offset;
1164         return 0;
1165 }
1166
1167 static int
1168 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1169                         const unsigned cipher_len,
1170                         const unsigned cipher_offset)
1171 {
1172         struct crypto_testsuite_params *ts_params = &testsuite_params;
1173         struct crypto_unittest_params *ut_params = &unittest_params;
1174         unsigned iv_pad_len = 0;
1175
1176         /* Generate Crypto op data structure */
1177         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1178                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1179         TEST_ASSERT_NOT_NULL(ut_params->op,
1180                                 "Failed to allocate pktmbuf offload");
1181
1182         /* Set crypto operation data parameters */
1183         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1184
1185         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1186
1187         /* set crypto operation source mbuf */
1188         sym_op->m_src = ut_params->ibuf;
1189         sym_op->m_dst = ut_params->obuf;
1190
1191         /* iv */
1192         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1193         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1194                         , iv_pad_len);
1195
1196         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1197
1198         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1199         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1200         sym_op->cipher.iv.length = iv_pad_len;
1201
1202         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1203         sym_op->cipher.data.length = cipher_len;
1204         sym_op->cipher.data.offset = cipher_offset;
1205         return 0;
1206 }
1207
1208 static int
1209 create_snow3g_cipher_auth_session(uint8_t dev_id,
1210                 enum rte_crypto_cipher_operation cipher_op,
1211                 enum rte_crypto_auth_operation auth_op,
1212                 const uint8_t *key, const uint8_t key_len,
1213                 const uint8_t aad_len, const uint8_t auth_len)
1214 {
1215         uint8_t cipher_auth_key[key_len];
1216
1217         struct crypto_unittest_params *ut_params = &unittest_params;
1218
1219         memcpy(cipher_auth_key, key, key_len);
1220
1221         /* Setup Authentication Parameters */
1222         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1223         ut_params->auth_xform.next = NULL;
1224
1225         ut_params->auth_xform.auth.op = auth_op;
1226         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1227         ut_params->auth_xform.auth.key.length = key_len;
1228         /* Hash key = cipher key */
1229         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1230         ut_params->auth_xform.auth.digest_length = auth_len;
1231         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1232
1233         /* Setup Cipher Parameters */
1234         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1235         ut_params->cipher_xform.next = &ut_params->auth_xform;
1236
1237         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1238         ut_params->cipher_xform.cipher.op = cipher_op;
1239         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1240         ut_params->cipher_xform.cipher.key.length = key_len;
1241
1242 #ifdef RTE_APP_TEST_DEBUG
1243         rte_hexdump(stdout, "key:", key, key_len);
1244 #endif
1245         /* Create Crypto session*/
1246         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1247                                 &ut_params->cipher_xform);
1248
1249         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1250         return 0;
1251 }
1252
1253 static int
1254 create_snow3g_auth_cipher_session(uint8_t dev_id,
1255                 enum rte_crypto_cipher_operation cipher_op,
1256                 enum rte_crypto_auth_operation auth_op,
1257                 const uint8_t *key, const uint8_t key_len,
1258                 const uint8_t aad_len, const uint8_t auth_len)
1259         {
1260         uint8_t auth_cipher_key[key_len];
1261
1262         struct crypto_unittest_params *ut_params = &unittest_params;
1263
1264         memcpy(auth_cipher_key, key, key_len);
1265
1266         /* Setup Authentication Parameters */
1267         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1268         ut_params->auth_xform.auth.op = auth_op;
1269         ut_params->auth_xform.next = &ut_params->cipher_xform;
1270         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1271         ut_params->auth_xform.auth.key.length = key_len;
1272         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1273         ut_params->auth_xform.auth.digest_length = auth_len;
1274         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1275
1276         /* Setup Cipher Parameters */
1277         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1278         ut_params->cipher_xform.next = NULL;
1279         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1280         ut_params->cipher_xform.cipher.op = cipher_op;
1281         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1282         ut_params->cipher_xform.cipher.key.length = key_len;
1283
1284 #ifdef RTE_APP_TEST_DEBUG
1285         rte_hexdump(stdout, "key:", key, key_len);
1286 #endif
1287         /* Create Crypto session*/
1288         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1289                                 &ut_params->auth_xform);
1290
1291         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1292
1293         return 0;
1294 }
1295
1296 static int
1297 create_snow3g_hash_operation(const uint8_t *auth_tag,
1298                 const unsigned auth_tag_len,
1299                 const uint8_t *aad, const unsigned aad_len,
1300                 unsigned data_pad_len,
1301                 enum rte_crypto_auth_operation op,
1302                 const unsigned auth_len, const unsigned auth_offset)
1303 {
1304         struct crypto_testsuite_params *ts_params = &testsuite_params;
1305
1306         struct crypto_unittest_params *ut_params = &unittest_params;
1307
1308         unsigned aad_buffer_len;
1309
1310         /* Generate Crypto op data structure */
1311         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1312                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1313         TEST_ASSERT_NOT_NULL(ut_params->op,
1314                 "Failed to allocate pktmbuf offload");
1315
1316         /* Set crypto operation data parameters */
1317         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1318
1319         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1320
1321         /* set crypto operation source mbuf */
1322         sym_op->m_src = ut_params->ibuf;
1323
1324         /* aad */
1325         /*
1326         * Always allocate the aad up to the block size.
1327         * The cryptodev API calls out -
1328         *  - the array must be big enough to hold the AAD, plus any
1329         *   space to round this up to the nearest multiple of the
1330         *   block size (16 bytes).
1331         */
1332         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1333         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1334                         ut_params->ibuf, aad_buffer_len);
1335         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1336                                         "no room to prepend aad");
1337         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1338                         ut_params->ibuf);
1339         sym_op->auth.aad.length = aad_len;
1340
1341         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1342         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1343
1344 #ifdef RTE_APP_TEST_DEBUG
1345         rte_hexdump(stdout, "aad:",
1346                         sym_op->auth.aad.data, aad_len);
1347 #endif
1348
1349         /* digest */
1350         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1351                                         ut_params->ibuf, auth_tag_len);
1352
1353         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1354                                 "no room to append auth tag");
1355         ut_params->digest = sym_op->auth.digest.data;
1356         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1357                         ut_params->ibuf, data_pad_len + aad_len);
1358         sym_op->auth.digest.length = auth_tag_len;
1359         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1360                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1361         else
1362                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1363
1364 #ifdef RTE_APP_TEST_DEBUG
1365         rte_hexdump(stdout, "digest:",
1366                 sym_op->auth.digest.data,
1367                 sym_op->auth.digest.length);
1368 #endif
1369
1370         sym_op->auth.data.length = auth_len;
1371         sym_op->auth.data.offset = auth_offset;
1372
1373         return 0;
1374 }
1375
1376 static int
1377 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1378                 const unsigned auth_tag_len,
1379                 const uint8_t *aad, const uint8_t aad_len,
1380                 unsigned data_pad_len,
1381                 enum rte_crypto_auth_operation op,
1382                 const uint8_t *iv, const uint8_t iv_len,
1383                 const unsigned cipher_len, const unsigned cipher_offset,
1384                 const unsigned auth_len, const unsigned auth_offset)
1385 {
1386         struct crypto_testsuite_params *ts_params = &testsuite_params;
1387         struct crypto_unittest_params *ut_params = &unittest_params;
1388
1389         unsigned iv_pad_len = 0;
1390         unsigned aad_buffer_len;
1391
1392         /* Generate Crypto op data structure */
1393         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1394                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1395         TEST_ASSERT_NOT_NULL(ut_params->op,
1396                         "Failed to allocate pktmbuf offload");
1397         /* Set crypto operation data parameters */
1398         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1399
1400         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1401
1402         /* set crypto operation source mbuf */
1403         sym_op->m_src = ut_params->ibuf;
1404
1405
1406         /* iv */
1407         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1408
1409         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1410                 ut_params->ibuf, iv_pad_len);
1411         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1412
1413         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1414         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1415         sym_op->cipher.iv.length = iv_pad_len;
1416
1417         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1418
1419         sym_op->cipher.data.length = cipher_len;
1420         sym_op->cipher.data.offset = cipher_offset;
1421
1422         /* aad */
1423         /*
1424         * Always allocate the aad up to the block size.
1425         * The cryptodev API calls out -
1426         *  - the array must be big enough to hold the AAD, plus any
1427         *   space to round this up to the nearest multiple of the
1428         *   block size (16 bytes).
1429         */
1430         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1431
1432         sym_op->auth.aad.data =
1433                         (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1434         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1435                         "no room to prepend aad");
1436         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1437                         ut_params->ibuf);
1438         sym_op->auth.aad.length = aad_len;
1439
1440         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1441         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1442
1443 #ifdef RTE_APP_TEST_DEBUG
1444         rte_hexdump(stdout, "aad:",
1445                         sym_op->auth.aad.data, aad_len);
1446 #endif
1447
1448         /* digest */
1449         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1450                         ut_params->ibuf, auth_tag_len);
1451
1452         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1453                         "no room to append auth tag");
1454         ut_params->digest = sym_op->auth.digest.data;
1455         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1456                         ut_params->ibuf, data_pad_len + aad_len);
1457         sym_op->auth.digest.length = auth_tag_len;
1458         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1459                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1460         else
1461                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1462
1463         #ifdef RTE_APP_TEST_DEBUG
1464         rte_hexdump(stdout, "digest:",
1465                 sym_op->auth.digest.data,
1466                 sym_op->auth.digest.length);
1467         #endif
1468
1469         sym_op->auth.data.length = auth_len;
1470         sym_op->auth.data.offset = auth_offset;
1471
1472         return 0;
1473 }
1474
1475 static int
1476 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1477                 const uint8_t *iv, const uint8_t iv_len,
1478                 const uint8_t *aad, const uint8_t aad_len,
1479                 unsigned data_pad_len,
1480                 const unsigned cipher_len, const unsigned cipher_offset,
1481                 const unsigned auth_len, const unsigned auth_offset)
1482 {
1483         struct crypto_testsuite_params *ts_params = &testsuite_params;
1484         struct crypto_unittest_params *ut_params = &unittest_params;
1485
1486         unsigned iv_pad_len = 0;
1487         unsigned aad_buffer_len = 0;
1488
1489         /* Generate Crypto op data structure */
1490         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1491                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1492         TEST_ASSERT_NOT_NULL(ut_params->op,
1493                         "Failed to allocate pktmbuf offload");
1494
1495         /* Set crypto operation data parameters */
1496         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1497
1498         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1499
1500         /* set crypto operation source mbuf */
1501         sym_op->m_src = ut_params->ibuf;
1502
1503         /* digest */
1504         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1505                         ut_params->ibuf, auth_tag_len);
1506
1507         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1508                         "no room to append auth tag");
1509
1510         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1511                         ut_params->ibuf, data_pad_len);
1512         sym_op->auth.digest.length = auth_tag_len;
1513
1514         memset(sym_op->auth.digest.data, 0, auth_tag_len);
1515
1516         #ifdef RTE_APP_TEST_DEBUG
1517                 rte_hexdump(stdout, "digest:",
1518                         sym_op->auth.digest.data,
1519                         sym_op->auth.digest.length);
1520         #endif
1521         /* iv */
1522         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1523
1524         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1525                 ut_params->ibuf, iv_pad_len);
1526         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1527
1528         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1529         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1530         sym_op->cipher.iv.length = iv_pad_len;
1531
1532         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1533
1534         /* aad */
1535         /*
1536         * Always allocate the aad up to the block size.
1537         * The cryptodev API calls out -
1538         *  - the array must be big enough to hold the AAD, plus any
1539         *   space to round this up to the nearest multiple of the
1540         *   block size (16 bytes).
1541         */
1542         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1543
1544         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1545         ut_params->ibuf, aad_buffer_len);
1546         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1547                                 "no room to prepend aad");
1548         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1549                                 ut_params->ibuf);
1550         sym_op->auth.aad.length = aad_len;
1551
1552         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1553         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1554
1555 #ifdef RTE_APP_TEST_DEBUG
1556         rte_hexdump(stdout, "aad:",
1557                         sym_op->auth.aad.data, aad_len);
1558 #endif
1559
1560         sym_op->cipher.data.length = cipher_len;
1561         sym_op->cipher.data.offset = auth_offset + cipher_offset;
1562
1563         sym_op->auth.data.length = auth_len;
1564         sym_op->auth.data.offset = auth_offset + cipher_offset;
1565
1566         return 0;
1567 }
1568
1569 static int
1570 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1571 {
1572         struct crypto_testsuite_params *ts_params = &testsuite_params;
1573         struct crypto_unittest_params *ut_params = &unittest_params;
1574
1575         int retval;
1576         unsigned plaintext_pad_len;
1577         uint8_t *plaintext;
1578
1579         /* Create SNOW3G session */
1580         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1581                         tdata->key.data, tdata->key.len,
1582                         tdata->aad.len, tdata->digest.len,
1583                         RTE_CRYPTO_AUTH_OP_GENERATE);
1584         if (retval < 0)
1585                 return retval;
1586
1587         /* alloc mbuf and set payload */
1588         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1589
1590         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1591         rte_pktmbuf_tailroom(ut_params->ibuf));
1592
1593         /* Append data which is padded to a multiple of */
1594         /* the algorithms block size */
1595         plaintext_pad_len = tdata->plaintext.len >> 3;
1596         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1597                                 plaintext_pad_len);
1598         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1599
1600         /* Create SNOW3G opertaion */
1601         retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1602                         tdata->aad.data, tdata->aad.len,
1603                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1604                         tdata->validAuthLenInBits.len,
1605                         tdata->validAuthOffsetLenInBits.len);
1606         if (retval < 0)
1607                 return retval;
1608
1609         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1610                                 ut_params->op);
1611         ut_params->obuf = ut_params->op->sym->m_src;
1612         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1613         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1614                         + plaintext_pad_len + tdata->aad.len;
1615
1616         /* Validate obuf */
1617         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1618         ut_params->digest,
1619         tdata->digest.data,
1620         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1621         "Snow3G Generated auth tag not as expected");
1622
1623         return 0;
1624 }
1625
1626 static int
1627 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1628 {
1629         struct crypto_testsuite_params *ts_params = &testsuite_params;
1630         struct crypto_unittest_params *ut_params = &unittest_params;
1631
1632         int retval;
1633         unsigned plaintext_pad_len;
1634         uint8_t *plaintext;
1635
1636         /* Create SNOW3G session */
1637         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1638                                 tdata->key.data, tdata->key.len,
1639                                 tdata->aad.len, tdata->digest.len,
1640                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1641         if (retval < 0)
1642                 return retval;
1643         /* alloc mbuf and set payload */
1644         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1645
1646         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1647         rte_pktmbuf_tailroom(ut_params->ibuf));
1648
1649         /* Append data which is padded to a multiple */
1650         /* of the algorithms block size */
1651         plaintext_pad_len = tdata->plaintext.len >> 3;
1652         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1653                                         plaintext_pad_len);
1654         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1655
1656         /* Create SNOW3G operation */
1657         retval = create_snow3g_hash_operation(tdata->digest.data,
1658                         tdata->digest.len,
1659                         tdata->aad.data, tdata->aad.len,
1660                         plaintext_pad_len,
1661                         RTE_CRYPTO_AUTH_OP_VERIFY,
1662                         tdata->validAuthLenInBits.len,
1663                         tdata->validAuthOffsetLenInBits.len);
1664         if (retval < 0)
1665                 return retval;
1666
1667         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1668                                 ut_params->op);
1669         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1670         ut_params->obuf = ut_params->op->sym->m_src;
1671         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1672                                 + plaintext_pad_len + tdata->aad.len;
1673
1674         /* Validate obuf */
1675         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1676                 return 0;
1677         else
1678                 return -1;
1679
1680         return 0;
1681 }
1682
1683
1684 static int
1685 test_snow3g_hash_generate_test_case_1(void)
1686 {
1687         return test_snow3g_authentication(&snow3g_hash_test_case_1);
1688 }
1689
1690 static int
1691 test_snow3g_hash_generate_test_case_2(void)
1692 {
1693         return test_snow3g_authentication(&snow3g_hash_test_case_2);
1694 }
1695
1696 static int
1697 test_snow3g_hash_generate_test_case_3(void)
1698 {
1699         return test_snow3g_authentication(&snow3g_hash_test_case_3);
1700 }
1701
1702 static int
1703 test_snow3g_hash_verify_test_case_1(void)
1704 {
1705         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1706
1707 }
1708
1709 static int
1710 test_snow3g_hash_verify_test_case_2(void)
1711 {
1712         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1713 }
1714
1715 static int
1716 test_snow3g_hash_verify_test_case_3(void)
1717 {
1718         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1719 }
1720
1721 static int
1722 test_snow3g_encryption(const struct snow3g_test_data *tdata)
1723 {
1724         struct crypto_testsuite_params *ts_params = &testsuite_params;
1725         struct crypto_unittest_params *ut_params = &unittest_params;
1726
1727         int retval;
1728         uint8_t *plaintext, *ciphertext;
1729         uint8_t plaintext_pad_len;
1730         uint8_t lastByteValidBits = 8;
1731         uint8_t lastByteMask = 0xFF;
1732
1733         /* Create SNOW3G session */
1734         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1735                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1736                                         tdata->key.data, tdata->key.len);
1737         if (retval < 0)
1738                 return retval;
1739
1740         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1741
1742         /* Clear mbuf payload */
1743         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1744                rte_pktmbuf_tailroom(ut_params->ibuf));
1745
1746         /*
1747          * Append data which is padded to a
1748          * multiple of the algorithms block size
1749          */
1750         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1751         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1752
1753         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1754                                                 plaintext_pad_len);
1755         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1756
1757 #ifdef RTE_APP_TEST_DEBUG
1758         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1759 #endif
1760         /* Create SNOW3G operation */
1761         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1762                                         tdata->validCipherLenInBits.len,
1763                                         tdata->validCipherOffsetLenInBits.len);
1764         if (retval < 0)
1765                 return retval;
1766
1767         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1768                                                 ut_params->op);
1769         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1770
1771         ut_params->obuf = ut_params->op->sym->m_dst;
1772         if (ut_params->obuf)
1773                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1774                                 + tdata->iv.len;
1775         else
1776                 ciphertext = plaintext;
1777
1778         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1779         if (lastByteValidBits == 0)
1780                 lastByteValidBits = 8;
1781         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1782         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1783
1784 #ifdef RTE_APP_TEST_DEBUG
1785         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1786 #endif
1787         /* Validate obuf */
1788         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1789                 ciphertext,
1790                 tdata->ciphertext.data,
1791                 tdata->ciphertext.len >> 3,
1792                 "Snow3G Ciphertext data not as expected");
1793         return 0;
1794 }
1795
1796
1797 static int
1798 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
1799 {
1800         struct crypto_testsuite_params *ts_params = &testsuite_params;
1801         struct crypto_unittest_params *ut_params = &unittest_params;
1802         uint8_t *plaintext, *ciphertext;
1803
1804         int retval;
1805         uint8_t plaintext_pad_len;
1806         uint8_t lastByteValidBits = 8;
1807         uint8_t lastByteMask = 0xFF;
1808
1809         /* Create SNOW3G session */
1810         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1811                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1812                                         tdata->key.data, tdata->key.len);
1813         if (retval < 0)
1814                 return retval;
1815
1816         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1817         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1818
1819         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1820                         "Failed to allocate input buffer in mempool");
1821         TEST_ASSERT_NOT_NULL(ut_params->obuf,
1822                         "Failed to allocate output buffer in mempool");
1823
1824         /* Clear mbuf payload */
1825         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1826                rte_pktmbuf_tailroom(ut_params->ibuf));
1827
1828         /*
1829          * Append data which is padded to a
1830          * multiple of the algorithms block size
1831          */
1832         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1833         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1834
1835         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1836                                                 plaintext_pad_len);
1837
1838         rte_pktmbuf_append(ut_params->obuf,
1839                                                 plaintext_pad_len);
1840
1841         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1842
1843 #ifdef RTE_APP_TEST_DEBUG
1844         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1845 #endif
1846         /* Create SNOW3G operation */
1847         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1848                                         tdata->iv.len,
1849                                         tdata->validCipherLenInBits.len,
1850                                         tdata->validCipherOffsetLenInBits.len);
1851         if (retval < 0)
1852                 return retval;
1853
1854         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1855                                                 ut_params->op);
1856         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1857
1858         ut_params->obuf = ut_params->op->sym->m_dst;
1859         if (ut_params->obuf)
1860                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1861                                 + tdata->iv.len;
1862         else
1863                 ciphertext = plaintext;
1864
1865         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1866         if (lastByteValidBits == 0)
1867                 lastByteValidBits = 8;
1868         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1869         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1870
1871 #ifdef RTE_APP_TEST_DEBUG
1872         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1873 #endif
1874         /* Validate obuf */
1875         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1876                 ciphertext,
1877                 tdata->ciphertext.data,
1878                 tdata->ciphertext.len >> 3,
1879                 "Snow3G Ciphertext data not as expected");
1880         return 0;
1881 }
1882
1883
1884 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
1885 {
1886         struct crypto_testsuite_params *ts_params = &testsuite_params;
1887         struct crypto_unittest_params *ut_params = &unittest_params;
1888
1889         int retval;
1890
1891         uint8_t *plaintext, *ciphertext;
1892         uint8_t ciphertext_pad_len;
1893         uint8_t lastByteValidBits = 8;
1894         uint8_t lastByteMask = 0xFF;
1895
1896         /* Create SNOW3G session */
1897         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1898                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
1899                                         tdata->key.data, tdata->key.len);
1900         if (retval < 0)
1901                 return retval;
1902
1903         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1904
1905         /* Clear mbuf payload */
1906         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1907                rte_pktmbuf_tailroom(ut_params->ibuf));
1908
1909         /*
1910          * Append data which is padded to a
1911          * multiple of the algorithms block size
1912          */
1913         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1914
1915         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1916                                                 ciphertext_pad_len);
1917         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1918
1919 #ifdef RTE_APP_TEST_DEBUG
1920         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1921 #endif
1922         /* Create SNOW3G operation */
1923         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1924                                         tdata->validCipherLenInBits.len,
1925                                         tdata->validCipherOffsetLenInBits.len);
1926         if (retval < 0)
1927                 return retval;
1928
1929         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1930                                                 ut_params->op);
1931         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1932         ut_params->obuf = ut_params->op->sym->m_src;
1933         if (ut_params->obuf)
1934                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1935                                 + tdata->iv.len;
1936         else
1937                 plaintext = ciphertext;
1938         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
1939         if (lastByteValidBits == 0)
1940                 lastByteValidBits = 8;
1941         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1942         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1943
1944 #ifdef RTE_APP_TEST_DEBUG
1945         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1946 #endif
1947         /* Validate obuf */
1948         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1949                                 tdata->plaintext.data,
1950                                 tdata->plaintext.len >> 3,
1951                                 "Snow3G Plaintext data not as expected");
1952         return 0;
1953 }
1954
1955 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
1956 {
1957         struct crypto_testsuite_params *ts_params = &testsuite_params;
1958         struct crypto_unittest_params *ut_params = &unittest_params;
1959
1960         int retval;
1961
1962         uint8_t *plaintext, *ciphertext;
1963         uint8_t ciphertext_pad_len;
1964         uint8_t lastByteValidBits = 8;
1965         uint8_t lastByteMask = 0xFF;
1966
1967         /* Create SNOW3G session */
1968         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1969                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
1970                                         tdata->key.data, tdata->key.len);
1971         if (retval < 0)
1972                 return retval;
1973
1974         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1975         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1976
1977         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1978                         "Failed to allocate input buffer");
1979         TEST_ASSERT_NOT_NULL(ut_params->obuf,
1980                         "Failed to allocate output buffer");
1981
1982         /* Clear mbuf payload */
1983         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1984                rte_pktmbuf_tailroom(ut_params->ibuf));
1985
1986         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
1987                        rte_pktmbuf_tailroom(ut_params->obuf));
1988
1989         /*
1990          * Append data which is padded to a
1991          * multiple of the algorithms block size
1992          */
1993         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1994
1995         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1996                                                 ciphertext_pad_len);
1997
1998         rte_pktmbuf_append(ut_params->obuf,
1999                                                 ciphertext_pad_len);
2000
2001         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2002
2003 #ifdef RTE_APP_TEST_DEBUG
2004         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2005 #endif
2006         /* Create SNOW3G operation */
2007         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2008                                         tdata->iv.len,
2009                                         tdata->validCipherLenInBits.len,
2010                                         tdata->validCipherOffsetLenInBits.len);
2011         if (retval < 0)
2012                 return retval;
2013
2014         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2015                                                 ut_params->op);
2016         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2017         ut_params->obuf = ut_params->op->sym->m_dst;
2018         if (ut_params->obuf)
2019                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2020                                 + tdata->iv.len;
2021         else
2022                 plaintext = ciphertext;
2023         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
2024         if (lastByteValidBits == 0)
2025                 lastByteValidBits = 8;
2026         lastByteMask = lastByteMask << (8 - lastByteValidBits);
2027         (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2028
2029 #ifdef RTE_APP_TEST_DEBUG
2030         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2031 #endif
2032         /* Validate obuf */
2033         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2034                                 tdata->plaintext.data,
2035                                 tdata->plaintext.len >> 3,
2036                                 "Snow3G Plaintext data not as expected");
2037         return 0;
2038 }
2039
2040 static int
2041 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2042 {
2043         struct crypto_testsuite_params *ts_params = &testsuite_params;
2044         struct crypto_unittest_params *ut_params = &unittest_params;
2045
2046         int retval;
2047
2048         uint8_t *plaintext, *ciphertext;
2049         uint8_t plaintext_pad_len;
2050         uint8_t lastByteValidBits = 8;
2051         uint8_t lastByteMask = 0xFF;
2052
2053         /* Create SNOW3G session */
2054         retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2055                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2056                         RTE_CRYPTO_AUTH_OP_GENERATE,
2057                         tdata->key.data, tdata->key.len,
2058                         tdata->aad.len, tdata->digest.len);
2059         if (retval < 0)
2060                 return retval;
2061         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2062
2063         /* clear mbuf payload */
2064         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2065                         rte_pktmbuf_tailroom(ut_params->ibuf));
2066
2067         /* Append data which is padded to a multiple */
2068         /*  of the algorithms block size */
2069         plaintext_pad_len = tdata->plaintext.len >> 3;
2070
2071         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2072                         plaintext_pad_len);
2073         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2074
2075 #ifdef RTE_APP_TEST_DEBUG
2076         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2077 #endif
2078
2079         /* Create SNOW3G operation */
2080         retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2081                         tdata->digest.len, tdata->aad.data,
2082                         tdata->aad.len, /*tdata->plaintext.len,*/
2083                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2084                         tdata->iv.data, tdata->iv.len,
2085                         tdata->validCipherLenInBits.len,
2086                         tdata->validCipherOffsetLenInBits.len,
2087                         tdata->validAuthLenInBits.len,
2088                         tdata->validAuthOffsetLenInBits.len);
2089         if (retval < 0)
2090                 return retval;
2091
2092         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2093                         ut_params->op);
2094         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2095         ut_params->obuf = ut_params->op->sym->m_src;
2096         if (ut_params->obuf)
2097                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2098                                 + tdata->iv.len;
2099         else
2100                 ciphertext = plaintext;
2101         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2102         if (lastByteValidBits == 0)
2103                 lastByteValidBits = 8;
2104         lastByteMask = lastByteMask << (8-lastByteValidBits);
2105         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2106
2107 #ifdef RTE_APP_TEST_DEBUG
2108         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2109 #endif
2110         /* Validate obuf */
2111         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2112                         ciphertext,
2113                         tdata->ciphertext.data,
2114                         tdata->ciphertext.len >> 3,
2115                         "Snow3G Ciphertext data not as expected");
2116
2117         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2118             + plaintext_pad_len + tdata->aad.len;
2119
2120         /* Validate obuf */
2121         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2122                         ut_params->digest,
2123                         tdata->digest.data,
2124                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2125                         "Snow3G Generated auth tag not as expected");
2126         return 0;
2127 }
2128 static int
2129 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2130 {
2131         struct crypto_testsuite_params *ts_params = &testsuite_params;
2132         struct crypto_unittest_params *ut_params = &unittest_params;
2133
2134         int retval;
2135
2136         uint8_t *plaintext, *ciphertext;
2137         uint8_t plaintext_pad_len;
2138         uint8_t lastByteValidBits = 8;
2139         uint8_t lastByteMask = 0xFF;
2140
2141         /* Create SNOW3G session */
2142         retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2143                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2144                         RTE_CRYPTO_AUTH_OP_GENERATE,
2145                         tdata->key.data, tdata->key.len,
2146                         tdata->aad.len, tdata->digest.len);
2147         if (retval < 0)
2148                 return retval;
2149
2150         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2151
2152         /* clear mbuf payload */
2153         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2154                         rte_pktmbuf_tailroom(ut_params->ibuf));
2155
2156         /* Append data which is padded to a multiple */
2157         /* of the algorithms block size */
2158         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2159
2160         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2161                         plaintext_pad_len);
2162         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2163
2164 #ifdef RTE_APP_TEST_DEBUG
2165         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2166 #endif
2167
2168         /* Create SNOW3G operation */
2169         retval = create_snow3g_auth_cipher_operation(
2170                 tdata->digest.len,
2171                 tdata->iv.data, tdata->iv.len,
2172                 tdata->aad.data, tdata->aad.len,
2173                 plaintext_pad_len,
2174                 tdata->validCipherLenInBits.len,
2175                 tdata->validCipherOffsetLenInBits.len,
2176                 tdata->validAuthLenInBits.len,
2177                 tdata->validAuthOffsetLenInBits.len
2178         );
2179
2180         if (retval < 0)
2181                 return retval;
2182
2183         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2184                         ut_params->op);
2185         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2186         ut_params->obuf = ut_params->op->sym->m_src;
2187         if (ut_params->obuf)
2188                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2189                                 + tdata->aad.len + tdata->iv.len;
2190         else
2191                 ciphertext = plaintext;
2192
2193         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2194         if (lastByteValidBits == 0)
2195                 lastByteValidBits = 8;
2196         lastByteMask = lastByteMask << (8-lastByteValidBits);
2197         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2198         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2199                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2200         #ifdef RTE_APP_TEST_DEBUG
2201         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2202 #endif
2203         /* Validate obuf */
2204         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2205                 ciphertext,
2206                 tdata->ciphertext.data,
2207                 tdata->ciphertext.len >> 3,
2208                 "Snow3G Ciphertext data not as expected");
2209
2210         /* Validate obuf */
2211         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2212                 ut_params->digest,
2213                 tdata->digest.data,
2214                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2215                 "Snow3G Generated auth tag not as expected");
2216         return 0;
2217 }
2218
2219 static int
2220 test_snow3g_encryption_test_case_1(void)
2221 {
2222         return test_snow3g_encryption(&snow3g_test_case_1);
2223 }
2224
2225 static int
2226 test_snow3g_encryption_test_case_1_oop(void)
2227 {
2228         return test_snow3g_encryption_oop(&snow3g_test_case_1);
2229 }
2230
2231 static int
2232 test_snow3g_encryption_test_case_2(void)
2233 {
2234         return test_snow3g_encryption(&snow3g_test_case_2);
2235 }
2236
2237 static int
2238 test_snow3g_encryption_test_case_3(void)
2239 {
2240         return test_snow3g_encryption(&snow3g_test_case_3);
2241 }
2242
2243 static int
2244 test_snow3g_encryption_test_case_4(void)
2245 {
2246         return test_snow3g_encryption(&snow3g_test_case_4);
2247 }
2248
2249 static int
2250 test_snow3g_encryption_test_case_5(void)
2251 {
2252         return test_snow3g_encryption(&snow3g_test_case_5);
2253 }
2254
2255 static int
2256 test_snow3g_decryption_test_case_1(void)
2257 {
2258         return test_snow3g_decryption(&snow3g_test_case_1);
2259 }
2260
2261 static int
2262 test_snow3g_decryption_test_case_1_oop(void)
2263 {
2264         return test_snow3g_decryption_oop(&snow3g_test_case_1);
2265 }
2266
2267 static int
2268 test_snow3g_decryption_test_case_2(void)
2269 {
2270         return test_snow3g_decryption(&snow3g_test_case_2);
2271 }
2272
2273 static int
2274 test_snow3g_decryption_test_case_3(void)
2275 {
2276         return test_snow3g_decryption(&snow3g_test_case_3);
2277 }
2278
2279 static int
2280 test_snow3g_decryption_test_case_4(void)
2281 {
2282         return test_snow3g_decryption(&snow3g_test_case_4);
2283 }
2284
2285 static int
2286 test_snow3g_decryption_test_case_5(void)
2287 {
2288         return test_snow3g_decryption(&snow3g_test_case_5);
2289 }
2290 static int
2291 test_snow3g_authenticated_encryption_test_case_1(void)
2292 {
2293         return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2294 }
2295
2296 static int
2297 test_snow3g_encrypted_authentication_test_case_1(void)
2298 {
2299         return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2300 }
2301
2302 /* ***** AES-GCM Tests ***** */
2303
2304 static int
2305 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2306                 const uint8_t *key, const uint8_t key_len,
2307                 const uint8_t aad_len, const uint8_t auth_len)
2308 {
2309         uint8_t cipher_key[key_len];
2310
2311         struct crypto_unittest_params *ut_params = &unittest_params;
2312
2313
2314         memcpy(cipher_key, key, key_len);
2315
2316         /* Setup Cipher Parameters */
2317         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2318         ut_params->cipher_xform.next = NULL;
2319
2320         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2321         ut_params->cipher_xform.cipher.op = op;
2322         ut_params->cipher_xform.cipher.key.data = cipher_key;
2323         ut_params->cipher_xform.cipher.key.length = key_len;
2324
2325 #ifdef RTE_APP_TEST_DEBUG
2326         rte_hexdump(stdout, "key:", key, key_len);
2327 #endif
2328         /* Setup Authentication Parameters */
2329         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2330         ut_params->auth_xform.next = NULL;
2331
2332         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2333
2334         ut_params->auth_xform.auth.digest_length = auth_len;
2335         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2336         ut_params->auth_xform.auth.key.length = 0;
2337         ut_params->auth_xform.auth.key.data = NULL;
2338
2339         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2340                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2341
2342                 /* Create Crypto session*/
2343                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2344                                 &ut_params->cipher_xform);
2345         } else {/* Create Crypto session*/
2346                 ut_params->auth_xform.next = &ut_params->cipher_xform;
2347                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2348                                 &ut_params->auth_xform);
2349         }
2350
2351         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2352
2353         return 0;
2354 }
2355
2356 static int
2357 create_gcm_operation(enum rte_crypto_cipher_operation op,
2358                 const uint8_t *auth_tag, const unsigned auth_tag_len,
2359                 const uint8_t *iv, const unsigned iv_len,
2360                 const uint8_t *aad, const unsigned aad_len,
2361                 const unsigned data_len, unsigned data_pad_len)
2362 {
2363         struct crypto_testsuite_params *ts_params = &testsuite_params;
2364         struct crypto_unittest_params *ut_params = &unittest_params;
2365
2366         unsigned iv_pad_len = 0, aad_buffer_len;
2367
2368         /* Generate Crypto op data structure */
2369         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2370                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2371         TEST_ASSERT_NOT_NULL(ut_params->op,
2372                         "Failed to allocate symmetric crypto operation struct");
2373
2374         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2375
2376
2377
2378         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2379                         ut_params->ibuf, auth_tag_len);
2380         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2381                         "no room to append digest");
2382         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2383                         ut_params->ibuf, data_pad_len);
2384         sym_op->auth.digest.length = auth_tag_len;
2385
2386         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2387                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2388 #ifdef RTE_APP_TEST_DEBUG
2389                 rte_hexdump(stdout, "digest:",
2390                                 sym_op->auth.digest.data,
2391                                 sym_op->auth.digest.length);
2392 #endif
2393         }
2394
2395         /* iv */
2396         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2397
2398         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2399                         ut_params->ibuf, iv_pad_len);
2400         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2401
2402         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2403         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2404         sym_op->cipher.iv.length = iv_pad_len;
2405
2406         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2407
2408         /* CalcY0 */
2409         if (iv_len != 16)
2410                 sym_op->cipher.iv.data[15] = 1;
2411
2412         /*
2413          * Always allocate the aad up to the block size.
2414          * The cryptodev API calls out -
2415          *  - the array must be big enough to hold the AAD, plus any
2416          *   space to round this up to the nearest multiple of the
2417          *   block size (16 bytes).
2418          */
2419         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2420
2421         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2422                         ut_params->ibuf, aad_buffer_len);
2423         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2424                         "no room to prepend aad");
2425         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2426                         ut_params->ibuf);
2427         sym_op->auth.aad.length = aad_len;
2428
2429         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2430         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2431
2432 #ifdef RTE_APP_TEST_DEBUG
2433         rte_hexdump(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
2434         rte_hexdump(stdout, "aad:",
2435                         sym_op->auth.aad.data, aad_len);
2436 #endif
2437         sym_op->cipher.data.length = data_len;
2438         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2439
2440         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2441         sym_op->auth.data.length = data_len;
2442
2443         return 0;
2444 }
2445
2446 static int
2447 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2448 {
2449         struct crypto_testsuite_params *ts_params = &testsuite_params;
2450         struct crypto_unittest_params *ut_params = &unittest_params;
2451
2452         int retval;
2453
2454         uint8_t *plaintext, *ciphertext, *auth_tag;
2455         uint16_t plaintext_pad_len;
2456
2457         /* Create GCM session */
2458         retval = create_gcm_session(ts_params->valid_devs[0],
2459                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2460                         tdata->key.data, tdata->key.len,
2461                         tdata->aad.len, tdata->auth_tag.len);
2462         if (retval < 0)
2463                 return retval;
2464
2465
2466         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2467
2468         /* clear mbuf payload */
2469         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2470                         rte_pktmbuf_tailroom(ut_params->ibuf));
2471
2472         /*
2473          * Append data which is padded to a multiple
2474          * of the algorithms block size
2475          */
2476         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2477
2478         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2479                         plaintext_pad_len);
2480         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2481
2482 #ifdef RTE_APP_TEST_DEBUG
2483         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2484 #endif
2485         /* Create GCM opertaion */
2486         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2487                         tdata->auth_tag.data, tdata->auth_tag.len,
2488                         tdata->iv.data, tdata->iv.len,
2489                         tdata->aad.data, tdata->aad.len,
2490                         tdata->plaintext.len, plaintext_pad_len);
2491         if (retval < 0)
2492                 return retval;
2493
2494         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2495
2496         ut_params->op->sym->m_src = ut_params->ibuf;
2497
2498         /* Process crypto operation */
2499         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2500                         ut_params->op), "failed to process sym crypto op");
2501
2502         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2503                         "crypto op processing failed");
2504
2505         if (ut_params->op->sym->m_dst) {
2506                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2507                                 uint8_t *);
2508                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
2509                                 uint8_t *, plaintext_pad_len);
2510         } else {
2511                 ciphertext = plaintext;
2512                 auth_tag = plaintext + plaintext_pad_len;
2513         }
2514
2515 #ifdef RTE_APP_TEST_DEBUG
2516         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2517         rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
2518 #endif
2519         /* Validate obuf */
2520         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2521                         ciphertext,
2522                         tdata->ciphertext.data,
2523                         tdata->ciphertext.len,
2524                         "GCM Ciphertext data not as expected");
2525
2526         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2527                         auth_tag,
2528                         tdata->auth_tag.data,
2529                         tdata->auth_tag.len,
2530                         "GCM Generated auth tag not as expected");
2531
2532         return 0;
2533
2534 }
2535
2536 static int
2537 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
2538 {
2539         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
2540 }
2541
2542 static int
2543 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
2544 {
2545         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
2546 }
2547
2548 static int
2549 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
2550 {
2551         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
2552 }
2553
2554 static int
2555 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
2556 {
2557         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
2558 }
2559
2560 static int
2561 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
2562 {
2563         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
2564 }
2565
2566 static int
2567 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
2568 {
2569         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
2570 }
2571
2572 static int
2573 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
2574 {
2575         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
2576 }
2577
2578 static int
2579 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
2580 {
2581         struct crypto_testsuite_params *ts_params = &testsuite_params;
2582         struct crypto_unittest_params *ut_params = &unittest_params;
2583
2584         int retval;
2585
2586         uint8_t *plaintext, *ciphertext;
2587         uint16_t ciphertext_pad_len;
2588
2589         /* Create GCM session */
2590         retval = create_gcm_session(ts_params->valid_devs[0],
2591                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2592                         tdata->key.data, tdata->key.len,
2593                         tdata->aad.len, tdata->auth_tag.len);
2594         if (retval < 0)
2595                 return retval;
2596
2597
2598         /* alloc mbuf and set payload */
2599         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2600
2601         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2602                         rte_pktmbuf_tailroom(ut_params->ibuf));
2603
2604         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2605
2606         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2607                         ciphertext_pad_len);
2608         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2609
2610 #ifdef RTE_APP_TEST_DEBUG
2611         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2612 #endif
2613         /* Create GCM opertaion */
2614         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
2615                         tdata->auth_tag.data, tdata->auth_tag.len,
2616                         tdata->iv.data, tdata->iv.len,
2617                         tdata->aad.data, tdata->aad.len,
2618                         tdata->ciphertext.len, ciphertext_pad_len);
2619         if (retval < 0)
2620                 return retval;
2621
2622
2623         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2624
2625         ut_params->op->sym->m_src = ut_params->ibuf;
2626
2627         /* Process crypto operation */
2628         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2629                         ut_params->op), "failed to process sym crypto op");
2630
2631         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2632                         "crypto op processing failed");
2633
2634         if (ut_params->op->sym->m_dst)
2635                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2636                                 uint8_t *);
2637         else
2638                 plaintext = ciphertext;
2639
2640 #ifdef RTE_APP_TEST_DEBUG
2641         rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
2642 #endif
2643         /* Validate obuf */
2644         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2645                         plaintext,
2646                         tdata->plaintext.data,
2647                         tdata->plaintext.len,
2648                         "GCM plaintext data not as expected");
2649
2650         TEST_ASSERT_EQUAL(ut_params->op->status,
2651                         RTE_CRYPTO_OP_STATUS_SUCCESS,
2652                         "GCM authentication failed");
2653         return 0;
2654 }
2655
2656 static int
2657 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
2658 {
2659         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
2660 }
2661
2662 static int
2663 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
2664 {
2665         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
2666 }
2667
2668 static int
2669 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
2670 {
2671         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
2672 }
2673
2674 static int
2675 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
2676 {
2677         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
2678 }
2679
2680 static int
2681 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
2682 {
2683         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
2684 }
2685
2686 static int
2687 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
2688 {
2689         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
2690 }
2691
2692 static int
2693 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
2694 {
2695         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
2696 }
2697
2698 static int
2699 test_stats(void)
2700 {
2701         struct crypto_testsuite_params *ts_params = &testsuite_params;
2702         struct rte_cryptodev_stats stats;
2703         struct rte_cryptodev *dev;
2704         cryptodev_stats_get_t temp_pfn;
2705
2706         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2707         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2708                         &stats) == -ENODEV),
2709                 "rte_cryptodev_stats_get invalid dev failed");
2710         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2711                 "rte_cryptodev_stats_get invalid Param failed");
2712         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2713         temp_pfn = dev->dev_ops->stats_get;
2714         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2715         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2716                         == -ENOTSUP),
2717                 "rte_cryptodev_stats_get invalid Param failed");
2718         dev->dev_ops->stats_get = temp_pfn;
2719
2720         /* Test expected values */
2721         ut_setup();
2722         test_AES_CBC_HMAC_SHA1_encrypt_digest();
2723         ut_teardown();
2724         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2725                         &stats),
2726                 "rte_cryptodev_stats_get failed");
2727         TEST_ASSERT((stats.enqueued_count == 1),
2728                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2729         TEST_ASSERT((stats.dequeued_count == 1),
2730                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2731         TEST_ASSERT((stats.enqueue_err_count == 0),
2732                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2733         TEST_ASSERT((stats.dequeue_err_count == 0),
2734                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2735
2736         /* invalid device but should ignore and not reset device stats*/
2737         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2738         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2739                         &stats),
2740                 "rte_cryptodev_stats_get failed");
2741         TEST_ASSERT((stats.enqueued_count == 1),
2742                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2743
2744         /* check that a valid reset clears stats */
2745         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2746         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2747                         &stats),
2748                                           "rte_cryptodev_stats_get failed");
2749         TEST_ASSERT((stats.enqueued_count == 0),
2750                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2751         TEST_ASSERT((stats.dequeued_count == 0),
2752                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2753
2754         return TEST_SUCCESS;
2755 }
2756
2757
2758 static int
2759 test_multi_session(void)
2760 {
2761         struct crypto_testsuite_params *ts_params = &testsuite_params;
2762         struct crypto_unittest_params *ut_params = &unittest_params;
2763
2764         struct rte_cryptodev_info dev_info;
2765         struct rte_cryptodev_sym_session **sessions;
2766
2767         uint16_t i;
2768
2769         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2770
2771
2772         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2773
2774         sessions = rte_malloc(NULL,
2775                         (sizeof(struct rte_cryptodev_sym_session *) *
2776                         dev_info.sym.max_nb_sessions) + 1, 0);
2777
2778         /* Create multiple crypto sessions*/
2779         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2780                 sessions[i] = rte_cryptodev_sym_session_create(
2781                                 ts_params->valid_devs[0],
2782                         &ut_params->auth_xform);
2783                 TEST_ASSERT_NOT_NULL(sessions[i],
2784                                 "Session creation failed at session number %u",
2785                                 i);
2786
2787                 /* Attempt to send a request on each session */
2788                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2789                                 sessions[i], ut_params, ts_params),
2790                                 "Failed to perform decrypt on request "
2791                                 "number %u.", i);
2792                 /* free crypto operation structure */
2793                 if (ut_params->op)
2794                         rte_crypto_op_free(ut_params->op);
2795
2796                 /*
2797                  * free mbuf - both obuf and ibuf are usually the same,
2798                  * but rte copes even if we call free twice
2799                  */
2800                 if (ut_params->obuf) {
2801                         rte_pktmbuf_free(ut_params->obuf);
2802                         ut_params->obuf = 0;
2803                 }
2804         }
2805
2806         /* Next session create should fail */
2807         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2808                         &ut_params->auth_xform);
2809         TEST_ASSERT_NULL(sessions[i],
2810                         "Session creation succeeded unexpectedly!");
2811
2812         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2813                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2814                                 sessions[i]);
2815
2816         rte_free(sessions);
2817
2818         return TEST_SUCCESS;
2819 }
2820
2821 static int
2822 test_null_cipher_only_operation(void)
2823 {
2824         struct crypto_testsuite_params *ts_params = &testsuite_params;
2825         struct crypto_unittest_params *ut_params = &unittest_params;
2826
2827         /* Generate test mbuf data and space for digest */
2828         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2829                         catch_22_quote, QUOTE_512_BYTES, 0);
2830
2831         /* Setup Cipher Parameters */
2832         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2833         ut_params->cipher_xform.next = NULL;
2834
2835         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2836         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2837
2838         /* Create Crypto session*/
2839         ut_params->sess = rte_cryptodev_sym_session_create(
2840                         ts_params->valid_devs[0], &ut_params->cipher_xform);
2841         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2842
2843         /* Generate Crypto op data structure */
2844         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2845                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2846         TEST_ASSERT_NOT_NULL(ut_params->op,
2847                         "Failed to allocate symmetric crypto operation struct");
2848
2849         /* Set crypto operation data parameters */
2850         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2851
2852         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2853
2854         /* set crypto operation source mbuf */
2855         sym_op->m_src = ut_params->ibuf;
2856
2857         sym_op->cipher.data.offset = 0;
2858         sym_op->cipher.data.length = QUOTE_512_BYTES;
2859
2860         /* Process crypto operation */
2861         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2862                         ut_params->op);
2863         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2864
2865         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2866                         "crypto operation processing failed");
2867
2868         /* Validate obuf */
2869         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2870                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2871                         catch_22_quote,
2872                         QUOTE_512_BYTES,
2873                         "Ciphertext data not as expected");
2874
2875         return TEST_SUCCESS;
2876 }
2877
2878 static int
2879 test_null_auth_only_operation(void)
2880 {
2881         struct crypto_testsuite_params *ts_params = &testsuite_params;
2882         struct crypto_unittest_params *ut_params = &unittest_params;
2883
2884         /* Generate test mbuf data and space for digest */
2885         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2886                         catch_22_quote, QUOTE_512_BYTES, 0);
2887
2888         /* Setup HMAC Parameters */
2889         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2890         ut_params->auth_xform.next = NULL;
2891
2892         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2893         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2894
2895         /* Create Crypto session*/
2896         ut_params->sess = rte_cryptodev_sym_session_create(
2897                         ts_params->valid_devs[0], &ut_params->auth_xform);
2898         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2899
2900         /* Generate Crypto op data structure */
2901         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2902                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2903         TEST_ASSERT_NOT_NULL(ut_params->op,
2904                         "Failed to allocate symmetric crypto operation struct");
2905
2906         /* Set crypto operation data parameters */
2907         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2908
2909         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2910
2911         sym_op->m_src = ut_params->ibuf;
2912
2913         sym_op->auth.data.offset = 0;
2914         sym_op->auth.data.length = QUOTE_512_BYTES;
2915
2916         /* Process crypto operation */
2917         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2918                         ut_params->op);
2919         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2920
2921         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2922                         "crypto operation processing failed");
2923
2924         return TEST_SUCCESS;
2925 }
2926
2927 static int
2928 test_null_cipher_auth_operation(void)
2929 {
2930         struct crypto_testsuite_params *ts_params = &testsuite_params;
2931         struct crypto_unittest_params *ut_params = &unittest_params;
2932
2933         /* Generate test mbuf data and space for digest */
2934         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2935                         catch_22_quote, QUOTE_512_BYTES, 0);
2936
2937         /* Setup Cipher Parameters */
2938         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2939         ut_params->cipher_xform.next = &ut_params->auth_xform;
2940
2941         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2942         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2943
2944         /* Setup HMAC Parameters */
2945         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2946         ut_params->auth_xform.next = NULL;
2947
2948         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2949         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2950
2951         /* Create Crypto session*/
2952         ut_params->sess = rte_cryptodev_sym_session_create(
2953                         ts_params->valid_devs[0], &ut_params->cipher_xform);
2954         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2955
2956         /* Generate Crypto op data structure */
2957         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2958                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2959         TEST_ASSERT_NOT_NULL(ut_params->op,
2960                         "Failed to allocate symmetric crypto operation struct");
2961
2962         /* Set crypto operation data parameters */
2963         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2964
2965         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2966
2967         sym_op->m_src = ut_params->ibuf;
2968
2969         sym_op->cipher.data.offset = 0;
2970         sym_op->cipher.data.length = QUOTE_512_BYTES;
2971
2972         sym_op->auth.data.offset = 0;
2973         sym_op->auth.data.length = QUOTE_512_BYTES;
2974
2975         /* Process crypto operation */
2976         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2977                         ut_params->op);
2978         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2979
2980         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2981                         "crypto operation processing failed");
2982
2983         /* Validate obuf */
2984         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2985                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2986                         catch_22_quote,
2987                         QUOTE_512_BYTES,
2988                         "Ciphertext data not as expected");
2989
2990         return TEST_SUCCESS;
2991 }
2992
2993 static int
2994 test_null_auth_cipher_operation(void)
2995 {
2996         struct crypto_testsuite_params *ts_params = &testsuite_params;
2997         struct crypto_unittest_params *ut_params = &unittest_params;
2998
2999         /* Generate test mbuf data and space for digest */
3000         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3001                         catch_22_quote, QUOTE_512_BYTES, 0);
3002
3003         /* Setup Cipher Parameters */
3004         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3005         ut_params->cipher_xform.next = NULL;
3006
3007         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3008         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3009
3010         /* Setup HMAC Parameters */
3011         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3012         ut_params->auth_xform.next = &ut_params->cipher_xform;
3013
3014         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3015         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3016
3017         /* Create Crypto session*/
3018         ut_params->sess = rte_cryptodev_sym_session_create(
3019                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3020         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3021
3022         /* Generate Crypto op data structure */
3023         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3024                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3025         TEST_ASSERT_NOT_NULL(ut_params->op,
3026                         "Failed to allocate symmetric crypto operation struct");
3027
3028         /* Set crypto operation data parameters */
3029         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3030
3031         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3032
3033         sym_op->m_src = ut_params->ibuf;
3034
3035         sym_op->cipher.data.offset = 0;
3036         sym_op->cipher.data.length = QUOTE_512_BYTES;
3037
3038         sym_op->auth.data.offset = 0;
3039         sym_op->auth.data.length = QUOTE_512_BYTES;
3040
3041         /* Process crypto operation */
3042         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3043                         ut_params->op);
3044         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3045
3046         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3047                         "crypto operation processing failed");
3048
3049         /* Validate obuf */
3050         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3051                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3052                         catch_22_quote,
3053                         QUOTE_512_BYTES,
3054                         "Ciphertext data not as expected");
3055
3056         return TEST_SUCCESS;
3057 }
3058
3059
3060 static int
3061 test_null_invalid_operation(void)
3062 {
3063         struct crypto_testsuite_params *ts_params = &testsuite_params;
3064         struct crypto_unittest_params *ut_params = &unittest_params;
3065
3066         /* Setup Cipher Parameters */
3067         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3068         ut_params->cipher_xform.next = NULL;
3069
3070         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3071         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3072
3073         /* Create Crypto session*/
3074         ut_params->sess = rte_cryptodev_sym_session_create(
3075                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3076         TEST_ASSERT_NULL(ut_params->sess,
3077                         "Session creation succeeded unexpectedly");
3078
3079
3080         /* Setup HMAC Parameters */
3081         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3082         ut_params->auth_xform.next = NULL;
3083
3084         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3085         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3086
3087         /* Create Crypto session*/
3088         ut_params->sess = rte_cryptodev_sym_session_create(
3089                         ts_params->valid_devs[0], &ut_params->auth_xform);
3090         TEST_ASSERT_NULL(ut_params->sess,
3091                         "Session creation succeeded unexpectedly");
3092
3093         return TEST_SUCCESS;
3094 }
3095
3096
3097 #define NULL_BURST_LENGTH (32)
3098
3099 static int
3100 test_null_burst_operation(void)
3101 {
3102         struct crypto_testsuite_params *ts_params = &testsuite_params;
3103         struct crypto_unittest_params *ut_params = &unittest_params;
3104
3105         unsigned i, burst_len = NULL_BURST_LENGTH;
3106
3107         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3108         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3109
3110         /* Setup Cipher Parameters */
3111         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3112         ut_params->cipher_xform.next = &ut_params->auth_xform;
3113
3114         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3115         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3116
3117         /* Setup HMAC Parameters */
3118         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3119         ut_params->auth_xform.next = NULL;
3120
3121         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3122         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3123
3124         /* Create Crypto session*/
3125         ut_params->sess = rte_cryptodev_sym_session_create(
3126                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3127         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3128
3129         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3130                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3131                         burst_len, "failed to generate burst of crypto ops");
3132
3133         /* Generate an operation for each mbuf in burst */
3134         for (i = 0; i < burst_len; i++) {
3135                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3136
3137                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3138
3139                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3140                                 sizeof(unsigned));
3141                 *data = i;
3142
3143                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3144
3145                 burst[i]->sym->m_src = m;
3146         }
3147
3148         /* Process crypto operation */
3149         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3150                         0, burst, burst_len),
3151                         burst_len,
3152                         "Error enqueuing burst");
3153
3154         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3155                         0, burst_dequeued, burst_len),
3156                         burst_len,
3157                         "Error dequeuing burst");
3158
3159
3160         for (i = 0; i < burst_len; i++) {
3161                 TEST_ASSERT_EQUAL(
3162                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3163                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3164                                         uint32_t *),
3165                         "data not as expected");
3166
3167                 rte_pktmbuf_free(burst[i]->sym->m_src);
3168                 rte_crypto_op_free(burst[i]);
3169         }
3170
3171         return TEST_SUCCESS;
3172 }
3173
3174
3175
3176
3177 static struct unit_test_suite cryptodev_qat_testsuite  = {
3178         .suite_name = "Crypto QAT Unit Test Suite",
3179         .setup = testsuite_setup,
3180         .teardown = testsuite_teardown,
3181         .unit_test_cases = {
3182                 TEST_CASE_ST(ut_setup, ut_teardown,
3183                                 test_device_configure_invalid_dev_id),
3184                 TEST_CASE_ST(ut_setup, ut_teardown,
3185                                 test_device_configure_invalid_queue_pair_ids),
3186                 TEST_CASE_ST(ut_setup, ut_teardown,
3187                                 test_queue_pair_descriptor_setup),
3188                 TEST_CASE_ST(ut_setup, ut_teardown,
3189                                 test_multi_session),
3190
3191                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3192                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3193
3194                 /** AES GCM Authenticated Encryption */
3195                 TEST_CASE_ST(ut_setup, ut_teardown,
3196                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3197                 TEST_CASE_ST(ut_setup, ut_teardown,
3198                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3199                 TEST_CASE_ST(ut_setup, ut_teardown,
3200                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3201                 TEST_CASE_ST(ut_setup, ut_teardown,
3202                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3203                 TEST_CASE_ST(ut_setup, ut_teardown,
3204                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3205                 TEST_CASE_ST(ut_setup, ut_teardown,
3206                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3207                 TEST_CASE_ST(ut_setup, ut_teardown,
3208                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3209
3210                 /** AES GCM Authenticated Decryption */
3211                 TEST_CASE_ST(ut_setup, ut_teardown,
3212                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3213                 TEST_CASE_ST(ut_setup, ut_teardown,
3214                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3215                 TEST_CASE_ST(ut_setup, ut_teardown,
3216                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3217                 TEST_CASE_ST(ut_setup, ut_teardown,
3218                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3219                 TEST_CASE_ST(ut_setup, ut_teardown,
3220                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3221                 TEST_CASE_ST(ut_setup, ut_teardown,
3222                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3223                 TEST_CASE_ST(ut_setup, ut_teardown,
3224                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3225
3226                 /** Snow3G encrypt only (UEA2) */
3227                 TEST_CASE_ST(ut_setup, ut_teardown,
3228                         test_snow3g_encryption_test_case_1),
3229                 TEST_CASE_ST(ut_setup, ut_teardown,
3230                         test_snow3g_encryption_test_case_2),
3231                 TEST_CASE_ST(ut_setup, ut_teardown,
3232                         test_snow3g_encryption_test_case_3),
3233                 TEST_CASE_ST(ut_setup, ut_teardown,
3234                         test_snow3g_encryption_test_case_4),
3235                 TEST_CASE_ST(ut_setup, ut_teardown,
3236                         test_snow3g_encryption_test_case_5),
3237
3238                 TEST_CASE_ST(ut_setup, ut_teardown,
3239                         test_snow3g_encryption_test_case_1_oop),
3240                 TEST_CASE_ST(ut_setup, ut_teardown,
3241                         test_snow3g_decryption_test_case_1_oop),
3242
3243                 /** Snow3G decrypt only (UEA2) */
3244                 TEST_CASE_ST(ut_setup, ut_teardown,
3245                         test_snow3g_decryption_test_case_1),
3246                 TEST_CASE_ST(ut_setup, ut_teardown,
3247                         test_snow3g_decryption_test_case_2),
3248                 TEST_CASE_ST(ut_setup, ut_teardown,
3249                         test_snow3g_decryption_test_case_3),
3250                 TEST_CASE_ST(ut_setup, ut_teardown,
3251                         test_snow3g_decryption_test_case_4),
3252                 TEST_CASE_ST(ut_setup, ut_teardown,
3253                         test_snow3g_decryption_test_case_5),
3254                 TEST_CASE_ST(ut_setup, ut_teardown,
3255                         test_snow3g_hash_generate_test_case_1),
3256                 TEST_CASE_ST(ut_setup, ut_teardown,
3257                         test_snow3g_hash_generate_test_case_2),
3258                 TEST_CASE_ST(ut_setup, ut_teardown,
3259                         test_snow3g_hash_generate_test_case_3),
3260                 TEST_CASE_ST(ut_setup, ut_teardown,
3261                         test_snow3g_hash_verify_test_case_1),
3262                 TEST_CASE_ST(ut_setup, ut_teardown,
3263                         test_snow3g_hash_verify_test_case_2),
3264                 TEST_CASE_ST(ut_setup, ut_teardown,
3265                         test_snow3g_hash_verify_test_case_3),
3266                 TEST_CASE_ST(ut_setup, ut_teardown,
3267                         test_snow3g_authenticated_encryption_test_case_1),
3268                 TEST_CASE_ST(ut_setup, ut_teardown,
3269                         test_snow3g_encrypted_authentication_test_case_1),
3270                 TEST_CASES_END() /**< NULL terminate unit test array */
3271         }
3272 };
3273
3274 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
3275         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3276         .setup = testsuite_setup,
3277         .teardown = testsuite_teardown,
3278         .unit_test_cases = {
3279                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3280
3281                 TEST_CASES_END() /**< NULL terminate unit test array */
3282         }
3283 };
3284
3285 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
3286         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3287         .setup = testsuite_setup,
3288         .teardown = testsuite_teardown,
3289         .unit_test_cases = {
3290                 /** AES GCM Authenticated Encryption */
3291                 TEST_CASE_ST(ut_setup, ut_teardown,
3292                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3293                 TEST_CASE_ST(ut_setup, ut_teardown,
3294                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3295                 TEST_CASE_ST(ut_setup, ut_teardown,
3296                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3297                 TEST_CASE_ST(ut_setup, ut_teardown,
3298                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3299                 TEST_CASE_ST(ut_setup, ut_teardown,
3300                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3301                 TEST_CASE_ST(ut_setup, ut_teardown,
3302                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3303                 TEST_CASE_ST(ut_setup, ut_teardown,
3304                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3305
3306                 /** AES GCM Authenticated Decryption */
3307                 TEST_CASE_ST(ut_setup, ut_teardown,
3308                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3309                 TEST_CASE_ST(ut_setup, ut_teardown,
3310                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3311                 TEST_CASE_ST(ut_setup, ut_teardown,
3312                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3313                 TEST_CASE_ST(ut_setup, ut_teardown,
3314                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3315                 TEST_CASE_ST(ut_setup, ut_teardown,
3316                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3317                 TEST_CASE_ST(ut_setup, ut_teardown,
3318                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3319                 TEST_CASE_ST(ut_setup, ut_teardown,
3320                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3321
3322                 TEST_CASES_END() /**< NULL terminate unit test array */
3323         }
3324 };
3325
3326 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
3327         .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3328         .setup = testsuite_setup,
3329         .teardown = testsuite_teardown,
3330         .unit_test_cases = {
3331                 /** Snow3G encrypt only (UEA2) */
3332                 TEST_CASE_ST(ut_setup, ut_teardown,
3333                         test_snow3g_encryption_test_case_1),
3334                 TEST_CASE_ST(ut_setup, ut_teardown,
3335                         test_snow3g_encryption_test_case_2),
3336                 TEST_CASE_ST(ut_setup, ut_teardown,
3337                         test_snow3g_encryption_test_case_3),
3338                 TEST_CASE_ST(ut_setup, ut_teardown,
3339                         test_snow3g_encryption_test_case_4),
3340                 TEST_CASE_ST(ut_setup, ut_teardown,
3341                         test_snow3g_encryption_test_case_5),
3342
3343
3344                 /** Snow3G decrypt only (UEA2) */
3345                 TEST_CASE_ST(ut_setup, ut_teardown,
3346                         test_snow3g_decryption_test_case_1),
3347                 TEST_CASE_ST(ut_setup, ut_teardown,
3348                         test_snow3g_decryption_test_case_2),
3349                 TEST_CASE_ST(ut_setup, ut_teardown,
3350                         test_snow3g_decryption_test_case_3),
3351                 TEST_CASE_ST(ut_setup, ut_teardown,
3352                         test_snow3g_decryption_test_case_4),
3353                 TEST_CASE_ST(ut_setup, ut_teardown,
3354                         test_snow3g_decryption_test_case_5),
3355                 TEST_CASE_ST(ut_setup, ut_teardown,
3356                         test_snow3g_hash_generate_test_case_1),
3357                 TEST_CASE_ST(ut_setup, ut_teardown,
3358                         test_snow3g_hash_generate_test_case_2),
3359                 TEST_CASE_ST(ut_setup, ut_teardown,
3360                         test_snow3g_hash_generate_test_case_3),
3361                 TEST_CASE_ST(ut_setup, ut_teardown,
3362                         test_snow3g_hash_verify_test_case_1),
3363                 TEST_CASE_ST(ut_setup, ut_teardown,
3364                         test_snow3g_hash_verify_test_case_2),
3365                 TEST_CASE_ST(ut_setup, ut_teardown,
3366                         test_snow3g_hash_verify_test_case_3),
3367                 TEST_CASE_ST(ut_setup, ut_teardown,
3368                         test_snow3g_authenticated_encryption_test_case_1),
3369                 TEST_CASE_ST(ut_setup, ut_teardown,
3370                         test_snow3g_encrypted_authentication_test_case_1),
3371
3372                 TEST_CASES_END() /**< NULL terminate unit test array */
3373         }
3374 };
3375
3376 static struct unit_test_suite cryptodev_null_testsuite  = {
3377         .suite_name = "Crypto Device NULL Unit Test Suite",
3378         .setup = testsuite_setup,
3379         .teardown = testsuite_teardown,
3380         .unit_test_cases = {
3381                 TEST_CASE_ST(ut_setup, ut_teardown,
3382                         test_null_auth_only_operation),
3383                 TEST_CASE_ST(ut_setup, ut_teardown,
3384                         test_null_cipher_only_operation),
3385                 TEST_CASE_ST(ut_setup, ut_teardown,
3386                         test_null_cipher_auth_operation),
3387                 TEST_CASE_ST(ut_setup, ut_teardown,
3388                         test_null_auth_cipher_operation),
3389                 TEST_CASE_ST(ut_setup, ut_teardown,
3390                         test_null_invalid_operation),
3391                 TEST_CASE_ST(ut_setup, ut_teardown,
3392                         test_null_burst_operation),
3393
3394                 TEST_CASES_END() /**< NULL terminate unit test array */
3395         }
3396 };
3397
3398 static int
3399 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3400 {
3401         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3402         return unit_test_suite_runner(&cryptodev_qat_testsuite);
3403 }
3404 static struct test_command cryptodev_qat_cmd = {
3405         .command = "cryptodev_qat_autotest",
3406         .callback = test_cryptodev_qat,
3407 };
3408
3409 static int
3410 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3411 {
3412         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3413
3414         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3415 }
3416
3417 static struct test_command cryptodev_aesni_mb_cmd = {
3418         .command = "cryptodev_aesni_mb_autotest",
3419         .callback = test_cryptodev_aesni_mb,
3420 };
3421
3422 static int
3423 test_cryptodev_aesni_gcm(void)
3424 {
3425         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3426
3427         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3428 }
3429
3430 static struct test_command cryptodev_aesni_gcm_cmd = {
3431         .command = "cryptodev_aesni_gcm_autotest",
3432         .callback = test_cryptodev_aesni_gcm,
3433 };
3434
3435 static int
3436 test_cryptodev_null(void)
3437 {
3438         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
3439
3440         return unit_test_suite_runner(&cryptodev_null_testsuite);
3441 }
3442
3443 static struct test_command cryptodev_null_cmd = {
3444         .command = "cryptodev_null_autotest",
3445         .callback = test_cryptodev_null,
3446 };
3447
3448 static int
3449 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3450 {
3451         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3452
3453         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3454 }
3455
3456 static struct test_command cryptodev_sw_snow3g_cmd = {
3457         .command = "cryptodev_sw_snow3g_autotest",
3458         .callback = test_cryptodev_sw_snow3g,
3459 };
3460
3461 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3462 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3463 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3464 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
3465 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);