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