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