55367dfabbc0a735b5b26606bcfdea37ffd3b62e
[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 #include <rte_mbuf_offload.h>
39
40 #include <rte_crypto.h>
41 #include <rte_cryptodev.h>
42 #include <rte_cryptodev_pmd.h>
43
44 #include "test.h"
45 #include "test_cryptodev.h"
46
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 /*
73  * Forward declarations.
74  */
75 static int
76 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
77                 struct crypto_unittest_params *ut_params);
78
79 static int
80 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
81                 struct crypto_unittest_params *ut_params,
82                 struct crypto_testsuite_params *ts_param);
83
84 static struct rte_mbuf *
85 setup_test_string(struct rte_mempool *mpool,
86                 const char *string, size_t len, uint8_t blocksize)
87 {
88         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
89         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
90
91         memset(m->buf_addr, 0, m->buf_len);
92         if (m) {
93                 char *dst = rte_pktmbuf_append(m, t_len);
94
95                 if (!dst) {
96                         rte_pktmbuf_free(m);
97                         return NULL;
98                 }
99
100                 rte_memcpy(dst, string, t_len);
101         }
102
103         return m;
104 }
105
106 #if HEX_DUMP
107 static void
108 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
109 {
110         rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
111 }
112 #endif
113
114 static struct rte_crypto_op *
115 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
116 {
117 #if HEX_DUMP
118         hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
119 #endif
120
121         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
122                 printf("Error sending packet for encryption");
123                 return NULL;
124         }
125
126         op = NULL;
127
128         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
129                 rte_pause();
130
131 #if HEX_DUMP
132         if (obuf)
133                 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
134 #endif
135
136         return op;
137 }
138
139 static struct crypto_testsuite_params testsuite_params = { NULL };
140 static struct crypto_unittest_params unittest_params;
141
142 static int
143 testsuite_setup(void)
144 {
145         struct crypto_testsuite_params *ts_params = &testsuite_params;
146         struct rte_cryptodev_info info;
147         unsigned i, nb_devs, dev_id;
148         int ret;
149         uint16_t qp_id;
150
151         memset(ts_params, 0, sizeof(*ts_params));
152
153         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
154         if (ts_params->mbuf_pool == NULL) {
155                 /* Not already created so create */
156                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
157                                 "CRYPTO_MBUFPOOL",
158                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
159                                 rte_socket_id());
160                 if (ts_params->mbuf_pool == NULL) {
161                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
162                         return TEST_FAILED;
163                 }
164         }
165
166         ts_params->op_mpool = rte_crypto_op_pool_create(
167                         "MBUF_CRYPTO_SYM_OP_POOL",
168                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
169                         NUM_MBUFS, MBUF_CACHE_SIZE,
170                         DEFAULT_NUM_XFORMS *
171                         sizeof(struct rte_crypto_sym_xform),
172                         rte_socket_id());
173         if (ts_params->op_mpool == NULL) {
174                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
175                 return TEST_FAILED;
176         }
177
178         /* Create 2 AESNI MB devices if required */
179         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
180                 nb_devs = rte_cryptodev_count_devtype(
181                                 RTE_CRYPTODEV_AESNI_MB_PMD);
182                 if (nb_devs < 2) {
183                         for (i = nb_devs; i < 2; i++) {
184                                 ret = rte_eal_vdev_init(
185                                         CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
186
187                                 TEST_ASSERT(ret == 0,
188                                         "Failed to create instance %u of"
189                                         " pmd : %s",
190                                         i, CRYPTODEV_NAME_AESNI_MB_PMD);
191                         }
192                 }
193         }
194
195         nb_devs = rte_cryptodev_count();
196         if (nb_devs < 1) {
197                 RTE_LOG(ERR, USER1, "No crypto devices found?");
198                 return TEST_FAILED;
199         }
200
201         /* Create list of valid crypto devs */
202         for (i = 0; i < nb_devs; i++) {
203                 rte_cryptodev_info_get(i, &info);
204                 if (info.dev_type == gbl_cryptodev_type)
205                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
206         }
207
208         if (ts_params->valid_dev_count < 1)
209                 return TEST_FAILED;
210
211         /* Set up all the qps on the first of the valid devices found */
212         for (i = 0; i < 1; i++) {
213                 dev_id = ts_params->valid_devs[i];
214
215                 rte_cryptodev_info_get(dev_id, &info);
216
217                 /*
218                  * Since we can't free and re-allocate queue memory always set
219                  * the queues on this device up to max size first so enough
220                  * memory is allocated for any later re-configures needed by
221                  * other tests
222                  */
223
224                 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
225                 ts_params->conf.socket_id = SOCKET_ID_ANY;
226                 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
227
228                 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
229                                 &ts_params->conf),
230                                 "Failed to configure cryptodev %u with %u qps",
231                                 dev_id, ts_params->conf.nb_queue_pairs);
232
233                 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
234
235                 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
236                         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
237                                         dev_id, qp_id, &ts_params->qp_conf,
238                                         rte_cryptodev_socket_id(dev_id)),
239                                         "Failed to setup queue pair %u on "
240                                         "cryptodev %u",
241                                         qp_id, dev_id);
242                 }
243         }
244
245         return TEST_SUCCESS;
246 }
247
248 static void
249 testsuite_teardown(void)
250 {
251         struct crypto_testsuite_params *ts_params = &testsuite_params;
252
253         if (ts_params->mbuf_pool != NULL) {
254                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
255                 rte_mempool_count(ts_params->mbuf_pool));
256         }
257
258         if (ts_params->op_mpool != NULL) {
259                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
260                 rte_mempool_count(ts_params->op_mpool));
261         }
262
263 }
264
265 static int
266 ut_setup(void)
267 {
268         struct crypto_testsuite_params *ts_params = &testsuite_params;
269         struct crypto_unittest_params *ut_params = &unittest_params;
270
271         uint16_t qp_id;
272
273         /* Clear unit test parameters before running test */
274         memset(ut_params, 0, sizeof(*ut_params));
275
276         /* Reconfigure device to default parameters */
277         ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
278         ts_params->conf.socket_id = SOCKET_ID_ANY;
279         ts_params->conf.session_mp.nb_objs =
280                         (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
281                                         DEFAULT_NUM_OPS_INFLIGHT :
282                                         DEFAULT_NUM_OPS_INFLIGHT;
283
284         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
285                         &ts_params->conf),
286                         "Failed to configure cryptodev %u",
287                         ts_params->valid_devs[0]);
288
289         /*
290          * Now reconfigure queues to size we actually want to use in this
291          * test suite.
292          */
293         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
294
295         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
296                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
297                         ts_params->valid_devs[0], qp_id,
298                         &ts_params->qp_conf,
299                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
300                         "Failed to setup queue pair %u on cryptodev %u",
301                         qp_id, ts_params->valid_devs[0]);
302         }
303
304
305         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
306
307         /* Start the device */
308         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
309                         "Failed to start cryptodev %u",
310                         ts_params->valid_devs[0]);
311
312         return TEST_SUCCESS;
313 }
314
315 static void
316 ut_teardown(void)
317 {
318         struct crypto_testsuite_params *ts_params = &testsuite_params;
319         struct crypto_unittest_params *ut_params = &unittest_params;
320         struct rte_cryptodev_stats stats;
321
322         /* free crypto session structure */
323         if (ut_params->sess) {
324                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
325                                 ut_params->sess);
326                 ut_params->sess = NULL;
327         }
328
329         /* free crypto operation structure */
330         if (ut_params->op)
331                 rte_crypto_op_free(ut_params->op);
332
333         /*
334          * free mbuf - both obuf and ibuf are usually the same,
335          * but rte copes even if we call free twice
336          */
337         if (ut_params->obuf) {
338                 rte_pktmbuf_free(ut_params->obuf);
339                 ut_params->obuf = 0;
340         }
341         if (ut_params->ibuf) {
342                 rte_pktmbuf_free(ut_params->ibuf);
343                 ut_params->ibuf = 0;
344         }
345
346         if (ts_params->mbuf_pool != NULL)
347                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
348                                 rte_mempool_count(ts_params->mbuf_pool));
349
350         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
351
352         /* Stop the device */
353         rte_cryptodev_stop(ts_params->valid_devs[0]);
354 }
355
356 static int
357 test_device_configure_invalid_dev_id(void)
358 {
359         struct crypto_testsuite_params *ts_params = &testsuite_params;
360         uint16_t dev_id, num_devs = 0;
361
362         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
363                         "Need at least %d devices for test", 1);
364
365         /* valid dev_id values */
366         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
367
368         /* Stop the device in case it's started so it can be configured */
369         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
370
371         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
372                         "Failed test for rte_cryptodev_configure: "
373                         "invalid dev_num %u", dev_id);
374
375         /* invalid dev_id values */
376         dev_id = num_devs;
377
378         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
379                         "Failed test for rte_cryptodev_configure: "
380                         "invalid dev_num %u", dev_id);
381
382         dev_id = 0xff;
383
384         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
385                         "Failed test for rte_cryptodev_configure:"
386                         "invalid dev_num %u", dev_id);
387
388         return TEST_SUCCESS;
389 }
390
391 static int
392 test_device_configure_invalid_queue_pair_ids(void)
393 {
394         struct crypto_testsuite_params *ts_params = &testsuite_params;
395
396         /* Stop the device in case it's started so it can be configured */
397         rte_cryptodev_stop(ts_params->valid_devs[0]);
398
399         /* valid - one queue pairs */
400         ts_params->conf.nb_queue_pairs = 1;
401
402         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
403                         &ts_params->conf),
404                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
405                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
406
407
408         /* valid - max value queue pairs */
409         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
410
411         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
412                         &ts_params->conf),
413                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
414                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
415
416
417         /* invalid - zero queue pairs */
418         ts_params->conf.nb_queue_pairs = 0;
419
420         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
421                         &ts_params->conf),
422                         "Failed test for rte_cryptodev_configure, dev_id %u,"
423                         " invalid qps: %u",
424                         ts_params->valid_devs[0],
425                         ts_params->conf.nb_queue_pairs);
426
427
428         /* invalid - max value supported by field queue pairs */
429         ts_params->conf.nb_queue_pairs = UINT16_MAX;
430
431         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
432                         &ts_params->conf),
433                         "Failed test for rte_cryptodev_configure, dev_id %u,"
434                         " invalid qps: %u",
435                         ts_params->valid_devs[0],
436                         ts_params->conf.nb_queue_pairs);
437
438
439         /* invalid - max value + 1 queue pairs */
440         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
441
442         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
443                         &ts_params->conf),
444                         "Failed test for rte_cryptodev_configure, dev_id %u,"
445                         " invalid qps: %u",
446                         ts_params->valid_devs[0],
447                         ts_params->conf.nb_queue_pairs);
448
449         return TEST_SUCCESS;
450 }
451
452 static int
453 test_queue_pair_descriptor_setup(void)
454 {
455         struct crypto_testsuite_params *ts_params = &testsuite_params;
456         struct rte_cryptodev_info dev_info;
457         struct rte_cryptodev_qp_conf qp_conf = {
458                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
459         };
460
461         uint16_t qp_id;
462
463         /* Stop the device in case it's started so it can be configured */
464         rte_cryptodev_stop(ts_params->valid_devs[0]);
465
466
467         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
468
469         ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
470
471         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
472                         &ts_params->conf), "Failed to configure cryptodev %u",
473                         ts_params->valid_devs[0]);
474
475
476         /*
477          * Test various ring sizes on this device. memzones can't be
478          * freed so are re-used if ring is released and re-created.
479          */
480         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
481
482         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
483                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
484                                 ts_params->valid_devs[0], qp_id, &qp_conf,
485                                 rte_cryptodev_socket_id(
486                                                 ts_params->valid_devs[0])),
487                                 "Failed test for "
488                                 "rte_cryptodev_queue_pair_setup: num_inflights "
489                                 "%u on qp %u on cryptodev %u",
490                                 qp_conf.nb_descriptors, qp_id,
491                                 ts_params->valid_devs[0]);
492         }
493
494         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
495
496         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
497                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
498                                 ts_params->valid_devs[0], qp_id, &qp_conf,
499                                 rte_cryptodev_socket_id(
500                                                 ts_params->valid_devs[0])),
501                                 "Failed test for"
502                                 " rte_cryptodev_queue_pair_setup: num_inflights"
503                                 " %u on qp %u on cryptodev %u",
504                                 qp_conf.nb_descriptors, qp_id,
505                                 ts_params->valid_devs[0]);
506         }
507
508         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
509
510         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
511                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
512                                 ts_params->valid_devs[0], qp_id, &qp_conf,
513                                 rte_cryptodev_socket_id(
514                                                 ts_params->valid_devs[0])),
515                                 "Failed test for "
516                                 "rte_cryptodev_queue_pair_setup: num_inflights"
517                                 " %u on qp %u on cryptodev %u",
518                                 qp_conf.nb_descriptors, qp_id,
519                                 ts_params->valid_devs[0]);
520         }
521
522         /* invalid number of descriptors - max supported + 2 */
523         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
524
525         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
526                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
527                                 ts_params->valid_devs[0], qp_id, &qp_conf,
528                                 rte_cryptodev_socket_id(
529                                                 ts_params->valid_devs[0])),
530                                 "Unexpectedly passed test for "
531                                 "rte_cryptodev_queue_pair_setup:"
532                                 "num_inflights %u on qp %u on cryptodev %u",
533                                 qp_conf.nb_descriptors, qp_id,
534                                 ts_params->valid_devs[0]);
535         }
536
537         /* invalid number of descriptors - max value of parameter */
538         qp_conf.nb_descriptors = UINT32_MAX-1;
539
540         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
541                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
542                                 ts_params->valid_devs[0], qp_id, &qp_conf,
543                                 rte_cryptodev_socket_id(
544                                                 ts_params->valid_devs[0])),
545                                 "Unexpectedly passed test for "
546                                 "rte_cryptodev_queue_pair_setup:"
547                                 "num_inflights %u on qp %u on cryptodev %u",
548                                 qp_conf.nb_descriptors, qp_id,
549                                 ts_params->valid_devs[0]);
550         }
551
552         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
553
554         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
555                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
556                                 ts_params->valid_devs[0], qp_id, &qp_conf,
557                                 rte_cryptodev_socket_id(
558                                                 ts_params->valid_devs[0])),
559                                 "Failed test for"
560                                 " rte_cryptodev_queue_pair_setup:"
561                                 "num_inflights %u on qp %u on cryptodev %u",
562                                 qp_conf.nb_descriptors, qp_id,
563                                 ts_params->valid_devs[0]);
564         }
565
566         /* invalid number of descriptors - max supported + 1 */
567         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
568
569         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
570                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
571                                 ts_params->valid_devs[0], qp_id, &qp_conf,
572                                 rte_cryptodev_socket_id(
573                                                 ts_params->valid_devs[0])),
574                                 "Unexpectedly passed test for "
575                                 "rte_cryptodev_queue_pair_setup:"
576                                 "num_inflights %u on qp %u on cryptodev %u",
577                                 qp_conf.nb_descriptors, qp_id,
578                                 ts_params->valid_devs[0]);
579         }
580
581         /* test invalid queue pair id */
582         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
583
584         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
585
586         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
587                         ts_params->valid_devs[0],
588                         qp_id, &qp_conf,
589                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
590                         "Failed test for rte_cryptodev_queue_pair_setup:"
591                         "invalid qp %u on cryptodev %u",
592                         qp_id, ts_params->valid_devs[0]);
593
594         qp_id = 0xffff; /*invalid*/
595
596         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
597                         ts_params->valid_devs[0],
598                         qp_id, &qp_conf,
599                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
600                         "Failed test for rte_cryptodev_queue_pair_setup:"
601                         "invalid qp %u on cryptodev %u",
602                         qp_id, ts_params->valid_devs[0]);
603
604         return TEST_SUCCESS;
605 }
606
607 /* ***** Plaintext data for tests ***** */
608
609 const char catch_22_quote_1[] =
610                 "There was only one catch and that was Catch-22, which "
611                 "specified that a concern for one's safety in the face of "
612                 "dangers that were real and immediate was the process of a "
613                 "rational mind. Orr was crazy and could be grounded. All he "
614                 "had to do was ask; and as soon as he did, he would no longer "
615                 "be crazy and would have to fly more missions. Orr would be "
616                 "crazy to fly more missions and sane if he didn't, but if he "
617                 "was sane he had to fly them. If he flew them he was crazy "
618                 "and didn't have to; but if he didn't want to he was sane and "
619                 "had to. Yossarian was moved very deeply by the absolute "
620                 "simplicity of this clause of Catch-22 and let out a "
621                 "respectful whistle. \"That's some catch, that Catch-22\", he "
622                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
623
624 const char catch_22_quote[] =
625                 "What a lousy earth! He wondered how many people were "
626                 "destitute that same night even in his own prosperous country, "
627                 "how many homes were shanties, how many husbands were drunk "
628                 "and wives socked, and how many children were bullied, abused, "
629                 "or abandoned. How many families hungered for food they could "
630                 "not afford to buy? How many hearts were broken? How many "
631                 "suicides would take place that same night, how many people "
632                 "would go insane? How many cockroaches and landlords would "
633                 "triumph? How many winners were losers, successes failures, "
634                 "and rich men poor men? How many wise guys were stupid? How "
635                 "many happy endings were unhappy endings? How many honest men "
636                 "were liars, brave men cowards, loyal men traitors, how many "
637                 "sainted men were corrupt, how many people in positions of "
638                 "trust had sold their souls to bodyguards, how many had never "
639                 "had souls? How many straight-and-narrow paths were crooked "
640                 "paths? How many best families were worst families and how "
641                 "many good people were bad people? When you added them all up "
642                 "and then subtracted, you might be left with only the children, "
643                 "and perhaps with Albert Einstein and an old violinist or "
644                 "sculptor somewhere.";
645
646 #define QUOTE_480_BYTES         (480)
647 #define QUOTE_512_BYTES         (512)
648 #define QUOTE_768_BYTES         (768)
649 #define QUOTE_1024_BYTES        (1024)
650
651
652
653 /* ***** SHA1 Hash Tests ***** */
654
655 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
656
657 static uint8_t hmac_sha1_key[] = {
658         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
659         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
660         0xDE, 0xF4, 0xDE, 0xAD };
661
662 /* ***** SHA224 Hash Tests ***** */
663
664 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
665
666
667 /* ***** AES-CBC Cipher Tests ***** */
668
669 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
670 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
671
672 static uint8_t aes_cbc_key[] = {
673         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
674         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
675
676 static uint8_t aes_cbc_iv[] = {
677         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
678         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
679
680
681 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
682
683 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
684         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
685         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
686         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
687         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
688         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
689         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
690         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
691         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
692         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
693         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
694         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
695         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
696         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
697         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
698         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
699         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
700         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
701         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
702         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
703         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
704         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
705         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
706         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
707         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
708         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
709         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
710         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
711         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
712         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
713         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
714         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
715         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
716         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
717         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
718         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
719         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
720         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
721         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
722         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
723         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
724         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
725         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
726         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
727         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
728         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
729         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
730         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
731         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
732         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
733         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
734         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
735         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
736         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
737         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
738         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
739         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
740         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
741         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
742         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
743         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
744         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
745         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
746         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
747         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
748 };
749
750 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
751         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
752         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
753         0x18, 0x8c, 0x1d, 0x32
754 };
755
756
757 static int
758 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
759 {
760         struct crypto_testsuite_params *ts_params = &testsuite_params;
761         struct crypto_unittest_params *ut_params = &unittest_params;
762
763         /* Generate test mbuf data and space for digest */
764         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
765                         catch_22_quote, QUOTE_512_BYTES, 0);
766
767         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
768                         DIGEST_BYTE_LENGTH_SHA1);
769         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
770
771         /* Setup Cipher Parameters */
772         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
773         ut_params->cipher_xform.next = &ut_params->auth_xform;
774
775         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
776         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
777         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
778         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
779
780         /* Setup HMAC Parameters */
781         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
782
783         ut_params->auth_xform.next = NULL;
784
785         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
786         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
787         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
788         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
789         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
790
791         /* Create crypto session*/
792         ut_params->sess = rte_cryptodev_sym_session_create(
793                         ts_params->valid_devs[0],
794                         &ut_params->cipher_xform);
795         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
796
797         /* Generate crypto op data structure */
798         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
799                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
800         TEST_ASSERT_NOT_NULL(ut_params->op,
801                         "Failed to allocate symmetric crypto operation struct");
802
803         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
804
805         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
806
807         /* set crypto operation source mbuf */
808         sym_op->m_src = ut_params->ibuf;
809
810         /* Set crypto operation authentication parameters */
811         sym_op->auth.digest.data = ut_params->digest;
812         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
813                         ut_params->ibuf, QUOTE_512_BYTES);
814         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
815
816         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
817         sym_op->auth.data.length = QUOTE_512_BYTES;
818
819         /* Set crypto operation cipher parameters */
820         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
821                         CIPHER_IV_LENGTH_AES_CBC);
822         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
823         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
824
825         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
826                         CIPHER_IV_LENGTH_AES_CBC);
827
828         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
829         sym_op->cipher.data.length = QUOTE_512_BYTES;
830
831         /* Process crypto operation */
832         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
833                         ut_params->op), "failed to process sym crypto op");
834
835         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
836                         "crypto op processing failed");
837
838         /* Validate obuf */
839         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
840                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
841
842         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
843                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
844                         QUOTE_512_BYTES,
845                         "ciphertext data not as expected");
846
847         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
848
849         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
850                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
851                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
852                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
853                                         DIGEST_BYTE_LENGTH_SHA1,
854                         "Generated digest data not as expected");
855
856         return TEST_SUCCESS;
857 }
858
859 static int
860 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
861 {
862         struct crypto_testsuite_params *ts_params = &testsuite_params;
863         struct crypto_unittest_params *ut_params = &unittest_params;
864
865         /* Generate test mbuf data and space for digest */
866         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
867                         catch_22_quote, QUOTE_512_BYTES, 0);
868
869         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
870                         DIGEST_BYTE_LENGTH_SHA1);
871         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
872
873         /* Generate Crypto op data structure */
874         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
875                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
876         TEST_ASSERT_NOT_NULL(ut_params->op,
877                         "Failed to allocate symmetric crypto operation struct");
878
879         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
880                         "failed to allocate space for crypto transforms");
881
882         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
883
884         /* set crypto operation source mbuf */
885         sym_op->m_src = ut_params->ibuf;
886
887         /* Set crypto operation data parameters */
888         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
889
890         /* cipher parameters */
891         sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
892         sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
893         sym_op->xform->cipher.key.data = aes_cbc_key;
894         sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
895
896         /* hash parameters */
897         sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
898
899         sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
900         sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
901         sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
902         sym_op->xform->next->auth.key.data = hmac_sha1_key;
903         sym_op->xform->next->auth.digest_length =
904                         DIGEST_BYTE_LENGTH_SHA1;
905
906         sym_op->auth.digest.data = ut_params->digest;
907         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
908                         ut_params->ibuf, QUOTE_512_BYTES);
909         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
910
911
912         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
913         sym_op->auth.data.length = QUOTE_512_BYTES;
914
915         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
916                         CIPHER_IV_LENGTH_AES_CBC);
917         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
918         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
919
920         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
921                         CIPHER_IV_LENGTH_AES_CBC);
922
923         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
924         sym_op->cipher.data.length = QUOTE_512_BYTES;
925
926         /* Process crypto operation */
927         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
928                         ut_params->op), "failed to process sym crypto op");
929
930         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
931                         "crypto op processing failed");
932
933         ut_params->obuf = ut_params->op->sym->m_src;
934
935         /* Validate obuf */
936         TEST_ASSERT_BUFFERS_ARE_EQUAL(
937                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
938                         CIPHER_IV_LENGTH_AES_CBC,
939                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
940                         QUOTE_512_BYTES,
941                         "Ciphertext data not as expected");
942
943         TEST_ASSERT_BUFFERS_ARE_EQUAL(
944                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
945                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
946                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
947                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
948                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
949                                         DIGEST_BYTE_LENGTH_SHA1,
950                         "Generated digest data not as expected");
951
952
953         return TEST_SUCCESS;
954 }
955
956 static int
957 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
958 {
959         struct crypto_testsuite_params *ts_params = &testsuite_params;
960         struct crypto_unittest_params *ut_params = &unittest_params;
961
962         /* Generate test mbuf data and digest */
963         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
964                         (const char *)
965                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
966                         QUOTE_512_BYTES, 0);
967
968         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
969                         DIGEST_BYTE_LENGTH_SHA1);
970         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
971
972         rte_memcpy(ut_params->digest,
973                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
974                         DIGEST_BYTE_LENGTH_SHA1);
975
976         /* Setup Cipher Parameters */
977         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
978         ut_params->cipher_xform.next = NULL;
979
980         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
981         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
982         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
983         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
984
985         /* Setup HMAC Parameters */
986         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
987         ut_params->auth_xform.next = &ut_params->cipher_xform;
988
989         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
990         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
991         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
992         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
993         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
994
995         /* Create Crypto session*/
996         ut_params->sess =
997                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
998                                                 &ut_params->auth_xform);
999         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1000
1001         /* Generate Crypto op data structure */
1002         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1003                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1004         TEST_ASSERT_NOT_NULL(ut_params->op,
1005                         "Failed to allocate symmetric crypto operation struct");
1006
1007         /* attach symmetric crypto session to crypto operations */
1008         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1009
1010         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1011
1012         /* set crypto operation source mbuf */
1013         sym_op->m_src = ut_params->ibuf;
1014
1015         sym_op->auth.digest.data = ut_params->digest;
1016         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1017                         ut_params->ibuf, QUOTE_512_BYTES);
1018         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1019
1020         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1021         sym_op->auth.data.length = QUOTE_512_BYTES;
1022
1023         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1024                         CIPHER_IV_LENGTH_AES_CBC);
1025         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1026         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1027
1028         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1029                         CIPHER_IV_LENGTH_AES_CBC);
1030
1031         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1032         sym_op->cipher.data.length = QUOTE_512_BYTES;
1033
1034
1035         /* Process crypto operation */
1036         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1037                         ut_params->op), "failed to process sym crypto op");
1038
1039         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1040                         "crypto op processing failed");
1041
1042         ut_params->obuf = ut_params->op->sym->m_src;
1043
1044
1045         /* Validate obuf */
1046         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1047                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1048                         CIPHER_IV_LENGTH_AES_CBC,
1049                         catch_22_quote,
1050                         QUOTE_512_BYTES,
1051                         "Ciphertext data not as expected");
1052
1053         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1054                         "Digest verification failed");
1055
1056
1057         return TEST_SUCCESS;
1058 }
1059
1060
1061 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1062
1063 #define HMAC_KEY_LENGTH_SHA256  (DIGEST_BYTE_LENGTH_SHA256)
1064
1065 static uint8_t hmac_sha256_key[] = {
1066         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1067         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1068         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1069         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1070
1071 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1072         0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1073         0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1074         0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1075         0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1076
1077 static int
1078 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1079 {
1080         struct crypto_testsuite_params *ts_params = &testsuite_params;
1081         struct crypto_unittest_params *ut_params = &unittest_params;
1082
1083         /* Generate test mbuf data and space for digest */
1084         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1085                         catch_22_quote, QUOTE_512_BYTES, 0);
1086
1087         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1088                         DIGEST_BYTE_LENGTH_SHA256);
1089         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1090
1091         /* Setup Cipher Parameters */
1092         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1093         ut_params->cipher_xform.next = &ut_params->auth_xform;
1094
1095         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1096         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1097         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1098         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1099
1100         /* Setup HMAC Parameters */
1101         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1102         ut_params->auth_xform.next = NULL;
1103
1104         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1105         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1106         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1107         ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1108         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1109
1110         /* Create Crypto session*/
1111         ut_params->sess = rte_cryptodev_sym_session_create(
1112                         ts_params->valid_devs[0],
1113                         &ut_params->cipher_xform);
1114         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1115
1116         /* Generate Crypto op data structure */
1117         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1118                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1119         TEST_ASSERT_NOT_NULL(ut_params->op,
1120                         "Failed to allocate symmetric crypto operation struct");
1121
1122         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1123
1124         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1125
1126         /* set crypto operation source mbuf */
1127         sym_op->m_src = ut_params->ibuf;
1128
1129         sym_op->auth.digest.data = ut_params->digest;
1130         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1131                         ut_params->ibuf, QUOTE_512_BYTES);
1132         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1133
1134         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1135         sym_op->auth.data.length = QUOTE_512_BYTES;
1136
1137         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1138                         CIPHER_IV_LENGTH_AES_CBC);
1139         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1140         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1141
1142         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1143                         CIPHER_IV_LENGTH_AES_CBC);
1144
1145         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1146         sym_op->cipher.data.length = QUOTE_512_BYTES;
1147
1148         /* Process crypto operation */
1149         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1150                         ut_params->op), "failed to process sym crypto op");
1151
1152         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1153                         "crypto op processing failed");
1154
1155         ut_params->obuf = ut_params->op->sym->m_src;
1156
1157         /* Validate obuf */
1158         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1159                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1160                         CIPHER_IV_LENGTH_AES_CBC,
1161                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1162                         QUOTE_512_BYTES,
1163                         "Ciphertext data not as expected");
1164
1165         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1166                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1167                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1168                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1169                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1170                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1171                                         DIGEST_BYTE_LENGTH_SHA256,
1172                         "Generated digest data not as expected");
1173
1174
1175         return TEST_SUCCESS;
1176 }
1177
1178 static int
1179 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1180 {
1181         struct crypto_testsuite_params *ts_params = &testsuite_params;
1182         struct crypto_unittest_params *ut_params = &unittest_params;
1183
1184         /* Generate test mbuf data and digest */
1185         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1186                         (const char *)
1187                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1188                         QUOTE_512_BYTES, 0);
1189
1190         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1191                         DIGEST_BYTE_LENGTH_SHA256);
1192         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1193
1194         rte_memcpy(ut_params->digest,
1195                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1196                         DIGEST_BYTE_LENGTH_SHA256);
1197
1198         /* Setup Cipher Parameters */
1199         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1200         ut_params->cipher_xform.next = NULL;
1201
1202         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1203         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1204         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1205         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1206
1207         /* Setup HMAC Parameters */
1208         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1209         ut_params->auth_xform.next = &ut_params->cipher_xform;
1210
1211         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1212         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1213         ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1214         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1215         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1216
1217         /* Create Crypto session*/
1218         ut_params->sess =
1219                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1220                                                 &ut_params->auth_xform);
1221         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1222
1223         /* Generate Crypto op data structure */
1224         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1225                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1226         TEST_ASSERT_NOT_NULL(ut_params->op,
1227                         "Failed to allocate symmetric crypto operation struct");
1228
1229
1230         /* Set crypto operation data parameters */
1231         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1232
1233         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1234
1235         /* set crypto operation source mbuf */
1236         sym_op->m_src = ut_params->ibuf;
1237
1238         sym_op->auth.digest.data = ut_params->digest;
1239         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1240                         ut_params->ibuf, QUOTE_512_BYTES);
1241         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1242
1243         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1244         sym_op->auth.data.length = QUOTE_512_BYTES;
1245
1246         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1247                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1248         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1249         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1250
1251         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1252                         CIPHER_IV_LENGTH_AES_CBC);
1253
1254         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1255         sym_op->cipher.data.length = QUOTE_512_BYTES;
1256
1257         /* Process crypto operation */
1258         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1259                         ut_params->op), "failed to process sym crypto op");
1260
1261         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1262                         "crypto op processing failed");
1263
1264         ut_params->obuf = ut_params->op->sym->m_src;
1265
1266         /* Validate obuf */
1267         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1268                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1269                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1270                         QUOTE_512_BYTES,
1271                         "Plaintext data not as expected");
1272
1273         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1274                         "Digest verification failed");
1275
1276         return TEST_SUCCESS;
1277 }
1278
1279 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1280
1281 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1282
1283 static uint8_t hmac_sha512_key[] = {
1284         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1285         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1286         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1287         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1288         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1289         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1290         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1291         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1292
1293 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1294         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1295         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1296         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1297         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1298         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1299         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1300         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1301         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1302
1303 static int
1304 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1305 {
1306         struct crypto_testsuite_params *ts_params = &testsuite_params;
1307         struct crypto_unittest_params *ut_params = &unittest_params;
1308
1309         /* Generate test mbuf data and space for digest */
1310         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1311                         catch_22_quote, QUOTE_512_BYTES, 0);
1312
1313         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1314                         DIGEST_BYTE_LENGTH_SHA512);
1315         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1316
1317         /* Setup Cipher Parameters */
1318         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1319         ut_params->cipher_xform.next = &ut_params->auth_xform;
1320
1321         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1322         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1323         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1324         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1325
1326         /* Setup HMAC Parameters */
1327         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1328         ut_params->auth_xform.next = NULL;
1329
1330         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1331         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1332         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1333         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1334         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1335
1336         /* Create Crypto session*/
1337         ut_params->sess =
1338                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1339                                                 &ut_params->cipher_xform);
1340
1341         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1342
1343         /* Generate Crypto op data structure */
1344         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1345                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1346         TEST_ASSERT_NOT_NULL(ut_params->op,
1347                         "Failed to allocate symmetric crypto operation struct");
1348
1349         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1350
1351         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1352
1353         /* set crypto operation source mbuf */
1354         sym_op->m_src = ut_params->ibuf;
1355
1356         sym_op->auth.digest.data = ut_params->digest;
1357         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1358                         ut_params->ibuf, QUOTE_512_BYTES);
1359         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1360
1361         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1362         sym_op->auth.data.length = QUOTE_512_BYTES;
1363
1364         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1365                         CIPHER_IV_LENGTH_AES_CBC);
1366         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1367         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1368
1369         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1370                         CIPHER_IV_LENGTH_AES_CBC);
1371
1372         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1373         sym_op->cipher.data.length = QUOTE_512_BYTES;
1374
1375         /* Process crypto operation */
1376         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1377                         ut_params->op), "failed to process sym crypto op");
1378
1379         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1380                         "crypto op processing failed");
1381
1382         ut_params->obuf = ut_params->op->sym->m_src;
1383
1384         /* Validate obuf */
1385         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1386                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1387                         CIPHER_IV_LENGTH_AES_CBC,
1388                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1389                         QUOTE_512_BYTES,
1390                         "Ciphertext data not as expected");
1391
1392         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1393                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1394                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1395                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1396                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1397                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1398                                         DIGEST_BYTE_LENGTH_SHA512,
1399                         "Generated digest data not as expected");
1400
1401         return TEST_SUCCESS;
1402 }
1403
1404
1405 static int
1406 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1407                 struct crypto_unittest_params *ut_params);
1408
1409 static int
1410 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1411                 struct crypto_unittest_params *ut_params,
1412                 struct crypto_testsuite_params *ts_params);
1413
1414 static int
1415 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1416 {
1417         struct crypto_unittest_params *ut_params = &unittest_params;
1418         struct crypto_testsuite_params *ts_params = &testsuite_params;
1419
1420         TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1421                         ut_params) == TEST_SUCCESS,
1422                         "Failed to create session params");
1423
1424         /* Create Crypto session*/
1425         ut_params->sess =
1426                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1427                                                 &ut_params->auth_xform);
1428         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1429
1430         return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1431                         ut_params, ts_params);
1432 }
1433
1434 static int
1435 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1436                 struct crypto_unittest_params *ut_params)
1437 {
1438
1439         /* Setup Cipher Parameters */
1440         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1441         ut_params->cipher_xform.next = NULL;
1442
1443         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1444         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1445         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1446         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1447
1448         /* Setup HMAC Parameters */
1449         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1450         ut_params->auth_xform.next = &ut_params->cipher_xform;
1451
1452         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1453         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1454         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1455         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1456         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1457
1458         return TEST_SUCCESS;
1459 }
1460
1461
1462 static int
1463 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1464                 struct crypto_unittest_params *ut_params,
1465                 struct crypto_testsuite_params *ts_params)
1466 {
1467         /* Generate test mbuf data and digest */
1468         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1469                         (const char *)
1470                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1471                         QUOTE_512_BYTES, 0);
1472
1473         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1474                         DIGEST_BYTE_LENGTH_SHA512);
1475         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1476
1477         rte_memcpy(ut_params->digest,
1478                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1479                         DIGEST_BYTE_LENGTH_SHA512);
1480
1481         /* Generate Crypto op data structure */
1482         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1483                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1484         TEST_ASSERT_NOT_NULL(ut_params->op,
1485                         "Failed to allocate symmetric crypto operation struct");
1486
1487         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1488
1489         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1490
1491         /* set crypto operation source mbuf */
1492         sym_op->m_src = ut_params->ibuf;
1493
1494         sym_op->auth.digest.data = ut_params->digest;
1495         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1496                         ut_params->ibuf, QUOTE_512_BYTES);
1497         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1498
1499         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1500         sym_op->auth.data.length = QUOTE_512_BYTES;
1501
1502         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1503                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1504         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1505                         ut_params->ibuf, 0);
1506         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1507
1508         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1509                         CIPHER_IV_LENGTH_AES_CBC);
1510
1511         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1512         sym_op->cipher.data.length = QUOTE_512_BYTES;
1513
1514         /* Process crypto operation */
1515         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1516                         ut_params->op), "failed to process sym crypto op");
1517
1518         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1519                         "crypto op processing failed");
1520
1521         ut_params->obuf = ut_params->op->sym->m_src;
1522
1523         /* Validate obuf */
1524         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1525                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1526                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1527                         QUOTE_512_BYTES,
1528                         "Plaintext data not as expected");
1529
1530         /* Validate obuf */
1531         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1532                         "Digest verification failed");
1533
1534         return TEST_SUCCESS;
1535 }
1536
1537 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1538
1539 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1540         0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1541         0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1542         };
1543
1544 static const uint8_t  catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1545         0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1546         0x77, 0x1D, 0x8B, 0x75
1547         };
1548
1549 static int
1550 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1551 {
1552         struct crypto_testsuite_params *ts_params = &testsuite_params;
1553         struct crypto_unittest_params *ut_params = &unittest_params;
1554
1555         /* Generate test mbuf data and space for digest */
1556         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1557                         catch_22_quote, QUOTE_512_BYTES, 0);
1558
1559         /* Setup Cipher Parameters */
1560         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1561         ut_params->cipher_xform.next = &ut_params->auth_xform;
1562
1563         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1564         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1565         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1566         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1567
1568         /* Setup HMAC Parameters */
1569         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1570         ut_params->auth_xform.next = NULL;
1571
1572         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1573         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1574         ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1575         ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1576         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1577
1578         /* Create Crypto session*/
1579         ut_params->sess = rte_cryptodev_sym_session_create(
1580                         ts_params->valid_devs[0],
1581                         &ut_params->cipher_xform);
1582         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1583
1584         /* Generate Crypto op data structure */
1585         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1586                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1587         TEST_ASSERT_NOT_NULL(ut_params->op,
1588                         "Failed to allocate symmetric crypto operation struct");
1589
1590         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1591
1592         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1593
1594         /* set crypto operation source mbuf */
1595         sym_op->m_src = ut_params->ibuf;
1596
1597         /* Set operation cipher parameters */
1598         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1599                         sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1600         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1601         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1602
1603         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1604                         CIPHER_IV_LENGTH_AES_CBC);
1605
1606         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1607         sym_op->cipher.data.length = QUOTE_512_BYTES;
1608
1609         /* Set operation authentication parameters */
1610         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1611                         sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1612         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1613                         sym_op->m_src,
1614                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1615         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1616
1617         memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1618
1619         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1620         sym_op->auth.data.length = QUOTE_512_BYTES;
1621
1622
1623         /* Process crypto operation */
1624         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1625                         ut_params->op);
1626         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1627
1628         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1629                         "crypto op processing failed");
1630
1631         /* Validate obuf */
1632         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1633                         rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1634                                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1635                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1636                         QUOTE_512_BYTES,
1637                         "Ciphertext data not as expected");
1638
1639         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1640                         rte_pktmbuf_mtod_offset(
1641                                         ut_params->op->sym->m_src, uint8_t *,
1642                                         CIPHER_IV_LENGTH_AES_CBC +
1643                                         QUOTE_512_BYTES),
1644                         catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1645                         DIGEST_BYTE_LENGTH_AES_XCBC,
1646                         "Generated digest data not as expected");
1647
1648         return TEST_SUCCESS;
1649 }
1650
1651 static int
1652 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1653 {
1654         struct crypto_testsuite_params *ts_params = &testsuite_params;
1655         struct crypto_unittest_params *ut_params = &unittest_params;
1656
1657         /* Generate test mbuf data and space for digest */
1658         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1659                 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1660                 QUOTE_512_BYTES, 0);
1661
1662         /* Setup Cipher Parameters */
1663         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1664         ut_params->cipher_xform.next = NULL;
1665
1666         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1667         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1668         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1669         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1670
1671         /* Setup HMAC Parameters */
1672         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1673         ut_params->auth_xform.next = &ut_params->cipher_xform;
1674
1675         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1676         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1677         ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1678         ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1679         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1680
1681         /* Create Crypto session*/
1682         ut_params->sess =
1683                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1684                                                 &ut_params->auth_xform);
1685         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1686
1687         /* Generate Crypto op data structure */
1688         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1689                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1690         TEST_ASSERT_NOT_NULL(ut_params->op,
1691                         "Failed to allocate symmetric crypto operation struct");
1692
1693         /* Set crypto operation data parameters */
1694         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1695
1696         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1697
1698         /* set crypto operation source mbuf */
1699         sym_op->m_src = ut_params->ibuf;
1700
1701
1702         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1703                                 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
1704         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1705                         "no room to append digest");
1706
1707         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1708                         ut_params->ibuf, QUOTE_512_BYTES);
1709         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1710
1711         rte_memcpy(sym_op->auth.digest.data,
1712                         catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1713                         DIGEST_BYTE_LENGTH_AES_XCBC);
1714
1715         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1716         sym_op->auth.data.length = QUOTE_512_BYTES;
1717
1718         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1719                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1720         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1721         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1722
1723         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1724                         CIPHER_IV_LENGTH_AES_CBC);
1725
1726         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1727         sym_op->cipher.data.length = QUOTE_512_BYTES;
1728
1729         /* Process crypto operation */
1730         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1731                         ut_params->op), "failed to process sym crypto op");
1732
1733         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1734                         "crypto op processing failed");
1735
1736         ut_params->obuf = ut_params->op->sym->m_src;
1737
1738         /* Validate obuf */
1739         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1740                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1741                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1742                         QUOTE_512_BYTES,
1743                         "Ciphertext data not as expected");
1744
1745         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1746                         "Digest verification failed");
1747
1748         return TEST_SUCCESS;
1749 }
1750
1751
1752 /* ***** AES-GCM Tests ***** */
1753
1754 static int
1755 test_stats(void)
1756 {
1757         struct crypto_testsuite_params *ts_params = &testsuite_params;
1758         struct rte_cryptodev_stats stats;
1759         struct rte_cryptodev *dev;
1760         cryptodev_stats_get_t temp_pfn;
1761
1762         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1763         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
1764                         &stats) == -ENODEV),
1765                 "rte_cryptodev_stats_get invalid dev failed");
1766         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
1767                 "rte_cryptodev_stats_get invalid Param failed");
1768         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
1769         temp_pfn = dev->dev_ops->stats_get;
1770         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
1771         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
1772                         == -ENOTSUP),
1773                 "rte_cryptodev_stats_get invalid Param failed");
1774         dev->dev_ops->stats_get = temp_pfn;
1775
1776         /* Test expected values */
1777         ut_setup();
1778         test_AES_CBC_HMAC_SHA1_encrypt_digest();
1779         ut_teardown();
1780         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1781                         &stats),
1782                 "rte_cryptodev_stats_get failed");
1783         TEST_ASSERT((stats.enqueued_count == 1),
1784                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1785         TEST_ASSERT((stats.dequeued_count == 1),
1786                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1787         TEST_ASSERT((stats.enqueue_err_count == 0),
1788                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1789         TEST_ASSERT((stats.dequeue_err_count == 0),
1790                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1791
1792         /* invalid device but should ignore and not reset device stats*/
1793         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
1794         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1795                         &stats),
1796                 "rte_cryptodev_stats_get failed");
1797         TEST_ASSERT((stats.enqueued_count == 1),
1798                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1799
1800         /* check that a valid reset clears stats */
1801         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1802         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1803                         &stats),
1804                                           "rte_cryptodev_stats_get failed");
1805         TEST_ASSERT((stats.enqueued_count == 0),
1806                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1807         TEST_ASSERT((stats.dequeued_count == 0),
1808                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1809
1810         return TEST_SUCCESS;
1811 }
1812
1813
1814 static int
1815 test_multi_session(void)
1816 {
1817         struct crypto_testsuite_params *ts_params = &testsuite_params;
1818         struct crypto_unittest_params *ut_params = &unittest_params;
1819
1820         struct rte_cryptodev_info dev_info;
1821         struct rte_cryptodev_sym_session **sessions;
1822
1823         uint16_t i;
1824
1825         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1826
1827
1828         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
1829
1830         sessions = rte_malloc(NULL,
1831                         (sizeof(struct rte_cryptodev_sym_session *) *
1832                         dev_info.sym.max_nb_sessions) + 1, 0);
1833
1834         /* Create multiple crypto sessions*/
1835         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
1836                 sessions[i] = rte_cryptodev_sym_session_create(
1837                                 ts_params->valid_devs[0],
1838                         &ut_params->auth_xform);
1839                 TEST_ASSERT_NOT_NULL(sessions[i],
1840                                 "Session creation failed at session number %u",
1841                                 i);
1842
1843                 /* Attempt to send a request on each session */
1844                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
1845                                 sessions[i], ut_params, ts_params),
1846                                 "Failed to perform decrypt on request "
1847                                 "number %u.", i);
1848         }
1849
1850         /* Next session create should fail */
1851         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1852                         &ut_params->auth_xform);
1853         TEST_ASSERT_NULL(sessions[i],
1854                         "Session creation succeeded unexpectedly!");
1855
1856         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
1857                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
1858                                 sessions[i]);
1859
1860         rte_free(sessions);
1861
1862         return TEST_SUCCESS;
1863 }
1864
1865 static int
1866 test_not_in_place_crypto(void)
1867 {
1868         struct crypto_testsuite_params *ts_params = &testsuite_params;
1869         struct crypto_unittest_params *ut_params = &unittest_params;
1870         struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1871
1872         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1873
1874         /* Create multiple crypto sessions*/
1875
1876         ut_params->sess = rte_cryptodev_sym_session_create(
1877                         ts_params->valid_devs[0], &ut_params->auth_xform);
1878
1879         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1880
1881
1882         /* Generate test mbuf data and digest */
1883         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1884                         (const char *)
1885                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1886                         QUOTE_512_BYTES, 0);
1887
1888         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1889                         DIGEST_BYTE_LENGTH_SHA512);
1890         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1891
1892         rte_memcpy(ut_params->digest,
1893                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1894                         DIGEST_BYTE_LENGTH_SHA512);
1895
1896         /* Generate Crypto op data structure */
1897         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1898                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1899         TEST_ASSERT_NOT_NULL(ut_params->op,
1900                         "Failed to allocate symmetric crypto operation struct");
1901
1902
1903         /* Set crypto operation data parameters */
1904         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1905
1906         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1907
1908         /* set crypto operation source mbuf */
1909         sym_op->m_src = ut_params->ibuf;
1910         sym_op->m_dst = dst_m;
1911
1912         sym_op->auth.digest.data = ut_params->digest;
1913         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1914                         ut_params->ibuf, QUOTE_512_BYTES);
1915         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1916
1917         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1918         sym_op->auth.data.length = QUOTE_512_BYTES;
1919
1920
1921         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1922                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1923         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1924                         ut_params->ibuf, 0);
1925         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1926
1927         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1928                         CIPHER_IV_LENGTH_AES_CBC);
1929
1930         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1931         sym_op->cipher.data.length = QUOTE_512_BYTES;
1932
1933         /* Process crypto operation */
1934         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1935                         ut_params->op);
1936         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
1937
1938         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1939                         "crypto operation processing failed");
1940
1941         /* Validate obuf */
1942         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1943                         rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
1944                         catch_22_quote,
1945                         QUOTE_512_BYTES,
1946                         "Plaintext data not as expected");
1947
1948         /* Validate obuf */
1949
1950         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1951                         "Digest verification failed");
1952
1953         return TEST_SUCCESS;
1954 }
1955
1956
1957 static struct unit_test_suite cryptodev_qat_testsuite  = {
1958         .suite_name = "Crypto QAT Unit Test Suite",
1959         .setup = testsuite_setup,
1960         .teardown = testsuite_teardown,
1961         .unit_test_cases = {
1962                 TEST_CASE_ST(ut_setup, ut_teardown,
1963                                 test_device_configure_invalid_dev_id),
1964                 TEST_CASE_ST(ut_setup, ut_teardown,
1965                                 test_device_configure_invalid_queue_pair_ids),
1966                 TEST_CASE_ST(ut_setup, ut_teardown,
1967                                 test_queue_pair_descriptor_setup),
1968                 TEST_CASE_ST(ut_setup, ut_teardown,
1969                                 test_multi_session),
1970
1971                 TEST_CASE_ST(ut_setup, ut_teardown,
1972                                 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1973                 TEST_CASE_ST(ut_setup, ut_teardown,
1974                                 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1975
1976                 TEST_CASE_ST(ut_setup, ut_teardown,
1977                                 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1978                 TEST_CASE_ST(ut_setup, ut_teardown,
1979                                 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1980
1981                 TEST_CASE_ST(ut_setup, ut_teardown,
1982                                 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1983                 TEST_CASE_ST(ut_setup, ut_teardown,
1984                                 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1985
1986                 TEST_CASE_ST(ut_setup, ut_teardown,
1987                                 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1988                 TEST_CASE_ST(ut_setup, ut_teardown,
1989                                 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1990
1991                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
1992
1993                 TEST_CASES_END() /**< NULL terminate unit test array */
1994         }
1995 };
1996
1997 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
1998         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
1999         .setup = testsuite_setup,
2000         .teardown = testsuite_teardown,
2001         .unit_test_cases = {
2002                 TEST_CASE_ST(ut_setup, ut_teardown,
2003                         test_AES_CBC_HMAC_SHA1_encrypt_digest),
2004                 TEST_CASE_ST(ut_setup, ut_teardown,
2005                         test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
2006
2007                 TEST_CASE_ST(ut_setup, ut_teardown,
2008                         test_AES_CBC_HMAC_SHA256_encrypt_digest),
2009                 TEST_CASE_ST(ut_setup, ut_teardown,
2010                         test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
2011
2012                 TEST_CASE_ST(ut_setup, ut_teardown,
2013                         test_AES_CBC_HMAC_SHA512_encrypt_digest),
2014                 TEST_CASE_ST(ut_setup, ut_teardown,
2015                         test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
2016
2017                 TEST_CASE_ST(ut_setup, ut_teardown,
2018                         test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
2019                 TEST_CASE_ST(ut_setup, ut_teardown,
2020                         test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
2021
2022                 TEST_CASE_ST(ut_setup, ut_teardown,
2023                         test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
2024
2025                 TEST_CASE_ST(ut_setup, ut_teardown,
2026                         test_not_in_place_crypto),
2027
2028                 TEST_CASES_END() /**< NULL terminate unit test array */
2029         }
2030 };
2031
2032 static int
2033 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
2034 {
2035         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
2036         return unit_test_suite_runner(&cryptodev_qat_testsuite);
2037 }
2038 static struct test_command cryptodev_qat_cmd = {
2039         .command = "cryptodev_qat_autotest",
2040         .callback = test_cryptodev_qat,
2041 };
2042
2043 static int
2044 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
2045 {
2046         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
2047
2048         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
2049 }
2050
2051 static struct test_command cryptodev_aesni_mb_cmd = {
2052         .command = "cryptodev_aesni_mb_autotest",
2053         .callback = test_cryptodev_aesni_mb,
2054 };
2055
2056 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
2057 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);