app/test: use hexdump if debug log is enabled
[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
1079         TEST_HEXDUMP(stdout, "key:", key, key_len);
1080
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         TEST_HEXDUMP(stdout, "key:", key, key_len);
1117
1118         /* Create Crypto session */
1119         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1120                                                 &ut_params->
1121                                                 cipher_xform);
1122         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1123         return 0;
1124 }
1125
1126 static int
1127 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1128                         const unsigned cipher_len,
1129                         const unsigned cipher_offset)
1130 {
1131         struct crypto_testsuite_params *ts_params = &testsuite_params;
1132         struct crypto_unittest_params *ut_params = &unittest_params;
1133         unsigned iv_pad_len = 0;
1134
1135         /* Generate Crypto op data structure */
1136         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1137                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1138         TEST_ASSERT_NOT_NULL(ut_params->op,
1139                                 "Failed to allocate pktmbuf offload");
1140
1141         /* Set crypto operation data parameters */
1142         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1143
1144         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1145
1146         /* set crypto operation source mbuf */
1147         sym_op->m_src = ut_params->ibuf;
1148
1149         /* iv */
1150         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1151         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1152                         , iv_pad_len);
1153
1154         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1155
1156         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1157         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1158         sym_op->cipher.iv.length = iv_pad_len;
1159
1160         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1161         sym_op->cipher.data.length = cipher_len;
1162         sym_op->cipher.data.offset = cipher_offset;
1163         return 0;
1164 }
1165
1166 static int
1167 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1168                         const unsigned cipher_len,
1169                         const unsigned cipher_offset)
1170 {
1171         struct crypto_testsuite_params *ts_params = &testsuite_params;
1172         struct crypto_unittest_params *ut_params = &unittest_params;
1173         unsigned iv_pad_len = 0;
1174
1175         /* Generate Crypto op data structure */
1176         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1177                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1178         TEST_ASSERT_NOT_NULL(ut_params->op,
1179                                 "Failed to allocate pktmbuf offload");
1180
1181         /* Set crypto operation data parameters */
1182         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1183
1184         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1185
1186         /* set crypto operation source mbuf */
1187         sym_op->m_src = ut_params->ibuf;
1188         sym_op->m_dst = ut_params->obuf;
1189
1190         /* iv */
1191         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1192         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1193                         , iv_pad_len);
1194
1195         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1196
1197         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1198         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1199         sym_op->cipher.iv.length = iv_pad_len;
1200
1201         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1202         sym_op->cipher.data.length = cipher_len;
1203         sym_op->cipher.data.offset = cipher_offset;
1204         return 0;
1205 }
1206
1207 static int
1208 create_snow3g_cipher_auth_session(uint8_t dev_id,
1209                 enum rte_crypto_cipher_operation cipher_op,
1210                 enum rte_crypto_auth_operation auth_op,
1211                 const uint8_t *key, const uint8_t key_len,
1212                 const uint8_t aad_len, const uint8_t auth_len)
1213 {
1214         uint8_t cipher_auth_key[key_len];
1215
1216         struct crypto_unittest_params *ut_params = &unittest_params;
1217
1218         memcpy(cipher_auth_key, key, key_len);
1219
1220         /* Setup Authentication Parameters */
1221         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1222         ut_params->auth_xform.next = NULL;
1223
1224         ut_params->auth_xform.auth.op = auth_op;
1225         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1226         ut_params->auth_xform.auth.key.length = key_len;
1227         /* Hash key = cipher key */
1228         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1229         ut_params->auth_xform.auth.digest_length = auth_len;
1230         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1231
1232         /* Setup Cipher Parameters */
1233         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1234         ut_params->cipher_xform.next = &ut_params->auth_xform;
1235
1236         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1237         ut_params->cipher_xform.cipher.op = cipher_op;
1238         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1239         ut_params->cipher_xform.cipher.key.length = key_len;
1240
1241         TEST_HEXDUMP(stdout, "key:", key, key_len);
1242
1243         /* Create Crypto session*/
1244         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1245                                 &ut_params->cipher_xform);
1246
1247         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1248         return 0;
1249 }
1250
1251 static int
1252 create_snow3g_auth_cipher_session(uint8_t dev_id,
1253                 enum rte_crypto_cipher_operation cipher_op,
1254                 enum rte_crypto_auth_operation auth_op,
1255                 const uint8_t *key, const uint8_t key_len,
1256                 const uint8_t aad_len, const uint8_t auth_len)
1257         {
1258         uint8_t auth_cipher_key[key_len];
1259
1260         struct crypto_unittest_params *ut_params = &unittest_params;
1261
1262         memcpy(auth_cipher_key, key, key_len);
1263
1264         /* Setup Authentication Parameters */
1265         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1266         ut_params->auth_xform.auth.op = auth_op;
1267         ut_params->auth_xform.next = &ut_params->cipher_xform;
1268         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1269         ut_params->auth_xform.auth.key.length = key_len;
1270         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1271         ut_params->auth_xform.auth.digest_length = auth_len;
1272         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1273
1274         /* Setup Cipher Parameters */
1275         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1276         ut_params->cipher_xform.next = NULL;
1277         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1278         ut_params->cipher_xform.cipher.op = cipher_op;
1279         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1280         ut_params->cipher_xform.cipher.key.length = key_len;
1281
1282         TEST_HEXDUMP(stdout, "key:", key, key_len);
1283
1284         /* Create Crypto session*/
1285         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1286                                 &ut_params->auth_xform);
1287
1288         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1289
1290         return 0;
1291 }
1292
1293 static int
1294 create_snow3g_hash_operation(const uint8_t *auth_tag,
1295                 const unsigned auth_tag_len,
1296                 const uint8_t *aad, const unsigned aad_len,
1297                 unsigned data_pad_len,
1298                 enum rte_crypto_auth_operation op,
1299                 const unsigned auth_len, const unsigned auth_offset)
1300 {
1301         struct crypto_testsuite_params *ts_params = &testsuite_params;
1302
1303         struct crypto_unittest_params *ut_params = &unittest_params;
1304
1305         unsigned aad_buffer_len;
1306
1307         /* Generate Crypto op data structure */
1308         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1309                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1310         TEST_ASSERT_NOT_NULL(ut_params->op,
1311                 "Failed to allocate pktmbuf offload");
1312
1313         /* Set crypto operation data parameters */
1314         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1315
1316         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1317
1318         /* set crypto operation source mbuf */
1319         sym_op->m_src = ut_params->ibuf;
1320
1321         /* aad */
1322         /*
1323         * Always allocate the aad up to the block size.
1324         * The cryptodev API calls out -
1325         *  - the array must be big enough to hold the AAD, plus any
1326         *   space to round this up to the nearest multiple of the
1327         *   block size (16 bytes).
1328         */
1329         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1330         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1331                         ut_params->ibuf, aad_buffer_len);
1332         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1333                                         "no room to prepend aad");
1334         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1335                         ut_params->ibuf);
1336         sym_op->auth.aad.length = aad_len;
1337
1338         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1339         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1340
1341         TEST_HEXDUMP(stdout, "aad:",
1342                         sym_op->auth.aad.data, aad_len);
1343
1344         /* digest */
1345         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1346                                         ut_params->ibuf, auth_tag_len);
1347
1348         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1349                                 "no room to append auth tag");
1350         ut_params->digest = sym_op->auth.digest.data;
1351         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1352                         ut_params->ibuf, data_pad_len + aad_len);
1353         sym_op->auth.digest.length = auth_tag_len;
1354         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1355                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1356         else
1357                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1358
1359         TEST_HEXDUMP(stdout, "digest:",
1360                 sym_op->auth.digest.data,
1361                 sym_op->auth.digest.length);
1362
1363         sym_op->auth.data.length = auth_len;
1364         sym_op->auth.data.offset = auth_offset;
1365
1366         return 0;
1367 }
1368
1369 static int
1370 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1371                 const unsigned auth_tag_len,
1372                 const uint8_t *aad, const uint8_t aad_len,
1373                 unsigned data_pad_len,
1374                 enum rte_crypto_auth_operation op,
1375                 const uint8_t *iv, const uint8_t iv_len,
1376                 const unsigned cipher_len, const unsigned cipher_offset,
1377                 const unsigned auth_len, const unsigned auth_offset)
1378 {
1379         struct crypto_testsuite_params *ts_params = &testsuite_params;
1380         struct crypto_unittest_params *ut_params = &unittest_params;
1381
1382         unsigned iv_pad_len = 0;
1383         unsigned aad_buffer_len;
1384
1385         /* Generate Crypto op data structure */
1386         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1387                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1388         TEST_ASSERT_NOT_NULL(ut_params->op,
1389                         "Failed to allocate pktmbuf offload");
1390         /* Set crypto operation data parameters */
1391         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1392
1393         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1394
1395         /* set crypto operation source mbuf */
1396         sym_op->m_src = ut_params->ibuf;
1397
1398
1399         /* iv */
1400         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1401
1402         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1403                 ut_params->ibuf, iv_pad_len);
1404         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1405
1406         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1407         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1408         sym_op->cipher.iv.length = iv_pad_len;
1409
1410         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1411
1412         sym_op->cipher.data.length = cipher_len;
1413         sym_op->cipher.data.offset = cipher_offset;
1414
1415         /* aad */
1416         /*
1417         * Always allocate the aad up to the block size.
1418         * The cryptodev API calls out -
1419         *  - the array must be big enough to hold the AAD, plus any
1420         *   space to round this up to the nearest multiple of the
1421         *   block size (16 bytes).
1422         */
1423         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1424
1425         sym_op->auth.aad.data =
1426                         (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1427         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1428                         "no room to prepend aad");
1429         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1430                         ut_params->ibuf);
1431         sym_op->auth.aad.length = aad_len;
1432
1433         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1434         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1435
1436         TEST_HEXDUMP(stdout, "aad:",
1437                         sym_op->auth.aad.data, aad_len);
1438
1439         /* digest */
1440         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1441                         ut_params->ibuf, auth_tag_len);
1442
1443         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1444                         "no room to append auth tag");
1445         ut_params->digest = sym_op->auth.digest.data;
1446         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1447                         ut_params->ibuf, data_pad_len + aad_len);
1448         sym_op->auth.digest.length = auth_tag_len;
1449         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1450                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1451         else
1452                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1453
1454         TEST_HEXDUMP(stdout, "digest:",
1455                 sym_op->auth.digest.data,
1456                 sym_op->auth.digest.length);
1457
1458         sym_op->auth.data.length = auth_len;
1459         sym_op->auth.data.offset = auth_offset;
1460
1461         return 0;
1462 }
1463
1464 static int
1465 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1466                 const uint8_t *iv, const uint8_t iv_len,
1467                 const uint8_t *aad, const uint8_t aad_len,
1468                 unsigned data_pad_len,
1469                 const unsigned cipher_len, const unsigned cipher_offset,
1470                 const unsigned auth_len, const unsigned auth_offset)
1471 {
1472         struct crypto_testsuite_params *ts_params = &testsuite_params;
1473         struct crypto_unittest_params *ut_params = &unittest_params;
1474
1475         unsigned iv_pad_len = 0;
1476         unsigned aad_buffer_len = 0;
1477
1478         /* Generate Crypto op data structure */
1479         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1480                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1481         TEST_ASSERT_NOT_NULL(ut_params->op,
1482                         "Failed to allocate pktmbuf offload");
1483
1484         /* Set crypto operation data parameters */
1485         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1486
1487         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1488
1489         /* set crypto operation source mbuf */
1490         sym_op->m_src = ut_params->ibuf;
1491
1492         /* digest */
1493         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1494                         ut_params->ibuf, auth_tag_len);
1495
1496         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1497                         "no room to append auth tag");
1498
1499         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1500                         ut_params->ibuf, data_pad_len);
1501         sym_op->auth.digest.length = auth_tag_len;
1502
1503         memset(sym_op->auth.digest.data, 0, auth_tag_len);
1504
1505         TEST_HEXDUMP(stdout, "digest:",
1506                         sym_op->auth.digest.data,
1507                         sym_op->auth.digest.length);
1508
1509         /* iv */
1510         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1511
1512         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1513                 ut_params->ibuf, iv_pad_len);
1514         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1515
1516         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1517         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1518         sym_op->cipher.iv.length = iv_pad_len;
1519
1520         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1521
1522         /* aad */
1523         /*
1524         * Always allocate the aad up to the block size.
1525         * The cryptodev API calls out -
1526         *  - the array must be big enough to hold the AAD, plus any
1527         *   space to round this up to the nearest multiple of the
1528         *   block size (16 bytes).
1529         */
1530         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1531
1532         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1533         ut_params->ibuf, aad_buffer_len);
1534         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1535                                 "no room to prepend aad");
1536         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1537                                 ut_params->ibuf);
1538         sym_op->auth.aad.length = aad_len;
1539
1540         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1541         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1542
1543         TEST_HEXDUMP(stdout, "aad:",
1544                         sym_op->auth.aad.data, aad_len);
1545
1546         sym_op->cipher.data.length = cipher_len;
1547         sym_op->cipher.data.offset = auth_offset + cipher_offset;
1548
1549         sym_op->auth.data.length = auth_len;
1550         sym_op->auth.data.offset = auth_offset + cipher_offset;
1551
1552         return 0;
1553 }
1554
1555 static int
1556 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1557 {
1558         struct crypto_testsuite_params *ts_params = &testsuite_params;
1559         struct crypto_unittest_params *ut_params = &unittest_params;
1560
1561         int retval;
1562         unsigned plaintext_pad_len;
1563         uint8_t *plaintext;
1564
1565         /* Create SNOW3G session */
1566         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1567                         tdata->key.data, tdata->key.len,
1568                         tdata->aad.len, tdata->digest.len,
1569                         RTE_CRYPTO_AUTH_OP_GENERATE);
1570         if (retval < 0)
1571                 return retval;
1572
1573         /* alloc mbuf and set payload */
1574         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1575
1576         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1577         rte_pktmbuf_tailroom(ut_params->ibuf));
1578
1579         /* Append data which is padded to a multiple of */
1580         /* the algorithms block size */
1581         plaintext_pad_len = tdata->plaintext.len >> 3;
1582         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1583                                 plaintext_pad_len);
1584         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1585
1586         /* Create SNOW3G opertaion */
1587         retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1588                         tdata->aad.data, tdata->aad.len,
1589                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1590                         tdata->validAuthLenInBits.len,
1591                         tdata->validAuthOffsetLenInBits.len);
1592         if (retval < 0)
1593                 return retval;
1594
1595         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1596                                 ut_params->op);
1597         ut_params->obuf = ut_params->op->sym->m_src;
1598         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1599         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1600                         + plaintext_pad_len + tdata->aad.len;
1601
1602         /* Validate obuf */
1603         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1604         ut_params->digest,
1605         tdata->digest.data,
1606         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1607         "Snow3G Generated auth tag not as expected");
1608
1609         return 0;
1610 }
1611
1612 static int
1613 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1614 {
1615         struct crypto_testsuite_params *ts_params = &testsuite_params;
1616         struct crypto_unittest_params *ut_params = &unittest_params;
1617
1618         int retval;
1619         unsigned plaintext_pad_len;
1620         uint8_t *plaintext;
1621
1622         /* Create SNOW3G session */
1623         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1624                                 tdata->key.data, tdata->key.len,
1625                                 tdata->aad.len, tdata->digest.len,
1626                                 RTE_CRYPTO_AUTH_OP_VERIFY);
1627         if (retval < 0)
1628                 return retval;
1629         /* alloc mbuf and set payload */
1630         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1631
1632         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1633         rte_pktmbuf_tailroom(ut_params->ibuf));
1634
1635         /* Append data which is padded to a multiple */
1636         /* of the algorithms block size */
1637         plaintext_pad_len = tdata->plaintext.len >> 3;
1638         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1639                                         plaintext_pad_len);
1640         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1641
1642         /* Create SNOW3G operation */
1643         retval = create_snow3g_hash_operation(tdata->digest.data,
1644                         tdata->digest.len,
1645                         tdata->aad.data, tdata->aad.len,
1646                         plaintext_pad_len,
1647                         RTE_CRYPTO_AUTH_OP_VERIFY,
1648                         tdata->validAuthLenInBits.len,
1649                         tdata->validAuthOffsetLenInBits.len);
1650         if (retval < 0)
1651                 return retval;
1652
1653         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1654                                 ut_params->op);
1655         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1656         ut_params->obuf = ut_params->op->sym->m_src;
1657         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1658                                 + plaintext_pad_len + tdata->aad.len;
1659
1660         /* Validate obuf */
1661         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1662                 return 0;
1663         else
1664                 return -1;
1665
1666         return 0;
1667 }
1668
1669
1670 static int
1671 test_snow3g_hash_generate_test_case_1(void)
1672 {
1673         return test_snow3g_authentication(&snow3g_hash_test_case_1);
1674 }
1675
1676 static int
1677 test_snow3g_hash_generate_test_case_2(void)
1678 {
1679         return test_snow3g_authentication(&snow3g_hash_test_case_2);
1680 }
1681
1682 static int
1683 test_snow3g_hash_generate_test_case_3(void)
1684 {
1685         return test_snow3g_authentication(&snow3g_hash_test_case_3);
1686 }
1687
1688 static int
1689 test_snow3g_hash_verify_test_case_1(void)
1690 {
1691         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1692
1693 }
1694
1695 static int
1696 test_snow3g_hash_verify_test_case_2(void)
1697 {
1698         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1699 }
1700
1701 static int
1702 test_snow3g_hash_verify_test_case_3(void)
1703 {
1704         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1705 }
1706
1707 static int
1708 test_snow3g_encryption(const struct snow3g_test_data *tdata)
1709 {
1710         struct crypto_testsuite_params *ts_params = &testsuite_params;
1711         struct crypto_unittest_params *ut_params = &unittest_params;
1712
1713         int retval;
1714         uint8_t *plaintext, *ciphertext;
1715         uint8_t plaintext_pad_len;
1716         uint8_t lastByteValidBits = 8;
1717         uint8_t lastByteMask = 0xFF;
1718
1719         /* Create SNOW3G session */
1720         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1721                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1722                                         tdata->key.data, tdata->key.len);
1723         if (retval < 0)
1724                 return retval;
1725
1726         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1727
1728         /* Clear mbuf payload */
1729         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1730                rte_pktmbuf_tailroom(ut_params->ibuf));
1731
1732         /*
1733          * Append data which is padded to a
1734          * multiple of the algorithms block size
1735          */
1736         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1737         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1738
1739         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1740                                                 plaintext_pad_len);
1741         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1742
1743         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1744
1745         /* Create SNOW3G operation */
1746         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1747                                         tdata->validCipherLenInBits.len,
1748                                         tdata->validCipherOffsetLenInBits.len);
1749         if (retval < 0)
1750                 return retval;
1751
1752         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1753                                                 ut_params->op);
1754         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1755
1756         ut_params->obuf = ut_params->op->sym->m_dst;
1757         if (ut_params->obuf)
1758                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1759                                 + tdata->iv.len;
1760         else
1761                 ciphertext = plaintext;
1762
1763         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1764         if (lastByteValidBits == 0)
1765                 lastByteValidBits = 8;
1766         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1767         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1768
1769         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1770
1771         /* Validate obuf */
1772         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1773                 ciphertext,
1774                 tdata->ciphertext.data,
1775                 tdata->ciphertext.len >> 3,
1776                 "Snow3G Ciphertext data not as expected");
1777         return 0;
1778 }
1779
1780
1781 static int
1782 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
1783 {
1784         struct crypto_testsuite_params *ts_params = &testsuite_params;
1785         struct crypto_unittest_params *ut_params = &unittest_params;
1786         uint8_t *plaintext, *ciphertext;
1787
1788         int retval;
1789         uint8_t plaintext_pad_len;
1790         uint8_t lastByteValidBits = 8;
1791         uint8_t lastByteMask = 0xFF;
1792
1793         /* Create SNOW3G session */
1794         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1795                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1796                                         tdata->key.data, tdata->key.len);
1797         if (retval < 0)
1798                 return retval;
1799
1800         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1801         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1802
1803         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1804                         "Failed to allocate input buffer in mempool");
1805         TEST_ASSERT_NOT_NULL(ut_params->obuf,
1806                         "Failed to allocate output buffer in mempool");
1807
1808         /* Clear mbuf payload */
1809         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1810                rte_pktmbuf_tailroom(ut_params->ibuf));
1811
1812         /*
1813          * Append data which is padded to a
1814          * multiple of the algorithms block size
1815          */
1816         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1817         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1818
1819         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1820                                                 plaintext_pad_len);
1821
1822         rte_pktmbuf_append(ut_params->obuf,
1823                                                 plaintext_pad_len);
1824
1825         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1826
1827         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1828
1829         /* Create SNOW3G operation */
1830         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1831                                         tdata->iv.len,
1832                                         tdata->validCipherLenInBits.len,
1833                                         tdata->validCipherOffsetLenInBits.len);
1834         if (retval < 0)
1835                 return retval;
1836
1837         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1838                                                 ut_params->op);
1839         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1840
1841         ut_params->obuf = ut_params->op->sym->m_dst;
1842         if (ut_params->obuf)
1843                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1844                                 + tdata->iv.len;
1845         else
1846                 ciphertext = plaintext;
1847
1848         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1849         if (lastByteValidBits == 0)
1850                 lastByteValidBits = 8;
1851         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1852         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1853
1854         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1855
1856         /* Validate obuf */
1857         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1858                 ciphertext,
1859                 tdata->ciphertext.data,
1860                 tdata->ciphertext.len >> 3,
1861                 "Snow3G Ciphertext data not as expected");
1862         return 0;
1863 }
1864
1865
1866 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
1867 {
1868         struct crypto_testsuite_params *ts_params = &testsuite_params;
1869         struct crypto_unittest_params *ut_params = &unittest_params;
1870
1871         int retval;
1872
1873         uint8_t *plaintext, *ciphertext;
1874         uint8_t ciphertext_pad_len;
1875         uint8_t lastByteValidBits = 8;
1876         uint8_t lastByteMask = 0xFF;
1877
1878         /* Create SNOW3G session */
1879         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1880                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
1881                                         tdata->key.data, tdata->key.len);
1882         if (retval < 0)
1883                 return retval;
1884
1885         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1886
1887         /* Clear mbuf payload */
1888         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1889                rte_pktmbuf_tailroom(ut_params->ibuf));
1890
1891         /*
1892          * Append data which is padded to a
1893          * multiple of the algorithms block size
1894          */
1895         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1896
1897         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1898                                                 ciphertext_pad_len);
1899         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1900
1901         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1902
1903         /* Create SNOW3G operation */
1904         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1905                                         tdata->validCipherLenInBits.len,
1906                                         tdata->validCipherOffsetLenInBits.len);
1907         if (retval < 0)
1908                 return retval;
1909
1910         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1911                                                 ut_params->op);
1912         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1913         ut_params->obuf = ut_params->op->sym->m_src;
1914         if (ut_params->obuf)
1915                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1916                                 + tdata->iv.len;
1917         else
1918                 plaintext = ciphertext;
1919         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
1920         if (lastByteValidBits == 0)
1921                 lastByteValidBits = 8;
1922         lastByteMask = lastByteMask << (8 - lastByteValidBits);
1923         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1924
1925         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1926
1927         /* Validate obuf */
1928         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1929                                 tdata->plaintext.data,
1930                                 tdata->plaintext.len >> 3,
1931                                 "Snow3G Plaintext data not as expected");
1932         return 0;
1933 }
1934
1935 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
1936 {
1937         struct crypto_testsuite_params *ts_params = &testsuite_params;
1938         struct crypto_unittest_params *ut_params = &unittest_params;
1939
1940         int retval;
1941
1942         uint8_t *plaintext, *ciphertext;
1943         uint8_t ciphertext_pad_len;
1944         uint8_t lastByteValidBits = 8;
1945         uint8_t lastByteMask = 0xFF;
1946
1947         /* Create SNOW3G session */
1948         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1949                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
1950                                         tdata->key.data, tdata->key.len);
1951         if (retval < 0)
1952                 return retval;
1953
1954         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1955         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1956
1957         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1958                         "Failed to allocate input buffer");
1959         TEST_ASSERT_NOT_NULL(ut_params->obuf,
1960                         "Failed to allocate output buffer");
1961
1962         /* Clear mbuf payload */
1963         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1964                rte_pktmbuf_tailroom(ut_params->ibuf));
1965
1966         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
1967                        rte_pktmbuf_tailroom(ut_params->obuf));
1968
1969         /*
1970          * Append data which is padded to a
1971          * multiple of the algorithms block size
1972          */
1973         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1974
1975         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1976                                                 ciphertext_pad_len);
1977
1978         rte_pktmbuf_append(ut_params->obuf,
1979                                                 ciphertext_pad_len);
1980
1981         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1982
1983         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1984
1985         /* Create SNOW3G operation */
1986         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1987                                         tdata->iv.len,
1988                                         tdata->validCipherLenInBits.len,
1989                                         tdata->validCipherOffsetLenInBits.len);
1990         if (retval < 0)
1991                 return retval;
1992
1993         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1994                                                 ut_params->op);
1995         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1996         ut_params->obuf = ut_params->op->sym->m_dst;
1997         if (ut_params->obuf)
1998                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1999                                 + tdata->iv.len;
2000         else
2001                 plaintext = ciphertext;
2002         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
2003         if (lastByteValidBits == 0)
2004                 lastByteValidBits = 8;
2005         lastByteMask = lastByteMask << (8 - lastByteValidBits);
2006         (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2007
2008         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2009
2010         /* Validate obuf */
2011         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2012                                 tdata->plaintext.data,
2013                                 tdata->plaintext.len >> 3,
2014                                 "Snow3G Plaintext data not as expected");
2015         return 0;
2016 }
2017
2018 static int
2019 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2020 {
2021         struct crypto_testsuite_params *ts_params = &testsuite_params;
2022         struct crypto_unittest_params *ut_params = &unittest_params;
2023
2024         int retval;
2025
2026         uint8_t *plaintext, *ciphertext;
2027         uint8_t plaintext_pad_len;
2028         uint8_t lastByteValidBits = 8;
2029         uint8_t lastByteMask = 0xFF;
2030
2031         /* Create SNOW3G session */
2032         retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2033                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2034                         RTE_CRYPTO_AUTH_OP_GENERATE,
2035                         tdata->key.data, tdata->key.len,
2036                         tdata->aad.len, tdata->digest.len);
2037         if (retval < 0)
2038                 return retval;
2039         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2040
2041         /* clear mbuf payload */
2042         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2043                         rte_pktmbuf_tailroom(ut_params->ibuf));
2044
2045         /* Append data which is padded to a multiple */
2046         /*  of the algorithms block size */
2047         plaintext_pad_len = tdata->plaintext.len >> 3;
2048
2049         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2050                         plaintext_pad_len);
2051         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2052
2053         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2054
2055         /* Create SNOW3G operation */
2056         retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2057                         tdata->digest.len, tdata->aad.data,
2058                         tdata->aad.len, /*tdata->plaintext.len,*/
2059                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2060                         tdata->iv.data, tdata->iv.len,
2061                         tdata->validCipherLenInBits.len,
2062                         tdata->validCipherOffsetLenInBits.len,
2063                         tdata->validAuthLenInBits.len,
2064                         tdata->validAuthOffsetLenInBits.len);
2065         if (retval < 0)
2066                 return retval;
2067
2068         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2069                         ut_params->op);
2070         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2071         ut_params->obuf = ut_params->op->sym->m_src;
2072         if (ut_params->obuf)
2073                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2074                                 + tdata->iv.len;
2075         else
2076                 ciphertext = plaintext;
2077         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2078         if (lastByteValidBits == 0)
2079                 lastByteValidBits = 8;
2080         lastByteMask = lastByteMask << (8-lastByteValidBits);
2081         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2082
2083         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2084
2085         /* Validate obuf */
2086         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2087                         ciphertext,
2088                         tdata->ciphertext.data,
2089                         tdata->ciphertext.len >> 3,
2090                         "Snow3G Ciphertext data not as expected");
2091
2092         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2093             + plaintext_pad_len + tdata->aad.len;
2094
2095         /* Validate obuf */
2096         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2097                         ut_params->digest,
2098                         tdata->digest.data,
2099                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2100                         "Snow3G Generated auth tag not as expected");
2101         return 0;
2102 }
2103 static int
2104 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2105 {
2106         struct crypto_testsuite_params *ts_params = &testsuite_params;
2107         struct crypto_unittest_params *ut_params = &unittest_params;
2108
2109         int retval;
2110
2111         uint8_t *plaintext, *ciphertext;
2112         uint8_t plaintext_pad_len;
2113         uint8_t lastByteValidBits = 8;
2114         uint8_t lastByteMask = 0xFF;
2115
2116         /* Create SNOW3G session */
2117         retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2118                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2119                         RTE_CRYPTO_AUTH_OP_GENERATE,
2120                         tdata->key.data, tdata->key.len,
2121                         tdata->aad.len, tdata->digest.len);
2122         if (retval < 0)
2123                 return retval;
2124
2125         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2126
2127         /* clear mbuf payload */
2128         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2129                         rte_pktmbuf_tailroom(ut_params->ibuf));
2130
2131         /* Append data which is padded to a multiple */
2132         /* of the algorithms block size */
2133         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2134
2135         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2136                         plaintext_pad_len);
2137         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2138
2139         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2140
2141         /* Create SNOW3G operation */
2142         retval = create_snow3g_auth_cipher_operation(
2143                 tdata->digest.len,
2144                 tdata->iv.data, tdata->iv.len,
2145                 tdata->aad.data, tdata->aad.len,
2146                 plaintext_pad_len,
2147                 tdata->validCipherLenInBits.len,
2148                 tdata->validCipherOffsetLenInBits.len,
2149                 tdata->validAuthLenInBits.len,
2150                 tdata->validAuthOffsetLenInBits.len
2151         );
2152
2153         if (retval < 0)
2154                 return retval;
2155
2156         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2157                         ut_params->op);
2158         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2159         ut_params->obuf = ut_params->op->sym->m_src;
2160         if (ut_params->obuf)
2161                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2162                                 + tdata->aad.len + tdata->iv.len;
2163         else
2164                 ciphertext = plaintext;
2165
2166         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2167         if (lastByteValidBits == 0)
2168                 lastByteValidBits = 8;
2169         lastByteMask = lastByteMask << (8-lastByteValidBits);
2170         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2171         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2172                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2173         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2174
2175         /* Validate obuf */
2176         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2177                 ciphertext,
2178                 tdata->ciphertext.data,
2179                 tdata->ciphertext.len >> 3,
2180                 "Snow3G Ciphertext data not as expected");
2181
2182         /* Validate obuf */
2183         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2184                 ut_params->digest,
2185                 tdata->digest.data,
2186                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2187                 "Snow3G Generated auth tag not as expected");
2188         return 0;
2189 }
2190
2191 static int
2192 test_snow3g_encryption_test_case_1(void)
2193 {
2194         return test_snow3g_encryption(&snow3g_test_case_1);
2195 }
2196
2197 static int
2198 test_snow3g_encryption_test_case_1_oop(void)
2199 {
2200         return test_snow3g_encryption_oop(&snow3g_test_case_1);
2201 }
2202
2203 static int
2204 test_snow3g_encryption_test_case_2(void)
2205 {
2206         return test_snow3g_encryption(&snow3g_test_case_2);
2207 }
2208
2209 static int
2210 test_snow3g_encryption_test_case_3(void)
2211 {
2212         return test_snow3g_encryption(&snow3g_test_case_3);
2213 }
2214
2215 static int
2216 test_snow3g_encryption_test_case_4(void)
2217 {
2218         return test_snow3g_encryption(&snow3g_test_case_4);
2219 }
2220
2221 static int
2222 test_snow3g_encryption_test_case_5(void)
2223 {
2224         return test_snow3g_encryption(&snow3g_test_case_5);
2225 }
2226
2227 static int
2228 test_snow3g_decryption_test_case_1(void)
2229 {
2230         return test_snow3g_decryption(&snow3g_test_case_1);
2231 }
2232
2233 static int
2234 test_snow3g_decryption_test_case_1_oop(void)
2235 {
2236         return test_snow3g_decryption_oop(&snow3g_test_case_1);
2237 }
2238
2239 static int
2240 test_snow3g_decryption_test_case_2(void)
2241 {
2242         return test_snow3g_decryption(&snow3g_test_case_2);
2243 }
2244
2245 static int
2246 test_snow3g_decryption_test_case_3(void)
2247 {
2248         return test_snow3g_decryption(&snow3g_test_case_3);
2249 }
2250
2251 static int
2252 test_snow3g_decryption_test_case_4(void)
2253 {
2254         return test_snow3g_decryption(&snow3g_test_case_4);
2255 }
2256
2257 static int
2258 test_snow3g_decryption_test_case_5(void)
2259 {
2260         return test_snow3g_decryption(&snow3g_test_case_5);
2261 }
2262 static int
2263 test_snow3g_authenticated_encryption_test_case_1(void)
2264 {
2265         return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2266 }
2267
2268 static int
2269 test_snow3g_encrypted_authentication_test_case_1(void)
2270 {
2271         return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2272 }
2273
2274 /* ***** AES-GCM Tests ***** */
2275
2276 static int
2277 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2278                 const uint8_t *key, const uint8_t key_len,
2279                 const uint8_t aad_len, const uint8_t auth_len)
2280 {
2281         uint8_t cipher_key[key_len];
2282
2283         struct crypto_unittest_params *ut_params = &unittest_params;
2284
2285
2286         memcpy(cipher_key, key, key_len);
2287
2288         /* Setup Cipher Parameters */
2289         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2290         ut_params->cipher_xform.next = NULL;
2291
2292         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2293         ut_params->cipher_xform.cipher.op = op;
2294         ut_params->cipher_xform.cipher.key.data = cipher_key;
2295         ut_params->cipher_xform.cipher.key.length = key_len;
2296
2297         TEST_HEXDUMP(stdout, "key:", key, key_len);
2298
2299         /* Setup Authentication Parameters */
2300         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2301         ut_params->auth_xform.next = NULL;
2302
2303         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2304
2305         ut_params->auth_xform.auth.digest_length = auth_len;
2306         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2307         ut_params->auth_xform.auth.key.length = 0;
2308         ut_params->auth_xform.auth.key.data = NULL;
2309
2310         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2311                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2312
2313                 /* Create Crypto session*/
2314                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2315                                 &ut_params->cipher_xform);
2316         } else {/* Create Crypto session*/
2317                 ut_params->auth_xform.next = &ut_params->cipher_xform;
2318                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2319                                 &ut_params->auth_xform);
2320         }
2321
2322         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2323
2324         return 0;
2325 }
2326
2327 static int
2328 create_gcm_operation(enum rte_crypto_cipher_operation op,
2329                 const uint8_t *auth_tag, const unsigned auth_tag_len,
2330                 const uint8_t *iv, const unsigned iv_len,
2331                 const uint8_t *aad, const unsigned aad_len,
2332                 const unsigned data_len, unsigned data_pad_len)
2333 {
2334         struct crypto_testsuite_params *ts_params = &testsuite_params;
2335         struct crypto_unittest_params *ut_params = &unittest_params;
2336
2337         unsigned iv_pad_len = 0, aad_buffer_len;
2338
2339         /* Generate Crypto op data structure */
2340         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2341                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2342         TEST_ASSERT_NOT_NULL(ut_params->op,
2343                         "Failed to allocate symmetric crypto operation struct");
2344
2345         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2346
2347
2348
2349         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2350                         ut_params->ibuf, auth_tag_len);
2351         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2352                         "no room to append digest");
2353         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2354                         ut_params->ibuf, data_pad_len);
2355         sym_op->auth.digest.length = auth_tag_len;
2356
2357         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2358                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2359                 TEST_HEXDUMP(stdout, "digest:",
2360                                 sym_op->auth.digest.data,
2361                                 sym_op->auth.digest.length);
2362         }
2363
2364         /* iv */
2365         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2366
2367         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2368                         ut_params->ibuf, iv_pad_len);
2369         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2370
2371         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2372         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2373         sym_op->cipher.iv.length = iv_pad_len;
2374
2375         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2376
2377         /* CalcY0 */
2378         if (iv_len != 16)
2379                 sym_op->cipher.iv.data[15] = 1;
2380
2381         /*
2382          * Always allocate the aad up to the block size.
2383          * The cryptodev API calls out -
2384          *  - the array must be big enough to hold the AAD, plus any
2385          *   space to round this up to the nearest multiple of the
2386          *   block size (16 bytes).
2387          */
2388         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2389
2390         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2391                         ut_params->ibuf, aad_buffer_len);
2392         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2393                         "no room to prepend aad");
2394         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2395                         ut_params->ibuf);
2396         sym_op->auth.aad.length = aad_len;
2397
2398         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2399         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2400
2401         TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
2402         TEST_HEXDUMP(stdout, "aad:",
2403                         sym_op->auth.aad.data, aad_len);
2404
2405         sym_op->cipher.data.length = data_len;
2406         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2407
2408         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2409         sym_op->auth.data.length = data_len;
2410
2411         return 0;
2412 }
2413
2414 static int
2415 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2416 {
2417         struct crypto_testsuite_params *ts_params = &testsuite_params;
2418         struct crypto_unittest_params *ut_params = &unittest_params;
2419
2420         int retval;
2421
2422         uint8_t *plaintext, *ciphertext, *auth_tag;
2423         uint16_t plaintext_pad_len;
2424
2425         /* Create GCM session */
2426         retval = create_gcm_session(ts_params->valid_devs[0],
2427                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2428                         tdata->key.data, tdata->key.len,
2429                         tdata->aad.len, tdata->auth_tag.len);
2430         if (retval < 0)
2431                 return retval;
2432
2433
2434         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2435
2436         /* clear mbuf payload */
2437         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2438                         rte_pktmbuf_tailroom(ut_params->ibuf));
2439
2440         /*
2441          * Append data which is padded to a multiple
2442          * of the algorithms block size
2443          */
2444         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2445
2446         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2447                         plaintext_pad_len);
2448         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2449
2450         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2451
2452         /* Create GCM opertaion */
2453         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2454                         tdata->auth_tag.data, tdata->auth_tag.len,
2455                         tdata->iv.data, tdata->iv.len,
2456                         tdata->aad.data, tdata->aad.len,
2457                         tdata->plaintext.len, plaintext_pad_len);
2458         if (retval < 0)
2459                 return retval;
2460
2461         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2462
2463         ut_params->op->sym->m_src = ut_params->ibuf;
2464
2465         /* Process crypto operation */
2466         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2467                         ut_params->op), "failed to process sym crypto op");
2468
2469         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2470                         "crypto op processing failed");
2471
2472         if (ut_params->op->sym->m_dst) {
2473                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2474                                 uint8_t *);
2475                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
2476                                 uint8_t *, plaintext_pad_len);
2477         } else {
2478                 ciphertext = plaintext;
2479                 auth_tag = plaintext + plaintext_pad_len;
2480         }
2481
2482         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2483         TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
2484
2485         /* Validate obuf */
2486         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2487                         ciphertext,
2488                         tdata->ciphertext.data,
2489                         tdata->ciphertext.len,
2490                         "GCM Ciphertext data not as expected");
2491
2492         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2493                         auth_tag,
2494                         tdata->auth_tag.data,
2495                         tdata->auth_tag.len,
2496                         "GCM Generated auth tag not as expected");
2497
2498         return 0;
2499
2500 }
2501
2502 static int
2503 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
2504 {
2505         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
2506 }
2507
2508 static int
2509 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
2510 {
2511         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
2512 }
2513
2514 static int
2515 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
2516 {
2517         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
2518 }
2519
2520 static int
2521 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
2522 {
2523         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
2524 }
2525
2526 static int
2527 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
2528 {
2529         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
2530 }
2531
2532 static int
2533 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
2534 {
2535         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
2536 }
2537
2538 static int
2539 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
2540 {
2541         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
2542 }
2543
2544 static int
2545 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
2546 {
2547         struct crypto_testsuite_params *ts_params = &testsuite_params;
2548         struct crypto_unittest_params *ut_params = &unittest_params;
2549
2550         int retval;
2551
2552         uint8_t *plaintext, *ciphertext;
2553         uint16_t ciphertext_pad_len;
2554
2555         /* Create GCM session */
2556         retval = create_gcm_session(ts_params->valid_devs[0],
2557                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
2558                         tdata->key.data, tdata->key.len,
2559                         tdata->aad.len, tdata->auth_tag.len);
2560         if (retval < 0)
2561                 return retval;
2562
2563
2564         /* alloc mbuf and set payload */
2565         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2566
2567         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2568                         rte_pktmbuf_tailroom(ut_params->ibuf));
2569
2570         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2571
2572         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2573                         ciphertext_pad_len);
2574         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2575
2576         TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2577
2578         /* Create GCM opertaion */
2579         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
2580                         tdata->auth_tag.data, tdata->auth_tag.len,
2581                         tdata->iv.data, tdata->iv.len,
2582                         tdata->aad.data, tdata->aad.len,
2583                         tdata->ciphertext.len, ciphertext_pad_len);
2584         if (retval < 0)
2585                 return retval;
2586
2587
2588         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2589
2590         ut_params->op->sym->m_src = ut_params->ibuf;
2591
2592         /* Process crypto operation */
2593         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2594                         ut_params->op), "failed to process sym crypto op");
2595
2596         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2597                         "crypto op processing failed");
2598
2599         if (ut_params->op->sym->m_dst)
2600                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2601                                 uint8_t *);
2602         else
2603                 plaintext = ciphertext;
2604
2605         TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
2606
2607         /* Validate obuf */
2608         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2609                         plaintext,
2610                         tdata->plaintext.data,
2611                         tdata->plaintext.len,
2612                         "GCM plaintext data not as expected");
2613
2614         TEST_ASSERT_EQUAL(ut_params->op->status,
2615                         RTE_CRYPTO_OP_STATUS_SUCCESS,
2616                         "GCM authentication failed");
2617         return 0;
2618 }
2619
2620 static int
2621 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
2622 {
2623         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
2624 }
2625
2626 static int
2627 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
2628 {
2629         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
2630 }
2631
2632 static int
2633 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
2634 {
2635         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
2636 }
2637
2638 static int
2639 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
2640 {
2641         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
2642 }
2643
2644 static int
2645 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
2646 {
2647         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
2648 }
2649
2650 static int
2651 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
2652 {
2653         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
2654 }
2655
2656 static int
2657 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
2658 {
2659         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
2660 }
2661
2662 static int
2663 test_stats(void)
2664 {
2665         struct crypto_testsuite_params *ts_params = &testsuite_params;
2666         struct rte_cryptodev_stats stats;
2667         struct rte_cryptodev *dev;
2668         cryptodev_stats_get_t temp_pfn;
2669
2670         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2671         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2672                         &stats) == -ENODEV),
2673                 "rte_cryptodev_stats_get invalid dev failed");
2674         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2675                 "rte_cryptodev_stats_get invalid Param failed");
2676         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2677         temp_pfn = dev->dev_ops->stats_get;
2678         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2679         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2680                         == -ENOTSUP),
2681                 "rte_cryptodev_stats_get invalid Param failed");
2682         dev->dev_ops->stats_get = temp_pfn;
2683
2684         /* Test expected values */
2685         ut_setup();
2686         test_AES_CBC_HMAC_SHA1_encrypt_digest();
2687         ut_teardown();
2688         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2689                         &stats),
2690                 "rte_cryptodev_stats_get failed");
2691         TEST_ASSERT((stats.enqueued_count == 1),
2692                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2693         TEST_ASSERT((stats.dequeued_count == 1),
2694                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2695         TEST_ASSERT((stats.enqueue_err_count == 0),
2696                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2697         TEST_ASSERT((stats.dequeue_err_count == 0),
2698                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2699
2700         /* invalid device but should ignore and not reset device stats*/
2701         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2702         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2703                         &stats),
2704                 "rte_cryptodev_stats_get failed");
2705         TEST_ASSERT((stats.enqueued_count == 1),
2706                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2707
2708         /* check that a valid reset clears stats */
2709         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2710         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2711                         &stats),
2712                                           "rte_cryptodev_stats_get failed");
2713         TEST_ASSERT((stats.enqueued_count == 0),
2714                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2715         TEST_ASSERT((stats.dequeued_count == 0),
2716                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2717
2718         return TEST_SUCCESS;
2719 }
2720
2721
2722 static int
2723 test_multi_session(void)
2724 {
2725         struct crypto_testsuite_params *ts_params = &testsuite_params;
2726         struct crypto_unittest_params *ut_params = &unittest_params;
2727
2728         struct rte_cryptodev_info dev_info;
2729         struct rte_cryptodev_sym_session **sessions;
2730
2731         uint16_t i;
2732
2733         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2734
2735
2736         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2737
2738         sessions = rte_malloc(NULL,
2739                         (sizeof(struct rte_cryptodev_sym_session *) *
2740                         dev_info.sym.max_nb_sessions) + 1, 0);
2741
2742         /* Create multiple crypto sessions*/
2743         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2744                 sessions[i] = rte_cryptodev_sym_session_create(
2745                                 ts_params->valid_devs[0],
2746                         &ut_params->auth_xform);
2747                 TEST_ASSERT_NOT_NULL(sessions[i],
2748                                 "Session creation failed at session number %u",
2749                                 i);
2750
2751                 /* Attempt to send a request on each session */
2752                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2753                                 sessions[i], ut_params, ts_params),
2754                                 "Failed to perform decrypt on request "
2755                                 "number %u.", i);
2756                 /* free crypto operation structure */
2757                 if (ut_params->op)
2758                         rte_crypto_op_free(ut_params->op);
2759
2760                 /*
2761                  * free mbuf - both obuf and ibuf are usually the same,
2762                  * but rte copes even if we call free twice
2763                  */
2764                 if (ut_params->obuf) {
2765                         rte_pktmbuf_free(ut_params->obuf);
2766                         ut_params->obuf = 0;
2767                 }
2768         }
2769
2770         /* Next session create should fail */
2771         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2772                         &ut_params->auth_xform);
2773         TEST_ASSERT_NULL(sessions[i],
2774                         "Session creation succeeded unexpectedly!");
2775
2776         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2777                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2778                                 sessions[i]);
2779
2780         rte_free(sessions);
2781
2782         return TEST_SUCCESS;
2783 }
2784
2785 static int
2786 test_null_cipher_only_operation(void)
2787 {
2788         struct crypto_testsuite_params *ts_params = &testsuite_params;
2789         struct crypto_unittest_params *ut_params = &unittest_params;
2790
2791         /* Generate test mbuf data and space for digest */
2792         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2793                         catch_22_quote, QUOTE_512_BYTES, 0);
2794
2795         /* Setup Cipher Parameters */
2796         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2797         ut_params->cipher_xform.next = NULL;
2798
2799         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2800         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2801
2802         /* Create Crypto session*/
2803         ut_params->sess = rte_cryptodev_sym_session_create(
2804                         ts_params->valid_devs[0], &ut_params->cipher_xform);
2805         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2806
2807         /* Generate Crypto op data structure */
2808         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2809                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2810         TEST_ASSERT_NOT_NULL(ut_params->op,
2811                         "Failed to allocate symmetric crypto operation struct");
2812
2813         /* Set crypto operation data parameters */
2814         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2815
2816         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2817
2818         /* set crypto operation source mbuf */
2819         sym_op->m_src = ut_params->ibuf;
2820
2821         sym_op->cipher.data.offset = 0;
2822         sym_op->cipher.data.length = QUOTE_512_BYTES;
2823
2824         /* Process crypto operation */
2825         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2826                         ut_params->op);
2827         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2828
2829         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2830                         "crypto operation processing failed");
2831
2832         /* Validate obuf */
2833         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2834                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2835                         catch_22_quote,
2836                         QUOTE_512_BYTES,
2837                         "Ciphertext data not as expected");
2838
2839         return TEST_SUCCESS;
2840 }
2841
2842 static int
2843 test_null_auth_only_operation(void)
2844 {
2845         struct crypto_testsuite_params *ts_params = &testsuite_params;
2846         struct crypto_unittest_params *ut_params = &unittest_params;
2847
2848         /* Generate test mbuf data and space for digest */
2849         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2850                         catch_22_quote, QUOTE_512_BYTES, 0);
2851
2852         /* Setup HMAC Parameters */
2853         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2854         ut_params->auth_xform.next = NULL;
2855
2856         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2857         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2858
2859         /* Create Crypto session*/
2860         ut_params->sess = rte_cryptodev_sym_session_create(
2861                         ts_params->valid_devs[0], &ut_params->auth_xform);
2862         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2863
2864         /* Generate Crypto op data structure */
2865         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2866                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2867         TEST_ASSERT_NOT_NULL(ut_params->op,
2868                         "Failed to allocate symmetric crypto operation struct");
2869
2870         /* Set crypto operation data parameters */
2871         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2872
2873         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2874
2875         sym_op->m_src = ut_params->ibuf;
2876
2877         sym_op->auth.data.offset = 0;
2878         sym_op->auth.data.length = QUOTE_512_BYTES;
2879
2880         /* Process crypto operation */
2881         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2882                         ut_params->op);
2883         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2884
2885         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2886                         "crypto operation processing failed");
2887
2888         return TEST_SUCCESS;
2889 }
2890
2891 static int
2892 test_null_cipher_auth_operation(void)
2893 {
2894         struct crypto_testsuite_params *ts_params = &testsuite_params;
2895         struct crypto_unittest_params *ut_params = &unittest_params;
2896
2897         /* Generate test mbuf data and space for digest */
2898         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2899                         catch_22_quote, QUOTE_512_BYTES, 0);
2900
2901         /* Setup Cipher Parameters */
2902         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2903         ut_params->cipher_xform.next = &ut_params->auth_xform;
2904
2905         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2906         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2907
2908         /* Setup HMAC Parameters */
2909         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2910         ut_params->auth_xform.next = NULL;
2911
2912         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2913         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2914
2915         /* Create Crypto session*/
2916         ut_params->sess = rte_cryptodev_sym_session_create(
2917                         ts_params->valid_devs[0], &ut_params->cipher_xform);
2918         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2919
2920         /* Generate Crypto op data structure */
2921         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2922                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2923         TEST_ASSERT_NOT_NULL(ut_params->op,
2924                         "Failed to allocate symmetric crypto operation struct");
2925
2926         /* Set crypto operation data parameters */
2927         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2928
2929         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2930
2931         sym_op->m_src = ut_params->ibuf;
2932
2933         sym_op->cipher.data.offset = 0;
2934         sym_op->cipher.data.length = QUOTE_512_BYTES;
2935
2936         sym_op->auth.data.offset = 0;
2937         sym_op->auth.data.length = QUOTE_512_BYTES;
2938
2939         /* Process crypto operation */
2940         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2941                         ut_params->op);
2942         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2943
2944         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2945                         "crypto operation processing failed");
2946
2947         /* Validate obuf */
2948         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2949                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2950                         catch_22_quote,
2951                         QUOTE_512_BYTES,
2952                         "Ciphertext data not as expected");
2953
2954         return TEST_SUCCESS;
2955 }
2956
2957 static int
2958 test_null_auth_cipher_operation(void)
2959 {
2960         struct crypto_testsuite_params *ts_params = &testsuite_params;
2961         struct crypto_unittest_params *ut_params = &unittest_params;
2962
2963         /* Generate test mbuf data and space for digest */
2964         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2965                         catch_22_quote, QUOTE_512_BYTES, 0);
2966
2967         /* Setup Cipher Parameters */
2968         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2969         ut_params->cipher_xform.next = NULL;
2970
2971         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2972         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2973
2974         /* Setup HMAC Parameters */
2975         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2976         ut_params->auth_xform.next = &ut_params->cipher_xform;
2977
2978         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2979         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2980
2981         /* Create Crypto session*/
2982         ut_params->sess = rte_cryptodev_sym_session_create(
2983                         ts_params->valid_devs[0], &ut_params->cipher_xform);
2984         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2985
2986         /* Generate Crypto op data structure */
2987         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2988                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2989         TEST_ASSERT_NOT_NULL(ut_params->op,
2990                         "Failed to allocate symmetric crypto operation struct");
2991
2992         /* Set crypto operation data parameters */
2993         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2994
2995         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2996
2997         sym_op->m_src = ut_params->ibuf;
2998
2999         sym_op->cipher.data.offset = 0;
3000         sym_op->cipher.data.length = QUOTE_512_BYTES;
3001
3002         sym_op->auth.data.offset = 0;
3003         sym_op->auth.data.length = QUOTE_512_BYTES;
3004
3005         /* Process crypto operation */
3006         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3007                         ut_params->op);
3008         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3009
3010         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3011                         "crypto operation processing failed");
3012
3013         /* Validate obuf */
3014         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3015                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3016                         catch_22_quote,
3017                         QUOTE_512_BYTES,
3018                         "Ciphertext data not as expected");
3019
3020         return TEST_SUCCESS;
3021 }
3022
3023
3024 static int
3025 test_null_invalid_operation(void)
3026 {
3027         struct crypto_testsuite_params *ts_params = &testsuite_params;
3028         struct crypto_unittest_params *ut_params = &unittest_params;
3029
3030         /* Setup Cipher Parameters */
3031         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3032         ut_params->cipher_xform.next = NULL;
3033
3034         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3035         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3036
3037         /* Create Crypto session*/
3038         ut_params->sess = rte_cryptodev_sym_session_create(
3039                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3040         TEST_ASSERT_NULL(ut_params->sess,
3041                         "Session creation succeeded unexpectedly");
3042
3043
3044         /* Setup HMAC Parameters */
3045         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3046         ut_params->auth_xform.next = NULL;
3047
3048         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3049         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3050
3051         /* Create Crypto session*/
3052         ut_params->sess = rte_cryptodev_sym_session_create(
3053                         ts_params->valid_devs[0], &ut_params->auth_xform);
3054         TEST_ASSERT_NULL(ut_params->sess,
3055                         "Session creation succeeded unexpectedly");
3056
3057         return TEST_SUCCESS;
3058 }
3059
3060
3061 #define NULL_BURST_LENGTH (32)
3062
3063 static int
3064 test_null_burst_operation(void)
3065 {
3066         struct crypto_testsuite_params *ts_params = &testsuite_params;
3067         struct crypto_unittest_params *ut_params = &unittest_params;
3068
3069         unsigned i, burst_len = NULL_BURST_LENGTH;
3070
3071         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3072         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3073
3074         /* Setup Cipher Parameters */
3075         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3076         ut_params->cipher_xform.next = &ut_params->auth_xform;
3077
3078         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3079         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3080
3081         /* Setup HMAC Parameters */
3082         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3083         ut_params->auth_xform.next = NULL;
3084
3085         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3086         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3087
3088         /* Create Crypto session*/
3089         ut_params->sess = rte_cryptodev_sym_session_create(
3090                         ts_params->valid_devs[0], &ut_params->cipher_xform);
3091         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3092
3093         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3094                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3095                         burst_len, "failed to generate burst of crypto ops");
3096
3097         /* Generate an operation for each mbuf in burst */
3098         for (i = 0; i < burst_len; i++) {
3099                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3100
3101                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3102
3103                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3104                                 sizeof(unsigned));
3105                 *data = i;
3106
3107                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3108
3109                 burst[i]->sym->m_src = m;
3110         }
3111
3112         /* Process crypto operation */
3113         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3114                         0, burst, burst_len),
3115                         burst_len,
3116                         "Error enqueuing burst");
3117
3118         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3119                         0, burst_dequeued, burst_len),
3120                         burst_len,
3121                         "Error dequeuing burst");
3122
3123
3124         for (i = 0; i < burst_len; i++) {
3125                 TEST_ASSERT_EQUAL(
3126                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3127                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3128                                         uint32_t *),
3129                         "data not as expected");
3130
3131                 rte_pktmbuf_free(burst[i]->sym->m_src);
3132                 rte_crypto_op_free(burst[i]);
3133         }
3134
3135         return TEST_SUCCESS;
3136 }
3137
3138
3139
3140
3141 static struct unit_test_suite cryptodev_qat_testsuite  = {
3142         .suite_name = "Crypto QAT Unit Test Suite",
3143         .setup = testsuite_setup,
3144         .teardown = testsuite_teardown,
3145         .unit_test_cases = {
3146                 TEST_CASE_ST(ut_setup, ut_teardown,
3147                                 test_device_configure_invalid_dev_id),
3148                 TEST_CASE_ST(ut_setup, ut_teardown,
3149                                 test_device_configure_invalid_queue_pair_ids),
3150                 TEST_CASE_ST(ut_setup, ut_teardown,
3151                                 test_queue_pair_descriptor_setup),
3152                 TEST_CASE_ST(ut_setup, ut_teardown,
3153                                 test_multi_session),
3154
3155                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3156                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3157
3158                 /** AES GCM Authenticated Encryption */
3159                 TEST_CASE_ST(ut_setup, ut_teardown,
3160                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3161                 TEST_CASE_ST(ut_setup, ut_teardown,
3162                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3163                 TEST_CASE_ST(ut_setup, ut_teardown,
3164                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3165                 TEST_CASE_ST(ut_setup, ut_teardown,
3166                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3167                 TEST_CASE_ST(ut_setup, ut_teardown,
3168                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3169                 TEST_CASE_ST(ut_setup, ut_teardown,
3170                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3171                 TEST_CASE_ST(ut_setup, ut_teardown,
3172                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3173
3174                 /** AES GCM Authenticated Decryption */
3175                 TEST_CASE_ST(ut_setup, ut_teardown,
3176                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3177                 TEST_CASE_ST(ut_setup, ut_teardown,
3178                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3179                 TEST_CASE_ST(ut_setup, ut_teardown,
3180                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3181                 TEST_CASE_ST(ut_setup, ut_teardown,
3182                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3183                 TEST_CASE_ST(ut_setup, ut_teardown,
3184                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3185                 TEST_CASE_ST(ut_setup, ut_teardown,
3186                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3187                 TEST_CASE_ST(ut_setup, ut_teardown,
3188                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3189
3190                 /** Snow3G encrypt only (UEA2) */
3191                 TEST_CASE_ST(ut_setup, ut_teardown,
3192                         test_snow3g_encryption_test_case_1),
3193                 TEST_CASE_ST(ut_setup, ut_teardown,
3194                         test_snow3g_encryption_test_case_2),
3195                 TEST_CASE_ST(ut_setup, ut_teardown,
3196                         test_snow3g_encryption_test_case_3),
3197                 TEST_CASE_ST(ut_setup, ut_teardown,
3198                         test_snow3g_encryption_test_case_4),
3199                 TEST_CASE_ST(ut_setup, ut_teardown,
3200                         test_snow3g_encryption_test_case_5),
3201
3202                 TEST_CASE_ST(ut_setup, ut_teardown,
3203                         test_snow3g_encryption_test_case_1_oop),
3204                 TEST_CASE_ST(ut_setup, ut_teardown,
3205                         test_snow3g_decryption_test_case_1_oop),
3206
3207                 /** Snow3G decrypt only (UEA2) */
3208                 TEST_CASE_ST(ut_setup, ut_teardown,
3209                         test_snow3g_decryption_test_case_1),
3210                 TEST_CASE_ST(ut_setup, ut_teardown,
3211                         test_snow3g_decryption_test_case_2),
3212                 TEST_CASE_ST(ut_setup, ut_teardown,
3213                         test_snow3g_decryption_test_case_3),
3214                 TEST_CASE_ST(ut_setup, ut_teardown,
3215                         test_snow3g_decryption_test_case_4),
3216                 TEST_CASE_ST(ut_setup, ut_teardown,
3217                         test_snow3g_decryption_test_case_5),
3218                 TEST_CASE_ST(ut_setup, ut_teardown,
3219                         test_snow3g_hash_generate_test_case_1),
3220                 TEST_CASE_ST(ut_setup, ut_teardown,
3221                         test_snow3g_hash_generate_test_case_2),
3222                 TEST_CASE_ST(ut_setup, ut_teardown,
3223                         test_snow3g_hash_generate_test_case_3),
3224                 TEST_CASE_ST(ut_setup, ut_teardown,
3225                         test_snow3g_hash_verify_test_case_1),
3226                 TEST_CASE_ST(ut_setup, ut_teardown,
3227                         test_snow3g_hash_verify_test_case_2),
3228                 TEST_CASE_ST(ut_setup, ut_teardown,
3229                         test_snow3g_hash_verify_test_case_3),
3230                 TEST_CASE_ST(ut_setup, ut_teardown,
3231                         test_snow3g_authenticated_encryption_test_case_1),
3232                 TEST_CASE_ST(ut_setup, ut_teardown,
3233                         test_snow3g_encrypted_authentication_test_case_1),
3234                 TEST_CASES_END() /**< NULL terminate unit test array */
3235         }
3236 };
3237
3238 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
3239         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3240         .setup = testsuite_setup,
3241         .teardown = testsuite_teardown,
3242         .unit_test_cases = {
3243                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3244
3245                 TEST_CASES_END() /**< NULL terminate unit test array */
3246         }
3247 };
3248
3249 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
3250         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3251         .setup = testsuite_setup,
3252         .teardown = testsuite_teardown,
3253         .unit_test_cases = {
3254                 /** AES GCM Authenticated Encryption */
3255                 TEST_CASE_ST(ut_setup, ut_teardown,
3256                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
3257                 TEST_CASE_ST(ut_setup, ut_teardown,
3258                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
3259                 TEST_CASE_ST(ut_setup, ut_teardown,
3260                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
3261                 TEST_CASE_ST(ut_setup, ut_teardown,
3262                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
3263                 TEST_CASE_ST(ut_setup, ut_teardown,
3264                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
3265                 TEST_CASE_ST(ut_setup, ut_teardown,
3266                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
3267                 TEST_CASE_ST(ut_setup, ut_teardown,
3268                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
3269
3270                 /** AES GCM Authenticated Decryption */
3271                 TEST_CASE_ST(ut_setup, ut_teardown,
3272                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
3273                 TEST_CASE_ST(ut_setup, ut_teardown,
3274                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
3275                 TEST_CASE_ST(ut_setup, ut_teardown,
3276                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
3277                 TEST_CASE_ST(ut_setup, ut_teardown,
3278                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
3279                 TEST_CASE_ST(ut_setup, ut_teardown,
3280                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
3281                 TEST_CASE_ST(ut_setup, ut_teardown,
3282                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
3283                 TEST_CASE_ST(ut_setup, ut_teardown,
3284                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
3285
3286                 TEST_CASES_END() /**< NULL terminate unit test array */
3287         }
3288 };
3289
3290 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
3291         .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3292         .setup = testsuite_setup,
3293         .teardown = testsuite_teardown,
3294         .unit_test_cases = {
3295                 /** Snow3G encrypt only (UEA2) */
3296                 TEST_CASE_ST(ut_setup, ut_teardown,
3297                         test_snow3g_encryption_test_case_1),
3298                 TEST_CASE_ST(ut_setup, ut_teardown,
3299                         test_snow3g_encryption_test_case_2),
3300                 TEST_CASE_ST(ut_setup, ut_teardown,
3301                         test_snow3g_encryption_test_case_3),
3302                 TEST_CASE_ST(ut_setup, ut_teardown,
3303                         test_snow3g_encryption_test_case_4),
3304                 TEST_CASE_ST(ut_setup, ut_teardown,
3305                         test_snow3g_encryption_test_case_5),
3306
3307
3308                 /** Snow3G decrypt only (UEA2) */
3309                 TEST_CASE_ST(ut_setup, ut_teardown,
3310                         test_snow3g_decryption_test_case_1),
3311                 TEST_CASE_ST(ut_setup, ut_teardown,
3312                         test_snow3g_decryption_test_case_2),
3313                 TEST_CASE_ST(ut_setup, ut_teardown,
3314                         test_snow3g_decryption_test_case_3),
3315                 TEST_CASE_ST(ut_setup, ut_teardown,
3316                         test_snow3g_decryption_test_case_4),
3317                 TEST_CASE_ST(ut_setup, ut_teardown,
3318                         test_snow3g_decryption_test_case_5),
3319                 TEST_CASE_ST(ut_setup, ut_teardown,
3320                         test_snow3g_hash_generate_test_case_1),
3321                 TEST_CASE_ST(ut_setup, ut_teardown,
3322                         test_snow3g_hash_generate_test_case_2),
3323                 TEST_CASE_ST(ut_setup, ut_teardown,
3324                         test_snow3g_hash_generate_test_case_3),
3325                 TEST_CASE_ST(ut_setup, ut_teardown,
3326                         test_snow3g_hash_verify_test_case_1),
3327                 TEST_CASE_ST(ut_setup, ut_teardown,
3328                         test_snow3g_hash_verify_test_case_2),
3329                 TEST_CASE_ST(ut_setup, ut_teardown,
3330                         test_snow3g_hash_verify_test_case_3),
3331                 TEST_CASE_ST(ut_setup, ut_teardown,
3332                         test_snow3g_authenticated_encryption_test_case_1),
3333                 TEST_CASE_ST(ut_setup, ut_teardown,
3334                         test_snow3g_encrypted_authentication_test_case_1),
3335
3336                 TEST_CASES_END() /**< NULL terminate unit test array */
3337         }
3338 };
3339
3340 static struct unit_test_suite cryptodev_null_testsuite  = {
3341         .suite_name = "Crypto Device NULL Unit Test Suite",
3342         .setup = testsuite_setup,
3343         .teardown = testsuite_teardown,
3344         .unit_test_cases = {
3345                 TEST_CASE_ST(ut_setup, ut_teardown,
3346                         test_null_auth_only_operation),
3347                 TEST_CASE_ST(ut_setup, ut_teardown,
3348                         test_null_cipher_only_operation),
3349                 TEST_CASE_ST(ut_setup, ut_teardown,
3350                         test_null_cipher_auth_operation),
3351                 TEST_CASE_ST(ut_setup, ut_teardown,
3352                         test_null_auth_cipher_operation),
3353                 TEST_CASE_ST(ut_setup, ut_teardown,
3354                         test_null_invalid_operation),
3355                 TEST_CASE_ST(ut_setup, ut_teardown,
3356                         test_null_burst_operation),
3357
3358                 TEST_CASES_END() /**< NULL terminate unit test array */
3359         }
3360 };
3361
3362 static int
3363 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3364 {
3365         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3366         return unit_test_suite_runner(&cryptodev_qat_testsuite);
3367 }
3368 static struct test_command cryptodev_qat_cmd = {
3369         .command = "cryptodev_qat_autotest",
3370         .callback = test_cryptodev_qat,
3371 };
3372
3373 static int
3374 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3375 {
3376         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3377
3378         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3379 }
3380
3381 static struct test_command cryptodev_aesni_mb_cmd = {
3382         .command = "cryptodev_aesni_mb_autotest",
3383         .callback = test_cryptodev_aesni_mb,
3384 };
3385
3386 static int
3387 test_cryptodev_aesni_gcm(void)
3388 {
3389         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3390
3391         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3392 }
3393
3394 static struct test_command cryptodev_aesni_gcm_cmd = {
3395         .command = "cryptodev_aesni_gcm_autotest",
3396         .callback = test_cryptodev_aesni_gcm,
3397 };
3398
3399 static int
3400 test_cryptodev_null(void)
3401 {
3402         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
3403
3404         return unit_test_suite_runner(&cryptodev_null_testsuite);
3405 }
3406
3407 static struct test_command cryptodev_null_cmd = {
3408         .command = "cryptodev_null_autotest",
3409         .callback = test_cryptodev_null,
3410 };
3411
3412 static int
3413 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3414 {
3415         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3416
3417         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3418 }
3419
3420 static struct test_command cryptodev_sw_snow3g_cmd = {
3421         .command = "cryptodev_sw_snow3g_autotest",
3422         .callback = test_cryptodev_sw_snow3g,
3423 };
3424
3425 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3426 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3427 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3428 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
3429 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);