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