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