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