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