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