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