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