test/crypto: add capability checks
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2019 Intel Corporation
3  */
4
5 #include <time.h>
6
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_mbuf.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
13 #include <rte_bus_vdev.h>
14
15 #include <rte_crypto.h>
16 #include <rte_cryptodev.h>
17 #include <rte_cryptodev_pmd.h>
18 #include <rte_string_fns.h>
19
20 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
21 #include <rte_cryptodev_scheduler.h>
22 #include <rte_cryptodev_scheduler_operations.h>
23 #endif
24
25 #include <rte_lcore.h>
26
27 #include "test.h"
28 #include "test_cryptodev.h"
29
30 #include "test_cryptodev_blockcipher.h"
31 #include "test_cryptodev_aes_test_vectors.h"
32 #include "test_cryptodev_des_test_vectors.h"
33 #include "test_cryptodev_hash_test_vectors.h"
34 #include "test_cryptodev_kasumi_test_vectors.h"
35 #include "test_cryptodev_kasumi_hash_test_vectors.h"
36 #include "test_cryptodev_snow3g_test_vectors.h"
37 #include "test_cryptodev_snow3g_hash_test_vectors.h"
38 #include "test_cryptodev_zuc_test_vectors.h"
39 #include "test_cryptodev_aead_test_vectors.h"
40 #include "test_cryptodev_hmac_test_vectors.h"
41 #include "test_cryptodev_mixed_test_vectors.h"
42 #ifdef RTE_LIBRTE_SECURITY
43 #include "test_cryptodev_security_pdcp_test_vectors.h"
44 #include "test_cryptodev_security_pdcp_test_func.h"
45 #endif
46
47 #define VDEV_ARGS_SIZE 100
48 #define MAX_NB_SESSIONS 4
49
50 #define IN_PLACE 0
51 #define OUT_OF_PLACE 1
52
53 static int gbl_driver_id;
54
55 struct crypto_testsuite_params {
56         struct rte_mempool *mbuf_pool;
57         struct rte_mempool *large_mbuf_pool;
58         struct rte_mempool *op_mpool;
59         struct rte_mempool *session_mpool;
60         struct rte_mempool *session_priv_mpool;
61         struct rte_cryptodev_config conf;
62         struct rte_cryptodev_qp_conf qp_conf;
63
64         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
65         uint8_t valid_dev_count;
66 };
67
68 struct crypto_unittest_params {
69         struct rte_crypto_sym_xform cipher_xform;
70         struct rte_crypto_sym_xform auth_xform;
71         struct rte_crypto_sym_xform aead_xform;
72
73         union {
74                 struct rte_cryptodev_sym_session *sess;
75 #ifdef RTE_LIBRTE_SECURITY
76                 struct rte_security_session *sec_session;
77 #endif
78         };
79 #ifdef RTE_LIBRTE_SECURITY
80         enum rte_security_session_action_type type;
81 #endif
82         struct rte_crypto_op *op;
83
84         struct rte_mbuf *obuf, *ibuf;
85
86         uint8_t *digest;
87 };
88
89 #define ALIGN_POW2_ROUNDUP(num, align) \
90         (((num) + (align) - 1) & ~((align) - 1))
91
92 /*
93  * Forward declarations.
94  */
95 static int
96 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
97                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
98                 uint8_t *hmac_key);
99
100 static int
101 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
102                 struct crypto_unittest_params *ut_params,
103                 struct crypto_testsuite_params *ts_param,
104                 const uint8_t *cipher,
105                 const uint8_t *digest,
106                 const uint8_t *iv);
107
108 static struct rte_mbuf *
109 setup_test_string(struct rte_mempool *mpool,
110                 const char *string, size_t len, uint8_t blocksize)
111 {
112         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
113         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
114
115         memset(m->buf_addr, 0, m->buf_len);
116         if (m) {
117                 char *dst = rte_pktmbuf_append(m, t_len);
118
119                 if (!dst) {
120                         rte_pktmbuf_free(m);
121                         return NULL;
122                 }
123                 if (string != NULL)
124                         rte_memcpy(dst, string, t_len);
125                 else
126                         memset(dst, 0, t_len);
127         }
128
129         return m;
130 }
131
132 /* Get number of bytes in X bits (rounding up) */
133 static uint32_t
134 ceil_byte_length(uint32_t num_bits)
135 {
136         if (num_bits % 8)
137                 return ((num_bits >> 3) + 1);
138         else
139                 return (num_bits >> 3);
140 }
141
142 static struct rte_crypto_op *
143 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
144 {
145         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
146                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
147                 return NULL;
148         }
149
150         op = NULL;
151
152         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
153                 rte_pause();
154
155         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
156                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
157                 return NULL;
158         }
159
160         return op;
161 }
162
163 static struct crypto_testsuite_params testsuite_params = { NULL };
164 static struct crypto_unittest_params unittest_params;
165
166 static int
167 testsuite_setup(void)
168 {
169         struct crypto_testsuite_params *ts_params = &testsuite_params;
170         struct rte_cryptodev_info info;
171         uint32_t i = 0, nb_devs, dev_id;
172         int ret;
173         uint16_t qp_id;
174
175         memset(ts_params, 0, sizeof(*ts_params));
176
177         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
178         if (ts_params->mbuf_pool == NULL) {
179                 /* Not already created so create */
180                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
181                                 "CRYPTO_MBUFPOOL",
182                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
183                                 rte_socket_id());
184                 if (ts_params->mbuf_pool == NULL) {
185                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
186                         return TEST_FAILED;
187                 }
188         }
189
190         ts_params->large_mbuf_pool = rte_mempool_lookup(
191                         "CRYPTO_LARGE_MBUFPOOL");
192         if (ts_params->large_mbuf_pool == NULL) {
193                 /* Not already created so create */
194                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
195                                 "CRYPTO_LARGE_MBUFPOOL",
196                                 1, 0, 0, UINT16_MAX,
197                                 rte_socket_id());
198                 if (ts_params->large_mbuf_pool == NULL) {
199                         RTE_LOG(ERR, USER1,
200                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
201                         return TEST_FAILED;
202                 }
203         }
204
205         ts_params->op_mpool = rte_crypto_op_pool_create(
206                         "MBUF_CRYPTO_SYM_OP_POOL",
207                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
208                         NUM_MBUFS, MBUF_CACHE_SIZE,
209                         DEFAULT_NUM_XFORMS *
210                         sizeof(struct rte_crypto_sym_xform) +
211                         MAXIMUM_IV_LENGTH,
212                         rte_socket_id());
213         if (ts_params->op_mpool == NULL) {
214                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
215                 return TEST_FAILED;
216         }
217
218         /* Create an AESNI MB device if required */
219         if (gbl_driver_id == rte_cryptodev_driver_id_get(
220                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
221                 nb_devs = rte_cryptodev_device_count_by_driver(
222                                 rte_cryptodev_driver_id_get(
223                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
224                 if (nb_devs < 1) {
225                         ret = rte_vdev_init(
226                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
227
228                         TEST_ASSERT(ret == 0,
229                                 "Failed to create instance of"
230                                 " pmd : %s",
231                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
232                 }
233         }
234
235         /* Create an AESNI GCM device if required */
236         if (gbl_driver_id == rte_cryptodev_driver_id_get(
237                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
238                 nb_devs = rte_cryptodev_device_count_by_driver(
239                                 rte_cryptodev_driver_id_get(
240                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
241                 if (nb_devs < 1) {
242                         TEST_ASSERT_SUCCESS(rte_vdev_init(
243                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
244                                 "Failed to create instance of"
245                                 " pmd : %s",
246                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
247                 }
248         }
249
250         /* Create a SNOW 3G device if required */
251         if (gbl_driver_id == rte_cryptodev_driver_id_get(
252                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
253                 nb_devs = rte_cryptodev_device_count_by_driver(
254                                 rte_cryptodev_driver_id_get(
255                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
256                 if (nb_devs < 1) {
257                         TEST_ASSERT_SUCCESS(rte_vdev_init(
258                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
259                                 "Failed to create instance of"
260                                 " pmd : %s",
261                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
262                 }
263         }
264
265         /* Create a KASUMI device if required */
266         if (gbl_driver_id == rte_cryptodev_driver_id_get(
267                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
268                 nb_devs = rte_cryptodev_device_count_by_driver(
269                                 rte_cryptodev_driver_id_get(
270                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
271                 if (nb_devs < 1) {
272                         TEST_ASSERT_SUCCESS(rte_vdev_init(
273                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
274                                 "Failed to create instance of"
275                                 " pmd : %s",
276                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
277                 }
278         }
279
280         /* Create a ZUC device if required */
281         if (gbl_driver_id == rte_cryptodev_driver_id_get(
282                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
283                 nb_devs = rte_cryptodev_device_count_by_driver(
284                                 rte_cryptodev_driver_id_get(
285                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
286                 if (nb_devs < 1) {
287                         TEST_ASSERT_SUCCESS(rte_vdev_init(
288                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
289                                 "Failed to create instance of"
290                                 " pmd : %s",
291                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
292                 }
293         }
294
295         /* Create a NULL device if required */
296         if (gbl_driver_id == rte_cryptodev_driver_id_get(
297                         RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
298                 nb_devs = rte_cryptodev_device_count_by_driver(
299                                 rte_cryptodev_driver_id_get(
300                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
301                 if (nb_devs < 1) {
302                         ret = rte_vdev_init(
303                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
304
305                         TEST_ASSERT(ret == 0,
306                                 "Failed to create instance of"
307                                 " pmd : %s",
308                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
309                 }
310         }
311
312         /* Create an OPENSSL device if required */
313         if (gbl_driver_id == rte_cryptodev_driver_id_get(
314                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
315                 nb_devs = rte_cryptodev_device_count_by_driver(
316                                 rte_cryptodev_driver_id_get(
317                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
318                 if (nb_devs < 1) {
319                         ret = rte_vdev_init(
320                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
321                                 NULL);
322
323                         TEST_ASSERT(ret == 0, "Failed to create "
324                                 "instance of pmd : %s",
325                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
326                 }
327         }
328
329         /* Create a ARMv8 device if required */
330         if (gbl_driver_id == rte_cryptodev_driver_id_get(
331                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
332                 nb_devs = rte_cryptodev_device_count_by_driver(
333                                 rte_cryptodev_driver_id_get(
334                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
335                 if (nb_devs < 1) {
336                         ret = rte_vdev_init(
337                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
338                                 NULL);
339
340                         TEST_ASSERT(ret == 0, "Failed to create "
341                                 "instance of pmd : %s",
342                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
343                 }
344         }
345
346         /* Create a MVSAM device if required */
347         if (gbl_driver_id == rte_cryptodev_driver_id_get(
348                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) {
349                 nb_devs = rte_cryptodev_device_count_by_driver(
350                                 rte_cryptodev_driver_id_get(
351                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)));
352                 if (nb_devs < 1) {
353                         ret = rte_vdev_init(
354                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD),
355                                 NULL);
356
357                         TEST_ASSERT(ret == 0, "Failed to create "
358                                 "instance of pmd : %s",
359                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
360                 }
361         }
362
363         /* Create an CCP device if required */
364         if (gbl_driver_id == rte_cryptodev_driver_id_get(
365                         RTE_STR(CRYPTODEV_NAME_CCP_PMD))) {
366                 nb_devs = rte_cryptodev_device_count_by_driver(
367                                 rte_cryptodev_driver_id_get(
368                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)));
369                 if (nb_devs < 1) {
370                         ret = rte_vdev_init(
371                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD),
372                                 NULL);
373
374                         TEST_ASSERT(ret == 0, "Failed to create "
375                                 "instance of pmd : %s",
376                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD));
377                 }
378         }
379
380 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
381         char vdev_args[VDEV_ARGS_SIZE] = {""};
382         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
383                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
384         uint16_t slave_core_count = 0;
385         uint16_t socket_id = 0;
386
387         if (gbl_driver_id == rte_cryptodev_driver_id_get(
388                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
389
390                 /* Identify the Slave Cores
391                  * Use 2 slave cores for the device args
392                  */
393                 RTE_LCORE_FOREACH_SLAVE(i) {
394                         if (slave_core_count > 1)
395                                 break;
396                         snprintf(vdev_args, sizeof(vdev_args),
397                                         "%s%d", temp_str, i);
398                         strcpy(temp_str, vdev_args);
399                         strlcat(temp_str, ";", sizeof(temp_str));
400                         slave_core_count++;
401                         socket_id = rte_lcore_to_socket_id(i);
402                 }
403                 if (slave_core_count != 2) {
404                         RTE_LOG(ERR, USER1,
405                                 "Cryptodev scheduler test require at least "
406                                 "two slave cores to run. "
407                                 "Please use the correct coremask.\n");
408                         return TEST_FAILED;
409                 }
410                 strcpy(temp_str, vdev_args);
411                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
412                                 temp_str, socket_id);
413                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
414                 nb_devs = rte_cryptodev_device_count_by_driver(
415                                 rte_cryptodev_driver_id_get(
416                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
417                 if (nb_devs < 1) {
418                         ret = rte_vdev_init(
419                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
420                                         vdev_args);
421                         TEST_ASSERT(ret == 0,
422                                 "Failed to create instance %u of"
423                                 " pmd : %s",
424                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
425                 }
426         }
427 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
428
429         nb_devs = rte_cryptodev_count();
430         if (nb_devs < 1) {
431                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
432                 return TEST_SKIPPED;
433         }
434
435         /* Create list of valid crypto devs */
436         for (i = 0; i < nb_devs; i++) {
437                 rte_cryptodev_info_get(i, &info);
438                 if (info.driver_id == gbl_driver_id)
439                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
440         }
441
442         if (ts_params->valid_dev_count < 1)
443                 return TEST_FAILED;
444
445         /* Set up all the qps on the first of the valid devices found */
446
447         dev_id = ts_params->valid_devs[0];
448
449         rte_cryptodev_info_get(dev_id, &info);
450
451         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
452         ts_params->conf.socket_id = SOCKET_ID_ANY;
453         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
454
455         unsigned int session_size =
456                 rte_cryptodev_sym_get_private_session_size(dev_id);
457
458         /*
459          * Create mempool with maximum number of sessions * 2,
460          * to include the session headers
461          */
462         if (info.sym.max_nb_sessions != 0 &&
463                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
464                 RTE_LOG(ERR, USER1, "Device does not support "
465                                 "at least %u sessions\n",
466                                 MAX_NB_SESSIONS);
467                 return TEST_FAILED;
468         }
469
470         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
471                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
472                         SOCKET_ID_ANY);
473         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
474                         "session mempool allocation failed");
475
476         ts_params->session_priv_mpool = rte_mempool_create(
477                         "test_sess_mp_priv",
478                         MAX_NB_SESSIONS,
479                         session_size,
480                         0, 0, NULL, NULL, NULL,
481                         NULL, SOCKET_ID_ANY,
482                         0);
483         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
484                         "session mempool allocation failed");
485
486
487
488         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
489                         &ts_params->conf),
490                         "Failed to configure cryptodev %u with %u qps",
491                         dev_id, ts_params->conf.nb_queue_pairs);
492
493         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
494         ts_params->qp_conf.mp_session = ts_params->session_mpool;
495         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
496
497         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
498                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
499                         dev_id, qp_id, &ts_params->qp_conf,
500                         rte_cryptodev_socket_id(dev_id)),
501                         "Failed to setup queue pair %u on cryptodev %u",
502                         qp_id, dev_id);
503         }
504
505         return TEST_SUCCESS;
506 }
507
508 static void
509 testsuite_teardown(void)
510 {
511         struct crypto_testsuite_params *ts_params = &testsuite_params;
512
513         if (ts_params->mbuf_pool != NULL) {
514                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
515                 rte_mempool_avail_count(ts_params->mbuf_pool));
516         }
517
518         if (ts_params->op_mpool != NULL) {
519                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
520                 rte_mempool_avail_count(ts_params->op_mpool));
521         }
522
523         /* Free session mempools */
524         if (ts_params->session_priv_mpool != NULL) {
525                 rte_mempool_free(ts_params->session_priv_mpool);
526                 ts_params->session_priv_mpool = NULL;
527         }
528
529         if (ts_params->session_mpool != NULL) {
530                 rte_mempool_free(ts_params->session_mpool);
531                 ts_params->session_mpool = NULL;
532         }
533 }
534
535 static int
536 ut_setup(void)
537 {
538         struct crypto_testsuite_params *ts_params = &testsuite_params;
539         struct crypto_unittest_params *ut_params = &unittest_params;
540
541         uint16_t qp_id;
542
543         /* Clear unit test parameters before running test */
544         memset(ut_params, 0, sizeof(*ut_params));
545
546         /* Reconfigure device to default parameters */
547         ts_params->conf.socket_id = SOCKET_ID_ANY;
548         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
549         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
550         ts_params->qp_conf.mp_session = ts_params->session_mpool;
551         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
552
553         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
554                         &ts_params->conf),
555                         "Failed to configure cryptodev %u",
556                         ts_params->valid_devs[0]);
557
558         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
559                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
560                         ts_params->valid_devs[0], qp_id,
561                         &ts_params->qp_conf,
562                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
563                         "Failed to setup queue pair %u on cryptodev %u",
564                         qp_id, ts_params->valid_devs[0]);
565         }
566
567
568         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
569
570         /* Start the device */
571         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
572                         "Failed to start cryptodev %u",
573                         ts_params->valid_devs[0]);
574
575         return TEST_SUCCESS;
576 }
577
578 static void
579 ut_teardown(void)
580 {
581         struct crypto_testsuite_params *ts_params = &testsuite_params;
582         struct crypto_unittest_params *ut_params = &unittest_params;
583         struct rte_cryptodev_stats stats;
584
585         /* free crypto session structure */
586 #ifdef RTE_LIBRTE_SECURITY
587         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
588                 if (ut_params->sec_session) {
589                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
590                                                 (ts_params->valid_devs[0]),
591                                                 ut_params->sec_session);
592                         ut_params->sec_session = NULL;
593                 }
594         } else
595 #endif
596         {
597                 if (ut_params->sess) {
598                         rte_cryptodev_sym_session_clear(
599                                         ts_params->valid_devs[0],
600                                         ut_params->sess);
601                         rte_cryptodev_sym_session_free(ut_params->sess);
602                         ut_params->sess = NULL;
603                 }
604         }
605
606         /* free crypto operation structure */
607         if (ut_params->op)
608                 rte_crypto_op_free(ut_params->op);
609
610         /*
611          * free mbuf - both obuf and ibuf are usually the same,
612          * so check if they point at the same address is necessary,
613          * to avoid freeing the mbuf twice.
614          */
615         if (ut_params->obuf) {
616                 rte_pktmbuf_free(ut_params->obuf);
617                 if (ut_params->ibuf == ut_params->obuf)
618                         ut_params->ibuf = 0;
619                 ut_params->obuf = 0;
620         }
621         if (ut_params->ibuf) {
622                 rte_pktmbuf_free(ut_params->ibuf);
623                 ut_params->ibuf = 0;
624         }
625
626         if (ts_params->mbuf_pool != NULL)
627                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
628                         rte_mempool_avail_count(ts_params->mbuf_pool));
629
630         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
631
632         /* Stop the device */
633         rte_cryptodev_stop(ts_params->valid_devs[0]);
634 }
635
636 static int
637 test_device_configure_invalid_dev_id(void)
638 {
639         struct crypto_testsuite_params *ts_params = &testsuite_params;
640         uint16_t dev_id, num_devs = 0;
641
642         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
643                         "Need at least %d devices for test", 1);
644
645         /* valid dev_id values */
646         dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
647
648         /* Stop the device in case it's started so it can be configured */
649         rte_cryptodev_stop(dev_id);
650
651         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
652                         "Failed test for rte_cryptodev_configure: "
653                         "invalid dev_num %u", dev_id);
654
655         /* invalid dev_id values */
656         dev_id = num_devs;
657
658         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
659                         "Failed test for rte_cryptodev_configure: "
660                         "invalid dev_num %u", dev_id);
661
662         dev_id = 0xff;
663
664         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
665                         "Failed test for rte_cryptodev_configure:"
666                         "invalid dev_num %u", dev_id);
667
668         return TEST_SUCCESS;
669 }
670
671 static int
672 test_device_configure_invalid_queue_pair_ids(void)
673 {
674         struct crypto_testsuite_params *ts_params = &testsuite_params;
675         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
676
677         /* This test is for QAT and NITROX PMDs only */
678         if (gbl_driver_id != rte_cryptodev_driver_id_get(
679                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)) &&
680             gbl_driver_id != rte_cryptodev_driver_id_get(
681                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD)))
682                 return -ENOTSUP;
683
684         /* Stop the device in case it's started so it can be configured */
685         rte_cryptodev_stop(ts_params->valid_devs[0]);
686
687         /* valid - one queue pairs */
688         ts_params->conf.nb_queue_pairs = 1;
689
690         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
691                         &ts_params->conf),
692                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
693                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
694
695
696         /* valid - max value queue pairs */
697         ts_params->conf.nb_queue_pairs = orig_nb_qps;
698
699         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
700                         &ts_params->conf),
701                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
702                         ts_params->valid_devs[0],
703                         ts_params->conf.nb_queue_pairs);
704
705
706         /* invalid - zero queue pairs */
707         ts_params->conf.nb_queue_pairs = 0;
708
709         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
710                         &ts_params->conf),
711                         "Failed test for rte_cryptodev_configure, dev_id %u,"
712                         " invalid qps: %u",
713                         ts_params->valid_devs[0],
714                         ts_params->conf.nb_queue_pairs);
715
716
717         /* invalid - max value supported by field queue pairs */
718         ts_params->conf.nb_queue_pairs = UINT16_MAX;
719
720         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
721                         &ts_params->conf),
722                         "Failed test for rte_cryptodev_configure, dev_id %u,"
723                         " invalid qps: %u",
724                         ts_params->valid_devs[0],
725                         ts_params->conf.nb_queue_pairs);
726
727
728         /* invalid - max value + 1 queue pairs */
729         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
730
731         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
732                         &ts_params->conf),
733                         "Failed test for rte_cryptodev_configure, dev_id %u,"
734                         " invalid qps: %u",
735                         ts_params->valid_devs[0],
736                         ts_params->conf.nb_queue_pairs);
737
738         /* revert to original testsuite value */
739         ts_params->conf.nb_queue_pairs = orig_nb_qps;
740
741         return TEST_SUCCESS;
742 }
743
744 static int
745 test_queue_pair_descriptor_setup(void)
746 {
747         struct crypto_testsuite_params *ts_params = &testsuite_params;
748         struct rte_cryptodev_info dev_info;
749         struct rte_cryptodev_qp_conf qp_conf = {
750                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
751         };
752
753         uint16_t qp_id;
754
755         /* This test is for QAT PMD only */
756         if (gbl_driver_id != rte_cryptodev_driver_id_get(
757                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)))
758                 return -ENOTSUP;
759
760         /* Stop the device in case it's started so it can be configured */
761         rte_cryptodev_stop(ts_params->valid_devs[0]);
762
763
764         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
765
766         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
767                         &ts_params->conf),
768                         "Failed to configure cryptodev %u",
769                         ts_params->valid_devs[0]);
770
771         /*
772          * Test various ring sizes on this device. memzones can't be
773          * freed so are re-used if ring is released and re-created.
774          */
775         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
776         qp_conf.mp_session = ts_params->session_mpool;
777         qp_conf.mp_session_private = ts_params->session_priv_mpool;
778
779         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
780                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
781                                 ts_params->valid_devs[0], qp_id, &qp_conf,
782                                 rte_cryptodev_socket_id(
783                                                 ts_params->valid_devs[0])),
784                                 "Failed test for "
785                                 "rte_cryptodev_queue_pair_setup: num_inflights "
786                                 "%u on qp %u on cryptodev %u",
787                                 qp_conf.nb_descriptors, qp_id,
788                                 ts_params->valid_devs[0]);
789         }
790
791         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
792
793         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
794                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
795                                 ts_params->valid_devs[0], qp_id, &qp_conf,
796                                 rte_cryptodev_socket_id(
797                                                 ts_params->valid_devs[0])),
798                                 "Failed test for"
799                                 " rte_cryptodev_queue_pair_setup: num_inflights"
800                                 " %u on qp %u on cryptodev %u",
801                                 qp_conf.nb_descriptors, qp_id,
802                                 ts_params->valid_devs[0]);
803         }
804
805         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
806
807         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
808                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
809                                 ts_params->valid_devs[0], qp_id, &qp_conf,
810                                 rte_cryptodev_socket_id(
811                                                 ts_params->valid_devs[0])),
812                                 "Failed test for "
813                                 "rte_cryptodev_queue_pair_setup: num_inflights"
814                                 " %u on qp %u on cryptodev %u",
815                                 qp_conf.nb_descriptors, qp_id,
816                                 ts_params->valid_devs[0]);
817         }
818
819         /* invalid number of descriptors - max supported + 2 */
820         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
821
822         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
823                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
824                                 ts_params->valid_devs[0], qp_id, &qp_conf,
825                                 rte_cryptodev_socket_id(
826                                                 ts_params->valid_devs[0])),
827                                 "Unexpectedly passed test for "
828                                 "rte_cryptodev_queue_pair_setup:"
829                                 "num_inflights %u on qp %u on cryptodev %u",
830                                 qp_conf.nb_descriptors, qp_id,
831                                 ts_params->valid_devs[0]);
832         }
833
834         /* invalid number of descriptors - max value of parameter */
835         qp_conf.nb_descriptors = UINT32_MAX-1;
836
837         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
838                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
839                                 ts_params->valid_devs[0], qp_id, &qp_conf,
840                                 rte_cryptodev_socket_id(
841                                                 ts_params->valid_devs[0])),
842                                 "Unexpectedly passed test for "
843                                 "rte_cryptodev_queue_pair_setup:"
844                                 "num_inflights %u on qp %u on cryptodev %u",
845                                 qp_conf.nb_descriptors, qp_id,
846                                 ts_params->valid_devs[0]);
847         }
848
849         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
850
851         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
852                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
853                                 ts_params->valid_devs[0], qp_id, &qp_conf,
854                                 rte_cryptodev_socket_id(
855                                                 ts_params->valid_devs[0])),
856                                 "Failed test for"
857                                 " rte_cryptodev_queue_pair_setup:"
858                                 "num_inflights %u on qp %u on cryptodev %u",
859                                 qp_conf.nb_descriptors, qp_id,
860                                 ts_params->valid_devs[0]);
861         }
862
863         /* invalid number of descriptors - max supported + 1 */
864         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
865
866         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
867                 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
868                                 ts_params->valid_devs[0], qp_id, &qp_conf,
869                                 rte_cryptodev_socket_id(
870                                                 ts_params->valid_devs[0])),
871                                 "Unexpectedly passed test for "
872                                 "rte_cryptodev_queue_pair_setup:"
873                                 "num_inflights %u on qp %u on cryptodev %u",
874                                 qp_conf.nb_descriptors, qp_id,
875                                 ts_params->valid_devs[0]);
876         }
877
878         /* test invalid queue pair id */
879         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
880
881         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
882
883         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
884                         ts_params->valid_devs[0],
885                         qp_id, &qp_conf,
886                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
887                         "Failed test for rte_cryptodev_queue_pair_setup:"
888                         "invalid qp %u on cryptodev %u",
889                         qp_id, ts_params->valid_devs[0]);
890
891         qp_id = 0xffff; /*invalid*/
892
893         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
894                         ts_params->valid_devs[0],
895                         qp_id, &qp_conf,
896                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
897                         "Failed test for rte_cryptodev_queue_pair_setup:"
898                         "invalid qp %u on cryptodev %u",
899                         qp_id, ts_params->valid_devs[0]);
900
901         return TEST_SUCCESS;
902 }
903
904 /* ***** Plaintext data for tests ***** */
905
906 const char catch_22_quote_1[] =
907                 "There was only one catch and that was Catch-22, which "
908                 "specified that a concern for one's safety in the face of "
909                 "dangers that were real and immediate was the process of a "
910                 "rational mind. Orr was crazy and could be grounded. All he "
911                 "had to do was ask; and as soon as he did, he would no longer "
912                 "be crazy and would have to fly more missions. Orr would be "
913                 "crazy to fly more missions and sane if he didn't, but if he "
914                 "was sane he had to fly them. If he flew them he was crazy "
915                 "and didn't have to; but if he didn't want to he was sane and "
916                 "had to. Yossarian was moved very deeply by the absolute "
917                 "simplicity of this clause of Catch-22 and let out a "
918                 "respectful whistle. \"That's some catch, that Catch-22\", he "
919                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
920
921 const char catch_22_quote[] =
922                 "What a lousy earth! He wondered how many people were "
923                 "destitute that same night even in his own prosperous country, "
924                 "how many homes were shanties, how many husbands were drunk "
925                 "and wives socked, and how many children were bullied, abused, "
926                 "or abandoned. How many families hungered for food they could "
927                 "not afford to buy? How many hearts were broken? How many "
928                 "suicides would take place that same night, how many people "
929                 "would go insane? How many cockroaches and landlords would "
930                 "triumph? How many winners were losers, successes failures, "
931                 "and rich men poor men? How many wise guys were stupid? How "
932                 "many happy endings were unhappy endings? How many honest men "
933                 "were liars, brave men cowards, loyal men traitors, how many "
934                 "sainted men were corrupt, how many people in positions of "
935                 "trust had sold their souls to bodyguards, how many had never "
936                 "had souls? How many straight-and-narrow paths were crooked "
937                 "paths? How many best families were worst families and how "
938                 "many good people were bad people? When you added them all up "
939                 "and then subtracted, you might be left with only the children, "
940                 "and perhaps with Albert Einstein and an old violinist or "
941                 "sculptor somewhere.";
942
943 #define QUOTE_480_BYTES         (480)
944 #define QUOTE_512_BYTES         (512)
945 #define QUOTE_768_BYTES         (768)
946 #define QUOTE_1024_BYTES        (1024)
947
948
949
950 /* ***** SHA1 Hash Tests ***** */
951
952 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
953
954 static uint8_t hmac_sha1_key[] = {
955         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
956         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
957         0xDE, 0xF4, 0xDE, 0xAD };
958
959 /* ***** SHA224 Hash Tests ***** */
960
961 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
962
963
964 /* ***** AES-CBC Cipher Tests ***** */
965
966 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
967 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
968
969 static uint8_t aes_cbc_key[] = {
970         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
971         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
972
973 static uint8_t aes_cbc_iv[] = {
974         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
975         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
976
977
978 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
979
980 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
981         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
982         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
983         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
984         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
985         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
986         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
987         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
988         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
989         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
990         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
991         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
992         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
993         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
994         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
995         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
996         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
997         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
998         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
999         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1000         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1001         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1002         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1003         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1004         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1005         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1006         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1007         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1008         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1009         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1010         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1011         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1012         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1013         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1014         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1015         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1016         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1017         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1018         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1019         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1020         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1021         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1022         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1023         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1024         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1025         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1026         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1027         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1028         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1029         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1030         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1031         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1032         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1033         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1034         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1035         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1036         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1037         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1038         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1039         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1040         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1041         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1042         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1043         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1044         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1045 };
1046
1047 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1048         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1049         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1050         0x18, 0x8c, 0x1d, 0x32
1051 };
1052
1053
1054 /* Multisession Vector context Test */
1055 /*Begin Session 0 */
1056 static uint8_t ms_aes_cbc_key0[] = {
1057         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1058         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1059 };
1060
1061 static uint8_t ms_aes_cbc_iv0[] = {
1062         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1063         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1064 };
1065
1066 static const uint8_t ms_aes_cbc_cipher0[] = {
1067                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1068                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1069                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1070                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1071                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1072                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1073                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1074                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1075                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1076                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1077                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1078                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1079                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1080                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1081                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1082                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1083                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1084                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1085                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1086                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1087                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1088                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1089                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1090                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1091                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1092                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1093                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1094                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1095                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1096                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1097                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1098                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1099                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1100                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1101                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1102                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1103                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1104                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1105                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1106                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1107                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1108                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1109                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1110                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1111                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1112                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1113                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1114                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1115                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1116                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1117                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1118                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1119                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1120                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1121                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1122                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1123                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1124                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1125                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1126                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1127                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1128                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1129                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1130                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1131 };
1132
1133
1134 static  uint8_t ms_hmac_key0[] = {
1135                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1136                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1137                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1138                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1139                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1140                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1141                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1142                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1143 };
1144
1145 static const uint8_t ms_hmac_digest0[] = {
1146                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1147                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1148                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1149                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1150                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1151                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1152                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1153                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1154                 };
1155
1156 /* End Session 0 */
1157 /* Begin session 1 */
1158
1159 static  uint8_t ms_aes_cbc_key1[] = {
1160                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1161                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1162 };
1163
1164 static  uint8_t ms_aes_cbc_iv1[] = {
1165         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1166         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1167 };
1168
1169 static const uint8_t ms_aes_cbc_cipher1[] = {
1170                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1171                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1172                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1173                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1174                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1175                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1176                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1177                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1178                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1179                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1180                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1181                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1182                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1183                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1184                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1185                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1186                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1187                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1188                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1189                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1190                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1191                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1192                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1193                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1194                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1195                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1196                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1197                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1198                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1199                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1200                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1201                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1202                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1203                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1204                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1205                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1206                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1207                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1208                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1209                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1210                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1211                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1212                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1213                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1214                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1215                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1216                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1217                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1218                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1219                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1220                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1221                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1222                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1223                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1224                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1225                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1226                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1227                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1228                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1229                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1230                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1231                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1232                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1233                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1234
1235 };
1236
1237 static uint8_t ms_hmac_key1[] = {
1238                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1239                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1240                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1241                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1242                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1243                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1244                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1245                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1246 };
1247
1248 static const uint8_t ms_hmac_digest1[] = {
1249                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1250                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1251                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1252                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1253                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1254                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1255                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1256                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1257 };
1258 /* End Session 1  */
1259 /* Begin Session 2 */
1260 static  uint8_t ms_aes_cbc_key2[] = {
1261                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1262                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1263 };
1264
1265 static  uint8_t ms_aes_cbc_iv2[] = {
1266                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1267                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1268 };
1269
1270 static const uint8_t ms_aes_cbc_cipher2[] = {
1271                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1272                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1273                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1274                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1275                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1276                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1277                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1278                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1279                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1280                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1281                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1282                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1283                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1284                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1285                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1286                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1287                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1288                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1289                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1290                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1291                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1292                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1293                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1294                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1295                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1296                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1297                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1298                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1299                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1300                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1301                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1302                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1303                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1304                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1305                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1306                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1307                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1308                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1309                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1310                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1311                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1312                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1313                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1314                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1315                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1316                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1317                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1318                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1319                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1320                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1321                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1322                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1323                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1324                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1325                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1326                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1327                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1328                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1329                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1330                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1331                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1332                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1333                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1334                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1335 };
1336
1337 static  uint8_t ms_hmac_key2[] = {
1338                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1339                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1340                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1341                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1342                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1343                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1344                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1345                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1346 };
1347
1348 static const uint8_t ms_hmac_digest2[] = {
1349                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1350                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1351                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1352                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1353                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1354                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1355                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1356                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1357 };
1358
1359 /* End Session 2 */
1360
1361
1362 static int
1363 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1364 {
1365         struct crypto_testsuite_params *ts_params = &testsuite_params;
1366         struct crypto_unittest_params *ut_params = &unittest_params;
1367
1368         /* Verify the capabilities */
1369         struct rte_cryptodev_sym_capability_idx cap_idx;
1370         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1371         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
1372         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1373                         &cap_idx) == NULL)
1374                 return -ENOTSUP;
1375         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1376         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
1377         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1378                         &cap_idx) == NULL)
1379                 return -ENOTSUP;
1380
1381         /* Generate test mbuf data and space for digest */
1382         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1383                         catch_22_quote, QUOTE_512_BYTES, 0);
1384
1385         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1386                         DIGEST_BYTE_LENGTH_SHA1);
1387         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1388
1389         /* Setup Cipher Parameters */
1390         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1391         ut_params->cipher_xform.next = &ut_params->auth_xform;
1392
1393         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1394         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1395         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1396         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1397         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1398         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1399
1400         /* Setup HMAC Parameters */
1401         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1402
1403         ut_params->auth_xform.next = NULL;
1404
1405         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1406         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1407         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1408         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1409         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1410
1411         ut_params->sess = rte_cryptodev_sym_session_create(
1412                         ts_params->session_mpool);
1413
1414         /* Create crypto session*/
1415         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1416                         ut_params->sess, &ut_params->cipher_xform,
1417                         ts_params->session_priv_mpool);
1418         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1419
1420         /* Generate crypto op data structure */
1421         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1422                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1423         TEST_ASSERT_NOT_NULL(ut_params->op,
1424                         "Failed to allocate symmetric crypto operation struct");
1425
1426         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1427
1428         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1429
1430         /* set crypto operation source mbuf */
1431         sym_op->m_src = ut_params->ibuf;
1432
1433         /* Set crypto operation authentication parameters */
1434         sym_op->auth.digest.data = ut_params->digest;
1435         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1436                         ut_params->ibuf, QUOTE_512_BYTES);
1437
1438         sym_op->auth.data.offset = 0;
1439         sym_op->auth.data.length = QUOTE_512_BYTES;
1440
1441         /* Copy IV at the end of the crypto operation */
1442         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1443                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1444
1445         /* Set crypto operation cipher parameters */
1446         sym_op->cipher.data.offset = 0;
1447         sym_op->cipher.data.length = QUOTE_512_BYTES;
1448
1449         /* Process crypto operation */
1450         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1451                         ut_params->op), "failed to process sym crypto op");
1452
1453         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1454                         "crypto op processing failed");
1455
1456         /* Validate obuf */
1457         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1458                         uint8_t *);
1459
1460         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1461                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1462                         QUOTE_512_BYTES,
1463                         "ciphertext data not as expected");
1464
1465         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1466
1467         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1468                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1469                         gbl_driver_id == rte_cryptodev_driver_id_get(
1470                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1471                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1472                                         DIGEST_BYTE_LENGTH_SHA1,
1473                         "Generated digest data not as expected");
1474
1475         return TEST_SUCCESS;
1476 }
1477
1478 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1479
1480 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1481
1482 static uint8_t hmac_sha512_key[] = {
1483         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1484         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1485         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1486         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1487         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1488         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1489         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1490         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1491
1492 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1493         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1494         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1495         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1496         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1497         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1498         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1499         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1500         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1501
1502
1503
1504 static int
1505 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1506                 struct crypto_unittest_params *ut_params,
1507                 uint8_t *cipher_key,
1508                 uint8_t *hmac_key);
1509
1510 static int
1511 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1512                 struct crypto_unittest_params *ut_params,
1513                 struct crypto_testsuite_params *ts_params,
1514                 const uint8_t *cipher,
1515                 const uint8_t *digest,
1516                 const uint8_t *iv);
1517
1518
1519 static int
1520 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1521                 struct crypto_unittest_params *ut_params,
1522                 uint8_t *cipher_key,
1523                 uint8_t *hmac_key)
1524 {
1525
1526         /* Setup Cipher Parameters */
1527         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1528         ut_params->cipher_xform.next = NULL;
1529
1530         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1531         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1532         ut_params->cipher_xform.cipher.key.data = cipher_key;
1533         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1534         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1535         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1536
1537         /* Setup HMAC Parameters */
1538         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1539         ut_params->auth_xform.next = &ut_params->cipher_xform;
1540
1541         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1542         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1543         ut_params->auth_xform.auth.key.data = hmac_key;
1544         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1545         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1546
1547         return TEST_SUCCESS;
1548 }
1549
1550
1551 static int
1552 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1553                 struct crypto_unittest_params *ut_params,
1554                 struct crypto_testsuite_params *ts_params,
1555                 const uint8_t *cipher,
1556                 const uint8_t *digest,
1557                 const uint8_t *iv)
1558 {
1559         /* Generate test mbuf data and digest */
1560         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1561                         (const char *)
1562                         cipher,
1563                         QUOTE_512_BYTES, 0);
1564
1565         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1566                         DIGEST_BYTE_LENGTH_SHA512);
1567         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1568
1569         rte_memcpy(ut_params->digest,
1570                         digest,
1571                         DIGEST_BYTE_LENGTH_SHA512);
1572
1573         /* Generate Crypto op data structure */
1574         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1575                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1576         TEST_ASSERT_NOT_NULL(ut_params->op,
1577                         "Failed to allocate symmetric crypto operation struct");
1578
1579         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1580
1581         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1582
1583         /* set crypto operation source mbuf */
1584         sym_op->m_src = ut_params->ibuf;
1585
1586         sym_op->auth.digest.data = ut_params->digest;
1587         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1588                         ut_params->ibuf, QUOTE_512_BYTES);
1589
1590         sym_op->auth.data.offset = 0;
1591         sym_op->auth.data.length = QUOTE_512_BYTES;
1592
1593         /* Copy IV at the end of the crypto operation */
1594         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1595                         iv, CIPHER_IV_LENGTH_AES_CBC);
1596
1597         sym_op->cipher.data.offset = 0;
1598         sym_op->cipher.data.length = QUOTE_512_BYTES;
1599
1600         /* Process crypto operation */
1601         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1602                         ut_params->op), "failed to process sym crypto op");
1603
1604         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1605                         "crypto op processing failed");
1606
1607         ut_params->obuf = ut_params->op->sym->m_src;
1608
1609         /* Validate obuf */
1610         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1611                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1612                         catch_22_quote,
1613                         QUOTE_512_BYTES,
1614                         "Plaintext data not as expected");
1615
1616         /* Validate obuf */
1617         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1618                         "Digest verification failed");
1619
1620         return TEST_SUCCESS;
1621 }
1622
1623 static int
1624 test_blockcipher(enum blockcipher_test_type test_type)
1625 {
1626         struct crypto_testsuite_params *ts_params = &testsuite_params;
1627         int status;
1628
1629         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1630                 ts_params->op_mpool,
1631                 ts_params->session_mpool, ts_params->session_priv_mpool,
1632                 ts_params->valid_devs[0],
1633                 gbl_driver_id,
1634                 test_type);
1635
1636         if (status == -ENOTSUP)
1637                 return status;
1638
1639         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1640
1641         return TEST_SUCCESS;
1642 }
1643
1644 static int
1645 test_AES_cipheronly_all(void)
1646 {
1647         return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
1648 }
1649
1650 static int
1651 test_AES_docsis_all(void)
1652 {
1653         return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
1654 }
1655
1656 static int
1657 test_DES_docsis_all(void)
1658 {
1659         return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
1660 }
1661
1662 static int
1663 test_DES_cipheronly_all(void)
1664 {
1665         return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
1666 }
1667
1668 static int
1669 test_authonly_all(void)
1670 {
1671         return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
1672 }
1673
1674 static int
1675 test_AES_chain_all(void)
1676 {
1677         return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
1678 }
1679
1680 static int
1681 test_3DES_chain_all(void)
1682 {
1683         return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
1684 }
1685
1686 static int
1687 test_3DES_cipheronly_all(void)
1688 {
1689         return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
1690 }
1691
1692 /* ***** SNOW 3G Tests ***** */
1693 static int
1694 create_wireless_algo_hash_session(uint8_t dev_id,
1695         const uint8_t *key, const uint8_t key_len,
1696         const uint8_t iv_len, const uint8_t auth_len,
1697         enum rte_crypto_auth_operation op,
1698         enum rte_crypto_auth_algorithm algo)
1699 {
1700         uint8_t hash_key[key_len];
1701         int status;
1702
1703         struct crypto_testsuite_params *ts_params = &testsuite_params;
1704         struct crypto_unittest_params *ut_params = &unittest_params;
1705
1706         memcpy(hash_key, key, key_len);
1707
1708         debug_hexdump(stdout, "key:", key, key_len);
1709
1710         /* Setup Authentication Parameters */
1711         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1712         ut_params->auth_xform.next = NULL;
1713
1714         ut_params->auth_xform.auth.op = op;
1715         ut_params->auth_xform.auth.algo = algo;
1716         ut_params->auth_xform.auth.key.length = key_len;
1717         ut_params->auth_xform.auth.key.data = hash_key;
1718         ut_params->auth_xform.auth.digest_length = auth_len;
1719         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
1720         ut_params->auth_xform.auth.iv.length = iv_len;
1721         ut_params->sess = rte_cryptodev_sym_session_create(
1722                         ts_params->session_mpool);
1723
1724         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1725                         &ut_params->auth_xform,
1726                         ts_params->session_priv_mpool);
1727         TEST_ASSERT_EQUAL(status, 0, "session init failed");
1728         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1729         return 0;
1730 }
1731
1732 static int
1733 create_wireless_algo_cipher_session(uint8_t dev_id,
1734                         enum rte_crypto_cipher_operation op,
1735                         enum rte_crypto_cipher_algorithm algo,
1736                         const uint8_t *key, const uint8_t key_len,
1737                         uint8_t iv_len)
1738 {
1739         uint8_t cipher_key[key_len];
1740         int status;
1741         struct crypto_testsuite_params *ts_params = &testsuite_params;
1742         struct crypto_unittest_params *ut_params = &unittest_params;
1743
1744         memcpy(cipher_key, key, key_len);
1745
1746         /* Setup Cipher Parameters */
1747         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1748         ut_params->cipher_xform.next = NULL;
1749
1750         ut_params->cipher_xform.cipher.algo = algo;
1751         ut_params->cipher_xform.cipher.op = op;
1752         ut_params->cipher_xform.cipher.key.data = cipher_key;
1753         ut_params->cipher_xform.cipher.key.length = key_len;
1754         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1755         ut_params->cipher_xform.cipher.iv.length = iv_len;
1756
1757         debug_hexdump(stdout, "key:", key, key_len);
1758
1759         /* Create Crypto session */
1760         ut_params->sess = rte_cryptodev_sym_session_create(
1761                         ts_params->session_mpool);
1762
1763         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1764                         &ut_params->cipher_xform,
1765                         ts_params->session_priv_mpool);
1766         TEST_ASSERT_EQUAL(status, 0, "session init failed");
1767         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1768         return 0;
1769 }
1770
1771 static int
1772 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
1773                         unsigned int cipher_len,
1774                         unsigned int cipher_offset)
1775 {
1776         struct crypto_testsuite_params *ts_params = &testsuite_params;
1777         struct crypto_unittest_params *ut_params = &unittest_params;
1778
1779         /* Generate Crypto op data structure */
1780         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1781                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1782         TEST_ASSERT_NOT_NULL(ut_params->op,
1783                                 "Failed to allocate pktmbuf offload");
1784
1785         /* Set crypto operation data parameters */
1786         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1787
1788         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1789
1790         /* set crypto operation source mbuf */
1791         sym_op->m_src = ut_params->ibuf;
1792
1793         /* iv */
1794         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1795                         iv, iv_len);
1796         sym_op->cipher.data.length = cipher_len;
1797         sym_op->cipher.data.offset = cipher_offset;
1798         return 0;
1799 }
1800
1801 static int
1802 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
1803                         unsigned int cipher_len,
1804                         unsigned int cipher_offset)
1805 {
1806         struct crypto_testsuite_params *ts_params = &testsuite_params;
1807         struct crypto_unittest_params *ut_params = &unittest_params;
1808
1809         /* Generate Crypto op data structure */
1810         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1811                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1812         TEST_ASSERT_NOT_NULL(ut_params->op,
1813                                 "Failed to allocate pktmbuf offload");
1814
1815         /* Set crypto operation data parameters */
1816         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1817
1818         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1819
1820         /* set crypto operation source mbuf */
1821         sym_op->m_src = ut_params->ibuf;
1822         sym_op->m_dst = ut_params->obuf;
1823
1824         /* iv */
1825         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1826                         iv, iv_len);
1827         sym_op->cipher.data.length = cipher_len;
1828         sym_op->cipher.data.offset = cipher_offset;
1829         return 0;
1830 }
1831
1832 static int
1833 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1834                 enum rte_crypto_cipher_operation cipher_op,
1835                 enum rte_crypto_auth_operation auth_op,
1836                 enum rte_crypto_auth_algorithm auth_algo,
1837                 enum rte_crypto_cipher_algorithm cipher_algo,
1838                 const uint8_t *key, uint8_t key_len,
1839                 uint8_t auth_iv_len, uint8_t auth_len,
1840                 uint8_t cipher_iv_len)
1841
1842 {
1843         uint8_t cipher_auth_key[key_len];
1844         int status;
1845
1846         struct crypto_testsuite_params *ts_params = &testsuite_params;
1847         struct crypto_unittest_params *ut_params = &unittest_params;
1848
1849         memcpy(cipher_auth_key, key, key_len);
1850
1851         /* Setup Authentication Parameters */
1852         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1853         ut_params->auth_xform.next = NULL;
1854
1855         ut_params->auth_xform.auth.op = auth_op;
1856         ut_params->auth_xform.auth.algo = auth_algo;
1857         ut_params->auth_xform.auth.key.length = key_len;
1858         /* Hash key = cipher key */
1859         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1860         ut_params->auth_xform.auth.digest_length = auth_len;
1861         /* Auth IV will be after cipher IV */
1862         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
1863         ut_params->auth_xform.auth.iv.length = auth_iv_len;
1864
1865         /* Setup Cipher Parameters */
1866         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1867         ut_params->cipher_xform.next = &ut_params->auth_xform;
1868
1869         ut_params->cipher_xform.cipher.algo = cipher_algo;
1870         ut_params->cipher_xform.cipher.op = cipher_op;
1871         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1872         ut_params->cipher_xform.cipher.key.length = key_len;
1873         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1874         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
1875
1876         debug_hexdump(stdout, "key:", key, key_len);
1877
1878         /* Create Crypto session*/
1879         ut_params->sess = rte_cryptodev_sym_session_create(
1880                         ts_params->session_mpool);
1881         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1882
1883         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1884                         &ut_params->cipher_xform,
1885                         ts_params->session_priv_mpool);
1886         if (status == -ENOTSUP)
1887                 return status;
1888
1889         TEST_ASSERT_EQUAL(status, 0, "session init failed");
1890         return 0;
1891 }
1892
1893 static int
1894 create_wireless_cipher_auth_session(uint8_t dev_id,
1895                 enum rte_crypto_cipher_operation cipher_op,
1896                 enum rte_crypto_auth_operation auth_op,
1897                 enum rte_crypto_auth_algorithm auth_algo,
1898                 enum rte_crypto_cipher_algorithm cipher_algo,
1899                 const struct wireless_test_data *tdata)
1900 {
1901         const uint8_t key_len = tdata->key.len;
1902         uint8_t cipher_auth_key[key_len];
1903         int status;
1904
1905         struct crypto_testsuite_params *ts_params = &testsuite_params;
1906         struct crypto_unittest_params *ut_params = &unittest_params;
1907         const uint8_t *key = tdata->key.data;
1908         const uint8_t auth_len = tdata->digest.len;
1909         uint8_t cipher_iv_len = tdata->cipher_iv.len;
1910         uint8_t auth_iv_len = tdata->auth_iv.len;
1911
1912         memcpy(cipher_auth_key, key, key_len);
1913
1914         /* Setup Authentication Parameters */
1915         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1916         ut_params->auth_xform.next = NULL;
1917
1918         ut_params->auth_xform.auth.op = auth_op;
1919         ut_params->auth_xform.auth.algo = auth_algo;
1920         ut_params->auth_xform.auth.key.length = key_len;
1921         /* Hash key = cipher key */
1922         ut_params->auth_xform.auth.key.data = cipher_auth_key;
1923         ut_params->auth_xform.auth.digest_length = auth_len;
1924         /* Auth IV will be after cipher IV */
1925         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
1926         ut_params->auth_xform.auth.iv.length = auth_iv_len;
1927
1928         /* Setup Cipher Parameters */
1929         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1930         ut_params->cipher_xform.next = &ut_params->auth_xform;
1931
1932         ut_params->cipher_xform.cipher.algo = cipher_algo;
1933         ut_params->cipher_xform.cipher.op = cipher_op;
1934         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1935         ut_params->cipher_xform.cipher.key.length = key_len;
1936         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1937         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
1938
1939
1940         debug_hexdump(stdout, "key:", key, key_len);
1941
1942         /* Create Crypto session*/
1943         ut_params->sess = rte_cryptodev_sym_session_create(
1944                         ts_params->session_mpool);
1945
1946         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
1947                         &ut_params->cipher_xform,
1948                         ts_params->session_priv_mpool);
1949
1950         TEST_ASSERT_EQUAL(status, 0, "session init failed");
1951         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1952         return 0;
1953 }
1954
1955 static int
1956 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
1957                 const struct wireless_test_data *tdata)
1958 {
1959         return create_wireless_cipher_auth_session(dev_id,
1960                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1961                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
1962                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
1963 }
1964
1965 static int
1966 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1967                 enum rte_crypto_cipher_operation cipher_op,
1968                 enum rte_crypto_auth_operation auth_op,
1969                 enum rte_crypto_auth_algorithm auth_algo,
1970                 enum rte_crypto_cipher_algorithm cipher_algo,
1971                 const uint8_t *key, const uint8_t key_len,
1972                 uint8_t auth_iv_len, uint8_t auth_len,
1973                 uint8_t cipher_iv_len)
1974 {
1975         uint8_t auth_cipher_key[key_len];
1976         int status;
1977         struct crypto_testsuite_params *ts_params = &testsuite_params;
1978         struct crypto_unittest_params *ut_params = &unittest_params;
1979
1980         memcpy(auth_cipher_key, key, key_len);
1981
1982         /* Setup Authentication Parameters */
1983         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1984         ut_params->auth_xform.auth.op = auth_op;
1985         ut_params->auth_xform.next = &ut_params->cipher_xform;
1986         ut_params->auth_xform.auth.algo = auth_algo;
1987         ut_params->auth_xform.auth.key.length = key_len;
1988         ut_params->auth_xform.auth.key.data = auth_cipher_key;
1989         ut_params->auth_xform.auth.digest_length = auth_len;
1990         /* Auth IV will be after cipher IV */
1991         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
1992         ut_params->auth_xform.auth.iv.length = auth_iv_len;
1993
1994         /* Setup Cipher Parameters */
1995         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1996         ut_params->cipher_xform.next = NULL;
1997         ut_params->cipher_xform.cipher.algo = cipher_algo;
1998         ut_params->cipher_xform.cipher.op = cipher_op;
1999         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2000         ut_params->cipher_xform.cipher.key.length = key_len;
2001         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2002         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2003
2004         debug_hexdump(stdout, "key:", key, key_len);
2005
2006         /* Create Crypto session*/
2007         ut_params->sess = rte_cryptodev_sym_session_create(
2008                         ts_params->session_mpool);
2009         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2010
2011         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2012                 ut_params->auth_xform.next = NULL;
2013                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2014                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2015                                 &ut_params->cipher_xform,
2016                                 ts_params->session_priv_mpool);
2017
2018         } else
2019                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2020                                 &ut_params->auth_xform,
2021                                 ts_params->session_priv_mpool);
2022
2023         if (status == -ENOTSUP)
2024                 return status;
2025
2026         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2027
2028         return 0;
2029 }
2030
2031 static int
2032 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2033                 unsigned int auth_tag_len,
2034                 const uint8_t *iv, unsigned int iv_len,
2035                 unsigned int data_pad_len,
2036                 enum rte_crypto_auth_operation op,
2037                 unsigned int auth_len, unsigned int auth_offset)
2038 {
2039         struct crypto_testsuite_params *ts_params = &testsuite_params;
2040
2041         struct crypto_unittest_params *ut_params = &unittest_params;
2042
2043         /* Generate Crypto op data structure */
2044         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2045                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2046         TEST_ASSERT_NOT_NULL(ut_params->op,
2047                 "Failed to allocate pktmbuf offload");
2048
2049         /* Set crypto operation data parameters */
2050         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2051
2052         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2053
2054         /* set crypto operation source mbuf */
2055         sym_op->m_src = ut_params->ibuf;
2056
2057         /* iv */
2058         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2059                         iv, iv_len);
2060         /* digest */
2061         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2062                                         ut_params->ibuf, auth_tag_len);
2063
2064         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2065                                 "no room to append auth tag");
2066         ut_params->digest = sym_op->auth.digest.data;
2067         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2068                         ut_params->ibuf, data_pad_len);
2069         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2070                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2071         else
2072                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2073
2074         debug_hexdump(stdout, "digest:",
2075                 sym_op->auth.digest.data,
2076                 auth_tag_len);
2077
2078         sym_op->auth.data.length = auth_len;
2079         sym_op->auth.data.offset = auth_offset;
2080
2081         return 0;
2082 }
2083
2084 static int
2085 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2086         enum rte_crypto_auth_operation op)
2087 {
2088         struct crypto_testsuite_params *ts_params = &testsuite_params;
2089         struct crypto_unittest_params *ut_params = &unittest_params;
2090
2091         const uint8_t *auth_tag = tdata->digest.data;
2092         const unsigned int auth_tag_len = tdata->digest.len;
2093         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2094         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2095
2096         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2097         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2098         const uint8_t *auth_iv = tdata->auth_iv.data;
2099         const uint8_t auth_iv_len = tdata->auth_iv.len;
2100         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2101         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2102
2103         /* Generate Crypto op data structure */
2104         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2105                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2106         TEST_ASSERT_NOT_NULL(ut_params->op,
2107                         "Failed to allocate pktmbuf offload");
2108         /* Set crypto operation data parameters */
2109         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2110
2111         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2112
2113         /* set crypto operation source mbuf */
2114         sym_op->m_src = ut_params->ibuf;
2115
2116         /* digest */
2117         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2118                         ut_params->ibuf, auth_tag_len);
2119
2120         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2121                         "no room to append auth tag");
2122         ut_params->digest = sym_op->auth.digest.data;
2123         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2124                         ut_params->ibuf, data_pad_len);
2125         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2126                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2127         else
2128                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2129
2130         debug_hexdump(stdout, "digest:",
2131                 sym_op->auth.digest.data,
2132                 auth_tag_len);
2133
2134         /* Copy cipher and auth IVs at the end of the crypto operation */
2135         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2136                                                 IV_OFFSET);
2137         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2138         iv_ptr += cipher_iv_len;
2139         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2140
2141         sym_op->cipher.data.length = cipher_len;
2142         sym_op->cipher.data.offset = 0;
2143         sym_op->auth.data.length = auth_len;
2144         sym_op->auth.data.offset = 0;
2145
2146         return 0;
2147 }
2148
2149 static int
2150 create_zuc_cipher_hash_generate_operation(
2151                 const struct wireless_test_data *tdata)
2152 {
2153         return create_wireless_cipher_hash_operation(tdata,
2154                 RTE_CRYPTO_AUTH_OP_GENERATE);
2155 }
2156
2157 static int
2158 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2159                 const unsigned auth_tag_len,
2160                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2161                 unsigned data_pad_len,
2162                 enum rte_crypto_auth_operation op,
2163                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2164                 const unsigned cipher_len, const unsigned cipher_offset,
2165                 const unsigned auth_len, const unsigned auth_offset)
2166 {
2167         struct crypto_testsuite_params *ts_params = &testsuite_params;
2168         struct crypto_unittest_params *ut_params = &unittest_params;
2169
2170         enum rte_crypto_cipher_algorithm cipher_algo =
2171                         ut_params->cipher_xform.cipher.algo;
2172         enum rte_crypto_auth_algorithm auth_algo =
2173                         ut_params->auth_xform.auth.algo;
2174
2175         /* Generate Crypto op data structure */
2176         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2177                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2178         TEST_ASSERT_NOT_NULL(ut_params->op,
2179                         "Failed to allocate pktmbuf offload");
2180         /* Set crypto operation data parameters */
2181         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2182
2183         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2184
2185         /* set crypto operation source mbuf */
2186         sym_op->m_src = ut_params->ibuf;
2187
2188         /* digest */
2189         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2190                         ut_params->ibuf, auth_tag_len);
2191
2192         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2193                         "no room to append auth tag");
2194         ut_params->digest = sym_op->auth.digest.data;
2195
2196         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2197                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2198                                 ut_params->ibuf, data_pad_len);
2199         } else {
2200                 struct rte_mbuf *m = ut_params->ibuf;
2201                 unsigned int offset = data_pad_len;
2202
2203                 while (offset > m->data_len && m->next != NULL) {
2204                         offset -= m->data_len;
2205                         m = m->next;
2206                 }
2207                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2208                         m, offset);
2209         }
2210
2211         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2212                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2213         else
2214                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2215
2216         debug_hexdump(stdout, "digest:",
2217                 sym_op->auth.digest.data,
2218                 auth_tag_len);
2219
2220         /* Copy cipher and auth IVs at the end of the crypto operation */
2221         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2222                                                 IV_OFFSET);
2223         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2224         iv_ptr += cipher_iv_len;
2225         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2226
2227         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2228                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2229                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2230                 sym_op->cipher.data.length = cipher_len;
2231                 sym_op->cipher.data.offset = cipher_offset;
2232         } else {
2233                 sym_op->cipher.data.length = cipher_len >> 3;
2234                 sym_op->cipher.data.offset = cipher_offset >> 3;
2235         }
2236
2237         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2238                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2239                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2240                 sym_op->auth.data.length = auth_len;
2241                 sym_op->auth.data.offset = auth_offset;
2242         } else {
2243                 sym_op->auth.data.length = auth_len >> 3;
2244                 sym_op->auth.data.offset = auth_offset >> 3;
2245         }
2246
2247         return 0;
2248 }
2249
2250 static int
2251 create_wireless_algo_auth_cipher_operation(
2252                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2253                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2254                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2255                 unsigned int data_pad_len,
2256                 unsigned int cipher_len, unsigned int cipher_offset,
2257                 unsigned int auth_len, unsigned int auth_offset,
2258                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2259 {
2260         struct crypto_testsuite_params *ts_params = &testsuite_params;
2261         struct crypto_unittest_params *ut_params = &unittest_params;
2262
2263         enum rte_crypto_cipher_algorithm cipher_algo =
2264                         ut_params->cipher_xform.cipher.algo;
2265         enum rte_crypto_auth_algorithm auth_algo =
2266                         ut_params->auth_xform.auth.algo;
2267
2268         /* Generate Crypto op data structure */
2269         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2270                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2271         TEST_ASSERT_NOT_NULL(ut_params->op,
2272                         "Failed to allocate pktmbuf offload");
2273
2274         /* Set crypto operation data parameters */
2275         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2276
2277         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2278
2279         /* set crypto operation mbufs */
2280         sym_op->m_src = ut_params->ibuf;
2281         if (op_mode == OUT_OF_PLACE)
2282                 sym_op->m_dst = ut_params->obuf;
2283
2284         /* digest */
2285         if (!do_sgl) {
2286                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2287                         (op_mode == IN_PLACE ?
2288                                 ut_params->ibuf : ut_params->obuf),
2289                         uint8_t *, data_pad_len);
2290                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2291                         (op_mode == IN_PLACE ?
2292                                 ut_params->ibuf : ut_params->obuf),
2293                         data_pad_len);
2294                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2295         } else {
2296                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2297                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2298                                 sym_op->m_src : sym_op->m_dst);
2299                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2300                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2301                         sgl_buf = sgl_buf->next;
2302                 }
2303                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2304                                 uint8_t *, remaining_off);
2305                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2306                                 remaining_off);
2307                 memset(sym_op->auth.digest.data, 0, remaining_off);
2308                 while (sgl_buf->next != NULL) {
2309                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2310                                 0, rte_pktmbuf_data_len(sgl_buf));
2311                         sgl_buf = sgl_buf->next;
2312                 }
2313         }
2314
2315         /* Copy digest for the verification */
2316         if (verify)
2317                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2318
2319         /* Copy cipher and auth IVs at the end of the crypto operation */
2320         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2321                         ut_params->op, uint8_t *, IV_OFFSET);
2322
2323         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2324         iv_ptr += cipher_iv_len;
2325         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2326
2327         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2328                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2329                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2330                 sym_op->cipher.data.length = cipher_len;
2331                 sym_op->cipher.data.offset = cipher_offset;
2332         } else {
2333                 sym_op->cipher.data.length = cipher_len >> 3;
2334                 sym_op->cipher.data.offset = cipher_offset >> 3;
2335         }
2336
2337         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2338                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2339                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2340                 sym_op->auth.data.length = auth_len;
2341                 sym_op->auth.data.offset = auth_offset;
2342         } else {
2343                 sym_op->auth.data.length = auth_len >> 3;
2344                 sym_op->auth.data.offset = auth_offset >> 3;
2345         }
2346
2347         return 0;
2348 }
2349
2350 static int
2351 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2352 {
2353         struct crypto_testsuite_params *ts_params = &testsuite_params;
2354         struct crypto_unittest_params *ut_params = &unittest_params;
2355
2356         int retval;
2357         unsigned plaintext_pad_len;
2358         unsigned plaintext_len;
2359         uint8_t *plaintext;
2360
2361         /* QAT PMD supports byte-aligned data only */
2362         if ((tdata->validAuthLenInBits.len % 8 != 0) &&
2363                         (gbl_driver_id == rte_cryptodev_driver_id_get(
2364                                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD))))
2365                 return -ENOTSUP;
2366
2367         /* Verify the capabilities */
2368         struct rte_cryptodev_sym_capability_idx cap_idx;
2369         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2370         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2371         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2372                         &cap_idx) == NULL)
2373                 return -ENOTSUP;
2374
2375         /* Create SNOW 3G session */
2376         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2377                         tdata->key.data, tdata->key.len,
2378                         tdata->auth_iv.len, tdata->digest.len,
2379                         RTE_CRYPTO_AUTH_OP_GENERATE,
2380                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2381         if (retval < 0)
2382                 return retval;
2383
2384         /* alloc mbuf and set payload */
2385         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2386
2387         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2388         rte_pktmbuf_tailroom(ut_params->ibuf));
2389
2390         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2391         /* Append data which is padded to a multiple of */
2392         /* the algorithms block size */
2393         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2394         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2395                                 plaintext_pad_len);
2396         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2397
2398         /* Create SNOW 3G operation */
2399         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2400                         tdata->auth_iv.data, tdata->auth_iv.len,
2401                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2402                         tdata->validAuthLenInBits.len,
2403                         0);
2404         if (retval < 0)
2405                 return retval;
2406
2407         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2408                                 ut_params->op);
2409         ut_params->obuf = ut_params->op->sym->m_src;
2410         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2411         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2412                         + plaintext_pad_len;
2413
2414         /* Validate obuf */
2415         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2416         ut_params->digest,
2417         tdata->digest.data,
2418         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2419         "SNOW 3G Generated auth tag not as expected");
2420
2421         return 0;
2422 }
2423
2424 static int
2425 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2426 {
2427         struct crypto_testsuite_params *ts_params = &testsuite_params;
2428         struct crypto_unittest_params *ut_params = &unittest_params;
2429
2430         int retval;
2431         unsigned plaintext_pad_len;
2432         unsigned plaintext_len;
2433         uint8_t *plaintext;
2434
2435         /* QAT PMD supports byte-aligned data only */
2436         if ((tdata->validAuthLenInBits.len % 8 != 0) &&
2437                         (gbl_driver_id == rte_cryptodev_driver_id_get(
2438                                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD))))
2439                 return -ENOTSUP;
2440
2441         /* Verify the capabilities */
2442         struct rte_cryptodev_sym_capability_idx cap_idx;
2443         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2444         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2445         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2446                         &cap_idx) == NULL)
2447                 return -ENOTSUP;
2448
2449         /* Create SNOW 3G session */
2450         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2451                                 tdata->key.data, tdata->key.len,
2452                                 tdata->auth_iv.len, tdata->digest.len,
2453                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2454                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2455         if (retval < 0)
2456                 return retval;
2457         /* alloc mbuf and set payload */
2458         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2459
2460         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2461         rte_pktmbuf_tailroom(ut_params->ibuf));
2462
2463         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2464         /* Append data which is padded to a multiple of */
2465         /* the algorithms block size */
2466         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2467         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2468                                 plaintext_pad_len);
2469         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2470
2471         /* Create SNOW 3G operation */
2472         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2473                         tdata->digest.len,
2474                         tdata->auth_iv.data, tdata->auth_iv.len,
2475                         plaintext_pad_len,
2476                         RTE_CRYPTO_AUTH_OP_VERIFY,
2477                         tdata->validAuthLenInBits.len,
2478                         0);
2479         if (retval < 0)
2480                 return retval;
2481
2482         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2483                                 ut_params->op);
2484         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2485         ut_params->obuf = ut_params->op->sym->m_src;
2486         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2487                                 + plaintext_pad_len;
2488
2489         /* Validate obuf */
2490         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2491                 return 0;
2492         else
2493                 return -1;
2494
2495         return 0;
2496 }
2497
2498 static int
2499 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2500 {
2501         struct crypto_testsuite_params *ts_params = &testsuite_params;
2502         struct crypto_unittest_params *ut_params = &unittest_params;
2503
2504         int retval;
2505         unsigned plaintext_pad_len;
2506         unsigned plaintext_len;
2507         uint8_t *plaintext;
2508
2509         /* Verify the capabilities */
2510         struct rte_cryptodev_sym_capability_idx cap_idx;
2511         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2512         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2513         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2514                         &cap_idx) == NULL)
2515                 return -ENOTSUP;
2516
2517         /* Create KASUMI session */
2518         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2519                         tdata->key.data, tdata->key.len,
2520                         0, tdata->digest.len,
2521                         RTE_CRYPTO_AUTH_OP_GENERATE,
2522                         RTE_CRYPTO_AUTH_KASUMI_F9);
2523         if (retval < 0)
2524                 return retval;
2525
2526         /* alloc mbuf and set payload */
2527         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2528
2529         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2530         rte_pktmbuf_tailroom(ut_params->ibuf));
2531
2532         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2533         /* Append data which is padded to a multiple of */
2534         /* the algorithms block size */
2535         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2536         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2537                                 plaintext_pad_len);
2538         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2539
2540         /* Create KASUMI operation */
2541         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2542                         NULL, 0,
2543                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2544                         tdata->plaintext.len,
2545                         0);
2546         if (retval < 0)
2547                 return retval;
2548
2549         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2550                                 ut_params->op);
2551         ut_params->obuf = ut_params->op->sym->m_src;
2552         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2553         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2554                         + plaintext_pad_len;
2555
2556         /* Validate obuf */
2557         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2558         ut_params->digest,
2559         tdata->digest.data,
2560         DIGEST_BYTE_LENGTH_KASUMI_F9,
2561         "KASUMI Generated auth tag not as expected");
2562
2563         return 0;
2564 }
2565
2566 static int
2567 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2568 {
2569         struct crypto_testsuite_params *ts_params = &testsuite_params;
2570         struct crypto_unittest_params *ut_params = &unittest_params;
2571
2572         int retval;
2573         unsigned plaintext_pad_len;
2574         unsigned plaintext_len;
2575         uint8_t *plaintext;
2576
2577         /* Verify the capabilities */
2578         struct rte_cryptodev_sym_capability_idx cap_idx;
2579         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2580         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2581         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2582                         &cap_idx) == NULL)
2583                 return -ENOTSUP;
2584
2585         /* Create KASUMI session */
2586         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2587                                 tdata->key.data, tdata->key.len,
2588                                 0, tdata->digest.len,
2589                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2590                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2591         if (retval < 0)
2592                 return retval;
2593         /* alloc mbuf and set payload */
2594         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2595
2596         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2597         rte_pktmbuf_tailroom(ut_params->ibuf));
2598
2599         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2600         /* Append data which is padded to a multiple */
2601         /* of the algorithms block size */
2602         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2603         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2604                                 plaintext_pad_len);
2605         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2606
2607         /* Create KASUMI operation */
2608         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2609                         tdata->digest.len,
2610                         NULL, 0,
2611                         plaintext_pad_len,
2612                         RTE_CRYPTO_AUTH_OP_VERIFY,
2613                         tdata->plaintext.len,
2614                         0);
2615         if (retval < 0)
2616                 return retval;
2617
2618         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2619                                 ut_params->op);
2620         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2621         ut_params->obuf = ut_params->op->sym->m_src;
2622         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2623                                 + plaintext_pad_len;
2624
2625         /* Validate obuf */
2626         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2627                 return 0;
2628         else
2629                 return -1;
2630
2631         return 0;
2632 }
2633
2634 static int
2635 test_snow3g_hash_generate_test_case_1(void)
2636 {
2637         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2638 }
2639
2640 static int
2641 test_snow3g_hash_generate_test_case_2(void)
2642 {
2643         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2644 }
2645
2646 static int
2647 test_snow3g_hash_generate_test_case_3(void)
2648 {
2649         return test_snow3g_authentication(&snow3g_hash_test_case_3);
2650 }
2651
2652 static int
2653 test_snow3g_hash_generate_test_case_4(void)
2654 {
2655         return test_snow3g_authentication(&snow3g_hash_test_case_4);
2656 }
2657
2658 static int
2659 test_snow3g_hash_generate_test_case_5(void)
2660 {
2661         return test_snow3g_authentication(&snow3g_hash_test_case_5);
2662 }
2663
2664 static int
2665 test_snow3g_hash_generate_test_case_6(void)
2666 {
2667         return test_snow3g_authentication(&snow3g_hash_test_case_6);
2668 }
2669
2670 static int
2671 test_snow3g_hash_verify_test_case_1(void)
2672 {
2673         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2674
2675 }
2676
2677 static int
2678 test_snow3g_hash_verify_test_case_2(void)
2679 {
2680         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2681 }
2682
2683 static int
2684 test_snow3g_hash_verify_test_case_3(void)
2685 {
2686         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2687 }
2688
2689 static int
2690 test_snow3g_hash_verify_test_case_4(void)
2691 {
2692         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2693 }
2694
2695 static int
2696 test_snow3g_hash_verify_test_case_5(void)
2697 {
2698         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2699 }
2700
2701 static int
2702 test_snow3g_hash_verify_test_case_6(void)
2703 {
2704         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2705 }
2706
2707 static int
2708 test_kasumi_hash_generate_test_case_1(void)
2709 {
2710         return test_kasumi_authentication(&kasumi_hash_test_case_1);
2711 }
2712
2713 static int
2714 test_kasumi_hash_generate_test_case_2(void)
2715 {
2716         return test_kasumi_authentication(&kasumi_hash_test_case_2);
2717 }
2718
2719 static int
2720 test_kasumi_hash_generate_test_case_3(void)
2721 {
2722         return test_kasumi_authentication(&kasumi_hash_test_case_3);
2723 }
2724
2725 static int
2726 test_kasumi_hash_generate_test_case_4(void)
2727 {
2728         return test_kasumi_authentication(&kasumi_hash_test_case_4);
2729 }
2730
2731 static int
2732 test_kasumi_hash_generate_test_case_5(void)
2733 {
2734         return test_kasumi_authentication(&kasumi_hash_test_case_5);
2735 }
2736
2737 static int
2738 test_kasumi_hash_generate_test_case_6(void)
2739 {
2740         return test_kasumi_authentication(&kasumi_hash_test_case_6);
2741 }
2742
2743 static int
2744 test_kasumi_hash_verify_test_case_1(void)
2745 {
2746         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2747 }
2748
2749 static int
2750 test_kasumi_hash_verify_test_case_2(void)
2751 {
2752         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2753 }
2754
2755 static int
2756 test_kasumi_hash_verify_test_case_3(void)
2757 {
2758         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2759 }
2760
2761 static int
2762 test_kasumi_hash_verify_test_case_4(void)
2763 {
2764         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2765 }
2766
2767 static int
2768 test_kasumi_hash_verify_test_case_5(void)
2769 {
2770         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2771 }
2772
2773 static int
2774 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2775 {
2776         struct crypto_testsuite_params *ts_params = &testsuite_params;
2777         struct crypto_unittest_params *ut_params = &unittest_params;
2778
2779         int retval;
2780         uint8_t *plaintext, *ciphertext;
2781         unsigned plaintext_pad_len;
2782         unsigned plaintext_len;
2783
2784         /* Verify the capabilities */
2785         struct rte_cryptodev_sym_capability_idx cap_idx;
2786         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2787         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
2788         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2789                         &cap_idx) == NULL)
2790                 return -ENOTSUP;
2791
2792         /* Create KASUMI session */
2793         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2794                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2795                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2796                                         tdata->key.data, tdata->key.len,
2797                                         tdata->cipher_iv.len);
2798         if (retval < 0)
2799                 return retval;
2800
2801         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2802
2803         /* Clear mbuf payload */
2804         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2805                rte_pktmbuf_tailroom(ut_params->ibuf));
2806
2807         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2808         /* Append data which is padded to a multiple */
2809         /* of the algorithms block size */
2810         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2811         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2812                                 plaintext_pad_len);
2813         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2814
2815         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
2816
2817         /* Create KASUMI operation */
2818         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
2819                                 tdata->cipher_iv.len,
2820                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
2821                                 tdata->validCipherOffsetInBits.len);
2822         if (retval < 0)
2823                 return retval;
2824
2825         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2826                                                 ut_params->op);
2827         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2828
2829         ut_params->obuf = ut_params->op->sym->m_dst;
2830         if (ut_params->obuf)
2831                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
2832         else
2833                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
2834
2835         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2836
2837         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
2838                                 (tdata->validCipherOffsetInBits.len >> 3);
2839         /* Validate obuf */
2840         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2841                 ciphertext,
2842                 reference_ciphertext,
2843                 tdata->validCipherLenInBits.len,
2844                 "KASUMI Ciphertext data not as expected");
2845         return 0;
2846 }
2847
2848 static int
2849 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
2850 {
2851         struct crypto_testsuite_params *ts_params = &testsuite_params;
2852         struct crypto_unittest_params *ut_params = &unittest_params;
2853
2854         int retval;
2855
2856         unsigned int plaintext_pad_len;
2857         unsigned int plaintext_len;
2858
2859         uint8_t buffer[10000];
2860         const uint8_t *ciphertext;
2861
2862         struct rte_cryptodev_info dev_info;
2863
2864         /* Verify the capabilities */
2865         struct rte_cryptodev_sym_capability_idx cap_idx;
2866         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2867         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
2868         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2869                         &cap_idx) == NULL)
2870                 return -ENOTSUP;
2871
2872         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2873
2874         uint64_t feat_flags = dev_info.feature_flags;
2875
2876         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
2877                 printf("Device doesn't support in-place scatter-gather. "
2878                                 "Test Skipped.\n");
2879                 return -ENOTSUP;
2880         }
2881
2882         /* Create KASUMI session */
2883         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2884                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2885                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2886                                         tdata->key.data, tdata->key.len,
2887                                         tdata->cipher_iv.len);
2888         if (retval < 0)
2889                 return retval;
2890
2891         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2892
2893
2894         /* Append data which is padded to a multiple */
2895         /* of the algorithms block size */
2896         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2897
2898         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
2899                         plaintext_pad_len, 10, 0);
2900
2901         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
2902
2903         /* Create KASUMI operation */
2904         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
2905                                 tdata->cipher_iv.len,
2906                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
2907                                 tdata->validCipherOffsetInBits.len);
2908         if (retval < 0)
2909                 return retval;
2910
2911         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2912                                                 ut_params->op);
2913         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2914
2915         ut_params->obuf = ut_params->op->sym->m_dst;
2916
2917         if (ut_params->obuf)
2918                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
2919                                 plaintext_len, buffer);
2920         else
2921                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
2922                                 tdata->validCipherOffsetInBits.len >> 3,
2923                                 plaintext_len, buffer);
2924
2925         /* Validate obuf */
2926         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2927
2928         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
2929                                 (tdata->validCipherOffsetInBits.len >> 3);
2930         /* Validate obuf */
2931         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2932                 ciphertext,
2933                 reference_ciphertext,
2934                 tdata->validCipherLenInBits.len,
2935                 "KASUMI Ciphertext data not as expected");
2936         return 0;
2937 }
2938
2939 static int
2940 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2941 {
2942         struct crypto_testsuite_params *ts_params = &testsuite_params;
2943         struct crypto_unittest_params *ut_params = &unittest_params;
2944
2945         int retval;
2946         uint8_t *plaintext, *ciphertext;
2947         unsigned plaintext_pad_len;
2948         unsigned plaintext_len;
2949
2950         /* Verify the capabilities */
2951         struct rte_cryptodev_sym_capability_idx cap_idx;
2952         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2953         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
2954         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2955                         &cap_idx) == NULL)
2956                 return -ENOTSUP;
2957
2958         /* Create KASUMI session */
2959         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2960                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2961                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
2962                                         tdata->key.data, tdata->key.len,
2963                                         tdata->cipher_iv.len);
2964         if (retval < 0)
2965                 return retval;
2966
2967         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2968         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2969
2970         /* Clear mbuf payload */
2971         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2972                rte_pktmbuf_tailroom(ut_params->ibuf));
2973
2974         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2975         /* Append data which is padded to a multiple */
2976         /* of the algorithms block size */
2977         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2978         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2979                                 plaintext_pad_len);
2980         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2981         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2982
2983         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
2984
2985         /* Create KASUMI operation */
2986         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
2987                                 tdata->cipher_iv.len,
2988                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
2989                                 tdata->validCipherOffsetInBits.len);
2990         if (retval < 0)
2991                 return retval;
2992
2993         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2994                                                 ut_params->op);
2995         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2996
2997         ut_params->obuf = ut_params->op->sym->m_dst;
2998         if (ut_params->obuf)
2999                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3000         else
3001                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3002
3003         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3004
3005         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3006                                 (tdata->validCipherOffsetInBits.len >> 3);
3007         /* Validate obuf */
3008         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3009                 ciphertext,
3010                 reference_ciphertext,
3011                 tdata->validCipherLenInBits.len,
3012                 "KASUMI Ciphertext data not as expected");
3013         return 0;
3014 }
3015
3016 static int
3017 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3018 {
3019         struct crypto_testsuite_params *ts_params = &testsuite_params;
3020         struct crypto_unittest_params *ut_params = &unittest_params;
3021
3022         int retval;
3023         unsigned int plaintext_pad_len;
3024         unsigned int plaintext_len;
3025
3026         const uint8_t *ciphertext;
3027         uint8_t buffer[2048];
3028
3029         struct rte_cryptodev_info dev_info;
3030
3031         /* Verify the capabilities */
3032         struct rte_cryptodev_sym_capability_idx cap_idx;
3033         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3034         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3035         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3036                         &cap_idx) == NULL)
3037                 return -ENOTSUP;
3038
3039         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3040
3041         uint64_t feat_flags = dev_info.feature_flags;
3042         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3043                 printf("Device doesn't support out-of-place scatter-gather "
3044                                 "in both input and output mbufs. "
3045                                 "Test Skipped.\n");
3046                 return -ENOTSUP;
3047         }
3048
3049         /* Create KASUMI session */
3050         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3051                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3052                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3053                                         tdata->key.data, tdata->key.len,
3054                                         tdata->cipher_iv.len);
3055         if (retval < 0)
3056                 return retval;
3057
3058         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3059         /* Append data which is padded to a multiple */
3060         /* of the algorithms block size */
3061         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3062
3063         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3064                         plaintext_pad_len, 10, 0);
3065         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3066                         plaintext_pad_len, 3, 0);
3067
3068         /* Append data which is padded to a multiple */
3069         /* of the algorithms block size */
3070         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3071
3072         /* Create KASUMI operation */
3073         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3074                                 tdata->cipher_iv.len,
3075                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3076                                 tdata->validCipherOffsetInBits.len);
3077         if (retval < 0)
3078                 return retval;
3079
3080         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3081                                                 ut_params->op);
3082         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3083
3084         ut_params->obuf = ut_params->op->sym->m_dst;
3085         if (ut_params->obuf)
3086                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3087                                 plaintext_pad_len, buffer);
3088         else
3089                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3090                                 tdata->validCipherOffsetInBits.len >> 3,
3091                                 plaintext_pad_len, buffer);
3092
3093         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3094                                 (tdata->validCipherOffsetInBits.len >> 3);
3095         /* Validate obuf */
3096         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3097                 ciphertext,
3098                 reference_ciphertext,
3099                 tdata->validCipherLenInBits.len,
3100                 "KASUMI Ciphertext data not as expected");
3101         return 0;
3102 }
3103
3104
3105 static int
3106 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3107 {
3108         struct crypto_testsuite_params *ts_params = &testsuite_params;
3109         struct crypto_unittest_params *ut_params = &unittest_params;
3110
3111         int retval;
3112         uint8_t *ciphertext, *plaintext;
3113         unsigned ciphertext_pad_len;
3114         unsigned ciphertext_len;
3115
3116         /* Verify the capabilities */
3117         struct rte_cryptodev_sym_capability_idx cap_idx;
3118         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3119         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3120         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3121                         &cap_idx) == NULL)
3122                 return -ENOTSUP;
3123
3124         /* Create KASUMI session */
3125         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3126                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3127                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3128                                         tdata->key.data, tdata->key.len,
3129                                         tdata->cipher_iv.len);
3130         if (retval < 0)
3131                 return retval;
3132
3133         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3134         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3135
3136         /* Clear mbuf payload */
3137         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3138                rte_pktmbuf_tailroom(ut_params->ibuf));
3139
3140         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3141         /* Append data which is padded to a multiple */
3142         /* of the algorithms block size */
3143         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3144         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3145                                 ciphertext_pad_len);
3146         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3147         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3148
3149         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3150
3151         /* Create KASUMI operation */
3152         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3153                                 tdata->cipher_iv.len,
3154                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3155                                 tdata->validCipherOffsetInBits.len);
3156         if (retval < 0)
3157                 return retval;
3158
3159         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3160                                                 ut_params->op);
3161         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3162
3163         ut_params->obuf = ut_params->op->sym->m_dst;
3164         if (ut_params->obuf)
3165                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3166         else
3167                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3168
3169         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3170
3171         const uint8_t *reference_plaintext = tdata->plaintext.data +
3172                                 (tdata->validCipherOffsetInBits.len >> 3);
3173         /* Validate obuf */
3174         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3175                 plaintext,
3176                 reference_plaintext,
3177                 tdata->validCipherLenInBits.len,
3178                 "KASUMI Plaintext data not as expected");
3179         return 0;
3180 }
3181
3182 static int
3183 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3184 {
3185         struct crypto_testsuite_params *ts_params = &testsuite_params;
3186         struct crypto_unittest_params *ut_params = &unittest_params;
3187
3188         int retval;
3189         uint8_t *ciphertext, *plaintext;
3190         unsigned ciphertext_pad_len;
3191         unsigned ciphertext_len;
3192
3193         /* Verify the capabilities */
3194         struct rte_cryptodev_sym_capability_idx cap_idx;
3195         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3196         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3197         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3198                         &cap_idx) == NULL)
3199                 return -ENOTSUP;
3200
3201         /* Create KASUMI session */
3202         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3203                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3204                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3205                                         tdata->key.data, tdata->key.len,
3206                                         tdata->cipher_iv.len);
3207         if (retval < 0)
3208                 return retval;
3209
3210         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3211
3212         /* Clear mbuf payload */
3213         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3214                rte_pktmbuf_tailroom(ut_params->ibuf));
3215
3216         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3217         /* Append data which is padded to a multiple */
3218         /* of the algorithms block size */
3219         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3220         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3221                                 ciphertext_pad_len);
3222         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3223
3224         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3225
3226         /* Create KASUMI operation */
3227         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3228                                         tdata->cipher_iv.len,
3229                                         tdata->ciphertext.len,
3230                                         tdata->validCipherOffsetInBits.len);
3231         if (retval < 0)
3232                 return retval;
3233
3234         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3235                                                 ut_params->op);
3236         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3237
3238         ut_params->obuf = ut_params->op->sym->m_dst;
3239         if (ut_params->obuf)
3240                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3241         else
3242                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3243
3244         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3245
3246         const uint8_t *reference_plaintext = tdata->plaintext.data +
3247                                 (tdata->validCipherOffsetInBits.len >> 3);
3248         /* Validate obuf */
3249         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3250                 plaintext,
3251                 reference_plaintext,
3252                 tdata->validCipherLenInBits.len,
3253                 "KASUMI Plaintext data not as expected");
3254         return 0;
3255 }
3256
3257 static int
3258 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3259 {
3260         struct crypto_testsuite_params *ts_params = &testsuite_params;
3261         struct crypto_unittest_params *ut_params = &unittest_params;
3262
3263         int retval;
3264         uint8_t *plaintext, *ciphertext;
3265         unsigned plaintext_pad_len;
3266         unsigned plaintext_len;
3267
3268         /* Verify the capabilities */
3269         struct rte_cryptodev_sym_capability_idx cap_idx;
3270         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3271         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3272         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3273                         &cap_idx) == NULL)
3274                 return -ENOTSUP;
3275
3276         /* Create SNOW 3G session */
3277         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3278                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3279                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3280                                         tdata->key.data, tdata->key.len,
3281                                         tdata->cipher_iv.len);
3282         if (retval < 0)
3283                 return retval;
3284
3285         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3286
3287         /* Clear mbuf payload */
3288         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3289                rte_pktmbuf_tailroom(ut_params->ibuf));
3290
3291         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3292         /* Append data which is padded to a multiple of */
3293         /* the algorithms block size */
3294         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3295         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3296                                 plaintext_pad_len);
3297         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3298
3299         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3300
3301         /* Create SNOW 3G operation */
3302         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3303                                         tdata->cipher_iv.len,
3304                                         tdata->validCipherLenInBits.len,
3305                                         0);
3306         if (retval < 0)
3307                 return retval;
3308
3309         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3310                                                 ut_params->op);
3311         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3312
3313         ut_params->obuf = ut_params->op->sym->m_dst;
3314         if (ut_params->obuf)
3315                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3316         else
3317                 ciphertext = plaintext;
3318
3319         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3320
3321         /* Validate obuf */
3322         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3323                 ciphertext,
3324                 tdata->ciphertext.data,
3325                 tdata->validDataLenInBits.len,
3326                 "SNOW 3G Ciphertext data not as expected");
3327         return 0;
3328 }
3329
3330
3331 static int
3332 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3333 {
3334         struct crypto_testsuite_params *ts_params = &testsuite_params;
3335         struct crypto_unittest_params *ut_params = &unittest_params;
3336         uint8_t *plaintext, *ciphertext;
3337
3338         int retval;
3339         unsigned plaintext_pad_len;
3340         unsigned plaintext_len;
3341
3342         /* Verify the capabilities */
3343         struct rte_cryptodev_sym_capability_idx cap_idx;
3344         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3345         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3346         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3347                         &cap_idx) == NULL)
3348                 return -ENOTSUP;
3349
3350         /* Create SNOW 3G session */
3351         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3352                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3353                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3354                                         tdata->key.data, tdata->key.len,
3355                                         tdata->cipher_iv.len);
3356         if (retval < 0)
3357                 return retval;
3358
3359         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3360         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3361
3362         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3363                         "Failed to allocate input buffer in mempool");
3364         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3365                         "Failed to allocate output buffer in mempool");
3366
3367         /* Clear mbuf payload */
3368         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3369                rte_pktmbuf_tailroom(ut_params->ibuf));
3370
3371         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3372         /* Append data which is padded to a multiple of */
3373         /* the algorithms block size */
3374         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3375         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3376                                 plaintext_pad_len);
3377         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3378         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3379
3380         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3381
3382         /* Create SNOW 3G operation */
3383         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3384                                         tdata->cipher_iv.len,
3385                                         tdata->validCipherLenInBits.len,
3386                                         0);
3387         if (retval < 0)
3388                 return retval;
3389
3390         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3391                                                 ut_params->op);
3392         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3393
3394         ut_params->obuf = ut_params->op->sym->m_dst;
3395         if (ut_params->obuf)
3396                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3397         else
3398                 ciphertext = plaintext;
3399
3400         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3401
3402         /* Validate obuf */
3403         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3404                 ciphertext,
3405                 tdata->ciphertext.data,
3406                 tdata->validDataLenInBits.len,
3407                 "SNOW 3G Ciphertext data not as expected");
3408         return 0;
3409 }
3410
3411 static int
3412 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3413 {
3414         struct crypto_testsuite_params *ts_params = &testsuite_params;
3415         struct crypto_unittest_params *ut_params = &unittest_params;
3416
3417         int retval;
3418         unsigned int plaintext_pad_len;
3419         unsigned int plaintext_len;
3420         uint8_t buffer[10000];
3421         const uint8_t *ciphertext;
3422
3423         struct rte_cryptodev_info dev_info;
3424
3425         /* Verify the capabilities */
3426         struct rte_cryptodev_sym_capability_idx cap_idx;
3427         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3428         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3429         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3430                         &cap_idx) == NULL)
3431                 return -ENOTSUP;
3432
3433         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3434
3435         uint64_t feat_flags = dev_info.feature_flags;
3436
3437         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3438                 printf("Device doesn't support out-of-place scatter-gather "
3439                                 "in both input and output mbufs. "
3440                                 "Test Skipped.\n");
3441                 return -ENOTSUP;
3442         }
3443
3444         /* Create SNOW 3G session */
3445         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3446                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3447                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3448                                         tdata->key.data, tdata->key.len,
3449                                         tdata->cipher_iv.len);
3450         if (retval < 0)
3451                 return retval;
3452
3453         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3454         /* Append data which is padded to a multiple of */
3455         /* the algorithms block size */
3456         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3457
3458         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3459                         plaintext_pad_len, 10, 0);
3460         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3461                         plaintext_pad_len, 3, 0);
3462
3463         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3464                         "Failed to allocate input buffer in mempool");
3465         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3466                         "Failed to allocate output buffer in mempool");
3467
3468         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3469
3470         /* Create SNOW 3G operation */
3471         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3472                                         tdata->cipher_iv.len,
3473                                         tdata->validCipherLenInBits.len,
3474                                         0);
3475         if (retval < 0)
3476                 return retval;
3477
3478         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3479                                                 ut_params->op);
3480         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3481
3482         ut_params->obuf = ut_params->op->sym->m_dst;
3483         if (ut_params->obuf)
3484                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3485                                 plaintext_len, buffer);
3486         else
3487                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3488                                 plaintext_len, buffer);
3489
3490         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3491
3492         /* Validate obuf */
3493         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3494                 ciphertext,
3495                 tdata->ciphertext.data,
3496                 tdata->validDataLenInBits.len,
3497                 "SNOW 3G Ciphertext data not as expected");
3498
3499         return 0;
3500 }
3501
3502 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3503 static void
3504 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3505 {
3506         uint8_t curr_byte, prev_byte;
3507         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3508         uint8_t lower_byte_mask = (1 << offset) - 1;
3509         unsigned i;
3510
3511         prev_byte = buffer[0];
3512         buffer[0] >>= offset;
3513
3514         for (i = 1; i < length_in_bytes; i++) {
3515                 curr_byte = buffer[i];
3516                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3517                                 (curr_byte >> offset);
3518                 prev_byte = curr_byte;
3519         }
3520 }
3521
3522 static int
3523 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3524 {
3525         struct crypto_testsuite_params *ts_params = &testsuite_params;
3526         struct crypto_unittest_params *ut_params = &unittest_params;
3527         uint8_t *plaintext, *ciphertext;
3528         int retval;
3529         uint32_t plaintext_len;
3530         uint32_t plaintext_pad_len;
3531         uint8_t extra_offset = 4;
3532         uint8_t *expected_ciphertext_shifted;
3533
3534         /* QAT PMD supports byte-aligned data only */
3535         if (gbl_driver_id == rte_cryptodev_driver_id_get(
3536                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)))
3537                 return -ENOTSUP;
3538
3539         /* Verify the capabilities */
3540         struct rte_cryptodev_sym_capability_idx cap_idx;
3541         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3542         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3543         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3544                         &cap_idx) == NULL)
3545                 return -ENOTSUP;
3546
3547         /* Create SNOW 3G session */
3548         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3549                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3550                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3551                                         tdata->key.data, tdata->key.len,
3552                                         tdata->cipher_iv.len);
3553         if (retval < 0)
3554                 return retval;
3555
3556         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3557         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3558
3559         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3560                         "Failed to allocate input buffer in mempool");
3561         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3562                         "Failed to allocate output buffer in mempool");
3563
3564         /* Clear mbuf payload */
3565         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3566                rte_pktmbuf_tailroom(ut_params->ibuf));
3567
3568         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3569         /*
3570          * Append data which is padded to a
3571          * multiple of the algorithms block size
3572          */
3573         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3574
3575         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3576                                                 plaintext_pad_len);
3577
3578         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3579
3580         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3581         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3582
3583 #ifdef RTE_APP_TEST_DEBUG
3584         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3585 #endif
3586         /* Create SNOW 3G operation */
3587         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3588                                         tdata->cipher_iv.len,
3589                                         tdata->validCipherLenInBits.len,
3590                                         extra_offset);
3591         if (retval < 0)
3592                 return retval;
3593
3594         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3595                                                 ut_params->op);
3596         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3597
3598         ut_params->obuf = ut_params->op->sym->m_dst;
3599         if (ut_params->obuf)
3600                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3601         else
3602                 ciphertext = plaintext;
3603
3604 #ifdef RTE_APP_TEST_DEBUG
3605         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3606 #endif
3607
3608         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
3609
3610         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3611                         "failed to reserve memory for ciphertext shifted\n");
3612
3613         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3614                         ceil_byte_length(tdata->ciphertext.len));
3615         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3616                         extra_offset);
3617         /* Validate obuf */
3618         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3619                 ciphertext,
3620                 expected_ciphertext_shifted,
3621                 tdata->validDataLenInBits.len,
3622                 extra_offset,
3623                 "SNOW 3G Ciphertext data not as expected");
3624         return 0;
3625 }
3626
3627 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3628 {
3629         struct crypto_testsuite_params *ts_params = &testsuite_params;
3630         struct crypto_unittest_params *ut_params = &unittest_params;
3631
3632         int retval;
3633
3634         uint8_t *plaintext, *ciphertext;
3635         unsigned ciphertext_pad_len;
3636         unsigned ciphertext_len;
3637
3638         /* Verify the capabilities */
3639         struct rte_cryptodev_sym_capability_idx cap_idx;
3640         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3641         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3642         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3643                         &cap_idx) == NULL)
3644                 return -ENOTSUP;
3645
3646         /* Create SNOW 3G session */
3647         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3648                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3649                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3650                                         tdata->key.data, tdata->key.len,
3651                                         tdata->cipher_iv.len);
3652         if (retval < 0)
3653                 return retval;
3654
3655         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3656
3657         /* Clear mbuf payload */
3658         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3659                rte_pktmbuf_tailroom(ut_params->ibuf));
3660
3661         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3662         /* Append data which is padded to a multiple of */
3663         /* the algorithms block size */
3664         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3665         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3666                                 ciphertext_pad_len);
3667         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3668
3669         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3670
3671         /* Create SNOW 3G operation */
3672         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3673                                         tdata->cipher_iv.len,
3674                                         tdata->validCipherLenInBits.len,
3675                                         tdata->cipher.offset_bits);
3676         if (retval < 0)
3677                 return retval;
3678
3679         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3680                                                 ut_params->op);
3681         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3682         ut_params->obuf = ut_params->op->sym->m_dst;
3683         if (ut_params->obuf)
3684                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3685         else
3686                 plaintext = ciphertext;
3687
3688         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3689
3690         /* Validate obuf */
3691         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3692                                 tdata->plaintext.data,
3693                                 tdata->validDataLenInBits.len,
3694                                 "SNOW 3G Plaintext data not as expected");
3695         return 0;
3696 }
3697
3698 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3699 {
3700         struct crypto_testsuite_params *ts_params = &testsuite_params;
3701         struct crypto_unittest_params *ut_params = &unittest_params;
3702
3703         int retval;
3704
3705         uint8_t *plaintext, *ciphertext;
3706         unsigned ciphertext_pad_len;
3707         unsigned ciphertext_len;
3708
3709         /* Verify the capabilities */
3710         struct rte_cryptodev_sym_capability_idx cap_idx;
3711         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3712         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3713         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3714                         &cap_idx) == NULL)
3715                 return -ENOTSUP;
3716
3717         /* Create SNOW 3G session */
3718         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3719                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3720                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3721                                         tdata->key.data, tdata->key.len,
3722                                         tdata->cipher_iv.len);
3723         if (retval < 0)
3724                 return retval;
3725
3726         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3727         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3728
3729         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3730                         "Failed to allocate input buffer");
3731         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3732                         "Failed to allocate output buffer");
3733
3734         /* Clear mbuf payload */
3735         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3736                rte_pktmbuf_tailroom(ut_params->ibuf));
3737
3738         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3739                        rte_pktmbuf_tailroom(ut_params->obuf));
3740
3741         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3742         /* Append data which is padded to a multiple of */
3743         /* the algorithms block size */
3744         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3745         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3746                                 ciphertext_pad_len);
3747         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3748         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3749
3750         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3751
3752         /* Create SNOW 3G operation */
3753         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3754                                         tdata->cipher_iv.len,
3755                                         tdata->validCipherLenInBits.len,
3756                                         0);
3757         if (retval < 0)
3758                 return retval;
3759
3760         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3761                                                 ut_params->op);
3762         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3763         ut_params->obuf = ut_params->op->sym->m_dst;
3764         if (ut_params->obuf)
3765                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3766         else
3767                 plaintext = ciphertext;
3768
3769         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3770
3771         /* Validate obuf */
3772         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3773                                 tdata->plaintext.data,
3774                                 tdata->validDataLenInBits.len,
3775                                 "SNOW 3G Plaintext data not as expected");
3776         return 0;
3777 }
3778
3779 static int
3780 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
3781 {
3782         struct crypto_testsuite_params *ts_params = &testsuite_params;
3783         struct crypto_unittest_params *ut_params = &unittest_params;
3784
3785         int retval;
3786
3787         uint8_t *plaintext, *ciphertext;
3788         unsigned int plaintext_pad_len;
3789         unsigned int plaintext_len;
3790
3791         struct rte_cryptodev_sym_capability_idx cap_idx;
3792
3793         /* Check if device supports ZUC EEA3 */
3794         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3795         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
3796
3797         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3798                         &cap_idx) == NULL)
3799                 return -ENOTSUP;
3800
3801         /* Check if device supports ZUC EIA3 */
3802         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3803         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
3804
3805         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3806                         &cap_idx) == NULL)
3807                 return -ENOTSUP;
3808
3809         /* Create ZUC session */
3810         retval = create_zuc_cipher_auth_encrypt_generate_session(
3811                         ts_params->valid_devs[0],
3812                         tdata);
3813         if (retval < 0)
3814                 return retval;
3815         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3816
3817         /* clear mbuf payload */
3818         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3819                         rte_pktmbuf_tailroom(ut_params->ibuf));
3820
3821         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3822         /* Append data which is padded to a multiple of */
3823         /* the algorithms block size */
3824         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3825         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3826                                 plaintext_pad_len);
3827         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3828
3829         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3830
3831         /* Create ZUC operation */
3832         retval = create_zuc_cipher_hash_generate_operation(tdata);
3833         if (retval < 0)
3834                 return retval;
3835
3836         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3837                         ut_params->op);
3838         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3839         ut_params->obuf = ut_params->op->sym->m_src;
3840         if (ut_params->obuf)
3841                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3842         else
3843                 ciphertext = plaintext;
3844
3845         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3846         /* Validate obuf */
3847         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3848                         ciphertext,
3849                         tdata->ciphertext.data,
3850                         tdata->validDataLenInBits.len,
3851                         "ZUC Ciphertext data not as expected");
3852
3853         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3854             + plaintext_pad_len;
3855
3856         /* Validate obuf */
3857         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3858                         ut_params->digest,
3859                         tdata->digest.data,
3860                         4,
3861                         "ZUC Generated auth tag not as expected");
3862         return 0;
3863 }
3864
3865 static int
3866 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3867 {
3868         struct crypto_testsuite_params *ts_params = &testsuite_params;
3869         struct crypto_unittest_params *ut_params = &unittest_params;
3870
3871         int retval;
3872
3873         uint8_t *plaintext, *ciphertext;
3874         unsigned plaintext_pad_len;
3875         unsigned plaintext_len;
3876
3877         /* Verify the capabilities */
3878         struct rte_cryptodev_sym_capability_idx cap_idx;
3879         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3880         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3881         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3882                         &cap_idx) == NULL)
3883                 return -ENOTSUP;
3884         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3885         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3886         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3887                         &cap_idx) == NULL)
3888                 return -ENOTSUP;
3889
3890         /* Create SNOW 3G session */
3891         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3892                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3893                         RTE_CRYPTO_AUTH_OP_GENERATE,
3894                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3895                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3896                         tdata->key.data, tdata->key.len,
3897                         tdata->auth_iv.len, tdata->digest.len,
3898                         tdata->cipher_iv.len);
3899         if (retval < 0)
3900                 return retval;
3901         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3902
3903         /* clear mbuf payload */
3904         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3905                         rte_pktmbuf_tailroom(ut_params->ibuf));
3906
3907         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3908         /* Append data which is padded to a multiple of */
3909         /* the algorithms block size */
3910         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3911         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3912                                 plaintext_pad_len);
3913         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3914
3915         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3916
3917         /* Create SNOW 3G operation */
3918         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3919                         tdata->digest.len, tdata->auth_iv.data,
3920                         tdata->auth_iv.len,
3921                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3922                         tdata->cipher_iv.data, tdata->cipher_iv.len,
3923                         tdata->validCipherLenInBits.len,
3924                         0,
3925                         tdata->validAuthLenInBits.len,
3926                         0
3927                         );
3928         if (retval < 0)
3929                 return retval;
3930
3931         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3932                         ut_params->op);
3933         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3934         ut_params->obuf = ut_params->op->sym->m_src;
3935         if (ut_params->obuf)
3936                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3937         else
3938                 ciphertext = plaintext;
3939
3940         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3941         /* Validate obuf */
3942         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3943                         ciphertext,
3944                         tdata->ciphertext.data,
3945                         tdata->validDataLenInBits.len,
3946                         "SNOW 3G Ciphertext data not as expected");
3947
3948         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3949             + plaintext_pad_len;
3950
3951         /* Validate obuf */
3952         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3953                         ut_params->digest,
3954                         tdata->digest.data,
3955                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3956                         "SNOW 3G Generated auth tag not as expected");
3957         return 0;
3958 }
3959
3960 static int
3961 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
3962         uint8_t op_mode, uint8_t verify)
3963 {
3964         struct crypto_testsuite_params *ts_params = &testsuite_params;
3965         struct crypto_unittest_params *ut_params = &unittest_params;
3966
3967         int retval;
3968
3969         uint8_t *plaintext = NULL, *ciphertext = NULL;
3970         unsigned int plaintext_pad_len;
3971         unsigned int plaintext_len;
3972         unsigned int ciphertext_pad_len;
3973         unsigned int ciphertext_len;
3974
3975         struct rte_cryptodev_info dev_info;
3976
3977         /* Verify the capabilities */
3978         struct rte_cryptodev_sym_capability_idx cap_idx;
3979         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3980         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3981         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3982                         &cap_idx) == NULL)
3983                 return -ENOTSUP;
3984         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3985         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3986         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3987                         &cap_idx) == NULL)
3988                 return -ENOTSUP;
3989
3990         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3991
3992         uint64_t feat_flags = dev_info.feature_flags;
3993
3994         if (op_mode == OUT_OF_PLACE) {
3995                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
3996                         printf("Device doesn't support digest encrypted.\n");
3997                         return -ENOTSUP;
3998                 }
3999         }
4000
4001         /* Create SNOW 3G session */
4002         retval = create_wireless_algo_auth_cipher_session(
4003                         ts_params->valid_devs[0],
4004                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4005                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4006                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4007                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4008                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4009                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4010                         tdata->key.data, tdata->key.len,
4011                         tdata->auth_iv.len, tdata->digest.len,
4012                         tdata->cipher_iv.len);
4013
4014         if (retval < 0)
4015                 return retval;
4016
4017         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4018         if (op_mode == OUT_OF_PLACE)
4019                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4020
4021         /* clear mbuf payload */
4022         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4023                 rte_pktmbuf_tailroom(ut_params->ibuf));
4024         if (op_mode == OUT_OF_PLACE)
4025                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4026                         rte_pktmbuf_tailroom(ut_params->obuf));
4027
4028         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4029         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4030         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4031         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4032
4033         if (verify) {
4034                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4035                                         ciphertext_pad_len);
4036                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4037                 if (op_mode == OUT_OF_PLACE)
4038                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4039                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4040                         ciphertext_len);
4041         } else {
4042                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4043                                         plaintext_pad_len);
4044                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4045                 if (op_mode == OUT_OF_PLACE)
4046                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4047                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4048         }
4049
4050         /* Create SNOW 3G operation */
4051         retval = create_wireless_algo_auth_cipher_operation(
4052                 tdata->digest.data, tdata->digest.len,
4053                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4054                 tdata->auth_iv.data, tdata->auth_iv.len,
4055                 (tdata->digest.offset_bytes == 0 ?
4056                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4057                         : tdata->digest.offset_bytes),
4058                 tdata->validCipherLenInBits.len,
4059                 tdata->cipher.offset_bits,
4060                 tdata->validAuthLenInBits.len,
4061                 tdata->auth.offset_bits,
4062                 op_mode, 0, verify);
4063
4064         if (retval < 0)
4065                 return retval;
4066
4067         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4068                         ut_params->op);
4069
4070         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4071
4072         ut_params->obuf = (op_mode == IN_PLACE ?
4073                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4074
4075         if (verify) {
4076                 if (ut_params->obuf)
4077                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4078                                                         uint8_t *);
4079                 else
4080                         plaintext = ciphertext +
4081                                 (tdata->cipher.offset_bits >> 3);
4082
4083                 debug_hexdump(stdout, "plaintext:", plaintext,
4084                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4085                 debug_hexdump(stdout, "plaintext expected:",
4086                         tdata->plaintext.data,
4087                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4088         } else {
4089                 if (ut_params->obuf)
4090                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4091                                                         uint8_t *);
4092                 else
4093                         ciphertext = plaintext;
4094
4095                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4096                         ciphertext_len);
4097                 debug_hexdump(stdout, "ciphertext expected:",
4098                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4099
4100                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4101                         + (tdata->digest.offset_bytes == 0 ?
4102                 plaintext_pad_len : tdata->digest.offset_bytes);
4103
4104                 debug_hexdump(stdout, "digest:", ut_params->digest,
4105                         tdata->digest.len);
4106                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4107                                 tdata->digest.len);
4108         }
4109
4110         /* Validate obuf */
4111         if (verify) {
4112                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4113                         plaintext,
4114                         tdata->plaintext.data,
4115                         tdata->plaintext.len >> 3,
4116                         "SNOW 3G Plaintext data not as expected");
4117         } else {
4118                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4119                         ciphertext,
4120                         tdata->ciphertext.data,
4121                         tdata->validDataLenInBits.len,
4122                         "SNOW 3G Ciphertext data not as expected");
4123
4124                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4125                         ut_params->digest,
4126                         tdata->digest.data,
4127                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4128                         "SNOW 3G Generated auth tag not as expected");
4129         }
4130         return 0;
4131 }
4132
4133 static int
4134 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4135         uint8_t op_mode, uint8_t verify)
4136 {
4137         struct crypto_testsuite_params *ts_params = &testsuite_params;
4138         struct crypto_unittest_params *ut_params = &unittest_params;
4139
4140         int retval;
4141
4142         const uint8_t *plaintext = NULL;
4143         const uint8_t *ciphertext = NULL;
4144         const uint8_t *digest = NULL;
4145         unsigned int plaintext_pad_len;
4146         unsigned int plaintext_len;
4147         unsigned int ciphertext_pad_len;
4148         unsigned int ciphertext_len;
4149         uint8_t buffer[10000];
4150         uint8_t digest_buffer[10000];
4151
4152         struct rte_cryptodev_info dev_info;
4153
4154         /* Verify the capabilities */
4155         struct rte_cryptodev_sym_capability_idx cap_idx;
4156         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4157         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4158         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4159                         &cap_idx) == NULL)
4160                 return -ENOTSUP;
4161         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4162         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4163         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4164                         &cap_idx) == NULL)
4165                 return -ENOTSUP;
4166
4167         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4168
4169         uint64_t feat_flags = dev_info.feature_flags;
4170
4171         if (op_mode == IN_PLACE) {
4172                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4173                         printf("Device doesn't support in-place scatter-gather "
4174                                         "in both input and output mbufs.\n");
4175                         return -ENOTSUP;
4176                 }
4177         } else {
4178                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4179                         printf("Device doesn't support out-of-place scatter-gather "
4180                                         "in both input and output mbufs.\n");
4181                         return -ENOTSUP;
4182                 }
4183                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4184                         printf("Device doesn't support digest encrypted.\n");
4185                         return -ENOTSUP;
4186                 }
4187         }
4188
4189         /* Create SNOW 3G session */
4190         retval = create_wireless_algo_auth_cipher_session(
4191                         ts_params->valid_devs[0],
4192                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4193                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4194                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4195                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4196                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4197                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4198                         tdata->key.data, tdata->key.len,
4199                         tdata->auth_iv.len, tdata->digest.len,
4200                         tdata->cipher_iv.len);
4201
4202         if (retval < 0)
4203                 return retval;
4204
4205         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4206         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4207         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4208         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4209
4210         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4211                         plaintext_pad_len, 15, 0);
4212         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4213                         "Failed to allocate input buffer in mempool");
4214
4215         if (op_mode == OUT_OF_PLACE) {
4216                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4217                                 plaintext_pad_len, 15, 0);
4218                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4219                                 "Failed to allocate output buffer in mempool");
4220         }
4221
4222         if (verify) {
4223                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4224                         tdata->ciphertext.data);
4225                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4226                                         ciphertext_len, buffer);
4227                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4228                         ciphertext_len);
4229         } else {
4230                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4231                         tdata->plaintext.data);
4232                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4233                                         plaintext_len, buffer);
4234                 debug_hexdump(stdout, "plaintext:", plaintext,
4235                         plaintext_len);
4236         }
4237         memset(buffer, 0, sizeof(buffer));
4238
4239         /* Create SNOW 3G operation */
4240         retval = create_wireless_algo_auth_cipher_operation(
4241                 tdata->digest.data, tdata->digest.len,
4242                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4243                 tdata->auth_iv.data, tdata->auth_iv.len,
4244                 (tdata->digest.offset_bytes == 0 ?
4245                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4246                         : tdata->digest.offset_bytes),
4247                 tdata->validCipherLenInBits.len,
4248                 tdata->cipher.offset_bits,
4249                 tdata->validAuthLenInBits.len,
4250                 tdata->auth.offset_bits,
4251                 op_mode, 1, verify);
4252
4253         if (retval < 0)
4254                 return retval;
4255
4256         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4257                         ut_params->op);
4258
4259         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4260
4261         ut_params->obuf = (op_mode == IN_PLACE ?
4262                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4263
4264         if (verify) {
4265                 if (ut_params->obuf)
4266                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4267                                         plaintext_len, buffer);
4268                 else
4269                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4270                                         plaintext_len, buffer);
4271
4272                 debug_hexdump(stdout, "plaintext:", plaintext,
4273                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4274                 debug_hexdump(stdout, "plaintext expected:",
4275                         tdata->plaintext.data,
4276                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4277         } else {
4278                 if (ut_params->obuf)
4279                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4280                                         ciphertext_len, buffer);
4281                 else
4282                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4283                                         ciphertext_len, buffer);
4284
4285                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4286                         ciphertext_len);
4287                 debug_hexdump(stdout, "ciphertext expected:",
4288                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4289
4290                 if (ut_params->obuf)
4291                         digest = rte_pktmbuf_read(ut_params->obuf,
4292                                 (tdata->digest.offset_bytes == 0 ?
4293                                 plaintext_pad_len : tdata->digest.offset_bytes),
4294                                 tdata->digest.len, digest_buffer);
4295                 else
4296                         digest = rte_pktmbuf_read(ut_params->ibuf,
4297                                 (tdata->digest.offset_bytes == 0 ?
4298                                 plaintext_pad_len : tdata->digest.offset_bytes),
4299                                 tdata->digest.len, digest_buffer);
4300
4301                 debug_hexdump(stdout, "digest:", digest,
4302                         tdata->digest.len);
4303                 debug_hexdump(stdout, "digest expected:",
4304                         tdata->digest.data, tdata->digest.len);
4305         }
4306
4307         /* Validate obuf */
4308         if (verify) {
4309                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4310                         plaintext,
4311                         tdata->plaintext.data,
4312                         tdata->plaintext.len >> 3,
4313                         "SNOW 3G Plaintext data not as expected");
4314         } else {
4315                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4316                         ciphertext,
4317                         tdata->ciphertext.data,
4318                         tdata->validDataLenInBits.len,
4319                         "SNOW 3G Ciphertext data not as expected");
4320
4321                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4322                         digest,
4323                         tdata->digest.data,
4324                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4325                         "SNOW 3G Generated auth tag not as expected");
4326         }
4327         return 0;
4328 }
4329
4330 static int
4331 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4332         uint8_t op_mode, uint8_t verify)
4333 {
4334         struct crypto_testsuite_params *ts_params = &testsuite_params;
4335         struct crypto_unittest_params *ut_params = &unittest_params;
4336
4337         int retval;
4338
4339         uint8_t *plaintext = NULL, *ciphertext = NULL;
4340         unsigned int plaintext_pad_len;
4341         unsigned int plaintext_len;
4342         unsigned int ciphertext_pad_len;
4343         unsigned int ciphertext_len;
4344
4345         struct rte_cryptodev_info dev_info;
4346
4347         /* Verify the capabilities */
4348         struct rte_cryptodev_sym_capability_idx cap_idx;
4349         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4350         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4351         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4352                         &cap_idx) == NULL)
4353                 return -ENOTSUP;
4354         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4355         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4356         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4357                         &cap_idx) == NULL)
4358                 return -ENOTSUP;
4359
4360         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4361
4362         uint64_t feat_flags = dev_info.feature_flags;
4363
4364         if (op_mode == OUT_OF_PLACE) {
4365                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4366                         printf("Device doesn't support digest encrypted.\n");
4367                         return -ENOTSUP;
4368                 }
4369         }
4370
4371         /* Create KASUMI session */
4372         retval = create_wireless_algo_auth_cipher_session(
4373                         ts_params->valid_devs[0],
4374                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4375                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4376                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4377                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4378                         RTE_CRYPTO_AUTH_KASUMI_F9,
4379                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4380                         tdata->key.data, tdata->key.len,
4381                         0, tdata->digest.len,
4382                         tdata->cipher_iv.len);
4383
4384         if (retval < 0)
4385                 return retval;
4386
4387         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4388         if (op_mode == OUT_OF_PLACE)
4389                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4390
4391         /* clear mbuf payload */
4392         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4393                 rte_pktmbuf_tailroom(ut_params->ibuf));
4394         if (op_mode == OUT_OF_PLACE)
4395                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4396                         rte_pktmbuf_tailroom(ut_params->obuf));
4397
4398         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4399         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4400         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4401         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4402
4403         if (verify) {
4404                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4405                                         ciphertext_pad_len);
4406                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4407                 if (op_mode == OUT_OF_PLACE)
4408                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4409                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4410                         ciphertext_len);
4411         } else {
4412                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4413                                         plaintext_pad_len);
4414                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4415                 if (op_mode == OUT_OF_PLACE)
4416                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4417                 debug_hexdump(stdout, "plaintext:", plaintext,
4418                         plaintext_len);
4419         }
4420
4421         /* Create KASUMI operation */
4422         retval = create_wireless_algo_auth_cipher_operation(
4423                 tdata->digest.data, tdata->digest.len,
4424                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4425                 NULL, 0,
4426                 (tdata->digest.offset_bytes == 0 ?
4427                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4428                         : tdata->digest.offset_bytes),
4429                 tdata->validCipherLenInBits.len,
4430                 tdata->validCipherOffsetInBits.len,
4431                 tdata->validAuthLenInBits.len,
4432                 0,
4433                 op_mode, 0, verify);
4434
4435         if (retval < 0)
4436                 return retval;
4437
4438         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4439                         ut_params->op);
4440
4441         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4442
4443         ut_params->obuf = (op_mode == IN_PLACE ?
4444                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4445
4446
4447         if (verify) {
4448                 if (ut_params->obuf)
4449                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4450                                                         uint8_t *);
4451                 else
4452                         plaintext = ciphertext;
4453
4454                 debug_hexdump(stdout, "plaintext:", plaintext,
4455                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4456                 debug_hexdump(stdout, "plaintext expected:",
4457                         tdata->plaintext.data,
4458                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4459         } else {
4460                 if (ut_params->obuf)
4461                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4462                                                         uint8_t *);
4463                 else
4464                         ciphertext = plaintext;
4465
4466                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4467                         ciphertext_len);
4468                 debug_hexdump(stdout, "ciphertext expected:",
4469                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4470
4471                 ut_params->digest = rte_pktmbuf_mtod(
4472                         ut_params->obuf, uint8_t *) +
4473                         (tdata->digest.offset_bytes == 0 ?
4474                         plaintext_pad_len : tdata->digest.offset_bytes);
4475
4476                 debug_hexdump(stdout, "digest:", ut_params->digest,
4477                         tdata->digest.len);
4478                 debug_hexdump(stdout, "digest expected:",
4479                         tdata->digest.data, tdata->digest.len);
4480         }
4481
4482         /* Validate obuf */
4483         if (verify) {
4484                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4485                         plaintext,
4486                         tdata->plaintext.data,
4487                         tdata->plaintext.len >> 3,
4488                         "KASUMI Plaintext data not as expected");
4489         } else {
4490                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4491                         ciphertext,
4492                         tdata->ciphertext.data,
4493                         tdata->ciphertext.len >> 3,
4494                         "KASUMI Ciphertext data not as expected");
4495
4496                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4497                         ut_params->digest,
4498                         tdata->digest.data,
4499                         DIGEST_BYTE_LENGTH_KASUMI_F9,
4500                         "KASUMI Generated auth tag not as expected");
4501         }
4502         return 0;
4503 }
4504
4505 static int
4506 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
4507         uint8_t op_mode, uint8_t verify)
4508 {
4509         struct crypto_testsuite_params *ts_params = &testsuite_params;
4510         struct crypto_unittest_params *ut_params = &unittest_params;
4511
4512         int retval;
4513
4514         const uint8_t *plaintext = NULL;
4515         const uint8_t *ciphertext = NULL;
4516         const uint8_t *digest = NULL;
4517         unsigned int plaintext_pad_len;
4518         unsigned int plaintext_len;
4519         unsigned int ciphertext_pad_len;
4520         unsigned int ciphertext_len;
4521         uint8_t buffer[10000];
4522         uint8_t digest_buffer[10000];
4523
4524         struct rte_cryptodev_info dev_info;
4525
4526         /* Verify the capabilities */
4527         struct rte_cryptodev_sym_capability_idx cap_idx;
4528         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4529         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4530         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4531                         &cap_idx) == NULL)
4532                 return -ENOTSUP;
4533         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4534         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4535         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4536                         &cap_idx) == NULL)
4537                 return -ENOTSUP;
4538
4539         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4540
4541         uint64_t feat_flags = dev_info.feature_flags;
4542
4543         if (op_mode == IN_PLACE) {
4544                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4545                         printf("Device doesn't support in-place scatter-gather "
4546                                         "in both input and output mbufs.\n");
4547                         return -ENOTSUP;
4548                 }
4549         } else {
4550                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4551                         printf("Device doesn't support out-of-place scatter-gather "
4552                                         "in both input and output mbufs.\n");
4553                         return -ENOTSUP;
4554                 }
4555                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4556                         printf("Device doesn't support digest encrypted.\n");
4557                         return -ENOTSUP;
4558                 }
4559         }
4560
4561         /* Create KASUMI session */
4562         retval = create_wireless_algo_auth_cipher_session(
4563                         ts_params->valid_devs[0],
4564                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4565                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4566                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4567                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4568                         RTE_CRYPTO_AUTH_KASUMI_F9,
4569                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4570                         tdata->key.data, tdata->key.len,
4571                         0, tdata->digest.len,
4572                         tdata->cipher_iv.len);
4573
4574         if (retval < 0)
4575                 return retval;
4576
4577         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4578         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4579         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4580         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4581
4582         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4583                         plaintext_pad_len, 15, 0);
4584         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4585                         "Failed to allocate input buffer in mempool");
4586
4587         if (op_mode == OUT_OF_PLACE) {
4588                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4589                                 plaintext_pad_len, 15, 0);
4590                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4591                                 "Failed to allocate output buffer in mempool");
4592         }
4593
4594         if (verify) {
4595                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4596                         tdata->ciphertext.data);
4597                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4598                                         ciphertext_len, buffer);
4599                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4600                         ciphertext_len);
4601         } else {
4602                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4603                         tdata->plaintext.data);
4604                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4605                                         plaintext_len, buffer);
4606                 debug_hexdump(stdout, "plaintext:", plaintext,
4607                         plaintext_len);
4608         }
4609         memset(buffer, 0, sizeof(buffer));
4610
4611         /* Create KASUMI operation */
4612         retval = create_wireless_algo_auth_cipher_operation(
4613                 tdata->digest.data, tdata->digest.len,
4614                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4615                 NULL, 0,
4616                 (tdata->digest.offset_bytes == 0 ?
4617                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4618                         : tdata->digest.offset_bytes),
4619                 tdata->validCipherLenInBits.len,
4620                 tdata->validCipherOffsetInBits.len,
4621                 tdata->validAuthLenInBits.len,
4622                 0,
4623                 op_mode, 1, verify);
4624
4625         if (retval < 0)
4626                 return retval;
4627
4628         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4629                         ut_params->op);
4630
4631         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4632
4633         ut_params->obuf = (op_mode == IN_PLACE ?
4634                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4635
4636         if (verify) {
4637                 if (ut_params->obuf)
4638                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4639                                         plaintext_len, buffer);
4640                 else
4641                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4642                                         plaintext_len, buffer);
4643
4644                 debug_hexdump(stdout, "plaintext:", plaintext,
4645                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4646                 debug_hexdump(stdout, "plaintext expected:",
4647                         tdata->plaintext.data,
4648                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4649         } else {
4650                 if (ut_params->obuf)
4651                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4652                                         ciphertext_len, buffer);
4653                 else
4654                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4655                                         ciphertext_len, buffer);
4656
4657                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4658                         ciphertext_len);
4659                 debug_hexdump(stdout, "ciphertext expected:",
4660                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4661
4662                 if (ut_params->obuf)
4663                         digest = rte_pktmbuf_read(ut_params->obuf,
4664                                 (tdata->digest.offset_bytes == 0 ?
4665                                 plaintext_pad_len : tdata->digest.offset_bytes),
4666                                 tdata->digest.len, digest_buffer);
4667                 else
4668                         digest = rte_pktmbuf_read(ut_params->ibuf,
4669                                 (tdata->digest.offset_bytes == 0 ?
4670                                 plaintext_pad_len : tdata->digest.offset_bytes),
4671                                 tdata->digest.len, digest_buffer);
4672
4673                 debug_hexdump(stdout, "digest:", digest,
4674                         tdata->digest.len);
4675                 debug_hexdump(stdout, "digest expected:",
4676                         tdata->digest.data, tdata->digest.len);
4677         }
4678
4679         /* Validate obuf */
4680         if (verify) {
4681                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4682                         plaintext,
4683                         tdata->plaintext.data,
4684                         tdata->plaintext.len >> 3,
4685                         "KASUMI Plaintext data not as expected");
4686         } else {
4687                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4688                         ciphertext,
4689                         tdata->ciphertext.data,
4690                         tdata->validDataLenInBits.len,
4691                         "KASUMI Ciphertext data not as expected");
4692
4693                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4694                         digest,
4695                         tdata->digest.data,
4696                         DIGEST_BYTE_LENGTH_KASUMI_F9,
4697                         "KASUMI Generated auth tag not as expected");
4698         }
4699         return 0;
4700 }
4701
4702 static int
4703 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
4704 {
4705         struct crypto_testsuite_params *ts_params = &testsuite_params;
4706         struct crypto_unittest_params *ut_params = &unittest_params;
4707
4708         int retval;
4709
4710         uint8_t *plaintext, *ciphertext;
4711         unsigned plaintext_pad_len;
4712         unsigned plaintext_len;
4713
4714         /* Verify the capabilities */
4715         struct rte_cryptodev_sym_capability_idx cap_idx;
4716         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4717         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4718         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4719                         &cap_idx) == NULL)
4720                 return -ENOTSUP;
4721         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4722         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4723         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4724                         &cap_idx) == NULL)
4725                 return -ENOTSUP;
4726
4727         /* Create KASUMI session */
4728         retval = create_wireless_algo_cipher_auth_session(
4729                         ts_params->valid_devs[0],
4730                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4731                         RTE_CRYPTO_AUTH_OP_GENERATE,
4732                         RTE_CRYPTO_AUTH_KASUMI_F9,
4733                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4734                         tdata->key.data, tdata->key.len,
4735                         0, tdata->digest.len,
4736                         tdata->cipher_iv.len);
4737         if (retval < 0)
4738                 return retval;
4739
4740         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4741
4742         /* clear mbuf payload */
4743         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4744                         rte_pktmbuf_tailroom(ut_params->ibuf));
4745
4746         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4747         /* Append data which is padded to a multiple of */
4748         /* the algorithms block size */
4749         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4750         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4751                                 plaintext_pad_len);
4752         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4753
4754         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4755
4756         /* Create KASUMI operation */
4757         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4758                                 tdata->digest.len, NULL, 0,
4759                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4760                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4761                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4762                                 tdata->validCipherOffsetInBits.len,
4763                                 tdata->validAuthLenInBits.len,
4764                                 0
4765                                 );
4766         if (retval < 0)
4767                 return retval;
4768
4769         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4770                         ut_params->op);
4771         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4772
4773         if (ut_params->op->sym->m_dst)
4774                 ut_params->obuf = ut_params->op->sym->m_dst;
4775         else
4776                 ut_params->obuf = ut_params->op->sym->m_src;
4777
4778         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
4779                                 tdata->validCipherOffsetInBits.len >> 3);
4780
4781         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4782                         + plaintext_pad_len;
4783
4784         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4785                                 (tdata->validCipherOffsetInBits.len >> 3);
4786         /* Validate obuf */
4787         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4788                 ciphertext,
4789                 reference_ciphertext,
4790                 tdata->validCipherLenInBits.len,
4791                 "KASUMI Ciphertext data not as expected");
4792
4793         /* Validate obuf */
4794         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4795                 ut_params->digest,
4796                 tdata->digest.data,
4797                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4798                 "KASUMI Generated auth tag not as expected");
4799         return 0;
4800 }
4801
4802 static int
4803 test_zuc_encryption(const struct wireless_test_data *tdata)
4804 {
4805         struct crypto_testsuite_params *ts_params = &testsuite_params;
4806         struct crypto_unittest_params *ut_params = &unittest_params;
4807
4808         int retval;
4809         uint8_t *plaintext, *ciphertext;
4810         unsigned plaintext_pad_len;
4811         unsigned plaintext_len;
4812
4813         struct rte_cryptodev_sym_capability_idx cap_idx;
4814
4815         /* Check if device supports ZUC EEA3 */
4816         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4817         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4818
4819         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4820                         &cap_idx) == NULL)
4821                 return -ENOTSUP;
4822
4823         /* Create ZUC session */
4824         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4825                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4826                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4827                                         tdata->key.data, tdata->key.len,
4828                                         tdata->cipher_iv.len);
4829         if (retval < 0)
4830                 return retval;
4831
4832         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4833
4834         /* Clear mbuf payload */
4835         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4836                rte_pktmbuf_tailroom(ut_params->ibuf));
4837
4838         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4839         /* Append data which is padded to a multiple */
4840         /* of the algorithms block size */
4841         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4842         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4843                                 plaintext_pad_len);
4844         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4845
4846         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4847
4848         /* Create ZUC operation */
4849         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4850                                         tdata->cipher_iv.len,
4851                                         tdata->plaintext.len,
4852                                         0);
4853         if (retval < 0)
4854                 return retval;
4855
4856         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4857                                                 ut_params->op);
4858         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4859
4860         ut_params->obuf = ut_params->op->sym->m_dst;
4861         if (ut_params->obuf)
4862                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4863         else
4864                 ciphertext = plaintext;
4865
4866         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4867
4868         /* Validate obuf */
4869         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4870                 ciphertext,
4871                 tdata->ciphertext.data,
4872                 tdata->validCipherLenInBits.len,
4873                 "ZUC Ciphertext data not as expected");
4874         return 0;
4875 }
4876
4877 static int
4878 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
4879 {
4880         struct crypto_testsuite_params *ts_params = &testsuite_params;
4881         struct crypto_unittest_params *ut_params = &unittest_params;
4882
4883         int retval;
4884
4885         unsigned int plaintext_pad_len;
4886         unsigned int plaintext_len;
4887         const uint8_t *ciphertext;
4888         uint8_t ciphertext_buffer[2048];
4889         struct rte_cryptodev_info dev_info;
4890
4891         struct rte_cryptodev_sym_capability_idx cap_idx;
4892
4893         /* Check if device supports ZUC EEA3 */
4894         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4895         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4896
4897         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4898                         &cap_idx) == NULL)
4899                 return -ENOTSUP;
4900
4901         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4902
4903         uint64_t feat_flags = dev_info.feature_flags;
4904
4905         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4906                 printf("Device doesn't support in-place scatter-gather. "
4907                                 "Test Skipped.\n");
4908                 return -ENOTSUP;
4909         }
4910
4911         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4912
4913         /* Append data which is padded to a multiple */
4914         /* of the algorithms block size */
4915         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4916
4917         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4918                         plaintext_pad_len, 10, 0);
4919
4920         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4921                         tdata->plaintext.data);
4922
4923         /* Create ZUC session */
4924         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4925                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4926                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
4927                         tdata->key.data, tdata->key.len,
4928                         tdata->cipher_iv.len);
4929         if (retval < 0)
4930                 return retval;
4931
4932         /* Clear mbuf payload */
4933
4934         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4935
4936         /* Create ZUC operation */
4937         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4938                         tdata->cipher_iv.len, tdata->plaintext.len,
4939                         0);
4940         if (retval < 0)
4941                 return retval;
4942
4943         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4944                                                 ut_params->op);
4945         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4946
4947         ut_params->obuf = ut_params->op->sym->m_dst;
4948         if (ut_params->obuf)
4949                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
4950                         0, plaintext_len, ciphertext_buffer);
4951         else
4952                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4953                         0, plaintext_len, ciphertext_buffer);
4954
4955         /* Validate obuf */
4956         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4957
4958         /* Validate obuf */
4959         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4960                 ciphertext,
4961                 tdata->ciphertext.data,
4962                 tdata->validCipherLenInBits.len,
4963                 "ZUC Ciphertext data not as expected");
4964
4965         return 0;
4966 }
4967
4968 static int
4969 test_zuc_authentication(const struct wireless_test_data *tdata)
4970 {
4971         struct crypto_testsuite_params *ts_params = &testsuite_params;
4972         struct crypto_unittest_params *ut_params = &unittest_params;
4973
4974         int retval;
4975         unsigned plaintext_pad_len;
4976         unsigned plaintext_len;
4977         uint8_t *plaintext;
4978
4979         struct rte_cryptodev_sym_capability_idx cap_idx;
4980
4981         /* QAT PMD supports byte-aligned data only */
4982         if ((tdata->validAuthLenInBits.len % 8 != 0) &&
4983                         (gbl_driver_id == rte_cryptodev_driver_id_get(
4984                                 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD))))
4985                 return -ENOTSUP;
4986
4987         /* Check if device supports ZUC EIA3 */
4988         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4989         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4990
4991         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4992                         &cap_idx) == NULL)
4993                 return -ENOTSUP;
4994
4995         /* Create ZUC session */
4996         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
4997                         tdata->key.data, tdata->key.len,
4998                         tdata->auth_iv.len, tdata->digest.len,
4999                         RTE_CRYPTO_AUTH_OP_GENERATE,
5000                         RTE_CRYPTO_AUTH_ZUC_EIA3);
5001         if (retval < 0)
5002                 return retval;
5003
5004         /* alloc mbuf and set payload */
5005         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5006
5007         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5008         rte_pktmbuf_tailroom(ut_params->ibuf));
5009
5010         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5011         /* Append data which is padded to a multiple of */
5012         /* the algorithms block size */
5013         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5014         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5015                                 plaintext_pad_len);
5016         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5017
5018         /* Create ZUC operation */
5019         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5020                         tdata->auth_iv.data, tdata->auth_iv.len,
5021                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5022                         tdata->validAuthLenInBits.len,
5023                         0);
5024         if (retval < 0)
5025                 return retval;
5026
5027         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5028                                 ut_params->op);
5029         ut_params->obuf = ut_params->op->sym->m_src;
5030         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5031         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5032                         + plaintext_pad_len;
5033
5034         /* Validate obuf */
5035         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5036         ut_params->digest,
5037         tdata->digest.data,
5038         tdata->digest.len,
5039         "ZUC Generated auth tag not as expected");
5040
5041         return 0;
5042 }
5043
5044 static int
5045 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5046         uint8_t op_mode, uint8_t verify)
5047 {
5048         struct crypto_testsuite_params *ts_params = &testsuite_params;
5049         struct crypto_unittest_params *ut_params = &unittest_params;
5050
5051         int retval;
5052
5053         uint8_t *plaintext = NULL, *ciphertext = NULL;
5054         unsigned int plaintext_pad_len;
5055         unsigned int plaintext_len;
5056         unsigned int ciphertext_pad_len;
5057         unsigned int ciphertext_len;
5058
5059         struct rte_cryptodev_info dev_info;
5060         struct rte_cryptodev_sym_capability_idx cap_idx;
5061
5062         /* Check if device supports ZUC EIA3 */
5063         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5064         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5065
5066         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5067                         &cap_idx) == NULL)
5068                 return -ENOTSUP;
5069
5070         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5071
5072         uint64_t feat_flags = dev_info.feature_flags;
5073
5074         if (op_mode == OUT_OF_PLACE) {
5075                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5076                         printf("Device doesn't support digest encrypted.\n");
5077                         return -ENOTSUP;
5078                 }
5079         }
5080
5081         /* Create ZUC session */
5082         retval = create_wireless_algo_auth_cipher_session(
5083                         ts_params->valid_devs[0],
5084                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5085                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5086                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5087                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5088                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5089                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5090                         tdata->key.data, tdata->key.len,
5091                         tdata->auth_iv.len, tdata->digest.len,
5092                         tdata->cipher_iv.len);
5093
5094         if (retval < 0)
5095                 return retval;
5096
5097         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5098         if (op_mode == OUT_OF_PLACE)
5099                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5100
5101         /* clear mbuf payload */
5102         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5103                 rte_pktmbuf_tailroom(ut_params->ibuf));
5104         if (op_mode == OUT_OF_PLACE)
5105                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5106                         rte_pktmbuf_tailroom(ut_params->obuf));
5107
5108         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5109         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5110         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5111         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5112
5113         if (verify) {
5114                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5115                                         ciphertext_pad_len);
5116                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5117                 if (op_mode == OUT_OF_PLACE)
5118                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5119                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5120                         ciphertext_len);
5121         } else {
5122                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5123                                         plaintext_pad_len);
5124                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5125                 if (op_mode == OUT_OF_PLACE)
5126                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5127                 debug_hexdump(stdout, "plaintext:", plaintext,
5128                         plaintext_len);
5129         }
5130
5131         /* Create ZUC operation */
5132         retval = create_wireless_algo_auth_cipher_operation(
5133                 tdata->digest.data, tdata->digest.len,
5134                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5135                 tdata->auth_iv.data, tdata->auth_iv.len,
5136                 (tdata->digest.offset_bytes == 0 ?
5137                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5138                         : tdata->digest.offset_bytes),
5139                 tdata->validCipherLenInBits.len,
5140                 tdata->validCipherOffsetInBits.len,
5141                 tdata->validAuthLenInBits.len,
5142                 0,
5143                 op_mode, 0, verify);
5144
5145         if (retval < 0)
5146                 return retval;
5147
5148         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5149                         ut_params->op);
5150
5151         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5152
5153         ut_params->obuf = (op_mode == IN_PLACE ?
5154                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5155
5156
5157         if (verify) {
5158                 if (ut_params->obuf)
5159                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5160                                                         uint8_t *);
5161                 else
5162                         plaintext = ciphertext;
5163
5164                 debug_hexdump(stdout, "plaintext:", plaintext,
5165                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5166                 debug_hexdump(stdout, "plaintext expected:",
5167                         tdata->plaintext.data,
5168                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5169         } else {
5170                 if (ut_params->obuf)
5171                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5172                                                         uint8_t *);
5173                 else
5174                         ciphertext = plaintext;
5175
5176                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5177                         ciphertext_len);
5178                 debug_hexdump(stdout, "ciphertext expected:",
5179                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5180
5181                 ut_params->digest = rte_pktmbuf_mtod(
5182                         ut_params->obuf, uint8_t *) +
5183                         (tdata->digest.offset_bytes == 0 ?
5184                         plaintext_pad_len : tdata->digest.offset_bytes);
5185
5186                 debug_hexdump(stdout, "digest:", ut_params->digest,
5187                         tdata->digest.len);
5188                 debug_hexdump(stdout, "digest expected:",
5189                         tdata->digest.data, tdata->digest.len);
5190         }
5191
5192         /* Validate obuf */
5193         if (verify) {
5194                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5195                         plaintext,
5196                         tdata->plaintext.data,
5197                         tdata->plaintext.len >> 3,
5198                         "ZUC Plaintext data not as expected");
5199         } else {
5200                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5201                         ciphertext,
5202                         tdata->ciphertext.data,
5203                         tdata->ciphertext.len >> 3,
5204                         "ZUC Ciphertext data not as expected");
5205
5206                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5207                         ut_params->digest,
5208                         tdata->digest.data,
5209                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5210                         "ZUC Generated auth tag not as expected");
5211         }
5212         return 0;
5213 }
5214
5215 static int
5216 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5217         uint8_t op_mode, uint8_t verify)
5218 {
5219         struct crypto_testsuite_params *ts_params = &testsuite_params;
5220         struct crypto_unittest_params *ut_params = &unittest_params;
5221
5222         int retval;
5223
5224         const uint8_t *plaintext = NULL;
5225         const uint8_t *ciphertext = NULL;
5226         const uint8_t *digest = NULL;
5227         unsigned int plaintext_pad_len;
5228         unsigned int plaintext_len;
5229         unsigned int ciphertext_pad_len;
5230         unsigned int ciphertext_len;
5231         uint8_t buffer[10000];
5232         uint8_t digest_buffer[10000];
5233
5234         struct rte_cryptodev_info dev_info;
5235         struct rte_cryptodev_sym_capability_idx cap_idx;
5236
5237         /* Check if device supports ZUC EIA3 */
5238         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5239         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5240
5241         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5242                         &cap_idx) == NULL)
5243                 return -ENOTSUP;
5244
5245         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5246
5247         uint64_t feat_flags = dev_info.feature_flags;
5248
5249         if (op_mode == IN_PLACE) {
5250                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5251                         printf("Device doesn't support in-place scatter-gather "
5252                                         "in both input and output mbufs.\n");
5253                         return -ENOTSUP;
5254                 }
5255         } else {
5256                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5257                         printf("Device doesn't support out-of-place scatter-gather "
5258                                         "in both input and output mbufs.\n");
5259                         return -ENOTSUP;
5260                 }
5261                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5262                         printf("Device doesn't support digest encrypted.\n");
5263                         return -ENOTSUP;
5264                 }
5265         }
5266
5267         /* Create ZUC session */
5268         retval = create_wireless_algo_auth_cipher_session(
5269                         ts_params->valid_devs[0],
5270                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5271                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5272                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5273                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5274                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5275                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5276                         tdata->key.data, tdata->key.len,
5277                         tdata->auth_iv.len, tdata->digest.len,
5278                         tdata->cipher_iv.len);
5279
5280         if (retval < 0)
5281                 return retval;
5282
5283         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5284         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5285         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5286         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5287
5288         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5289                         plaintext_pad_len, 15, 0);
5290         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5291                         "Failed to allocate input buffer in mempool");
5292
5293         if (op_mode == OUT_OF_PLACE) {
5294                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5295                                 plaintext_pad_len, 15, 0);
5296                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5297                                 "Failed to allocate output buffer in mempool");
5298         }
5299
5300         if (verify) {
5301                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5302                         tdata->ciphertext.data);
5303                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5304                                         ciphertext_len, buffer);
5305                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5306                         ciphertext_len);
5307         } else {
5308                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5309                         tdata->plaintext.data);
5310                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5311                                         plaintext_len, buffer);
5312                 debug_hexdump(stdout, "plaintext:", plaintext,
5313                         plaintext_len);
5314         }
5315         memset(buffer, 0, sizeof(buffer));
5316
5317         /* Create ZUC operation */
5318         retval = create_wireless_algo_auth_cipher_operation(
5319                 tdata->digest.data, tdata->digest.len,
5320                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5321                 NULL, 0,
5322                 (tdata->digest.offset_bytes == 0 ?
5323                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5324                         : tdata->digest.offset_bytes),
5325                 tdata->validCipherLenInBits.len,
5326                 tdata->validCipherOffsetInBits.len,
5327                 tdata->validAuthLenInBits.len,
5328                 0,
5329                 op_mode, 1, verify);
5330
5331         if (retval < 0)
5332                 return retval;
5333
5334         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5335                         ut_params->op);
5336
5337         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5338
5339         ut_params->obuf = (op_mode == IN_PLACE ?
5340                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5341
5342         if (verify) {
5343                 if (ut_params->obuf)
5344                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5345                                         plaintext_len, buffer);
5346                 else
5347                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5348                                         plaintext_len, buffer);
5349
5350                 debug_hexdump(stdout, "plaintext:", plaintext,
5351                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5352                 debug_hexdump(stdout, "plaintext expected:",
5353                         tdata->plaintext.data,
5354                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5355         } else {
5356                 if (ut_params->obuf)
5357                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5358                                         ciphertext_len, buffer);
5359                 else
5360                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5361                                         ciphertext_len, buffer);
5362
5363                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5364                         ciphertext_len);
5365                 debug_hexdump(stdout, "ciphertext expected:",
5366                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5367
5368                 if (ut_params->obuf)
5369                         digest = rte_pktmbuf_read(ut_params->obuf,
5370                                 (tdata->digest.offset_bytes == 0 ?
5371                                 plaintext_pad_len : tdata->digest.offset_bytes),
5372                                 tdata->digest.len, digest_buffer);
5373                 else
5374                         digest = rte_pktmbuf_read(ut_params->ibuf,
5375                                 (tdata->digest.offset_bytes == 0 ?
5376                                 plaintext_pad_len : tdata->digest.offset_bytes),
5377                                 tdata->digest.len, digest_buffer);
5378
5379                 debug_hexdump(stdout, "digest:", digest,
5380                         tdata->digest.len);
5381                 debug_hexdump(stdout, "digest expected:",
5382                         tdata->digest.data, tdata->digest.len);
5383         }
5384
5385         /* Validate obuf */
5386         if (verify) {
5387                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5388                         plaintext,
5389                         tdata->plaintext.data,
5390                         tdata->plaintext.len >> 3,
5391                         "ZUC Plaintext data not as expected");
5392         } else {
5393                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5394                         ciphertext,
5395                         tdata->ciphertext.data,
5396                         tdata->validDataLenInBits.len,
5397                         "ZUC Ciphertext data not as expected");
5398
5399                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5400                         digest,
5401                         tdata->digest.data,
5402                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5403                         "ZUC Generated auth tag not as expected");
5404         }
5405         return 0;
5406 }
5407
5408 static int
5409 test_kasumi_encryption_test_case_1(void)
5410 {
5411         return test_kasumi_encryption(&kasumi_test_case_1);
5412 }
5413
5414 static int
5415 test_kasumi_encryption_test_case_1_sgl(void)
5416 {
5417         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
5418 }
5419
5420 static int
5421 test_kasumi_encryption_test_case_1_oop(void)
5422 {
5423         return test_kasumi_encryption_oop(&kasumi_test_case_1);
5424 }
5425
5426 static int
5427 test_kasumi_encryption_test_case_1_oop_sgl(void)
5428 {
5429         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
5430 }
5431
5432 static int
5433 test_kasumi_encryption_test_case_2(void)
5434 {
5435         return test_kasumi_encryption(&kasumi_test_case_2);
5436 }
5437
5438 static int
5439 test_kasumi_encryption_test_case_3(void)
5440 {
5441         return test_kasumi_encryption(&kasumi_test_case_3);
5442 }
5443
5444 static int
5445 test_kasumi_encryption_test_case_4(void)
5446 {
5447         return test_kasumi_encryption(&kasumi_test_case_4);
5448 }
5449
5450 static int
5451 test_kasumi_encryption_test_case_5(void)
5452 {
5453         return test_kasumi_encryption(&kasumi_test_case_5);
5454 }
5455
5456 static int
5457 test_kasumi_decryption_test_case_1(void)
5458 {
5459         return test_kasumi_decryption(&kasumi_test_case_1);
5460 }
5461
5462 static int
5463 test_kasumi_decryption_test_case_1_oop(void)
5464 {
5465         return test_kasumi_decryption_oop(&kasumi_test_case_1);
5466 }
5467
5468 static int
5469 test_kasumi_decryption_test_case_2(void)
5470 {
5471         return test_kasumi_decryption(&kasumi_test_case_2);
5472 }
5473
5474 static int
5475 test_kasumi_decryption_test_case_3(void)
5476 {
5477         return test_kasumi_decryption(&kasumi_test_case_3);
5478 }
5479
5480 static int
5481 test_kasumi_decryption_test_case_4(void)
5482 {
5483         return test_kasumi_decryption(&kasumi_test_case_4);
5484 }
5485
5486 static int
5487 test_kasumi_decryption_test_case_5(void)
5488 {
5489         return test_kasumi_decryption(&kasumi_test_case_5);
5490 }
5491 static int
5492 test_snow3g_encryption_test_case_1(void)
5493 {
5494         return test_snow3g_encryption(&snow3g_test_case_1);
5495 }
5496
5497 static int
5498 test_snow3g_encryption_test_case_1_oop(void)
5499 {
5500         return test_snow3g_encryption_oop(&snow3g_test_case_1);
5501 }
5502
5503 static int
5504 test_snow3g_encryption_test_case_1_oop_sgl(void)
5505 {
5506         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
5507 }
5508
5509
5510 static int
5511 test_snow3g_encryption_test_case_1_offset_oop(void)
5512 {
5513         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
5514 }
5515
5516 static int
5517 test_snow3g_encryption_test_case_2(void)
5518 {
5519         return test_snow3g_encryption(&snow3g_test_case_2);
5520 }
5521
5522 static int
5523 test_snow3g_encryption_test_case_3(void)
5524 {
5525         return test_snow3g_encryption(&snow3g_test_case_3);
5526 }
5527
5528 static int
5529 test_snow3g_encryption_test_case_4(void)
5530 {
5531         return test_snow3g_encryption(&snow3g_test_case_4);
5532 }
5533
5534 static int
5535 test_snow3g_encryption_test_case_5(void)
5536 {
5537         return test_snow3g_encryption(&snow3g_test_case_5);
5538 }
5539
5540 static int
5541 test_snow3g_decryption_test_case_1(void)
5542 {
5543         return test_snow3g_decryption(&snow3g_test_case_1);
5544 }
5545
5546 static int
5547 test_snow3g_decryption_test_case_1_oop(void)
5548 {
5549         return test_snow3g_decryption_oop(&snow3g_test_case_1);
5550 }
5551
5552 static int
5553 test_snow3g_decryption_test_case_2(void)
5554 {
5555         return test_snow3g_decryption(&snow3g_test_case_2);
5556 }
5557
5558 static int
5559 test_snow3g_decryption_test_case_3(void)
5560 {
5561         return test_snow3g_decryption(&snow3g_test_case_3);
5562 }
5563
5564 static int
5565 test_snow3g_decryption_test_case_4(void)
5566 {
5567         return test_snow3g_decryption(&snow3g_test_case_4);
5568 }
5569
5570 static int
5571 test_snow3g_decryption_test_case_5(void)
5572 {
5573         return test_snow3g_decryption(&snow3g_test_case_5);
5574 }
5575
5576 /*
5577  * Function prepares snow3g_hash_test_data from snow3g_test_data.
5578  * Pattern digest from snow3g_test_data must be allocated as
5579  * 4 last bytes in plaintext.
5580  */
5581 static void
5582 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
5583                 struct snow3g_hash_test_data *output)
5584 {
5585         if ((pattern != NULL) && (output != NULL)) {
5586                 output->key.len = pattern->key.len;
5587
5588                 memcpy(output->key.data,
5589                 pattern->key.data, pattern->key.len);
5590
5591                 output->auth_iv.len = pattern->auth_iv.len;
5592
5593                 memcpy(output->auth_iv.data,
5594                 pattern->auth_iv.data, pattern->auth_iv.len);
5595
5596                 output->plaintext.len = pattern->plaintext.len;
5597
5598                 memcpy(output->plaintext.data,
5599                 pattern->plaintext.data, pattern->plaintext.len >> 3);
5600
5601                 output->digest.len = pattern->digest.len;
5602
5603                 memcpy(output->digest.data,
5604                 &pattern->plaintext.data[pattern->digest.offset_bytes],
5605                 pattern->digest.len);
5606
5607                 output->validAuthLenInBits.len =
5608                 pattern->validAuthLenInBits.len;
5609         }
5610 }
5611
5612 /*
5613  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
5614  */
5615 static int
5616 test_snow3g_decryption_with_digest_test_case_1(void)
5617 {
5618         struct snow3g_hash_test_data snow3g_hash_data;
5619
5620         /*
5621          * Function prepare data for hash veryfication test case.
5622          * Digest is allocated in 4 last bytes in plaintext, pattern.
5623          */
5624         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
5625
5626         return test_snow3g_decryption(&snow3g_test_case_7) &
5627                         test_snow3g_authentication_verify(&snow3g_hash_data);
5628 }
5629
5630 static int
5631 test_snow3g_cipher_auth_test_case_1(void)
5632 {
5633         return test_snow3g_cipher_auth(&snow3g_test_case_3);
5634 }
5635
5636 static int
5637 test_snow3g_auth_cipher_test_case_1(void)
5638 {
5639         return test_snow3g_auth_cipher(
5640                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
5641 }
5642
5643 static int
5644 test_snow3g_auth_cipher_test_case_2(void)
5645 {
5646         return test_snow3g_auth_cipher(
5647                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
5648 }
5649
5650 static int
5651 test_snow3g_auth_cipher_test_case_2_oop(void)
5652 {
5653         return test_snow3g_auth_cipher(
5654                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5655 }
5656
5657 static int
5658 test_snow3g_auth_cipher_part_digest_enc(void)
5659 {
5660         return test_snow3g_auth_cipher(
5661                 &snow3g_auth_cipher_partial_digest_encryption,
5662                         IN_PLACE, 0);
5663 }
5664
5665 static int
5666 test_snow3g_auth_cipher_part_digest_enc_oop(void)
5667 {
5668         return test_snow3g_auth_cipher(
5669                 &snow3g_auth_cipher_partial_digest_encryption,
5670                         OUT_OF_PLACE, 0);
5671 }
5672
5673 static int
5674 test_snow3g_auth_cipher_test_case_3_sgl(void)
5675 {
5676         return test_snow3g_auth_cipher_sgl(
5677                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
5678 }
5679
5680 static int
5681 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
5682 {
5683         return test_snow3g_auth_cipher_sgl(
5684                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
5685 }
5686
5687 static int
5688 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
5689 {
5690         return test_snow3g_auth_cipher_sgl(
5691                 &snow3g_auth_cipher_partial_digest_encryption,
5692                         IN_PLACE, 0);
5693 }
5694
5695 static int
5696 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
5697 {
5698         return test_snow3g_auth_cipher_sgl(
5699                 &snow3g_auth_cipher_partial_digest_encryption,
5700                         OUT_OF_PLACE, 0);
5701 }
5702
5703 static int
5704 test_snow3g_auth_cipher_verify_test_case_1(void)
5705 {
5706         return test_snow3g_auth_cipher(
5707                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
5708 }
5709
5710 static int
5711 test_snow3g_auth_cipher_verify_test_case_2(void)
5712 {
5713         return test_snow3g_auth_cipher(
5714                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
5715 }
5716
5717 static int
5718 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
5719 {
5720         return test_snow3g_auth_cipher(
5721                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5722 }
5723
5724 static int
5725 test_snow3g_auth_cipher_verify_part_digest_enc(void)
5726 {
5727         return test_snow3g_auth_cipher(
5728                 &snow3g_auth_cipher_partial_digest_encryption,
5729                         IN_PLACE, 1);
5730 }
5731
5732 static int
5733 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
5734 {
5735         return test_snow3g_auth_cipher(
5736                 &snow3g_auth_cipher_partial_digest_encryption,
5737                         OUT_OF_PLACE, 1);
5738 }
5739
5740 static int
5741 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
5742 {
5743         return test_snow3g_auth_cipher_sgl(
5744                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
5745 }
5746
5747 static int
5748 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
5749 {
5750         return test_snow3g_auth_cipher_sgl(
5751                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
5752 }
5753
5754 static int
5755 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
5756 {
5757         return test_snow3g_auth_cipher_sgl(
5758                 &snow3g_auth_cipher_partial_digest_encryption,
5759                         IN_PLACE, 1);
5760 }
5761
5762 static int
5763 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
5764 {
5765         return test_snow3g_auth_cipher_sgl(
5766                 &snow3g_auth_cipher_partial_digest_encryption,
5767                         OUT_OF_PLACE, 1);
5768 }
5769
5770 static int
5771 test_snow3g_auth_cipher_with_digest_test_case_1(void)
5772 {
5773         return test_snow3g_auth_cipher(
5774                 &snow3g_test_case_7, IN_PLACE, 0);
5775 }
5776
5777 static int
5778 test_kasumi_auth_cipher_test_case_1(void)
5779 {
5780         return test_kasumi_auth_cipher(
5781                 &kasumi_test_case_3, IN_PLACE, 0);
5782 }
5783
5784 static int
5785 test_kasumi_auth_cipher_test_case_2(void)
5786 {
5787         return test_kasumi_auth_cipher(
5788                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
5789 }
5790
5791 static int
5792 test_kasumi_auth_cipher_test_case_2_oop(void)
5793 {
5794         return test_kasumi_auth_cipher(
5795                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5796 }
5797
5798 static int
5799 test_kasumi_auth_cipher_test_case_2_sgl(void)
5800 {
5801         return test_kasumi_auth_cipher_sgl(
5802                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
5803 }
5804
5805 static int
5806 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
5807 {
5808         return test_kasumi_auth_cipher_sgl(
5809                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5810 }
5811
5812 static int
5813 test_kasumi_auth_cipher_verify_test_case_1(void)
5814 {
5815         return test_kasumi_auth_cipher(
5816                 &kasumi_test_case_3, IN_PLACE, 1);
5817 }
5818
5819 static int
5820 test_kasumi_auth_cipher_verify_test_case_2(void)
5821 {
5822         return test_kasumi_auth_cipher(
5823                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
5824 }
5825
5826 static int
5827 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
5828 {
5829         return test_kasumi_auth_cipher(
5830                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5831 }
5832
5833 static int
5834 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
5835 {
5836         return test_kasumi_auth_cipher_sgl(
5837                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
5838 }
5839
5840 static int
5841 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
5842 {
5843         return test_kasumi_auth_cipher_sgl(
5844                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5845 }
5846
5847 static int
5848 test_kasumi_cipher_auth_test_case_1(void)
5849 {
5850         return test_kasumi_cipher_auth(&kasumi_test_case_6);
5851 }
5852
5853 static int
5854 test_zuc_encryption_test_case_1(void)
5855 {
5856         return test_zuc_encryption(&zuc_test_case_cipher_193b);
5857 }
5858
5859 static int
5860 test_zuc_encryption_test_case_2(void)
5861 {
5862         return test_zuc_encryption(&zuc_test_case_cipher_800b);
5863 }
5864
5865 static int
5866 test_zuc_encryption_test_case_3(void)
5867 {
5868         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
5869 }
5870
5871 static int
5872 test_zuc_encryption_test_case_4(void)
5873 {
5874         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
5875 }
5876
5877 static int
5878 test_zuc_encryption_test_case_5(void)
5879 {
5880         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
5881 }
5882
5883 static int
5884 test_zuc_encryption_test_case_6_sgl(void)
5885 {
5886         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
5887 }
5888
5889 static int
5890 test_zuc_hash_generate_test_case_1(void)
5891 {
5892         return test_zuc_authentication(&zuc_test_case_auth_1b);
5893 }
5894
5895 static int
5896 test_zuc_hash_generate_test_case_2(void)
5897 {
5898         return test_zuc_authentication(&zuc_test_case_auth_90b);
5899 }
5900
5901 static int
5902 test_zuc_hash_generate_test_case_3(void)
5903 {
5904         return test_zuc_authentication(&zuc_test_case_auth_577b);
5905 }
5906
5907 static int
5908 test_zuc_hash_generate_test_case_4(void)
5909 {
5910         return test_zuc_authentication(&zuc_test_case_auth_2079b);
5911 }
5912
5913 static int
5914 test_zuc_hash_generate_test_case_5(void)
5915 {
5916         return test_zuc_authentication(&zuc_test_auth_5670b);
5917 }
5918
5919 static int
5920 test_zuc_hash_generate_test_case_6(void)
5921 {
5922         return test_zuc_authentication(&zuc_test_case_auth_128b);
5923 }
5924
5925 static int
5926 test_zuc_hash_generate_test_case_7(void)
5927 {
5928         /* This test is not for SW ZUC PMD */
5929         if (gbl_driver_id == rte_cryptodev_driver_id_get(
5930                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD)))
5931                 return -ENOTSUP;
5932
5933         return test_zuc_authentication(&zuc_test_case_auth_2080b);
5934 }
5935
5936 static int
5937 test_zuc_hash_generate_test_case_8(void)
5938 {
5939         return test_zuc_authentication(&zuc_test_case_auth_584b);
5940 }
5941
5942 static int
5943 test_zuc_cipher_auth_test_case_1(void)
5944 {
5945         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
5946 }
5947
5948 static int
5949 test_zuc_cipher_auth_test_case_2(void)
5950 {
5951         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
5952 }
5953
5954 static int
5955 test_zuc_auth_cipher_test_case_1(void)
5956 {
5957         /* This test is not for SW ZUC PMD */
5958         if (gbl_driver_id == rte_cryptodev_driver_id_get(
5959                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD)))
5960                 return -ENOTSUP;
5961
5962         return test_zuc_auth_cipher(
5963                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
5964 }
5965
5966 static int
5967 test_zuc_auth_cipher_test_case_1_oop(void)
5968 {
5969         return test_zuc_auth_cipher(
5970                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
5971 }
5972
5973 static int
5974 test_zuc_auth_cipher_test_case_1_sgl(void)
5975 {
5976         return test_zuc_auth_cipher_sgl(
5977                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
5978 }
5979
5980 static int
5981 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
5982 {
5983         return test_zuc_auth_cipher_sgl(
5984                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
5985 }
5986
5987 static int
5988 test_zuc_auth_cipher_verify_test_case_1(void)
5989 {
5990         return test_zuc_auth_cipher(
5991                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
5992 }
5993
5994 static int
5995 test_zuc_auth_cipher_verify_test_case_1_oop(void)
5996 {
5997         return test_zuc_auth_cipher(
5998                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
5999 }
6000
6001 static int
6002 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6003 {
6004         return test_zuc_auth_cipher_sgl(
6005                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6006 }
6007
6008 static int
6009 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6010 {
6011         return test_zuc_auth_cipher_sgl(
6012                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6013 }
6014
6015 static int
6016 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6017 {
6018         uint8_t dev_id = testsuite_params.valid_devs[0];
6019
6020         struct rte_cryptodev_sym_capability_idx cap_idx;
6021
6022         /* Check if device supports particular cipher algorithm */
6023         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6024         cap_idx.algo.cipher = tdata->cipher_algo;
6025         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6026                 return -ENOTSUP;
6027
6028         /* Check if device supports particular hash algorithm */
6029         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6030         cap_idx.algo.auth = tdata->auth_algo;
6031         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6032                 return -ENOTSUP;
6033
6034         return 0;
6035 }
6036
6037 static int
6038 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6039         uint8_t op_mode, uint8_t verify)
6040 {
6041         struct crypto_testsuite_params *ts_params = &testsuite_params;
6042         struct crypto_unittest_params *ut_params = &unittest_params;
6043
6044         int retval;
6045
6046         uint8_t *plaintext = NULL, *ciphertext = NULL;
6047         unsigned int plaintext_pad_len;
6048         unsigned int plaintext_len;
6049         unsigned int ciphertext_pad_len;
6050         unsigned int ciphertext_len;
6051
6052         struct rte_cryptodev_info dev_info;
6053         struct rte_crypto_op *op;
6054
6055         /* Check if device supports particular algorithms separately */
6056         if (test_mixed_check_if_unsupported(tdata))
6057                 return -ENOTSUP;
6058
6059         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6060
6061         uint64_t feat_flags = dev_info.feature_flags;
6062
6063         if (op_mode == OUT_OF_PLACE) {
6064                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6065                         printf("Device doesn't support digest encrypted.\n");
6066                         return -ENOTSUP;
6067                 }
6068         }
6069
6070         /* Create the session */
6071         if (verify)
6072                 retval = create_wireless_algo_cipher_auth_session(
6073                                 ts_params->valid_devs[0],
6074                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6075                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6076                                 tdata->auth_algo,
6077                                 tdata->cipher_algo,
6078                                 tdata->auth_key.data, tdata->auth_key.len,
6079                                 tdata->auth_iv.len, tdata->digest_enc.len,
6080                                 tdata->cipher_iv.len);
6081         else
6082                 retval = create_wireless_algo_auth_cipher_session(
6083                                 ts_params->valid_devs[0],
6084                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6085                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6086                                 tdata->auth_algo,
6087                                 tdata->cipher_algo,
6088                                 tdata->auth_key.data, tdata->auth_key.len,
6089                                 tdata->auth_iv.len, tdata->digest_enc.len,
6090                                 tdata->cipher_iv.len);
6091         if (retval < 0)
6092                 return retval;
6093
6094         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6095         if (op_mode == OUT_OF_PLACE)
6096                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6097
6098         /* clear mbuf payload */
6099         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6100                 rte_pktmbuf_tailroom(ut_params->ibuf));
6101         if (op_mode == OUT_OF_PLACE)
6102                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6103                                 rte_pktmbuf_tailroom(ut_params->obuf));
6104
6105         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6106         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6107         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6108         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6109
6110         if (verify) {
6111                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6112                                 ciphertext_pad_len);
6113                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6114                 if (op_mode == OUT_OF_PLACE)
6115                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6116                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6117                                 ciphertext_len);
6118         } else {
6119                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6120                                 plaintext_pad_len);
6121                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6122                 if (op_mode == OUT_OF_PLACE)
6123                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6124                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6125         }
6126
6127         /* Create the operation */
6128         retval = create_wireless_algo_auth_cipher_operation(
6129                         tdata->digest_enc.data, tdata->digest_enc.len,
6130                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6131                         tdata->auth_iv.data, tdata->auth_iv.len,
6132                         (tdata->digest_enc.offset == 0 ?
6133                                 plaintext_pad_len
6134                                 : tdata->digest_enc.offset),
6135                         tdata->validCipherLen.len_bits,
6136                         tdata->cipher.offset_bits,
6137                         tdata->validAuthLen.len_bits,
6138                         tdata->auth.offset_bits,
6139                         op_mode, 0, verify);
6140
6141         if (retval < 0)
6142                 return retval;
6143
6144         op = process_crypto_request(ts_params->valid_devs[0],
6145                         ut_params->op);
6146
6147         /* Check if the op failed because the device doesn't */
6148         /* support this particular combination of algorithms */
6149         if (op == NULL && ut_params->op->status ==
6150                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6151                 printf("Device doesn't support this mixed combination. "
6152                                 "Test Skipped.\n");
6153                 return -ENOTSUP;
6154         }
6155         ut_params->op = op;
6156
6157         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6158
6159         ut_params->obuf = (op_mode == IN_PLACE ?
6160                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6161
6162         if (verify) {
6163                 if (ut_params->obuf)
6164                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6165                                                         uint8_t *);
6166                 else
6167                         plaintext = ciphertext +
6168                                         (tdata->cipher.offset_bits >> 3);
6169
6170                 debug_hexdump(stdout, "plaintext:", plaintext,
6171                                 tdata->plaintext.len_bits >> 3);
6172                 debug_hexdump(stdout, "plaintext expected:",
6173                                 tdata->plaintext.data,
6174                                 tdata->plaintext.len_bits >> 3);
6175         } else {
6176                 if (ut_params->obuf)
6177                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6178                                         uint8_t *);
6179                 else
6180                         ciphertext = plaintext;
6181
6182                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6183                                 ciphertext_len);
6184                 debug_hexdump(stdout, "ciphertext expected:",
6185                                 tdata->ciphertext.data,
6186                                 tdata->ciphertext.len_bits >> 3);
6187
6188                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6189                                 + (tdata->digest_enc.offset == 0 ?
6190                 plaintext_pad_len : tdata->digest_enc.offset);
6191
6192                 debug_hexdump(stdout, "digest:", ut_params->digest,
6193                                 tdata->digest_enc.len);
6194                 debug_hexdump(stdout, "digest expected:",
6195                                 tdata->digest_enc.data,
6196                                 tdata->digest_enc.len);
6197         }
6198
6199         /* Validate obuf */
6200         if (verify) {
6201                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6202                                 plaintext,
6203                                 tdata->plaintext.data,
6204                                 tdata->plaintext.len_bits >> 3,
6205                                 "Plaintext data not as expected");
6206         } else {
6207                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6208                                 ciphertext,
6209                                 tdata->ciphertext.data,
6210                                 tdata->validDataLen.len_bits,
6211                                 "Ciphertext data not as expected");
6212
6213                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6214                                 ut_params->digest,
6215                                 tdata->digest_enc.data,
6216                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6217                                 "Generated auth tag not as expected");
6218         }
6219
6220         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6221                         "crypto op processing failed");
6222
6223         return 0;
6224 }
6225
6226 static int
6227 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6228         uint8_t op_mode, uint8_t verify)
6229 {
6230         struct crypto_testsuite_params *ts_params = &testsuite_params;
6231         struct crypto_unittest_params *ut_params = &unittest_params;
6232
6233         int retval;
6234
6235         const uint8_t *plaintext = NULL;
6236         const uint8_t *ciphertext = NULL;
6237         const uint8_t *digest = NULL;
6238         unsigned int plaintext_pad_len;
6239         unsigned int plaintext_len;
6240         unsigned int ciphertext_pad_len;
6241         unsigned int ciphertext_len;
6242         uint8_t buffer[10000];
6243         uint8_t digest_buffer[10000];
6244
6245         struct rte_cryptodev_info dev_info;
6246         struct rte_crypto_op *op;
6247
6248         /* Check if device supports particular algorithms */
6249         if (test_mixed_check_if_unsupported(tdata))
6250                 return -ENOTSUP;
6251
6252         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6253
6254         uint64_t feat_flags = dev_info.feature_flags;
6255
6256         if (op_mode == IN_PLACE) {
6257                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6258                         printf("Device doesn't support in-place scatter-gather "
6259                                         "in both input and output mbufs.\n");
6260                         return -ENOTSUP;
6261                 }
6262         } else {
6263                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6264                         printf("Device doesn't support out-of-place scatter-gather "
6265                                         "in both input and output mbufs.\n");
6266                         return -ENOTSUP;
6267                 }
6268                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6269                         printf("Device doesn't support digest encrypted.\n");
6270                         return -ENOTSUP;
6271                 }
6272         }
6273
6274         /* Create the session */
6275         if (verify)
6276                 retval = create_wireless_algo_cipher_auth_session(
6277                                 ts_params->valid_devs[0],
6278                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6279                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6280                                 tdata->auth_algo,
6281                                 tdata->cipher_algo,
6282                                 tdata->auth_key.data, tdata->auth_key.len,
6283                                 tdata->auth_iv.len, tdata->digest_enc.len,
6284                                 tdata->cipher_iv.len);
6285         else
6286                 retval = create_wireless_algo_auth_cipher_session(
6287                                 ts_params->valid_devs[0],
6288                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6289                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6290                                 tdata->auth_algo,
6291                                 tdata->cipher_algo,
6292                                 tdata->auth_key.data, tdata->auth_key.len,
6293                                 tdata->auth_iv.len, tdata->digest_enc.len,
6294                                 tdata->cipher_iv.len);
6295         if (retval < 0)
6296                 return retval;
6297
6298         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6299         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6300         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6301         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6302
6303         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6304                         ciphertext_pad_len, 15, 0);
6305         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6306                         "Failed to allocate input buffer in mempool");
6307
6308         if (op_mode == OUT_OF_PLACE) {
6309                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6310                                 plaintext_pad_len, 15, 0);
6311                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6312                                 "Failed to allocate output buffer in mempool");
6313         }
6314
6315         if (verify) {
6316                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6317                         tdata->ciphertext.data);
6318                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6319                                         ciphertext_len, buffer);
6320                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6321                         ciphertext_len);
6322         } else {
6323                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6324                         tdata->plaintext.data);
6325                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6326                                         plaintext_len, buffer);
6327                 debug_hexdump(stdout, "plaintext:", plaintext,
6328                         plaintext_len);
6329         }
6330         memset(buffer, 0, sizeof(buffer));
6331
6332         /* Create the operation */
6333         retval = create_wireless_algo_auth_cipher_operation(
6334                         tdata->digest_enc.data, tdata->digest_enc.len,
6335                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6336                         tdata->auth_iv.data, tdata->auth_iv.len,
6337                         (tdata->digest_enc.offset == 0 ?
6338                                 plaintext_pad_len
6339                                 : tdata->digest_enc.offset),
6340                         tdata->validCipherLen.len_bits,
6341                         tdata->cipher.offset_bits,
6342                         tdata->validAuthLen.len_bits,
6343                         tdata->auth.offset_bits,
6344                         op_mode, 1, verify);
6345
6346         if (retval < 0)
6347                 return retval;
6348
6349         op = process_crypto_request(ts_params->valid_devs[0],
6350                         ut_params->op);
6351
6352         /* Check if the op failed because the device doesn't */
6353         /* support this particular combination of algorithms */
6354         if (op == NULL && ut_params->op->status ==
6355                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6356                 printf("Device doesn't support this mixed combination. "
6357                                 "Test Skipped.\n");
6358                 return -ENOTSUP;
6359         }
6360
6361         ut_params->op = op;
6362
6363         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6364
6365         ut_params->obuf = (op_mode == IN_PLACE ?
6366                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6367
6368         if (verify) {
6369                 if (ut_params->obuf)
6370                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6371                                         plaintext_len, buffer);
6372                 else
6373                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6374                                         plaintext_len, buffer);
6375
6376                 debug_hexdump(stdout, "plaintext:", plaintext,
6377                                 (tdata->plaintext.len_bits >> 3) -
6378                                 tdata->digest_enc.len);
6379                 debug_hexdump(stdout, "plaintext expected:",
6380                                 tdata->plaintext.data,
6381                                 (tdata->plaintext.len_bits >> 3) -
6382                                 tdata->digest_enc.len);
6383         } else {
6384                 if (ut_params->obuf)
6385                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6386                                         ciphertext_len, buffer);
6387                 else
6388                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6389                                         ciphertext_len, buffer);
6390
6391                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6392                         ciphertext_len);
6393                 debug_hexdump(stdout, "ciphertext expected:",
6394                         tdata->ciphertext.data,
6395                         tdata->ciphertext.len_bits >> 3);
6396
6397                 if (ut_params->obuf)
6398                         digest = rte_pktmbuf_read(ut_params->obuf,
6399                                         (tdata->digest_enc.offset == 0 ?
6400                                                 plaintext_pad_len :
6401                                                 tdata->digest_enc.offset),
6402                                         tdata->digest_enc.len, digest_buffer);
6403                 else
6404                         digest = rte_pktmbuf_read(ut_params->ibuf,
6405                                         (tdata->digest_enc.offset == 0 ?
6406                                                 plaintext_pad_len :
6407                                                 tdata->digest_enc.offset),
6408                                         tdata->digest_enc.len, digest_buffer);
6409
6410                 debug_hexdump(stdout, "digest:", digest,
6411                                 tdata->digest_enc.len);
6412                 debug_hexdump(stdout, "digest expected:",
6413                                 tdata->digest_enc.data, tdata->digest_enc.len);
6414         }
6415
6416         /* Validate obuf */
6417         if (verify) {
6418                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6419                                 plaintext,
6420                                 tdata->plaintext.data,
6421                                 tdata->plaintext.len_bits >> 3,
6422                                 "Plaintext data not as expected");
6423         } else {
6424                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6425                                 ciphertext,
6426                                 tdata->ciphertext.data,
6427                                 tdata->validDataLen.len_bits,
6428                                 "Ciphertext data not as expected");
6429                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6430                                 digest,
6431                                 tdata->digest_enc.data,
6432                                 tdata->digest_enc.len,
6433                                 "Generated auth tag not as expected");
6434         }
6435
6436         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6437                         "crypto op processing failed");
6438
6439         return 0;
6440 }
6441
6442 /** AUTH AES CMAC + CIPHER AES CTR */
6443
6444 static int
6445 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
6446 {
6447         return test_mixed_auth_cipher(
6448                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
6449 }
6450
6451 static int
6452 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
6453 {
6454         return test_mixed_auth_cipher(
6455                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6456 }
6457
6458 static int
6459 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
6460 {
6461         return test_mixed_auth_cipher_sgl(
6462                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
6463 }
6464
6465 static int
6466 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
6467 {
6468         return test_mixed_auth_cipher_sgl(
6469                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6470 }
6471
6472 static int
6473 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
6474 {
6475         return test_mixed_auth_cipher(
6476                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
6477 }
6478
6479 static int
6480 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
6481 {
6482         return test_mixed_auth_cipher(
6483                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6484 }
6485
6486 static int
6487 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
6488 {
6489         return test_mixed_auth_cipher_sgl(
6490                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
6491 }
6492
6493 static int
6494 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
6495 {
6496         return test_mixed_auth_cipher_sgl(
6497                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6498 }
6499
6500 /** MIXED AUTH + CIPHER */
6501
6502 static int
6503 test_auth_zuc_cipher_snow_test_case_1(void)
6504 {
6505         return test_mixed_auth_cipher(
6506                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6507 }
6508
6509 static int
6510 test_verify_auth_zuc_cipher_snow_test_case_1(void)
6511 {
6512         return test_mixed_auth_cipher(
6513                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6514 }
6515
6516 static int
6517 test_auth_aes_cmac_cipher_snow_test_case_1(void)
6518 {
6519         return test_mixed_auth_cipher(
6520                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6521 }
6522
6523 static int
6524 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
6525 {
6526         return test_mixed_auth_cipher(
6527                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6528 }
6529
6530 static int
6531 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
6532 {
6533         return test_mixed_auth_cipher(
6534                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6535 }
6536
6537 static int
6538 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
6539 {
6540         return test_mixed_auth_cipher(
6541                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6542 }
6543
6544 static int
6545 test_auth_snow_cipher_aes_ctr_test_case_1(void)
6546 {
6547         return test_mixed_auth_cipher(
6548                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6549 }
6550
6551 static int
6552 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
6553 {
6554         return test_mixed_auth_cipher(
6555                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6556 }
6557
6558 static int
6559 test_auth_snow_cipher_zuc_test_case_1(void)
6560 {
6561         return test_mixed_auth_cipher(
6562                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6563 }
6564
6565 static int
6566 test_verify_auth_snow_cipher_zuc_test_case_1(void)
6567 {
6568         return test_mixed_auth_cipher(
6569                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6570 }
6571
6572 static int
6573 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
6574 {
6575         return test_mixed_auth_cipher(
6576                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6577 }
6578
6579 static int
6580 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
6581 {
6582         return test_mixed_auth_cipher(
6583                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6584 }
6585
6586 static int
6587 test_auth_null_cipher_snow_test_case_1(void)
6588 {
6589         return test_mixed_auth_cipher(
6590                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6591 }
6592
6593 static int
6594 test_verify_auth_null_cipher_snow_test_case_1(void)
6595 {
6596         return test_mixed_auth_cipher(
6597                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6598 }
6599
6600 static int
6601 test_auth_null_cipher_zuc_test_case_1(void)
6602 {
6603         return test_mixed_auth_cipher(
6604                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6605 }
6606
6607 static int
6608 test_verify_auth_null_cipher_zuc_test_case_1(void)
6609 {
6610         return test_mixed_auth_cipher(
6611                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6612 }
6613
6614 static int
6615 test_auth_snow_cipher_null_test_case_1(void)
6616 {
6617         return test_mixed_auth_cipher(
6618                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6619 }
6620
6621 static int
6622 test_verify_auth_snow_cipher_null_test_case_1(void)
6623 {
6624         return test_mixed_auth_cipher(
6625                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6626 }
6627
6628 static int
6629 test_auth_zuc_cipher_null_test_case_1(void)
6630 {
6631         return test_mixed_auth_cipher(
6632                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6633 }
6634
6635 static int
6636 test_verify_auth_zuc_cipher_null_test_case_1(void)
6637 {
6638         return test_mixed_auth_cipher(
6639                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6640 }
6641
6642 static int
6643 test_auth_null_cipher_aes_ctr_test_case_1(void)
6644 {
6645         return test_mixed_auth_cipher(
6646                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6647 }
6648
6649 static int
6650 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
6651 {
6652         return test_mixed_auth_cipher(
6653                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6654 }
6655
6656 static int
6657 test_auth_aes_cmac_cipher_null_test_case_1(void)
6658 {
6659         return test_mixed_auth_cipher(
6660                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6661 }
6662
6663 static int
6664 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
6665 {
6666         return test_mixed_auth_cipher(
6667                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6668 }
6669
6670 /* ***** AEAD algorithm Tests ***** */
6671
6672 static int
6673 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
6674                 enum rte_crypto_aead_operation op,
6675                 const uint8_t *key, const uint8_t key_len,
6676                 const uint16_t aad_len, const uint8_t auth_len,
6677                 uint8_t iv_len)
6678 {
6679         uint8_t aead_key[key_len];
6680
6681         struct crypto_testsuite_params *ts_params = &testsuite_params;
6682         struct crypto_unittest_params *ut_params = &unittest_params;
6683
6684         memcpy(aead_key, key, key_len);
6685
6686         /* Setup AEAD Parameters */
6687         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
6688         ut_params->aead_xform.next = NULL;
6689         ut_params->aead_xform.aead.algo = algo;
6690         ut_params->aead_xform.aead.op = op;
6691         ut_params->aead_xform.aead.key.data = aead_key;
6692         ut_params->aead_xform.aead.key.length = key_len;
6693         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
6694         ut_params->aead_xform.aead.iv.length = iv_len;
6695         ut_params->aead_xform.aead.digest_length = auth_len;
6696         ut_params->aead_xform.aead.aad_length = aad_len;
6697
6698         debug_hexdump(stdout, "key:", key, key_len);
6699
6700         /* Create Crypto session*/
6701         ut_params->sess = rte_cryptodev_sym_session_create(
6702                         ts_params->session_mpool);
6703
6704         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6705                         &ut_params->aead_xform,
6706                         ts_params->session_priv_mpool);
6707
6708         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6709
6710         return 0;
6711 }
6712
6713 static int
6714 create_aead_xform(struct rte_crypto_op *op,
6715                 enum rte_crypto_aead_algorithm algo,
6716                 enum rte_crypto_aead_operation aead_op,
6717                 uint8_t *key, const uint8_t key_len,
6718                 const uint8_t aad_len, const uint8_t auth_len,
6719                 uint8_t iv_len)
6720 {
6721         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
6722                         "failed to allocate space for crypto transform");
6723
6724         struct rte_crypto_sym_op *sym_op = op->sym;
6725
6726         /* Setup AEAD Parameters */
6727         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
6728         sym_op->xform->next = NULL;
6729         sym_op->xform->aead.algo = algo;
6730         sym_op->xform->aead.op = aead_op;
6731         sym_op->xform->aead.key.data = key;
6732         sym_op->xform->aead.key.length = key_len;
6733         sym_op->xform->aead.iv.offset = IV_OFFSET;
6734         sym_op->xform->aead.iv.length = iv_len;
6735         sym_op->xform->aead.digest_length = auth_len;
6736         sym_op->xform->aead.aad_length = aad_len;
6737
6738         debug_hexdump(stdout, "key:", key, key_len);
6739
6740         return 0;
6741 }
6742
6743 static int
6744 create_aead_operation(enum rte_crypto_aead_operation op,
6745                 const struct aead_test_data *tdata)
6746 {
6747         struct crypto_testsuite_params *ts_params = &testsuite_params;
6748         struct crypto_unittest_params *ut_params = &unittest_params;
6749
6750         uint8_t *plaintext, *ciphertext;
6751         unsigned int aad_pad_len, plaintext_pad_len;
6752
6753         /* Generate Crypto op data structure */
6754         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6755                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6756         TEST_ASSERT_NOT_NULL(ut_params->op,
6757                         "Failed to allocate symmetric crypto operation struct");
6758
6759         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6760
6761         /* Append aad data */
6762         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
6763                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
6764                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6765                                 aad_pad_len);
6766                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6767                                 "no room to append aad");
6768
6769                 sym_op->aead.aad.phys_addr =
6770                                 rte_pktmbuf_iova(ut_params->ibuf);
6771                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
6772                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
6773                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6774                         tdata->aad.len);
6775
6776                 /* Append IV at the end of the crypto operation*/
6777                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6778                                 uint8_t *, IV_OFFSET);
6779
6780                 /* Copy IV 1 byte after the IV pointer, according to the API */
6781                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
6782                 debug_hexdump(stdout, "iv:", iv_ptr,
6783                         tdata->iv.len);
6784         } else {
6785                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6786                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6787                                 aad_pad_len);
6788                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6789                                 "no room to append aad");
6790
6791                 sym_op->aead.aad.phys_addr =
6792                                 rte_pktmbuf_iova(ut_params->ibuf);
6793                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
6794                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6795                         tdata->aad.len);
6796
6797                 /* Append IV at the end of the crypto operation*/
6798                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6799                                 uint8_t *, IV_OFFSET);
6800
6801                 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
6802                 debug_hexdump(stdout, "iv:", iv_ptr,
6803                         tdata->iv.len);
6804         }
6805
6806         /* Append plaintext/ciphertext */
6807         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6808                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6809                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6810                                 plaintext_pad_len);
6811                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6812
6813                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6814                 debug_hexdump(stdout, "plaintext:", plaintext,
6815                                 tdata->plaintext.len);
6816
6817                 if (ut_params->obuf) {
6818                         ciphertext = (uint8_t *)rte_pktmbuf_append(
6819                                         ut_params->obuf,
6820                                         plaintext_pad_len + aad_pad_len);
6821                         TEST_ASSERT_NOT_NULL(ciphertext,
6822                                         "no room to append ciphertext");
6823
6824                         memset(ciphertext + aad_pad_len, 0,
6825                                         tdata->ciphertext.len);
6826                 }
6827         } else {
6828                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
6829                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6830                                 plaintext_pad_len);
6831                 TEST_ASSERT_NOT_NULL(ciphertext,
6832                                 "no room to append ciphertext");
6833
6834                 memcpy(ciphertext, tdata->ciphertext.data,
6835                                 tdata->ciphertext.len);
6836                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6837                                 tdata->ciphertext.len);
6838
6839                 if (ut_params->obuf) {
6840                         plaintext = (uint8_t *)rte_pktmbuf_append(
6841                                         ut_params->obuf,
6842                                         plaintext_pad_len + aad_pad_len);
6843                         TEST_ASSERT_NOT_NULL(plaintext,
6844                                         "no room to append plaintext");
6845
6846                         memset(plaintext + aad_pad_len, 0,
6847                                         tdata->plaintext.len);
6848                 }
6849         }
6850
6851         /* Append digest data */
6852         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6853                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6854                                 ut_params->obuf ? ut_params->obuf :
6855                                                 ut_params->ibuf,
6856                                                 tdata->auth_tag.len);
6857                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6858                                 "no room to append digest");
6859                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
6860                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6861                                 ut_params->obuf ? ut_params->obuf :
6862                                                 ut_params->ibuf,
6863                                                 plaintext_pad_len +
6864                                                 aad_pad_len);
6865         } else {
6866                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6867                                 ut_params->ibuf, tdata->auth_tag.len);
6868                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6869                                 "no room to append digest");
6870                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6871                                 ut_params->ibuf,
6872                                 plaintext_pad_len + aad_pad_len);
6873
6874                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
6875                         tdata->auth_tag.len);
6876                 debug_hexdump(stdout, "digest:",
6877                         sym_op->aead.digest.data,
6878                         tdata->auth_tag.len);
6879         }
6880
6881         sym_op->aead.data.length = tdata->plaintext.len;
6882         sym_op->aead.data.offset = aad_pad_len;
6883
6884         return 0;
6885 }
6886
6887 static int
6888 test_authenticated_encryption(const struct aead_test_data *tdata)
6889 {
6890         struct crypto_testsuite_params *ts_params = &testsuite_params;
6891         struct crypto_unittest_params *ut_params = &unittest_params;
6892
6893         int retval;
6894         uint8_t *ciphertext, *auth_tag;
6895         uint16_t plaintext_pad_len;
6896         uint32_t i;
6897
6898         /* Verify the capabilities */
6899         struct rte_cryptodev_sym_capability_idx cap_idx;
6900         const struct rte_cryptodev_symmetric_capability *capability;
6901         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
6902         cap_idx.algo.aead = tdata->algo;
6903         capability = rte_cryptodev_sym_capability_get(
6904                         ts_params->valid_devs[0], &cap_idx);
6905         if (capability == NULL)
6906                 return -ENOTSUP;
6907         if (rte_cryptodev_sym_capability_check_aead(
6908                         capability, tdata->key.len, tdata->auth_tag.len,
6909                         tdata->aad.len, tdata->iv.len))
6910                 return -ENOTSUP;
6911
6912         /* Create AEAD session */
6913         retval = create_aead_session(ts_params->valid_devs[0],
6914                         tdata->algo,
6915                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
6916                         tdata->key.data, tdata->key.len,
6917                         tdata->aad.len, tdata->auth_tag.len,
6918                         tdata->iv.len);
6919         if (retval < 0)
6920                 return retval;
6921
6922         if (tdata->aad.len > MBUF_SIZE) {
6923                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6924                 /* Populate full size of add data */
6925                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
6926                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
6927         } else
6928                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6929
6930         /* clear mbuf payload */
6931         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6932                         rte_pktmbuf_tailroom(ut_params->ibuf));
6933
6934         /* Create AEAD operation */
6935         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
6936         if (retval < 0)
6937                 return retval;
6938
6939         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6940
6941         ut_params->op->sym->m_src = ut_params->ibuf;
6942
6943         /* Process crypto operation */
6944         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6945                         ut_params->op), "failed to process sym crypto op");
6946
6947         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6948                         "crypto op processing failed");
6949
6950         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6951
6952         if (ut_params->op->sym->m_dst) {
6953                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
6954                                 uint8_t *);
6955                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6956                                 uint8_t *, plaintext_pad_len);
6957         } else {
6958                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
6959                                 uint8_t *,
6960                                 ut_params->op->sym->cipher.data.offset);
6961                 auth_tag = ciphertext + plaintext_pad_len;
6962         }
6963
6964         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
6965         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
6966
6967         /* Validate obuf */
6968         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6969                         ciphertext,
6970                         tdata->ciphertext.data,
6971                         tdata->ciphertext.len,
6972                         "Ciphertext data not as expected");
6973
6974         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6975                         auth_tag,
6976                         tdata->auth_tag.data,
6977                         tdata->auth_tag.len,
6978                         "Generated auth tag not as expected");
6979
6980         return 0;
6981
6982 }
6983
6984 #ifdef RTE_LIBRTE_SECURITY
6985 /* Basic algorithm run function for async inplace mode.
6986  * Creates a session from input parameters and runs one operation
6987  * on input_vec. Checks the output of the crypto operation against
6988  * output_vec.
6989  */
6990 static int
6991 test_pdcp_proto(int i, int oop,
6992         enum rte_crypto_cipher_operation opc,
6993         enum rte_crypto_auth_operation opa,
6994         uint8_t *input_vec,
6995         unsigned int input_vec_len,
6996         uint8_t *output_vec,
6997         unsigned int output_vec_len)
6998 {
6999         struct crypto_testsuite_params *ts_params = &testsuite_params;
7000         struct crypto_unittest_params *ut_params = &unittest_params;
7001         uint8_t *plaintext;
7002         int ret = TEST_SUCCESS;
7003         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7004                                 rte_cryptodev_get_sec_ctx(
7005                                 ts_params->valid_devs[0]);
7006
7007         /* Verify the capabilities */
7008         struct rte_security_capability_idx sec_cap_idx;
7009
7010         sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7011         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7012         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7013         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7014                 return -ENOTSUP;
7015
7016         /* Generate test mbuf data */
7017         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7018
7019         /* clear mbuf payload */
7020         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7021                         rte_pktmbuf_tailroom(ut_params->ibuf));
7022
7023         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7024                                                   input_vec_len);
7025         memcpy(plaintext, input_vec, input_vec_len);
7026
7027         /* Out of place support */
7028         if (oop) {
7029                 /*
7030                  * For out-op-place we need to alloc another mbuf
7031                  */
7032                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7033                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7034         }
7035
7036         /* Set crypto type as IPSEC */
7037         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7038
7039         /* Setup Cipher Parameters */
7040         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7041         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7042         ut_params->cipher_xform.cipher.op = opc;
7043         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7044         ut_params->cipher_xform.cipher.key.length =
7045                                         pdcp_test_params[i].cipher_key_len;
7046         ut_params->cipher_xform.cipher.iv.length = 0;
7047
7048         /* Setup HMAC Parameters if ICV header is required */
7049         if (pdcp_test_params[i].auth_alg != 0) {
7050                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7051                 ut_params->auth_xform.next = NULL;
7052                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7053                 ut_params->auth_xform.auth.op = opa;
7054                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7055                 ut_params->auth_xform.auth.key.length =
7056                                         pdcp_test_params[i].auth_key_len;
7057
7058                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7059         } else {
7060                 ut_params->cipher_xform.next = NULL;
7061         }
7062
7063         struct rte_security_session_conf sess_conf = {
7064                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
7065                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7066                 {.pdcp = {
7067                         .bearer = pdcp_test_bearer[i],
7068                         .domain = pdcp_test_params[i].domain,
7069                         .pkt_dir = pdcp_test_packet_direction[i],
7070                         .sn_size = pdcp_test_data_sn_size[i],
7071                         .hfn = pdcp_test_hfn[i],
7072                         .hfn_threshold = pdcp_test_hfn_threshold[i],
7073                 } },
7074                 .crypto_xform = &ut_params->cipher_xform
7075         };
7076
7077         /* Create security session */
7078         ut_params->sec_session = rte_security_session_create(ctx,
7079                                 &sess_conf, ts_params->session_priv_mpool);
7080
7081         if (!ut_params->sec_session) {
7082                 printf("TestCase %s()-%d line %d failed %s: ",
7083                         __func__, i, __LINE__, "Failed to allocate session");
7084                 ret = TEST_FAILED;
7085                 goto on_err;
7086         }
7087
7088         /* Generate crypto op data structure */
7089         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7090                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7091         if (!ut_params->op) {
7092                 printf("TestCase %s()-%d line %d failed %s: ",
7093                         __func__, i, __LINE__,
7094                         "Failed to allocate symmetric crypto operation struct");
7095                 ret = TEST_FAILED;
7096                 goto on_err;
7097         }
7098
7099         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7100
7101         /* set crypto operation source mbuf */
7102         ut_params->op->sym->m_src = ut_params->ibuf;
7103         if (oop)
7104                 ut_params->op->sym->m_dst = ut_params->obuf;
7105
7106         /* Process crypto operation */
7107         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7108                 == NULL) {
7109                 printf("TestCase %s()-%d line %d failed %s: ",
7110                         __func__, i, __LINE__,
7111                         "failed to process sym crypto op");
7112                 ret = TEST_FAILED;
7113                 goto on_err;
7114         }
7115
7116         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7117                 printf("TestCase %s()-%d line %d failed %s: ",
7118                         __func__, i, __LINE__, "crypto op processing failed");
7119                 ret = TEST_FAILED;
7120                 goto on_err;
7121         }
7122
7123         /* Validate obuf */
7124         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7125                         uint8_t *);
7126         if (oop) {
7127                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7128                                 uint8_t *);
7129         }
7130
7131         if (memcmp(ciphertext, output_vec, output_vec_len)) {
7132                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7133                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7134                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7135                 ret = TEST_FAILED;
7136                 goto on_err;
7137         }
7138
7139 on_err:
7140         rte_crypto_op_free(ut_params->op);
7141         ut_params->op = NULL;
7142
7143         if (ut_params->sec_session)
7144                 rte_security_session_destroy(ctx, ut_params->sec_session);
7145         ut_params->sec_session = NULL;
7146
7147         rte_pktmbuf_free(ut_params->ibuf);
7148         ut_params->ibuf = NULL;
7149         if (oop) {
7150                 rte_pktmbuf_free(ut_params->obuf);
7151                 ut_params->obuf = NULL;
7152         }
7153
7154         return ret;
7155 }
7156
7157 static int
7158 test_pdcp_proto_SGL(int i, int oop,
7159         enum rte_crypto_cipher_operation opc,
7160         enum rte_crypto_auth_operation opa,
7161         uint8_t *input_vec,
7162         unsigned int input_vec_len,
7163         uint8_t *output_vec,
7164         unsigned int output_vec_len,
7165         uint32_t fragsz,
7166         uint32_t fragsz_oop)
7167 {
7168         struct crypto_testsuite_params *ts_params = &testsuite_params;
7169         struct crypto_unittest_params *ut_params = &unittest_params;
7170         uint8_t *plaintext;
7171         struct rte_mbuf *buf, *buf_oop = NULL;
7172         int ret = TEST_SUCCESS;
7173         int to_trn = 0;
7174         int to_trn_tbl[16];
7175         int segs = 1;
7176         unsigned int trn_data = 0;
7177         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7178                                 rte_cryptodev_get_sec_ctx(
7179                                 ts_params->valid_devs[0]);
7180
7181         /* Verify the capabilities */
7182         struct rte_security_capability_idx sec_cap_idx;
7183
7184         sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7185         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7186         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7187         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7188                 return -ENOTSUP;
7189
7190         if (fragsz > input_vec_len)
7191                 fragsz = input_vec_len;
7192
7193         uint16_t plaintext_len = fragsz;
7194         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7195
7196         if (fragsz_oop > output_vec_len)
7197                 frag_size_oop = output_vec_len;
7198
7199         int ecx = 0;
7200         if (input_vec_len % fragsz != 0) {
7201                 if (input_vec_len / fragsz + 1 > 16)
7202                         return 1;
7203         } else if (input_vec_len / fragsz > 16)
7204                 return 1;
7205
7206         /* Out of place support */
7207         if (oop) {
7208                 /*
7209                  * For out-op-place we need to alloc another mbuf
7210                  */
7211                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7212                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
7213                 buf_oop = ut_params->obuf;
7214         }
7215
7216         /* Generate test mbuf data */
7217         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7218
7219         /* clear mbuf payload */
7220         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7221                         rte_pktmbuf_tailroom(ut_params->ibuf));
7222
7223         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7224                                                   plaintext_len);
7225         memcpy(plaintext, input_vec, plaintext_len);
7226         trn_data += plaintext_len;
7227
7228         buf = ut_params->ibuf;
7229
7230         /*
7231          * Loop until no more fragments
7232          */
7233
7234         while (trn_data < input_vec_len) {
7235                 ++segs;
7236                 to_trn = (input_vec_len - trn_data < fragsz) ?
7237                                 (input_vec_len - trn_data) : fragsz;
7238
7239                 to_trn_tbl[ecx++] = to_trn;
7240
7241                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7242                 buf = buf->next;
7243
7244                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7245                                 rte_pktmbuf_tailroom(buf));
7246
7247                 /* OOP */
7248                 if (oop && !fragsz_oop) {
7249                         buf_oop->next =
7250                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7251                         buf_oop = buf_oop->next;
7252                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7253                                         0, rte_pktmbuf_tailroom(buf_oop));
7254                         rte_pktmbuf_append(buf_oop, to_trn);
7255                 }
7256
7257                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7258                                 to_trn);
7259
7260                 memcpy(plaintext, input_vec + trn_data, to_trn);
7261                 trn_data += to_trn;
7262         }
7263
7264         ut_params->ibuf->nb_segs = segs;
7265
7266         segs = 1;
7267         if (fragsz_oop && oop) {
7268                 to_trn = 0;
7269                 ecx = 0;
7270
7271                 trn_data = frag_size_oop;
7272                 while (trn_data < output_vec_len) {
7273                         ++segs;
7274                         to_trn =
7275                                 (output_vec_len - trn_data <
7276                                                 frag_size_oop) ?
7277                                 (output_vec_len - trn_data) :
7278                                                 frag_size_oop;
7279
7280                         to_trn_tbl[ecx++] = to_trn;
7281
7282                         buf_oop->next =
7283                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
7284                         buf_oop = buf_oop->next;
7285                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7286                                         0, rte_pktmbuf_tailroom(buf_oop));
7287                         rte_pktmbuf_append(buf_oop, to_trn);
7288
7289                         trn_data += to_trn;
7290                 }
7291                 ut_params->obuf->nb_segs = segs;
7292         }
7293
7294         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7295
7296         /* Setup Cipher Parameters */
7297         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7298         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7299         ut_params->cipher_xform.cipher.op = opc;
7300         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7301         ut_params->cipher_xform.cipher.key.length =
7302                                         pdcp_test_params[i].cipher_key_len;
7303         ut_params->cipher_xform.cipher.iv.length = 0;
7304
7305         /* Setup HMAC Parameters if ICV header is required */
7306         if (pdcp_test_params[i].auth_alg != 0) {
7307                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7308                 ut_params->auth_xform.next = NULL;
7309                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7310                 ut_params->auth_xform.auth.op = opa;
7311                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7312                 ut_params->auth_xform.auth.key.length =
7313                                         pdcp_test_params[i].auth_key_len;
7314
7315                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7316         } else {
7317                 ut_params->cipher_xform.next = NULL;
7318         }
7319
7320         struct rte_security_session_conf sess_conf = {
7321                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
7322                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7323                 {.pdcp = {
7324                         .bearer = pdcp_test_bearer[i],
7325                         .domain = pdcp_test_params[i].domain,
7326                         .pkt_dir = pdcp_test_packet_direction[i],
7327                         .sn_size = pdcp_test_data_sn_size[i],
7328                         .hfn = pdcp_test_hfn[i],
7329                         .hfn_threshold = pdcp_test_hfn_threshold[i],
7330                 } },
7331                 .crypto_xform = &ut_params->cipher_xform
7332         };
7333
7334         /* Create security session */
7335         ut_params->sec_session = rte_security_session_create(ctx,
7336                                 &sess_conf, ts_params->session_priv_mpool);
7337
7338         if (!ut_params->sec_session) {
7339                 printf("TestCase %s()-%d line %d failed %s: ",
7340                         __func__, i, __LINE__, "Failed to allocate session");
7341                 ret = TEST_FAILED;
7342                 goto on_err;
7343         }
7344
7345         /* Generate crypto op data structure */
7346         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7347                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7348         if (!ut_params->op) {
7349                 printf("TestCase %s()-%d line %d failed %s: ",
7350                         __func__, i, __LINE__,
7351                         "Failed to allocate symmetric crypto operation struct");
7352                 ret = TEST_FAILED;
7353                 goto on_err;
7354         }
7355
7356         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7357
7358         /* set crypto operation source mbuf */
7359         ut_params->op->sym->m_src = ut_params->ibuf;
7360         if (oop)
7361                 ut_params->op->sym->m_dst = ut_params->obuf;
7362
7363         /* Process crypto operation */
7364         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7365                 == NULL) {
7366                 printf("TestCase %s()-%d line %d failed %s: ",
7367                         __func__, i, __LINE__,
7368                         "failed to process sym crypto op");
7369                 ret = TEST_FAILED;
7370                 goto on_err;
7371         }
7372
7373         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7374                 printf("TestCase %s()-%d line %d failed %s: ",
7375                         __func__, i, __LINE__, "crypto op processing failed");
7376                 ret = TEST_FAILED;
7377                 goto on_err;
7378         }
7379
7380         /* Validate obuf */
7381         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7382                         uint8_t *);
7383         if (oop) {
7384                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7385                                 uint8_t *);
7386         }
7387         if (fragsz_oop)
7388                 fragsz = frag_size_oop;
7389         if (memcmp(ciphertext, output_vec, fragsz)) {
7390                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7391                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
7392                 rte_hexdump(stdout, "reference", output_vec, fragsz);
7393                 ret = TEST_FAILED;
7394                 goto on_err;
7395         }
7396
7397         buf = ut_params->op->sym->m_src->next;
7398         if (oop)
7399                 buf = ut_params->op->sym->m_dst->next;
7400
7401         unsigned int off = fragsz;
7402
7403         ecx = 0;
7404         while (buf) {
7405                 ciphertext = rte_pktmbuf_mtod(buf,
7406                                 uint8_t *);
7407                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
7408                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7409                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
7410                         rte_hexdump(stdout, "reference", output_vec + off,
7411                                         to_trn_tbl[ecx]);
7412                         ret = TEST_FAILED;
7413                         goto on_err;
7414                 }
7415                 off += to_trn_tbl[ecx++];
7416                 buf = buf->next;
7417         }
7418 on_err:
7419         rte_crypto_op_free(ut_params->op);
7420         ut_params->op = NULL;
7421
7422         if (ut_params->sec_session)
7423                 rte_security_session_destroy(ctx, ut_params->sec_session);
7424         ut_params->sec_session = NULL;
7425
7426         rte_pktmbuf_free(ut_params->ibuf);
7427         ut_params->ibuf = NULL;
7428         if (oop) {
7429                 rte_pktmbuf_free(ut_params->obuf);
7430                 ut_params->obuf = NULL;
7431         }
7432
7433         return ret;
7434 }
7435
7436 int
7437 test_pdcp_proto_cplane_encap(int i)
7438 {
7439         return test_pdcp_proto(i, 0,
7440                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7441                 RTE_CRYPTO_AUTH_OP_GENERATE,
7442                 pdcp_test_data_in[i],
7443                 pdcp_test_data_in_len[i],
7444                 pdcp_test_data_out[i],
7445                 pdcp_test_data_in_len[i]+4);
7446 }
7447
7448 int
7449 test_pdcp_proto_uplane_encap(int i)
7450 {
7451         return test_pdcp_proto(i, 0,
7452                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7453                 RTE_CRYPTO_AUTH_OP_GENERATE,
7454                 pdcp_test_data_in[i],
7455                 pdcp_test_data_in_len[i],
7456                 pdcp_test_data_out[i],
7457                 pdcp_test_data_in_len[i]);
7458
7459 }
7460
7461 int
7462 test_pdcp_proto_uplane_encap_with_int(int i)
7463 {
7464         return test_pdcp_proto(i, 0,
7465                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7466                 RTE_CRYPTO_AUTH_OP_GENERATE,
7467                 pdcp_test_data_in[i],
7468                 pdcp_test_data_in_len[i],
7469                 pdcp_test_data_out[i],
7470                 pdcp_test_data_in_len[i] + 4);
7471 }
7472
7473 int
7474 test_pdcp_proto_cplane_decap(int i)
7475 {
7476         return test_pdcp_proto(i, 0,
7477                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7478                 RTE_CRYPTO_AUTH_OP_VERIFY,
7479                 pdcp_test_data_out[i],
7480                 pdcp_test_data_in_len[i] + 4,
7481                 pdcp_test_data_in[i],
7482                 pdcp_test_data_in_len[i]);
7483 }
7484
7485 int
7486 test_pdcp_proto_uplane_decap(int i)
7487 {
7488         return test_pdcp_proto(i, 0,
7489                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7490                 RTE_CRYPTO_AUTH_OP_VERIFY,
7491                 pdcp_test_data_out[i],
7492                 pdcp_test_data_in_len[i],
7493                 pdcp_test_data_in[i],
7494                 pdcp_test_data_in_len[i]);
7495 }
7496
7497 int
7498 test_pdcp_proto_uplane_decap_with_int(int i)
7499 {
7500         return test_pdcp_proto(i, 0,
7501                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7502                 RTE_CRYPTO_AUTH_OP_VERIFY,
7503                 pdcp_test_data_out[i],
7504                 pdcp_test_data_in_len[i] + 4,
7505                 pdcp_test_data_in[i],
7506                 pdcp_test_data_in_len[i]);
7507 }
7508
7509 static int
7510 test_PDCP_PROTO_SGL_in_place_32B(void)
7511 {
7512         /* i can be used for running any PDCP case
7513          * In this case it is uplane 12-bit AES-SNOW DL encap
7514          */
7515         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
7516         return test_pdcp_proto_SGL(i, IN_PLACE,
7517                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7518                         RTE_CRYPTO_AUTH_OP_GENERATE,
7519                         pdcp_test_data_in[i],
7520                         pdcp_test_data_in_len[i],
7521                         pdcp_test_data_out[i],
7522                         pdcp_test_data_in_len[i]+4,
7523                         32, 0);
7524 }
7525 static int
7526 test_PDCP_PROTO_SGL_oop_32B_128B(void)
7527 {
7528         /* i can be used for running any PDCP case
7529          * In this case it is uplane 18-bit NULL-NULL DL encap
7530          */
7531         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
7532         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7533                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7534                         RTE_CRYPTO_AUTH_OP_GENERATE,
7535                         pdcp_test_data_in[i],
7536                         pdcp_test_data_in_len[i],
7537                         pdcp_test_data_out[i],
7538                         pdcp_test_data_in_len[i]+4,
7539                         32, 128);
7540 }
7541 static int
7542 test_PDCP_PROTO_SGL_oop_32B_40B(void)
7543 {
7544         /* i can be used for running any PDCP case
7545          * In this case it is uplane 18-bit AES DL encap
7546          */
7547         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
7548                         + DOWNLINK;
7549         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7550                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7551                         RTE_CRYPTO_AUTH_OP_GENERATE,
7552                         pdcp_test_data_in[i],
7553                         pdcp_test_data_in_len[i],
7554                         pdcp_test_data_out[i],
7555                         pdcp_test_data_in_len[i],
7556                         32, 40);
7557 }
7558 static int
7559 test_PDCP_PROTO_SGL_oop_128B_32B(void)
7560 {
7561         /* i can be used for running any PDCP case
7562          * In this case it is cplane 12-bit AES-ZUC DL encap
7563          */
7564         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
7565         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7566                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7567                         RTE_CRYPTO_AUTH_OP_GENERATE,
7568                         pdcp_test_data_in[i],
7569                         pdcp_test_data_in_len[i],
7570                         pdcp_test_data_out[i],
7571                         pdcp_test_data_in_len[i]+4,
7572                         128, 32);
7573 }
7574 #endif
7575
7576 static int
7577 test_AES_GCM_authenticated_encryption_test_case_1(void)
7578 {
7579         return test_authenticated_encryption(&gcm_test_case_1);
7580 }
7581
7582 static int
7583 test_AES_GCM_authenticated_encryption_test_case_2(void)
7584 {
7585         return test_authenticated_encryption(&gcm_test_case_2);
7586 }
7587
7588 static int
7589 test_AES_GCM_authenticated_encryption_test_case_3(void)
7590 {
7591         return test_authenticated_encryption(&gcm_test_case_3);
7592 }
7593
7594 static int
7595 test_AES_GCM_authenticated_encryption_test_case_4(void)
7596 {
7597         return test_authenticated_encryption(&gcm_test_case_4);
7598 }
7599
7600 static int
7601 test_AES_GCM_authenticated_encryption_test_case_5(void)
7602 {
7603         return test_authenticated_encryption(&gcm_test_case_5);
7604 }
7605
7606 static int
7607 test_AES_GCM_authenticated_encryption_test_case_6(void)
7608 {
7609         return test_authenticated_encryption(&gcm_test_case_6);
7610 }
7611
7612 static int
7613 test_AES_GCM_authenticated_encryption_test_case_7(void)
7614 {
7615         return test_authenticated_encryption(&gcm_test_case_7);
7616 }
7617
7618 static int
7619 test_AES_GCM_authenticated_encryption_test_case_8(void)
7620 {
7621         return test_authenticated_encryption(&gcm_test_case_8);
7622 }
7623
7624 static int
7625 test_AES_GCM_auth_encryption_test_case_192_1(void)
7626 {
7627         return test_authenticated_encryption(&gcm_test_case_192_1);
7628 }
7629
7630 static int
7631 test_AES_GCM_auth_encryption_test_case_192_2(void)
7632 {
7633         return test_authenticated_encryption(&gcm_test_case_192_2);
7634 }
7635
7636 static int
7637 test_AES_GCM_auth_encryption_test_case_192_3(void)
7638 {
7639         return test_authenticated_encryption(&gcm_test_case_192_3);
7640 }
7641
7642 static int
7643 test_AES_GCM_auth_encryption_test_case_192_4(void)
7644 {
7645         return test_authenticated_encryption(&gcm_test_case_192_4);
7646 }
7647
7648 static int
7649 test_AES_GCM_auth_encryption_test_case_192_5(void)
7650 {
7651         return test_authenticated_encryption(&gcm_test_case_192_5);
7652 }
7653
7654 static int
7655 test_AES_GCM_auth_encryption_test_case_192_6(void)
7656 {
7657         return test_authenticated_encryption(&gcm_test_case_192_6);
7658 }
7659
7660 static int
7661 test_AES_GCM_auth_encryption_test_case_192_7(void)
7662 {
7663         return test_authenticated_encryption(&gcm_test_case_192_7);
7664 }
7665
7666 static int
7667 test_AES_GCM_auth_encryption_test_case_256_1(void)
7668 {
7669         return test_authenticated_encryption(&gcm_test_case_256_1);
7670 }
7671
7672 static int
7673 test_AES_GCM_auth_encryption_test_case_256_2(void)
7674 {
7675         return test_authenticated_encryption(&gcm_test_case_256_2);
7676 }
7677
7678 static int
7679 test_AES_GCM_auth_encryption_test_case_256_3(void)
7680 {
7681         return test_authenticated_encryption(&gcm_test_case_256_3);
7682 }
7683
7684 static int
7685 test_AES_GCM_auth_encryption_test_case_256_4(void)
7686 {
7687         return test_authenticated_encryption(&gcm_test_case_256_4);
7688 }
7689
7690 static int
7691 test_AES_GCM_auth_encryption_test_case_256_5(void)
7692 {
7693         return test_authenticated_encryption(&gcm_test_case_256_5);
7694 }
7695
7696 static int
7697 test_AES_GCM_auth_encryption_test_case_256_6(void)
7698 {
7699         return test_authenticated_encryption(&gcm_test_case_256_6);
7700 }
7701
7702 static int
7703 test_AES_GCM_auth_encryption_test_case_256_7(void)
7704 {
7705         return test_authenticated_encryption(&gcm_test_case_256_7);
7706 }
7707
7708 static int
7709 test_AES_GCM_auth_encryption_test_case_aad_1(void)
7710 {
7711         return test_authenticated_encryption(&gcm_test_case_aad_1);
7712 }
7713
7714 static int
7715 test_AES_GCM_auth_encryption_test_case_aad_2(void)
7716 {
7717         return test_authenticated_encryption(&gcm_test_case_aad_2);
7718 }
7719
7720 static int
7721 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
7722 {
7723         struct aead_test_data tdata;
7724         int res;
7725
7726         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7727         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7728         tdata.iv.data[0] += 1;
7729         res = test_authenticated_encryption(&tdata);
7730         if (res == -ENOTSUP)
7731                 return res;
7732         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7733         return TEST_SUCCESS;
7734 }
7735
7736 static int
7737 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
7738 {
7739         struct aead_test_data tdata;
7740         int res;
7741
7742         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7743         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7744         tdata.plaintext.data[0] += 1;
7745         res = test_authenticated_encryption(&tdata);
7746         if (res == -ENOTSUP)
7747                 return res;
7748         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7749         return TEST_SUCCESS;
7750 }
7751
7752 static int
7753 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
7754 {
7755         struct aead_test_data tdata;
7756         int res;
7757
7758         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7759         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7760         tdata.ciphertext.data[0] += 1;
7761         res = test_authenticated_encryption(&tdata);
7762         if (res == -ENOTSUP)
7763                 return res;
7764         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7765         return TEST_SUCCESS;
7766 }
7767
7768 static int
7769 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
7770 {
7771         struct aead_test_data tdata;
7772         int res;
7773
7774         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7775         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7776         tdata.aad.len += 1;
7777         res = test_authenticated_encryption(&tdata);
7778         if (res == -ENOTSUP)
7779                 return res;
7780         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7781         return TEST_SUCCESS;
7782 }
7783
7784 static int
7785 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
7786 {
7787         struct aead_test_data tdata;
7788         uint8_t aad[gcm_test_case_7.aad.len];
7789         int res;
7790
7791         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7792         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7793         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
7794         aad[0] += 1;
7795         tdata.aad.data = aad;
7796         res = test_authenticated_encryption(&tdata);
7797         if (res == -ENOTSUP)
7798                 return res;
7799         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7800         return TEST_SUCCESS;
7801 }
7802
7803 static int
7804 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
7805 {
7806         struct aead_test_data tdata;
7807         int res;
7808
7809         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7810         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7811         tdata.auth_tag.data[0] += 1;
7812         res = test_authenticated_encryption(&tdata);
7813         if (res == -ENOTSUP)
7814                 return res;
7815         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7816         return TEST_SUCCESS;
7817 }
7818
7819 static int
7820 test_authenticated_decryption(const struct aead_test_data *tdata)
7821 {
7822         struct crypto_testsuite_params *ts_params = &testsuite_params;
7823         struct crypto_unittest_params *ut_params = &unittest_params;
7824
7825         int retval;
7826         uint8_t *plaintext;
7827         uint32_t i;
7828
7829         /* Verify the capabilities */
7830         struct rte_cryptodev_sym_capability_idx cap_idx;
7831         const struct rte_cryptodev_symmetric_capability *capability;
7832         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7833         cap_idx.algo.aead = tdata->algo;
7834         capability = rte_cryptodev_sym_capability_get(
7835                         ts_params->valid_devs[0], &cap_idx);
7836         if (capability == NULL)
7837                 return -ENOTSUP;
7838         if (rte_cryptodev_sym_capability_check_aead(
7839                         capability, tdata->key.len, tdata->auth_tag.len,
7840                         tdata->aad.len, tdata->iv.len))
7841                 return -ENOTSUP;
7842
7843         /* Create AEAD session */
7844         retval = create_aead_session(ts_params->valid_devs[0],
7845                         tdata->algo,
7846                         RTE_CRYPTO_AEAD_OP_DECRYPT,
7847                         tdata->key.data, tdata->key.len,
7848                         tdata->aad.len, tdata->auth_tag.len,
7849                         tdata->iv.len);
7850         if (retval < 0)
7851                 return retval;
7852
7853         /* alloc mbuf and set payload */
7854         if (tdata->aad.len > MBUF_SIZE) {
7855                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7856                 /* Populate full size of add data */
7857                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7858                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7859         } else
7860                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7861
7862         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7863                         rte_pktmbuf_tailroom(ut_params->ibuf));
7864
7865         /* Create AEAD operation */
7866         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
7867         if (retval < 0)
7868                 return retval;
7869
7870         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7871
7872         ut_params->op->sym->m_src = ut_params->ibuf;
7873
7874         /* Process crypto operation */
7875         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7876                         ut_params->op), "failed to process sym crypto op");
7877
7878         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7879                         "crypto op processing failed");
7880
7881         if (ut_params->op->sym->m_dst)
7882                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7883                                 uint8_t *);
7884         else
7885                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7886                                 uint8_t *,
7887                                 ut_params->op->sym->cipher.data.offset);
7888
7889         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
7890
7891         /* Validate obuf */
7892         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7893                         plaintext,
7894                         tdata->plaintext.data,
7895                         tdata->plaintext.len,
7896                         "Plaintext data not as expected");
7897
7898         TEST_ASSERT_EQUAL(ut_params->op->status,
7899                         RTE_CRYPTO_OP_STATUS_SUCCESS,
7900                         "Authentication failed");
7901
7902         return 0;
7903 }
7904
7905 static int
7906 test_AES_GCM_authenticated_decryption_test_case_1(void)
7907 {
7908         return test_authenticated_decryption(&gcm_test_case_1);
7909 }
7910
7911 static int
7912 test_AES_GCM_authenticated_decryption_test_case_2(void)
7913 {
7914         return test_authenticated_decryption(&gcm_test_case_2);
7915 }
7916
7917 static int
7918 test_AES_GCM_authenticated_decryption_test_case_3(void)
7919 {
7920         return test_authenticated_decryption(&gcm_test_case_3);
7921 }
7922
7923 static int
7924 test_AES_GCM_authenticated_decryption_test_case_4(void)
7925 {
7926         return test_authenticated_decryption(&gcm_test_case_4);
7927 }
7928
7929 static int
7930 test_AES_GCM_authenticated_decryption_test_case_5(void)
7931 {
7932         return test_authenticated_decryption(&gcm_test_case_5);
7933 }
7934
7935 static int
7936 test_AES_GCM_authenticated_decryption_test_case_6(void)
7937 {
7938         return test_authenticated_decryption(&gcm_test_case_6);
7939 }
7940
7941 static int
7942 test_AES_GCM_authenticated_decryption_test_case_7(void)
7943 {
7944         return test_authenticated_decryption(&gcm_test_case_7);
7945 }
7946
7947 static int
7948 test_AES_GCM_authenticated_decryption_test_case_8(void)
7949 {
7950         return test_authenticated_decryption(&gcm_test_case_8);
7951 }
7952
7953 static int
7954 test_AES_GCM_auth_decryption_test_case_192_1(void)
7955 {
7956         return test_authenticated_decryption(&gcm_test_case_192_1);
7957 }
7958
7959 static int
7960 test_AES_GCM_auth_decryption_test_case_192_2(void)
7961 {
7962         return test_authenticated_decryption(&gcm_test_case_192_2);
7963 }
7964
7965 static int
7966 test_AES_GCM_auth_decryption_test_case_192_3(void)
7967 {
7968         return test_authenticated_decryption(&gcm_test_case_192_3);
7969 }
7970
7971 static int
7972 test_AES_GCM_auth_decryption_test_case_192_4(void)
7973 {
7974         return test_authenticated_decryption(&gcm_test_case_192_4);
7975 }
7976
7977 static int
7978 test_AES_GCM_auth_decryption_test_case_192_5(void)
7979 {
7980         return test_authenticated_decryption(&gcm_test_case_192_5);
7981 }
7982
7983 static int
7984 test_AES_GCM_auth_decryption_test_case_192_6(void)
7985 {
7986         return test_authenticated_decryption(&gcm_test_case_192_6);
7987 }
7988
7989 static int
7990 test_AES_GCM_auth_decryption_test_case_192_7(void)
7991 {
7992         return test_authenticated_decryption(&gcm_test_case_192_7);
7993 }
7994
7995 static int
7996 test_AES_GCM_auth_decryption_test_case_256_1(void)
7997 {
7998         return test_authenticated_decryption(&gcm_test_case_256_1);
7999 }
8000
8001 static int
8002 test_AES_GCM_auth_decryption_test_case_256_2(void)
8003 {
8004         return test_authenticated_decryption(&gcm_test_case_256_2);
8005 }
8006
8007 static int
8008 test_AES_GCM_auth_decryption_test_case_256_3(void)
8009 {
8010         return test_authenticated_decryption(&gcm_test_case_256_3);
8011 }
8012
8013 static int
8014 test_AES_GCM_auth_decryption_test_case_256_4(void)
8015 {
8016         return test_authenticated_decryption(&gcm_test_case_256_4);
8017 }
8018
8019 static int
8020 test_AES_GCM_auth_decryption_test_case_256_5(void)
8021 {
8022         return test_authenticated_decryption(&gcm_test_case_256_5);
8023 }
8024
8025 static int
8026 test_AES_GCM_auth_decryption_test_case_256_6(void)
8027 {
8028         return test_authenticated_decryption(&gcm_test_case_256_6);
8029 }
8030
8031 static int
8032 test_AES_GCM_auth_decryption_test_case_256_7(void)
8033 {
8034         return test_authenticated_decryption(&gcm_test_case_256_7);
8035 }
8036
8037 static int
8038 test_AES_GCM_auth_decryption_test_case_aad_1(void)
8039 {
8040         return test_authenticated_decryption(&gcm_test_case_aad_1);
8041 }
8042
8043 static int
8044 test_AES_GCM_auth_decryption_test_case_aad_2(void)
8045 {
8046         return test_authenticated_decryption(&gcm_test_case_aad_2);
8047 }
8048
8049 static int
8050 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
8051 {
8052         struct aead_test_data tdata;
8053         int res;
8054
8055         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8056         tdata.iv.data[0] += 1;
8057         res = test_authenticated_decryption(&tdata);
8058         if (res == -ENOTSUP)
8059                 return res;
8060         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8061         return TEST_SUCCESS;
8062 }
8063
8064 static int
8065 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
8066 {
8067         struct aead_test_data tdata;
8068         int res;
8069
8070         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8071         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8072         tdata.plaintext.data[0] += 1;
8073         res = test_authenticated_decryption(&tdata);
8074         if (res == -ENOTSUP)
8075                 return res;
8076         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8077         return TEST_SUCCESS;
8078 }
8079
8080 static int
8081 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
8082 {
8083         struct aead_test_data tdata;
8084         int res;
8085
8086         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8087         tdata.ciphertext.data[0] += 1;
8088         res = test_authenticated_decryption(&tdata);
8089         if (res == -ENOTSUP)
8090                 return res;
8091         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8092         return TEST_SUCCESS;
8093 }
8094
8095 static int
8096 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
8097 {
8098         struct aead_test_data tdata;
8099         int res;
8100
8101         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8102         tdata.aad.len += 1;
8103         res = test_authenticated_decryption(&tdata);
8104         if (res == -ENOTSUP)
8105                 return res;
8106         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8107         return TEST_SUCCESS;
8108 }
8109
8110 static int
8111 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
8112 {
8113         struct aead_test_data tdata;
8114         uint8_t aad[gcm_test_case_7.aad.len];
8115         int res;
8116
8117         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8118         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
8119         aad[0] += 1;
8120         tdata.aad.data = aad;
8121         res = test_authenticated_decryption(&tdata);
8122         if (res == -ENOTSUP)
8123                 return res;
8124         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8125         return TEST_SUCCESS;
8126 }
8127
8128 static int
8129 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
8130 {
8131         struct aead_test_data tdata;
8132         int res;
8133
8134         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8135         tdata.auth_tag.data[0] += 1;
8136         res = test_authenticated_decryption(&tdata);
8137         if (res == -ENOTSUP)
8138                 return res;
8139         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
8140         return TEST_SUCCESS;
8141 }
8142
8143 static int
8144 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
8145 {
8146         struct crypto_testsuite_params *ts_params = &testsuite_params;
8147         struct crypto_unittest_params *ut_params = &unittest_params;
8148
8149         int retval;
8150         uint8_t *ciphertext, *auth_tag;
8151         uint16_t plaintext_pad_len;
8152
8153         /* Verify the capabilities */
8154         struct rte_cryptodev_sym_capability_idx cap_idx;
8155         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8156         cap_idx.algo.aead = tdata->algo;
8157         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8158                         &cap_idx) == NULL)
8159                 return -ENOTSUP;
8160
8161         /* Create AEAD session */
8162         retval = create_aead_session(ts_params->valid_devs[0],
8163                         tdata->algo,
8164                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8165                         tdata->key.data, tdata->key.len,
8166                         tdata->aad.len, tdata->auth_tag.len,
8167                         tdata->iv.len);
8168         if (retval < 0)
8169                 return retval;
8170
8171         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8172         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8173
8174         /* clear mbuf payload */
8175         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8176                         rte_pktmbuf_tailroom(ut_params->ibuf));
8177         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8178                         rte_pktmbuf_tailroom(ut_params->obuf));
8179
8180         /* Create AEAD operation */
8181         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8182         if (retval < 0)
8183                 return retval;
8184
8185         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8186
8187         ut_params->op->sym->m_src = ut_params->ibuf;
8188         ut_params->op->sym->m_dst = ut_params->obuf;
8189
8190         /* Process crypto operation */
8191         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8192                         ut_params->op), "failed to process sym crypto op");
8193
8194         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8195                         "crypto op processing failed");
8196
8197         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8198
8199         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8200                         ut_params->op->sym->cipher.data.offset);
8201         auth_tag = ciphertext + plaintext_pad_len;
8202
8203         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8204         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8205
8206         /* Validate obuf */
8207         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8208                         ciphertext,
8209                         tdata->ciphertext.data,
8210                         tdata->ciphertext.len,
8211                         "Ciphertext data not as expected");
8212
8213         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8214                         auth_tag,
8215                         tdata->auth_tag.data,
8216                         tdata->auth_tag.len,
8217                         "Generated auth tag not as expected");
8218
8219         return 0;
8220
8221 }
8222
8223 static int
8224 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
8225 {
8226         return test_authenticated_encryption_oop(&gcm_test_case_5);
8227 }
8228
8229 static int
8230 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
8231 {
8232         struct crypto_testsuite_params *ts_params = &testsuite_params;
8233         struct crypto_unittest_params *ut_params = &unittest_params;
8234
8235         int retval;
8236         uint8_t *plaintext;
8237
8238         /* Verify the capabilities */
8239         struct rte_cryptodev_sym_capability_idx cap_idx;
8240         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8241         cap_idx.algo.aead = tdata->algo;
8242         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8243                         &cap_idx) == NULL)
8244                 return -ENOTSUP;
8245
8246         /* Create AEAD session */
8247         retval = create_aead_session(ts_params->valid_devs[0],
8248                         tdata->algo,
8249                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8250                         tdata->key.data, tdata->key.len,
8251                         tdata->aad.len, tdata->auth_tag.len,
8252                         tdata->iv.len);
8253         if (retval < 0)
8254                 return retval;
8255
8256         /* alloc mbuf and set payload */
8257         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8258         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8259
8260         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8261                         rte_pktmbuf_tailroom(ut_params->ibuf));
8262         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8263                         rte_pktmbuf_tailroom(ut_params->obuf));
8264
8265         /* Create AEAD operation */
8266         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8267         if (retval < 0)
8268                 return retval;
8269
8270         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8271
8272         ut_params->op->sym->m_src = ut_params->ibuf;
8273         ut_params->op->sym->m_dst = ut_params->obuf;
8274
8275         /* Process crypto operation */
8276         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8277                         ut_params->op), "failed to process sym crypto op");
8278
8279         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8280                         "crypto op processing failed");
8281
8282         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8283                         ut_params->op->sym->cipher.data.offset);
8284
8285         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8286
8287         /* Validate obuf */
8288         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8289                         plaintext,
8290                         tdata->plaintext.data,
8291                         tdata->plaintext.len,
8292                         "Plaintext data not as expected");
8293
8294         TEST_ASSERT_EQUAL(ut_params->op->status,
8295                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8296                         "Authentication failed");
8297         return 0;
8298 }
8299
8300 static int
8301 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
8302 {
8303         return test_authenticated_decryption_oop(&gcm_test_case_5);
8304 }
8305
8306 static int
8307 test_authenticated_encryption_sessionless(
8308                 const struct aead_test_data *tdata)
8309 {
8310         struct crypto_testsuite_params *ts_params = &testsuite_params;
8311         struct crypto_unittest_params *ut_params = &unittest_params;
8312
8313         int retval;
8314         uint8_t *ciphertext, *auth_tag;
8315         uint16_t plaintext_pad_len;
8316         uint8_t key[tdata->key.len + 1];
8317
8318         /* This test is for AESNI MB and AESNI GCM PMDs only */
8319         if ((gbl_driver_id != rte_cryptodev_driver_id_get(
8320                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) &&
8321                         (gbl_driver_id != rte_cryptodev_driver_id_get(
8322                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))))
8323                 return -ENOTSUP;
8324
8325         /* Verify the capabilities */
8326         struct rte_cryptodev_sym_capability_idx cap_idx;
8327         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8328         cap_idx.algo.aead = tdata->algo;
8329         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8330                         &cap_idx) == NULL)
8331                 return -ENOTSUP;
8332
8333         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8334
8335         /* clear mbuf payload */
8336         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8337                         rte_pktmbuf_tailroom(ut_params->ibuf));
8338
8339         /* Create AEAD operation */
8340         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8341         if (retval < 0)
8342                 return retval;
8343
8344         /* Create GCM xform */
8345         memcpy(key, tdata->key.data, tdata->key.len);
8346         retval = create_aead_xform(ut_params->op,
8347                         tdata->algo,
8348                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8349                         key, tdata->key.len,
8350                         tdata->aad.len, tdata->auth_tag.len,
8351                         tdata->iv.len);
8352         if (retval < 0)
8353                 return retval;
8354
8355         ut_params->op->sym->m_src = ut_params->ibuf;
8356
8357         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8358                         RTE_CRYPTO_OP_SESSIONLESS,
8359                         "crypto op session type not sessionless");
8360
8361         /* Process crypto operation */
8362         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8363                         ut_params->op), "failed to process sym crypto op");
8364
8365         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8366
8367         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8368                         "crypto op status not success");
8369
8370         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8371
8372         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8373                         ut_params->op->sym->cipher.data.offset);
8374         auth_tag = ciphertext + plaintext_pad_len;
8375
8376         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8377         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8378
8379         /* Validate obuf */
8380         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8381                         ciphertext,
8382                         tdata->ciphertext.data,
8383                         tdata->ciphertext.len,
8384                         "Ciphertext data not as expected");
8385
8386         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8387                         auth_tag,
8388                         tdata->auth_tag.data,
8389                         tdata->auth_tag.len,
8390                         "Generated auth tag not as expected");
8391
8392         return 0;
8393
8394 }
8395
8396 static int
8397 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
8398 {
8399         return test_authenticated_encryption_sessionless(
8400                         &gcm_test_case_5);
8401 }
8402
8403 static int
8404 test_authenticated_decryption_sessionless(
8405                 const struct aead_test_data *tdata)
8406 {
8407         struct crypto_testsuite_params *ts_params = &testsuite_params;
8408         struct crypto_unittest_params *ut_params = &unittest_params;
8409
8410         int retval;
8411         uint8_t *plaintext;
8412         uint8_t key[tdata->key.len + 1];
8413
8414         /* This test is for AESNI MB and AESNI GCM PMDs only */
8415         if ((gbl_driver_id != rte_cryptodev_driver_id_get(
8416                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) &&
8417                         (gbl_driver_id != rte_cryptodev_driver_id_get(
8418                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))))
8419                 return -ENOTSUP;
8420
8421         /* Verify the capabilities */
8422         struct rte_cryptodev_sym_capability_idx cap_idx;
8423         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8424         cap_idx.algo.aead = tdata->algo;
8425         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8426                         &cap_idx) == NULL)
8427                 return -ENOTSUP;
8428
8429         /* alloc mbuf and set payload */
8430         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8431
8432         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8433                         rte_pktmbuf_tailroom(ut_params->ibuf));
8434
8435         /* Create AEAD operation */
8436         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8437         if (retval < 0)
8438                 return retval;
8439
8440         /* Create AEAD xform */
8441         memcpy(key, tdata->key.data, tdata->key.len);
8442         retval = create_aead_xform(ut_params->op,
8443                         tdata->algo,
8444                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8445                         key, tdata->key.len,
8446                         tdata->aad.len, tdata->auth_tag.len,
8447                         tdata->iv.len);
8448         if (retval < 0)
8449                 return retval;
8450
8451         ut_params->op->sym->m_src = ut_params->ibuf;
8452
8453         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8454                         RTE_CRYPTO_OP_SESSIONLESS,
8455                         "crypto op session type not sessionless");
8456
8457         /* Process crypto operation */
8458         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8459                         ut_params->op), "failed to process sym crypto op");
8460
8461         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8462
8463         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8464                         "crypto op status not success");
8465
8466         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8467                         ut_params->op->sym->cipher.data.offset);
8468
8469         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8470
8471         /* Validate obuf */
8472         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8473                         plaintext,
8474                         tdata->plaintext.data,
8475                         tdata->plaintext.len,
8476                         "Plaintext data not as expected");
8477
8478         TEST_ASSERT_EQUAL(ut_params->op->status,
8479                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8480                         "Authentication failed");
8481         return 0;
8482 }
8483
8484 static int
8485 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
8486 {
8487         return test_authenticated_decryption_sessionless(
8488                         &gcm_test_case_5);
8489 }
8490
8491 static int
8492 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
8493 {
8494         return test_authenticated_encryption(&ccm_test_case_128_1);
8495 }
8496
8497 static int
8498 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
8499 {
8500         return test_authenticated_encryption(&ccm_test_case_128_2);
8501 }
8502
8503 static int
8504 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
8505 {
8506         return test_authenticated_encryption(&ccm_test_case_128_3);
8507 }
8508
8509 static int
8510 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
8511 {
8512         return test_authenticated_decryption(&ccm_test_case_128_1);
8513 }
8514
8515 static int
8516 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
8517 {
8518         return test_authenticated_decryption(&ccm_test_case_128_2);
8519 }
8520
8521 static int
8522 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
8523 {
8524         return test_authenticated_decryption(&ccm_test_case_128_3);
8525 }
8526
8527 static int
8528 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
8529 {
8530         return test_authenticated_encryption(&ccm_test_case_192_1);
8531 }
8532
8533 static int
8534 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
8535 {
8536         return test_authenticated_encryption(&ccm_test_case_192_2);
8537 }
8538
8539 static int
8540 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
8541 {
8542         return test_authenticated_encryption(&ccm_test_case_192_3);
8543 }
8544
8545 static int
8546 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
8547 {
8548         return test_authenticated_decryption(&ccm_test_case_192_1);
8549 }
8550
8551 static int
8552 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
8553 {
8554         return test_authenticated_decryption(&ccm_test_case_192_2);
8555 }
8556
8557 static int
8558 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
8559 {
8560         return test_authenticated_decryption(&ccm_test_case_192_3);
8561 }
8562
8563 static int
8564 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
8565 {
8566         return test_authenticated_encryption(&ccm_test_case_256_1);
8567 }
8568
8569 static int
8570 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
8571 {
8572         return test_authenticated_encryption(&ccm_test_case_256_2);
8573 }
8574
8575 static int
8576 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
8577 {
8578         return test_authenticated_encryption(&ccm_test_case_256_3);
8579 }
8580
8581 static int
8582 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
8583 {
8584         return test_authenticated_decryption(&ccm_test_case_256_1);
8585 }
8586
8587 static int
8588 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
8589 {
8590         return test_authenticated_decryption(&ccm_test_case_256_2);
8591 }
8592
8593 static int
8594 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
8595 {
8596         return test_authenticated_decryption(&ccm_test_case_256_3);
8597 }
8598
8599 static int
8600 test_stats(void)
8601 {
8602         struct crypto_testsuite_params *ts_params = &testsuite_params;
8603         struct rte_cryptodev_stats stats;
8604         struct rte_cryptodev *dev;
8605         cryptodev_stats_get_t temp_pfn;
8606
8607         /* Verify the capabilities */
8608         struct rte_cryptodev_sym_capability_idx cap_idx;
8609         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8610         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
8611         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8612                         &cap_idx) == NULL)
8613                 return -ENOTSUP;
8614         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8615         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
8616         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8617                         &cap_idx) == NULL)
8618                 return -ENOTSUP;
8619
8620         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8621         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
8622                         &stats) == -ENODEV),
8623                 "rte_cryptodev_stats_get invalid dev failed");
8624         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
8625                 "rte_cryptodev_stats_get invalid Param failed");
8626         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
8627         temp_pfn = dev->dev_ops->stats_get;
8628         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
8629         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
8630                         == -ENOTSUP),
8631                 "rte_cryptodev_stats_get invalid Param failed");
8632         dev->dev_ops->stats_get = temp_pfn;
8633
8634         /* Test expected values */
8635         ut_setup();
8636         test_AES_CBC_HMAC_SHA1_encrypt_digest();
8637         ut_teardown();
8638         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8639                         &stats),
8640                 "rte_cryptodev_stats_get failed");
8641         TEST_ASSERT((stats.enqueued_count == 1),
8642                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8643         TEST_ASSERT((stats.dequeued_count == 1),
8644                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8645         TEST_ASSERT((stats.enqueue_err_count == 0),
8646                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8647         TEST_ASSERT((stats.dequeue_err_count == 0),
8648                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8649
8650         /* invalid device but should ignore and not reset device stats*/
8651         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
8652         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8653                         &stats),
8654                 "rte_cryptodev_stats_get failed");
8655         TEST_ASSERT((stats.enqueued_count == 1),
8656                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8657
8658         /* check that a valid reset clears stats */
8659         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8660         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8661                         &stats),
8662                                           "rte_cryptodev_stats_get failed");
8663         TEST_ASSERT((stats.enqueued_count == 0),
8664                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8665         TEST_ASSERT((stats.dequeued_count == 0),
8666                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8667
8668         return TEST_SUCCESS;
8669 }
8670
8671 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
8672                                    struct crypto_unittest_params *ut_params,
8673                                    enum rte_crypto_auth_operation op,
8674                                    const struct HMAC_MD5_vector *test_case)
8675 {
8676         uint8_t key[64];
8677
8678         memcpy(key, test_case->key.data, test_case->key.len);
8679
8680         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8681         ut_params->auth_xform.next = NULL;
8682         ut_params->auth_xform.auth.op = op;
8683
8684         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
8685
8686         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
8687         ut_params->auth_xform.auth.key.length = test_case->key.len;
8688         ut_params->auth_xform.auth.key.data = key;
8689
8690         ut_params->sess = rte_cryptodev_sym_session_create(
8691                         ts_params->session_mpool);
8692
8693         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8694                         ut_params->sess, &ut_params->auth_xform,
8695                         ts_params->session_priv_mpool);
8696
8697         if (ut_params->sess == NULL)
8698                 return TEST_FAILED;
8699
8700         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8701
8702         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8703                         rte_pktmbuf_tailroom(ut_params->ibuf));
8704
8705         return 0;
8706 }
8707
8708 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
8709                               const struct HMAC_MD5_vector *test_case,
8710                               uint8_t **plaintext)
8711 {
8712         uint16_t plaintext_pad_len;
8713
8714         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8715
8716         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8717                                 16);
8718
8719         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8720                         plaintext_pad_len);
8721         memcpy(*plaintext, test_case->plaintext.data,
8722                         test_case->plaintext.len);
8723
8724         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
8725                         ut_params->ibuf, MD5_DIGEST_LEN);
8726         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
8727                         "no room to append digest");
8728         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
8729                         ut_params->ibuf, plaintext_pad_len);
8730
8731         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
8732                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
8733                            test_case->auth_tag.len);
8734         }
8735
8736         sym_op->auth.data.offset = 0;
8737         sym_op->auth.data.length = test_case->plaintext.len;
8738
8739         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8740         ut_params->op->sym->m_src = ut_params->ibuf;
8741
8742         return 0;
8743 }
8744
8745 static int
8746 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
8747 {
8748         uint16_t plaintext_pad_len;
8749         uint8_t *plaintext, *auth_tag;
8750
8751         struct crypto_testsuite_params *ts_params = &testsuite_params;
8752         struct crypto_unittest_params *ut_params = &unittest_params;
8753
8754         /* Verify the capabilities */
8755         struct rte_cryptodev_sym_capability_idx cap_idx;
8756         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8757         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
8758         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8759                         &cap_idx) == NULL)
8760                 return -ENOTSUP;
8761
8762         if (MD5_HMAC_create_session(ts_params, ut_params,
8763                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
8764                 return TEST_FAILED;
8765
8766         /* Generate Crypto op data structure */
8767         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8768                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8769         TEST_ASSERT_NOT_NULL(ut_params->op,
8770                         "Failed to allocate symmetric crypto operation struct");
8771
8772         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8773                                 16);
8774
8775         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
8776                 return TEST_FAILED;
8777
8778         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8779                         ut_params->op), "failed to process sym crypto op");
8780
8781         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8782                         "crypto op processing failed");
8783
8784         if (ut_params->op->sym->m_dst) {
8785                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8786                                 uint8_t *, plaintext_pad_len);
8787         } else {
8788                 auth_tag = plaintext + plaintext_pad_len;
8789         }
8790
8791         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8792                         auth_tag,
8793                         test_case->auth_tag.data,
8794                         test_case->auth_tag.len,
8795                         "HMAC_MD5 generated tag not as expected");
8796
8797         return TEST_SUCCESS;
8798 }
8799
8800 static int
8801 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
8802 {
8803         uint8_t *plaintext;
8804
8805         struct crypto_testsuite_params *ts_params = &testsuite_params;
8806         struct crypto_unittest_params *ut_params = &unittest_params;
8807
8808         /* Verify the capabilities */
8809         struct rte_cryptodev_sym_capability_idx cap_idx;
8810         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8811         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
8812         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8813                         &cap_idx) == NULL)
8814                 return -ENOTSUP;
8815
8816         if (MD5_HMAC_create_session(ts_params, ut_params,
8817                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
8818                 return TEST_FAILED;
8819         }
8820
8821         /* Generate Crypto op data structure */
8822         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8823                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8824         TEST_ASSERT_NOT_NULL(ut_params->op,
8825                         "Failed to allocate symmetric crypto operation struct");
8826
8827         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
8828                 return TEST_FAILED;
8829
8830         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8831                         ut_params->op), "failed to process sym crypto op");
8832
8833         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8834                         "HMAC_MD5 crypto op processing failed");
8835
8836         return TEST_SUCCESS;
8837 }
8838
8839 static int
8840 test_MD5_HMAC_generate_case_1(void)
8841 {
8842         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
8843 }
8844
8845 static int
8846 test_MD5_HMAC_verify_case_1(void)
8847 {
8848         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
8849 }
8850
8851 static int
8852 test_MD5_HMAC_generate_case_2(void)
8853 {
8854         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
8855 }
8856
8857 static int
8858 test_MD5_HMAC_verify_case_2(void)
8859 {
8860         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
8861 }
8862
8863 static int
8864 test_multi_session(void)
8865 {
8866         struct crypto_testsuite_params *ts_params = &testsuite_params;
8867         struct crypto_unittest_params *ut_params = &unittest_params;
8868
8869         struct rte_cryptodev_info dev_info;
8870         struct rte_cryptodev_sym_session **sessions;
8871
8872         uint16_t i;
8873
8874         /* Verify the capabilities */
8875         struct rte_cryptodev_sym_capability_idx cap_idx;
8876         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8877         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
8878         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8879                         &cap_idx) == NULL)
8880                 return -ENOTSUP;
8881         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8882         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
8883         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8884                         &cap_idx) == NULL)
8885                 return -ENOTSUP;
8886
8887         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
8888                         aes_cbc_key, hmac_sha512_key);
8889
8890
8891         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8892
8893         sessions = rte_malloc(NULL,
8894                         (sizeof(struct rte_cryptodev_sym_session *) *
8895                         MAX_NB_SESSIONS) + 1, 0);
8896
8897         /* Create multiple crypto sessions*/
8898         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8899
8900                 sessions[i] = rte_cryptodev_sym_session_create(
8901                                 ts_params->session_mpool);
8902
8903                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8904                                 sessions[i], &ut_params->auth_xform,
8905                                 ts_params->session_priv_mpool);
8906                 TEST_ASSERT_NOT_NULL(sessions[i],
8907                                 "Session creation failed at session number %u",
8908                                 i);
8909
8910                 /* Attempt to send a request on each session */
8911                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
8912                         sessions[i],
8913                         ut_params,
8914                         ts_params,
8915                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
8916                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
8917                         aes_cbc_iv),
8918                         "Failed to perform decrypt on request number %u.", i);
8919                 /* free crypto operation structure */
8920                 if (ut_params->op)
8921                         rte_crypto_op_free(ut_params->op);
8922
8923                 /*
8924                  * free mbuf - both obuf and ibuf are usually the same,
8925                  * so check if they point at the same address is necessary,
8926                  * to avoid freeing the mbuf twice.
8927                  */
8928                 if (ut_params->obuf) {
8929                         rte_pktmbuf_free(ut_params->obuf);
8930                         if (ut_params->ibuf == ut_params->obuf)
8931                                 ut_params->ibuf = 0;
8932                         ut_params->obuf = 0;
8933                 }
8934                 if (ut_params->ibuf) {
8935                         rte_pktmbuf_free(ut_params->ibuf);
8936                         ut_params->ibuf = 0;
8937                 }
8938         }
8939
8940         /* Next session create should fail */
8941         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8942                         sessions[i], &ut_params->auth_xform,
8943                         ts_params->session_priv_mpool);
8944         TEST_ASSERT_NULL(sessions[i],
8945                         "Session creation succeeded unexpectedly!");
8946
8947         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8948                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
8949                                 sessions[i]);
8950                 rte_cryptodev_sym_session_free(sessions[i]);
8951         }
8952
8953         rte_free(sessions);
8954
8955         return TEST_SUCCESS;
8956 }
8957
8958 struct multi_session_params {
8959         struct crypto_unittest_params ut_params;
8960         uint8_t *cipher_key;
8961         uint8_t *hmac_key;
8962         const uint8_t *cipher;
8963         const uint8_t *digest;
8964         uint8_t *iv;
8965 };
8966
8967 #define MB_SESSION_NUMBER 3
8968
8969 static int
8970 test_multi_session_random_usage(void)
8971 {
8972         struct crypto_testsuite_params *ts_params = &testsuite_params;
8973         struct rte_cryptodev_info dev_info;
8974         struct rte_cryptodev_sym_session **sessions;
8975         uint32_t i, j;
8976         struct multi_session_params ut_paramz[] = {
8977
8978                 {
8979                         .cipher_key = ms_aes_cbc_key0,
8980                         .hmac_key = ms_hmac_key0,
8981                         .cipher = ms_aes_cbc_cipher0,
8982                         .digest = ms_hmac_digest0,
8983                         .iv = ms_aes_cbc_iv0
8984                 },
8985                 {
8986                         .cipher_key = ms_aes_cbc_key1,
8987                         .hmac_key = ms_hmac_key1,
8988                         .cipher = ms_aes_cbc_cipher1,
8989                         .digest = ms_hmac_digest1,
8990                         .iv = ms_aes_cbc_iv1
8991                 },
8992                 {
8993                         .cipher_key = ms_aes_cbc_key2,
8994                         .hmac_key = ms_hmac_key2,
8995                         .cipher = ms_aes_cbc_cipher2,
8996                         .digest = ms_hmac_digest2,
8997                         .iv = ms_aes_cbc_iv2
8998                 },
8999
9000         };
9001
9002         /* Verify the capabilities */
9003         struct rte_cryptodev_sym_capability_idx cap_idx;
9004         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9005         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9006         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9007                         &cap_idx) == NULL)
9008                 return -ENOTSUP;
9009         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9010         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9011         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9012                         &cap_idx) == NULL)
9013                 return -ENOTSUP;
9014
9015         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9016
9017         sessions = rte_malloc(NULL,
9018                         (sizeof(struct rte_cryptodev_sym_session *)
9019                                         * MAX_NB_SESSIONS) + 1, 0);
9020
9021         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9022                 sessions[i] = rte_cryptodev_sym_session_create(
9023                                 ts_params->session_mpool);
9024
9025                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
9026                                 sizeof(struct crypto_unittest_params));
9027
9028                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
9029                                 &ut_paramz[i].ut_params,
9030                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
9031
9032                 /* Create multiple crypto sessions*/
9033                 rte_cryptodev_sym_session_init(
9034                                 ts_params->valid_devs[0],
9035                                 sessions[i],
9036                                 &ut_paramz[i].ut_params.auth_xform,
9037                                 ts_params->session_priv_mpool);
9038
9039                 TEST_ASSERT_NOT_NULL(sessions[i],
9040                                 "Session creation failed at session number %u",
9041                                 i);
9042
9043         }
9044
9045         srand(time(NULL));
9046         for (i = 0; i < 40000; i++) {
9047
9048                 j = rand() % MB_SESSION_NUMBER;
9049
9050                 TEST_ASSERT_SUCCESS(
9051                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
9052                                         sessions[j],
9053                                         &ut_paramz[j].ut_params,
9054                                         ts_params, ut_paramz[j].cipher,
9055                                         ut_paramz[j].digest,
9056                                         ut_paramz[j].iv),
9057                         "Failed to perform decrypt on request number %u.", i);
9058
9059                 if (ut_paramz[j].ut_params.op)
9060                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
9061
9062                 /*
9063                  * free mbuf - both obuf and ibuf are usually the same,
9064                  * so check if they point at the same address is necessary,
9065                  * to avoid freeing the mbuf twice.
9066                  */
9067                 if (ut_paramz[j].ut_params.obuf) {
9068                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
9069                         if (ut_paramz[j].ut_params.ibuf
9070                                         == ut_paramz[j].ut_params.obuf)
9071                                 ut_paramz[j].ut_params.ibuf = 0;
9072                         ut_paramz[j].ut_params.obuf = 0;
9073                 }
9074                 if (ut_paramz[j].ut_params.ibuf) {
9075                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
9076                         ut_paramz[j].ut_params.ibuf = 0;
9077                 }
9078         }
9079
9080         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9081                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9082                                 sessions[i]);
9083                 rte_cryptodev_sym_session_free(sessions[i]);
9084         }
9085
9086         rte_free(sessions);
9087
9088         return TEST_SUCCESS;
9089 }
9090
9091 static int
9092 test_null_cipher_only_operation(void)
9093 {
9094         struct crypto_testsuite_params *ts_params = &testsuite_params;
9095         struct crypto_unittest_params *ut_params = &unittest_params;
9096
9097         /* Verify the capabilities */
9098         struct rte_cryptodev_sym_capability_idx cap_idx;
9099         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9100         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9101         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9102                         &cap_idx) == NULL)
9103                 return -ENOTSUP;
9104
9105         /* Generate test mbuf data and space for digest */
9106         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9107                         catch_22_quote, QUOTE_512_BYTES, 0);
9108
9109         /* Setup Cipher Parameters */
9110         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9111         ut_params->cipher_xform.next = NULL;
9112
9113         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9114         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9115
9116         ut_params->sess = rte_cryptodev_sym_session_create(
9117                         ts_params->session_mpool);
9118
9119         /* Create Crypto session*/
9120         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9121                                 ut_params->sess,
9122                                 &ut_params->cipher_xform,
9123                                 ts_params->session_priv_mpool);
9124         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9125
9126         /* Generate Crypto op data structure */
9127         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9128                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9129         TEST_ASSERT_NOT_NULL(ut_params->op,
9130                         "Failed to allocate symmetric crypto operation struct");
9131
9132         /* Set crypto operation data parameters */
9133         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9134
9135         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9136
9137         /* set crypto operation source mbuf */
9138         sym_op->m_src = ut_params->ibuf;
9139
9140         sym_op->cipher.data.offset = 0;
9141         sym_op->cipher.data.length = QUOTE_512_BYTES;
9142
9143         /* Process crypto operation */
9144         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9145                         ut_params->op);
9146         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9147
9148         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9149                         "crypto operation processing failed");
9150
9151         /* Validate obuf */
9152         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9153                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9154                         catch_22_quote,
9155                         QUOTE_512_BYTES,
9156                         "Ciphertext data not as expected");
9157
9158         return TEST_SUCCESS;
9159 }
9160 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
9161                         0xab, 0xab, 0xab, 0xab,
9162                         0xab, 0xab, 0xab, 0xab,
9163                         0xab, 0xab, 0xab, 0xab};
9164 static int
9165 test_null_auth_only_operation(void)
9166 {
9167         struct crypto_testsuite_params *ts_params = &testsuite_params;
9168         struct crypto_unittest_params *ut_params = &unittest_params;
9169         uint8_t *digest;
9170
9171         /* Verify the capabilities */
9172         struct rte_cryptodev_sym_capability_idx cap_idx;
9173         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9174         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9175         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9176                         &cap_idx) == NULL)
9177                 return -ENOTSUP;
9178
9179         /* Generate test mbuf data and space for digest */
9180         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9181                         catch_22_quote, QUOTE_512_BYTES, 0);
9182
9183         /* create a pointer for digest, but don't expect anything to be written
9184          * here in a NULL auth algo so no mbuf append done.
9185          */
9186         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9187                         QUOTE_512_BYTES);
9188         /* prefill the memory pointed to by digest */
9189         memcpy(digest, orig_data, sizeof(orig_data));
9190
9191         /* Setup HMAC Parameters */
9192         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9193         ut_params->auth_xform.next = NULL;
9194
9195         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9196         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9197
9198         ut_params->sess = rte_cryptodev_sym_session_create(
9199                         ts_params->session_mpool);
9200
9201         /* Create Crypto session*/
9202         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9203                         ut_params->sess, &ut_params->auth_xform,
9204                         ts_params->session_priv_mpool);
9205         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9206
9207         /* Generate Crypto op data structure */
9208         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9209                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9210         TEST_ASSERT_NOT_NULL(ut_params->op,
9211                         "Failed to allocate symmetric crypto operation struct");
9212
9213         /* Set crypto operation data parameters */
9214         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9215
9216         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9217
9218         sym_op->m_src = ut_params->ibuf;
9219
9220         sym_op->auth.data.offset = 0;
9221         sym_op->auth.data.length = QUOTE_512_BYTES;
9222         sym_op->auth.digest.data = digest;
9223         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9224                         QUOTE_512_BYTES);
9225
9226         /* Process crypto operation */
9227         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9228                         ut_params->op);
9229         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9230
9231         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9232                         "crypto operation processing failed");
9233         /* Make sure memory pointed to by digest hasn't been overwritten */
9234         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9235                         orig_data,
9236                         digest,
9237                         sizeof(orig_data),
9238                         "Memory at digest ptr overwritten unexpectedly");
9239
9240         return TEST_SUCCESS;
9241 }
9242
9243
9244 static int
9245 test_null_cipher_auth_operation(void)
9246 {
9247         struct crypto_testsuite_params *ts_params = &testsuite_params;
9248         struct crypto_unittest_params *ut_params = &unittest_params;
9249         uint8_t *digest;
9250
9251         /* Verify the capabilities */
9252         struct rte_cryptodev_sym_capability_idx cap_idx;
9253         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9254         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9255         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9256                         &cap_idx) == NULL)
9257                 return -ENOTSUP;
9258         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9259         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9260         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9261                         &cap_idx) == NULL)
9262                 return -ENOTSUP;
9263
9264         /* Generate test mbuf data and space for digest */
9265         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9266                         catch_22_quote, QUOTE_512_BYTES, 0);
9267
9268         /* create a pointer for digest, but don't expect anything to be written
9269          * here in a NULL auth algo so no mbuf append done.
9270          */
9271         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9272                         QUOTE_512_BYTES);
9273         /* prefill the memory pointed to by digest */
9274         memcpy(digest, orig_data, sizeof(orig_data));
9275
9276         /* Setup Cipher Parameters */
9277         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9278         ut_params->cipher_xform.next = &ut_params->auth_xform;
9279
9280         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9281         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9282
9283         /* Setup HMAC Parameters */
9284         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9285         ut_params->auth_xform.next = NULL;
9286
9287         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9288         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9289
9290         ut_params->sess = rte_cryptodev_sym_session_create(
9291                         ts_params->session_mpool);
9292
9293         /* Create Crypto session*/
9294         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9295                         ut_params->sess, &ut_params->cipher_xform,
9296                         ts_params->session_priv_mpool);
9297         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9298
9299         /* Generate Crypto op data structure */
9300         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9301                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9302         TEST_ASSERT_NOT_NULL(ut_params->op,
9303                         "Failed to allocate symmetric crypto operation struct");
9304
9305         /* Set crypto operation data parameters */
9306         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9307
9308         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9309
9310         sym_op->m_src = ut_params->ibuf;
9311
9312         sym_op->cipher.data.offset = 0;
9313         sym_op->cipher.data.length = QUOTE_512_BYTES;
9314
9315         sym_op->auth.data.offset = 0;
9316         sym_op->auth.data.length = QUOTE_512_BYTES;
9317         sym_op->auth.digest.data = digest;
9318         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9319                         QUOTE_512_BYTES);
9320
9321         /* Process crypto operation */
9322         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9323                         ut_params->op);
9324         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9325
9326         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9327                         "crypto operation processing failed");
9328
9329         /* Validate obuf */
9330         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9331                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9332                         catch_22_quote,
9333                         QUOTE_512_BYTES,
9334                         "Ciphertext data not as expected");
9335         /* Make sure memory pointed to by digest hasn't been overwritten */
9336         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9337                         orig_data,
9338                         digest,
9339                         sizeof(orig_data),
9340                         "Memory at digest ptr overwritten unexpectedly");
9341
9342         return TEST_SUCCESS;
9343 }
9344
9345 static int
9346 test_null_auth_cipher_operation(void)
9347 {
9348         struct crypto_testsuite_params *ts_params = &testsuite_params;
9349         struct crypto_unittest_params *ut_params = &unittest_params;
9350         uint8_t *digest;
9351
9352         /* Verify the capabilities */
9353         struct rte_cryptodev_sym_capability_idx cap_idx;
9354         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9355         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9356         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9357                         &cap_idx) == NULL)
9358                 return -ENOTSUP;
9359         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9360         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9361         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9362                         &cap_idx) == NULL)
9363                 return -ENOTSUP;
9364
9365         /* Generate test mbuf data */
9366         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9367                         catch_22_quote, QUOTE_512_BYTES, 0);
9368
9369         /* create a pointer for digest, but don't expect anything to be written
9370          * here in a NULL auth algo so no mbuf append done.
9371          */
9372         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9373                                 QUOTE_512_BYTES);
9374         /* prefill the memory pointed to by digest */
9375         memcpy(digest, orig_data, sizeof(orig_data));
9376
9377         /* Setup Cipher Parameters */
9378         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9379         ut_params->cipher_xform.next = NULL;
9380
9381         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9382         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9383
9384         /* Setup HMAC Parameters */
9385         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9386         ut_params->auth_xform.next = &ut_params->cipher_xform;
9387
9388         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9389         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9390
9391         ut_params->sess = rte_cryptodev_sym_session_create(
9392                         ts_params->session_mpool);
9393
9394         /* Create Crypto session*/
9395         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9396                         ut_params->sess, &ut_params->cipher_xform,
9397                         ts_params->session_priv_mpool);
9398         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9399
9400         /* Generate Crypto op data structure */
9401         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9402                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9403         TEST_ASSERT_NOT_NULL(ut_params->op,
9404                         "Failed to allocate symmetric crypto operation struct");
9405
9406         /* Set crypto operation data parameters */
9407         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9408
9409         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9410
9411         sym_op->m_src = ut_params->ibuf;
9412
9413         sym_op->cipher.data.offset = 0;
9414         sym_op->cipher.data.length = QUOTE_512_BYTES;
9415
9416         sym_op->auth.data.offset = 0;
9417         sym_op->auth.data.length = QUOTE_512_BYTES;
9418         sym_op->auth.digest.data = digest;
9419         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9420                                         QUOTE_512_BYTES);
9421
9422         /* Process crypto operation */
9423         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9424                         ut_params->op);
9425         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9426
9427         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9428                         "crypto operation processing failed");
9429
9430         /* Validate obuf */
9431         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9432                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9433                         catch_22_quote,
9434                         QUOTE_512_BYTES,
9435                         "Ciphertext data not as expected");
9436         /* Make sure memory pointed to by digest hasn't been overwritten */
9437         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9438                         orig_data,
9439                         digest,
9440                         sizeof(orig_data),
9441                         "Memory at digest ptr overwritten unexpectedly");
9442
9443         return TEST_SUCCESS;
9444 }
9445
9446
9447 static int
9448 test_null_invalid_operation(void)
9449 {
9450         struct crypto_testsuite_params *ts_params = &testsuite_params;
9451         struct crypto_unittest_params *ut_params = &unittest_params;
9452         int ret;
9453
9454         /* This test is for NULL PMD only */
9455         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9456                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9457                 return -ENOTSUP;
9458
9459         /* Setup Cipher Parameters */
9460         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9461         ut_params->cipher_xform.next = NULL;
9462
9463         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
9464         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9465
9466         ut_params->sess = rte_cryptodev_sym_session_create(
9467                         ts_params->session_mpool);
9468
9469         /* Create Crypto session*/
9470         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9471                         ut_params->sess, &ut_params->cipher_xform,
9472                         ts_params->session_priv_mpool);
9473         TEST_ASSERT(ret < 0,
9474                         "Session creation succeeded unexpectedly");
9475
9476
9477         /* Setup HMAC Parameters */
9478         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9479         ut_params->auth_xform.next = NULL;
9480
9481         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
9482         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9483
9484         ut_params->sess = rte_cryptodev_sym_session_create(
9485                         ts_params->session_mpool);
9486
9487         /* Create Crypto session*/
9488         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9489                         ut_params->sess, &ut_params->auth_xform,
9490                         ts_params->session_priv_mpool);
9491         TEST_ASSERT(ret < 0,
9492                         "Session creation succeeded unexpectedly");
9493
9494         return TEST_SUCCESS;
9495 }
9496
9497
9498 #define NULL_BURST_LENGTH (32)
9499
9500 static int
9501 test_null_burst_operation(void)
9502 {
9503         struct crypto_testsuite_params *ts_params = &testsuite_params;
9504         struct crypto_unittest_params *ut_params = &unittest_params;
9505
9506         unsigned i, burst_len = NULL_BURST_LENGTH;
9507
9508         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
9509         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
9510
9511         /* This test is for NULL PMD only */
9512         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9513                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9514                 return -ENOTSUP;
9515
9516         /* Setup Cipher Parameters */
9517         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9518         ut_params->cipher_xform.next = &ut_params->auth_xform;
9519
9520         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9521         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9522
9523         /* Setup HMAC Parameters */
9524         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9525         ut_params->auth_xform.next = NULL;
9526
9527         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9528         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9529
9530         ut_params->sess = rte_cryptodev_sym_session_create(
9531                         ts_params->session_mpool);
9532
9533         /* Create Crypto session*/
9534         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9535                         ut_params->sess, &ut_params->cipher_xform,
9536                         ts_params->session_priv_mpool);
9537         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9538
9539         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
9540                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
9541                         burst_len, "failed to generate burst of crypto ops");
9542
9543         /* Generate an operation for each mbuf in burst */
9544         for (i = 0; i < burst_len; i++) {
9545                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9546
9547                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
9548
9549                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
9550                                 sizeof(unsigned));
9551                 *data = i;
9552
9553                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
9554
9555                 burst[i]->sym->m_src = m;
9556         }
9557
9558         /* Process crypto operation */
9559         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
9560                         0, burst, burst_len),
9561                         burst_len,
9562                         "Error enqueuing burst");
9563
9564         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
9565                         0, burst_dequeued, burst_len),
9566                         burst_len,
9567                         "Error dequeuing burst");
9568
9569
9570         for (i = 0; i < burst_len; i++) {
9571                 TEST_ASSERT_EQUAL(
9572                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
9573                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
9574                                         uint32_t *),
9575                         "data not as expected");
9576
9577                 rte_pktmbuf_free(burst[i]->sym->m_src);
9578                 rte_crypto_op_free(burst[i]);
9579         }
9580
9581         return TEST_SUCCESS;
9582 }
9583
9584 static void
9585 generate_gmac_large_plaintext(uint8_t *data)
9586 {
9587         uint16_t i;
9588
9589         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
9590                 memcpy(&data[i], &data[0], 32);
9591 }
9592
9593 static int
9594 create_gmac_operation(enum rte_crypto_auth_operation op,
9595                 const struct gmac_test_data *tdata)
9596 {
9597         struct crypto_testsuite_params *ts_params = &testsuite_params;
9598         struct crypto_unittest_params *ut_params = &unittest_params;
9599         struct rte_crypto_sym_op *sym_op;
9600
9601         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9602
9603         /* Generate Crypto op data structure */
9604         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9605                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9606         TEST_ASSERT_NOT_NULL(ut_params->op,
9607                         "Failed to allocate symmetric crypto operation struct");
9608
9609         sym_op = ut_params->op->sym;
9610
9611         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9612                         ut_params->ibuf, tdata->gmac_tag.len);
9613         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9614                         "no room to append digest");
9615
9616         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9617                         ut_params->ibuf, plaintext_pad_len);
9618
9619         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9620                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
9621                                 tdata->gmac_tag.len);
9622                 debug_hexdump(stdout, "digest:",
9623                                 sym_op->auth.digest.data,
9624                                 tdata->gmac_tag.len);
9625         }
9626
9627         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9628                         uint8_t *, IV_OFFSET);
9629
9630         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
9631
9632         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
9633
9634         sym_op->cipher.data.length = 0;
9635         sym_op->cipher.data.offset = 0;
9636
9637         sym_op->auth.data.offset = 0;
9638         sym_op->auth.data.length = tdata->plaintext.len;
9639
9640         return 0;
9641 }
9642
9643 static int create_gmac_session(uint8_t dev_id,
9644                 const struct gmac_test_data *tdata,
9645                 enum rte_crypto_auth_operation auth_op)
9646 {
9647         uint8_t auth_key[tdata->key.len];
9648
9649         struct crypto_testsuite_params *ts_params = &testsuite_params;
9650         struct crypto_unittest_params *ut_params = &unittest_params;
9651
9652         memcpy(auth_key, tdata->key.data, tdata->key.len);
9653
9654         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9655         ut_params->auth_xform.next = NULL;
9656
9657         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
9658         ut_params->auth_xform.auth.op = auth_op;
9659         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
9660         ut_params->auth_xform.auth.key.length = tdata->key.len;
9661         ut_params->auth_xform.auth.key.data = auth_key;
9662         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
9663         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
9664
9665
9666         ut_params->sess = rte_cryptodev_sym_session_create(
9667                         ts_params->session_mpool);
9668
9669         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
9670                         &ut_params->auth_xform,
9671                         ts_params->session_priv_mpool);
9672
9673         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9674
9675         return 0;
9676 }
9677
9678 static int
9679 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
9680 {
9681         struct crypto_testsuite_params *ts_params = &testsuite_params;
9682         struct crypto_unittest_params *ut_params = &unittest_params;
9683
9684         int retval;
9685
9686         uint8_t *auth_tag, *plaintext;
9687         uint16_t plaintext_pad_len;
9688
9689         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
9690                               "No GMAC length in the source data");
9691
9692         /* Verify the capabilities */
9693         struct rte_cryptodev_sym_capability_idx cap_idx;
9694         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9695         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
9696         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9697                         &cap_idx) == NULL)
9698                 return -ENOTSUP;
9699
9700         retval = create_gmac_session(ts_params->valid_devs[0],
9701                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
9702
9703         if (retval < 0)
9704                 return retval;
9705
9706         if (tdata->plaintext.len > MBUF_SIZE)
9707                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9708         else
9709                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9710         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9711                         "Failed to allocate input buffer in mempool");
9712
9713         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9714                         rte_pktmbuf_tailroom(ut_params->ibuf));
9715
9716         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9717         /*
9718          * Runtime generate the large plain text instead of use hard code
9719          * plain text vector. It is done to avoid create huge source file
9720          * with the test vector.
9721          */
9722         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
9723                 generate_gmac_large_plaintext(tdata->plaintext.data);
9724
9725         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9726                                 plaintext_pad_len);
9727         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9728
9729         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9730         debug_hexdump(stdout, "plaintext:", plaintext,
9731                         tdata->plaintext.len);
9732
9733         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
9734                         tdata);
9735
9736         if (retval < 0)
9737                 return retval;
9738
9739         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9740
9741         ut_params->op->sym->m_src = ut_params->ibuf;
9742
9743         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9744                         ut_params->op), "failed to process sym crypto op");
9745
9746         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9747                         "crypto op processing failed");
9748
9749         if (ut_params->op->sym->m_dst) {
9750                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9751                                 uint8_t *, plaintext_pad_len);
9752         } else {
9753                 auth_tag = plaintext + plaintext_pad_len;
9754         }
9755
9756         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
9757
9758         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9759                         auth_tag,
9760                         tdata->gmac_tag.data,
9761                         tdata->gmac_tag.len,
9762                         "GMAC Generated auth tag not as expected");
9763
9764         return 0;
9765 }
9766
9767 static int
9768 test_AES_GMAC_authentication_test_case_1(void)
9769 {
9770         return test_AES_GMAC_authentication(&gmac_test_case_1);
9771 }
9772
9773 static int
9774 test_AES_GMAC_authentication_test_case_2(void)
9775 {
9776         return test_AES_GMAC_authentication(&gmac_test_case_2);
9777 }
9778
9779 static int
9780 test_AES_GMAC_authentication_test_case_3(void)
9781 {
9782         return test_AES_GMAC_authentication(&gmac_test_case_3);
9783 }
9784
9785 static int
9786 test_AES_GMAC_authentication_test_case_4(void)
9787 {
9788         return test_AES_GMAC_authentication(&gmac_test_case_4);
9789 }
9790
9791 static int
9792 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
9793 {
9794         struct crypto_testsuite_params *ts_params = &testsuite_params;
9795         struct crypto_unittest_params *ut_params = &unittest_params;
9796         int retval;
9797         uint32_t plaintext_pad_len;
9798         uint8_t *plaintext;
9799
9800         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
9801                               "No GMAC length in the source data");
9802
9803         /* Verify the capabilities */
9804         struct rte_cryptodev_sym_capability_idx cap_idx;
9805         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9806         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
9807         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9808                         &cap_idx) == NULL)
9809                 return -ENOTSUP;
9810
9811         retval = create_gmac_session(ts_params->valid_devs[0],
9812                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
9813
9814         if (retval < 0)
9815                 return retval;
9816
9817         if (tdata->plaintext.len > MBUF_SIZE)
9818                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9819         else
9820                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9821         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9822                         "Failed to allocate input buffer in mempool");
9823
9824         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9825                         rte_pktmbuf_tailroom(ut_params->ibuf));
9826
9827         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9828
9829         /*
9830          * Runtime generate the large plain text instead of use hard code
9831          * plain text vector. It is done to avoid create huge source file
9832          * with the test vector.
9833          */
9834         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
9835                 generate_gmac_large_plaintext(tdata->plaintext.data);
9836
9837         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9838                                 plaintext_pad_len);
9839         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9840
9841         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9842         debug_hexdump(stdout, "plaintext:", plaintext,
9843                         tdata->plaintext.len);
9844
9845         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
9846                         tdata);
9847
9848         if (retval < 0)
9849                 return retval;
9850
9851         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9852
9853         ut_params->op->sym->m_src = ut_params->ibuf;
9854
9855         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9856                         ut_params->op), "failed to process sym crypto op");
9857
9858         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9859                         "crypto op processing failed");
9860
9861         return 0;
9862
9863 }
9864
9865 static int
9866 test_AES_GMAC_authentication_verify_test_case_1(void)
9867 {
9868         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
9869 }
9870
9871 static int
9872 test_AES_GMAC_authentication_verify_test_case_2(void)
9873 {
9874         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
9875 }
9876
9877 static int
9878 test_AES_GMAC_authentication_verify_test_case_3(void)
9879 {
9880         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
9881 }
9882
9883 static int
9884 test_AES_GMAC_authentication_verify_test_case_4(void)
9885 {
9886         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
9887 }
9888
9889 struct test_crypto_vector {
9890         enum rte_crypto_cipher_algorithm crypto_algo;
9891         unsigned int cipher_offset;
9892         unsigned int cipher_len;
9893
9894         struct {
9895                 uint8_t data[64];
9896                 unsigned int len;
9897         } cipher_key;
9898
9899         struct {
9900                 uint8_t data[64];
9901                 unsigned int len;
9902         } iv;
9903
9904         struct {
9905                 const uint8_t *data;
9906                 unsigned int len;
9907         } plaintext;
9908
9909         struct {
9910                 const uint8_t *data;
9911                 unsigned int len;
9912         } ciphertext;
9913
9914         enum rte_crypto_auth_algorithm auth_algo;
9915         unsigned int auth_offset;
9916
9917         struct {
9918                 uint8_t data[128];
9919                 unsigned int len;
9920         } auth_key;
9921
9922         struct {
9923                 const uint8_t *data;
9924                 unsigned int len;
9925         } aad;
9926
9927         struct {
9928                 uint8_t data[128];
9929                 unsigned int len;
9930         } digest;
9931 };
9932
9933 static const struct test_crypto_vector
9934 hmac_sha1_test_crypto_vector = {
9935         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
9936         .plaintext = {
9937                 .data = plaintext_hash,
9938                 .len = 512
9939         },
9940         .auth_key = {
9941                 .data = {
9942                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
9943                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
9944                         0xDE, 0xF4, 0xDE, 0xAD
9945                 },
9946                 .len = 20
9947         },
9948         .digest = {
9949                 .data = {
9950                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
9951                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
9952                         0x3F, 0x91, 0x64, 0x59
9953                 },
9954                 .len = 20
9955         }
9956 };
9957
9958 static const struct test_crypto_vector
9959 aes128_gmac_test_vector = {
9960         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
9961         .plaintext = {
9962                 .data = plaintext_hash,
9963                 .len = 512
9964         },
9965         .iv = {
9966                 .data = {
9967                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9968                         0x08, 0x09, 0x0A, 0x0B
9969                 },
9970                 .len = 12
9971         },
9972         .auth_key = {
9973                 .data = {
9974                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
9975                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
9976                 },
9977                 .len = 16
9978         },
9979         .digest = {
9980                 .data = {
9981                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
9982                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
9983                 },
9984                 .len = 16
9985         }
9986 };
9987
9988 static const struct test_crypto_vector
9989 aes128cbc_hmac_sha1_test_vector = {
9990         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
9991         .cipher_offset = 0,
9992         .cipher_len = 512,
9993         .cipher_key = {
9994                 .data = {
9995                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
9996                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
9997                 },
9998                 .len = 16
9999         },
10000         .iv = {
10001                 .data = {
10002                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10003                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10004                 },
10005                 .len = 16
10006         },
10007         .plaintext = {
10008                 .data = plaintext_hash,
10009                 .len = 512
10010         },
10011         .ciphertext = {
10012                 .data = ciphertext512_aes128cbc,
10013                 .len = 512
10014         },
10015         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10016         .auth_offset = 0,
10017         .auth_key = {
10018                 .data = {
10019                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10020                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10021                         0xDE, 0xF4, 0xDE, 0xAD
10022                 },
10023                 .len = 20
10024         },
10025         .digest = {
10026                 .data = {
10027                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
10028                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10029                         0x18, 0x8C, 0x1D, 0x32
10030                 },
10031                 .len = 20
10032         }
10033 };
10034
10035 static const struct test_crypto_vector
10036 aes128cbc_hmac_sha1_aad_test_vector = {
10037         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10038         .cipher_offset = 12,
10039         .cipher_len = 496,
10040         .cipher_key = {
10041                 .data = {
10042                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10043                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10044                 },
10045                 .len = 16
10046         },
10047         .iv = {
10048                 .data = {
10049                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10050                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10051                 },
10052                 .len = 16
10053         },
10054         .plaintext = {
10055                 .data = plaintext_hash,
10056                 .len = 512
10057         },
10058         .ciphertext = {
10059                 .data = ciphertext512_aes128cbc_aad,
10060                 .len = 512
10061         },
10062         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10063         .auth_offset = 0,
10064         .auth_key = {
10065                 .data = {
10066                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10067                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10068                         0xDE, 0xF4, 0xDE, 0xAD
10069                 },
10070                 .len = 20
10071         },
10072         .digest = {
10073                 .data = {
10074                         0x1F, 0x6A, 0xD2, 0x8B, 0x4B, 0xB3, 0xC0, 0x9E,
10075                         0x86, 0x9B, 0x3A, 0xF2, 0x00, 0x5B, 0x4F, 0x08,
10076                         0x62, 0x8D, 0x62, 0x65
10077                 },
10078                 .len = 20
10079         }
10080 };
10081
10082 static void
10083 data_corruption(uint8_t *data)
10084 {
10085         data[0] += 1;
10086 }
10087
10088 static void
10089 tag_corruption(uint8_t *data, unsigned int tag_offset)
10090 {
10091         data[tag_offset] += 1;
10092 }
10093
10094 static int
10095 create_auth_session(struct crypto_unittest_params *ut_params,
10096                 uint8_t dev_id,
10097                 const struct test_crypto_vector *reference,
10098                 enum rte_crypto_auth_operation auth_op)
10099 {
10100         struct crypto_testsuite_params *ts_params = &testsuite_params;
10101         uint8_t auth_key[reference->auth_key.len + 1];
10102
10103         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10104
10105         /* Setup Authentication Parameters */
10106         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10107         ut_params->auth_xform.auth.op = auth_op;
10108         ut_params->auth_xform.next = NULL;
10109         ut_params->auth_xform.auth.algo = reference->auth_algo;
10110         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10111         ut_params->auth_xform.auth.key.data = auth_key;
10112         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10113
10114         /* Create Crypto session*/
10115         ut_params->sess = rte_cryptodev_sym_session_create(
10116                         ts_params->session_mpool);
10117
10118         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10119                                 &ut_params->auth_xform,
10120                                 ts_params->session_priv_mpool);
10121
10122         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10123
10124         return 0;
10125 }
10126
10127 static int
10128 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
10129                 uint8_t dev_id,
10130                 const struct test_crypto_vector *reference,
10131                 enum rte_crypto_auth_operation auth_op,
10132                 enum rte_crypto_cipher_operation cipher_op)
10133 {
10134         struct crypto_testsuite_params *ts_params = &testsuite_params;
10135         uint8_t cipher_key[reference->cipher_key.len + 1];
10136         uint8_t auth_key[reference->auth_key.len + 1];
10137
10138         memcpy(cipher_key, reference->cipher_key.data,
10139                         reference->cipher_key.len);
10140         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10141
10142         /* Setup Authentication Parameters */
10143         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10144         ut_params->auth_xform.auth.op = auth_op;
10145         ut_params->auth_xform.auth.algo = reference->auth_algo;
10146         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10147         ut_params->auth_xform.auth.key.data = auth_key;
10148         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10149
10150         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
10151                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10152                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
10153         } else {
10154                 ut_params->auth_xform.next = &ut_params->cipher_xform;
10155
10156                 /* Setup Cipher Parameters */
10157                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10158                 ut_params->cipher_xform.next = NULL;
10159                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10160                 ut_params->cipher_xform.cipher.op = cipher_op;
10161                 ut_params->cipher_xform.cipher.key.data = cipher_key;
10162                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10163                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10164                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10165         }
10166
10167         /* Create Crypto session*/
10168         ut_params->sess = rte_cryptodev_sym_session_create(
10169                         ts_params->session_mpool);
10170
10171         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10172                                 &ut_params->auth_xform,
10173                                 ts_params->session_priv_mpool);
10174
10175         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10176
10177         return 0;
10178 }
10179
10180 static int
10181 create_auth_operation(struct crypto_testsuite_params *ts_params,
10182                 struct crypto_unittest_params *ut_params,
10183                 const struct test_crypto_vector *reference,
10184                 unsigned int auth_generate)
10185 {
10186         /* Generate Crypto op data structure */
10187         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10188                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10189         TEST_ASSERT_NOT_NULL(ut_params->op,
10190                         "Failed to allocate pktmbuf offload");
10191
10192         /* Set crypto operation data parameters */
10193         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10194
10195         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10196
10197         /* set crypto operation source mbuf */
10198         sym_op->m_src = ut_params->ibuf;
10199
10200         /* digest */
10201         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10202                         ut_params->ibuf, reference->digest.len);
10203
10204         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10205                         "no room to append auth tag");
10206
10207         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10208                         ut_params->ibuf, reference->plaintext.len);
10209
10210         if (auth_generate)
10211                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10212         else
10213                 memcpy(sym_op->auth.digest.data,
10214                                 reference->digest.data,
10215                                 reference->digest.len);
10216
10217         debug_hexdump(stdout, "digest:",
10218                         sym_op->auth.digest.data,
10219                         reference->digest.len);
10220
10221         sym_op->auth.data.length = reference->plaintext.len;
10222         sym_op->auth.data.offset = 0;
10223
10224         return 0;
10225 }
10226
10227 static int
10228 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
10229                 struct crypto_unittest_params *ut_params,
10230                 const struct test_crypto_vector *reference,
10231                 unsigned int auth_generate)
10232 {
10233         /* Generate Crypto op data structure */
10234         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10235                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10236         TEST_ASSERT_NOT_NULL(ut_params->op,
10237                         "Failed to allocate pktmbuf offload");
10238
10239         /* Set crypto operation data parameters */
10240         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10241
10242         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10243
10244         /* set crypto operation source mbuf */
10245         sym_op->m_src = ut_params->ibuf;
10246
10247         /* digest */
10248         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10249                         ut_params->ibuf, reference->digest.len);
10250
10251         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10252                         "no room to append auth tag");
10253
10254         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10255                         ut_params->ibuf, reference->ciphertext.len);
10256
10257         if (auth_generate)
10258                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10259         else
10260                 memcpy(sym_op->auth.digest.data,
10261                                 reference->digest.data,
10262                                 reference->digest.len);
10263
10264         debug_hexdump(stdout, "digest:",
10265                         sym_op->auth.digest.data,
10266                         reference->digest.len);
10267
10268         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10269                         reference->iv.data, reference->iv.len);
10270
10271         sym_op->cipher.data.length = 0;
10272         sym_op->cipher.data.offset = 0;
10273
10274         sym_op->auth.data.length = reference->plaintext.len;
10275         sym_op->auth.data.offset = 0;
10276
10277         return 0;
10278 }
10279
10280 static int
10281 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
10282                 struct crypto_unittest_params *ut_params,
10283                 const struct test_crypto_vector *reference,
10284                 unsigned int auth_generate)
10285 {
10286         /* Generate Crypto op data structure */
10287         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10288                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10289         TEST_ASSERT_NOT_NULL(ut_params->op,
10290                         "Failed to allocate pktmbuf offload");
10291
10292         /* Set crypto operation data parameters */
10293         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10294
10295         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10296
10297         /* set crypto operation source mbuf */
10298         sym_op->m_src = ut_params->ibuf;
10299
10300         /* digest */
10301         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10302                         ut_params->ibuf, reference->digest.len);
10303
10304         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10305                         "no room to append auth tag");
10306
10307         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10308                         ut_params->ibuf, reference->ciphertext.len);
10309
10310         if (auth_generate)
10311                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10312         else
10313                 memcpy(sym_op->auth.digest.data,
10314                                 reference->digest.data,
10315                                 reference->digest.len);
10316
10317         debug_hexdump(stdout, "digest:",
10318                         sym_op->auth.digest.data,
10319                         reference->digest.len);
10320
10321         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10322                         reference->iv.data, reference->iv.len);
10323
10324         sym_op->cipher.data.length = reference->cipher_len;
10325         sym_op->cipher.data.offset = reference->cipher_offset;
10326
10327         sym_op->auth.data.length = reference->plaintext.len;
10328         sym_op->auth.data.offset = reference->auth_offset;
10329
10330         return 0;
10331 }
10332
10333 static int
10334 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10335                 struct crypto_unittest_params *ut_params,
10336                 const struct test_crypto_vector *reference)
10337 {
10338         return create_auth_operation(ts_params, ut_params, reference, 0);
10339 }
10340
10341 static int
10342 create_auth_verify_GMAC_operation(
10343                 struct crypto_testsuite_params *ts_params,
10344                 struct crypto_unittest_params *ut_params,
10345                 const struct test_crypto_vector *reference)
10346 {
10347         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
10348 }
10349
10350 static int
10351 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10352                 struct crypto_unittest_params *ut_params,
10353                 const struct test_crypto_vector *reference)
10354 {
10355         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
10356 }
10357
10358 static int
10359 test_authentication_verify_fail_when_data_corruption(
10360                 struct crypto_testsuite_params *ts_params,
10361                 struct crypto_unittest_params *ut_params,
10362                 const struct test_crypto_vector *reference,
10363                 unsigned int data_corrupted)
10364 {
10365         int retval;
10366
10367         uint8_t *plaintext;
10368
10369         /* Verify the capabilities */
10370         struct rte_cryptodev_sym_capability_idx cap_idx;
10371         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10372         cap_idx.algo.auth = reference->auth_algo;
10373         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10374                         &cap_idx) == NULL)
10375                 return -ENOTSUP;
10376
10377         /* Create session */
10378         retval = create_auth_session(ut_params,
10379                         ts_params->valid_devs[0],
10380                         reference,
10381                         RTE_CRYPTO_AUTH_OP_VERIFY);
10382         if (retval < 0)
10383                 return retval;
10384
10385         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10386         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10387                         "Failed to allocate input buffer in mempool");
10388
10389         /* clear mbuf payload */
10390         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10391                         rte_pktmbuf_tailroom(ut_params->ibuf));
10392
10393         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10394                         reference->plaintext.len);
10395         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10396         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10397
10398         debug_hexdump(stdout, "plaintext:", plaintext,
10399                 reference->plaintext.len);
10400
10401         /* Create operation */
10402         retval = create_auth_verify_operation(ts_params, ut_params, reference);
10403
10404         if (retval < 0)
10405                 return retval;
10406
10407         if (data_corrupted)
10408                 data_corruption(plaintext);
10409         else
10410                 tag_corruption(plaintext, reference->plaintext.len);
10411
10412         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10413                         ut_params->op);
10414
10415         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10416
10417         return 0;
10418 }
10419
10420 static int
10421 test_authentication_verify_GMAC_fail_when_corruption(
10422                 struct crypto_testsuite_params *ts_params,
10423                 struct crypto_unittest_params *ut_params,
10424                 const struct test_crypto_vector *reference,
10425                 unsigned int data_corrupted)
10426 {
10427         int retval;
10428         uint8_t *plaintext;
10429
10430         /* Verify the capabilities */
10431         struct rte_cryptodev_sym_capability_idx cap_idx;
10432         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10433         cap_idx.algo.auth = reference->auth_algo;
10434         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10435                         &cap_idx) == NULL)
10436                 return -ENOTSUP;
10437
10438         /* Create session */
10439         retval = create_auth_cipher_session(ut_params,
10440                         ts_params->valid_devs[0],
10441                         reference,
10442                         RTE_CRYPTO_AUTH_OP_VERIFY,
10443                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10444         if (retval < 0)
10445                 return retval;
10446
10447         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10448         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10449                         "Failed to allocate input buffer in mempool");
10450
10451         /* clear mbuf payload */
10452         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10453                         rte_pktmbuf_tailroom(ut_params->ibuf));
10454
10455         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10456                         reference->plaintext.len);
10457         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10458         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10459
10460         debug_hexdump(stdout, "plaintext:", plaintext,
10461                 reference->plaintext.len);
10462
10463         /* Create operation */
10464         retval = create_auth_verify_GMAC_operation(ts_params,
10465                         ut_params,
10466                         reference);
10467
10468         if (retval < 0)
10469                 return retval;
10470
10471         if (data_corrupted)
10472                 data_corruption(plaintext);
10473         else
10474                 tag_corruption(plaintext, reference->aad.len);
10475
10476         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10477                         ut_params->op);
10478
10479         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10480
10481         return 0;
10482 }
10483
10484 static int
10485 test_authenticated_decryption_fail_when_corruption(
10486                 struct crypto_testsuite_params *ts_params,
10487                 struct crypto_unittest_params *ut_params,
10488                 const struct test_crypto_vector *reference,
10489                 unsigned int data_corrupted)
10490 {
10491         int retval;
10492
10493         uint8_t *ciphertext;
10494
10495         /* Verify the capabilities */
10496         struct rte_cryptodev_sym_capability_idx cap_idx;
10497         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10498         cap_idx.algo.auth = reference->auth_algo;
10499         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10500                         &cap_idx) == NULL)
10501                 return -ENOTSUP;
10502         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10503         cap_idx.algo.cipher = reference->crypto_algo;
10504         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10505                         &cap_idx) == NULL)
10506                 return -ENOTSUP;
10507
10508         /* Create session */
10509         retval = create_auth_cipher_session(ut_params,
10510                         ts_params->valid_devs[0],
10511                         reference,
10512                         RTE_CRYPTO_AUTH_OP_VERIFY,
10513                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10514         if (retval < 0)
10515                 return retval;
10516
10517         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10518         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10519                         "Failed to allocate input buffer in mempool");
10520
10521         /* clear mbuf payload */
10522         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10523                         rte_pktmbuf_tailroom(ut_params->ibuf));
10524
10525         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10526                         reference->ciphertext.len);
10527         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10528         memcpy(ciphertext, reference->ciphertext.data,
10529                         reference->ciphertext.len);
10530
10531         /* Create operation */
10532         retval = create_cipher_auth_verify_operation(ts_params,
10533                         ut_params,
10534                         reference);
10535
10536         if (retval < 0)
10537                 return retval;
10538
10539         if (data_corrupted)
10540                 data_corruption(ciphertext);
10541         else
10542                 tag_corruption(ciphertext, reference->ciphertext.len);
10543
10544         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10545                         ut_params->op);
10546
10547         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10548
10549         return 0;
10550 }
10551
10552 static int
10553 test_authenticated_encryt_with_esn(
10554                 struct crypto_testsuite_params *ts_params,
10555                 struct crypto_unittest_params *ut_params,
10556                 const struct test_crypto_vector *reference)
10557 {
10558         int retval;
10559
10560         uint8_t *authciphertext, *plaintext, *auth_tag;
10561         uint16_t plaintext_pad_len;
10562         uint8_t cipher_key[reference->cipher_key.len + 1];
10563         uint8_t auth_key[reference->auth_key.len + 1];
10564
10565         /* Verify the capabilities */
10566         struct rte_cryptodev_sym_capability_idx cap_idx;
10567         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10568         cap_idx.algo.auth = reference->auth_algo;
10569         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10570                         &cap_idx) == NULL)
10571                 return -ENOTSUP;
10572         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10573         cap_idx.algo.cipher = reference->crypto_algo;
10574         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10575                         &cap_idx) == NULL)
10576                 return -ENOTSUP;
10577
10578         /* Create session */
10579         memcpy(cipher_key, reference->cipher_key.data,
10580                         reference->cipher_key.len);
10581         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10582
10583         /* Setup Cipher Parameters */
10584         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10585         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10586         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10587         ut_params->cipher_xform.cipher.key.data = cipher_key;
10588         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10589         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10590         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10591
10592         ut_params->cipher_xform.next = &ut_params->auth_xform;
10593
10594         /* Setup Authentication Parameters */
10595         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10596         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10597         ut_params->auth_xform.auth.algo = reference->auth_algo;
10598         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10599         ut_params->auth_xform.auth.key.data = auth_key;
10600         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10601         ut_params->auth_xform.next = NULL;
10602
10603         /* Create Crypto session*/
10604         ut_params->sess = rte_cryptodev_sym_session_create(
10605                         ts_params->session_mpool);
10606
10607         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10608                                 ut_params->sess,
10609                                 &ut_params->cipher_xform,
10610                                 ts_params->session_priv_mpool);
10611
10612         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10613
10614         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10615         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10616                         "Failed to allocate input buffer in mempool");
10617
10618         /* clear mbuf payload */
10619         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10620                         rte_pktmbuf_tailroom(ut_params->ibuf));
10621
10622         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10623                         reference->plaintext.len);
10624         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10625         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10626
10627         /* Create operation */
10628         retval = create_cipher_auth_operation(ts_params,
10629                         ut_params,
10630                         reference, 0);
10631
10632         if (retval < 0)
10633                 return retval;
10634
10635         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10636                         ut_params->op);
10637
10638         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
10639
10640         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10641                         "crypto op processing failed");
10642
10643         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
10644
10645         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10646                         ut_params->op->sym->auth.data.offset);
10647         auth_tag = authciphertext + plaintext_pad_len;
10648         debug_hexdump(stdout, "ciphertext:", authciphertext,
10649                         reference->ciphertext.len);
10650         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
10651
10652         /* Validate obuf */
10653         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10654                         authciphertext,
10655                         reference->ciphertext.data,
10656                         reference->ciphertext.len,
10657                         "Ciphertext data not as expected");
10658
10659         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10660                         auth_tag,
10661                         reference->digest.data,
10662                         reference->digest.len,
10663                         "Generated digest not as expected");
10664
10665         return TEST_SUCCESS;
10666
10667 }
10668
10669 static int
10670 test_authenticated_decrypt_with_esn(
10671                 struct crypto_testsuite_params *ts_params,
10672                 struct crypto_unittest_params *ut_params,
10673                 const struct test_crypto_vector *reference)
10674 {
10675         int retval;
10676
10677         uint8_t *ciphertext;
10678         uint8_t cipher_key[reference->cipher_key.len + 1];
10679         uint8_t auth_key[reference->auth_key.len + 1];
10680
10681         /* Verify the capabilities */
10682         struct rte_cryptodev_sym_capability_idx cap_idx;
10683         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10684         cap_idx.algo.auth = reference->auth_algo;
10685         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10686                         &cap_idx) == NULL)
10687                 return -ENOTSUP;
10688         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10689         cap_idx.algo.cipher = reference->crypto_algo;
10690         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10691                         &cap_idx) == NULL)
10692                 return -ENOTSUP;
10693
10694         /* Create session */
10695         memcpy(cipher_key, reference->cipher_key.data,
10696                         reference->cipher_key.len);
10697         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10698
10699         /* Setup Authentication Parameters */
10700         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10701         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
10702         ut_params->auth_xform.auth.algo = reference->auth_algo;
10703         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10704         ut_params->auth_xform.auth.key.data = auth_key;
10705         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10706         ut_params->auth_xform.next = &ut_params->cipher_xform;
10707
10708         /* Setup Cipher Parameters */
10709         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10710         ut_params->cipher_xform.next = NULL;
10711         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10712         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10713         ut_params->cipher_xform.cipher.key.data = cipher_key;
10714         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10715         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10716         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10717
10718         /* Create Crypto session*/
10719         ut_params->sess = rte_cryptodev_sym_session_create(
10720                         ts_params->session_mpool);
10721
10722         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10723                                 ut_params->sess,
10724                                 &ut_params->auth_xform,
10725                                 ts_params->session_priv_mpool);
10726
10727         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10728
10729         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10730         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10731                         "Failed to allocate input buffer in mempool");
10732
10733         /* clear mbuf payload */
10734         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10735                         rte_pktmbuf_tailroom(ut_params->ibuf));
10736
10737         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10738                         reference->ciphertext.len);
10739         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10740         memcpy(ciphertext, reference->ciphertext.data,
10741                         reference->ciphertext.len);
10742
10743         /* Create operation */
10744         retval = create_cipher_auth_verify_operation(ts_params,
10745                         ut_params,
10746                         reference);
10747
10748         if (retval < 0)
10749                 return retval;
10750
10751         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10752                         ut_params->op);
10753
10754         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10755         TEST_ASSERT_EQUAL(ut_params->op->status,
10756                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10757                         "crypto op processing passed");
10758
10759         ut_params->obuf = ut_params->op->sym->m_src;
10760         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
10761
10762         return 0;
10763 }
10764
10765 static int
10766 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
10767                 const struct aead_test_data *tdata,
10768                 void *digest_mem, uint64_t digest_phys)
10769 {
10770         struct crypto_testsuite_params *ts_params = &testsuite_params;
10771         struct crypto_unittest_params *ut_params = &unittest_params;
10772
10773         const unsigned int auth_tag_len = tdata->auth_tag.len;
10774         const unsigned int iv_len = tdata->iv.len;
10775         unsigned int aad_len = tdata->aad.len;
10776         unsigned int aad_len_pad = 0;
10777
10778         /* Generate Crypto op data structure */
10779         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10780                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10781         TEST_ASSERT_NOT_NULL(ut_params->op,
10782                 "Failed to allocate symmetric crypto operation struct");
10783
10784         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10785
10786         sym_op->aead.digest.data = digest_mem;
10787
10788         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
10789                         "no room to append digest");
10790
10791         sym_op->aead.digest.phys_addr = digest_phys;
10792
10793         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
10794                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
10795                                 auth_tag_len);
10796                 debug_hexdump(stdout, "digest:",
10797                                 sym_op->aead.digest.data,
10798                                 auth_tag_len);
10799         }
10800
10801         /* Append aad data */
10802         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
10803                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10804                                 uint8_t *, IV_OFFSET);
10805
10806                 /* Copy IV 1 byte after the IV pointer, according to the API */
10807                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
10808
10809                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
10810
10811                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
10812                                 ut_params->ibuf, aad_len);
10813                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
10814                                 "no room to prepend aad");
10815                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
10816                                 ut_params->ibuf);
10817
10818                 memset(sym_op->aead.aad.data, 0, aad_len);
10819                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
10820                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
10821
10822                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
10823                 debug_hexdump(stdout, "aad:",
10824                                 sym_op->aead.aad.data, aad_len);
10825         } else {
10826                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10827                                 uint8_t *, IV_OFFSET);
10828
10829                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
10830
10831                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
10832
10833                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
10834                                 ut_params->ibuf, aad_len_pad);
10835                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
10836                                 "no room to prepend aad");
10837                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
10838                                 ut_params->ibuf);
10839
10840                 memset(sym_op->aead.aad.data, 0, aad_len);
10841                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
10842
10843                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
10844                 debug_hexdump(stdout, "aad:",
10845                                 sym_op->aead.aad.data, aad_len);
10846         }
10847
10848         sym_op->aead.data.length = tdata->plaintext.len;
10849         sym_op->aead.data.offset = aad_len_pad;
10850
10851         return 0;
10852 }
10853
10854 #define SGL_MAX_NO      16
10855
10856 static int
10857 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
10858                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
10859 {
10860         struct crypto_testsuite_params *ts_params = &testsuite_params;
10861         struct crypto_unittest_params *ut_params = &unittest_params;
10862         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
10863         int retval;
10864         int to_trn = 0;
10865         int to_trn_tbl[SGL_MAX_NO];
10866         int segs = 1;
10867         unsigned int trn_data = 0;
10868         uint8_t *plaintext, *ciphertext, *auth_tag;
10869         struct rte_cryptodev_info dev_info;
10870
10871         /* Verify the capabilities */
10872         struct rte_cryptodev_sym_capability_idx cap_idx;
10873         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10874         cap_idx.algo.aead = tdata->algo;
10875         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10876                         &cap_idx) == NULL)
10877                 return -ENOTSUP;
10878
10879         /* Detailed check for the particular SGL support flag */
10880         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10881         if (!oop) {
10882                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
10883                 if (sgl_in && (!(dev_info.feature_flags &
10884                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
10885                         return -ENOTSUP;
10886         } else {
10887                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
10888                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
10889                                 tdata->plaintext.len;
10890                 if (sgl_in && !sgl_out) {
10891                         if (!(dev_info.feature_flags &
10892                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
10893                                 return -ENOTSUP;
10894                 } else if (!sgl_in && sgl_out) {
10895                         if (!(dev_info.feature_flags &
10896                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
10897                                 return -ENOTSUP;
10898                 } else if (sgl_in && sgl_out) {
10899                         if (!(dev_info.feature_flags &
10900                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
10901                                 return -ENOTSUP;
10902                 }
10903         }
10904
10905         if (fragsz > tdata->plaintext.len)
10906                 fragsz = tdata->plaintext.len;
10907
10908         uint16_t plaintext_len = fragsz;
10909         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
10910
10911         if (fragsz_oop > tdata->plaintext.len)
10912                 frag_size_oop = tdata->plaintext.len;
10913
10914         int ecx = 0;
10915         void *digest_mem = NULL;
10916
10917         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
10918
10919         if (tdata->plaintext.len % fragsz != 0) {
10920                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
10921                         return 1;
10922         }       else {
10923                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
10924                         return 1;
10925         }
10926
10927         /*
10928          * For out-op-place we need to alloc another mbuf
10929          */
10930         if (oop) {
10931                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10932                 rte_pktmbuf_append(ut_params->obuf,
10933                                 frag_size_oop + prepend_len);
10934                 buf_oop = ut_params->obuf;
10935         }
10936
10937         /* Create AEAD session */
10938         retval = create_aead_session(ts_params->valid_devs[0],
10939                         tdata->algo,
10940                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10941                         tdata->key.data, tdata->key.len,
10942                         tdata->aad.len, tdata->auth_tag.len,
10943                         tdata->iv.len);
10944         if (retval < 0)
10945                 return retval;
10946
10947         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10948
10949         /* clear mbuf payload */
10950         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10951                         rte_pktmbuf_tailroom(ut_params->ibuf));
10952
10953         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10954                         plaintext_len);
10955
10956         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
10957
10958         trn_data += plaintext_len;
10959
10960         buf = ut_params->ibuf;
10961
10962         /*
10963          * Loop until no more fragments
10964          */
10965
10966         while (trn_data < tdata->plaintext.len) {
10967                 ++segs;
10968                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
10969                                 (tdata->plaintext.len - trn_data) : fragsz;
10970
10971                 to_trn_tbl[ecx++] = to_trn;
10972
10973                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10974                 buf = buf->next;
10975
10976                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
10977                                 rte_pktmbuf_tailroom(buf));
10978
10979                 /* OOP */
10980                 if (oop && !fragsz_oop) {
10981                         buf_last_oop = buf_oop->next =
10982                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
10983                         buf_oop = buf_oop->next;
10984                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
10985                                         0, rte_pktmbuf_tailroom(buf_oop));
10986                         rte_pktmbuf_append(buf_oop, to_trn);
10987                 }
10988
10989                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
10990                                 to_trn);
10991
10992                 memcpy(plaintext, tdata->plaintext.data + trn_data,
10993                                 to_trn);
10994                 trn_data += to_trn;
10995                 if (trn_data  == tdata->plaintext.len) {
10996                         if (oop) {
10997                                 if (!fragsz_oop)
10998                                         digest_mem = rte_pktmbuf_append(buf_oop,
10999                                                 tdata->auth_tag.len);
11000                         } else
11001                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11002                                         tdata->auth_tag.len);
11003                 }
11004         }
11005
11006         uint64_t digest_phys = 0;
11007
11008         ut_params->ibuf->nb_segs = segs;
11009
11010         segs = 1;
11011         if (fragsz_oop && oop) {
11012                 to_trn = 0;
11013                 ecx = 0;
11014
11015                 if (frag_size_oop == tdata->plaintext.len) {
11016                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
11017                                 tdata->auth_tag.len);
11018
11019                         digest_phys = rte_pktmbuf_iova_offset(
11020                                         ut_params->obuf,
11021                                         tdata->plaintext.len + prepend_len);
11022                 }
11023
11024                 trn_data = frag_size_oop;
11025                 while (trn_data < tdata->plaintext.len) {
11026                         ++segs;
11027                         to_trn =
11028                                 (tdata->plaintext.len - trn_data <
11029                                                 frag_size_oop) ?
11030                                 (tdata->plaintext.len - trn_data) :
11031                                                 frag_size_oop;
11032
11033                         to_trn_tbl[ecx++] = to_trn;
11034
11035                         buf_last_oop = buf_oop->next =
11036                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11037                         buf_oop = buf_oop->next;
11038                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11039                                         0, rte_pktmbuf_tailroom(buf_oop));
11040                         rte_pktmbuf_append(buf_oop, to_trn);
11041
11042                         trn_data += to_trn;
11043
11044                         if (trn_data  == tdata->plaintext.len) {
11045                                 digest_mem = rte_pktmbuf_append(buf_oop,
11046                                         tdata->auth_tag.len);
11047                         }
11048                 }
11049
11050                 ut_params->obuf->nb_segs = segs;
11051         }
11052
11053         /*
11054          * Place digest at the end of the last buffer
11055          */
11056         if (!digest_phys)
11057                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11058         if (oop && buf_last_oop)
11059                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
11060
11061         if (!digest_mem && !oop) {
11062                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11063                                 + tdata->auth_tag.len);
11064                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11065                                 tdata->plaintext.len);
11066         }
11067
11068         /* Create AEAD operation */
11069         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
11070                         tdata, digest_mem, digest_phys);
11071
11072         if (retval < 0)
11073                 return retval;
11074
11075         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11076
11077         ut_params->op->sym->m_src = ut_params->ibuf;
11078         if (oop)
11079                 ut_params->op->sym->m_dst = ut_params->obuf;
11080
11081         /* Process crypto operation */
11082         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11083                         ut_params->op), "failed to process sym crypto op");
11084
11085         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11086                         "crypto op processing failed");
11087
11088
11089         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11090                         uint8_t *, prepend_len);
11091         if (oop) {
11092                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11093                                 uint8_t *, prepend_len);
11094         }
11095
11096         if (fragsz_oop)
11097                 fragsz = fragsz_oop;
11098
11099         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11100                         ciphertext,
11101                         tdata->ciphertext.data,
11102                         fragsz,
11103                         "Ciphertext data not as expected");
11104
11105         buf = ut_params->op->sym->m_src->next;
11106         if (oop)
11107                 buf = ut_params->op->sym->m_dst->next;
11108
11109         unsigned int off = fragsz;
11110
11111         ecx = 0;
11112         while (buf) {
11113                 ciphertext = rte_pktmbuf_mtod(buf,
11114                                 uint8_t *);
11115
11116                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
11117                                 ciphertext,
11118                                 tdata->ciphertext.data + off,
11119                                 to_trn_tbl[ecx],
11120                                 "Ciphertext data not as expected");
11121
11122                 off += to_trn_tbl[ecx++];
11123                 buf = buf->next;
11124         }
11125
11126         auth_tag = digest_mem;
11127         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11128                         auth_tag,
11129                         tdata->auth_tag.data,
11130                         tdata->auth_tag.len,
11131                         "Generated auth tag not as expected");
11132
11133         return 0;
11134 }
11135
11136 static int
11137 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
11138 {
11139         return test_authenticated_encryption_SGL(
11140                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
11141 }
11142
11143 static int
11144 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
11145 {
11146         return test_authenticated_encryption_SGL(
11147                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
11148 }
11149
11150 static int
11151 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
11152 {
11153         return test_authenticated_encryption_SGL(
11154                         &gcm_test_case_8, OUT_OF_PLACE, 400,
11155                         gcm_test_case_8.plaintext.len);
11156 }
11157
11158 static int
11159 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
11160 {
11161         /* This test is not for OPENSSL PMD */
11162         if (gbl_driver_id == rte_cryptodev_driver_id_get(
11163                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
11164                 return -ENOTSUP;
11165
11166         return test_authenticated_encryption_SGL(
11167                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
11168 }
11169
11170 static int
11171 test_authentication_verify_fail_when_data_corrupted(
11172                 struct crypto_testsuite_params *ts_params,
11173                 struct crypto_unittest_params *ut_params,
11174                 const struct test_crypto_vector *reference)
11175 {
11176         return test_authentication_verify_fail_when_data_corruption(
11177                         ts_params, ut_params, reference, 1);
11178 }
11179
11180 static int
11181 test_authentication_verify_fail_when_tag_corrupted(
11182                 struct crypto_testsuite_params *ts_params,
11183                 struct crypto_unittest_params *ut_params,
11184                 const struct test_crypto_vector *reference)
11185 {
11186         return test_authentication_verify_fail_when_data_corruption(
11187                         ts_params, ut_params, reference, 0);
11188 }
11189
11190 static int
11191 test_authentication_verify_GMAC_fail_when_data_corrupted(
11192                 struct crypto_testsuite_params *ts_params,
11193                 struct crypto_unittest_params *ut_params,
11194                 const struct test_crypto_vector *reference)
11195 {
11196         return test_authentication_verify_GMAC_fail_when_corruption(
11197                         ts_params, ut_params, reference, 1);
11198 }
11199
11200 static int
11201 test_authentication_verify_GMAC_fail_when_tag_corrupted(
11202                 struct crypto_testsuite_params *ts_params,
11203                 struct crypto_unittest_params *ut_params,
11204                 const struct test_crypto_vector *reference)
11205 {
11206         return test_authentication_verify_GMAC_fail_when_corruption(
11207                         ts_params, ut_params, reference, 0);
11208 }
11209
11210 static int
11211 test_authenticated_decryption_fail_when_data_corrupted(
11212                 struct crypto_testsuite_params *ts_params,
11213                 struct crypto_unittest_params *ut_params,
11214                 const struct test_crypto_vector *reference)
11215 {
11216         return test_authenticated_decryption_fail_when_corruption(
11217                         ts_params, ut_params, reference, 1);
11218 }
11219
11220 static int
11221 test_authenticated_decryption_fail_when_tag_corrupted(
11222                 struct crypto_testsuite_params *ts_params,
11223                 struct crypto_unittest_params *ut_params,
11224                 const struct test_crypto_vector *reference)
11225 {
11226         return test_authenticated_decryption_fail_when_corruption(
11227                         ts_params, ut_params, reference, 0);
11228 }
11229
11230 static int
11231 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
11232 {
11233         return test_authentication_verify_fail_when_data_corrupted(
11234                         &testsuite_params, &unittest_params,
11235                         &hmac_sha1_test_crypto_vector);
11236 }
11237
11238 static int
11239 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
11240 {
11241         return test_authentication_verify_fail_when_tag_corrupted(
11242                         &testsuite_params, &unittest_params,
11243                         &hmac_sha1_test_crypto_vector);
11244 }
11245
11246 static int
11247 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
11248 {
11249         return test_authentication_verify_GMAC_fail_when_data_corrupted(
11250                         &testsuite_params, &unittest_params,
11251                         &aes128_gmac_test_vector);
11252 }
11253
11254 static int
11255 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
11256 {
11257         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
11258                         &testsuite_params, &unittest_params,
11259                         &aes128_gmac_test_vector);
11260 }
11261
11262 static int
11263 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
11264 {
11265         return test_authenticated_decryption_fail_when_data_corrupted(
11266                         &testsuite_params,
11267                         &unittest_params,
11268                         &aes128cbc_hmac_sha1_test_vector);
11269 }
11270
11271 static int
11272 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
11273 {
11274         return test_authenticated_decryption_fail_when_tag_corrupted(
11275                         &testsuite_params,
11276                         &unittest_params,
11277                         &aes128cbc_hmac_sha1_test_vector);
11278 }
11279
11280 static int
11281 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11282 {
11283         return test_authenticated_encryt_with_esn(
11284                         &testsuite_params,
11285                         &unittest_params,
11286                         &aes128cbc_hmac_sha1_aad_test_vector);
11287 }
11288
11289 static int
11290 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11291 {
11292         return test_authenticated_decrypt_with_esn(
11293                         &testsuite_params,
11294                         &unittest_params,
11295                         &aes128cbc_hmac_sha1_aad_test_vector);
11296 }
11297
11298 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
11299
11300 /* global AESNI slave IDs for the scheduler test */
11301 uint8_t aesni_ids[2];
11302
11303 static int
11304 test_scheduler_attach_slave_op(void)
11305 {
11306         struct crypto_testsuite_params *ts_params = &testsuite_params;
11307         uint8_t sched_id = ts_params->valid_devs[0];
11308         uint32_t nb_devs, i, nb_devs_attached = 0;
11309         int ret;
11310         char vdev_name[32];
11311
11312         /* create 2 AESNI_MB if necessary */
11313         nb_devs = rte_cryptodev_device_count_by_driver(
11314                         rte_cryptodev_driver_id_get(
11315                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
11316         if (nb_devs < 2) {
11317                 for (i = nb_devs; i < 2; i++) {
11318                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
11319                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
11320                                         i);
11321                         ret = rte_vdev_init(vdev_name, NULL);
11322
11323                         TEST_ASSERT(ret == 0,
11324                                 "Failed to create instance %u of"
11325                                 " pmd : %s",
11326                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11327                 }
11328         }
11329
11330         /* attach 2 AESNI_MB cdevs */
11331         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
11332                         i++) {
11333                 struct rte_cryptodev_info info;
11334                 unsigned int session_size;
11335
11336                 rte_cryptodev_info_get(i, &info);
11337                 if (info.driver_id != rte_cryptodev_driver_id_get(
11338                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
11339                         continue;
11340
11341                 session_size = rte_cryptodev_sym_get_private_session_size(i);
11342                 /*
11343                  * Create the session mempool again, since now there are new devices
11344                  * to use the mempool.
11345                  */
11346                 if (ts_params->session_mpool) {
11347                         rte_mempool_free(ts_params->session_mpool);
11348                         ts_params->session_mpool = NULL;
11349                 }
11350                 if (ts_params->session_priv_mpool) {
11351                         rte_mempool_free(ts_params->session_priv_mpool);
11352                         ts_params->session_priv_mpool = NULL;
11353                 }
11354
11355                 if (info.sym.max_nb_sessions != 0 &&
11356                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
11357                         RTE_LOG(ERR, USER1,
11358                                         "Device does not support "
11359                                         "at least %u sessions\n",
11360                                         MAX_NB_SESSIONS);
11361                         return TEST_FAILED;
11362                 }
11363                 /*
11364                  * Create mempool with maximum number of sessions,
11365                  * to include the session headers
11366                  */
11367                 if (ts_params->session_mpool == NULL) {
11368                         ts_params->session_mpool =
11369                                 rte_cryptodev_sym_session_pool_create(
11370                                                 "test_sess_mp",
11371                                                 MAX_NB_SESSIONS, 0, 0, 0,
11372                                                 SOCKET_ID_ANY);
11373                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
11374                                         "session mempool allocation failed");
11375                 }
11376
11377                 /*
11378                  * Create mempool with maximum number of sessions,
11379                  * to include device specific session private data
11380                  */
11381                 if (ts_params->session_priv_mpool == NULL) {
11382                         ts_params->session_priv_mpool = rte_mempool_create(
11383                                         "test_sess_mp_priv",
11384                                         MAX_NB_SESSIONS,
11385                                         session_size,
11386                                         0, 0, NULL, NULL, NULL,
11387                                         NULL, SOCKET_ID_ANY,
11388                                         0);
11389
11390                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
11391                                         "session mempool allocation failed");
11392                 }
11393
11394                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
11395                 ts_params->qp_conf.mp_session_private =
11396                                 ts_params->session_priv_mpool;
11397
11398                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
11399                                 (uint8_t)i);
11400
11401                 TEST_ASSERT(ret == 0,
11402                         "Failed to attach device %u of pmd : %s", i,
11403                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11404
11405                 aesni_ids[nb_devs_attached] = (uint8_t)i;
11406
11407                 nb_devs_attached++;
11408         }
11409
11410         return 0;
11411 }
11412
11413 static int
11414 test_scheduler_detach_slave_op(void)
11415 {
11416         struct crypto_testsuite_params *ts_params = &testsuite_params;
11417         uint8_t sched_id = ts_params->valid_devs[0];
11418         uint32_t i;
11419         int ret;
11420
11421         for (i = 0; i < 2; i++) {
11422                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
11423                                 aesni_ids[i]);
11424                 TEST_ASSERT(ret == 0,
11425                         "Failed to detach device %u", aesni_ids[i]);
11426         }
11427
11428         return 0;
11429 }
11430
11431 static int
11432 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
11433 {
11434         struct crypto_testsuite_params *ts_params = &testsuite_params;
11435         uint8_t sched_id = ts_params->valid_devs[0];
11436         /* set mode */
11437         return rte_cryptodev_scheduler_mode_set(sched_id,
11438                 scheduler_mode);
11439 }
11440
11441 static int
11442 test_scheduler_mode_roundrobin_op(void)
11443 {
11444         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
11445                         0, "Failed to set roundrobin mode");
11446         return 0;
11447
11448 }
11449
11450 static int
11451 test_scheduler_mode_multicore_op(void)
11452 {
11453         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
11454                         0, "Failed to set multicore mode");
11455
11456         return 0;
11457 }
11458
11459 static int
11460 test_scheduler_mode_failover_op(void)
11461 {
11462         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
11463                         0, "Failed to set failover mode");
11464
11465         return 0;
11466 }
11467
11468 static int
11469 test_scheduler_mode_pkt_size_distr_op(void)
11470 {
11471         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
11472                         0, "Failed to set pktsize mode");
11473
11474         return 0;
11475 }
11476
11477 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
11478         .suite_name = "Crypto Device Scheduler Unit Test Suite",
11479         .setup = testsuite_setup,
11480         .teardown = testsuite_teardown,
11481         .unit_test_cases = {
11482                 /* Multi Core */
11483                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11484                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
11485                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11486                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11487                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11488                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11489
11490                 /* Round Robin */
11491                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11492                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
11493                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11494                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11495                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11496                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11497
11498                 /* Fail over */
11499                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11500                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
11501                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11502                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11503                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11504                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11505
11506                 /* PKT SIZE */
11507                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11508                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
11509                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11510                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11511                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11512                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11513
11514                 TEST_CASES_END() /**< NULL terminate unit test array */
11515         }
11516 };
11517
11518 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
11519
11520 static struct unit_test_suite cryptodev_qat_testsuite  = {
11521         .suite_name = "Crypto QAT Unit Test Suite",
11522         .setup = testsuite_setup,
11523         .teardown = testsuite_teardown,
11524         .unit_test_cases = {
11525                 TEST_CASE_ST(ut_setup, ut_teardown,
11526                                 test_device_configure_invalid_dev_id),
11527                 TEST_CASE_ST(ut_setup, ut_teardown,
11528                                 test_device_configure_invalid_queue_pair_ids),
11529                 TEST_CASE_ST(ut_setup, ut_teardown,
11530                                 test_queue_pair_descriptor_setup),
11531                 TEST_CASE_ST(ut_setup, ut_teardown,
11532                                 test_multi_session),
11533
11534                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11535                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11536                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
11537                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
11538                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
11539                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
11540                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
11541                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11542                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
11543
11544                 /** AES CCM Authenticated Encryption 128 bits key */
11545                 TEST_CASE_ST(ut_setup, ut_teardown,
11546                         test_AES_CCM_authenticated_encryption_test_case_128_1),
11547                 TEST_CASE_ST(ut_setup, ut_teardown,
11548                         test_AES_CCM_authenticated_encryption_test_case_128_2),
11549                 TEST_CASE_ST(ut_setup, ut_teardown,
11550                         test_AES_CCM_authenticated_encryption_test_case_128_3),
11551
11552                 /** AES CCM Authenticated Decryption 128 bits key*/
11553                 TEST_CASE_ST(ut_setup, ut_teardown,
11554                         test_AES_CCM_authenticated_decryption_test_case_128_1),
11555                 TEST_CASE_ST(ut_setup, ut_teardown,
11556                         test_AES_CCM_authenticated_decryption_test_case_128_2),
11557                 TEST_CASE_ST(ut_setup, ut_teardown,
11558                         test_AES_CCM_authenticated_decryption_test_case_128_3),
11559
11560                 /** AES GCM Authenticated Encryption */
11561                 TEST_CASE_ST(ut_setup, ut_teardown,
11562                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
11563                 TEST_CASE_ST(ut_setup, ut_teardown,
11564                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
11565                 TEST_CASE_ST(ut_setup, ut_teardown,
11566                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
11567                 TEST_CASE_ST(ut_setup, ut_teardown,
11568                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11569                 TEST_CASE_ST(ut_setup, ut_teardown,
11570                         test_AES_GCM_authenticated_encryption_test_case_1),
11571                 TEST_CASE_ST(ut_setup, ut_teardown,
11572                         test_AES_GCM_authenticated_encryption_test_case_2),
11573                 TEST_CASE_ST(ut_setup, ut_teardown,
11574                         test_AES_GCM_authenticated_encryption_test_case_3),
11575                 TEST_CASE_ST(ut_setup, ut_teardown,
11576                         test_AES_GCM_authenticated_encryption_test_case_4),
11577                 TEST_CASE_ST(ut_setup, ut_teardown,
11578                         test_AES_GCM_authenticated_encryption_test_case_5),
11579                 TEST_CASE_ST(ut_setup, ut_teardown,
11580                         test_AES_GCM_authenticated_encryption_test_case_6),
11581                 TEST_CASE_ST(ut_setup, ut_teardown,
11582                         test_AES_GCM_authenticated_encryption_test_case_7),
11583                 TEST_CASE_ST(ut_setup, ut_teardown,
11584                         test_AES_GCM_authenticated_encryption_test_case_8),
11585
11586                 /** AES GCM Authenticated Decryption */
11587                 TEST_CASE_ST(ut_setup, ut_teardown,
11588                         test_AES_GCM_authenticated_decryption_test_case_1),
11589                 TEST_CASE_ST(ut_setup, ut_teardown,
11590                         test_AES_GCM_authenticated_decryption_test_case_2),
11591                 TEST_CASE_ST(ut_setup, ut_teardown,
11592                         test_AES_GCM_authenticated_decryption_test_case_3),
11593                 TEST_CASE_ST(ut_setup, ut_teardown,
11594                         test_AES_GCM_authenticated_decryption_test_case_4),
11595                 TEST_CASE_ST(ut_setup, ut_teardown,
11596                         test_AES_GCM_authenticated_decryption_test_case_5),
11597                 TEST_CASE_ST(ut_setup, ut_teardown,
11598                         test_AES_GCM_authenticated_decryption_test_case_6),
11599                 TEST_CASE_ST(ut_setup, ut_teardown,
11600                         test_AES_GCM_authenticated_decryption_test_case_7),
11601                 TEST_CASE_ST(ut_setup, ut_teardown,
11602                         test_AES_GCM_authenticated_decryption_test_case_8),
11603
11604                 /** AES GCM Authenticated Encryption 192 bits key */
11605                 TEST_CASE_ST(ut_setup, ut_teardown,
11606                         test_AES_GCM_auth_encryption_test_case_192_1),
11607                 TEST_CASE_ST(ut_setup, ut_teardown,
11608                         test_AES_GCM_auth_encryption_test_case_192_2),
11609                 TEST_CASE_ST(ut_setup, ut_teardown,
11610                         test_AES_GCM_auth_encryption_test_case_192_3),
11611                 TEST_CASE_ST(ut_setup, ut_teardown,
11612                         test_AES_GCM_auth_encryption_test_case_192_4),
11613                 TEST_CASE_ST(ut_setup, ut_teardown,
11614                         test_AES_GCM_auth_encryption_test_case_192_5),
11615                 TEST_CASE_ST(ut_setup, ut_teardown,
11616                         test_AES_GCM_auth_encryption_test_case_192_6),
11617                 TEST_CASE_ST(ut_setup, ut_teardown,
11618                         test_AES_GCM_auth_encryption_test_case_192_7),
11619
11620                 /** AES GCM Authenticated Decryption 192 bits key */
11621                 TEST_CASE_ST(ut_setup, ut_teardown,
11622                         test_AES_GCM_auth_decryption_test_case_192_1),
11623                 TEST_CASE_ST(ut_setup, ut_teardown,
11624                         test_AES_GCM_auth_decryption_test_case_192_2),
11625                 TEST_CASE_ST(ut_setup, ut_teardown,
11626                         test_AES_GCM_auth_decryption_test_case_192_3),
11627                 TEST_CASE_ST(ut_setup, ut_teardown,
11628                         test_AES_GCM_auth_decryption_test_case_192_4),
11629                 TEST_CASE_ST(ut_setup, ut_teardown,
11630                         test_AES_GCM_auth_decryption_test_case_192_5),
11631                 TEST_CASE_ST(ut_setup, ut_teardown,
11632                         test_AES_GCM_auth_decryption_test_case_192_6),
11633                 TEST_CASE_ST(ut_setup, ut_teardown,
11634                         test_AES_GCM_auth_decryption_test_case_192_7),
11635
11636                 /** AES GCM Authenticated Encryption 256 bits key */
11637                 TEST_CASE_ST(ut_setup, ut_teardown,
11638                         test_AES_GCM_auth_encryption_test_case_256_1),
11639                 TEST_CASE_ST(ut_setup, ut_teardown,
11640                         test_AES_GCM_auth_encryption_test_case_256_2),
11641                 TEST_CASE_ST(ut_setup, ut_teardown,
11642                         test_AES_GCM_auth_encryption_test_case_256_3),
11643                 TEST_CASE_ST(ut_setup, ut_teardown,
11644                         test_AES_GCM_auth_encryption_test_case_256_4),
11645                 TEST_CASE_ST(ut_setup, ut_teardown,
11646                         test_AES_GCM_auth_encryption_test_case_256_5),
11647                 TEST_CASE_ST(ut_setup, ut_teardown,
11648                         test_AES_GCM_auth_encryption_test_case_256_6),
11649                 TEST_CASE_ST(ut_setup, ut_teardown,
11650                         test_AES_GCM_auth_encryption_test_case_256_7),
11651
11652                 /** AES GCM Authenticated Decryption 256 bits key */
11653                 TEST_CASE_ST(ut_setup, ut_teardown,
11654                         test_AES_GCM_auth_decryption_test_case_256_1),
11655                 TEST_CASE_ST(ut_setup, ut_teardown,
11656                         test_AES_GCM_auth_decryption_test_case_256_2),
11657                 TEST_CASE_ST(ut_setup, ut_teardown,
11658                         test_AES_GCM_auth_decryption_test_case_256_3),
11659                 TEST_CASE_ST(ut_setup, ut_teardown,
11660                         test_AES_GCM_auth_decryption_test_case_256_4),
11661                 TEST_CASE_ST(ut_setup, ut_teardown,
11662                         test_AES_GCM_auth_decryption_test_case_256_5),
11663                 TEST_CASE_ST(ut_setup, ut_teardown,
11664                         test_AES_GCM_auth_decryption_test_case_256_6),
11665                 TEST_CASE_ST(ut_setup, ut_teardown,
11666                         test_AES_GCM_auth_decryption_test_case_256_7),
11667
11668                 /** AES GMAC Authentication */
11669                 TEST_CASE_ST(ut_setup, ut_teardown,
11670                         test_AES_GMAC_authentication_test_case_1),
11671                 TEST_CASE_ST(ut_setup, ut_teardown,
11672                         test_AES_GMAC_authentication_verify_test_case_1),
11673                 TEST_CASE_ST(ut_setup, ut_teardown,
11674                         test_AES_GMAC_authentication_test_case_2),
11675                 TEST_CASE_ST(ut_setup, ut_teardown,
11676                         test_AES_GMAC_authentication_verify_test_case_2),
11677                 TEST_CASE_ST(ut_setup, ut_teardown,
11678                         test_AES_GMAC_authentication_test_case_3),
11679                 TEST_CASE_ST(ut_setup, ut_teardown,
11680                         test_AES_GMAC_authentication_verify_test_case_3),
11681
11682                 /** SNOW 3G encrypt only (UEA2) */
11683                 TEST_CASE_ST(ut_setup, ut_teardown,
11684                         test_snow3g_encryption_test_case_1),
11685                 TEST_CASE_ST(ut_setup, ut_teardown,
11686                         test_snow3g_encryption_test_case_2),
11687                 TEST_CASE_ST(ut_setup, ut_teardown,
11688                         test_snow3g_encryption_test_case_3),
11689                 TEST_CASE_ST(ut_setup, ut_teardown,
11690                         test_snow3g_encryption_test_case_4),
11691                 TEST_CASE_ST(ut_setup, ut_teardown,
11692                         test_snow3g_encryption_test_case_5),
11693
11694                 TEST_CASE_ST(ut_setup, ut_teardown,
11695                         test_snow3g_encryption_test_case_1_oop),
11696                 TEST_CASE_ST(ut_setup, ut_teardown,
11697                         test_snow3g_decryption_test_case_1_oop),
11698
11699                 /** SNOW 3G generate auth, then encrypt (UEA2) */
11700                 TEST_CASE_ST(ut_setup, ut_teardown,
11701                         test_snow3g_auth_cipher_test_case_1),
11702                 TEST_CASE_ST(ut_setup, ut_teardown,
11703                         test_snow3g_auth_cipher_test_case_2),
11704                 TEST_CASE_ST(ut_setup, ut_teardown,
11705                         test_snow3g_auth_cipher_test_case_2_oop),
11706                 TEST_CASE_ST(ut_setup, ut_teardown,
11707                         test_snow3g_auth_cipher_part_digest_enc),
11708                 TEST_CASE_ST(ut_setup, ut_teardown,
11709                         test_snow3g_auth_cipher_part_digest_enc_oop),
11710                 TEST_CASE_ST(ut_setup, ut_teardown,
11711                         test_snow3g_auth_cipher_test_case_3_sgl),
11712                 TEST_CASE_ST(ut_setup, ut_teardown,
11713                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
11714                 TEST_CASE_ST(ut_setup, ut_teardown,
11715                         test_snow3g_auth_cipher_part_digest_enc_sgl),
11716                 TEST_CASE_ST(ut_setup, ut_teardown,
11717                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
11718
11719                 /** SNOW 3G decrypt (UEA2), then verify auth */
11720                 TEST_CASE_ST(ut_setup, ut_teardown,
11721                         test_snow3g_auth_cipher_verify_test_case_1),
11722                 TEST_CASE_ST(ut_setup, ut_teardown,
11723                         test_snow3g_auth_cipher_verify_test_case_2),
11724                 TEST_CASE_ST(ut_setup, ut_teardown,
11725                         test_snow3g_auth_cipher_verify_test_case_2_oop),
11726                 TEST_CASE_ST(ut_setup, ut_teardown,
11727                         test_snow3g_auth_cipher_verify_part_digest_enc),
11728                 TEST_CASE_ST(ut_setup, ut_teardown,
11729                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
11730                 TEST_CASE_ST(ut_setup, ut_teardown,
11731                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
11732                 TEST_CASE_ST(ut_setup, ut_teardown,
11733                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
11734                 TEST_CASE_ST(ut_setup, ut_teardown,
11735                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
11736                 TEST_CASE_ST(ut_setup, ut_teardown,
11737                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
11738
11739                 /** SNOW 3G decrypt only (UEA2) */
11740                 TEST_CASE_ST(ut_setup, ut_teardown,
11741                         test_snow3g_decryption_test_case_1),
11742                 TEST_CASE_ST(ut_setup, ut_teardown,
11743                         test_snow3g_decryption_test_case_2),
11744                 TEST_CASE_ST(ut_setup, ut_teardown,
11745                         test_snow3g_decryption_test_case_3),
11746                 TEST_CASE_ST(ut_setup, ut_teardown,
11747                         test_snow3g_decryption_test_case_4),
11748                 TEST_CASE_ST(ut_setup, ut_teardown,
11749                         test_snow3g_decryption_test_case_5),
11750                 TEST_CASE_ST(ut_setup, ut_teardown,
11751                         test_snow3g_decryption_with_digest_test_case_1),
11752                 TEST_CASE_ST(ut_setup, ut_teardown,
11753                         test_snow3g_hash_generate_test_case_1),
11754                 TEST_CASE_ST(ut_setup, ut_teardown,
11755                         test_snow3g_hash_generate_test_case_2),
11756                 TEST_CASE_ST(ut_setup, ut_teardown,
11757                         test_snow3g_hash_generate_test_case_3),
11758                 TEST_CASE_ST(ut_setup, ut_teardown,
11759                         test_snow3g_hash_verify_test_case_1),
11760                 TEST_CASE_ST(ut_setup, ut_teardown,
11761                         test_snow3g_hash_verify_test_case_2),
11762                 TEST_CASE_ST(ut_setup, ut_teardown,
11763                         test_snow3g_hash_verify_test_case_3),
11764                 TEST_CASE_ST(ut_setup, ut_teardown,
11765                         test_snow3g_cipher_auth_test_case_1),
11766                 TEST_CASE_ST(ut_setup, ut_teardown,
11767                         test_snow3g_auth_cipher_with_digest_test_case_1),
11768
11769                 /** ZUC encrypt only (EEA3) */
11770                 TEST_CASE_ST(ut_setup, ut_teardown,
11771                         test_zuc_encryption_test_case_1),
11772                 TEST_CASE_ST(ut_setup, ut_teardown,
11773                         test_zuc_encryption_test_case_2),
11774                 TEST_CASE_ST(ut_setup, ut_teardown,
11775                         test_zuc_encryption_test_case_3),
11776                 TEST_CASE_ST(ut_setup, ut_teardown,
11777                         test_zuc_encryption_test_case_4),
11778                 TEST_CASE_ST(ut_setup, ut_teardown,
11779                         test_zuc_encryption_test_case_5),
11780
11781                 /** ZUC authenticate (EIA3) */
11782                 TEST_CASE_ST(ut_setup, ut_teardown,
11783                         test_zuc_hash_generate_test_case_6),
11784                 TEST_CASE_ST(ut_setup, ut_teardown,
11785                         test_zuc_hash_generate_test_case_7),
11786                 TEST_CASE_ST(ut_setup, ut_teardown,
11787                         test_zuc_hash_generate_test_case_8),
11788
11789                 /** ZUC alg-chain (EEA3/EIA3) */
11790                 TEST_CASE_ST(ut_setup, ut_teardown,
11791                         test_zuc_cipher_auth_test_case_1),
11792                 TEST_CASE_ST(ut_setup, ut_teardown,
11793                         test_zuc_cipher_auth_test_case_2),
11794
11795                 /** ZUC generate auth, then encrypt (EEA3) */
11796                 TEST_CASE_ST(ut_setup, ut_teardown,
11797                         test_zuc_auth_cipher_test_case_1),
11798                 TEST_CASE_ST(ut_setup, ut_teardown,
11799                         test_zuc_auth_cipher_test_case_1_oop),
11800                 TEST_CASE_ST(ut_setup, ut_teardown,
11801                         test_zuc_auth_cipher_test_case_1_sgl),
11802                 TEST_CASE_ST(ut_setup, ut_teardown,
11803                         test_zuc_auth_cipher_test_case_1_oop_sgl),
11804
11805                 /** ZUC decrypt (EEA3), then verify auth */
11806                 TEST_CASE_ST(ut_setup, ut_teardown,
11807                         test_zuc_auth_cipher_verify_test_case_1),
11808                 TEST_CASE_ST(ut_setup, ut_teardown,
11809                         test_zuc_auth_cipher_verify_test_case_1_oop),
11810                 TEST_CASE_ST(ut_setup, ut_teardown,
11811                         test_zuc_auth_cipher_verify_test_case_1_sgl),
11812                 TEST_CASE_ST(ut_setup, ut_teardown,
11813                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
11814
11815                 /** HMAC_MD5 Authentication */
11816                 TEST_CASE_ST(ut_setup, ut_teardown,
11817                         test_MD5_HMAC_generate_case_1),
11818                 TEST_CASE_ST(ut_setup, ut_teardown,
11819                         test_MD5_HMAC_verify_case_1),
11820                 TEST_CASE_ST(ut_setup, ut_teardown,
11821                         test_MD5_HMAC_generate_case_2),
11822                 TEST_CASE_ST(ut_setup, ut_teardown,
11823                         test_MD5_HMAC_verify_case_2),
11824
11825                 /** NULL algo tests done in chain_all,
11826                  * cipheronly and authonly suites
11827                  */
11828
11829                 /** KASUMI tests */
11830                 TEST_CASE_ST(ut_setup, ut_teardown,
11831                         test_kasumi_hash_generate_test_case_1),
11832                 TEST_CASE_ST(ut_setup, ut_teardown,
11833                         test_kasumi_hash_generate_test_case_2),
11834                 TEST_CASE_ST(ut_setup, ut_teardown,
11835                         test_kasumi_hash_generate_test_case_3),
11836                 TEST_CASE_ST(ut_setup, ut_teardown,
11837                         test_kasumi_hash_generate_test_case_4),
11838                 TEST_CASE_ST(ut_setup, ut_teardown,
11839                         test_kasumi_hash_generate_test_case_5),
11840                 TEST_CASE_ST(ut_setup, ut_teardown,
11841                         test_kasumi_hash_generate_test_case_6),
11842
11843                 TEST_CASE_ST(ut_setup, ut_teardown,
11844                         test_kasumi_hash_verify_test_case_1),
11845                 TEST_CASE_ST(ut_setup, ut_teardown,
11846                         test_kasumi_hash_verify_test_case_2),
11847                 TEST_CASE_ST(ut_setup, ut_teardown,
11848                         test_kasumi_hash_verify_test_case_3),
11849                 TEST_CASE_ST(ut_setup, ut_teardown,
11850                         test_kasumi_hash_verify_test_case_4),
11851                 TEST_CASE_ST(ut_setup, ut_teardown,
11852                         test_kasumi_hash_verify_test_case_5),
11853
11854                 TEST_CASE_ST(ut_setup, ut_teardown,
11855                         test_kasumi_encryption_test_case_1),
11856                 TEST_CASE_ST(ut_setup, ut_teardown,
11857                         test_kasumi_encryption_test_case_3),
11858                 TEST_CASE_ST(ut_setup, ut_teardown,
11859                         test_kasumi_cipher_auth_test_case_1),
11860
11861                 /** KASUMI generate auth, then encrypt (F8) */
11862                 TEST_CASE_ST(ut_setup, ut_teardown,
11863                         test_kasumi_auth_cipher_test_case_1),
11864                 TEST_CASE_ST(ut_setup, ut_teardown,
11865                         test_kasumi_auth_cipher_test_case_2),
11866                 TEST_CASE_ST(ut_setup, ut_teardown,
11867                         test_kasumi_auth_cipher_test_case_2_oop),
11868                 TEST_CASE_ST(ut_setup, ut_teardown,
11869                         test_kasumi_auth_cipher_test_case_2_sgl),
11870                 TEST_CASE_ST(ut_setup, ut_teardown,
11871                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
11872
11873                 /** KASUMI decrypt (F8), then verify auth */
11874                 TEST_CASE_ST(ut_setup, ut_teardown,
11875                         test_kasumi_auth_cipher_verify_test_case_1),
11876                 TEST_CASE_ST(ut_setup, ut_teardown,
11877                         test_kasumi_auth_cipher_verify_test_case_2),
11878                 TEST_CASE_ST(ut_setup, ut_teardown,
11879                         test_kasumi_auth_cipher_verify_test_case_2_oop),
11880                 TEST_CASE_ST(ut_setup, ut_teardown,
11881                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
11882                 TEST_CASE_ST(ut_setup, ut_teardown,
11883                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
11884
11885                 /** Negative tests */
11886                 TEST_CASE_ST(ut_setup, ut_teardown,
11887                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
11888                 TEST_CASE_ST(ut_setup, ut_teardown,
11889                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
11890                 TEST_CASE_ST(ut_setup, ut_teardown,
11891                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
11892                 TEST_CASE_ST(ut_setup, ut_teardown,
11893                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
11894                 TEST_CASE_ST(ut_setup, ut_teardown,
11895                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
11896                 TEST_CASE_ST(ut_setup, ut_teardown,
11897                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
11898                 TEST_CASE_ST(ut_setup, ut_teardown,
11899                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
11900                 TEST_CASE_ST(ut_setup, ut_teardown,
11901                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
11902                 TEST_CASE_ST(ut_setup, ut_teardown,
11903                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
11904                 TEST_CASE_ST(ut_setup, ut_teardown,
11905                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
11906                 TEST_CASE_ST(ut_setup, ut_teardown,
11907                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
11908                 TEST_CASE_ST(ut_setup, ut_teardown,
11909                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
11910                 TEST_CASE_ST(ut_setup, ut_teardown,
11911                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
11912                 TEST_CASE_ST(ut_setup, ut_teardown,
11913                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
11914                 TEST_CASE_ST(ut_setup, ut_teardown,
11915                         authentication_verify_AES128_GMAC_fail_data_corrupt),
11916                 TEST_CASE_ST(ut_setup, ut_teardown,
11917                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
11918                 TEST_CASE_ST(ut_setup, ut_teardown,
11919                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
11920                 TEST_CASE_ST(ut_setup, ut_teardown,
11921                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
11922
11923                 /** Mixed CIPHER + HASH algorithms */
11924                 /** AUTH AES CMAC + CIPHER AES CTR */
11925                 TEST_CASE_ST(ut_setup, ut_teardown,
11926                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
11927                 TEST_CASE_ST(ut_setup, ut_teardown,
11928                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
11929                 TEST_CASE_ST(ut_setup, ut_teardown,
11930                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
11931                 TEST_CASE_ST(ut_setup, ut_teardown,
11932                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
11933                 TEST_CASE_ST(ut_setup, ut_teardown,
11934                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
11935                 TEST_CASE_ST(ut_setup, ut_teardown,
11936                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
11937                 TEST_CASE_ST(ut_setup, ut_teardown,
11938                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
11939                 TEST_CASE_ST(ut_setup, ut_teardown,
11940                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
11941
11942                 /** AUTH ZUC + CIPHER SNOW3G */
11943                 TEST_CASE_ST(ut_setup, ut_teardown,
11944                         test_auth_zuc_cipher_snow_test_case_1),
11945                 TEST_CASE_ST(ut_setup, ut_teardown,
11946                         test_verify_auth_zuc_cipher_snow_test_case_1),
11947                 /** AUTH AES CMAC + CIPHER SNOW3G */
11948                 TEST_CASE_ST(ut_setup, ut_teardown,
11949                         test_auth_aes_cmac_cipher_snow_test_case_1),
11950                 TEST_CASE_ST(ut_setup, ut_teardown,
11951                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
11952                 /** AUTH ZUC + CIPHER AES CTR */
11953                 TEST_CASE_ST(ut_setup, ut_teardown,
11954                         test_auth_zuc_cipher_aes_ctr_test_case_1),
11955                 TEST_CASE_ST(ut_setup, ut_teardown,
11956                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
11957                 /** AUTH SNOW3G + CIPHER AES CTR */
11958                 TEST_CASE_ST(ut_setup, ut_teardown,
11959                         test_auth_snow_cipher_aes_ctr_test_case_1),
11960                 TEST_CASE_ST(ut_setup, ut_teardown,
11961                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
11962                 /** AUTH SNOW3G + CIPHER ZUC */
11963                 TEST_CASE_ST(ut_setup, ut_teardown,
11964                         test_auth_snow_cipher_zuc_test_case_1),
11965                 TEST_CASE_ST(ut_setup, ut_teardown,
11966                         test_verify_auth_snow_cipher_zuc_test_case_1),
11967                 /** AUTH AES CMAC + CIPHER ZUC */
11968                 TEST_CASE_ST(ut_setup, ut_teardown,
11969                         test_auth_aes_cmac_cipher_zuc_test_case_1),
11970                 TEST_CASE_ST(ut_setup, ut_teardown,
11971                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
11972
11973                 /** AUTH NULL + CIPHER SNOW3G */
11974                 TEST_CASE_ST(ut_setup, ut_teardown,
11975                         test_auth_null_cipher_snow_test_case_1),
11976                 TEST_CASE_ST(ut_setup, ut_teardown,
11977                         test_verify_auth_null_cipher_snow_test_case_1),
11978                 /** AUTH NULL + CIPHER ZUC */
11979                 TEST_CASE_ST(ut_setup, ut_teardown,
11980                         test_auth_null_cipher_zuc_test_case_1),
11981                 TEST_CASE_ST(ut_setup, ut_teardown,
11982                         test_verify_auth_null_cipher_zuc_test_case_1),
11983                 /** AUTH SNOW3G + CIPHER NULL */
11984                 TEST_CASE_ST(ut_setup, ut_teardown,
11985                         test_auth_snow_cipher_null_test_case_1),
11986                 TEST_CASE_ST(ut_setup, ut_teardown,
11987                         test_verify_auth_snow_cipher_null_test_case_1),
11988                 /** AUTH ZUC + CIPHER NULL */
11989                 TEST_CASE_ST(ut_setup, ut_teardown,
11990                         test_auth_zuc_cipher_null_test_case_1),
11991                 TEST_CASE_ST(ut_setup, ut_teardown,
11992                         test_verify_auth_zuc_cipher_null_test_case_1),
11993                 /** AUTH NULL + CIPHER AES CTR */
11994                 TEST_CASE_ST(ut_setup, ut_teardown,
11995                         test_auth_null_cipher_aes_ctr_test_case_1),
11996                 TEST_CASE_ST(ut_setup, ut_teardown,
11997                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
11998                 /** AUTH AES CMAC + CIPHER NULL */
11999                 TEST_CASE_ST(ut_setup, ut_teardown,
12000                         test_auth_aes_cmac_cipher_null_test_case_1),
12001                 TEST_CASE_ST(ut_setup, ut_teardown,
12002                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
12003
12004                 TEST_CASES_END() /**< NULL terminate unit test array */
12005         }
12006 };
12007
12008 static struct unit_test_suite cryptodev_virtio_testsuite = {
12009         .suite_name = "Crypto VIRTIO Unit Test Suite",
12010         .setup = testsuite_setup,
12011         .teardown = testsuite_teardown,
12012         .unit_test_cases = {
12013                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12014
12015                 TEST_CASES_END() /**< NULL terminate unit test array */
12016         }
12017 };
12018
12019 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
12020         .suite_name = "Crypto Device AESNI MB Unit Test Suite",
12021         .setup = testsuite_setup,
12022         .teardown = testsuite_teardown,
12023         .unit_test_cases = {
12024 #if IMB_VERSION_NUM >= IMB_VERSION(0, 51, 0)
12025                 TEST_CASE_ST(ut_setup, ut_teardown,
12026                         test_AES_GCM_authenticated_encryption_test_case_1),
12027                 TEST_CASE_ST(ut_setup, ut_teardown,
12028                         test_AES_GCM_authenticated_encryption_test_case_2),
12029                 TEST_CASE_ST(ut_setup, ut_teardown,
12030                         test_AES_GCM_authenticated_encryption_test_case_3),
12031                 TEST_CASE_ST(ut_setup, ut_teardown,
12032                         test_AES_GCM_authenticated_encryption_test_case_4),
12033                 TEST_CASE_ST(ut_setup, ut_teardown,
12034                         test_AES_GCM_authenticated_encryption_test_case_5),
12035                 TEST_CASE_ST(ut_setup, ut_teardown,
12036                         test_AES_GCM_authenticated_encryption_test_case_6),
12037                 TEST_CASE_ST(ut_setup, ut_teardown,
12038                         test_AES_GCM_authenticated_encryption_test_case_7),
12039
12040                 /** AES GCM Authenticated Decryption */
12041                 TEST_CASE_ST(ut_setup, ut_teardown,
12042                         test_AES_GCM_authenticated_decryption_test_case_1),
12043                 TEST_CASE_ST(ut_setup, ut_teardown,
12044                         test_AES_GCM_authenticated_decryption_test_case_2),
12045                 TEST_CASE_ST(ut_setup, ut_teardown,
12046                         test_AES_GCM_authenticated_decryption_test_case_3),
12047                 TEST_CASE_ST(ut_setup, ut_teardown,
12048                         test_AES_GCM_authenticated_decryption_test_case_4),
12049                 TEST_CASE_ST(ut_setup, ut_teardown,
12050                         test_AES_GCM_authenticated_decryption_test_case_5),
12051                 TEST_CASE_ST(ut_setup, ut_teardown,
12052                         test_AES_GCM_authenticated_decryption_test_case_6),
12053                 TEST_CASE_ST(ut_setup, ut_teardown,
12054                         test_AES_GCM_authenticated_decryption_test_case_7),
12055
12056                 /** AES GCM Authenticated Encryption 192 bits key */
12057                 TEST_CASE_ST(ut_setup, ut_teardown,
12058                         test_AES_GCM_auth_encryption_test_case_192_1),
12059                 TEST_CASE_ST(ut_setup, ut_teardown,
12060                         test_AES_GCM_auth_encryption_test_case_192_2),
12061                 TEST_CASE_ST(ut_setup, ut_teardown,
12062                         test_AES_GCM_auth_encryption_test_case_192_3),
12063                 TEST_CASE_ST(ut_setup, ut_teardown,
12064                         test_AES_GCM_auth_encryption_test_case_192_4),
12065                 TEST_CASE_ST(ut_setup, ut_teardown,
12066                         test_AES_GCM_auth_encryption_test_case_192_5),
12067                 TEST_CASE_ST(ut_setup, ut_teardown,
12068                         test_AES_GCM_auth_encryption_test_case_192_6),
12069                 TEST_CASE_ST(ut_setup, ut_teardown,
12070                         test_AES_GCM_auth_encryption_test_case_192_7),
12071
12072                 /** AES GCM Authenticated Decryption 192 bits key */
12073                 TEST_CASE_ST(ut_setup, ut_teardown,
12074                         test_AES_GCM_auth_decryption_test_case_192_1),
12075                 TEST_CASE_ST(ut_setup, ut_teardown,
12076                         test_AES_GCM_auth_decryption_test_case_192_2),
12077                 TEST_CASE_ST(ut_setup, ut_teardown,
12078                         test_AES_GCM_auth_decryption_test_case_192_3),
12079                 TEST_CASE_ST(ut_setup, ut_teardown,
12080                         test_AES_GCM_auth_decryption_test_case_192_4),
12081                 TEST_CASE_ST(ut_setup, ut_teardown,
12082                         test_AES_GCM_auth_decryption_test_case_192_5),
12083                 TEST_CASE_ST(ut_setup, ut_teardown,
12084                         test_AES_GCM_auth_decryption_test_case_192_6),
12085                 TEST_CASE_ST(ut_setup, ut_teardown,
12086                         test_AES_GCM_auth_decryption_test_case_192_7),
12087
12088                 /** AES GCM Authenticated Encryption 256 bits key */
12089                 TEST_CASE_ST(ut_setup, ut_teardown,
12090                         test_AES_GCM_auth_encryption_test_case_256_1),
12091                 TEST_CASE_ST(ut_setup, ut_teardown,
12092                         test_AES_GCM_auth_encryption_test_case_256_2),
12093                 TEST_CASE_ST(ut_setup, ut_teardown,
12094                         test_AES_GCM_auth_encryption_test_case_256_3),
12095                 TEST_CASE_ST(ut_setup, ut_teardown,
12096                         test_AES_GCM_auth_encryption_test_case_256_4),
12097                 TEST_CASE_ST(ut_setup, ut_teardown,
12098                         test_AES_GCM_auth_encryption_test_case_256_5),
12099                 TEST_CASE_ST(ut_setup, ut_teardown,
12100                         test_AES_GCM_auth_encryption_test_case_256_6),
12101                 TEST_CASE_ST(ut_setup, ut_teardown,
12102                         test_AES_GCM_auth_encryption_test_case_256_7),
12103
12104                 /** AES GCM Authenticated Decryption 256 bits key */
12105                 TEST_CASE_ST(ut_setup, ut_teardown,
12106                         test_AES_GCM_auth_decryption_test_case_256_1),
12107                 TEST_CASE_ST(ut_setup, ut_teardown,
12108                         test_AES_GCM_auth_decryption_test_case_256_2),
12109                 TEST_CASE_ST(ut_setup, ut_teardown,
12110                         test_AES_GCM_auth_decryption_test_case_256_3),
12111                 TEST_CASE_ST(ut_setup, ut_teardown,
12112                         test_AES_GCM_auth_decryption_test_case_256_4),
12113                 TEST_CASE_ST(ut_setup, ut_teardown,
12114                         test_AES_GCM_auth_decryption_test_case_256_5),
12115                 TEST_CASE_ST(ut_setup, ut_teardown,
12116                         test_AES_GCM_auth_decryption_test_case_256_6),
12117                 TEST_CASE_ST(ut_setup, ut_teardown,
12118                         test_AES_GCM_auth_decryption_test_case_256_7),
12119
12120                 /** AES GCM Authenticated Encryption big aad size */
12121                 TEST_CASE_ST(ut_setup, ut_teardown,
12122                         test_AES_GCM_auth_encryption_test_case_aad_1),
12123                 TEST_CASE_ST(ut_setup, ut_teardown,
12124                         test_AES_GCM_auth_encryption_test_case_aad_2),
12125
12126                 /** AES GCM Authenticated Decryption big aad size */
12127                 TEST_CASE_ST(ut_setup, ut_teardown,
12128                         test_AES_GCM_auth_decryption_test_case_aad_1),
12129                 TEST_CASE_ST(ut_setup, ut_teardown,
12130                         test_AES_GCM_auth_decryption_test_case_aad_2),
12131
12132                 /** Session-less tests */
12133                 TEST_CASE_ST(ut_setup, ut_teardown,
12134                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
12135                 TEST_CASE_ST(ut_setup, ut_teardown,
12136                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
12137
12138                 /** AES GMAC Authentication */
12139                 TEST_CASE_ST(ut_setup, ut_teardown,
12140                         test_AES_GMAC_authentication_test_case_1),
12141                 TEST_CASE_ST(ut_setup, ut_teardown,
12142                         test_AES_GMAC_authentication_verify_test_case_1),
12143                 TEST_CASE_ST(ut_setup, ut_teardown,
12144                         test_AES_GMAC_authentication_test_case_2),
12145                 TEST_CASE_ST(ut_setup, ut_teardown,
12146                         test_AES_GMAC_authentication_verify_test_case_2),
12147                 TEST_CASE_ST(ut_setup, ut_teardown,
12148                         test_AES_GMAC_authentication_test_case_3),
12149                 TEST_CASE_ST(ut_setup, ut_teardown,
12150                         test_AES_GMAC_authentication_verify_test_case_3),
12151 #endif /* IMB_VERSION_NUM >= IMB_VERSION(0, 51, 0) */
12152
12153                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12154                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12155                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
12156                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12157                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
12158                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
12159                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12160                 TEST_CASE_ST(ut_setup, ut_teardown,
12161                         test_AES_CCM_authenticated_encryption_test_case_128_1),
12162                 TEST_CASE_ST(ut_setup, ut_teardown,
12163                         test_AES_CCM_authenticated_decryption_test_case_128_1),
12164                 TEST_CASE_ST(ut_setup, ut_teardown,
12165                         test_AES_CCM_authenticated_encryption_test_case_128_2),
12166                 TEST_CASE_ST(ut_setup, ut_teardown,
12167                         test_AES_CCM_authenticated_decryption_test_case_128_2),
12168                 TEST_CASE_ST(ut_setup, ut_teardown,
12169                         test_AES_CCM_authenticated_encryption_test_case_128_3),
12170                 TEST_CASE_ST(ut_setup, ut_teardown,
12171                         test_AES_CCM_authenticated_decryption_test_case_128_3),
12172
12173                 TEST_CASES_END() /**< NULL terminate unit test array */
12174         }
12175 };
12176
12177 static struct unit_test_suite cryptodev_openssl_testsuite  = {
12178         .suite_name = "Crypto Device OPENSSL Unit Test Suite",
12179         .setup = testsuite_setup,
12180         .teardown = testsuite_teardown,
12181         .unit_test_cases = {
12182                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12183                 TEST_CASE_ST(ut_setup, ut_teardown,
12184                                 test_multi_session_random_usage),
12185                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12186                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12187                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12188                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12189                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
12190                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
12191                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12192
12193                 /** AES GCM Authenticated Encryption */
12194                 TEST_CASE_ST(ut_setup, ut_teardown,
12195                         test_AES_GCM_authenticated_encryption_test_case_1),
12196                 TEST_CASE_ST(ut_setup, ut_teardown,
12197                         test_AES_GCM_authenticated_encryption_test_case_2),
12198                 TEST_CASE_ST(ut_setup, ut_teardown,
12199                         test_AES_GCM_authenticated_encryption_test_case_3),
12200                 TEST_CASE_ST(ut_setup, ut_teardown,
12201                         test_AES_GCM_authenticated_encryption_test_case_4),
12202                 TEST_CASE_ST(ut_setup, ut_teardown,
12203                         test_AES_GCM_authenticated_encryption_test_case_5),
12204                 TEST_CASE_ST(ut_setup, ut_teardown,
12205                         test_AES_GCM_authenticated_encryption_test_case_6),
12206                 TEST_CASE_ST(ut_setup, ut_teardown,
12207                         test_AES_GCM_authenticated_encryption_test_case_7),
12208
12209                 /** AES GCM Authenticated Decryption */
12210                 TEST_CASE_ST(ut_setup, ut_teardown,
12211                         test_AES_GCM_authenticated_decryption_test_case_1),
12212                 TEST_CASE_ST(ut_setup, ut_teardown,
12213                         test_AES_GCM_authenticated_decryption_test_case_2),
12214                 TEST_CASE_ST(ut_setup, ut_teardown,
12215                         test_AES_GCM_authenticated_decryption_test_case_3),
12216                 TEST_CASE_ST(ut_setup, ut_teardown,
12217                         test_AES_GCM_authenticated_decryption_test_case_4),
12218                 TEST_CASE_ST(ut_setup, ut_teardown,
12219                         test_AES_GCM_authenticated_decryption_test_case_5),
12220                 TEST_CASE_ST(ut_setup, ut_teardown,
12221                         test_AES_GCM_authenticated_decryption_test_case_6),
12222                 TEST_CASE_ST(ut_setup, ut_teardown,
12223                         test_AES_GCM_authenticated_decryption_test_case_7),
12224
12225
12226                 /** AES GCM Authenticated Encryption 192 bits key */
12227                 TEST_CASE_ST(ut_setup, ut_teardown,
12228                         test_AES_GCM_auth_encryption_test_case_192_1),
12229                 TEST_CASE_ST(ut_setup, ut_teardown,
12230                         test_AES_GCM_auth_encryption_test_case_192_2),
12231                 TEST_CASE_ST(ut_setup, ut_teardown,
12232                         test_AES_GCM_auth_encryption_test_case_192_3),
12233                 TEST_CASE_ST(ut_setup, ut_teardown,
12234                         test_AES_GCM_auth_encryption_test_case_192_4),
12235                 TEST_CASE_ST(ut_setup, ut_teardown,
12236                         test_AES_GCM_auth_encryption_test_case_192_5),
12237                 TEST_CASE_ST(ut_setup, ut_teardown,
12238                         test_AES_GCM_auth_encryption_test_case_192_6),
12239                 TEST_CASE_ST(ut_setup, ut_teardown,
12240                         test_AES_GCM_auth_encryption_test_case_192_7),
12241
12242                 /** AES GCM Authenticated Decryption 192 bits key */
12243                 TEST_CASE_ST(ut_setup, ut_teardown,
12244                         test_AES_GCM_auth_decryption_test_case_192_1),
12245                 TEST_CASE_ST(ut_setup, ut_teardown,
12246                         test_AES_GCM_auth_decryption_test_case_192_2),
12247                 TEST_CASE_ST(ut_setup, ut_teardown,
12248                         test_AES_GCM_auth_decryption_test_case_192_3),
12249                 TEST_CASE_ST(ut_setup, ut_teardown,
12250                         test_AES_GCM_auth_decryption_test_case_192_4),
12251                 TEST_CASE_ST(ut_setup, ut_teardown,
12252                         test_AES_GCM_auth_decryption_test_case_192_5),
12253                 TEST_CASE_ST(ut_setup, ut_teardown,
12254                         test_AES_GCM_auth_decryption_test_case_192_6),
12255                 TEST_CASE_ST(ut_setup, ut_teardown,
12256                         test_AES_GCM_auth_decryption_test_case_192_7),
12257
12258                 /** AES GCM Authenticated Encryption 256 bits key */
12259                 TEST_CASE_ST(ut_setup, ut_teardown,
12260                         test_AES_GCM_auth_encryption_test_case_256_1),
12261                 TEST_CASE_ST(ut_setup, ut_teardown,
12262                         test_AES_GCM_auth_encryption_test_case_256_2),
12263                 TEST_CASE_ST(ut_setup, ut_teardown,
12264                         test_AES_GCM_auth_encryption_test_case_256_3),
12265                 TEST_CASE_ST(ut_setup, ut_teardown,
12266                         test_AES_GCM_auth_encryption_test_case_256_4),
12267                 TEST_CASE_ST(ut_setup, ut_teardown,
12268                         test_AES_GCM_auth_encryption_test_case_256_5),
12269                 TEST_CASE_ST(ut_setup, ut_teardown,
12270                         test_AES_GCM_auth_encryption_test_case_256_6),
12271                 TEST_CASE_ST(ut_setup, ut_teardown,
12272                         test_AES_GCM_auth_encryption_test_case_256_7),
12273
12274                 /** AES GCM Authenticated Decryption 256 bits key */
12275                 TEST_CASE_ST(ut_setup, ut_teardown,
12276                         test_AES_GCM_auth_decryption_test_case_256_1),
12277                 TEST_CASE_ST(ut_setup, ut_teardown,
12278                         test_AES_GCM_auth_decryption_test_case_256_2),
12279                 TEST_CASE_ST(ut_setup, ut_teardown,
12280                         test_AES_GCM_auth_decryption_test_case_256_3),
12281                 TEST_CASE_ST(ut_setup, ut_teardown,
12282                         test_AES_GCM_auth_decryption_test_case_256_4),
12283                 TEST_CASE_ST(ut_setup, ut_teardown,
12284                         test_AES_GCM_auth_decryption_test_case_256_5),
12285                 TEST_CASE_ST(ut_setup, ut_teardown,
12286                         test_AES_GCM_auth_decryption_test_case_256_6),
12287                 TEST_CASE_ST(ut_setup, ut_teardown,
12288                         test_AES_GCM_auth_decryption_test_case_256_7),
12289
12290                 /** AES GMAC Authentication */
12291                 TEST_CASE_ST(ut_setup, ut_teardown,
12292                         test_AES_GMAC_authentication_test_case_1),
12293                 TEST_CASE_ST(ut_setup, ut_teardown,
12294                         test_AES_GMAC_authentication_verify_test_case_1),
12295                 TEST_CASE_ST(ut_setup, ut_teardown,
12296                         test_AES_GMAC_authentication_test_case_2),
12297                 TEST_CASE_ST(ut_setup, ut_teardown,
12298                         test_AES_GMAC_authentication_verify_test_case_2),
12299                 TEST_CASE_ST(ut_setup, ut_teardown,
12300                         test_AES_GMAC_authentication_test_case_3),
12301                 TEST_CASE_ST(ut_setup, ut_teardown,
12302                         test_AES_GMAC_authentication_verify_test_case_3),
12303                 TEST_CASE_ST(ut_setup, ut_teardown,
12304                         test_AES_GMAC_authentication_test_case_4),
12305                 TEST_CASE_ST(ut_setup, ut_teardown,
12306                         test_AES_GMAC_authentication_verify_test_case_4),
12307
12308                 /** AES CCM Authenticated Encryption 128 bits key */
12309                 TEST_CASE_ST(ut_setup, ut_teardown,
12310                         test_AES_CCM_authenticated_encryption_test_case_128_1),
12311                 TEST_CASE_ST(ut_setup, ut_teardown,
12312                         test_AES_CCM_authenticated_encryption_test_case_128_2),
12313                 TEST_CASE_ST(ut_setup, ut_teardown,
12314                         test_AES_CCM_authenticated_encryption_test_case_128_3),
12315
12316                 /** AES CCM Authenticated Decryption 128 bits key*/
12317                 TEST_CASE_ST(ut_setup, ut_teardown,
12318                         test_AES_CCM_authenticated_decryption_test_case_128_1),
12319                 TEST_CASE_ST(ut_setup, ut_teardown,
12320                         test_AES_CCM_authenticated_decryption_test_case_128_2),
12321                 TEST_CASE_ST(ut_setup, ut_teardown,
12322                         test_AES_CCM_authenticated_decryption_test_case_128_3),
12323
12324                 /** AES CCM Authenticated Encryption 192 bits key */
12325                 TEST_CASE_ST(ut_setup, ut_teardown,
12326                         test_AES_CCM_authenticated_encryption_test_case_192_1),
12327                 TEST_CASE_ST(ut_setup, ut_teardown,
12328                         test_AES_CCM_authenticated_encryption_test_case_192_2),
12329                 TEST_CASE_ST(ut_setup, ut_teardown,
12330                         test_AES_CCM_authenticated_encryption_test_case_192_3),
12331
12332                 /** AES CCM Authenticated Decryption 192 bits key*/
12333                 TEST_CASE_ST(ut_setup, ut_teardown,
12334                         test_AES_CCM_authenticated_decryption_test_case_192_1),
12335                 TEST_CASE_ST(ut_setup, ut_teardown,
12336                         test_AES_CCM_authenticated_decryption_test_case_192_2),
12337                 TEST_CASE_ST(ut_setup, ut_teardown,
12338                         test_AES_CCM_authenticated_decryption_test_case_192_3),
12339
12340                 /** AES CCM Authenticated Encryption 256 bits key */
12341                 TEST_CASE_ST(ut_setup, ut_teardown,
12342                         test_AES_CCM_authenticated_encryption_test_case_256_1),
12343                 TEST_CASE_ST(ut_setup, ut_teardown,
12344                         test_AES_CCM_authenticated_encryption_test_case_256_2),
12345                 TEST_CASE_ST(ut_setup, ut_teardown,
12346                         test_AES_CCM_authenticated_encryption_test_case_256_3),
12347
12348                 /** AES CCM Authenticated Decryption 256 bits key*/
12349                 TEST_CASE_ST(ut_setup, ut_teardown,
12350                         test_AES_CCM_authenticated_decryption_test_case_256_1),
12351                 TEST_CASE_ST(ut_setup, ut_teardown,
12352                         test_AES_CCM_authenticated_decryption_test_case_256_2),
12353                 TEST_CASE_ST(ut_setup, ut_teardown,
12354                         test_AES_CCM_authenticated_decryption_test_case_256_3),
12355
12356                 /** Scatter-Gather */
12357                 TEST_CASE_ST(ut_setup, ut_teardown,
12358                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12359
12360                 /** Negative tests */
12361                 TEST_CASE_ST(ut_setup, ut_teardown,
12362                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12363                 TEST_CASE_ST(ut_setup, ut_teardown,
12364                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12365                 TEST_CASE_ST(ut_setup, ut_teardown,
12366                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12367                 TEST_CASE_ST(ut_setup, ut_teardown,
12368                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12369                 TEST_CASE_ST(ut_setup, ut_teardown,
12370                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12371                 TEST_CASE_ST(ut_setup, ut_teardown,
12372                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12373
12374                 /* ESN Testcase */
12375                 TEST_CASE_ST(ut_setup, ut_teardown,
12376                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12377
12378                 TEST_CASE_ST(ut_setup, ut_teardown,
12379                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12380
12381                 TEST_CASES_END() /**< NULL terminate unit test array */
12382         }
12383 };
12384
12385 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
12386         .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
12387         .setup = testsuite_setup,
12388         .teardown = testsuite_teardown,
12389         .unit_test_cases = {
12390                 /** AES GCM Authenticated Encryption */
12391                 TEST_CASE_ST(ut_setup, ut_teardown,
12392                         test_AES_GCM_authenticated_encryption_test_case_1),
12393                 TEST_CASE_ST(ut_setup, ut_teardown,
12394                         test_AES_GCM_authenticated_encryption_test_case_2),
12395                 TEST_CASE_ST(ut_setup, ut_teardown,
12396                         test_AES_GCM_authenticated_encryption_test_case_3),
12397                 TEST_CASE_ST(ut_setup, ut_teardown,
12398                         test_AES_GCM_authenticated_encryption_test_case_4),
12399                 TEST_CASE_ST(ut_setup, ut_teardown,
12400                         test_AES_GCM_authenticated_encryption_test_case_5),
12401                 TEST_CASE_ST(ut_setup, ut_teardown,
12402                         test_AES_GCM_authenticated_encryption_test_case_6),
12403                 TEST_CASE_ST(ut_setup, ut_teardown,
12404                         test_AES_GCM_authenticated_encryption_test_case_7),
12405
12406                 /** AES GCM Authenticated Decryption */
12407                 TEST_CASE_ST(ut_setup, ut_teardown,
12408                         test_AES_GCM_authenticated_decryption_test_case_1),
12409                 TEST_CASE_ST(ut_setup, ut_teardown,
12410                         test_AES_GCM_authenticated_decryption_test_case_2),
12411                 TEST_CASE_ST(ut_setup, ut_teardown,
12412                         test_AES_GCM_authenticated_decryption_test_case_3),
12413                 TEST_CASE_ST(ut_setup, ut_teardown,
12414                         test_AES_GCM_authenticated_decryption_test_case_4),
12415                 TEST_CASE_ST(ut_setup, ut_teardown,
12416                         test_AES_GCM_authenticated_decryption_test_case_5),
12417                 TEST_CASE_ST(ut_setup, ut_teardown,
12418                         test_AES_GCM_authenticated_decryption_test_case_6),
12419                 TEST_CASE_ST(ut_setup, ut_teardown,
12420                         test_AES_GCM_authenticated_decryption_test_case_7),
12421
12422                 /** AES GCM Authenticated Encryption 192 bits key */
12423                 TEST_CASE_ST(ut_setup, ut_teardown,
12424                         test_AES_GCM_auth_encryption_test_case_192_1),
12425                 TEST_CASE_ST(ut_setup, ut_teardown,
12426                         test_AES_GCM_auth_encryption_test_case_192_2),
12427                 TEST_CASE_ST(ut_setup, ut_teardown,
12428                         test_AES_GCM_auth_encryption_test_case_192_3),
12429                 TEST_CASE_ST(ut_setup, ut_teardown,
12430                         test_AES_GCM_auth_encryption_test_case_192_4),
12431                 TEST_CASE_ST(ut_setup, ut_teardown,
12432                         test_AES_GCM_auth_encryption_test_case_192_5),
12433                 TEST_CASE_ST(ut_setup, ut_teardown,
12434                         test_AES_GCM_auth_encryption_test_case_192_6),
12435                 TEST_CASE_ST(ut_setup, ut_teardown,
12436                         test_AES_GCM_auth_encryption_test_case_192_7),
12437
12438                 /** AES GCM Authenticated Decryption 192 bits key */
12439                 TEST_CASE_ST(ut_setup, ut_teardown,
12440                         test_AES_GCM_auth_decryption_test_case_192_1),
12441                 TEST_CASE_ST(ut_setup, ut_teardown,
12442                         test_AES_GCM_auth_decryption_test_case_192_2),
12443                 TEST_CASE_ST(ut_setup, ut_teardown,
12444                         test_AES_GCM_auth_decryption_test_case_192_3),
12445                 TEST_CASE_ST(ut_setup, ut_teardown,
12446                         test_AES_GCM_auth_decryption_test_case_192_4),
12447                 TEST_CASE_ST(ut_setup, ut_teardown,
12448                         test_AES_GCM_auth_decryption_test_case_192_5),
12449                 TEST_CASE_ST(ut_setup, ut_teardown,
12450                         test_AES_GCM_auth_decryption_test_case_192_6),
12451                 TEST_CASE_ST(ut_setup, ut_teardown,
12452                         test_AES_GCM_auth_decryption_test_case_192_7),
12453
12454                 /** AES GCM Authenticated Encryption 256 bits key */
12455                 TEST_CASE_ST(ut_setup, ut_teardown,
12456                         test_AES_GCM_auth_encryption_test_case_256_1),
12457                 TEST_CASE_ST(ut_setup, ut_teardown,
12458                         test_AES_GCM_auth_encryption_test_case_256_2),
12459                 TEST_CASE_ST(ut_setup, ut_teardown,
12460                         test_AES_GCM_auth_encryption_test_case_256_3),
12461                 TEST_CASE_ST(ut_setup, ut_teardown,
12462                         test_AES_GCM_auth_encryption_test_case_256_4),
12463                 TEST_CASE_ST(ut_setup, ut_teardown,
12464                         test_AES_GCM_auth_encryption_test_case_256_5),
12465                 TEST_CASE_ST(ut_setup, ut_teardown,
12466                         test_AES_GCM_auth_encryption_test_case_256_6),
12467                 TEST_CASE_ST(ut_setup, ut_teardown,
12468                         test_AES_GCM_auth_encryption_test_case_256_7),
12469
12470                 /** AES GCM Authenticated Decryption 256 bits key */
12471                 TEST_CASE_ST(ut_setup, ut_teardown,
12472                         test_AES_GCM_auth_decryption_test_case_256_1),
12473                 TEST_CASE_ST(ut_setup, ut_teardown,
12474                         test_AES_GCM_auth_decryption_test_case_256_2),
12475                 TEST_CASE_ST(ut_setup, ut_teardown,
12476                         test_AES_GCM_auth_decryption_test_case_256_3),
12477                 TEST_CASE_ST(ut_setup, ut_teardown,
12478                         test_AES_GCM_auth_decryption_test_case_256_4),
12479                 TEST_CASE_ST(ut_setup, ut_teardown,
12480                         test_AES_GCM_auth_decryption_test_case_256_5),
12481                 TEST_CASE_ST(ut_setup, ut_teardown,
12482                         test_AES_GCM_auth_decryption_test_case_256_6),
12483                 TEST_CASE_ST(ut_setup, ut_teardown,
12484                         test_AES_GCM_auth_decryption_test_case_256_7),
12485
12486                 /** AES GCM Authenticated Encryption big aad size */
12487                 TEST_CASE_ST(ut_setup, ut_teardown,
12488                         test_AES_GCM_auth_encryption_test_case_aad_1),
12489                 TEST_CASE_ST(ut_setup, ut_teardown,
12490                         test_AES_GCM_auth_encryption_test_case_aad_2),
12491
12492                 /** AES GCM Authenticated Decryption big aad size */
12493                 TEST_CASE_ST(ut_setup, ut_teardown,
12494                         test_AES_GCM_auth_decryption_test_case_aad_1),
12495                 TEST_CASE_ST(ut_setup, ut_teardown,
12496                         test_AES_GCM_auth_decryption_test_case_aad_2),
12497
12498                 /** AES GMAC Authentication */
12499                 TEST_CASE_ST(ut_setup, ut_teardown,
12500                         test_AES_GMAC_authentication_test_case_1),
12501                 TEST_CASE_ST(ut_setup, ut_teardown,
12502                         test_AES_GMAC_authentication_verify_test_case_1),
12503                 TEST_CASE_ST(ut_setup, ut_teardown,
12504                         test_AES_GMAC_authentication_test_case_3),
12505                 TEST_CASE_ST(ut_setup, ut_teardown,
12506                         test_AES_GMAC_authentication_verify_test_case_3),
12507                 TEST_CASE_ST(ut_setup, ut_teardown,
12508                         test_AES_GMAC_authentication_test_case_4),
12509                 TEST_CASE_ST(ut_setup, ut_teardown,
12510                         test_AES_GMAC_authentication_verify_test_case_4),
12511
12512                 /** Negative tests */
12513                 TEST_CASE_ST(ut_setup, ut_teardown,
12514                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12515                 TEST_CASE_ST(ut_setup, ut_teardown,
12516                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12517
12518                 /** Out of place tests */
12519                 TEST_CASE_ST(ut_setup, ut_teardown,
12520                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12521                 TEST_CASE_ST(ut_setup, ut_teardown,
12522                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12523
12524                 /** Session-less tests */
12525                 TEST_CASE_ST(ut_setup, ut_teardown,
12526                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
12527                 TEST_CASE_ST(ut_setup, ut_teardown,
12528                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
12529
12530                 /** Scatter-Gather */
12531                 TEST_CASE_ST(ut_setup, ut_teardown,
12532                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12533                 TEST_CASE_ST(ut_setup, ut_teardown,
12534                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12535
12536                 TEST_CASES_END() /**< NULL terminate unit test array */
12537         }
12538 };
12539
12540 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
12541         .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
12542         .setup = testsuite_setup,
12543         .teardown = testsuite_teardown,
12544         .unit_test_cases = {
12545                 /** KASUMI encrypt only (UEA1) */
12546                 TEST_CASE_ST(ut_setup, ut_teardown,
12547                         test_kasumi_encryption_test_case_1),
12548                 TEST_CASE_ST(ut_setup, ut_teardown,
12549                         test_kasumi_encryption_test_case_1_sgl),
12550                 TEST_CASE_ST(ut_setup, ut_teardown,
12551                         test_kasumi_encryption_test_case_2),
12552                 TEST_CASE_ST(ut_setup, ut_teardown,
12553                         test_kasumi_encryption_test_case_3),
12554                 TEST_CASE_ST(ut_setup, ut_teardown,
12555                         test_kasumi_encryption_test_case_4),
12556                 TEST_CASE_ST(ut_setup, ut_teardown,
12557                         test_kasumi_encryption_test_case_5),
12558                 /** KASUMI decrypt only (UEA1) */
12559                 TEST_CASE_ST(ut_setup, ut_teardown,
12560                         test_kasumi_decryption_test_case_1),
12561                 TEST_CASE_ST(ut_setup, ut_teardown,
12562                         test_kasumi_decryption_test_case_2),
12563                 TEST_CASE_ST(ut_setup, ut_teardown,
12564                         test_kasumi_decryption_test_case_3),
12565                 TEST_CASE_ST(ut_setup, ut_teardown,
12566                         test_kasumi_decryption_test_case_4),
12567                 TEST_CASE_ST(ut_setup, ut_teardown,
12568                         test_kasumi_decryption_test_case_5),
12569
12570                 TEST_CASE_ST(ut_setup, ut_teardown,
12571                         test_kasumi_encryption_test_case_1_oop),
12572                 TEST_CASE_ST(ut_setup, ut_teardown,
12573                         test_kasumi_encryption_test_case_1_oop_sgl),
12574
12575
12576                 TEST_CASE_ST(ut_setup, ut_teardown,
12577                         test_kasumi_decryption_test_case_1_oop),
12578
12579                 /** KASUMI hash only (UIA1) */
12580                 TEST_CASE_ST(ut_setup, ut_teardown,
12581                         test_kasumi_hash_generate_test_case_1),
12582                 TEST_CASE_ST(ut_setup, ut_teardown,
12583                         test_kasumi_hash_generate_test_case_2),
12584                 TEST_CASE_ST(ut_setup, ut_teardown,
12585                         test_kasumi_hash_generate_test_case_3),
12586                 TEST_CASE_ST(ut_setup, ut_teardown,
12587                         test_kasumi_hash_generate_test_case_4),
12588                 TEST_CASE_ST(ut_setup, ut_teardown,
12589                         test_kasumi_hash_generate_test_case_5),
12590                 TEST_CASE_ST(ut_setup, ut_teardown,
12591                         test_kasumi_hash_generate_test_case_6),
12592                 TEST_CASE_ST(ut_setup, ut_teardown,
12593                         test_kasumi_hash_verify_test_case_1),
12594                 TEST_CASE_ST(ut_setup, ut_teardown,
12595                         test_kasumi_hash_verify_test_case_2),
12596                 TEST_CASE_ST(ut_setup, ut_teardown,
12597                         test_kasumi_hash_verify_test_case_3),
12598                 TEST_CASE_ST(ut_setup, ut_teardown,
12599                         test_kasumi_hash_verify_test_case_4),
12600                 TEST_CASE_ST(ut_setup, ut_teardown,
12601                         test_kasumi_hash_verify_test_case_5),
12602                 TEST_CASE_ST(ut_setup, ut_teardown,
12603                         test_kasumi_cipher_auth_test_case_1),
12604
12605                 /** KASUMI generate auth, then encrypt (F8) */
12606                 TEST_CASE_ST(ut_setup, ut_teardown,
12607                         test_kasumi_auth_cipher_test_case_1),
12608                 TEST_CASE_ST(ut_setup, ut_teardown,
12609                         test_kasumi_auth_cipher_test_case_2),
12610                 TEST_CASE_ST(ut_setup, ut_teardown,
12611                         test_kasumi_auth_cipher_test_case_2_oop),
12612                 TEST_CASE_ST(ut_setup, ut_teardown,
12613                         test_kasumi_auth_cipher_test_case_2_sgl),
12614                 TEST_CASE_ST(ut_setup, ut_teardown,
12615                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
12616
12617                 /** KASUMI decrypt (F8), then verify auth */
12618                 TEST_CASE_ST(ut_setup, ut_teardown,
12619                         test_kasumi_auth_cipher_verify_test_case_1),
12620                 TEST_CASE_ST(ut_setup, ut_teardown,
12621                         test_kasumi_auth_cipher_verify_test_case_2),
12622                 TEST_CASE_ST(ut_setup, ut_teardown,
12623                         test_kasumi_auth_cipher_verify_test_case_2_oop),
12624                 TEST_CASE_ST(ut_setup, ut_teardown,
12625                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
12626                 TEST_CASE_ST(ut_setup, ut_teardown,
12627                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
12628                 TEST_CASES_END() /**< NULL terminate unit test array */
12629         }
12630 };
12631 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
12632         .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
12633         .setup = testsuite_setup,
12634         .teardown = testsuite_teardown,
12635         .unit_test_cases = {
12636                 /** SNOW 3G encrypt only (UEA2) */
12637                 TEST_CASE_ST(ut_setup, ut_teardown,
12638                         test_snow3g_encryption_test_case_1),
12639                 TEST_CASE_ST(ut_setup, ut_teardown,
12640                         test_snow3g_encryption_test_case_2),
12641                 TEST_CASE_ST(ut_setup, ut_teardown,
12642                         test_snow3g_encryption_test_case_3),
12643                 TEST_CASE_ST(ut_setup, ut_teardown,
12644                         test_snow3g_encryption_test_case_4),
12645                 TEST_CASE_ST(ut_setup, ut_teardown,
12646                         test_snow3g_encryption_test_case_5),
12647                 TEST_CASE_ST(ut_setup, ut_teardown,
12648                         test_snow3g_auth_cipher_with_digest_test_case_1),
12649
12650                 TEST_CASE_ST(ut_setup, ut_teardown,
12651                         test_snow3g_encryption_test_case_1_oop),
12652                 TEST_CASE_ST(ut_setup, ut_teardown,
12653                                 test_snow3g_encryption_test_case_1_oop_sgl),
12654                 TEST_CASE_ST(ut_setup, ut_teardown,
12655                         test_snow3g_decryption_test_case_1_oop),
12656
12657                 TEST_CASE_ST(ut_setup, ut_teardown,
12658                         test_snow3g_encryption_test_case_1_offset_oop),
12659
12660                 /** SNOW 3G decrypt only (UEA2) */
12661                 TEST_CASE_ST(ut_setup, ut_teardown,
12662                         test_snow3g_decryption_test_case_1),
12663                 TEST_CASE_ST(ut_setup, ut_teardown,
12664                         test_snow3g_decryption_test_case_2),
12665                 TEST_CASE_ST(ut_setup, ut_teardown,
12666                         test_snow3g_decryption_test_case_3),
12667                 TEST_CASE_ST(ut_setup, ut_teardown,
12668                         test_snow3g_decryption_test_case_4),
12669                 TEST_CASE_ST(ut_setup, ut_teardown,
12670                         test_snow3g_decryption_test_case_5),
12671                 TEST_CASE_ST(ut_setup, ut_teardown,
12672                         test_snow3g_decryption_with_digest_test_case_1),
12673                 TEST_CASE_ST(ut_setup, ut_teardown,
12674                         test_snow3g_hash_generate_test_case_1),
12675                 TEST_CASE_ST(ut_setup, ut_teardown,
12676                         test_snow3g_hash_generate_test_case_2),
12677                 TEST_CASE_ST(ut_setup, ut_teardown,
12678                         test_snow3g_hash_generate_test_case_3),
12679                 /* Tests with buffers which length is not byte-aligned */
12680                 TEST_CASE_ST(ut_setup, ut_teardown,
12681                         test_snow3g_hash_generate_test_case_4),
12682                 TEST_CASE_ST(ut_setup, ut_teardown,
12683                         test_snow3g_hash_generate_test_case_5),
12684                 TEST_CASE_ST(ut_setup, ut_teardown,
12685                         test_snow3g_hash_generate_test_case_6),
12686                 TEST_CASE_ST(ut_setup, ut_teardown,
12687                         test_snow3g_hash_verify_test_case_1),
12688                 TEST_CASE_ST(ut_setup, ut_teardown,
12689                         test_snow3g_hash_verify_test_case_2),
12690                 TEST_CASE_ST(ut_setup, ut_teardown,
12691                         test_snow3g_hash_verify_test_case_3),
12692                 /* Tests with buffers which length is not byte-aligned */
12693                 TEST_CASE_ST(ut_setup, ut_teardown,
12694                         test_snow3g_hash_verify_test_case_4),
12695                 TEST_CASE_ST(ut_setup, ut_teardown,
12696                         test_snow3g_hash_verify_test_case_5),
12697                 TEST_CASE_ST(ut_setup, ut_teardown,
12698                         test_snow3g_hash_verify_test_case_6),
12699                 TEST_CASE_ST(ut_setup, ut_teardown,
12700                         test_snow3g_cipher_auth_test_case_1),
12701
12702                 /** SNOW 3G generate auth, then encrypt (UEA2) */
12703                 TEST_CASE_ST(ut_setup, ut_teardown,
12704                         test_snow3g_auth_cipher_test_case_1),
12705                 TEST_CASE_ST(ut_setup, ut_teardown,
12706                         test_snow3g_auth_cipher_test_case_2),
12707                 TEST_CASE_ST(ut_setup, ut_teardown,
12708                         test_snow3g_auth_cipher_test_case_2_oop),
12709                 TEST_CASE_ST(ut_setup, ut_teardown,
12710                         test_snow3g_auth_cipher_part_digest_enc),
12711                 TEST_CASE_ST(ut_setup, ut_teardown,
12712                         test_snow3g_auth_cipher_part_digest_enc_oop),
12713                 TEST_CASE_ST(ut_setup, ut_teardown,
12714                         test_snow3g_auth_cipher_test_case_3_sgl),
12715                 TEST_CASE_ST(ut_setup, ut_teardown,
12716                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
12717                 TEST_CASE_ST(ut_setup, ut_teardown,
12718                         test_snow3g_auth_cipher_part_digest_enc_sgl),
12719                 TEST_CASE_ST(ut_setup, ut_teardown,
12720                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
12721
12722                 /** SNOW 3G decrypt (UEA2), then verify auth */
12723                 TEST_CASE_ST(ut_setup, ut_teardown,
12724                         test_snow3g_auth_cipher_verify_test_case_1),
12725                 TEST_CASE_ST(ut_setup, ut_teardown,
12726                         test_snow3g_auth_cipher_verify_test_case_2),
12727                 TEST_CASE_ST(ut_setup, ut_teardown,
12728                         test_snow3g_auth_cipher_verify_test_case_2_oop),
12729                 TEST_CASE_ST(ut_setup, ut_teardown,
12730                         test_snow3g_auth_cipher_verify_part_digest_enc),
12731                 TEST_CASE_ST(ut_setup, ut_teardown,
12732                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
12733                 TEST_CASE_ST(ut_setup, ut_teardown,
12734                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
12735                 TEST_CASE_ST(ut_setup, ut_teardown,
12736                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
12737                 TEST_CASE_ST(ut_setup, ut_teardown,
12738                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
12739                 TEST_CASE_ST(ut_setup, ut_teardown,
12740                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
12741
12742                 TEST_CASES_END() /**< NULL terminate unit test array */
12743         }
12744 };
12745
12746 static struct unit_test_suite cryptodev_sw_zuc_testsuite  = {
12747         .suite_name = "Crypto Device SW ZUC Unit Test Suite",
12748         .setup = testsuite_setup,
12749         .teardown = testsuite_teardown,
12750         .unit_test_cases = {
12751                 /** ZUC encrypt only (EEA3) */
12752                 TEST_CASE_ST(ut_setup, ut_teardown,
12753                         test_zuc_encryption_test_case_1),
12754                 TEST_CASE_ST(ut_setup, ut_teardown,
12755                         test_zuc_encryption_test_case_2),
12756                 TEST_CASE_ST(ut_setup, ut_teardown,
12757                         test_zuc_encryption_test_case_3),
12758                 TEST_CASE_ST(ut_setup, ut_teardown,
12759                         test_zuc_encryption_test_case_4),
12760                 TEST_CASE_ST(ut_setup, ut_teardown,
12761                         test_zuc_encryption_test_case_5),
12762                 TEST_CASE_ST(ut_setup, ut_teardown,
12763                         test_zuc_hash_generate_test_case_1),
12764                 TEST_CASE_ST(ut_setup, ut_teardown,
12765                         test_zuc_hash_generate_test_case_2),
12766                 TEST_CASE_ST(ut_setup, ut_teardown,
12767                         test_zuc_hash_generate_test_case_3),
12768                 TEST_CASE_ST(ut_setup, ut_teardown,
12769                         test_zuc_hash_generate_test_case_4),
12770                 TEST_CASE_ST(ut_setup, ut_teardown,
12771                         test_zuc_hash_generate_test_case_5),
12772                 TEST_CASE_ST(ut_setup, ut_teardown,
12773                         test_zuc_encryption_test_case_6_sgl),
12774                 TEST_CASES_END() /**< NULL terminate unit test array */
12775         }
12776 };
12777
12778 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
12779         .suite_name = "Crypto CAAM JR Unit Test Suite",
12780         .setup = testsuite_setup,
12781         .teardown = testsuite_teardown,
12782         .unit_test_cases = {
12783                 TEST_CASE_ST(ut_setup, ut_teardown,
12784                              test_device_configure_invalid_dev_id),
12785                 TEST_CASE_ST(ut_setup, ut_teardown,
12786                              test_multi_session),
12787
12788                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12789                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12790                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12791                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12792                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12793
12794                 TEST_CASES_END() /**< NULL terminate unit test array */
12795         }
12796 };
12797
12798 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
12799         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
12800         .setup = testsuite_setup,
12801         .teardown = testsuite_teardown,
12802         .unit_test_cases = {
12803                 TEST_CASE_ST(ut_setup, ut_teardown,
12804                              test_device_configure_invalid_dev_id),
12805                 TEST_CASE_ST(ut_setup, ut_teardown,
12806                              test_multi_session),
12807
12808                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12809                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12810                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12811                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12812                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12813
12814 #ifdef RTE_LIBRTE_SECURITY
12815                 TEST_CASE_ST(ut_setup, ut_teardown,
12816                         test_PDCP_PROTO_cplane_encap_all),
12817
12818                 TEST_CASE_ST(ut_setup, ut_teardown,
12819                         test_PDCP_PROTO_cplane_decap_all),
12820
12821                 TEST_CASE_ST(ut_setup, ut_teardown,
12822                         test_PDCP_PROTO_uplane_encap_all),
12823
12824                 TEST_CASE_ST(ut_setup, ut_teardown,
12825                         test_PDCP_PROTO_uplane_decap_all),
12826
12827                 TEST_CASE_ST(ut_setup, ut_teardown,
12828                         test_PDCP_PROTO_SGL_in_place_32B),
12829                 TEST_CASE_ST(ut_setup, ut_teardown,
12830                         test_PDCP_PROTO_SGL_oop_32B_128B),
12831                 TEST_CASE_ST(ut_setup, ut_teardown,
12832                         test_PDCP_PROTO_SGL_oop_32B_40B),
12833                 TEST_CASE_ST(ut_setup, ut_teardown,
12834                         test_PDCP_PROTO_SGL_oop_128B_32B),
12835 #endif
12836                 /** AES GCM Authenticated Encryption */
12837                 TEST_CASE_ST(ut_setup, ut_teardown,
12838                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12839                 TEST_CASE_ST(ut_setup, ut_teardown,
12840                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12841                 TEST_CASE_ST(ut_setup, ut_teardown,
12842                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12843                 TEST_CASE_ST(ut_setup, ut_teardown,
12844                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12845                 TEST_CASE_ST(ut_setup, ut_teardown,
12846                         test_AES_GCM_authenticated_encryption_test_case_1),
12847                 TEST_CASE_ST(ut_setup, ut_teardown,
12848                         test_AES_GCM_authenticated_encryption_test_case_2),
12849                 TEST_CASE_ST(ut_setup, ut_teardown,
12850                         test_AES_GCM_authenticated_encryption_test_case_3),
12851                 TEST_CASE_ST(ut_setup, ut_teardown,
12852                         test_AES_GCM_authenticated_encryption_test_case_4),
12853                 TEST_CASE_ST(ut_setup, ut_teardown,
12854                         test_AES_GCM_authenticated_encryption_test_case_5),
12855                 TEST_CASE_ST(ut_setup, ut_teardown,
12856                         test_AES_GCM_authenticated_encryption_test_case_6),
12857                 TEST_CASE_ST(ut_setup, ut_teardown,
12858                         test_AES_GCM_authenticated_encryption_test_case_7),
12859                 TEST_CASE_ST(ut_setup, ut_teardown,
12860                         test_AES_GCM_authenticated_encryption_test_case_8),
12861
12862                 /** AES GCM Authenticated Decryption */
12863                 TEST_CASE_ST(ut_setup, ut_teardown,
12864                         test_AES_GCM_authenticated_decryption_test_case_1),
12865                 TEST_CASE_ST(ut_setup, ut_teardown,
12866                         test_AES_GCM_authenticated_decryption_test_case_2),
12867                 TEST_CASE_ST(ut_setup, ut_teardown,
12868                         test_AES_GCM_authenticated_decryption_test_case_3),
12869                 TEST_CASE_ST(ut_setup, ut_teardown,
12870                         test_AES_GCM_authenticated_decryption_test_case_4),
12871                 TEST_CASE_ST(ut_setup, ut_teardown,
12872                         test_AES_GCM_authenticated_decryption_test_case_5),
12873                 TEST_CASE_ST(ut_setup, ut_teardown,
12874                         test_AES_GCM_authenticated_decryption_test_case_6),
12875                 TEST_CASE_ST(ut_setup, ut_teardown,
12876                         test_AES_GCM_authenticated_decryption_test_case_7),
12877                 TEST_CASE_ST(ut_setup, ut_teardown,
12878                         test_AES_GCM_authenticated_decryption_test_case_8),
12879
12880                 /** AES GCM Authenticated Encryption 192 bits key */
12881                 TEST_CASE_ST(ut_setup, ut_teardown,
12882                         test_AES_GCM_auth_encryption_test_case_192_1),
12883                 TEST_CASE_ST(ut_setup, ut_teardown,
12884                         test_AES_GCM_auth_encryption_test_case_192_2),
12885                 TEST_CASE_ST(ut_setup, ut_teardown,
12886                         test_AES_GCM_auth_encryption_test_case_192_3),
12887                 TEST_CASE_ST(ut_setup, ut_teardown,
12888                         test_AES_GCM_auth_encryption_test_case_192_4),
12889                 TEST_CASE_ST(ut_setup, ut_teardown,
12890                         test_AES_GCM_auth_encryption_test_case_192_5),
12891                 TEST_CASE_ST(ut_setup, ut_teardown,
12892                         test_AES_GCM_auth_encryption_test_case_192_6),
12893                 TEST_CASE_ST(ut_setup, ut_teardown,
12894                         test_AES_GCM_auth_encryption_test_case_192_7),
12895
12896                 /** AES GCM Authenticated Decryption 192 bits key */
12897                 TEST_CASE_ST(ut_setup, ut_teardown,
12898                         test_AES_GCM_auth_decryption_test_case_192_1),
12899                 TEST_CASE_ST(ut_setup, ut_teardown,
12900                         test_AES_GCM_auth_decryption_test_case_192_2),
12901                 TEST_CASE_ST(ut_setup, ut_teardown,
12902                         test_AES_GCM_auth_decryption_test_case_192_3),
12903                 TEST_CASE_ST(ut_setup, ut_teardown,
12904                         test_AES_GCM_auth_decryption_test_case_192_4),
12905                 TEST_CASE_ST(ut_setup, ut_teardown,
12906                         test_AES_GCM_auth_decryption_test_case_192_5),
12907                 TEST_CASE_ST(ut_setup, ut_teardown,
12908                         test_AES_GCM_auth_decryption_test_case_192_6),
12909                 TEST_CASE_ST(ut_setup, ut_teardown,
12910                         test_AES_GCM_auth_decryption_test_case_192_7),
12911
12912                 /** AES GCM Authenticated Encryption 256 bits key */
12913                 TEST_CASE_ST(ut_setup, ut_teardown,
12914                         test_AES_GCM_auth_encryption_test_case_256_1),
12915                 TEST_CASE_ST(ut_setup, ut_teardown,
12916                         test_AES_GCM_auth_encryption_test_case_256_2),
12917                 TEST_CASE_ST(ut_setup, ut_teardown,
12918                         test_AES_GCM_auth_encryption_test_case_256_3),
12919                 TEST_CASE_ST(ut_setup, ut_teardown,
12920                         test_AES_GCM_auth_encryption_test_case_256_4),
12921                 TEST_CASE_ST(ut_setup, ut_teardown,
12922                         test_AES_GCM_auth_encryption_test_case_256_5),
12923                 TEST_CASE_ST(ut_setup, ut_teardown,
12924                         test_AES_GCM_auth_encryption_test_case_256_6),
12925                 TEST_CASE_ST(ut_setup, ut_teardown,
12926                         test_AES_GCM_auth_encryption_test_case_256_7),
12927
12928                 /** AES GCM Authenticated Decryption 256 bits key */
12929                 TEST_CASE_ST(ut_setup, ut_teardown,
12930                         test_AES_GCM_auth_decryption_test_case_256_1),
12931                 TEST_CASE_ST(ut_setup, ut_teardown,
12932                         test_AES_GCM_auth_decryption_test_case_256_2),
12933                 TEST_CASE_ST(ut_setup, ut_teardown,
12934                         test_AES_GCM_auth_decryption_test_case_256_3),
12935                 TEST_CASE_ST(ut_setup, ut_teardown,
12936                         test_AES_GCM_auth_decryption_test_case_256_4),
12937                 TEST_CASE_ST(ut_setup, ut_teardown,
12938                         test_AES_GCM_auth_decryption_test_case_256_5),
12939                 TEST_CASE_ST(ut_setup, ut_teardown,
12940                         test_AES_GCM_auth_decryption_test_case_256_6),
12941                 TEST_CASE_ST(ut_setup, ut_teardown,
12942                         test_AES_GCM_auth_decryption_test_case_256_7),
12943
12944                 /** Out of place tests */
12945                 TEST_CASE_ST(ut_setup, ut_teardown,
12946                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12947                 TEST_CASE_ST(ut_setup, ut_teardown,
12948                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12949
12950                 /** SNOW 3G encrypt only (UEA2) */
12951                 TEST_CASE_ST(ut_setup, ut_teardown,
12952                         test_snow3g_encryption_test_case_1),
12953                 TEST_CASE_ST(ut_setup, ut_teardown,
12954                         test_snow3g_encryption_test_case_2),
12955                 TEST_CASE_ST(ut_setup, ut_teardown,
12956                         test_snow3g_encryption_test_case_3),
12957                 TEST_CASE_ST(ut_setup, ut_teardown,
12958                         test_snow3g_encryption_test_case_4),
12959                 TEST_CASE_ST(ut_setup, ut_teardown,
12960                         test_snow3g_encryption_test_case_5),
12961
12962                 TEST_CASE_ST(ut_setup, ut_teardown,
12963                         test_snow3g_encryption_test_case_1_oop),
12964                 TEST_CASE_ST(ut_setup, ut_teardown,
12965                                 test_snow3g_encryption_test_case_1_oop_sgl),
12966                 TEST_CASE_ST(ut_setup, ut_teardown,
12967                         test_snow3g_decryption_test_case_1_oop),
12968
12969                 /** SNOW 3G decrypt only (UEA2) */
12970                 TEST_CASE_ST(ut_setup, ut_teardown,
12971                         test_snow3g_decryption_test_case_1),
12972                 TEST_CASE_ST(ut_setup, ut_teardown,
12973                         test_snow3g_decryption_test_case_2),
12974                 TEST_CASE_ST(ut_setup, ut_teardown,
12975                         test_snow3g_decryption_test_case_3),
12976                 TEST_CASE_ST(ut_setup, ut_teardown,
12977                         test_snow3g_decryption_test_case_4),
12978                 TEST_CASE_ST(ut_setup, ut_teardown,
12979                         test_snow3g_decryption_test_case_5),
12980
12981                 TEST_CASE_ST(ut_setup, ut_teardown,
12982                         test_snow3g_hash_generate_test_case_1),
12983                 TEST_CASE_ST(ut_setup, ut_teardown,
12984                         test_snow3g_hash_generate_test_case_2),
12985                 TEST_CASE_ST(ut_setup, ut_teardown,
12986                         test_snow3g_hash_generate_test_case_3),
12987                 TEST_CASE_ST(ut_setup, ut_teardown,
12988                         test_snow3g_hash_verify_test_case_1),
12989                 TEST_CASE_ST(ut_setup, ut_teardown,
12990                         test_snow3g_hash_verify_test_case_2),
12991                 TEST_CASE_ST(ut_setup, ut_teardown,
12992                         test_snow3g_hash_verify_test_case_3),
12993
12994                 /** ZUC encrypt only (EEA3) */
12995                 TEST_CASE_ST(ut_setup, ut_teardown,
12996                         test_zuc_encryption_test_case_1),
12997                 TEST_CASE_ST(ut_setup, ut_teardown,
12998                         test_zuc_encryption_test_case_2),
12999                 TEST_CASE_ST(ut_setup, ut_teardown,
13000                         test_zuc_encryption_test_case_3),
13001                 TEST_CASE_ST(ut_setup, ut_teardown,
13002                         test_zuc_encryption_test_case_4),
13003                 TEST_CASE_ST(ut_setup, ut_teardown,
13004                         test_zuc_encryption_test_case_5),
13005
13006                 /** ZUC authenticate (EIA3) */
13007                 TEST_CASE_ST(ut_setup, ut_teardown,
13008                         test_zuc_hash_generate_test_case_6),
13009                 TEST_CASE_ST(ut_setup, ut_teardown,
13010                         test_zuc_hash_generate_test_case_7),
13011                 TEST_CASE_ST(ut_setup, ut_teardown,
13012                         test_zuc_hash_generate_test_case_8),
13013
13014                 /** Negative tests */
13015                 TEST_CASE_ST(ut_setup, ut_teardown,
13016                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
13017                 TEST_CASE_ST(ut_setup, ut_teardown,
13018                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13019                 TEST_CASE_ST(ut_setup, ut_teardown,
13020                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13021                 TEST_CASE_ST(ut_setup, ut_teardown,
13022                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13023                 TEST_CASE_ST(ut_setup, ut_teardown,
13024                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
13025                 TEST_CASE_ST(ut_setup, ut_teardown,
13026                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
13027                 TEST_CASE_ST(ut_setup, ut_teardown,
13028                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
13029                 TEST_CASE_ST(ut_setup, ut_teardown,
13030                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13031                 TEST_CASE_ST(ut_setup, ut_teardown,
13032                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13033                 TEST_CASE_ST(ut_setup, ut_teardown,
13034                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13035                 TEST_CASE_ST(ut_setup, ut_teardown,
13036                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
13037                 TEST_CASE_ST(ut_setup, ut_teardown,
13038                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
13039                 TEST_CASE_ST(ut_setup, ut_teardown,
13040                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13041                 TEST_CASE_ST(ut_setup, ut_teardown,
13042                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13043                 TEST_CASE_ST(ut_setup, ut_teardown,
13044                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13045                 TEST_CASE_ST(ut_setup, ut_teardown,
13046                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13047
13048                 /* ESN Testcase */
13049                 TEST_CASE_ST(ut_setup, ut_teardown,
13050                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13051                 TEST_CASE_ST(ut_setup, ut_teardown,
13052                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13053
13054                 TEST_CASES_END() /**< NULL terminate unit test array */
13055         }
13056 };
13057
13058 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
13059         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
13060         .setup = testsuite_setup,
13061         .teardown = testsuite_teardown,
13062         .unit_test_cases = {
13063                 TEST_CASE_ST(ut_setup, ut_teardown,
13064                         test_device_configure_invalid_dev_id),
13065                 TEST_CASE_ST(ut_setup, ut_teardown,
13066                         test_multi_session),
13067                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13068                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13069                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13070                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13071                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13072
13073 #ifdef RTE_LIBRTE_SECURITY
13074                 TEST_CASE_ST(ut_setup, ut_teardown,
13075                         test_PDCP_PROTO_cplane_encap_all),
13076
13077                 TEST_CASE_ST(ut_setup, ut_teardown,
13078                         test_PDCP_PROTO_cplane_decap_all),
13079
13080                 TEST_CASE_ST(ut_setup, ut_teardown,
13081                         test_PDCP_PROTO_uplane_encap_all),
13082
13083                 TEST_CASE_ST(ut_setup, ut_teardown,
13084                         test_PDCP_PROTO_uplane_decap_all),
13085
13086                 TEST_CASE_ST(ut_setup, ut_teardown,
13087                         test_PDCP_PROTO_SGL_in_place_32B),
13088                 TEST_CASE_ST(ut_setup, ut_teardown,
13089                         test_PDCP_PROTO_SGL_oop_32B_128B),
13090                 TEST_CASE_ST(ut_setup, ut_teardown,
13091                         test_PDCP_PROTO_SGL_oop_32B_40B),
13092                 TEST_CASE_ST(ut_setup, ut_teardown,
13093                         test_PDCP_PROTO_SGL_oop_128B_32B),
13094 #endif
13095                 /** AES GCM Authenticated Encryption */
13096                 TEST_CASE_ST(ut_setup, ut_teardown,
13097                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13098                 TEST_CASE_ST(ut_setup, ut_teardown,
13099                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13100                 TEST_CASE_ST(ut_setup, ut_teardown,
13101                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13102                 TEST_CASE_ST(ut_setup, ut_teardown,
13103                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13104                 TEST_CASE_ST(ut_setup, ut_teardown,
13105                         test_AES_GCM_authenticated_encryption_test_case_1),
13106                 TEST_CASE_ST(ut_setup, ut_teardown,
13107                         test_AES_GCM_authenticated_encryption_test_case_2),
13108                 TEST_CASE_ST(ut_setup, ut_teardown,
13109                         test_AES_GCM_authenticated_encryption_test_case_3),
13110                 TEST_CASE_ST(ut_setup, ut_teardown,
13111                         test_AES_GCM_authenticated_encryption_test_case_4),
13112                 TEST_CASE_ST(ut_setup, ut_teardown,
13113                         test_AES_GCM_authenticated_encryption_test_case_5),
13114                 TEST_CASE_ST(ut_setup, ut_teardown,
13115                         test_AES_GCM_authenticated_encryption_test_case_6),
13116                 TEST_CASE_ST(ut_setup, ut_teardown,
13117                         test_AES_GCM_authenticated_encryption_test_case_7),
13118                 TEST_CASE_ST(ut_setup, ut_teardown,
13119                         test_AES_GCM_authenticated_encryption_test_case_8),
13120
13121                 /** AES GCM Authenticated Decryption */
13122                 TEST_CASE_ST(ut_setup, ut_teardown,
13123                         test_AES_GCM_authenticated_decryption_test_case_1),
13124                 TEST_CASE_ST(ut_setup, ut_teardown,
13125                         test_AES_GCM_authenticated_decryption_test_case_2),
13126                 TEST_CASE_ST(ut_setup, ut_teardown,
13127                         test_AES_GCM_authenticated_decryption_test_case_3),
13128                 TEST_CASE_ST(ut_setup, ut_teardown,
13129                         test_AES_GCM_authenticated_decryption_test_case_4),
13130                 TEST_CASE_ST(ut_setup, ut_teardown,
13131                         test_AES_GCM_authenticated_decryption_test_case_5),
13132                 TEST_CASE_ST(ut_setup, ut_teardown,
13133                         test_AES_GCM_authenticated_decryption_test_case_6),
13134                 TEST_CASE_ST(ut_setup, ut_teardown,
13135                         test_AES_GCM_authenticated_decryption_test_case_7),
13136                 TEST_CASE_ST(ut_setup, ut_teardown,
13137                         test_AES_GCM_authenticated_decryption_test_case_8),
13138
13139                 /** AES GCM Authenticated Encryption 192 bits key */
13140                 TEST_CASE_ST(ut_setup, ut_teardown,
13141                         test_AES_GCM_auth_encryption_test_case_192_1),
13142                 TEST_CASE_ST(ut_setup, ut_teardown,
13143                         test_AES_GCM_auth_encryption_test_case_192_2),
13144                 TEST_CASE_ST(ut_setup, ut_teardown,
13145                         test_AES_GCM_auth_encryption_test_case_192_3),
13146                 TEST_CASE_ST(ut_setup, ut_teardown,
13147                         test_AES_GCM_auth_encryption_test_case_192_4),
13148                 TEST_CASE_ST(ut_setup, ut_teardown,
13149                         test_AES_GCM_auth_encryption_test_case_192_5),
13150                 TEST_CASE_ST(ut_setup, ut_teardown,
13151                         test_AES_GCM_auth_encryption_test_case_192_6),
13152                 TEST_CASE_ST(ut_setup, ut_teardown,
13153                         test_AES_GCM_auth_encryption_test_case_192_7),
13154
13155                 /** AES GCM Authenticated Decryption 192 bits key */
13156                 TEST_CASE_ST(ut_setup, ut_teardown,
13157                         test_AES_GCM_auth_decryption_test_case_192_1),
13158                 TEST_CASE_ST(ut_setup, ut_teardown,
13159                         test_AES_GCM_auth_decryption_test_case_192_2),
13160                 TEST_CASE_ST(ut_setup, ut_teardown,
13161                         test_AES_GCM_auth_decryption_test_case_192_3),
13162                 TEST_CASE_ST(ut_setup, ut_teardown,
13163                         test_AES_GCM_auth_decryption_test_case_192_4),
13164                 TEST_CASE_ST(ut_setup, ut_teardown,
13165                         test_AES_GCM_auth_decryption_test_case_192_5),
13166                 TEST_CASE_ST(ut_setup, ut_teardown,
13167                         test_AES_GCM_auth_decryption_test_case_192_6),
13168                 TEST_CASE_ST(ut_setup, ut_teardown,
13169                         test_AES_GCM_auth_decryption_test_case_192_7),
13170
13171                 /** AES GCM Authenticated Encryption 256 bits key */
13172                 TEST_CASE_ST(ut_setup, ut_teardown,
13173                         test_AES_GCM_auth_encryption_test_case_256_1),
13174                 TEST_CASE_ST(ut_setup, ut_teardown,
13175                         test_AES_GCM_auth_encryption_test_case_256_2),
13176                 TEST_CASE_ST(ut_setup, ut_teardown,
13177                         test_AES_GCM_auth_encryption_test_case_256_3),
13178                 TEST_CASE_ST(ut_setup, ut_teardown,
13179                         test_AES_GCM_auth_encryption_test_case_256_4),
13180                 TEST_CASE_ST(ut_setup, ut_teardown,
13181                         test_AES_GCM_auth_encryption_test_case_256_5),
13182                 TEST_CASE_ST(ut_setup, ut_teardown,
13183                         test_AES_GCM_auth_encryption_test_case_256_6),
13184                 TEST_CASE_ST(ut_setup, ut_teardown,
13185                         test_AES_GCM_auth_encryption_test_case_256_7),
13186
13187                 /** AES GCM Authenticated Decryption 256 bits key */
13188                 TEST_CASE_ST(ut_setup, ut_teardown,
13189                         test_AES_GCM_auth_decryption_test_case_256_1),
13190                 TEST_CASE_ST(ut_setup, ut_teardown,
13191                         test_AES_GCM_auth_decryption_test_case_256_2),
13192                 TEST_CASE_ST(ut_setup, ut_teardown,
13193                         test_AES_GCM_auth_decryption_test_case_256_3),
13194                 TEST_CASE_ST(ut_setup, ut_teardown,
13195                         test_AES_GCM_auth_decryption_test_case_256_4),
13196                 TEST_CASE_ST(ut_setup, ut_teardown,
13197                         test_AES_GCM_auth_decryption_test_case_256_5),
13198                 TEST_CASE_ST(ut_setup, ut_teardown,
13199                         test_AES_GCM_auth_decryption_test_case_256_6),
13200                 TEST_CASE_ST(ut_setup, ut_teardown,
13201                         test_AES_GCM_auth_decryption_test_case_256_7),
13202
13203                 /** Out of place tests */
13204                 TEST_CASE_ST(ut_setup, ut_teardown,
13205                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13206                 TEST_CASE_ST(ut_setup, ut_teardown,
13207                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13208
13209                 /** SNOW 3G encrypt only (UEA2) */
13210                 TEST_CASE_ST(ut_setup, ut_teardown,
13211                         test_snow3g_encryption_test_case_1),
13212                 TEST_CASE_ST(ut_setup, ut_teardown,
13213                         test_snow3g_encryption_test_case_2),
13214                 TEST_CASE_ST(ut_setup, ut_teardown,
13215                         test_snow3g_encryption_test_case_3),
13216                 TEST_CASE_ST(ut_setup, ut_teardown,
13217                         test_snow3g_encryption_test_case_4),
13218                 TEST_CASE_ST(ut_setup, ut_teardown,
13219                         test_snow3g_encryption_test_case_5),
13220
13221                 TEST_CASE_ST(ut_setup, ut_teardown,
13222                         test_snow3g_encryption_test_case_1_oop),
13223                 TEST_CASE_ST(ut_setup, ut_teardown,
13224                                 test_snow3g_encryption_test_case_1_oop_sgl),
13225                 TEST_CASE_ST(ut_setup, ut_teardown,
13226                         test_snow3g_decryption_test_case_1_oop),
13227
13228                 /** SNOW 3G decrypt only (UEA2) */
13229                 TEST_CASE_ST(ut_setup, ut_teardown,
13230                         test_snow3g_decryption_test_case_1),
13231                 TEST_CASE_ST(ut_setup, ut_teardown,
13232                         test_snow3g_decryption_test_case_2),
13233                 TEST_CASE_ST(ut_setup, ut_teardown,
13234                         test_snow3g_decryption_test_case_3),
13235                 TEST_CASE_ST(ut_setup, ut_teardown,
13236                         test_snow3g_decryption_test_case_4),
13237                 TEST_CASE_ST(ut_setup, ut_teardown,
13238                         test_snow3g_decryption_test_case_5),
13239
13240                 TEST_CASE_ST(ut_setup, ut_teardown,
13241                         test_snow3g_hash_generate_test_case_1),
13242                 TEST_CASE_ST(ut_setup, ut_teardown,
13243                         test_snow3g_hash_generate_test_case_2),
13244                 TEST_CASE_ST(ut_setup, ut_teardown,
13245                         test_snow3g_hash_generate_test_case_3),
13246                 TEST_CASE_ST(ut_setup, ut_teardown,
13247                         test_snow3g_hash_verify_test_case_1),
13248                 TEST_CASE_ST(ut_setup, ut_teardown,
13249                         test_snow3g_hash_verify_test_case_2),
13250                 TEST_CASE_ST(ut_setup, ut_teardown,
13251                         test_snow3g_hash_verify_test_case_3),
13252
13253                 /** ZUC encrypt only (EEA3) */
13254                 TEST_CASE_ST(ut_setup, ut_teardown,
13255                         test_zuc_encryption_test_case_1),
13256                 TEST_CASE_ST(ut_setup, ut_teardown,
13257                         test_zuc_encryption_test_case_2),
13258                 TEST_CASE_ST(ut_setup, ut_teardown,
13259                         test_zuc_encryption_test_case_3),
13260                 TEST_CASE_ST(ut_setup, ut_teardown,
13261                         test_zuc_encryption_test_case_4),
13262                 TEST_CASE_ST(ut_setup, ut_teardown,
13263                         test_zuc_encryption_test_case_5),
13264
13265                 /** ZUC authenticate (EIA3) */
13266                 TEST_CASE_ST(ut_setup, ut_teardown,
13267                         test_zuc_hash_generate_test_case_6),
13268                 TEST_CASE_ST(ut_setup, ut_teardown,
13269                         test_zuc_hash_generate_test_case_7),
13270                 TEST_CASE_ST(ut_setup, ut_teardown,
13271                         test_zuc_hash_generate_test_case_8),
13272
13273                 /** HMAC_MD5 Authentication */
13274                 TEST_CASE_ST(ut_setup, ut_teardown,
13275                         test_MD5_HMAC_generate_case_1),
13276                 TEST_CASE_ST(ut_setup, ut_teardown,
13277                         test_MD5_HMAC_verify_case_1),
13278                 TEST_CASE_ST(ut_setup, ut_teardown,
13279                         test_MD5_HMAC_generate_case_2),
13280                 TEST_CASE_ST(ut_setup, ut_teardown,
13281                         test_MD5_HMAC_verify_case_2),
13282
13283                 /** Negative tests */
13284                 TEST_CASE_ST(ut_setup, ut_teardown,
13285                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
13286                 TEST_CASE_ST(ut_setup, ut_teardown,
13287                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13288                 TEST_CASE_ST(ut_setup, ut_teardown,
13289                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13290                 TEST_CASE_ST(ut_setup, ut_teardown,
13291                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13292                 TEST_CASE_ST(ut_setup, ut_teardown,
13293                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
13294                 TEST_CASE_ST(ut_setup, ut_teardown,
13295                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
13296                 TEST_CASE_ST(ut_setup, ut_teardown,
13297                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
13298                 TEST_CASE_ST(ut_setup, ut_teardown,
13299                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13300                 TEST_CASE_ST(ut_setup, ut_teardown,
13301                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13302                 TEST_CASE_ST(ut_setup, ut_teardown,
13303                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13304                 TEST_CASE_ST(ut_setup, ut_teardown,
13305                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
13306                 TEST_CASE_ST(ut_setup, ut_teardown,
13307                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
13308                 TEST_CASE_ST(ut_setup, ut_teardown,
13309                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13310                 TEST_CASE_ST(ut_setup, ut_teardown,
13311                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13312                 TEST_CASE_ST(ut_setup, ut_teardown,
13313                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13314                 TEST_CASE_ST(ut_setup, ut_teardown,
13315                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13316
13317                 /* ESN Testcase */
13318                 TEST_CASE_ST(ut_setup, ut_teardown,
13319                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13320
13321                 TEST_CASE_ST(ut_setup, ut_teardown,
13322                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13323
13324                 TEST_CASES_END() /**< NULL terminate unit test array */
13325         }
13326 };
13327
13328 static struct unit_test_suite cryptodev_null_testsuite  = {
13329         .suite_name = "Crypto Device NULL Unit Test Suite",
13330         .setup = testsuite_setup,
13331         .teardown = testsuite_teardown,
13332         .unit_test_cases = {
13333                 TEST_CASE_ST(ut_setup, ut_teardown,
13334                         test_null_invalid_operation),
13335                 TEST_CASE_ST(ut_setup, ut_teardown,
13336                         test_null_burst_operation),
13337                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13338                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13339                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13340
13341                 TEST_CASES_END() /**< NULL terminate unit test array */
13342         }
13343 };
13344
13345 static struct unit_test_suite cryptodev_armv8_testsuite  = {
13346         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
13347         .setup = testsuite_setup,
13348         .teardown = testsuite_teardown,
13349         .unit_test_cases = {
13350                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13351
13352                 /** Negative tests */
13353                 TEST_CASE_ST(ut_setup, ut_teardown,
13354                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13355                 TEST_CASE_ST(ut_setup, ut_teardown,
13356                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13357
13358                 TEST_CASES_END() /**< NULL terminate unit test array */
13359         }
13360 };
13361
13362 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
13363         .suite_name = "Crypto Device Marvell Component Test Suite",
13364         .setup = testsuite_setup,
13365         .teardown = testsuite_teardown,
13366         .unit_test_cases = {
13367                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13368                 TEST_CASE_ST(ut_setup, ut_teardown,
13369                                 test_multi_session_random_usage),
13370                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13371                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13372                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13373                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13374                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13375
13376                 /** Negative tests */
13377                 TEST_CASE_ST(ut_setup, ut_teardown,
13378                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13379                 TEST_CASE_ST(ut_setup, ut_teardown,
13380                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13381                 TEST_CASE_ST(ut_setup, ut_teardown,
13382                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13383                 TEST_CASE_ST(ut_setup, ut_teardown,
13384                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13385
13386                 TEST_CASES_END() /**< NULL terminate unit test array */
13387         }
13388 };
13389
13390 static struct unit_test_suite cryptodev_ccp_testsuite  = {
13391         .suite_name = "Crypto Device CCP Unit Test Suite",
13392         .setup = testsuite_setup,
13393         .teardown = testsuite_teardown,
13394         .unit_test_cases = {
13395                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13396                 TEST_CASE_ST(ut_setup, ut_teardown,
13397                                 test_multi_session_random_usage),
13398                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13399                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13400                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13401                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13402                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13403
13404                 /** Negative tests */
13405                 TEST_CASE_ST(ut_setup, ut_teardown,
13406                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13407                 TEST_CASE_ST(ut_setup, ut_teardown,
13408                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13409                 TEST_CASE_ST(ut_setup, ut_teardown,
13410                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13411                 TEST_CASE_ST(ut_setup, ut_teardown,
13412                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13413
13414                 TEST_CASES_END() /**< NULL terminate unit test array */
13415         }
13416 };
13417
13418 static struct unit_test_suite cryptodev_octeontx_testsuite  = {
13419         .suite_name = "Crypto Device OCTEONTX Unit Test Suite",
13420         .setup = testsuite_setup,
13421         .teardown = testsuite_teardown,
13422         .unit_test_cases = {
13423                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13424                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13425                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13426                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13427                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13428
13429                 /** AES GCM Authenticated Encryption */
13430                 TEST_CASE_ST(ut_setup, ut_teardown,
13431                         test_AES_GCM_authenticated_encryption_test_case_1),
13432                 TEST_CASE_ST(ut_setup, ut_teardown,
13433                         test_AES_GCM_authenticated_encryption_test_case_2),
13434                 TEST_CASE_ST(ut_setup, ut_teardown,
13435                         test_AES_GCM_authenticated_encryption_test_case_3),
13436                 TEST_CASE_ST(ut_setup, ut_teardown,
13437                         test_AES_GCM_authenticated_encryption_test_case_4),
13438                 TEST_CASE_ST(ut_setup, ut_teardown,
13439                         test_AES_GCM_authenticated_encryption_test_case_5),
13440                 TEST_CASE_ST(ut_setup, ut_teardown,
13441                         test_AES_GCM_authenticated_encryption_test_case_6),
13442                 TEST_CASE_ST(ut_setup, ut_teardown,
13443                         test_AES_GCM_authenticated_encryption_test_case_7),
13444
13445                 /** AES GCM Authenticated Decryption */
13446                 TEST_CASE_ST(ut_setup, ut_teardown,
13447                         test_AES_GCM_authenticated_decryption_test_case_1),
13448                 TEST_CASE_ST(ut_setup, ut_teardown,
13449                         test_AES_GCM_authenticated_decryption_test_case_2),
13450                 TEST_CASE_ST(ut_setup, ut_teardown,
13451                         test_AES_GCM_authenticated_decryption_test_case_3),
13452                 TEST_CASE_ST(ut_setup, ut_teardown,
13453                         test_AES_GCM_authenticated_decryption_test_case_4),
13454                 TEST_CASE_ST(ut_setup, ut_teardown,
13455                         test_AES_GCM_authenticated_decryption_test_case_5),
13456                 TEST_CASE_ST(ut_setup, ut_teardown,
13457                         test_AES_GCM_authenticated_decryption_test_case_6),
13458                 TEST_CASE_ST(ut_setup, ut_teardown,
13459                         test_AES_GCM_authenticated_decryption_test_case_7),
13460                 /** AES GMAC Authentication */
13461                 TEST_CASE_ST(ut_setup, ut_teardown,
13462                         test_AES_GMAC_authentication_test_case_1),
13463                 TEST_CASE_ST(ut_setup, ut_teardown,
13464                         test_AES_GMAC_authentication_verify_test_case_1),
13465                 TEST_CASE_ST(ut_setup, ut_teardown,
13466                         test_AES_GMAC_authentication_test_case_2),
13467                 TEST_CASE_ST(ut_setup, ut_teardown,
13468                         test_AES_GMAC_authentication_verify_test_case_2),
13469                 TEST_CASE_ST(ut_setup, ut_teardown,
13470                         test_AES_GMAC_authentication_test_case_3),
13471                 TEST_CASE_ST(ut_setup, ut_teardown,
13472                         test_AES_GMAC_authentication_verify_test_case_3),
13473
13474                 /** SNOW 3G encrypt only (UEA2) */
13475                 TEST_CASE_ST(ut_setup, ut_teardown,
13476                         test_snow3g_encryption_test_case_1),
13477                 TEST_CASE_ST(ut_setup, ut_teardown,
13478                         test_snow3g_encryption_test_case_2),
13479                 TEST_CASE_ST(ut_setup, ut_teardown,
13480                         test_snow3g_encryption_test_case_3),
13481                 TEST_CASE_ST(ut_setup, ut_teardown,
13482                         test_snow3g_encryption_test_case_4),
13483                 TEST_CASE_ST(ut_setup, ut_teardown,
13484                         test_snow3g_encryption_test_case_5),
13485
13486                 TEST_CASE_ST(ut_setup, ut_teardown,
13487                         test_snow3g_encryption_test_case_1_oop),
13488                 TEST_CASE_ST(ut_setup, ut_teardown,
13489                         test_snow3g_decryption_test_case_1_oop),
13490                 TEST_CASE_ST(ut_setup, ut_teardown,
13491                         test_snow3g_encryption_test_case_1_oop_sgl),
13492
13493                 /** SNOW 3G decrypt only (UEA2) */
13494                 TEST_CASE_ST(ut_setup, ut_teardown,
13495                         test_snow3g_decryption_test_case_1),
13496                 TEST_CASE_ST(ut_setup, ut_teardown,
13497                         test_snow3g_decryption_test_case_2),
13498                 TEST_CASE_ST(ut_setup, ut_teardown,
13499                         test_snow3g_decryption_test_case_3),
13500                 TEST_CASE_ST(ut_setup, ut_teardown,
13501                         test_snow3g_decryption_test_case_4),
13502                 TEST_CASE_ST(ut_setup, ut_teardown,
13503                         test_snow3g_decryption_test_case_5),
13504
13505                 TEST_CASE_ST(ut_setup, ut_teardown,
13506                         test_snow3g_hash_generate_test_case_1),
13507                 TEST_CASE_ST(ut_setup, ut_teardown,
13508                         test_snow3g_hash_generate_test_case_2),
13509                 TEST_CASE_ST(ut_setup, ut_teardown,
13510                         test_snow3g_hash_generate_test_case_3),
13511                 TEST_CASE_ST(ut_setup, ut_teardown,
13512                         test_snow3g_hash_verify_test_case_1),
13513                 TEST_CASE_ST(ut_setup, ut_teardown,
13514                         test_snow3g_hash_verify_test_case_2),
13515                 TEST_CASE_ST(ut_setup, ut_teardown,
13516                         test_snow3g_hash_verify_test_case_3),
13517
13518                 /** ZUC encrypt only (EEA3) */
13519                 TEST_CASE_ST(ut_setup, ut_teardown,
13520                         test_zuc_encryption_test_case_1),
13521                 TEST_CASE_ST(ut_setup, ut_teardown,
13522                         test_zuc_encryption_test_case_2),
13523                 TEST_CASE_ST(ut_setup, ut_teardown,
13524                         test_zuc_encryption_test_case_3),
13525                 TEST_CASE_ST(ut_setup, ut_teardown,
13526                         test_zuc_encryption_test_case_4),
13527                 TEST_CASE_ST(ut_setup, ut_teardown,
13528                         test_zuc_encryption_test_case_5),
13529                 TEST_CASE_ST(ut_setup, ut_teardown,
13530                         test_zuc_hash_generate_test_case_1),
13531                 TEST_CASE_ST(ut_setup, ut_teardown,
13532                         test_zuc_hash_generate_test_case_2),
13533                 TEST_CASE_ST(ut_setup, ut_teardown,
13534                         test_zuc_hash_generate_test_case_3),
13535                 TEST_CASE_ST(ut_setup, ut_teardown,
13536                         test_zuc_hash_generate_test_case_4),
13537                 TEST_CASE_ST(ut_setup, ut_teardown,
13538                         test_zuc_hash_generate_test_case_5),
13539                 TEST_CASE_ST(ut_setup, ut_teardown,
13540                         test_zuc_encryption_test_case_6_sgl),
13541
13542                 /** KASUMI encrypt only (UEA1) */
13543                 TEST_CASE_ST(ut_setup, ut_teardown,
13544                         test_kasumi_encryption_test_case_1),
13545                 TEST_CASE_ST(ut_setup, ut_teardown,
13546                         test_kasumi_encryption_test_case_2),
13547                 TEST_CASE_ST(ut_setup, ut_teardown,
13548                         test_kasumi_encryption_test_case_3),
13549                 TEST_CASE_ST(ut_setup, ut_teardown,
13550                         test_kasumi_encryption_test_case_4),
13551                 TEST_CASE_ST(ut_setup, ut_teardown,
13552                         test_kasumi_encryption_test_case_5),
13553                 TEST_CASE_ST(ut_setup, ut_teardown,
13554                         test_kasumi_encryption_test_case_1_sgl),
13555                 TEST_CASE_ST(ut_setup, ut_teardown,
13556                         test_kasumi_encryption_test_case_1_oop_sgl),
13557                 /** KASUMI decrypt only (UEA1) */
13558                 TEST_CASE_ST(ut_setup, ut_teardown,
13559                         test_kasumi_decryption_test_case_1),
13560                 TEST_CASE_ST(ut_setup, ut_teardown,
13561                         test_kasumi_decryption_test_case_2),
13562                 TEST_CASE_ST(ut_setup, ut_teardown,
13563                         test_kasumi_decryption_test_case_3),
13564                 TEST_CASE_ST(ut_setup, ut_teardown,
13565                         test_kasumi_decryption_test_case_4),
13566                 TEST_CASE_ST(ut_setup, ut_teardown,
13567                         test_kasumi_decryption_test_case_5),
13568
13569                 TEST_CASE_ST(ut_setup, ut_teardown,
13570                         test_kasumi_encryption_test_case_1_oop),
13571                 TEST_CASE_ST(ut_setup, ut_teardown,
13572                         test_kasumi_decryption_test_case_1_oop),
13573
13574                 /** KASUMI hash only (UIA1) */
13575                 TEST_CASE_ST(ut_setup, ut_teardown,
13576                         test_kasumi_hash_generate_test_case_1),
13577                 TEST_CASE_ST(ut_setup, ut_teardown,
13578                         test_kasumi_hash_generate_test_case_2),
13579                 TEST_CASE_ST(ut_setup, ut_teardown,
13580                         test_kasumi_hash_generate_test_case_3),
13581                 TEST_CASE_ST(ut_setup, ut_teardown,
13582                         test_kasumi_hash_generate_test_case_4),
13583                 TEST_CASE_ST(ut_setup, ut_teardown,
13584                         test_kasumi_hash_generate_test_case_5),
13585                 TEST_CASE_ST(ut_setup, ut_teardown,
13586                         test_kasumi_hash_generate_test_case_6),
13587                 TEST_CASE_ST(ut_setup, ut_teardown,
13588                         test_kasumi_hash_verify_test_case_1),
13589                 TEST_CASE_ST(ut_setup, ut_teardown,
13590                         test_kasumi_hash_verify_test_case_2),
13591                 TEST_CASE_ST(ut_setup, ut_teardown,
13592                         test_kasumi_hash_verify_test_case_3),
13593                 TEST_CASE_ST(ut_setup, ut_teardown,
13594                         test_kasumi_hash_verify_test_case_4),
13595                 TEST_CASE_ST(ut_setup, ut_teardown,
13596                         test_kasumi_hash_verify_test_case_5),
13597
13598                 /** NULL tests */
13599                 TEST_CASE_ST(ut_setup, ut_teardown,
13600                         test_null_cipher_only_operation),
13601                 TEST_CASE_ST(ut_setup, ut_teardown,
13602                         test_null_auth_only_operation),
13603                 TEST_CASE_ST(ut_setup, ut_teardown,
13604                         test_null_cipher_auth_operation),
13605                 TEST_CASE_ST(ut_setup, ut_teardown,
13606                         test_null_auth_cipher_operation),
13607
13608                 /** Negative tests */
13609                 TEST_CASE_ST(ut_setup, ut_teardown,
13610                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13611                 TEST_CASE_ST(ut_setup, ut_teardown,
13612                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13613                 TEST_CASE_ST(ut_setup, ut_teardown,
13614                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13615                 TEST_CASE_ST(ut_setup, ut_teardown,
13616                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13617                 TEST_CASE_ST(ut_setup, ut_teardown,
13618                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13619                 TEST_CASE_ST(ut_setup, ut_teardown,
13620                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13621                 TEST_CASES_END() /**< NULL terminate unit test array */
13622         }
13623 };
13624
13625 static struct unit_test_suite cryptodev_nitrox_testsuite  = {
13626         .suite_name = "Crypto NITROX Unit Test Suite",
13627         .setup = testsuite_setup,
13628         .teardown = testsuite_teardown,
13629         .unit_test_cases = {
13630                 TEST_CASE_ST(ut_setup, ut_teardown,
13631                              test_device_configure_invalid_dev_id),
13632                 TEST_CASE_ST(ut_setup, ut_teardown,
13633                                 test_device_configure_invalid_queue_pair_ids),
13634                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13635
13636                 TEST_CASES_END() /**< NULL terminate unit test array */
13637         }
13638 };
13639
13640 static struct unit_test_suite cryptodev_octeontx2_testsuite  = {
13641         .suite_name = "Crypto Device OCTEON TX2 Unit Test Suite",
13642         .setup = testsuite_setup,
13643         .teardown = testsuite_teardown,
13644         .unit_test_cases = {
13645                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13646                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13647                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13648                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13649                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13650
13651                 /** AES GCM Authenticated Encryption */
13652                 TEST_CASE_ST(ut_setup, ut_teardown,
13653                         test_AES_GCM_authenticated_encryption_test_case_1),
13654                 TEST_CASE_ST(ut_setup, ut_teardown,
13655                         test_AES_GCM_authenticated_encryption_test_case_2),
13656                 TEST_CASE_ST(ut_setup, ut_teardown,
13657                         test_AES_GCM_authenticated_encryption_test_case_3),
13658                 TEST_CASE_ST(ut_setup, ut_teardown,
13659                         test_AES_GCM_authenticated_encryption_test_case_4),
13660                 TEST_CASE_ST(ut_setup, ut_teardown,
13661                         test_AES_GCM_authenticated_encryption_test_case_5),
13662                 TEST_CASE_ST(ut_setup, ut_teardown,
13663                         test_AES_GCM_authenticated_encryption_test_case_6),
13664                 TEST_CASE_ST(ut_setup, ut_teardown,
13665                         test_AES_GCM_authenticated_encryption_test_case_7),
13666
13667                 /** AES GCM Authenticated Decryption */
13668                 TEST_CASE_ST(ut_setup, ut_teardown,
13669                         test_AES_GCM_authenticated_decryption_test_case_1),
13670                 TEST_CASE_ST(ut_setup, ut_teardown,
13671                         test_AES_GCM_authenticated_decryption_test_case_2),
13672                 TEST_CASE_ST(ut_setup, ut_teardown,
13673                         test_AES_GCM_authenticated_decryption_test_case_3),
13674                 TEST_CASE_ST(ut_setup, ut_teardown,
13675                         test_AES_GCM_authenticated_decryption_test_case_4),
13676                 TEST_CASE_ST(ut_setup, ut_teardown,
13677                         test_AES_GCM_authenticated_decryption_test_case_5),
13678                 TEST_CASE_ST(ut_setup, ut_teardown,
13679                         test_AES_GCM_authenticated_decryption_test_case_6),
13680                 TEST_CASE_ST(ut_setup, ut_teardown,
13681                         test_AES_GCM_authenticated_decryption_test_case_7),
13682                 /** AES GMAC Authentication */
13683                 TEST_CASE_ST(ut_setup, ut_teardown,
13684                         test_AES_GMAC_authentication_test_case_1),
13685                 TEST_CASE_ST(ut_setup, ut_teardown,
13686                         test_AES_GMAC_authentication_verify_test_case_1),
13687                 TEST_CASE_ST(ut_setup, ut_teardown,
13688                         test_AES_GMAC_authentication_test_case_2),
13689                 TEST_CASE_ST(ut_setup, ut_teardown,
13690                         test_AES_GMAC_authentication_verify_test_case_2),
13691                 TEST_CASE_ST(ut_setup, ut_teardown,
13692                         test_AES_GMAC_authentication_test_case_3),
13693                 TEST_CASE_ST(ut_setup, ut_teardown,
13694                         test_AES_GMAC_authentication_verify_test_case_3),
13695
13696                 /** SNOW 3G encrypt only (UEA2) */
13697                 TEST_CASE_ST(ut_setup, ut_teardown,
13698                         test_snow3g_encryption_test_case_1),
13699                 TEST_CASE_ST(ut_setup, ut_teardown,
13700                         test_snow3g_encryption_test_case_2),
13701                 TEST_CASE_ST(ut_setup, ut_teardown,
13702                         test_snow3g_encryption_test_case_3),
13703                 TEST_CASE_ST(ut_setup, ut_teardown,
13704                         test_snow3g_encryption_test_case_4),
13705                 TEST_CASE_ST(ut_setup, ut_teardown,
13706                         test_snow3g_encryption_test_case_5),
13707
13708                 TEST_CASE_ST(ut_setup, ut_teardown,
13709                         test_snow3g_encryption_test_case_1_oop),
13710                 TEST_CASE_ST(ut_setup, ut_teardown,
13711                         test_snow3g_decryption_test_case_1_oop),
13712                 TEST_CASE_ST(ut_setup, ut_teardown,
13713                         test_snow3g_encryption_test_case_1_oop_sgl),
13714
13715                 /** SNOW 3G decrypt only (UEA2) */
13716                 TEST_CASE_ST(ut_setup, ut_teardown,
13717                         test_snow3g_decryption_test_case_1),
13718                 TEST_CASE_ST(ut_setup, ut_teardown,
13719                         test_snow3g_decryption_test_case_2),
13720                 TEST_CASE_ST(ut_setup, ut_teardown,
13721                         test_snow3g_decryption_test_case_3),
13722                 TEST_CASE_ST(ut_setup, ut_teardown,
13723                         test_snow3g_decryption_test_case_4),
13724                 TEST_CASE_ST(ut_setup, ut_teardown,
13725                         test_snow3g_decryption_test_case_5),
13726
13727                 TEST_CASE_ST(ut_setup, ut_teardown,
13728                         test_snow3g_hash_generate_test_case_1),
13729                 TEST_CASE_ST(ut_setup, ut_teardown,
13730                         test_snow3g_hash_generate_test_case_2),
13731                 TEST_CASE_ST(ut_setup, ut_teardown,
13732                         test_snow3g_hash_generate_test_case_3),
13733                 TEST_CASE_ST(ut_setup, ut_teardown,
13734                         test_snow3g_hash_verify_test_case_1),
13735                 TEST_CASE_ST(ut_setup, ut_teardown,
13736                         test_snow3g_hash_verify_test_case_2),
13737                 TEST_CASE_ST(ut_setup, ut_teardown,
13738                         test_snow3g_hash_verify_test_case_3),
13739
13740                 /** ZUC encrypt only (EEA3) */
13741                 TEST_CASE_ST(ut_setup, ut_teardown,
13742                         test_zuc_encryption_test_case_1),
13743                 TEST_CASE_ST(ut_setup, ut_teardown,
13744                         test_zuc_encryption_test_case_2),
13745                 TEST_CASE_ST(ut_setup, ut_teardown,
13746                         test_zuc_encryption_test_case_3),
13747                 TEST_CASE_ST(ut_setup, ut_teardown,
13748                         test_zuc_encryption_test_case_4),
13749                 TEST_CASE_ST(ut_setup, ut_teardown,
13750                         test_zuc_encryption_test_case_5),
13751                 TEST_CASE_ST(ut_setup, ut_teardown,
13752                         test_zuc_hash_generate_test_case_1),
13753                 TEST_CASE_ST(ut_setup, ut_teardown,
13754                         test_zuc_hash_generate_test_case_2),
13755                 TEST_CASE_ST(ut_setup, ut_teardown,
13756                         test_zuc_hash_generate_test_case_3),
13757                 TEST_CASE_ST(ut_setup, ut_teardown,
13758                         test_zuc_hash_generate_test_case_4),
13759                 TEST_CASE_ST(ut_setup, ut_teardown,
13760                         test_zuc_hash_generate_test_case_5),
13761                 TEST_CASE_ST(ut_setup, ut_teardown,
13762                         test_zuc_encryption_test_case_6_sgl),
13763
13764                 /** KASUMI encrypt only (UEA1) */
13765                 TEST_CASE_ST(ut_setup, ut_teardown,
13766                         test_kasumi_encryption_test_case_1),
13767                 TEST_CASE_ST(ut_setup, ut_teardown,
13768                         test_kasumi_encryption_test_case_2),
13769                 TEST_CASE_ST(ut_setup, ut_teardown,
13770                         test_kasumi_encryption_test_case_3),
13771                 TEST_CASE_ST(ut_setup, ut_teardown,
13772                         test_kasumi_encryption_test_case_4),
13773                 TEST_CASE_ST(ut_setup, ut_teardown,
13774                         test_kasumi_encryption_test_case_5),
13775                 TEST_CASE_ST(ut_setup, ut_teardown,
13776                         test_kasumi_encryption_test_case_1_sgl),
13777                 TEST_CASE_ST(ut_setup, ut_teardown,
13778                         test_kasumi_encryption_test_case_1_oop_sgl),
13779                 /** KASUMI decrypt only (UEA1) */
13780                 TEST_CASE_ST(ut_setup, ut_teardown,
13781                         test_kasumi_decryption_test_case_1),
13782                 TEST_CASE_ST(ut_setup, ut_teardown,
13783                         test_kasumi_decryption_test_case_2),
13784                 TEST_CASE_ST(ut_setup, ut_teardown,
13785                         test_kasumi_decryption_test_case_3),
13786                 TEST_CASE_ST(ut_setup, ut_teardown,
13787                         test_kasumi_decryption_test_case_4),
13788                 TEST_CASE_ST(ut_setup, ut_teardown,
13789                         test_kasumi_decryption_test_case_5),
13790
13791                 TEST_CASE_ST(ut_setup, ut_teardown,
13792                         test_kasumi_encryption_test_case_1_oop),
13793                 TEST_CASE_ST(ut_setup, ut_teardown,
13794                         test_kasumi_decryption_test_case_1_oop),
13795
13796                 /** KASUMI hash only (UIA1) */
13797                 TEST_CASE_ST(ut_setup, ut_teardown,
13798                         test_kasumi_hash_generate_test_case_1),
13799                 TEST_CASE_ST(ut_setup, ut_teardown,
13800                         test_kasumi_hash_generate_test_case_2),
13801                 TEST_CASE_ST(ut_setup, ut_teardown,
13802                         test_kasumi_hash_generate_test_case_3),
13803                 TEST_CASE_ST(ut_setup, ut_teardown,
13804                         test_kasumi_hash_generate_test_case_4),
13805                 TEST_CASE_ST(ut_setup, ut_teardown,
13806                         test_kasumi_hash_generate_test_case_5),
13807                 TEST_CASE_ST(ut_setup, ut_teardown,
13808                         test_kasumi_hash_generate_test_case_6),
13809                 TEST_CASE_ST(ut_setup, ut_teardown,
13810                         test_kasumi_hash_verify_test_case_1),
13811                 TEST_CASE_ST(ut_setup, ut_teardown,
13812                         test_kasumi_hash_verify_test_case_2),
13813                 TEST_CASE_ST(ut_setup, ut_teardown,
13814                         test_kasumi_hash_verify_test_case_3),
13815                 TEST_CASE_ST(ut_setup, ut_teardown,
13816                         test_kasumi_hash_verify_test_case_4),
13817                 TEST_CASE_ST(ut_setup, ut_teardown,
13818                         test_kasumi_hash_verify_test_case_5),
13819
13820                 /** NULL tests */
13821                 TEST_CASE_ST(ut_setup, ut_teardown,
13822                         test_null_cipher_only_operation),
13823                 TEST_CASE_ST(ut_setup, ut_teardown,
13824                         test_null_auth_only_operation),
13825                 TEST_CASE_ST(ut_setup, ut_teardown,
13826                         test_null_cipher_auth_operation),
13827                 TEST_CASE_ST(ut_setup, ut_teardown,
13828                         test_null_auth_cipher_operation),
13829
13830                 /** Negative tests */
13831                 TEST_CASE_ST(ut_setup, ut_teardown,
13832                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13833                 TEST_CASE_ST(ut_setup, ut_teardown,
13834                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13835                 TEST_CASE_ST(ut_setup, ut_teardown,
13836                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13837                 TEST_CASE_ST(ut_setup, ut_teardown,
13838                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13839                 TEST_CASE_ST(ut_setup, ut_teardown,
13840                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13841                 TEST_CASE_ST(ut_setup, ut_teardown,
13842                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13843                 TEST_CASES_END() /**< NULL terminate unit test array */
13844         }
13845 };
13846
13847 static int
13848 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13849 {
13850         gbl_driver_id = rte_cryptodev_driver_id_get(
13851                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13852
13853         if (gbl_driver_id == -1) {
13854                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
13855                 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
13856                 "are enabled in config file to run this testsuite.\n");
13857                 return TEST_SKIPPED;
13858         }
13859
13860         return unit_test_suite_runner(&cryptodev_qat_testsuite);
13861 }
13862
13863 static int
13864 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13865 {
13866         gbl_driver_id = rte_cryptodev_driver_id_get(
13867                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13868
13869         if (gbl_driver_id == -1) {
13870                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
13871                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
13872                                 "in config file to run this testsuite.\n");
13873                 return TEST_FAILED;
13874         }
13875
13876         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13877 }
13878
13879 static int
13880 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13881 {
13882         gbl_driver_id = rte_cryptodev_driver_id_get(
13883                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13884
13885         if (gbl_driver_id == -1) {
13886                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
13887                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
13888                                 "in config file to run this testsuite.\n");
13889                 return TEST_SKIPPED;
13890         }
13891
13892         return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
13893 }
13894
13895 static int
13896 test_cryptodev_openssl(void)
13897 {
13898         gbl_driver_id = rte_cryptodev_driver_id_get(
13899                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13900
13901         if (gbl_driver_id == -1) {
13902                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
13903                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
13904                                 "in config file to run this testsuite.\n");
13905                 return TEST_SKIPPED;
13906         }
13907
13908         return unit_test_suite_runner(&cryptodev_openssl_testsuite);
13909 }
13910
13911 static int
13912 test_cryptodev_aesni_gcm(void)
13913 {
13914         gbl_driver_id = rte_cryptodev_driver_id_get(
13915                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13916
13917         if (gbl_driver_id == -1) {
13918                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
13919                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
13920                                 "in config file to run this testsuite.\n");
13921                 return TEST_SKIPPED;
13922         }
13923
13924         return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
13925 }
13926
13927 static int
13928 test_cryptodev_null(void)
13929 {
13930         gbl_driver_id = rte_cryptodev_driver_id_get(
13931                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13932
13933         if (gbl_driver_id == -1) {
13934                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
13935                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
13936                                 "in config file to run this testsuite.\n");
13937                 return TEST_SKIPPED;
13938         }
13939
13940         return unit_test_suite_runner(&cryptodev_null_testsuite);
13941 }
13942
13943 static int
13944 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13945 {
13946         gbl_driver_id = rte_cryptodev_driver_id_get(
13947                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13948
13949         if (gbl_driver_id == -1) {
13950                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
13951                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
13952                                 "in config file to run this testsuite.\n");
13953                 return TEST_SKIPPED;
13954         }
13955
13956         return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
13957 }
13958
13959 static int
13960 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13961 {
13962         gbl_driver_id = rte_cryptodev_driver_id_get(
13963                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13964
13965         if (gbl_driver_id == -1) {
13966                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13967                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
13968                                 "in config file to run this testsuite.\n");
13969                 return TEST_SKIPPED;
13970         }
13971
13972         return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
13973 }
13974
13975 static int
13976 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13977 {
13978         gbl_driver_id = rte_cryptodev_driver_id_get(
13979                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13980
13981         if (gbl_driver_id == -1) {
13982                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13983                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
13984                                 "in config file to run this testsuite.\n");
13985                 return TEST_SKIPPED;
13986         }
13987
13988         return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
13989 }
13990
13991 static int
13992 test_cryptodev_armv8(void)
13993 {
13994         gbl_driver_id = rte_cryptodev_driver_id_get(
13995                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13996
13997         if (gbl_driver_id == -1) {
13998                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
13999                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
14000                                 "in config file to run this testsuite.\n");
14001                 return TEST_SKIPPED;
14002         }
14003
14004         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
14005 }
14006
14007 static int
14008 test_cryptodev_mrvl(void)
14009 {
14010         gbl_driver_id = rte_cryptodev_driver_id_get(
14011                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14012
14013         if (gbl_driver_id == -1) {
14014                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if "
14015                                 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled "
14016                                 "in config file to run this testsuite.\n");
14017                 return TEST_SKIPPED;
14018         }
14019
14020         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
14021 }
14022
14023 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
14024
14025 static int
14026 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
14027 {
14028         gbl_driver_id = rte_cryptodev_driver_id_get(
14029                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14030
14031         if (gbl_driver_id == -1) {
14032                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
14033                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
14034                                 "in config file to run this testsuite.\n");
14035                 return TEST_SKIPPED;
14036         }
14037
14038         if (rte_cryptodev_driver_id_get(
14039                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14040                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
14041                         " enabled in config file to run this testsuite.\n");
14042                 return TEST_SKIPPED;
14043 }
14044         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
14045 }
14046
14047 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14048
14049 #endif
14050
14051 static int
14052 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14053 {
14054         gbl_driver_id = rte_cryptodev_driver_id_get(
14055                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14056
14057         if (gbl_driver_id == -1) {
14058                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
14059                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
14060                                 "in config file to run this testsuite.\n");
14061                 return TEST_SKIPPED;
14062         }
14063
14064         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
14065 }
14066
14067 static int
14068 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14069 {
14070         gbl_driver_id = rte_cryptodev_driver_id_get(
14071                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14072
14073         if (gbl_driver_id == -1) {
14074                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
14075                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
14076                                 "in config file to run this testsuite.\n");
14077                 return TEST_SKIPPED;
14078         }
14079
14080         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
14081 }
14082
14083 static int
14084 test_cryptodev_ccp(void)
14085 {
14086         gbl_driver_id = rte_cryptodev_driver_id_get(
14087                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14088
14089         if (gbl_driver_id == -1) {
14090                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
14091                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
14092                                 "in config file to run this testsuite.\n");
14093                 return TEST_FAILED;
14094         }
14095
14096         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
14097 }
14098
14099 static int
14100 test_cryptodev_octeontx(void)
14101 {
14102         gbl_driver_id = rte_cryptodev_driver_id_get(
14103                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14104         if (gbl_driver_id == -1) {
14105                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
14106                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
14107                                 "enabled in config file to run this "
14108                                 "testsuite.\n");
14109                 return TEST_FAILED;
14110         }
14111         return unit_test_suite_runner(&cryptodev_octeontx_testsuite);
14112 }
14113
14114 static int
14115 test_cryptodev_octeontx2(void)
14116 {
14117         gbl_driver_id = rte_cryptodev_driver_id_get(
14118                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14119         if (gbl_driver_id == -1) {
14120                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded. Check if "
14121                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
14122                                 "enabled in config file to run this "
14123                                 "testsuite.\n");
14124                 return TEST_FAILED;
14125         }
14126         return unit_test_suite_runner(&cryptodev_octeontx2_testsuite);
14127 }
14128
14129 static int
14130 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14131 {
14132         gbl_driver_id = rte_cryptodev_driver_id_get(
14133                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14134
14135         if (gbl_driver_id == -1) {
14136                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded. Check if "
14137                                 "CONFIG_RTE_LIBRTE_PMD_CAAM_JR is enabled "
14138                                 "in config file to run this testsuite.\n");
14139                 return TEST_FAILED;
14140         }
14141
14142         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
14143 }
14144
14145 static int
14146 test_cryptodev_nitrox(void)
14147 {
14148         gbl_driver_id = rte_cryptodev_driver_id_get(
14149                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14150
14151         if (gbl_driver_id == -1) {
14152                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded. Check if "
14153                                 "CONFIG_RTE_LIBRTE_PMD_NITROX is enabled "
14154                                 "in config file to run this testsuite.\n");
14155                 return TEST_FAILED;
14156         }
14157
14158         return unit_test_suite_runner(&cryptodev_nitrox_testsuite);
14159 }
14160
14161 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14162 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14163 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14164 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14165 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14166 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14167 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14168 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14169 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14170 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14171 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14172 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14173 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14174 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14175 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14176 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14177 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14178 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);