d86bdbf8ea2a3c9b2a3aeec4bd67c18e8e111279
[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 #endif
7723
7724 static int
7725 test_AES_GCM_authenticated_encryption_test_case_1(void)
7726 {
7727         return test_authenticated_encryption(&gcm_test_case_1);
7728 }
7729
7730 static int
7731 test_AES_GCM_authenticated_encryption_test_case_2(void)
7732 {
7733         return test_authenticated_encryption(&gcm_test_case_2);
7734 }
7735
7736 static int
7737 test_AES_GCM_authenticated_encryption_test_case_3(void)
7738 {
7739         return test_authenticated_encryption(&gcm_test_case_3);
7740 }
7741
7742 static int
7743 test_AES_GCM_authenticated_encryption_test_case_4(void)
7744 {
7745         return test_authenticated_encryption(&gcm_test_case_4);
7746 }
7747
7748 static int
7749 test_AES_GCM_authenticated_encryption_test_case_5(void)
7750 {
7751         return test_authenticated_encryption(&gcm_test_case_5);
7752 }
7753
7754 static int
7755 test_AES_GCM_authenticated_encryption_test_case_6(void)
7756 {
7757         return test_authenticated_encryption(&gcm_test_case_6);
7758 }
7759
7760 static int
7761 test_AES_GCM_authenticated_encryption_test_case_7(void)
7762 {
7763         return test_authenticated_encryption(&gcm_test_case_7);
7764 }
7765
7766 static int
7767 test_AES_GCM_authenticated_encryption_test_case_8(void)
7768 {
7769         return test_authenticated_encryption(&gcm_test_case_8);
7770 }
7771
7772 static int
7773 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
7774 {
7775         return test_authenticated_encryption(&gcm_J0_test_case_1);
7776 }
7777
7778 static int
7779 test_AES_GCM_auth_encryption_test_case_192_1(void)
7780 {
7781         return test_authenticated_encryption(&gcm_test_case_192_1);
7782 }
7783
7784 static int
7785 test_AES_GCM_auth_encryption_test_case_192_2(void)
7786 {
7787         return test_authenticated_encryption(&gcm_test_case_192_2);
7788 }
7789
7790 static int
7791 test_AES_GCM_auth_encryption_test_case_192_3(void)
7792 {
7793         return test_authenticated_encryption(&gcm_test_case_192_3);
7794 }
7795
7796 static int
7797 test_AES_GCM_auth_encryption_test_case_192_4(void)
7798 {
7799         return test_authenticated_encryption(&gcm_test_case_192_4);
7800 }
7801
7802 static int
7803 test_AES_GCM_auth_encryption_test_case_192_5(void)
7804 {
7805         return test_authenticated_encryption(&gcm_test_case_192_5);
7806 }
7807
7808 static int
7809 test_AES_GCM_auth_encryption_test_case_192_6(void)
7810 {
7811         return test_authenticated_encryption(&gcm_test_case_192_6);
7812 }
7813
7814 static int
7815 test_AES_GCM_auth_encryption_test_case_192_7(void)
7816 {
7817         return test_authenticated_encryption(&gcm_test_case_192_7);
7818 }
7819
7820 static int
7821 test_AES_GCM_auth_encryption_test_case_256_1(void)
7822 {
7823         return test_authenticated_encryption(&gcm_test_case_256_1);
7824 }
7825
7826 static int
7827 test_AES_GCM_auth_encryption_test_case_256_2(void)
7828 {
7829         return test_authenticated_encryption(&gcm_test_case_256_2);
7830 }
7831
7832 static int
7833 test_AES_GCM_auth_encryption_test_case_256_3(void)
7834 {
7835         return test_authenticated_encryption(&gcm_test_case_256_3);
7836 }
7837
7838 static int
7839 test_AES_GCM_auth_encryption_test_case_256_4(void)
7840 {
7841         return test_authenticated_encryption(&gcm_test_case_256_4);
7842 }
7843
7844 static int
7845 test_AES_GCM_auth_encryption_test_case_256_5(void)
7846 {
7847         return test_authenticated_encryption(&gcm_test_case_256_5);
7848 }
7849
7850 static int
7851 test_AES_GCM_auth_encryption_test_case_256_6(void)
7852 {
7853         return test_authenticated_encryption(&gcm_test_case_256_6);
7854 }
7855
7856 static int
7857 test_AES_GCM_auth_encryption_test_case_256_7(void)
7858 {
7859         return test_authenticated_encryption(&gcm_test_case_256_7);
7860 }
7861
7862 static int
7863 test_AES_GCM_auth_encryption_test_case_aad_1(void)
7864 {
7865         return test_authenticated_encryption(&gcm_test_case_aad_1);
7866 }
7867
7868 static int
7869 test_AES_GCM_auth_encryption_test_case_aad_2(void)
7870 {
7871         return test_authenticated_encryption(&gcm_test_case_aad_2);
7872 }
7873
7874 static int
7875 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
7876 {
7877         struct aead_test_data tdata;
7878         int res;
7879
7880         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7881         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7882         tdata.iv.data[0] += 1;
7883         res = test_authenticated_encryption(&tdata);
7884         if (res == -ENOTSUP)
7885                 return res;
7886         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7887         return TEST_SUCCESS;
7888 }
7889
7890 static int
7891 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
7892 {
7893         struct aead_test_data tdata;
7894         int res;
7895
7896         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7897         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7898         tdata.plaintext.data[0] += 1;
7899         res = test_authenticated_encryption(&tdata);
7900         if (res == -ENOTSUP)
7901                 return res;
7902         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7903         return TEST_SUCCESS;
7904 }
7905
7906 static int
7907 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
7908 {
7909         struct aead_test_data tdata;
7910         int res;
7911
7912         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7913         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7914         tdata.ciphertext.data[0] += 1;
7915         res = test_authenticated_encryption(&tdata);
7916         if (res == -ENOTSUP)
7917                 return res;
7918         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7919         return TEST_SUCCESS;
7920 }
7921
7922 static int
7923 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
7924 {
7925         struct aead_test_data tdata;
7926         int res;
7927
7928         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7929         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7930         tdata.aad.len += 1;
7931         res = test_authenticated_encryption(&tdata);
7932         if (res == -ENOTSUP)
7933                 return res;
7934         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7935         return TEST_SUCCESS;
7936 }
7937
7938 static int
7939 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
7940 {
7941         struct aead_test_data tdata;
7942         uint8_t aad[gcm_test_case_7.aad.len];
7943         int res;
7944
7945         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7946         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7947         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
7948         aad[0] += 1;
7949         tdata.aad.data = aad;
7950         res = test_authenticated_encryption(&tdata);
7951         if (res == -ENOTSUP)
7952                 return res;
7953         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7954         return TEST_SUCCESS;
7955 }
7956
7957 static int
7958 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
7959 {
7960         struct aead_test_data tdata;
7961         int res;
7962
7963         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
7964         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
7965         tdata.auth_tag.data[0] += 1;
7966         res = test_authenticated_encryption(&tdata);
7967         if (res == -ENOTSUP)
7968                 return res;
7969         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
7970         return TEST_SUCCESS;
7971 }
7972
7973 static int
7974 test_authenticated_decryption(const struct aead_test_data *tdata)
7975 {
7976         struct crypto_testsuite_params *ts_params = &testsuite_params;
7977         struct crypto_unittest_params *ut_params = &unittest_params;
7978
7979         int retval;
7980         uint8_t *plaintext;
7981         uint32_t i;
7982
7983         /* Verify the capabilities */
7984         struct rte_cryptodev_sym_capability_idx cap_idx;
7985         const struct rte_cryptodev_symmetric_capability *capability;
7986         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7987         cap_idx.algo.aead = tdata->algo;
7988         capability = rte_cryptodev_sym_capability_get(
7989                         ts_params->valid_devs[0], &cap_idx);
7990         if (capability == NULL)
7991                 return -ENOTSUP;
7992         if (rte_cryptodev_sym_capability_check_aead(
7993                         capability, tdata->key.len, tdata->auth_tag.len,
7994                         tdata->aad.len, tdata->iv.len))
7995                 return -ENOTSUP;
7996
7997         /* Create AEAD session */
7998         retval = create_aead_session(ts_params->valid_devs[0],
7999                         tdata->algo,
8000                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8001                         tdata->key.data, tdata->key.len,
8002                         tdata->aad.len, tdata->auth_tag.len,
8003                         tdata->iv.len);
8004         if (retval < 0)
8005                 return retval;
8006
8007         /* alloc mbuf and set payload */
8008         if (tdata->aad.len > MBUF_SIZE) {
8009                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8010                 /* Populate full size of add data */
8011                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8012                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8013         } else
8014                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8015
8016         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8017                         rte_pktmbuf_tailroom(ut_params->ibuf));
8018
8019         /* Create AEAD operation */
8020         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8021         if (retval < 0)
8022                 return retval;
8023
8024         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8025
8026         ut_params->op->sym->m_src = ut_params->ibuf;
8027
8028         /* Process crypto operation */
8029         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8030                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8031         else
8032                 TEST_ASSERT_NOT_NULL(
8033                         process_crypto_request(ts_params->valid_devs[0],
8034                         ut_params->op), "failed to process sym crypto op");
8035
8036         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8037                         "crypto op processing failed");
8038
8039         if (ut_params->op->sym->m_dst)
8040                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8041                                 uint8_t *);
8042         else
8043                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8044                                 uint8_t *,
8045                                 ut_params->op->sym->cipher.data.offset);
8046
8047         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8048
8049         /* Validate obuf */
8050         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8051                         plaintext,
8052                         tdata->plaintext.data,
8053                         tdata->plaintext.len,
8054                         "Plaintext data not as expected");
8055
8056         TEST_ASSERT_EQUAL(ut_params->op->status,
8057                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8058                         "Authentication failed");
8059
8060         return 0;
8061 }
8062
8063 static int
8064 test_AES_GCM_authenticated_decryption_test_case_1(void)
8065 {
8066         return test_authenticated_decryption(&gcm_test_case_1);
8067 }
8068
8069 static int
8070 test_AES_GCM_authenticated_decryption_test_case_2(void)
8071 {
8072         return test_authenticated_decryption(&gcm_test_case_2);
8073 }
8074
8075 static int
8076 test_AES_GCM_authenticated_decryption_test_case_3(void)
8077 {
8078         return test_authenticated_decryption(&gcm_test_case_3);
8079 }
8080
8081 static int
8082 test_AES_GCM_authenticated_decryption_test_case_4(void)
8083 {
8084         return test_authenticated_decryption(&gcm_test_case_4);
8085 }
8086
8087 static int
8088 test_AES_GCM_authenticated_decryption_test_case_5(void)
8089 {
8090         return test_authenticated_decryption(&gcm_test_case_5);
8091 }
8092
8093 static int
8094 test_AES_GCM_authenticated_decryption_test_case_6(void)
8095 {
8096         return test_authenticated_decryption(&gcm_test_case_6);
8097 }
8098
8099 static int
8100 test_AES_GCM_authenticated_decryption_test_case_7(void)
8101 {
8102         return test_authenticated_decryption(&gcm_test_case_7);
8103 }
8104
8105 static int
8106 test_AES_GCM_authenticated_decryption_test_case_8(void)
8107 {
8108         return test_authenticated_decryption(&gcm_test_case_8);
8109 }
8110
8111 static int
8112 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
8113 {
8114         return test_authenticated_decryption(&gcm_J0_test_case_1);
8115 }
8116
8117 static int
8118 test_AES_GCM_auth_decryption_test_case_192_1(void)
8119 {
8120         return test_authenticated_decryption(&gcm_test_case_192_1);
8121 }
8122
8123 static int
8124 test_AES_GCM_auth_decryption_test_case_192_2(void)
8125 {
8126         return test_authenticated_decryption(&gcm_test_case_192_2);
8127 }
8128
8129 static int
8130 test_AES_GCM_auth_decryption_test_case_192_3(void)
8131 {
8132         return test_authenticated_decryption(&gcm_test_case_192_3);
8133 }
8134
8135 static int
8136 test_AES_GCM_auth_decryption_test_case_192_4(void)
8137 {
8138         return test_authenticated_decryption(&gcm_test_case_192_4);
8139 }
8140
8141 static int
8142 test_AES_GCM_auth_decryption_test_case_192_5(void)
8143 {
8144         return test_authenticated_decryption(&gcm_test_case_192_5);
8145 }
8146
8147 static int
8148 test_AES_GCM_auth_decryption_test_case_192_6(void)
8149 {
8150         return test_authenticated_decryption(&gcm_test_case_192_6);
8151 }
8152
8153 static int
8154 test_AES_GCM_auth_decryption_test_case_192_7(void)
8155 {
8156         return test_authenticated_decryption(&gcm_test_case_192_7);
8157 }
8158
8159 static int
8160 test_AES_GCM_auth_decryption_test_case_256_1(void)
8161 {
8162         return test_authenticated_decryption(&gcm_test_case_256_1);
8163 }
8164
8165 static int
8166 test_AES_GCM_auth_decryption_test_case_256_2(void)
8167 {
8168         return test_authenticated_decryption(&gcm_test_case_256_2);
8169 }
8170
8171 static int
8172 test_AES_GCM_auth_decryption_test_case_256_3(void)
8173 {
8174         return test_authenticated_decryption(&gcm_test_case_256_3);
8175 }
8176
8177 static int
8178 test_AES_GCM_auth_decryption_test_case_256_4(void)
8179 {
8180         return test_authenticated_decryption(&gcm_test_case_256_4);
8181 }
8182
8183 static int
8184 test_AES_GCM_auth_decryption_test_case_256_5(void)
8185 {
8186         return test_authenticated_decryption(&gcm_test_case_256_5);
8187 }
8188
8189 static int
8190 test_AES_GCM_auth_decryption_test_case_256_6(void)
8191 {
8192         return test_authenticated_decryption(&gcm_test_case_256_6);
8193 }
8194
8195 static int
8196 test_AES_GCM_auth_decryption_test_case_256_7(void)
8197 {
8198         return test_authenticated_decryption(&gcm_test_case_256_7);
8199 }
8200
8201 static int
8202 test_AES_GCM_auth_decryption_test_case_aad_1(void)
8203 {
8204         return test_authenticated_decryption(&gcm_test_case_aad_1);
8205 }
8206
8207 static int
8208 test_AES_GCM_auth_decryption_test_case_aad_2(void)
8209 {
8210         return test_authenticated_decryption(&gcm_test_case_aad_2);
8211 }
8212
8213 static int
8214 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
8215 {
8216         struct aead_test_data tdata;
8217         int res;
8218
8219         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8220         tdata.iv.data[0] += 1;
8221         res = test_authenticated_decryption(&tdata);
8222         if (res == -ENOTSUP)
8223                 return res;
8224         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8225         return TEST_SUCCESS;
8226 }
8227
8228 static int
8229 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
8230 {
8231         struct aead_test_data tdata;
8232         int res;
8233
8234         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8235         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8236         tdata.plaintext.data[0] += 1;
8237         res = test_authenticated_decryption(&tdata);
8238         if (res == -ENOTSUP)
8239                 return res;
8240         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8241         return TEST_SUCCESS;
8242 }
8243
8244 static int
8245 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
8246 {
8247         struct aead_test_data tdata;
8248         int res;
8249
8250         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8251         tdata.ciphertext.data[0] += 1;
8252         res = test_authenticated_decryption(&tdata);
8253         if (res == -ENOTSUP)
8254                 return res;
8255         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8256         return TEST_SUCCESS;
8257 }
8258
8259 static int
8260 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
8261 {
8262         struct aead_test_data tdata;
8263         int res;
8264
8265         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8266         tdata.aad.len += 1;
8267         res = test_authenticated_decryption(&tdata);
8268         if (res == -ENOTSUP)
8269                 return res;
8270         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8271         return TEST_SUCCESS;
8272 }
8273
8274 static int
8275 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
8276 {
8277         struct aead_test_data tdata;
8278         uint8_t aad[gcm_test_case_7.aad.len];
8279         int res;
8280
8281         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8282         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
8283         aad[0] += 1;
8284         tdata.aad.data = aad;
8285         res = test_authenticated_decryption(&tdata);
8286         if (res == -ENOTSUP)
8287                 return res;
8288         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
8289         return TEST_SUCCESS;
8290 }
8291
8292 static int
8293 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
8294 {
8295         struct aead_test_data tdata;
8296         int res;
8297
8298         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8299         tdata.auth_tag.data[0] += 1;
8300         res = test_authenticated_decryption(&tdata);
8301         if (res == -ENOTSUP)
8302                 return res;
8303         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
8304         return TEST_SUCCESS;
8305 }
8306
8307 static int
8308 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
8309 {
8310         struct crypto_testsuite_params *ts_params = &testsuite_params;
8311         struct crypto_unittest_params *ut_params = &unittest_params;
8312
8313         int retval;
8314         uint8_t *ciphertext, *auth_tag;
8315         uint16_t plaintext_pad_len;
8316
8317         /* Verify the capabilities */
8318         struct rte_cryptodev_sym_capability_idx cap_idx;
8319         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8320         cap_idx.algo.aead = tdata->algo;
8321         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8322                         &cap_idx) == NULL)
8323                 return -ENOTSUP;
8324
8325         /* not supported with CPU crypto */
8326         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8327                 return -ENOTSUP;
8328
8329         /* Create AEAD session */
8330         retval = create_aead_session(ts_params->valid_devs[0],
8331                         tdata->algo,
8332                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8333                         tdata->key.data, tdata->key.len,
8334                         tdata->aad.len, tdata->auth_tag.len,
8335                         tdata->iv.len);
8336         if (retval < 0)
8337                 return retval;
8338
8339         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8340         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8341
8342         /* clear mbuf payload */
8343         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8344                         rte_pktmbuf_tailroom(ut_params->ibuf));
8345         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8346                         rte_pktmbuf_tailroom(ut_params->obuf));
8347
8348         /* Create AEAD operation */
8349         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8350         if (retval < 0)
8351                 return retval;
8352
8353         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8354
8355         ut_params->op->sym->m_src = ut_params->ibuf;
8356         ut_params->op->sym->m_dst = ut_params->obuf;
8357
8358         /* Process crypto operation */
8359         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8360                         ut_params->op), "failed to process sym crypto op");
8361
8362         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8363                         "crypto op processing failed");
8364
8365         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8366
8367         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8368                         ut_params->op->sym->cipher.data.offset);
8369         auth_tag = ciphertext + plaintext_pad_len;
8370
8371         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8372         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8373
8374         /* Validate obuf */
8375         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8376                         ciphertext,
8377                         tdata->ciphertext.data,
8378                         tdata->ciphertext.len,
8379                         "Ciphertext data not as expected");
8380
8381         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8382                         auth_tag,
8383                         tdata->auth_tag.data,
8384                         tdata->auth_tag.len,
8385                         "Generated auth tag not as expected");
8386
8387         return 0;
8388
8389 }
8390
8391 static int
8392 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
8393 {
8394         return test_authenticated_encryption_oop(&gcm_test_case_5);
8395 }
8396
8397 static int
8398 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
8399 {
8400         struct crypto_testsuite_params *ts_params = &testsuite_params;
8401         struct crypto_unittest_params *ut_params = &unittest_params;
8402
8403         int retval;
8404         uint8_t *plaintext;
8405
8406         /* Verify the capabilities */
8407         struct rte_cryptodev_sym_capability_idx cap_idx;
8408         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8409         cap_idx.algo.aead = tdata->algo;
8410         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8411                         &cap_idx) == NULL)
8412                 return -ENOTSUP;
8413
8414         /* not supported with CPU crypto */
8415         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8416                 return -ENOTSUP;
8417
8418         /* Create AEAD session */
8419         retval = create_aead_session(ts_params->valid_devs[0],
8420                         tdata->algo,
8421                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8422                         tdata->key.data, tdata->key.len,
8423                         tdata->aad.len, tdata->auth_tag.len,
8424                         tdata->iv.len);
8425         if (retval < 0)
8426                 return retval;
8427
8428         /* alloc mbuf and set payload */
8429         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8430         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8431
8432         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8433                         rte_pktmbuf_tailroom(ut_params->ibuf));
8434         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8435                         rte_pktmbuf_tailroom(ut_params->obuf));
8436
8437         /* Create AEAD operation */
8438         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8439         if (retval < 0)
8440                 return retval;
8441
8442         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8443
8444         ut_params->op->sym->m_src = ut_params->ibuf;
8445         ut_params->op->sym->m_dst = ut_params->obuf;
8446
8447         /* Process crypto operation */
8448         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8449                         ut_params->op), "failed to process sym crypto op");
8450
8451         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8452                         "crypto op processing failed");
8453
8454         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
8455                         ut_params->op->sym->cipher.data.offset);
8456
8457         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8458
8459         /* Validate obuf */
8460         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8461                         plaintext,
8462                         tdata->plaintext.data,
8463                         tdata->plaintext.len,
8464                         "Plaintext data not as expected");
8465
8466         TEST_ASSERT_EQUAL(ut_params->op->status,
8467                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8468                         "Authentication failed");
8469         return 0;
8470 }
8471
8472 static int
8473 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
8474 {
8475         return test_authenticated_decryption_oop(&gcm_test_case_5);
8476 }
8477
8478 static int
8479 test_authenticated_encryption_sessionless(
8480                 const struct aead_test_data *tdata)
8481 {
8482         struct crypto_testsuite_params *ts_params = &testsuite_params;
8483         struct crypto_unittest_params *ut_params = &unittest_params;
8484
8485         int retval;
8486         uint8_t *ciphertext, *auth_tag;
8487         uint16_t plaintext_pad_len;
8488         uint8_t key[tdata->key.len + 1];
8489         struct rte_cryptodev_info dev_info;
8490
8491         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8492         uint64_t feat_flags = dev_info.feature_flags;
8493
8494         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
8495                 printf("Device doesn't support Sessionless ops.\n");
8496                 return -ENOTSUP;
8497         }
8498
8499         /* not supported with CPU crypto */
8500         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8501                 return -ENOTSUP;
8502
8503         /* Verify the capabilities */
8504         struct rte_cryptodev_sym_capability_idx cap_idx;
8505         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8506         cap_idx.algo.aead = tdata->algo;
8507         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8508                         &cap_idx) == NULL)
8509                 return -ENOTSUP;
8510
8511         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8512
8513         /* clear mbuf payload */
8514         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8515                         rte_pktmbuf_tailroom(ut_params->ibuf));
8516
8517         /* Create AEAD operation */
8518         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8519         if (retval < 0)
8520                 return retval;
8521
8522         /* Create GCM xform */
8523         memcpy(key, tdata->key.data, tdata->key.len);
8524         retval = create_aead_xform(ut_params->op,
8525                         tdata->algo,
8526                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8527                         key, tdata->key.len,
8528                         tdata->aad.len, tdata->auth_tag.len,
8529                         tdata->iv.len);
8530         if (retval < 0)
8531                 return retval;
8532
8533         ut_params->op->sym->m_src = ut_params->ibuf;
8534
8535         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8536                         RTE_CRYPTO_OP_SESSIONLESS,
8537                         "crypto op session type not sessionless");
8538
8539         /* Process crypto operation */
8540         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8541                         ut_params->op), "failed to process sym crypto op");
8542
8543         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8544
8545         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8546                         "crypto op status not success");
8547
8548         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8549
8550         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8551                         ut_params->op->sym->cipher.data.offset);
8552         auth_tag = ciphertext + plaintext_pad_len;
8553
8554         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8555         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8556
8557         /* Validate obuf */
8558         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8559                         ciphertext,
8560                         tdata->ciphertext.data,
8561                         tdata->ciphertext.len,
8562                         "Ciphertext data not as expected");
8563
8564         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8565                         auth_tag,
8566                         tdata->auth_tag.data,
8567                         tdata->auth_tag.len,
8568                         "Generated auth tag not as expected");
8569
8570         return 0;
8571
8572 }
8573
8574 static int
8575 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
8576 {
8577         return test_authenticated_encryption_sessionless(
8578                         &gcm_test_case_5);
8579 }
8580
8581 static int
8582 test_authenticated_decryption_sessionless(
8583                 const struct aead_test_data *tdata)
8584 {
8585         struct crypto_testsuite_params *ts_params = &testsuite_params;
8586         struct crypto_unittest_params *ut_params = &unittest_params;
8587
8588         int retval;
8589         uint8_t *plaintext;
8590         uint8_t key[tdata->key.len + 1];
8591         struct rte_cryptodev_info dev_info;
8592
8593         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8594         uint64_t feat_flags = dev_info.feature_flags;
8595
8596         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
8597                 printf("Device doesn't support Sessionless ops.\n");
8598                 return -ENOTSUP;
8599         }
8600
8601         /* not supported with CPU crypto */
8602         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8603                 return -ENOTSUP;
8604
8605         /* Verify the capabilities */
8606         struct rte_cryptodev_sym_capability_idx cap_idx;
8607         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8608         cap_idx.algo.aead = tdata->algo;
8609         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8610                         &cap_idx) == NULL)
8611                 return -ENOTSUP;
8612
8613         /* alloc mbuf and set payload */
8614         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8615
8616         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8617                         rte_pktmbuf_tailroom(ut_params->ibuf));
8618
8619         /* Create AEAD operation */
8620         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
8621         if (retval < 0)
8622                 return retval;
8623
8624         /* Create AEAD xform */
8625         memcpy(key, tdata->key.data, tdata->key.len);
8626         retval = create_aead_xform(ut_params->op,
8627                         tdata->algo,
8628                         RTE_CRYPTO_AEAD_OP_DECRYPT,
8629                         key, tdata->key.len,
8630                         tdata->aad.len, tdata->auth_tag.len,
8631                         tdata->iv.len);
8632         if (retval < 0)
8633                 return retval;
8634
8635         ut_params->op->sym->m_src = ut_params->ibuf;
8636
8637         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
8638                         RTE_CRYPTO_OP_SESSIONLESS,
8639                         "crypto op session type not sessionless");
8640
8641         /* Process crypto operation */
8642         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
8643                         ut_params->op), "failed to process sym crypto op");
8644
8645         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
8646
8647         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8648                         "crypto op status not success");
8649
8650         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
8651                         ut_params->op->sym->cipher.data.offset);
8652
8653         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
8654
8655         /* Validate obuf */
8656         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8657                         plaintext,
8658                         tdata->plaintext.data,
8659                         tdata->plaintext.len,
8660                         "Plaintext data not as expected");
8661
8662         TEST_ASSERT_EQUAL(ut_params->op->status,
8663                         RTE_CRYPTO_OP_STATUS_SUCCESS,
8664                         "Authentication failed");
8665         return 0;
8666 }
8667
8668 static int
8669 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
8670 {
8671         return test_authenticated_decryption_sessionless(
8672                         &gcm_test_case_5);
8673 }
8674
8675 static int
8676 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
8677 {
8678         return test_authenticated_encryption(&ccm_test_case_128_1);
8679 }
8680
8681 static int
8682 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
8683 {
8684         return test_authenticated_encryption(&ccm_test_case_128_2);
8685 }
8686
8687 static int
8688 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
8689 {
8690         return test_authenticated_encryption(&ccm_test_case_128_3);
8691 }
8692
8693 static int
8694 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
8695 {
8696         return test_authenticated_decryption(&ccm_test_case_128_1);
8697 }
8698
8699 static int
8700 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
8701 {
8702         return test_authenticated_decryption(&ccm_test_case_128_2);
8703 }
8704
8705 static int
8706 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
8707 {
8708         return test_authenticated_decryption(&ccm_test_case_128_3);
8709 }
8710
8711 static int
8712 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
8713 {
8714         return test_authenticated_encryption(&ccm_test_case_192_1);
8715 }
8716
8717 static int
8718 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
8719 {
8720         return test_authenticated_encryption(&ccm_test_case_192_2);
8721 }
8722
8723 static int
8724 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
8725 {
8726         return test_authenticated_encryption(&ccm_test_case_192_3);
8727 }
8728
8729 static int
8730 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
8731 {
8732         return test_authenticated_decryption(&ccm_test_case_192_1);
8733 }
8734
8735 static int
8736 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
8737 {
8738         return test_authenticated_decryption(&ccm_test_case_192_2);
8739 }
8740
8741 static int
8742 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
8743 {
8744         return test_authenticated_decryption(&ccm_test_case_192_3);
8745 }
8746
8747 static int
8748 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
8749 {
8750         return test_authenticated_encryption(&ccm_test_case_256_1);
8751 }
8752
8753 static int
8754 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
8755 {
8756         return test_authenticated_encryption(&ccm_test_case_256_2);
8757 }
8758
8759 static int
8760 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
8761 {
8762         return test_authenticated_encryption(&ccm_test_case_256_3);
8763 }
8764
8765 static int
8766 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
8767 {
8768         return test_authenticated_decryption(&ccm_test_case_256_1);
8769 }
8770
8771 static int
8772 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
8773 {
8774         return test_authenticated_decryption(&ccm_test_case_256_2);
8775 }
8776
8777 static int
8778 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
8779 {
8780         return test_authenticated_decryption(&ccm_test_case_256_3);
8781 }
8782
8783 static int
8784 test_stats(void)
8785 {
8786         struct crypto_testsuite_params *ts_params = &testsuite_params;
8787         struct rte_cryptodev_stats stats;
8788         struct rte_cryptodev *dev;
8789         cryptodev_stats_get_t temp_pfn;
8790
8791         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8792                 return -ENOTSUP;
8793
8794         /* Verify the capabilities */
8795         struct rte_cryptodev_sym_capability_idx cap_idx;
8796         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8797         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
8798         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8799                         &cap_idx) == NULL)
8800                 return -ENOTSUP;
8801         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8802         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
8803         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8804                         &cap_idx) == NULL)
8805                 return -ENOTSUP;
8806
8807         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8808         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
8809                         &stats) == -ENODEV),
8810                 "rte_cryptodev_stats_get invalid dev failed");
8811         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
8812                 "rte_cryptodev_stats_get invalid Param failed");
8813         dev = &rte_cryptodevs[ts_params->valid_devs[0]];
8814         temp_pfn = dev->dev_ops->stats_get;
8815         dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
8816         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
8817                         == -ENOTSUP),
8818                 "rte_cryptodev_stats_get invalid Param failed");
8819         dev->dev_ops->stats_get = temp_pfn;
8820
8821         /* Test expected values */
8822         ut_setup();
8823         test_AES_CBC_HMAC_SHA1_encrypt_digest();
8824         ut_teardown();
8825         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8826                         &stats),
8827                 "rte_cryptodev_stats_get failed");
8828         TEST_ASSERT((stats.enqueued_count == 1),
8829                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8830         TEST_ASSERT((stats.dequeued_count == 1),
8831                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8832         TEST_ASSERT((stats.enqueue_err_count == 0),
8833                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8834         TEST_ASSERT((stats.dequeue_err_count == 0),
8835                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8836
8837         /* invalid device but should ignore and not reset device stats*/
8838         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
8839         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8840                         &stats),
8841                 "rte_cryptodev_stats_get failed");
8842         TEST_ASSERT((stats.enqueued_count == 1),
8843                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8844
8845         /* check that a valid reset clears stats */
8846         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
8847         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
8848                         &stats),
8849                                           "rte_cryptodev_stats_get failed");
8850         TEST_ASSERT((stats.enqueued_count == 0),
8851                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8852         TEST_ASSERT((stats.dequeued_count == 0),
8853                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
8854
8855         return TEST_SUCCESS;
8856 }
8857
8858 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
8859                                    struct crypto_unittest_params *ut_params,
8860                                    enum rte_crypto_auth_operation op,
8861                                    const struct HMAC_MD5_vector *test_case)
8862 {
8863         uint8_t key[64];
8864
8865         memcpy(key, test_case->key.data, test_case->key.len);
8866
8867         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8868         ut_params->auth_xform.next = NULL;
8869         ut_params->auth_xform.auth.op = op;
8870
8871         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
8872
8873         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
8874         ut_params->auth_xform.auth.key.length = test_case->key.len;
8875         ut_params->auth_xform.auth.key.data = key;
8876
8877         ut_params->sess = rte_cryptodev_sym_session_create(
8878                         ts_params->session_mpool);
8879
8880         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
8881                         ut_params->sess, &ut_params->auth_xform,
8882                         ts_params->session_priv_mpool);
8883
8884         if (ut_params->sess == NULL)
8885                 return TEST_FAILED;
8886
8887         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8888
8889         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8890                         rte_pktmbuf_tailroom(ut_params->ibuf));
8891
8892         return 0;
8893 }
8894
8895 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
8896                               const struct HMAC_MD5_vector *test_case,
8897                               uint8_t **plaintext)
8898 {
8899         uint16_t plaintext_pad_len;
8900
8901         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8902
8903         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8904                                 16);
8905
8906         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8907                         plaintext_pad_len);
8908         memcpy(*plaintext, test_case->plaintext.data,
8909                         test_case->plaintext.len);
8910
8911         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
8912                         ut_params->ibuf, MD5_DIGEST_LEN);
8913         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
8914                         "no room to append digest");
8915         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
8916                         ut_params->ibuf, plaintext_pad_len);
8917
8918         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
8919                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
8920                            test_case->auth_tag.len);
8921         }
8922
8923         sym_op->auth.data.offset = 0;
8924         sym_op->auth.data.length = test_case->plaintext.len;
8925
8926         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8927         ut_params->op->sym->m_src = ut_params->ibuf;
8928
8929         return 0;
8930 }
8931
8932 static int
8933 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
8934 {
8935         uint16_t plaintext_pad_len;
8936         uint8_t *plaintext, *auth_tag;
8937
8938         struct crypto_testsuite_params *ts_params = &testsuite_params;
8939         struct crypto_unittest_params *ut_params = &unittest_params;
8940
8941         /* Verify the capabilities */
8942         struct rte_cryptodev_sym_capability_idx cap_idx;
8943         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8944         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
8945         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
8946                         &cap_idx) == NULL)
8947                 return -ENOTSUP;
8948
8949         if (MD5_HMAC_create_session(ts_params, ut_params,
8950                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
8951                 return TEST_FAILED;
8952
8953         /* Generate Crypto op data structure */
8954         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8955                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8956         TEST_ASSERT_NOT_NULL(ut_params->op,
8957                         "Failed to allocate symmetric crypto operation struct");
8958
8959         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
8960                                 16);
8961
8962         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
8963                 return TEST_FAILED;
8964
8965         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8966                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
8967                         ut_params->op);
8968         else
8969                 TEST_ASSERT_NOT_NULL(
8970                         process_crypto_request(ts_params->valid_devs[0],
8971                                 ut_params->op),
8972                                 "failed to process sym crypto op");
8973
8974         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8975                         "crypto op processing failed");
8976
8977         if (ut_params->op->sym->m_dst) {
8978                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8979                                 uint8_t *, plaintext_pad_len);
8980         } else {
8981                 auth_tag = plaintext + plaintext_pad_len;
8982         }
8983
8984         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8985                         auth_tag,
8986                         test_case->auth_tag.data,
8987                         test_case->auth_tag.len,
8988                         "HMAC_MD5 generated tag not as expected");
8989
8990         return TEST_SUCCESS;
8991 }
8992
8993 static int
8994 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
8995 {
8996         uint8_t *plaintext;
8997
8998         struct crypto_testsuite_params *ts_params = &testsuite_params;
8999         struct crypto_unittest_params *ut_params = &unittest_params;
9000
9001         /* Verify the capabilities */
9002         struct rte_cryptodev_sym_capability_idx cap_idx;
9003         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9004         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
9005         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9006                         &cap_idx) == NULL)
9007                 return -ENOTSUP;
9008
9009         if (MD5_HMAC_create_session(ts_params, ut_params,
9010                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
9011                 return TEST_FAILED;
9012         }
9013
9014         /* Generate Crypto op data structure */
9015         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9016                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9017         TEST_ASSERT_NOT_NULL(ut_params->op,
9018                         "Failed to allocate symmetric crypto operation struct");
9019
9020         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
9021                 return TEST_FAILED;
9022
9023         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9024                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
9025                         ut_params->op);
9026         else
9027                 TEST_ASSERT_NOT_NULL(
9028                         process_crypto_request(ts_params->valid_devs[0],
9029                                 ut_params->op),
9030                                 "failed to process sym crypto op");
9031
9032         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9033                         "HMAC_MD5 crypto op processing failed");
9034
9035         return TEST_SUCCESS;
9036 }
9037
9038 static int
9039 test_MD5_HMAC_generate_case_1(void)
9040 {
9041         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
9042 }
9043
9044 static int
9045 test_MD5_HMAC_verify_case_1(void)
9046 {
9047         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
9048 }
9049
9050 static int
9051 test_MD5_HMAC_generate_case_2(void)
9052 {
9053         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
9054 }
9055
9056 static int
9057 test_MD5_HMAC_verify_case_2(void)
9058 {
9059         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
9060 }
9061
9062 static int
9063 test_multi_session(void)
9064 {
9065         struct crypto_testsuite_params *ts_params = &testsuite_params;
9066         struct crypto_unittest_params *ut_params = &unittest_params;
9067
9068         struct rte_cryptodev_info dev_info;
9069         struct rte_cryptodev_sym_session **sessions;
9070
9071         uint16_t i;
9072
9073         /* Verify the capabilities */
9074         struct rte_cryptodev_sym_capability_idx cap_idx;
9075         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9076         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9077         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9078                         &cap_idx) == NULL)
9079                 return -ENOTSUP;
9080         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9081         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9082         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9083                         &cap_idx) == NULL)
9084                 return -ENOTSUP;
9085
9086         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
9087                         aes_cbc_key, hmac_sha512_key);
9088
9089
9090         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9091
9092         sessions = rte_malloc(NULL,
9093                         (sizeof(struct rte_cryptodev_sym_session *) *
9094                         MAX_NB_SESSIONS) + 1, 0);
9095
9096         /* Create multiple crypto sessions*/
9097         for (i = 0; i < MAX_NB_SESSIONS; i++) {
9098
9099                 sessions[i] = rte_cryptodev_sym_session_create(
9100                                 ts_params->session_mpool);
9101
9102                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9103                                 sessions[i], &ut_params->auth_xform,
9104                                 ts_params->session_priv_mpool);
9105                 TEST_ASSERT_NOT_NULL(sessions[i],
9106                                 "Session creation failed at session number %u",
9107                                 i);
9108
9109                 /* Attempt to send a request on each session */
9110                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
9111                         sessions[i],
9112                         ut_params,
9113                         ts_params,
9114                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
9115                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
9116                         aes_cbc_iv),
9117                         "Failed to perform decrypt on request number %u.", i);
9118                 /* free crypto operation structure */
9119                 if (ut_params->op)
9120                         rte_crypto_op_free(ut_params->op);
9121
9122                 /*
9123                  * free mbuf - both obuf and ibuf are usually the same,
9124                  * so check if they point at the same address is necessary,
9125                  * to avoid freeing the mbuf twice.
9126                  */
9127                 if (ut_params->obuf) {
9128                         rte_pktmbuf_free(ut_params->obuf);
9129                         if (ut_params->ibuf == ut_params->obuf)
9130                                 ut_params->ibuf = 0;
9131                         ut_params->obuf = 0;
9132                 }
9133                 if (ut_params->ibuf) {
9134                         rte_pktmbuf_free(ut_params->ibuf);
9135                         ut_params->ibuf = 0;
9136                 }
9137         }
9138
9139         /* Next session create should fail */
9140         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9141                         sessions[i], &ut_params->auth_xform,
9142                         ts_params->session_priv_mpool);
9143         TEST_ASSERT_NULL(sessions[i],
9144                         "Session creation succeeded unexpectedly!");
9145
9146         for (i = 0; i < MAX_NB_SESSIONS; i++) {
9147                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9148                                 sessions[i]);
9149                 rte_cryptodev_sym_session_free(sessions[i]);
9150         }
9151
9152         rte_free(sessions);
9153
9154         return TEST_SUCCESS;
9155 }
9156
9157 struct multi_session_params {
9158         struct crypto_unittest_params ut_params;
9159         uint8_t *cipher_key;
9160         uint8_t *hmac_key;
9161         const uint8_t *cipher;
9162         const uint8_t *digest;
9163         uint8_t *iv;
9164 };
9165
9166 #define MB_SESSION_NUMBER 3
9167
9168 static int
9169 test_multi_session_random_usage(void)
9170 {
9171         struct crypto_testsuite_params *ts_params = &testsuite_params;
9172         struct rte_cryptodev_info dev_info;
9173         struct rte_cryptodev_sym_session **sessions;
9174         uint32_t i, j;
9175         struct multi_session_params ut_paramz[] = {
9176
9177                 {
9178                         .cipher_key = ms_aes_cbc_key0,
9179                         .hmac_key = ms_hmac_key0,
9180                         .cipher = ms_aes_cbc_cipher0,
9181                         .digest = ms_hmac_digest0,
9182                         .iv = ms_aes_cbc_iv0
9183                 },
9184                 {
9185                         .cipher_key = ms_aes_cbc_key1,
9186                         .hmac_key = ms_hmac_key1,
9187                         .cipher = ms_aes_cbc_cipher1,
9188                         .digest = ms_hmac_digest1,
9189                         .iv = ms_aes_cbc_iv1
9190                 },
9191                 {
9192                         .cipher_key = ms_aes_cbc_key2,
9193                         .hmac_key = ms_hmac_key2,
9194                         .cipher = ms_aes_cbc_cipher2,
9195                         .digest = ms_hmac_digest2,
9196                         .iv = ms_aes_cbc_iv2
9197                 },
9198
9199         };
9200
9201         /* Verify the capabilities */
9202         struct rte_cryptodev_sym_capability_idx cap_idx;
9203         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9204         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9205         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9206                         &cap_idx) == NULL)
9207                 return -ENOTSUP;
9208         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9209         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9210         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9211                         &cap_idx) == NULL)
9212                 return -ENOTSUP;
9213
9214         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9215
9216         sessions = rte_malloc(NULL,
9217                         (sizeof(struct rte_cryptodev_sym_session *)
9218                                         * MAX_NB_SESSIONS) + 1, 0);
9219
9220         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9221                 sessions[i] = rte_cryptodev_sym_session_create(
9222                                 ts_params->session_mpool);
9223
9224                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
9225                                 sizeof(struct crypto_unittest_params));
9226
9227                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
9228                                 &ut_paramz[i].ut_params,
9229                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
9230
9231                 /* Create multiple crypto sessions*/
9232                 rte_cryptodev_sym_session_init(
9233                                 ts_params->valid_devs[0],
9234                                 sessions[i],
9235                                 &ut_paramz[i].ut_params.auth_xform,
9236                                 ts_params->session_priv_mpool);
9237
9238                 TEST_ASSERT_NOT_NULL(sessions[i],
9239                                 "Session creation failed at session number %u",
9240                                 i);
9241
9242         }
9243
9244         srand(time(NULL));
9245         for (i = 0; i < 40000; i++) {
9246
9247                 j = rand() % MB_SESSION_NUMBER;
9248
9249                 TEST_ASSERT_SUCCESS(
9250                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
9251                                         sessions[j],
9252                                         &ut_paramz[j].ut_params,
9253                                         ts_params, ut_paramz[j].cipher,
9254                                         ut_paramz[j].digest,
9255                                         ut_paramz[j].iv),
9256                         "Failed to perform decrypt on request number %u.", i);
9257
9258                 if (ut_paramz[j].ut_params.op)
9259                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
9260
9261                 /*
9262                  * free mbuf - both obuf and ibuf are usually the same,
9263                  * so check if they point at the same address is necessary,
9264                  * to avoid freeing the mbuf twice.
9265                  */
9266                 if (ut_paramz[j].ut_params.obuf) {
9267                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
9268                         if (ut_paramz[j].ut_params.ibuf
9269                                         == ut_paramz[j].ut_params.obuf)
9270                                 ut_paramz[j].ut_params.ibuf = 0;
9271                         ut_paramz[j].ut_params.obuf = 0;
9272                 }
9273                 if (ut_paramz[j].ut_params.ibuf) {
9274                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
9275                         ut_paramz[j].ut_params.ibuf = 0;
9276                 }
9277         }
9278
9279         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9280                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9281                                 sessions[i]);
9282                 rte_cryptodev_sym_session_free(sessions[i]);
9283         }
9284
9285         rte_free(sessions);
9286
9287         return TEST_SUCCESS;
9288 }
9289
9290 static int
9291 test_null_cipher_only_operation(void)
9292 {
9293         struct crypto_testsuite_params *ts_params = &testsuite_params;
9294         struct crypto_unittest_params *ut_params = &unittest_params;
9295
9296         /* Verify the capabilities */
9297         struct rte_cryptodev_sym_capability_idx cap_idx;
9298         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9299         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9300         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9301                         &cap_idx) == NULL)
9302                 return -ENOTSUP;
9303
9304         /* Generate test mbuf data and space for digest */
9305         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9306                         catch_22_quote, QUOTE_512_BYTES, 0);
9307
9308         /* Setup Cipher Parameters */
9309         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9310         ut_params->cipher_xform.next = NULL;
9311
9312         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9313         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9314
9315         ut_params->sess = rte_cryptodev_sym_session_create(
9316                         ts_params->session_mpool);
9317
9318         /* Create Crypto session*/
9319         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9320                                 ut_params->sess,
9321                                 &ut_params->cipher_xform,
9322                                 ts_params->session_priv_mpool);
9323         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9324
9325         /* Generate Crypto op data structure */
9326         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9327                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9328         TEST_ASSERT_NOT_NULL(ut_params->op,
9329                         "Failed to allocate symmetric crypto operation struct");
9330
9331         /* Set crypto operation data parameters */
9332         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9333
9334         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9335
9336         /* set crypto operation source mbuf */
9337         sym_op->m_src = ut_params->ibuf;
9338
9339         sym_op->cipher.data.offset = 0;
9340         sym_op->cipher.data.length = QUOTE_512_BYTES;
9341
9342         /* Process crypto operation */
9343         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9344                         ut_params->op);
9345         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9346
9347         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9348                         "crypto operation processing failed");
9349
9350         /* Validate obuf */
9351         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9352                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9353                         catch_22_quote,
9354                         QUOTE_512_BYTES,
9355                         "Ciphertext data not as expected");
9356
9357         return TEST_SUCCESS;
9358 }
9359 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
9360                         0xab, 0xab, 0xab, 0xab,
9361                         0xab, 0xab, 0xab, 0xab,
9362                         0xab, 0xab, 0xab, 0xab};
9363 static int
9364 test_null_auth_only_operation(void)
9365 {
9366         struct crypto_testsuite_params *ts_params = &testsuite_params;
9367         struct crypto_unittest_params *ut_params = &unittest_params;
9368         uint8_t *digest;
9369
9370         /* Verify the capabilities */
9371         struct rte_cryptodev_sym_capability_idx cap_idx;
9372         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9373         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9374         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9375                         &cap_idx) == NULL)
9376                 return -ENOTSUP;
9377
9378         /* Generate test mbuf data and space for digest */
9379         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9380                         catch_22_quote, QUOTE_512_BYTES, 0);
9381
9382         /* create a pointer for digest, but don't expect anything to be written
9383          * here in a NULL auth algo so no mbuf append done.
9384          */
9385         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9386                         QUOTE_512_BYTES);
9387         /* prefill the memory pointed to by digest */
9388         memcpy(digest, orig_data, sizeof(orig_data));
9389
9390         /* Setup HMAC Parameters */
9391         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9392         ut_params->auth_xform.next = NULL;
9393
9394         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9395         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9396
9397         ut_params->sess = rte_cryptodev_sym_session_create(
9398                         ts_params->session_mpool);
9399
9400         /* Create Crypto session*/
9401         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9402                         ut_params->sess, &ut_params->auth_xform,
9403                         ts_params->session_priv_mpool);
9404         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9405
9406         /* Generate Crypto op data structure */
9407         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9408                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9409         TEST_ASSERT_NOT_NULL(ut_params->op,
9410                         "Failed to allocate symmetric crypto operation struct");
9411
9412         /* Set crypto operation data parameters */
9413         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9414
9415         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9416
9417         sym_op->m_src = ut_params->ibuf;
9418
9419         sym_op->auth.data.offset = 0;
9420         sym_op->auth.data.length = QUOTE_512_BYTES;
9421         sym_op->auth.digest.data = digest;
9422         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9423                         QUOTE_512_BYTES);
9424
9425         /* Process crypto operation */
9426         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9427                         ut_params->op);
9428         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9429
9430         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9431                         "crypto operation processing failed");
9432         /* Make sure memory pointed to by digest hasn't been overwritten */
9433         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9434                         orig_data,
9435                         digest,
9436                         sizeof(orig_data),
9437                         "Memory at digest ptr overwritten unexpectedly");
9438
9439         return TEST_SUCCESS;
9440 }
9441
9442
9443 static int
9444 test_null_cipher_auth_operation(void)
9445 {
9446         struct crypto_testsuite_params *ts_params = &testsuite_params;
9447         struct crypto_unittest_params *ut_params = &unittest_params;
9448         uint8_t *digest;
9449
9450         /* Verify the capabilities */
9451         struct rte_cryptodev_sym_capability_idx cap_idx;
9452         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9453         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9454         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9455                         &cap_idx) == NULL)
9456                 return -ENOTSUP;
9457         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9458         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9459         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9460                         &cap_idx) == NULL)
9461                 return -ENOTSUP;
9462
9463         /* Generate test mbuf data and space for digest */
9464         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9465                         catch_22_quote, QUOTE_512_BYTES, 0);
9466
9467         /* create a pointer for digest, but don't expect anything to be written
9468          * here in a NULL auth algo so no mbuf append done.
9469          */
9470         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9471                         QUOTE_512_BYTES);
9472         /* prefill the memory pointed to by digest */
9473         memcpy(digest, orig_data, sizeof(orig_data));
9474
9475         /* Setup Cipher Parameters */
9476         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9477         ut_params->cipher_xform.next = &ut_params->auth_xform;
9478
9479         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9480         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9481
9482         /* Setup HMAC Parameters */
9483         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9484         ut_params->auth_xform.next = NULL;
9485
9486         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9487         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9488
9489         ut_params->sess = rte_cryptodev_sym_session_create(
9490                         ts_params->session_mpool);
9491
9492         /* Create Crypto session*/
9493         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9494                         ut_params->sess, &ut_params->cipher_xform,
9495                         ts_params->session_priv_mpool);
9496         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9497
9498         /* Generate Crypto op data structure */
9499         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9500                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9501         TEST_ASSERT_NOT_NULL(ut_params->op,
9502                         "Failed to allocate symmetric crypto operation struct");
9503
9504         /* Set crypto operation data parameters */
9505         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9506
9507         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9508
9509         sym_op->m_src = ut_params->ibuf;
9510
9511         sym_op->cipher.data.offset = 0;
9512         sym_op->cipher.data.length = QUOTE_512_BYTES;
9513
9514         sym_op->auth.data.offset = 0;
9515         sym_op->auth.data.length = QUOTE_512_BYTES;
9516         sym_op->auth.digest.data = digest;
9517         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9518                         QUOTE_512_BYTES);
9519
9520         /* Process crypto operation */
9521         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9522                         ut_params->op);
9523         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9524
9525         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9526                         "crypto operation processing failed");
9527
9528         /* Validate obuf */
9529         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9530                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9531                         catch_22_quote,
9532                         QUOTE_512_BYTES,
9533                         "Ciphertext data not as expected");
9534         /* Make sure memory pointed to by digest hasn't been overwritten */
9535         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9536                         orig_data,
9537                         digest,
9538                         sizeof(orig_data),
9539                         "Memory at digest ptr overwritten unexpectedly");
9540
9541         return TEST_SUCCESS;
9542 }
9543
9544 static int
9545 test_null_auth_cipher_operation(void)
9546 {
9547         struct crypto_testsuite_params *ts_params = &testsuite_params;
9548         struct crypto_unittest_params *ut_params = &unittest_params;
9549         uint8_t *digest;
9550
9551         /* Verify the capabilities */
9552         struct rte_cryptodev_sym_capability_idx cap_idx;
9553         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9554         cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
9555         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9556                         &cap_idx) == NULL)
9557                 return -ENOTSUP;
9558         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9559         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
9560         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9561                         &cap_idx) == NULL)
9562                 return -ENOTSUP;
9563
9564         /* Generate test mbuf data */
9565         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
9566                         catch_22_quote, QUOTE_512_BYTES, 0);
9567
9568         /* create a pointer for digest, but don't expect anything to be written
9569          * here in a NULL auth algo so no mbuf append done.
9570          */
9571         digest = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9572                                 QUOTE_512_BYTES);
9573         /* prefill the memory pointed to by digest */
9574         memcpy(digest, orig_data, sizeof(orig_data));
9575
9576         /* Setup Cipher Parameters */
9577         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9578         ut_params->cipher_xform.next = NULL;
9579
9580         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9581         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9582
9583         /* Setup HMAC Parameters */
9584         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9585         ut_params->auth_xform.next = &ut_params->cipher_xform;
9586
9587         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9588         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9589
9590         ut_params->sess = rte_cryptodev_sym_session_create(
9591                         ts_params->session_mpool);
9592
9593         /* Create Crypto session*/
9594         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9595                         ut_params->sess, &ut_params->cipher_xform,
9596                         ts_params->session_priv_mpool);
9597         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9598
9599         /* Generate Crypto op data structure */
9600         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9601                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9602         TEST_ASSERT_NOT_NULL(ut_params->op,
9603                         "Failed to allocate symmetric crypto operation struct");
9604
9605         /* Set crypto operation data parameters */
9606         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9607
9608         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9609
9610         sym_op->m_src = ut_params->ibuf;
9611
9612         sym_op->cipher.data.offset = 0;
9613         sym_op->cipher.data.length = QUOTE_512_BYTES;
9614
9615         sym_op->auth.data.offset = 0;
9616         sym_op->auth.data.length = QUOTE_512_BYTES;
9617         sym_op->auth.digest.data = digest;
9618         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(ut_params->ibuf,
9619                                         QUOTE_512_BYTES);
9620
9621         /* Process crypto operation */
9622         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9623                         ut_params->op);
9624         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
9625
9626         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9627                         "crypto operation processing failed");
9628
9629         /* Validate obuf */
9630         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9631                         rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
9632                         catch_22_quote,
9633                         QUOTE_512_BYTES,
9634                         "Ciphertext data not as expected");
9635         /* Make sure memory pointed to by digest hasn't been overwritten */
9636         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9637                         orig_data,
9638                         digest,
9639                         sizeof(orig_data),
9640                         "Memory at digest ptr overwritten unexpectedly");
9641
9642         return TEST_SUCCESS;
9643 }
9644
9645
9646 static int
9647 test_null_invalid_operation(void)
9648 {
9649         struct crypto_testsuite_params *ts_params = &testsuite_params;
9650         struct crypto_unittest_params *ut_params = &unittest_params;
9651         int ret;
9652
9653         /* This test is for NULL PMD only */
9654         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9655                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9656                 return -ENOTSUP;
9657
9658         /* Setup Cipher Parameters */
9659         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9660         ut_params->cipher_xform.next = NULL;
9661
9662         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
9663         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9664
9665         ut_params->sess = rte_cryptodev_sym_session_create(
9666                         ts_params->session_mpool);
9667
9668         /* Create Crypto session*/
9669         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9670                         ut_params->sess, &ut_params->cipher_xform,
9671                         ts_params->session_priv_mpool);
9672         TEST_ASSERT(ret < 0,
9673                         "Session creation succeeded unexpectedly");
9674
9675
9676         /* Setup HMAC Parameters */
9677         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9678         ut_params->auth_xform.next = NULL;
9679
9680         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
9681         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9682
9683         ut_params->sess = rte_cryptodev_sym_session_create(
9684                         ts_params->session_mpool);
9685
9686         /* Create Crypto session*/
9687         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9688                         ut_params->sess, &ut_params->auth_xform,
9689                         ts_params->session_priv_mpool);
9690         TEST_ASSERT(ret < 0,
9691                         "Session creation succeeded unexpectedly");
9692
9693         return TEST_SUCCESS;
9694 }
9695
9696
9697 #define NULL_BURST_LENGTH (32)
9698
9699 static int
9700 test_null_burst_operation(void)
9701 {
9702         struct crypto_testsuite_params *ts_params = &testsuite_params;
9703         struct crypto_unittest_params *ut_params = &unittest_params;
9704
9705         unsigned i, burst_len = NULL_BURST_LENGTH;
9706
9707         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
9708         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
9709
9710         /* This test is for NULL PMD only */
9711         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9712                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9713                 return -ENOTSUP;
9714
9715         /* Setup Cipher Parameters */
9716         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9717         ut_params->cipher_xform.next = &ut_params->auth_xform;
9718
9719         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9720         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9721
9722         /* Setup HMAC Parameters */
9723         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9724         ut_params->auth_xform.next = NULL;
9725
9726         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9727         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9728
9729         ut_params->sess = rte_cryptodev_sym_session_create(
9730                         ts_params->session_mpool);
9731
9732         /* Create Crypto session*/
9733         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9734                         ut_params->sess, &ut_params->cipher_xform,
9735                         ts_params->session_priv_mpool);
9736         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9737
9738         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
9739                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
9740                         burst_len, "failed to generate burst of crypto ops");
9741
9742         /* Generate an operation for each mbuf in burst */
9743         for (i = 0; i < burst_len; i++) {
9744                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9745
9746                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
9747
9748                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
9749                                 sizeof(unsigned));
9750                 *data = i;
9751
9752                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
9753
9754                 burst[i]->sym->m_src = m;
9755         }
9756
9757         /* Process crypto operation */
9758         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
9759                         0, burst, burst_len),
9760                         burst_len,
9761                         "Error enqueuing burst");
9762
9763         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
9764                         0, burst_dequeued, burst_len),
9765                         burst_len,
9766                         "Error dequeuing burst");
9767
9768
9769         for (i = 0; i < burst_len; i++) {
9770                 TEST_ASSERT_EQUAL(
9771                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
9772                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
9773                                         uint32_t *),
9774                         "data not as expected");
9775
9776                 rte_pktmbuf_free(burst[i]->sym->m_src);
9777                 rte_crypto_op_free(burst[i]);
9778         }
9779
9780         return TEST_SUCCESS;
9781 }
9782
9783 static void
9784 generate_gmac_large_plaintext(uint8_t *data)
9785 {
9786         uint16_t i;
9787
9788         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
9789                 memcpy(&data[i], &data[0], 32);
9790 }
9791
9792 static int
9793 create_gmac_operation(enum rte_crypto_auth_operation op,
9794                 const struct gmac_test_data *tdata)
9795 {
9796         struct crypto_testsuite_params *ts_params = &testsuite_params;
9797         struct crypto_unittest_params *ut_params = &unittest_params;
9798         struct rte_crypto_sym_op *sym_op;
9799
9800         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9801
9802         /* Generate Crypto op data structure */
9803         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9804                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9805         TEST_ASSERT_NOT_NULL(ut_params->op,
9806                         "Failed to allocate symmetric crypto operation struct");
9807
9808         sym_op = ut_params->op->sym;
9809
9810         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9811                         ut_params->ibuf, tdata->gmac_tag.len);
9812         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9813                         "no room to append digest");
9814
9815         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9816                         ut_params->ibuf, plaintext_pad_len);
9817
9818         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9819                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
9820                                 tdata->gmac_tag.len);
9821                 debug_hexdump(stdout, "digest:",
9822                                 sym_op->auth.digest.data,
9823                                 tdata->gmac_tag.len);
9824         }
9825
9826         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9827                         uint8_t *, IV_OFFSET);
9828
9829         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
9830
9831         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
9832
9833         sym_op->cipher.data.length = 0;
9834         sym_op->cipher.data.offset = 0;
9835
9836         sym_op->auth.data.offset = 0;
9837         sym_op->auth.data.length = tdata->plaintext.len;
9838
9839         return 0;
9840 }
9841
9842 static int create_gmac_session(uint8_t dev_id,
9843                 const struct gmac_test_data *tdata,
9844                 enum rte_crypto_auth_operation auth_op)
9845 {
9846         uint8_t auth_key[tdata->key.len];
9847
9848         struct crypto_testsuite_params *ts_params = &testsuite_params;
9849         struct crypto_unittest_params *ut_params = &unittest_params;
9850
9851         memcpy(auth_key, tdata->key.data, tdata->key.len);
9852
9853         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9854         ut_params->auth_xform.next = NULL;
9855
9856         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
9857         ut_params->auth_xform.auth.op = auth_op;
9858         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
9859         ut_params->auth_xform.auth.key.length = tdata->key.len;
9860         ut_params->auth_xform.auth.key.data = auth_key;
9861         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
9862         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
9863
9864
9865         ut_params->sess = rte_cryptodev_sym_session_create(
9866                         ts_params->session_mpool);
9867
9868         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
9869                         &ut_params->auth_xform,
9870                         ts_params->session_priv_mpool);
9871
9872         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9873
9874         return 0;
9875 }
9876
9877 static int
9878 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
9879 {
9880         struct crypto_testsuite_params *ts_params = &testsuite_params;
9881         struct crypto_unittest_params *ut_params = &unittest_params;
9882
9883         int retval;
9884
9885         uint8_t *auth_tag, *plaintext;
9886         uint16_t plaintext_pad_len;
9887
9888         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
9889                               "No GMAC length in the source data");
9890
9891         /* Verify the capabilities */
9892         struct rte_cryptodev_sym_capability_idx cap_idx;
9893         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9894         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
9895         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9896                         &cap_idx) == NULL)
9897                 return -ENOTSUP;
9898
9899         retval = create_gmac_session(ts_params->valid_devs[0],
9900                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
9901
9902         if (retval < 0)
9903                 return retval;
9904
9905         if (tdata->plaintext.len > MBUF_SIZE)
9906                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9907         else
9908                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9909         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
9910                         "Failed to allocate input buffer in mempool");
9911
9912         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9913                         rte_pktmbuf_tailroom(ut_params->ibuf));
9914
9915         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9916         /*
9917          * Runtime generate the large plain text instead of use hard code
9918          * plain text vector. It is done to avoid create huge source file
9919          * with the test vector.
9920          */
9921         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
9922                 generate_gmac_large_plaintext(tdata->plaintext.data);
9923
9924         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9925                                 plaintext_pad_len);
9926         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9927
9928         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9929         debug_hexdump(stdout, "plaintext:", plaintext,
9930                         tdata->plaintext.len);
9931
9932         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
9933                         tdata);
9934
9935         if (retval < 0)
9936                 return retval;
9937
9938         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9939
9940         ut_params->op->sym->m_src = ut_params->ibuf;
9941
9942         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9943                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
9944                         ut_params->op);
9945         else
9946                 TEST_ASSERT_NOT_NULL(
9947                         process_crypto_request(ts_params->valid_devs[0],
9948                         ut_params->op), "failed to process sym crypto op");
9949
9950         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9951                         "crypto op processing failed");
9952
9953         if (ut_params->op->sym->m_dst) {
9954                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9955                                 uint8_t *, plaintext_pad_len);
9956         } else {
9957                 auth_tag = plaintext + plaintext_pad_len;
9958         }
9959
9960         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
9961
9962         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9963                         auth_tag,
9964                         tdata->gmac_tag.data,
9965                         tdata->gmac_tag.len,
9966                         "GMAC Generated auth tag not as expected");
9967
9968         return 0;
9969 }
9970
9971 static int
9972 test_AES_GMAC_authentication_test_case_1(void)
9973 {
9974         return test_AES_GMAC_authentication(&gmac_test_case_1);
9975 }
9976
9977 static int
9978 test_AES_GMAC_authentication_test_case_2(void)
9979 {
9980         return test_AES_GMAC_authentication(&gmac_test_case_2);
9981 }
9982
9983 static int
9984 test_AES_GMAC_authentication_test_case_3(void)
9985 {
9986         return test_AES_GMAC_authentication(&gmac_test_case_3);
9987 }
9988
9989 static int
9990 test_AES_GMAC_authentication_test_case_4(void)
9991 {
9992         return test_AES_GMAC_authentication(&gmac_test_case_4);
9993 }
9994
9995 static int
9996 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
9997 {
9998         struct crypto_testsuite_params *ts_params = &testsuite_params;
9999         struct crypto_unittest_params *ut_params = &unittest_params;
10000         int retval;
10001         uint32_t plaintext_pad_len;
10002         uint8_t *plaintext;
10003
10004         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10005                               "No GMAC length in the source data");
10006
10007         /* Verify the capabilities */
10008         struct rte_cryptodev_sym_capability_idx cap_idx;
10009         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10010         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10011         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10012                         &cap_idx) == NULL)
10013                 return -ENOTSUP;
10014
10015         retval = create_gmac_session(ts_params->valid_devs[0],
10016                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
10017
10018         if (retval < 0)
10019                 return retval;
10020
10021         if (tdata->plaintext.len > MBUF_SIZE)
10022                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10023         else
10024                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10025         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10026                         "Failed to allocate input buffer in mempool");
10027
10028         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10029                         rte_pktmbuf_tailroom(ut_params->ibuf));
10030
10031         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10032
10033         /*
10034          * Runtime generate the large plain text instead of use hard code
10035          * plain text vector. It is done to avoid create huge source file
10036          * with the test vector.
10037          */
10038         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10039                 generate_gmac_large_plaintext(tdata->plaintext.data);
10040
10041         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10042                                 plaintext_pad_len);
10043         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10044
10045         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10046         debug_hexdump(stdout, "plaintext:", plaintext,
10047                         tdata->plaintext.len);
10048
10049         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
10050                         tdata);
10051
10052         if (retval < 0)
10053                 return retval;
10054
10055         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10056
10057         ut_params->op->sym->m_src = ut_params->ibuf;
10058
10059         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10060                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10061                         ut_params->op);
10062         else
10063                 TEST_ASSERT_NOT_NULL(
10064                         process_crypto_request(ts_params->valid_devs[0],
10065                         ut_params->op), "failed to process sym crypto op");
10066
10067         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10068                         "crypto op processing failed");
10069
10070         return 0;
10071
10072 }
10073
10074 static int
10075 test_AES_GMAC_authentication_verify_test_case_1(void)
10076 {
10077         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
10078 }
10079
10080 static int
10081 test_AES_GMAC_authentication_verify_test_case_2(void)
10082 {
10083         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
10084 }
10085
10086 static int
10087 test_AES_GMAC_authentication_verify_test_case_3(void)
10088 {
10089         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
10090 }
10091
10092 static int
10093 test_AES_GMAC_authentication_verify_test_case_4(void)
10094 {
10095         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
10096 }
10097
10098 struct test_crypto_vector {
10099         enum rte_crypto_cipher_algorithm crypto_algo;
10100         unsigned int cipher_offset;
10101         unsigned int cipher_len;
10102
10103         struct {
10104                 uint8_t data[64];
10105                 unsigned int len;
10106         } cipher_key;
10107
10108         struct {
10109                 uint8_t data[64];
10110                 unsigned int len;
10111         } iv;
10112
10113         struct {
10114                 const uint8_t *data;
10115                 unsigned int len;
10116         } plaintext;
10117
10118         struct {
10119                 const uint8_t *data;
10120                 unsigned int len;
10121         } ciphertext;
10122
10123         enum rte_crypto_auth_algorithm auth_algo;
10124         unsigned int auth_offset;
10125
10126         struct {
10127                 uint8_t data[128];
10128                 unsigned int len;
10129         } auth_key;
10130
10131         struct {
10132                 const uint8_t *data;
10133                 unsigned int len;
10134         } aad;
10135
10136         struct {
10137                 uint8_t data[128];
10138                 unsigned int len;
10139         } digest;
10140 };
10141
10142 static const struct test_crypto_vector
10143 hmac_sha1_test_crypto_vector = {
10144         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10145         .plaintext = {
10146                 .data = plaintext_hash,
10147                 .len = 512
10148         },
10149         .auth_key = {
10150                 .data = {
10151                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10152                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10153                         0xDE, 0xF4, 0xDE, 0xAD
10154                 },
10155                 .len = 20
10156         },
10157         .digest = {
10158                 .data = {
10159                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
10160                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
10161                         0x3F, 0x91, 0x64, 0x59
10162                 },
10163                 .len = 20
10164         }
10165 };
10166
10167 static const struct test_crypto_vector
10168 aes128_gmac_test_vector = {
10169         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
10170         .plaintext = {
10171                 .data = plaintext_hash,
10172                 .len = 512
10173         },
10174         .iv = {
10175                 .data = {
10176                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10177                         0x08, 0x09, 0x0A, 0x0B
10178                 },
10179                 .len = 12
10180         },
10181         .auth_key = {
10182                 .data = {
10183                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10184                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
10185                 },
10186                 .len = 16
10187         },
10188         .digest = {
10189                 .data = {
10190                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
10191                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
10192                 },
10193                 .len = 16
10194         }
10195 };
10196
10197 static const struct test_crypto_vector
10198 aes128cbc_hmac_sha1_test_vector = {
10199         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10200         .cipher_offset = 0,
10201         .cipher_len = 512,
10202         .cipher_key = {
10203                 .data = {
10204                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10205                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10206                 },
10207                 .len = 16
10208         },
10209         .iv = {
10210                 .data = {
10211                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10212                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10213                 },
10214                 .len = 16
10215         },
10216         .plaintext = {
10217                 .data = plaintext_hash,
10218                 .len = 512
10219         },
10220         .ciphertext = {
10221                 .data = ciphertext512_aes128cbc,
10222                 .len = 512
10223         },
10224         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10225         .auth_offset = 0,
10226         .auth_key = {
10227                 .data = {
10228                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10229                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10230                         0xDE, 0xF4, 0xDE, 0xAD
10231                 },
10232                 .len = 20
10233         },
10234         .digest = {
10235                 .data = {
10236                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
10237                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10238                         0x18, 0x8C, 0x1D, 0x32
10239                 },
10240                 .len = 20
10241         }
10242 };
10243
10244 static const struct test_crypto_vector
10245 aes128cbc_hmac_sha1_aad_test_vector = {
10246         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10247         .cipher_offset = 12,
10248         .cipher_len = 496,
10249         .cipher_key = {
10250                 .data = {
10251                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10252                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10253                 },
10254                 .len = 16
10255         },
10256         .iv = {
10257                 .data = {
10258                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10259                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10260                 },
10261                 .len = 16
10262         },
10263         .plaintext = {
10264                 .data = plaintext_hash,
10265                 .len = 512
10266         },
10267         .ciphertext = {
10268                 .data = ciphertext512_aes128cbc_aad,
10269                 .len = 512
10270         },
10271         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10272         .auth_offset = 0,
10273         .auth_key = {
10274                 .data = {
10275                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10276                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10277                         0xDE, 0xF4, 0xDE, 0xAD
10278                 },
10279                 .len = 20
10280         },
10281         .digest = {
10282                 .data = {
10283                         0x1F, 0x6A, 0xD2, 0x8B, 0x4B, 0xB3, 0xC0, 0x9E,
10284                         0x86, 0x9B, 0x3A, 0xF2, 0x00, 0x5B, 0x4F, 0x08,
10285                         0x62, 0x8D, 0x62, 0x65
10286                 },
10287                 .len = 20
10288         }
10289 };
10290
10291 static void
10292 data_corruption(uint8_t *data)
10293 {
10294         data[0] += 1;
10295 }
10296
10297 static void
10298 tag_corruption(uint8_t *data, unsigned int tag_offset)
10299 {
10300         data[tag_offset] += 1;
10301 }
10302
10303 static int
10304 create_auth_session(struct crypto_unittest_params *ut_params,
10305                 uint8_t dev_id,
10306                 const struct test_crypto_vector *reference,
10307                 enum rte_crypto_auth_operation auth_op)
10308 {
10309         struct crypto_testsuite_params *ts_params = &testsuite_params;
10310         uint8_t auth_key[reference->auth_key.len + 1];
10311
10312         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10313
10314         /* Setup Authentication Parameters */
10315         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10316         ut_params->auth_xform.auth.op = auth_op;
10317         ut_params->auth_xform.next = NULL;
10318         ut_params->auth_xform.auth.algo = reference->auth_algo;
10319         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10320         ut_params->auth_xform.auth.key.data = auth_key;
10321         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10322
10323         /* Create Crypto session*/
10324         ut_params->sess = rte_cryptodev_sym_session_create(
10325                         ts_params->session_mpool);
10326
10327         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10328                                 &ut_params->auth_xform,
10329                                 ts_params->session_priv_mpool);
10330
10331         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10332
10333         return 0;
10334 }
10335
10336 static int
10337 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
10338                 uint8_t dev_id,
10339                 const struct test_crypto_vector *reference,
10340                 enum rte_crypto_auth_operation auth_op,
10341                 enum rte_crypto_cipher_operation cipher_op)
10342 {
10343         struct crypto_testsuite_params *ts_params = &testsuite_params;
10344         uint8_t cipher_key[reference->cipher_key.len + 1];
10345         uint8_t auth_key[reference->auth_key.len + 1];
10346
10347         memcpy(cipher_key, reference->cipher_key.data,
10348                         reference->cipher_key.len);
10349         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10350
10351         /* Setup Authentication Parameters */
10352         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10353         ut_params->auth_xform.auth.op = auth_op;
10354         ut_params->auth_xform.auth.algo = reference->auth_algo;
10355         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10356         ut_params->auth_xform.auth.key.data = auth_key;
10357         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10358
10359         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
10360                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10361                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
10362         } else {
10363                 ut_params->auth_xform.next = &ut_params->cipher_xform;
10364
10365                 /* Setup Cipher Parameters */
10366                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10367                 ut_params->cipher_xform.next = NULL;
10368                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10369                 ut_params->cipher_xform.cipher.op = cipher_op;
10370                 ut_params->cipher_xform.cipher.key.data = cipher_key;
10371                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10372                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10373                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10374         }
10375
10376         /* Create Crypto session*/
10377         ut_params->sess = rte_cryptodev_sym_session_create(
10378                         ts_params->session_mpool);
10379
10380         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10381                                 &ut_params->auth_xform,
10382                                 ts_params->session_priv_mpool);
10383
10384         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10385
10386         return 0;
10387 }
10388
10389 static int
10390 create_auth_operation(struct crypto_testsuite_params *ts_params,
10391                 struct crypto_unittest_params *ut_params,
10392                 const struct test_crypto_vector *reference,
10393                 unsigned int auth_generate)
10394 {
10395         /* Generate Crypto op data structure */
10396         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10397                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10398         TEST_ASSERT_NOT_NULL(ut_params->op,
10399                         "Failed to allocate pktmbuf offload");
10400
10401         /* Set crypto operation data parameters */
10402         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10403
10404         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10405
10406         /* set crypto operation source mbuf */
10407         sym_op->m_src = ut_params->ibuf;
10408
10409         /* digest */
10410         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10411                         ut_params->ibuf, reference->digest.len);
10412
10413         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10414                         "no room to append auth tag");
10415
10416         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10417                         ut_params->ibuf, reference->plaintext.len);
10418
10419         if (auth_generate)
10420                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10421         else
10422                 memcpy(sym_op->auth.digest.data,
10423                                 reference->digest.data,
10424                                 reference->digest.len);
10425
10426         debug_hexdump(stdout, "digest:",
10427                         sym_op->auth.digest.data,
10428                         reference->digest.len);
10429
10430         sym_op->auth.data.length = reference->plaintext.len;
10431         sym_op->auth.data.offset = 0;
10432
10433         return 0;
10434 }
10435
10436 static int
10437 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
10438                 struct crypto_unittest_params *ut_params,
10439                 const struct test_crypto_vector *reference,
10440                 unsigned int auth_generate)
10441 {
10442         /* Generate Crypto op data structure */
10443         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10444                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10445         TEST_ASSERT_NOT_NULL(ut_params->op,
10446                         "Failed to allocate pktmbuf offload");
10447
10448         /* Set crypto operation data parameters */
10449         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10450
10451         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10452
10453         /* set crypto operation source mbuf */
10454         sym_op->m_src = ut_params->ibuf;
10455
10456         /* digest */
10457         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10458                         ut_params->ibuf, reference->digest.len);
10459
10460         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10461                         "no room to append auth tag");
10462
10463         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10464                         ut_params->ibuf, reference->ciphertext.len);
10465
10466         if (auth_generate)
10467                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10468         else
10469                 memcpy(sym_op->auth.digest.data,
10470                                 reference->digest.data,
10471                                 reference->digest.len);
10472
10473         debug_hexdump(stdout, "digest:",
10474                         sym_op->auth.digest.data,
10475                         reference->digest.len);
10476
10477         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10478                         reference->iv.data, reference->iv.len);
10479
10480         sym_op->cipher.data.length = 0;
10481         sym_op->cipher.data.offset = 0;
10482
10483         sym_op->auth.data.length = reference->plaintext.len;
10484         sym_op->auth.data.offset = 0;
10485
10486         return 0;
10487 }
10488
10489 static int
10490 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
10491                 struct crypto_unittest_params *ut_params,
10492                 const struct test_crypto_vector *reference,
10493                 unsigned int auth_generate)
10494 {
10495         /* Generate Crypto op data structure */
10496         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10497                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10498         TEST_ASSERT_NOT_NULL(ut_params->op,
10499                         "Failed to allocate pktmbuf offload");
10500
10501         /* Set crypto operation data parameters */
10502         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10503
10504         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10505
10506         /* set crypto operation source mbuf */
10507         sym_op->m_src = ut_params->ibuf;
10508
10509         /* digest */
10510         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10511                         ut_params->ibuf, reference->digest.len);
10512
10513         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10514                         "no room to append auth tag");
10515
10516         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10517                         ut_params->ibuf, reference->ciphertext.len);
10518
10519         if (auth_generate)
10520                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10521         else
10522                 memcpy(sym_op->auth.digest.data,
10523                                 reference->digest.data,
10524                                 reference->digest.len);
10525
10526         debug_hexdump(stdout, "digest:",
10527                         sym_op->auth.digest.data,
10528                         reference->digest.len);
10529
10530         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10531                         reference->iv.data, reference->iv.len);
10532
10533         sym_op->cipher.data.length = reference->cipher_len;
10534         sym_op->cipher.data.offset = reference->cipher_offset;
10535
10536         sym_op->auth.data.length = reference->plaintext.len;
10537         sym_op->auth.data.offset = reference->auth_offset;
10538
10539         return 0;
10540 }
10541
10542 static int
10543 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10544                 struct crypto_unittest_params *ut_params,
10545                 const struct test_crypto_vector *reference)
10546 {
10547         return create_auth_operation(ts_params, ut_params, reference, 0);
10548 }
10549
10550 static int
10551 create_auth_verify_GMAC_operation(
10552                 struct crypto_testsuite_params *ts_params,
10553                 struct crypto_unittest_params *ut_params,
10554                 const struct test_crypto_vector *reference)
10555 {
10556         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
10557 }
10558
10559 static int
10560 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10561                 struct crypto_unittest_params *ut_params,
10562                 const struct test_crypto_vector *reference)
10563 {
10564         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
10565 }
10566
10567 static int
10568 test_authentication_verify_fail_when_data_corruption(
10569                 struct crypto_testsuite_params *ts_params,
10570                 struct crypto_unittest_params *ut_params,
10571                 const struct test_crypto_vector *reference,
10572                 unsigned int data_corrupted)
10573 {
10574         int retval;
10575
10576         uint8_t *plaintext;
10577
10578         /* Verify the capabilities */
10579         struct rte_cryptodev_sym_capability_idx cap_idx;
10580         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10581         cap_idx.algo.auth = reference->auth_algo;
10582         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10583                         &cap_idx) == NULL)
10584                 return -ENOTSUP;
10585
10586         /* Create session */
10587         retval = create_auth_session(ut_params,
10588                         ts_params->valid_devs[0],
10589                         reference,
10590                         RTE_CRYPTO_AUTH_OP_VERIFY);
10591         if (retval < 0)
10592                 return retval;
10593
10594         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10595         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10596                         "Failed to allocate input buffer in mempool");
10597
10598         /* clear mbuf payload */
10599         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10600                         rte_pktmbuf_tailroom(ut_params->ibuf));
10601
10602         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10603                         reference->plaintext.len);
10604         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10605         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10606
10607         debug_hexdump(stdout, "plaintext:", plaintext,
10608                 reference->plaintext.len);
10609
10610         /* Create operation */
10611         retval = create_auth_verify_operation(ts_params, ut_params, reference);
10612
10613         if (retval < 0)
10614                 return retval;
10615
10616         if (data_corrupted)
10617                 data_corruption(plaintext);
10618         else
10619                 tag_corruption(plaintext, reference->plaintext.len);
10620
10621         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10622                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10623                         ut_params->op);
10624                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10625                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10626                         "authentication not failed");
10627         } else {
10628                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10629                         ut_params->op);
10630                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10631         }
10632
10633         return 0;
10634 }
10635
10636 static int
10637 test_authentication_verify_GMAC_fail_when_corruption(
10638                 struct crypto_testsuite_params *ts_params,
10639                 struct crypto_unittest_params *ut_params,
10640                 const struct test_crypto_vector *reference,
10641                 unsigned int data_corrupted)
10642 {
10643         int retval;
10644         uint8_t *plaintext;
10645
10646         /* Verify the capabilities */
10647         struct rte_cryptodev_sym_capability_idx cap_idx;
10648         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10649         cap_idx.algo.auth = reference->auth_algo;
10650         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10651                         &cap_idx) == NULL)
10652                 return -ENOTSUP;
10653
10654         /* Create session */
10655         retval = create_auth_cipher_session(ut_params,
10656                         ts_params->valid_devs[0],
10657                         reference,
10658                         RTE_CRYPTO_AUTH_OP_VERIFY,
10659                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10660         if (retval < 0)
10661                 return retval;
10662
10663         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10664         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10665                         "Failed to allocate input buffer in mempool");
10666
10667         /* clear mbuf payload */
10668         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10669                         rte_pktmbuf_tailroom(ut_params->ibuf));
10670
10671         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10672                         reference->plaintext.len);
10673         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10674         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10675
10676         debug_hexdump(stdout, "plaintext:", plaintext,
10677                 reference->plaintext.len);
10678
10679         /* Create operation */
10680         retval = create_auth_verify_GMAC_operation(ts_params,
10681                         ut_params,
10682                         reference);
10683
10684         if (retval < 0)
10685                 return retval;
10686
10687         if (data_corrupted)
10688                 data_corruption(plaintext);
10689         else
10690                 tag_corruption(plaintext, reference->aad.len);
10691
10692         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10693                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10694                         ut_params->op);
10695                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10696                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10697                         "authentication not failed");
10698         } else {
10699                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10700                         ut_params->op);
10701                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10702         }
10703
10704         return 0;
10705 }
10706
10707 static int
10708 test_authenticated_decryption_fail_when_corruption(
10709                 struct crypto_testsuite_params *ts_params,
10710                 struct crypto_unittest_params *ut_params,
10711                 const struct test_crypto_vector *reference,
10712                 unsigned int data_corrupted)
10713 {
10714         int retval;
10715
10716         uint8_t *ciphertext;
10717
10718         /* Verify the capabilities */
10719         struct rte_cryptodev_sym_capability_idx cap_idx;
10720         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10721         cap_idx.algo.auth = reference->auth_algo;
10722         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10723                         &cap_idx) == NULL)
10724                 return -ENOTSUP;
10725         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10726         cap_idx.algo.cipher = reference->crypto_algo;
10727         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10728                         &cap_idx) == NULL)
10729                 return -ENOTSUP;
10730
10731         /* Create session */
10732         retval = create_auth_cipher_session(ut_params,
10733                         ts_params->valid_devs[0],
10734                         reference,
10735                         RTE_CRYPTO_AUTH_OP_VERIFY,
10736                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10737         if (retval < 0)
10738                 return retval;
10739
10740         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10741         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10742                         "Failed to allocate input buffer in mempool");
10743
10744         /* clear mbuf payload */
10745         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10746                         rte_pktmbuf_tailroom(ut_params->ibuf));
10747
10748         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10749                         reference->ciphertext.len);
10750         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10751         memcpy(ciphertext, reference->ciphertext.data,
10752                         reference->ciphertext.len);
10753
10754         /* Create operation */
10755         retval = create_cipher_auth_verify_operation(ts_params,
10756                         ut_params,
10757                         reference);
10758
10759         if (retval < 0)
10760                 return retval;
10761
10762         if (data_corrupted)
10763                 data_corruption(ciphertext);
10764         else
10765                 tag_corruption(ciphertext, reference->ciphertext.len);
10766
10767         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10768                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10769                         ut_params->op);
10770                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10771                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10772                         "authentication not failed");
10773         } else {
10774                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10775                         ut_params->op);
10776                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10777         }
10778
10779         return 0;
10780 }
10781
10782 static int
10783 test_authenticated_encryt_with_esn(
10784                 struct crypto_testsuite_params *ts_params,
10785                 struct crypto_unittest_params *ut_params,
10786                 const struct test_crypto_vector *reference)
10787 {
10788         int retval;
10789
10790         uint8_t *authciphertext, *plaintext, *auth_tag;
10791         uint16_t plaintext_pad_len;
10792         uint8_t cipher_key[reference->cipher_key.len + 1];
10793         uint8_t auth_key[reference->auth_key.len + 1];
10794
10795         /* Verify the capabilities */
10796         struct rte_cryptodev_sym_capability_idx cap_idx;
10797         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10798         cap_idx.algo.auth = reference->auth_algo;
10799         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10800                         &cap_idx) == NULL)
10801                 return -ENOTSUP;
10802         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10803         cap_idx.algo.cipher = reference->crypto_algo;
10804         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10805                         &cap_idx) == NULL)
10806                 return -ENOTSUP;
10807
10808         /* Create session */
10809         memcpy(cipher_key, reference->cipher_key.data,
10810                         reference->cipher_key.len);
10811         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10812
10813         /* Setup Cipher Parameters */
10814         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10815         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10816         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10817         ut_params->cipher_xform.cipher.key.data = cipher_key;
10818         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10819         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10820         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10821
10822         ut_params->cipher_xform.next = &ut_params->auth_xform;
10823
10824         /* Setup Authentication Parameters */
10825         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10826         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10827         ut_params->auth_xform.auth.algo = reference->auth_algo;
10828         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10829         ut_params->auth_xform.auth.key.data = auth_key;
10830         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10831         ut_params->auth_xform.next = NULL;
10832
10833         /* Create Crypto session*/
10834         ut_params->sess = rte_cryptodev_sym_session_create(
10835                         ts_params->session_mpool);
10836
10837         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10838                                 ut_params->sess,
10839                                 &ut_params->cipher_xform,
10840                                 ts_params->session_priv_mpool);
10841
10842         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10843
10844         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10845         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10846                         "Failed to allocate input buffer in mempool");
10847
10848         /* clear mbuf payload */
10849         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10850                         rte_pktmbuf_tailroom(ut_params->ibuf));
10851
10852         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10853                         reference->plaintext.len);
10854         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10855         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10856
10857         /* Create operation */
10858         retval = create_cipher_auth_operation(ts_params,
10859                         ut_params,
10860                         reference, 0);
10861
10862         if (retval < 0)
10863                 return retval;
10864
10865         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10866                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10867                         ut_params->op);
10868         else
10869                 ut_params->op = process_crypto_request(
10870                         ts_params->valid_devs[0], ut_params->op);
10871
10872         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
10873
10874         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10875                         "crypto op processing failed");
10876
10877         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
10878
10879         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10880                         ut_params->op->sym->auth.data.offset);
10881         auth_tag = authciphertext + plaintext_pad_len;
10882         debug_hexdump(stdout, "ciphertext:", authciphertext,
10883                         reference->ciphertext.len);
10884         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
10885
10886         /* Validate obuf */
10887         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10888                         authciphertext,
10889                         reference->ciphertext.data,
10890                         reference->ciphertext.len,
10891                         "Ciphertext data not as expected");
10892
10893         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10894                         auth_tag,
10895                         reference->digest.data,
10896                         reference->digest.len,
10897                         "Generated digest not as expected");
10898
10899         return TEST_SUCCESS;
10900
10901 }
10902
10903 static int
10904 test_authenticated_decrypt_with_esn(
10905                 struct crypto_testsuite_params *ts_params,
10906                 struct crypto_unittest_params *ut_params,
10907                 const struct test_crypto_vector *reference)
10908 {
10909         int retval;
10910
10911         uint8_t *ciphertext;
10912         uint8_t cipher_key[reference->cipher_key.len + 1];
10913         uint8_t auth_key[reference->auth_key.len + 1];
10914
10915         /* Verify the capabilities */
10916         struct rte_cryptodev_sym_capability_idx cap_idx;
10917         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10918         cap_idx.algo.auth = reference->auth_algo;
10919         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10920                         &cap_idx) == NULL)
10921                 return -ENOTSUP;
10922         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10923         cap_idx.algo.cipher = reference->crypto_algo;
10924         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10925                         &cap_idx) == NULL)
10926                 return -ENOTSUP;
10927
10928         /* Create session */
10929         memcpy(cipher_key, reference->cipher_key.data,
10930                         reference->cipher_key.len);
10931         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10932
10933         /* Setup Authentication Parameters */
10934         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10935         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
10936         ut_params->auth_xform.auth.algo = reference->auth_algo;
10937         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10938         ut_params->auth_xform.auth.key.data = auth_key;
10939         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10940         ut_params->auth_xform.next = &ut_params->cipher_xform;
10941
10942         /* Setup Cipher Parameters */
10943         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10944         ut_params->cipher_xform.next = NULL;
10945         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10946         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10947         ut_params->cipher_xform.cipher.key.data = cipher_key;
10948         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10949         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10950         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10951
10952         /* Create Crypto session*/
10953         ut_params->sess = rte_cryptodev_sym_session_create(
10954                         ts_params->session_mpool);
10955
10956         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10957                                 ut_params->sess,
10958                                 &ut_params->auth_xform,
10959                                 ts_params->session_priv_mpool);
10960
10961         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10962
10963         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10964         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10965                         "Failed to allocate input buffer in mempool");
10966
10967         /* clear mbuf payload */
10968         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10969                         rte_pktmbuf_tailroom(ut_params->ibuf));
10970
10971         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10972                         reference->ciphertext.len);
10973         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10974         memcpy(ciphertext, reference->ciphertext.data,
10975                         reference->ciphertext.len);
10976
10977         /* Create operation */
10978         retval = create_cipher_auth_verify_operation(ts_params,
10979                         ut_params,
10980                         reference);
10981
10982         if (retval < 0)
10983                 return retval;
10984
10985         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10986                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10987                         ut_params->op);
10988         else
10989                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10990                         ut_params->op);
10991
10992         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10993         TEST_ASSERT_EQUAL(ut_params->op->status,
10994                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10995                         "crypto op processing passed");
10996
10997         ut_params->obuf = ut_params->op->sym->m_src;
10998         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
10999
11000         return 0;
11001 }
11002
11003 static int
11004 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
11005                 const struct aead_test_data *tdata,
11006                 void *digest_mem, uint64_t digest_phys)
11007 {
11008         struct crypto_testsuite_params *ts_params = &testsuite_params;
11009         struct crypto_unittest_params *ut_params = &unittest_params;
11010
11011         const unsigned int auth_tag_len = tdata->auth_tag.len;
11012         const unsigned int iv_len = tdata->iv.len;
11013         unsigned int aad_len = tdata->aad.len;
11014         unsigned int aad_len_pad = 0;
11015
11016         /* Generate Crypto op data structure */
11017         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11018                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11019         TEST_ASSERT_NOT_NULL(ut_params->op,
11020                 "Failed to allocate symmetric crypto operation struct");
11021
11022         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11023
11024         sym_op->aead.digest.data = digest_mem;
11025
11026         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
11027                         "no room to append digest");
11028
11029         sym_op->aead.digest.phys_addr = digest_phys;
11030
11031         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
11032                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
11033                                 auth_tag_len);
11034                 debug_hexdump(stdout, "digest:",
11035                                 sym_op->aead.digest.data,
11036                                 auth_tag_len);
11037         }
11038
11039         /* Append aad data */
11040         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
11041                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11042                                 uint8_t *, IV_OFFSET);
11043
11044                 /* Copy IV 1 byte after the IV pointer, according to the API */
11045                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
11046
11047                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
11048
11049                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
11050                                 ut_params->ibuf, aad_len);
11051                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
11052                                 "no room to prepend aad");
11053                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
11054                                 ut_params->ibuf);
11055
11056                 memset(sym_op->aead.aad.data, 0, aad_len);
11057                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
11058                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
11059
11060                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
11061                 debug_hexdump(stdout, "aad:",
11062                                 sym_op->aead.aad.data, aad_len);
11063         } else {
11064                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11065                                 uint8_t *, IV_OFFSET);
11066
11067                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
11068
11069                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
11070
11071                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
11072                                 ut_params->ibuf, aad_len_pad);
11073                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
11074                                 "no room to prepend aad");
11075                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
11076                                 ut_params->ibuf);
11077
11078                 memset(sym_op->aead.aad.data, 0, aad_len);
11079                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
11080
11081                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
11082                 debug_hexdump(stdout, "aad:",
11083                                 sym_op->aead.aad.data, aad_len);
11084         }
11085
11086         sym_op->aead.data.length = tdata->plaintext.len;
11087         sym_op->aead.data.offset = aad_len_pad;
11088
11089         return 0;
11090 }
11091
11092 #define SGL_MAX_NO      16
11093
11094 static int
11095 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
11096                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
11097 {
11098         struct crypto_testsuite_params *ts_params = &testsuite_params;
11099         struct crypto_unittest_params *ut_params = &unittest_params;
11100         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
11101         int retval;
11102         int to_trn = 0;
11103         int to_trn_tbl[SGL_MAX_NO];
11104         int segs = 1;
11105         unsigned int trn_data = 0;
11106         uint8_t *plaintext, *ciphertext, *auth_tag;
11107         struct rte_cryptodev_info dev_info;
11108
11109         /* Verify the capabilities */
11110         struct rte_cryptodev_sym_capability_idx cap_idx;
11111         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11112         cap_idx.algo.aead = tdata->algo;
11113         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11114                         &cap_idx) == NULL)
11115                 return -ENOTSUP;
11116
11117         /* OOP not supported with CPU crypto */
11118         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11119                 return -ENOTSUP;
11120
11121         /* Detailed check for the particular SGL support flag */
11122         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11123         if (!oop) {
11124                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
11125                 if (sgl_in && (!(dev_info.feature_flags &
11126                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
11127                         return -ENOTSUP;
11128         } else {
11129                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
11130                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
11131                                 tdata->plaintext.len;
11132                 if (sgl_in && !sgl_out) {
11133                         if (!(dev_info.feature_flags &
11134                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
11135                                 return -ENOTSUP;
11136                 } else if (!sgl_in && sgl_out) {
11137                         if (!(dev_info.feature_flags &
11138                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
11139                                 return -ENOTSUP;
11140                 } else if (sgl_in && sgl_out) {
11141                         if (!(dev_info.feature_flags &
11142                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
11143                                 return -ENOTSUP;
11144                 }
11145         }
11146
11147         if (fragsz > tdata->plaintext.len)
11148                 fragsz = tdata->plaintext.len;
11149
11150         uint16_t plaintext_len = fragsz;
11151         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
11152
11153         if (fragsz_oop > tdata->plaintext.len)
11154                 frag_size_oop = tdata->plaintext.len;
11155
11156         int ecx = 0;
11157         void *digest_mem = NULL;
11158
11159         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
11160
11161         if (tdata->plaintext.len % fragsz != 0) {
11162                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
11163                         return 1;
11164         }       else {
11165                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
11166                         return 1;
11167         }
11168
11169         /*
11170          * For out-op-place we need to alloc another mbuf
11171          */
11172         if (oop) {
11173                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11174                 rte_pktmbuf_append(ut_params->obuf,
11175                                 frag_size_oop + prepend_len);
11176                 buf_oop = ut_params->obuf;
11177         }
11178
11179         /* Create AEAD session */
11180         retval = create_aead_session(ts_params->valid_devs[0],
11181                         tdata->algo,
11182                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
11183                         tdata->key.data, tdata->key.len,
11184                         tdata->aad.len, tdata->auth_tag.len,
11185                         tdata->iv.len);
11186         if (retval < 0)
11187                 return retval;
11188
11189         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11190
11191         /* clear mbuf payload */
11192         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11193                         rte_pktmbuf_tailroom(ut_params->ibuf));
11194
11195         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11196                         plaintext_len);
11197
11198         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11199
11200         trn_data += plaintext_len;
11201
11202         buf = ut_params->ibuf;
11203
11204         /*
11205          * Loop until no more fragments
11206          */
11207
11208         while (trn_data < tdata->plaintext.len) {
11209                 ++segs;
11210                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11211                                 (tdata->plaintext.len - trn_data) : fragsz;
11212
11213                 to_trn_tbl[ecx++] = to_trn;
11214
11215                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11216                 buf = buf->next;
11217
11218                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11219                                 rte_pktmbuf_tailroom(buf));
11220
11221                 /* OOP */
11222                 if (oop && !fragsz_oop) {
11223                         buf_last_oop = buf_oop->next =
11224                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11225                         buf_oop = buf_oop->next;
11226                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11227                                         0, rte_pktmbuf_tailroom(buf_oop));
11228                         rte_pktmbuf_append(buf_oop, to_trn);
11229                 }
11230
11231                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11232                                 to_trn);
11233
11234                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11235                                 to_trn);
11236                 trn_data += to_trn;
11237                 if (trn_data  == tdata->plaintext.len) {
11238                         if (oop) {
11239                                 if (!fragsz_oop)
11240                                         digest_mem = rte_pktmbuf_append(buf_oop,
11241                                                 tdata->auth_tag.len);
11242                         } else
11243                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11244                                         tdata->auth_tag.len);
11245                 }
11246         }
11247
11248         uint64_t digest_phys = 0;
11249
11250         ut_params->ibuf->nb_segs = segs;
11251
11252         segs = 1;
11253         if (fragsz_oop && oop) {
11254                 to_trn = 0;
11255                 ecx = 0;
11256
11257                 if (frag_size_oop == tdata->plaintext.len) {
11258                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
11259                                 tdata->auth_tag.len);
11260
11261                         digest_phys = rte_pktmbuf_iova_offset(
11262                                         ut_params->obuf,
11263                                         tdata->plaintext.len + prepend_len);
11264                 }
11265
11266                 trn_data = frag_size_oop;
11267                 while (trn_data < tdata->plaintext.len) {
11268                         ++segs;
11269                         to_trn =
11270                                 (tdata->plaintext.len - trn_data <
11271                                                 frag_size_oop) ?
11272                                 (tdata->plaintext.len - trn_data) :
11273                                                 frag_size_oop;
11274
11275                         to_trn_tbl[ecx++] = to_trn;
11276
11277                         buf_last_oop = buf_oop->next =
11278                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11279                         buf_oop = buf_oop->next;
11280                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11281                                         0, rte_pktmbuf_tailroom(buf_oop));
11282                         rte_pktmbuf_append(buf_oop, to_trn);
11283
11284                         trn_data += to_trn;
11285
11286                         if (trn_data  == tdata->plaintext.len) {
11287                                 digest_mem = rte_pktmbuf_append(buf_oop,
11288                                         tdata->auth_tag.len);
11289                         }
11290                 }
11291
11292                 ut_params->obuf->nb_segs = segs;
11293         }
11294
11295         /*
11296          * Place digest at the end of the last buffer
11297          */
11298         if (!digest_phys)
11299                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11300         if (oop && buf_last_oop)
11301                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
11302
11303         if (!digest_mem && !oop) {
11304                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11305                                 + tdata->auth_tag.len);
11306                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11307                                 tdata->plaintext.len);
11308         }
11309
11310         /* Create AEAD operation */
11311         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
11312                         tdata, digest_mem, digest_phys);
11313
11314         if (retval < 0)
11315                 return retval;
11316
11317         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11318
11319         ut_params->op->sym->m_src = ut_params->ibuf;
11320         if (oop)
11321                 ut_params->op->sym->m_dst = ut_params->obuf;
11322
11323         /* Process crypto operation */
11324         if (oop == IN_PLACE &&
11325                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11326                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
11327         else
11328                 TEST_ASSERT_NOT_NULL(
11329                         process_crypto_request(ts_params->valid_devs[0],
11330                         ut_params->op), "failed to process sym crypto op");
11331
11332         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11333                         "crypto op processing failed");
11334
11335
11336         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11337                         uint8_t *, prepend_len);
11338         if (oop) {
11339                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11340                                 uint8_t *, prepend_len);
11341         }
11342
11343         if (fragsz_oop)
11344                 fragsz = fragsz_oop;
11345
11346         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11347                         ciphertext,
11348                         tdata->ciphertext.data,
11349                         fragsz,
11350                         "Ciphertext data not as expected");
11351
11352         buf = ut_params->op->sym->m_src->next;
11353         if (oop)
11354                 buf = ut_params->op->sym->m_dst->next;
11355
11356         unsigned int off = fragsz;
11357
11358         ecx = 0;
11359         while (buf) {
11360                 ciphertext = rte_pktmbuf_mtod(buf,
11361                                 uint8_t *);
11362
11363                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
11364                                 ciphertext,
11365                                 tdata->ciphertext.data + off,
11366                                 to_trn_tbl[ecx],
11367                                 "Ciphertext data not as expected");
11368
11369                 off += to_trn_tbl[ecx++];
11370                 buf = buf->next;
11371         }
11372
11373         auth_tag = digest_mem;
11374         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11375                         auth_tag,
11376                         tdata->auth_tag.data,
11377                         tdata->auth_tag.len,
11378                         "Generated auth tag not as expected");
11379
11380         return 0;
11381 }
11382
11383 static int
11384 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
11385 {
11386         return test_authenticated_encryption_SGL(
11387                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
11388 }
11389
11390 static int
11391 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
11392 {
11393         return test_authenticated_encryption_SGL(
11394                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
11395 }
11396
11397 static int
11398 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
11399 {
11400         return test_authenticated_encryption_SGL(
11401                         &gcm_test_case_8, OUT_OF_PLACE, 400,
11402                         gcm_test_case_8.plaintext.len);
11403 }
11404
11405 static int
11406 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
11407 {
11408         /* This test is not for OPENSSL PMD */
11409         if (gbl_driver_id == rte_cryptodev_driver_id_get(
11410                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
11411                 return -ENOTSUP;
11412
11413         return test_authenticated_encryption_SGL(
11414                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
11415 }
11416
11417 static int
11418 test_authentication_verify_fail_when_data_corrupted(
11419                 struct crypto_testsuite_params *ts_params,
11420                 struct crypto_unittest_params *ut_params,
11421                 const struct test_crypto_vector *reference)
11422 {
11423         return test_authentication_verify_fail_when_data_corruption(
11424                         ts_params, ut_params, reference, 1);
11425 }
11426
11427 static int
11428 test_authentication_verify_fail_when_tag_corrupted(
11429                 struct crypto_testsuite_params *ts_params,
11430                 struct crypto_unittest_params *ut_params,
11431                 const struct test_crypto_vector *reference)
11432 {
11433         return test_authentication_verify_fail_when_data_corruption(
11434                         ts_params, ut_params, reference, 0);
11435 }
11436
11437 static int
11438 test_authentication_verify_GMAC_fail_when_data_corrupted(
11439                 struct crypto_testsuite_params *ts_params,
11440                 struct crypto_unittest_params *ut_params,
11441                 const struct test_crypto_vector *reference)
11442 {
11443         return test_authentication_verify_GMAC_fail_when_corruption(
11444                         ts_params, ut_params, reference, 1);
11445 }
11446
11447 static int
11448 test_authentication_verify_GMAC_fail_when_tag_corrupted(
11449                 struct crypto_testsuite_params *ts_params,
11450                 struct crypto_unittest_params *ut_params,
11451                 const struct test_crypto_vector *reference)
11452 {
11453         return test_authentication_verify_GMAC_fail_when_corruption(
11454                         ts_params, ut_params, reference, 0);
11455 }
11456
11457 static int
11458 test_authenticated_decryption_fail_when_data_corrupted(
11459                 struct crypto_testsuite_params *ts_params,
11460                 struct crypto_unittest_params *ut_params,
11461                 const struct test_crypto_vector *reference)
11462 {
11463         return test_authenticated_decryption_fail_when_corruption(
11464                         ts_params, ut_params, reference, 1);
11465 }
11466
11467 static int
11468 test_authenticated_decryption_fail_when_tag_corrupted(
11469                 struct crypto_testsuite_params *ts_params,
11470                 struct crypto_unittest_params *ut_params,
11471                 const struct test_crypto_vector *reference)
11472 {
11473         return test_authenticated_decryption_fail_when_corruption(
11474                         ts_params, ut_params, reference, 0);
11475 }
11476
11477 static int
11478 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
11479 {
11480         return test_authentication_verify_fail_when_data_corrupted(
11481                         &testsuite_params, &unittest_params,
11482                         &hmac_sha1_test_crypto_vector);
11483 }
11484
11485 static int
11486 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
11487 {
11488         return test_authentication_verify_fail_when_tag_corrupted(
11489                         &testsuite_params, &unittest_params,
11490                         &hmac_sha1_test_crypto_vector);
11491 }
11492
11493 static int
11494 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
11495 {
11496         return test_authentication_verify_GMAC_fail_when_data_corrupted(
11497                         &testsuite_params, &unittest_params,
11498                         &aes128_gmac_test_vector);
11499 }
11500
11501 static int
11502 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
11503 {
11504         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
11505                         &testsuite_params, &unittest_params,
11506                         &aes128_gmac_test_vector);
11507 }
11508
11509 static int
11510 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
11511 {
11512         return test_authenticated_decryption_fail_when_data_corrupted(
11513                         &testsuite_params,
11514                         &unittest_params,
11515                         &aes128cbc_hmac_sha1_test_vector);
11516 }
11517
11518 static int
11519 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
11520 {
11521         return test_authenticated_decryption_fail_when_tag_corrupted(
11522                         &testsuite_params,
11523                         &unittest_params,
11524                         &aes128cbc_hmac_sha1_test_vector);
11525 }
11526
11527 static int
11528 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11529 {
11530         return test_authenticated_encryt_with_esn(
11531                         &testsuite_params,
11532                         &unittest_params,
11533                         &aes128cbc_hmac_sha1_aad_test_vector);
11534 }
11535
11536 static int
11537 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11538 {
11539         return test_authenticated_decrypt_with_esn(
11540                         &testsuite_params,
11541                         &unittest_params,
11542                         &aes128cbc_hmac_sha1_aad_test_vector);
11543 }
11544
11545 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
11546
11547 /* global AESNI slave IDs for the scheduler test */
11548 uint8_t aesni_ids[2];
11549
11550 static int
11551 test_scheduler_attach_slave_op(void)
11552 {
11553         struct crypto_testsuite_params *ts_params = &testsuite_params;
11554         uint8_t sched_id = ts_params->valid_devs[0];
11555         uint32_t nb_devs, i, nb_devs_attached = 0;
11556         int ret;
11557         char vdev_name[32];
11558
11559         /* create 2 AESNI_MB if necessary */
11560         nb_devs = rte_cryptodev_device_count_by_driver(
11561                         rte_cryptodev_driver_id_get(
11562                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
11563         if (nb_devs < 2) {
11564                 for (i = nb_devs; i < 2; i++) {
11565                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
11566                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
11567                                         i);
11568                         ret = rte_vdev_init(vdev_name, NULL);
11569
11570                         TEST_ASSERT(ret == 0,
11571                                 "Failed to create instance %u of"
11572                                 " pmd : %s",
11573                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11574                 }
11575         }
11576
11577         /* attach 2 AESNI_MB cdevs */
11578         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
11579                         i++) {
11580                 struct rte_cryptodev_info info;
11581                 unsigned int session_size;
11582
11583                 rte_cryptodev_info_get(i, &info);
11584                 if (info.driver_id != rte_cryptodev_driver_id_get(
11585                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
11586                         continue;
11587
11588                 session_size = rte_cryptodev_sym_get_private_session_size(i);
11589                 /*
11590                  * Create the session mempool again, since now there are new devices
11591                  * to use the mempool.
11592                  */
11593                 if (ts_params->session_mpool) {
11594                         rte_mempool_free(ts_params->session_mpool);
11595                         ts_params->session_mpool = NULL;
11596                 }
11597                 if (ts_params->session_priv_mpool) {
11598                         rte_mempool_free(ts_params->session_priv_mpool);
11599                         ts_params->session_priv_mpool = NULL;
11600                 }
11601
11602                 if (info.sym.max_nb_sessions != 0 &&
11603                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
11604                         RTE_LOG(ERR, USER1,
11605                                         "Device does not support "
11606                                         "at least %u sessions\n",
11607                                         MAX_NB_SESSIONS);
11608                         return TEST_FAILED;
11609                 }
11610                 /*
11611                  * Create mempool with maximum number of sessions,
11612                  * to include the session headers
11613                  */
11614                 if (ts_params->session_mpool == NULL) {
11615                         ts_params->session_mpool =
11616                                 rte_cryptodev_sym_session_pool_create(
11617                                                 "test_sess_mp",
11618                                                 MAX_NB_SESSIONS, 0, 0, 0,
11619                                                 SOCKET_ID_ANY);
11620                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
11621                                         "session mempool allocation failed");
11622                 }
11623
11624                 /*
11625                  * Create mempool with maximum number of sessions,
11626                  * to include device specific session private data
11627                  */
11628                 if (ts_params->session_priv_mpool == NULL) {
11629                         ts_params->session_priv_mpool = rte_mempool_create(
11630                                         "test_sess_mp_priv",
11631                                         MAX_NB_SESSIONS,
11632                                         session_size,
11633                                         0, 0, NULL, NULL, NULL,
11634                                         NULL, SOCKET_ID_ANY,
11635                                         0);
11636
11637                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
11638                                         "session mempool allocation failed");
11639                 }
11640
11641                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
11642                 ts_params->qp_conf.mp_session_private =
11643                                 ts_params->session_priv_mpool;
11644
11645                 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
11646                                 (uint8_t)i);
11647
11648                 TEST_ASSERT(ret == 0,
11649                         "Failed to attach device %u of pmd : %s", i,
11650                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11651
11652                 aesni_ids[nb_devs_attached] = (uint8_t)i;
11653
11654                 nb_devs_attached++;
11655         }
11656
11657         return 0;
11658 }
11659
11660 static int
11661 test_scheduler_detach_slave_op(void)
11662 {
11663         struct crypto_testsuite_params *ts_params = &testsuite_params;
11664         uint8_t sched_id = ts_params->valid_devs[0];
11665         uint32_t i;
11666         int ret;
11667
11668         for (i = 0; i < 2; i++) {
11669                 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
11670                                 aesni_ids[i]);
11671                 TEST_ASSERT(ret == 0,
11672                         "Failed to detach device %u", aesni_ids[i]);
11673         }
11674
11675         return 0;
11676 }
11677
11678 static int
11679 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
11680 {
11681         struct crypto_testsuite_params *ts_params = &testsuite_params;
11682         uint8_t sched_id = ts_params->valid_devs[0];
11683         /* set mode */
11684         return rte_cryptodev_scheduler_mode_set(sched_id,
11685                 scheduler_mode);
11686 }
11687
11688 static int
11689 test_scheduler_mode_roundrobin_op(void)
11690 {
11691         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
11692                         0, "Failed to set roundrobin mode");
11693         return 0;
11694
11695 }
11696
11697 static int
11698 test_scheduler_mode_multicore_op(void)
11699 {
11700         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
11701                         0, "Failed to set multicore mode");
11702
11703         return 0;
11704 }
11705
11706 static int
11707 test_scheduler_mode_failover_op(void)
11708 {
11709         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
11710                         0, "Failed to set failover mode");
11711
11712         return 0;
11713 }
11714
11715 static int
11716 test_scheduler_mode_pkt_size_distr_op(void)
11717 {
11718         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
11719                         0, "Failed to set pktsize mode");
11720
11721         return 0;
11722 }
11723
11724 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
11725         .suite_name = "Crypto Device Scheduler Unit Test Suite",
11726         .setup = testsuite_setup,
11727         .teardown = testsuite_teardown,
11728         .unit_test_cases = {
11729                 /* Multi Core */
11730                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11731                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
11732                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11733                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11734                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11735                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11736
11737                 /* Round Robin */
11738                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11739                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
11740                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11741                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11742                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11743                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11744
11745                 /* Fail over */
11746                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11747                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
11748                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11749                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11750                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11751                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11752
11753                 /* PKT SIZE */
11754                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11755                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
11756                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11757                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11758                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11759                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11760
11761                 TEST_CASES_END() /**< NULL terminate unit test array */
11762         }
11763 };
11764
11765 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
11766
11767 static struct unit_test_suite cryptodev_testsuite  = {
11768         .suite_name = "Crypto Unit Test Suite",
11769         .setup = testsuite_setup,
11770         .teardown = testsuite_teardown,
11771         .unit_test_cases = {
11772                 TEST_CASE_ST(ut_setup, ut_teardown,
11773                                 test_device_configure_invalid_dev_id),
11774                 TEST_CASE_ST(ut_setup, ut_teardown,
11775                                 test_device_configure_invalid_queue_pair_ids),
11776                 TEST_CASE_ST(ut_setup, ut_teardown,
11777                                 test_queue_pair_descriptor_setup),
11778
11779                 TEST_CASE_ST(ut_setup, ut_teardown,
11780                                 test_multi_session),
11781                 TEST_CASE_ST(ut_setup, ut_teardown,
11782                                 test_multi_session_random_usage),
11783
11784                 TEST_CASE_ST(ut_setup, ut_teardown,
11785                         test_null_invalid_operation),
11786                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
11787
11788                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11789                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11790                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
11791                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
11792                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
11793                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
11794                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
11795                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11796                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
11797
11798                 /** AES CCM Authenticated Encryption 128 bits key */
11799                 TEST_CASE_ST(ut_setup, ut_teardown,
11800                         test_AES_CCM_authenticated_encryption_test_case_128_1),
11801                 TEST_CASE_ST(ut_setup, ut_teardown,
11802                         test_AES_CCM_authenticated_encryption_test_case_128_2),
11803                 TEST_CASE_ST(ut_setup, ut_teardown,
11804                         test_AES_CCM_authenticated_encryption_test_case_128_3),
11805
11806                 /** AES CCM Authenticated Decryption 128 bits key*/
11807                 TEST_CASE_ST(ut_setup, ut_teardown,
11808                         test_AES_CCM_authenticated_decryption_test_case_128_1),
11809                 TEST_CASE_ST(ut_setup, ut_teardown,
11810                         test_AES_CCM_authenticated_decryption_test_case_128_2),
11811                 TEST_CASE_ST(ut_setup, ut_teardown,
11812                         test_AES_CCM_authenticated_decryption_test_case_128_3),
11813
11814                 /** AES CCM Authenticated Encryption 192 bits key */
11815                 TEST_CASE_ST(ut_setup, ut_teardown,
11816                         test_AES_CCM_authenticated_encryption_test_case_192_1),
11817                 TEST_CASE_ST(ut_setup, ut_teardown,
11818                         test_AES_CCM_authenticated_encryption_test_case_192_2),
11819                 TEST_CASE_ST(ut_setup, ut_teardown,
11820                         test_AES_CCM_authenticated_encryption_test_case_192_3),
11821
11822                 /** AES CCM Authenticated Decryption 192 bits key*/
11823                 TEST_CASE_ST(ut_setup, ut_teardown,
11824                         test_AES_CCM_authenticated_decryption_test_case_192_1),
11825                 TEST_CASE_ST(ut_setup, ut_teardown,
11826                         test_AES_CCM_authenticated_decryption_test_case_192_2),
11827                 TEST_CASE_ST(ut_setup, ut_teardown,
11828                         test_AES_CCM_authenticated_decryption_test_case_192_3),
11829
11830                 /** AES CCM Authenticated Encryption 256 bits key */
11831                 TEST_CASE_ST(ut_setup, ut_teardown,
11832                         test_AES_CCM_authenticated_encryption_test_case_256_1),
11833                 TEST_CASE_ST(ut_setup, ut_teardown,
11834                         test_AES_CCM_authenticated_encryption_test_case_256_2),
11835                 TEST_CASE_ST(ut_setup, ut_teardown,
11836                         test_AES_CCM_authenticated_encryption_test_case_256_3),
11837
11838                 /** AES CCM Authenticated Decryption 256 bits key*/
11839                 TEST_CASE_ST(ut_setup, ut_teardown,
11840                         test_AES_CCM_authenticated_decryption_test_case_256_1),
11841                 TEST_CASE_ST(ut_setup, ut_teardown,
11842                         test_AES_CCM_authenticated_decryption_test_case_256_2),
11843                 TEST_CASE_ST(ut_setup, ut_teardown,
11844                         test_AES_CCM_authenticated_decryption_test_case_256_3),
11845
11846                 /** AES GCM Authenticated Encryption */
11847                 TEST_CASE_ST(ut_setup, ut_teardown,
11848                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
11849                 TEST_CASE_ST(ut_setup, ut_teardown,
11850                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
11851                 TEST_CASE_ST(ut_setup, ut_teardown,
11852                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
11853                 TEST_CASE_ST(ut_setup, ut_teardown,
11854                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
11855                 TEST_CASE_ST(ut_setup, ut_teardown,
11856                         test_AES_GCM_authenticated_encryption_test_case_1),
11857                 TEST_CASE_ST(ut_setup, ut_teardown,
11858                         test_AES_GCM_authenticated_encryption_test_case_2),
11859                 TEST_CASE_ST(ut_setup, ut_teardown,
11860                         test_AES_GCM_authenticated_encryption_test_case_3),
11861                 TEST_CASE_ST(ut_setup, ut_teardown,
11862                         test_AES_GCM_authenticated_encryption_test_case_4),
11863                 TEST_CASE_ST(ut_setup, ut_teardown,
11864                         test_AES_GCM_authenticated_encryption_test_case_5),
11865                 TEST_CASE_ST(ut_setup, ut_teardown,
11866                         test_AES_GCM_authenticated_encryption_test_case_6),
11867                 TEST_CASE_ST(ut_setup, ut_teardown,
11868                         test_AES_GCM_authenticated_encryption_test_case_7),
11869                 TEST_CASE_ST(ut_setup, ut_teardown,
11870                         test_AES_GCM_authenticated_encryption_test_case_8),
11871                 TEST_CASE_ST(ut_setup, ut_teardown,
11872                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
11873
11874                 /** AES GCM Authenticated Decryption */
11875                 TEST_CASE_ST(ut_setup, ut_teardown,
11876                         test_AES_GCM_authenticated_decryption_test_case_1),
11877                 TEST_CASE_ST(ut_setup, ut_teardown,
11878                         test_AES_GCM_authenticated_decryption_test_case_2),
11879                 TEST_CASE_ST(ut_setup, ut_teardown,
11880                         test_AES_GCM_authenticated_decryption_test_case_3),
11881                 TEST_CASE_ST(ut_setup, ut_teardown,
11882                         test_AES_GCM_authenticated_decryption_test_case_4),
11883                 TEST_CASE_ST(ut_setup, ut_teardown,
11884                         test_AES_GCM_authenticated_decryption_test_case_5),
11885                 TEST_CASE_ST(ut_setup, ut_teardown,
11886                         test_AES_GCM_authenticated_decryption_test_case_6),
11887                 TEST_CASE_ST(ut_setup, ut_teardown,
11888                         test_AES_GCM_authenticated_decryption_test_case_7),
11889                 TEST_CASE_ST(ut_setup, ut_teardown,
11890                         test_AES_GCM_authenticated_decryption_test_case_8),
11891                 TEST_CASE_ST(ut_setup, ut_teardown,
11892                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
11893
11894                 /** AES GCM Authenticated Encryption 192 bits key */
11895                 TEST_CASE_ST(ut_setup, ut_teardown,
11896                         test_AES_GCM_auth_encryption_test_case_192_1),
11897                 TEST_CASE_ST(ut_setup, ut_teardown,
11898                         test_AES_GCM_auth_encryption_test_case_192_2),
11899                 TEST_CASE_ST(ut_setup, ut_teardown,
11900                         test_AES_GCM_auth_encryption_test_case_192_3),
11901                 TEST_CASE_ST(ut_setup, ut_teardown,
11902                         test_AES_GCM_auth_encryption_test_case_192_4),
11903                 TEST_CASE_ST(ut_setup, ut_teardown,
11904                         test_AES_GCM_auth_encryption_test_case_192_5),
11905                 TEST_CASE_ST(ut_setup, ut_teardown,
11906                         test_AES_GCM_auth_encryption_test_case_192_6),
11907                 TEST_CASE_ST(ut_setup, ut_teardown,
11908                         test_AES_GCM_auth_encryption_test_case_192_7),
11909
11910                 /** AES GCM Authenticated Decryption 192 bits key */
11911                 TEST_CASE_ST(ut_setup, ut_teardown,
11912                         test_AES_GCM_auth_decryption_test_case_192_1),
11913                 TEST_CASE_ST(ut_setup, ut_teardown,
11914                         test_AES_GCM_auth_decryption_test_case_192_2),
11915                 TEST_CASE_ST(ut_setup, ut_teardown,
11916                         test_AES_GCM_auth_decryption_test_case_192_3),
11917                 TEST_CASE_ST(ut_setup, ut_teardown,
11918                         test_AES_GCM_auth_decryption_test_case_192_4),
11919                 TEST_CASE_ST(ut_setup, ut_teardown,
11920                         test_AES_GCM_auth_decryption_test_case_192_5),
11921                 TEST_CASE_ST(ut_setup, ut_teardown,
11922                         test_AES_GCM_auth_decryption_test_case_192_6),
11923                 TEST_CASE_ST(ut_setup, ut_teardown,
11924                         test_AES_GCM_auth_decryption_test_case_192_7),
11925
11926                 /** AES GCM Authenticated Encryption 256 bits key */
11927                 TEST_CASE_ST(ut_setup, ut_teardown,
11928                         test_AES_GCM_auth_encryption_test_case_256_1),
11929                 TEST_CASE_ST(ut_setup, ut_teardown,
11930                         test_AES_GCM_auth_encryption_test_case_256_2),
11931                 TEST_CASE_ST(ut_setup, ut_teardown,
11932                         test_AES_GCM_auth_encryption_test_case_256_3),
11933                 TEST_CASE_ST(ut_setup, ut_teardown,
11934                         test_AES_GCM_auth_encryption_test_case_256_4),
11935                 TEST_CASE_ST(ut_setup, ut_teardown,
11936                         test_AES_GCM_auth_encryption_test_case_256_5),
11937                 TEST_CASE_ST(ut_setup, ut_teardown,
11938                         test_AES_GCM_auth_encryption_test_case_256_6),
11939                 TEST_CASE_ST(ut_setup, ut_teardown,
11940                         test_AES_GCM_auth_encryption_test_case_256_7),
11941
11942                 /** AES GCM Authenticated Decryption 256 bits key */
11943                 TEST_CASE_ST(ut_setup, ut_teardown,
11944                         test_AES_GCM_auth_decryption_test_case_256_1),
11945                 TEST_CASE_ST(ut_setup, ut_teardown,
11946                         test_AES_GCM_auth_decryption_test_case_256_2),
11947                 TEST_CASE_ST(ut_setup, ut_teardown,
11948                         test_AES_GCM_auth_decryption_test_case_256_3),
11949                 TEST_CASE_ST(ut_setup, ut_teardown,
11950                         test_AES_GCM_auth_decryption_test_case_256_4),
11951                 TEST_CASE_ST(ut_setup, ut_teardown,
11952                         test_AES_GCM_auth_decryption_test_case_256_5),
11953                 TEST_CASE_ST(ut_setup, ut_teardown,
11954                         test_AES_GCM_auth_decryption_test_case_256_6),
11955                 TEST_CASE_ST(ut_setup, ut_teardown,
11956                         test_AES_GCM_auth_decryption_test_case_256_7),
11957
11958                 /** AES GCM Authenticated Encryption big aad size */
11959                 TEST_CASE_ST(ut_setup, ut_teardown,
11960                         test_AES_GCM_auth_encryption_test_case_aad_1),
11961                 TEST_CASE_ST(ut_setup, ut_teardown,
11962                         test_AES_GCM_auth_encryption_test_case_aad_2),
11963
11964                 /** AES GCM Authenticated Decryption big aad size */
11965                 TEST_CASE_ST(ut_setup, ut_teardown,
11966                         test_AES_GCM_auth_decryption_test_case_aad_1),
11967                 TEST_CASE_ST(ut_setup, ut_teardown,
11968                         test_AES_GCM_auth_decryption_test_case_aad_2),
11969
11970                 /** Out of place tests */
11971                 TEST_CASE_ST(ut_setup, ut_teardown,
11972                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
11973                 TEST_CASE_ST(ut_setup, ut_teardown,
11974                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
11975
11976                 /** Session-less tests */
11977                 TEST_CASE_ST(ut_setup, ut_teardown,
11978                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
11979                 TEST_CASE_ST(ut_setup, ut_teardown,
11980                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
11981
11982                 /** AES GMAC Authentication */
11983                 TEST_CASE_ST(ut_setup, ut_teardown,
11984                         test_AES_GMAC_authentication_test_case_1),
11985                 TEST_CASE_ST(ut_setup, ut_teardown,
11986                         test_AES_GMAC_authentication_verify_test_case_1),
11987                 TEST_CASE_ST(ut_setup, ut_teardown,
11988                         test_AES_GMAC_authentication_test_case_2),
11989                 TEST_CASE_ST(ut_setup, ut_teardown,
11990                         test_AES_GMAC_authentication_verify_test_case_2),
11991                 TEST_CASE_ST(ut_setup, ut_teardown,
11992                         test_AES_GMAC_authentication_test_case_3),
11993                 TEST_CASE_ST(ut_setup, ut_teardown,
11994                         test_AES_GMAC_authentication_verify_test_case_3),
11995                 TEST_CASE_ST(ut_setup, ut_teardown,
11996                         test_AES_GMAC_authentication_test_case_4),
11997                 TEST_CASE_ST(ut_setup, ut_teardown,
11998                         test_AES_GMAC_authentication_verify_test_case_4),
11999
12000                 /** SNOW 3G encrypt only (UEA2) */
12001                 TEST_CASE_ST(ut_setup, ut_teardown,
12002                         test_snow3g_encryption_test_case_1),
12003                 TEST_CASE_ST(ut_setup, ut_teardown,
12004                         test_snow3g_encryption_test_case_2),
12005                 TEST_CASE_ST(ut_setup, ut_teardown,
12006                         test_snow3g_encryption_test_case_3),
12007                 TEST_CASE_ST(ut_setup, ut_teardown,
12008                         test_snow3g_encryption_test_case_4),
12009                 TEST_CASE_ST(ut_setup, ut_teardown,
12010                         test_snow3g_encryption_test_case_5),
12011
12012                 TEST_CASE_ST(ut_setup, ut_teardown,
12013                         test_snow3g_encryption_test_case_1_oop),
12014                 TEST_CASE_ST(ut_setup, ut_teardown,
12015                         test_snow3g_encryption_test_case_1_oop_sgl),
12016                 TEST_CASE_ST(ut_setup, ut_teardown,
12017                         test_snow3g_encryption_test_case_1_offset_oop),
12018                 TEST_CASE_ST(ut_setup, ut_teardown,
12019                         test_snow3g_decryption_test_case_1_oop),
12020
12021                 /** SNOW 3G generate auth, then encrypt (UEA2) */
12022                 TEST_CASE_ST(ut_setup, ut_teardown,
12023                         test_snow3g_auth_cipher_test_case_1),
12024                 TEST_CASE_ST(ut_setup, ut_teardown,
12025                         test_snow3g_auth_cipher_test_case_2),
12026                 TEST_CASE_ST(ut_setup, ut_teardown,
12027                         test_snow3g_auth_cipher_test_case_2_oop),
12028                 TEST_CASE_ST(ut_setup, ut_teardown,
12029                         test_snow3g_auth_cipher_part_digest_enc),
12030                 TEST_CASE_ST(ut_setup, ut_teardown,
12031                         test_snow3g_auth_cipher_part_digest_enc_oop),
12032                 TEST_CASE_ST(ut_setup, ut_teardown,
12033                         test_snow3g_auth_cipher_test_case_3_sgl),
12034                 TEST_CASE_ST(ut_setup, ut_teardown,
12035                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
12036                 TEST_CASE_ST(ut_setup, ut_teardown,
12037                         test_snow3g_auth_cipher_part_digest_enc_sgl),
12038                 TEST_CASE_ST(ut_setup, ut_teardown,
12039                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
12040
12041                 /** SNOW 3G decrypt (UEA2), then verify auth */
12042                 TEST_CASE_ST(ut_setup, ut_teardown,
12043                         test_snow3g_auth_cipher_verify_test_case_1),
12044                 TEST_CASE_ST(ut_setup, ut_teardown,
12045                         test_snow3g_auth_cipher_verify_test_case_2),
12046                 TEST_CASE_ST(ut_setup, ut_teardown,
12047                         test_snow3g_auth_cipher_verify_test_case_2_oop),
12048                 TEST_CASE_ST(ut_setup, ut_teardown,
12049                         test_snow3g_auth_cipher_verify_part_digest_enc),
12050                 TEST_CASE_ST(ut_setup, ut_teardown,
12051                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
12052                 TEST_CASE_ST(ut_setup, ut_teardown,
12053                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
12054                 TEST_CASE_ST(ut_setup, ut_teardown,
12055                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
12056                 TEST_CASE_ST(ut_setup, ut_teardown,
12057                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
12058                 TEST_CASE_ST(ut_setup, ut_teardown,
12059                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
12060
12061                 /** SNOW 3G decrypt only (UEA2) */
12062                 TEST_CASE_ST(ut_setup, ut_teardown,
12063                         test_snow3g_decryption_test_case_1),
12064                 TEST_CASE_ST(ut_setup, ut_teardown,
12065                         test_snow3g_decryption_test_case_2),
12066                 TEST_CASE_ST(ut_setup, ut_teardown,
12067                         test_snow3g_decryption_test_case_3),
12068                 TEST_CASE_ST(ut_setup, ut_teardown,
12069                         test_snow3g_decryption_test_case_4),
12070                 TEST_CASE_ST(ut_setup, ut_teardown,
12071                         test_snow3g_decryption_test_case_5),
12072                 TEST_CASE_ST(ut_setup, ut_teardown,
12073                         test_snow3g_decryption_with_digest_test_case_1),
12074                 TEST_CASE_ST(ut_setup, ut_teardown,
12075                         test_snow3g_hash_generate_test_case_1),
12076                 TEST_CASE_ST(ut_setup, ut_teardown,
12077                         test_snow3g_hash_generate_test_case_2),
12078                 TEST_CASE_ST(ut_setup, ut_teardown,
12079                         test_snow3g_hash_generate_test_case_3),
12080                 /* Tests with buffers which length is not byte-aligned */
12081                 TEST_CASE_ST(ut_setup, ut_teardown,
12082                         test_snow3g_hash_generate_test_case_4),
12083                 TEST_CASE_ST(ut_setup, ut_teardown,
12084                         test_snow3g_hash_generate_test_case_5),
12085                 TEST_CASE_ST(ut_setup, ut_teardown,
12086                         test_snow3g_hash_generate_test_case_6),
12087                 TEST_CASE_ST(ut_setup, ut_teardown,
12088                         test_snow3g_hash_verify_test_case_1),
12089                 TEST_CASE_ST(ut_setup, ut_teardown,
12090                         test_snow3g_hash_verify_test_case_2),
12091                 TEST_CASE_ST(ut_setup, ut_teardown,
12092                         test_snow3g_hash_verify_test_case_3),
12093                 /* Tests with buffers which length is not byte-aligned */
12094                 TEST_CASE_ST(ut_setup, ut_teardown,
12095                         test_snow3g_hash_verify_test_case_4),
12096                 TEST_CASE_ST(ut_setup, ut_teardown,
12097                         test_snow3g_hash_verify_test_case_5),
12098                 TEST_CASE_ST(ut_setup, ut_teardown,
12099                         test_snow3g_hash_verify_test_case_6),
12100                 TEST_CASE_ST(ut_setup, ut_teardown,
12101                         test_snow3g_cipher_auth_test_case_1),
12102                 TEST_CASE_ST(ut_setup, ut_teardown,
12103                         test_snow3g_auth_cipher_with_digest_test_case_1),
12104
12105                 /** ZUC encrypt only (EEA3) */
12106                 TEST_CASE_ST(ut_setup, ut_teardown,
12107                         test_zuc_encryption_test_case_1),
12108                 TEST_CASE_ST(ut_setup, ut_teardown,
12109                         test_zuc_encryption_test_case_2),
12110                 TEST_CASE_ST(ut_setup, ut_teardown,
12111                         test_zuc_encryption_test_case_3),
12112                 TEST_CASE_ST(ut_setup, ut_teardown,
12113                         test_zuc_encryption_test_case_4),
12114                 TEST_CASE_ST(ut_setup, ut_teardown,
12115                         test_zuc_encryption_test_case_5),
12116                 TEST_CASE_ST(ut_setup, ut_teardown,
12117                         test_zuc_encryption_test_case_6_sgl),
12118
12119                 /** ZUC authenticate (EIA3) */
12120                 TEST_CASE_ST(ut_setup, ut_teardown,
12121                         test_zuc_hash_generate_test_case_1),
12122                 TEST_CASE_ST(ut_setup, ut_teardown,
12123                         test_zuc_hash_generate_test_case_2),
12124                 TEST_CASE_ST(ut_setup, ut_teardown,
12125                         test_zuc_hash_generate_test_case_3),
12126                 TEST_CASE_ST(ut_setup, ut_teardown,
12127                         test_zuc_hash_generate_test_case_4),
12128                 TEST_CASE_ST(ut_setup, ut_teardown,
12129                         test_zuc_hash_generate_test_case_5),
12130                 TEST_CASE_ST(ut_setup, ut_teardown,
12131                         test_zuc_hash_generate_test_case_6),
12132                 TEST_CASE_ST(ut_setup, ut_teardown,
12133                         test_zuc_hash_generate_test_case_7),
12134                 TEST_CASE_ST(ut_setup, ut_teardown,
12135                         test_zuc_hash_generate_test_case_8),
12136
12137                 /** ZUC alg-chain (EEA3/EIA3) */
12138                 TEST_CASE_ST(ut_setup, ut_teardown,
12139                         test_zuc_cipher_auth_test_case_1),
12140                 TEST_CASE_ST(ut_setup, ut_teardown,
12141                         test_zuc_cipher_auth_test_case_2),
12142
12143                 /** ZUC generate auth, then encrypt (EEA3) */
12144                 TEST_CASE_ST(ut_setup, ut_teardown,
12145                         test_zuc_auth_cipher_test_case_1),
12146                 TEST_CASE_ST(ut_setup, ut_teardown,
12147                         test_zuc_auth_cipher_test_case_1_oop),
12148                 TEST_CASE_ST(ut_setup, ut_teardown,
12149                         test_zuc_auth_cipher_test_case_1_sgl),
12150                 TEST_CASE_ST(ut_setup, ut_teardown,
12151                         test_zuc_auth_cipher_test_case_1_oop_sgl),
12152
12153                 /** ZUC decrypt (EEA3), then verify auth */
12154                 TEST_CASE_ST(ut_setup, ut_teardown,
12155                         test_zuc_auth_cipher_verify_test_case_1),
12156                 TEST_CASE_ST(ut_setup, ut_teardown,
12157                         test_zuc_auth_cipher_verify_test_case_1_oop),
12158                 TEST_CASE_ST(ut_setup, ut_teardown,
12159                         test_zuc_auth_cipher_verify_test_case_1_sgl),
12160                 TEST_CASE_ST(ut_setup, ut_teardown,
12161                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
12162
12163                 /** HMAC_MD5 Authentication */
12164                 TEST_CASE_ST(ut_setup, ut_teardown,
12165                         test_MD5_HMAC_generate_case_1),
12166                 TEST_CASE_ST(ut_setup, ut_teardown,
12167                         test_MD5_HMAC_verify_case_1),
12168                 TEST_CASE_ST(ut_setup, ut_teardown,
12169                         test_MD5_HMAC_generate_case_2),
12170                 TEST_CASE_ST(ut_setup, ut_teardown,
12171                         test_MD5_HMAC_verify_case_2),
12172
12173                 /** KASUMI hash only (UIA1) */
12174                 TEST_CASE_ST(ut_setup, ut_teardown,
12175                         test_kasumi_hash_generate_test_case_1),
12176                 TEST_CASE_ST(ut_setup, ut_teardown,
12177                         test_kasumi_hash_generate_test_case_2),
12178                 TEST_CASE_ST(ut_setup, ut_teardown,
12179                         test_kasumi_hash_generate_test_case_3),
12180                 TEST_CASE_ST(ut_setup, ut_teardown,
12181                         test_kasumi_hash_generate_test_case_4),
12182                 TEST_CASE_ST(ut_setup, ut_teardown,
12183                         test_kasumi_hash_generate_test_case_5),
12184                 TEST_CASE_ST(ut_setup, ut_teardown,
12185                         test_kasumi_hash_generate_test_case_6),
12186
12187                 TEST_CASE_ST(ut_setup, ut_teardown,
12188                         test_kasumi_hash_verify_test_case_1),
12189                 TEST_CASE_ST(ut_setup, ut_teardown,
12190                         test_kasumi_hash_verify_test_case_2),
12191                 TEST_CASE_ST(ut_setup, ut_teardown,
12192                         test_kasumi_hash_verify_test_case_3),
12193                 TEST_CASE_ST(ut_setup, ut_teardown,
12194                         test_kasumi_hash_verify_test_case_4),
12195                 TEST_CASE_ST(ut_setup, ut_teardown,
12196                         test_kasumi_hash_verify_test_case_5),
12197
12198                 /** KASUMI encrypt only (UEA1) */
12199                 TEST_CASE_ST(ut_setup, ut_teardown,
12200                         test_kasumi_encryption_test_case_1),
12201                 TEST_CASE_ST(ut_setup, ut_teardown,
12202                         test_kasumi_encryption_test_case_1_sgl),
12203                 TEST_CASE_ST(ut_setup, ut_teardown,
12204                         test_kasumi_encryption_test_case_1_oop),
12205                 TEST_CASE_ST(ut_setup, ut_teardown,
12206                         test_kasumi_encryption_test_case_1_oop_sgl),
12207                 TEST_CASE_ST(ut_setup, ut_teardown,
12208                         test_kasumi_encryption_test_case_2),
12209                 TEST_CASE_ST(ut_setup, ut_teardown,
12210                         test_kasumi_encryption_test_case_3),
12211                 TEST_CASE_ST(ut_setup, ut_teardown,
12212                         test_kasumi_encryption_test_case_4),
12213                 TEST_CASE_ST(ut_setup, ut_teardown,
12214                         test_kasumi_encryption_test_case_5),
12215
12216                 /** KASUMI decrypt only (UEA1) */
12217                 TEST_CASE_ST(ut_setup, ut_teardown,
12218                         test_kasumi_decryption_test_case_1),
12219                 TEST_CASE_ST(ut_setup, ut_teardown,
12220                         test_kasumi_decryption_test_case_2),
12221                 TEST_CASE_ST(ut_setup, ut_teardown,
12222                         test_kasumi_decryption_test_case_3),
12223                 TEST_CASE_ST(ut_setup, ut_teardown,
12224                         test_kasumi_decryption_test_case_4),
12225                 TEST_CASE_ST(ut_setup, ut_teardown,
12226                         test_kasumi_decryption_test_case_5),
12227                 TEST_CASE_ST(ut_setup, ut_teardown,
12228                         test_kasumi_decryption_test_case_1_oop),
12229
12230                 TEST_CASE_ST(ut_setup, ut_teardown,
12231                         test_kasumi_cipher_auth_test_case_1),
12232
12233                 /** KASUMI generate auth, then encrypt (F8) */
12234                 TEST_CASE_ST(ut_setup, ut_teardown,
12235                         test_kasumi_auth_cipher_test_case_1),
12236                 TEST_CASE_ST(ut_setup, ut_teardown,
12237                         test_kasumi_auth_cipher_test_case_2),
12238                 TEST_CASE_ST(ut_setup, ut_teardown,
12239                         test_kasumi_auth_cipher_test_case_2_oop),
12240                 TEST_CASE_ST(ut_setup, ut_teardown,
12241                         test_kasumi_auth_cipher_test_case_2_sgl),
12242                 TEST_CASE_ST(ut_setup, ut_teardown,
12243                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
12244
12245                 /** KASUMI decrypt (F8), then verify auth */
12246                 TEST_CASE_ST(ut_setup, ut_teardown,
12247                         test_kasumi_auth_cipher_verify_test_case_1),
12248                 TEST_CASE_ST(ut_setup, ut_teardown,
12249                         test_kasumi_auth_cipher_verify_test_case_2),
12250                 TEST_CASE_ST(ut_setup, ut_teardown,
12251                         test_kasumi_auth_cipher_verify_test_case_2_oop),
12252                 TEST_CASE_ST(ut_setup, ut_teardown,
12253                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
12254                 TEST_CASE_ST(ut_setup, ut_teardown,
12255                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
12256
12257                 /** ESN Testcase */
12258                 TEST_CASE_ST(ut_setup, ut_teardown,
12259                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12260                 TEST_CASE_ST(ut_setup, ut_teardown,
12261                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12262
12263                 /** Negative tests */
12264                 TEST_CASE_ST(ut_setup, ut_teardown,
12265                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12266                 TEST_CASE_ST(ut_setup, ut_teardown,
12267                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12268                 TEST_CASE_ST(ut_setup, ut_teardown,
12269                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12270                 TEST_CASE_ST(ut_setup, ut_teardown,
12271                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12272                 TEST_CASE_ST(ut_setup, ut_teardown,
12273                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12274                 TEST_CASE_ST(ut_setup, ut_teardown,
12275                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12276                 TEST_CASE_ST(ut_setup, ut_teardown,
12277                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12278                 TEST_CASE_ST(ut_setup, ut_teardown,
12279                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12280                 TEST_CASE_ST(ut_setup, ut_teardown,
12281                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12282                 TEST_CASE_ST(ut_setup, ut_teardown,
12283                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12284                 TEST_CASE_ST(ut_setup, ut_teardown,
12285                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12286                 TEST_CASE_ST(ut_setup, ut_teardown,
12287                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12288                 TEST_CASE_ST(ut_setup, ut_teardown,
12289                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12290                 TEST_CASE_ST(ut_setup, ut_teardown,
12291                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12292                 TEST_CASE_ST(ut_setup, ut_teardown,
12293                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12294                 TEST_CASE_ST(ut_setup, ut_teardown,
12295                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12296                 TEST_CASE_ST(ut_setup, ut_teardown,
12297                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12298                 TEST_CASE_ST(ut_setup, ut_teardown,
12299                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12300
12301                 /** Mixed CIPHER + HASH algorithms */
12302                 /** AUTH AES CMAC + CIPHER AES CTR */
12303                 TEST_CASE_ST(ut_setup, ut_teardown,
12304                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
12305                 TEST_CASE_ST(ut_setup, ut_teardown,
12306                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12307                 TEST_CASE_ST(ut_setup, ut_teardown,
12308                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12309                 TEST_CASE_ST(ut_setup, ut_teardown,
12310                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12311                 TEST_CASE_ST(ut_setup, ut_teardown,
12312                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
12313                 TEST_CASE_ST(ut_setup, ut_teardown,
12314                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12315                 TEST_CASE_ST(ut_setup, ut_teardown,
12316                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12317                 TEST_CASE_ST(ut_setup, ut_teardown,
12318                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12319
12320                 /** AUTH ZUC + CIPHER SNOW3G */
12321                 TEST_CASE_ST(ut_setup, ut_teardown,
12322                         test_auth_zuc_cipher_snow_test_case_1),
12323                 TEST_CASE_ST(ut_setup, ut_teardown,
12324                         test_verify_auth_zuc_cipher_snow_test_case_1),
12325                 /** AUTH AES CMAC + CIPHER SNOW3G */
12326                 TEST_CASE_ST(ut_setup, ut_teardown,
12327                         test_auth_aes_cmac_cipher_snow_test_case_1),
12328                 TEST_CASE_ST(ut_setup, ut_teardown,
12329                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
12330                 /** AUTH ZUC + CIPHER AES CTR */
12331                 TEST_CASE_ST(ut_setup, ut_teardown,
12332                         test_auth_zuc_cipher_aes_ctr_test_case_1),
12333                 TEST_CASE_ST(ut_setup, ut_teardown,
12334                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
12335                 /** AUTH SNOW3G + CIPHER AES CTR */
12336                 TEST_CASE_ST(ut_setup, ut_teardown,
12337                         test_auth_snow_cipher_aes_ctr_test_case_1),
12338                 TEST_CASE_ST(ut_setup, ut_teardown,
12339                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
12340                 /** AUTH SNOW3G + CIPHER ZUC */
12341                 TEST_CASE_ST(ut_setup, ut_teardown,
12342                         test_auth_snow_cipher_zuc_test_case_1),
12343                 TEST_CASE_ST(ut_setup, ut_teardown,
12344                         test_verify_auth_snow_cipher_zuc_test_case_1),
12345                 /** AUTH AES CMAC + CIPHER ZUC */
12346                 TEST_CASE_ST(ut_setup, ut_teardown,
12347                         test_auth_aes_cmac_cipher_zuc_test_case_1),
12348                 TEST_CASE_ST(ut_setup, ut_teardown,
12349                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
12350
12351                 /** AUTH NULL + CIPHER SNOW3G */
12352                 TEST_CASE_ST(ut_setup, ut_teardown,
12353                         test_auth_null_cipher_snow_test_case_1),
12354                 TEST_CASE_ST(ut_setup, ut_teardown,
12355                         test_verify_auth_null_cipher_snow_test_case_1),
12356                 /** AUTH NULL + CIPHER ZUC */
12357                 TEST_CASE_ST(ut_setup, ut_teardown,
12358                         test_auth_null_cipher_zuc_test_case_1),
12359                 TEST_CASE_ST(ut_setup, ut_teardown,
12360                         test_verify_auth_null_cipher_zuc_test_case_1),
12361                 /** AUTH SNOW3G + CIPHER NULL */
12362                 TEST_CASE_ST(ut_setup, ut_teardown,
12363                         test_auth_snow_cipher_null_test_case_1),
12364                 TEST_CASE_ST(ut_setup, ut_teardown,
12365                         test_verify_auth_snow_cipher_null_test_case_1),
12366                 /** AUTH ZUC + CIPHER NULL */
12367                 TEST_CASE_ST(ut_setup, ut_teardown,
12368                         test_auth_zuc_cipher_null_test_case_1),
12369                 TEST_CASE_ST(ut_setup, ut_teardown,
12370                         test_verify_auth_zuc_cipher_null_test_case_1),
12371                 /** AUTH NULL + CIPHER AES CTR */
12372                 TEST_CASE_ST(ut_setup, ut_teardown,
12373                         test_auth_null_cipher_aes_ctr_test_case_1),
12374                 TEST_CASE_ST(ut_setup, ut_teardown,
12375                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
12376                 /** AUTH AES CMAC + CIPHER NULL */
12377                 TEST_CASE_ST(ut_setup, ut_teardown,
12378                         test_auth_aes_cmac_cipher_null_test_case_1),
12379                 TEST_CASE_ST(ut_setup, ut_teardown,
12380                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
12381
12382                 TEST_CASES_END() /**< NULL terminate unit test array */
12383         }
12384 };
12385
12386 static struct unit_test_suite cryptodev_virtio_testsuite = {
12387         .suite_name = "Crypto VIRTIO Unit Test Suite",
12388         .setup = testsuite_setup,
12389         .teardown = testsuite_teardown,
12390         .unit_test_cases = {
12391                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12392
12393                 TEST_CASES_END() /**< NULL terminate unit test array */
12394         }
12395 };
12396
12397 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
12398         .suite_name = "Crypto CAAM JR Unit Test Suite",
12399         .setup = testsuite_setup,
12400         .teardown = testsuite_teardown,
12401         .unit_test_cases = {
12402                 TEST_CASE_ST(ut_setup, ut_teardown,
12403                              test_device_configure_invalid_dev_id),
12404                 TEST_CASE_ST(ut_setup, ut_teardown,
12405                              test_multi_session),
12406
12407                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12408                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12409                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12410                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12411                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12412
12413                 TEST_CASES_END() /**< NULL terminate unit test array */
12414         }
12415 };
12416
12417 static struct unit_test_suite cryptodev_dpaa_sec_testsuite  = {
12418         .suite_name = "Crypto DPAA_SEC Unit Test Suite",
12419         .setup = testsuite_setup,
12420         .teardown = testsuite_teardown,
12421         .unit_test_cases = {
12422                 TEST_CASE_ST(ut_setup, ut_teardown,
12423                              test_device_configure_invalid_dev_id),
12424                 TEST_CASE_ST(ut_setup, ut_teardown,
12425                              test_multi_session),
12426
12427                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12428                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12429                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12430                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12431                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12432
12433 #ifdef RTE_LIBRTE_SECURITY
12434                 TEST_CASE_ST(ut_setup, ut_teardown,
12435                         test_PDCP_PROTO_cplane_encap_all),
12436
12437                 TEST_CASE_ST(ut_setup, ut_teardown,
12438                         test_PDCP_PROTO_cplane_decap_all),
12439
12440                 TEST_CASE_ST(ut_setup, ut_teardown,
12441                         test_PDCP_PROTO_uplane_encap_all),
12442
12443                 TEST_CASE_ST(ut_setup, ut_teardown,
12444                         test_PDCP_PROTO_uplane_decap_all),
12445
12446                 TEST_CASE_ST(ut_setup, ut_teardown,
12447                         test_PDCP_PROTO_SGL_in_place_32B),
12448                 TEST_CASE_ST(ut_setup, ut_teardown,
12449                         test_PDCP_PROTO_SGL_oop_32B_128B),
12450                 TEST_CASE_ST(ut_setup, ut_teardown,
12451                         test_PDCP_PROTO_SGL_oop_32B_40B),
12452                 TEST_CASE_ST(ut_setup, ut_teardown,
12453                         test_PDCP_PROTO_SGL_oop_128B_32B),
12454 #endif
12455                 /** AES GCM Authenticated Encryption */
12456                 TEST_CASE_ST(ut_setup, ut_teardown,
12457                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12458                 TEST_CASE_ST(ut_setup, ut_teardown,
12459                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12460                 TEST_CASE_ST(ut_setup, ut_teardown,
12461                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12462                 TEST_CASE_ST(ut_setup, ut_teardown,
12463                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12464                 TEST_CASE_ST(ut_setup, ut_teardown,
12465                         test_AES_GCM_authenticated_encryption_test_case_1),
12466                 TEST_CASE_ST(ut_setup, ut_teardown,
12467                         test_AES_GCM_authenticated_encryption_test_case_2),
12468                 TEST_CASE_ST(ut_setup, ut_teardown,
12469                         test_AES_GCM_authenticated_encryption_test_case_3),
12470                 TEST_CASE_ST(ut_setup, ut_teardown,
12471                         test_AES_GCM_authenticated_encryption_test_case_4),
12472                 TEST_CASE_ST(ut_setup, ut_teardown,
12473                         test_AES_GCM_authenticated_encryption_test_case_5),
12474                 TEST_CASE_ST(ut_setup, ut_teardown,
12475                         test_AES_GCM_authenticated_encryption_test_case_6),
12476                 TEST_CASE_ST(ut_setup, ut_teardown,
12477                         test_AES_GCM_authenticated_encryption_test_case_7),
12478                 TEST_CASE_ST(ut_setup, ut_teardown,
12479                         test_AES_GCM_authenticated_encryption_test_case_8),
12480
12481                 /** AES GCM Authenticated Decryption */
12482                 TEST_CASE_ST(ut_setup, ut_teardown,
12483                         test_AES_GCM_authenticated_decryption_test_case_1),
12484                 TEST_CASE_ST(ut_setup, ut_teardown,
12485                         test_AES_GCM_authenticated_decryption_test_case_2),
12486                 TEST_CASE_ST(ut_setup, ut_teardown,
12487                         test_AES_GCM_authenticated_decryption_test_case_3),
12488                 TEST_CASE_ST(ut_setup, ut_teardown,
12489                         test_AES_GCM_authenticated_decryption_test_case_4),
12490                 TEST_CASE_ST(ut_setup, ut_teardown,
12491                         test_AES_GCM_authenticated_decryption_test_case_5),
12492                 TEST_CASE_ST(ut_setup, ut_teardown,
12493                         test_AES_GCM_authenticated_decryption_test_case_6),
12494                 TEST_CASE_ST(ut_setup, ut_teardown,
12495                         test_AES_GCM_authenticated_decryption_test_case_7),
12496                 TEST_CASE_ST(ut_setup, ut_teardown,
12497                         test_AES_GCM_authenticated_decryption_test_case_8),
12498
12499                 /** AES GCM Authenticated Encryption 192 bits key */
12500                 TEST_CASE_ST(ut_setup, ut_teardown,
12501                         test_AES_GCM_auth_encryption_test_case_192_1),
12502                 TEST_CASE_ST(ut_setup, ut_teardown,
12503                         test_AES_GCM_auth_encryption_test_case_192_2),
12504                 TEST_CASE_ST(ut_setup, ut_teardown,
12505                         test_AES_GCM_auth_encryption_test_case_192_3),
12506                 TEST_CASE_ST(ut_setup, ut_teardown,
12507                         test_AES_GCM_auth_encryption_test_case_192_4),
12508                 TEST_CASE_ST(ut_setup, ut_teardown,
12509                         test_AES_GCM_auth_encryption_test_case_192_5),
12510                 TEST_CASE_ST(ut_setup, ut_teardown,
12511                         test_AES_GCM_auth_encryption_test_case_192_6),
12512                 TEST_CASE_ST(ut_setup, ut_teardown,
12513                         test_AES_GCM_auth_encryption_test_case_192_7),
12514
12515                 /** AES GCM Authenticated Decryption 192 bits key */
12516                 TEST_CASE_ST(ut_setup, ut_teardown,
12517                         test_AES_GCM_auth_decryption_test_case_192_1),
12518                 TEST_CASE_ST(ut_setup, ut_teardown,
12519                         test_AES_GCM_auth_decryption_test_case_192_2),
12520                 TEST_CASE_ST(ut_setup, ut_teardown,
12521                         test_AES_GCM_auth_decryption_test_case_192_3),
12522                 TEST_CASE_ST(ut_setup, ut_teardown,
12523                         test_AES_GCM_auth_decryption_test_case_192_4),
12524                 TEST_CASE_ST(ut_setup, ut_teardown,
12525                         test_AES_GCM_auth_decryption_test_case_192_5),
12526                 TEST_CASE_ST(ut_setup, ut_teardown,
12527                         test_AES_GCM_auth_decryption_test_case_192_6),
12528                 TEST_CASE_ST(ut_setup, ut_teardown,
12529                         test_AES_GCM_auth_decryption_test_case_192_7),
12530
12531                 /** AES GCM Authenticated Encryption 256 bits key */
12532                 TEST_CASE_ST(ut_setup, ut_teardown,
12533                         test_AES_GCM_auth_encryption_test_case_256_1),
12534                 TEST_CASE_ST(ut_setup, ut_teardown,
12535                         test_AES_GCM_auth_encryption_test_case_256_2),
12536                 TEST_CASE_ST(ut_setup, ut_teardown,
12537                         test_AES_GCM_auth_encryption_test_case_256_3),
12538                 TEST_CASE_ST(ut_setup, ut_teardown,
12539                         test_AES_GCM_auth_encryption_test_case_256_4),
12540                 TEST_CASE_ST(ut_setup, ut_teardown,
12541                         test_AES_GCM_auth_encryption_test_case_256_5),
12542                 TEST_CASE_ST(ut_setup, ut_teardown,
12543                         test_AES_GCM_auth_encryption_test_case_256_6),
12544                 TEST_CASE_ST(ut_setup, ut_teardown,
12545                         test_AES_GCM_auth_encryption_test_case_256_7),
12546
12547                 /** AES GCM Authenticated Decryption 256 bits key */
12548                 TEST_CASE_ST(ut_setup, ut_teardown,
12549                         test_AES_GCM_auth_decryption_test_case_256_1),
12550                 TEST_CASE_ST(ut_setup, ut_teardown,
12551                         test_AES_GCM_auth_decryption_test_case_256_2),
12552                 TEST_CASE_ST(ut_setup, ut_teardown,
12553                         test_AES_GCM_auth_decryption_test_case_256_3),
12554                 TEST_CASE_ST(ut_setup, ut_teardown,
12555                         test_AES_GCM_auth_decryption_test_case_256_4),
12556                 TEST_CASE_ST(ut_setup, ut_teardown,
12557                         test_AES_GCM_auth_decryption_test_case_256_5),
12558                 TEST_CASE_ST(ut_setup, ut_teardown,
12559                         test_AES_GCM_auth_decryption_test_case_256_6),
12560                 TEST_CASE_ST(ut_setup, ut_teardown,
12561                         test_AES_GCM_auth_decryption_test_case_256_7),
12562
12563                 /** Out of place tests */
12564                 TEST_CASE_ST(ut_setup, ut_teardown,
12565                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12566                 TEST_CASE_ST(ut_setup, ut_teardown,
12567                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12568
12569                 /** SNOW 3G encrypt only (UEA2) */
12570                 TEST_CASE_ST(ut_setup, ut_teardown,
12571                         test_snow3g_encryption_test_case_1),
12572                 TEST_CASE_ST(ut_setup, ut_teardown,
12573                         test_snow3g_encryption_test_case_2),
12574                 TEST_CASE_ST(ut_setup, ut_teardown,
12575                         test_snow3g_encryption_test_case_3),
12576                 TEST_CASE_ST(ut_setup, ut_teardown,
12577                         test_snow3g_encryption_test_case_4),
12578                 TEST_CASE_ST(ut_setup, ut_teardown,
12579                         test_snow3g_encryption_test_case_5),
12580
12581                 TEST_CASE_ST(ut_setup, ut_teardown,
12582                         test_snow3g_encryption_test_case_1_oop),
12583                 TEST_CASE_ST(ut_setup, ut_teardown,
12584                                 test_snow3g_encryption_test_case_1_oop_sgl),
12585                 TEST_CASE_ST(ut_setup, ut_teardown,
12586                         test_snow3g_decryption_test_case_1_oop),
12587
12588                 /** SNOW 3G decrypt only (UEA2) */
12589                 TEST_CASE_ST(ut_setup, ut_teardown,
12590                         test_snow3g_decryption_test_case_1),
12591                 TEST_CASE_ST(ut_setup, ut_teardown,
12592                         test_snow3g_decryption_test_case_2),
12593                 TEST_CASE_ST(ut_setup, ut_teardown,
12594                         test_snow3g_decryption_test_case_3),
12595                 TEST_CASE_ST(ut_setup, ut_teardown,
12596                         test_snow3g_decryption_test_case_4),
12597                 TEST_CASE_ST(ut_setup, ut_teardown,
12598                         test_snow3g_decryption_test_case_5),
12599
12600                 TEST_CASE_ST(ut_setup, ut_teardown,
12601                         test_snow3g_hash_generate_test_case_1),
12602                 TEST_CASE_ST(ut_setup, ut_teardown,
12603                         test_snow3g_hash_generate_test_case_2),
12604                 TEST_CASE_ST(ut_setup, ut_teardown,
12605                         test_snow3g_hash_generate_test_case_3),
12606                 TEST_CASE_ST(ut_setup, ut_teardown,
12607                         test_snow3g_hash_verify_test_case_1),
12608                 TEST_CASE_ST(ut_setup, ut_teardown,
12609                         test_snow3g_hash_verify_test_case_2),
12610                 TEST_CASE_ST(ut_setup, ut_teardown,
12611                         test_snow3g_hash_verify_test_case_3),
12612
12613                 /** ZUC encrypt only (EEA3) */
12614                 TEST_CASE_ST(ut_setup, ut_teardown,
12615                         test_zuc_encryption_test_case_1),
12616                 TEST_CASE_ST(ut_setup, ut_teardown,
12617                         test_zuc_encryption_test_case_2),
12618                 TEST_CASE_ST(ut_setup, ut_teardown,
12619                         test_zuc_encryption_test_case_3),
12620                 TEST_CASE_ST(ut_setup, ut_teardown,
12621                         test_zuc_encryption_test_case_4),
12622                 TEST_CASE_ST(ut_setup, ut_teardown,
12623                         test_zuc_encryption_test_case_5),
12624
12625                 /** ZUC authenticate (EIA3) */
12626                 TEST_CASE_ST(ut_setup, ut_teardown,
12627                         test_zuc_hash_generate_test_case_6),
12628                 TEST_CASE_ST(ut_setup, ut_teardown,
12629                         test_zuc_hash_generate_test_case_7),
12630                 TEST_CASE_ST(ut_setup, ut_teardown,
12631                         test_zuc_hash_generate_test_case_8),
12632
12633                 /** Negative tests */
12634                 TEST_CASE_ST(ut_setup, ut_teardown,
12635                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12636                 TEST_CASE_ST(ut_setup, ut_teardown,
12637                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12638                 TEST_CASE_ST(ut_setup, ut_teardown,
12639                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12640                 TEST_CASE_ST(ut_setup, ut_teardown,
12641                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12642                 TEST_CASE_ST(ut_setup, ut_teardown,
12643                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12644                 TEST_CASE_ST(ut_setup, ut_teardown,
12645                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12646                 TEST_CASE_ST(ut_setup, ut_teardown,
12647                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12648                 TEST_CASE_ST(ut_setup, ut_teardown,
12649                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12650                 TEST_CASE_ST(ut_setup, ut_teardown,
12651                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12652                 TEST_CASE_ST(ut_setup, ut_teardown,
12653                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12654                 TEST_CASE_ST(ut_setup, ut_teardown,
12655                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12656                 TEST_CASE_ST(ut_setup, ut_teardown,
12657                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12658                 TEST_CASE_ST(ut_setup, ut_teardown,
12659                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12660                 TEST_CASE_ST(ut_setup, ut_teardown,
12661                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12662                 TEST_CASE_ST(ut_setup, ut_teardown,
12663                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12664                 TEST_CASE_ST(ut_setup, ut_teardown,
12665                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12666
12667                 /* ESN Testcase */
12668                 TEST_CASE_ST(ut_setup, ut_teardown,
12669                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12670                 TEST_CASE_ST(ut_setup, ut_teardown,
12671                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12672
12673                 TEST_CASES_END() /**< NULL terminate unit test array */
12674         }
12675 };
12676
12677 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite  = {
12678         .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
12679         .setup = testsuite_setup,
12680         .teardown = testsuite_teardown,
12681         .unit_test_cases = {
12682                 TEST_CASE_ST(ut_setup, ut_teardown,
12683                         test_device_configure_invalid_dev_id),
12684                 TEST_CASE_ST(ut_setup, ut_teardown,
12685                         test_multi_session),
12686                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12687                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12688                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12689                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12690                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12691
12692 #ifdef RTE_LIBRTE_SECURITY
12693                 TEST_CASE_ST(ut_setup, ut_teardown,
12694                         test_PDCP_PROTO_cplane_encap_all),
12695
12696                 TEST_CASE_ST(ut_setup, ut_teardown,
12697                         test_PDCP_PROTO_cplane_decap_all),
12698
12699                 TEST_CASE_ST(ut_setup, ut_teardown,
12700                         test_PDCP_PROTO_uplane_encap_all),
12701
12702                 TEST_CASE_ST(ut_setup, ut_teardown,
12703                         test_PDCP_PROTO_uplane_decap_all),
12704
12705                 TEST_CASE_ST(ut_setup, ut_teardown,
12706                         test_PDCP_PROTO_SGL_in_place_32B),
12707                 TEST_CASE_ST(ut_setup, ut_teardown,
12708                         test_PDCP_PROTO_SGL_oop_32B_128B),
12709                 TEST_CASE_ST(ut_setup, ut_teardown,
12710                         test_PDCP_PROTO_SGL_oop_32B_40B),
12711                 TEST_CASE_ST(ut_setup, ut_teardown,
12712                         test_PDCP_PROTO_SGL_oop_128B_32B),
12713 #endif
12714                 /** AES GCM Authenticated Encryption */
12715                 TEST_CASE_ST(ut_setup, ut_teardown,
12716                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12717                 TEST_CASE_ST(ut_setup, ut_teardown,
12718                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12719                 TEST_CASE_ST(ut_setup, ut_teardown,
12720                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12721                 TEST_CASE_ST(ut_setup, ut_teardown,
12722                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12723                 TEST_CASE_ST(ut_setup, ut_teardown,
12724                         test_AES_GCM_authenticated_encryption_test_case_1),
12725                 TEST_CASE_ST(ut_setup, ut_teardown,
12726                         test_AES_GCM_authenticated_encryption_test_case_2),
12727                 TEST_CASE_ST(ut_setup, ut_teardown,
12728                         test_AES_GCM_authenticated_encryption_test_case_3),
12729                 TEST_CASE_ST(ut_setup, ut_teardown,
12730                         test_AES_GCM_authenticated_encryption_test_case_4),
12731                 TEST_CASE_ST(ut_setup, ut_teardown,
12732                         test_AES_GCM_authenticated_encryption_test_case_5),
12733                 TEST_CASE_ST(ut_setup, ut_teardown,
12734                         test_AES_GCM_authenticated_encryption_test_case_6),
12735                 TEST_CASE_ST(ut_setup, ut_teardown,
12736                         test_AES_GCM_authenticated_encryption_test_case_7),
12737                 TEST_CASE_ST(ut_setup, ut_teardown,
12738                         test_AES_GCM_authenticated_encryption_test_case_8),
12739
12740                 /** AES GCM Authenticated Decryption */
12741                 TEST_CASE_ST(ut_setup, ut_teardown,
12742                         test_AES_GCM_authenticated_decryption_test_case_1),
12743                 TEST_CASE_ST(ut_setup, ut_teardown,
12744                         test_AES_GCM_authenticated_decryption_test_case_2),
12745                 TEST_CASE_ST(ut_setup, ut_teardown,
12746                         test_AES_GCM_authenticated_decryption_test_case_3),
12747                 TEST_CASE_ST(ut_setup, ut_teardown,
12748                         test_AES_GCM_authenticated_decryption_test_case_4),
12749                 TEST_CASE_ST(ut_setup, ut_teardown,
12750                         test_AES_GCM_authenticated_decryption_test_case_5),
12751                 TEST_CASE_ST(ut_setup, ut_teardown,
12752                         test_AES_GCM_authenticated_decryption_test_case_6),
12753                 TEST_CASE_ST(ut_setup, ut_teardown,
12754                         test_AES_GCM_authenticated_decryption_test_case_7),
12755                 TEST_CASE_ST(ut_setup, ut_teardown,
12756                         test_AES_GCM_authenticated_decryption_test_case_8),
12757
12758                 /** AES GCM Authenticated Encryption 192 bits key */
12759                 TEST_CASE_ST(ut_setup, ut_teardown,
12760                         test_AES_GCM_auth_encryption_test_case_192_1),
12761                 TEST_CASE_ST(ut_setup, ut_teardown,
12762                         test_AES_GCM_auth_encryption_test_case_192_2),
12763                 TEST_CASE_ST(ut_setup, ut_teardown,
12764                         test_AES_GCM_auth_encryption_test_case_192_3),
12765                 TEST_CASE_ST(ut_setup, ut_teardown,
12766                         test_AES_GCM_auth_encryption_test_case_192_4),
12767                 TEST_CASE_ST(ut_setup, ut_teardown,
12768                         test_AES_GCM_auth_encryption_test_case_192_5),
12769                 TEST_CASE_ST(ut_setup, ut_teardown,
12770                         test_AES_GCM_auth_encryption_test_case_192_6),
12771                 TEST_CASE_ST(ut_setup, ut_teardown,
12772                         test_AES_GCM_auth_encryption_test_case_192_7),
12773
12774                 /** AES GCM Authenticated Decryption 192 bits key */
12775                 TEST_CASE_ST(ut_setup, ut_teardown,
12776                         test_AES_GCM_auth_decryption_test_case_192_1),
12777                 TEST_CASE_ST(ut_setup, ut_teardown,
12778                         test_AES_GCM_auth_decryption_test_case_192_2),
12779                 TEST_CASE_ST(ut_setup, ut_teardown,
12780                         test_AES_GCM_auth_decryption_test_case_192_3),
12781                 TEST_CASE_ST(ut_setup, ut_teardown,
12782                         test_AES_GCM_auth_decryption_test_case_192_4),
12783                 TEST_CASE_ST(ut_setup, ut_teardown,
12784                         test_AES_GCM_auth_decryption_test_case_192_5),
12785                 TEST_CASE_ST(ut_setup, ut_teardown,
12786                         test_AES_GCM_auth_decryption_test_case_192_6),
12787                 TEST_CASE_ST(ut_setup, ut_teardown,
12788                         test_AES_GCM_auth_decryption_test_case_192_7),
12789
12790                 /** AES GCM Authenticated Encryption 256 bits key */
12791                 TEST_CASE_ST(ut_setup, ut_teardown,
12792                         test_AES_GCM_auth_encryption_test_case_256_1),
12793                 TEST_CASE_ST(ut_setup, ut_teardown,
12794                         test_AES_GCM_auth_encryption_test_case_256_2),
12795                 TEST_CASE_ST(ut_setup, ut_teardown,
12796                         test_AES_GCM_auth_encryption_test_case_256_3),
12797                 TEST_CASE_ST(ut_setup, ut_teardown,
12798                         test_AES_GCM_auth_encryption_test_case_256_4),
12799                 TEST_CASE_ST(ut_setup, ut_teardown,
12800                         test_AES_GCM_auth_encryption_test_case_256_5),
12801                 TEST_CASE_ST(ut_setup, ut_teardown,
12802                         test_AES_GCM_auth_encryption_test_case_256_6),
12803                 TEST_CASE_ST(ut_setup, ut_teardown,
12804                         test_AES_GCM_auth_encryption_test_case_256_7),
12805
12806                 /** AES GCM Authenticated Decryption 256 bits key */
12807                 TEST_CASE_ST(ut_setup, ut_teardown,
12808                         test_AES_GCM_auth_decryption_test_case_256_1),
12809                 TEST_CASE_ST(ut_setup, ut_teardown,
12810                         test_AES_GCM_auth_decryption_test_case_256_2),
12811                 TEST_CASE_ST(ut_setup, ut_teardown,
12812                         test_AES_GCM_auth_decryption_test_case_256_3),
12813                 TEST_CASE_ST(ut_setup, ut_teardown,
12814                         test_AES_GCM_auth_decryption_test_case_256_4),
12815                 TEST_CASE_ST(ut_setup, ut_teardown,
12816                         test_AES_GCM_auth_decryption_test_case_256_5),
12817                 TEST_CASE_ST(ut_setup, ut_teardown,
12818                         test_AES_GCM_auth_decryption_test_case_256_6),
12819                 TEST_CASE_ST(ut_setup, ut_teardown,
12820                         test_AES_GCM_auth_decryption_test_case_256_7),
12821
12822                 /** Out of place tests */
12823                 TEST_CASE_ST(ut_setup, ut_teardown,
12824                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12825                 TEST_CASE_ST(ut_setup, ut_teardown,
12826                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12827
12828                 /** SNOW 3G encrypt only (UEA2) */
12829                 TEST_CASE_ST(ut_setup, ut_teardown,
12830                         test_snow3g_encryption_test_case_1),
12831                 TEST_CASE_ST(ut_setup, ut_teardown,
12832                         test_snow3g_encryption_test_case_2),
12833                 TEST_CASE_ST(ut_setup, ut_teardown,
12834                         test_snow3g_encryption_test_case_3),
12835                 TEST_CASE_ST(ut_setup, ut_teardown,
12836                         test_snow3g_encryption_test_case_4),
12837                 TEST_CASE_ST(ut_setup, ut_teardown,
12838                         test_snow3g_encryption_test_case_5),
12839
12840                 TEST_CASE_ST(ut_setup, ut_teardown,
12841                         test_snow3g_encryption_test_case_1_oop),
12842                 TEST_CASE_ST(ut_setup, ut_teardown,
12843                                 test_snow3g_encryption_test_case_1_oop_sgl),
12844                 TEST_CASE_ST(ut_setup, ut_teardown,
12845                         test_snow3g_decryption_test_case_1_oop),
12846
12847                 /** SNOW 3G decrypt only (UEA2) */
12848                 TEST_CASE_ST(ut_setup, ut_teardown,
12849                         test_snow3g_decryption_test_case_1),
12850                 TEST_CASE_ST(ut_setup, ut_teardown,
12851                         test_snow3g_decryption_test_case_2),
12852                 TEST_CASE_ST(ut_setup, ut_teardown,
12853                         test_snow3g_decryption_test_case_3),
12854                 TEST_CASE_ST(ut_setup, ut_teardown,
12855                         test_snow3g_decryption_test_case_4),
12856                 TEST_CASE_ST(ut_setup, ut_teardown,
12857                         test_snow3g_decryption_test_case_5),
12858
12859                 TEST_CASE_ST(ut_setup, ut_teardown,
12860                         test_snow3g_hash_generate_test_case_1),
12861                 TEST_CASE_ST(ut_setup, ut_teardown,
12862                         test_snow3g_hash_generate_test_case_2),
12863                 TEST_CASE_ST(ut_setup, ut_teardown,
12864                         test_snow3g_hash_generate_test_case_3),
12865                 TEST_CASE_ST(ut_setup, ut_teardown,
12866                         test_snow3g_hash_verify_test_case_1),
12867                 TEST_CASE_ST(ut_setup, ut_teardown,
12868                         test_snow3g_hash_verify_test_case_2),
12869                 TEST_CASE_ST(ut_setup, ut_teardown,
12870                         test_snow3g_hash_verify_test_case_3),
12871
12872                 /** ZUC encrypt only (EEA3) */
12873                 TEST_CASE_ST(ut_setup, ut_teardown,
12874                         test_zuc_encryption_test_case_1),
12875                 TEST_CASE_ST(ut_setup, ut_teardown,
12876                         test_zuc_encryption_test_case_2),
12877                 TEST_CASE_ST(ut_setup, ut_teardown,
12878                         test_zuc_encryption_test_case_3),
12879                 TEST_CASE_ST(ut_setup, ut_teardown,
12880                         test_zuc_encryption_test_case_4),
12881                 TEST_CASE_ST(ut_setup, ut_teardown,
12882                         test_zuc_encryption_test_case_5),
12883
12884                 /** ZUC authenticate (EIA3) */
12885                 TEST_CASE_ST(ut_setup, ut_teardown,
12886                         test_zuc_hash_generate_test_case_6),
12887                 TEST_CASE_ST(ut_setup, ut_teardown,
12888                         test_zuc_hash_generate_test_case_7),
12889                 TEST_CASE_ST(ut_setup, ut_teardown,
12890                         test_zuc_hash_generate_test_case_8),
12891
12892                 /** HMAC_MD5 Authentication */
12893                 TEST_CASE_ST(ut_setup, ut_teardown,
12894                         test_MD5_HMAC_generate_case_1),
12895                 TEST_CASE_ST(ut_setup, ut_teardown,
12896                         test_MD5_HMAC_verify_case_1),
12897                 TEST_CASE_ST(ut_setup, ut_teardown,
12898                         test_MD5_HMAC_generate_case_2),
12899                 TEST_CASE_ST(ut_setup, ut_teardown,
12900                         test_MD5_HMAC_verify_case_2),
12901
12902                 /** Negative tests */
12903                 TEST_CASE_ST(ut_setup, ut_teardown,
12904                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12905                 TEST_CASE_ST(ut_setup, ut_teardown,
12906                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12907                 TEST_CASE_ST(ut_setup, ut_teardown,
12908                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12909                 TEST_CASE_ST(ut_setup, ut_teardown,
12910                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12911                 TEST_CASE_ST(ut_setup, ut_teardown,
12912                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12913                 TEST_CASE_ST(ut_setup, ut_teardown,
12914                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12915                 TEST_CASE_ST(ut_setup, ut_teardown,
12916                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12917                 TEST_CASE_ST(ut_setup, ut_teardown,
12918                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12919                 TEST_CASE_ST(ut_setup, ut_teardown,
12920                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12921                 TEST_CASE_ST(ut_setup, ut_teardown,
12922                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12923                 TEST_CASE_ST(ut_setup, ut_teardown,
12924                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12925                 TEST_CASE_ST(ut_setup, ut_teardown,
12926                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12927                 TEST_CASE_ST(ut_setup, ut_teardown,
12928                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12929                 TEST_CASE_ST(ut_setup, ut_teardown,
12930                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12931                 TEST_CASE_ST(ut_setup, ut_teardown,
12932                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12933                 TEST_CASE_ST(ut_setup, ut_teardown,
12934                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12935
12936                 /* ESN Testcase */
12937                 TEST_CASE_ST(ut_setup, ut_teardown,
12938                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12939
12940                 TEST_CASE_ST(ut_setup, ut_teardown,
12941                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12942
12943                 TEST_CASES_END() /**< NULL terminate unit test array */
12944         }
12945 };
12946
12947 static struct unit_test_suite cryptodev_armv8_testsuite  = {
12948         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
12949         .setup = testsuite_setup,
12950         .teardown = testsuite_teardown,
12951         .unit_test_cases = {
12952                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12953
12954                 /** Negative tests */
12955                 TEST_CASE_ST(ut_setup, ut_teardown,
12956                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12957                 TEST_CASE_ST(ut_setup, ut_teardown,
12958                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12959
12960                 TEST_CASES_END() /**< NULL terminate unit test array */
12961         }
12962 };
12963
12964 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
12965         .suite_name = "Crypto Device Marvell Component Test Suite",
12966         .setup = testsuite_setup,
12967         .teardown = testsuite_teardown,
12968         .unit_test_cases = {
12969                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12970                 TEST_CASE_ST(ut_setup, ut_teardown,
12971                                 test_multi_session_random_usage),
12972                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12973                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12974                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12975                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12976                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12977
12978                 /** Negative tests */
12979                 TEST_CASE_ST(ut_setup, ut_teardown,
12980                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12981                 TEST_CASE_ST(ut_setup, ut_teardown,
12982                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12983                 TEST_CASE_ST(ut_setup, ut_teardown,
12984                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12985                 TEST_CASE_ST(ut_setup, ut_teardown,
12986                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12987
12988                 TEST_CASES_END() /**< NULL terminate unit test array */
12989         }
12990 };
12991
12992 static struct unit_test_suite cryptodev_ccp_testsuite  = {
12993         .suite_name = "Crypto Device CCP Unit Test Suite",
12994         .setup = testsuite_setup,
12995         .teardown = testsuite_teardown,
12996         .unit_test_cases = {
12997                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12998                 TEST_CASE_ST(ut_setup, ut_teardown,
12999                                 test_multi_session_random_usage),
13000                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13001                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13002                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13003                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13004                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13005
13006                 /** Negative tests */
13007                 TEST_CASE_ST(ut_setup, ut_teardown,
13008                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13009                 TEST_CASE_ST(ut_setup, ut_teardown,
13010                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13011                 TEST_CASE_ST(ut_setup, ut_teardown,
13012                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13013                 TEST_CASE_ST(ut_setup, ut_teardown,
13014                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13015
13016                 TEST_CASES_END() /**< NULL terminate unit test array */
13017         }
13018 };
13019
13020 static struct unit_test_suite cryptodev_octeontx_testsuite  = {
13021         .suite_name = "Crypto Device OCTEONTX Unit Test Suite",
13022         .setup = testsuite_setup,
13023         .teardown = testsuite_teardown,
13024         .unit_test_cases = {
13025                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13026                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13027                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13028                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13029                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13030
13031                 /** AES GCM Authenticated Encryption */
13032                 TEST_CASE_ST(ut_setup, ut_teardown,
13033                         test_AES_GCM_authenticated_encryption_test_case_1),
13034                 TEST_CASE_ST(ut_setup, ut_teardown,
13035                         test_AES_GCM_authenticated_encryption_test_case_2),
13036                 TEST_CASE_ST(ut_setup, ut_teardown,
13037                         test_AES_GCM_authenticated_encryption_test_case_3),
13038                 TEST_CASE_ST(ut_setup, ut_teardown,
13039                         test_AES_GCM_authenticated_encryption_test_case_4),
13040                 TEST_CASE_ST(ut_setup, ut_teardown,
13041                         test_AES_GCM_authenticated_encryption_test_case_5),
13042                 TEST_CASE_ST(ut_setup, ut_teardown,
13043                         test_AES_GCM_authenticated_encryption_test_case_6),
13044                 TEST_CASE_ST(ut_setup, ut_teardown,
13045                         test_AES_GCM_authenticated_encryption_test_case_7),
13046
13047                 /** AES GCM Authenticated Decryption */
13048                 TEST_CASE_ST(ut_setup, ut_teardown,
13049                         test_AES_GCM_authenticated_decryption_test_case_1),
13050                 TEST_CASE_ST(ut_setup, ut_teardown,
13051                         test_AES_GCM_authenticated_decryption_test_case_2),
13052                 TEST_CASE_ST(ut_setup, ut_teardown,
13053                         test_AES_GCM_authenticated_decryption_test_case_3),
13054                 TEST_CASE_ST(ut_setup, ut_teardown,
13055                         test_AES_GCM_authenticated_decryption_test_case_4),
13056                 TEST_CASE_ST(ut_setup, ut_teardown,
13057                         test_AES_GCM_authenticated_decryption_test_case_5),
13058                 TEST_CASE_ST(ut_setup, ut_teardown,
13059                         test_AES_GCM_authenticated_decryption_test_case_6),
13060                 TEST_CASE_ST(ut_setup, ut_teardown,
13061                         test_AES_GCM_authenticated_decryption_test_case_7),
13062                 /** AES GMAC Authentication */
13063                 TEST_CASE_ST(ut_setup, ut_teardown,
13064                         test_AES_GMAC_authentication_test_case_1),
13065                 TEST_CASE_ST(ut_setup, ut_teardown,
13066                         test_AES_GMAC_authentication_verify_test_case_1),
13067                 TEST_CASE_ST(ut_setup, ut_teardown,
13068                         test_AES_GMAC_authentication_test_case_2),
13069                 TEST_CASE_ST(ut_setup, ut_teardown,
13070                         test_AES_GMAC_authentication_verify_test_case_2),
13071                 TEST_CASE_ST(ut_setup, ut_teardown,
13072                         test_AES_GMAC_authentication_test_case_3),
13073                 TEST_CASE_ST(ut_setup, ut_teardown,
13074                         test_AES_GMAC_authentication_verify_test_case_3),
13075
13076                 /** SNOW 3G encrypt only (UEA2) */
13077                 TEST_CASE_ST(ut_setup, ut_teardown,
13078                         test_snow3g_encryption_test_case_1),
13079                 TEST_CASE_ST(ut_setup, ut_teardown,
13080                         test_snow3g_encryption_test_case_2),
13081                 TEST_CASE_ST(ut_setup, ut_teardown,
13082                         test_snow3g_encryption_test_case_3),
13083                 TEST_CASE_ST(ut_setup, ut_teardown,
13084                         test_snow3g_encryption_test_case_4),
13085                 TEST_CASE_ST(ut_setup, ut_teardown,
13086                         test_snow3g_encryption_test_case_5),
13087
13088                 TEST_CASE_ST(ut_setup, ut_teardown,
13089                         test_snow3g_encryption_test_case_1_oop),
13090                 TEST_CASE_ST(ut_setup, ut_teardown,
13091                         test_snow3g_decryption_test_case_1_oop),
13092                 TEST_CASE_ST(ut_setup, ut_teardown,
13093                         test_snow3g_encryption_test_case_1_oop_sgl),
13094
13095                 /** SNOW 3G decrypt only (UEA2) */
13096                 TEST_CASE_ST(ut_setup, ut_teardown,
13097                         test_snow3g_decryption_test_case_1),
13098                 TEST_CASE_ST(ut_setup, ut_teardown,
13099                         test_snow3g_decryption_test_case_2),
13100                 TEST_CASE_ST(ut_setup, ut_teardown,
13101                         test_snow3g_decryption_test_case_3),
13102                 TEST_CASE_ST(ut_setup, ut_teardown,
13103                         test_snow3g_decryption_test_case_4),
13104                 TEST_CASE_ST(ut_setup, ut_teardown,
13105                         test_snow3g_decryption_test_case_5),
13106
13107                 TEST_CASE_ST(ut_setup, ut_teardown,
13108                         test_snow3g_hash_generate_test_case_1),
13109                 TEST_CASE_ST(ut_setup, ut_teardown,
13110                         test_snow3g_hash_generate_test_case_2),
13111                 TEST_CASE_ST(ut_setup, ut_teardown,
13112                         test_snow3g_hash_generate_test_case_3),
13113                 TEST_CASE_ST(ut_setup, ut_teardown,
13114                         test_snow3g_hash_verify_test_case_1),
13115                 TEST_CASE_ST(ut_setup, ut_teardown,
13116                         test_snow3g_hash_verify_test_case_2),
13117                 TEST_CASE_ST(ut_setup, ut_teardown,
13118                         test_snow3g_hash_verify_test_case_3),
13119
13120                 /** ZUC encrypt only (EEA3) */
13121                 TEST_CASE_ST(ut_setup, ut_teardown,
13122                         test_zuc_encryption_test_case_1),
13123                 TEST_CASE_ST(ut_setup, ut_teardown,
13124                         test_zuc_encryption_test_case_2),
13125                 TEST_CASE_ST(ut_setup, ut_teardown,
13126                         test_zuc_encryption_test_case_3),
13127                 TEST_CASE_ST(ut_setup, ut_teardown,
13128                         test_zuc_encryption_test_case_4),
13129                 TEST_CASE_ST(ut_setup, ut_teardown,
13130                         test_zuc_encryption_test_case_5),
13131                 TEST_CASE_ST(ut_setup, ut_teardown,
13132                         test_zuc_hash_generate_test_case_1),
13133                 TEST_CASE_ST(ut_setup, ut_teardown,
13134                         test_zuc_hash_generate_test_case_2),
13135                 TEST_CASE_ST(ut_setup, ut_teardown,
13136                         test_zuc_hash_generate_test_case_3),
13137                 TEST_CASE_ST(ut_setup, ut_teardown,
13138                         test_zuc_hash_generate_test_case_4),
13139                 TEST_CASE_ST(ut_setup, ut_teardown,
13140                         test_zuc_hash_generate_test_case_5),
13141                 TEST_CASE_ST(ut_setup, ut_teardown,
13142                         test_zuc_encryption_test_case_6_sgl),
13143
13144                 /** KASUMI encrypt only (UEA1) */
13145                 TEST_CASE_ST(ut_setup, ut_teardown,
13146                         test_kasumi_encryption_test_case_1),
13147                 TEST_CASE_ST(ut_setup, ut_teardown,
13148                         test_kasumi_encryption_test_case_2),
13149                 TEST_CASE_ST(ut_setup, ut_teardown,
13150                         test_kasumi_encryption_test_case_3),
13151                 TEST_CASE_ST(ut_setup, ut_teardown,
13152                         test_kasumi_encryption_test_case_4),
13153                 TEST_CASE_ST(ut_setup, ut_teardown,
13154                         test_kasumi_encryption_test_case_5),
13155                 TEST_CASE_ST(ut_setup, ut_teardown,
13156                         test_kasumi_encryption_test_case_1_sgl),
13157                 TEST_CASE_ST(ut_setup, ut_teardown,
13158                         test_kasumi_encryption_test_case_1_oop_sgl),
13159                 /** KASUMI decrypt only (UEA1) */
13160                 TEST_CASE_ST(ut_setup, ut_teardown,
13161                         test_kasumi_decryption_test_case_1),
13162                 TEST_CASE_ST(ut_setup, ut_teardown,
13163                         test_kasumi_decryption_test_case_2),
13164                 TEST_CASE_ST(ut_setup, ut_teardown,
13165                         test_kasumi_decryption_test_case_3),
13166                 TEST_CASE_ST(ut_setup, ut_teardown,
13167                         test_kasumi_decryption_test_case_4),
13168                 TEST_CASE_ST(ut_setup, ut_teardown,
13169                         test_kasumi_decryption_test_case_5),
13170
13171                 TEST_CASE_ST(ut_setup, ut_teardown,
13172                         test_kasumi_encryption_test_case_1_oop),
13173                 TEST_CASE_ST(ut_setup, ut_teardown,
13174                         test_kasumi_decryption_test_case_1_oop),
13175
13176                 /** KASUMI hash only (UIA1) */
13177                 TEST_CASE_ST(ut_setup, ut_teardown,
13178                         test_kasumi_hash_generate_test_case_1),
13179                 TEST_CASE_ST(ut_setup, ut_teardown,
13180                         test_kasumi_hash_generate_test_case_2),
13181                 TEST_CASE_ST(ut_setup, ut_teardown,
13182                         test_kasumi_hash_generate_test_case_3),
13183                 TEST_CASE_ST(ut_setup, ut_teardown,
13184                         test_kasumi_hash_generate_test_case_4),
13185                 TEST_CASE_ST(ut_setup, ut_teardown,
13186                         test_kasumi_hash_generate_test_case_5),
13187                 TEST_CASE_ST(ut_setup, ut_teardown,
13188                         test_kasumi_hash_generate_test_case_6),
13189                 TEST_CASE_ST(ut_setup, ut_teardown,
13190                         test_kasumi_hash_verify_test_case_1),
13191                 TEST_CASE_ST(ut_setup, ut_teardown,
13192                         test_kasumi_hash_verify_test_case_2),
13193                 TEST_CASE_ST(ut_setup, ut_teardown,
13194                         test_kasumi_hash_verify_test_case_3),
13195                 TEST_CASE_ST(ut_setup, ut_teardown,
13196                         test_kasumi_hash_verify_test_case_4),
13197                 TEST_CASE_ST(ut_setup, ut_teardown,
13198                         test_kasumi_hash_verify_test_case_5),
13199
13200                 /** NULL tests */
13201                 TEST_CASE_ST(ut_setup, ut_teardown,
13202                         test_null_cipher_only_operation),
13203                 TEST_CASE_ST(ut_setup, ut_teardown,
13204                         test_null_auth_only_operation),
13205                 TEST_CASE_ST(ut_setup, ut_teardown,
13206                         test_null_cipher_auth_operation),
13207                 TEST_CASE_ST(ut_setup, ut_teardown,
13208                         test_null_auth_cipher_operation),
13209
13210                 /** Negative tests */
13211                 TEST_CASE_ST(ut_setup, ut_teardown,
13212                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13213                 TEST_CASE_ST(ut_setup, ut_teardown,
13214                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13215                 TEST_CASE_ST(ut_setup, ut_teardown,
13216                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13217                 TEST_CASE_ST(ut_setup, ut_teardown,
13218                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13219                 TEST_CASE_ST(ut_setup, ut_teardown,
13220                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13221                 TEST_CASE_ST(ut_setup, ut_teardown,
13222                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13223                 TEST_CASES_END() /**< NULL terminate unit test array */
13224         }
13225 };
13226
13227 static struct unit_test_suite cryptodev_nitrox_testsuite  = {
13228         .suite_name = "Crypto NITROX Unit Test Suite",
13229         .setup = testsuite_setup,
13230         .teardown = testsuite_teardown,
13231         .unit_test_cases = {
13232                 TEST_CASE_ST(ut_setup, ut_teardown,
13233                              test_device_configure_invalid_dev_id),
13234                 TEST_CASE_ST(ut_setup, ut_teardown,
13235                                 test_device_configure_invalid_queue_pair_ids),
13236                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13237                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13238
13239                 TEST_CASES_END() /**< NULL terminate unit test array */
13240         }
13241 };
13242
13243 static struct unit_test_suite cryptodev_octeontx2_testsuite  = {
13244         .suite_name = "Crypto Device OCTEON TX2 Unit Test Suite",
13245         .setup = testsuite_setup,
13246         .teardown = testsuite_teardown,
13247         .unit_test_cases = {
13248                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13249                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13250                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13251                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13252                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13253
13254                 /** AES GCM Authenticated Encryption */
13255                 TEST_CASE_ST(ut_setup, ut_teardown,
13256                         test_AES_GCM_authenticated_encryption_test_case_1),
13257                 TEST_CASE_ST(ut_setup, ut_teardown,
13258                         test_AES_GCM_authenticated_encryption_test_case_2),
13259                 TEST_CASE_ST(ut_setup, ut_teardown,
13260                         test_AES_GCM_authenticated_encryption_test_case_3),
13261                 TEST_CASE_ST(ut_setup, ut_teardown,
13262                         test_AES_GCM_authenticated_encryption_test_case_4),
13263                 TEST_CASE_ST(ut_setup, ut_teardown,
13264                         test_AES_GCM_authenticated_encryption_test_case_5),
13265                 TEST_CASE_ST(ut_setup, ut_teardown,
13266                         test_AES_GCM_authenticated_encryption_test_case_6),
13267                 TEST_CASE_ST(ut_setup, ut_teardown,
13268                         test_AES_GCM_authenticated_encryption_test_case_7),
13269
13270                 /** AES GCM Authenticated Decryption */
13271                 TEST_CASE_ST(ut_setup, ut_teardown,
13272                         test_AES_GCM_authenticated_decryption_test_case_1),
13273                 TEST_CASE_ST(ut_setup, ut_teardown,
13274                         test_AES_GCM_authenticated_decryption_test_case_2),
13275                 TEST_CASE_ST(ut_setup, ut_teardown,
13276                         test_AES_GCM_authenticated_decryption_test_case_3),
13277                 TEST_CASE_ST(ut_setup, ut_teardown,
13278                         test_AES_GCM_authenticated_decryption_test_case_4),
13279                 TEST_CASE_ST(ut_setup, ut_teardown,
13280                         test_AES_GCM_authenticated_decryption_test_case_5),
13281                 TEST_CASE_ST(ut_setup, ut_teardown,
13282                         test_AES_GCM_authenticated_decryption_test_case_6),
13283                 TEST_CASE_ST(ut_setup, ut_teardown,
13284                         test_AES_GCM_authenticated_decryption_test_case_7),
13285                 /** AES GMAC Authentication */
13286                 TEST_CASE_ST(ut_setup, ut_teardown,
13287                         test_AES_GMAC_authentication_test_case_1),
13288                 TEST_CASE_ST(ut_setup, ut_teardown,
13289                         test_AES_GMAC_authentication_verify_test_case_1),
13290                 TEST_CASE_ST(ut_setup, ut_teardown,
13291                         test_AES_GMAC_authentication_test_case_2),
13292                 TEST_CASE_ST(ut_setup, ut_teardown,
13293                         test_AES_GMAC_authentication_verify_test_case_2),
13294                 TEST_CASE_ST(ut_setup, ut_teardown,
13295                         test_AES_GMAC_authentication_test_case_3),
13296                 TEST_CASE_ST(ut_setup, ut_teardown,
13297                         test_AES_GMAC_authentication_verify_test_case_3),
13298
13299                 /** SNOW 3G encrypt only (UEA2) */
13300                 TEST_CASE_ST(ut_setup, ut_teardown,
13301                         test_snow3g_encryption_test_case_1),
13302                 TEST_CASE_ST(ut_setup, ut_teardown,
13303                         test_snow3g_encryption_test_case_2),
13304                 TEST_CASE_ST(ut_setup, ut_teardown,
13305                         test_snow3g_encryption_test_case_3),
13306                 TEST_CASE_ST(ut_setup, ut_teardown,
13307                         test_snow3g_encryption_test_case_4),
13308                 TEST_CASE_ST(ut_setup, ut_teardown,
13309                         test_snow3g_encryption_test_case_5),
13310
13311                 TEST_CASE_ST(ut_setup, ut_teardown,
13312                         test_snow3g_encryption_test_case_1_oop),
13313                 TEST_CASE_ST(ut_setup, ut_teardown,
13314                         test_snow3g_decryption_test_case_1_oop),
13315                 TEST_CASE_ST(ut_setup, ut_teardown,
13316                         test_snow3g_encryption_test_case_1_oop_sgl),
13317
13318                 /** SNOW 3G decrypt only (UEA2) */
13319                 TEST_CASE_ST(ut_setup, ut_teardown,
13320                         test_snow3g_decryption_test_case_1),
13321                 TEST_CASE_ST(ut_setup, ut_teardown,
13322                         test_snow3g_decryption_test_case_2),
13323                 TEST_CASE_ST(ut_setup, ut_teardown,
13324                         test_snow3g_decryption_test_case_3),
13325                 TEST_CASE_ST(ut_setup, ut_teardown,
13326                         test_snow3g_decryption_test_case_4),
13327                 TEST_CASE_ST(ut_setup, ut_teardown,
13328                         test_snow3g_decryption_test_case_5),
13329
13330                 TEST_CASE_ST(ut_setup, ut_teardown,
13331                         test_snow3g_hash_generate_test_case_1),
13332                 TEST_CASE_ST(ut_setup, ut_teardown,
13333                         test_snow3g_hash_generate_test_case_2),
13334                 TEST_CASE_ST(ut_setup, ut_teardown,
13335                         test_snow3g_hash_generate_test_case_3),
13336                 TEST_CASE_ST(ut_setup, ut_teardown,
13337                         test_snow3g_hash_verify_test_case_1),
13338                 TEST_CASE_ST(ut_setup, ut_teardown,
13339                         test_snow3g_hash_verify_test_case_2),
13340                 TEST_CASE_ST(ut_setup, ut_teardown,
13341                         test_snow3g_hash_verify_test_case_3),
13342
13343                 /** ZUC encrypt only (EEA3) */
13344                 TEST_CASE_ST(ut_setup, ut_teardown,
13345                         test_zuc_encryption_test_case_1),
13346                 TEST_CASE_ST(ut_setup, ut_teardown,
13347                         test_zuc_encryption_test_case_2),
13348                 TEST_CASE_ST(ut_setup, ut_teardown,
13349                         test_zuc_encryption_test_case_3),
13350                 TEST_CASE_ST(ut_setup, ut_teardown,
13351                         test_zuc_encryption_test_case_4),
13352                 TEST_CASE_ST(ut_setup, ut_teardown,
13353                         test_zuc_encryption_test_case_5),
13354                 TEST_CASE_ST(ut_setup, ut_teardown,
13355                         test_zuc_hash_generate_test_case_1),
13356                 TEST_CASE_ST(ut_setup, ut_teardown,
13357                         test_zuc_hash_generate_test_case_2),
13358                 TEST_CASE_ST(ut_setup, ut_teardown,
13359                         test_zuc_hash_generate_test_case_3),
13360                 TEST_CASE_ST(ut_setup, ut_teardown,
13361                         test_zuc_hash_generate_test_case_4),
13362                 TEST_CASE_ST(ut_setup, ut_teardown,
13363                         test_zuc_hash_generate_test_case_5),
13364                 TEST_CASE_ST(ut_setup, ut_teardown,
13365                         test_zuc_encryption_test_case_6_sgl),
13366
13367                 /** KASUMI encrypt only (UEA1) */
13368                 TEST_CASE_ST(ut_setup, ut_teardown,
13369                         test_kasumi_encryption_test_case_1),
13370                 TEST_CASE_ST(ut_setup, ut_teardown,
13371                         test_kasumi_encryption_test_case_2),
13372                 TEST_CASE_ST(ut_setup, ut_teardown,
13373                         test_kasumi_encryption_test_case_3),
13374                 TEST_CASE_ST(ut_setup, ut_teardown,
13375                         test_kasumi_encryption_test_case_4),
13376                 TEST_CASE_ST(ut_setup, ut_teardown,
13377                         test_kasumi_encryption_test_case_5),
13378                 TEST_CASE_ST(ut_setup, ut_teardown,
13379                         test_kasumi_encryption_test_case_1_sgl),
13380                 TEST_CASE_ST(ut_setup, ut_teardown,
13381                         test_kasumi_encryption_test_case_1_oop_sgl),
13382                 /** KASUMI decrypt only (UEA1) */
13383                 TEST_CASE_ST(ut_setup, ut_teardown,
13384                         test_kasumi_decryption_test_case_1),
13385                 TEST_CASE_ST(ut_setup, ut_teardown,
13386                         test_kasumi_decryption_test_case_2),
13387                 TEST_CASE_ST(ut_setup, ut_teardown,
13388                         test_kasumi_decryption_test_case_3),
13389                 TEST_CASE_ST(ut_setup, ut_teardown,
13390                         test_kasumi_decryption_test_case_4),
13391                 TEST_CASE_ST(ut_setup, ut_teardown,
13392                         test_kasumi_decryption_test_case_5),
13393
13394                 TEST_CASE_ST(ut_setup, ut_teardown,
13395                         test_kasumi_encryption_test_case_1_oop),
13396                 TEST_CASE_ST(ut_setup, ut_teardown,
13397                         test_kasumi_decryption_test_case_1_oop),
13398
13399                 /** KASUMI hash only (UIA1) */
13400                 TEST_CASE_ST(ut_setup, ut_teardown,
13401                         test_kasumi_hash_generate_test_case_1),
13402                 TEST_CASE_ST(ut_setup, ut_teardown,
13403                         test_kasumi_hash_generate_test_case_2),
13404                 TEST_CASE_ST(ut_setup, ut_teardown,
13405                         test_kasumi_hash_generate_test_case_3),
13406                 TEST_CASE_ST(ut_setup, ut_teardown,
13407                         test_kasumi_hash_generate_test_case_4),
13408                 TEST_CASE_ST(ut_setup, ut_teardown,
13409                         test_kasumi_hash_generate_test_case_5),
13410                 TEST_CASE_ST(ut_setup, ut_teardown,
13411                         test_kasumi_hash_generate_test_case_6),
13412                 TEST_CASE_ST(ut_setup, ut_teardown,
13413                         test_kasumi_hash_verify_test_case_1),
13414                 TEST_CASE_ST(ut_setup, ut_teardown,
13415                         test_kasumi_hash_verify_test_case_2),
13416                 TEST_CASE_ST(ut_setup, ut_teardown,
13417                         test_kasumi_hash_verify_test_case_3),
13418                 TEST_CASE_ST(ut_setup, ut_teardown,
13419                         test_kasumi_hash_verify_test_case_4),
13420                 TEST_CASE_ST(ut_setup, ut_teardown,
13421                         test_kasumi_hash_verify_test_case_5),
13422
13423                 /** NULL tests */
13424                 TEST_CASE_ST(ut_setup, ut_teardown,
13425                         test_null_cipher_only_operation),
13426                 TEST_CASE_ST(ut_setup, ut_teardown,
13427                         test_null_auth_only_operation),
13428                 TEST_CASE_ST(ut_setup, ut_teardown,
13429                         test_null_cipher_auth_operation),
13430                 TEST_CASE_ST(ut_setup, ut_teardown,
13431                         test_null_auth_cipher_operation),
13432
13433                 /** Negative tests */
13434                 TEST_CASE_ST(ut_setup, ut_teardown,
13435                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13436                 TEST_CASE_ST(ut_setup, ut_teardown,
13437                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13438                 TEST_CASE_ST(ut_setup, ut_teardown,
13439                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13440                 TEST_CASE_ST(ut_setup, ut_teardown,
13441                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13442                 TEST_CASE_ST(ut_setup, ut_teardown,
13443                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13444                 TEST_CASE_ST(ut_setup, ut_teardown,
13445                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13446                 TEST_CASES_END() /**< NULL terminate unit test array */
13447         }
13448 };
13449
13450 static int
13451 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13452 {
13453         gbl_driver_id = rte_cryptodev_driver_id_get(
13454                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13455
13456         if (gbl_driver_id == -1) {
13457                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
13458                 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
13459                 "are enabled in config file to run this testsuite.\n");
13460                 return TEST_SKIPPED;
13461         }
13462
13463         return unit_test_suite_runner(&cryptodev_testsuite);
13464 }
13465
13466 static int
13467 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13468 {
13469         gbl_driver_id = rte_cryptodev_driver_id_get(
13470                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13471
13472         if (gbl_driver_id == -1) {
13473                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
13474                                 "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
13475                                 "in config file to run this testsuite.\n");
13476                 return TEST_FAILED;
13477         }
13478
13479         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13480 }
13481
13482 static int
13483 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13484 {
13485         gbl_driver_id = rte_cryptodev_driver_id_get(
13486                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13487
13488         if (gbl_driver_id == -1) {
13489                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
13490                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
13491                                 "in config file to run this testsuite.\n");
13492                 return TEST_SKIPPED;
13493         }
13494
13495         return unit_test_suite_runner(&cryptodev_testsuite);
13496 }
13497
13498 static int
13499 test_cryptodev_cpu_aesni_mb(void)
13500 {
13501         int32_t rc;
13502         enum rte_security_session_action_type at;
13503
13504         gbl_driver_id = rte_cryptodev_driver_id_get(
13505                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13506
13507         if (gbl_driver_id == -1) {
13508                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
13509                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
13510                                 "in config file to run this testsuite.\n");
13511                 return TEST_SKIPPED;
13512         }
13513
13514         at = gbl_action_type;
13515         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13516         rc = unit_test_suite_runner(&cryptodev_testsuite);
13517         gbl_action_type = at;
13518         return rc;
13519 }
13520
13521 static int
13522 test_cryptodev_openssl(void)
13523 {
13524         gbl_driver_id = rte_cryptodev_driver_id_get(
13525                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13526
13527         if (gbl_driver_id == -1) {
13528                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
13529                                 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
13530                                 "in config file to run this testsuite.\n");
13531                 return TEST_SKIPPED;
13532         }
13533
13534         return unit_test_suite_runner(&cryptodev_testsuite);
13535 }
13536
13537 static int
13538 test_cryptodev_aesni_gcm(void)
13539 {
13540         gbl_driver_id = rte_cryptodev_driver_id_get(
13541                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13542
13543         if (gbl_driver_id == -1) {
13544                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
13545                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
13546                                 "in config file to run this testsuite.\n");
13547                 return TEST_SKIPPED;
13548         }
13549
13550         return unit_test_suite_runner(&cryptodev_testsuite);
13551 }
13552
13553 static int
13554 test_cryptodev_cpu_aesni_gcm(void)
13555 {
13556         int32_t rc;
13557         enum rte_security_session_action_type at;
13558
13559         gbl_driver_id = rte_cryptodev_driver_id_get(
13560                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13561
13562         if (gbl_driver_id == -1) {
13563                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded. Check if "
13564                                 "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM is enabled "
13565                                 "in config file to run this testsuite.\n");
13566                 return TEST_SKIPPED;
13567         }
13568
13569         at = gbl_action_type;
13570         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13571         rc = unit_test_suite_runner(&cryptodev_testsuite);
13572         gbl_action_type = at;
13573         return rc;
13574 }
13575
13576 static int
13577 test_cryptodev_null(void)
13578 {
13579         gbl_driver_id = rte_cryptodev_driver_id_get(
13580                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13581
13582         if (gbl_driver_id == -1) {
13583                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded. Check if "
13584                                 "CONFIG_RTE_LIBRTE_PMD_NULL is enabled "
13585                                 "in config file to run this testsuite.\n");
13586                 return TEST_SKIPPED;
13587         }
13588
13589         return unit_test_suite_runner(&cryptodev_testsuite);
13590 }
13591
13592 static int
13593 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13594 {
13595         gbl_driver_id = rte_cryptodev_driver_id_get(
13596                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13597
13598         if (gbl_driver_id == -1) {
13599                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded. Check if "
13600                                 "CONFIG_RTE_LIBRTE_PMD_SNOW3G is enabled "
13601                                 "in config file to run this testsuite.\n");
13602                 return TEST_SKIPPED;
13603         }
13604
13605         return unit_test_suite_runner(&cryptodev_testsuite);
13606 }
13607
13608 static int
13609 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13610 {
13611         gbl_driver_id = rte_cryptodev_driver_id_get(
13612                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13613
13614         if (gbl_driver_id == -1) {
13615                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13616                                 "CONFIG_RTE_LIBRTE_PMD_KASUMI is enabled "
13617                                 "in config file to run this testsuite.\n");
13618                 return TEST_SKIPPED;
13619         }
13620
13621         return unit_test_suite_runner(&cryptodev_testsuite);
13622 }
13623
13624 static int
13625 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13626 {
13627         gbl_driver_id = rte_cryptodev_driver_id_get(
13628                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13629
13630         if (gbl_driver_id == -1) {
13631                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded. Check if "
13632                                 "CONFIG_RTE_LIBRTE_PMD_ZUC is enabled "
13633                                 "in config file to run this testsuite.\n");
13634                 return TEST_SKIPPED;
13635         }
13636
13637         return unit_test_suite_runner(&cryptodev_testsuite);
13638 }
13639
13640 static int
13641 test_cryptodev_armv8(void)
13642 {
13643         gbl_driver_id = rte_cryptodev_driver_id_get(
13644                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13645
13646         if (gbl_driver_id == -1) {
13647                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded. Check if "
13648                                 "CONFIG_RTE_LIBRTE_PMD_ARMV8 is enabled "
13649                                 "in config file to run this testsuite.\n");
13650                 return TEST_SKIPPED;
13651         }
13652
13653         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
13654 }
13655
13656 static int
13657 test_cryptodev_mrvl(void)
13658 {
13659         gbl_driver_id = rte_cryptodev_driver_id_get(
13660                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
13661
13662         if (gbl_driver_id == -1) {
13663                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded. Check if "
13664                                 "CONFIG_RTE_LIBRTE_PMD_MVSAM_CRYPTO is enabled "
13665                                 "in config file to run this testsuite.\n");
13666                 return TEST_SKIPPED;
13667         }
13668
13669         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
13670 }
13671
13672 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
13673
13674 static int
13675 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
13676 {
13677         gbl_driver_id = rte_cryptodev_driver_id_get(
13678                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13679
13680         if (gbl_driver_id == -1) {
13681                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded. Check if "
13682                                 "CONFIG_RTE_LIBRTE_PMD_SCHEDULER is enabled "
13683                                 "in config file to run this testsuite.\n");
13684                 return TEST_SKIPPED;
13685         }
13686
13687         if (rte_cryptodev_driver_id_get(
13688                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
13689                 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
13690                         " enabled in config file to run this testsuite.\n");
13691                 return TEST_SKIPPED;
13692 }
13693         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
13694 }
13695
13696 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
13697
13698 #endif
13699
13700 static int
13701 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13702 {
13703         gbl_driver_id = rte_cryptodev_driver_id_get(
13704                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
13705
13706         if (gbl_driver_id == -1) {
13707                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded. Check if "
13708                                 "CONFIG_RTE_LIBRTE_PMD_DPAA2_SEC is enabled "
13709                                 "in config file to run this testsuite.\n");
13710                 return TEST_SKIPPED;
13711         }
13712
13713         return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
13714 }
13715
13716 static int
13717 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13718 {
13719         gbl_driver_id = rte_cryptodev_driver_id_get(
13720                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
13721
13722         if (gbl_driver_id == -1) {
13723                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded. Check if "
13724                                 "CONFIG_RTE_LIBRTE_PMD_DPAA_SEC is enabled "
13725                                 "in config file to run this testsuite.\n");
13726                 return TEST_SKIPPED;
13727         }
13728
13729         return unit_test_suite_runner(&cryptodev_dpaa_sec_testsuite);
13730 }
13731
13732 static int
13733 test_cryptodev_ccp(void)
13734 {
13735         gbl_driver_id = rte_cryptodev_driver_id_get(
13736                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
13737
13738         if (gbl_driver_id == -1) {
13739                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded. Check if "
13740                                 "CONFIG_RTE_LIBRTE_PMD_CCP is enabled "
13741                                 "in config file to run this testsuite.\n");
13742                 return TEST_FAILED;
13743         }
13744
13745         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
13746 }
13747
13748 static int
13749 test_cryptodev_octeontx(void)
13750 {
13751         gbl_driver_id = rte_cryptodev_driver_id_get(
13752                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
13753         if (gbl_driver_id == -1) {
13754                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
13755                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
13756                                 "enabled in config file to run this "
13757                                 "testsuite.\n");
13758                 return TEST_FAILED;
13759         }
13760         return unit_test_suite_runner(&cryptodev_octeontx_testsuite);
13761 }
13762
13763 static int
13764 test_cryptodev_octeontx2(void)
13765 {
13766         gbl_driver_id = rte_cryptodev_driver_id_get(
13767                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
13768         if (gbl_driver_id == -1) {
13769                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded. Check if "
13770                                 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
13771                                 "enabled in config file to run this "
13772                                 "testsuite.\n");
13773                 return TEST_FAILED;
13774         }
13775         return unit_test_suite_runner(&cryptodev_octeontx2_testsuite);
13776 }
13777
13778 static int
13779 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
13780 {
13781         gbl_driver_id = rte_cryptodev_driver_id_get(
13782                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
13783
13784         if (gbl_driver_id == -1) {
13785                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded. Check if "
13786                                 "CONFIG_RTE_LIBRTE_PMD_CAAM_JR is enabled "
13787                                 "in config file to run this testsuite.\n");
13788                 return TEST_FAILED;
13789         }
13790
13791         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
13792 }
13793
13794 static int
13795 test_cryptodev_nitrox(void)
13796 {
13797         gbl_driver_id = rte_cryptodev_driver_id_get(
13798                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
13799
13800         if (gbl_driver_id == -1) {
13801                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded. Check if "
13802                                 "CONFIG_RTE_LIBRTE_PMD_NITROX is enabled "
13803                                 "in config file to run this testsuite.\n");
13804                 return TEST_FAILED;
13805         }
13806
13807         return unit_test_suite_runner(&cryptodev_nitrox_testsuite);
13808 }
13809
13810 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
13811 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
13812 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
13813         test_cryptodev_cpu_aesni_mb);
13814 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
13815 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
13816 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
13817         test_cryptodev_cpu_aesni_gcm);
13818 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
13819 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
13820 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
13821 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
13822 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
13823 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
13824 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
13825 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
13826 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
13827 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
13828 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
13829 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
13830 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
13831 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);