e6abc22b6c95ea4c9c414234b7cc2a130dec63f5
[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 (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5075                 printf("Device doesn't support digest encrypted.\n");
5076                 return -ENOTSUP;
5077         }
5078
5079         /* Create ZUC session */
5080         retval = create_wireless_algo_auth_cipher_session(
5081                         ts_params->valid_devs[0],
5082                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5083                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5084                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5085                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5086                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5087                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5088                         tdata->key.data, tdata->key.len,
5089                         tdata->auth_iv.len, tdata->digest.len,
5090                         tdata->cipher_iv.len);
5091
5092         if (retval < 0)
5093                 return retval;
5094
5095         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5096         if (op_mode == OUT_OF_PLACE)
5097                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5098
5099         /* clear mbuf payload */
5100         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5101                 rte_pktmbuf_tailroom(ut_params->ibuf));
5102         if (op_mode == OUT_OF_PLACE)
5103                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5104                         rte_pktmbuf_tailroom(ut_params->obuf));
5105
5106         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5107         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5108         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5109         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5110
5111         if (verify) {
5112                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5113                                         ciphertext_pad_len);
5114                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5115                 if (op_mode == OUT_OF_PLACE)
5116                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5117                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5118                         ciphertext_len);
5119         } else {
5120                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5121                                         plaintext_pad_len);
5122                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5123                 if (op_mode == OUT_OF_PLACE)
5124                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5125                 debug_hexdump(stdout, "plaintext:", plaintext,
5126                         plaintext_len);
5127         }
5128
5129         /* Create ZUC operation */
5130         retval = create_wireless_algo_auth_cipher_operation(
5131                 tdata->digest.data, tdata->digest.len,
5132                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5133                 tdata->auth_iv.data, tdata->auth_iv.len,
5134                 (tdata->digest.offset_bytes == 0 ?
5135                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5136                         : tdata->digest.offset_bytes),
5137                 tdata->validCipherLenInBits.len,
5138                 tdata->validCipherOffsetInBits.len,
5139                 tdata->validAuthLenInBits.len,
5140                 0,
5141                 op_mode, 0, verify);
5142
5143         if (retval < 0)
5144                 return retval;
5145
5146         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5147                         ut_params->op);
5148
5149         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5150
5151         ut_params->obuf = (op_mode == IN_PLACE ?
5152                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5153
5154
5155         if (verify) {
5156                 if (ut_params->obuf)
5157                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5158                                                         uint8_t *);
5159                 else
5160                         plaintext = ciphertext;
5161
5162                 debug_hexdump(stdout, "plaintext:", plaintext,
5163                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5164                 debug_hexdump(stdout, "plaintext expected:",
5165                         tdata->plaintext.data,
5166                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5167         } else {
5168                 if (ut_params->obuf)
5169                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5170                                                         uint8_t *);
5171                 else
5172                         ciphertext = plaintext;
5173
5174                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5175                         ciphertext_len);
5176                 debug_hexdump(stdout, "ciphertext expected:",
5177                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5178
5179                 ut_params->digest = rte_pktmbuf_mtod(
5180                         ut_params->obuf, uint8_t *) +
5181                         (tdata->digest.offset_bytes == 0 ?
5182                         plaintext_pad_len : tdata->digest.offset_bytes);
5183
5184                 debug_hexdump(stdout, "digest:", ut_params->digest,
5185                         tdata->digest.len);
5186                 debug_hexdump(stdout, "digest expected:",
5187                         tdata->digest.data, tdata->digest.len);
5188         }
5189
5190         /* Validate obuf */
5191         if (verify) {
5192                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5193                         plaintext,
5194                         tdata->plaintext.data,
5195                         tdata->plaintext.len >> 3,
5196                         "ZUC Plaintext data not as expected");
5197         } else {
5198                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5199                         ciphertext,
5200                         tdata->ciphertext.data,
5201                         tdata->ciphertext.len >> 3,
5202                         "ZUC Ciphertext data not as expected");
5203
5204                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5205                         ut_params->digest,
5206                         tdata->digest.data,
5207                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5208                         "ZUC Generated auth tag not as expected");
5209         }
5210         return 0;
5211 }
5212
5213 static int
5214 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5215         uint8_t op_mode, uint8_t verify)
5216 {
5217         struct crypto_testsuite_params *ts_params = &testsuite_params;
5218         struct crypto_unittest_params *ut_params = &unittest_params;
5219
5220         int retval;
5221
5222         const uint8_t *plaintext = NULL;
5223         const uint8_t *ciphertext = NULL;
5224         const uint8_t *digest = NULL;
5225         unsigned int plaintext_pad_len;
5226         unsigned int plaintext_len;
5227         unsigned int ciphertext_pad_len;
5228         unsigned int ciphertext_len;
5229         uint8_t buffer[10000];
5230         uint8_t digest_buffer[10000];
5231
5232         struct rte_cryptodev_info dev_info;
5233         struct rte_cryptodev_sym_capability_idx cap_idx;
5234
5235         /* Check if device supports ZUC EIA3 */
5236         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5237         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5238
5239         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5240                         &cap_idx) == NULL)
5241                 return -ENOTSUP;
5242
5243         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5244
5245         uint64_t feat_flags = dev_info.feature_flags;
5246
5247         if (op_mode == IN_PLACE) {
5248                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5249                         printf("Device doesn't support in-place scatter-gather "
5250                                         "in both input and output mbufs.\n");
5251                         return -ENOTSUP;
5252                 }
5253         } else {
5254                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5255                         printf("Device doesn't support out-of-place scatter-gather "
5256                                         "in both input and output mbufs.\n");
5257                         return -ENOTSUP;
5258                 }
5259                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5260                         printf("Device doesn't support digest encrypted.\n");
5261                         return -ENOTSUP;
5262                 }
5263         }
5264
5265         /* Create ZUC session */
5266         retval = create_wireless_algo_auth_cipher_session(
5267                         ts_params->valid_devs[0],
5268                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5269                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5270                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5271                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5272                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5273                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5274                         tdata->key.data, tdata->key.len,
5275                         tdata->auth_iv.len, tdata->digest.len,
5276                         tdata->cipher_iv.len);
5277
5278         if (retval < 0)
5279                 return retval;
5280
5281         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5282         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5283         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5284         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5285
5286         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5287                         plaintext_pad_len, 15, 0);
5288         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5289                         "Failed to allocate input buffer in mempool");
5290
5291         if (op_mode == OUT_OF_PLACE) {
5292                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5293                                 plaintext_pad_len, 15, 0);
5294                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5295                                 "Failed to allocate output buffer in mempool");
5296         }
5297
5298         if (verify) {
5299                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5300                         tdata->ciphertext.data);
5301                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5302                                         ciphertext_len, buffer);
5303                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5304                         ciphertext_len);
5305         } else {
5306                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5307                         tdata->plaintext.data);
5308                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5309                                         plaintext_len, buffer);
5310                 debug_hexdump(stdout, "plaintext:", plaintext,
5311                         plaintext_len);
5312         }
5313         memset(buffer, 0, sizeof(buffer));
5314
5315         /* Create ZUC operation */
5316         retval = create_wireless_algo_auth_cipher_operation(
5317                 tdata->digest.data, tdata->digest.len,
5318                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5319                 NULL, 0,
5320                 (tdata->digest.offset_bytes == 0 ?
5321                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5322                         : tdata->digest.offset_bytes),
5323                 tdata->validCipherLenInBits.len,
5324                 tdata->validCipherOffsetInBits.len,
5325                 tdata->validAuthLenInBits.len,
5326                 0,
5327                 op_mode, 1, verify);
5328
5329         if (retval < 0)
5330                 return retval;
5331
5332         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5333                         ut_params->op);
5334
5335         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5336
5337         ut_params->obuf = (op_mode == IN_PLACE ?
5338                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5339
5340         if (verify) {
5341                 if (ut_params->obuf)
5342                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5343                                         plaintext_len, buffer);
5344                 else
5345                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5346                                         plaintext_len, buffer);
5347
5348                 debug_hexdump(stdout, "plaintext:", plaintext,
5349                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5350                 debug_hexdump(stdout, "plaintext expected:",
5351                         tdata->plaintext.data,
5352                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5353         } else {
5354                 if (ut_params->obuf)
5355                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5356                                         ciphertext_len, buffer);
5357                 else
5358                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5359                                         ciphertext_len, buffer);
5360
5361                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5362                         ciphertext_len);
5363                 debug_hexdump(stdout, "ciphertext expected:",
5364                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5365
5366                 if (ut_params->obuf)
5367                         digest = rte_pktmbuf_read(ut_params->obuf,
5368                                 (tdata->digest.offset_bytes == 0 ?
5369                                 plaintext_pad_len : tdata->digest.offset_bytes),
5370                                 tdata->digest.len, digest_buffer);
5371                 else
5372                         digest = rte_pktmbuf_read(ut_params->ibuf,
5373                                 (tdata->digest.offset_bytes == 0 ?
5374                                 plaintext_pad_len : tdata->digest.offset_bytes),
5375                                 tdata->digest.len, digest_buffer);
5376
5377                 debug_hexdump(stdout, "digest:", digest,
5378                         tdata->digest.len);
5379                 debug_hexdump(stdout, "digest expected:",
5380                         tdata->digest.data, tdata->digest.len);
5381         }
5382
5383         /* Validate obuf */
5384         if (verify) {
5385                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5386                         plaintext,
5387                         tdata->plaintext.data,
5388                         tdata->plaintext.len >> 3,
5389                         "ZUC Plaintext data not as expected");
5390         } else {
5391                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5392                         ciphertext,
5393                         tdata->ciphertext.data,
5394                         tdata->validDataLenInBits.len,
5395                         "ZUC Ciphertext data not as expected");
5396
5397                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5398                         digest,
5399                         tdata->digest.data,
5400                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5401                         "ZUC Generated auth tag not as expected");
5402         }
5403         return 0;
5404 }
5405
5406 static int
5407 test_kasumi_encryption_test_case_1(void)
5408 {
5409         return test_kasumi_encryption(&kasumi_test_case_1);
5410 }
5411
5412 static int
5413 test_kasumi_encryption_test_case_1_sgl(void)
5414 {
5415         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
5416 }
5417
5418 static int
5419 test_kasumi_encryption_test_case_1_oop(void)
5420 {
5421         return test_kasumi_encryption_oop(&kasumi_test_case_1);
5422 }
5423
5424 static int
5425 test_kasumi_encryption_test_case_1_oop_sgl(void)
5426 {
5427         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
5428 }
5429
5430 static int
5431 test_kasumi_encryption_test_case_2(void)
5432 {
5433         return test_kasumi_encryption(&kasumi_test_case_2);
5434 }
5435
5436 static int
5437 test_kasumi_encryption_test_case_3(void)
5438 {
5439         return test_kasumi_encryption(&kasumi_test_case_3);
5440 }
5441
5442 static int
5443 test_kasumi_encryption_test_case_4(void)
5444 {
5445         return test_kasumi_encryption(&kasumi_test_case_4);
5446 }
5447
5448 static int
5449 test_kasumi_encryption_test_case_5(void)
5450 {
5451         return test_kasumi_encryption(&kasumi_test_case_5);
5452 }
5453
5454 static int
5455 test_kasumi_decryption_test_case_1(void)
5456 {
5457         return test_kasumi_decryption(&kasumi_test_case_1);
5458 }
5459
5460 static int
5461 test_kasumi_decryption_test_case_1_oop(void)
5462 {
5463         return test_kasumi_decryption_oop(&kasumi_test_case_1);
5464 }
5465
5466 static int
5467 test_kasumi_decryption_test_case_2(void)
5468 {
5469         return test_kasumi_decryption(&kasumi_test_case_2);
5470 }
5471
5472 static int
5473 test_kasumi_decryption_test_case_3(void)
5474 {
5475         return test_kasumi_decryption(&kasumi_test_case_3);
5476 }
5477
5478 static int
5479 test_kasumi_decryption_test_case_4(void)
5480 {
5481         return test_kasumi_decryption(&kasumi_test_case_4);
5482 }
5483
5484 static int
5485 test_kasumi_decryption_test_case_5(void)
5486 {
5487         return test_kasumi_decryption(&kasumi_test_case_5);
5488 }
5489 static int
5490 test_snow3g_encryption_test_case_1(void)
5491 {
5492         return test_snow3g_encryption(&snow3g_test_case_1);
5493 }
5494
5495 static int
5496 test_snow3g_encryption_test_case_1_oop(void)
5497 {
5498         return test_snow3g_encryption_oop(&snow3g_test_case_1);
5499 }
5500
5501 static int
5502 test_snow3g_encryption_test_case_1_oop_sgl(void)
5503 {
5504         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
5505 }
5506
5507
5508 static int
5509 test_snow3g_encryption_test_case_1_offset_oop(void)
5510 {
5511         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
5512 }
5513
5514 static int
5515 test_snow3g_encryption_test_case_2(void)
5516 {
5517         return test_snow3g_encryption(&snow3g_test_case_2);
5518 }
5519
5520 static int
5521 test_snow3g_encryption_test_case_3(void)
5522 {
5523         return test_snow3g_encryption(&snow3g_test_case_3);
5524 }
5525
5526 static int
5527 test_snow3g_encryption_test_case_4(void)
5528 {
5529         return test_snow3g_encryption(&snow3g_test_case_4);
5530 }
5531
5532 static int
5533 test_snow3g_encryption_test_case_5(void)
5534 {
5535         return test_snow3g_encryption(&snow3g_test_case_5);
5536 }
5537
5538 static int
5539 test_snow3g_decryption_test_case_1(void)
5540 {
5541         return test_snow3g_decryption(&snow3g_test_case_1);
5542 }
5543
5544 static int
5545 test_snow3g_decryption_test_case_1_oop(void)
5546 {
5547         return test_snow3g_decryption_oop(&snow3g_test_case_1);
5548 }
5549
5550 static int
5551 test_snow3g_decryption_test_case_2(void)
5552 {
5553         return test_snow3g_decryption(&snow3g_test_case_2);
5554 }
5555
5556 static int
5557 test_snow3g_decryption_test_case_3(void)
5558 {
5559         return test_snow3g_decryption(&snow3g_test_case_3);
5560 }
5561
5562 static int
5563 test_snow3g_decryption_test_case_4(void)
5564 {
5565         return test_snow3g_decryption(&snow3g_test_case_4);
5566 }
5567
5568 static int
5569 test_snow3g_decryption_test_case_5(void)
5570 {
5571         return test_snow3g_decryption(&snow3g_test_case_5);
5572 }
5573
5574 /*
5575  * Function prepares snow3g_hash_test_data from snow3g_test_data.
5576  * Pattern digest from snow3g_test_data must be allocated as
5577  * 4 last bytes in plaintext.
5578  */
5579 static void
5580 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
5581                 struct snow3g_hash_test_data *output)
5582 {
5583         if ((pattern != NULL) && (output != NULL)) {
5584                 output->key.len = pattern->key.len;
5585
5586                 memcpy(output->key.data,
5587                 pattern->key.data, pattern->key.len);
5588
5589                 output->auth_iv.len = pattern->auth_iv.len;
5590
5591                 memcpy(output->auth_iv.data,
5592                 pattern->auth_iv.data, pattern->auth_iv.len);
5593
5594                 output->plaintext.len = pattern->plaintext.len;
5595
5596                 memcpy(output->plaintext.data,
5597                 pattern->plaintext.data, pattern->plaintext.len >> 3);
5598
5599                 output->digest.len = pattern->digest.len;
5600
5601                 memcpy(output->digest.data,
5602                 &pattern->plaintext.data[pattern->digest.offset_bytes],
5603                 pattern->digest.len);
5604
5605                 output->validAuthLenInBits.len =
5606                 pattern->validAuthLenInBits.len;
5607         }
5608 }
5609
5610 /*
5611  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
5612  */
5613 static int
5614 test_snow3g_decryption_with_digest_test_case_1(void)
5615 {
5616         struct snow3g_hash_test_data snow3g_hash_data;
5617
5618         /*
5619          * Function prepare data for hash veryfication test case.
5620          * Digest is allocated in 4 last bytes in plaintext, pattern.
5621          */
5622         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
5623
5624         return test_snow3g_decryption(&snow3g_test_case_7) &
5625                         test_snow3g_authentication_verify(&snow3g_hash_data);
5626 }
5627
5628 static int
5629 test_snow3g_cipher_auth_test_case_1(void)
5630 {
5631         return test_snow3g_cipher_auth(&snow3g_test_case_3);
5632 }
5633
5634 static int
5635 test_snow3g_auth_cipher_test_case_1(void)
5636 {
5637         return test_snow3g_auth_cipher(
5638                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
5639 }
5640
5641 static int
5642 test_snow3g_auth_cipher_test_case_2(void)
5643 {
5644         return test_snow3g_auth_cipher(
5645                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
5646 }
5647
5648 static int
5649 test_snow3g_auth_cipher_test_case_2_oop(void)
5650 {
5651         return test_snow3g_auth_cipher(
5652                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5653 }
5654
5655 static int
5656 test_snow3g_auth_cipher_part_digest_enc(void)
5657 {
5658         return test_snow3g_auth_cipher(
5659                 &snow3g_auth_cipher_partial_digest_encryption,
5660                         IN_PLACE, 0);
5661 }
5662
5663 static int
5664 test_snow3g_auth_cipher_part_digest_enc_oop(void)
5665 {
5666         return test_snow3g_auth_cipher(
5667                 &snow3g_auth_cipher_partial_digest_encryption,
5668                         OUT_OF_PLACE, 0);
5669 }
5670
5671 static int
5672 test_snow3g_auth_cipher_test_case_3_sgl(void)
5673 {
5674         return test_snow3g_auth_cipher_sgl(
5675                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
5676 }
5677
5678 static int
5679 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
5680 {
5681         return test_snow3g_auth_cipher_sgl(
5682                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
5683 }
5684
5685 static int
5686 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
5687 {
5688         return test_snow3g_auth_cipher_sgl(
5689                 &snow3g_auth_cipher_partial_digest_encryption,
5690                         IN_PLACE, 0);
5691 }
5692
5693 static int
5694 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
5695 {
5696         return test_snow3g_auth_cipher_sgl(
5697                 &snow3g_auth_cipher_partial_digest_encryption,
5698                         OUT_OF_PLACE, 0);
5699 }
5700
5701 static int
5702 test_snow3g_auth_cipher_verify_test_case_1(void)
5703 {
5704         return test_snow3g_auth_cipher(
5705                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
5706 }
5707
5708 static int
5709 test_snow3g_auth_cipher_verify_test_case_2(void)
5710 {
5711         return test_snow3g_auth_cipher(
5712                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
5713 }
5714
5715 static int
5716 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
5717 {
5718         return test_snow3g_auth_cipher(
5719                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5720 }
5721
5722 static int
5723 test_snow3g_auth_cipher_verify_part_digest_enc(void)
5724 {
5725         return test_snow3g_auth_cipher(
5726                 &snow3g_auth_cipher_partial_digest_encryption,
5727                         IN_PLACE, 1);
5728 }
5729
5730 static int
5731 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
5732 {
5733         return test_snow3g_auth_cipher(
5734                 &snow3g_auth_cipher_partial_digest_encryption,
5735                         OUT_OF_PLACE, 1);
5736 }
5737
5738 static int
5739 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
5740 {
5741         return test_snow3g_auth_cipher_sgl(
5742                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
5743 }
5744
5745 static int
5746 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
5747 {
5748         return test_snow3g_auth_cipher_sgl(
5749                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
5750 }
5751
5752 static int
5753 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
5754 {
5755         return test_snow3g_auth_cipher_sgl(
5756                 &snow3g_auth_cipher_partial_digest_encryption,
5757                         IN_PLACE, 1);
5758 }
5759
5760 static int
5761 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
5762 {
5763         return test_snow3g_auth_cipher_sgl(
5764                 &snow3g_auth_cipher_partial_digest_encryption,
5765                         OUT_OF_PLACE, 1);
5766 }
5767
5768 static int
5769 test_snow3g_auth_cipher_with_digest_test_case_1(void)
5770 {
5771         return test_snow3g_auth_cipher(
5772                 &snow3g_test_case_7, IN_PLACE, 0);
5773 }
5774
5775 static int
5776 test_kasumi_auth_cipher_test_case_1(void)
5777 {
5778         return test_kasumi_auth_cipher(
5779                 &kasumi_test_case_3, IN_PLACE, 0);
5780 }
5781
5782 static int
5783 test_kasumi_auth_cipher_test_case_2(void)
5784 {
5785         return test_kasumi_auth_cipher(
5786                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
5787 }
5788
5789 static int
5790 test_kasumi_auth_cipher_test_case_2_oop(void)
5791 {
5792         return test_kasumi_auth_cipher(
5793                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5794 }
5795
5796 static int
5797 test_kasumi_auth_cipher_test_case_2_sgl(void)
5798 {
5799         return test_kasumi_auth_cipher_sgl(
5800                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
5801 }
5802
5803 static int
5804 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
5805 {
5806         return test_kasumi_auth_cipher_sgl(
5807                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
5808 }
5809
5810 static int
5811 test_kasumi_auth_cipher_verify_test_case_1(void)
5812 {
5813         return test_kasumi_auth_cipher(
5814                 &kasumi_test_case_3, IN_PLACE, 1);
5815 }
5816
5817 static int
5818 test_kasumi_auth_cipher_verify_test_case_2(void)
5819 {
5820         return test_kasumi_auth_cipher(
5821                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
5822 }
5823
5824 static int
5825 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
5826 {
5827         return test_kasumi_auth_cipher(
5828                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5829 }
5830
5831 static int
5832 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
5833 {
5834         return test_kasumi_auth_cipher_sgl(
5835                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
5836 }
5837
5838 static int
5839 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
5840 {
5841         return test_kasumi_auth_cipher_sgl(
5842                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
5843 }
5844
5845 static int
5846 test_kasumi_cipher_auth_test_case_1(void)
5847 {
5848         return test_kasumi_cipher_auth(&kasumi_test_case_6);
5849 }
5850
5851 static int
5852 test_zuc_encryption_test_case_1(void)
5853 {
5854         return test_zuc_encryption(&zuc_test_case_cipher_193b);
5855 }
5856
5857 static int
5858 test_zuc_encryption_test_case_2(void)
5859 {
5860         return test_zuc_encryption(&zuc_test_case_cipher_800b);
5861 }
5862
5863 static int
5864 test_zuc_encryption_test_case_3(void)
5865 {
5866         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
5867 }
5868
5869 static int
5870 test_zuc_encryption_test_case_4(void)
5871 {
5872         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
5873 }
5874
5875 static int
5876 test_zuc_encryption_test_case_5(void)
5877 {
5878         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
5879 }
5880
5881 static int
5882 test_zuc_encryption_test_case_6_sgl(void)
5883 {
5884         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
5885 }
5886
5887 static int
5888 test_zuc_hash_generate_test_case_1(void)
5889 {
5890         return test_zuc_authentication(&zuc_test_case_auth_1b);
5891 }
5892
5893 static int
5894 test_zuc_hash_generate_test_case_2(void)
5895 {
5896         return test_zuc_authentication(&zuc_test_case_auth_90b);
5897 }
5898
5899 static int
5900 test_zuc_hash_generate_test_case_3(void)
5901 {
5902         return test_zuc_authentication(&zuc_test_case_auth_577b);
5903 }
5904
5905 static int
5906 test_zuc_hash_generate_test_case_4(void)
5907 {
5908         return test_zuc_authentication(&zuc_test_case_auth_2079b);
5909 }
5910
5911 static int
5912 test_zuc_hash_generate_test_case_5(void)
5913 {
5914         return test_zuc_authentication(&zuc_test_auth_5670b);
5915 }
5916
5917 static int
5918 test_zuc_hash_generate_test_case_6(void)
5919 {
5920         return test_zuc_authentication(&zuc_test_case_auth_128b);
5921 }
5922
5923 static int
5924 test_zuc_hash_generate_test_case_7(void)
5925 {
5926         /* This test is not for SW ZUC PMD */
5927         if (gbl_driver_id == rte_cryptodev_driver_id_get(
5928                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD)))
5929                 return -ENOTSUP;
5930
5931         return test_zuc_authentication(&zuc_test_case_auth_2080b);
5932 }
5933
5934 static int
5935 test_zuc_hash_generate_test_case_8(void)
5936 {
5937         return test_zuc_authentication(&zuc_test_case_auth_584b);
5938 }
5939
5940 static int
5941 test_zuc_cipher_auth_test_case_1(void)
5942 {
5943         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
5944 }
5945
5946 static int
5947 test_zuc_cipher_auth_test_case_2(void)
5948 {
5949         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
5950 }
5951
5952 static int
5953 test_zuc_auth_cipher_test_case_1(void)
5954 {
5955         /* This test is not for SW ZUC PMD */
5956         if (gbl_driver_id == rte_cryptodev_driver_id_get(
5957                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD)))
5958                 return -ENOTSUP;
5959
5960         return test_zuc_auth_cipher(
5961                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
5962 }
5963
5964 static int
5965 test_zuc_auth_cipher_test_case_1_oop(void)
5966 {
5967         return test_zuc_auth_cipher(
5968                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
5969 }
5970
5971 static int
5972 test_zuc_auth_cipher_test_case_1_sgl(void)
5973 {
5974         return test_zuc_auth_cipher_sgl(
5975                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
5976 }
5977
5978 static int
5979 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
5980 {
5981         return test_zuc_auth_cipher_sgl(
5982                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
5983 }
5984
5985 static int
5986 test_zuc_auth_cipher_verify_test_case_1(void)
5987 {
5988         return test_zuc_auth_cipher(
5989                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
5990 }
5991
5992 static int
5993 test_zuc_auth_cipher_verify_test_case_1_oop(void)
5994 {
5995         return test_zuc_auth_cipher(
5996                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
5997 }
5998
5999 static int
6000 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6001 {
6002         return test_zuc_auth_cipher_sgl(
6003                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6004 }
6005
6006 static int
6007 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6008 {
6009         return test_zuc_auth_cipher_sgl(
6010                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6011 }
6012
6013 static int
6014 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6015 {
6016         uint8_t dev_id = testsuite_params.valid_devs[0];
6017
6018         struct rte_cryptodev_sym_capability_idx cap_idx;
6019
6020         /* Check if device supports particular cipher algorithm */
6021         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6022         cap_idx.algo.cipher = tdata->cipher_algo;
6023         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6024                 return -ENOTSUP;
6025
6026         /* Check if device supports particular hash algorithm */
6027         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6028         cap_idx.algo.auth = tdata->auth_algo;
6029         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6030                 return -ENOTSUP;
6031
6032         return 0;
6033 }
6034
6035 static int
6036 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6037         uint8_t op_mode, uint8_t verify)
6038 {
6039         struct crypto_testsuite_params *ts_params = &testsuite_params;
6040         struct crypto_unittest_params *ut_params = &unittest_params;
6041
6042         int retval;
6043
6044         uint8_t *plaintext = NULL, *ciphertext = NULL;
6045         unsigned int plaintext_pad_len;
6046         unsigned int plaintext_len;
6047         unsigned int ciphertext_pad_len;
6048         unsigned int ciphertext_len;
6049
6050         struct rte_cryptodev_info dev_info;
6051         struct rte_crypto_op *op;
6052
6053         /* Check if device supports particular algorithms separately */
6054         if (test_mixed_check_if_unsupported(tdata))
6055                 return -ENOTSUP;
6056
6057         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6058
6059         uint64_t feat_flags = dev_info.feature_flags;
6060
6061         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6062                 printf("Device doesn't support digest encrypted.\n");
6063                 return -ENOTSUP;
6064         }
6065
6066         /* Create the session */
6067         if (verify)
6068                 retval = create_wireless_algo_cipher_auth_session(
6069                                 ts_params->valid_devs[0],
6070                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6071                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6072                                 tdata->auth_algo,
6073                                 tdata->cipher_algo,
6074                                 tdata->auth_key.data, tdata->auth_key.len,
6075                                 tdata->auth_iv.len, tdata->digest_enc.len,
6076                                 tdata->cipher_iv.len);
6077         else
6078                 retval = create_wireless_algo_auth_cipher_session(
6079                                 ts_params->valid_devs[0],
6080                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6081                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6082                                 tdata->auth_algo,
6083                                 tdata->cipher_algo,
6084                                 tdata->auth_key.data, tdata->auth_key.len,
6085                                 tdata->auth_iv.len, tdata->digest_enc.len,
6086                                 tdata->cipher_iv.len);
6087         if (retval < 0)
6088                 return retval;
6089
6090         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6091         if (op_mode == OUT_OF_PLACE)
6092                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6093
6094         /* clear mbuf payload */
6095         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6096                 rte_pktmbuf_tailroom(ut_params->ibuf));
6097         if (op_mode == OUT_OF_PLACE)
6098                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6099                                 rte_pktmbuf_tailroom(ut_params->obuf));
6100
6101         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6102         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6103         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6104         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6105
6106         if (verify) {
6107                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6108                                 ciphertext_pad_len);
6109                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6110                 if (op_mode == OUT_OF_PLACE)
6111                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6112                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6113                                 ciphertext_len);
6114         } else {
6115                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6116                                 plaintext_pad_len);
6117                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6118                 if (op_mode == OUT_OF_PLACE)
6119                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6120                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6121         }
6122
6123         /* Create the operation */
6124         retval = create_wireless_algo_auth_cipher_operation(
6125                         tdata->digest_enc.data, tdata->digest_enc.len,
6126                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6127                         tdata->auth_iv.data, tdata->auth_iv.len,
6128                         (tdata->digest_enc.offset == 0 ?
6129                                 plaintext_pad_len
6130                                 : tdata->digest_enc.offset),
6131                         tdata->validCipherLen.len_bits,
6132                         tdata->cipher.offset_bits,
6133                         tdata->validAuthLen.len_bits,
6134                         tdata->auth.offset_bits,
6135                         op_mode, 0, verify);
6136
6137         if (retval < 0)
6138                 return retval;
6139
6140         op = process_crypto_request(ts_params->valid_devs[0],
6141                         ut_params->op);
6142
6143         /* Check if the op failed because the device doesn't */
6144         /* support this particular combination of algorithms */
6145         if (op == NULL && ut_params->op->status ==
6146                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6147                 printf("Device doesn't support this mixed combination. "
6148                                 "Test Skipped.\n");
6149                 return -ENOTSUP;
6150         }
6151         ut_params->op = op;
6152
6153         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6154
6155         ut_params->obuf = (op_mode == IN_PLACE ?
6156                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6157
6158         if (verify) {
6159                 if (ut_params->obuf)
6160                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6161                                                         uint8_t *);
6162                 else
6163                         plaintext = ciphertext +
6164                                         (tdata->cipher.offset_bits >> 3);
6165
6166                 debug_hexdump(stdout, "plaintext:", plaintext,
6167                                 tdata->plaintext.len_bits >> 3);
6168                 debug_hexdump(stdout, "plaintext expected:",
6169                                 tdata->plaintext.data,
6170                                 tdata->plaintext.len_bits >> 3);
6171         } else {
6172                 if (ut_params->obuf)
6173                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6174                                         uint8_t *);
6175                 else
6176                         ciphertext = plaintext;
6177
6178                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6179                                 ciphertext_len);
6180                 debug_hexdump(stdout, "ciphertext expected:",
6181                                 tdata->ciphertext.data,
6182                                 tdata->ciphertext.len_bits >> 3);
6183
6184                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6185                                 + (tdata->digest_enc.offset == 0 ?
6186                 plaintext_pad_len : tdata->digest_enc.offset);
6187
6188                 debug_hexdump(stdout, "digest:", ut_params->digest,
6189                                 tdata->digest_enc.len);
6190                 debug_hexdump(stdout, "digest expected:",
6191                                 tdata->digest_enc.data,
6192                                 tdata->digest_enc.len);
6193         }
6194
6195         /* Validate obuf */
6196         if (verify) {
6197                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6198                                 plaintext,
6199                                 tdata->plaintext.data,
6200                                 tdata->plaintext.len_bits >> 3,
6201                                 "Plaintext data not as expected");
6202         } else {
6203                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6204                                 ciphertext,
6205                                 tdata->ciphertext.data,
6206                                 tdata->validDataLen.len_bits,
6207                                 "Ciphertext data not as expected");
6208
6209                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6210                                 ut_params->digest,
6211                                 tdata->digest_enc.data,
6212                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6213                                 "Generated auth tag not as expected");
6214         }
6215
6216         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6217                         "crypto op processing failed");
6218
6219         return 0;
6220 }
6221
6222 static int
6223 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6224         uint8_t op_mode, uint8_t verify)
6225 {
6226         struct crypto_testsuite_params *ts_params = &testsuite_params;
6227         struct crypto_unittest_params *ut_params = &unittest_params;
6228
6229         int retval;
6230
6231         const uint8_t *plaintext = NULL;
6232         const uint8_t *ciphertext = NULL;
6233         const uint8_t *digest = NULL;
6234         unsigned int plaintext_pad_len;
6235         unsigned int plaintext_len;
6236         unsigned int ciphertext_pad_len;
6237         unsigned int ciphertext_len;
6238         uint8_t buffer[10000];
6239         uint8_t digest_buffer[10000];
6240
6241         struct rte_cryptodev_info dev_info;
6242         struct rte_crypto_op *op;
6243
6244         /* Check if device supports particular algorithms */
6245         if (test_mixed_check_if_unsupported(tdata))
6246                 return -ENOTSUP;
6247
6248         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6249
6250         uint64_t feat_flags = dev_info.feature_flags;
6251
6252         if (op_mode == IN_PLACE) {
6253                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6254                         printf("Device doesn't support in-place scatter-gather "
6255                                         "in both input and output mbufs.\n");
6256                         return -ENOTSUP;
6257                 }
6258         } else {
6259                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6260                         printf("Device doesn't support out-of-place scatter-gather "
6261                                         "in both input and output mbufs.\n");
6262                         return -ENOTSUP;
6263                 }
6264                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6265                         printf("Device doesn't support digest encrypted.\n");
6266                         return -ENOTSUP;
6267                 }
6268         }
6269
6270         /* Create the session */
6271         if (verify)
6272                 retval = create_wireless_algo_cipher_auth_session(
6273                                 ts_params->valid_devs[0],
6274                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6275                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6276                                 tdata->auth_algo,
6277                                 tdata->cipher_algo,
6278                                 tdata->auth_key.data, tdata->auth_key.len,
6279                                 tdata->auth_iv.len, tdata->digest_enc.len,
6280                                 tdata->cipher_iv.len);
6281         else
6282                 retval = create_wireless_algo_auth_cipher_session(
6283                                 ts_params->valid_devs[0],
6284                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6285                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6286                                 tdata->auth_algo,
6287                                 tdata->cipher_algo,
6288                                 tdata->auth_key.data, tdata->auth_key.len,
6289                                 tdata->auth_iv.len, tdata->digest_enc.len,
6290                                 tdata->cipher_iv.len);
6291         if (retval < 0)
6292                 return retval;
6293
6294         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6295         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6296         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6297         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6298
6299         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6300                         ciphertext_pad_len, 15, 0);
6301         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6302                         "Failed to allocate input buffer in mempool");
6303
6304         if (op_mode == OUT_OF_PLACE) {
6305                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6306                                 plaintext_pad_len, 15, 0);
6307                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6308                                 "Failed to allocate output buffer in mempool");
6309         }
6310
6311         if (verify) {
6312                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6313                         tdata->ciphertext.data);
6314                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6315                                         ciphertext_len, buffer);
6316                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6317                         ciphertext_len);
6318         } else {
6319                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6320                         tdata->plaintext.data);
6321                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6322                                         plaintext_len, buffer);
6323                 debug_hexdump(stdout, "plaintext:", plaintext,
6324                         plaintext_len);
6325         }
6326         memset(buffer, 0, sizeof(buffer));
6327
6328         /* Create the operation */
6329         retval = create_wireless_algo_auth_cipher_operation(
6330                         tdata->digest_enc.data, tdata->digest_enc.len,
6331                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6332                         tdata->auth_iv.data, tdata->auth_iv.len,
6333                         (tdata->digest_enc.offset == 0 ?
6334                                 plaintext_pad_len
6335                                 : tdata->digest_enc.offset),
6336                         tdata->validCipherLen.len_bits,
6337                         tdata->cipher.offset_bits,
6338                         tdata->validAuthLen.len_bits,
6339                         tdata->auth.offset_bits,
6340                         op_mode, 1, verify);
6341
6342         if (retval < 0)
6343                 return retval;
6344
6345         op = process_crypto_request(ts_params->valid_devs[0],
6346                         ut_params->op);
6347
6348         /* Check if the op failed because the device doesn't */
6349         /* support this particular combination of algorithms */
6350         if (op == NULL && ut_params->op->status ==
6351                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6352                 printf("Device doesn't support this mixed combination. "
6353                                 "Test Skipped.\n");
6354                 return -ENOTSUP;
6355         }
6356
6357         ut_params->op = op;
6358
6359         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6360
6361         ut_params->obuf = (op_mode == IN_PLACE ?
6362                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6363
6364         if (verify) {
6365                 if (ut_params->obuf)
6366                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6367                                         plaintext_len, buffer);
6368                 else
6369                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6370                                         plaintext_len, buffer);
6371
6372                 debug_hexdump(stdout, "plaintext:", plaintext,
6373                                 (tdata->plaintext.len_bits >> 3) -
6374                                 tdata->digest_enc.len);
6375                 debug_hexdump(stdout, "plaintext expected:",
6376                                 tdata->plaintext.data,
6377                                 (tdata->plaintext.len_bits >> 3) -
6378                                 tdata->digest_enc.len);
6379         } else {
6380                 if (ut_params->obuf)
6381                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6382                                         ciphertext_len, buffer);
6383                 else
6384                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6385                                         ciphertext_len, buffer);
6386
6387                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6388                         ciphertext_len);
6389                 debug_hexdump(stdout, "ciphertext expected:",
6390                         tdata->ciphertext.data,
6391                         tdata->ciphertext.len_bits >> 3);
6392
6393                 if (ut_params->obuf)
6394                         digest = rte_pktmbuf_read(ut_params->obuf,
6395                                         (tdata->digest_enc.offset == 0 ?
6396                                                 plaintext_pad_len :
6397                                                 tdata->digest_enc.offset),
6398                                         tdata->digest_enc.len, digest_buffer);
6399                 else
6400                         digest = rte_pktmbuf_read(ut_params->ibuf,
6401                                         (tdata->digest_enc.offset == 0 ?
6402                                                 plaintext_pad_len :
6403                                                 tdata->digest_enc.offset),
6404                                         tdata->digest_enc.len, digest_buffer);
6405
6406                 debug_hexdump(stdout, "digest:", digest,
6407                                 tdata->digest_enc.len);
6408                 debug_hexdump(stdout, "digest expected:",
6409                                 tdata->digest_enc.data, tdata->digest_enc.len);
6410         }
6411
6412         /* Validate obuf */
6413         if (verify) {
6414                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6415                                 plaintext,
6416                                 tdata->plaintext.data,
6417                                 tdata->plaintext.len_bits >> 3,
6418                                 "Plaintext data not as expected");
6419         } else {
6420                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6421                                 ciphertext,
6422                                 tdata->ciphertext.data,
6423                                 tdata->validDataLen.len_bits,
6424                                 "Ciphertext data not as expected");
6425                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6426                                 digest,
6427                                 tdata->digest_enc.data,
6428                                 tdata->digest_enc.len,
6429                                 "Generated auth tag not as expected");
6430         }
6431
6432         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6433                         "crypto op processing failed");
6434
6435         return 0;
6436 }
6437
6438 /** AUTH AES CMAC + CIPHER AES CTR */
6439
6440 static int
6441 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
6442 {
6443         return test_mixed_auth_cipher(
6444                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
6445 }
6446
6447 static int
6448 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
6449 {
6450         return test_mixed_auth_cipher(
6451                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6452 }
6453
6454 static int
6455 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
6456 {
6457         return test_mixed_auth_cipher_sgl(
6458                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
6459 }
6460
6461 static int
6462 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
6463 {
6464         return test_mixed_auth_cipher_sgl(
6465                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6466 }
6467
6468 static int
6469 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
6470 {
6471         return test_mixed_auth_cipher(
6472                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
6473 }
6474
6475 static int
6476 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
6477 {
6478         return test_mixed_auth_cipher(
6479                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6480 }
6481
6482 static int
6483 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
6484 {
6485         return test_mixed_auth_cipher_sgl(
6486                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
6487 }
6488
6489 static int
6490 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
6491 {
6492         return test_mixed_auth_cipher_sgl(
6493                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6494 }
6495
6496 /** MIXED AUTH + CIPHER */
6497
6498 static int
6499 test_auth_zuc_cipher_snow_test_case_1(void)
6500 {
6501         return test_mixed_auth_cipher(
6502                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6503 }
6504
6505 static int
6506 test_verify_auth_zuc_cipher_snow_test_case_1(void)
6507 {
6508         return test_mixed_auth_cipher(
6509                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6510 }
6511
6512 static int
6513 test_auth_aes_cmac_cipher_snow_test_case_1(void)
6514 {
6515         return test_mixed_auth_cipher(
6516                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6517 }
6518
6519 static int
6520 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
6521 {
6522         return test_mixed_auth_cipher(
6523                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6524 }
6525
6526 static int
6527 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
6528 {
6529         return test_mixed_auth_cipher(
6530                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6531 }
6532
6533 static int
6534 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
6535 {
6536         return test_mixed_auth_cipher(
6537                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6538 }
6539
6540 static int
6541 test_auth_snow_cipher_aes_ctr_test_case_1(void)
6542 {
6543         return test_mixed_auth_cipher(
6544                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6545 }
6546
6547 static int
6548 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
6549 {
6550         return test_mixed_auth_cipher(
6551                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6552 }
6553
6554 static int
6555 test_auth_snow_cipher_zuc_test_case_1(void)
6556 {
6557         return test_mixed_auth_cipher(
6558                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6559 }
6560
6561 static int
6562 test_verify_auth_snow_cipher_zuc_test_case_1(void)
6563 {
6564         return test_mixed_auth_cipher(
6565                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6566 }
6567
6568 static int
6569 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
6570 {
6571         return test_mixed_auth_cipher(
6572                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6573 }
6574
6575 static int
6576 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
6577 {
6578         return test_mixed_auth_cipher(
6579                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6580 }
6581
6582 static int
6583 test_auth_null_cipher_snow_test_case_1(void)
6584 {
6585         return test_mixed_auth_cipher(
6586                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
6587 }
6588
6589 static int
6590 test_verify_auth_null_cipher_snow_test_case_1(void)
6591 {
6592         return test_mixed_auth_cipher(
6593                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
6594 }
6595
6596 static int
6597 test_auth_null_cipher_zuc_test_case_1(void)
6598 {
6599         return test_mixed_auth_cipher(
6600                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
6601 }
6602
6603 static int
6604 test_verify_auth_null_cipher_zuc_test_case_1(void)
6605 {
6606         return test_mixed_auth_cipher(
6607                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
6608 }
6609
6610 static int
6611 test_auth_snow_cipher_null_test_case_1(void)
6612 {
6613         return test_mixed_auth_cipher(
6614                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6615 }
6616
6617 static int
6618 test_verify_auth_snow_cipher_null_test_case_1(void)
6619 {
6620         return test_mixed_auth_cipher(
6621                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6622 }
6623
6624 static int
6625 test_auth_zuc_cipher_null_test_case_1(void)
6626 {
6627         return test_mixed_auth_cipher(
6628                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6629 }
6630
6631 static int
6632 test_verify_auth_zuc_cipher_null_test_case_1(void)
6633 {
6634         return test_mixed_auth_cipher(
6635                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6636 }
6637
6638 static int
6639 test_auth_null_cipher_aes_ctr_test_case_1(void)
6640 {
6641         return test_mixed_auth_cipher(
6642                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
6643 }
6644
6645 static int
6646 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
6647 {
6648         return test_mixed_auth_cipher(
6649                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
6650 }
6651
6652 static int
6653 test_auth_aes_cmac_cipher_null_test_case_1(void)
6654 {
6655         return test_mixed_auth_cipher(
6656                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
6657 }
6658
6659 static int
6660 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
6661 {
6662         return test_mixed_auth_cipher(
6663                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
6664 }
6665
6666 /* ***** AEAD algorithm Tests ***** */
6667
6668 static int
6669 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
6670                 enum rte_crypto_aead_operation op,
6671                 const uint8_t *key, const uint8_t key_len,
6672                 const uint16_t aad_len, const uint8_t auth_len,
6673                 uint8_t iv_len)
6674 {
6675         uint8_t aead_key[key_len];
6676
6677         struct crypto_testsuite_params *ts_params = &testsuite_params;
6678         struct crypto_unittest_params *ut_params = &unittest_params;
6679
6680         memcpy(aead_key, key, key_len);
6681
6682         /* Setup AEAD Parameters */
6683         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
6684         ut_params->aead_xform.next = NULL;
6685         ut_params->aead_xform.aead.algo = algo;
6686         ut_params->aead_xform.aead.op = op;
6687         ut_params->aead_xform.aead.key.data = aead_key;
6688         ut_params->aead_xform.aead.key.length = key_len;
6689         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
6690         ut_params->aead_xform.aead.iv.length = iv_len;
6691         ut_params->aead_xform.aead.digest_length = auth_len;
6692         ut_params->aead_xform.aead.aad_length = aad_len;
6693
6694         debug_hexdump(stdout, "key:", key, key_len);
6695
6696         /* Create Crypto session*/
6697         ut_params->sess = rte_cryptodev_sym_session_create(
6698                         ts_params->session_mpool);
6699
6700         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
6701                         &ut_params->aead_xform,
6702                         ts_params->session_priv_mpool);
6703
6704         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6705
6706         return 0;
6707 }
6708
6709 static int
6710 create_aead_xform(struct rte_crypto_op *op,
6711                 enum rte_crypto_aead_algorithm algo,
6712                 enum rte_crypto_aead_operation aead_op,
6713                 uint8_t *key, const uint8_t key_len,
6714                 const uint8_t aad_len, const uint8_t auth_len,
6715                 uint8_t iv_len)
6716 {
6717         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
6718                         "failed to allocate space for crypto transform");
6719
6720         struct rte_crypto_sym_op *sym_op = op->sym;
6721
6722         /* Setup AEAD Parameters */
6723         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
6724         sym_op->xform->next = NULL;
6725         sym_op->xform->aead.algo = algo;
6726         sym_op->xform->aead.op = aead_op;
6727         sym_op->xform->aead.key.data = key;
6728         sym_op->xform->aead.key.length = key_len;
6729         sym_op->xform->aead.iv.offset = IV_OFFSET;
6730         sym_op->xform->aead.iv.length = iv_len;
6731         sym_op->xform->aead.digest_length = auth_len;
6732         sym_op->xform->aead.aad_length = aad_len;
6733
6734         debug_hexdump(stdout, "key:", key, key_len);
6735
6736         return 0;
6737 }
6738
6739 static int
6740 create_aead_operation(enum rte_crypto_aead_operation op,
6741                 const struct aead_test_data *tdata)
6742 {
6743         struct crypto_testsuite_params *ts_params = &testsuite_params;
6744         struct crypto_unittest_params *ut_params = &unittest_params;
6745
6746         uint8_t *plaintext, *ciphertext;
6747         unsigned int aad_pad_len, plaintext_pad_len;
6748
6749         /* Generate Crypto op data structure */
6750         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6751                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6752         TEST_ASSERT_NOT_NULL(ut_params->op,
6753                         "Failed to allocate symmetric crypto operation struct");
6754
6755         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6756
6757         /* Append aad data */
6758         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
6759                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
6760                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6761                                 aad_pad_len);
6762                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6763                                 "no room to append aad");
6764
6765                 sym_op->aead.aad.phys_addr =
6766                                 rte_pktmbuf_iova(ut_params->ibuf);
6767                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
6768                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
6769                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6770                         tdata->aad.len);
6771
6772                 /* Append IV at the end of the crypto operation*/
6773                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6774                                 uint8_t *, IV_OFFSET);
6775
6776                 /* Copy IV 1 byte after the IV pointer, according to the API */
6777                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
6778                 debug_hexdump(stdout, "iv:", iv_ptr,
6779                         tdata->iv.len);
6780         } else {
6781                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6782                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6783                                 aad_pad_len);
6784                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
6785                                 "no room to append aad");
6786
6787                 sym_op->aead.aad.phys_addr =
6788                                 rte_pktmbuf_iova(ut_params->ibuf);
6789                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
6790                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
6791                         tdata->aad.len);
6792
6793                 /* Append IV at the end of the crypto operation*/
6794                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
6795                                 uint8_t *, IV_OFFSET);
6796
6797                 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
6798                 debug_hexdump(stdout, "iv:", iv_ptr,
6799                         tdata->iv.len);
6800         }
6801
6802         /* Append plaintext/ciphertext */
6803         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6804                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6805                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6806                                 plaintext_pad_len);
6807                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6808
6809                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
6810                 debug_hexdump(stdout, "plaintext:", plaintext,
6811                                 tdata->plaintext.len);
6812
6813                 if (ut_params->obuf) {
6814                         ciphertext = (uint8_t *)rte_pktmbuf_append(
6815                                         ut_params->obuf,
6816                                         plaintext_pad_len + aad_pad_len);
6817                         TEST_ASSERT_NOT_NULL(ciphertext,
6818                                         "no room to append ciphertext");
6819
6820                         memset(ciphertext + aad_pad_len, 0,
6821                                         tdata->ciphertext.len);
6822                 }
6823         } else {
6824                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
6825                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6826                                 plaintext_pad_len);
6827                 TEST_ASSERT_NOT_NULL(ciphertext,
6828                                 "no room to append ciphertext");
6829
6830                 memcpy(ciphertext, tdata->ciphertext.data,
6831                                 tdata->ciphertext.len);
6832                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6833                                 tdata->ciphertext.len);
6834
6835                 if (ut_params->obuf) {
6836                         plaintext = (uint8_t *)rte_pktmbuf_append(
6837                                         ut_params->obuf,
6838                                         plaintext_pad_len + aad_pad_len);
6839                         TEST_ASSERT_NOT_NULL(plaintext,
6840                                         "no room to append plaintext");
6841
6842                         memset(plaintext + aad_pad_len, 0,
6843                                         tdata->plaintext.len);
6844                 }
6845         }
6846
6847         /* Append digest data */
6848         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
6849                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6850                                 ut_params->obuf ? ut_params->obuf :
6851                                                 ut_params->ibuf,
6852                                                 tdata->auth_tag.len);
6853                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6854                                 "no room to append digest");
6855                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
6856                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6857                                 ut_params->obuf ? ut_params->obuf :
6858                                                 ut_params->ibuf,
6859                                                 plaintext_pad_len +
6860                                                 aad_pad_len);
6861         } else {
6862                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
6863                                 ut_params->ibuf, tdata->auth_tag.len);
6864                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
6865                                 "no room to append digest");
6866                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
6867                                 ut_params->ibuf,
6868                                 plaintext_pad_len + aad_pad_len);
6869
6870                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
6871                         tdata->auth_tag.len);
6872                 debug_hexdump(stdout, "digest:",
6873                         sym_op->aead.digest.data,
6874                         tdata->auth_tag.len);
6875         }
6876
6877         sym_op->aead.data.length = tdata->plaintext.len;
6878         sym_op->aead.data.offset = aad_pad_len;
6879
6880         return 0;
6881 }
6882
6883 static int
6884 test_authenticated_encryption(const struct aead_test_data *tdata)
6885 {
6886         struct crypto_testsuite_params *ts_params = &testsuite_params;
6887         struct crypto_unittest_params *ut_params = &unittest_params;
6888
6889         int retval;
6890         uint8_t *ciphertext, *auth_tag;
6891         uint16_t plaintext_pad_len;
6892         uint32_t i;
6893
6894         /* Verify the capabilities */
6895         struct rte_cryptodev_sym_capability_idx cap_idx;
6896         const struct rte_cryptodev_symmetric_capability *capability;
6897         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
6898         cap_idx.algo.aead = tdata->algo;
6899         capability = rte_cryptodev_sym_capability_get(
6900                         ts_params->valid_devs[0], &cap_idx);
6901         if (capability == NULL)
6902                 return -ENOTSUP;
6903         if (rte_cryptodev_sym_capability_check_aead(
6904                         capability, tdata->key.len, tdata->auth_tag.len,
6905                         tdata->aad.len, tdata->iv.len))
6906                 return -ENOTSUP;
6907
6908         /* Create AEAD session */
6909         retval = create_aead_session(ts_params->valid_devs[0],
6910                         tdata->algo,
6911                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
6912                         tdata->key.data, tdata->key.len,
6913                         tdata->aad.len, tdata->auth_tag.len,
6914                         tdata->iv.len);
6915         if (retval < 0)
6916                 return retval;
6917
6918         if (tdata->aad.len > MBUF_SIZE) {
6919                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6920                 /* Populate full size of add data */
6921                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
6922                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
6923         } else
6924                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6925
6926         /* clear mbuf payload */
6927         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6928                         rte_pktmbuf_tailroom(ut_params->ibuf));
6929
6930         /* Create AEAD operation */
6931         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
6932         if (retval < 0)
6933                 return retval;
6934
6935         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6936
6937         ut_params->op->sym->m_src = ut_params->ibuf;
6938
6939         /* Process crypto operation */
6940         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6941                         ut_params->op), "failed to process sym crypto op");
6942
6943         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6944                         "crypto op processing failed");
6945
6946         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
6947
6948         if (ut_params->op->sym->m_dst) {
6949                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
6950                                 uint8_t *);
6951                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6952                                 uint8_t *, plaintext_pad_len);
6953         } else {
6954                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
6955                                 uint8_t *,
6956                                 ut_params->op->sym->cipher.data.offset);
6957                 auth_tag = ciphertext + plaintext_pad_len;
6958         }
6959
6960         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
6961         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
6962
6963         /* Validate obuf */
6964         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6965                         ciphertext,
6966                         tdata->ciphertext.data,
6967                         tdata->ciphertext.len,
6968                         "Ciphertext data not as expected");
6969
6970         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6971                         auth_tag,
6972                         tdata->auth_tag.data,
6973                         tdata->auth_tag.len,
6974                         "Generated auth tag not as expected");
6975
6976         return 0;
6977
6978 }
6979
6980 #ifdef RTE_LIBRTE_SECURITY
6981 /* Basic algorithm run function for async inplace mode.
6982  * Creates a session from input parameters and runs one operation
6983  * on input_vec. Checks the output of the crypto operation against
6984  * output_vec.
6985  */
6986 static int
6987 test_pdcp_proto(int i, int oop,
6988         enum rte_crypto_cipher_operation opc,
6989         enum rte_crypto_auth_operation opa,
6990         uint8_t *input_vec,
6991         unsigned int input_vec_len,
6992         uint8_t *output_vec,
6993         unsigned int output_vec_len)
6994 {
6995         struct crypto_testsuite_params *ts_params = &testsuite_params;
6996         struct crypto_unittest_params *ut_params = &unittest_params;
6997         uint8_t *plaintext;
6998         int ret = TEST_SUCCESS;
6999         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7000                                 rte_cryptodev_get_sec_ctx(
7001                                 ts_params->valid_devs[0]);
7002
7003         /* Verify the capabilities */
7004         struct rte_security_capability_idx sec_cap_idx;
7005
7006         sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7007         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7008         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7009         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7010                 return -ENOTSUP;
7011
7012         /* Generate test mbuf data */
7013         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7014
7015         /* clear mbuf payload */
7016         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7017                         rte_pktmbuf_tailroom(ut_params->ibuf));
7018
7019         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7020                                                   input_vec_len);
7021         memcpy(plaintext, input_vec, input_vec_len);
7022
7023         /* Out of place support */
7024         if (oop) {
7025                 /*
7026                  * For out-op-place we need to alloc another mbuf
7027                  */
7028                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7029                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7030         }
7031
7032         /* Set crypto type as IPSEC */
7033         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7034
7035         /* Setup Cipher Parameters */
7036         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7037         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7038         ut_params->cipher_xform.cipher.op = opc;
7039         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7040         ut_params->cipher_xform.cipher.key.length =
7041                                         pdcp_test_params[i].cipher_key_len;
7042         ut_params->cipher_xform.cipher.iv.length = 0;
7043
7044         /* Setup HMAC Parameters if ICV header is required */
7045         if (pdcp_test_params[i].auth_alg != 0) {
7046                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7047                 ut_params->auth_xform.next = NULL;
7048                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7049                 ut_params->auth_xform.auth.op = opa;
7050                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7051                 ut_params->auth_xform.auth.key.length =
7052                                         pdcp_test_params[i].auth_key_len;
7053
7054                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7055         } else {
7056                 ut_params->cipher_xform.next = NULL;
7057         }
7058
7059         struct rte_security_session_conf sess_conf = {
7060                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
7061                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7062                 {.pdcp = {
7063                         .bearer = pdcp_test_bearer[i],
7064                         .domain = pdcp_test_params[i].domain,
7065                         .pkt_dir = pdcp_test_packet_direction[i],
7066                         .sn_size = pdcp_test_data_sn_size[i],
7067                         .hfn = pdcp_test_hfn[i],
7068                         .hfn_threshold = pdcp_test_hfn_threshold[i],
7069                 } },
7070                 .crypto_xform = &ut_params->cipher_xform
7071         };
7072
7073         /* Create security session */
7074         ut_params->sec_session = rte_security_session_create(ctx,
7075                                 &sess_conf, ts_params->session_priv_mpool);
7076
7077         if (!ut_params->sec_session) {
7078                 printf("TestCase %s()-%d line %d failed %s: ",
7079                         __func__, i, __LINE__, "Failed to allocate session");
7080                 ret = TEST_FAILED;
7081                 goto on_err;
7082         }
7083
7084         /* Generate crypto op data structure */
7085         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7086                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7087         if (!ut_params->op) {
7088                 printf("TestCase %s()-%d line %d failed %s: ",
7089                         __func__, i, __LINE__,
7090                         "Failed to allocate symmetric crypto operation struct");
7091                 ret = TEST_FAILED;
7092                 goto on_err;
7093         }
7094
7095         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7096
7097         /* set crypto operation source mbuf */
7098         ut_params->op->sym->m_src = ut_params->ibuf;
7099         if (oop)
7100                 ut_params->op->sym->m_dst = ut_params->obuf;
7101
7102         /* Process crypto operation */
7103         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7104                 == NULL) {
7105                 printf("TestCase %s()-%d line %d failed %s: ",
7106                         __func__, i, __LINE__,
7107                         "failed to process sym crypto op");
7108                 ret = TEST_FAILED;
7109                 goto on_err;
7110         }
7111
7112         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7113                 printf("TestCase %s()-%d line %d failed %s: ",
7114                         __func__, i, __LINE__, "crypto op processing failed");
7115                 ret = TEST_FAILED;
7116                 goto on_err;
7117         }
7118
7119         /* Validate obuf */
7120         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7121                         uint8_t *);
7122         if (oop) {
7123                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7124                                 uint8_t *);
7125         }
7126
7127         if (memcmp(ciphertext, output_vec, output_vec_len)) {
7128                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7129                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7130                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7131                 ret = TEST_FAILED;
7132                 goto on_err;
7133         }
7134
7135 on_err:
7136         rte_crypto_op_free(ut_params->op);
7137         ut_params->op = NULL;
7138
7139         if (ut_params->sec_session)
7140                 rte_security_session_destroy(ctx, ut_params->sec_session);
7141         ut_params->sec_session = NULL;
7142
7143         rte_pktmbuf_free(ut_params->ibuf);
7144         ut_params->ibuf = NULL;
7145         if (oop) {
7146                 rte_pktmbuf_free(ut_params->obuf);
7147                 ut_params->obuf = NULL;
7148         }
7149
7150         return ret;
7151 }
7152
7153 static int
7154 test_pdcp_proto_SGL(int i, int oop,
7155         enum rte_crypto_cipher_operation opc,
7156         enum rte_crypto_auth_operation opa,
7157         uint8_t *input_vec,
7158         unsigned int input_vec_len,
7159         uint8_t *output_vec,
7160         unsigned int output_vec_len,
7161         uint32_t fragsz,
7162         uint32_t fragsz_oop)
7163 {
7164         struct crypto_testsuite_params *ts_params = &testsuite_params;
7165         struct crypto_unittest_params *ut_params = &unittest_params;
7166         uint8_t *plaintext;
7167         struct rte_mbuf *buf, *buf_oop = NULL;
7168         int ret = TEST_SUCCESS;
7169         int to_trn = 0;
7170         int to_trn_tbl[16];
7171         int segs = 1;
7172         unsigned int trn_data = 0;
7173         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7174                                 rte_cryptodev_get_sec_ctx(
7175                                 ts_params->valid_devs[0]);
7176
7177         /* Verify the capabilities */
7178         struct rte_security_capability_idx sec_cap_idx;
7179
7180         sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7181         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7182         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7183         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7184                 return -ENOTSUP;
7185
7186         if (fragsz > input_vec_len)
7187                 fragsz = input_vec_len;
7188
7189         uint16_t plaintext_len = fragsz;
7190         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7191
7192         if (fragsz_oop > output_vec_len)
7193                 frag_size_oop = output_vec_len;
7194
7195         int ecx = 0;
7196         if (input_vec_len % fragsz != 0) {
7197                 if (input_vec_len / fragsz + 1 > 16)
7198                         return 1;
7199         } else if (input_vec_len / fragsz > 16)
7200                 return 1;
7201
7202         /* Out of place support */
7203         if (oop) {
7204                 /*
7205                  * For out-op-place we need to alloc another mbuf
7206                  */
7207                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7208                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
7209                 buf_oop = ut_params->obuf;
7210         }
7211
7212         /* Generate test mbuf data */
7213         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7214
7215         /* clear mbuf payload */
7216         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7217                         rte_pktmbuf_tailroom(ut_params->ibuf));
7218
7219         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7220                                                   plaintext_len);
7221         memcpy(plaintext, input_vec, plaintext_len);
7222         trn_data += plaintext_len;
7223
7224         buf = ut_params->ibuf;
7225
7226         /*
7227          * Loop until no more fragments
7228          */
7229
7230         while (trn_data < input_vec_len) {
7231                 ++segs;
7232                 to_trn = (input_vec_len - trn_data < fragsz) ?
7233                                 (input_vec_len - trn_data) : fragsz;
7234
7235                 to_trn_tbl[ecx++] = to_trn;
7236
7237                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7238                 buf = buf->next;
7239
7240                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7241                                 rte_pktmbuf_tailroom(buf));
7242
7243                 /* OOP */
7244                 if (oop && !fragsz_oop) {
7245                         buf_oop->next =
7246                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7247                         buf_oop = buf_oop->next;
7248                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7249                                         0, rte_pktmbuf_tailroom(buf_oop));
7250                         rte_pktmbuf_append(buf_oop, to_trn);
7251                 }
7252
7253                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7254                                 to_trn);
7255
7256                 memcpy(plaintext, input_vec + trn_data, to_trn);
7257                 trn_data += to_trn;
7258         }
7259
7260         ut_params->ibuf->nb_segs = segs;
7261
7262         segs = 1;
7263         if (fragsz_oop && oop) {
7264                 to_trn = 0;
7265                 ecx = 0;
7266
7267                 trn_data = frag_size_oop;
7268                 while (trn_data < output_vec_len) {
7269                         ++segs;
7270                         to_trn =
7271                                 (output_vec_len - trn_data <
7272                                                 frag_size_oop) ?
7273                                 (output_vec_len - trn_data) :
7274                                                 frag_size_oop;
7275
7276                         to_trn_tbl[ecx++] = to_trn;
7277
7278                         buf_oop->next =
7279                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
7280                         buf_oop = buf_oop->next;
7281                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7282                                         0, rte_pktmbuf_tailroom(buf_oop));
7283                         rte_pktmbuf_append(buf_oop, to_trn);
7284
7285                         trn_data += to_trn;
7286                 }
7287                 ut_params->obuf->nb_segs = segs;
7288         }
7289
7290         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
7291
7292         /* Setup Cipher Parameters */
7293         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7294         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7295         ut_params->cipher_xform.cipher.op = opc;
7296         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7297         ut_params->cipher_xform.cipher.key.length =
7298                                         pdcp_test_params[i].cipher_key_len;
7299         ut_params->cipher_xform.cipher.iv.length = 0;
7300
7301         /* Setup HMAC Parameters if ICV header is required */
7302         if (pdcp_test_params[i].auth_alg != 0) {
7303                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7304                 ut_params->auth_xform.next = NULL;
7305                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7306                 ut_params->auth_xform.auth.op = opa;
7307                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7308                 ut_params->auth_xform.auth.key.length =
7309                                         pdcp_test_params[i].auth_key_len;
7310
7311                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7312         } else {
7313                 ut_params->cipher_xform.next = NULL;
7314         }
7315
7316         struct rte_security_session_conf sess_conf = {
7317                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
7318                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7319                 {.pdcp = {
7320                         .bearer = pdcp_test_bearer[i],
7321                         .domain = pdcp_test_params[i].domain,
7322                         .pkt_dir = pdcp_test_packet_direction[i],
7323                         .sn_size = pdcp_test_data_sn_size[i],
7324                         .hfn = pdcp_test_hfn[i],
7325                         .hfn_threshold = pdcp_test_hfn_threshold[i],
7326                 } },
7327                 .crypto_xform = &ut_params->cipher_xform
7328         };
7329
7330         /* Create security session */
7331         ut_params->sec_session = rte_security_session_create(ctx,
7332                                 &sess_conf, ts_params->session_priv_mpool);
7333
7334         if (!ut_params->sec_session) {
7335                 printf("TestCase %s()-%d line %d failed %s: ",
7336                         __func__, i, __LINE__, "Failed to allocate session");
7337                 ret = TEST_FAILED;
7338                 goto on_err;
7339         }
7340
7341         /* Generate crypto op data structure */
7342         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7343                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7344         if (!ut_params->op) {
7345                 printf("TestCase %s()-%d line %d failed %s: ",
7346                         __func__, i, __LINE__,
7347                         "Failed to allocate symmetric crypto operation struct");
7348                 ret = TEST_FAILED;
7349                 goto on_err;
7350         }
7351
7352         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7353
7354         /* set crypto operation source mbuf */
7355         ut_params->op->sym->m_src = ut_params->ibuf;
7356         if (oop)
7357                 ut_params->op->sym->m_dst = ut_params->obuf;
7358
7359         /* Process crypto operation */
7360         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7361                 == NULL) {
7362                 printf("TestCase %s()-%d line %d failed %s: ",
7363                         __func__, i, __LINE__,
7364                         "failed to process sym crypto op");
7365                 ret = TEST_FAILED;
7366                 goto on_err;
7367         }
7368
7369         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7370                 printf("TestCase %s()-%d line %d failed %s: ",
7371                         __func__, i, __LINE__, "crypto op processing failed");
7372                 ret = TEST_FAILED;
7373                 goto on_err;
7374         }
7375
7376         /* Validate obuf */
7377         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7378                         uint8_t *);
7379         if (oop) {
7380                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7381                                 uint8_t *);
7382         }
7383         if (fragsz_oop)
7384                 fragsz = frag_size_oop;
7385         if (memcmp(ciphertext, output_vec, fragsz)) {
7386                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7387                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
7388                 rte_hexdump(stdout, "reference", output_vec, fragsz);
7389                 ret = TEST_FAILED;
7390                 goto on_err;
7391         }
7392
7393         buf = ut_params->op->sym->m_src->next;
7394         if (oop)
7395                 buf = ut_params->op->sym->m_dst->next;
7396
7397         unsigned int off = fragsz;
7398
7399         ecx = 0;
7400         while (buf) {
7401                 ciphertext = rte_pktmbuf_mtod(buf,
7402                                 uint8_t *);
7403                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
7404                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7405                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
7406                         rte_hexdump(stdout, "reference", output_vec + off,
7407                                         to_trn_tbl[ecx]);
7408                         ret = TEST_FAILED;
7409                         goto on_err;
7410                 }
7411                 off += to_trn_tbl[ecx++];
7412                 buf = buf->next;
7413         }
7414 on_err:
7415         rte_crypto_op_free(ut_params->op);
7416         ut_params->op = NULL;
7417
7418         if (ut_params->sec_session)
7419                 rte_security_session_destroy(ctx, ut_params->sec_session);
7420         ut_params->sec_session = NULL;
7421
7422         rte_pktmbuf_free(ut_params->ibuf);
7423         ut_params->ibuf = NULL;
7424         if (oop) {
7425                 rte_pktmbuf_free(ut_params->obuf);
7426                 ut_params->obuf = NULL;
7427         }
7428
7429         return ret;
7430 }
7431
7432 int
7433 test_pdcp_proto_cplane_encap(int i)
7434 {
7435         return test_pdcp_proto(i, 0,
7436                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7437                 RTE_CRYPTO_AUTH_OP_GENERATE,
7438                 pdcp_test_data_in[i],
7439                 pdcp_test_data_in_len[i],
7440                 pdcp_test_data_out[i],
7441                 pdcp_test_data_in_len[i]+4);
7442 }
7443
7444 int
7445 test_pdcp_proto_uplane_encap(int i)
7446 {
7447         return test_pdcp_proto(i, 0,
7448                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7449                 RTE_CRYPTO_AUTH_OP_GENERATE,
7450                 pdcp_test_data_in[i],
7451                 pdcp_test_data_in_len[i],
7452                 pdcp_test_data_out[i],
7453                 pdcp_test_data_in_len[i]);
7454
7455 }
7456
7457 int
7458 test_pdcp_proto_uplane_encap_with_int(int i)
7459 {
7460         return test_pdcp_proto(i, 0,
7461                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7462                 RTE_CRYPTO_AUTH_OP_GENERATE,
7463                 pdcp_test_data_in[i],
7464                 pdcp_test_data_in_len[i],
7465                 pdcp_test_data_out[i],
7466                 pdcp_test_data_in_len[i] + 4);
7467 }
7468
7469 int
7470 test_pdcp_proto_cplane_decap(int i)
7471 {
7472         return test_pdcp_proto(i, 0,
7473                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7474                 RTE_CRYPTO_AUTH_OP_VERIFY,
7475                 pdcp_test_data_out[i],
7476                 pdcp_test_data_in_len[i] + 4,
7477                 pdcp_test_data_in[i],
7478                 pdcp_test_data_in_len[i]);
7479 }
7480
7481 int
7482 test_pdcp_proto_uplane_decap(int i)
7483 {
7484         return test_pdcp_proto(i, 0,
7485                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7486                 RTE_CRYPTO_AUTH_OP_VERIFY,
7487                 pdcp_test_data_out[i],
7488                 pdcp_test_data_in_len[i],
7489                 pdcp_test_data_in[i],
7490                 pdcp_test_data_in_len[i]);
7491 }
7492
7493 int
7494 test_pdcp_proto_uplane_decap_with_int(int i)
7495 {
7496         return test_pdcp_proto(i, 0,
7497                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7498                 RTE_CRYPTO_AUTH_OP_VERIFY,
7499                 pdcp_test_data_out[i],
7500                 pdcp_test_data_in_len[i] + 4,
7501                 pdcp_test_data_in[i],
7502                 pdcp_test_data_in_len[i]);
7503 }
7504
7505 static int
7506 test_PDCP_PROTO_SGL_in_place_32B(void)
7507 {
7508         /* i can be used for running any PDCP case
7509          * In this case it is uplane 12-bit AES-SNOW DL encap
7510          */
7511         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
7512         return test_pdcp_proto_SGL(i, IN_PLACE,
7513                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7514                         RTE_CRYPTO_AUTH_OP_GENERATE,
7515                         pdcp_test_data_in[i],
7516                         pdcp_test_data_in_len[i],
7517                         pdcp_test_data_out[i],
7518                         pdcp_test_data_in_len[i]+4,
7519                         32, 0);
7520 }
7521 static int
7522 test_PDCP_PROTO_SGL_oop_32B_128B(void)
7523 {
7524         /* i can be used for running any PDCP case
7525          * In this case it is uplane 18-bit NULL-NULL DL encap
7526          */
7527         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
7528         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7529                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7530                         RTE_CRYPTO_AUTH_OP_GENERATE,
7531                         pdcp_test_data_in[i],
7532                         pdcp_test_data_in_len[i],
7533                         pdcp_test_data_out[i],
7534                         pdcp_test_data_in_len[i]+4,
7535                         32, 128);
7536 }
7537 static int
7538 test_PDCP_PROTO_SGL_oop_32B_40B(void)
7539 {
7540         /* i can be used for running any PDCP case
7541          * In this case it is uplane 18-bit AES DL encap
7542          */
7543         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
7544                         + DOWNLINK;
7545         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7546                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7547                         RTE_CRYPTO_AUTH_OP_GENERATE,
7548                         pdcp_test_data_in[i],
7549                         pdcp_test_data_in_len[i],
7550                         pdcp_test_data_out[i],
7551                         pdcp_test_data_in_len[i],
7552                         32, 40);
7553 }
7554 static int
7555 test_PDCP_PROTO_SGL_oop_128B_32B(void)
7556 {
7557         /* i can be used for running any PDCP case
7558          * In this case it is cplane 12-bit AES-ZUC DL encap
7559          */
7560         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
7561         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
7562                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7563                         RTE_CRYPTO_AUTH_OP_GENERATE,
7564                         pdcp_test_data_in[i],
7565                         pdcp_test_data_in_len[i],
7566                         pdcp_test_data_out[i],
7567                         pdcp_test_data_in_len[i]+4,
7568                         128, 32);
7569 }
7570 #endif
7571
7572 static int
7573 test_AES_GCM_authenticated_encryption_test_case_1(void)
7574 {
7575         return test_authenticated_encryption(&gcm_test_case_1);
7576 }
7577
7578 static int
7579 test_AES_GCM_authenticated_encryption_test_case_2(void)
7580 {
7581         return test_authenticated_encryption(&gcm_test_case_2);
7582 }
7583
7584 static int
7585 test_AES_GCM_authenticated_encryption_test_case_3(void)
7586 {
7587         return test_authenticated_encryption(&gcm_test_case_3);
7588 }
7589
7590 static int
7591 test_AES_GCM_authenticated_encryption_test_case_4(void)
7592 {
7593         return test_authenticated_encryption(&gcm_test_case_4);
7594 }
7595
7596 static int
7597 test_AES_GCM_authenticated_encryption_test_case_5(void)
7598 {
7599         return test_authenticated_encryption(&gcm_test_case_5);
7600 }
7601
7602 static int
7603 test_AES_GCM_authenticated_encryption_test_case_6(void)
7604 {
7605         return test_authenticated_encryption(&gcm_test_case_6);
7606 }
7607
7608 static int
7609 test_AES_GCM_authenticated_encryption_test_case_7(void)
7610 {
7611         return test_authenticated_encryption(&gcm_test_case_7);
7612 }
7613
7614 static int
7615 test_AES_GCM_authenticated_encryption_test_case_8(void)
7616 {
7617         return test_authenticated_encryption(&gcm_test_case_8);
7618 }
7619
7620 static int
7621 test_AES_GCM_auth_encryption_test_case_192_1(void)
7622 {
7623         return test_authenticated_encryption(&gcm_test_case_192_1);
7624 }
7625
7626 static int
7627 test_AES_GCM_auth_encryption_test_case_192_2(void)
7628 {
7629         return test_authenticated_encryption(&gcm_test_case_192_2);
7630 }
7631
7632 static int
7633 test_AES_GCM_auth_encryption_test_case_192_3(void)
7634 {
7635         return test_authenticated_encryption(&gcm_test_case_192_3);
7636 }
7637
7638 static int
7639 test_AES_GCM_auth_encryption_test_case_192_4(void)
7640 {
7641         return test_authenticated_encryption(&gcm_test_case_192_4);
7642 }
7643
7644 static int
7645 test_AES_GCM_auth_encryption_test_case_192_5(void)
7646 {
7647         return test_authenticated_encryption(&gcm_test_case_192_5);
7648 }
7649
7650 static int
7651 test_AES_GCM_auth_encryption_test_case_192_6(void)
7652 {
7653         return test_authenticated_encryption(&gcm_test_case_192_6);
7654 }
7655
7656 static int
7657 test_AES_GCM_auth_encryption_test_case_192_7(void)
7658 {
7659         return test_authenticated_encryption(&gcm_test_case_192_7);
7660 }
7661
7662 static int
7663 test_AES_GCM_auth_encryption_test_case_256_1(void)
7664 {
7665         return test_authenticated_encryption(&gcm_test_case_256_1);
7666 }
7667
7668 static int
7669 test_AES_GCM_auth_encryption_test_case_256_2(void)
7670 {
7671         return test_authenticated_encryption(&gcm_test_case_256_2);
7672 }
7673
7674 static int
7675 test_AES_GCM_auth_encryption_test_case_256_3(void)
7676 {
7677         return test_authenticated_encryption(&gcm_test_case_256_3);
7678 }
7679
7680 static int
7681 test_AES_GCM_auth_encryption_test_case_256_4(void)
7682 {
7683         return test_authenticated_encryption(&gcm_test_case_256_4);
7684 }
7685
7686 static int
7687 test_AES_GCM_auth_encryption_test_case_256_5(void)
7688 {
7689         return test_authenticated_encryption(&gcm_test_case_256_5);
7690 }
7691
7692 static int
7693 test_AES_GCM_auth_encryption_test_case_256_6(void)
7694 {
7695         return test_authenticated_encryption(&gcm_test_case_256_6);
7696 }
7697
7698 static int
7699 test_AES_GCM_auth_encryption_test_case_256_7(void)
7700 {
7701         return test_authenticated_encryption(&gcm_test_case_256_7);
7702 }
7703
7704 static int
7705 test_AES_GCM_auth_encryption_test_case_aad_1(void)
7706 {
7707         return test_authenticated_encryption(&gcm_test_case_aad_1);
7708 }
7709
7710 static int
7711 test_AES_GCM_auth_encryption_test_case_aad_2(void)
7712 {
7713         return test_authenticated_encryption(&gcm_test_case_aad_2);
7714 }
7715
7716 static int
7717 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
7718 {
7719         struct aead_test_data tdata;
7720         int res;
7721
7722         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7723         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7724         tdata.iv.data[0] += 1;
7725         res = test_authenticated_encryption(&tdata);
7726         if (res == -ENOTSUP)
7727                 return res;
7728         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7729         return TEST_SUCCESS;
7730 }
7731
7732 static int
7733 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
7734 {
7735         struct aead_test_data tdata;
7736         int res;
7737
7738         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7739         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7740         tdata.plaintext.data[0] += 1;
7741         res = test_authenticated_encryption(&tdata);
7742         if (res == -ENOTSUP)
7743                 return res;
7744         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7745         return TEST_SUCCESS;
7746 }
7747
7748 static int
7749 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
7750 {
7751         struct aead_test_data tdata;
7752         int res;
7753
7754         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7755         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7756         tdata.ciphertext.data[0] += 1;
7757         res = test_authenticated_encryption(&tdata);
7758         if (res == -ENOTSUP)
7759                 return res;
7760         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7761         return TEST_SUCCESS;
7762 }
7763
7764 static int
7765 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
7766 {
7767         struct aead_test_data tdata;
7768         int res;
7769
7770         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7771         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7772         tdata.aad.len += 1;
7773         res = test_authenticated_encryption(&tdata);
7774         if (res == -ENOTSUP)
7775                 return res;
7776         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7777         return TEST_SUCCESS;
7778 }
7779
7780 static int
7781 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
7782 {
7783         struct aead_test_data tdata;
7784         uint8_t aad[gcm_test_case_7.aad.len];
7785         int res;
7786
7787         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7788         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7789         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
7790         aad[0] += 1;
7791         tdata.aad.data = aad;
7792         res = test_authenticated_encryption(&tdata);
7793         if (res == -ENOTSUP)
7794                 return res;
7795         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7796         return TEST_SUCCESS;
7797 }
7798
7799 static int
7800 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
7801 {
7802         struct aead_test_data tdata;
7803         int res;
7804
7805         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7806         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7807         tdata.auth_tag.data[0] += 1;
7808         res = test_authenticated_encryption(&tdata);
7809         if (res == -ENOTSUP)
7810                 return res;
7811         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7812         return TEST_SUCCESS;
7813 }
7814
7815 static int
7816 test_authenticated_decryption(const struct aead_test_data *tdata)
7817 {
7818         struct crypto_testsuite_params *ts_params = &testsuite_params;
7819         struct crypto_unittest_params *ut_params = &unittest_params;
7820
7821         int retval;
7822         uint8_t *plaintext;
7823         uint32_t i;
7824
7825         /* Verify the capabilities */
7826         struct rte_cryptodev_sym_capability_idx cap_idx;
7827         const struct rte_cryptodev_symmetric_capability *capability;
7828         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7829         cap_idx.algo.aead = tdata->algo;
7830         capability = rte_cryptodev_sym_capability_get(
7831                         ts_params->valid_devs[0], &cap_idx);
7832         if (capability == NULL)
7833                 return -ENOTSUP;
7834         if (rte_cryptodev_sym_capability_check_aead(
7835                         capability, tdata->key.len, tdata->auth_tag.len,
7836                         tdata->aad.len, tdata->iv.len))
7837                 return -ENOTSUP;
7838
7839         /* Create AEAD session */
7840         retval = create_aead_session(ts_params->valid_devs[0],
7841                         tdata->algo,
7842                         RTE_CRYPTO_AEAD_OP_DECRYPT,
7843                         tdata->key.data, tdata->key.len,
7844                         tdata->aad.len, tdata->auth_tag.len,
7845                         tdata->iv.len);
7846         if (retval < 0)
7847                 return retval;
7848
7849         /* alloc mbuf and set payload */
7850         if (tdata->aad.len > MBUF_SIZE) {
7851                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7852                 /* Populate full size of add data */
7853                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7854                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7855         } else
7856                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7857
7858         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7859                         rte_pktmbuf_tailroom(ut_params->ibuf));
7860
7861         /* Create AEAD operation */
7862         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
7863         if (retval < 0)
7864                 return retval;
7865
7866         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7867
7868         ut_params->op->sym->m_src = ut_params->ibuf;
7869
7870         /* Process crypto operation */
7871         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7872                         ut_params->op), "failed to process sym crypto op");
7873
7874         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7875                         "crypto op processing failed");
7876
7877         if (ut_params->op->sym->m_dst)
7878                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7879                                 uint8_t *);
7880         else
7881                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7882                                 uint8_t *,
7883                                 ut_params->op->sym->cipher.data.offset);
7884
7885         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
7886
7887         /* Validate obuf */
7888         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7889                         plaintext,
7890                         tdata->plaintext.data,
7891                         tdata->plaintext.len,
7892                         "Plaintext data not as expected");
7893
7894         TEST_ASSERT_EQUAL(ut_params->op->status,
7895                         RTE_CRYPTO_OP_STATUS_SUCCESS,
7896                         "Authentication failed");
7897
7898         return 0;
7899 }
7900
7901 static int
7902 test_AES_GCM_authenticated_decryption_test_case_1(void)
7903 {
7904         return test_authenticated_decryption(&gcm_test_case_1);
7905 }
7906
7907 static int
7908 test_AES_GCM_authenticated_decryption_test_case_2(void)
7909 {
7910         return test_authenticated_decryption(&gcm_test_case_2);
7911 }
7912
7913 static int
7914 test_AES_GCM_authenticated_decryption_test_case_3(void)
7915 {
7916         return test_authenticated_decryption(&gcm_test_case_3);
7917 }
7918
7919 static int
7920 test_AES_GCM_authenticated_decryption_test_case_4(void)
7921 {
7922         return test_authenticated_decryption(&gcm_test_case_4);
7923 }
7924
7925 static int
7926 test_AES_GCM_authenticated_decryption_test_case_5(void)
7927 {
7928         return test_authenticated_decryption(&gcm_test_case_5);
7929 }
7930
7931 static int
7932 test_AES_GCM_authenticated_decryption_test_case_6(void)
7933 {
7934         return test_authenticated_decryption(&gcm_test_case_6);
7935 }
7936
7937 static int
7938 test_AES_GCM_authenticated_decryption_test_case_7(void)
7939 {
7940         return test_authenticated_decryption(&gcm_test_case_7);
7941 }
7942
7943 static int
7944 test_AES_GCM_authenticated_decryption_test_case_8(void)
7945 {
7946         return test_authenticated_decryption(&gcm_test_case_8);
7947 }
7948
7949 static int
7950 test_AES_GCM_auth_decryption_test_case_192_1(void)
7951 {
7952         return test_authenticated_decryption(&gcm_test_case_192_1);
7953 }
7954
7955 static int
7956 test_AES_GCM_auth_decryption_test_case_192_2(void)
7957 {
7958         return test_authenticated_decryption(&gcm_test_case_192_2);
7959 }
7960
7961 static int
7962 test_AES_GCM_auth_decryption_test_case_192_3(void)
7963 {
7964         return test_authenticated_decryption(&gcm_test_case_192_3);
7965 }
7966
7967 static int
7968 test_AES_GCM_auth_decryption_test_case_192_4(void)
7969 {
7970         return test_authenticated_decryption(&gcm_test_case_192_4);
7971 }
7972
7973 static int
7974 test_AES_GCM_auth_decryption_test_case_192_5(void)
7975 {
7976         return test_authenticated_decryption(&gcm_test_case_192_5);
7977 }
7978
7979 static int
7980 test_AES_GCM_auth_decryption_test_case_192_6(void)
7981 {
7982         return test_authenticated_decryption(&gcm_test_case_192_6);
7983 }
7984
7985 static int
7986 test_AES_GCM_auth_decryption_test_case_192_7(void)
7987 {
7988         return test_authenticated_decryption(&gcm_test_case_192_7);
7989 }
7990
7991 static int
7992 test_AES_GCM_auth_decryption_test_case_256_1(void)
7993 {
7994         return test_authenticated_decryption(&gcm_test_case_256_1);
7995 }
7996
7997 static int
7998 test_AES_GCM_auth_decryption_test_case_256_2(void)
7999 {
8000         return test_authenticated_decryption(&gcm_test_case_256_2);
8001 }
8002
8003 static int
8004 test_AES_GCM_auth_decryption_test_case_256_3(void)
8005 {
8006         return test_authenticated_decryption(&gcm_test_case_256_3);
8007 }
8008
8009 static int
8010 test_AES_GCM_auth_decryption_test_case_256_4(void)
8011 {
8012         return test_authenticated_decryption(&gcm_test_case_256_4);
8013 }
8014
8015 static int
8016 test_AES_GCM_auth_decryption_test_case_256_5(void)
8017 {
8018         return test_authenticated_decryption(&gcm_test_case_256_5);
8019 }
8020
8021 static int
8022 test_AES_GCM_auth_decryption_test_case_256_6(void)
8023 {
8024         return test_authenticated_decryption(&gcm_test_case_256_6);
8025 }
8026
8027 static int
8028 test_AES_GCM_auth_decryption_test_case_256_7(void)
8029 {
8030         return test_authenticated_decryption(&gcm_test_case_256_7);
8031 }
8032
8033 static int
8034 test_AES_GCM_auth_decryption_test_case_aad_1(void)
8035 {
8036         return test_authenticated_decryption(&gcm_test_case_aad_1);
8037 }
8038
8039 static int
8040 test_AES_GCM_auth_decryption_test_case_aad_2(void)
8041 {
8042         return test_authenticated_decryption(&gcm_test_case_aad_2);
8043 }
8044
8045 static int
8046 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
8047 {
8048         struct aead_test_data tdata;
8049         int res;
8050
8051         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8052         tdata.iv.data[0] += 1;
8053         res = test_authenticated_decryption(&tdata);
8054         if (res == -ENOTSUP)
8055                 return res;
8056         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8057         return TEST_SUCCESS;
8058 }
8059
8060 static int
8061 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
8062 {
8063         struct aead_test_data tdata;
8064         int res;
8065
8066         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8067         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8068         tdata.plaintext.data[0] += 1;
8069         res = test_authenticated_decryption(&tdata);
8070         if (res == -ENOTSUP)
8071                 return res;
8072         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8073         return TEST_SUCCESS;
8074 }
8075
8076 static int
8077 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
8078 {
8079         struct aead_test_data tdata;
8080         int res;
8081
8082         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8083         tdata.ciphertext.data[0] += 1;
8084         res = test_authenticated_decryption(&tdata);
8085         if (res == -ENOTSUP)
8086                 return res;
8087         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8088         return TEST_SUCCESS;
8089 }
8090
8091 static int
8092 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
8093 {
8094         struct aead_test_data tdata;
8095         int res;
8096
8097         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8098         tdata.aad.len += 1;
8099         res = test_authenticated_decryption(&tdata);
8100         if (res == -ENOTSUP)
8101                 return res;
8102         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8103         return TEST_SUCCESS;
8104 }
8105
8106 static int
8107 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
8108 {
8109         struct aead_test_data tdata;
8110         uint8_t aad[gcm_test_case_7.aad.len];
8111         int res;
8112
8113         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8114         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
8115         aad[0] += 1;
8116         tdata.aad.data = aad;
8117         res = test_authenticated_decryption(&tdata);
8118         if (res == -ENOTSUP)
8119                 return res;
8120         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8121         return TEST_SUCCESS;
8122 }
8123
8124 static int
8125 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
8126 {
8127         struct aead_test_data tdata;
8128         int res;
8129
8130         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8131         tdata.auth_tag.data[0] += 1;
8132         res = test_authenticated_decryption(&tdata);
8133         if (res == -ENOTSUP)
8134                 return res;
8135         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
8136         return TEST_SUCCESS;
8137 }
8138
8139 static int
8140 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
8141 {
8142         struct crypto_testsuite_params *ts_params = &testsuite_params;
8143         struct crypto_unittest_params *ut_params = &unittest_params;
8144
8145         int retval;
8146         uint8_t *ciphertext, *auth_tag;
8147         uint16_t plaintext_pad_len;
8148
8149         /* Verify the capabilities */
8150         struct rte_cryptodev_sym_capability_idx cap_idx;
8151         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8152         cap_idx.algo.aead = tdata->algo;
8153         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8154                         &cap_idx) == NULL)
8155                 return -ENOTSUP;
8156
8157         /* Create AEAD session */
8158         retval = create_aead_session(ts_params->valid_devs[0],
8159                         tdata->algo,
8160                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8161                         tdata->key.data, tdata->key.len,
8162                         tdata->aad.len, tdata->auth_tag.len,
8163                         tdata->iv.len);
8164         if (retval < 0)
8165                 return retval;
8166
8167         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8168         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8169
8170         /* clear mbuf payload */
8171         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8172                         rte_pktmbuf_tailroom(ut_params->ibuf));
8173         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8174                         rte_pktmbuf_tailroom(ut_params->obuf));
8175
8176         /* Create AEAD operation */
8177         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8178         if (retval < 0)
8179                 return retval;
8180
8181         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8182
8183         ut_params->op->sym->m_src = ut_params->ibuf;
8184         ut_params->op->sym->m_dst = ut_params->obuf;
8185
8186         /* Process crypto operation */
8187         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8188                         ut_params->op), "failed to process sym crypto op");
8189
8190         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8191                         "crypto op processing failed");
8192
8193         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8194
8195         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8196                         ut_params->op->sym->cipher.data.offset);
8197         auth_tag = ciphertext + plaintext_pad_len;
8198
8199         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8200         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8201
8202         /* Validate obuf */
8203         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8204                         ciphertext,
8205                         tdata->ciphertext.data,
8206                         tdata->ciphertext.len,
8207                         "Ciphertext data not as expected");
8208
8209         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8210                         auth_tag,
8211                         tdata->auth_tag.data,
8212                         tdata->auth_tag.len,
8213                         "Generated auth tag not as expected");
8214
8215         return 0;
8216
8217 }
8218
8219 static int
8220 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
8221 {
8222         return test_authenticated_encryption_oop(&gcm_test_case_5);
8223 }
8224
8225 static int
8226 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
8227 {
8228         struct crypto_testsuite_params *ts_params = &testsuite_params;
8229         struct crypto_unittest_params *ut_params = &unittest_params;
8230
8231         int retval;
8232         uint8_t *plaintext;
8233
8234         /* Verify the capabilities */
8235         struct rte_cryptodev_sym_capability_idx cap_idx;
8236         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8237         cap_idx.algo.aead = tdata->algo;
8238         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8239                         &cap_idx) == NULL)
8240                 return -ENOTSUP;
8241
8242         /* Create AEAD session */
8243         retval = create_aead_session(ts_params->valid_devs[0],
8244                         tdata->algo,
8245                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8246                         tdata->key.data, tdata->key.len,
8247                         tdata->aad.len, tdata->auth_tag.len,
8248                         tdata->iv.len);
8249         if (retval < 0)
8250                 return retval;
8251
8252         /* alloc mbuf and set payload */
8253         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8254         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8255
8256         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8257                         rte_pktmbuf_tailroom(ut_params->ibuf));
8258         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8259                         rte_pktmbuf_tailroom(ut_params->obuf));
8260
8261         /* Create AEAD operation */
8262         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8263         if (retval < 0)
8264                 return retval;
8265
8266         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8267
8268         ut_params->op->sym->m_src = ut_params->ibuf;
8269         ut_params->op->sym->m_dst = ut_params->obuf;
8270
8271         /* Process crypto operation */
8272         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8273                         ut_params->op), "failed to process sym crypto op");
8274
8275         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8276                         "crypto op processing failed");
8277
8278         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8279                         ut_params->op->sym->cipher.data.offset);
8280
8281         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8282
8283         /* Validate obuf */
8284         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8285                         plaintext,
8286                         tdata->plaintext.data,
8287                         tdata->plaintext.len,
8288                         "Plaintext data not as expected");
8289
8290         TEST_ASSERT_EQUAL(ut_params->op->status,
8291                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8292                         "Authentication failed");
8293         return 0;
8294 }
8295
8296 static int
8297 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
8298 {
8299         return test_authenticated_decryption_oop(&gcm_test_case_5);
8300 }
8301
8302 static int
8303 test_authenticated_encryption_sessionless(
8304                 const struct aead_test_data *tdata)
8305 {
8306         struct crypto_testsuite_params *ts_params = &testsuite_params;
8307         struct crypto_unittest_params *ut_params = &unittest_params;
8308
8309         int retval;
8310         uint8_t *ciphertext, *auth_tag;
8311         uint16_t plaintext_pad_len;
8312         uint8_t key[tdata->key.len + 1];
8313
8314         /* This test is for AESNI MB and AESNI GCM PMDs only */
8315         if ((gbl_driver_id != rte_cryptodev_driver_id_get(
8316                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) &&
8317                         (gbl_driver_id != rte_cryptodev_driver_id_get(
8318                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))))
8319                 return -ENOTSUP;
8320
8321         /* Verify the capabilities */
8322         struct rte_cryptodev_sym_capability_idx cap_idx;
8323         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8324         cap_idx.algo.aead = tdata->algo;
8325         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8326                         &cap_idx) == NULL)
8327                 return -ENOTSUP;
8328
8329         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8330
8331         /* clear mbuf payload */
8332         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8333                         rte_pktmbuf_tailroom(ut_params->ibuf));
8334
8335         /* Create AEAD operation */
8336         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8337         if (retval < 0)
8338                 return retval;
8339
8340         /* Create GCM xform */
8341         memcpy(key, tdata->key.data, tdata->key.len);
8342         retval = create_aead_xform(ut_params->op,
8343                         tdata->algo,
8344                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8345                         key, tdata->key.len,
8346                         tdata->aad.len, tdata->auth_tag.len,
8347                         tdata->iv.len);
8348         if (retval < 0)
8349                 return retval;
8350
8351         ut_params->op->sym->m_src = ut_params->ibuf;
8352
8353         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8354                         RTE_CRYPTO_OP_SESSIONLESS,
8355                         "crypto op session type not sessionless");
8356
8357         /* Process crypto operation */
8358         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8359                         ut_params->op), "failed to process sym crypto op");
8360
8361         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8362
8363         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8364                         "crypto op status not success");
8365
8366         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8367
8368         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8369                         ut_params->op->sym->cipher.data.offset);
8370         auth_tag = ciphertext + plaintext_pad_len;
8371
8372         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8373         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8374
8375         /* Validate obuf */
8376         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8377                         ciphertext,
8378                         tdata->ciphertext.data,
8379                         tdata->ciphertext.len,
8380                         "Ciphertext data not as expected");
8381
8382         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8383                         auth_tag,
8384                         tdata->auth_tag.data,
8385                         tdata->auth_tag.len,
8386                         "Generated auth tag not as expected");
8387
8388         return 0;
8389
8390 }
8391
8392 static int
8393 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
8394 {
8395         return test_authenticated_encryption_sessionless(
8396                         &gcm_test_case_5);
8397 }
8398
8399 static int
8400 test_authenticated_decryption_sessionless(
8401                 const struct aead_test_data *tdata)
8402 {
8403         struct crypto_testsuite_params *ts_params = &testsuite_params;
8404         struct crypto_unittest_params *ut_params = &unittest_params;
8405
8406         int retval;
8407         uint8_t *plaintext;
8408         uint8_t key[tdata->key.len + 1];
8409
8410         /* This test is for AESNI MB and AESNI GCM PMDs only */
8411         if ((gbl_driver_id != rte_cryptodev_driver_id_get(
8412                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) &&
8413                         (gbl_driver_id != rte_cryptodev_driver_id_get(
8414                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))))
8415                 return -ENOTSUP;
8416
8417         /* Verify the capabilities */
8418         struct rte_cryptodev_sym_capability_idx cap_idx;
8419         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8420         cap_idx.algo.aead = tdata->algo;
8421         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8422                         &cap_idx) == NULL)
8423                 return -ENOTSUP;
8424
8425         /* alloc mbuf and set payload */
8426         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8427
8428         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8429                         rte_pktmbuf_tailroom(ut_params->ibuf));
8430
8431         /* Create AEAD operation */
8432         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8433         if (retval < 0)
8434                 return retval;
8435
8436         /* Create AEAD xform */
8437         memcpy(key, tdata->key.data, tdata->key.len);
8438         retval = create_aead_xform(ut_params->op,
8439                         tdata->algo,
8440                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8441                         key, tdata->key.len,
8442                         tdata->aad.len, tdata->auth_tag.len,
8443                         tdata->iv.len);
8444         if (retval < 0)
8445                 return retval;
8446
8447         ut_params->op->sym->m_src = ut_params->ibuf;
8448
8449         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8450                         RTE_CRYPTO_OP_SESSIONLESS,
8451                         "crypto op session type not sessionless");
8452
8453         /* Process crypto operation */
8454         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8455                         ut_params->op), "failed to process sym crypto op");
8456
8457         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8458
8459         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8460                         "crypto op status not success");
8461
8462         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8463                         ut_params->op->sym->cipher.data.offset);
8464
8465         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8466
8467         /* Validate obuf */
8468         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8469                         plaintext,
8470                         tdata->plaintext.data,
8471                         tdata->plaintext.len,
8472                         "Plaintext data not as expected");
8473
8474         TEST_ASSERT_EQUAL(ut_params->op->status,
8475                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8476                         "Authentication failed");
8477         return 0;
8478 }
8479
8480 static int
8481 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
8482 {
8483         return test_authenticated_decryption_sessionless(
8484                         &gcm_test_case_5);
8485 }
8486
8487 static int
8488 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
8489 {
8490         return test_authenticated_encryption(&ccm_test_case_128_1);
8491 }
8492
8493 static int
8494 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
8495 {
8496         return test_authenticated_encryption(&ccm_test_case_128_2);
8497 }
8498
8499 static int
8500 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
8501 {
8502         return test_authenticated_encryption(&ccm_test_case_128_3);
8503 }
8504
8505 static int
8506 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
8507 {
8508         return test_authenticated_decryption(&ccm_test_case_128_1);
8509 }
8510
8511 static int
8512 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
8513 {
8514         return test_authenticated_decryption(&ccm_test_case_128_2);
8515 }
8516
8517 static int
8518 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
8519 {
8520         return test_authenticated_decryption(&ccm_test_case_128_3);
8521 }
8522
8523 static int
8524 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
8525 {
8526         return test_authenticated_encryption(&ccm_test_case_192_1);
8527 }
8528
8529 static int
8530 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
8531 {
8532         return test_authenticated_encryption(&ccm_test_case_192_2);
8533 }
8534
8535 static int
8536 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
8537 {
8538         return test_authenticated_encryption(&ccm_test_case_192_3);
8539 }
8540
8541 static int
8542 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
8543 {
8544         return test_authenticated_decryption(&ccm_test_case_192_1);
8545 }
8546
8547 static int
8548 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
8549 {
8550         return test_authenticated_decryption(&ccm_test_case_192_2);
8551 }
8552
8553 static int
8554 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
8555 {
8556         return test_authenticated_decryption(&ccm_test_case_192_3);
8557 }
8558
8559 static int
8560 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
8561 {
8562         return test_authenticated_encryption(&ccm_test_case_256_1);
8563 }
8564
8565 static int
8566 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
8567 {
8568         return test_authenticated_encryption(&ccm_test_case_256_2);
8569 }
8570
8571 static int
8572 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
8573 {
8574         return test_authenticated_encryption(&ccm_test_case_256_3);
8575 }
8576
8577 static int
8578 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
8579 {
8580         return test_authenticated_decryption(&ccm_test_case_256_1);
8581 }
8582
8583 static int
8584 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
8585 {
8586         return test_authenticated_decryption(&ccm_test_case_256_2);
8587 }
8588
8589 static int
8590 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
8591 {
8592         return test_authenticated_decryption(&ccm_test_case_256_3);
8593 }
8594
8595 static int
8596 test_stats(void)
8597 {
8598         struct crypto_testsuite_params *ts_params = &testsuite_params;
8599         struct rte_cryptodev_stats stats;
8600         struct rte_cryptodev *dev;
8601         cryptodev_stats_get_t temp_pfn;
8602
8603         /* Verify the capabilities */
8604         struct rte_cryptodev_sym_capability_idx cap_idx;
8605         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8606         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
8607         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8608                         &cap_idx) == NULL)
8609                 return -ENOTSUP;
8610         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8611         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
8612         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8613                         &cap_idx) == NULL)
8614                 return -ENOTSUP;
8615
8616         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8617         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
8618                         &stats) == -ENODEV),
8619                 "rte_cryptodev_stats_get invalid dev failed");
8620         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
8621                 "rte_cryptodev_stats_get invalid Param failed");
8622         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
8623         temp_pfn = dev->dev_ops->stats_get;
8624         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
8625         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
8626                         == -ENOTSUP),
8627                 "rte_cryptodev_stats_get invalid Param failed");
8628         dev->dev_ops->stats_get = temp_pfn;
8629
8630         /* Test expected values */
8631         ut_setup();
8632         test_AES_CBC_HMAC_SHA1_encrypt_digest();
8633         ut_teardown();
8634         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8635                         &stats),
8636                 "rte_cryptodev_stats_get failed");
8637         TEST_ASSERT((stats.enqueued_count == 1),
8638                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8639         TEST_ASSERT((stats.dequeued_count == 1),
8640                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8641         TEST_ASSERT((stats.enqueue_err_count == 0),
8642                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8643         TEST_ASSERT((stats.dequeue_err_count == 0),
8644                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8645
8646         /* invalid device but should ignore and not reset device stats*/
8647         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
8648         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8649                         &stats),
8650                 "rte_cryptodev_stats_get failed");
8651         TEST_ASSERT((stats.enqueued_count == 1),
8652                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8653
8654         /* check that a valid reset clears stats */
8655         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8656         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8657                         &stats),
8658                                           "rte_cryptodev_stats_get failed");
8659         TEST_ASSERT((stats.enqueued_count == 0),
8660                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8661         TEST_ASSERT((stats.dequeued_count == 0),
8662                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8663
8664         return TEST_SUCCESS;
8665 }
8666
8667 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
8668                                    struct crypto_unittest_params *ut_params,
8669                                    enum rte_crypto_auth_operation op,
8670                                    const struct HMAC_MD5_vector *test_case)
8671 {
8672         uint8_t key[64];
8673
8674         memcpy(key, test_case->key.data, test_case->key.len);
8675
8676         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8677         ut_params->auth_xform.next = NULL;
8678         ut_params->auth_xform.auth.op = op;
8679
8680         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
8681
8682         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
8683         ut_params->auth_xform.auth.key.length = test_case->key.len;
8684         ut_params->auth_xform.auth.key.data = key;
8685
8686         ut_params->sess = rte_cryptodev_sym_session_create(
8687                         ts_params->session_mpool);
8688
8689         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8690                         ut_params->sess, &ut_params->auth_xform,
8691                         ts_params->session_priv_mpool);
8692
8693         if (ut_params->sess == NULL)
8694                 return TEST_FAILED;
8695
8696         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8697
8698         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8699                         rte_pktmbuf_tailroom(ut_params->ibuf));
8700
8701         return 0;
8702 }
8703
8704 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
8705                               const struct HMAC_MD5_vector *test_case,
8706                               uint8_t **plaintext)
8707 {
8708         uint16_t plaintext_pad_len;
8709
8710         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8711
8712         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8713                                 16);
8714
8715         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8716                         plaintext_pad_len);
8717         memcpy(*plaintext, test_case->plaintext.data,
8718                         test_case->plaintext.len);
8719
8720         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
8721                         ut_params->ibuf, MD5_DIGEST_LEN);
8722         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
8723                         "no room to append digest");
8724         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
8725                         ut_params->ibuf, plaintext_pad_len);
8726
8727         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
8728                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
8729                            test_case->auth_tag.len);
8730         }
8731
8732         sym_op->auth.data.offset = 0;
8733         sym_op->auth.data.length = test_case->plaintext.len;
8734
8735         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8736         ut_params->op->sym->m_src = ut_params->ibuf;
8737
8738         return 0;
8739 }
8740
8741 static int
8742 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
8743 {
8744         uint16_t plaintext_pad_len;
8745         uint8_t *plaintext, *auth_tag;
8746
8747         struct crypto_testsuite_params *ts_params = &testsuite_params;
8748         struct crypto_unittest_params *ut_params = &unittest_params;
8749
8750         /* Verify the capabilities */
8751         struct rte_cryptodev_sym_capability_idx cap_idx;
8752         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8753         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
8754         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8755                         &cap_idx) == NULL)
8756                 return -ENOTSUP;
8757
8758         if (MD5_HMAC_create_session(ts_params, ut_params,
8759                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
8760                 return TEST_FAILED;
8761
8762         /* Generate Crypto op data structure */
8763         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8764                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8765         TEST_ASSERT_NOT_NULL(ut_params->op,
8766                         "Failed to allocate symmetric crypto operation struct");
8767
8768         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8769                                 16);
8770
8771         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
8772                 return TEST_FAILED;
8773
8774         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8775                         ut_params->op), "failed to process sym crypto op");
8776
8777         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8778                         "crypto op processing failed");
8779
8780         if (ut_params->op->sym->m_dst) {
8781                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8782                                 uint8_t *, plaintext_pad_len);
8783         } else {
8784                 auth_tag = plaintext + plaintext_pad_len;
8785         }
8786
8787         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8788                         auth_tag,
8789                         test_case->auth_tag.data,
8790                         test_case->auth_tag.len,
8791                         "HMAC_MD5 generated tag not as expected");
8792
8793         return TEST_SUCCESS;
8794 }
8795
8796 static int
8797 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
8798 {
8799         uint8_t *plaintext;
8800
8801         struct crypto_testsuite_params *ts_params = &testsuite_params;
8802         struct crypto_unittest_params *ut_params = &unittest_params;
8803
8804         /* Verify the capabilities */
8805         struct rte_cryptodev_sym_capability_idx cap_idx;
8806         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8807         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
8808         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8809                         &cap_idx) == NULL)
8810                 return -ENOTSUP;
8811
8812         if (MD5_HMAC_create_session(ts_params, ut_params,
8813                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
8814                 return TEST_FAILED;
8815         }
8816
8817         /* Generate Crypto op data structure */
8818         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8819                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8820         TEST_ASSERT_NOT_NULL(ut_params->op,
8821                         "Failed to allocate symmetric crypto operation struct");
8822
8823         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
8824                 return TEST_FAILED;
8825
8826         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8827                         ut_params->op), "failed to process sym crypto op");
8828
8829         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8830                         "HMAC_MD5 crypto op processing failed");
8831
8832         return TEST_SUCCESS;
8833 }
8834
8835 static int
8836 test_MD5_HMAC_generate_case_1(void)
8837 {
8838         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
8839 }
8840
8841 static int
8842 test_MD5_HMAC_verify_case_1(void)
8843 {
8844         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
8845 }
8846
8847 static int
8848 test_MD5_HMAC_generate_case_2(void)
8849 {
8850         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
8851 }
8852
8853 static int
8854 test_MD5_HMAC_verify_case_2(void)
8855 {
8856         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
8857 }
8858
8859 static int
8860 test_multi_session(void)
8861 {
8862         struct crypto_testsuite_params *ts_params = &testsuite_params;
8863         struct crypto_unittest_params *ut_params = &unittest_params;
8864
8865         struct rte_cryptodev_info dev_info;
8866         struct rte_cryptodev_sym_session **sessions;
8867
8868         uint16_t i;
8869
8870         /* Verify the capabilities */
8871         struct rte_cryptodev_sym_capability_idx cap_idx;
8872         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8873         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
8874         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8875                         &cap_idx) == NULL)
8876                 return -ENOTSUP;
8877         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8878         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
8879         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8880                         &cap_idx) == NULL)
8881                 return -ENOTSUP;
8882
8883         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
8884                         aes_cbc_key, hmac_sha512_key);
8885
8886
8887         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8888
8889         sessions = rte_malloc(NULL,
8890                         (sizeof(struct rte_cryptodev_sym_session *) *
8891                         MAX_NB_SESSIONS) + 1, 0);
8892
8893         /* Create multiple crypto sessions*/
8894         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8895
8896                 sessions[i] = rte_cryptodev_sym_session_create(
8897                                 ts_params->session_mpool);
8898
8899                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8900                                 sessions[i], &ut_params->auth_xform,
8901                                 ts_params->session_priv_mpool);
8902                 TEST_ASSERT_NOT_NULL(sessions[i],
8903                                 "Session creation failed at session number %u",
8904                                 i);
8905
8906                 /* Attempt to send a request on each session */
8907                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
8908                         sessions[i],
8909                         ut_params,
8910                         ts_params,
8911                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
8912                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
8913                         aes_cbc_iv),
8914                         "Failed to perform decrypt on request number %u.", i);
8915                 /* free crypto operation structure */
8916                 if (ut_params->op)
8917                         rte_crypto_op_free(ut_params->op);
8918
8919                 /*
8920                  * free mbuf - both obuf and ibuf are usually the same,
8921                  * so check if they point at the same address is necessary,
8922                  * to avoid freeing the mbuf twice.
8923                  */
8924                 if (ut_params->obuf) {
8925                         rte_pktmbuf_free(ut_params->obuf);
8926                         if (ut_params->ibuf == ut_params->obuf)
8927                                 ut_params->ibuf = 0;
8928                         ut_params->obuf = 0;
8929                 }
8930                 if (ut_params->ibuf) {
8931                         rte_pktmbuf_free(ut_params->ibuf);
8932                         ut_params->ibuf = 0;
8933                 }
8934         }
8935
8936         /* Next session create should fail */
8937         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8938                         sessions[i], &ut_params->auth_xform,
8939                         ts_params->session_priv_mpool);
8940         TEST_ASSERT_NULL(sessions[i],
8941                         "Session creation succeeded unexpectedly!");
8942
8943         for (i = 0; i < MAX_NB_SESSIONS; i++) {
8944                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
8945                                 sessions[i]);
8946                 rte_cryptodev_sym_session_free(sessions[i]);
8947         }
8948
8949         rte_free(sessions);
8950
8951         return TEST_SUCCESS;
8952 }
8953
8954 struct multi_session_params {
8955         struct crypto_unittest_params ut_params;
8956         uint8_t *cipher_key;
8957         uint8_t *hmac_key;
8958         const uint8_t *cipher;
8959         const uint8_t *digest;
8960         uint8_t *iv;
8961 };
8962
8963 #define MB_SESSION_NUMBER 3
8964
8965 static int
8966 test_multi_session_random_usage(void)
8967 {
8968         struct crypto_testsuite_params *ts_params = &testsuite_params;
8969         struct rte_cryptodev_info dev_info;
8970         struct rte_cryptodev_sym_session **sessions;
8971         uint32_t i, j;
8972         struct multi_session_params ut_paramz[] = {
8973
8974                 {
8975                         .cipher_key = ms_aes_cbc_key0,
8976                         .hmac_key = ms_hmac_key0,
8977                         .cipher = ms_aes_cbc_cipher0,
8978                         .digest = ms_hmac_digest0,
8979                         .iv = ms_aes_cbc_iv0
8980                 },
8981                 {
8982                         .cipher_key = ms_aes_cbc_key1,
8983                         .hmac_key = ms_hmac_key1,
8984                         .cipher = ms_aes_cbc_cipher1,
8985                         .digest = ms_hmac_digest1,
8986                         .iv = ms_aes_cbc_iv1
8987                 },
8988                 {
8989                         .cipher_key = ms_aes_cbc_key2,
8990                         .hmac_key = ms_hmac_key2,
8991                         .cipher = ms_aes_cbc_cipher2,
8992                         .digest = ms_hmac_digest2,
8993                         .iv = ms_aes_cbc_iv2
8994                 },
8995
8996         };
8997
8998         /* Verify the capabilities */
8999         struct rte_cryptodev_sym_capability_idx cap_idx;
9000         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9001         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9002         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9003                         &cap_idx) == NULL)
9004                 return -ENOTSUP;
9005         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9006         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9007         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9008                         &cap_idx) == NULL)
9009                 return -ENOTSUP;
9010
9011         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9012
9013         sessions = rte_malloc(NULL,
9014                         (sizeof(struct rte_cryptodev_sym_session *)
9015                                         * MAX_NB_SESSIONS) + 1, 0);
9016
9017         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9018                 sessions[i] = rte_cryptodev_sym_session_create(
9019                                 ts_params->session_mpool);
9020
9021                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
9022                                 sizeof(struct crypto_unittest_params));
9023
9024                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
9025                                 &ut_paramz[i].ut_params,
9026                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
9027
9028                 /* Create multiple crypto sessions*/
9029                 rte_cryptodev_sym_session_init(
9030                                 ts_params->valid_devs[0],
9031                                 sessions[i],
9032                                 &ut_paramz[i].ut_params.auth_xform,
9033                                 ts_params->session_priv_mpool);
9034
9035                 TEST_ASSERT_NOT_NULL(sessions[i],
9036                                 "Session creation failed at session number %u",
9037                                 i);
9038
9039         }
9040
9041         srand(time(NULL));
9042         for (i = 0; i < 40000; i++) {
9043
9044                 j = rand() % MB_SESSION_NUMBER;
9045
9046                 TEST_ASSERT_SUCCESS(
9047                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
9048                                         sessions[j],
9049                                         &ut_paramz[j].ut_params,
9050                                         ts_params, ut_paramz[j].cipher,
9051                                         ut_paramz[j].digest,
9052                                         ut_paramz[j].iv),
9053                         "Failed to perform decrypt on request number %u.", i);
9054
9055                 if (ut_paramz[j].ut_params.op)
9056                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
9057
9058                 /*
9059                  * free mbuf - both obuf and ibuf are usually the same,
9060                  * so check if they point at the same address is necessary,
9061                  * to avoid freeing the mbuf twice.
9062                  */
9063                 if (ut_paramz[j].ut_params.obuf) {
9064                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
9065                         if (ut_paramz[j].ut_params.ibuf
9066                                         == ut_paramz[j].ut_params.obuf)
9067                                 ut_paramz[j].ut_params.ibuf = 0;
9068                         ut_paramz[j].ut_params.obuf = 0;
9069                 }
9070                 if (ut_paramz[j].ut_params.ibuf) {
9071                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
9072                         ut_paramz[j].ut_params.ibuf = 0;
9073                 }
9074         }
9075
9076         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9077                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9078                                 sessions[i]);
9079                 rte_cryptodev_sym_session_free(sessions[i]);
9080         }
9081
9082         rte_free(sessions);
9083
9084         return TEST_SUCCESS;
9085 }
9086
9087 static int
9088 test_null_cipher_only_operation(void)
9089 {
9090         struct crypto_testsuite_params *ts_params = &testsuite_params;
9091         struct crypto_unittest_params *ut_params = &unittest_params;
9092
9093         /* Verify the capabilities */
9094         struct rte_cryptodev_sym_capability_idx cap_idx;
9095         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9096         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9097         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9098                         &cap_idx) == NULL)
9099                 return -ENOTSUP;
9100
9101         /* Generate test mbuf data and space for digest */
9102         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9103                         catch_22_quote, QUOTE_512_BYTES, 0);
9104
9105         /* Setup Cipher Parameters */
9106         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9107         ut_params->cipher_xform.next = NULL;
9108
9109         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9110         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9111
9112         ut_params->sess = rte_cryptodev_sym_session_create(
9113                         ts_params->session_mpool);
9114
9115         /* Create Crypto session*/
9116         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9117                                 ut_params->sess,
9118                                 &ut_params->cipher_xform,
9119                                 ts_params->session_priv_mpool);
9120         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9121
9122         /* Generate Crypto op data structure */
9123         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9124                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9125         TEST_ASSERT_NOT_NULL(ut_params->op,
9126                         "Failed to allocate symmetric crypto operation struct");
9127
9128         /* Set crypto operation data parameters */
9129         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9130
9131         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9132
9133         /* set crypto operation source mbuf */
9134         sym_op->m_src = ut_params->ibuf;
9135
9136         sym_op->cipher.data.offset = 0;
9137         sym_op->cipher.data.length = QUOTE_512_BYTES;
9138
9139         /* Process crypto operation */
9140         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9141                         ut_params->op);
9142         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9143
9144         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9145                         "crypto operation processing failed");
9146
9147         /* Validate obuf */
9148         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9149                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9150                         catch_22_quote,
9151                         QUOTE_512_BYTES,
9152                         "Ciphertext data not as expected");
9153
9154         return TEST_SUCCESS;
9155 }
9156 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
9157                         0xab, 0xab, 0xab, 0xab,
9158                         0xab, 0xab, 0xab, 0xab,
9159                         0xab, 0xab, 0xab, 0xab};
9160 static int
9161 test_null_auth_only_operation(void)
9162 {
9163         struct crypto_testsuite_params *ts_params = &testsuite_params;
9164         struct crypto_unittest_params *ut_params = &unittest_params;
9165         uint8_t *digest;
9166
9167         /* Verify the capabilities */
9168         struct rte_cryptodev_sym_capability_idx cap_idx;
9169         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9170         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9171         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9172                         &cap_idx) == NULL)
9173                 return -ENOTSUP;
9174
9175         /* Generate test mbuf data and space for digest */
9176         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9177                         catch_22_quote, QUOTE_512_BYTES, 0);
9178
9179         /* create a pointer for digest, but don't expect anything to be written
9180          * here in a NULL auth algo so no mbuf append done.
9181          */
9182         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9183                         QUOTE_512_BYTES);
9184         /* prefill the memory pointed to by digest */
9185         memcpy(digest, orig_data, sizeof(orig_data));
9186
9187         /* Setup HMAC Parameters */
9188         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9189         ut_params->auth_xform.next = NULL;
9190
9191         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9192         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9193
9194         ut_params->sess = rte_cryptodev_sym_session_create(
9195                         ts_params->session_mpool);
9196
9197         /* Create Crypto session*/
9198         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9199                         ut_params->sess, &ut_params->auth_xform,
9200                         ts_params->session_priv_mpool);
9201         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9202
9203         /* Generate Crypto op data structure */
9204         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9205                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9206         TEST_ASSERT_NOT_NULL(ut_params->op,
9207                         "Failed to allocate symmetric crypto operation struct");
9208
9209         /* Set crypto operation data parameters */
9210         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9211
9212         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9213
9214         sym_op->m_src = ut_params->ibuf;
9215
9216         sym_op->auth.data.offset = 0;
9217         sym_op->auth.data.length = QUOTE_512_BYTES;
9218         sym_op->auth.digest.data = digest;
9219         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9220                         QUOTE_512_BYTES);
9221
9222         /* Process crypto operation */
9223         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9224                         ut_params->op);
9225         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9226
9227         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9228                         "crypto operation processing failed");
9229         /* Make sure memory pointed to by digest hasn't been overwritten */
9230         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9231                         orig_data,
9232                         digest,
9233                         sizeof(orig_data),
9234                         "Memory at digest ptr overwritten unexpectedly");
9235
9236         return TEST_SUCCESS;
9237 }
9238
9239
9240 static int
9241 test_null_cipher_auth_operation(void)
9242 {
9243         struct crypto_testsuite_params *ts_params = &testsuite_params;
9244         struct crypto_unittest_params *ut_params = &unittest_params;
9245         uint8_t *digest;
9246
9247         /* Verify the capabilities */
9248         struct rte_cryptodev_sym_capability_idx cap_idx;
9249         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9250         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9251         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9252                         &cap_idx) == NULL)
9253                 return -ENOTSUP;
9254         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9255         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9256         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9257                         &cap_idx) == NULL)
9258                 return -ENOTSUP;
9259
9260         /* Generate test mbuf data and space for digest */
9261         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9262                         catch_22_quote, QUOTE_512_BYTES, 0);
9263
9264         /* create a pointer for digest, but don't expect anything to be written
9265          * here in a NULL auth algo so no mbuf append done.
9266          */
9267         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9268                         QUOTE_512_BYTES);
9269         /* prefill the memory pointed to by digest */
9270         memcpy(digest, orig_data, sizeof(orig_data));
9271
9272         /* Setup Cipher Parameters */
9273         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9274         ut_params->cipher_xform.next = &ut_params->auth_xform;
9275
9276         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9277         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9278
9279         /* Setup HMAC Parameters */
9280         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9281         ut_params->auth_xform.next = NULL;
9282
9283         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9284         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9285
9286         ut_params->sess = rte_cryptodev_sym_session_create(
9287                         ts_params->session_mpool);
9288
9289         /* Create Crypto session*/
9290         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9291                         ut_params->sess, &ut_params->cipher_xform,
9292                         ts_params->session_priv_mpool);
9293         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9294
9295         /* Generate Crypto op data structure */
9296         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9297                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9298         TEST_ASSERT_NOT_NULL(ut_params->op,
9299                         "Failed to allocate symmetric crypto operation struct");
9300
9301         /* Set crypto operation data parameters */
9302         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9303
9304         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9305
9306         sym_op->m_src = ut_params->ibuf;
9307
9308         sym_op->cipher.data.offset = 0;
9309         sym_op->cipher.data.length = QUOTE_512_BYTES;
9310
9311         sym_op->auth.data.offset = 0;
9312         sym_op->auth.data.length = QUOTE_512_BYTES;
9313         sym_op->auth.digest.data = digest;
9314         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9315                         QUOTE_512_BYTES);
9316
9317         /* Process crypto operation */
9318         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9319                         ut_params->op);
9320         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9321
9322         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9323                         "crypto operation processing failed");
9324
9325         /* Validate obuf */
9326         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9327                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9328                         catch_22_quote,
9329                         QUOTE_512_BYTES,
9330                         "Ciphertext data not as expected");
9331         /* Make sure memory pointed to by digest hasn't been overwritten */
9332         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9333                         orig_data,
9334                         digest,
9335                         sizeof(orig_data),
9336                         "Memory at digest ptr overwritten unexpectedly");
9337
9338         return TEST_SUCCESS;
9339 }
9340
9341 static int
9342 test_null_auth_cipher_operation(void)
9343 {
9344         struct crypto_testsuite_params *ts_params = &testsuite_params;
9345         struct crypto_unittest_params *ut_params = &unittest_params;
9346         uint8_t *digest;
9347
9348         /* Verify the capabilities */
9349         struct rte_cryptodev_sym_capability_idx cap_idx;
9350         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9351         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9352         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9353                         &cap_idx) == NULL)
9354                 return -ENOTSUP;
9355         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9356         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9357         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9358                         &cap_idx) == NULL)
9359                 return -ENOTSUP;
9360
9361         /* Generate test mbuf data */
9362         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9363                         catch_22_quote, QUOTE_512_BYTES, 0);
9364
9365         /* create a pointer for digest, but don't expect anything to be written
9366          * here in a NULL auth algo so no mbuf append done.
9367          */
9368         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9369                                 QUOTE_512_BYTES);
9370         /* prefill the memory pointed to by digest */
9371         memcpy(digest, orig_data, sizeof(orig_data));
9372
9373         /* Setup Cipher Parameters */
9374         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9375         ut_params->cipher_xform.next = NULL;
9376
9377         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9378         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9379
9380         /* Setup HMAC Parameters */
9381         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9382         ut_params->auth_xform.next = &ut_params->cipher_xform;
9383
9384         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9385         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9386
9387         ut_params->sess = rte_cryptodev_sym_session_create(
9388                         ts_params->session_mpool);
9389
9390         /* Create Crypto session*/
9391         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9392                         ut_params->sess, &ut_params->cipher_xform,
9393                         ts_params->session_priv_mpool);
9394         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9395
9396         /* Generate Crypto op data structure */
9397         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9398                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9399         TEST_ASSERT_NOT_NULL(ut_params->op,
9400                         "Failed to allocate symmetric crypto operation struct");
9401
9402         /* Set crypto operation data parameters */
9403         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9404
9405         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9406
9407         sym_op->m_src = ut_params->ibuf;
9408
9409         sym_op->cipher.data.offset = 0;
9410         sym_op->cipher.data.length = QUOTE_512_BYTES;
9411
9412         sym_op->auth.data.offset = 0;
9413         sym_op->auth.data.length = QUOTE_512_BYTES;
9414         sym_op->auth.digest.data = digest;
9415         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9416                                         QUOTE_512_BYTES);
9417
9418         /* Process crypto operation */
9419         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9420                         ut_params->op);
9421         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9422
9423         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9424                         "crypto operation processing failed");
9425
9426         /* Validate obuf */
9427         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9428                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9429                         catch_22_quote,
9430                         QUOTE_512_BYTES,
9431                         "Ciphertext data not as expected");
9432         /* Make sure memory pointed to by digest hasn't been overwritten */
9433         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9434                         orig_data,
9435                         digest,
9436                         sizeof(orig_data),
9437                         "Memory at digest ptr overwritten unexpectedly");
9438
9439         return TEST_SUCCESS;
9440 }
9441
9442
9443 static int
9444 test_null_invalid_operation(void)
9445 {
9446         struct crypto_testsuite_params *ts_params = &testsuite_params;
9447         struct crypto_unittest_params *ut_params = &unittest_params;
9448         int ret;
9449
9450         /* This test is for NULL PMD only */
9451         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9452                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9453                 return -ENOTSUP;
9454
9455         /* Setup Cipher Parameters */
9456         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9457         ut_params->cipher_xform.next = NULL;
9458
9459         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
9460         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9461
9462         ut_params->sess = rte_cryptodev_sym_session_create(
9463                         ts_params->session_mpool);
9464
9465         /* Create Crypto session*/
9466         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9467                         ut_params->sess, &ut_params->cipher_xform,
9468                         ts_params->session_priv_mpool);
9469         TEST_ASSERT(ret < 0,
9470                         "Session creation succeeded unexpectedly");
9471
9472
9473         /* Setup HMAC Parameters */
9474         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9475         ut_params->auth_xform.next = NULL;
9476
9477         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
9478         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9479
9480         ut_params->sess = rte_cryptodev_sym_session_create(
9481                         ts_params->session_mpool);
9482
9483         /* Create Crypto session*/
9484         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9485                         ut_params->sess, &ut_params->auth_xform,
9486                         ts_params->session_priv_mpool);
9487         TEST_ASSERT(ret < 0,
9488                         "Session creation succeeded unexpectedly");
9489
9490         return TEST_SUCCESS;
9491 }
9492
9493
9494 #define NULL_BURST_LENGTH (32)
9495
9496 static int
9497 test_null_burst_operation(void)
9498 {
9499         struct crypto_testsuite_params *ts_params = &testsuite_params;
9500         struct crypto_unittest_params *ut_params = &unittest_params;
9501
9502         unsigned i, burst_len = NULL_BURST_LENGTH;
9503
9504         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
9505         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
9506
9507         /* This test is for NULL PMD only */
9508         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9509                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9510                 return -ENOTSUP;
9511
9512         /* Setup Cipher Parameters */
9513         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9514         ut_params->cipher_xform.next = &ut_params->auth_xform;
9515
9516         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9517         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9518
9519         /* Setup HMAC Parameters */
9520         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9521         ut_params->auth_xform.next = NULL;
9522
9523         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9524         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9525
9526         ut_params->sess = rte_cryptodev_sym_session_create(
9527                         ts_params->session_mpool);
9528
9529         /* Create Crypto session*/
9530         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9531                         ut_params->sess, &ut_params->cipher_xform,
9532                         ts_params->session_priv_mpool);
9533         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9534
9535         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
9536                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
9537                         burst_len, "failed to generate burst of crypto ops");
9538
9539         /* Generate an operation for each mbuf in burst */
9540         for (i = 0; i < burst_len; i++) {
9541                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9542
9543                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
9544
9545                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
9546                                 sizeof(unsigned));
9547                 *data = i;
9548
9549                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
9550
9551                 burst[i]->sym->m_src = m;
9552         }
9553
9554         /* Process crypto operation */
9555         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
9556                         0, burst, burst_len),
9557                         burst_len,
9558                         "Error enqueuing burst");
9559
9560         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
9561                         0, burst_dequeued, burst_len),
9562                         burst_len,
9563                         "Error dequeuing burst");
9564
9565
9566         for (i = 0; i < burst_len; i++) {
9567                 TEST_ASSERT_EQUAL(
9568                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
9569                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
9570                                         uint32_t *),
9571                         "data not as expected");
9572
9573                 rte_pktmbuf_free(burst[i]->sym->m_src);
9574                 rte_crypto_op_free(burst[i]);
9575         }
9576
9577         return TEST_SUCCESS;
9578 }
9579
9580 static void
9581 generate_gmac_large_plaintext(uint8_t *data)
9582 {
9583         uint16_t i;
9584
9585         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
9586                 memcpy(&data[i], &data[0], 32);
9587 }
9588
9589 static int
9590 create_gmac_operation(enum rte_crypto_auth_operation op,
9591                 const struct gmac_test_data *tdata)
9592 {
9593         struct crypto_testsuite_params *ts_params = &testsuite_params;
9594         struct crypto_unittest_params *ut_params = &unittest_params;
9595         struct rte_crypto_sym_op *sym_op;
9596
9597         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9598
9599         /* Generate Crypto op data structure */
9600         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9601                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9602         TEST_ASSERT_NOT_NULL(ut_params->op,
9603                         "Failed to allocate symmetric crypto operation struct");
9604
9605         sym_op = ut_params->op->sym;
9606
9607         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9608                         ut_params->ibuf, tdata->gmac_tag.len);
9609         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9610                         "no room to append digest");
9611
9612         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9613                         ut_params->ibuf, plaintext_pad_len);
9614
9615         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9616                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
9617                                 tdata->gmac_tag.len);
9618                 debug_hexdump(stdout, "digest:",
9619                                 sym_op->auth.digest.data,
9620                                 tdata->gmac_tag.len);
9621         }
9622
9623         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9624                         uint8_t *, IV_OFFSET);
9625
9626         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
9627
9628         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
9629
9630         sym_op->cipher.data.length = 0;
9631         sym_op->cipher.data.offset = 0;
9632
9633         sym_op->auth.data.offset = 0;
9634         sym_op->auth.data.length = tdata->plaintext.len;
9635
9636         return 0;
9637 }
9638
9639 static int create_gmac_session(uint8_t dev_id,
9640                 const struct gmac_test_data *tdata,
9641                 enum rte_crypto_auth_operation auth_op)
9642 {
9643         uint8_t auth_key[tdata->key.len];
9644
9645         struct crypto_testsuite_params *ts_params = &testsuite_params;
9646         struct crypto_unittest_params *ut_params = &unittest_params;
9647
9648         memcpy(auth_key, tdata->key.data, tdata->key.len);
9649
9650         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9651         ut_params->auth_xform.next = NULL;
9652
9653         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
9654         ut_params->auth_xform.auth.op = auth_op;
9655         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
9656         ut_params->auth_xform.auth.key.length = tdata->key.len;
9657         ut_params->auth_xform.auth.key.data = auth_key;
9658         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
9659         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
9660
9661
9662         ut_params->sess = rte_cryptodev_sym_session_create(
9663                         ts_params->session_mpool);
9664
9665         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
9666                         &ut_params->auth_xform,
9667                         ts_params->session_priv_mpool);
9668
9669         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9670
9671         return 0;
9672 }
9673
9674 static int
9675 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
9676 {
9677         struct crypto_testsuite_params *ts_params = &testsuite_params;
9678         struct crypto_unittest_params *ut_params = &unittest_params;
9679
9680         int retval;
9681
9682         uint8_t *auth_tag, *plaintext;
9683         uint16_t plaintext_pad_len;
9684
9685         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
9686                               "No GMAC length in the source data");
9687
9688         /* Verify the capabilities */
9689         struct rte_cryptodev_sym_capability_idx cap_idx;
9690         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9691         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
9692         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9693                         &cap_idx) == NULL)
9694                 return -ENOTSUP;
9695
9696         retval = create_gmac_session(ts_params->valid_devs[0],
9697                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
9698
9699         if (retval < 0)
9700                 return retval;
9701
9702         if (tdata->plaintext.len > MBUF_SIZE)
9703                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9704         else
9705                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9706         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9707                         "Failed to allocate input buffer in mempool");
9708
9709         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9710                         rte_pktmbuf_tailroom(ut_params->ibuf));
9711
9712         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9713         /*
9714          * Runtime generate the large plain text instead of use hard code
9715          * plain text vector. It is done to avoid create huge source file
9716          * with the test vector.
9717          */
9718         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
9719                 generate_gmac_large_plaintext(tdata->plaintext.data);
9720
9721         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9722                                 plaintext_pad_len);
9723         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9724
9725         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9726         debug_hexdump(stdout, "plaintext:", plaintext,
9727                         tdata->plaintext.len);
9728
9729         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
9730                         tdata);
9731
9732         if (retval < 0)
9733                 return retval;
9734
9735         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9736
9737         ut_params->op->sym->m_src = ut_params->ibuf;
9738
9739         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9740                         ut_params->op), "failed to process sym crypto op");
9741
9742         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9743                         "crypto op processing failed");
9744
9745         if (ut_params->op->sym->m_dst) {
9746                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9747                                 uint8_t *, plaintext_pad_len);
9748         } else {
9749                 auth_tag = plaintext + plaintext_pad_len;
9750         }
9751
9752         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
9753
9754         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9755                         auth_tag,
9756                         tdata->gmac_tag.data,
9757                         tdata->gmac_tag.len,
9758                         "GMAC Generated auth tag not as expected");
9759
9760         return 0;
9761 }
9762
9763 static int
9764 test_AES_GMAC_authentication_test_case_1(void)
9765 {
9766         return test_AES_GMAC_authentication(&gmac_test_case_1);
9767 }
9768
9769 static int
9770 test_AES_GMAC_authentication_test_case_2(void)
9771 {
9772         return test_AES_GMAC_authentication(&gmac_test_case_2);
9773 }
9774
9775 static int
9776 test_AES_GMAC_authentication_test_case_3(void)
9777 {
9778         return test_AES_GMAC_authentication(&gmac_test_case_3);
9779 }
9780
9781 static int
9782 test_AES_GMAC_authentication_test_case_4(void)
9783 {
9784         return test_AES_GMAC_authentication(&gmac_test_case_4);
9785 }
9786
9787 static int
9788 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
9789 {
9790         struct crypto_testsuite_params *ts_params = &testsuite_params;
9791         struct crypto_unittest_params *ut_params = &unittest_params;
9792         int retval;
9793         uint32_t plaintext_pad_len;
9794         uint8_t *plaintext;
9795
9796         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
9797                               "No GMAC length in the source data");
9798
9799         /* Verify the capabilities */
9800         struct rte_cryptodev_sym_capability_idx cap_idx;
9801         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9802         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
9803         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9804                         &cap_idx) == NULL)
9805                 return -ENOTSUP;
9806
9807         retval = create_gmac_session(ts_params->valid_devs[0],
9808                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
9809
9810         if (retval < 0)
9811                 return retval;
9812
9813         if (tdata->plaintext.len > MBUF_SIZE)
9814                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9815         else
9816                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9817         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9818                         "Failed to allocate input buffer in mempool");
9819
9820         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9821                         rte_pktmbuf_tailroom(ut_params->ibuf));
9822
9823         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9824
9825         /*
9826          * Runtime generate the large plain text instead of use hard code
9827          * plain text vector. It is done to avoid create huge source file
9828          * with the test vector.
9829          */
9830         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
9831                 generate_gmac_large_plaintext(tdata->plaintext.data);
9832
9833         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9834                                 plaintext_pad_len);
9835         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9836
9837         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9838         debug_hexdump(stdout, "plaintext:", plaintext,
9839                         tdata->plaintext.len);
9840
9841         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
9842                         tdata);
9843
9844         if (retval < 0)
9845                 return retval;
9846
9847         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9848
9849         ut_params->op->sym->m_src = ut_params->ibuf;
9850
9851         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9852                         ut_params->op), "failed to process sym crypto op");
9853
9854         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9855                         "crypto op processing failed");
9856
9857         return 0;
9858
9859 }
9860
9861 static int
9862 test_AES_GMAC_authentication_verify_test_case_1(void)
9863 {
9864         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
9865 }
9866
9867 static int
9868 test_AES_GMAC_authentication_verify_test_case_2(void)
9869 {
9870         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
9871 }
9872
9873 static int
9874 test_AES_GMAC_authentication_verify_test_case_3(void)
9875 {
9876         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
9877 }
9878
9879 static int
9880 test_AES_GMAC_authentication_verify_test_case_4(void)
9881 {
9882         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
9883 }
9884
9885 struct test_crypto_vector {
9886         enum rte_crypto_cipher_algorithm crypto_algo;
9887         unsigned int cipher_offset;
9888         unsigned int cipher_len;
9889
9890         struct {
9891                 uint8_t data[64];
9892                 unsigned int len;
9893         } cipher_key;
9894
9895         struct {
9896                 uint8_t data[64];
9897                 unsigned int len;
9898         } iv;
9899
9900         struct {
9901                 const uint8_t *data;
9902                 unsigned int len;
9903         } plaintext;
9904
9905         struct {
9906                 const uint8_t *data;
9907                 unsigned int len;
9908         } ciphertext;
9909
9910         enum rte_crypto_auth_algorithm auth_algo;
9911         unsigned int auth_offset;
9912
9913         struct {
9914                 uint8_t data[128];
9915                 unsigned int len;
9916         } auth_key;
9917
9918         struct {
9919                 const uint8_t *data;
9920                 unsigned int len;
9921         } aad;
9922
9923         struct {
9924                 uint8_t data[128];
9925                 unsigned int len;
9926         } digest;
9927 };
9928
9929 static const struct test_crypto_vector
9930 hmac_sha1_test_crypto_vector = {
9931         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
9932         .plaintext = {
9933                 .data = plaintext_hash,
9934                 .len = 512
9935         },
9936         .auth_key = {
9937                 .data = {
9938                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
9939                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
9940                         0xDE, 0xF4, 0xDE, 0xAD
9941                 },
9942                 .len = 20
9943         },
9944         .digest = {
9945                 .data = {
9946                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
9947                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
9948                         0x3F, 0x91, 0x64, 0x59
9949                 },
9950                 .len = 20
9951         }
9952 };
9953
9954 static const struct test_crypto_vector
9955 aes128_gmac_test_vector = {
9956         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
9957         .plaintext = {
9958                 .data = plaintext_hash,
9959                 .len = 512
9960         },
9961         .iv = {
9962                 .data = {
9963                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9964                         0x08, 0x09, 0x0A, 0x0B
9965                 },
9966                 .len = 12
9967         },
9968         .auth_key = {
9969                 .data = {
9970                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
9971                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
9972                 },
9973                 .len = 16
9974         },
9975         .digest = {
9976                 .data = {
9977                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
9978                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
9979                 },
9980                 .len = 16
9981         }
9982 };
9983
9984 static const struct test_crypto_vector
9985 aes128cbc_hmac_sha1_test_vector = {
9986         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
9987         .cipher_offset = 0,
9988         .cipher_len = 512,
9989         .cipher_key = {
9990                 .data = {
9991                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
9992                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
9993                 },
9994                 .len = 16
9995         },
9996         .iv = {
9997                 .data = {
9998                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
9999                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10000                 },
10001                 .len = 16
10002         },
10003         .plaintext = {
10004                 .data = plaintext_hash,
10005                 .len = 512
10006         },
10007         .ciphertext = {
10008                 .data = ciphertext512_aes128cbc,
10009                 .len = 512
10010         },
10011         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10012         .auth_offset = 0,
10013         .auth_key = {
10014                 .data = {
10015                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10016                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10017                         0xDE, 0xF4, 0xDE, 0xAD
10018                 },
10019                 .len = 20
10020         },
10021         .digest = {
10022                 .data = {
10023                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
10024                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10025                         0x18, 0x8C, 0x1D, 0x32
10026                 },
10027                 .len = 20
10028         }
10029 };
10030
10031 static const struct test_crypto_vector
10032 aes128cbc_hmac_sha1_aad_test_vector = {
10033         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10034         .cipher_offset = 12,
10035         .cipher_len = 496,
10036         .cipher_key = {
10037                 .data = {
10038                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10039                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10040                 },
10041                 .len = 16
10042         },
10043         .iv = {
10044                 .data = {
10045                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10046                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10047                 },
10048                 .len = 16
10049         },
10050         .plaintext = {
10051                 .data = plaintext_hash,
10052                 .len = 512
10053         },
10054         .ciphertext = {
10055                 .data = ciphertext512_aes128cbc_aad,
10056                 .len = 512
10057         },
10058         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10059         .auth_offset = 0,
10060         .auth_key = {
10061                 .data = {
10062                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10063                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10064                         0xDE, 0xF4, 0xDE, 0xAD
10065                 },
10066                 .len = 20
10067         },
10068         .digest = {
10069                 .data = {
10070                         0x1F, 0x6A, 0xD2, 0x8B, 0x4B, 0xB3, 0xC0, 0x9E,
10071                         0x86, 0x9B, 0x3A, 0xF2, 0x00, 0x5B, 0x4F, 0x08,
10072                         0x62, 0x8D, 0x62, 0x65
10073                 },
10074                 .len = 20
10075         }
10076 };
10077
10078 static void
10079 data_corruption(uint8_t *data)
10080 {
10081         data[0] += 1;
10082 }
10083
10084 static void
10085 tag_corruption(uint8_t *data, unsigned int tag_offset)
10086 {
10087         data[tag_offset] += 1;
10088 }
10089
10090 static int
10091 create_auth_session(struct crypto_unittest_params *ut_params,
10092                 uint8_t dev_id,
10093                 const struct test_crypto_vector *reference,
10094                 enum rte_crypto_auth_operation auth_op)
10095 {
10096         struct crypto_testsuite_params *ts_params = &testsuite_params;
10097         uint8_t auth_key[reference->auth_key.len + 1];
10098
10099         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10100
10101         /* Setup Authentication Parameters */
10102         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10103         ut_params->auth_xform.auth.op = auth_op;
10104         ut_params->auth_xform.next = NULL;
10105         ut_params->auth_xform.auth.algo = reference->auth_algo;
10106         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10107         ut_params->auth_xform.auth.key.data = auth_key;
10108         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10109
10110         /* Create Crypto session*/
10111         ut_params->sess = rte_cryptodev_sym_session_create(
10112                         ts_params->session_mpool);
10113
10114         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10115                                 &ut_params->auth_xform,
10116                                 ts_params->session_priv_mpool);
10117
10118         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10119
10120         return 0;
10121 }
10122
10123 static int
10124 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
10125                 uint8_t dev_id,
10126                 const struct test_crypto_vector *reference,
10127                 enum rte_crypto_auth_operation auth_op,
10128                 enum rte_crypto_cipher_operation cipher_op)
10129 {
10130         struct crypto_testsuite_params *ts_params = &testsuite_params;
10131         uint8_t cipher_key[reference->cipher_key.len + 1];
10132         uint8_t auth_key[reference->auth_key.len + 1];
10133
10134         memcpy(cipher_key, reference->cipher_key.data,
10135                         reference->cipher_key.len);
10136         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10137
10138         /* Setup Authentication Parameters */
10139         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10140         ut_params->auth_xform.auth.op = auth_op;
10141         ut_params->auth_xform.auth.algo = reference->auth_algo;
10142         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10143         ut_params->auth_xform.auth.key.data = auth_key;
10144         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10145
10146         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
10147                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10148                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
10149         } else {
10150                 ut_params->auth_xform.next = &ut_params->cipher_xform;
10151
10152                 /* Setup Cipher Parameters */
10153                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10154                 ut_params->cipher_xform.next = NULL;
10155                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10156                 ut_params->cipher_xform.cipher.op = cipher_op;
10157                 ut_params->cipher_xform.cipher.key.data = cipher_key;
10158                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10159                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10160                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10161         }
10162
10163         /* Create Crypto session*/
10164         ut_params->sess = rte_cryptodev_sym_session_create(
10165                         ts_params->session_mpool);
10166
10167         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10168                                 &ut_params->auth_xform,
10169                                 ts_params->session_priv_mpool);
10170
10171         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10172
10173         return 0;
10174 }
10175
10176 static int
10177 create_auth_operation(struct crypto_testsuite_params *ts_params,
10178                 struct crypto_unittest_params *ut_params,
10179                 const struct test_crypto_vector *reference,
10180                 unsigned int auth_generate)
10181 {
10182         /* Generate Crypto op data structure */
10183         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10184                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10185         TEST_ASSERT_NOT_NULL(ut_params->op,
10186                         "Failed to allocate pktmbuf offload");
10187
10188         /* Set crypto operation data parameters */
10189         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10190
10191         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10192
10193         /* set crypto operation source mbuf */
10194         sym_op->m_src = ut_params->ibuf;
10195
10196         /* digest */
10197         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10198                         ut_params->ibuf, reference->digest.len);
10199
10200         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10201                         "no room to append auth tag");
10202
10203         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10204                         ut_params->ibuf, reference->plaintext.len);
10205
10206         if (auth_generate)
10207                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10208         else
10209                 memcpy(sym_op->auth.digest.data,
10210                                 reference->digest.data,
10211                                 reference->digest.len);
10212
10213         debug_hexdump(stdout, "digest:",
10214                         sym_op->auth.digest.data,
10215                         reference->digest.len);
10216
10217         sym_op->auth.data.length = reference->plaintext.len;
10218         sym_op->auth.data.offset = 0;
10219
10220         return 0;
10221 }
10222
10223 static int
10224 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
10225                 struct crypto_unittest_params *ut_params,
10226                 const struct test_crypto_vector *reference,
10227                 unsigned int auth_generate)
10228 {
10229         /* Generate Crypto op data structure */
10230         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10231                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10232         TEST_ASSERT_NOT_NULL(ut_params->op,
10233                         "Failed to allocate pktmbuf offload");
10234
10235         /* Set crypto operation data parameters */
10236         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10237
10238         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10239
10240         /* set crypto operation source mbuf */
10241         sym_op->m_src = ut_params->ibuf;
10242
10243         /* digest */
10244         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10245                         ut_params->ibuf, reference->digest.len);
10246
10247         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10248                         "no room to append auth tag");
10249
10250         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10251                         ut_params->ibuf, reference->ciphertext.len);
10252
10253         if (auth_generate)
10254                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10255         else
10256                 memcpy(sym_op->auth.digest.data,
10257                                 reference->digest.data,
10258                                 reference->digest.len);
10259
10260         debug_hexdump(stdout, "digest:",
10261                         sym_op->auth.digest.data,
10262                         reference->digest.len);
10263
10264         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10265                         reference->iv.data, reference->iv.len);
10266
10267         sym_op->cipher.data.length = 0;
10268         sym_op->cipher.data.offset = 0;
10269
10270         sym_op->auth.data.length = reference->plaintext.len;
10271         sym_op->auth.data.offset = 0;
10272
10273         return 0;
10274 }
10275
10276 static int
10277 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
10278                 struct crypto_unittest_params *ut_params,
10279                 const struct test_crypto_vector *reference,
10280                 unsigned int auth_generate)
10281 {
10282         /* Generate Crypto op data structure */
10283         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10284                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10285         TEST_ASSERT_NOT_NULL(ut_params->op,
10286                         "Failed to allocate pktmbuf offload");
10287
10288         /* Set crypto operation data parameters */
10289         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10290
10291         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10292
10293         /* set crypto operation source mbuf */
10294         sym_op->m_src = ut_params->ibuf;
10295
10296         /* digest */
10297         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10298                         ut_params->ibuf, reference->digest.len);
10299
10300         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10301                         "no room to append auth tag");
10302
10303         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10304                         ut_params->ibuf, reference->ciphertext.len);
10305
10306         if (auth_generate)
10307                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10308         else
10309                 memcpy(sym_op->auth.digest.data,
10310                                 reference->digest.data,
10311                                 reference->digest.len);
10312
10313         debug_hexdump(stdout, "digest:",
10314                         sym_op->auth.digest.data,
10315                         reference->digest.len);
10316
10317         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10318                         reference->iv.data, reference->iv.len);
10319
10320         sym_op->cipher.data.length = reference->cipher_len;
10321         sym_op->cipher.data.offset = reference->cipher_offset;
10322
10323         sym_op->auth.data.length = reference->plaintext.len;
10324         sym_op->auth.data.offset = reference->auth_offset;
10325
10326         return 0;
10327 }
10328
10329 static int
10330 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10331                 struct crypto_unittest_params *ut_params,
10332                 const struct test_crypto_vector *reference)
10333 {
10334         return create_auth_operation(ts_params, ut_params, reference, 0);
10335 }
10336
10337 static int
10338 create_auth_verify_GMAC_operation(
10339                 struct crypto_testsuite_params *ts_params,
10340                 struct crypto_unittest_params *ut_params,
10341                 const struct test_crypto_vector *reference)
10342 {
10343         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
10344 }
10345
10346 static int
10347 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10348                 struct crypto_unittest_params *ut_params,
10349                 const struct test_crypto_vector *reference)
10350 {
10351         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
10352 }
10353
10354 static int
10355 test_authentication_verify_fail_when_data_corruption(
10356                 struct crypto_testsuite_params *ts_params,
10357                 struct crypto_unittest_params *ut_params,
10358                 const struct test_crypto_vector *reference,
10359                 unsigned int data_corrupted)
10360 {
10361         int retval;
10362
10363         uint8_t *plaintext;
10364
10365         /* Verify the capabilities */
10366         struct rte_cryptodev_sym_capability_idx cap_idx;
10367         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10368         cap_idx.algo.auth = reference->auth_algo;
10369         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10370                         &cap_idx) == NULL)
10371                 return -ENOTSUP;
10372
10373         /* Create session */
10374         retval = create_auth_session(ut_params,
10375                         ts_params->valid_devs[0],
10376                         reference,
10377                         RTE_CRYPTO_AUTH_OP_VERIFY);
10378         if (retval < 0)
10379                 return retval;
10380
10381         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10382         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10383                         "Failed to allocate input buffer in mempool");
10384
10385         /* clear mbuf payload */
10386         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10387                         rte_pktmbuf_tailroom(ut_params->ibuf));
10388
10389         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10390                         reference->plaintext.len);
10391         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10392         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10393
10394         debug_hexdump(stdout, "plaintext:", plaintext,
10395                 reference->plaintext.len);
10396
10397         /* Create operation */
10398         retval = create_auth_verify_operation(ts_params, ut_params, reference);
10399
10400         if (retval < 0)
10401                 return retval;
10402
10403         if (data_corrupted)
10404                 data_corruption(plaintext);
10405         else
10406                 tag_corruption(plaintext, reference->plaintext.len);
10407
10408         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10409                         ut_params->op);
10410
10411         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10412
10413         return 0;
10414 }
10415
10416 static int
10417 test_authentication_verify_GMAC_fail_when_corruption(
10418                 struct crypto_testsuite_params *ts_params,
10419                 struct crypto_unittest_params *ut_params,
10420                 const struct test_crypto_vector *reference,
10421                 unsigned int data_corrupted)
10422 {
10423         int retval;
10424         uint8_t *plaintext;
10425
10426         /* Verify the capabilities */
10427         struct rte_cryptodev_sym_capability_idx cap_idx;
10428         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10429         cap_idx.algo.auth = reference->auth_algo;
10430         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10431                         &cap_idx) == NULL)
10432                 return -ENOTSUP;
10433
10434         /* Create session */
10435         retval = create_auth_cipher_session(ut_params,
10436                         ts_params->valid_devs[0],
10437                         reference,
10438                         RTE_CRYPTO_AUTH_OP_VERIFY,
10439                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10440         if (retval < 0)
10441                 return retval;
10442
10443         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10444         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10445                         "Failed to allocate input buffer in mempool");
10446
10447         /* clear mbuf payload */
10448         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10449                         rte_pktmbuf_tailroom(ut_params->ibuf));
10450
10451         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10452                         reference->plaintext.len);
10453         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10454         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10455
10456         debug_hexdump(stdout, "plaintext:", plaintext,
10457                 reference->plaintext.len);
10458
10459         /* Create operation */
10460         retval = create_auth_verify_GMAC_operation(ts_params,
10461                         ut_params,
10462                         reference);
10463
10464         if (retval < 0)
10465                 return retval;
10466
10467         if (data_corrupted)
10468                 data_corruption(plaintext);
10469         else
10470                 tag_corruption(plaintext, reference->aad.len);
10471
10472         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10473                         ut_params->op);
10474
10475         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10476
10477         return 0;
10478 }
10479
10480 static int
10481 test_authenticated_decryption_fail_when_corruption(
10482                 struct crypto_testsuite_params *ts_params,
10483                 struct crypto_unittest_params *ut_params,
10484                 const struct test_crypto_vector *reference,
10485                 unsigned int data_corrupted)
10486 {
10487         int retval;
10488
10489         uint8_t *ciphertext;
10490
10491         /* Verify the capabilities */
10492         struct rte_cryptodev_sym_capability_idx cap_idx;
10493         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10494         cap_idx.algo.auth = reference->auth_algo;
10495         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10496                         &cap_idx) == NULL)
10497                 return -ENOTSUP;
10498         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10499         cap_idx.algo.cipher = reference->crypto_algo;
10500         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10501                         &cap_idx) == NULL)
10502                 return -ENOTSUP;
10503
10504         /* Create session */
10505         retval = create_auth_cipher_session(ut_params,
10506                         ts_params->valid_devs[0],
10507                         reference,
10508                         RTE_CRYPTO_AUTH_OP_VERIFY,
10509                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10510         if (retval < 0)
10511                 return retval;
10512
10513         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10514         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10515                         "Failed to allocate input buffer in mempool");
10516
10517         /* clear mbuf payload */
10518         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10519                         rte_pktmbuf_tailroom(ut_params->ibuf));
10520
10521         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10522                         reference->ciphertext.len);
10523         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10524         memcpy(ciphertext, reference->ciphertext.data,
10525                         reference->ciphertext.len);
10526
10527         /* Create operation */
10528         retval = create_cipher_auth_verify_operation(ts_params,
10529                         ut_params,
10530                         reference);
10531
10532         if (retval < 0)
10533                 return retval;
10534
10535         if (data_corrupted)
10536                 data_corruption(ciphertext);
10537         else
10538                 tag_corruption(ciphertext, reference->ciphertext.len);
10539
10540         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10541                         ut_params->op);
10542
10543         TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10544
10545         return 0;
10546 }
10547
10548 static int
10549 test_authenticated_encryt_with_esn(
10550                 struct crypto_testsuite_params *ts_params,
10551                 struct crypto_unittest_params *ut_params,
10552                 const struct test_crypto_vector *reference)
10553 {
10554         int retval;
10555
10556         uint8_t *authciphertext, *plaintext, *auth_tag;
10557         uint16_t plaintext_pad_len;
10558         uint8_t cipher_key[reference->cipher_key.len + 1];
10559         uint8_t auth_key[reference->auth_key.len + 1];
10560
10561         /* Verify the capabilities */
10562         struct rte_cryptodev_sym_capability_idx cap_idx;
10563         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10564         cap_idx.algo.auth = reference->auth_algo;
10565         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10566                         &cap_idx) == NULL)
10567                 return -ENOTSUP;
10568         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10569         cap_idx.algo.cipher = reference->crypto_algo;
10570         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10571                         &cap_idx) == NULL)
10572                 return -ENOTSUP;
10573
10574         /* Create session */
10575         memcpy(cipher_key, reference->cipher_key.data,
10576                         reference->cipher_key.len);
10577         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10578
10579         /* Setup Cipher Parameters */
10580         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10581         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10582         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10583         ut_params->cipher_xform.cipher.key.data = cipher_key;
10584         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10585         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10586         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10587
10588         ut_params->cipher_xform.next = &ut_params->auth_xform;
10589
10590         /* Setup Authentication Parameters */
10591         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10592         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10593         ut_params->auth_xform.auth.algo = reference->auth_algo;
10594         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10595         ut_params->auth_xform.auth.key.data = auth_key;
10596         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10597         ut_params->auth_xform.next = NULL;
10598
10599         /* Create Crypto session*/
10600         ut_params->sess = rte_cryptodev_sym_session_create(
10601                         ts_params->session_mpool);
10602
10603         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10604                                 ut_params->sess,
10605                                 &ut_params->cipher_xform,
10606                                 ts_params->session_priv_mpool);
10607
10608         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10609
10610         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10611         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10612                         "Failed to allocate input buffer in mempool");
10613
10614         /* clear mbuf payload */
10615         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10616                         rte_pktmbuf_tailroom(ut_params->ibuf));
10617
10618         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10619                         reference->plaintext.len);
10620         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10621         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10622
10623         /* Create operation */
10624         retval = create_cipher_auth_operation(ts_params,
10625                         ut_params,
10626                         reference, 0);
10627
10628         if (retval < 0)
10629                 return retval;
10630
10631         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10632                         ut_params->op);
10633
10634         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
10635
10636         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10637                         "crypto op processing failed");
10638
10639         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
10640
10641         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10642                         ut_params->op->sym->auth.data.offset);
10643         auth_tag = authciphertext + plaintext_pad_len;
10644         debug_hexdump(stdout, "ciphertext:", authciphertext,
10645                         reference->ciphertext.len);
10646         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
10647
10648         /* Validate obuf */
10649         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10650                         authciphertext,
10651                         reference->ciphertext.data,
10652                         reference->ciphertext.len,
10653                         "Ciphertext data not as expected");
10654
10655         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10656                         auth_tag,
10657                         reference->digest.data,
10658                         reference->digest.len,
10659                         "Generated digest not as expected");
10660
10661         return TEST_SUCCESS;
10662
10663 }
10664
10665 static int
10666 test_authenticated_decrypt_with_esn(
10667                 struct crypto_testsuite_params *ts_params,
10668                 struct crypto_unittest_params *ut_params,
10669                 const struct test_crypto_vector *reference)
10670 {
10671         int retval;
10672
10673         uint8_t *ciphertext;
10674         uint8_t cipher_key[reference->cipher_key.len + 1];
10675         uint8_t auth_key[reference->auth_key.len + 1];
10676
10677         /* Verify the capabilities */
10678         struct rte_cryptodev_sym_capability_idx cap_idx;
10679         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10680         cap_idx.algo.auth = reference->auth_algo;
10681         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10682                         &cap_idx) == NULL)
10683                 return -ENOTSUP;
10684         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10685         cap_idx.algo.cipher = reference->crypto_algo;
10686         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10687                         &cap_idx) == NULL)
10688                 return -ENOTSUP;
10689
10690         /* Create session */
10691         memcpy(cipher_key, reference->cipher_key.data,
10692                         reference->cipher_key.len);
10693         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10694
10695         /* Setup Authentication Parameters */
10696         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10697         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
10698         ut_params->auth_xform.auth.algo = reference->auth_algo;
10699         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10700         ut_params->auth_xform.auth.key.data = auth_key;
10701         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10702         ut_params->auth_xform.next = &ut_params->cipher_xform;
10703
10704         /* Setup Cipher Parameters */
10705         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10706         ut_params->cipher_xform.next = NULL;
10707         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10708         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10709         ut_params->cipher_xform.cipher.key.data = cipher_key;
10710         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10711         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10712         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10713
10714         /* Create Crypto session*/
10715         ut_params->sess = rte_cryptodev_sym_session_create(
10716                         ts_params->session_mpool);
10717
10718         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10719                                 ut_params->sess,
10720                                 &ut_params->auth_xform,
10721                                 ts_params->session_priv_mpool);
10722
10723         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10724
10725         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10726         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10727                         "Failed to allocate input buffer in mempool");
10728
10729         /* clear mbuf payload */
10730         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10731                         rte_pktmbuf_tailroom(ut_params->ibuf));
10732
10733         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10734                         reference->ciphertext.len);
10735         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10736         memcpy(ciphertext, reference->ciphertext.data,
10737                         reference->ciphertext.len);
10738
10739         /* Create operation */
10740         retval = create_cipher_auth_verify_operation(ts_params,
10741                         ut_params,
10742                         reference);
10743
10744         if (retval < 0)
10745                 return retval;
10746
10747         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10748                         ut_params->op);
10749
10750         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10751         TEST_ASSERT_EQUAL(ut_params->op->status,
10752                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10753                         "crypto op processing passed");
10754
10755         ut_params->obuf = ut_params->op->sym->m_src;
10756         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
10757
10758         return 0;
10759 }
10760
10761 static int
10762 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
10763                 const struct aead_test_data *tdata,
10764                 void *digest_mem, uint64_t digest_phys)
10765 {
10766         struct crypto_testsuite_params *ts_params = &testsuite_params;
10767         struct crypto_unittest_params *ut_params = &unittest_params;
10768
10769         const unsigned int auth_tag_len = tdata->auth_tag.len;
10770         const unsigned int iv_len = tdata->iv.len;
10771         unsigned int aad_len = tdata->aad.len;
10772         unsigned int aad_len_pad = 0;
10773
10774         /* Generate Crypto op data structure */
10775         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10776                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10777         TEST_ASSERT_NOT_NULL(ut_params->op,
10778                 "Failed to allocate symmetric crypto operation struct");
10779
10780         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10781
10782         sym_op->aead.digest.data = digest_mem;
10783
10784         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
10785                         "no room to append digest");
10786
10787         sym_op->aead.digest.phys_addr = digest_phys;
10788
10789         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
10790                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
10791                                 auth_tag_len);
10792                 debug_hexdump(stdout, "digest:",
10793                                 sym_op->aead.digest.data,
10794                                 auth_tag_len);
10795         }
10796
10797         /* Append aad data */
10798         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
10799                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10800                                 uint8_t *, IV_OFFSET);
10801
10802                 /* Copy IV 1 byte after the IV pointer, according to the API */
10803                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
10804
10805                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
10806
10807                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
10808                                 ut_params->ibuf, aad_len);
10809                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
10810                                 "no room to prepend aad");
10811                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
10812                                 ut_params->ibuf);
10813
10814                 memset(sym_op->aead.aad.data, 0, aad_len);
10815                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
10816                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
10817
10818                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
10819                 debug_hexdump(stdout, "aad:",
10820                                 sym_op->aead.aad.data, aad_len);
10821         } else {
10822                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10823                                 uint8_t *, IV_OFFSET);
10824
10825                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
10826
10827                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
10828
10829                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
10830                                 ut_params->ibuf, aad_len_pad);
10831                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
10832                                 "no room to prepend aad");
10833                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
10834                                 ut_params->ibuf);
10835
10836                 memset(sym_op->aead.aad.data, 0, aad_len);
10837                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
10838
10839                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
10840                 debug_hexdump(stdout, "aad:",
10841                                 sym_op->aead.aad.data, aad_len);
10842         }
10843
10844         sym_op->aead.data.length = tdata->plaintext.len;
10845         sym_op->aead.data.offset = aad_len_pad;
10846
10847         return 0;
10848 }
10849
10850 #define SGL_MAX_NO      16
10851
10852 static int
10853 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
10854                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
10855 {
10856         struct crypto_testsuite_params *ts_params = &testsuite_params;
10857         struct crypto_unittest_params *ut_params = &unittest_params;
10858         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
10859         int retval;
10860         int to_trn = 0;
10861         int to_trn_tbl[SGL_MAX_NO];
10862         int segs = 1;
10863         unsigned int trn_data = 0;
10864         uint8_t *plaintext, *ciphertext, *auth_tag;
10865         struct rte_cryptodev_info dev_info;
10866
10867         /* Verify the capabilities */
10868         struct rte_cryptodev_sym_capability_idx cap_idx;
10869         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10870         cap_idx.algo.aead = tdata->algo;
10871         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10872                         &cap_idx) == NULL)
10873                 return -ENOTSUP;
10874
10875         /* Detailed check for the particular SGL support flag */
10876         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10877         if (!oop) {
10878                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
10879                 if (sgl_in && (!(dev_info.feature_flags &
10880                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
10881                         return -ENOTSUP;
10882         } else {
10883                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
10884                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
10885                                 tdata->plaintext.len;
10886                 if (sgl_in && !sgl_out) {
10887                         if (!(dev_info.feature_flags &
10888                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
10889                                 return -ENOTSUP;
10890                 } else if (!sgl_in && sgl_out) {
10891                         if (!(dev_info.feature_flags &
10892                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
10893                                 return -ENOTSUP;
10894                 } else if (sgl_in && sgl_out) {
10895                         if (!(dev_info.feature_flags &
10896                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
10897                                 return -ENOTSUP;
10898                 }
10899         }
10900
10901         if (fragsz > tdata->plaintext.len)
10902                 fragsz = tdata->plaintext.len;
10903
10904         uint16_t plaintext_len = fragsz;
10905         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
10906
10907         if (fragsz_oop > tdata->plaintext.len)
10908                 frag_size_oop = tdata->plaintext.len;
10909
10910         int ecx = 0;
10911         void *digest_mem = NULL;
10912
10913         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
10914
10915         if (tdata->plaintext.len % fragsz != 0) {
10916                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
10917                         return 1;
10918         }       else {
10919                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
10920                         return 1;
10921         }
10922
10923         /*
10924          * For out-op-place we need to alloc another mbuf
10925          */
10926         if (oop) {
10927                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10928                 rte_pktmbuf_append(ut_params->obuf,
10929                                 frag_size_oop + prepend_len);
10930                 buf_oop = ut_params->obuf;
10931         }
10932
10933         /* Create AEAD session */
10934         retval = create_aead_session(ts_params->valid_devs[0],
10935                         tdata->algo,
10936                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10937                         tdata->key.data, tdata->key.len,
10938                         tdata->aad.len, tdata->auth_tag.len,
10939                         tdata->iv.len);
10940         if (retval < 0)
10941                 return retval;
10942
10943         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10944
10945         /* clear mbuf payload */
10946         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10947                         rte_pktmbuf_tailroom(ut_params->ibuf));
10948
10949         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10950                         plaintext_len);
10951
10952         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
10953
10954         trn_data += plaintext_len;
10955
10956         buf = ut_params->ibuf;
10957
10958         /*
10959          * Loop until no more fragments
10960          */
10961
10962         while (trn_data < tdata->plaintext.len) {
10963                 ++segs;
10964                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
10965                                 (tdata->plaintext.len - trn_data) : fragsz;
10966
10967                 to_trn_tbl[ecx++] = to_trn;
10968
10969                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10970                 buf = buf->next;
10971
10972                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
10973                                 rte_pktmbuf_tailroom(buf));
10974
10975                 /* OOP */
10976                 if (oop && !fragsz_oop) {
10977                         buf_last_oop = buf_oop->next =
10978                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
10979                         buf_oop = buf_oop->next;
10980                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
10981                                         0, rte_pktmbuf_tailroom(buf_oop));
10982                         rte_pktmbuf_append(buf_oop, to_trn);
10983                 }
10984
10985                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
10986                                 to_trn);
10987
10988                 memcpy(plaintext, tdata->plaintext.data + trn_data,
10989                                 to_trn);
10990                 trn_data += to_trn;
10991                 if (trn_data  == tdata->plaintext.len) {
10992                         if (oop) {
10993                                 if (!fragsz_oop)
10994                                         digest_mem = rte_pktmbuf_append(buf_oop,
10995                                                 tdata->auth_tag.len);
10996                         } else
10997                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
10998                                         tdata->auth_tag.len);
10999                 }
11000         }
11001
11002         uint64_t digest_phys = 0;
11003
11004         ut_params->ibuf->nb_segs = segs;
11005
11006         segs = 1;
11007         if (fragsz_oop && oop) {
11008                 to_trn = 0;
11009                 ecx = 0;
11010
11011                 if (frag_size_oop == tdata->plaintext.len) {
11012                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
11013                                 tdata->auth_tag.len);
11014
11015                         digest_phys = rte_pktmbuf_iova_offset(
11016                                         ut_params->obuf,
11017                                         tdata->plaintext.len + prepend_len);
11018                 }
11019
11020                 trn_data = frag_size_oop;
11021                 while (trn_data < tdata->plaintext.len) {
11022                         ++segs;
11023                         to_trn =
11024                                 (tdata->plaintext.len - trn_data <
11025                                                 frag_size_oop) ?
11026                                 (tdata->plaintext.len - trn_data) :
11027                                                 frag_size_oop;
11028
11029                         to_trn_tbl[ecx++] = to_trn;
11030
11031                         buf_last_oop = buf_oop->next =
11032                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11033                         buf_oop = buf_oop->next;
11034                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11035                                         0, rte_pktmbuf_tailroom(buf_oop));
11036                         rte_pktmbuf_append(buf_oop, to_trn);
11037
11038                         trn_data += to_trn;
11039
11040                         if (trn_data  == tdata->plaintext.len) {
11041                                 digest_mem = rte_pktmbuf_append(buf_oop,
11042                                         tdata->auth_tag.len);
11043                         }
11044                 }
11045
11046                 ut_params->obuf->nb_segs = segs;
11047         }
11048
11049         /*
11050          * Place digest at the end of the last buffer
11051          */
11052         if (!digest_phys)
11053                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11054         if (oop && buf_last_oop)
11055                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
11056
11057         if (!digest_mem && !oop) {
11058                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11059                                 + tdata->auth_tag.len);
11060                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11061                                 tdata->plaintext.len);
11062         }
11063
11064         /* Create AEAD operation */
11065         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
11066                         tdata, digest_mem, digest_phys);
11067
11068         if (retval < 0)
11069                 return retval;
11070
11071         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11072
11073         ut_params->op->sym->m_src = ut_params->ibuf;
11074         if (oop)
11075                 ut_params->op->sym->m_dst = ut_params->obuf;
11076
11077         /* Process crypto operation */
11078         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11079                         ut_params->op), "failed to process sym crypto op");
11080
11081         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11082                         "crypto op processing failed");
11083
11084
11085         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11086                         uint8_t *, prepend_len);
11087         if (oop) {
11088                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11089                                 uint8_t *, prepend_len);
11090         }
11091
11092         if (fragsz_oop)
11093                 fragsz = fragsz_oop;
11094
11095         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11096                         ciphertext,
11097                         tdata->ciphertext.data,
11098                         fragsz,
11099                         "Ciphertext data not as expected");
11100
11101         buf = ut_params->op->sym->m_src->next;
11102         if (oop)
11103                 buf = ut_params->op->sym->m_dst->next;
11104
11105         unsigned int off = fragsz;
11106
11107         ecx = 0;
11108         while (buf) {
11109                 ciphertext = rte_pktmbuf_mtod(buf,
11110                                 uint8_t *);
11111
11112                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
11113                                 ciphertext,
11114                                 tdata->ciphertext.data + off,
11115                                 to_trn_tbl[ecx],
11116                                 "Ciphertext data not as expected");
11117
11118                 off += to_trn_tbl[ecx++];
11119                 buf = buf->next;
11120         }
11121
11122         auth_tag = digest_mem;
11123         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11124                         auth_tag,
11125                         tdata->auth_tag.data,
11126                         tdata->auth_tag.len,
11127                         "Generated auth tag not as expected");
11128
11129         return 0;
11130 }
11131
11132 static int
11133 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
11134 {
11135         return test_authenticated_encryption_SGL(
11136                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
11137 }
11138
11139 static int
11140 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
11141 {
11142         return test_authenticated_encryption_SGL(
11143                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
11144 }
11145
11146 static int
11147 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
11148 {
11149         return test_authenticated_encryption_SGL(
11150                         &gcm_test_case_8, OUT_OF_PLACE, 400,
11151                         gcm_test_case_8.plaintext.len);
11152 }
11153
11154 static int
11155 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
11156 {
11157         /* This test is not for OPENSSL PMD */
11158         if (gbl_driver_id == rte_cryptodev_driver_id_get(
11159                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
11160                 return -ENOTSUP;
11161
11162         return test_authenticated_encryption_SGL(
11163                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
11164 }
11165
11166 static int
11167 test_authentication_verify_fail_when_data_corrupted(
11168                 struct crypto_testsuite_params *ts_params,
11169                 struct crypto_unittest_params *ut_params,
11170                 const struct test_crypto_vector *reference)
11171 {
11172         return test_authentication_verify_fail_when_data_corruption(
11173                         ts_params, ut_params, reference, 1);
11174 }
11175
11176 static int
11177 test_authentication_verify_fail_when_tag_corrupted(
11178                 struct crypto_testsuite_params *ts_params,
11179                 struct crypto_unittest_params *ut_params,
11180                 const struct test_crypto_vector *reference)
11181 {
11182         return test_authentication_verify_fail_when_data_corruption(
11183                         ts_params, ut_params, reference, 0);
11184 }
11185
11186 static int
11187 test_authentication_verify_GMAC_fail_when_data_corrupted(
11188                 struct crypto_testsuite_params *ts_params,
11189                 struct crypto_unittest_params *ut_params,
11190                 const struct test_crypto_vector *reference)
11191 {
11192         return test_authentication_verify_GMAC_fail_when_corruption(
11193                         ts_params, ut_params, reference, 1);
11194 }
11195
11196 static int
11197 test_authentication_verify_GMAC_fail_when_tag_corrupted(
11198                 struct crypto_testsuite_params *ts_params,
11199                 struct crypto_unittest_params *ut_params,
11200                 const struct test_crypto_vector *reference)
11201 {
11202         return test_authentication_verify_GMAC_fail_when_corruption(
11203                         ts_params, ut_params, reference, 0);
11204 }
11205
11206 static int
11207 test_authenticated_decryption_fail_when_data_corrupted(
11208                 struct crypto_testsuite_params *ts_params,
11209                 struct crypto_unittest_params *ut_params,
11210                 const struct test_crypto_vector *reference)
11211 {
11212         return test_authenticated_decryption_fail_when_corruption(
11213                         ts_params, ut_params, reference, 1);
11214 }
11215
11216 static int
11217 test_authenticated_decryption_fail_when_tag_corrupted(
11218                 struct crypto_testsuite_params *ts_params,
11219                 struct crypto_unittest_params *ut_params,
11220                 const struct test_crypto_vector *reference)
11221 {
11222         return test_authenticated_decryption_fail_when_corruption(
11223                         ts_params, ut_params, reference, 0);
11224 }
11225
11226 static int
11227 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
11228 {
11229         return test_authentication_verify_fail_when_data_corrupted(
11230                         &testsuite_params, &unittest_params,
11231                         &hmac_sha1_test_crypto_vector);
11232 }
11233
11234 static int
11235 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
11236 {
11237         return test_authentication_verify_fail_when_tag_corrupted(
11238                         &testsuite_params, &unittest_params,
11239                         &hmac_sha1_test_crypto_vector);
11240 }
11241
11242 static int
11243 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
11244 {
11245         return test_authentication_verify_GMAC_fail_when_data_corrupted(
11246                         &testsuite_params, &unittest_params,
11247                         &aes128_gmac_test_vector);
11248 }
11249
11250 static int
11251 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
11252 {
11253         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
11254                         &testsuite_params, &unittest_params,
11255                         &aes128_gmac_test_vector);
11256 }
11257
11258 static int
11259 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
11260 {
11261         return test_authenticated_decryption_fail_when_data_corrupted(
11262                         &testsuite_params,
11263                         &unittest_params,
11264                         &aes128cbc_hmac_sha1_test_vector);
11265 }
11266
11267 static int
11268 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
11269 {
11270         return test_authenticated_decryption_fail_when_tag_corrupted(
11271                         &testsuite_params,
11272                         &unittest_params,
11273                         &aes128cbc_hmac_sha1_test_vector);
11274 }
11275
11276 static int
11277 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11278 {
11279         return test_authenticated_encryt_with_esn(
11280                         &testsuite_params,
11281                         &unittest_params,
11282                         &aes128cbc_hmac_sha1_aad_test_vector);
11283 }
11284
11285 static int
11286 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11287 {
11288         return test_authenticated_decrypt_with_esn(
11289                         &testsuite_params,
11290                         &unittest_params,
11291                         &aes128cbc_hmac_sha1_aad_test_vector);
11292 }
11293
11294 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
11295
11296 /* global AESNI slave IDs for the scheduler test */
11297 uint8_t aesni_ids[2];
11298
11299 static int
11300 test_scheduler_attach_slave_op(void)
11301 {
11302         struct crypto_testsuite_params *ts_params = &testsuite_params;
11303         uint8_t sched_id = ts_params->valid_devs[0];
11304         uint32_t nb_devs, i, nb_devs_attached = 0;
11305         int ret;
11306         char vdev_name[32];
11307
11308         /* create 2 AESNI_MB if necessary */
11309         nb_devs = rte_cryptodev_device_count_by_driver(
11310                         rte_cryptodev_driver_id_get(
11311                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
11312         if (nb_devs < 2) {
11313                 for (i = nb_devs; i < 2; i++) {
11314                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
11315                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
11316                                         i);
11317                         ret = rte_vdev_init(vdev_name, NULL);
11318
11319                         TEST_ASSERT(ret == 0,
11320                                 "Failed to create instance %u of"
11321                                 " pmd : %s",
11322                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11323                 }
11324         }
11325
11326         /* attach 2 AESNI_MB cdevs */
11327         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
11328                         i++) {
11329                 struct rte_cryptodev_info info;
11330                 unsigned int session_size;
11331
11332                 rte_cryptodev_info_get(i, &info);
11333                 if (info.driver_id != rte_cryptodev_driver_id_get(
11334                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
11335                         continue;
11336
11337                 session_size = rte_cryptodev_sym_get_private_session_size(i);
11338                 /*
11339                  * Create the session mempool again, since now there are new devices
11340                  * to use the mempool.
11341                  */
11342                 if (ts_params->session_mpool) {
11343                         rte_mempool_free(ts_params->session_mpool);
11344                         ts_params->session_mpool = NULL;
11345                 }
11346                 if (ts_params->session_priv_mpool) {
11347                         rte_mempool_free(ts_params->session_priv_mpool);
11348                         ts_params->session_priv_mpool = NULL;
11349                 }
11350
11351                 if (info.sym.max_nb_sessions != 0 &&
11352                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
11353                         RTE_LOG(ERR, USER1,
11354                                         "Device does not support "
11355                                         "at least %u sessions\n",
11356                                         MAX_NB_SESSIONS);
11357                         return TEST_FAILED;
11358                 }
11359                 /*
11360                  * Create mempool with maximum number of sessions,
11361                  * to include the session headers
11362                  */
11363                 if (ts_params->session_mpool == NULL) {
11364                         ts_params->session_mpool =
11365                                 rte_cryptodev_sym_session_pool_create(
11366                                                 "test_sess_mp",
11367                                                 MAX_NB_SESSIONS, 0, 0, 0,
11368                                                 SOCKET_ID_ANY);
11369                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
11370                                         "session mempool allocation failed");
11371                 }
11372
11373                 /*
11374                  * Create mempool with maximum number of sessions,
11375                  * to include device specific session private data
11376                  */
11377                 if (ts_params->session_priv_mpool == NULL) {
11378                         ts_params->session_priv_mpool = rte_mempool_create(
11379                                         "test_sess_mp_priv",
11380                                         MAX_NB_SESSIONS,
11381                                         session_size,
11382                                         0, 0, NULL, NULL, NULL,
11383                                         NULL, SOCKET_ID_ANY,
11384                                         0);
11385
11386                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
11387                                         "session mempool allocation failed");
11388                 }
11389
11390                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
11391                 ts_params->qp_conf.mp_session_private =
11392                                 ts_params->session_priv_mpool;
11393
11394                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
11395                                 (uint8_t)i);
11396
11397                 TEST_ASSERT(ret == 0,
11398                         "Failed to attach device %u of pmd : %s", i,
11399                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11400
11401                 aesni_ids[nb_devs_attached] = (uint8_t)i;
11402
11403                 nb_devs_attached++;
11404         }
11405
11406         return 0;
11407 }
11408
11409 static int
11410 test_scheduler_detach_slave_op(void)
11411 {
11412         struct crypto_testsuite_params *ts_params = &testsuite_params;
11413         uint8_t sched_id = ts_params->valid_devs[0];
11414         uint32_t i;
11415         int ret;
11416
11417         for (i = 0; i < 2; i++) {
11418                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
11419                                 aesni_ids[i]);
11420                 TEST_ASSERT(ret == 0,
11421                         "Failed to detach device %u", aesni_ids[i]);
11422         }
11423
11424         return 0;
11425 }
11426
11427 static int
11428 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
11429 {
11430         struct crypto_testsuite_params *ts_params = &testsuite_params;
11431         uint8_t sched_id = ts_params->valid_devs[0];
11432         /* set mode */
11433         return rte_cryptodev_scheduler_mode_set(sched_id,
11434                 scheduler_mode);
11435 }
11436
11437 static int
11438 test_scheduler_mode_roundrobin_op(void)
11439 {
11440         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
11441                         0, "Failed to set roundrobin mode");
11442         return 0;
11443
11444 }
11445
11446 static int
11447 test_scheduler_mode_multicore_op(void)
11448 {
11449         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
11450                         0, "Failed to set multicore mode");
11451
11452         return 0;
11453 }
11454
11455 static int
11456 test_scheduler_mode_failover_op(void)
11457 {
11458         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
11459                         0, "Failed to set failover mode");
11460
11461         return 0;
11462 }
11463
11464 static int
11465 test_scheduler_mode_pkt_size_distr_op(void)
11466 {
11467         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
11468                         0, "Failed to set pktsize mode");
11469
11470         return 0;
11471 }
11472
11473 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
11474         .suite_name = "Crypto Device Scheduler Unit Test Suite",
11475         .setup = testsuite_setup,
11476         .teardown = testsuite_teardown,
11477         .unit_test_cases = {
11478                 /* Multi Core */
11479                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11480                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
11481                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11482                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11483                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11484                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11485
11486                 /* Round Robin */
11487                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11488                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
11489                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11490                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11491                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11492                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11493
11494                 /* Fail over */
11495                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11496                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
11497                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11498                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11499                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11500                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11501
11502                 /* PKT SIZE */
11503                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11504                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
11505                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11506                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11507                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11508                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11509
11510                 TEST_CASES_END() /**< NULL terminate unit test array */
11511         }
11512 };
11513
11514 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
11515
11516 static struct unit_test_suite cryptodev_testsuite  = {
11517         .suite_name = "Crypto Unit Test Suite",
11518         .setup = testsuite_setup,
11519         .teardown = testsuite_teardown,
11520         .unit_test_cases = {
11521                 TEST_CASE_ST(ut_setup, ut_teardown,
11522                                 test_device_configure_invalid_dev_id),
11523                 TEST_CASE_ST(ut_setup, ut_teardown,
11524                                 test_device_configure_invalid_queue_pair_ids),
11525                 TEST_CASE_ST(ut_setup, ut_teardown,
11526                                 test_queue_pair_descriptor_setup),
11527
11528                 TEST_CASE_ST(ut_setup, ut_teardown,
11529                                 test_multi_session),
11530                 TEST_CASE_ST(ut_setup, ut_teardown,
11531                                 test_multi_session_random_usage),
11532
11533                 TEST_CASE_ST(ut_setup, ut_teardown,
11534                         test_null_invalid_operation),
11535                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
11536
11537                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11538                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11539                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
11540                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
11541                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
11542                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
11543                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
11544                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11545                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
11546
11547                 /** AES CCM Authenticated Encryption 128 bits key */
11548                 TEST_CASE_ST(ut_setup, ut_teardown,
11549                         test_AES_CCM_authenticated_encryption_test_case_128_1),
11550                 TEST_CASE_ST(ut_setup, ut_teardown,
11551                         test_AES_CCM_authenticated_encryption_test_case_128_2),
11552                 TEST_CASE_ST(ut_setup, ut_teardown,
11553                         test_AES_CCM_authenticated_encryption_test_case_128_3),
11554
11555                 /** AES CCM Authenticated Decryption 128 bits key*/
11556                 TEST_CASE_ST(ut_setup, ut_teardown,
11557                         test_AES_CCM_authenticated_decryption_test_case_128_1),
11558                 TEST_CASE_ST(ut_setup, ut_teardown,
11559                         test_AES_CCM_authenticated_decryption_test_case_128_2),
11560                 TEST_CASE_ST(ut_setup, ut_teardown,
11561                         test_AES_CCM_authenticated_decryption_test_case_128_3),
11562
11563                 /** AES CCM Authenticated Encryption 192 bits key */
11564                 TEST_CASE_ST(ut_setup, ut_teardown,
11565                         test_AES_CCM_authenticated_encryption_test_case_192_1),
11566                 TEST_CASE_ST(ut_setup, ut_teardown,
11567                         test_AES_CCM_authenticated_encryption_test_case_192_2),
11568                 TEST_CASE_ST(ut_setup, ut_teardown,
11569                         test_AES_CCM_authenticated_encryption_test_case_192_3),
11570
11571                 /** AES CCM Authenticated Decryption 192 bits key*/
11572                 TEST_CASE_ST(ut_setup, ut_teardown,
11573                         test_AES_CCM_authenticated_decryption_test_case_192_1),
11574                 TEST_CASE_ST(ut_setup, ut_teardown,
11575                         test_AES_CCM_authenticated_decryption_test_case_192_2),
11576                 TEST_CASE_ST(ut_setup, ut_teardown,
11577                         test_AES_CCM_authenticated_decryption_test_case_192_3),
11578
11579                 /** AES CCM Authenticated Encryption 256 bits key */
11580                 TEST_CASE_ST(ut_setup, ut_teardown,
11581                         test_AES_CCM_authenticated_encryption_test_case_256_1),
11582                 TEST_CASE_ST(ut_setup, ut_teardown,
11583                         test_AES_CCM_authenticated_encryption_test_case_256_2),
11584                 TEST_CASE_ST(ut_setup, ut_teardown,
11585                         test_AES_CCM_authenticated_encryption_test_case_256_3),
11586
11587                 /** AES CCM Authenticated Decryption 256 bits key*/
11588                 TEST_CASE_ST(ut_setup, ut_teardown,
11589                         test_AES_CCM_authenticated_decryption_test_case_256_1),
11590                 TEST_CASE_ST(ut_setup, ut_teardown,
11591                         test_AES_CCM_authenticated_decryption_test_case_256_2),
11592                 TEST_CASE_ST(ut_setup, ut_teardown,
11593                         test_AES_CCM_authenticated_decryption_test_case_256_3),
11594
11595                 /** AES GCM Authenticated Encryption */
11596                 TEST_CASE_ST(ut_setup, ut_teardown,
11597                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
11598                 TEST_CASE_ST(ut_setup, ut_teardown,
11599                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
11600                 TEST_CASE_ST(ut_setup, ut_teardown,
11601                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
11602                 TEST_CASE_ST(ut_setup, ut_teardown,
11603                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11604                 TEST_CASE_ST(ut_setup, ut_teardown,
11605                         test_AES_GCM_authenticated_encryption_test_case_1),
11606                 TEST_CASE_ST(ut_setup, ut_teardown,
11607                         test_AES_GCM_authenticated_encryption_test_case_2),
11608                 TEST_CASE_ST(ut_setup, ut_teardown,
11609                         test_AES_GCM_authenticated_encryption_test_case_3),
11610                 TEST_CASE_ST(ut_setup, ut_teardown,
11611                         test_AES_GCM_authenticated_encryption_test_case_4),
11612                 TEST_CASE_ST(ut_setup, ut_teardown,
11613                         test_AES_GCM_authenticated_encryption_test_case_5),
11614                 TEST_CASE_ST(ut_setup, ut_teardown,
11615                         test_AES_GCM_authenticated_encryption_test_case_6),
11616                 TEST_CASE_ST(ut_setup, ut_teardown,
11617                         test_AES_GCM_authenticated_encryption_test_case_7),
11618                 TEST_CASE_ST(ut_setup, ut_teardown,
11619                         test_AES_GCM_authenticated_encryption_test_case_8),
11620
11621                 /** AES GCM Authenticated Decryption */
11622                 TEST_CASE_ST(ut_setup, ut_teardown,
11623                         test_AES_GCM_authenticated_decryption_test_case_1),
11624                 TEST_CASE_ST(ut_setup, ut_teardown,
11625                         test_AES_GCM_authenticated_decryption_test_case_2),
11626                 TEST_CASE_ST(ut_setup, ut_teardown,
11627                         test_AES_GCM_authenticated_decryption_test_case_3),
11628                 TEST_CASE_ST(ut_setup, ut_teardown,
11629                         test_AES_GCM_authenticated_decryption_test_case_4),
11630                 TEST_CASE_ST(ut_setup, ut_teardown,
11631                         test_AES_GCM_authenticated_decryption_test_case_5),
11632                 TEST_CASE_ST(ut_setup, ut_teardown,
11633                         test_AES_GCM_authenticated_decryption_test_case_6),
11634                 TEST_CASE_ST(ut_setup, ut_teardown,
11635                         test_AES_GCM_authenticated_decryption_test_case_7),
11636                 TEST_CASE_ST(ut_setup, ut_teardown,
11637                         test_AES_GCM_authenticated_decryption_test_case_8),
11638
11639                 /** AES GCM Authenticated Encryption 192 bits key */
11640                 TEST_CASE_ST(ut_setup, ut_teardown,
11641                         test_AES_GCM_auth_encryption_test_case_192_1),
11642                 TEST_CASE_ST(ut_setup, ut_teardown,
11643                         test_AES_GCM_auth_encryption_test_case_192_2),
11644                 TEST_CASE_ST(ut_setup, ut_teardown,
11645                         test_AES_GCM_auth_encryption_test_case_192_3),
11646                 TEST_CASE_ST(ut_setup, ut_teardown,
11647                         test_AES_GCM_auth_encryption_test_case_192_4),
11648                 TEST_CASE_ST(ut_setup, ut_teardown,
11649                         test_AES_GCM_auth_encryption_test_case_192_5),
11650                 TEST_CASE_ST(ut_setup, ut_teardown,
11651                         test_AES_GCM_auth_encryption_test_case_192_6),
11652                 TEST_CASE_ST(ut_setup, ut_teardown,
11653                         test_AES_GCM_auth_encryption_test_case_192_7),
11654
11655                 /** AES GCM Authenticated Decryption 192 bits key */
11656                 TEST_CASE_ST(ut_setup, ut_teardown,
11657                         test_AES_GCM_auth_decryption_test_case_192_1),
11658                 TEST_CASE_ST(ut_setup, ut_teardown,
11659                         test_AES_GCM_auth_decryption_test_case_192_2),
11660                 TEST_CASE_ST(ut_setup, ut_teardown,
11661                         test_AES_GCM_auth_decryption_test_case_192_3),
11662                 TEST_CASE_ST(ut_setup, ut_teardown,
11663                         test_AES_GCM_auth_decryption_test_case_192_4),
11664                 TEST_CASE_ST(ut_setup, ut_teardown,
11665                         test_AES_GCM_auth_decryption_test_case_192_5),
11666                 TEST_CASE_ST(ut_setup, ut_teardown,
11667                         test_AES_GCM_auth_decryption_test_case_192_6),
11668                 TEST_CASE_ST(ut_setup, ut_teardown,
11669                         test_AES_GCM_auth_decryption_test_case_192_7),
11670
11671                 /** AES GCM Authenticated Encryption 256 bits key */
11672                 TEST_CASE_ST(ut_setup, ut_teardown,
11673                         test_AES_GCM_auth_encryption_test_case_256_1),
11674                 TEST_CASE_ST(ut_setup, ut_teardown,
11675                         test_AES_GCM_auth_encryption_test_case_256_2),
11676                 TEST_CASE_ST(ut_setup, ut_teardown,
11677                         test_AES_GCM_auth_encryption_test_case_256_3),
11678                 TEST_CASE_ST(ut_setup, ut_teardown,
11679                         test_AES_GCM_auth_encryption_test_case_256_4),
11680                 TEST_CASE_ST(ut_setup, ut_teardown,
11681                         test_AES_GCM_auth_encryption_test_case_256_5),
11682                 TEST_CASE_ST(ut_setup, ut_teardown,
11683                         test_AES_GCM_auth_encryption_test_case_256_6),
11684                 TEST_CASE_ST(ut_setup, ut_teardown,
11685                         test_AES_GCM_auth_encryption_test_case_256_7),
11686
11687                 /** AES GCM Authenticated Decryption 256 bits key */
11688                 TEST_CASE_ST(ut_setup, ut_teardown,
11689                         test_AES_GCM_auth_decryption_test_case_256_1),
11690                 TEST_CASE_ST(ut_setup, ut_teardown,
11691                         test_AES_GCM_auth_decryption_test_case_256_2),
11692                 TEST_CASE_ST(ut_setup, ut_teardown,
11693                         test_AES_GCM_auth_decryption_test_case_256_3),
11694                 TEST_CASE_ST(ut_setup, ut_teardown,
11695                         test_AES_GCM_auth_decryption_test_case_256_4),
11696                 TEST_CASE_ST(ut_setup, ut_teardown,
11697                         test_AES_GCM_auth_decryption_test_case_256_5),
11698                 TEST_CASE_ST(ut_setup, ut_teardown,
11699                         test_AES_GCM_auth_decryption_test_case_256_6),
11700                 TEST_CASE_ST(ut_setup, ut_teardown,
11701                         test_AES_GCM_auth_decryption_test_case_256_7),
11702
11703                 /** AES GCM Authenticated Encryption big aad size */
11704                 TEST_CASE_ST(ut_setup, ut_teardown,
11705                         test_AES_GCM_auth_encryption_test_case_aad_1),
11706                 TEST_CASE_ST(ut_setup, ut_teardown,
11707                         test_AES_GCM_auth_encryption_test_case_aad_2),
11708
11709                 /** AES GCM Authenticated Decryption big aad size */
11710                 TEST_CASE_ST(ut_setup, ut_teardown,
11711                         test_AES_GCM_auth_decryption_test_case_aad_1),
11712                 TEST_CASE_ST(ut_setup, ut_teardown,
11713                         test_AES_GCM_auth_decryption_test_case_aad_2),
11714
11715                 /** Out of place tests */
11716                 TEST_CASE_ST(ut_setup, ut_teardown,
11717                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
11718                 TEST_CASE_ST(ut_setup, ut_teardown,
11719                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
11720
11721                 /** Session-less tests */
11722                 TEST_CASE_ST(ut_setup, ut_teardown,
11723                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
11724                 TEST_CASE_ST(ut_setup, ut_teardown,
11725                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
11726
11727                 /** AES GMAC Authentication */
11728                 TEST_CASE_ST(ut_setup, ut_teardown,
11729                         test_AES_GMAC_authentication_test_case_1),
11730                 TEST_CASE_ST(ut_setup, ut_teardown,
11731                         test_AES_GMAC_authentication_verify_test_case_1),
11732                 TEST_CASE_ST(ut_setup, ut_teardown,
11733                         test_AES_GMAC_authentication_test_case_2),
11734                 TEST_CASE_ST(ut_setup, ut_teardown,
11735                         test_AES_GMAC_authentication_verify_test_case_2),
11736                 TEST_CASE_ST(ut_setup, ut_teardown,
11737                         test_AES_GMAC_authentication_test_case_3),
11738                 TEST_CASE_ST(ut_setup, ut_teardown,
11739                         test_AES_GMAC_authentication_verify_test_case_3),
11740                 TEST_CASE_ST(ut_setup, ut_teardown,
11741                         test_AES_GMAC_authentication_test_case_4),
11742                 TEST_CASE_ST(ut_setup, ut_teardown,
11743                         test_AES_GMAC_authentication_verify_test_case_4),
11744
11745                 /** SNOW 3G encrypt only (UEA2) */
11746                 TEST_CASE_ST(ut_setup, ut_teardown,
11747                         test_snow3g_encryption_test_case_1),
11748                 TEST_CASE_ST(ut_setup, ut_teardown,
11749                         test_snow3g_encryption_test_case_2),
11750                 TEST_CASE_ST(ut_setup, ut_teardown,
11751                         test_snow3g_encryption_test_case_3),
11752                 TEST_CASE_ST(ut_setup, ut_teardown,
11753                         test_snow3g_encryption_test_case_4),
11754                 TEST_CASE_ST(ut_setup, ut_teardown,
11755                         test_snow3g_encryption_test_case_5),
11756
11757                 TEST_CASE_ST(ut_setup, ut_teardown,
11758                         test_snow3g_encryption_test_case_1_oop),
11759                 TEST_CASE_ST(ut_setup, ut_teardown,
11760                         test_snow3g_encryption_test_case_1_oop_sgl),
11761                 TEST_CASE_ST(ut_setup, ut_teardown,
11762                         test_snow3g_encryption_test_case_1_offset_oop),
11763                 TEST_CASE_ST(ut_setup, ut_teardown,
11764                         test_snow3g_decryption_test_case_1_oop),
11765
11766                 /** SNOW 3G generate auth, then encrypt (UEA2) */
11767                 TEST_CASE_ST(ut_setup, ut_teardown,
11768                         test_snow3g_auth_cipher_test_case_1),
11769                 TEST_CASE_ST(ut_setup, ut_teardown,
11770                         test_snow3g_auth_cipher_test_case_2),
11771                 TEST_CASE_ST(ut_setup, ut_teardown,
11772                         test_snow3g_auth_cipher_test_case_2_oop),
11773                 TEST_CASE_ST(ut_setup, ut_teardown,
11774                         test_snow3g_auth_cipher_part_digest_enc),
11775                 TEST_CASE_ST(ut_setup, ut_teardown,
11776                         test_snow3g_auth_cipher_part_digest_enc_oop),
11777                 TEST_CASE_ST(ut_setup, ut_teardown,
11778                         test_snow3g_auth_cipher_test_case_3_sgl),
11779                 TEST_CASE_ST(ut_setup, ut_teardown,
11780                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
11781                 TEST_CASE_ST(ut_setup, ut_teardown,
11782                         test_snow3g_auth_cipher_part_digest_enc_sgl),
11783                 TEST_CASE_ST(ut_setup, ut_teardown,
11784                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
11785
11786                 /** SNOW 3G decrypt (UEA2), then verify auth */
11787                 TEST_CASE_ST(ut_setup, ut_teardown,
11788                         test_snow3g_auth_cipher_verify_test_case_1),
11789                 TEST_CASE_ST(ut_setup, ut_teardown,
11790                         test_snow3g_auth_cipher_verify_test_case_2),
11791                 TEST_CASE_ST(ut_setup, ut_teardown,
11792                         test_snow3g_auth_cipher_verify_test_case_2_oop),
11793                 TEST_CASE_ST(ut_setup, ut_teardown,
11794                         test_snow3g_auth_cipher_verify_part_digest_enc),
11795                 TEST_CASE_ST(ut_setup, ut_teardown,
11796                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
11797                 TEST_CASE_ST(ut_setup, ut_teardown,
11798                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
11799                 TEST_CASE_ST(ut_setup, ut_teardown,
11800                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
11801                 TEST_CASE_ST(ut_setup, ut_teardown,
11802                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
11803                 TEST_CASE_ST(ut_setup, ut_teardown,
11804                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
11805
11806                 /** SNOW 3G decrypt only (UEA2) */
11807                 TEST_CASE_ST(ut_setup, ut_teardown,
11808                         test_snow3g_decryption_test_case_1),
11809                 TEST_CASE_ST(ut_setup, ut_teardown,
11810                         test_snow3g_decryption_test_case_2),
11811                 TEST_CASE_ST(ut_setup, ut_teardown,
11812                         test_snow3g_decryption_test_case_3),
11813                 TEST_CASE_ST(ut_setup, ut_teardown,
11814                         test_snow3g_decryption_test_case_4),
11815                 TEST_CASE_ST(ut_setup, ut_teardown,
11816                         test_snow3g_decryption_test_case_5),
11817                 TEST_CASE_ST(ut_setup, ut_teardown,
11818                         test_snow3g_decryption_with_digest_test_case_1),
11819                 TEST_CASE_ST(ut_setup, ut_teardown,
11820                         test_snow3g_hash_generate_test_case_1),
11821                 TEST_CASE_ST(ut_setup, ut_teardown,
11822                         test_snow3g_hash_generate_test_case_2),
11823                 TEST_CASE_ST(ut_setup, ut_teardown,
11824                         test_snow3g_hash_generate_test_case_3),
11825                 /* Tests with buffers which length is not byte-aligned */
11826                 TEST_CASE_ST(ut_setup, ut_teardown,
11827                         test_snow3g_hash_generate_test_case_4),
11828                 TEST_CASE_ST(ut_setup, ut_teardown,
11829                         test_snow3g_hash_generate_test_case_5),
11830                 TEST_CASE_ST(ut_setup, ut_teardown,
11831                         test_snow3g_hash_generate_test_case_6),
11832                 TEST_CASE_ST(ut_setup, ut_teardown,
11833                         test_snow3g_hash_verify_test_case_1),
11834                 TEST_CASE_ST(ut_setup, ut_teardown,
11835                         test_snow3g_hash_verify_test_case_2),
11836                 TEST_CASE_ST(ut_setup, ut_teardown,
11837                         test_snow3g_hash_verify_test_case_3),
11838                 /* Tests with buffers which length is not byte-aligned */
11839                 TEST_CASE_ST(ut_setup, ut_teardown,
11840                         test_snow3g_hash_verify_test_case_4),
11841                 TEST_CASE_ST(ut_setup, ut_teardown,
11842                         test_snow3g_hash_verify_test_case_5),
11843                 TEST_CASE_ST(ut_setup, ut_teardown,
11844                         test_snow3g_hash_verify_test_case_6),
11845                 TEST_CASE_ST(ut_setup, ut_teardown,
11846                         test_snow3g_cipher_auth_test_case_1),
11847                 TEST_CASE_ST(ut_setup, ut_teardown,
11848                         test_snow3g_auth_cipher_with_digest_test_case_1),
11849
11850                 /** ZUC encrypt only (EEA3) */
11851                 TEST_CASE_ST(ut_setup, ut_teardown,
11852                         test_zuc_encryption_test_case_1),
11853                 TEST_CASE_ST(ut_setup, ut_teardown,
11854                         test_zuc_encryption_test_case_2),
11855                 TEST_CASE_ST(ut_setup, ut_teardown,
11856                         test_zuc_encryption_test_case_3),
11857                 TEST_CASE_ST(ut_setup, ut_teardown,
11858                         test_zuc_encryption_test_case_4),
11859                 TEST_CASE_ST(ut_setup, ut_teardown,
11860                         test_zuc_encryption_test_case_5),
11861                 TEST_CASE_ST(ut_setup, ut_teardown,
11862                         test_zuc_encryption_test_case_6_sgl),
11863
11864                 /** ZUC authenticate (EIA3) */
11865                 TEST_CASE_ST(ut_setup, ut_teardown,
11866                         test_zuc_hash_generate_test_case_1),
11867                 TEST_CASE_ST(ut_setup, ut_teardown,
11868                         test_zuc_hash_generate_test_case_2),
11869                 TEST_CASE_ST(ut_setup, ut_teardown,
11870                         test_zuc_hash_generate_test_case_3),
11871                 TEST_CASE_ST(ut_setup, ut_teardown,
11872                         test_zuc_hash_generate_test_case_4),
11873                 TEST_CASE_ST(ut_setup, ut_teardown,
11874                         test_zuc_hash_generate_test_case_5),
11875                 TEST_CASE_ST(ut_setup, ut_teardown,
11876                         test_zuc_hash_generate_test_case_6),
11877                 TEST_CASE_ST(ut_setup, ut_teardown,
11878                         test_zuc_hash_generate_test_case_7),
11879                 TEST_CASE_ST(ut_setup, ut_teardown,
11880                         test_zuc_hash_generate_test_case_8),
11881
11882                 /** ZUC alg-chain (EEA3/EIA3) */
11883                 TEST_CASE_ST(ut_setup, ut_teardown,
11884                         test_zuc_cipher_auth_test_case_1),
11885                 TEST_CASE_ST(ut_setup, ut_teardown,
11886                         test_zuc_cipher_auth_test_case_2),
11887
11888                 /** ZUC generate auth, then encrypt (EEA3) */
11889                 TEST_CASE_ST(ut_setup, ut_teardown,
11890                         test_zuc_auth_cipher_test_case_1),
11891                 TEST_CASE_ST(ut_setup, ut_teardown,
11892                         test_zuc_auth_cipher_test_case_1_oop),
11893                 TEST_CASE_ST(ut_setup, ut_teardown,
11894                         test_zuc_auth_cipher_test_case_1_sgl),
11895                 TEST_CASE_ST(ut_setup, ut_teardown,
11896                         test_zuc_auth_cipher_test_case_1_oop_sgl),
11897
11898                 /** ZUC decrypt (EEA3), then verify auth */
11899                 TEST_CASE_ST(ut_setup, ut_teardown,
11900                         test_zuc_auth_cipher_verify_test_case_1),
11901                 TEST_CASE_ST(ut_setup, ut_teardown,
11902                         test_zuc_auth_cipher_verify_test_case_1_oop),
11903                 TEST_CASE_ST(ut_setup, ut_teardown,
11904                         test_zuc_auth_cipher_verify_test_case_1_sgl),
11905                 TEST_CASE_ST(ut_setup, ut_teardown,
11906                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
11907
11908                 /** HMAC_MD5 Authentication */
11909                 TEST_CASE_ST(ut_setup, ut_teardown,
11910                         test_MD5_HMAC_generate_case_1),
11911                 TEST_CASE_ST(ut_setup, ut_teardown,
11912                         test_MD5_HMAC_verify_case_1),
11913                 TEST_CASE_ST(ut_setup, ut_teardown,
11914                         test_MD5_HMAC_generate_case_2),
11915                 TEST_CASE_ST(ut_setup, ut_teardown,
11916                         test_MD5_HMAC_verify_case_2),
11917
11918                 /** KASUMI hash only (UIA1) */
11919                 TEST_CASE_ST(ut_setup, ut_teardown,
11920                         test_kasumi_hash_generate_test_case_1),
11921                 TEST_CASE_ST(ut_setup, ut_teardown,
11922                         test_kasumi_hash_generate_test_case_2),
11923                 TEST_CASE_ST(ut_setup, ut_teardown,
11924                         test_kasumi_hash_generate_test_case_3),
11925                 TEST_CASE_ST(ut_setup, ut_teardown,
11926                         test_kasumi_hash_generate_test_case_4),
11927                 TEST_CASE_ST(ut_setup, ut_teardown,
11928                         test_kasumi_hash_generate_test_case_5),
11929                 TEST_CASE_ST(ut_setup, ut_teardown,
11930                         test_kasumi_hash_generate_test_case_6),
11931
11932                 TEST_CASE_ST(ut_setup, ut_teardown,
11933                         test_kasumi_hash_verify_test_case_1),
11934                 TEST_CASE_ST(ut_setup, ut_teardown,
11935                         test_kasumi_hash_verify_test_case_2),
11936                 TEST_CASE_ST(ut_setup, ut_teardown,
11937                         test_kasumi_hash_verify_test_case_3),
11938                 TEST_CASE_ST(ut_setup, ut_teardown,
11939                         test_kasumi_hash_verify_test_case_4),
11940                 TEST_CASE_ST(ut_setup, ut_teardown,
11941                         test_kasumi_hash_verify_test_case_5),
11942
11943                 /** KASUMI encrypt only (UEA1) */
11944                 TEST_CASE_ST(ut_setup, ut_teardown,
11945                         test_kasumi_encryption_test_case_1),
11946                 TEST_CASE_ST(ut_setup, ut_teardown,
11947                         test_kasumi_encryption_test_case_1_sgl),
11948                 TEST_CASE_ST(ut_setup, ut_teardown,
11949                         test_kasumi_encryption_test_case_1_oop),
11950                 TEST_CASE_ST(ut_setup, ut_teardown,
11951                         test_kasumi_encryption_test_case_1_oop_sgl),
11952                 TEST_CASE_ST(ut_setup, ut_teardown,
11953                         test_kasumi_encryption_test_case_2),
11954                 TEST_CASE_ST(ut_setup, ut_teardown,
11955                         test_kasumi_encryption_test_case_3),
11956                 TEST_CASE_ST(ut_setup, ut_teardown,
11957                         test_kasumi_encryption_test_case_4),
11958                 TEST_CASE_ST(ut_setup, ut_teardown,
11959                         test_kasumi_encryption_test_case_5),
11960
11961                 /** KASUMI decrypt only (UEA1) */
11962                 TEST_CASE_ST(ut_setup, ut_teardown,
11963                         test_kasumi_decryption_test_case_1),
11964                 TEST_CASE_ST(ut_setup, ut_teardown,
11965                         test_kasumi_decryption_test_case_2),
11966                 TEST_CASE_ST(ut_setup, ut_teardown,
11967                         test_kasumi_decryption_test_case_3),
11968                 TEST_CASE_ST(ut_setup, ut_teardown,
11969                         test_kasumi_decryption_test_case_4),
11970                 TEST_CASE_ST(ut_setup, ut_teardown,
11971                         test_kasumi_decryption_test_case_5),
11972                 TEST_CASE_ST(ut_setup, ut_teardown,
11973                         test_kasumi_decryption_test_case_1_oop),
11974
11975                 TEST_CASE_ST(ut_setup, ut_teardown,
11976                         test_kasumi_cipher_auth_test_case_1),
11977
11978                 /** KASUMI generate auth, then encrypt (F8) */
11979                 TEST_CASE_ST(ut_setup, ut_teardown,
11980                         test_kasumi_auth_cipher_test_case_1),
11981                 TEST_CASE_ST(ut_setup, ut_teardown,
11982                         test_kasumi_auth_cipher_test_case_2),
11983                 TEST_CASE_ST(ut_setup, ut_teardown,
11984                         test_kasumi_auth_cipher_test_case_2_oop),
11985                 TEST_CASE_ST(ut_setup, ut_teardown,
11986                         test_kasumi_auth_cipher_test_case_2_sgl),
11987                 TEST_CASE_ST(ut_setup, ut_teardown,
11988                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
11989
11990                 /** KASUMI decrypt (F8), then verify auth */
11991                 TEST_CASE_ST(ut_setup, ut_teardown,
11992                         test_kasumi_auth_cipher_verify_test_case_1),
11993                 TEST_CASE_ST(ut_setup, ut_teardown,
11994                         test_kasumi_auth_cipher_verify_test_case_2),
11995                 TEST_CASE_ST(ut_setup, ut_teardown,
11996                         test_kasumi_auth_cipher_verify_test_case_2_oop),
11997                 TEST_CASE_ST(ut_setup, ut_teardown,
11998                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
11999                 TEST_CASE_ST(ut_setup, ut_teardown,
12000                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
12001
12002                 /** ESN Testcase */
12003                 TEST_CASE_ST(ut_setup, ut_teardown,
12004                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12005                 TEST_CASE_ST(ut_setup, ut_teardown,
12006                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12007
12008                 /** Negative tests */
12009                 TEST_CASE_ST(ut_setup, ut_teardown,
12010                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12011                 TEST_CASE_ST(ut_setup, ut_teardown,
12012                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12013                 TEST_CASE_ST(ut_setup, ut_teardown,
12014                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12015                 TEST_CASE_ST(ut_setup, ut_teardown,
12016                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12017                 TEST_CASE_ST(ut_setup, ut_teardown,
12018                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12019                 TEST_CASE_ST(ut_setup, ut_teardown,
12020                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12021                 TEST_CASE_ST(ut_setup, ut_teardown,
12022                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12023                 TEST_CASE_ST(ut_setup, ut_teardown,
12024                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12025                 TEST_CASE_ST(ut_setup, ut_teardown,
12026                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12027                 TEST_CASE_ST(ut_setup, ut_teardown,
12028                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12029                 TEST_CASE_ST(ut_setup, ut_teardown,
12030                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12031                 TEST_CASE_ST(ut_setup, ut_teardown,
12032                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12033                 TEST_CASE_ST(ut_setup, ut_teardown,
12034                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12035                 TEST_CASE_ST(ut_setup, ut_teardown,
12036                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12037                 TEST_CASE_ST(ut_setup, ut_teardown,
12038                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12039                 TEST_CASE_ST(ut_setup, ut_teardown,
12040                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12041                 TEST_CASE_ST(ut_setup, ut_teardown,
12042                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12043                 TEST_CASE_ST(ut_setup, ut_teardown,
12044                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12045
12046                 /** Mixed CIPHER + HASH algorithms */
12047                 /** AUTH AES CMAC + CIPHER AES CTR */
12048                 TEST_CASE_ST(ut_setup, ut_teardown,
12049                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
12050                 TEST_CASE_ST(ut_setup, ut_teardown,
12051                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12052                 TEST_CASE_ST(ut_setup, ut_teardown,
12053                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12054                 TEST_CASE_ST(ut_setup, ut_teardown,
12055                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12056                 TEST_CASE_ST(ut_setup, ut_teardown,
12057                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
12058                 TEST_CASE_ST(ut_setup, ut_teardown,
12059                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12060                 TEST_CASE_ST(ut_setup, ut_teardown,
12061                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12062                 TEST_CASE_ST(ut_setup, ut_teardown,
12063                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12064
12065                 /** AUTH ZUC + CIPHER SNOW3G */
12066                 TEST_CASE_ST(ut_setup, ut_teardown,
12067                         test_auth_zuc_cipher_snow_test_case_1),
12068                 TEST_CASE_ST(ut_setup, ut_teardown,
12069                         test_verify_auth_zuc_cipher_snow_test_case_1),
12070                 /** AUTH AES CMAC + CIPHER SNOW3G */
12071                 TEST_CASE_ST(ut_setup, ut_teardown,
12072                         test_auth_aes_cmac_cipher_snow_test_case_1),
12073                 TEST_CASE_ST(ut_setup, ut_teardown,
12074                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
12075                 /** AUTH ZUC + CIPHER AES CTR */
12076                 TEST_CASE_ST(ut_setup, ut_teardown,
12077                         test_auth_zuc_cipher_aes_ctr_test_case_1),
12078                 TEST_CASE_ST(ut_setup, ut_teardown,
12079                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
12080                 /** AUTH SNOW3G + CIPHER AES CTR */
12081                 TEST_CASE_ST(ut_setup, ut_teardown,
12082                         test_auth_snow_cipher_aes_ctr_test_case_1),
12083                 TEST_CASE_ST(ut_setup, ut_teardown,
12084                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
12085                 /** AUTH SNOW3G + CIPHER ZUC */
12086                 TEST_CASE_ST(ut_setup, ut_teardown,
12087                         test_auth_snow_cipher_zuc_test_case_1),
12088                 TEST_CASE_ST(ut_setup, ut_teardown,
12089                         test_verify_auth_snow_cipher_zuc_test_case_1),
12090                 /** AUTH AES CMAC + CIPHER ZUC */
12091                 TEST_CASE_ST(ut_setup, ut_teardown,
12092                         test_auth_aes_cmac_cipher_zuc_test_case_1),
12093                 TEST_CASE_ST(ut_setup, ut_teardown,
12094                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
12095
12096                 /** AUTH NULL + CIPHER SNOW3G */
12097                 TEST_CASE_ST(ut_setup, ut_teardown,
12098                         test_auth_null_cipher_snow_test_case_1),
12099                 TEST_CASE_ST(ut_setup, ut_teardown,
12100                         test_verify_auth_null_cipher_snow_test_case_1),
12101                 /** AUTH NULL + CIPHER ZUC */
12102                 TEST_CASE_ST(ut_setup, ut_teardown,
12103                         test_auth_null_cipher_zuc_test_case_1),
12104                 TEST_CASE_ST(ut_setup, ut_teardown,
12105                         test_verify_auth_null_cipher_zuc_test_case_1),
12106                 /** AUTH SNOW3G + CIPHER NULL */
12107                 TEST_CASE_ST(ut_setup, ut_teardown,
12108                         test_auth_snow_cipher_null_test_case_1),
12109                 TEST_CASE_ST(ut_setup, ut_teardown,
12110                         test_verify_auth_snow_cipher_null_test_case_1),
12111                 /** AUTH ZUC + CIPHER NULL */
12112                 TEST_CASE_ST(ut_setup, ut_teardown,
12113                         test_auth_zuc_cipher_null_test_case_1),
12114                 TEST_CASE_ST(ut_setup, ut_teardown,
12115                         test_verify_auth_zuc_cipher_null_test_case_1),
12116                 /** AUTH NULL + CIPHER AES CTR */
12117                 TEST_CASE_ST(ut_setup, ut_teardown,
12118                         test_auth_null_cipher_aes_ctr_test_case_1),
12119                 TEST_CASE_ST(ut_setup, ut_teardown,
12120                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
12121                 /** AUTH AES CMAC + CIPHER NULL */
12122                 TEST_CASE_ST(ut_setup, ut_teardown,
12123                         test_auth_aes_cmac_cipher_null_test_case_1),
12124                 TEST_CASE_ST(ut_setup, ut_teardown,
12125                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
12126
12127                 TEST_CASES_END() /**< NULL terminate unit test array */
12128         }
12129 };
12130
12131 static struct unit_test_suite cryptodev_virtio_testsuite = {
12132         .suite_name = "Crypto VIRTIO Unit Test Suite",
12133         .setup = testsuite_setup,
12134         .teardown = testsuite_teardown,
12135         .unit_test_cases = {
12136                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12137
12138                 TEST_CASES_END() /**< NULL terminate unit test array */
12139         }
12140 };
12141
12142 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
12143         .suite_name = "Crypto CAAM JR Unit Test Suite",
12144         .setup = testsuite_setup,
12145         .teardown = testsuite_teardown,
12146         .unit_test_cases = {
12147                 TEST_CASE_ST(ut_setup, ut_teardown,
12148                              test_device_configure_invalid_dev_id),
12149                 TEST_CASE_ST(ut_setup, ut_teardown,
12150                              test_multi_session),
12151
12152                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12153                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12154                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12155                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12156                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12157
12158                 TEST_CASES_END() /**< NULL terminate unit test array */
12159         }
12160 };
12161
12162 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
12163         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
12164         .setup = testsuite_setup,
12165         .teardown = testsuite_teardown,
12166         .unit_test_cases = {
12167                 TEST_CASE_ST(ut_setup, ut_teardown,
12168                              test_device_configure_invalid_dev_id),
12169                 TEST_CASE_ST(ut_setup, ut_teardown,
12170                              test_multi_session),
12171
12172                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12173                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12174                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12175                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12176                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12177
12178 #ifdef RTE_LIBRTE_SECURITY
12179                 TEST_CASE_ST(ut_setup, ut_teardown,
12180                         test_PDCP_PROTO_cplane_encap_all),
12181
12182                 TEST_CASE_ST(ut_setup, ut_teardown,
12183                         test_PDCP_PROTO_cplane_decap_all),
12184
12185                 TEST_CASE_ST(ut_setup, ut_teardown,
12186                         test_PDCP_PROTO_uplane_encap_all),
12187
12188                 TEST_CASE_ST(ut_setup, ut_teardown,
12189                         test_PDCP_PROTO_uplane_decap_all),
12190
12191                 TEST_CASE_ST(ut_setup, ut_teardown,
12192                         test_PDCP_PROTO_SGL_in_place_32B),
12193                 TEST_CASE_ST(ut_setup, ut_teardown,
12194                         test_PDCP_PROTO_SGL_oop_32B_128B),
12195                 TEST_CASE_ST(ut_setup, ut_teardown,
12196                         test_PDCP_PROTO_SGL_oop_32B_40B),
12197                 TEST_CASE_ST(ut_setup, ut_teardown,
12198                         test_PDCP_PROTO_SGL_oop_128B_32B),
12199 #endif
12200                 /** AES GCM Authenticated Encryption */
12201                 TEST_CASE_ST(ut_setup, ut_teardown,
12202                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12203                 TEST_CASE_ST(ut_setup, ut_teardown,
12204                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12205                 TEST_CASE_ST(ut_setup, ut_teardown,
12206                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12207                 TEST_CASE_ST(ut_setup, ut_teardown,
12208                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12209                 TEST_CASE_ST(ut_setup, ut_teardown,
12210                         test_AES_GCM_authenticated_encryption_test_case_1),
12211                 TEST_CASE_ST(ut_setup, ut_teardown,
12212                         test_AES_GCM_authenticated_encryption_test_case_2),
12213                 TEST_CASE_ST(ut_setup, ut_teardown,
12214                         test_AES_GCM_authenticated_encryption_test_case_3),
12215                 TEST_CASE_ST(ut_setup, ut_teardown,
12216                         test_AES_GCM_authenticated_encryption_test_case_4),
12217                 TEST_CASE_ST(ut_setup, ut_teardown,
12218                         test_AES_GCM_authenticated_encryption_test_case_5),
12219                 TEST_CASE_ST(ut_setup, ut_teardown,
12220                         test_AES_GCM_authenticated_encryption_test_case_6),
12221                 TEST_CASE_ST(ut_setup, ut_teardown,
12222                         test_AES_GCM_authenticated_encryption_test_case_7),
12223                 TEST_CASE_ST(ut_setup, ut_teardown,
12224                         test_AES_GCM_authenticated_encryption_test_case_8),
12225
12226                 /** AES GCM Authenticated Decryption */
12227                 TEST_CASE_ST(ut_setup, ut_teardown,
12228                         test_AES_GCM_authenticated_decryption_test_case_1),
12229                 TEST_CASE_ST(ut_setup, ut_teardown,
12230                         test_AES_GCM_authenticated_decryption_test_case_2),
12231                 TEST_CASE_ST(ut_setup, ut_teardown,
12232                         test_AES_GCM_authenticated_decryption_test_case_3),
12233                 TEST_CASE_ST(ut_setup, ut_teardown,
12234                         test_AES_GCM_authenticated_decryption_test_case_4),
12235                 TEST_CASE_ST(ut_setup, ut_teardown,
12236                         test_AES_GCM_authenticated_decryption_test_case_5),
12237                 TEST_CASE_ST(ut_setup, ut_teardown,
12238                         test_AES_GCM_authenticated_decryption_test_case_6),
12239                 TEST_CASE_ST(ut_setup, ut_teardown,
12240                         test_AES_GCM_authenticated_decryption_test_case_7),
12241                 TEST_CASE_ST(ut_setup, ut_teardown,
12242                         test_AES_GCM_authenticated_decryption_test_case_8),
12243
12244                 /** AES GCM Authenticated Encryption 192 bits key */
12245                 TEST_CASE_ST(ut_setup, ut_teardown,
12246                         test_AES_GCM_auth_encryption_test_case_192_1),
12247                 TEST_CASE_ST(ut_setup, ut_teardown,
12248                         test_AES_GCM_auth_encryption_test_case_192_2),
12249                 TEST_CASE_ST(ut_setup, ut_teardown,
12250                         test_AES_GCM_auth_encryption_test_case_192_3),
12251                 TEST_CASE_ST(ut_setup, ut_teardown,
12252                         test_AES_GCM_auth_encryption_test_case_192_4),
12253                 TEST_CASE_ST(ut_setup, ut_teardown,
12254                         test_AES_GCM_auth_encryption_test_case_192_5),
12255                 TEST_CASE_ST(ut_setup, ut_teardown,
12256                         test_AES_GCM_auth_encryption_test_case_192_6),
12257                 TEST_CASE_ST(ut_setup, ut_teardown,
12258                         test_AES_GCM_auth_encryption_test_case_192_7),
12259
12260                 /** AES GCM Authenticated Decryption 192 bits key */
12261                 TEST_CASE_ST(ut_setup, ut_teardown,
12262                         test_AES_GCM_auth_decryption_test_case_192_1),
12263                 TEST_CASE_ST(ut_setup, ut_teardown,
12264                         test_AES_GCM_auth_decryption_test_case_192_2),
12265                 TEST_CASE_ST(ut_setup, ut_teardown,
12266                         test_AES_GCM_auth_decryption_test_case_192_3),
12267                 TEST_CASE_ST(ut_setup, ut_teardown,
12268                         test_AES_GCM_auth_decryption_test_case_192_4),
12269                 TEST_CASE_ST(ut_setup, ut_teardown,
12270                         test_AES_GCM_auth_decryption_test_case_192_5),
12271                 TEST_CASE_ST(ut_setup, ut_teardown,
12272                         test_AES_GCM_auth_decryption_test_case_192_6),
12273                 TEST_CASE_ST(ut_setup, ut_teardown,
12274                         test_AES_GCM_auth_decryption_test_case_192_7),
12275
12276                 /** AES GCM Authenticated Encryption 256 bits key */
12277                 TEST_CASE_ST(ut_setup, ut_teardown,
12278                         test_AES_GCM_auth_encryption_test_case_256_1),
12279                 TEST_CASE_ST(ut_setup, ut_teardown,
12280                         test_AES_GCM_auth_encryption_test_case_256_2),
12281                 TEST_CASE_ST(ut_setup, ut_teardown,
12282                         test_AES_GCM_auth_encryption_test_case_256_3),
12283                 TEST_CASE_ST(ut_setup, ut_teardown,
12284                         test_AES_GCM_auth_encryption_test_case_256_4),
12285                 TEST_CASE_ST(ut_setup, ut_teardown,
12286                         test_AES_GCM_auth_encryption_test_case_256_5),
12287                 TEST_CASE_ST(ut_setup, ut_teardown,
12288                         test_AES_GCM_auth_encryption_test_case_256_6),
12289                 TEST_CASE_ST(ut_setup, ut_teardown,
12290                         test_AES_GCM_auth_encryption_test_case_256_7),
12291
12292                 /** AES GCM Authenticated Decryption 256 bits key */
12293                 TEST_CASE_ST(ut_setup, ut_teardown,
12294                         test_AES_GCM_auth_decryption_test_case_256_1),
12295                 TEST_CASE_ST(ut_setup, ut_teardown,
12296                         test_AES_GCM_auth_decryption_test_case_256_2),
12297                 TEST_CASE_ST(ut_setup, ut_teardown,
12298                         test_AES_GCM_auth_decryption_test_case_256_3),
12299                 TEST_CASE_ST(ut_setup, ut_teardown,
12300                         test_AES_GCM_auth_decryption_test_case_256_4),
12301                 TEST_CASE_ST(ut_setup, ut_teardown,
12302                         test_AES_GCM_auth_decryption_test_case_256_5),
12303                 TEST_CASE_ST(ut_setup, ut_teardown,
12304                         test_AES_GCM_auth_decryption_test_case_256_6),
12305                 TEST_CASE_ST(ut_setup, ut_teardown,
12306                         test_AES_GCM_auth_decryption_test_case_256_7),
12307
12308                 /** Out of place tests */
12309                 TEST_CASE_ST(ut_setup, ut_teardown,
12310                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12311                 TEST_CASE_ST(ut_setup, ut_teardown,
12312                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12313
12314                 /** SNOW 3G encrypt only (UEA2) */
12315                 TEST_CASE_ST(ut_setup, ut_teardown,
12316                         test_snow3g_encryption_test_case_1),
12317                 TEST_CASE_ST(ut_setup, ut_teardown,
12318                         test_snow3g_encryption_test_case_2),
12319                 TEST_CASE_ST(ut_setup, ut_teardown,
12320                         test_snow3g_encryption_test_case_3),
12321                 TEST_CASE_ST(ut_setup, ut_teardown,
12322                         test_snow3g_encryption_test_case_4),
12323                 TEST_CASE_ST(ut_setup, ut_teardown,
12324                         test_snow3g_encryption_test_case_5),
12325
12326                 TEST_CASE_ST(ut_setup, ut_teardown,
12327                         test_snow3g_encryption_test_case_1_oop),
12328                 TEST_CASE_ST(ut_setup, ut_teardown,
12329                                 test_snow3g_encryption_test_case_1_oop_sgl),
12330                 TEST_CASE_ST(ut_setup, ut_teardown,
12331                         test_snow3g_decryption_test_case_1_oop),
12332
12333                 /** SNOW 3G decrypt only (UEA2) */
12334                 TEST_CASE_ST(ut_setup, ut_teardown,
12335                         test_snow3g_decryption_test_case_1),
12336                 TEST_CASE_ST(ut_setup, ut_teardown,
12337                         test_snow3g_decryption_test_case_2),
12338                 TEST_CASE_ST(ut_setup, ut_teardown,
12339                         test_snow3g_decryption_test_case_3),
12340                 TEST_CASE_ST(ut_setup, ut_teardown,
12341                         test_snow3g_decryption_test_case_4),
12342                 TEST_CASE_ST(ut_setup, ut_teardown,
12343                         test_snow3g_decryption_test_case_5),
12344
12345                 TEST_CASE_ST(ut_setup, ut_teardown,
12346                         test_snow3g_hash_generate_test_case_1),
12347                 TEST_CASE_ST(ut_setup, ut_teardown,
12348                         test_snow3g_hash_generate_test_case_2),
12349                 TEST_CASE_ST(ut_setup, ut_teardown,
12350                         test_snow3g_hash_generate_test_case_3),
12351                 TEST_CASE_ST(ut_setup, ut_teardown,
12352                         test_snow3g_hash_verify_test_case_1),
12353                 TEST_CASE_ST(ut_setup, ut_teardown,
12354                         test_snow3g_hash_verify_test_case_2),
12355                 TEST_CASE_ST(ut_setup, ut_teardown,
12356                         test_snow3g_hash_verify_test_case_3),
12357
12358                 /** ZUC encrypt only (EEA3) */
12359                 TEST_CASE_ST(ut_setup, ut_teardown,
12360                         test_zuc_encryption_test_case_1),
12361                 TEST_CASE_ST(ut_setup, ut_teardown,
12362                         test_zuc_encryption_test_case_2),
12363                 TEST_CASE_ST(ut_setup, ut_teardown,
12364                         test_zuc_encryption_test_case_3),
12365                 TEST_CASE_ST(ut_setup, ut_teardown,
12366                         test_zuc_encryption_test_case_4),
12367                 TEST_CASE_ST(ut_setup, ut_teardown,
12368                         test_zuc_encryption_test_case_5),
12369
12370                 /** ZUC authenticate (EIA3) */
12371                 TEST_CASE_ST(ut_setup, ut_teardown,
12372                         test_zuc_hash_generate_test_case_6),
12373                 TEST_CASE_ST(ut_setup, ut_teardown,
12374                         test_zuc_hash_generate_test_case_7),
12375                 TEST_CASE_ST(ut_setup, ut_teardown,
12376                         test_zuc_hash_generate_test_case_8),
12377
12378                 /** Negative tests */
12379                 TEST_CASE_ST(ut_setup, ut_teardown,
12380                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12381                 TEST_CASE_ST(ut_setup, ut_teardown,
12382                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12383                 TEST_CASE_ST(ut_setup, ut_teardown,
12384                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12385                 TEST_CASE_ST(ut_setup, ut_teardown,
12386                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12387                 TEST_CASE_ST(ut_setup, ut_teardown,
12388                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12389                 TEST_CASE_ST(ut_setup, ut_teardown,
12390                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12391                 TEST_CASE_ST(ut_setup, ut_teardown,
12392                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12393                 TEST_CASE_ST(ut_setup, ut_teardown,
12394                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12395                 TEST_CASE_ST(ut_setup, ut_teardown,
12396                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12397                 TEST_CASE_ST(ut_setup, ut_teardown,
12398                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12399                 TEST_CASE_ST(ut_setup, ut_teardown,
12400                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12401                 TEST_CASE_ST(ut_setup, ut_teardown,
12402                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12403                 TEST_CASE_ST(ut_setup, ut_teardown,
12404                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12405                 TEST_CASE_ST(ut_setup, ut_teardown,
12406                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12407                 TEST_CASE_ST(ut_setup, ut_teardown,
12408                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12409                 TEST_CASE_ST(ut_setup, ut_teardown,
12410                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12411
12412                 /* ESN Testcase */
12413                 TEST_CASE_ST(ut_setup, ut_teardown,
12414                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12415                 TEST_CASE_ST(ut_setup, ut_teardown,
12416                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12417
12418                 TEST_CASES_END() /**< NULL terminate unit test array */
12419         }
12420 };
12421
12422 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
12423         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
12424         .setup = testsuite_setup,
12425         .teardown = testsuite_teardown,
12426         .unit_test_cases = {
12427                 TEST_CASE_ST(ut_setup, ut_teardown,
12428                         test_device_configure_invalid_dev_id),
12429                 TEST_CASE_ST(ut_setup, ut_teardown,
12430                         test_multi_session),
12431                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12432                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12433                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12434                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12435                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12436
12437 #ifdef RTE_LIBRTE_SECURITY
12438                 TEST_CASE_ST(ut_setup, ut_teardown,
12439                         test_PDCP_PROTO_cplane_encap_all),
12440
12441                 TEST_CASE_ST(ut_setup, ut_teardown,
12442                         test_PDCP_PROTO_cplane_decap_all),
12443
12444                 TEST_CASE_ST(ut_setup, ut_teardown,
12445                         test_PDCP_PROTO_uplane_encap_all),
12446
12447                 TEST_CASE_ST(ut_setup, ut_teardown,
12448                         test_PDCP_PROTO_uplane_decap_all),
12449
12450                 TEST_CASE_ST(ut_setup, ut_teardown,
12451                         test_PDCP_PROTO_SGL_in_place_32B),
12452                 TEST_CASE_ST(ut_setup, ut_teardown,
12453                         test_PDCP_PROTO_SGL_oop_32B_128B),
12454                 TEST_CASE_ST(ut_setup, ut_teardown,
12455                         test_PDCP_PROTO_SGL_oop_32B_40B),
12456                 TEST_CASE_ST(ut_setup, ut_teardown,
12457                         test_PDCP_PROTO_SGL_oop_128B_32B),
12458 #endif
12459                 /** AES GCM Authenticated Encryption */
12460                 TEST_CASE_ST(ut_setup, ut_teardown,
12461                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12462                 TEST_CASE_ST(ut_setup, ut_teardown,
12463                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12464                 TEST_CASE_ST(ut_setup, ut_teardown,
12465                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12466                 TEST_CASE_ST(ut_setup, ut_teardown,
12467                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12468                 TEST_CASE_ST(ut_setup, ut_teardown,
12469                         test_AES_GCM_authenticated_encryption_test_case_1),
12470                 TEST_CASE_ST(ut_setup, ut_teardown,
12471                         test_AES_GCM_authenticated_encryption_test_case_2),
12472                 TEST_CASE_ST(ut_setup, ut_teardown,
12473                         test_AES_GCM_authenticated_encryption_test_case_3),
12474                 TEST_CASE_ST(ut_setup, ut_teardown,
12475                         test_AES_GCM_authenticated_encryption_test_case_4),
12476                 TEST_CASE_ST(ut_setup, ut_teardown,
12477                         test_AES_GCM_authenticated_encryption_test_case_5),
12478                 TEST_CASE_ST(ut_setup, ut_teardown,
12479                         test_AES_GCM_authenticated_encryption_test_case_6),
12480                 TEST_CASE_ST(ut_setup, ut_teardown,
12481                         test_AES_GCM_authenticated_encryption_test_case_7),
12482                 TEST_CASE_ST(ut_setup, ut_teardown,
12483                         test_AES_GCM_authenticated_encryption_test_case_8),
12484
12485                 /** AES GCM Authenticated Decryption */
12486                 TEST_CASE_ST(ut_setup, ut_teardown,
12487                         test_AES_GCM_authenticated_decryption_test_case_1),
12488                 TEST_CASE_ST(ut_setup, ut_teardown,
12489                         test_AES_GCM_authenticated_decryption_test_case_2),
12490                 TEST_CASE_ST(ut_setup, ut_teardown,
12491                         test_AES_GCM_authenticated_decryption_test_case_3),
12492                 TEST_CASE_ST(ut_setup, ut_teardown,
12493                         test_AES_GCM_authenticated_decryption_test_case_4),
12494                 TEST_CASE_ST(ut_setup, ut_teardown,
12495                         test_AES_GCM_authenticated_decryption_test_case_5),
12496                 TEST_CASE_ST(ut_setup, ut_teardown,
12497                         test_AES_GCM_authenticated_decryption_test_case_6),
12498                 TEST_CASE_ST(ut_setup, ut_teardown,
12499                         test_AES_GCM_authenticated_decryption_test_case_7),
12500                 TEST_CASE_ST(ut_setup, ut_teardown,
12501                         test_AES_GCM_authenticated_decryption_test_case_8),
12502
12503                 /** AES GCM Authenticated Encryption 192 bits key */
12504                 TEST_CASE_ST(ut_setup, ut_teardown,
12505                         test_AES_GCM_auth_encryption_test_case_192_1),
12506                 TEST_CASE_ST(ut_setup, ut_teardown,
12507                         test_AES_GCM_auth_encryption_test_case_192_2),
12508                 TEST_CASE_ST(ut_setup, ut_teardown,
12509                         test_AES_GCM_auth_encryption_test_case_192_3),
12510                 TEST_CASE_ST(ut_setup, ut_teardown,
12511                         test_AES_GCM_auth_encryption_test_case_192_4),
12512                 TEST_CASE_ST(ut_setup, ut_teardown,
12513                         test_AES_GCM_auth_encryption_test_case_192_5),
12514                 TEST_CASE_ST(ut_setup, ut_teardown,
12515                         test_AES_GCM_auth_encryption_test_case_192_6),
12516                 TEST_CASE_ST(ut_setup, ut_teardown,
12517                         test_AES_GCM_auth_encryption_test_case_192_7),
12518
12519                 /** AES GCM Authenticated Decryption 192 bits key */
12520                 TEST_CASE_ST(ut_setup, ut_teardown,
12521                         test_AES_GCM_auth_decryption_test_case_192_1),
12522                 TEST_CASE_ST(ut_setup, ut_teardown,
12523                         test_AES_GCM_auth_decryption_test_case_192_2),
12524                 TEST_CASE_ST(ut_setup, ut_teardown,
12525                         test_AES_GCM_auth_decryption_test_case_192_3),
12526                 TEST_CASE_ST(ut_setup, ut_teardown,
12527                         test_AES_GCM_auth_decryption_test_case_192_4),
12528                 TEST_CASE_ST(ut_setup, ut_teardown,
12529                         test_AES_GCM_auth_decryption_test_case_192_5),
12530                 TEST_CASE_ST(ut_setup, ut_teardown,
12531                         test_AES_GCM_auth_decryption_test_case_192_6),
12532                 TEST_CASE_ST(ut_setup, ut_teardown,
12533                         test_AES_GCM_auth_decryption_test_case_192_7),
12534
12535                 /** AES GCM Authenticated Encryption 256 bits key */
12536                 TEST_CASE_ST(ut_setup, ut_teardown,
12537                         test_AES_GCM_auth_encryption_test_case_256_1),
12538                 TEST_CASE_ST(ut_setup, ut_teardown,
12539                         test_AES_GCM_auth_encryption_test_case_256_2),
12540                 TEST_CASE_ST(ut_setup, ut_teardown,
12541                         test_AES_GCM_auth_encryption_test_case_256_3),
12542                 TEST_CASE_ST(ut_setup, ut_teardown,
12543                         test_AES_GCM_auth_encryption_test_case_256_4),
12544                 TEST_CASE_ST(ut_setup, ut_teardown,
12545                         test_AES_GCM_auth_encryption_test_case_256_5),
12546                 TEST_CASE_ST(ut_setup, ut_teardown,
12547                         test_AES_GCM_auth_encryption_test_case_256_6),
12548                 TEST_CASE_ST(ut_setup, ut_teardown,
12549                         test_AES_GCM_auth_encryption_test_case_256_7),
12550
12551                 /** AES GCM Authenticated Decryption 256 bits key */
12552                 TEST_CASE_ST(ut_setup, ut_teardown,
12553                         test_AES_GCM_auth_decryption_test_case_256_1),
12554                 TEST_CASE_ST(ut_setup, ut_teardown,
12555                         test_AES_GCM_auth_decryption_test_case_256_2),
12556                 TEST_CASE_ST(ut_setup, ut_teardown,
12557                         test_AES_GCM_auth_decryption_test_case_256_3),
12558                 TEST_CASE_ST(ut_setup, ut_teardown,
12559                         test_AES_GCM_auth_decryption_test_case_256_4),
12560                 TEST_CASE_ST(ut_setup, ut_teardown,
12561                         test_AES_GCM_auth_decryption_test_case_256_5),
12562                 TEST_CASE_ST(ut_setup, ut_teardown,
12563                         test_AES_GCM_auth_decryption_test_case_256_6),
12564                 TEST_CASE_ST(ut_setup, ut_teardown,
12565                         test_AES_GCM_auth_decryption_test_case_256_7),
12566
12567                 /** Out of place tests */
12568                 TEST_CASE_ST(ut_setup, ut_teardown,
12569                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12570                 TEST_CASE_ST(ut_setup, ut_teardown,
12571                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12572
12573                 /** SNOW 3G encrypt only (UEA2) */
12574                 TEST_CASE_ST(ut_setup, ut_teardown,
12575                         test_snow3g_encryption_test_case_1),
12576                 TEST_CASE_ST(ut_setup, ut_teardown,
12577                         test_snow3g_encryption_test_case_2),
12578                 TEST_CASE_ST(ut_setup, ut_teardown,
12579                         test_snow3g_encryption_test_case_3),
12580                 TEST_CASE_ST(ut_setup, ut_teardown,
12581                         test_snow3g_encryption_test_case_4),
12582                 TEST_CASE_ST(ut_setup, ut_teardown,
12583                         test_snow3g_encryption_test_case_5),
12584
12585                 TEST_CASE_ST(ut_setup, ut_teardown,
12586                         test_snow3g_encryption_test_case_1_oop),
12587                 TEST_CASE_ST(ut_setup, ut_teardown,
12588                                 test_snow3g_encryption_test_case_1_oop_sgl),
12589                 TEST_CASE_ST(ut_setup, ut_teardown,
12590                         test_snow3g_decryption_test_case_1_oop),
12591
12592                 /** SNOW 3G decrypt only (UEA2) */
12593                 TEST_CASE_ST(ut_setup, ut_teardown,
12594                         test_snow3g_decryption_test_case_1),
12595                 TEST_CASE_ST(ut_setup, ut_teardown,
12596                         test_snow3g_decryption_test_case_2),
12597                 TEST_CASE_ST(ut_setup, ut_teardown,
12598                         test_snow3g_decryption_test_case_3),
12599                 TEST_CASE_ST(ut_setup, ut_teardown,
12600                         test_snow3g_decryption_test_case_4),
12601                 TEST_CASE_ST(ut_setup, ut_teardown,
12602                         test_snow3g_decryption_test_case_5),
12603
12604                 TEST_CASE_ST(ut_setup, ut_teardown,
12605                         test_snow3g_hash_generate_test_case_1),
12606                 TEST_CASE_ST(ut_setup, ut_teardown,
12607                         test_snow3g_hash_generate_test_case_2),
12608                 TEST_CASE_ST(ut_setup, ut_teardown,
12609                         test_snow3g_hash_generate_test_case_3),
12610                 TEST_CASE_ST(ut_setup, ut_teardown,
12611                         test_snow3g_hash_verify_test_case_1),
12612                 TEST_CASE_ST(ut_setup, ut_teardown,
12613                         test_snow3g_hash_verify_test_case_2),
12614                 TEST_CASE_ST(ut_setup, ut_teardown,
12615                         test_snow3g_hash_verify_test_case_3),
12616
12617                 /** ZUC encrypt only (EEA3) */
12618                 TEST_CASE_ST(ut_setup, ut_teardown,
12619                         test_zuc_encryption_test_case_1),
12620                 TEST_CASE_ST(ut_setup, ut_teardown,
12621                         test_zuc_encryption_test_case_2),
12622                 TEST_CASE_ST(ut_setup, ut_teardown,
12623                         test_zuc_encryption_test_case_3),
12624                 TEST_CASE_ST(ut_setup, ut_teardown,
12625                         test_zuc_encryption_test_case_4),
12626                 TEST_CASE_ST(ut_setup, ut_teardown,
12627                         test_zuc_encryption_test_case_5),
12628
12629                 /** ZUC authenticate (EIA3) */
12630                 TEST_CASE_ST(ut_setup, ut_teardown,
12631                         test_zuc_hash_generate_test_case_6),
12632                 TEST_CASE_ST(ut_setup, ut_teardown,
12633                         test_zuc_hash_generate_test_case_7),
12634                 TEST_CASE_ST(ut_setup, ut_teardown,
12635                         test_zuc_hash_generate_test_case_8),
12636
12637                 /** HMAC_MD5 Authentication */
12638                 TEST_CASE_ST(ut_setup, ut_teardown,
12639                         test_MD5_HMAC_generate_case_1),
12640                 TEST_CASE_ST(ut_setup, ut_teardown,
12641                         test_MD5_HMAC_verify_case_1),
12642                 TEST_CASE_ST(ut_setup, ut_teardown,
12643                         test_MD5_HMAC_generate_case_2),
12644                 TEST_CASE_ST(ut_setup, ut_teardown,
12645                         test_MD5_HMAC_verify_case_2),
12646
12647                 /** Negative tests */
12648                 TEST_CASE_ST(ut_setup, ut_teardown,
12649                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12650                 TEST_CASE_ST(ut_setup, ut_teardown,
12651                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12652                 TEST_CASE_ST(ut_setup, ut_teardown,
12653                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12654                 TEST_CASE_ST(ut_setup, ut_teardown,
12655                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12656                 TEST_CASE_ST(ut_setup, ut_teardown,
12657                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12658                 TEST_CASE_ST(ut_setup, ut_teardown,
12659                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12660                 TEST_CASE_ST(ut_setup, ut_teardown,
12661                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12662                 TEST_CASE_ST(ut_setup, ut_teardown,
12663                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12664                 TEST_CASE_ST(ut_setup, ut_teardown,
12665                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12666                 TEST_CASE_ST(ut_setup, ut_teardown,
12667                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12668                 TEST_CASE_ST(ut_setup, ut_teardown,
12669                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12670                 TEST_CASE_ST(ut_setup, ut_teardown,
12671                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12672                 TEST_CASE_ST(ut_setup, ut_teardown,
12673                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12674                 TEST_CASE_ST(ut_setup, ut_teardown,
12675                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12676                 TEST_CASE_ST(ut_setup, ut_teardown,
12677                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12678                 TEST_CASE_ST(ut_setup, ut_teardown,
12679                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12680
12681                 /* ESN Testcase */
12682                 TEST_CASE_ST(ut_setup, ut_teardown,
12683                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12684
12685                 TEST_CASE_ST(ut_setup, ut_teardown,
12686                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12687
12688                 TEST_CASES_END() /**< NULL terminate unit test array */
12689         }
12690 };
12691
12692 static struct unit_test_suite cryptodev_armv8_testsuite  = {
12693         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
12694         .setup = testsuite_setup,
12695         .teardown = testsuite_teardown,
12696         .unit_test_cases = {
12697                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12698
12699                 /** Negative tests */
12700                 TEST_CASE_ST(ut_setup, ut_teardown,
12701                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12702                 TEST_CASE_ST(ut_setup, ut_teardown,
12703                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12704
12705                 TEST_CASES_END() /**< NULL terminate unit test array */
12706         }
12707 };
12708
12709 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
12710         .suite_name = "Crypto Device Marvell Component Test Suite",
12711         .setup = testsuite_setup,
12712         .teardown = testsuite_teardown,
12713         .unit_test_cases = {
12714                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12715                 TEST_CASE_ST(ut_setup, ut_teardown,
12716                                 test_multi_session_random_usage),
12717                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12718                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12719                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12720                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12721                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12722
12723                 /** Negative tests */
12724                 TEST_CASE_ST(ut_setup, ut_teardown,
12725                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12726                 TEST_CASE_ST(ut_setup, ut_teardown,
12727                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12728                 TEST_CASE_ST(ut_setup, ut_teardown,
12729                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12730                 TEST_CASE_ST(ut_setup, ut_teardown,
12731                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12732
12733                 TEST_CASES_END() /**< NULL terminate unit test array */
12734         }
12735 };
12736
12737 static struct unit_test_suite cryptodev_ccp_testsuite  = {
12738         .suite_name = "Crypto Device CCP Unit Test Suite",
12739         .setup = testsuite_setup,
12740         .teardown = testsuite_teardown,
12741         .unit_test_cases = {
12742                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12743                 TEST_CASE_ST(ut_setup, ut_teardown,
12744                                 test_multi_session_random_usage),
12745                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12746                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12747                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12748                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12749                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12750
12751                 /** Negative tests */
12752                 TEST_CASE_ST(ut_setup, ut_teardown,
12753                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12754                 TEST_CASE_ST(ut_setup, ut_teardown,
12755                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12756                 TEST_CASE_ST(ut_setup, ut_teardown,
12757                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12758                 TEST_CASE_ST(ut_setup, ut_teardown,
12759                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12760
12761                 TEST_CASES_END() /**< NULL terminate unit test array */
12762         }
12763 };
12764
12765 static struct unit_test_suite cryptodev_octeontx_testsuite  = {
12766         .suite_name = "Crypto Device OCTEONTX Unit Test Suite",
12767         .setup = testsuite_setup,
12768         .teardown = testsuite_teardown,
12769         .unit_test_cases = {
12770                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12771                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12772                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12773                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12774                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12775
12776                 /** AES GCM Authenticated Encryption */
12777                 TEST_CASE_ST(ut_setup, ut_teardown,
12778                         test_AES_GCM_authenticated_encryption_test_case_1),
12779                 TEST_CASE_ST(ut_setup, ut_teardown,
12780                         test_AES_GCM_authenticated_encryption_test_case_2),
12781                 TEST_CASE_ST(ut_setup, ut_teardown,
12782                         test_AES_GCM_authenticated_encryption_test_case_3),
12783                 TEST_CASE_ST(ut_setup, ut_teardown,
12784                         test_AES_GCM_authenticated_encryption_test_case_4),
12785                 TEST_CASE_ST(ut_setup, ut_teardown,
12786                         test_AES_GCM_authenticated_encryption_test_case_5),
12787                 TEST_CASE_ST(ut_setup, ut_teardown,
12788                         test_AES_GCM_authenticated_encryption_test_case_6),
12789                 TEST_CASE_ST(ut_setup, ut_teardown,
12790                         test_AES_GCM_authenticated_encryption_test_case_7),
12791
12792                 /** AES GCM Authenticated Decryption */
12793                 TEST_CASE_ST(ut_setup, ut_teardown,
12794                         test_AES_GCM_authenticated_decryption_test_case_1),
12795                 TEST_CASE_ST(ut_setup, ut_teardown,
12796                         test_AES_GCM_authenticated_decryption_test_case_2),
12797                 TEST_CASE_ST(ut_setup, ut_teardown,
12798                         test_AES_GCM_authenticated_decryption_test_case_3),
12799                 TEST_CASE_ST(ut_setup, ut_teardown,
12800                         test_AES_GCM_authenticated_decryption_test_case_4),
12801                 TEST_CASE_ST(ut_setup, ut_teardown,
12802                         test_AES_GCM_authenticated_decryption_test_case_5),
12803                 TEST_CASE_ST(ut_setup, ut_teardown,
12804                         test_AES_GCM_authenticated_decryption_test_case_6),
12805                 TEST_CASE_ST(ut_setup, ut_teardown,
12806                         test_AES_GCM_authenticated_decryption_test_case_7),
12807                 /** AES GMAC Authentication */
12808                 TEST_CASE_ST(ut_setup, ut_teardown,
12809                         test_AES_GMAC_authentication_test_case_1),
12810                 TEST_CASE_ST(ut_setup, ut_teardown,
12811                         test_AES_GMAC_authentication_verify_test_case_1),
12812                 TEST_CASE_ST(ut_setup, ut_teardown,
12813                         test_AES_GMAC_authentication_test_case_2),
12814                 TEST_CASE_ST(ut_setup, ut_teardown,
12815                         test_AES_GMAC_authentication_verify_test_case_2),
12816                 TEST_CASE_ST(ut_setup, ut_teardown,
12817                         test_AES_GMAC_authentication_test_case_3),
12818                 TEST_CASE_ST(ut_setup, ut_teardown,
12819                         test_AES_GMAC_authentication_verify_test_case_3),
12820
12821                 /** SNOW 3G encrypt only (UEA2) */
12822                 TEST_CASE_ST(ut_setup, ut_teardown,
12823                         test_snow3g_encryption_test_case_1),
12824                 TEST_CASE_ST(ut_setup, ut_teardown,
12825                         test_snow3g_encryption_test_case_2),
12826                 TEST_CASE_ST(ut_setup, ut_teardown,
12827                         test_snow3g_encryption_test_case_3),
12828                 TEST_CASE_ST(ut_setup, ut_teardown,
12829                         test_snow3g_encryption_test_case_4),
12830                 TEST_CASE_ST(ut_setup, ut_teardown,
12831                         test_snow3g_encryption_test_case_5),
12832
12833                 TEST_CASE_ST(ut_setup, ut_teardown,
12834                         test_snow3g_encryption_test_case_1_oop),
12835                 TEST_CASE_ST(ut_setup, ut_teardown,
12836                         test_snow3g_decryption_test_case_1_oop),
12837                 TEST_CASE_ST(ut_setup, ut_teardown,
12838                         test_snow3g_encryption_test_case_1_oop_sgl),
12839
12840                 /** SNOW 3G decrypt only (UEA2) */
12841                 TEST_CASE_ST(ut_setup, ut_teardown,
12842                         test_snow3g_decryption_test_case_1),
12843                 TEST_CASE_ST(ut_setup, ut_teardown,
12844                         test_snow3g_decryption_test_case_2),
12845                 TEST_CASE_ST(ut_setup, ut_teardown,
12846                         test_snow3g_decryption_test_case_3),
12847                 TEST_CASE_ST(ut_setup, ut_teardown,
12848                         test_snow3g_decryption_test_case_4),
12849                 TEST_CASE_ST(ut_setup, ut_teardown,
12850                         test_snow3g_decryption_test_case_5),
12851
12852                 TEST_CASE_ST(ut_setup, ut_teardown,
12853                         test_snow3g_hash_generate_test_case_1),
12854                 TEST_CASE_ST(ut_setup, ut_teardown,
12855                         test_snow3g_hash_generate_test_case_2),
12856                 TEST_CASE_ST(ut_setup, ut_teardown,
12857                         test_snow3g_hash_generate_test_case_3),
12858                 TEST_CASE_ST(ut_setup, ut_teardown,
12859                         test_snow3g_hash_verify_test_case_1),
12860                 TEST_CASE_ST(ut_setup, ut_teardown,
12861                         test_snow3g_hash_verify_test_case_2),
12862                 TEST_CASE_ST(ut_setup, ut_teardown,
12863                         test_snow3g_hash_verify_test_case_3),
12864
12865                 /** ZUC encrypt only (EEA3) */
12866                 TEST_CASE_ST(ut_setup, ut_teardown,
12867                         test_zuc_encryption_test_case_1),
12868                 TEST_CASE_ST(ut_setup, ut_teardown,
12869                         test_zuc_encryption_test_case_2),
12870                 TEST_CASE_ST(ut_setup, ut_teardown,
12871                         test_zuc_encryption_test_case_3),
12872                 TEST_CASE_ST(ut_setup, ut_teardown,
12873                         test_zuc_encryption_test_case_4),
12874                 TEST_CASE_ST(ut_setup, ut_teardown,
12875                         test_zuc_encryption_test_case_5),
12876                 TEST_CASE_ST(ut_setup, ut_teardown,
12877                         test_zuc_hash_generate_test_case_1),
12878                 TEST_CASE_ST(ut_setup, ut_teardown,
12879                         test_zuc_hash_generate_test_case_2),
12880                 TEST_CASE_ST(ut_setup, ut_teardown,
12881                         test_zuc_hash_generate_test_case_3),
12882                 TEST_CASE_ST(ut_setup, ut_teardown,
12883                         test_zuc_hash_generate_test_case_4),
12884                 TEST_CASE_ST(ut_setup, ut_teardown,
12885                         test_zuc_hash_generate_test_case_5),
12886                 TEST_CASE_ST(ut_setup, ut_teardown,
12887                         test_zuc_encryption_test_case_6_sgl),
12888
12889                 /** KASUMI encrypt only (UEA1) */
12890                 TEST_CASE_ST(ut_setup, ut_teardown,
12891                         test_kasumi_encryption_test_case_1),
12892                 TEST_CASE_ST(ut_setup, ut_teardown,
12893                         test_kasumi_encryption_test_case_2),
12894                 TEST_CASE_ST(ut_setup, ut_teardown,
12895                         test_kasumi_encryption_test_case_3),
12896                 TEST_CASE_ST(ut_setup, ut_teardown,
12897                         test_kasumi_encryption_test_case_4),
12898                 TEST_CASE_ST(ut_setup, ut_teardown,
12899                         test_kasumi_encryption_test_case_5),
12900                 TEST_CASE_ST(ut_setup, ut_teardown,
12901                         test_kasumi_encryption_test_case_1_sgl),
12902                 TEST_CASE_ST(ut_setup, ut_teardown,
12903                         test_kasumi_encryption_test_case_1_oop_sgl),
12904                 /** KASUMI decrypt only (UEA1) */
12905                 TEST_CASE_ST(ut_setup, ut_teardown,
12906                         test_kasumi_decryption_test_case_1),
12907                 TEST_CASE_ST(ut_setup, ut_teardown,
12908                         test_kasumi_decryption_test_case_2),
12909                 TEST_CASE_ST(ut_setup, ut_teardown,
12910                         test_kasumi_decryption_test_case_3),
12911                 TEST_CASE_ST(ut_setup, ut_teardown,
12912                         test_kasumi_decryption_test_case_4),
12913                 TEST_CASE_ST(ut_setup, ut_teardown,
12914                         test_kasumi_decryption_test_case_5),
12915
12916                 TEST_CASE_ST(ut_setup, ut_teardown,
12917                         test_kasumi_encryption_test_case_1_oop),
12918                 TEST_CASE_ST(ut_setup, ut_teardown,
12919                         test_kasumi_decryption_test_case_1_oop),
12920
12921                 /** KASUMI hash only (UIA1) */
12922                 TEST_CASE_ST(ut_setup, ut_teardown,
12923                         test_kasumi_hash_generate_test_case_1),
12924                 TEST_CASE_ST(ut_setup, ut_teardown,
12925                         test_kasumi_hash_generate_test_case_2),
12926                 TEST_CASE_ST(ut_setup, ut_teardown,
12927                         test_kasumi_hash_generate_test_case_3),
12928                 TEST_CASE_ST(ut_setup, ut_teardown,
12929                         test_kasumi_hash_generate_test_case_4),
12930                 TEST_CASE_ST(ut_setup, ut_teardown,
12931                         test_kasumi_hash_generate_test_case_5),
12932                 TEST_CASE_ST(ut_setup, ut_teardown,
12933                         test_kasumi_hash_generate_test_case_6),
12934                 TEST_CASE_ST(ut_setup, ut_teardown,
12935                         test_kasumi_hash_verify_test_case_1),
12936                 TEST_CASE_ST(ut_setup, ut_teardown,
12937                         test_kasumi_hash_verify_test_case_2),
12938                 TEST_CASE_ST(ut_setup, ut_teardown,
12939                         test_kasumi_hash_verify_test_case_3),
12940                 TEST_CASE_ST(ut_setup, ut_teardown,
12941                         test_kasumi_hash_verify_test_case_4),
12942                 TEST_CASE_ST(ut_setup, ut_teardown,
12943                         test_kasumi_hash_verify_test_case_5),
12944
12945                 /** NULL tests */
12946                 TEST_CASE_ST(ut_setup, ut_teardown,
12947                         test_null_cipher_only_operation),
12948                 TEST_CASE_ST(ut_setup, ut_teardown,
12949                         test_null_auth_only_operation),
12950                 TEST_CASE_ST(ut_setup, ut_teardown,
12951                         test_null_cipher_auth_operation),
12952                 TEST_CASE_ST(ut_setup, ut_teardown,
12953                         test_null_auth_cipher_operation),
12954
12955                 /** Negative tests */
12956                 TEST_CASE_ST(ut_setup, ut_teardown,
12957                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12958                 TEST_CASE_ST(ut_setup, ut_teardown,
12959                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12960                 TEST_CASE_ST(ut_setup, ut_teardown,
12961                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12962                 TEST_CASE_ST(ut_setup, ut_teardown,
12963                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12964                 TEST_CASE_ST(ut_setup, ut_teardown,
12965                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12966                 TEST_CASE_ST(ut_setup, ut_teardown,
12967                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12968                 TEST_CASES_END() /**< NULL terminate unit test array */
12969         }
12970 };
12971
12972 static struct unit_test_suite cryptodev_nitrox_testsuite  = {
12973         .suite_name = "Crypto NITROX Unit Test Suite",
12974         .setup = testsuite_setup,
12975         .teardown = testsuite_teardown,
12976         .unit_test_cases = {
12977                 TEST_CASE_ST(ut_setup, ut_teardown,
12978                              test_device_configure_invalid_dev_id),
12979                 TEST_CASE_ST(ut_setup, ut_teardown,
12980                                 test_device_configure_invalid_queue_pair_ids),
12981                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12982
12983                 TEST_CASES_END() /**< NULL terminate unit test array */
12984         }
12985 };
12986
12987 static struct unit_test_suite cryptodev_octeontx2_testsuite  = {
12988         .suite_name = "Crypto Device OCTEON TX2 Unit Test Suite",
12989         .setup = testsuite_setup,
12990         .teardown = testsuite_teardown,
12991         .unit_test_cases = {
12992                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12993                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12994                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12995                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12996                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12997
12998                 /** AES GCM Authenticated Encryption */
12999                 TEST_CASE_ST(ut_setup, ut_teardown,
13000                         test_AES_GCM_authenticated_encryption_test_case_1),
13001                 TEST_CASE_ST(ut_setup, ut_teardown,
13002                         test_AES_GCM_authenticated_encryption_test_case_2),
13003                 TEST_CASE_ST(ut_setup, ut_teardown,
13004                         test_AES_GCM_authenticated_encryption_test_case_3),
13005                 TEST_CASE_ST(ut_setup, ut_teardown,
13006                         test_AES_GCM_authenticated_encryption_test_case_4),
13007                 TEST_CASE_ST(ut_setup, ut_teardown,
13008                         test_AES_GCM_authenticated_encryption_test_case_5),
13009                 TEST_CASE_ST(ut_setup, ut_teardown,
13010                         test_AES_GCM_authenticated_encryption_test_case_6),
13011                 TEST_CASE_ST(ut_setup, ut_teardown,
13012                         test_AES_GCM_authenticated_encryption_test_case_7),
13013
13014                 /** AES GCM Authenticated Decryption */
13015                 TEST_CASE_ST(ut_setup, ut_teardown,
13016                         test_AES_GCM_authenticated_decryption_test_case_1),
13017                 TEST_CASE_ST(ut_setup, ut_teardown,
13018                         test_AES_GCM_authenticated_decryption_test_case_2),
13019                 TEST_CASE_ST(ut_setup, ut_teardown,
13020                         test_AES_GCM_authenticated_decryption_test_case_3),
13021                 TEST_CASE_ST(ut_setup, ut_teardown,
13022                         test_AES_GCM_authenticated_decryption_test_case_4),
13023                 TEST_CASE_ST(ut_setup, ut_teardown,
13024                         test_AES_GCM_authenticated_decryption_test_case_5),
13025                 TEST_CASE_ST(ut_setup, ut_teardown,
13026                         test_AES_GCM_authenticated_decryption_test_case_6),
13027                 TEST_CASE_ST(ut_setup, ut_teardown,
13028                         test_AES_GCM_authenticated_decryption_test_case_7),
13029                 /** AES GMAC Authentication */
13030                 TEST_CASE_ST(ut_setup, ut_teardown,
13031                         test_AES_GMAC_authentication_test_case_1),
13032                 TEST_CASE_ST(ut_setup, ut_teardown,
13033                         test_AES_GMAC_authentication_verify_test_case_1),
13034                 TEST_CASE_ST(ut_setup, ut_teardown,
13035                         test_AES_GMAC_authentication_test_case_2),
13036                 TEST_CASE_ST(ut_setup, ut_teardown,
13037                         test_AES_GMAC_authentication_verify_test_case_2),
13038                 TEST_CASE_ST(ut_setup, ut_teardown,
13039                         test_AES_GMAC_authentication_test_case_3),
13040                 TEST_CASE_ST(ut_setup, ut_teardown,
13041                         test_AES_GMAC_authentication_verify_test_case_3),
13042
13043                 /** SNOW 3G encrypt only (UEA2) */
13044                 TEST_CASE_ST(ut_setup, ut_teardown,
13045                         test_snow3g_encryption_test_case_1),
13046                 TEST_CASE_ST(ut_setup, ut_teardown,
13047                         test_snow3g_encryption_test_case_2),
13048                 TEST_CASE_ST(ut_setup, ut_teardown,
13049                         test_snow3g_encryption_test_case_3),
13050                 TEST_CASE_ST(ut_setup, ut_teardown,
13051                         test_snow3g_encryption_test_case_4),
13052                 TEST_CASE_ST(ut_setup, ut_teardown,
13053                         test_snow3g_encryption_test_case_5),
13054
13055                 TEST_CASE_ST(ut_setup, ut_teardown,
13056                         test_snow3g_encryption_test_case_1_oop),
13057                 TEST_CASE_ST(ut_setup, ut_teardown,
13058                         test_snow3g_decryption_test_case_1_oop),
13059                 TEST_CASE_ST(ut_setup, ut_teardown,
13060                         test_snow3g_encryption_test_case_1_oop_sgl),
13061
13062                 /** SNOW 3G decrypt only (UEA2) */
13063                 TEST_CASE_ST(ut_setup, ut_teardown,
13064                         test_snow3g_decryption_test_case_1),
13065                 TEST_CASE_ST(ut_setup, ut_teardown,
13066                         test_snow3g_decryption_test_case_2),
13067                 TEST_CASE_ST(ut_setup, ut_teardown,
13068                         test_snow3g_decryption_test_case_3),
13069                 TEST_CASE_ST(ut_setup, ut_teardown,
13070                         test_snow3g_decryption_test_case_4),
13071                 TEST_CASE_ST(ut_setup, ut_teardown,
13072                         test_snow3g_decryption_test_case_5),
13073
13074                 TEST_CASE_ST(ut_setup, ut_teardown,
13075                         test_snow3g_hash_generate_test_case_1),
13076                 TEST_CASE_ST(ut_setup, ut_teardown,
13077                         test_snow3g_hash_generate_test_case_2),
13078                 TEST_CASE_ST(ut_setup, ut_teardown,
13079                         test_snow3g_hash_generate_test_case_3),
13080                 TEST_CASE_ST(ut_setup, ut_teardown,
13081                         test_snow3g_hash_verify_test_case_1),
13082                 TEST_CASE_ST(ut_setup, ut_teardown,
13083                         test_snow3g_hash_verify_test_case_2),
13084                 TEST_CASE_ST(ut_setup, ut_teardown,
13085                         test_snow3g_hash_verify_test_case_3),
13086
13087                 /** ZUC encrypt only (EEA3) */
13088                 TEST_CASE_ST(ut_setup, ut_teardown,
13089                         test_zuc_encryption_test_case_1),
13090                 TEST_CASE_ST(ut_setup, ut_teardown,
13091                         test_zuc_encryption_test_case_2),
13092                 TEST_CASE_ST(ut_setup, ut_teardown,
13093                         test_zuc_encryption_test_case_3),
13094                 TEST_CASE_ST(ut_setup, ut_teardown,
13095                         test_zuc_encryption_test_case_4),
13096                 TEST_CASE_ST(ut_setup, ut_teardown,
13097                         test_zuc_encryption_test_case_5),
13098                 TEST_CASE_ST(ut_setup, ut_teardown,
13099                         test_zuc_hash_generate_test_case_1),
13100                 TEST_CASE_ST(ut_setup, ut_teardown,
13101                         test_zuc_hash_generate_test_case_2),
13102                 TEST_CASE_ST(ut_setup, ut_teardown,
13103                         test_zuc_hash_generate_test_case_3),
13104                 TEST_CASE_ST(ut_setup, ut_teardown,
13105                         test_zuc_hash_generate_test_case_4),
13106                 TEST_CASE_ST(ut_setup, ut_teardown,
13107                         test_zuc_hash_generate_test_case_5),
13108                 TEST_CASE_ST(ut_setup, ut_teardown,
13109                         test_zuc_encryption_test_case_6_sgl),
13110
13111                 /** KASUMI encrypt only (UEA1) */
13112                 TEST_CASE_ST(ut_setup, ut_teardown,
13113                         test_kasumi_encryption_test_case_1),
13114                 TEST_CASE_ST(ut_setup, ut_teardown,
13115                         test_kasumi_encryption_test_case_2),
13116                 TEST_CASE_ST(ut_setup, ut_teardown,
13117                         test_kasumi_encryption_test_case_3),
13118                 TEST_CASE_ST(ut_setup, ut_teardown,
13119                         test_kasumi_encryption_test_case_4),
13120                 TEST_CASE_ST(ut_setup, ut_teardown,
13121                         test_kasumi_encryption_test_case_5),
13122                 TEST_CASE_ST(ut_setup, ut_teardown,
13123                         test_kasumi_encryption_test_case_1_sgl),
13124                 TEST_CASE_ST(ut_setup, ut_teardown,
13125                         test_kasumi_encryption_test_case_1_oop_sgl),
13126                 /** KASUMI decrypt only (UEA1) */
13127                 TEST_CASE_ST(ut_setup, ut_teardown,
13128                         test_kasumi_decryption_test_case_1),
13129                 TEST_CASE_ST(ut_setup, ut_teardown,
13130                         test_kasumi_decryption_test_case_2),
13131                 TEST_CASE_ST(ut_setup, ut_teardown,
13132                         test_kasumi_decryption_test_case_3),
13133                 TEST_CASE_ST(ut_setup, ut_teardown,
13134                         test_kasumi_decryption_test_case_4),
13135                 TEST_CASE_ST(ut_setup, ut_teardown,
13136                         test_kasumi_decryption_test_case_5),
13137
13138                 TEST_CASE_ST(ut_setup, ut_teardown,
13139                         test_kasumi_encryption_test_case_1_oop),
13140                 TEST_CASE_ST(ut_setup, ut_teardown,
13141                         test_kasumi_decryption_test_case_1_oop),
13142
13143                 /** KASUMI hash only (UIA1) */
13144                 TEST_CASE_ST(ut_setup, ut_teardown,
13145                         test_kasumi_hash_generate_test_case_1),
13146                 TEST_CASE_ST(ut_setup, ut_teardown,
13147                         test_kasumi_hash_generate_test_case_2),
13148                 TEST_CASE_ST(ut_setup, ut_teardown,
13149                         test_kasumi_hash_generate_test_case_3),
13150                 TEST_CASE_ST(ut_setup, ut_teardown,
13151                         test_kasumi_hash_generate_test_case_4),
13152                 TEST_CASE_ST(ut_setup, ut_teardown,
13153                         test_kasumi_hash_generate_test_case_5),
13154                 TEST_CASE_ST(ut_setup, ut_teardown,
13155                         test_kasumi_hash_generate_test_case_6),
13156                 TEST_CASE_ST(ut_setup, ut_teardown,
13157                         test_kasumi_hash_verify_test_case_1),
13158                 TEST_CASE_ST(ut_setup, ut_teardown,
13159                         test_kasumi_hash_verify_test_case_2),
13160                 TEST_CASE_ST(ut_setup, ut_teardown,
13161                         test_kasumi_hash_verify_test_case_3),
13162                 TEST_CASE_ST(ut_setup, ut_teardown,
13163                         test_kasumi_hash_verify_test_case_4),
13164                 TEST_CASE_ST(ut_setup, ut_teardown,
13165                         test_kasumi_hash_verify_test_case_5),
13166
13167                 /** NULL tests */
13168                 TEST_CASE_ST(ut_setup, ut_teardown,
13169                         test_null_cipher_only_operation),
13170                 TEST_CASE_ST(ut_setup, ut_teardown,
13171                         test_null_auth_only_operation),
13172                 TEST_CASE_ST(ut_setup, ut_teardown,
13173                         test_null_cipher_auth_operation),
13174                 TEST_CASE_ST(ut_setup, ut_teardown,
13175                         test_null_auth_cipher_operation),
13176
13177                 /** Negative tests */
13178                 TEST_CASE_ST(ut_setup, ut_teardown,
13179                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13180                 TEST_CASE_ST(ut_setup, ut_teardown,
13181                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13182                 TEST_CASE_ST(ut_setup, ut_teardown,
13183                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13184                 TEST_CASE_ST(ut_setup, ut_teardown,
13185                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13186                 TEST_CASE_ST(ut_setup, ut_teardown,
13187                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13188                 TEST_CASE_ST(ut_setup, ut_teardown,
13189                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13190                 TEST_CASES_END() /**< NULL terminate unit test array */
13191         }
13192 };
13193
13194 static int
13195 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13196 {
13197         gbl_driver_id = rte_cryptodev_driver_id_get(
13198                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13199
13200         if (gbl_driver_id == -1) {
13201                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
13202                 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
13203                 "are enabled in config file to run this testsuite.\n");
13204                 return TEST_SKIPPED;
13205         }
13206
13207         return unit_test_suite_runner(&cryptodev_testsuite);
13208 }
13209
13210 static int
13211 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13212 {
13213         gbl_driver_id = rte_cryptodev_driver_id_get(
13214                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13215
13216         if (gbl_driver_id == -1) {
13217                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
13218                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
13219                                 "in config file to run this testsuite.\n");
13220                 return TEST_FAILED;
13221         }
13222
13223         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13224 }
13225
13226 static int
13227 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13228 {
13229         gbl_driver_id = rte_cryptodev_driver_id_get(
13230                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13231
13232         if (gbl_driver_id == -1) {
13233                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
13234                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
13235                                 "in config file to run this testsuite.\n");
13236                 return TEST_SKIPPED;
13237         }
13238
13239         return unit_test_suite_runner(&cryptodev_testsuite);
13240 }
13241
13242 static int
13243 test_cryptodev_openssl(void)
13244 {
13245         gbl_driver_id = rte_cryptodev_driver_id_get(
13246                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13247
13248         if (gbl_driver_id == -1) {
13249                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
13250                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
13251                                 "in config file to run this testsuite.\n");
13252                 return TEST_SKIPPED;
13253         }
13254
13255         return unit_test_suite_runner(&cryptodev_testsuite);
13256 }
13257
13258 static int
13259 test_cryptodev_aesni_gcm(void)
13260 {
13261         gbl_driver_id = rte_cryptodev_driver_id_get(
13262                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13263
13264         if (gbl_driver_id == -1) {
13265                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
13266                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
13267                                 "in config file to run this testsuite.\n");
13268                 return TEST_SKIPPED;
13269         }
13270
13271         return unit_test_suite_runner(&cryptodev_testsuite);
13272 }
13273
13274 static int
13275 test_cryptodev_null(void)
13276 {
13277         gbl_driver_id = rte_cryptodev_driver_id_get(
13278                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13279
13280         if (gbl_driver_id == -1) {
13281                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
13282                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
13283                                 "in config file to run this testsuite.\n");
13284                 return TEST_SKIPPED;
13285         }
13286
13287         return unit_test_suite_runner(&cryptodev_testsuite);
13288 }
13289
13290 static int
13291 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13292 {
13293         gbl_driver_id = rte_cryptodev_driver_id_get(
13294                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13295
13296         if (gbl_driver_id == -1) {
13297                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
13298                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
13299                                 "in config file to run this testsuite.\n");
13300                 return TEST_SKIPPED;
13301         }
13302
13303         return unit_test_suite_runner(&cryptodev_testsuite);
13304 }
13305
13306 static int
13307 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13308 {
13309         gbl_driver_id = rte_cryptodev_driver_id_get(
13310                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13311
13312         if (gbl_driver_id == -1) {
13313                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13314                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
13315                                 "in config file to run this testsuite.\n");
13316                 return TEST_SKIPPED;
13317         }
13318
13319         return unit_test_suite_runner(&cryptodev_testsuite);
13320 }
13321
13322 static int
13323 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13324 {
13325         gbl_driver_id = rte_cryptodev_driver_id_get(
13326                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13327
13328         if (gbl_driver_id == -1) {
13329                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13330                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
13331                                 "in config file to run this testsuite.\n");
13332                 return TEST_SKIPPED;
13333         }
13334
13335         return unit_test_suite_runner(&cryptodev_testsuite);
13336 }
13337
13338 static int
13339 test_cryptodev_armv8(void)
13340 {
13341         gbl_driver_id = rte_cryptodev_driver_id_get(
13342                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13343
13344         if (gbl_driver_id == -1) {
13345                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
13346                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
13347                                 "in config file to run this testsuite.\n");
13348                 return TEST_SKIPPED;
13349         }
13350
13351         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
13352 }
13353
13354 static int
13355 test_cryptodev_mrvl(void)
13356 {
13357         gbl_driver_id = rte_cryptodev_driver_id_get(
13358                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
13359
13360         if (gbl_driver_id == -1) {
13361                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if "
13362                                 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled "
13363                                 "in config file to run this testsuite.\n");
13364                 return TEST_SKIPPED;
13365         }
13366
13367         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
13368 }
13369
13370 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
13371
13372 static int
13373 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
13374 {
13375         gbl_driver_id = rte_cryptodev_driver_id_get(
13376                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13377
13378         if (gbl_driver_id == -1) {
13379                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
13380                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
13381                                 "in config file to run this testsuite.\n");
13382                 return TEST_SKIPPED;
13383         }
13384
13385         if (rte_cryptodev_driver_id_get(
13386                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
13387                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
13388                         " enabled in config file to run this testsuite.\n");
13389                 return TEST_SKIPPED;
13390 }
13391         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
13392 }
13393
13394 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
13395
13396 #endif
13397
13398 static int
13399 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13400 {
13401         gbl_driver_id = rte_cryptodev_driver_id_get(
13402                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
13403
13404         if (gbl_driver_id == -1) {
13405                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
13406                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
13407                                 "in config file to run this testsuite.\n");
13408                 return TEST_SKIPPED;
13409         }
13410
13411         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
13412 }
13413
13414 static int
13415 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13416 {
13417         gbl_driver_id = rte_cryptodev_driver_id_get(
13418                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
13419
13420         if (gbl_driver_id == -1) {
13421                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
13422                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
13423                                 "in config file to run this testsuite.\n");
13424                 return TEST_SKIPPED;
13425         }
13426
13427         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
13428 }
13429
13430 static int
13431 test_cryptodev_ccp(void)
13432 {
13433         gbl_driver_id = rte_cryptodev_driver_id_get(
13434                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
13435
13436         if (gbl_driver_id == -1) {
13437                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
13438                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
13439                                 "in config file to run this testsuite.\n");
13440                 return TEST_FAILED;
13441         }
13442
13443         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
13444 }
13445
13446 static int
13447 test_cryptodev_octeontx(void)
13448 {
13449         gbl_driver_id = rte_cryptodev_driver_id_get(
13450                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
13451         if (gbl_driver_id == -1) {
13452                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
13453                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
13454                                 "enabled in config file to run this "
13455                                 "testsuite.\n");
13456                 return TEST_FAILED;
13457         }
13458         return unit_test_suite_runner(&cryptodev_octeontx_testsuite);
13459 }
13460
13461 static int
13462 test_cryptodev_octeontx2(void)
13463 {
13464         gbl_driver_id = rte_cryptodev_driver_id_get(
13465                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
13466         if (gbl_driver_id == -1) {
13467                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded. Check if "
13468                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
13469                                 "enabled in config file to run this "
13470                                 "testsuite.\n");
13471                 return TEST_FAILED;
13472         }
13473         return unit_test_suite_runner(&cryptodev_octeontx2_testsuite);
13474 }
13475
13476 static int
13477 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
13478 {
13479         gbl_driver_id = rte_cryptodev_driver_id_get(
13480                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
13481
13482         if (gbl_driver_id == -1) {
13483                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded. Check if "
13484                                 "CONFIG_RTE_LIBRTE_PMD_CAAM_JR is enabled "
13485                                 "in config file to run this testsuite.\n");
13486                 return TEST_FAILED;
13487         }
13488
13489         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
13490 }
13491
13492 static int
13493 test_cryptodev_nitrox(void)
13494 {
13495         gbl_driver_id = rte_cryptodev_driver_id_get(
13496                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
13497
13498         if (gbl_driver_id == -1) {
13499                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded. Check if "
13500                                 "CONFIG_RTE_LIBRTE_PMD_NITROX is enabled "
13501                                 "in config file to run this testsuite.\n");
13502                 return TEST_FAILED;
13503         }
13504
13505         return unit_test_suite_runner(&cryptodev_nitrox_testsuite);
13506 }
13507
13508 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
13509 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
13510 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
13511 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
13512 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
13513 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
13514 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
13515 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
13516 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
13517 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
13518 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
13519 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
13520 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
13521 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
13522 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
13523 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
13524 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
13525 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);