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