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