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