aesni_mb: add AES-CTR
[dpdk.git] / app / test / test_cryptodev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Intel Corporation nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
42
43 #include "test.h"
44 #include "test_cryptodev.h"
45
46 #include "test_cryptodev_aes_ctr_test_vectors.h"
47 #include "test_cryptodev_snow3g_test_vectors.h"
48 #include "test_cryptodev_snow3g_hash_test_vectors.h"
49 #include "test_cryptodev_gcm_test_vectors.h"
50
51 static enum rte_cryptodev_type gbl_cryptodev_type;
52
53 struct crypto_testsuite_params {
54         struct rte_mempool *mbuf_pool;
55         struct rte_mempool *op_mpool;
56         struct rte_cryptodev_config conf;
57         struct rte_cryptodev_qp_conf qp_conf;
58
59         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
60         uint8_t valid_dev_count;
61 };
62
63 struct crypto_unittest_params {
64         struct rte_crypto_sym_xform cipher_xform;
65         struct rte_crypto_sym_xform auth_xform;
66
67         struct rte_cryptodev_sym_session *sess;
68
69         struct rte_crypto_op *op;
70
71         struct rte_mbuf *obuf, *ibuf;
72
73         uint8_t *digest;
74 };
75
76 #define ALIGN_POW2_ROUNDUP(num, align) \
77         (((num) + (align) - 1) & ~((align) - 1))
78
79 /*
80  * Forward declarations.
81  */
82 static int
83 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
84                 struct crypto_unittest_params *ut_params);
85
86 static int
87 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
88                 struct crypto_unittest_params *ut_params,
89                 struct crypto_testsuite_params *ts_param);
90
91 static struct rte_mbuf *
92 setup_test_string(struct rte_mempool *mpool,
93                 const char *string, size_t len, uint8_t blocksize)
94 {
95         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
96         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
97
98         memset(m->buf_addr, 0, m->buf_len);
99         if (m) {
100                 char *dst = rte_pktmbuf_append(m, t_len);
101
102                 if (!dst) {
103                         rte_pktmbuf_free(m);
104                         return NULL;
105                 }
106                 if (string != NULL)
107                         rte_memcpy(dst, string, t_len);
108                 else
109                         memset(dst, 0, t_len);
110         }
111
112         return m;
113 }
114 static int
115 setup_oop_test_mbufs(struct rte_mbuf **ibuf, struct rte_mbuf **obuf,
116                 struct rte_mempool *mpool,      const char *string, size_t len,
117                 uint8_t blocksize) {
118         *ibuf = setup_test_string(mpool, string, len, blocksize);
119         if (*ibuf == NULL)
120                 return -(EFAULT);
121         *obuf = setup_test_string(mpool, NULL, len, blocksize);
122         if (*obuf == NULL)
123                 return -(EFAULT);
124
125         return 0;
126 }
127
128 #if HEX_DUMP
129 static void
130 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
131 {
132         rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
133 }
134 #endif
135
136 static struct rte_crypto_op *
137 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
138 {
139 #if HEX_DUMP
140         hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
141 #endif
142
143         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
144                 printf("Error sending packet for encryption");
145                 return NULL;
146         }
147
148         op = NULL;
149
150         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
151                 rte_pause();
152
153 #if HEX_DUMP
154         if (obuf)
155                 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
156 #endif
157
158         return op;
159 }
160
161 static struct crypto_testsuite_params testsuite_params = { NULL };
162 static struct crypto_unittest_params unittest_params;
163
164 static int
165 testsuite_setup(void)
166 {
167         struct crypto_testsuite_params *ts_params = &testsuite_params;
168         struct rte_cryptodev_info info;
169         unsigned i, nb_devs, dev_id;
170         int ret;
171         uint16_t qp_id;
172
173         memset(ts_params, 0, sizeof(*ts_params));
174
175         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
176         if (ts_params->mbuf_pool == NULL) {
177                 /* Not already created so create */
178                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
179                                 "CRYPTO_MBUFPOOL",
180                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
181                                 rte_socket_id());
182                 if (ts_params->mbuf_pool == NULL) {
183                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
184                         return TEST_FAILED;
185                 }
186         }
187
188         ts_params->op_mpool = rte_crypto_op_pool_create(
189                         "MBUF_CRYPTO_SYM_OP_POOL",
190                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
191                         NUM_MBUFS, MBUF_CACHE_SIZE,
192                         DEFAULT_NUM_XFORMS *
193                         sizeof(struct rte_crypto_sym_xform),
194                         rte_socket_id());
195         if (ts_params->op_mpool == NULL) {
196                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
197                 return TEST_FAILED;
198         }
199
200         /* Create 2 AESNI MB devices if required */
201         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
202                 nb_devs = rte_cryptodev_count_devtype(
203                                 RTE_CRYPTODEV_AESNI_MB_PMD);
204                 if (nb_devs < 2) {
205                         for (i = nb_devs; i < 2; i++) {
206                                 ret = rte_eal_vdev_init(
207                                         CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
208
209                                 TEST_ASSERT(ret == 0,
210                                         "Failed to create instance %u of"
211                                         " pmd : %s",
212                                         i, CRYPTODEV_NAME_AESNI_MB_PMD);
213                         }
214                 }
215         }
216
217         /* Create 2 AESNI GCM devices if required */
218         if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
219                 nb_devs = rte_cryptodev_count_devtype(
220                                 RTE_CRYPTODEV_AESNI_GCM_PMD);
221                 if (nb_devs < 2) {
222                         for (i = nb_devs; i < 2; i++) {
223                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
224                                         CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
225                                         "Failed to create instance %u of"
226                                         " pmd : %s",
227                                         i, CRYPTODEV_NAME_AESNI_GCM_PMD);
228                         }
229                 }
230         }
231
232         /* Create 2 Snow3G devices if required */
233         if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
234                 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
235                 if (nb_devs < 2) {
236                         for (i = nb_devs; i < 2; i++) {
237                                 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
238                                         CRYPTODEV_NAME_SNOW3G_PMD, NULL),
239                                         "Failed to create instance %u of"
240                                         " pmd : %s",
241                                         i, CRYPTODEV_NAME_SNOW3G_PMD);
242                         }
243                 }
244         }
245
246         /* Create 2 NULL devices if required */
247         if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
248                 nb_devs = rte_cryptodev_count_devtype(
249                                 RTE_CRYPTODEV_NULL_PMD);
250                 if (nb_devs < 2) {
251                         for (i = nb_devs; i < 2; i++) {
252                                 int dev_id = rte_eal_vdev_init(
253                                         CRYPTODEV_NAME_NULL_PMD, NULL);
254
255                                 TEST_ASSERT(dev_id >= 0,
256                                         "Failed to create instance %u of"
257                                         " pmd : %s",
258                                         i, CRYPTODEV_NAME_NULL_PMD);
259                         }
260                 }
261         }
262
263         nb_devs = rte_cryptodev_count();
264         if (nb_devs < 1) {
265                 RTE_LOG(ERR, USER1, "No crypto devices found?");
266                 return TEST_FAILED;
267         }
268
269         /* Create list of valid crypto devs */
270         for (i = 0; i < nb_devs; i++) {
271                 rte_cryptodev_info_get(i, &info);
272                 if (info.dev_type == gbl_cryptodev_type)
273                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
274         }
275
276         if (ts_params->valid_dev_count < 1)
277                 return TEST_FAILED;
278
279         /* Set up all the qps on the first of the valid devices found */
280         for (i = 0; i < 1; i++) {
281                 dev_id = ts_params->valid_devs[i];
282
283                 rte_cryptodev_info_get(dev_id, &info);
284
285                 /*
286                  * Since we can't free and re-allocate queue memory always set
287                  * the queues on this device up to max size first so enough
288                  * memory is allocated for any later re-configures needed by
289                  * other tests
290                  */
291
292                 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
293                 ts_params->conf.socket_id = SOCKET_ID_ANY;
294                 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
295
296                 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
297                                 &ts_params->conf),
298                                 "Failed to configure cryptodev %u with %u qps",
299                                 dev_id, ts_params->conf.nb_queue_pairs);
300
301                 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
302
303                 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
304                         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
305                                         dev_id, qp_id, &ts_params->qp_conf,
306                                         rte_cryptodev_socket_id(dev_id)),
307                                         "Failed to setup queue pair %u on "
308                                         "cryptodev %u",
309                                         qp_id, dev_id);
310                 }
311         }
312
313         return TEST_SUCCESS;
314 }
315
316 static void
317 testsuite_teardown(void)
318 {
319         struct crypto_testsuite_params *ts_params = &testsuite_params;
320
321         if (ts_params->mbuf_pool != NULL) {
322                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
323                 rte_mempool_count(ts_params->mbuf_pool));
324         }
325
326         if (ts_params->op_mpool != NULL) {
327                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
328                 rte_mempool_count(ts_params->op_mpool));
329         }
330
331 }
332
333 static int
334 ut_setup(void)
335 {
336         struct crypto_testsuite_params *ts_params = &testsuite_params;
337         struct crypto_unittest_params *ut_params = &unittest_params;
338
339         uint16_t qp_id;
340
341         /* Clear unit test parameters before running test */
342         memset(ut_params, 0, sizeof(*ut_params));
343
344         /* Reconfigure device to default parameters */
345         ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
346         ts_params->conf.socket_id = SOCKET_ID_ANY;
347         ts_params->conf.session_mp.nb_objs =
348                         (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
349                                         DEFAULT_NUM_OPS_INFLIGHT :
350                                         DEFAULT_NUM_OPS_INFLIGHT;
351
352         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
353                         &ts_params->conf),
354                         "Failed to configure cryptodev %u",
355                         ts_params->valid_devs[0]);
356
357         /*
358          * Now reconfigure queues to size we actually want to use in this
359          * test suite.
360          */
361         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
362
363         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
364                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
365                         ts_params->valid_devs[0], qp_id,
366                         &ts_params->qp_conf,
367                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
368                         "Failed to setup queue pair %u on cryptodev %u",
369                         qp_id, ts_params->valid_devs[0]);
370         }
371
372
373         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
374
375         /* Start the device */
376         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
377                         "Failed to start cryptodev %u",
378                         ts_params->valid_devs[0]);
379
380         return TEST_SUCCESS;
381 }
382
383 static void
384 ut_teardown(void)
385 {
386         struct crypto_testsuite_params *ts_params = &testsuite_params;
387         struct crypto_unittest_params *ut_params = &unittest_params;
388         struct rte_cryptodev_stats stats;
389
390         /* free crypto session structure */
391         if (ut_params->sess) {
392                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
393                                 ut_params->sess);
394                 ut_params->sess = NULL;
395         }
396
397         /* free crypto operation structure */
398         if (ut_params->op)
399                 rte_crypto_op_free(ut_params->op);
400
401         /*
402          * free mbuf - both obuf and ibuf are usually the same,
403          * but rte copes even if we call free twice
404          */
405         if (ut_params->obuf) {
406                 rte_pktmbuf_free(ut_params->obuf);
407                 ut_params->obuf = 0;
408         }
409         if (ut_params->ibuf) {
410                 rte_pktmbuf_free(ut_params->ibuf);
411                 ut_params->ibuf = 0;
412         }
413
414         if (ts_params->mbuf_pool != NULL)
415                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
416                                 rte_mempool_count(ts_params->mbuf_pool));
417
418         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
419
420         /* Stop the device */
421         rte_cryptodev_stop(ts_params->valid_devs[0]);
422 }
423
424 static int
425 test_device_configure_invalid_dev_id(void)
426 {
427         struct crypto_testsuite_params *ts_params = &testsuite_params;
428         uint16_t dev_id, num_devs = 0;
429
430         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
431                         "Need at least %d devices for test", 1);
432
433         /* valid dev_id values */
434         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
435
436         /* Stop the device in case it's started so it can be configured */
437         rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
438
439         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
440                         "Failed test for rte_cryptodev_configure: "
441                         "invalid dev_num %u", dev_id);
442
443         /* invalid dev_id values */
444         dev_id = num_devs;
445
446         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
447                         "Failed test for rte_cryptodev_configure: "
448                         "invalid dev_num %u", dev_id);
449
450         dev_id = 0xff;
451
452         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
453                         "Failed test for rte_cryptodev_configure:"
454                         "invalid dev_num %u", dev_id);
455
456         return TEST_SUCCESS;
457 }
458
459 static int
460 test_device_configure_invalid_queue_pair_ids(void)
461 {
462         struct crypto_testsuite_params *ts_params = &testsuite_params;
463
464         /* Stop the device in case it's started so it can be configured */
465         rte_cryptodev_stop(ts_params->valid_devs[0]);
466
467         /* valid - one queue pairs */
468         ts_params->conf.nb_queue_pairs = 1;
469
470         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
471                         &ts_params->conf),
472                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
473                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
474
475
476         /* valid - max value queue pairs */
477         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
478
479         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
480                         &ts_params->conf),
481                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
482                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
483
484
485         /* invalid - zero queue pairs */
486         ts_params->conf.nb_queue_pairs = 0;
487
488         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
489                         &ts_params->conf),
490                         "Failed test for rte_cryptodev_configure, dev_id %u,"
491                         " invalid qps: %u",
492                         ts_params->valid_devs[0],
493                         ts_params->conf.nb_queue_pairs);
494
495
496         /* invalid - max value supported by field queue pairs */
497         ts_params->conf.nb_queue_pairs = UINT16_MAX;
498
499         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
500                         &ts_params->conf),
501                         "Failed test for rte_cryptodev_configure, dev_id %u,"
502                         " invalid qps: %u",
503                         ts_params->valid_devs[0],
504                         ts_params->conf.nb_queue_pairs);
505
506
507         /* invalid - max value + 1 queue pairs */
508         ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
509
510         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
511                         &ts_params->conf),
512                         "Failed test for rte_cryptodev_configure, dev_id %u,"
513                         " invalid qps: %u",
514                         ts_params->valid_devs[0],
515                         ts_params->conf.nb_queue_pairs);
516
517         return TEST_SUCCESS;
518 }
519
520 static int
521 test_queue_pair_descriptor_setup(void)
522 {
523         struct crypto_testsuite_params *ts_params = &testsuite_params;
524         struct rte_cryptodev_info dev_info;
525         struct rte_cryptodev_qp_conf qp_conf = {
526                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
527         };
528
529         uint16_t qp_id;
530
531         /* Stop the device in case it's started so it can be configured */
532         rte_cryptodev_stop(ts_params->valid_devs[0]);
533
534
535         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
536
537         ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
538
539         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
540                         &ts_params->conf), "Failed to configure cryptodev %u",
541                         ts_params->valid_devs[0]);
542
543
544         /*
545          * Test various ring sizes on this device. memzones can't be
546          * freed so are re-used if ring is released and re-created.
547          */
548         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
549
550         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
551                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
552                                 ts_params->valid_devs[0], qp_id, &qp_conf,
553                                 rte_cryptodev_socket_id(
554                                                 ts_params->valid_devs[0])),
555                                 "Failed test for "
556                                 "rte_cryptodev_queue_pair_setup: num_inflights "
557                                 "%u on qp %u on cryptodev %u",
558                                 qp_conf.nb_descriptors, qp_id,
559                                 ts_params->valid_devs[0]);
560         }
561
562         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
563
564         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
565                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
566                                 ts_params->valid_devs[0], qp_id, &qp_conf,
567                                 rte_cryptodev_socket_id(
568                                                 ts_params->valid_devs[0])),
569                                 "Failed test for"
570                                 " rte_cryptodev_queue_pair_setup: num_inflights"
571                                 " %u on qp %u on cryptodev %u",
572                                 qp_conf.nb_descriptors, qp_id,
573                                 ts_params->valid_devs[0]);
574         }
575
576         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
577
578         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
579                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
580                                 ts_params->valid_devs[0], qp_id, &qp_conf,
581                                 rte_cryptodev_socket_id(
582                                                 ts_params->valid_devs[0])),
583                                 "Failed test for "
584                                 "rte_cryptodev_queue_pair_setup: num_inflights"
585                                 " %u on qp %u on cryptodev %u",
586                                 qp_conf.nb_descriptors, qp_id,
587                                 ts_params->valid_devs[0]);
588         }
589
590         /* invalid number of descriptors - max supported + 2 */
591         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
592
593         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
594                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
595                                 ts_params->valid_devs[0], qp_id, &qp_conf,
596                                 rte_cryptodev_socket_id(
597                                                 ts_params->valid_devs[0])),
598                                 "Unexpectedly passed test for "
599                                 "rte_cryptodev_queue_pair_setup:"
600                                 "num_inflights %u on qp %u on cryptodev %u",
601                                 qp_conf.nb_descriptors, qp_id,
602                                 ts_params->valid_devs[0]);
603         }
604
605         /* invalid number of descriptors - max value of parameter */
606         qp_conf.nb_descriptors = UINT32_MAX-1;
607
608         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
609                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
610                                 ts_params->valid_devs[0], qp_id, &qp_conf,
611                                 rte_cryptodev_socket_id(
612                                                 ts_params->valid_devs[0])),
613                                 "Unexpectedly passed test for "
614                                 "rte_cryptodev_queue_pair_setup:"
615                                 "num_inflights %u on qp %u on cryptodev %u",
616                                 qp_conf.nb_descriptors, qp_id,
617                                 ts_params->valid_devs[0]);
618         }
619
620         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
621
622         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
623                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
624                                 ts_params->valid_devs[0], qp_id, &qp_conf,
625                                 rte_cryptodev_socket_id(
626                                                 ts_params->valid_devs[0])),
627                                 "Failed test for"
628                                 " rte_cryptodev_queue_pair_setup:"
629                                 "num_inflights %u on qp %u on cryptodev %u",
630                                 qp_conf.nb_descriptors, qp_id,
631                                 ts_params->valid_devs[0]);
632         }
633
634         /* invalid number of descriptors - max supported + 1 */
635         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
636
637         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
638                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
639                                 ts_params->valid_devs[0], qp_id, &qp_conf,
640                                 rte_cryptodev_socket_id(
641                                                 ts_params->valid_devs[0])),
642                                 "Unexpectedly passed test for "
643                                 "rte_cryptodev_queue_pair_setup:"
644                                 "num_inflights %u on qp %u on cryptodev %u",
645                                 qp_conf.nb_descriptors, qp_id,
646                                 ts_params->valid_devs[0]);
647         }
648
649         /* test invalid queue pair id */
650         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
651
652         qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;         /*invalid */
653
654         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
655                         ts_params->valid_devs[0],
656                         qp_id, &qp_conf,
657                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
658                         "Failed test for rte_cryptodev_queue_pair_setup:"
659                         "invalid qp %u on cryptodev %u",
660                         qp_id, ts_params->valid_devs[0]);
661
662         qp_id = 0xffff; /*invalid*/
663
664         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
665                         ts_params->valid_devs[0],
666                         qp_id, &qp_conf,
667                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
668                         "Failed test for rte_cryptodev_queue_pair_setup:"
669                         "invalid qp %u on cryptodev %u",
670                         qp_id, ts_params->valid_devs[0]);
671
672         return TEST_SUCCESS;
673 }
674
675 /* ***** Plaintext data for tests ***** */
676
677 const char catch_22_quote_1[] =
678                 "There was only one catch and that was Catch-22, which "
679                 "specified that a concern for one's safety in the face of "
680                 "dangers that were real and immediate was the process of a "
681                 "rational mind. Orr was crazy and could be grounded. All he "
682                 "had to do was ask; and as soon as he did, he would no longer "
683                 "be crazy and would have to fly more missions. Orr would be "
684                 "crazy to fly more missions and sane if he didn't, but if he "
685                 "was sane he had to fly them. If he flew them he was crazy "
686                 "and didn't have to; but if he didn't want to he was sane and "
687                 "had to. Yossarian was moved very deeply by the absolute "
688                 "simplicity of this clause of Catch-22 and let out a "
689                 "respectful whistle. \"That's some catch, that Catch-22\", he "
690                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
691
692 const char catch_22_quote[] =
693                 "What a lousy earth! He wondered how many people were "
694                 "destitute that same night even in his own prosperous country, "
695                 "how many homes were shanties, how many husbands were drunk "
696                 "and wives socked, and how many children were bullied, abused, "
697                 "or abandoned. How many families hungered for food they could "
698                 "not afford to buy? How many hearts were broken? How many "
699                 "suicides would take place that same night, how many people "
700                 "would go insane? How many cockroaches and landlords would "
701                 "triumph? How many winners were losers, successes failures, "
702                 "and rich men poor men? How many wise guys were stupid? How "
703                 "many happy endings were unhappy endings? How many honest men "
704                 "were liars, brave men cowards, loyal men traitors, how many "
705                 "sainted men were corrupt, how many people in positions of "
706                 "trust had sold their souls to bodyguards, how many had never "
707                 "had souls? How many straight-and-narrow paths were crooked "
708                 "paths? How many best families were worst families and how "
709                 "many good people were bad people? When you added them all up "
710                 "and then subtracted, you might be left with only the children, "
711                 "and perhaps with Albert Einstein and an old violinist or "
712                 "sculptor somewhere.";
713
714 #define QUOTE_480_BYTES         (480)
715 #define QUOTE_512_BYTES         (512)
716 #define QUOTE_768_BYTES         (768)
717 #define QUOTE_1024_BYTES        (1024)
718
719
720
721 /* ***** SHA1 Hash Tests ***** */
722
723 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
724
725 static uint8_t hmac_sha1_key[] = {
726         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
727         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
728         0xDE, 0xF4, 0xDE, 0xAD };
729
730 /* ***** SHA224 Hash Tests ***** */
731
732 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
733
734
735 /* ***** AES-CBC Cipher Tests ***** */
736
737 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
738 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
739
740 static uint8_t aes_cbc_key[] = {
741         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
742         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
743
744 static uint8_t aes_cbc_iv[] = {
745         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
746         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
747
748
749 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
750
751 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
752         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
753         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
754         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
755         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
756         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
757         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
758         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
759         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
760         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
761         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
762         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
763         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
764         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
765         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
766         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
767         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
768         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
769         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
770         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
771         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
772         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
773         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
774         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
775         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
776         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
777         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
778         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
779         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
780         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
781         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
782         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
783         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
784         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
785         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
786         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
787         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
788         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
789         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
790         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
791         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
792         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
793         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
794         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
795         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
796         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
797         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
798         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
799         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
800         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
801         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
802         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
803         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
804         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
805         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
806         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
807         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
808         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
809         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
810         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
811         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
812         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
813         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
814         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
815         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
816 };
817
818 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
819         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
820         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
821         0x18, 0x8c, 0x1d, 0x32
822 };
823
824
825 static int
826 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
827 {
828         struct crypto_testsuite_params *ts_params = &testsuite_params;
829         struct crypto_unittest_params *ut_params = &unittest_params;
830
831         /* Generate test mbuf data and space for digest */
832         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
833                         catch_22_quote, QUOTE_512_BYTES, 0);
834
835         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
836                         DIGEST_BYTE_LENGTH_SHA1);
837         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
838
839         /* Setup Cipher Parameters */
840         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
841         ut_params->cipher_xform.next = &ut_params->auth_xform;
842
843         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
844         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
845         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
846         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
847
848         /* Setup HMAC Parameters */
849         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
850
851         ut_params->auth_xform.next = NULL;
852
853         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
854         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
855         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
856         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
857         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
858
859         /* Create crypto session*/
860         ut_params->sess = rte_cryptodev_sym_session_create(
861                         ts_params->valid_devs[0],
862                         &ut_params->cipher_xform);
863         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
864
865         /* Generate crypto op data structure */
866         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
867                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
868         TEST_ASSERT_NOT_NULL(ut_params->op,
869                         "Failed to allocate symmetric crypto operation struct");
870
871         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
872
873         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
874
875         /* set crypto operation source mbuf */
876         sym_op->m_src = ut_params->ibuf;
877
878         /* Set crypto operation authentication parameters */
879         sym_op->auth.digest.data = ut_params->digest;
880         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
881                         ut_params->ibuf, QUOTE_512_BYTES);
882         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
883
884         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
885         sym_op->auth.data.length = QUOTE_512_BYTES;
886
887         /* Set crypto operation cipher parameters */
888         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
889                         CIPHER_IV_LENGTH_AES_CBC);
890         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
891         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
892
893         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
894                         CIPHER_IV_LENGTH_AES_CBC);
895
896         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
897         sym_op->cipher.data.length = QUOTE_512_BYTES;
898
899         /* Process crypto operation */
900         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
901                         ut_params->op), "failed to process sym crypto op");
902
903         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
904                         "crypto op processing failed");
905
906         /* Validate obuf */
907         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
908                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
909
910         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
911                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
912                         QUOTE_512_BYTES,
913                         "ciphertext data not as expected");
914
915         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
916
917         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
918                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
919                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
920                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
921                                         DIGEST_BYTE_LENGTH_SHA1,
922                         "Generated digest data not as expected");
923
924         return TEST_SUCCESS;
925 }
926
927
928 static int
929 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop(void)
930 {
931         struct crypto_testsuite_params *ts_params = &testsuite_params;
932         struct crypto_unittest_params *ut_params = &unittest_params;
933
934         /* Generate test mbuf data and space for digest */
935
936         TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
937                         &ut_params->obuf, ts_params->mbuf_pool, catch_22_quote,
938                         QUOTE_512_BYTES, 0), 0,
939                         "Allocation of rte_mbuf failed");
940
941         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->obuf,
942                                 DIGEST_BYTE_LENGTH_SHA1);
943
944         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
945
946         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
947         ut_params->cipher_xform.next = &ut_params->auth_xform;
948
949         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
950         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
951         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
952         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
953
954         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
955         ut_params->auth_xform.next = NULL;
956
957         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
958         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
959         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
960         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
961         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
962
963         ut_params->sess = rte_cryptodev_sym_session_create(
964                         ts_params->valid_devs[0],
965                         &ut_params->cipher_xform);
966
967         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
968
969         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
970                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
971
972
973         TEST_ASSERT_NOT_NULL(ut_params->op,
974                         "Failed to allocate symmetric crypto operation struct");
975
976         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
977
978         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
979
980         /* set crypto operation source mbuf */
981         sym_op->m_src = ut_params->ibuf;
982         sym_op->m_dst = ut_params->obuf;
983
984         sym_op->auth.digest.data = ut_params->digest;
985
986         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
987                         ut_params->obuf, QUOTE_512_BYTES);
988
989         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
990         sym_op->auth.data.length = QUOTE_512_BYTES;
991
992         /* Set crypto operation cipher parameters */
993         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
994                         CIPHER_IV_LENGTH_AES_CBC);
995
996         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
997                         "Failed to prepend place for iv input");
998
999         TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
1000                         CIPHER_IV_LENGTH_AES_CBC),
1001                         "Failed to prepend place for iv output");
1002
1003         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1004
1005         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1006         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1007
1008         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1009                         CIPHER_IV_LENGTH_AES_CBC);
1010
1011         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1012         sym_op->cipher.data.length = QUOTE_512_BYTES;
1013
1014
1015         /* Process crypto operation */
1016         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1017                         ut_params->op), "failed to process sym crypto op");
1018
1019         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1020                         "crypto op processing failed");
1021
1022         /* Validate obuf */
1023         uint8_t *ciphertext;
1024
1025         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
1026                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1027
1028         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1029                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1030                         QUOTE_512_BYTES,
1031                         "ciphertext data not as expected");
1032
1033         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1034
1035         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1036                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1037                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1038                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1039                                         DIGEST_BYTE_LENGTH_SHA1,
1040                         "Generated digest data not as expected");
1041
1042
1043         return TEST_SUCCESS;
1044 }
1045
1046
1047 static int
1048 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver(void)
1049 {
1050         struct crypto_testsuite_params *ts_params = &testsuite_params;
1051         struct crypto_unittest_params *ut_params = &unittest_params;
1052
1053         /* Generate test mbuf data and digest */
1054
1055         TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
1056                         &ut_params->obuf, ts_params->mbuf_pool,
1057                         (const char *)
1058                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1059                         QUOTE_512_BYTES, 0), 0,
1060                         "Allocation of rte_mbuf failed");
1061
1062         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1063                         DIGEST_BYTE_LENGTH_SHA1);
1064
1065         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1066
1067         rte_memcpy(ut_params->digest,
1068                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1069                         DIGEST_BYTE_LENGTH_SHA1);
1070
1071         /* Setup Cipher Parameters */
1072         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1073         ut_params->cipher_xform.next = NULL;
1074
1075         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1076         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1077         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1078         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1079
1080         /* Setup HMAC Parameters */
1081         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1082         ut_params->auth_xform.next = &ut_params->cipher_xform;
1083
1084         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1085         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1086         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1087         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1088         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1089
1090         /* Create Crypto session*/
1091         ut_params->sess =
1092                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1093                                                 &ut_params->auth_xform);
1094         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1095
1096         /* Generate Crypto op data structure */
1097         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1098                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1099         TEST_ASSERT_NOT_NULL(ut_params->op,
1100                         "Failed to allocate symmetric crypto operation struct");
1101
1102         /* attach symmetric crypto session to crypto operations */
1103         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1104
1105         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1106
1107         /* set crypto operation source mbuf */
1108         sym_op->m_src = ut_params->ibuf;
1109         sym_op->m_dst = ut_params->obuf;
1110
1111         sym_op->auth.digest.data = ut_params->digest;
1112         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1113                         ut_params->ibuf, QUOTE_512_BYTES);
1114         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1115
1116         sym_op->auth.data.length = QUOTE_512_BYTES;
1117
1118         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1119                         CIPHER_IV_LENGTH_AES_CBC);
1120
1121         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
1122                         "Failed to prepend place for iv input");
1123
1124         TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
1125                         CIPHER_IV_LENGTH_AES_CBC),
1126                         "Failed to prepend place for iv output");
1127
1128         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1129
1130         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1131         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1132
1133         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1134                         CIPHER_IV_LENGTH_AES_CBC);
1135
1136         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1137         sym_op->cipher.data.length = QUOTE_512_BYTES;
1138
1139
1140         /* Process crypto operation */
1141         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1142                         ut_params->op), "failed to process sym crypto op");
1143
1144         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1145                         "Digest verification failed");
1146
1147         ut_params->obuf = ut_params->op->sym->m_dst;
1148
1149         /* Validate obuf */
1150         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1151                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1152                         CIPHER_IV_LENGTH_AES_CBC,
1153                         catch_22_quote,
1154                         QUOTE_512_BYTES,
1155                         "Ciphertext data not as expected");
1156
1157
1158         return TEST_SUCCESS;
1159 }
1160
1161
1162 static int
1163 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
1164 {
1165         struct crypto_testsuite_params *ts_params = &testsuite_params;
1166         struct crypto_unittest_params *ut_params = &unittest_params;
1167
1168         /* Generate test mbuf data and space for digest */
1169         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1170                         catch_22_quote, QUOTE_512_BYTES, 0);
1171
1172         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1173                         DIGEST_BYTE_LENGTH_SHA1);
1174         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1175
1176         /* Generate Crypto op data structure */
1177         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1178                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1179         TEST_ASSERT_NOT_NULL(ut_params->op,
1180                         "Failed to allocate symmetric crypto operation struct");
1181
1182         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
1183                         "failed to allocate space for crypto transforms");
1184
1185         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1186
1187         /* set crypto operation source mbuf */
1188         sym_op->m_src = ut_params->ibuf;
1189
1190         /* Set crypto operation data parameters */
1191         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1192
1193         /* cipher parameters */
1194         sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1195         sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1196         sym_op->xform->cipher.key.data = aes_cbc_key;
1197         sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1198
1199         /* hash parameters */
1200         sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
1201
1202         sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1203         sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1204         sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
1205         sym_op->xform->next->auth.key.data = hmac_sha1_key;
1206         sym_op->xform->next->auth.digest_length =
1207                         DIGEST_BYTE_LENGTH_SHA1;
1208
1209         sym_op->auth.digest.data = ut_params->digest;
1210         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1211                         ut_params->ibuf, QUOTE_512_BYTES);
1212         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1213
1214
1215         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1216         sym_op->auth.data.length = QUOTE_512_BYTES;
1217
1218         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1219                         CIPHER_IV_LENGTH_AES_CBC);
1220         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1221         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1222
1223         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1224                         CIPHER_IV_LENGTH_AES_CBC);
1225
1226         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1227         sym_op->cipher.data.length = QUOTE_512_BYTES;
1228
1229         /* Process crypto operation */
1230         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1231                         ut_params->op), "failed to process sym crypto op");
1232
1233         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1234                         "crypto op processing failed");
1235
1236         ut_params->obuf = ut_params->op->sym->m_src;
1237
1238         /* Validate obuf */
1239         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1240                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1241                         CIPHER_IV_LENGTH_AES_CBC,
1242                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1243                         QUOTE_512_BYTES,
1244                         "Ciphertext data not as expected");
1245
1246         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1247                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1248                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1249                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1250                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1251                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1252                                         DIGEST_BYTE_LENGTH_SHA1,
1253                         "Generated digest data not as expected");
1254
1255
1256         return TEST_SUCCESS;
1257 }
1258
1259 static int
1260 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
1261 {
1262         struct crypto_testsuite_params *ts_params = &testsuite_params;
1263         struct crypto_unittest_params *ut_params = &unittest_params;
1264
1265         /* Generate test mbuf data and digest */
1266         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1267                         (const char *)
1268                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1269                         QUOTE_512_BYTES, 0);
1270
1271         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1272                         DIGEST_BYTE_LENGTH_SHA1);
1273         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1274
1275         rte_memcpy(ut_params->digest,
1276                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1277                         DIGEST_BYTE_LENGTH_SHA1);
1278
1279         /* Setup Cipher Parameters */
1280         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1281         ut_params->cipher_xform.next = NULL;
1282
1283         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1284         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1285         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1286         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1287
1288         /* Setup HMAC Parameters */
1289         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1290         ut_params->auth_xform.next = &ut_params->cipher_xform;
1291
1292         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1293         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1294         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1295         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1296         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1297
1298         /* Create Crypto session*/
1299         ut_params->sess =
1300                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1301                                                 &ut_params->auth_xform);
1302         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1303
1304         /* Generate Crypto op data structure */
1305         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1306                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1307         TEST_ASSERT_NOT_NULL(ut_params->op,
1308                         "Failed to allocate symmetric crypto operation struct");
1309
1310         /* attach symmetric crypto session to crypto operations */
1311         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1312
1313         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1314
1315         /* set crypto operation source mbuf */
1316         sym_op->m_src = ut_params->ibuf;
1317
1318         sym_op->auth.digest.data = ut_params->digest;
1319         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1320                         ut_params->ibuf, QUOTE_512_BYTES);
1321         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1322
1323         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1324         sym_op->auth.data.length = QUOTE_512_BYTES;
1325
1326         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1327                         CIPHER_IV_LENGTH_AES_CBC);
1328         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1329         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1330
1331         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1332                         CIPHER_IV_LENGTH_AES_CBC);
1333
1334         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1335         sym_op->cipher.data.length = QUOTE_512_BYTES;
1336
1337
1338         /* Process crypto operation */
1339         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1340                         ut_params->op), "failed to process sym crypto op");
1341
1342         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1343                         "crypto op processing failed");
1344
1345         ut_params->obuf = ut_params->op->sym->m_src;
1346
1347
1348         /* Validate obuf */
1349         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1350                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1351                         CIPHER_IV_LENGTH_AES_CBC,
1352                         catch_22_quote,
1353                         QUOTE_512_BYTES,
1354                         "Ciphertext data not as expected");
1355
1356         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1357                         "Digest verification failed");
1358
1359
1360         return TEST_SUCCESS;
1361 }
1362
1363     /* **** AES counter mode tests **** */
1364
1365 static int
1366 test_AES_CTR_encrypt_digest(const struct aes_ctr_test_data *tdata)
1367 {
1368         struct crypto_testsuite_params *ts_params = &testsuite_params;
1369         struct crypto_unittest_params *ut_params = &unittest_params;
1370         struct rte_crypto_sym_op *sym_op;
1371
1372         uint8_t hash_key[tdata->auth_key.len];
1373         uint8_t cipher_key[tdata->key.len];
1374
1375         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1376                         (const char *)tdata->plaintext.data,
1377                         tdata->plaintext.len, 0);
1378
1379         /* Setup Cipher Parameters */
1380         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1381         ut_params->cipher_xform.next = &ut_params->auth_xform;
1382
1383         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
1384         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1385
1386         rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
1387         ut_params->cipher_xform.cipher.key.data = cipher_key;
1388         ut_params->cipher_xform.cipher.key.length =
1389                         tdata->key.len;
1390
1391         /* Setup HMAC Parameters */
1392         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1393         ut_params->auth_xform.next = NULL;
1394
1395         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1396         ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
1397         ut_params->auth_xform.auth.key.length =
1398                         tdata->auth_key.len;
1399         rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
1400         ut_params->auth_xform.auth.key.data = hash_key;
1401         ut_params->auth_xform.auth.digest_length = tdata->digest.len;
1402
1403         /* Create Crypto session*/
1404         ut_params->sess = rte_cryptodev_sym_session_create(
1405                         ts_params->valid_devs[0],
1406                         &ut_params->cipher_xform);
1407         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1408
1409         /* Generate Crypto op data structure */
1410         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1411                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1412         TEST_ASSERT_NOT_NULL(ut_params->op,
1413                         "Failed to allocate symmetric crypto operation struct");
1414
1415         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1416
1417         sym_op = ut_params->op->sym;
1418
1419         /* set crypto operation source mbuf */
1420         sym_op->m_src = ut_params->ibuf;
1421
1422         /* Set operation cipher parameters */
1423         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1424                         sym_op->m_src, tdata->iv.len);
1425         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1426         sym_op->cipher.iv.length = tdata->iv.len;
1427
1428         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
1429                         tdata->iv.len);
1430
1431         sym_op->cipher.data.offset = tdata->iv.len;
1432         sym_op->cipher.data.length = tdata->plaintext.len;
1433
1434         /* Set operation authentication parameters */
1435         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1436                         sym_op->m_src, tdata->digest.len);
1437         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1438                         sym_op->m_src,
1439                         tdata->iv.len + tdata->ciphertext.len);
1440         sym_op->auth.digest.length = tdata->digest.len;
1441
1442         memset(sym_op->auth.digest.data, 0, tdata->digest.len);
1443
1444         sym_op->auth.data.offset = tdata->iv.len;
1445         sym_op->auth.data.length = tdata->plaintext.len;
1446
1447         /* Process crypto operation */
1448         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1449                         ut_params->op);
1450
1451         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1452                         "crypto op processing failed");
1453
1454         uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1455                         uint8_t *, tdata->iv.len);
1456
1457         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1458                         tdata->ciphertext.data,
1459                         tdata->ciphertext.len,
1460                         "ciphertext data not as expected");
1461
1462         uint8_t *digest = ciphertext + tdata->ciphertext.len;
1463
1464         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1465                         tdata->digest.data, tdata->digest.len,
1466                         "Generated digest data not as expected");
1467
1468         return TEST_SUCCESS;
1469 }
1470
1471 static int
1472 test_AES_CTR_encrypt_digest_case_1(void)
1473 {
1474         return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_1);
1475 }
1476 static int
1477 test_AES_CTR_encrypt_digest_case_2(void)
1478 {
1479         return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_2);
1480 }
1481 static int
1482 test_AES_CTR_encrypt_digest_case_3(void)
1483 {
1484         return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_3);
1485 }
1486
1487 static int
1488 test_AES_CTR_digest_verify_decrypt(const struct aes_ctr_test_data *tdata)
1489 {
1490         struct crypto_testsuite_params *ts_params = &testsuite_params;
1491         struct crypto_unittest_params *ut_params = &unittest_params;
1492         struct rte_crypto_sym_op *sym_op;
1493
1494         uint8_t hash_key[tdata->auth_key.len];
1495         uint8_t cipher_key[tdata->key.len];
1496
1497         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1498                         (const char *)tdata->ciphertext.data,
1499                         tdata->ciphertext.len, 0);
1500
1501         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1502                         tdata->digest.len);
1503
1504         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1505
1506         rte_memcpy(ut_params->digest,
1507                         tdata->digest.data,
1508                         tdata->digest.len);
1509
1510         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1511         ut_params->auth_xform.next = &ut_params->cipher_xform;
1512
1513         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1514         ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
1515         ut_params->auth_xform.auth.key.length = tdata->auth_key.len;
1516         rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
1517         ut_params->auth_xform.auth.key.data =
1518                         hash_key;
1519         ut_params->auth_xform.auth.digest_length = tdata->digest.len;
1520
1521         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1522         ut_params->cipher_xform.next = NULL;
1523
1524         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
1525         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1526
1527         rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
1528         ut_params->cipher_xform.cipher.key.data =
1529                         cipher_key;
1530         ut_params->cipher_xform.cipher.key.length = tdata->key.len;
1531
1532         ut_params->sess = rte_cryptodev_sym_session_create(
1533                         ts_params->valid_devs[0],
1534                         &ut_params->auth_xform);
1535         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1536
1537         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1538                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1539         TEST_ASSERT_NOT_NULL(ut_params->op,
1540                         "Failed to allocate symmetric crypto operation struct");
1541
1542         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1543
1544         sym_op = ut_params->op->sym;
1545
1546         sym_op->m_src = ut_params->ibuf;
1547
1548         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1549                         sym_op->m_src, tdata->iv.len);
1550         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1551         sym_op->cipher.iv.length = tdata->iv.len;
1552
1553         rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
1554                         tdata->iv.len);
1555
1556         sym_op->cipher.data.offset = tdata->iv.len;
1557         sym_op->cipher.data.length = tdata->ciphertext.len;
1558
1559         sym_op->auth.digest.data = ut_params->digest;
1560         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1561                         sym_op->m_src,
1562                         tdata->iv.len + tdata->ciphertext.len);
1563         sym_op->auth.digest.length = tdata->digest.len;
1564
1565         sym_op->auth.data.offset = tdata->iv.len;
1566         sym_op->auth.data.length = tdata->ciphertext.len;
1567
1568         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1569                         ut_params->op);
1570
1571         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1572                         "crypto op processing failed");
1573
1574         uint8_t *plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1575                         uint8_t *, tdata->iv.len);
1576
1577         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1578                         tdata->plaintext.data,
1579                         tdata->plaintext.len,
1580                         "plaintext data not as expected");
1581
1582
1583         return TEST_SUCCESS;
1584 }
1585
1586 static int
1587 test_AES_CTR_digest_verify_decrypt_case_1(void)
1588 {
1589         return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_1);
1590 }
1591 static int
1592 test_AES_CTR_digest_verify_decrypt_case_2(void)
1593 {
1594         return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_2);
1595 }
1596 static int
1597 test_AES_CTR_digest_verify_decrypt_case_3(void)
1598 {
1599         return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_3);
1600 }
1601
1602
1603 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1604
1605 #define HMAC_KEY_LENGTH_SHA256  (DIGEST_BYTE_LENGTH_SHA256)
1606
1607 static uint8_t hmac_sha256_key[] = {
1608         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1609         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1610         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1611         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1612
1613 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1614         0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1615         0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1616         0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1617         0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1618
1619 static int
1620 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1621 {
1622         struct crypto_testsuite_params *ts_params = &testsuite_params;
1623         struct crypto_unittest_params *ut_params = &unittest_params;
1624
1625         /* Generate test mbuf data and space for digest */
1626         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1627                         catch_22_quote, QUOTE_512_BYTES, 0);
1628
1629         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1630                         DIGEST_BYTE_LENGTH_SHA256);
1631         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1632
1633         /* Setup Cipher Parameters */
1634         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1635         ut_params->cipher_xform.next = &ut_params->auth_xform;
1636
1637         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1638         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1639         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1640         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1641
1642         /* Setup HMAC Parameters */
1643         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1644         ut_params->auth_xform.next = NULL;
1645
1646         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1647         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1648         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1649         ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1650         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1651
1652         /* Create Crypto session*/
1653         ut_params->sess = rte_cryptodev_sym_session_create(
1654                         ts_params->valid_devs[0],
1655                         &ut_params->cipher_xform);
1656         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1657
1658         /* Generate Crypto op data structure */
1659         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1660                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1661         TEST_ASSERT_NOT_NULL(ut_params->op,
1662                         "Failed to allocate symmetric crypto operation struct");
1663
1664         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1665
1666         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1667
1668         /* set crypto operation source mbuf */
1669         sym_op->m_src = ut_params->ibuf;
1670
1671         sym_op->auth.digest.data = ut_params->digest;
1672         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1673                         ut_params->ibuf, QUOTE_512_BYTES);
1674         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1675
1676         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1677         sym_op->auth.data.length = QUOTE_512_BYTES;
1678
1679         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1680                         CIPHER_IV_LENGTH_AES_CBC);
1681         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1682         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1683
1684         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1685                         CIPHER_IV_LENGTH_AES_CBC);
1686
1687         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1688         sym_op->cipher.data.length = QUOTE_512_BYTES;
1689
1690         /* Process crypto operation */
1691         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1692                         ut_params->op), "failed to process sym crypto op");
1693
1694         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1695                         "crypto op processing failed");
1696
1697         ut_params->obuf = ut_params->op->sym->m_src;
1698
1699         /* Validate obuf */
1700         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1701                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1702                         CIPHER_IV_LENGTH_AES_CBC,
1703                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1704                         QUOTE_512_BYTES,
1705                         "Ciphertext data not as expected");
1706
1707         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1708                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1709                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1710                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1711                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1712                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1713                                         DIGEST_BYTE_LENGTH_SHA256,
1714                         "Generated digest data not as expected");
1715
1716
1717         return TEST_SUCCESS;
1718 }
1719
1720 static int
1721 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1722 {
1723         struct crypto_testsuite_params *ts_params = &testsuite_params;
1724         struct crypto_unittest_params *ut_params = &unittest_params;
1725
1726         /* Generate test mbuf data and digest */
1727         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1728                         (const char *)
1729                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1730                         QUOTE_512_BYTES, 0);
1731
1732         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1733                         DIGEST_BYTE_LENGTH_SHA256);
1734         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1735
1736         rte_memcpy(ut_params->digest,
1737                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1738                         DIGEST_BYTE_LENGTH_SHA256);
1739
1740         /* Setup Cipher Parameters */
1741         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1742         ut_params->cipher_xform.next = NULL;
1743
1744         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1745         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1746         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1747         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1748
1749         /* Setup HMAC Parameters */
1750         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1751         ut_params->auth_xform.next = &ut_params->cipher_xform;
1752
1753         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1754         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1755         ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1756         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1757         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1758
1759         /* Create Crypto session*/
1760         ut_params->sess =
1761                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1762                                                 &ut_params->auth_xform);
1763         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1764
1765         /* Generate Crypto op data structure */
1766         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1767                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1768         TEST_ASSERT_NOT_NULL(ut_params->op,
1769                         "Failed to allocate symmetric crypto operation struct");
1770
1771
1772         /* Set crypto operation data parameters */
1773         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1774
1775         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1776
1777         /* set crypto operation source mbuf */
1778         sym_op->m_src = ut_params->ibuf;
1779
1780         sym_op->auth.digest.data = ut_params->digest;
1781         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1782                         ut_params->ibuf, QUOTE_512_BYTES);
1783         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1784
1785         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1786         sym_op->auth.data.length = QUOTE_512_BYTES;
1787
1788         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1789                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1790         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1791         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1792
1793         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1794                         CIPHER_IV_LENGTH_AES_CBC);
1795
1796         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1797         sym_op->cipher.data.length = QUOTE_512_BYTES;
1798
1799         /* Process crypto operation */
1800         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1801                         ut_params->op), "failed to process sym crypto op");
1802
1803         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1804                         "crypto op processing failed");
1805
1806         ut_params->obuf = ut_params->op->sym->m_src;
1807
1808         /* Validate obuf */
1809         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1810                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1811                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1812                         QUOTE_512_BYTES,
1813                         "Plaintext data not as expected");
1814
1815         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1816                         "Digest verification failed");
1817
1818         return TEST_SUCCESS;
1819 }
1820
1821 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1822
1823 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1824
1825 static uint8_t hmac_sha512_key[] = {
1826         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1827         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1828         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1829         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1830         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1831         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1832         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1833         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1834
1835 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1836         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1837         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1838         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1839         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1840         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1841         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1842         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1843         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1844
1845 static int
1846 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1847 {
1848         struct crypto_testsuite_params *ts_params = &testsuite_params;
1849         struct crypto_unittest_params *ut_params = &unittest_params;
1850
1851         /* Generate test mbuf data and space for digest */
1852         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1853                         catch_22_quote, QUOTE_512_BYTES, 0);
1854
1855         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1856                         DIGEST_BYTE_LENGTH_SHA512);
1857         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1858
1859         /* Setup Cipher Parameters */
1860         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1861         ut_params->cipher_xform.next = &ut_params->auth_xform;
1862
1863         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1864         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1865         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1866         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1867
1868         /* Setup HMAC 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 = RTE_CRYPTO_AUTH_OP_GENERATE;
1873         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1874         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1875         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1876         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1877
1878         /* Create Crypto session*/
1879         ut_params->sess =
1880                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1881                                                 &ut_params->cipher_xform);
1882
1883         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1884
1885         /* Generate Crypto op data structure */
1886         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1887                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1888         TEST_ASSERT_NOT_NULL(ut_params->op,
1889                         "Failed to allocate symmetric crypto operation struct");
1890
1891         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1892
1893         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1894
1895         /* set crypto operation source mbuf */
1896         sym_op->m_src = ut_params->ibuf;
1897
1898         sym_op->auth.digest.data = ut_params->digest;
1899         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1900                         ut_params->ibuf, QUOTE_512_BYTES);
1901         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1902
1903         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1904         sym_op->auth.data.length = QUOTE_512_BYTES;
1905
1906         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1907                         CIPHER_IV_LENGTH_AES_CBC);
1908         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1909         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1910
1911         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1912                         CIPHER_IV_LENGTH_AES_CBC);
1913
1914         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1915         sym_op->cipher.data.length = QUOTE_512_BYTES;
1916
1917         /* Process crypto operation */
1918         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1919                         ut_params->op), "failed to process sym crypto op");
1920
1921         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1922                         "crypto op processing failed");
1923
1924         ut_params->obuf = ut_params->op->sym->m_src;
1925
1926         /* Validate obuf */
1927         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1928                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1929                         CIPHER_IV_LENGTH_AES_CBC,
1930                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1931                         QUOTE_512_BYTES,
1932                         "Ciphertext data not as expected");
1933
1934         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1935                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1936                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1937                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1938                         gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1939                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1940                                         DIGEST_BYTE_LENGTH_SHA512,
1941                         "Generated digest data not as expected");
1942
1943         return TEST_SUCCESS;
1944 }
1945
1946
1947 static int
1948 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1949                 struct crypto_unittest_params *ut_params);
1950
1951 static int
1952 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1953                 struct crypto_unittest_params *ut_params,
1954                 struct crypto_testsuite_params *ts_params);
1955
1956 static int
1957 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1958 {
1959         struct crypto_unittest_params *ut_params = &unittest_params;
1960         struct crypto_testsuite_params *ts_params = &testsuite_params;
1961
1962         TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1963                         ut_params) == TEST_SUCCESS,
1964                         "Failed to create session params");
1965
1966         /* Create Crypto session*/
1967         ut_params->sess =
1968                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1969                                                 &ut_params->auth_xform);
1970         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1971
1972         return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1973                         ut_params, ts_params);
1974 }
1975
1976 static int
1977 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1978                 struct crypto_unittest_params *ut_params)
1979 {
1980
1981         /* Setup Cipher Parameters */
1982         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1983         ut_params->cipher_xform.next = NULL;
1984
1985         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1986         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1987         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1988         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1989
1990         /* Setup HMAC Parameters */
1991         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1992         ut_params->auth_xform.next = &ut_params->cipher_xform;
1993
1994         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1995         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1996         ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1997         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1998         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1999
2000         return TEST_SUCCESS;
2001 }
2002
2003
2004 static int
2005 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2006                 struct crypto_unittest_params *ut_params,
2007                 struct crypto_testsuite_params *ts_params)
2008 {
2009         /* Generate test mbuf data and digest */
2010         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2011                         (const char *)
2012                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2013                         QUOTE_512_BYTES, 0);
2014
2015         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2016                         DIGEST_BYTE_LENGTH_SHA512);
2017         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2018
2019         rte_memcpy(ut_params->digest,
2020                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
2021                         DIGEST_BYTE_LENGTH_SHA512);
2022
2023         /* Generate Crypto op data structure */
2024         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2025                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2026         TEST_ASSERT_NOT_NULL(ut_params->op,
2027                         "Failed to allocate symmetric crypto operation struct");
2028
2029         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2030
2031         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2032
2033         /* set crypto operation source mbuf */
2034         sym_op->m_src = ut_params->ibuf;
2035
2036         sym_op->auth.digest.data = ut_params->digest;
2037         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2038                         ut_params->ibuf, QUOTE_512_BYTES);
2039         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
2040
2041         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2042         sym_op->auth.data.length = QUOTE_512_BYTES;
2043
2044         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2045                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2046         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
2047                         ut_params->ibuf, 0);
2048         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2049
2050         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2051                         CIPHER_IV_LENGTH_AES_CBC);
2052
2053         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2054         sym_op->cipher.data.length = QUOTE_512_BYTES;
2055
2056         /* Process crypto operation */
2057         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2058                         ut_params->op), "failed to process sym crypto op");
2059
2060         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2061                         "crypto op processing failed");
2062
2063         ut_params->obuf = ut_params->op->sym->m_src;
2064
2065         /* Validate obuf */
2066         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2067                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
2068                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
2069                         QUOTE_512_BYTES,
2070                         "Plaintext data not as expected");
2071
2072         /* Validate obuf */
2073         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2074                         "Digest verification failed");
2075
2076         return TEST_SUCCESS;
2077 }
2078
2079 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
2080
2081 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
2082         0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
2083         0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
2084         };
2085
2086 static const uint8_t  catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
2087         0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
2088         0x77, 0x1D, 0x8B, 0x75
2089         };
2090
2091 static int
2092 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
2093 {
2094         struct crypto_testsuite_params *ts_params = &testsuite_params;
2095         struct crypto_unittest_params *ut_params = &unittest_params;
2096
2097         /* Generate test mbuf data and space for digest */
2098         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2099                         catch_22_quote, QUOTE_512_BYTES, 0);
2100
2101         /* Setup Cipher Parameters */
2102         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2103         ut_params->cipher_xform.next = &ut_params->auth_xform;
2104
2105         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2106         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2107         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2108         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2109
2110         /* Setup HMAC Parameters */
2111         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2112         ut_params->auth_xform.next = NULL;
2113
2114         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2115         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2116         ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
2117         ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
2118         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
2119
2120         /* Create Crypto session*/
2121         ut_params->sess = rte_cryptodev_sym_session_create(
2122                         ts_params->valid_devs[0],
2123                         &ut_params->cipher_xform);
2124         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2125
2126         /* Generate Crypto op data structure */
2127         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2128                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2129         TEST_ASSERT_NOT_NULL(ut_params->op,
2130                         "Failed to allocate symmetric crypto operation struct");
2131
2132         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2133
2134         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2135
2136         /* set crypto operation source mbuf */
2137         sym_op->m_src = ut_params->ibuf;
2138
2139         /* Set operation cipher parameters */
2140         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2141                         sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
2142         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
2143         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2144
2145         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2146                         CIPHER_IV_LENGTH_AES_CBC);
2147
2148         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2149         sym_op->cipher.data.length = QUOTE_512_BYTES;
2150
2151         /* Set operation authentication parameters */
2152         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2153                         sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
2154         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2155                         sym_op->m_src,
2156                         CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
2157         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
2158
2159         memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
2160
2161         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2162         sym_op->auth.data.length = QUOTE_512_BYTES;
2163
2164
2165         /* Process crypto operation */
2166         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2167                         ut_params->op);
2168         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
2169
2170         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2171                         "crypto op processing failed");
2172
2173         /* Validate obuf */
2174         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2175                         rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
2176                                         uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
2177                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2178                         QUOTE_512_BYTES,
2179                         "Ciphertext data not as expected");
2180
2181         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2182                         rte_pktmbuf_mtod_offset(
2183                                         ut_params->op->sym->m_src, uint8_t *,
2184                                         CIPHER_IV_LENGTH_AES_CBC +
2185                                         QUOTE_512_BYTES),
2186                         catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
2187                         DIGEST_BYTE_LENGTH_AES_XCBC,
2188                         "Generated digest data not as expected");
2189
2190         return TEST_SUCCESS;
2191 }
2192
2193 static int
2194 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
2195 {
2196         struct crypto_testsuite_params *ts_params = &testsuite_params;
2197         struct crypto_unittest_params *ut_params = &unittest_params;
2198
2199         /* Generate test mbuf data and space for digest */
2200         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2201                 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2202                 QUOTE_512_BYTES, 0);
2203
2204         /* Setup Cipher Parameters */
2205         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2206         ut_params->cipher_xform.next = NULL;
2207
2208         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2209         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2210         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2211         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2212
2213         /* Setup HMAC Parameters */
2214         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2215         ut_params->auth_xform.next = &ut_params->cipher_xform;
2216
2217         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2218         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2219         ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
2220         ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
2221         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
2222
2223         /* Create Crypto session*/
2224         ut_params->sess =
2225                 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2226                                                 &ut_params->auth_xform);
2227         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2228
2229         /* Generate Crypto op data structure */
2230         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2231                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2232         TEST_ASSERT_NOT_NULL(ut_params->op,
2233                         "Failed to allocate symmetric crypto operation struct");
2234
2235         /* Set crypto operation data parameters */
2236         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2237
2238         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2239
2240         /* set crypto operation source mbuf */
2241         sym_op->m_src = ut_params->ibuf;
2242
2243
2244         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2245                                 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
2246         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2247                         "no room to append digest");
2248
2249         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2250                         ut_params->ibuf, QUOTE_512_BYTES);
2251         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
2252
2253         rte_memcpy(sym_op->auth.digest.data,
2254                         catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
2255                         DIGEST_BYTE_LENGTH_AES_XCBC);
2256
2257         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2258         sym_op->auth.data.length = QUOTE_512_BYTES;
2259
2260         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2261                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2262         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2263         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2264
2265         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2266                         CIPHER_IV_LENGTH_AES_CBC);
2267
2268         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2269         sym_op->cipher.data.length = QUOTE_512_BYTES;
2270
2271         /* Process crypto operation */
2272         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2273                         ut_params->op), "failed to process sym crypto op");
2274
2275         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2276                         "crypto op processing failed");
2277
2278         ut_params->obuf = ut_params->op->sym->m_src;
2279
2280         /* Validate obuf */
2281         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2282                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
2283                         CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
2284                         QUOTE_512_BYTES,
2285                         "Ciphertext data not as expected");
2286
2287         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2288                         "Digest verification failed");
2289
2290         return TEST_SUCCESS;
2291 }
2292
2293 /* ***** Snow3G Tests ***** */
2294 static int
2295 create_snow3g_hash_session(uint8_t dev_id,
2296         const uint8_t *key, const uint8_t key_len,
2297         const uint8_t aad_len, const uint8_t auth_len,
2298         enum rte_crypto_auth_operation op)
2299 {
2300         uint8_t hash_key[key_len];
2301
2302         struct crypto_unittest_params *ut_params = &unittest_params;
2303
2304         memcpy(hash_key, key, key_len);
2305 #ifdef RTE_APP_TEST_DEBUG
2306         rte_hexdump(stdout, "key:", key, key_len);
2307 #endif
2308         /* Setup Authentication Parameters */
2309         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2310         ut_params->auth_xform.next = NULL;
2311
2312         ut_params->auth_xform.auth.op = op;
2313         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2314         ut_params->auth_xform.auth.key.length = key_len;
2315         ut_params->auth_xform.auth.key.data = hash_key;
2316         ut_params->auth_xform.auth.digest_length = auth_len;
2317         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2318         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2319                                 &ut_params->auth_xform);
2320         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2321         return 0;
2322 }
2323 static int
2324 create_snow3g_cipher_session(uint8_t dev_id,
2325                         enum rte_crypto_cipher_operation op,
2326                         const uint8_t *key, const uint8_t key_len)
2327 {
2328         uint8_t cipher_key[key_len];
2329
2330         struct crypto_unittest_params *ut_params = &unittest_params;
2331
2332         memcpy(cipher_key, key, key_len);
2333
2334         /* Setup Cipher Parameters */
2335         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2336         ut_params->cipher_xform.next = NULL;
2337
2338         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2339         ut_params->cipher_xform.cipher.op = op;
2340         ut_params->cipher_xform.cipher.key.data = cipher_key;
2341         ut_params->cipher_xform.cipher.key.length = key_len;
2342
2343 #ifdef RTE_APP_TEST_DEBUG
2344         rte_hexdump(stdout, "key:", key, key_len);
2345 #endif
2346         /* Create Crypto session */
2347         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2348                                                 &ut_params->
2349                                                 cipher_xform);
2350         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2351         return 0;
2352 }
2353
2354 static int
2355 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
2356                         const unsigned cipher_len,
2357                         const unsigned cipher_offset)
2358 {
2359         struct crypto_testsuite_params *ts_params = &testsuite_params;
2360         struct crypto_unittest_params *ut_params = &unittest_params;
2361         unsigned iv_pad_len = 0;
2362
2363         /* Generate Crypto op data structure */
2364         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2365                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2366         TEST_ASSERT_NOT_NULL(ut_params->op,
2367                                 "Failed to allocate pktmbuf offload");
2368
2369         /* Set crypto operation data parameters */
2370         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2371
2372         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2373
2374         /* set crypto operation source mbuf */
2375         sym_op->m_src = ut_params->ibuf;
2376
2377         /* iv */
2378         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2379         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2380                         , iv_pad_len);
2381
2382         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2383
2384         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2385         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2386         sym_op->cipher.iv.length = iv_pad_len;
2387
2388         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2389         sym_op->cipher.data.length = cipher_len;
2390         sym_op->cipher.data.offset = cipher_offset;
2391         return 0;
2392 }
2393
2394 static int
2395 create_snow3g_cipher_operation_oop(const uint8_t *iv, const unsigned iv_len,
2396                         const unsigned cipher_len,
2397                         const unsigned cipher_offset)
2398 {
2399         struct crypto_testsuite_params *ts_params = &testsuite_params;
2400         struct crypto_unittest_params *ut_params = &unittest_params;
2401         unsigned iv_pad_len = 0;
2402
2403         /* Generate Crypto op data structure */
2404         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2405                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2406         TEST_ASSERT_NOT_NULL(ut_params->op,
2407                                 "Failed to allocate pktmbuf offload");
2408
2409         /* Set crypto operation data parameters */
2410         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2411
2412         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2413
2414         /* set crypto operation source mbuf */
2415         sym_op->m_src = ut_params->ibuf;
2416         sym_op->m_dst = ut_params->obuf;
2417
2418         /* iv */
2419         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2420         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2421                         , iv_pad_len);
2422
2423         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2424
2425         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2426         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2427         sym_op->cipher.iv.length = iv_pad_len;
2428
2429         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2430         sym_op->cipher.data.length = cipher_len;
2431         sym_op->cipher.data.offset = cipher_offset;
2432         return 0;
2433 }
2434
2435 static int
2436 create_snow3g_cipher_auth_session(uint8_t dev_id,
2437                 enum rte_crypto_cipher_operation cipher_op,
2438                 enum rte_crypto_auth_operation auth_op,
2439                 const uint8_t *key, const uint8_t key_len,
2440                 const uint8_t aad_len, const uint8_t auth_len)
2441 {
2442         uint8_t cipher_auth_key[key_len];
2443
2444         struct crypto_unittest_params *ut_params = &unittest_params;
2445
2446         memcpy(cipher_auth_key, key, key_len);
2447
2448         /* Setup Authentication Parameters */
2449         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2450         ut_params->auth_xform.next = NULL;
2451
2452         ut_params->auth_xform.auth.op = auth_op;
2453         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2454         ut_params->auth_xform.auth.key.length = key_len;
2455         /* Hash key = cipher key */
2456         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2457         ut_params->auth_xform.auth.digest_length = auth_len;
2458         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2459
2460         /* Setup Cipher Parameters */
2461         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2462         ut_params->cipher_xform.next = &ut_params->auth_xform;
2463
2464         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2465         ut_params->cipher_xform.cipher.op = cipher_op;
2466         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2467         ut_params->cipher_xform.cipher.key.length = key_len;
2468
2469 #ifdef RTE_APP_TEST_DEBUG
2470         rte_hexdump(stdout, "key:", key, key_len);
2471 #endif
2472         /* Create Crypto session*/
2473         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2474                                 &ut_params->cipher_xform);
2475
2476         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2477         return 0;
2478 }
2479
2480 static int
2481 create_snow3g_auth_cipher_session(uint8_t dev_id,
2482                 enum rte_crypto_cipher_operation cipher_op,
2483                 enum rte_crypto_auth_operation auth_op,
2484                 const uint8_t *key, const uint8_t key_len,
2485                 const uint8_t aad_len, const uint8_t auth_len)
2486         {
2487         uint8_t auth_cipher_key[key_len];
2488
2489         struct crypto_unittest_params *ut_params = &unittest_params;
2490
2491         memcpy(auth_cipher_key, key, key_len);
2492
2493         /* Setup Authentication Parameters */
2494         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2495         ut_params->auth_xform.auth.op = auth_op;
2496         ut_params->auth_xform.next = &ut_params->cipher_xform;
2497         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2498         ut_params->auth_xform.auth.key.length = key_len;
2499         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2500         ut_params->auth_xform.auth.digest_length = auth_len;
2501         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2502
2503         /* Setup Cipher Parameters */
2504         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2505         ut_params->cipher_xform.next = NULL;
2506         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2507         ut_params->cipher_xform.cipher.op = cipher_op;
2508         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2509         ut_params->cipher_xform.cipher.key.length = key_len;
2510
2511 #ifdef RTE_APP_TEST_DEBUG
2512         rte_hexdump(stdout, "key:", key, key_len);
2513 #endif
2514         /* Create Crypto session*/
2515         ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2516                                 &ut_params->auth_xform);
2517
2518         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2519
2520         return 0;
2521 }
2522
2523 static int
2524 create_snow3g_hash_operation(const uint8_t *auth_tag,
2525                 const unsigned auth_tag_len,
2526                 const uint8_t *aad, const unsigned aad_len,
2527                 unsigned data_pad_len,
2528                 enum rte_crypto_auth_operation op,
2529                 const unsigned auth_len, const unsigned auth_offset)
2530 {
2531         struct crypto_testsuite_params *ts_params = &testsuite_params;
2532
2533         struct crypto_unittest_params *ut_params = &unittest_params;
2534
2535         unsigned aad_buffer_len;
2536
2537         /* Generate Crypto op data structure */
2538         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2539                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2540         TEST_ASSERT_NOT_NULL(ut_params->op,
2541                 "Failed to allocate pktmbuf offload");
2542
2543         /* Set crypto operation data parameters */
2544         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2545
2546         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2547
2548         /* set crypto operation source mbuf */
2549         sym_op->m_src = ut_params->ibuf;
2550
2551         /* aad */
2552         /*
2553         * Always allocate the aad up to the block size.
2554         * The cryptodev API calls out -
2555         *  - the array must be big enough to hold the AAD, plus any
2556         *   space to round this up to the nearest multiple of the
2557         *   block size (16 bytes).
2558         */
2559         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2560         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2561                         ut_params->ibuf, aad_buffer_len);
2562         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2563                                         "no room to prepend aad");
2564         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2565                         ut_params->ibuf);
2566         sym_op->auth.aad.length = aad_len;
2567
2568         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2569         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2570
2571 #ifdef RTE_APP_TEST_DEBUG
2572         rte_hexdump(stdout, "aad:",
2573                         sym_op->auth.aad.data, aad_len);
2574 #endif
2575
2576         /* digest */
2577         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2578                                         ut_params->ibuf, auth_tag_len);
2579
2580         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2581                                 "no room to append auth tag");
2582         ut_params->digest = sym_op->auth.digest.data;
2583         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2584                         ut_params->ibuf, data_pad_len + aad_len);
2585         sym_op->auth.digest.length = auth_tag_len;
2586         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2587                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2588         else
2589                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2590
2591 #ifdef RTE_APP_TEST_DEBUG
2592         rte_hexdump(stdout, "digest:",
2593                 sym_op->auth.digest.data,
2594                 sym_op->auth.digest.length);
2595 #endif
2596
2597         sym_op->auth.data.length = auth_len;
2598         sym_op->auth.data.offset = auth_offset;
2599
2600         return 0;
2601 }
2602
2603 static int
2604 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2605                 const unsigned auth_tag_len,
2606                 const uint8_t *aad, const uint8_t aad_len,
2607                 unsigned data_pad_len,
2608                 enum rte_crypto_auth_operation op,
2609                 const uint8_t *iv, const uint8_t iv_len,
2610                 const unsigned cipher_len, const unsigned cipher_offset,
2611                 const unsigned auth_len, const unsigned auth_offset)
2612 {
2613         struct crypto_testsuite_params *ts_params = &testsuite_params;
2614         struct crypto_unittest_params *ut_params = &unittest_params;
2615
2616         unsigned iv_pad_len = 0;
2617         unsigned aad_buffer_len;
2618
2619         /* Generate Crypto op data structure */
2620         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2621                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2622         TEST_ASSERT_NOT_NULL(ut_params->op,
2623                         "Failed to allocate pktmbuf offload");
2624         /* Set crypto operation data parameters */
2625         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2626
2627         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2628
2629         /* set crypto operation source mbuf */
2630         sym_op->m_src = ut_params->ibuf;
2631
2632
2633         /* iv */
2634         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2635
2636         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2637                 ut_params->ibuf, iv_pad_len);
2638         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2639
2640         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2641         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2642         sym_op->cipher.iv.length = iv_pad_len;
2643
2644         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2645
2646         sym_op->cipher.data.length = cipher_len;
2647         sym_op->cipher.data.offset = cipher_offset;
2648
2649         /* aad */
2650         /*
2651         * Always allocate the aad up to the block size.
2652         * The cryptodev API calls out -
2653         *  - the array must be big enough to hold the AAD, plus any
2654         *   space to round this up to the nearest multiple of the
2655         *   block size (16 bytes).
2656         */
2657         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2658
2659         sym_op->auth.aad.data =
2660                         (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2661         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2662                         "no room to prepend aad");
2663         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2664                         ut_params->ibuf);
2665         sym_op->auth.aad.length = aad_len;
2666
2667         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2668         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2669
2670 #ifdef RTE_APP_TEST_DEBUG
2671         rte_hexdump(stdout, "aad:",
2672                         sym_op->auth.aad.data, aad_len);
2673 #endif
2674
2675         /* digest */
2676         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2677                         ut_params->ibuf, auth_tag_len);
2678
2679         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2680                         "no room to append auth tag");
2681         ut_params->digest = sym_op->auth.digest.data;
2682         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2683                         ut_params->ibuf, data_pad_len + aad_len);
2684         sym_op->auth.digest.length = auth_tag_len;
2685         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2686                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2687         else
2688                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2689
2690         #ifdef RTE_APP_TEST_DEBUG
2691         rte_hexdump(stdout, "digest:",
2692                 sym_op->auth.digest.data,
2693                 sym_op->auth.digest.length);
2694         #endif
2695
2696         sym_op->auth.data.length = auth_len;
2697         sym_op->auth.data.offset = auth_offset;
2698
2699         return 0;
2700 }
2701
2702 static int
2703 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2704                 const uint8_t *iv, const uint8_t iv_len,
2705                 const uint8_t *aad, const uint8_t aad_len,
2706                 unsigned data_pad_len,
2707                 const unsigned cipher_len, const unsigned cipher_offset,
2708                 const unsigned auth_len, const unsigned auth_offset)
2709 {
2710         struct crypto_testsuite_params *ts_params = &testsuite_params;
2711         struct crypto_unittest_params *ut_params = &unittest_params;
2712
2713         unsigned iv_pad_len = 0;
2714         unsigned aad_buffer_len = 0;
2715
2716         /* Generate Crypto op data structure */
2717         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2718                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2719         TEST_ASSERT_NOT_NULL(ut_params->op,
2720                         "Failed to allocate pktmbuf offload");
2721
2722         /* Set crypto operation data parameters */
2723         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2724
2725         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2726
2727         /* set crypto operation source mbuf */
2728         sym_op->m_src = ut_params->ibuf;
2729
2730         /* digest */
2731         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2732                         ut_params->ibuf, auth_tag_len);
2733
2734         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2735                         "no room to append auth tag");
2736
2737         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2738                         ut_params->ibuf, data_pad_len);
2739         sym_op->auth.digest.length = auth_tag_len;
2740
2741         memset(sym_op->auth.digest.data, 0, auth_tag_len);
2742
2743         #ifdef RTE_APP_TEST_DEBUG
2744                 rte_hexdump(stdout, "digest:",
2745                         sym_op->auth.digest.data,
2746                         sym_op->auth.digest.length);
2747         #endif
2748         /* iv */
2749         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2750
2751         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2752                 ut_params->ibuf, iv_pad_len);
2753         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2754
2755         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2756         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2757         sym_op->cipher.iv.length = iv_pad_len;
2758
2759         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2760
2761         /* aad */
2762         /*
2763         * Always allocate the aad up to the block size.
2764         * The cryptodev API calls out -
2765         *  - the array must be big enough to hold the AAD, plus any
2766         *   space to round this up to the nearest multiple of the
2767         *   block size (16 bytes).
2768         */
2769         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2770
2771         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2772         ut_params->ibuf, aad_buffer_len);
2773         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2774                                 "no room to prepend aad");
2775         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2776                                 ut_params->ibuf);
2777         sym_op->auth.aad.length = aad_len;
2778
2779         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2780         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2781
2782 #ifdef RTE_APP_TEST_DEBUG
2783         rte_hexdump(stdout, "aad:",
2784                         sym_op->auth.aad.data, aad_len);
2785 #endif
2786
2787         sym_op->cipher.data.length = cipher_len;
2788         sym_op->cipher.data.offset = auth_offset + cipher_offset;
2789
2790         sym_op->auth.data.length = auth_len;
2791         sym_op->auth.data.offset = auth_offset + cipher_offset;
2792
2793         return 0;
2794 }
2795
2796 static int
2797 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2798 {
2799         struct crypto_testsuite_params *ts_params = &testsuite_params;
2800         struct crypto_unittest_params *ut_params = &unittest_params;
2801
2802         int retval;
2803         unsigned plaintext_pad_len;
2804         uint8_t *plaintext;
2805
2806         /* Create SNOW3G session */
2807         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2808                         tdata->key.data, tdata->key.len,
2809                         tdata->aad.len, tdata->digest.len,
2810                         RTE_CRYPTO_AUTH_OP_GENERATE);
2811         if (retval < 0)
2812                 return retval;
2813
2814         /* alloc mbuf and set payload */
2815         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2816
2817         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2818         rte_pktmbuf_tailroom(ut_params->ibuf));
2819
2820         /* Append data which is padded to a multiple of */
2821         /* the algorithms block size */
2822         plaintext_pad_len = tdata->plaintext.len >> 3;
2823         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2824                                 plaintext_pad_len);
2825         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2826
2827         /* Create SNOW3G opertaion */
2828         retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2829                         tdata->aad.data, tdata->aad.len,
2830                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2831                         tdata->validAuthLenInBits.len,
2832                         tdata->validAuthOffsetLenInBits.len);
2833         if (retval < 0)
2834                 return retval;
2835
2836         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2837                                 ut_params->op);
2838         ut_params->obuf = ut_params->op->sym->m_src;
2839         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2840         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2841                         + plaintext_pad_len + tdata->aad.len;
2842
2843         /* Validate obuf */
2844         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2845         ut_params->digest,
2846         tdata->digest.data,
2847         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2848         "Snow3G Generated auth tag not as expected");
2849
2850         return 0;
2851 }
2852
2853 static int
2854 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2855 {
2856         struct crypto_testsuite_params *ts_params = &testsuite_params;
2857         struct crypto_unittest_params *ut_params = &unittest_params;
2858
2859         int retval;
2860         unsigned plaintext_pad_len;
2861         uint8_t *plaintext;
2862
2863         /* Create SNOW3G session */
2864         retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2865                                 tdata->key.data, tdata->key.len,
2866                                 tdata->aad.len, tdata->digest.len,
2867                                 RTE_CRYPTO_AUTH_OP_VERIFY);
2868         if (retval < 0)
2869                 return retval;
2870         /* alloc mbuf and set payload */
2871         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2872
2873         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2874         rte_pktmbuf_tailroom(ut_params->ibuf));
2875
2876         /* Append data which is padded to a multiple */
2877         /* of the algorithms block size */
2878         plaintext_pad_len = tdata->plaintext.len >> 3;
2879         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2880                                         plaintext_pad_len);
2881         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2882
2883         /* Create SNOW3G operation */
2884         retval = create_snow3g_hash_operation(tdata->digest.data,
2885                         tdata->digest.len,
2886                         tdata->aad.data, tdata->aad.len,
2887                         plaintext_pad_len,
2888                         RTE_CRYPTO_AUTH_OP_VERIFY,
2889                         tdata->validAuthLenInBits.len,
2890                         tdata->validAuthOffsetLenInBits.len);
2891         if (retval < 0)
2892                 return retval;
2893
2894         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2895                                 ut_params->op);
2896         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2897         ut_params->obuf = ut_params->op->sym->m_src;
2898         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2899                                 + plaintext_pad_len + tdata->aad.len;
2900
2901         /* Validate obuf */
2902         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2903                 return 0;
2904         else
2905                 return -1;
2906
2907         return 0;
2908 }
2909
2910
2911 static int
2912 test_snow3g_hash_generate_test_case_1(void)
2913 {
2914         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2915 }
2916
2917 static int
2918 test_snow3g_hash_generate_test_case_2(void)
2919 {
2920         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2921 }
2922
2923 static int
2924 test_snow3g_hash_generate_test_case_3(void)
2925 {
2926         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2927 }
2928
2929 static int
2930 test_snow3g_hash_verify_test_case_1(void)
2931 {
2932         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2933
2934 }
2935
2936 static int
2937 test_snow3g_hash_verify_test_case_2(void)
2938 {
2939         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2940 }
2941
2942 static int
2943 test_snow3g_hash_verify_test_case_3(void)
2944 {
2945         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2946 }
2947
2948 static int
2949 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2950 {
2951         struct crypto_testsuite_params *ts_params = &testsuite_params;
2952         struct crypto_unittest_params *ut_params = &unittest_params;
2953
2954         int retval;
2955         uint8_t *plaintext, *ciphertext;
2956         uint8_t plaintext_pad_len;
2957         uint8_t lastByteValidBits = 8;
2958         uint8_t lastByteMask = 0xFF;
2959
2960         /* Create SNOW3G session */
2961         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2962                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2963                                         tdata->key.data, tdata->key.len);
2964         if (retval < 0)
2965                 return retval;
2966
2967         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2968
2969         /* Clear mbuf payload */
2970         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2971                rte_pktmbuf_tailroom(ut_params->ibuf));
2972
2973         /*
2974          * Append data which is padded to a
2975          * multiple of the algorithms block size
2976          */
2977         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2978         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2979
2980         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2981                                                 plaintext_pad_len);
2982         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2983
2984 #ifdef RTE_APP_TEST_DEBUG
2985         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2986 #endif
2987         /* Create SNOW3G operation */
2988         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2989                                         tdata->validCipherLenInBits.len,
2990                                         tdata->validCipherOffsetLenInBits.len);
2991         if (retval < 0)
2992                 return retval;
2993
2994         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2995                                                 ut_params->op);
2996         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2997
2998         ut_params->obuf = ut_params->op->sym->m_dst;
2999         if (ut_params->obuf)
3000                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3001                                 + tdata->iv.len;
3002         else
3003                 ciphertext = plaintext;
3004
3005         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3006         if (lastByteValidBits == 0)
3007                 lastByteValidBits = 8;
3008         lastByteMask = lastByteMask << (8 - lastByteValidBits);
3009         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3010
3011 #ifdef RTE_APP_TEST_DEBUG
3012         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3013 #endif
3014         /* Validate obuf */
3015         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3016                 ciphertext,
3017                 tdata->ciphertext.data,
3018                 tdata->ciphertext.len >> 3,
3019                 "Snow3G Ciphertext data not as expected");
3020         return 0;
3021 }
3022
3023
3024 static int
3025 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3026 {
3027         struct crypto_testsuite_params *ts_params = &testsuite_params;
3028         struct crypto_unittest_params *ut_params = &unittest_params;
3029         uint8_t *plaintext, *ciphertext;
3030
3031         int retval;
3032         uint8_t plaintext_pad_len;
3033         uint8_t lastByteValidBits = 8;
3034         uint8_t lastByteMask = 0xFF;
3035
3036         /* Create SNOW3G session */
3037         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3038                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3039                                         tdata->key.data, tdata->key.len);
3040         if (retval < 0)
3041                 return retval;
3042
3043         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3044         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3045
3046         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3047                         "Failed to allocate input buffer in mempool");
3048         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3049                         "Failed to allocate output buffer in mempool");
3050
3051         /* Clear mbuf payload */
3052         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3053                rte_pktmbuf_tailroom(ut_params->ibuf));
3054
3055         /*
3056          * Append data which is padded to a
3057          * multiple of the algorithms block size
3058          */
3059         /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
3060         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
3061
3062         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3063                                                 plaintext_pad_len);
3064
3065         rte_pktmbuf_append(ut_params->obuf,
3066                                                 plaintext_pad_len);
3067
3068         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3069
3070 #ifdef RTE_APP_TEST_DEBUG
3071         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3072 #endif
3073         /* Create SNOW3G operation */
3074         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
3075                                         tdata->iv.len,
3076                                         tdata->validCipherLenInBits.len,
3077                                         tdata->validCipherOffsetLenInBits.len);
3078         if (retval < 0)
3079                 return retval;
3080
3081         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3082                                                 ut_params->op);
3083         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3084
3085         ut_params->obuf = ut_params->op->sym->m_dst;
3086         if (ut_params->obuf)
3087                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3088                                 + tdata->iv.len;
3089         else
3090                 ciphertext = plaintext;
3091
3092         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3093         if (lastByteValidBits == 0)
3094                 lastByteValidBits = 8;
3095         lastByteMask = lastByteMask << (8 - lastByteValidBits);
3096         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3097
3098 #ifdef RTE_APP_TEST_DEBUG
3099         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3100 #endif
3101         /* Validate obuf */
3102         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3103                 ciphertext,
3104                 tdata->ciphertext.data,
3105                 tdata->ciphertext.len >> 3,
3106                 "Snow3G Ciphertext data not as expected");
3107         return 0;
3108 }
3109
3110
3111 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3112 {
3113         struct crypto_testsuite_params *ts_params = &testsuite_params;
3114         struct crypto_unittest_params *ut_params = &unittest_params;
3115
3116         int retval;
3117
3118         uint8_t *plaintext, *ciphertext;
3119         uint8_t ciphertext_pad_len;
3120         uint8_t lastByteValidBits = 8;
3121         uint8_t lastByteMask = 0xFF;
3122
3123         /* Create SNOW3G session */
3124         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3125                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3126                                         tdata->key.data, tdata->key.len);
3127         if (retval < 0)
3128                 return retval;
3129
3130         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3131
3132         /* Clear mbuf payload */
3133         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3134                rte_pktmbuf_tailroom(ut_params->ibuf));
3135
3136         /*
3137          * Append data which is padded to a
3138          * multiple of the algorithms block size
3139          */
3140         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
3141
3142         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3143                                                 ciphertext_pad_len);
3144         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
3145
3146 #ifdef RTE_APP_TEST_DEBUG
3147         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3148 #endif
3149         /* Create SNOW3G operation */
3150         retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
3151                                         tdata->validCipherLenInBits.len,
3152                                         tdata->validCipherOffsetLenInBits.len);
3153         if (retval < 0)
3154                 return retval;
3155
3156         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3157                                                 ut_params->op);
3158         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3159         ut_params->obuf = ut_params->op->sym->m_src;
3160         if (ut_params->obuf)
3161                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3162                                 + tdata->iv.len;
3163         else
3164                 plaintext = ciphertext;
3165         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
3166         if (lastByteValidBits == 0)
3167                 lastByteValidBits = 8;
3168         lastByteMask = lastByteMask << (8 - lastByteValidBits);
3169         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3170
3171 #ifdef RTE_APP_TEST_DEBUG
3172         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3173 #endif
3174         /* Validate obuf */
3175         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
3176                                 tdata->plaintext.data,
3177                                 tdata->plaintext.len >> 3,
3178                                 "Snow3G Plaintext data not as expected");
3179         return 0;
3180 }
3181
3182 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3183 {
3184         struct crypto_testsuite_params *ts_params = &testsuite_params;
3185         struct crypto_unittest_params *ut_params = &unittest_params;
3186
3187         int retval;
3188
3189         uint8_t *plaintext, *ciphertext;
3190         uint8_t ciphertext_pad_len;
3191         uint8_t lastByteValidBits = 8;
3192         uint8_t lastByteMask = 0xFF;
3193
3194         /* Create SNOW3G session */
3195         retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3196                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3197                                         tdata->key.data, tdata->key.len);
3198         if (retval < 0)
3199                 return retval;
3200
3201         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3202         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3203
3204         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3205                         "Failed to allocate input buffer");
3206         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3207                         "Failed to allocate output buffer");
3208
3209         /* Clear mbuf payload */
3210         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3211                rte_pktmbuf_tailroom(ut_params->ibuf));
3212
3213         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3214                        rte_pktmbuf_tailroom(ut_params->obuf));
3215
3216         /*
3217          * Append data which is padded to a
3218          * multiple of the algorithms block size
3219          */
3220         ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
3221
3222         ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3223                                                 ciphertext_pad_len);
3224
3225         rte_pktmbuf_append(ut_params->obuf,
3226                                                 ciphertext_pad_len);
3227
3228         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
3229
3230 #ifdef RTE_APP_TEST_DEBUG
3231         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3232 #endif
3233         /* Create SNOW3G operation */
3234         retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
3235                                         tdata->iv.len,
3236                                         tdata->validCipherLenInBits.len,
3237                                         tdata->validCipherOffsetLenInBits.len);
3238         if (retval < 0)
3239                 return retval;
3240
3241         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3242                                                 ut_params->op);
3243         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3244         ut_params->obuf = ut_params->op->sym->m_dst;
3245         if (ut_params->obuf)
3246                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3247                                 + tdata->iv.len;
3248         else
3249                 plaintext = ciphertext;
3250         lastByteValidBits = (tdata->validDataLenInBits.len  % 8);
3251         if (lastByteValidBits == 0)
3252                 lastByteValidBits = 8;
3253         lastByteMask = lastByteMask << (8 - lastByteValidBits);
3254         (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3255
3256 #ifdef RTE_APP_TEST_DEBUG
3257         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3258 #endif
3259         /* Validate obuf */
3260         TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
3261                                 tdata->plaintext.data,
3262                                 tdata->plaintext.len >> 3,
3263                                 "Snow3G Plaintext data not as expected");
3264         return 0;
3265 }
3266
3267 static int
3268 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
3269 {
3270         struct crypto_testsuite_params *ts_params = &testsuite_params;
3271         struct crypto_unittest_params *ut_params = &unittest_params;
3272
3273         int retval;
3274
3275         uint8_t *plaintext, *ciphertext;
3276         uint8_t plaintext_pad_len;
3277         uint8_t lastByteValidBits = 8;
3278         uint8_t lastByteMask = 0xFF;
3279
3280         /* Create SNOW3G session */
3281         retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
3282                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3283                         RTE_CRYPTO_AUTH_OP_GENERATE,
3284                         tdata->key.data, tdata->key.len,
3285                         tdata->aad.len, tdata->digest.len);
3286         if (retval < 0)
3287                 return retval;
3288         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3289
3290         /* clear mbuf payload */
3291         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3292                         rte_pktmbuf_tailroom(ut_params->ibuf));
3293
3294         /* Append data which is padded to a multiple */
3295         /*  of the algorithms block size */
3296         plaintext_pad_len = tdata->plaintext.len >> 3;
3297
3298         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3299                         plaintext_pad_len);
3300         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3301
3302 #ifdef RTE_APP_TEST_DEBUG
3303         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3304 #endif
3305
3306         /* Create SNOW3G operation */
3307         retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
3308                         tdata->digest.len, tdata->aad.data,
3309                         tdata->aad.len, /*tdata->plaintext.len,*/
3310                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3311                         tdata->iv.data, tdata->iv.len,
3312                         tdata->validCipherLenInBits.len,
3313                         tdata->validCipherOffsetLenInBits.len,
3314                         tdata->validAuthLenInBits.len,
3315                         tdata->validAuthOffsetLenInBits.len);
3316         if (retval < 0)
3317                 return retval;
3318
3319         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3320                         ut_params->op);
3321         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3322         ut_params->obuf = ut_params->op->sym->m_src;
3323         if (ut_params->obuf)
3324                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3325                                 + tdata->iv.len;
3326         else
3327                 ciphertext = plaintext;
3328         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3329         if (lastByteValidBits == 0)
3330                 lastByteValidBits = 8;
3331         lastByteMask = lastByteMask << (8-lastByteValidBits);
3332         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3333
3334 #ifdef RTE_APP_TEST_DEBUG
3335         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3336 #endif
3337         /* Validate obuf */
3338         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3339                         ciphertext,
3340                         tdata->ciphertext.data,
3341                         tdata->ciphertext.len >> 3,
3342                         "Snow3G Ciphertext data not as expected");
3343
3344         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3345             + plaintext_pad_len + tdata->aad.len;
3346
3347         /* Validate obuf */
3348         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3349                         ut_params->digest,
3350                         tdata->digest.data,
3351                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3352                         "Snow3G Generated auth tag not as expected");
3353         return 0;
3354 }
3355 static int
3356 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
3357 {
3358         struct crypto_testsuite_params *ts_params = &testsuite_params;
3359         struct crypto_unittest_params *ut_params = &unittest_params;
3360
3361         int retval;
3362
3363         uint8_t *plaintext, *ciphertext;
3364         uint8_t plaintext_pad_len;
3365         uint8_t lastByteValidBits = 8;
3366         uint8_t lastByteMask = 0xFF;
3367
3368         /* Create SNOW3G session */
3369         retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
3370                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3371                         RTE_CRYPTO_AUTH_OP_GENERATE,
3372                         tdata->key.data, tdata->key.len,
3373                         tdata->aad.len, tdata->digest.len);
3374         if (retval < 0)
3375                 return retval;
3376
3377         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3378
3379         /* clear mbuf payload */
3380         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3381                         rte_pktmbuf_tailroom(ut_params->ibuf));
3382
3383         /* Append data which is padded to a multiple */
3384         /* of the algorithms block size */
3385         plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
3386
3387         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3388                         plaintext_pad_len);
3389         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3390
3391 #ifdef RTE_APP_TEST_DEBUG
3392         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3393 #endif
3394
3395         /* Create SNOW3G operation */
3396         retval = create_snow3g_auth_cipher_operation(
3397                 tdata->digest.len,
3398                 tdata->iv.data, tdata->iv.len,
3399                 tdata->aad.data, tdata->aad.len,
3400                 plaintext_pad_len,
3401                 tdata->validCipherLenInBits.len,
3402                 tdata->validCipherOffsetLenInBits.len,
3403                 tdata->validAuthLenInBits.len,
3404                 tdata->validAuthOffsetLenInBits.len
3405         );
3406
3407         if (retval < 0)
3408                 return retval;
3409
3410         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3411                         ut_params->op);
3412         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3413         ut_params->obuf = ut_params->op->sym->m_src;
3414         if (ut_params->obuf)
3415                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3416                                 + tdata->aad.len + tdata->iv.len;
3417         else
3418                 ciphertext = plaintext;
3419
3420         lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3421         if (lastByteValidBits == 0)
3422                 lastByteValidBits = 8;
3423         lastByteMask = lastByteMask << (8-lastByteValidBits);
3424         (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3425         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3426                         + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3427         #ifdef RTE_APP_TEST_DEBUG
3428         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3429 #endif
3430         /* Validate obuf */
3431         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3432                 ciphertext,
3433                 tdata->ciphertext.data,
3434                 tdata->ciphertext.len >> 3,
3435                 "Snow3G Ciphertext data not as expected");
3436
3437         /* Validate obuf */
3438         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3439                 ut_params->digest,
3440                 tdata->digest.data,
3441                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3442                 "Snow3G Generated auth tag not as expected");
3443         return 0;
3444 }
3445
3446 static int
3447 test_snow3g_encryption_test_case_1(void)
3448 {
3449         return test_snow3g_encryption(&snow3g_test_case_1);
3450 }
3451
3452 static int
3453 test_snow3g_encryption_test_case_1_oop(void)
3454 {
3455         return test_snow3g_encryption_oop(&snow3g_test_case_1);
3456 }
3457
3458 static int
3459 test_snow3g_encryption_test_case_2(void)
3460 {
3461         return test_snow3g_encryption(&snow3g_test_case_2);
3462 }
3463
3464 static int
3465 test_snow3g_encryption_test_case_3(void)
3466 {
3467         return test_snow3g_encryption(&snow3g_test_case_3);
3468 }
3469
3470 static int
3471 test_snow3g_encryption_test_case_4(void)
3472 {
3473         return test_snow3g_encryption(&snow3g_test_case_4);
3474 }
3475
3476 static int
3477 test_snow3g_encryption_test_case_5(void)
3478 {
3479         return test_snow3g_encryption(&snow3g_test_case_5);
3480 }
3481
3482 static int
3483 test_snow3g_decryption_test_case_1(void)
3484 {
3485         return test_snow3g_decryption(&snow3g_test_case_1);
3486 }
3487
3488 static int
3489 test_snow3g_decryption_test_case_1_oop(void)
3490 {
3491         return test_snow3g_decryption_oop(&snow3g_test_case_1);
3492 }
3493
3494 static int
3495 test_snow3g_decryption_test_case_2(void)
3496 {
3497         return test_snow3g_decryption(&snow3g_test_case_2);
3498 }
3499
3500 static int
3501 test_snow3g_decryption_test_case_3(void)
3502 {
3503         return test_snow3g_decryption(&snow3g_test_case_3);
3504 }
3505
3506 static int
3507 test_snow3g_decryption_test_case_4(void)
3508 {
3509         return test_snow3g_decryption(&snow3g_test_case_4);
3510 }
3511
3512 static int
3513 test_snow3g_decryption_test_case_5(void)
3514 {
3515         return test_snow3g_decryption(&snow3g_test_case_5);
3516 }
3517 static int
3518 test_snow3g_authenticated_encryption_test_case_1(void)
3519 {
3520         return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
3521 }
3522
3523 static int
3524 test_snow3g_encrypted_authentication_test_case_1(void)
3525 {
3526         return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
3527 }
3528
3529 /* ***** AES-GCM Tests ***** */
3530
3531 static int
3532 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3533                 const uint8_t *key, const uint8_t key_len,
3534                 const uint8_t aad_len, const uint8_t auth_len)
3535 {
3536         uint8_t cipher_key[key_len];
3537
3538         struct crypto_unittest_params *ut_params = &unittest_params;
3539
3540
3541         memcpy(cipher_key, key, key_len);
3542
3543         /* Setup Cipher Parameters */
3544         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3545         ut_params->cipher_xform.next = NULL;
3546
3547         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3548         ut_params->cipher_xform.cipher.op = op;
3549         ut_params->cipher_xform.cipher.key.data = cipher_key;
3550         ut_params->cipher_xform.cipher.key.length = key_len;
3551
3552 #ifdef RTE_APP_TEST_DEBUG
3553         rte_hexdump(stdout, "key:", key, key_len);
3554 #endif
3555         /* Setup Authentication Parameters */
3556         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3557         ut_params->auth_xform.next = NULL;
3558
3559         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3560
3561         ut_params->auth_xform.auth.digest_length = auth_len;
3562         ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3563         ut_params->auth_xform.auth.key.length = 0;
3564         ut_params->auth_xform.auth.key.data = NULL;
3565
3566         if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3567                 ut_params->cipher_xform.next = &ut_params->auth_xform;
3568
3569                 /* Create Crypto session*/
3570                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3571                                 &ut_params->cipher_xform);
3572         } else {/* Create Crypto session*/
3573                 ut_params->auth_xform.next = &ut_params->cipher_xform;
3574                 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3575                                 &ut_params->auth_xform);
3576         }
3577
3578         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3579
3580         return 0;
3581 }
3582
3583 static int
3584 create_gcm_operation(enum rte_crypto_cipher_operation op,
3585                 const uint8_t *auth_tag, const unsigned auth_tag_len,
3586                 const uint8_t *iv, const unsigned iv_len,
3587                 const uint8_t *aad, const unsigned aad_len,
3588                 const unsigned data_len, unsigned data_pad_len)
3589 {
3590         struct crypto_testsuite_params *ts_params = &testsuite_params;
3591         struct crypto_unittest_params *ut_params = &unittest_params;
3592
3593         unsigned iv_pad_len = 0, aad_buffer_len;
3594
3595         /* Generate Crypto op data structure */
3596         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3597                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3598         TEST_ASSERT_NOT_NULL(ut_params->op,
3599                         "Failed to allocate symmetric crypto operation struct");
3600
3601         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3602
3603
3604
3605         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3606                         ut_params->ibuf, auth_tag_len);
3607         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3608                         "no room to append digest");
3609         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3610                         ut_params->ibuf, data_pad_len);
3611         sym_op->auth.digest.length = auth_tag_len;
3612
3613         if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3614                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3615 #ifdef RTE_APP_TEST_DEBUG
3616                 rte_hexdump(stdout, "digest:",
3617                                 ut_params->op->digest.data,
3618                                 ut_params->op->digest.length);
3619 #endif
3620         }
3621
3622         /* iv */
3623         iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3624
3625         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3626                         ut_params->ibuf, iv_pad_len);
3627         TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3628
3629         memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3630         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3631         sym_op->cipher.iv.length = iv_pad_len;
3632
3633         rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3634
3635         /* CalcY0 */
3636         if (iv_len != 16)
3637                 sym_op->cipher.iv.data[15] = 1;
3638
3639         /*
3640          * Always allocate the aad up to the block size.
3641          * The cryptodev API calls out -
3642          *  - the array must be big enough to hold the AAD, plus any
3643          *   space to round this up to the nearest multiple of the
3644          *   block size (16 bytes).
3645          */
3646         aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3647
3648         sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3649                         ut_params->ibuf, aad_buffer_len);
3650         TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3651                         "no room to prepend aad");
3652         sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3653                         ut_params->ibuf);
3654         sym_op->auth.aad.length = aad_len;
3655
3656         memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3657         rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3658
3659 #ifdef RTE_APP_TEST_DEBUG
3660         rte_hexdump(stdout, "iv:", ut_params->op->iv.data, iv_pad_len);
3661         rte_hexdump(stdout, "aad:",
3662                         ut_params->op->additional_auth.data, aad_len);
3663 #endif
3664         sym_op->cipher.data.length = data_len;
3665         sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3666
3667         sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3668         sym_op->auth.data.length = data_len;
3669
3670         return 0;
3671 }
3672
3673 static int
3674 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3675 {
3676         struct crypto_testsuite_params *ts_params = &testsuite_params;
3677         struct crypto_unittest_params *ut_params = &unittest_params;
3678
3679         int retval;
3680
3681         uint8_t *plaintext, *ciphertext, *auth_tag;
3682         uint16_t plaintext_pad_len;
3683
3684         /* Create GCM session */
3685         retval = create_gcm_session(ts_params->valid_devs[0],
3686                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3687                         tdata->key.data, tdata->key.len,
3688                         tdata->aad.len, tdata->auth_tag.len);
3689         if (retval < 0)
3690                 return retval;
3691
3692
3693         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3694
3695         /* clear mbuf payload */
3696         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3697                         rte_pktmbuf_tailroom(ut_params->ibuf));
3698
3699         /*
3700          * Append data which is padded to a multiple
3701          * of the algorithms block size
3702          */
3703         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3704
3705         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3706                         plaintext_pad_len);
3707         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3708
3709 #ifdef RTE_APP_TEST_DEBUG
3710         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3711 #endif
3712         /* Create GCM opertaion */
3713         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3714                         tdata->auth_tag.data, tdata->auth_tag.len,
3715                         tdata->iv.data, tdata->iv.len,
3716                         tdata->aad.data, tdata->aad.len,
3717                         tdata->plaintext.len, plaintext_pad_len);
3718         if (retval < 0)
3719                 return retval;
3720
3721         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3722
3723         ut_params->op->sym->m_src = ut_params->ibuf;
3724
3725         /* Process crypto operation */
3726         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3727                         ut_params->op), "failed to process sym crypto op");
3728
3729         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3730                         "crypto op processing failed");
3731
3732         if (ut_params->op->sym->m_dst) {
3733                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3734                                 uint8_t *);
3735                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3736                                 uint8_t *, plaintext_pad_len);
3737         } else {
3738                 ciphertext = plaintext;
3739                 auth_tag = plaintext + plaintext_pad_len;
3740         }
3741
3742 #ifdef RTE_APP_TEST_DEBUG
3743         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3744         rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3745 #endif
3746         /* Validate obuf */
3747         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3748                         ciphertext,
3749                         tdata->ciphertext.data,
3750                         tdata->ciphertext.len,
3751                         "GCM Ciphertext data not as expected");
3752
3753         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3754                         auth_tag,
3755                         tdata->auth_tag.data,
3756                         tdata->auth_tag.len,
3757                         "GCM Generated auth tag not as expected");
3758
3759         return 0;
3760
3761 }
3762
3763 static int
3764 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3765 {
3766         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3767 }
3768
3769 static int
3770 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3771 {
3772         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3773 }
3774
3775 static int
3776 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3777 {
3778         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3779 }
3780
3781 static int
3782 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3783 {
3784         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3785 }
3786
3787 static int
3788 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3789 {
3790         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3791 }
3792
3793 static int
3794 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3795 {
3796         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3797 }
3798
3799 static int
3800 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3801 {
3802         return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3803 }
3804
3805 static int
3806 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3807 {
3808         struct crypto_testsuite_params *ts_params = &testsuite_params;
3809         struct crypto_unittest_params *ut_params = &unittest_params;
3810
3811         int retval;
3812
3813         uint8_t *plaintext, *ciphertext;
3814         uint16_t ciphertext_pad_len;
3815
3816         /* Create GCM session */
3817         retval = create_gcm_session(ts_params->valid_devs[0],
3818                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3819                         tdata->key.data, tdata->key.len,
3820                         tdata->aad.len, tdata->auth_tag.len);
3821         if (retval < 0)
3822                 return retval;
3823
3824
3825         /* alloc mbuf and set payload */
3826         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3827
3828         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3829                         rte_pktmbuf_tailroom(ut_params->ibuf));
3830
3831         ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3832
3833         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3834                         ciphertext_pad_len);
3835         memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3836
3837 #ifdef RTE_APP_TEST_DEBUG
3838         rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3839 #endif
3840         /* Create GCM opertaion */
3841         retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3842                         tdata->auth_tag.data, tdata->auth_tag.len,
3843                         tdata->iv.data, tdata->iv.len,
3844                         tdata->aad.data, tdata->aad.len,
3845                         tdata->ciphertext.len, ciphertext_pad_len);
3846         if (retval < 0)
3847                 return retval;
3848
3849
3850         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3851
3852         ut_params->op->sym->m_src = ut_params->ibuf;
3853
3854         /* Process crypto operation */
3855         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3856                         ut_params->op), "failed to process sym crypto op");
3857
3858         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3859                         "crypto op processing failed");
3860
3861         if (ut_params->op->sym->m_dst)
3862                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3863                                 uint8_t *);
3864         else
3865                 plaintext = ciphertext;
3866
3867 #ifdef RTE_APP_TEST_DEBUG
3868         rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3869 #endif
3870         /* Validate obuf */
3871         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3872                         plaintext,
3873                         tdata->plaintext.data,
3874                         tdata->plaintext.len,
3875                         "GCM plaintext data not as expected");
3876
3877         TEST_ASSERT_EQUAL(ut_params->op->status,
3878                         RTE_CRYPTO_OP_STATUS_SUCCESS,
3879                         "GCM authentication failed");
3880         return 0;
3881 }
3882
3883 static int
3884 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3885 {
3886         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3887 }
3888
3889 static int
3890 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3891 {
3892         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3893 }
3894
3895 static int
3896 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3897 {
3898         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3899 }
3900
3901 static int
3902 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3903 {
3904         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3905 }
3906
3907 static int
3908 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3909 {
3910         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3911 }
3912
3913 static int
3914 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3915 {
3916         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3917 }
3918
3919 static int
3920 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3921 {
3922         return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3923 }
3924
3925 static int
3926 test_stats(void)
3927 {
3928         struct crypto_testsuite_params *ts_params = &testsuite_params;
3929         struct rte_cryptodev_stats stats;
3930         struct rte_cryptodev *dev;
3931         cryptodev_stats_get_t temp_pfn;
3932
3933         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3934         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3935                         &stats) == -ENODEV),
3936                 "rte_cryptodev_stats_get invalid dev failed");
3937         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3938                 "rte_cryptodev_stats_get invalid Param failed");
3939         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3940         temp_pfn = dev->dev_ops->stats_get;
3941         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3942         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3943                         == -ENOTSUP),
3944                 "rte_cryptodev_stats_get invalid Param failed");
3945         dev->dev_ops->stats_get = temp_pfn;
3946
3947         /* Test expected values */
3948         ut_setup();
3949         test_AES_CBC_HMAC_SHA1_encrypt_digest();
3950         ut_teardown();
3951         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3952                         &stats),
3953                 "rte_cryptodev_stats_get failed");
3954         TEST_ASSERT((stats.enqueued_count == 1),
3955                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3956         TEST_ASSERT((stats.dequeued_count == 1),
3957                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3958         TEST_ASSERT((stats.enqueue_err_count == 0),
3959                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3960         TEST_ASSERT((stats.dequeue_err_count == 0),
3961                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3962
3963         /* invalid device but should ignore and not reset device stats*/
3964         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3965         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3966                         &stats),
3967                 "rte_cryptodev_stats_get failed");
3968         TEST_ASSERT((stats.enqueued_count == 1),
3969                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3970
3971         /* check that a valid reset clears stats */
3972         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3973         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3974                         &stats),
3975                                           "rte_cryptodev_stats_get failed");
3976         TEST_ASSERT((stats.enqueued_count == 0),
3977                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3978         TEST_ASSERT((stats.dequeued_count == 0),
3979                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3980
3981         return TEST_SUCCESS;
3982 }
3983
3984
3985 static int
3986 test_multi_session(void)
3987 {
3988         struct crypto_testsuite_params *ts_params = &testsuite_params;
3989         struct crypto_unittest_params *ut_params = &unittest_params;
3990
3991         struct rte_cryptodev_info dev_info;
3992         struct rte_cryptodev_sym_session **sessions;
3993
3994         uint16_t i;
3995
3996         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3997
3998
3999         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4000
4001         sessions = rte_malloc(NULL,
4002                         (sizeof(struct rte_cryptodev_sym_session *) *
4003                         dev_info.sym.max_nb_sessions) + 1, 0);
4004
4005         /* Create multiple crypto sessions*/
4006         for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4007                 sessions[i] = rte_cryptodev_sym_session_create(
4008                                 ts_params->valid_devs[0],
4009                         &ut_params->auth_xform);
4010                 TEST_ASSERT_NOT_NULL(sessions[i],
4011                                 "Session creation failed at session number %u",
4012                                 i);
4013
4014                 /* Attempt to send a request on each session */
4015                 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
4016                                 sessions[i], ut_params, ts_params),
4017                                 "Failed to perform decrypt on request "
4018                                 "number %u.", i);
4019                 /* free crypto operation structure */
4020                 if (ut_params->op)
4021                         rte_crypto_op_free(ut_params->op);
4022
4023                 /*
4024                  * free mbuf - both obuf and ibuf are usually the same,
4025                  * but rte copes even if we call free twice
4026                  */
4027                 if (ut_params->obuf) {
4028                         rte_pktmbuf_free(ut_params->obuf);
4029                         ut_params->obuf = 0;
4030                 }
4031         }
4032
4033         /* Next session create should fail */
4034         sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4035                         &ut_params->auth_xform);
4036         TEST_ASSERT_NULL(sessions[i],
4037                         "Session creation succeeded unexpectedly!");
4038
4039         for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4040                 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4041                                 sessions[i]);
4042
4043         rte_free(sessions);
4044
4045         return TEST_SUCCESS;
4046 }
4047
4048 static int
4049 test_not_in_place_crypto(void)
4050 {
4051         struct crypto_testsuite_params *ts_params = &testsuite_params;
4052         struct crypto_unittest_params *ut_params = &unittest_params;
4053         struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4054
4055         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
4056
4057         /* Create multiple crypto sessions*/
4058
4059         ut_params->sess = rte_cryptodev_sym_session_create(
4060                         ts_params->valid_devs[0], &ut_params->auth_xform);
4061
4062         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4063
4064
4065         /* Generate test mbuf data and digest */
4066         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4067                         (const char *)
4068                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4069                         QUOTE_512_BYTES, 0);
4070
4071         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4072                         DIGEST_BYTE_LENGTH_SHA512);
4073         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
4074
4075         rte_memcpy(ut_params->digest,
4076                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4077                         DIGEST_BYTE_LENGTH_SHA512);
4078
4079         /* Generate Crypto op data structure */
4080         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4081                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4082         TEST_ASSERT_NOT_NULL(ut_params->op,
4083                         "Failed to allocate symmetric crypto operation struct");
4084
4085
4086         /* Set crypto operation data parameters */
4087         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4088
4089         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4090
4091         /* set crypto operation source mbuf */
4092         sym_op->m_src = ut_params->ibuf;
4093         sym_op->m_dst = dst_m;
4094
4095         sym_op->auth.digest.data = ut_params->digest;
4096         sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4097                         ut_params->ibuf, QUOTE_512_BYTES);
4098         sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
4099
4100         sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
4101         sym_op->auth.data.length = QUOTE_512_BYTES;
4102
4103
4104         sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4105                         ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
4106         sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
4107                         ut_params->ibuf, 0);
4108         sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
4109
4110         rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
4111                         CIPHER_IV_LENGTH_AES_CBC);
4112
4113         sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
4114         sym_op->cipher.data.length = QUOTE_512_BYTES;
4115
4116         /* Process crypto operation */
4117         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4118                         ut_params->op);
4119         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4120
4121         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4122                         "crypto operation processing failed");
4123
4124         /* Validate obuf */
4125         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4126                         rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
4127                         catch_22_quote,
4128                         QUOTE_512_BYTES,
4129                         "Plaintext data not as expected");
4130
4131         return TEST_SUCCESS;
4132 }
4133
4134 static int
4135 test_null_cipher_only_operation(void)
4136 {
4137         struct crypto_testsuite_params *ts_params = &testsuite_params;
4138         struct crypto_unittest_params *ut_params = &unittest_params;
4139
4140         /* Generate test mbuf data and space for digest */
4141         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4142                         catch_22_quote, QUOTE_512_BYTES, 0);
4143
4144         /* Setup Cipher Parameters */
4145         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4146         ut_params->cipher_xform.next = NULL;
4147
4148         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4149         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4150
4151         /* Create Crypto session*/
4152         ut_params->sess = rte_cryptodev_sym_session_create(
4153                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4154         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4155
4156         /* Generate Crypto op data structure */
4157         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4158                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4159         TEST_ASSERT_NOT_NULL(ut_params->op,
4160                         "Failed to allocate symmetric crypto operation struct");
4161
4162         /* Set crypto operation data parameters */
4163         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4164
4165         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4166
4167         /* set crypto operation source mbuf */
4168         sym_op->m_src = ut_params->ibuf;
4169
4170         sym_op->cipher.data.offset = 0;
4171         sym_op->cipher.data.length = QUOTE_512_BYTES;
4172
4173         /* Process crypto operation */
4174         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4175                         ut_params->op);
4176         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4177
4178         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4179                         "crypto operation processing failed");
4180
4181         /* Validate obuf */
4182         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4183                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4184                         catch_22_quote,
4185                         QUOTE_512_BYTES,
4186                         "Ciphertext data not as expected");
4187
4188         return TEST_SUCCESS;
4189 }
4190
4191 static int
4192 test_null_auth_only_operation(void)
4193 {
4194         struct crypto_testsuite_params *ts_params = &testsuite_params;
4195         struct crypto_unittest_params *ut_params = &unittest_params;
4196
4197         /* Generate test mbuf data and space for digest */
4198         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4199                         catch_22_quote, QUOTE_512_BYTES, 0);
4200
4201         /* Setup HMAC Parameters */
4202         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4203         ut_params->auth_xform.next = NULL;
4204
4205         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4206         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4207
4208         /* Create Crypto session*/
4209         ut_params->sess = rte_cryptodev_sym_session_create(
4210                         ts_params->valid_devs[0], &ut_params->auth_xform);
4211         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4212
4213         /* Generate Crypto op data structure */
4214         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4215                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4216         TEST_ASSERT_NOT_NULL(ut_params->op,
4217                         "Failed to allocate symmetric crypto operation struct");
4218
4219         /* Set crypto operation data parameters */
4220         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4221
4222         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4223
4224         sym_op->m_src = ut_params->ibuf;
4225
4226         sym_op->auth.data.offset = 0;
4227         sym_op->auth.data.length = QUOTE_512_BYTES;
4228
4229         /* Process crypto operation */
4230         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4231                         ut_params->op);
4232         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4233
4234         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4235                         "crypto operation processing failed");
4236
4237         return TEST_SUCCESS;
4238 }
4239
4240 static int
4241 test_null_cipher_auth_operation(void)
4242 {
4243         struct crypto_testsuite_params *ts_params = &testsuite_params;
4244         struct crypto_unittest_params *ut_params = &unittest_params;
4245
4246         /* Generate test mbuf data and space for digest */
4247         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4248                         catch_22_quote, QUOTE_512_BYTES, 0);
4249
4250         /* Setup Cipher Parameters */
4251         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4252         ut_params->cipher_xform.next = &ut_params->auth_xform;
4253
4254         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4255         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4256
4257         /* Setup HMAC Parameters */
4258         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4259         ut_params->auth_xform.next = NULL;
4260
4261         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4262         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4263
4264         /* Create Crypto session*/
4265         ut_params->sess = rte_cryptodev_sym_session_create(
4266                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4267         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4268
4269         /* Generate Crypto op data structure */
4270         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4271                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4272         TEST_ASSERT_NOT_NULL(ut_params->op,
4273                         "Failed to allocate symmetric crypto operation struct");
4274
4275         /* Set crypto operation data parameters */
4276         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4277
4278         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4279
4280         sym_op->m_src = ut_params->ibuf;
4281
4282         sym_op->cipher.data.offset = 0;
4283         sym_op->cipher.data.length = QUOTE_512_BYTES;
4284
4285         sym_op->auth.data.offset = 0;
4286         sym_op->auth.data.length = QUOTE_512_BYTES;
4287
4288         /* Process crypto operation */
4289         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4290                         ut_params->op);
4291         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4292
4293         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4294                         "crypto operation processing failed");
4295
4296         /* Validate obuf */
4297         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4298                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4299                         catch_22_quote,
4300                         QUOTE_512_BYTES,
4301                         "Ciphertext data not as expected");
4302
4303         return TEST_SUCCESS;
4304 }
4305
4306 static int
4307 test_null_auth_cipher_operation(void)
4308 {
4309         struct crypto_testsuite_params *ts_params = &testsuite_params;
4310         struct crypto_unittest_params *ut_params = &unittest_params;
4311
4312         /* Generate test mbuf data and space for digest */
4313         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4314                         catch_22_quote, QUOTE_512_BYTES, 0);
4315
4316         /* Setup Cipher Parameters */
4317         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4318         ut_params->cipher_xform.next = NULL;
4319
4320         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4321         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4322
4323         /* Setup HMAC Parameters */
4324         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4325         ut_params->auth_xform.next = &ut_params->cipher_xform;
4326
4327         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4328         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4329
4330         /* Create Crypto session*/
4331         ut_params->sess = rte_cryptodev_sym_session_create(
4332                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4333         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4334
4335         /* Generate Crypto op data structure */
4336         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4337                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4338         TEST_ASSERT_NOT_NULL(ut_params->op,
4339                         "Failed to allocate symmetric crypto operation struct");
4340
4341         /* Set crypto operation data parameters */
4342         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4343
4344         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4345
4346         sym_op->m_src = ut_params->ibuf;
4347
4348         sym_op->cipher.data.offset = 0;
4349         sym_op->cipher.data.length = QUOTE_512_BYTES;
4350
4351         sym_op->auth.data.offset = 0;
4352         sym_op->auth.data.length = QUOTE_512_BYTES;
4353
4354         /* Process crypto operation */
4355         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4356                         ut_params->op);
4357         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4358
4359         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4360                         "crypto operation processing failed");
4361
4362         /* Validate obuf */
4363         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4364                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4365                         catch_22_quote,
4366                         QUOTE_512_BYTES,
4367                         "Ciphertext data not as expected");
4368
4369         return TEST_SUCCESS;
4370 }
4371
4372
4373 static int
4374 test_null_invalid_operation(void)
4375 {
4376         struct crypto_testsuite_params *ts_params = &testsuite_params;
4377         struct crypto_unittest_params *ut_params = &unittest_params;
4378
4379         /* Setup Cipher Parameters */
4380         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4381         ut_params->cipher_xform.next = NULL;
4382
4383         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4384         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4385
4386         /* Create Crypto session*/
4387         ut_params->sess = rte_cryptodev_sym_session_create(
4388                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4389         TEST_ASSERT_NULL(ut_params->sess,
4390                         "Session creation succeeded unexpectedly");
4391
4392
4393         /* Setup HMAC Parameters */
4394         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4395         ut_params->auth_xform.next = NULL;
4396
4397         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4398         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4399
4400         /* Create Crypto session*/
4401         ut_params->sess = rte_cryptodev_sym_session_create(
4402                         ts_params->valid_devs[0], &ut_params->auth_xform);
4403         TEST_ASSERT_NULL(ut_params->sess,
4404                         "Session creation succeeded unexpectedly");
4405
4406         return TEST_SUCCESS;
4407 }
4408
4409
4410 #define NULL_BURST_LENGTH (32)
4411
4412 static int
4413 test_null_burst_operation(void)
4414 {
4415         struct crypto_testsuite_params *ts_params = &testsuite_params;
4416         struct crypto_unittest_params *ut_params = &unittest_params;
4417
4418         unsigned i, burst_len = NULL_BURST_LENGTH;
4419
4420         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4421         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4422
4423         /* Setup Cipher Parameters */
4424         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4425         ut_params->cipher_xform.next = &ut_params->auth_xform;
4426
4427         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4428         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4429
4430         /* Setup HMAC Parameters */
4431         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4432         ut_params->auth_xform.next = NULL;
4433
4434         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4435         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4436
4437         /* Create Crypto session*/
4438         ut_params->sess = rte_cryptodev_sym_session_create(
4439                         ts_params->valid_devs[0], &ut_params->cipher_xform);
4440         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4441
4442         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4443                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4444                         burst_len, "failed to generate burst of crypto ops");
4445
4446         /* Generate an operation for each mbuf in burst */
4447         for (i = 0; i < burst_len; i++) {
4448                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4449
4450                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4451
4452                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4453                                 sizeof(unsigned));
4454                 *data = i;
4455
4456                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4457
4458                 burst[i]->sym->m_src = m;
4459         }
4460
4461         /* Process crypto operation */
4462         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4463                         0, burst, burst_len),
4464                         burst_len,
4465                         "Error enqueuing burst");
4466
4467         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4468                         0, burst_dequeued, burst_len),
4469                         burst_len,
4470                         "Error dequeuing burst");
4471
4472
4473         for (i = 0; i < burst_len; i++) {
4474                 TEST_ASSERT_EQUAL(
4475                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4476                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4477                                         uint32_t *),
4478                         "data not as expected");
4479
4480                 rte_pktmbuf_free(burst[i]->sym->m_src);
4481                 rte_crypto_op_free(burst[i]);
4482         }
4483
4484         return TEST_SUCCESS;
4485 }
4486
4487
4488
4489
4490 static struct unit_test_suite cryptodev_qat_testsuite  = {
4491         .suite_name = "Crypto QAT Unit Test Suite",
4492         .setup = testsuite_setup,
4493         .teardown = testsuite_teardown,
4494         .unit_test_cases = {
4495                 TEST_CASE_ST(ut_setup, ut_teardown,
4496                                 test_device_configure_invalid_dev_id),
4497                 TEST_CASE_ST(ut_setup, ut_teardown,
4498                                 test_device_configure_invalid_queue_pair_ids),
4499                 TEST_CASE_ST(ut_setup, ut_teardown,
4500                                 test_queue_pair_descriptor_setup),
4501                 TEST_CASE_ST(ut_setup, ut_teardown,
4502                                 test_multi_session),
4503
4504                 TEST_CASE_ST(ut_setup, ut_teardown,
4505                                 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop),
4506                 TEST_CASE_ST(ut_setup, ut_teardown,
4507                                 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver),
4508
4509                 TEST_CASE_ST(ut_setup, ut_teardown,
4510                                 test_AES_CBC_HMAC_SHA1_encrypt_digest),
4511                 TEST_CASE_ST(ut_setup, ut_teardown,
4512                                 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4513
4514                 TEST_CASE_ST(ut_setup, ut_teardown,
4515                                 test_AES_CBC_HMAC_SHA256_encrypt_digest),
4516                 TEST_CASE_ST(ut_setup, ut_teardown,
4517                                 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4518
4519                 TEST_CASE_ST(ut_setup, ut_teardown,
4520                                 test_AES_CBC_HMAC_SHA512_encrypt_digest),
4521                 TEST_CASE_ST(ut_setup, ut_teardown,
4522                                 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4523
4524                 TEST_CASE_ST(ut_setup, ut_teardown,
4525                                 test_AES_CTR_encrypt_digest_case_1),
4526                 TEST_CASE_ST(ut_setup, ut_teardown,
4527                                 test_AES_CTR_encrypt_digest_case_2),
4528                 TEST_CASE_ST(ut_setup, ut_teardown,
4529                                 test_AES_CTR_encrypt_digest_case_3),
4530                 TEST_CASE_ST(ut_setup, ut_teardown,
4531                                 test_AES_CTR_digest_verify_decrypt_case_1),
4532                 TEST_CASE_ST(ut_setup, ut_teardown,
4533                                 test_AES_CTR_digest_verify_decrypt_case_2),
4534                 TEST_CASE_ST(ut_setup, ut_teardown,
4535                                 test_AES_CTR_digest_verify_decrypt_case_3),
4536
4537                 TEST_CASE_ST(ut_setup, ut_teardown,
4538                                 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4539                 TEST_CASE_ST(ut_setup, ut_teardown,
4540                                 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4541                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4542
4543                 /** AES GCM Authenticated Encryption */
4544                 TEST_CASE_ST(ut_setup, ut_teardown,
4545                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
4546                 TEST_CASE_ST(ut_setup, ut_teardown,
4547                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
4548                 TEST_CASE_ST(ut_setup, ut_teardown,
4549                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
4550                 TEST_CASE_ST(ut_setup, ut_teardown,
4551                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
4552                 TEST_CASE_ST(ut_setup, ut_teardown,
4553                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
4554                 TEST_CASE_ST(ut_setup, ut_teardown,
4555                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
4556                 TEST_CASE_ST(ut_setup, ut_teardown,
4557                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
4558
4559                 /** AES GCM Authenticated Decryption */
4560                 TEST_CASE_ST(ut_setup, ut_teardown,
4561                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
4562                 TEST_CASE_ST(ut_setup, ut_teardown,
4563                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
4564                 TEST_CASE_ST(ut_setup, ut_teardown,
4565                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
4566                 TEST_CASE_ST(ut_setup, ut_teardown,
4567                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
4568                 TEST_CASE_ST(ut_setup, ut_teardown,
4569                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
4570                 TEST_CASE_ST(ut_setup, ut_teardown,
4571                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
4572                 TEST_CASE_ST(ut_setup, ut_teardown,
4573                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
4574
4575                 /** Snow3G encrypt only (UEA2) */
4576                 TEST_CASE_ST(ut_setup, ut_teardown,
4577                         test_snow3g_encryption_test_case_1),
4578                 TEST_CASE_ST(ut_setup, ut_teardown,
4579                         test_snow3g_encryption_test_case_2),
4580                 TEST_CASE_ST(ut_setup, ut_teardown,
4581                         test_snow3g_encryption_test_case_3),
4582                 TEST_CASE_ST(ut_setup, ut_teardown,
4583                         test_snow3g_encryption_test_case_4),
4584                 TEST_CASE_ST(ut_setup, ut_teardown,
4585                         test_snow3g_encryption_test_case_5),
4586
4587                 TEST_CASE_ST(ut_setup, ut_teardown,
4588                         test_snow3g_encryption_test_case_1_oop),
4589                 TEST_CASE_ST(ut_setup, ut_teardown,
4590                         test_snow3g_decryption_test_case_1_oop),
4591
4592                 /** Snow3G decrypt only (UEA2) */
4593                 TEST_CASE_ST(ut_setup, ut_teardown,
4594                         test_snow3g_decryption_test_case_1),
4595                 TEST_CASE_ST(ut_setup, ut_teardown,
4596                         test_snow3g_decryption_test_case_2),
4597                 TEST_CASE_ST(ut_setup, ut_teardown,
4598                         test_snow3g_decryption_test_case_3),
4599                 TEST_CASE_ST(ut_setup, ut_teardown,
4600                         test_snow3g_decryption_test_case_4),
4601                 TEST_CASE_ST(ut_setup, ut_teardown,
4602                         test_snow3g_decryption_test_case_5),
4603                 TEST_CASE_ST(ut_setup, ut_teardown,
4604                         test_snow3g_hash_generate_test_case_1),
4605                 TEST_CASE_ST(ut_setup, ut_teardown,
4606                         test_snow3g_hash_generate_test_case_2),
4607                 TEST_CASE_ST(ut_setup, ut_teardown,
4608                         test_snow3g_hash_generate_test_case_3),
4609                 TEST_CASE_ST(ut_setup, ut_teardown,
4610                         test_snow3g_hash_verify_test_case_1),
4611                 TEST_CASE_ST(ut_setup, ut_teardown,
4612                         test_snow3g_hash_verify_test_case_2),
4613                 TEST_CASE_ST(ut_setup, ut_teardown,
4614                         test_snow3g_hash_verify_test_case_3),
4615                 TEST_CASE_ST(ut_setup, ut_teardown,
4616                         test_snow3g_authenticated_encryption_test_case_1),
4617                 TEST_CASE_ST(ut_setup, ut_teardown,
4618                         test_snow3g_encrypted_authentication_test_case_1),
4619                 TEST_CASES_END() /**< NULL terminate unit test array */
4620         }
4621 };
4622
4623 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
4624         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4625         .setup = testsuite_setup,
4626         .teardown = testsuite_teardown,
4627         .unit_test_cases = {
4628                 TEST_CASE_ST(ut_setup, ut_teardown,
4629                         test_AES_CBC_HMAC_SHA1_encrypt_digest),
4630                 TEST_CASE_ST(ut_setup, ut_teardown,
4631                         test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4632
4633                 TEST_CASE_ST(ut_setup, ut_teardown,
4634                         test_AES_CBC_HMAC_SHA256_encrypt_digest),
4635                 TEST_CASE_ST(ut_setup, ut_teardown,
4636                         test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4637
4638                 TEST_CASE_ST(ut_setup, ut_teardown,
4639                         test_AES_CBC_HMAC_SHA512_encrypt_digest),
4640                 TEST_CASE_ST(ut_setup, ut_teardown,
4641                         test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4642
4643                 TEST_CASE_ST(ut_setup, ut_teardown,
4644                         test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4645                 TEST_CASE_ST(ut_setup, ut_teardown,
4646                         test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4647
4648                 TEST_CASE_ST(ut_setup, ut_teardown,
4649                         test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
4650
4651                 TEST_CASE_ST(ut_setup, ut_teardown,
4652                                 test_AES_CTR_encrypt_digest_case_1),
4653                 TEST_CASE_ST(ut_setup, ut_teardown,
4654                                 test_AES_CTR_encrypt_digest_case_2),
4655                 TEST_CASE_ST(ut_setup, ut_teardown,
4656                                 test_AES_CTR_encrypt_digest_case_3),
4657                 TEST_CASE_ST(ut_setup, ut_teardown,
4658                                 test_AES_CTR_digest_verify_decrypt_case_1),
4659                 TEST_CASE_ST(ut_setup, ut_teardown,
4660                                 test_AES_CTR_digest_verify_decrypt_case_2),
4661                 TEST_CASE_ST(ut_setup, ut_teardown,
4662                                 test_AES_CTR_digest_verify_decrypt_case_3),
4663
4664                 TEST_CASE_ST(ut_setup, ut_teardown,
4665                         test_not_in_place_crypto),
4666
4667                 TEST_CASES_END() /**< NULL terminate unit test array */
4668         }
4669 };
4670
4671 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
4672         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4673         .setup = testsuite_setup,
4674         .teardown = testsuite_teardown,
4675         .unit_test_cases = {
4676                 /** AES GCM Authenticated Encryption */
4677                 TEST_CASE_ST(ut_setup, ut_teardown,
4678                         test_mb_AES_GCM_authenticated_encryption_test_case_1),
4679                 TEST_CASE_ST(ut_setup, ut_teardown,
4680                         test_mb_AES_GCM_authenticated_encryption_test_case_2),
4681                 TEST_CASE_ST(ut_setup, ut_teardown,
4682                         test_mb_AES_GCM_authenticated_encryption_test_case_3),
4683                 TEST_CASE_ST(ut_setup, ut_teardown,
4684                         test_mb_AES_GCM_authenticated_encryption_test_case_4),
4685                 TEST_CASE_ST(ut_setup, ut_teardown,
4686                         test_mb_AES_GCM_authenticated_encryption_test_case_5),
4687                 TEST_CASE_ST(ut_setup, ut_teardown,
4688                         test_mb_AES_GCM_authenticated_encryption_test_case_6),
4689                 TEST_CASE_ST(ut_setup, ut_teardown,
4690                         test_mb_AES_GCM_authenticated_encryption_test_case_7),
4691
4692                 /** AES GCM Authenticated Decryption */
4693                 TEST_CASE_ST(ut_setup, ut_teardown,
4694                         test_mb_AES_GCM_authenticated_decryption_test_case_1),
4695                 TEST_CASE_ST(ut_setup, ut_teardown,
4696                         test_mb_AES_GCM_authenticated_decryption_test_case_2),
4697                 TEST_CASE_ST(ut_setup, ut_teardown,
4698                         test_mb_AES_GCM_authenticated_decryption_test_case_3),
4699                 TEST_CASE_ST(ut_setup, ut_teardown,
4700                         test_mb_AES_GCM_authenticated_decryption_test_case_4),
4701                 TEST_CASE_ST(ut_setup, ut_teardown,
4702                         test_mb_AES_GCM_authenticated_decryption_test_case_5),
4703                 TEST_CASE_ST(ut_setup, ut_teardown,
4704                         test_mb_AES_GCM_authenticated_decryption_test_case_6),
4705                 TEST_CASE_ST(ut_setup, ut_teardown,
4706                         test_mb_AES_GCM_authenticated_decryption_test_case_7),
4707
4708                 TEST_CASES_END() /**< NULL terminate unit test array */
4709         }
4710 };
4711
4712 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
4713         .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4714         .setup = testsuite_setup,
4715         .teardown = testsuite_teardown,
4716         .unit_test_cases = {
4717                 /** Snow3G encrypt only (UEA2) */
4718                 TEST_CASE_ST(ut_setup, ut_teardown,
4719                         test_snow3g_encryption_test_case_1),
4720                 TEST_CASE_ST(ut_setup, ut_teardown,
4721                         test_snow3g_encryption_test_case_2),
4722                 TEST_CASE_ST(ut_setup, ut_teardown,
4723                         test_snow3g_encryption_test_case_3),
4724                 TEST_CASE_ST(ut_setup, ut_teardown,
4725                         test_snow3g_encryption_test_case_4),
4726                 TEST_CASE_ST(ut_setup, ut_teardown,
4727                         test_snow3g_encryption_test_case_5),
4728
4729
4730                 /** Snow3G decrypt only (UEA2) */
4731                 TEST_CASE_ST(ut_setup, ut_teardown,
4732                         test_snow3g_decryption_test_case_1),
4733                 TEST_CASE_ST(ut_setup, ut_teardown,
4734                         test_snow3g_decryption_test_case_2),
4735                 TEST_CASE_ST(ut_setup, ut_teardown,
4736                         test_snow3g_decryption_test_case_3),
4737                 TEST_CASE_ST(ut_setup, ut_teardown,
4738                         test_snow3g_decryption_test_case_4),
4739                 TEST_CASE_ST(ut_setup, ut_teardown,
4740                         test_snow3g_decryption_test_case_5),
4741                 TEST_CASE_ST(ut_setup, ut_teardown,
4742                         test_snow3g_hash_generate_test_case_1),
4743                 TEST_CASE_ST(ut_setup, ut_teardown,
4744                         test_snow3g_hash_generate_test_case_2),
4745                 TEST_CASE_ST(ut_setup, ut_teardown,
4746                         test_snow3g_hash_generate_test_case_3),
4747                 TEST_CASE_ST(ut_setup, ut_teardown,
4748                         test_snow3g_hash_verify_test_case_1),
4749                 TEST_CASE_ST(ut_setup, ut_teardown,
4750                         test_snow3g_hash_verify_test_case_2),
4751                 TEST_CASE_ST(ut_setup, ut_teardown,
4752                         test_snow3g_hash_verify_test_case_3),
4753                 TEST_CASE_ST(ut_setup, ut_teardown,
4754                         test_snow3g_authenticated_encryption_test_case_1),
4755                 TEST_CASE_ST(ut_setup, ut_teardown,
4756                         test_snow3g_encrypted_authentication_test_case_1),
4757
4758                 TEST_CASES_END() /**< NULL terminate unit test array */
4759         }
4760 };
4761
4762 static struct unit_test_suite cryptodev_null_testsuite  = {
4763         .suite_name = "Crypto Device NULL Unit Test Suite",
4764         .setup = testsuite_setup,
4765         .teardown = testsuite_teardown,
4766         .unit_test_cases = {
4767                 TEST_CASE_ST(ut_setup, ut_teardown,
4768                         test_null_auth_only_operation),
4769                 TEST_CASE_ST(ut_setup, ut_teardown,
4770                         test_null_cipher_only_operation),
4771                 TEST_CASE_ST(ut_setup, ut_teardown,
4772                         test_null_cipher_auth_operation),
4773                 TEST_CASE_ST(ut_setup, ut_teardown,
4774                         test_null_auth_cipher_operation),
4775                 TEST_CASE_ST(ut_setup, ut_teardown,
4776                         test_null_invalid_operation),
4777                 TEST_CASE_ST(ut_setup, ut_teardown,
4778                         test_null_burst_operation),
4779
4780                 TEST_CASES_END() /**< NULL terminate unit test array */
4781         }
4782 };
4783
4784 static int
4785 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4786 {
4787         gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4788         return unit_test_suite_runner(&cryptodev_qat_testsuite);
4789 }
4790 static struct test_command cryptodev_qat_cmd = {
4791         .command = "cryptodev_qat_autotest",
4792         .callback = test_cryptodev_qat,
4793 };
4794
4795 static int
4796 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4797 {
4798         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4799
4800         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4801 }
4802
4803 static struct test_command cryptodev_aesni_mb_cmd = {
4804         .command = "cryptodev_aesni_mb_autotest",
4805         .callback = test_cryptodev_aesni_mb,
4806 };
4807
4808 static int
4809 test_cryptodev_aesni_gcm(void)
4810 {
4811         gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4812
4813         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4814 }
4815
4816 static struct test_command cryptodev_aesni_gcm_cmd = {
4817         .command = "cryptodev_aesni_gcm_autotest",
4818         .callback = test_cryptodev_aesni_gcm,
4819 };
4820
4821 static int
4822 test_cryptodev_null(void)
4823 {
4824         gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4825
4826         return unit_test_suite_runner(&cryptodev_null_testsuite);
4827 }
4828
4829 static struct test_command cryptodev_null_cmd = {
4830         .command = "cryptodev_null_autotest",
4831         .callback = test_cryptodev_null,
4832 };
4833
4834 static int
4835 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4836 {
4837         gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4838
4839         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4840 }
4841
4842 static struct test_command cryptodev_sw_snow3g_cmd = {
4843         .command = "cryptodev_sw_snow3g_autotest",
4844         .callback = test_cryptodev_sw_snow3g,
4845 };
4846
4847 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4848 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4849 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4850 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4851 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);