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