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