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