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