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